author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 18 | be944660c56a |
permissions | -rw-r--r-- |
0 | 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 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* @deprecated 3.1.0 Use get_site() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* @see get_site() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
* @return WP_Site Current site object. |
0 | 25 |
*/ |
26 |
function get_dashboard_blog() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
_deprecated_function( __FUNCTION__, '3.1.0', 'get_site()' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
if ( $blog = get_site_option( 'dashboard_blog' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
return get_site( $blog ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
} |
0 | 31 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
return get_site( get_network()->site_id ); |
0 | 33 |
} |
34 |
||
35 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
* Generates a random password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
* @deprecated 3.0.0 Use wp_generate_password() |
0 | 40 |
* @see wp_generate_password() |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
* @param int $len Optional. The length of password to generate. Default 8. |
0 | 43 |
*/ |
44 |
function generate_random_password( $len = 8 ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
_deprecated_function( __FUNCTION__, '3.0.0', 'wp_generate_password()' ); |
0 | 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 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
* @deprecated 3.0.0 Use is_super_admin() |
0 | 60 |
* @see is_super_admin() |
61 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
* @param string $user_login Optional. Username for the user to check. Default empty. |
0 | 63 |
*/ |
64 |
function is_site_admin( $user_login = '' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
_deprecated_function( __FUNCTION__, '3.0.0', 'is_super_admin()' ); |
0 | 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 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
* Deprecated functionality to gracefully fail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
* @deprecated 3.0.0 Use wp_die() |
0 | 87 |
* @see wp_die() |
88 |
*/ |
|
89 |
function graceful_fail( $message ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
_deprecated_function( __FUNCTION__, '3.0.0', 'wp_die()' ); |
0 | 91 |
$message = apply_filters( 'graceful_fail', $message ); |
92 |
$message_template = apply_filters( 'graceful_fail_template', |
|
93 |
'<!DOCTYPE html> |
|
16 | 94 |
<html><head> |
0 | 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 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
* Deprecated functionality to retrieve user information. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
* @deprecated 3.0.0 Use get_user_by() |
0 | 125 |
* @see get_user_by() |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
* @param string $username Username. |
0 | 128 |
*/ |
129 |
function get_user_details( $username ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
_deprecated_function( __FUNCTION__, '3.0.0', 'get_user_by()' ); |
0 | 131 |
return get_user_by('login', $username); |
132 |
} |
|
133 |
||
134 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
* Deprecated functionality to clear the global post cache. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
* @deprecated 3.0.0 Use clean_post_cache() |
0 | 139 |
* @see clean_post_cache() |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
* @param int $post_id Post ID. |
0 | 142 |
*/ |
143 |
function clear_global_post_cache( $post_id ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
_deprecated_function( __FUNCTION__, '3.0.0', 'clean_post_cache()' ); |
0 | 145 |
} |
146 |
||
147 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
* Deprecated functionality to determin if the current site is the main site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
* @deprecated 3.0.0 Use is_main_site() |
0 | 152 |
* @see is_main_site() |
153 |
*/ |
|
154 |
function is_main_blog() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
_deprecated_function( __FUNCTION__, '3.0.0', 'is_main_site()' ); |
0 | 156 |
return is_main_site(); |
157 |
} |
|
158 |
||
159 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
* Deprecated functionality to validate an email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
* @deprecated 3.0.0 Use is_email() |
0 | 164 |
* @see is_email() |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
* @param string $email Email address to verify. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
* @param bool $check_domain Deprecated. |
16 | 168 |
* @return string|false Valid email address on success, false on failure. |
0 | 169 |
*/ |
170 |
function validate_email( $email, $check_domain = true) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
_deprecated_function( __FUNCTION__, '3.0.0', 'is_email()' ); |
0 | 172 |
return is_email( $email, $check_domain ); |
173 |
} |
|
174 |
||
175 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
* Deprecated functionality to retrieve a list of all sites. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
* @deprecated 3.0.0 Use wp_get_sites() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
* @see wp_get_sites() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
* @param int $start Optional. Offset for retrieving the blog list. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
* @param int $num Optional. Number of blogs to list. Default 10. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
* @param string $deprecated Unused. |
0 | 185 |
*/ |
186 |
function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
_deprecated_function( __FUNCTION__, '3.0.0', 'wp_get_sites()' ); |
0 | 188 |
|
189 |
global $wpdb; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
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", get_current_network_id() ), ARRAY_A ); |
0 | 191 |
|
5 | 192 |
$blog_list = array(); |
0 | 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 |
||
5 | 198 |
if ( ! $blog_list ) { |
0 | 199 |
return array(); |
5 | 200 |
} |
0 | 201 |
|
16 | 202 |
if ( 'all' === $num ) { |
5 | 203 |
return array_slice( $blog_list, $start, count( $blog_list ) ); |
204 |
} else { |
|
205 |
return array_slice( $blog_list, $start, $num ); |
|
206 |
} |
|
0 | 207 |
} |
208 |
||
209 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
* Deprecated functionality to retrieve a list of the most active sites. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
* @since MU (3.0.0) |
0 | 213 |
* @deprecated 3.0.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
* @param int $num Optional. Number of activate blogs to retrieve. Default 10. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
* @param bool $display Optional. Whether or not to display the most active blogs list. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
* @return array List of "most active" sites. |
0 | 218 |
*/ |
219 |
function get_most_active_blogs( $num = 10, $display = true ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
_deprecated_function( __FUNCTION__, '3.0.0' ); |
0 | 221 |
|
222 |
$blogs = get_blog_list( 0, 'all', false ); // $blog_id -> $details |
|
223 |
if ( is_array( $blogs ) ) { |
|
224 |
reset( $blogs ); |
|
5 | 225 |
$most_active = array(); |
226 |
$blog_list = array(); |
|
0 | 227 |
foreach ( (array) $blogs as $key => $details ) { |
228 |
$most_active[ $details['blog_id'] ] = $details['postcount']; |
|
16 | 229 |
$blog_list[ $details['blog_id'] ] = $details; // array_slice() removes keys! |
0 | 230 |
} |
231 |
arsort( $most_active ); |
|
232 |
reset( $most_active ); |
|
5 | 233 |
$t = array(); |
234 |
foreach ( (array) $most_active as $key => $details ) { |
|
0 | 235 |
$t[ $key ] = $blog_list[ $key ]; |
5 | 236 |
} |
0 | 237 |
unset( $most_active ); |
238 |
$most_active = $t; |
|
239 |
} |
|
240 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
if ( $display ) { |
0 | 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 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
* @deprecated 3.3.0 Use wp_redirect() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
* @see wp_redirect() |
0 | 267 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
* @param string $url Optional. Redirect URL. Default empty. |
0 | 269 |
*/ |
270 |
function wpmu_admin_do_redirect( $url = '' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
_deprecated_function( __FUNCTION__, '3.3.0', 'wp_redirect()' ); |
0 | 272 |
|
273 |
$ref = ''; |
|
9 | 274 |
if ( isset( $_GET['ref'] ) && isset( $_POST['ref'] ) && $_GET['ref'] !== $_POST['ref'] ) { |
275 |
wp_die( __( 'A variable mismatch has been detected.' ), __( 'Sorry, you are not allowed to view this item.' ), 400 ); |
|
276 |
} elseif ( isset( $_POST['ref'] ) ) { |
|
16 | 277 |
$ref = $_POST['ref']; |
9 | 278 |
} elseif ( isset( $_GET['ref'] ) ) { |
16 | 279 |
$ref = $_GET['ref']; |
9 | 280 |
} |
0 | 281 |
|
282 |
if ( $ref ) { |
|
283 |
$ref = wpmu_admin_redirect_add_updated_param( $ref ); |
|
284 |
wp_redirect( $ref ); |
|
16 | 285 |
exit; |
0 | 286 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) { |
0 | 288 |
wp_redirect( $_SERVER['HTTP_REFERER'] ); |
16 | 289 |
exit; |
0 | 290 |
} |
291 |
||
292 |
$url = wpmu_admin_redirect_add_updated_param( $url ); |
|
9 | 293 |
if ( isset( $_GET['redirect'] ) && isset( $_POST['redirect'] ) && $_GET['redirect'] !== $_POST['redirect'] ) { |
294 |
wp_die( __( 'A variable mismatch has been detected.' ), __( 'Sorry, you are not allowed to view this item.' ), 400 ); |
|
295 |
} elseif ( isset( $_GET['redirect'] ) ) { |
|
16 | 296 |
if ( 's_' === substr( $_GET['redirect'], 0, 2 ) ) |
0 | 297 |
$url .= '&action=blogs&s='. esc_html( substr( $_GET['redirect'], 2 ) ); |
298 |
} elseif ( isset( $_POST['redirect'] ) ) { |
|
299 |
$url = wpmu_admin_redirect_add_updated_param( $_POST['redirect'] ); |
|
300 |
} |
|
301 |
wp_redirect( $url ); |
|
16 | 302 |
exit; |
0 | 303 |
} |
304 |
||
305 |
/** |
|
306 |
* Adds an 'updated=true' argument to a URL. |
|
307 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
308 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
* @deprecated 3.3.0 Use add_query_arg() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
* @see add_query_arg() |
0 | 311 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
* @param string $url Optional. Redirect URL. Default empty. |
0 | 313 |
* @return string |
314 |
*/ |
|
315 |
function wpmu_admin_redirect_add_updated_param( $url = '' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
_deprecated_function( __FUNCTION__, '3.3.0', 'add_query_arg()' ); |
0 | 317 |
|
318 |
if ( strpos( $url, 'updated=true' ) === false ) { |
|
319 |
if ( strpos( $url, '?' ) === false ) |
|
320 |
return $url . '?updated=true'; |
|
321 |
else |
|
322 |
return $url . '&updated=true'; |
|
323 |
} |
|
324 |
return $url; |
|
325 |
} |
|
326 |
||
327 |
/** |
|
328 |
* Get a numeric user ID from either an email address or a login. |
|
329 |
* |
|
330 |
* A numeric string is considered to be an existing user ID |
|
331 |
* and is simply returned as such. |
|
332 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
* @deprecated 3.6.0 Use get_user_by() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
* @see get_user_by() |
0 | 336 |
* |
337 |
* @param string $string Either an email address or a login. |
|
338 |
* @return int |
|
339 |
*/ |
|
340 |
function get_user_id_from_string( $string ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
_deprecated_function( __FUNCTION__, '3.6.0', 'get_user_by()' ); |
0 | 342 |
|
343 |
if ( is_email( $string ) ) |
|
344 |
$user = get_user_by( 'email', $string ); |
|
345 |
elseif ( is_numeric( $string ) ) |
|
346 |
return $string; |
|
347 |
else |
|
348 |
$user = get_user_by( 'login', $string ); |
|
349 |
||
350 |
if ( $user ) |
|
351 |
return $user->ID; |
|
352 |
return 0; |
|
353 |
} |
|
354 |
||
355 |
/** |
|
356 |
* Get a full blog URL, given a domain and a path. |
|
357 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
* @since MU (3.0.0) |
0 | 359 |
* @deprecated 3.7.0 |
360 |
* |
|
361 |
* @param string $domain |
|
362 |
* @param string $path |
|
363 |
* @return string |
|
364 |
*/ |
|
365 |
function get_blogaddress_by_domain( $domain, $path ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
_deprecated_function( __FUNCTION__, '3.7.0' ); |
0 | 367 |
|
368 |
if ( is_subdomain_install() ) { |
|
369 |
$url = "http://" . $domain.$path; |
|
370 |
} else { |
|
371 |
if ( $domain != $_SERVER['HTTP_HOST'] ) { |
|
372 |
$blogname = substr( $domain, 0, strpos( $domain, '.' ) ); |
|
373 |
$url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path; |
|
16 | 374 |
// We're not installing the main blog. |
375 |
if ( 'www.' !== $blogname ) |
|
0 | 376 |
$url .= $blogname . '/'; |
16 | 377 |
} else { // Main blog. |
0 | 378 |
$url = 'http://' . $domain . $path; |
379 |
} |
|
380 |
} |
|
381 |
return esc_url_raw( $url ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
* Create an empty blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
* @deprecated 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
* @param string $domain The new blog's domain. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
* @param string $path The new blog's path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
* @param string $weblog_title The new blog's title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
* @param int $site_id Optional. Defaults to 1. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
* @return string|int The ID of the newly created blog |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
_deprecated_function( __FUNCTION__, '4.4.0' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
if ( empty($path) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
$path = '/'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
// Check if the domain has been used already. We should return an error message. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
if ( domain_exists($domain, $path, $site_id) ) |
16 | 404 |
return __( '<strong>Error</strong>: Site URL you’ve entered is already taken.' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
|
16 | 406 |
/* |
407 |
* Need to back up wpdb table names, and create a new wp_blogs entry for new blog. |
|
408 |
* Need to get blog_id from wp_blogs, and create new table names. |
|
409 |
* Must restore table names at the end of function. |
|
410 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) |
16 | 413 |
return __( '<strong>Error</strong>: There was a problem creating site entry.' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
switch_to_blog($blog_id); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
install_blog($blog_id); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
restore_current_blog(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
return $blog_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
* Get the admin for a domain/path combination. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
* @deprecated 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
* @param string $domain Optional. Network domain. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
* @param string $path Optional. Network path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
* @return array|false The network admins. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
function get_admin_users_for_domain( $domain = '', $path = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
_deprecated_function( __FUNCTION__, '4.4.0' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
if ( ! $domain ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
$network_id = get_current_network_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
$_networks = get_networks( array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
'fields' => 'ids', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
'number' => 1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
'domain' => $domain, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
'path' => $path, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
$network_id = ! empty( $_networks ) ? array_shift( $_networks ) : 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
if ( $network_id ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
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", $network_id ), ARRAY_A ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
* Return an array of sites for a network or networks. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
460 |
* @since 3.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
* @deprecated 4.6.0 Use get_sites() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
* @see get_sites() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
* Array of default arguments. Optional. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
* @type int|array $network_id A network ID or array of network IDs. Set to null to retrieve sites |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
* from all networks. Defaults to current network ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
* @type int $public Retrieve public or non-public sites. Default null, for any. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
* @type int $archived Retrieve archived or non-archived sites. Default null, for any. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
471 |
* @type int $mature Retrieve mature or non-mature sites. Default null, for any. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
472 |
* @type int $spam Retrieve spam or non-spam sites. Default null, for any. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
* @type int $deleted Retrieve deleted or non-deleted sites. Default null, for any. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
* @type int $limit Number of sites to limit the query to. Default 100. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
* @type int $offset Exclude the first x sites. Used in combination with the $limit parameter. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
* } |
16 | 477 |
* @return array[] An empty array if the installation is considered "large" via wp_is_large_network(). Otherwise, |
478 |
* an associative array of WP_Site data as arrays. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
function wp_get_sites( $args = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
481 |
_deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
if ( wp_is_large_network() ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
return array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
$defaults = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
'network_id' => get_current_network_id(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
'public' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
'archived' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
'mature' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
'spam' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
'deleted' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
'limit' => 100, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
'offset' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
$args = wp_parse_args( $args, $defaults ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
|
16 | 499 |
// Backward compatibility. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
if( is_array( $args['network_id'] ) ){ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
$args['network__in'] = $args['network_id']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
$args['network_id'] = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
if( is_numeric( $args['limit'] ) ){ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
$args['number'] = $args['limit']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
$args['limit'] = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
} elseif ( ! $args['limit'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
$args['number'] = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
$args['limit'] = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
// Make sure count is disabled. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
$args['count'] = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
$_sites = get_sites( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
$results = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
foreach ( $_sites as $_site ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
$_site = get_site( $_site ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
$results[] = $_site->to_array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
return $results; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
* Check whether a usermeta key has to do with the current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
* @deprecated 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
534 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
* @param string $key |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
* @param int $user_id Optional. Defaults to current user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
* @param int $blog_id Optional. Defaults to current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
* @return bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
541 |
function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
544 |
_deprecated_function( __FUNCTION__, '4.9.0' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
$current_user = wp_get_current_user(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
if ( $blog_id == 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
548 |
$blog_id = get_current_blog_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
$local_key = $wpdb->get_blog_prefix( $blog_id ) . $key; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
return isset( $current_user->$local_key ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
553 |
} |
9 | 554 |
|
555 |
/** |
|
556 |
* Store basic site info in the blogs table. |
|
557 |
* |
|
558 |
* This function creates a row in the wp_blogs table and returns |
|
559 |
* the new blog's ID. It is the first step in creating a new blog. |
|
560 |
* |
|
561 |
* @since MU (3.0.0) |
|
562 |
* @deprecated 5.1.0 Use `wp_insert_site()` |
|
563 |
* @see wp_insert_site() |
|
564 |
* |
|
565 |
* @param string $domain The domain of the new site. |
|
566 |
* @param string $path The path of the new site. |
|
567 |
* @param int $site_id Unless you're running a multi-network install, be sure to set this value to 1. |
|
568 |
* @return int|false The ID of the new row |
|
569 |
*/ |
|
570 |
function insert_blog($domain, $path, $site_id) { |
|
571 |
_deprecated_function( __FUNCTION__, '5.1.0', 'wp_insert_site()' ); |
|
572 |
||
573 |
$data = array( |
|
574 |
'domain' => $domain, |
|
575 |
'path' => $path, |
|
576 |
'site_id' => $site_id, |
|
577 |
); |
|
578 |
||
579 |
$site_id = wp_insert_site( $data ); |
|
580 |
if ( is_wp_error( $site_id ) ) { |
|
581 |
return false; |
|
582 |
} |
|
583 |
||
584 |
clean_blog_cache( $site_id ); |
|
585 |
||
586 |
return $site_id; |
|
587 |
} |
|
588 |
||
589 |
/** |
|
590 |
* Install an empty blog. |
|
591 |
* |
|
592 |
* Creates the new blog tables and options. If calling this function |
|
593 |
* directly, be sure to use switch_to_blog() first, so that $wpdb |
|
594 |
* points to the new blog. |
|
595 |
* |
|
596 |
* @since MU (3.0.0) |
|
597 |
* @deprecated 5.1.0 |
|
598 |
* |
|
16 | 599 |
* @global wpdb $wpdb WordPress database abstraction object. |
600 |
* @global WP_Roles $wp_roles WordPress role management object. |
|
9 | 601 |
* |
602 |
* @param int $blog_id The value returned by wp_insert_site(). |
|
603 |
* @param string $blog_title The title of the new site. |
|
604 |
*/ |
|
605 |
function install_blog( $blog_id, $blog_title = '' ) { |
|
606 |
global $wpdb, $wp_roles; |
|
607 |
||
608 |
_deprecated_function( __FUNCTION__, '5.1.0' ); |
|
609 |
||
16 | 610 |
// Cast for security. |
9 | 611 |
$blog_id = (int) $blog_id; |
612 |
||
16 | 613 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
9 | 614 |
|
615 |
$suppress = $wpdb->suppress_errors(); |
|
616 |
if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) { |
|
617 |
die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p></body></html>' ); |
|
618 |
} |
|
619 |
$wpdb->suppress_errors( $suppress ); |
|
620 |
||
621 |
$url = get_blogaddress_by_id( $blog_id ); |
|
622 |
||
16 | 623 |
// Set everything up. |
9 | 624 |
make_db_current_silent( 'blog' ); |
625 |
populate_options(); |
|
626 |
populate_roles(); |
|
627 |
||
628 |
// populate_roles() clears previous role definitions so we start over. |
|
629 |
$wp_roles = new WP_Roles(); |
|
630 |
||
631 |
$siteurl = $home = untrailingslashit( $url ); |
|
632 |
||
633 |
if ( ! is_subdomain_install() ) { |
|
634 |
||
635 |
if ( 'https' === parse_url( get_site_option( 'siteurl' ), PHP_URL_SCHEME ) ) { |
|
636 |
$siteurl = set_url_scheme( $siteurl, 'https' ); |
|
637 |
} |
|
638 |
if ( 'https' === parse_url( get_home_url( get_network()->site_id ), PHP_URL_SCHEME ) ) { |
|
639 |
$home = set_url_scheme( $home, 'https' ); |
|
640 |
} |
|
641 |
} |
|
642 |
||
643 |
update_option( 'siteurl', $siteurl ); |
|
644 |
update_option( 'home', $home ); |
|
645 |
||
646 |
if ( get_site_option( 'ms_files_rewriting' ) ) { |
|
647 |
update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" ); |
|
648 |
} else { |
|
649 |
update_option( 'upload_path', get_blog_option( get_network()->site_id, 'upload_path' ) ); |
|
650 |
} |
|
651 |
||
652 |
update_option( 'blogname', wp_unslash( $blog_title ) ); |
|
653 |
update_option( 'admin_email', '' ); |
|
654 |
||
16 | 655 |
// Remove all permissions. |
9 | 656 |
$table_prefix = $wpdb->get_blog_prefix(); |
16 | 657 |
delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true ); // Delete all. |
658 |
delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // Delete all. |
|
9 | 659 |
} |
660 |
||
661 |
/** |
|
662 |
* Set blog defaults. |
|
663 |
* |
|
664 |
* This function creates a row in the wp_blogs table. |
|
665 |
* |
|
666 |
* @since MU (3.0.0) |
|
667 |
* @deprecated MU |
|
668 |
* @deprecated Use wp_install_defaults() |
|
669 |
* |
|
670 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
671 |
* |
|
672 |
* @param int $blog_id Ignored in this function. |
|
673 |
* @param int $user_id |
|
674 |
*/ |
|
675 |
function install_blog_defaults( $blog_id, $user_id ) { |
|
676 |
global $wpdb; |
|
677 |
||
678 |
_deprecated_function( __FUNCTION__, 'MU' ); |
|
679 |
||
16 | 680 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
9 | 681 |
|
682 |
$suppress = $wpdb->suppress_errors(); |
|
683 |
||
684 |
wp_install_defaults( $user_id ); |
|
685 |
||
686 |
$wpdb->suppress_errors( $suppress ); |
|
687 |
} |
|
16 | 688 |
|
689 |
/** |
|
690 |
* Update the status of a user in the database. |
|
691 |
* |
|
692 |
* Previously used in core to mark a user as spam or "ham" (not spam) in Multisite. |
|
693 |
* |
|
694 |
* @since 3.0.0 |
|
695 |
* @deprecated 5.3.0 Use wp_update_user() |
|
696 |
* @see wp_update_user() |
|
697 |
* |
|
698 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
699 |
* |
|
700 |
* @param int $id The user ID. |
|
701 |
* @param string $pref The column in the wp_users table to update the user's status |
|
702 |
* in (presumably user_status, spam, or deleted). |
|
703 |
* @param int $value The new status for the user. |
|
704 |
* @param null $deprecated Deprecated as of 3.0.2 and should not be used. |
|
705 |
* @return int The initially passed $value. |
|
706 |
*/ |
|
707 |
function update_user_status( $id, $pref, $value, $deprecated = null ) { |
|
708 |
global $wpdb; |
|
709 |
||
710 |
_deprecated_function( __FUNCTION__, '5.3.0', 'wp_update_user()' ); |
|
711 |
||
712 |
if ( null !== $deprecated ) { |
|
713 |
_deprecated_argument( __FUNCTION__, '3.0.2' ); |
|
714 |
} |
|
715 |
||
716 |
$wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) ); |
|
717 |
||
718 |
$user = new WP_User( $id ); |
|
719 |
clean_user_cache( $user ); |
|
720 |
||
721 |
if ( 'spam' === $pref ) { |
|
722 |
if ( $value == 1 ) { |
|
723 |
/** This filter is documented in wp-includes/user.php */ |
|
724 |
do_action( 'make_spam_user', $id ); |
|
725 |
} else { |
|
726 |
/** This filter is documented in wp-includes/user.php */ |
|
727 |
do_action( 'make_ham_user', $id ); |
|
728 |
} |
|
729 |
} |
|
730 |
||
731 |
return $value; |
|
732 |
} |