3 * Deprecated functions from WordPress MU and the multisite feature. You shouldn't
4 * use these functions and look for the alternatives instead. The functions will be
5 * removed in a later version.
8 * @subpackage Deprecated
13 * Deprecated functions come here to die.
17 * Get the "dashboard blog", the blog where users without a blog edit their profile data.
18 * Dashboard blog functionality was removed in WordPress 3.1, replaced by the user admin.
21 * @deprecated 3.1.0 Use get_blog_details()
22 * @see get_blog_details()
24 * @return int Current site ID.
26 function get_dashboard_blog() {
27 _deprecated_function( __FUNCTION__, '3.1.0' );
28 if ( $blog = get_site_option( 'dashboard_blog' ) )
29 return get_blog_details( $blog );
31 return get_blog_details( $GLOBALS['current_site']->blog_id );
35 * Generates a random password.
38 * @deprecated 3.0.0 Use wp_generate_password()
39 * @see wp_generate_password()
41 * @param int $len Optional. The length of password to generate. Default 8.
43 function generate_random_password( $len = 8 ) {
44 _deprecated_function( __FUNCTION__, '3.0.0', 'wp_generate_password()' );
45 return wp_generate_password( $len );
49 * Determine if user is a site admin.
51 * Plugins should use is_multisite() instead of checking if this function exists
52 * to determine if multisite is enabled.
54 * This function must reside in a file included only if is_multisite() due to
55 * legacy function_exists() checks to determine if multisite is enabled.
58 * @deprecated 3.0.0 Use is_super_admin()
59 * @see is_super_admin()
61 * @param string $user_login Optional. Username for the user to check. Default empty.
63 function is_site_admin( $user_login = '' ) {
64 _deprecated_function( __FUNCTION__, '3.0.0', 'is_super_admin()' );
66 if ( empty( $user_login ) ) {
67 $user_id = get_current_user_id();
71 $user = get_user_by( 'login', $user_login );
72 if ( ! $user->exists() )
77 return is_super_admin( $user_id );
80 if ( !function_exists( 'graceful_fail' ) ) :
82 * Deprecated functionality to gracefully fail.
85 * @deprecated 3.0.0 Use wp_die()
88 function graceful_fail( $message ) {
89 _deprecated_function( __FUNCTION__, '3.0.0', 'wp_die()' );
90 $message = apply_filters( 'graceful_fail', $message );
91 $message_template = apply_filters( 'graceful_fail_template',
93 <html xmlns="http://www.w3.org/1999/xhtml"><head>
94 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
96 <style type="text/css">
101 line-height: 1.6em; font-family: Georgia, serif; width: 390px; margin: auto;
112 <p class="message">%s</p>
115 die( sprintf( $message_template, $message ) );
120 * Deprecated functionality to retrieve user information.
123 * @deprecated 3.0.0 Use get_user_by()
126 * @param string $username Username.
128 function get_user_details( $username ) {
129 _deprecated_function( __FUNCTION__, '3.0.0', 'get_user_by()' );
130 return get_user_by('login', $username);
134 * Deprecated functionality to clear the global post cache.
137 * @deprecated 3.0.0 Use clean_post_cache()
138 * @see clean_post_cache()
140 * @param int $post_id Post ID.
142 function clear_global_post_cache( $post_id ) {
143 _deprecated_function( __FUNCTION__, '3.0.0', 'clean_post_cache()' );
147 * Deprecated functionality to determin if the current site is the main site.
150 * @deprecated 3.0.0 Use is_main_site()
151 * @see is_main_site()
153 function is_main_blog() {
154 _deprecated_function( __FUNCTION__, '3.0.0', 'is_main_site()' );
155 return is_main_site();
159 * Deprecated functionality to validate an email address.
162 * @deprecated 3.0.0 Use is_email()
165 * @param string $email Email address to verify.
166 * @param bool $check_domain Deprecated.
167 * @return string|bool Either false or the valid email address.
169 function validate_email( $email, $check_domain = true) {
170 _deprecated_function( __FUNCTION__, '3.0.0', 'is_email()' );
171 return is_email( $email, $check_domain );
175 * Deprecated functionality to retrieve a list of all sites.
178 * @deprecated 3.0.0 Use wp_get_sites()
179 * @see wp_get_sites()
181 * @param int $start Optional. Offset for retrieving the blog list. Default 0.
182 * @param int $num Optional. Number of blogs to list. Default 10.
183 * @param string $deprecated Unused.
185 function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) {
186 _deprecated_function( __FUNCTION__, '3.0.0', 'wp_get_sites()' );
189 $blogs = $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid), ARRAY_A );
191 $blog_list = array();
192 foreach ( (array) $blogs as $details ) {
193 $blog_list[ $details['blog_id'] ] = $details;
194 $blog_list[ $details['blog_id'] ]['postcount'] = $wpdb->get_var( "SELECT COUNT(ID) FROM " . $wpdb->get_blog_prefix( $details['blog_id'] ). "posts WHERE post_status='publish' AND post_type='post'" );
197 if ( ! $blog_list ) {
201 if ( $num == 'all' ) {
202 return array_slice( $blog_list, $start, count( $blog_list ) );
204 return array_slice( $blog_list, $start, $num );
209 * Deprecated functionality to retrieve a list of the most active sites.
214 * @param int $num Optional. Number of activate blogs to retrieve. Default 10.
215 * @param bool $display Optional. Whether or not to display the most active blogs list. Default true.
216 * @return array List of "most active" sites.
218 function get_most_active_blogs( $num = 10, $display = true ) {
219 _deprecated_function( __FUNCTION__, '3.0.0' );
221 $blogs = get_blog_list( 0, 'all', false ); // $blog_id -> $details
222 if ( is_array( $blogs ) ) {
224 $most_active = array();
225 $blog_list = array();
226 foreach ( (array) $blogs as $key => $details ) {
227 $most_active[ $details['blog_id'] ] = $details['postcount'];
228 $blog_list[ $details['blog_id'] ] = $details; // array_slice() removes keys!!
230 arsort( $most_active );
231 reset( $most_active );
233 foreach ( (array) $most_active as $key => $details ) {
234 $t[ $key ] = $blog_list[ $key ];
236 unset( $most_active );
241 if ( is_array( $most_active ) ) {
242 reset( $most_active );
243 foreach ( (array) $most_active as $key => $details ) {
244 $url = esc_url('http://' . $details['domain'] . $details['path']);
245 echo '<li>' . $details['postcount'] . " <a href='$url'>$url</a></li>";
249 return array_slice( $most_active, 0, $num );
253 * Redirect a user based on $_GET or $_POST arguments.
255 * The function looks for redirect arguments in the following order:
258 * 3) $_SERVER['HTTP_REFERER']
259 * 4) $_GET['redirect']
260 * 5) $_POST['redirect']
264 * @deprecated 3.3.0 Use wp_redirect()
267 * @param string $url Optional. Redirect URL. Default empty.
269 function wpmu_admin_do_redirect( $url = '' ) {
270 _deprecated_function( __FUNCTION__, '3.3.0' );
273 if ( isset( $_GET['ref'] ) )
275 if ( isset( $_POST['ref'] ) )
276 $ref = $_POST['ref'];
279 $ref = wpmu_admin_redirect_add_updated_param( $ref );
283 if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
284 wp_redirect( $_SERVER['HTTP_REFERER'] );
288 $url = wpmu_admin_redirect_add_updated_param( $url );
289 if ( isset( $_GET['redirect'] ) ) {
290 if ( substr( $_GET['redirect'], 0, 2 ) == 's_' )
291 $url .= '&action=blogs&s='. esc_html( substr( $_GET['redirect'], 2 ) );
292 } elseif ( isset( $_POST['redirect'] ) ) {
293 $url = wpmu_admin_redirect_add_updated_param( $_POST['redirect'] );
300 * Adds an 'updated=true' argument to a URL.
303 * @deprecated 3.3.0 Use add_query_arg()
304 * @see add_query_arg()
306 * @param string $url Optional. Redirect URL. Default empty.
309 function wpmu_admin_redirect_add_updated_param( $url = '' ) {
310 _deprecated_function( __FUNCTION__, '3.3.0' );
312 if ( strpos( $url, 'updated=true' ) === false ) {
313 if ( strpos( $url, '?' ) === false )
314 return $url . '?updated=true';
316 return $url . '&updated=true';
322 * Get a numeric user ID from either an email address or a login.
324 * A numeric string is considered to be an existing user ID
325 * and is simply returned as such.
328 * @deprecated 3.6.0 Use get_user_by()
331 * @param string $string Either an email address or a login.
334 function get_user_id_from_string( $string ) {
335 _deprecated_function( __FUNCTION__, '3.6.0', 'get_user_by()' );
337 if ( is_email( $string ) )
338 $user = get_user_by( 'email', $string );
339 elseif ( is_numeric( $string ) )
342 $user = get_user_by( 'login', $string );
350 * Get a full blog URL, given a domain and a path.
355 * @param string $domain
356 * @param string $path
359 function get_blogaddress_by_domain( $domain, $path ) {
360 _deprecated_function( __FUNCTION__, '3.7.0' );
362 if ( is_subdomain_install() ) {
363 $url = "http://" . $domain.$path;
365 if ( $domain != $_SERVER['HTTP_HOST'] ) {
366 $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
367 $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path;
368 // we're not installing the main blog
369 if ( $blogname != 'www.' )
370 $url .= $blogname . '/';
371 } else { // main blog
372 $url = 'http://' . $domain . $path;
375 return esc_url_raw( $url );
379 * Create an empty blog.
384 * @param string $domain The new blog's domain.
385 * @param string $path The new blog's path.
386 * @param string $weblog_title The new blog's title.
387 * @param int $site_id Optional. Defaults to 1.
388 * @return string|int The ID of the newly created blog
390 function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) {
391 _deprecated_function( __FUNCTION__, '4.4.0' );
396 // Check if the domain has been used already. We should return an error message.
397 if ( domain_exists($domain, $path, $site_id) )
398 return __( '<strong>ERROR</strong>: Site URL already taken.' );
400 // Need to back up wpdb table names, and create a new wp_blogs entry for new blog.
401 // Need to get blog_id from wp_blogs, and create new table names.
402 // Must restore table names at the end of function.
404 if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
405 return __( '<strong>ERROR</strong>: problem creating site entry.' );
407 switch_to_blog($blog_id);
408 install_blog($blog_id);
409 restore_current_blog();
415 * Get the admin for a domain/path combination.
420 * @global wpdb $wpdb WordPress database abstraction object.
422 * @param string $sitedomain Optional. Site domain.
423 * @param string $path Optional. Site path.
424 * @return array|false The network admins
426 function get_admin_users_for_domain( $sitedomain = '', $path = '' ) {
427 _deprecated_function( __FUNCTION__, '4.4.0' );
432 $site_id = $wpdb->siteid;
434 $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) );
437 return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id ), ARRAY_A );
443 * Return an array of sites for a network or networks.
449 * @global wpdb $wpdb WordPress database abstraction object.
451 * @param array $args {
452 * Array of default arguments. Optional.
454 * @type int|array $network_id A network ID or array of network IDs. Set to null to retrieve sites
455 * from all networks. Defaults to current network ID.
456 * @type int $public Retrieve public or non-public sites. Default null, for any.
457 * @type int $archived Retrieve archived or non-archived sites. Default null, for any.
458 * @type int $mature Retrieve mature or non-mature sites. Default null, for any.
459 * @type int $spam Retrieve spam or non-spam sites. Default null, for any.
460 * @type int $deleted Retrieve deleted or non-deleted sites. Default null, for any.
461 * @type int $limit Number of sites to limit the query to. Default 100.
462 * @type int $offset Exclude the first x sites. Used in combination with the $limit parameter. Default 0.
464 * @return array An empty array if the install is considered "large" via wp_is_large_network(). Otherwise,
465 * an associative array of site data arrays, each containing the site (network) ID, blog ID,
466 * site domain and path, dates registered and modified, and the language ID. Also, boolean
467 * values for whether the site is public, archived, mature, spam, and/or deleted.
469 function wp_get_sites( $args = array() ) {
472 _deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' );
474 if ( wp_is_large_network() )
478 'network_id' => $wpdb->siteid,
488 $args = wp_parse_args( $args, $defaults );
490 // Backwards compatibility
491 if( is_array( $args['network_id'] ) ){
492 $args['network__in'] = $args['network_id'];
493 $args['network_id'] = null;
496 if( is_numeric( $args['limit'] ) ){
497 $args['number'] = $args['limit'];
498 $args['limit'] = null;
501 // Make sure count is disabled.
502 $args['count'] = false;
504 $_sites = get_sites( $args );
508 foreach ( $_sites as $_site ) {
509 $_site = get_site( $_site );
510 $results[] = $_site->to_array();