]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/ms-deprecated.php
WordPress 4.1.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
22  * @see get_blog_details()
23  * @return int
24  */
25 function get_dashboard_blog() {
26     _deprecated_function( __FUNCTION__, '3.1' );
27     if ( $blog = get_site_option( 'dashboard_blog' ) )
28         return get_blog_details( $blog );
29
30     return get_blog_details( $GLOBALS['current_site']->blog_id );
31 }
32
33 /**
34  * @since MU
35  * @deprecated 3.0.0
36  * @deprecated Use wp_generate_password()
37  * @see wp_generate_password()
38  */
39 function generate_random_password( $len = 8 ) {
40         _deprecated_function( __FUNCTION__, '3.0', 'wp_generate_password()' );
41         return wp_generate_password( $len );
42 }
43
44 /**
45  * Determine if user is a site admin.
46  *
47  * Plugins should use is_multisite() instead of checking if this function exists
48  * to determine if multisite is enabled.
49  *
50  * This function must reside in a file included only if is_multisite() due to
51  * legacy function_exists() checks to determine if multisite is enabled.
52  *
53  * @since MU
54  * @deprecated 3.0.0
55  * @deprecated Use is_super_admin()
56  * @see is_super_admin()
57  * @see is_multisite()
58  *
59  */
60 function is_site_admin( $user_login = '' ) {
61         _deprecated_function( __FUNCTION__, '3.0', 'is_super_admin()' );
62
63         if ( empty( $user_login ) ) {
64                 $user_id = get_current_user_id();
65                 if ( !$user_id )
66                         return false;
67         } else {
68                 $user = get_user_by( 'login', $user_login );
69                 if ( ! $user->exists() )
70                         return false;
71                 $user_id = $user->ID;
72         }
73
74         return is_super_admin( $user_id );
75 }
76
77 if ( !function_exists( 'graceful_fail' ) ) :
78 /**
79  * @since MU
80  * @deprecated 3.0.0
81  * @deprecated 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  * @since MU
117  * @deprecated 3.0.0
118  * @deprecated Use get_user_by()
119  * @see get_user_by()
120  */
121 function get_user_details( $username ) {
122         _deprecated_function( __FUNCTION__, '3.0', 'get_user_by()' );
123         return get_user_by('login', $username);
124 }
125
126 /**
127  * @since MU
128  * @deprecated 3.0.0
129  * @deprecated Use clean_post_cache()
130  * @see clean_post_cache()
131  */
132 function clear_global_post_cache( $post_id ) {
133         _deprecated_function( __FUNCTION__, '3.0', 'clean_post_cache()' );
134 }
135
136 /**
137  * @since MU
138  * @deprecated 3.0.0
139  * @deprecated Use is_main_site()
140  * @see is_main_site()
141  */
142 function is_main_blog() {
143         _deprecated_function( __FUNCTION__, '3.0', 'is_main_site()' );
144         return is_main_site();
145 }
146
147 /**
148  * @since MU
149  * @deprecated 3.0.0
150  * @deprecated Use is_email()
151  * @see is_email()
152  */
153 function validate_email( $email, $check_domain = true) {
154         _deprecated_function( __FUNCTION__, '3.0', 'is_email()' );
155         return is_email( $email, $check_domain );
156 }
157
158 /**
159  * @since MU
160  * @deprecated 3.0.0
161  * @deprecated No alternative available. For performance reasons this function is not recommended.
162  */
163 function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) {
164         _deprecated_function( __FUNCTION__, '3.0', 'wp_get_sites()' );
165
166         global $wpdb;
167         $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 );
168
169         foreach ( (array) $blogs as $details ) {
170                 $blog_list[ $details['blog_id'] ] = $details;
171                 $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'" );
172         }
173         unset( $blogs );
174         $blogs = $blog_list;
175
176         if ( false == is_array( $blogs ) )
177                 return array();
178
179         if ( $num == 'all' )
180                 return array_slice( $blogs, $start, count( $blogs ) );
181         else
182                 return array_slice( $blogs, $start, $num );
183 }
184
185 /**
186  * @since MU
187  * @deprecated 3.0.0
188  * @deprecated No alternative available. For performance reasons this function is not recommended.
189  */
190 function get_most_active_blogs( $num = 10, $display = true ) {
191         _deprecated_function( __FUNCTION__, '3.0' );
192
193         $blogs = get_blog_list( 0, 'all', false ); // $blog_id -> $details
194         if ( is_array( $blogs ) ) {
195                 reset( $blogs );
196                 foreach ( (array) $blogs as $key => $details ) {
197                         $most_active[ $details['blog_id'] ] = $details['postcount'];
198                         $blog_list[ $details['blog_id'] ] = $details; // array_slice() removes keys!!
199                 }
200                 arsort( $most_active );
201                 reset( $most_active );
202                 foreach ( (array) $most_active as $key => $details )
203                         $t[ $key ] = $blog_list[ $key ];
204
205                 unset( $most_active );
206                 $most_active = $t;
207         }
208
209         if ( $display == true ) {
210                 if ( is_array( $most_active ) ) {
211                         reset( $most_active );
212                         foreach ( (array) $most_active as $key => $details ) {
213                                 $url = esc_url('http://' . $details['domain'] . $details['path']);
214                                 echo '<li>' . $details['postcount'] . " <a href='$url'>$url</a></li>";
215                         }
216                 }
217         }
218         return array_slice( $most_active, 0, $num );
219 }
220
221 /**
222  * Redirect a user based on $_GET or $_POST arguments.
223  *
224  * The function looks for redirect arguments in the following order:
225  * 1) $_GET['ref']
226  * 2) $_POST['ref']
227  * 3) $_SERVER['HTTP_REFERER']
228  * 4) $_GET['redirect']
229  * 5) $_POST['redirect']
230  * 6) $url
231  *
232  * @since MU
233  * @deprecated 3.3.0
234  * @deprecated Use wp_redirect()
235  *
236  * @param string $url
237  */
238 function wpmu_admin_do_redirect( $url = '' ) {
239         _deprecated_function( __FUNCTION__, '3.3' );
240
241         $ref = '';
242         if ( isset( $_GET['ref'] ) )
243                 $ref = $_GET['ref'];
244         if ( isset( $_POST['ref'] ) )
245                 $ref = $_POST['ref'];
246
247         if ( $ref ) {
248                 $ref = wpmu_admin_redirect_add_updated_param( $ref );
249                 wp_redirect( $ref );
250                 exit();
251         }
252         if ( empty( $_SERVER['HTTP_REFERER'] ) == false ) {
253                 wp_redirect( $_SERVER['HTTP_REFERER'] );
254                 exit();
255         }
256
257         $url = wpmu_admin_redirect_add_updated_param( $url );
258         if ( isset( $_GET['redirect'] ) ) {
259                 if ( substr( $_GET['redirect'], 0, 2 ) == 's_' )
260                         $url .= '&action=blogs&s='. esc_html( substr( $_GET['redirect'], 2 ) );
261         } elseif ( isset( $_POST['redirect'] ) ) {
262                 $url = wpmu_admin_redirect_add_updated_param( $_POST['redirect'] );
263         }
264         wp_redirect( $url );
265         exit();
266 }
267
268 /**
269  * Adds an 'updated=true' argument to a URL.
270  *
271  * @since MU
272  * @deprecated 3.3.0
273  * @deprecated Use add_query_arg()
274  *
275  * @param string $url
276  * @return string
277  */
278 function wpmu_admin_redirect_add_updated_param( $url = '' ) {
279         _deprecated_function( __FUNCTION__, '3.3' );
280
281         if ( strpos( $url, 'updated=true' ) === false ) {
282                 if ( strpos( $url, '?' ) === false )
283                         return $url . '?updated=true';
284                 else
285                         return $url . '&updated=true';
286         }
287         return $url;
288 }
289
290 /**
291  * Get a numeric user ID from either an email address or a login.
292  *
293  * A numeric string is considered to be an existing user ID
294  * and is simply returned as such.
295  *
296  * @since MU
297  * @deprecated 3.6.0
298  * @deprecated Use get_user_by()
299  *
300  * @param string $string Either an email address or a login.
301  * @return int
302  */
303 function get_user_id_from_string( $string ) {
304         _deprecated_function( __FUNCTION__, '3.6', 'get_user_by()' );
305
306         if ( is_email( $string ) )
307                 $user = get_user_by( 'email', $string );
308         elseif ( is_numeric( $string ) )
309                 return $string;
310         else
311                 $user = get_user_by( 'login', $string );
312
313         if ( $user )
314                 return $user->ID;
315         return 0;
316 }
317
318 /**
319  * Get a full blog URL, given a domain and a path.
320  *
321  * @since MU
322  * @deprecated 3.7.0
323  *
324  * @param string $domain
325  * @param string $path
326  * @return string
327  */
328 function get_blogaddress_by_domain( $domain, $path ) {
329         _deprecated_function( __FUNCTION__, '3.7' );
330
331         if ( is_subdomain_install() ) {
332                 $url = "http://" . $domain.$path;
333         } else {
334                 if ( $domain != $_SERVER['HTTP_HOST'] ) {
335                         $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
336                         $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path;
337                         // we're not installing the main blog
338                         if ( $blogname != 'www.' )
339                                 $url .= $blogname . '/';
340                 } else { // main blog
341                         $url = 'http://' . $domain . $path;
342                 }
343         }
344         return esc_url_raw( $url );
345 }