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_site()
24 * @return WP_Site Current site object.
26 function get_dashboard_blog() {
27 _deprecated_function( __FUNCTION__, '3.1.0' );
28 if ( $blog = get_site_option( 'dashboard_blog' ) ) {
29 return get_site( $blog );
32 return get_site( get_network()->site_id );
36 * Generates a random password.
39 * @deprecated 3.0.0 Use wp_generate_password()
40 * @see wp_generate_password()
42 * @param int $len Optional. The length of password to generate. Default 8.
44 function generate_random_password( $len = 8 ) {
45 _deprecated_function( __FUNCTION__, '3.0.0', 'wp_generate_password()' );
46 return wp_generate_password( $len );
50 * Determine if user is a site admin.
52 * Plugins should use is_multisite() instead of checking if this function exists
53 * to determine if multisite is enabled.
55 * This function must reside in a file included only if is_multisite() due to
56 * legacy function_exists() checks to determine if multisite is enabled.
59 * @deprecated 3.0.0 Use is_super_admin()
60 * @see is_super_admin()
62 * @param string $user_login Optional. Username for the user to check. Default empty.
64 function is_site_admin( $user_login = '' ) {
65 _deprecated_function( __FUNCTION__, '3.0.0', 'is_super_admin()' );
67 if ( empty( $user_login ) ) {
68 $user_id = get_current_user_id();
72 $user = get_user_by( 'login', $user_login );
73 if ( ! $user->exists() )
78 return is_super_admin( $user_id );
81 if ( !function_exists( 'graceful_fail' ) ) :
83 * Deprecated functionality to gracefully fail.
86 * @deprecated 3.0.0 Use wp_die()
89 function graceful_fail( $message ) {
90 _deprecated_function( __FUNCTION__, '3.0.0', 'wp_die()' );
91 $message = apply_filters( 'graceful_fail', $message );
92 $message_template = apply_filters( 'graceful_fail_template',
94 <html xmlns="http://www.w3.org/1999/xhtml"><head>
95 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
97 <style type="text/css">
102 line-height: 1.6em; font-family: Georgia, serif; width: 390px; margin: auto;
113 <p class="message">%s</p>
116 die( sprintf( $message_template, $message ) );
121 * Deprecated functionality to retrieve user information.
124 * @deprecated 3.0.0 Use get_user_by()
127 * @param string $username Username.
129 function get_user_details( $username ) {
130 _deprecated_function( __FUNCTION__, '3.0.0', 'get_user_by()' );
131 return get_user_by('login', $username);
135 * Deprecated functionality to clear the global post cache.
138 * @deprecated 3.0.0 Use clean_post_cache()
139 * @see clean_post_cache()
141 * @param int $post_id Post ID.
143 function clear_global_post_cache( $post_id ) {
144 _deprecated_function( __FUNCTION__, '3.0.0', 'clean_post_cache()' );
148 * Deprecated functionality to determin if the current site is the main site.
151 * @deprecated 3.0.0 Use is_main_site()
152 * @see is_main_site()
154 function is_main_blog() {
155 _deprecated_function( __FUNCTION__, '3.0.0', 'is_main_site()' );
156 return is_main_site();
160 * Deprecated functionality to validate an email address.
163 * @deprecated 3.0.0 Use is_email()
166 * @param string $email Email address to verify.
167 * @param bool $check_domain Deprecated.
168 * @return string|bool Either false or the valid email address.
170 function validate_email( $email, $check_domain = true) {
171 _deprecated_function( __FUNCTION__, '3.0.0', 'is_email()' );
172 return is_email( $email, $check_domain );
176 * Deprecated functionality to retrieve a list of all sites.
179 * @deprecated 3.0.0 Use wp_get_sites()
180 * @see wp_get_sites()
182 * @param int $start Optional. Offset for retrieving the blog list. Default 0.
183 * @param int $num Optional. Number of blogs to list. Default 10.
184 * @param string $deprecated Unused.
186 function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) {
187 _deprecated_function( __FUNCTION__, '3.0.0', 'wp_get_sites()' );
190 $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 );
192 $blog_list = array();
193 foreach ( (array) $blogs as $details ) {
194 $blog_list[ $details['blog_id'] ] = $details;
195 $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'" );
198 if ( ! $blog_list ) {
202 if ( $num == 'all' ) {
203 return array_slice( $blog_list, $start, count( $blog_list ) );
205 return array_slice( $blog_list, $start, $num );
210 * Deprecated functionality to retrieve a list of the most active sites.
215 * @param int $num Optional. Number of activate blogs to retrieve. Default 10.
216 * @param bool $display Optional. Whether or not to display the most active blogs list. Default true.
217 * @return array List of "most active" sites.
219 function get_most_active_blogs( $num = 10, $display = true ) {
220 _deprecated_function( __FUNCTION__, '3.0.0' );
222 $blogs = get_blog_list( 0, 'all', false ); // $blog_id -> $details
223 if ( is_array( $blogs ) ) {
225 $most_active = array();
226 $blog_list = array();
227 foreach ( (array) $blogs as $key => $details ) {
228 $most_active[ $details['blog_id'] ] = $details['postcount'];
229 $blog_list[ $details['blog_id'] ] = $details; // array_slice() removes keys!!
231 arsort( $most_active );
232 reset( $most_active );
234 foreach ( (array) $most_active as $key => $details ) {
235 $t[ $key ] = $blog_list[ $key ];
237 unset( $most_active );
242 if ( is_array( $most_active ) ) {
243 reset( $most_active );
244 foreach ( (array) $most_active as $key => $details ) {
245 $url = esc_url('http://' . $details['domain'] . $details['path']);
246 echo '<li>' . $details['postcount'] . " <a href='$url'>$url</a></li>";
250 return array_slice( $most_active, 0, $num );
254 * Redirect a user based on $_GET or $_POST arguments.
256 * The function looks for redirect arguments in the following order:
259 * 3) $_SERVER['HTTP_REFERER']
260 * 4) $_GET['redirect']
261 * 5) $_POST['redirect']
265 * @deprecated 3.3.0 Use wp_redirect()
268 * @param string $url Optional. Redirect URL. Default empty.
270 function wpmu_admin_do_redirect( $url = '' ) {
271 _deprecated_function( __FUNCTION__, '3.3.0' );
274 if ( isset( $_GET['ref'] ) )
276 if ( isset( $_POST['ref'] ) )
277 $ref = $_POST['ref'];
280 $ref = wpmu_admin_redirect_add_updated_param( $ref );
284 if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
285 wp_redirect( $_SERVER['HTTP_REFERER'] );
289 $url = wpmu_admin_redirect_add_updated_param( $url );
290 if ( isset( $_GET['redirect'] ) ) {
291 if ( substr( $_GET['redirect'], 0, 2 ) == 's_' )
292 $url .= '&action=blogs&s='. esc_html( substr( $_GET['redirect'], 2 ) );
293 } elseif ( isset( $_POST['redirect'] ) ) {
294 $url = wpmu_admin_redirect_add_updated_param( $_POST['redirect'] );
301 * Adds an 'updated=true' argument to a URL.
304 * @deprecated 3.3.0 Use add_query_arg()
305 * @see add_query_arg()
307 * @param string $url Optional. Redirect URL. Default empty.
310 function wpmu_admin_redirect_add_updated_param( $url = '' ) {
311 _deprecated_function( __FUNCTION__, '3.3.0' );
313 if ( strpos( $url, 'updated=true' ) === false ) {
314 if ( strpos( $url, '?' ) === false )
315 return $url . '?updated=true';
317 return $url . '&updated=true';
323 * Get a numeric user ID from either an email address or a login.
325 * A numeric string is considered to be an existing user ID
326 * and is simply returned as such.
329 * @deprecated 3.6.0 Use get_user_by()
332 * @param string $string Either an email address or a login.
335 function get_user_id_from_string( $string ) {
336 _deprecated_function( __FUNCTION__, '3.6.0', 'get_user_by()' );
338 if ( is_email( $string ) )
339 $user = get_user_by( 'email', $string );
340 elseif ( is_numeric( $string ) )
343 $user = get_user_by( 'login', $string );
351 * Get a full blog URL, given a domain and a path.
356 * @param string $domain
357 * @param string $path
360 function get_blogaddress_by_domain( $domain, $path ) {
361 _deprecated_function( __FUNCTION__, '3.7.0' );
363 if ( is_subdomain_install() ) {
364 $url = "http://" . $domain.$path;
366 if ( $domain != $_SERVER['HTTP_HOST'] ) {
367 $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
368 $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path;
369 // we're not installing the main blog
370 if ( $blogname != 'www.' )
371 $url .= $blogname . '/';
372 } else { // main blog
373 $url = 'http://' . $domain . $path;
376 return esc_url_raw( $url );
380 * Create an empty blog.
385 * @param string $domain The new blog's domain.
386 * @param string $path The new blog's path.
387 * @param string $weblog_title The new blog's title.
388 * @param int $site_id Optional. Defaults to 1.
389 * @return string|int The ID of the newly created blog
391 function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) {
392 _deprecated_function( __FUNCTION__, '4.4.0' );
397 // Check if the domain has been used already. We should return an error message.
398 if ( domain_exists($domain, $path, $site_id) )
399 return __( '<strong>ERROR</strong>: Site URL already taken.' );
401 // Need to back up wpdb table names, and create a new wp_blogs entry for new blog.
402 // Need to get blog_id from wp_blogs, and create new table names.
403 // Must restore table names at the end of function.
405 if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
406 return __( '<strong>ERROR</strong>: problem creating site entry.' );
408 switch_to_blog($blog_id);
409 install_blog($blog_id);
410 restore_current_blog();
416 * Get the admin for a domain/path combination.
421 * @global wpdb $wpdb WordPress database abstraction object.
423 * @param string $sitedomain Optional. Site domain.
424 * @param string $path Optional. Site path.
425 * @return array|false The network admins
427 function get_admin_users_for_domain( $sitedomain = '', $path = '' ) {
428 _deprecated_function( __FUNCTION__, '4.4.0' );
433 $site_id = $wpdb->siteid;
435 $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) );
438 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 );
444 * Return an array of sites for a network or networks.
450 * @global wpdb $wpdb WordPress database abstraction object.
452 * @param array $args {
453 * Array of default arguments. Optional.
455 * @type int|array $network_id A network ID or array of network IDs. Set to null to retrieve sites
456 * from all networks. Defaults to current network ID.
457 * @type int $public Retrieve public or non-public sites. Default null, for any.
458 * @type int $archived Retrieve archived or non-archived sites. Default null, for any.
459 * @type int $mature Retrieve mature or non-mature sites. Default null, for any.
460 * @type int $spam Retrieve spam or non-spam sites. Default null, for any.
461 * @type int $deleted Retrieve deleted or non-deleted sites. Default null, for any.
462 * @type int $limit Number of sites to limit the query to. Default 100.
463 * @type int $offset Exclude the first x sites. Used in combination with the $limit parameter. Default 0.
465 * @return array An empty array if the install is considered "large" via wp_is_large_network(). Otherwise,
466 * an associative array of site data arrays, each containing the site (network) ID, blog ID,
467 * site domain and path, dates registered and modified, and the language ID. Also, boolean
468 * values for whether the site is public, archived, mature, spam, and/or deleted.
470 function wp_get_sites( $args = array() ) {
473 _deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' );
475 if ( wp_is_large_network() )
479 'network_id' => $wpdb->siteid,
489 $args = wp_parse_args( $args, $defaults );
491 // Backwards compatibility
492 if( is_array( $args['network_id'] ) ){
493 $args['network__in'] = $args['network_id'];
494 $args['network_id'] = null;
497 if( is_numeric( $args['limit'] ) ){
498 $args['number'] = $args['limit'];
499 $args['limit'] = null;
502 // Make sure count is disabled.
503 $args['count'] = false;
505 $_sites = get_sites( $args );
509 foreach ( $_sites as $_site ) {
510 $_site = get_site( $_site );
511 $results[] = $_site->to_array();