]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/ms-deprecated.php
WordPress 4.7.2
[autoinstalls/wordpress.git] / wp-includes / ms-deprecated.php
1 <?php
2 /**
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.
6  *
7  * @package WordPress
8  * @subpackage Deprecated
9  * @since 3.0.0
10  */
11
12 /*
13  * Deprecated functions come here to die.
14  */
15
16 /**
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.
19  *
20  * @since MU
21  * @deprecated 3.1.0 Use get_site()
22  * @see get_site()
23  *
24  * @return WP_Site Current site object.
25  */
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 );
30     }
31
32     return get_site( get_network()->site_id );
33 }
34
35 /**
36  * Generates a random password.
37  *
38  * @since MU
39  * @deprecated 3.0.0 Use wp_generate_password()
40  * @see wp_generate_password()
41  *
42  * @param int $len Optional. The length of password to generate. Default 8.
43  */
44 function generate_random_password( $len = 8 ) {
45         _deprecated_function( __FUNCTION__, '3.0.0', 'wp_generate_password()' );
46         return wp_generate_password( $len );
47 }
48
49 /**
50  * Determine if user is a site admin.
51  *
52  * Plugins should use is_multisite() instead of checking if this function exists
53  * to determine if multisite is enabled.
54  *
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.
57  *
58  * @since MU
59  * @deprecated 3.0.0 Use is_super_admin()
60  * @see is_super_admin()
61  *
62  * @param string $user_login Optional. Username for the user to check. Default empty.
63  */
64 function is_site_admin( $user_login = '' ) {
65         _deprecated_function( __FUNCTION__, '3.0.0', 'is_super_admin()' );
66
67         if ( empty( $user_login ) ) {
68                 $user_id = get_current_user_id();
69                 if ( !$user_id )
70                         return false;
71         } else {
72                 $user = get_user_by( 'login', $user_login );
73                 if ( ! $user->exists() )
74                         return false;
75                 $user_id = $user->ID;
76         }
77
78         return is_super_admin( $user_id );
79 }
80
81 if ( !function_exists( 'graceful_fail' ) ) :
82 /**
83  * Deprecated functionality to gracefully fail.
84  *
85  * @since MU
86  * @deprecated 3.0.0 Use wp_die()
87  * @see wp_die()
88  */
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',
93 '<!DOCTYPE html>
94 <html xmlns="http://www.w3.org/1999/xhtml"><head>
95 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
96 <title>Error!</title>
97 <style type="text/css">
98 img {
99         border: 0;
100 }
101 body {
102 line-height: 1.6em; font-family: Georgia, serif; width: 390px; margin: auto;
103 text-align: center;
104 }
105 .message {
106         font-size: 22px;
107         width: 350px;
108         margin: auto;
109 }
110 </style>
111 </head>
112 <body>
113 <p class="message">%s</p>
114 </body>
115 </html>' );
116         die( sprintf( $message_template, $message ) );
117 }
118 endif;
119
120 /**
121  * Deprecated functionality to retrieve user information.
122  *
123  * @since MU
124  * @deprecated 3.0.0 Use get_user_by()
125  * @see get_user_by()
126  *
127  * @param string $username Username.
128  */
129 function get_user_details( $username ) {
130         _deprecated_function( __FUNCTION__, '3.0.0', 'get_user_by()' );
131         return get_user_by('login', $username);
132 }
133
134 /**
135  * Deprecated functionality to clear the global post cache.
136  *
137  * @since MU
138  * @deprecated 3.0.0 Use clean_post_cache()
139  * @see clean_post_cache()
140  *
141  * @param int $post_id Post ID.
142  */
143 function clear_global_post_cache( $post_id ) {
144         _deprecated_function( __FUNCTION__, '3.0.0', 'clean_post_cache()' );
145 }
146
147 /**
148  * Deprecated functionality to determin if the current site is the main site.
149  *
150  * @since MU
151  * @deprecated 3.0.0 Use is_main_site()
152  * @see is_main_site()
153  */
154 function is_main_blog() {
155         _deprecated_function( __FUNCTION__, '3.0.0', 'is_main_site()' );
156         return is_main_site();
157 }
158
159 /**
160  * Deprecated functionality to validate an email address.
161  *
162  * @since MU
163  * @deprecated 3.0.0 Use is_email()
164  * @see is_email()
165  *
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.
169  */
170 function validate_email( $email, $check_domain = true) {
171         _deprecated_function( __FUNCTION__, '3.0.0', 'is_email()' );
172         return is_email( $email, $check_domain );
173 }
174
175 /**
176  * Deprecated functionality to retrieve a list of all sites.
177  *
178  * @since MU
179  * @deprecated 3.0.0 Use wp_get_sites()
180  * @see wp_get_sites()
181  *
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.
185  */
186 function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) {
187         _deprecated_function( __FUNCTION__, '3.0.0', 'wp_get_sites()' );
188
189         global $wpdb;
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 );
191
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'" );
196         }
197
198         if ( ! $blog_list ) {
199                 return array();
200         }
201
202         if ( $num == 'all' ) {
203                 return array_slice( $blog_list, $start, count( $blog_list ) );
204         } else {
205                 return array_slice( $blog_list, $start, $num );
206         }
207 }
208
209 /**
210  * Deprecated functionality to retrieve a list of the most active sites.
211  *
212  * @since MU
213  * @deprecated 3.0.0
214  *
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.
218  */
219 function get_most_active_blogs( $num = 10, $display = true ) {
220         _deprecated_function( __FUNCTION__, '3.0.0' );
221
222         $blogs = get_blog_list( 0, 'all', false ); // $blog_id -> $details
223         if ( is_array( $blogs ) ) {
224                 reset( $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!!
230                 }
231                 arsort( $most_active );
232                 reset( $most_active );
233                 $t = array();
234                 foreach ( (array) $most_active as $key => $details ) {
235                         $t[ $key ] = $blog_list[ $key ];
236                 }
237                 unset( $most_active );
238                 $most_active = $t;
239         }
240
241         if ( $display ) {
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>";
247                         }
248                 }
249         }
250         return array_slice( $most_active, 0, $num );
251 }
252
253 /**
254  * Redirect a user based on $_GET or $_POST arguments.
255  *
256  * The function looks for redirect arguments in the following order:
257  * 1) $_GET['ref']
258  * 2) $_POST['ref']
259  * 3) $_SERVER['HTTP_REFERER']
260  * 4) $_GET['redirect']
261  * 5) $_POST['redirect']
262  * 6) $url
263  *
264  * @since MU
265  * @deprecated 3.3.0 Use wp_redirect()
266  * @see wp_redirect()
267  *
268  * @param string $url Optional. Redirect URL. Default empty.
269  */
270 function wpmu_admin_do_redirect( $url = '' ) {
271         _deprecated_function( __FUNCTION__, '3.3.0' );
272
273         $ref = '';
274         if ( isset( $_GET['ref'] ) )
275                 $ref = $_GET['ref'];
276         if ( isset( $_POST['ref'] ) )
277                 $ref = $_POST['ref'];
278
279         if ( $ref ) {
280                 $ref = wpmu_admin_redirect_add_updated_param( $ref );
281                 wp_redirect( $ref );
282                 exit();
283         }
284         if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
285                 wp_redirect( $_SERVER['HTTP_REFERER'] );
286                 exit();
287         }
288
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'] );
295         }
296         wp_redirect( $url );
297         exit();
298 }
299
300 /**
301  * Adds an 'updated=true' argument to a URL.
302  *
303  * @since MU
304  * @deprecated 3.3.0 Use add_query_arg()
305  * @see add_query_arg()
306  *
307  * @param string $url Optional. Redirect URL. Default empty.
308  * @return string
309  */
310 function wpmu_admin_redirect_add_updated_param( $url = '' ) {
311         _deprecated_function( __FUNCTION__, '3.3.0' );
312
313         if ( strpos( $url, 'updated=true' ) === false ) {
314                 if ( strpos( $url, '?' ) === false )
315                         return $url . '?updated=true';
316                 else
317                         return $url . '&updated=true';
318         }
319         return $url;
320 }
321
322 /**
323  * Get a numeric user ID from either an email address or a login.
324  *
325  * A numeric string is considered to be an existing user ID
326  * and is simply returned as such.
327  *
328  * @since MU
329  * @deprecated 3.6.0 Use get_user_by()
330  * @see get_user_by()
331  *
332  * @param string $string Either an email address or a login.
333  * @return int
334  */
335 function get_user_id_from_string( $string ) {
336         _deprecated_function( __FUNCTION__, '3.6.0', 'get_user_by()' );
337
338         if ( is_email( $string ) )
339                 $user = get_user_by( 'email', $string );
340         elseif ( is_numeric( $string ) )
341                 return $string;
342         else
343                 $user = get_user_by( 'login', $string );
344
345         if ( $user )
346                 return $user->ID;
347         return 0;
348 }
349
350 /**
351  * Get a full blog URL, given a domain and a path.
352  *
353  * @since MU
354  * @deprecated 3.7.0
355  *
356  * @param string $domain
357  * @param string $path
358  * @return string
359  */
360 function get_blogaddress_by_domain( $domain, $path ) {
361         _deprecated_function( __FUNCTION__, '3.7.0' );
362
363         if ( is_subdomain_install() ) {
364                 $url = "http://" . $domain.$path;
365         } else {
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;
374                 }
375         }
376         return esc_url_raw( $url );
377 }
378
379 /**
380  * Create an empty blog.
381  *
382  * @since MU 1.0
383  * @deprecated 4.4.0
384  *
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
390  */
391 function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) {
392         _deprecated_function( __FUNCTION__, '4.4.0' );
393
394         if ( empty($path) )
395                 $path = '/';
396
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.' );
400
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.
404
405         if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
406                 return __( '<strong>ERROR</strong>: problem creating site entry.' );
407
408         switch_to_blog($blog_id);
409         install_blog($blog_id);
410         restore_current_blog();
411
412         return $blog_id;
413 }
414
415 /**
416  * Get the admin for a domain/path combination.
417  *
418  * @since MU 1.0
419  * @deprecated 4.4.0
420  *
421  * @global wpdb $wpdb WordPress database abstraction object.
422  *
423  * @param string $sitedomain Optional. Site domain.
424  * @param string $path       Optional. Site path.
425  * @return array|false The network admins
426  */
427 function get_admin_users_for_domain( $sitedomain = '', $path = '' ) {
428         _deprecated_function( __FUNCTION__, '4.4.0' );
429
430         global $wpdb;
431
432         if ( ! $sitedomain )
433                 $site_id = $wpdb->siteid;
434         else
435                 $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) );
436
437         if ( $site_id )
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 );
439
440         return false;
441 }
442
443 /**
444  * Return an array of sites for a network or networks.
445  *
446  * @since 3.7.0
447  * @deprecated 4.6.0
448  * @see get_sites()
449  *
450  * @global wpdb $wpdb WordPress database abstraction object.
451  *
452  * @param array $args {
453  *     Array of default arguments. Optional.
454  *
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.
464  * }
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.
469  */
470 function wp_get_sites( $args = array() ) {
471         global $wpdb;
472
473         _deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' );
474
475         if ( wp_is_large_network() )
476                 return array();
477
478         $defaults = array(
479                 'network_id' => $wpdb->siteid,
480                 'public'     => null,
481                 'archived'   => null,
482                 'mature'     => null,
483                 'spam'       => null,
484                 'deleted'    => null,
485                 'limit'      => 100,
486                 'offset'     => 0,
487         );
488
489         $args = wp_parse_args( $args, $defaults );
490
491         // Backwards compatibility
492         if( is_array( $args['network_id'] ) ){
493                 $args['network__in'] = $args['network_id'];
494                 $args['network_id'] = null;
495         }
496
497         if( is_numeric( $args['limit'] ) ){
498                 $args['number'] = $args['limit'];
499                 $args['limit'] = null;
500         }
501
502         // Make sure count is disabled.
503         $args['count'] = false;
504
505         $_sites  = get_sites( $args );
506
507         $results = array();
508
509         foreach ( $_sites as $_site ) {
510                 $_site = get_site( $_site );
511                 $results[] = $_site->to_array();
512         }
513
514         return $results;
515 }