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