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' );
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 function generate_random_password( $len = 8 ) {
42 _deprecated_function( __FUNCTION__, '3.0', 'wp_generate_password()' );
43 return wp_generate_password( $len );
47 * Determine if user is a site admin.
49 * Plugins should use is_multisite() instead of checking if this function exists
50 * to determine if multisite is enabled.
52 * This function must reside in a file included only if is_multisite() due to
53 * legacy function_exists() checks to determine if multisite is enabled.
56 * @deprecated 3.0.0 Use is_super_admin()
57 * @see is_super_admin()
59 function is_site_admin( $user_login = '' ) {
60 _deprecated_function( __FUNCTION__, '3.0', 'is_super_admin()' );
62 if ( empty( $user_login ) ) {
63 $user_id = get_current_user_id();
67 $user = get_user_by( 'login', $user_login );
68 if ( ! $user->exists() )
73 return is_super_admin( $user_id );
76 if ( !function_exists( 'graceful_fail' ) ) :
78 * Deprecated functionality to gracefully fail.
81 * @deprecated 3.0.0 Use wp_die()
84 function graceful_fail( $message ) {
85 _deprecated_function( __FUNCTION__, '3.0', 'wp_die()' );
86 $message = apply_filters( 'graceful_fail', $message );
87 $message_template = apply_filters( 'graceful_fail_template',
89 <html xmlns="http://www.w3.org/1999/xhtml"><head>
90 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
92 <style type="text/css">
97 line-height: 1.6em; font-family: Georgia, serif; width: 390px; margin: auto;
108 <p class="message">%s</p>
111 die( sprintf( $message_template, $message ) );
116 * Deprecated functionality to retrieve user information.
119 * @deprecated 3.0.0 Use get_user_by()
122 function get_user_details( $username ) {
123 _deprecated_function( __FUNCTION__, '3.0', 'get_user_by()' );
124 return get_user_by('login', $username);
128 * Deprecated functionality to clear the global post cache.
131 * @deprecated 3.0.0 Use clean_post_cache()
132 * @see clean_post_cache()
134 function clear_global_post_cache( $post_id ) {
135 _deprecated_function( __FUNCTION__, '3.0', 'clean_post_cache()' );
139 * Deprecated functionality to determin if the current site is the main site.
142 * @deprecated 3.0.0 Use is_main_site()
143 * @see is_main_site()
145 function is_main_blog() {
146 _deprecated_function( __FUNCTION__, '3.0', 'is_main_site()' );
147 return is_main_site();
151 * Deprecated functionality to validate an email address.
154 * @deprecated 3.0.0 Use is_email()
157 function validate_email( $email, $check_domain = true) {
158 _deprecated_function( __FUNCTION__, '3.0', 'is_email()' );
159 return is_email( $email, $check_domain );
163 * Deprecated functionality to retrieve a list of all sites.
166 * @deprecated 3.0.0 Use wp_get_sites()
167 * @see wp_get_sites()
169 function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) {
170 _deprecated_function( __FUNCTION__, '3.0', 'wp_get_sites()' );
173 $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 );
175 $blog_list = array();
176 foreach ( (array) $blogs as $details ) {
177 $blog_list[ $details['blog_id'] ] = $details;
178 $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'" );
181 if ( ! $blog_list ) {
185 if ( $num == 'all' ) {
186 return array_slice( $blog_list, $start, count( $blog_list ) );
188 return array_slice( $blog_list, $start, $num );
193 * Deprecated functionality to retrieve a list of the most active sites.
198 * @return array List of "most active" sites.
200 function get_most_active_blogs( $num = 10, $display = true ) {
201 _deprecated_function( __FUNCTION__, '3.0' );
203 $blogs = get_blog_list( 0, 'all', false ); // $blog_id -> $details
204 if ( is_array( $blogs ) ) {
206 $most_active = array();
207 $blog_list = array();
208 foreach ( (array) $blogs as $key => $details ) {
209 $most_active[ $details['blog_id'] ] = $details['postcount'];
210 $blog_list[ $details['blog_id'] ] = $details; // array_slice() removes keys!!
212 arsort( $most_active );
213 reset( $most_active );
215 foreach ( (array) $most_active as $key => $details ) {
216 $t[ $key ] = $blog_list[ $key ];
218 unset( $most_active );
223 if ( is_array( $most_active ) ) {
224 reset( $most_active );
225 foreach ( (array) $most_active as $key => $details ) {
226 $url = esc_url('http://' . $details['domain'] . $details['path']);
227 echo '<li>' . $details['postcount'] . " <a href='$url'>$url</a></li>";
231 return array_slice( $most_active, 0, $num );
235 * Redirect a user based on $_GET or $_POST arguments.
237 * The function looks for redirect arguments in the following order:
240 * 3) $_SERVER['HTTP_REFERER']
241 * 4) $_GET['redirect']
242 * 5) $_POST['redirect']
246 * @deprecated 3.3.0 Use wp_redirect()
251 function wpmu_admin_do_redirect( $url = '' ) {
252 _deprecated_function( __FUNCTION__, '3.3' );
255 if ( isset( $_GET['ref'] ) )
257 if ( isset( $_POST['ref'] ) )
258 $ref = $_POST['ref'];
261 $ref = wpmu_admin_redirect_add_updated_param( $ref );
265 if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
266 wp_redirect( $_SERVER['HTTP_REFERER'] );
270 $url = wpmu_admin_redirect_add_updated_param( $url );
271 if ( isset( $_GET['redirect'] ) ) {
272 if ( substr( $_GET['redirect'], 0, 2 ) == 's_' )
273 $url .= '&action=blogs&s='. esc_html( substr( $_GET['redirect'], 2 ) );
274 } elseif ( isset( $_POST['redirect'] ) ) {
275 $url = wpmu_admin_redirect_add_updated_param( $_POST['redirect'] );
282 * Adds an 'updated=true' argument to a URL.
285 * @deprecated 3.3.0 Use add_query_arg()
286 * @see add_query_arg()
291 function wpmu_admin_redirect_add_updated_param( $url = '' ) {
292 _deprecated_function( __FUNCTION__, '3.3' );
294 if ( strpos( $url, 'updated=true' ) === false ) {
295 if ( strpos( $url, '?' ) === false )
296 return $url . '?updated=true';
298 return $url . '&updated=true';
304 * Get a numeric user ID from either an email address or a login.
306 * A numeric string is considered to be an existing user ID
307 * and is simply returned as such.
310 * @deprecated 3.6.0 Use get_user_by()
313 * @param string $string Either an email address or a login.
316 function get_user_id_from_string( $string ) {
317 _deprecated_function( __FUNCTION__, '3.6', 'get_user_by()' );
319 if ( is_email( $string ) )
320 $user = get_user_by( 'email', $string );
321 elseif ( is_numeric( $string ) )
324 $user = get_user_by( 'login', $string );
332 * Get a full blog URL, given a domain and a path.
337 * @param string $domain
338 * @param string $path
341 function get_blogaddress_by_domain( $domain, $path ) {
342 _deprecated_function( __FUNCTION__, '3.7' );
344 if ( is_subdomain_install() ) {
345 $url = "http://" . $domain.$path;
347 if ( $domain != $_SERVER['HTTP_HOST'] ) {
348 $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
349 $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path;
350 // we're not installing the main blog
351 if ( $blogname != 'www.' )
352 $url .= $blogname . '/';
353 } else { // main blog
354 $url = 'http://' . $domain . $path;
357 return esc_url_raw( $url );
361 * Create an empty blog.
366 * @param string $domain The new blog's domain.
367 * @param string $path The new blog's path.
368 * @param string $weblog_title The new blog's title.
369 * @param int $site_id Optional. Defaults to 1.
370 * @return string|int The ID of the newly created blog
372 function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) {
373 _deprecated_function( __FUNCTION__, '4.4' );
378 // Check if the domain has been used already. We should return an error message.
379 if ( domain_exists($domain, $path, $site_id) )
380 return __( '<strong>ERROR</strong>: Site URL already taken.' );
382 // Need to back up wpdb table names, and create a new wp_blogs entry for new blog.
383 // Need to get blog_id from wp_blogs, and create new table names.
384 // Must restore table names at the end of function.
386 if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
387 return __( '<strong>ERROR</strong>: problem creating site entry.' );
389 switch_to_blog($blog_id);
390 install_blog($blog_id);
391 restore_current_blog();
397 * Get the admin for a domain/path combination.
402 * @global wpdb $wpdb WordPress database abstraction object.
404 * @param string $sitedomain Optional. Site domain.
405 * @param string $path Optional. Site path.
406 * @return array|false The network admins
408 function get_admin_users_for_domain( $sitedomain = '', $path = '' ) {
409 _deprecated_function( __FUNCTION__, '4.4' );
414 $site_id = $wpdb->siteid;
416 $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) );
419 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 );