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