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 |
* Multisite WordPress API |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Multisite |
|
7 |
* @since 3.0.0 |
|
8 |
*/ |
|
9 |
||
10 |
/** |
|
11 |
* Gets the network's site and user counts. |
|
12 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
* @since MU (3.0.0) |
0 | 14 |
* |
16 | 15 |
* @return int[] { |
16 |
* Site and user count for the network. |
|
17 |
* |
|
18 |
* @type int $blogs Number of sites on the network. |
|
19 |
* @type int $users Number of users on the network. |
|
20 |
* } |
|
0 | 21 |
*/ |
22 |
function get_sitestats() { |
|
23 |
$stats = array( |
|
24 |
'blogs' => get_blog_count(), |
|
25 |
'users' => get_user_count(), |
|
26 |
); |
|
27 |
||
28 |
return $stats; |
|
29 |
} |
|
30 |
||
31 |
/** |
|
32 |
* Get one of a user's active blogs |
|
33 |
* |
|
5 | 34 |
* Returns the user's primary blog, if they have one and |
0 | 35 |
* it is active. If it's inactive, function returns another |
36 |
* active blog of the user. If none are found, the user |
|
37 |
* is added as a Subscriber to the Dashboard Blog and that blog |
|
38 |
* is returned. |
|
39 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
* @since MU (3.0.0) |
0 | 41 |
* |
42 |
* @param int $user_id The unique ID of the user |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
* @return WP_Site|void The blog object |
0 | 44 |
*/ |
45 |
function get_active_blog_for_user( $user_id ) { |
|
46 |
$blogs = get_blogs_of_user( $user_id ); |
|
9 | 47 |
if ( empty( $blogs ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
return; |
9 | 49 |
} |
0 | 50 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
if ( ! is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
return $blogs[ get_current_blog_id() ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
} |
0 | 54 |
|
55 |
$primary_blog = get_user_meta( $user_id, 'primary_blog', true ); |
|
9 | 56 |
$first_blog = current( $blogs ); |
0 | 57 |
if ( false !== $primary_blog ) { |
58 |
if ( ! isset( $blogs[ $primary_blog ] ) ) { |
|
59 |
update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
$primary = get_site( $first_blog->userblog_id ); |
0 | 61 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
$primary = get_site( $primary_blog ); |
0 | 63 |
} |
64 |
} else { |
|
16 | 65 |
// TODO: Review this call to add_user_to_blog too - to get here the user must have a role on this blog? |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
$result = add_user_to_blog( $first_blog->userblog_id, $user_id, 'subscriber' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
if ( ! is_wp_error( $result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
$primary = $first_blog; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
} |
0 | 72 |
} |
73 |
||
16 | 74 |
if ( ( ! is_object( $primary ) ) || ( 1 == $primary->archived || 1 == $primary->spam || 1 == $primary->deleted ) ) { |
75 |
$blogs = get_blogs_of_user( $user_id, true ); // If a user's primary blog is shut down, check their other blogs. |
|
9 | 76 |
$ret = false; |
0 | 77 |
if ( is_array( $blogs ) && count( $blogs ) > 0 ) { |
78 |
foreach ( (array) $blogs as $blog_id => $blog ) { |
|
16 | 79 |
if ( get_current_network_id() != $blog->site_id ) { |
0 | 80 |
continue; |
9 | 81 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
$details = get_site( $blog_id ); |
16 | 83 |
if ( is_object( $details ) && 0 == $details->archived && 0 == $details->spam && 0 == $details->deleted ) { |
9 | 84 |
$ret = $details; |
85 |
if ( get_user_meta( $user_id, 'primary_blog', true ) != $blog_id ) { |
|
0 | 86 |
update_user_meta( $user_id, 'primary_blog', $blog_id ); |
9 | 87 |
} |
88 |
if ( ! get_user_meta( $user_id, 'source_domain', true ) ) { |
|
89 |
update_user_meta( $user_id, 'source_domain', $details->domain ); |
|
90 |
} |
|
0 | 91 |
break; |
92 |
} |
|
93 |
} |
|
94 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
return; |
0 | 96 |
} |
97 |
return $ret; |
|
98 |
} else { |
|
99 |
return $primary; |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
/** |
|
104 |
* The number of active users in your installation. |
|
105 |
* |
|
106 |
* The count is cached and updated twice daily. This is not a live count. |
|
107 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
* @since MU (3.0.0) |
9 | 109 |
* @since 4.8.0 The `$network_id` parameter has been added. |
0 | 110 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
* @param int|null $network_id ID of the network. Default is the current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
* @return int Number of active users on the network. |
0 | 113 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
function get_user_count( $network_id = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
return get_network_option( $network_id, 'user_count' ); |
0 | 116 |
} |
117 |
||
118 |
/** |
|
119 |
* The number of active sites on your installation. |
|
120 |
* |
|
121 |
* The count is cached and updated twice daily. This is not a live count. |
|
122 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
* @since MU (3.0.0) |
9 | 124 |
* @since 3.7.0 The `$network_id` parameter has been deprecated. |
125 |
* @since 4.8.0 The `$network_id` parameter is now being used. |
|
0 | 126 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
* @param int|null $network_id ID of the network. Default is the current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
* @return int Number of active sites on the network. |
0 | 129 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
function get_blog_count( $network_id = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
return get_network_option( $network_id, 'blog_count' ); |
0 | 132 |
} |
133 |
||
134 |
/** |
|
16 | 135 |
* Gets a blog post from any site on the network. |
136 |
* |
|
137 |
* This function is similar to get_post(), except that it can retrieve a post |
|
138 |
* from any site on the network, not just the current site. |
|
0 | 139 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
* @since MU (3.0.0) |
0 | 141 |
* |
142 |
* @param int $blog_id ID of the blog. |
|
16 | 143 |
* @param int $post_id ID of the post being looked for. |
144 |
* @return WP_Post|null WP_Post object on success, null on failure |
|
0 | 145 |
*/ |
146 |
function get_blog_post( $blog_id, $post_id ) { |
|
147 |
switch_to_blog( $blog_id ); |
|
148 |
$post = get_post( $post_id ); |
|
149 |
restore_current_blog(); |
|
150 |
||
151 |
return $post; |
|
152 |
} |
|
153 |
||
154 |
/** |
|
16 | 155 |
* Adds a user to a blog, along with specifying the user's role. |
0 | 156 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
* Use the {@see 'add_user_to_blog'} action to fire an event when users are added to a blog. |
0 | 158 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
* @since MU (3.0.0) |
0 | 160 |
* |
16 | 161 |
* @param int $blog_id ID of the blog the user is being added to. |
162 |
* @param int $user_id ID of the user being added. |
|
163 |
* @param string $role The role you want the user to have. |
|
164 |
* @return true|WP_Error True on success or a WP_Error object if the user doesn't exist |
|
165 |
* or could not be added. |
|
0 | 166 |
*/ |
167 |
function add_user_to_blog( $blog_id, $user_id, $role ) { |
|
9 | 168 |
switch_to_blog( $blog_id ); |
0 | 169 |
|
170 |
$user = get_userdata( $user_id ); |
|
171 |
||
172 |
if ( ! $user ) { |
|
173 |
restore_current_blog(); |
|
174 |
return new WP_Error( 'user_does_not_exist', __( 'The requested user does not exist.' ) ); |
|
175 |
} |
|
176 |
||
7
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 |
* Filters whether a user should be added to a site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
* |
16 | 182 |
* @param true|WP_Error $retval True if the user should be added to the site, error |
183 |
* object otherwise. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
* @param string $role User role. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
* @param int $blog_id Site ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
$can_add_user = apply_filters( 'can_add_user_to_blog', true, $user_id, $role, $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
if ( true !== $can_add_user ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
restore_current_blog(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
if ( is_wp_error( $can_add_user ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
return $can_add_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
196 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
return new WP_Error( 'user_cannot_be_added', __( 'User cannot be added to this site.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
|
9 | 200 |
if ( ! get_user_meta( $user_id, 'primary_blog', true ) ) { |
201 |
update_user_meta( $user_id, 'primary_blog', $blog_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
$site = get_site( $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
update_user_meta( $user_id, 'source_domain', $site->domain ); |
0 | 204 |
} |
205 |
||
9 | 206 |
$user->set_role( $role ); |
0 | 207 |
|
5 | 208 |
/** |
209 |
* Fires immediately after a user is added to a site. |
|
210 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
* @since MU (3.0.0) |
5 | 212 |
* |
213 |
* @param int $user_id User ID. |
|
214 |
* @param string $role User role. |
|
215 |
* @param int $blog_id Blog ID. |
|
216 |
*/ |
|
217 |
do_action( 'add_user_to_blog', $user_id, $role, $blog_id ); |
|
16 | 218 |
|
219 |
clean_user_cache( $user_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
wp_cache_delete( $blog_id . '_user_count', 'blog-details' ); |
16 | 221 |
|
0 | 222 |
restore_current_blog(); |
16 | 223 |
|
0 | 224 |
return true; |
225 |
} |
|
226 |
||
227 |
/** |
|
228 |
* Remove a user from a blog. |
|
229 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
230 |
* Use the {@see 'remove_user_from_blog'} action to fire an event when |
0 | 231 |
* users are removed from a blog. |
232 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
* Accepts an optional `$reassign` parameter, if you want to |
0 | 234 |
* reassign the user's blog posts to another user upon removal. |
235 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 239 |
* |
16 | 240 |
* @param int $user_id ID of the user being removed. |
241 |
* @param int $blog_id Optional. ID of the blog the user is being removed from. Default 0. |
|
242 |
* @param int $reassign Optional. ID of the user to whom to reassign posts. Default 0. |
|
243 |
* @return true|WP_Error True on success or a WP_Error object if the user doesn't exist. |
|
0 | 244 |
*/ |
16 | 245 |
function remove_user_from_blog( $user_id, $blog_id = 0, $reassign = 0 ) { |
0 | 246 |
global $wpdb; |
16 | 247 |
|
9 | 248 |
switch_to_blog( $blog_id ); |
0 | 249 |
$user_id = (int) $user_id; |
16 | 250 |
|
5 | 251 |
/** |
252 |
* Fires before a user is removed from a site. |
|
253 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
* @since MU (3.0.0) |
16 | 255 |
* @since 5.4.0 Added the `$reassign` parameter. |
5 | 256 |
* |
16 | 257 |
* @param int $user_id ID of the user being removed. |
258 |
* @param int $blog_id ID of the blog the user is being removed from. |
|
259 |
* @param int $reassign ID of the user to whom to reassign posts. |
|
5 | 260 |
*/ |
16 | 261 |
do_action( 'remove_user_from_blog', $user_id, $blog_id, $reassign ); |
0 | 262 |
|
16 | 263 |
// If being removed from the primary blog, set a new primary |
264 |
// if the user is assigned to multiple blogs. |
|
9 | 265 |
$primary_blog = get_user_meta( $user_id, 'primary_blog', true ); |
0 | 266 |
if ( $primary_blog == $blog_id ) { |
9 | 267 |
$new_id = ''; |
0 | 268 |
$new_domain = ''; |
9 | 269 |
$blogs = get_blogs_of_user( $user_id ); |
0 | 270 |
foreach ( (array) $blogs as $blog ) { |
9 | 271 |
if ( $blog->userblog_id == $blog_id ) { |
0 | 272 |
continue; |
9 | 273 |
} |
274 |
$new_id = $blog->userblog_id; |
|
0 | 275 |
$new_domain = $blog->domain; |
276 |
break; |
|
277 |
} |
|
278 |
||
9 | 279 |
update_user_meta( $user_id, 'primary_blog', $new_id ); |
280 |
update_user_meta( $user_id, 'source_domain', $new_domain ); |
|
0 | 281 |
} |
282 |
||
16 | 283 |
// wp_revoke_user( $user_id ); |
0 | 284 |
$user = get_userdata( $user_id ); |
285 |
if ( ! $user ) { |
|
286 |
restore_current_blog(); |
|
9 | 287 |
return new WP_Error( 'user_does_not_exist', __( 'That user does not exist.' ) ); |
0 | 288 |
} |
289 |
||
290 |
$user->remove_all_caps(); |
|
291 |
||
9 | 292 |
$blogs = get_blogs_of_user( $user_id ); |
293 |
if ( count( $blogs ) == 0 ) { |
|
294 |
update_user_meta( $user_id, 'primary_blog', '' ); |
|
295 |
update_user_meta( $user_id, 'source_domain', '' ); |
|
0 | 296 |
} |
297 |
||
16 | 298 |
if ( $reassign ) { |
0 | 299 |
$reassign = (int) $reassign; |
5 | 300 |
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $user_id ) ); |
301 |
$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $user_id ) ); |
|
302 |
||
303 |
if ( ! empty( $post_ids ) ) { |
|
304 |
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id ) ); |
|
305 |
array_walk( $post_ids, 'clean_post_cache' ); |
|
306 |
} |
|
307 |
||
308 |
if ( ! empty( $link_ids ) ) { |
|
309 |
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id ) ); |
|
310 |
array_walk( $link_ids, 'clean_bookmark_cache' ); |
|
311 |
} |
|
0 | 312 |
} |
313 |
||
314 |
restore_current_blog(); |
|
315 |
||
316 |
return true; |
|
317 |
} |
|
318 |
||
319 |
/** |
|
320 |
* Get the permalink for a post on another blog. |
|
321 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
* @since MU (3.0.0) 1.0 |
0 | 323 |
* |
324 |
* @param int $blog_id ID of the source blog. |
|
325 |
* @param int $post_id ID of the desired post. |
|
326 |
* @return string The post's permalink |
|
327 |
*/ |
|
328 |
function get_blog_permalink( $blog_id, $post_id ) { |
|
329 |
switch_to_blog( $blog_id ); |
|
330 |
$link = get_permalink( $post_id ); |
|
331 |
restore_current_blog(); |
|
332 |
||
333 |
return $link; |
|
334 |
} |
|
335 |
||
336 |
/** |
|
337 |
* Get a blog's numeric ID from its URL. |
|
338 |
* |
|
339 |
* On a subdirectory installation like example.com/blog1/, |
|
340 |
* $domain will be the root 'example.com' and $path the |
|
341 |
* subdirectory '/blog1/'. With subdomains like blog1.example.com, |
|
342 |
* $domain is 'blog1.example.com' and $path is '/'. |
|
343 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 347 |
* |
348 |
* @param string $domain |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
* @param string $path Optional. Not required for subdomain installations. |
0 | 350 |
* @return int 0 if no blog found, otherwise the ID of the matching blog |
351 |
*/ |
|
352 |
function get_blog_id_from_url( $domain, $path = '/' ) { |
|
353 |
$domain = strtolower( $domain ); |
|
9 | 354 |
$path = strtolower( $path ); |
355 |
$id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' ); |
|
0 | 356 |
|
16 | 357 |
if ( -1 == $id ) { // Blog does not exist. |
0 | 358 |
return 0; |
9 | 359 |
} elseif ( $id ) { |
0 | 360 |
return (int) $id; |
9 | 361 |
} |
0 | 362 |
|
9 | 363 |
$args = array( |
364 |
'domain' => $domain, |
|
365 |
'path' => $path, |
|
366 |
'fields' => 'ids', |
|
367 |
'number' => 1, |
|
368 |
'update_site_meta_cache' => false, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
$result = get_sites( $args ); |
9 | 371 |
$id = array_shift( $result ); |
0 | 372 |
|
373 |
if ( ! $id ) { |
|
374 |
wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' ); |
|
375 |
return 0; |
|
376 |
} |
|
377 |
||
378 |
wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' ); |
|
379 |
||
380 |
return $id; |
|
381 |
} |
|
382 |
||
16 | 383 |
// |
384 |
// Admin functions. |
|
385 |
// |
|
0 | 386 |
|
387 |
/** |
|
388 |
* Checks an email address against a list of banned domains. |
|
389 |
* |
|
390 |
* This function checks against the Banned Email Domains list |
|
391 |
* at wp-admin/network/settings.php. The check is only run on |
|
392 |
* self-registrations; user creation at wp-admin/network/users.php |
|
393 |
* bypasses this check. |
|
394 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
* @since MU (3.0.0) |
0 | 396 |
* |
397 |
* @param string $user_email The email provided by the user at registration. |
|
16 | 398 |
* @return bool True when the email address is banned, false otherwise. |
0 | 399 |
*/ |
400 |
function is_email_address_unsafe( $user_email ) { |
|
401 |
$banned_names = get_site_option( 'banned_email_domains' ); |
|
9 | 402 |
if ( $banned_names && ! is_array( $banned_names ) ) { |
0 | 403 |
$banned_names = explode( "\n", $banned_names ); |
9 | 404 |
} |
0 | 405 |
|
406 |
$is_email_address_unsafe = false; |
|
407 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
if ( $banned_names && is_array( $banned_names ) && false !== strpos( $user_email, '@', 1 ) ) { |
9 | 409 |
$banned_names = array_map( 'strtolower', $banned_names ); |
0 | 410 |
$normalized_email = strtolower( $user_email ); |
411 |
||
412 |
list( $email_local_part, $email_domain ) = explode( '@', $normalized_email ); |
|
413 |
||
414 |
foreach ( $banned_names as $banned_domain ) { |
|
9 | 415 |
if ( ! $banned_domain ) { |
0 | 416 |
continue; |
9 | 417 |
} |
0 | 418 |
|
419 |
if ( $email_domain == $banned_domain ) { |
|
420 |
$is_email_address_unsafe = true; |
|
421 |
break; |
|
422 |
} |
|
423 |
||
424 |
$dotted_domain = ".$banned_domain"; |
|
16 | 425 |
if ( substr( $normalized_email, -strlen( $dotted_domain ) ) === $dotted_domain ) { |
0 | 426 |
$is_email_address_unsafe = true; |
427 |
break; |
|
428 |
} |
|
429 |
} |
|
430 |
} |
|
431 |
||
5 | 432 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
* Filters whether an email address is unsafe. |
5 | 434 |
* |
435 |
* @since 3.5.0 |
|
436 |
* |
|
437 |
* @param bool $is_email_address_unsafe Whether the email address is "unsafe". Default false. |
|
438 |
* @param string $user_email User email address. |
|
439 |
*/ |
|
0 | 440 |
return apply_filters( 'is_email_address_unsafe', $is_email_address_unsafe, $user_email ); |
441 |
} |
|
442 |
||
443 |
/** |
|
5 | 444 |
* Sanitize and validate data required for a user sign-up. |
0 | 445 |
* |
5 | 446 |
* Verifies the validity and uniqueness of user names and user email addresses, |
16 | 447 |
* and checks email addresses against allowed and disallowed domains provided by |
448 |
* administrators. |
|
0 | 449 |
* |
5 | 450 |
* The {@see 'wpmu_validate_user_signup'} hook provides an easy way to modify the sign-up |
451 |
* process. The value $result, which is passed to the hook, contains both the user-provided |
|
452 |
* info and the error messages created by the function. {@see 'wpmu_validate_user_signup'} |
|
453 |
* allows you to process the data in any way you'd like, and unset the relevant errors if |
|
454 |
* necessary. |
|
0 | 455 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
* @since MU (3.0.0) |
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 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 459 |
* |
5 | 460 |
* @param string $user_name The login name provided by the user. |
0 | 461 |
* @param string $user_email The email provided by the user. |
16 | 462 |
* @return array { |
463 |
* The array of user name, email, and the error messages. |
|
464 |
* |
|
465 |
* @type string $user_name Sanitized and unique username. |
|
466 |
* @type string $orig_username Original username. |
|
467 |
* @type string $user_email User email address. |
|
468 |
* @type WP_Error $errors WP_Error object containing any errors found. |
|
469 |
* } |
|
0 | 470 |
*/ |
9 | 471 |
function wpmu_validate_user_signup( $user_name, $user_email ) { |
0 | 472 |
global $wpdb; |
473 |
||
474 |
$errors = new WP_Error(); |
|
475 |
||
476 |
$orig_username = $user_name; |
|
9 | 477 |
$user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) ); |
0 | 478 |
|
479 |
if ( $user_name != $orig_username || preg_match( '/[^a-z0-9]/', $user_name ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
$errors->add( 'user_name', __( 'Usernames can only contain lowercase letters (a-z) and numbers.' ) ); |
0 | 481 |
$user_name = $orig_username; |
482 |
} |
|
483 |
||
484 |
$user_email = sanitize_email( $user_email ); |
|
485 |
||
9 | 486 |
if ( empty( $user_name ) ) { |
487 |
$errors->add( 'user_name', __( 'Please enter a username.' ) ); |
|
488 |
} |
|
0 | 489 |
|
490 |
$illegal_names = get_site_option( 'illegal_names' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
if ( ! is_array( $illegal_names ) ) { |
9 | 492 |
$illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ); |
0 | 493 |
add_site_option( 'illegal_names', $illegal_names ); |
494 |
} |
|
16 | 495 |
if ( in_array( $user_name, $illegal_names, true ) ) { |
9 | 496 |
$errors->add( 'user_name', __( 'Sorry, that username is not allowed.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
/** This filter is documented in wp-includes/user.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
0 | 501 |
|
16 | 502 |
if ( in_array( strtolower( $user_name ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
9 | 503 |
$errors->add( 'user_name', __( 'Sorry, that username is not allowed.' ) ); |
7
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
if ( ! is_email( $user_email ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
$errors->add( 'user_email', __( 'Please enter a valid email address.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
} elseif ( is_email_address_unsafe( $user_email ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
$errors->add( 'user_email', __( 'You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
} |
0 | 511 |
|
9 | 512 |
if ( strlen( $user_name ) < 4 ) { |
513 |
$errors->add( 'user_name', __( 'Username must be at least 4 characters.' ) ); |
|
514 |
} |
|
0 | 515 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
if ( strlen( $user_name ) > 60 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
$errors->add( 'user_name', __( 'Username may not be longer than 60 characters.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
} |
0 | 519 |
|
16 | 520 |
// All numeric? |
9 | 521 |
if ( preg_match( '/^[0-9]*$/', $user_name ) ) { |
522 |
$errors->add( 'user_name', __( 'Sorry, usernames must have letters too!' ) ); |
|
523 |
} |
|
0 | 524 |
|
525 |
$limited_email_domains = get_site_option( 'limited_email_domains' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
if ( is_array( $limited_email_domains ) && ! empty( $limited_email_domains ) ) { |
9 | 527 |
$limited_email_domains = array_map( 'strtolower', $limited_email_domains ); |
528 |
$emaildomain = strtolower( substr( $user_email, 1 + strpos( $user_email, '@' ) ) ); |
|
529 |
if ( ! in_array( $emaildomain, $limited_email_domains, true ) ) { |
|
530 |
$errors->add( 'user_email', __( 'Sorry, that email address is not allowed!' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
} |
0 | 532 |
} |
533 |
||
534 |
// Check if the username has been used already. |
|
9 | 535 |
if ( username_exists( $user_name ) ) { |
0 | 536 |
$errors->add( 'user_name', __( 'Sorry, that username already exists!' ) ); |
9 | 537 |
} |
0 | 538 |
|
539 |
// Check if the email address has been used already. |
|
9 | 540 |
if ( email_exists( $user_email ) ) { |
0 | 541 |
$errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) ); |
9 | 542 |
} |
0 | 543 |
|
544 |
// Has someone already signed up for this username? |
|
9 | 545 |
$signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name ) ); |
16 | 546 |
if ( null != $signup ) { |
9 | 547 |
$registered_at = mysql2date( 'U', $signup->registered ); |
548 |
$now = time(); |
|
549 |
$diff = $now - $registered_at; |
|
0 | 550 |
// If registered more than two days ago, cancel registration and let this signup go through. |
9 | 551 |
if ( $diff > 2 * DAY_IN_SECONDS ) { |
0 | 552 |
$wpdb->delete( $wpdb->signups, array( 'user_login' => $user_name ) ); |
9 | 553 |
} else { |
554 |
$errors->add( 'user_name', __( 'That username is currently reserved but may be available in a couple of days.' ) ); |
|
555 |
} |
|
0 | 556 |
} |
557 |
||
9 | 558 |
$signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email ) ); |
16 | 559 |
if ( null != $signup ) { |
9 | 560 |
$diff = time() - mysql2date( 'U', $signup->registered ); |
0 | 561 |
// If registered more than two days ago, cancel registration and let this signup go through. |
9 | 562 |
if ( $diff > 2 * DAY_IN_SECONDS ) { |
0 | 563 |
$wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) ); |
9 | 564 |
} else { |
565 |
$errors->add( 'user_email', __( 'That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.' ) ); |
|
566 |
} |
|
0 | 567 |
} |
568 |
||
9 | 569 |
$result = array( |
570 |
'user_name' => $user_name, |
|
571 |
'orig_username' => $orig_username, |
|
572 |
'user_email' => $user_email, |
|
573 |
'errors' => $errors, |
|
574 |
); |
|
0 | 575 |
|
5 | 576 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
* Filters the validated user registration details. |
5 | 578 |
* |
579 |
* This does not allow you to override the username or email of the user during |
|
580 |
* registration. The values are solely used for validation and error handling. |
|
581 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
582 |
* @since MU (3.0.0) |
5 | 583 |
* |
584 |
* @param array $result { |
|
16 | 585 |
* The array of user name, email, and the error messages. |
5 | 586 |
* |
587 |
* @type string $user_name Sanitized and unique username. |
|
588 |
* @type string $orig_username Original username. |
|
589 |
* @type string $user_email User email address. |
|
590 |
* @type WP_Error $errors WP_Error object containing any errors found. |
|
591 |
* } |
|
592 |
*/ |
|
593 |
return apply_filters( 'wpmu_validate_user_signup', $result ); |
|
0 | 594 |
} |
595 |
||
596 |
/** |
|
597 |
* Processes new site registrations. |
|
598 |
* |
|
599 |
* Checks the data provided by the user during blog signup. Verifies |
|
600 |
* the validity and uniqueness of blog paths and domains. |
|
601 |
* |
|
602 |
* This function prevents the current user from registering a new site |
|
603 |
* with a blogname equivalent to another user's login name. Passing the |
|
604 |
* $user parameter to the function, where $user is the other user, is |
|
605 |
* effectively an override of this limitation. |
|
606 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
* Filter {@see 'wpmu_validate_blog_signup'} if you want to modify |
0 | 608 |
* the way that WordPress validates new site signups. |
609 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
* @since MU (3.0.0) |
0 | 611 |
* |
16 | 612 |
* @global wpdb $wpdb WordPress database abstraction object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
* @global string $domain |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
* @param string $blogname The blog name provided by the user. Must be unique. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
* @param string $blog_title The blog title provided by the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
* @param WP_User|string $user Optional. The user object to check against the new site name. |
16 | 618 |
* @return array { |
619 |
* Array of domain, path, blog name, blog title, user and error messages. |
|
620 |
* |
|
621 |
* @type string $domain Domain for the site. |
|
622 |
* @type string $path Path for the site. Used in subdirectory installations. |
|
623 |
* @type string $blogname The unique site name (slug). |
|
624 |
* @type string $blog_title Blog title. |
|
625 |
* @type string|WP_User $user By default, an empty string. A user object if provided. |
|
626 |
* @type WP_Error $errors WP_Error containing any errors found. |
|
627 |
* } |
|
0 | 628 |
*/ |
5 | 629 |
function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) { |
630 |
global $wpdb, $domain; |
|
0 | 631 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
$current_network = get_network(); |
9 | 633 |
$base = $current_network->path; |
0 | 634 |
|
635 |
$blog_title = strip_tags( $blog_title ); |
|
636 |
||
9 | 637 |
$errors = new WP_Error(); |
0 | 638 |
$illegal_names = get_site_option( 'illegal_names' ); |
16 | 639 |
if ( false == $illegal_names ) { |
0 | 640 |
$illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ); |
641 |
add_site_option( 'illegal_names', $illegal_names ); |
|
642 |
} |
|
643 |
||
5 | 644 |
/* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
* On sub dir installations, some names are so illegal, only a filter can |
5 | 646 |
* spring them from jail. |
647 |
*/ |
|
648 |
if ( ! is_subdomain_install() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
$illegal_names = array_merge( $illegal_names, get_subdirectory_reserved_names() ); |
5 | 650 |
} |
0 | 651 |
|
9 | 652 |
if ( empty( $blogname ) ) { |
653 |
$errors->add( 'blogname', __( 'Please enter a site name.' ) ); |
|
654 |
} |
|
0 | 655 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
656 |
if ( preg_match( '/[^a-z0-9]+/', $blogname ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
657 |
$errors->add( 'blogname', __( 'Site names can only contain lowercase letters (a-z) and numbers.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
} |
0 | 659 |
|
16 | 660 |
if ( in_array( $blogname, $illegal_names, true ) ) { |
9 | 661 |
$errors->add( 'blogname', __( 'That name is not allowed.' ) ); |
662 |
} |
|
0 | 663 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
664 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
665 |
* Filters the minimum site name length required when validating a site signup. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
666 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
667 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
668 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
669 |
* @param int $length The minimum site name length. Default 4. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
670 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
671 |
$minimum_site_name_length = apply_filters( 'minimum_site_name_length', 4 ); |
0 | 672 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
673 |
if ( strlen( $blogname ) < $minimum_site_name_length ) { |
16 | 674 |
/* translators: %s: Minimum site name length. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
$errors->add( 'blogname', sprintf( _n( 'Site name must be at least %s character.', 'Site name must be at least %s characters.', $minimum_site_name_length ), number_format_i18n( $minimum_site_name_length ) ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
676 |
} |
0 | 677 |
|
16 | 678 |
// Do not allow users to create a blog that conflicts with a page on the main blog. |
9 | 679 |
if ( ! is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( 'SELECT post_name FROM ' . $wpdb->get_blog_prefix( $current_network->site_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) { |
0 | 680 |
$errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) ); |
9 | 681 |
} |
0 | 682 |
|
16 | 683 |
// All numeric? |
9 | 684 |
if ( preg_match( '/^[0-9]*$/', $blogname ) ) { |
685 |
$errors->add( 'blogname', __( 'Sorry, site names must have letters too!' ) ); |
|
686 |
} |
|
0 | 687 |
|
5 | 688 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
* Filters the new site name during registration. |
5 | 690 |
* |
691 |
* The name is the site's subdomain or the site's subdirectory |
|
692 |
* path depending on the network settings. |
|
693 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
* @since MU (3.0.0) |
5 | 695 |
* |
696 |
* @param string $blogname Site name. |
|
697 |
*/ |
|
0 | 698 |
$blogname = apply_filters( 'newblogname', $blogname ); |
699 |
||
9 | 700 |
$blog_title = wp_unslash( $blog_title ); |
0 | 701 |
|
9 | 702 |
if ( empty( $blog_title ) ) { |
703 |
$errors->add( 'blog_title', __( 'Please enter a site title.' ) ); |
|
704 |
} |
|
0 | 705 |
|
706 |
// Check if the domain/path has been used already. |
|
707 |
if ( is_subdomain_install() ) { |
|
708 |
$mydomain = $blogname . '.' . preg_replace( '|^www\.|', '', $domain ); |
|
9 | 709 |
$path = $base; |
0 | 710 |
} else { |
711 |
$mydomain = "$domain"; |
|
9 | 712 |
$path = $base . $blogname . '/'; |
0 | 713 |
} |
9 | 714 |
if ( domain_exists( $mydomain, $path, $current_network->id ) ) { |
0 | 715 |
$errors->add( 'blogname', __( 'Sorry, that site already exists!' ) ); |
9 | 716 |
} |
0 | 717 |
|
718 |
if ( username_exists( $blogname ) ) { |
|
9 | 719 |
if ( ! is_object( $user ) || ( is_object( $user ) && ( $user->user_login != $blogname ) ) ) { |
0 | 720 |
$errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) ); |
9 | 721 |
} |
0 | 722 |
} |
723 |
||
724 |
// Has someone already signed up for this domain? |
|
16 | 725 |
// TODO: Check email too? |
726 |
$signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path ) ); |
|
9 | 727 |
if ( ! empty( $signup ) ) { |
728 |
$diff = time() - mysql2date( 'U', $signup->registered ); |
|
0 | 729 |
// If registered more than two days ago, cancel registration and let this signup go through. |
9 | 730 |
if ( $diff > 2 * DAY_IN_SECONDS ) { |
731 |
$wpdb->delete( |
|
732 |
$wpdb->signups, |
|
733 |
array( |
|
734 |
'domain' => $mydomain, |
|
735 |
'path' => $path, |
|
736 |
) |
|
737 |
); |
|
738 |
} else { |
|
739 |
$errors->add( 'blogname', __( 'That site is currently reserved but may be available in a couple days.' ) ); |
|
740 |
} |
|
0 | 741 |
} |
742 |
||
9 | 743 |
$result = array( |
744 |
'domain' => $mydomain, |
|
745 |
'path' => $path, |
|
746 |
'blogname' => $blogname, |
|
747 |
'blog_title' => $blog_title, |
|
748 |
'user' => $user, |
|
749 |
'errors' => $errors, |
|
750 |
); |
|
5 | 751 |
|
752 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
753 |
* Filters site details and error messages following registration. |
5 | 754 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
755 |
* @since MU (3.0.0) |
5 | 756 |
* |
757 |
* @param array $result { |
|
758 |
* Array of domain, path, blog name, blog title, user and error messages. |
|
759 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
760 |
* @type string $domain Domain for the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
761 |
* @type string $path Path for the site. Used in subdirectory installations. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
* @type string $blogname The unique site name (slug). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
763 |
* @type string $blog_title Blog title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
764 |
* @type string|WP_User $user By default, an empty string. A user object if provided. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
765 |
* @type WP_Error $errors WP_Error containing any errors found. |
5 | 766 |
* } |
767 |
*/ |
|
768 |
return apply_filters( 'wpmu_validate_blog_signup', $result ); |
|
0 | 769 |
} |
770 |
||
771 |
/** |
|
772 |
* Record site signup information for future activation. |
|
773 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
774 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
775 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
776 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 777 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
778 |
* @param string $domain The requested domain. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
779 |
* @param string $path The requested path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
780 |
* @param string $title The requested site title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
* @param string $user The user's requested login name. |
0 | 782 |
* @param string $user_email The user's email address. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
783 |
* @param array $meta Optional. Signup meta data. By default, contains the requested privacy setting and lang_id. |
0 | 784 |
*/ |
9 | 785 |
function wpmu_signup_blog( $domain, $path, $title, $user, $user_email, $meta = array() ) { |
0 | 786 |
global $wpdb; |
787 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
788 |
$key = substr( md5( time() . wp_rand() . $domain ), 0, 16 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
* Filters the metadata for a site signup. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
793 |
* The metadata will be serialized prior to storing it in the database. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
794 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
797 |
* @param array $meta Signup meta data. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
798 |
* @param string $domain The requested domain. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
799 |
* @param string $path The requested path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
800 |
* @param string $title The requested site title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
801 |
* @param string $user The user's requested login name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
802 |
* @param string $user_email The user's email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
803 |
* @param string $key The user's activation key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
804 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
$meta = apply_filters( 'signup_site_meta', $meta, $domain, $path, $title, $user, $user_email, $key ); |
0 | 806 |
|
9 | 807 |
$wpdb->insert( |
808 |
$wpdb->signups, |
|
809 |
array( |
|
810 |
'domain' => $domain, |
|
811 |
'path' => $path, |
|
812 |
'title' => $title, |
|
813 |
'user_login' => $user, |
|
814 |
'user_email' => $user_email, |
|
815 |
'registered' => current_time( 'mysql', true ), |
|
816 |
'activation_key' => $key, |
|
817 |
'meta' => serialize( $meta ), |
|
818 |
) |
|
819 |
); |
|
0 | 820 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
821 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
822 |
* Fires after site signup information has been written to the database. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
824 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
825 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
826 |
* @param string $domain The requested domain. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
* @param string $path The requested path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
828 |
* @param string $title The requested site title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
829 |
* @param string $user The user's requested login name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
* @param string $user_email The user's email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
* @param string $key The user's activation key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
832 |
* @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
833 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
do_action( 'after_signup_site', $domain, $path, $title, $user, $user_email, $key, $meta ); |
0 | 835 |
} |
836 |
||
837 |
/** |
|
838 |
* Record user signup information for future activation. |
|
839 |
* |
|
840 |
* This function is used when user registration is open but |
|
841 |
* new site registration is not. |
|
842 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
843 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
845 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 846 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
847 |
* @param string $user The user's requested login name. |
0 | 848 |
* @param string $user_email The user's email address. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
849 |
* @param array $meta Optional. Signup meta data. Default empty array. |
0 | 850 |
*/ |
851 |
function wpmu_signup_user( $user, $user_email, $meta = array() ) { |
|
852 |
global $wpdb; |
|
853 |
||
16 | 854 |
// Format data. |
9 | 855 |
$user = preg_replace( '/\s+/', '', sanitize_user( $user, true ) ); |
0 | 856 |
$user_email = sanitize_email( $user_email ); |
9 | 857 |
$key = substr( md5( time() . wp_rand() . $user_email ), 0, 16 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
858 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
* Filters the metadata for a user signup. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
* The metadata will be serialized prior to storing it in the database. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
864 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
865 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
866 |
* @param array $meta Signup meta data. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
867 |
* @param string $user The user's requested login name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
868 |
* @param string $user_email The user's email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
* @param string $key The user's activation key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
871 |
$meta = apply_filters( 'signup_user_meta', $meta, $user, $user_email, $key ); |
0 | 872 |
|
9 | 873 |
$wpdb->insert( |
874 |
$wpdb->signups, |
|
875 |
array( |
|
876 |
'domain' => '', |
|
877 |
'path' => '', |
|
878 |
'title' => '', |
|
879 |
'user_login' => $user, |
|
880 |
'user_email' => $user_email, |
|
881 |
'registered' => current_time( 'mysql', true ), |
|
882 |
'activation_key' => $key, |
|
883 |
'meta' => serialize( $meta ), |
|
884 |
) |
|
885 |
); |
|
0 | 886 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
888 |
* Fires after a user's signup information has been written to the database. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
891 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
* @param string $user The user's requested login name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
893 |
* @param string $user_email The user's email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
* @param string $key The user's activation key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
* @param array $meta Signup meta data. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
896 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
do_action( 'after_signup_user', $user, $user_email, $key, $meta ); |
0 | 898 |
} |
899 |
||
900 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
901 |
* Send a confirmation request email to a user when they sign up for a new site. The new site will not become active |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
902 |
* until the confirmation link is clicked. |
0 | 903 |
* |
904 |
* This is the notification function used when site registration |
|
905 |
* is enabled. |
|
906 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
* Filter {@see 'wpmu_signup_blog_notification'} to bypass this function or |
0 | 908 |
* replace it with your own notification behavior. |
909 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
910 |
* Filter {@see 'wpmu_signup_blog_notification_email'} and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
* {@see 'wpmu_signup_blog_notification_subject'} to change the content |
0 | 912 |
* and subject line of the email sent to newly registered users. |
913 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
914 |
* @since MU (3.0.0) |
0 | 915 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
916 |
* @param string $domain The new blog domain. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
* @param string $path The new blog path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
918 |
* @param string $title The site title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
919 |
* @param string $user_login The user's login name. |
0 | 920 |
* @param string $user_email The user's email address. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
* @param string $key The activation key created in wpmu_signup_blog() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
922 |
* @param array $meta Optional. Signup meta data. By default, contains the requested privacy setting and lang_id. |
0 | 923 |
* @return bool |
924 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
925 |
function wpmu_signup_blog_notification( $domain, $path, $title, $user_login, $user_email, $key, $meta = array() ) { |
5 | 926 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
* Filters whether to bypass the new site email notification. |
5 | 928 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
* @since MU (3.0.0) |
5 | 930 |
* |
931 |
* @param string|bool $domain Site domain. |
|
932 |
* @param string $path Site path. |
|
933 |
* @param string $title Site title. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
934 |
* @param string $user_login User login name. |
5 | 935 |
* @param string $user_email User email address. |
936 |
* @param string $key Activation key created in wpmu_signup_blog(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
937 |
* @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
5 | 938 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
939 |
if ( ! apply_filters( 'wpmu_signup_blog_notification', $domain, $path, $title, $user_login, $user_email, $key, $meta ) ) { |
0 | 940 |
return false; |
5 | 941 |
} |
0 | 942 |
|
943 |
// Send email with activation link. |
|
9 | 944 |
if ( ! is_subdomain_install() || get_current_network_id() != 1 ) { |
945 |
$activate_url = network_site_url( "wp-activate.php?key=$key" ); |
|
946 |
} else { |
|
16 | 947 |
$activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; // @todo Use *_url() API. |
9 | 948 |
} |
0 | 949 |
|
9 | 950 |
$activate_url = esc_url( $activate_url ); |
16 | 951 |
|
952 |
$admin_email = get_site_option( 'admin_email' ); |
|
953 |
||
954 |
if ( '' === $admin_email ) { |
|
955 |
$admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST ); |
|
9 | 956 |
} |
16 | 957 |
|
958 |
$from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress'; |
|
9 | 959 |
$message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
960 |
|
9 | 961 |
$user = get_user_by( 'login', $user_login ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
962 |
$switched_locale = switch_to_locale( get_user_locale( $user ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
963 |
|
0 | 964 |
$message = sprintf( |
5 | 965 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
966 |
* Filters the message content of the new blog notification email. |
5 | 967 |
* |
968 |
* Content should be formatted for transmission via wp_mail(). |
|
969 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
970 |
* @since MU (3.0.0) |
5 | 971 |
* |
972 |
* @param string $content Content of the notification email. |
|
973 |
* @param string $domain Site domain. |
|
974 |
* @param string $path Site path. |
|
975 |
* @param string $title Site title. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
976 |
* @param string $user_login User login name. |
5 | 977 |
* @param string $user_email User email address. |
978 |
* @param string $key Activation key created in wpmu_signup_blog(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
979 |
* @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
5 | 980 |
*/ |
9 | 981 |
apply_filters( |
982 |
'wpmu_signup_blog_notification_email', |
|
16 | 983 |
/* translators: New site notification email. 1: Activation URL, 2: New site URL. */ |
9 | 984 |
__( "To activate your blog, please click the following link:\n\n%1\$s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%2\$s" ), |
985 |
$domain, |
|
986 |
$path, |
|
987 |
$title, |
|
988 |
$user_login, |
|
989 |
$user_email, |
|
990 |
$key, |
|
991 |
$meta |
|
0 | 992 |
), |
993 |
$activate_url, |
|
994 |
esc_url( "http://{$domain}{$path}" ), |
|
995 |
$key |
|
996 |
); |
|
16 | 997 |
|
0 | 998 |
$subject = sprintf( |
5 | 999 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
* Filters the subject of the new blog notification email. |
5 | 1001 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
* @since MU (3.0.0) |
5 | 1003 |
* |
1004 |
* @param string $subject Subject of the notification email. |
|
1005 |
* @param string $domain Site domain. |
|
1006 |
* @param string $path Site path. |
|
1007 |
* @param string $title Site title. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1008 |
* @param string $user_login User login name. |
5 | 1009 |
* @param string $user_email User email address. |
1010 |
* @param string $key Activation key created in wpmu_signup_blog(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
* @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
5 | 1012 |
*/ |
9 | 1013 |
apply_filters( |
1014 |
'wpmu_signup_blog_notification_subject', |
|
16 | 1015 |
/* translators: New site notification email subject. 1: Network title, 2: New site URL. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
_x( '[%1$s] Activate %2$s', 'New site notification email subject' ), |
9 | 1017 |
$domain, |
1018 |
$path, |
|
1019 |
$title, |
|
1020 |
$user_login, |
|
1021 |
$user_email, |
|
1022 |
$key, |
|
1023 |
$meta |
|
0 | 1024 |
), |
1025 |
$from_name, |
|
1026 |
esc_url( 'http://' . $domain . $path ) |
|
1027 |
); |
|
16 | 1028 |
|
5 | 1029 |
wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1032 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
|
0 | 1035 |
return true; |
1036 |
} |
|
1037 |
||
1038 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
* Send a confirmation request email to a user when they sign up for a new user account (without signing up for a site |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
* at the same time). The user account will not become active until the confirmation link is clicked. |
0 | 1041 |
* |
1042 |
* This is the notification function used when no new site has |
|
1043 |
* been requested. |
|
1044 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
* Filter {@see 'wpmu_signup_user_notification'} to bypass this function or |
0 | 1046 |
* replace it with your own notification behavior. |
1047 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1048 |
* Filter {@see 'wpmu_signup_user_notification_email'} and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1049 |
* {@see 'wpmu_signup_user_notification_subject'} to change the content |
0 | 1050 |
* and subject line of the email sent to newly registered users. |
1051 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
* @since MU (3.0.0) |
0 | 1053 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
* @param string $user_login The user's login name. |
0 | 1055 |
* @param string $user_email The user's email address. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
* @param string $key The activation key created in wpmu_signup_user() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1057 |
* @param array $meta Optional. Signup meta data. Default empty array. |
0 | 1058 |
* @return bool |
1059 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
function wpmu_signup_user_notification( $user_login, $user_email, $key, $meta = array() ) { |
5 | 1061 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
* Filters whether to bypass the email notification for new user sign-up. |
5 | 1063 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
* @since MU (3.0.0) |
5 | 1065 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1066 |
* @param string $user_login User login name. |
5 | 1067 |
* @param string $user_email User email address. |
1068 |
* @param string $key Activation key created in wpmu_signup_user(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
* @param array $meta Signup meta data. Default empty array. |
5 | 1070 |
*/ |
9 | 1071 |
if ( ! apply_filters( 'wpmu_signup_user_notification', $user_login, $user_email, $key, $meta ) ) { |
0 | 1072 |
return false; |
9 | 1073 |
} |
0 | 1074 |
|
9 | 1075 |
$user = get_user_by( 'login', $user_login ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
$switched_locale = switch_to_locale( get_user_locale( $user ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
|
0 | 1078 |
// Send email with activation link. |
1079 |
$admin_email = get_site_option( 'admin_email' ); |
|
16 | 1080 |
|
1081 |
if ( '' === $admin_email ) { |
|
1082 |
$admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST ); |
|
9 | 1083 |
} |
16 | 1084 |
|
1085 |
$from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress'; |
|
9 | 1086 |
$message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
1087 |
$message = sprintf( |
|
5 | 1088 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
* Filters the content of the notification email for new user sign-up. |
5 | 1090 |
* |
1091 |
* Content should be formatted for transmission via wp_mail(). |
|
1092 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
* @since MU (3.0.0) |
5 | 1094 |
* |
1095 |
* @param string $content Content of the notification email. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
* @param string $user_login User login name. |
5 | 1097 |
* @param string $user_email User email address. |
1098 |
* @param string $key Activation key created in wpmu_signup_user(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
* @param array $meta Signup meta data. Default empty array. |
5 | 1100 |
*/ |
9 | 1101 |
apply_filters( |
1102 |
'wpmu_signup_user_notification_email', |
|
16 | 1103 |
/* translators: New user notification email. %s: Activation URL. */ |
0 | 1104 |
__( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login." ), |
9 | 1105 |
$user_login, |
1106 |
$user_email, |
|
1107 |
$key, |
|
1108 |
$meta |
|
0 | 1109 |
), |
1110 |
site_url( "wp-activate.php?key=$key" ) |
|
1111 |
); |
|
16 | 1112 |
|
0 | 1113 |
$subject = sprintf( |
5 | 1114 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
* Filters the subject of the notification email of new user signup. |
5 | 1116 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
* @since MU (3.0.0) |
5 | 1118 |
* |
1119 |
* @param string $subject Subject of the notification email. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1120 |
* @param string $user_login User login name. |
5 | 1121 |
* @param string $user_email User email address. |
1122 |
* @param string $key Activation key created in wpmu_signup_user(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
* @param array $meta Signup meta data. Default empty array. |
5 | 1124 |
*/ |
9 | 1125 |
apply_filters( |
1126 |
'wpmu_signup_user_notification_subject', |
|
16 | 1127 |
/* translators: New user notification email subject. 1: Network title, 2: New user login. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
_x( '[%1$s] Activate %2$s', 'New user notification email subject' ), |
9 | 1129 |
$user_login, |
1130 |
$user_email, |
|
1131 |
$key, |
|
1132 |
$meta |
|
0 | 1133 |
), |
1134 |
$from_name, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1135 |
$user_login |
0 | 1136 |
); |
16 | 1137 |
|
5 | 1138 |
wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1141 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1143 |
|
0 | 1144 |
return true; |
1145 |
} |
|
1146 |
||
1147 |
/** |
|
1148 |
* Activate a signup. |
|
1149 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1150 |
* Hook to {@see 'wpmu_activate_user'} or {@see 'wpmu_activate_blog'} for events |
0 | 1151 |
* that should happen only when users or sites are self-created (since |
1152 |
* those actions are not called when users and sites are created |
|
1153 |
* by a Super Admin). |
|
1154 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1155 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1156 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1157 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 1158 |
* |
1159 |
* @param string $key The activation key provided to the user. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1160 |
* @return array|WP_Error An array containing information about the activated user and/or blog |
0 | 1161 |
*/ |
9 | 1162 |
function wpmu_activate_signup( $key ) { |
0 | 1163 |
global $wpdb; |
1164 |
||
9 | 1165 |
$signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key ) ); |
0 | 1166 |
|
9 | 1167 |
if ( empty( $signup ) ) { |
0 | 1168 |
return new WP_Error( 'invalid_key', __( 'Invalid activation key.' ) ); |
9 | 1169 |
} |
0 | 1170 |
|
1171 |
if ( $signup->active ) { |
|
9 | 1172 |
if ( empty( $signup->domain ) ) { |
0 | 1173 |
return new WP_Error( 'already_active', __( 'The user is already active.' ), $signup ); |
9 | 1174 |
} else { |
0 | 1175 |
return new WP_Error( 'already_active', __( 'The site is already active.' ), $signup ); |
9 | 1176 |
} |
0 | 1177 |
} |
1178 |
||
9 | 1179 |
$meta = maybe_unserialize( $signup->meta ); |
0 | 1180 |
$password = wp_generate_password( 12, false ); |
1181 |
||
9 | 1182 |
$user_id = username_exists( $signup->user_login ); |
0 | 1183 |
|
9 | 1184 |
if ( ! $user_id ) { |
1185 |
$user_id = wpmu_create_user( $signup->user_login, $password, $signup->user_email ); |
|
1186 |
} else { |
|
0 | 1187 |
$user_already_exists = true; |
9 | 1188 |
} |
1189 |
||
1190 |
if ( ! $user_id ) { |
|
1191 |
return new WP_Error( 'create_user', __( 'Could not create user' ), $signup ); |
|
1192 |
} |
|
1193 |
||
1194 |
$now = current_time( 'mysql', true ); |
|
0 | 1195 |
|
9 | 1196 |
if ( empty( $signup->domain ) ) { |
1197 |
$wpdb->update( |
|
1198 |
$wpdb->signups, |
|
1199 |
array( |
|
1200 |
'active' => 1, |
|
1201 |
'activated' => $now, |
|
1202 |
), |
|
1203 |
array( 'activation_key' => $key ) |
|
1204 |
); |
|
0 | 1205 |
|
9 | 1206 |
if ( isset( $user_already_exists ) ) { |
1207 |
return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup ); |
|
1208 |
} |
|
0 | 1209 |
|
5 | 1210 |
/** |
1211 |
* Fires immediately after a new user is activated. |
|
1212 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
* @since MU (3.0.0) |
5 | 1214 |
* |
16 | 1215 |
* @param int $user_id User ID. |
1216 |
* @param string $password User password. |
|
1217 |
* @param array $meta Signup meta data. |
|
5 | 1218 |
*/ |
0 | 1219 |
do_action( 'wpmu_activate_user', $user_id, $password, $meta ); |
16 | 1220 |
|
9 | 1221 |
return array( |
1222 |
'user_id' => $user_id, |
|
1223 |
'password' => $password, |
|
1224 |
'meta' => $meta, |
|
1225 |
); |
|
0 | 1226 |
} |
1227 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
$blog_id = wpmu_create_blog( $signup->domain, $signup->path, $signup->title, $user_id, $meta, get_current_network_id() ); |
0 | 1229 |
|
1230 |
// TODO: What to do if we create a user but cannot create a blog? |
|
9 | 1231 |
if ( is_wp_error( $blog_id ) ) { |
16 | 1232 |
/* |
1233 |
* If blog is taken, that means a previous attempt to activate this blog |
|
1234 |
* failed in between creating the blog and setting the activation flag. |
|
1235 |
* Let's just set the active flag and instruct the user to reset their password. |
|
1236 |
*/ |
|
1237 |
if ( 'blog_taken' === $blog_id->get_error_code() ) { |
|
0 | 1238 |
$blog_id->add_data( $signup ); |
9 | 1239 |
$wpdb->update( |
1240 |
$wpdb->signups, |
|
1241 |
array( |
|
1242 |
'active' => 1, |
|
1243 |
'activated' => $now, |
|
1244 |
), |
|
1245 |
array( 'activation_key' => $key ) |
|
1246 |
); |
|
0 | 1247 |
} |
1248 |
return $blog_id; |
|
1249 |
} |
|
1250 |
||
9 | 1251 |
$wpdb->update( |
1252 |
$wpdb->signups, |
|
1253 |
array( |
|
1254 |
'active' => 1, |
|
1255 |
'activated' => $now, |
|
1256 |
), |
|
1257 |
array( 'activation_key' => $key ) |
|
1258 |
); |
|
16 | 1259 |
|
5 | 1260 |
/** |
1261 |
* Fires immediately after a site is activated. |
|
1262 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1263 |
* @since MU (3.0.0) |
5 | 1264 |
* |
1265 |
* @param int $blog_id Blog ID. |
|
1266 |
* @param int $user_id User ID. |
|
1267 |
* @param int $password User password. |
|
1268 |
* @param string $signup_title Site title. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1269 |
* @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
5 | 1270 |
*/ |
1271 |
do_action( 'wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta ); |
|
0 | 1272 |
|
9 | 1273 |
return array( |
1274 |
'blog_id' => $blog_id, |
|
1275 |
'user_id' => $user_id, |
|
1276 |
'password' => $password, |
|
1277 |
'title' => $signup->title, |
|
1278 |
'meta' => $meta, |
|
1279 |
); |
|
0 | 1280 |
} |
1281 |
||
1282 |
/** |
|
16 | 1283 |
* Deletes am associated signup entry when a user is deleted from the database. |
1284 |
* |
|
1285 |
* @since 5.5.0 |
|
1286 |
* |
|
1287 |
* @param int $id ID of the user to delete. |
|
1288 |
* @param int|null $reassign ID of the user to reassign posts and links to. |
|
1289 |
* @param WP_User $user User object. |
|
1290 |
*/ |
|
1291 |
function wp_delete_signup_on_user_delete( $id, $reassign, $user ) { |
|
1292 |
global $wpdb; |
|
1293 |
||
1294 |
$wpdb->delete( $wpdb->signups, array( 'user_login' => $user->user_login ) ); |
|
1295 |
} |
|
1296 |
||
1297 |
/** |
|
0 | 1298 |
* Create a user. |
1299 |
* |
|
1300 |
* This function runs when a user self-registers as well as when |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
* a Super Admin creates a new user. Hook to {@see 'wpmu_new_user'} for events |
0 | 1302 |
* that should affect all new users, but only on Multisite (otherwise |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
* use {@see'user_register'}). |
0 | 1304 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
* @since MU (3.0.0) |
0 | 1306 |
* |
1307 |
* @param string $user_name The new user's login name. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1308 |
* @param string $password The new user's password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1309 |
* @param string $email The new user's email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1310 |
* @return int|false Returns false on failure, or int $user_id on success |
0 | 1311 |
*/ |
1312 |
function wpmu_create_user( $user_name, $password, $email ) { |
|
1313 |
$user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) ); |
|
1314 |
||
1315 |
$user_id = wp_create_user( $user_name, $password, $email ); |
|
9 | 1316 |
if ( is_wp_error( $user_id ) ) { |
0 | 1317 |
return false; |
9 | 1318 |
} |
0 | 1319 |
|
1320 |
// Newly created users have no roles or caps until they are added to a blog. |
|
1321 |
delete_user_option( $user_id, 'capabilities' ); |
|
1322 |
delete_user_option( $user_id, 'user_level' ); |
|
1323 |
||
5 | 1324 |
/** |
1325 |
* Fires immediately after a new user is created. |
|
1326 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1327 |
* @since MU (3.0.0) |
5 | 1328 |
* |
1329 |
* @param int $user_id User ID. |
|
1330 |
*/ |
|
0 | 1331 |
do_action( 'wpmu_new_user', $user_id ); |
1332 |
||
1333 |
return $user_id; |
|
1334 |
} |
|
1335 |
||
1336 |
/** |
|
1337 |
* Create a site. |
|
1338 |
* |
|
1339 |
* This function runs when a user self-registers a new site as well |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1340 |
* as when a Super Admin creates a new site. Hook to {@see 'wpmu_new_blog'} |
0 | 1341 |
* for events that should affect all new sites. |
1342 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
* On subdirectory installations, $domain is the same as the main site's |
0 | 1344 |
* domain, and the path is the subdirectory name (eg 'example.com' |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1345 |
* and '/blog1/'). On subdomain installations, $domain is the new subdomain + |
0 | 1346 |
* root domain (eg 'blog1.example.com'), and $path is '/'. |
1347 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1348 |
* @since MU (3.0.0) |
0 | 1349 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1350 |
* @param string $domain The new site's domain. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1351 |
* @param string $path The new site's path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1352 |
* @param string $title The new site's title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1353 |
* @param int $user_id The user ID of the new site's admin. |
9 | 1354 |
* @param array $options Optional. Array of key=>value pairs used to set initial site options. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1355 |
* If valid status keys are included ('public', 'archived', 'mature', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1356 |
* 'spam', 'deleted', or 'lang_id') the given site status(es) will be |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1357 |
* updated. Otherwise, keys and values will be used to set options for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1358 |
* the new site. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1359 |
* @param int $network_id Optional. Network ID. Only relevant on multi-network installations. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1360 |
* @return int|WP_Error Returns WP_Error object on failure, the new site ID on success. |
0 | 1361 |
*/ |
9 | 1362 |
function wpmu_create_blog( $domain, $path, $title, $user_id, $options = array(), $network_id = 1 ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1363 |
$defaults = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1364 |
'public' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1365 |
); |
9 | 1366 |
$options = wp_parse_args( $options, $defaults ); |
0 | 1367 |
|
9 | 1368 |
$title = strip_tags( $title ); |
0 | 1369 |
$user_id = (int) $user_id; |
1370 |
||
1371 |
// Check if the domain has been used already. We should return an error message. |
|
9 | 1372 |
if ( domain_exists( $domain, $path, $network_id ) ) { |
0 | 1373 |
return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) ); |
9 | 1374 |
} |
0 | 1375 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1376 |
if ( ! wp_installing() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1377 |
wp_installing( true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1378 |
} |
0 | 1379 |
|
16 | 1380 |
$allowed_data_fields = array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ); |
0 | 1381 |
|
9 | 1382 |
$site_data = array_merge( |
1383 |
array( |
|
1384 |
'domain' => $domain, |
|
1385 |
'path' => $path, |
|
1386 |
'network_id' => $network_id, |
|
1387 |
), |
|
16 | 1388 |
array_intersect_key( $options, array_flip( $allowed_data_fields ) ) |
9 | 1389 |
); |
0 | 1390 |
|
9 | 1391 |
// Data to pass to wp_initialize_site(). |
1392 |
$site_initialization_data = array( |
|
1393 |
'title' => $title, |
|
1394 |
'user_id' => $user_id, |
|
16 | 1395 |
'options' => array_diff_key( $options, array_flip( $allowed_data_fields ) ), |
9 | 1396 |
); |
0 | 1397 |
|
9 | 1398 |
$blog_id = wp_insert_site( array_merge( $site_data, $site_initialization_data ) ); |
1399 |
||
1400 |
if ( is_wp_error( $blog_id ) ) { |
|
1401 |
return $blog_id; |
|
1402 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1403 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
wp_cache_set( 'last_changed', microtime(), 'sites' ); |
0 | 1405 |
|
1406 |
return $blog_id; |
|
1407 |
} |
|
1408 |
||
1409 |
/** |
|
1410 |
* Notifies the network admin that a new site has been activated. |
|
1411 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
* Filter {@see 'newblog_notify_siteadmin'} to change the content of |
0 | 1413 |
* the notification email. |
1414 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1415 |
* @since MU (3.0.0) |
9 | 1416 |
* @since 5.1.0 $blog_id now supports input from the {@see 'wp_initialize_site'} action. |
0 | 1417 |
* |
9 | 1418 |
* @param WP_Site|int $blog_id The new site's object or ID. |
1419 |
* @param string $deprecated Not used. |
|
0 | 1420 |
* @return bool |
1421 |
*/ |
|
1422 |
function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) { |
|
9 | 1423 |
if ( is_object( $blog_id ) ) { |
1424 |
$blog_id = $blog_id->blog_id; |
|
1425 |
} |
|
1426 |
||
16 | 1427 |
if ( 'yes' !== get_site_option( 'registrationnotification' ) ) { |
0 | 1428 |
return false; |
9 | 1429 |
} |
0 | 1430 |
|
1431 |
$email = get_site_option( 'admin_email' ); |
|
16 | 1432 |
|
9 | 1433 |
if ( is_email( $email ) == false ) { |
0 | 1434 |
return false; |
9 | 1435 |
} |
0 | 1436 |
|
9 | 1437 |
$options_site_url = esc_url( network_admin_url( 'settings.php' ) ); |
0 | 1438 |
|
1439 |
switch_to_blog( $blog_id ); |
|
1440 |
$blogname = get_option( 'blogname' ); |
|
9 | 1441 |
$siteurl = site_url(); |
0 | 1442 |
restore_current_blog(); |
1443 |
||
9 | 1444 |
$msg = sprintf( |
16 | 1445 |
/* translators: New site notification email. 1: Site URL, 2: User IP address, 3: URL to Network Settings screen. */ |
9 | 1446 |
__( |
1447 |
'New Site: %1$s |
|
0 | 1448 |
URL: %2$s |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1449 |
Remote IP address: %3$s |
0 | 1450 |
|
9 | 1451 |
Disable these notifications: %4$s' |
1452 |
), |
|
1453 |
$blogname, |
|
1454 |
$siteurl, |
|
1455 |
wp_unslash( $_SERVER['REMOTE_ADDR'] ), |
|
1456 |
$options_site_url |
|
1457 |
); |
|
5 | 1458 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1459 |
* Filters the message body of the new site activation email sent |
5 | 1460 |
* to the network administrator. |
1461 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1462 |
* @since MU (3.0.0) |
16 | 1463 |
* @since 5.4.0 The `$blog_id` parameter was added. |
5 | 1464 |
* |
16 | 1465 |
* @param string $msg Email body. |
1466 |
* @param int $blog_id The new site's ID. |
|
5 | 1467 |
*/ |
16 | 1468 |
$msg = apply_filters( 'newblog_notify_siteadmin', $msg, $blog_id ); |
0 | 1469 |
|
16 | 1470 |
/* translators: New site notification email subject. %s: New site URL. */ |
0 | 1471 |
wp_mail( $email, sprintf( __( 'New Site Registration: %s' ), $siteurl ), $msg ); |
16 | 1472 |
|
0 | 1473 |
return true; |
1474 |
} |
|
1475 |
||
1476 |
/** |
|
1477 |
* Notifies the network admin that a new user has been activated. |
|
1478 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1479 |
* Filter {@see 'newuser_notify_siteadmin'} to change the content of |
0 | 1480 |
* the notification email. |
1481 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1482 |
* @since MU (3.0.0) |
0 | 1483 |
* |
1484 |
* @param int $user_id The new user's ID. |
|
1485 |
* @return bool |
|
1486 |
*/ |
|
1487 |
function newuser_notify_siteadmin( $user_id ) { |
|
16 | 1488 |
if ( 'yes' !== get_site_option( 'registrationnotification' ) ) { |
0 | 1489 |
return false; |
9 | 1490 |
} |
0 | 1491 |
|
1492 |
$email = get_site_option( 'admin_email' ); |
|
1493 |
||
9 | 1494 |
if ( is_email( $email ) == false ) { |
0 | 1495 |
return false; |
9 | 1496 |
} |
0 | 1497 |
|
1498 |
$user = get_userdata( $user_id ); |
|
1499 |
||
9 | 1500 |
$options_site_url = esc_url( network_admin_url( 'settings.php' ) ); |
16 | 1501 |
|
9 | 1502 |
$msg = sprintf( |
16 | 1503 |
/* translators: New user notification email. 1: User login, 2: User IP address, 3: URL to Network Settings screen. */ |
9 | 1504 |
__( |
1505 |
'New User: %1$s |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1506 |
Remote IP address: %2$s |
0 | 1507 |
|
9 | 1508 |
Disable these notifications: %3$s' |
1509 |
), |
|
1510 |
$user->user_login, |
|
1511 |
wp_unslash( $_SERVER['REMOTE_ADDR'] ), |
|
1512 |
$options_site_url |
|
1513 |
); |
|
0 | 1514 |
|
5 | 1515 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1516 |
* Filters the message body of the new user activation email sent |
5 | 1517 |
* to the network administrator. |
1518 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1519 |
* @since MU (3.0.0) |
5 | 1520 |
* |
1521 |
* @param string $msg Email body. |
|
1522 |
* @param WP_User $user WP_User instance of the new user. |
|
1523 |
*/ |
|
0 | 1524 |
$msg = apply_filters( 'newuser_notify_siteadmin', $msg, $user ); |
16 | 1525 |
|
1526 |
/* translators: New user notification email subject. %s: User login. */ |
|
9 | 1527 |
wp_mail( $email, sprintf( __( 'New User Registration: %s' ), $user->user_login ), $msg ); |
16 | 1528 |
|
0 | 1529 |
return true; |
1530 |
} |
|
1531 |
||
1532 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1533 |
* Checks whether a site name is already taken. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1534 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1535 |
* The name is the site's subdomain or the site's subdirectory |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1536 |
* path depending on the network settings. |
0 | 1537 |
* |
1538 |
* Used during the new site registration process to ensure |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1539 |
* that each site name is unique. |
0 | 1540 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1541 |
* @since MU (3.0.0) |
0 | 1542 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1543 |
* @param string $domain The domain to be checked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1544 |
* @param string $path The path to be checked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1545 |
* @param int $network_id Optional. Network ID. Relevant only on multi-network installations. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1546 |
* @return int|null The site ID if the site name exists, null otherwise. |
0 | 1547 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1548 |
function domain_exists( $domain, $path, $network_id = 1 ) { |
9 | 1549 |
$path = trailingslashit( $path ); |
1550 |
$args = array( |
|
1551 |
'network_id' => $network_id, |
|
1552 |
'domain' => $domain, |
|
1553 |
'path' => $path, |
|
1554 |
'fields' => 'ids', |
|
1555 |
'number' => 1, |
|
1556 |
'update_site_meta_cache' => false, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1557 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1558 |
$result = get_sites( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1559 |
$result = array_shift( $result ); |
5 | 1560 |
|
1561 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1562 |
* Filters whether a site name is taken. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1563 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1564 |
* The name is the site's subdomain or the site's subdirectory |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1565 |
* path depending on the network settings. |
5 | 1566 |
* |
1567 |
* @since 3.5.0 |
|
1568 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1569 |
* @param int|null $result The site ID if the site name exists, null otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1570 |
* @param string $domain Domain to be checked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1571 |
* @param string $path Path to be checked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
* @param int $network_id Network ID. Relevant only on multi-network installations. |
5 | 1573 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1574 |
return apply_filters( 'domain_exists', $result, $domain, $path, $network_id ); |
0 | 1575 |
} |
1576 |
||
1577 |
/** |
|
5 | 1578 |
* Notify a user that their blog activation has been successful. |
0 | 1579 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1580 |
* Filter {@see 'wpmu_welcome_notification'} to disable or bypass. |
0 | 1581 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1582 |
* Filter {@see 'update_welcome_email'} and {@see 'update_welcome_subject'} to |
0 | 1583 |
* modify the content and subject line of the notification email. |
1584 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1585 |
* @since MU (3.0.0) |
0 | 1586 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1587 |
* @param int $blog_id Blog ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1588 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1589 |
* @param string $password User password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1590 |
* @param string $title Site title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1591 |
* @param array $meta Optional. Signup meta data. By default, contains the requested privacy setting and lang_id. |
0 | 1592 |
* @return bool |
1593 |
*/ |
|
1594 |
function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta = array() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1595 |
$current_network = get_network(); |
0 | 1596 |
|
5 | 1597 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1598 |
* Filters whether to bypass the welcome email after site activation. |
5 | 1599 |
* |
1600 |
* Returning false disables the welcome email. |
|
1601 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1602 |
* @since MU (3.0.0) |
5 | 1603 |
* |
1604 |
* @param int|bool $blog_id Blog ID. |
|
1605 |
* @param int $user_id User ID. |
|
1606 |
* @param string $password User password. |
|
1607 |
* @param string $title Site title. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1608 |
* @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
5 | 1609 |
*/ |
9 | 1610 |
if ( ! apply_filters( 'wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta ) ) { |
0 | 1611 |
return false; |
9 | 1612 |
} |
0 | 1613 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1614 |
$user = get_userdata( $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1615 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1616 |
$switched_locale = switch_to_locale( get_user_locale( $user ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1617 |
|
0 | 1618 |
$welcome_email = get_site_option( 'welcome_email' ); |
16 | 1619 |
if ( false == $welcome_email ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1620 |
/* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */ |
9 | 1621 |
$welcome_email = __( |
1622 |
'Howdy USERNAME, |
|
0 | 1623 |
|
1624 |
Your new SITE_NAME site has been successfully set up at: |
|
1625 |
BLOG_URL |
|
1626 |
||
1627 |
You can log in to the administrator account with the following information: |
|
5 | 1628 |
|
0 | 1629 |
Username: USERNAME |
1630 |
Password: PASSWORD |
|
1631 |
Log in here: BLOG_URLwp-login.php |
|
1632 |
||
1633 |
We hope you enjoy your new site. Thanks! |
|
1634 |
||
9 | 1635 |
--The Team @ SITE_NAME' |
1636 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1637 |
} |
0 | 1638 |
|
9 | 1639 |
$url = get_blogaddress_by_id( $blog_id ); |
0 | 1640 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1641 |
$welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email ); |
0 | 1642 |
$welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email ); |
1643 |
$welcome_email = str_replace( 'BLOG_URL', $url, $welcome_email ); |
|
1644 |
$welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email ); |
|
1645 |
$welcome_email = str_replace( 'PASSWORD', $password, $welcome_email ); |
|
1646 |
||
5 | 1647 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1648 |
* Filters the content of the welcome email after site activation. |
5 | 1649 |
* |
1650 |
* Content should be formatted for transmission via wp_mail(). |
|
1651 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1652 |
* @since MU (3.0.0) |
5 | 1653 |
* |
1654 |
* @param string $welcome_email Message body of the email. |
|
1655 |
* @param int $blog_id Blog ID. |
|
1656 |
* @param int $user_id User ID. |
|
1657 |
* @param string $password User password. |
|
1658 |
* @param string $title Site title. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1659 |
* @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
5 | 1660 |
*/ |
1661 |
$welcome_email = apply_filters( 'update_welcome_email', $welcome_email, $blog_id, $user_id, $password, $title, $meta ); |
|
16 | 1662 |
|
1663 |
$admin_email = get_site_option( 'admin_email' ); |
|
0 | 1664 |
|
16 | 1665 |
if ( '' === $admin_email ) { |
1666 |
$admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST ); |
|
9 | 1667 |
} |
0 | 1668 |
|
16 | 1669 |
$from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress'; |
9 | 1670 |
$message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
1671 |
$message = $welcome_email; |
|
0 | 1672 |
|
9 | 1673 |
if ( empty( $current_network->site_name ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1674 |
$current_network->site_name = 'WordPress'; |
9 | 1675 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1676 |
|
16 | 1677 |
/* translators: New site notification email subject. 1: Network title, 2: New site title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1678 |
$subject = __( 'New %1$s Site: %2$s' ); |
0 | 1679 |
|
5 | 1680 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1681 |
* Filters the subject of the welcome email after site activation. |
5 | 1682 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1683 |
* @since MU (3.0.0) |
5 | 1684 |
* |
1685 |
* @param string $subject Subject of the email. |
|
1686 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1687 |
$subject = apply_filters( 'update_welcome_subject', sprintf( $subject, $current_network->site_name, wp_unslash( $title ) ) ); |
16 | 1688 |
|
5 | 1689 |
wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1690 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1691 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1692 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1693 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1694 |
|
0 | 1695 |
return true; |
1696 |
} |
|
1697 |
||
1698 |
/** |
|
5 | 1699 |
* Notify a user that their account activation has been successful. |
0 | 1700 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1701 |
* Filter {@see 'wpmu_welcome_user_notification'} to disable or bypass. |
0 | 1702 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1703 |
* Filter {@see 'update_welcome_user_email'} and {@see 'update_welcome_user_subject'} to |
0 | 1704 |
* modify the content and subject line of the notification email. |
1705 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1706 |
* @since MU (3.0.0) |
0 | 1707 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1708 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1709 |
* @param string $password User password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1710 |
* @param array $meta Optional. Signup meta data. Default empty array. |
0 | 1711 |
* @return bool |
1712 |
*/ |
|
1713 |
function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1714 |
$current_network = get_network(); |
0 | 1715 |
|
5 | 1716 |
/** |
9 | 1717 |
* Filters whether to bypass the welcome email after user activation. |
5 | 1718 |
* |
1719 |
* Returning false disables the welcome email. |
|
1720 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1721 |
* @since MU (3.0.0) |
5 | 1722 |
* |
1723 |
* @param int $user_id User ID. |
|
1724 |
* @param string $password User password. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1725 |
* @param array $meta Signup meta data. Default empty array. |
5 | 1726 |
*/ |
9 | 1727 |
if ( ! apply_filters( 'wpmu_welcome_user_notification', $user_id, $password, $meta ) ) { |
0 | 1728 |
return false; |
9 | 1729 |
} |
0 | 1730 |
|
1731 |
$welcome_email = get_site_option( 'welcome_user_email' ); |
|
1732 |
||
1733 |
$user = get_userdata( $user_id ); |
|
1734 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1735 |
$switched_locale = switch_to_locale( get_user_locale( $user ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1736 |
|
5 | 1737 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1738 |
* Filters the content of the welcome email after user activation. |
5 | 1739 |
* |
1740 |
* Content should be formatted for transmission via wp_mail(). |
|
1741 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1742 |
* @since MU (3.0.0) |
5 | 1743 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1744 |
* @param string $welcome_email The message body of the account activation success email. |
5 | 1745 |
* @param int $user_id User ID. |
1746 |
* @param string $password User password. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1747 |
* @param array $meta Signup meta data. Default empty array. |
5 | 1748 |
*/ |
1749 |
$welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1750 |
$welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email ); |
0 | 1751 |
$welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email ); |
1752 |
$welcome_email = str_replace( 'PASSWORD', $password, $welcome_email ); |
|
1753 |
$welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email ); |
|
1754 |
||
1755 |
$admin_email = get_site_option( 'admin_email' ); |
|
1756 |
||
16 | 1757 |
if ( '' === $admin_email ) { |
1758 |
$admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST ); |
|
9 | 1759 |
} |
0 | 1760 |
|
16 | 1761 |
$from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress'; |
9 | 1762 |
$message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
1763 |
$message = $welcome_email; |
|
0 | 1764 |
|
9 | 1765 |
if ( empty( $current_network->site_name ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1766 |
$current_network->site_name = 'WordPress'; |
9 | 1767 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1768 |
|
16 | 1769 |
/* translators: New user notification email subject. 1: Network title, 2: New user login. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1770 |
$subject = __( 'New %1$s User: %2$s' ); |
0 | 1771 |
|
5 | 1772 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1773 |
* Filters the subject of the welcome email after user activation. |
5 | 1774 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1775 |
* @since MU (3.0.0) |
5 | 1776 |
* |
1777 |
* @param string $subject Subject of the email. |
|
1778 |
*/ |
|
9 | 1779 |
$subject = apply_filters( 'update_welcome_user_subject', sprintf( $subject, $current_network->site_name, $user->user_login ) ); |
16 | 1780 |
|
5 | 1781 |
wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1782 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1783 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1784 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1785 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1786 |
|
0 | 1787 |
return true; |
1788 |
} |
|
1789 |
||
1790 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1791 |
* Get the current network. |
0 | 1792 |
* |
1793 |
* Returns an object containing the 'id', 'domain', 'path', and 'site_name' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1794 |
* properties of the network being viewed. |
0 | 1795 |
* |
1796 |
* @see wpmu_current_site() |
|
1797 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1798 |
* @since MU (3.0.0) |
0 | 1799 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1800 |
* @global WP_Network $current_site |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1801 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1802 |
* @return WP_Network |
0 | 1803 |
*/ |
1804 |
function get_current_site() { |
|
1805 |
global $current_site; |
|
1806 |
return $current_site; |
|
1807 |
} |
|
1808 |
||
1809 |
/** |
|
1810 |
* Get a user's most recent post. |
|
1811 |
* |
|
1812 |
* Walks through each of a user's blogs to find the post with |
|
1813 |
* the most recent post_date_gmt. |
|
1814 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1815 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1816 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1817 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 1818 |
* |
1819 |
* @param int $user_id |
|
1820 |
* @return array Contains the blog_id, post_id, post_date_gmt, and post_gmt_ts |
|
1821 |
*/ |
|
1822 |
function get_most_recent_post_of_user( $user_id ) { |
|
1823 |
global $wpdb; |
|
1824 |
||
9 | 1825 |
$user_blogs = get_blogs_of_user( (int) $user_id ); |
0 | 1826 |
$most_recent_post = array(); |
1827 |
||
1828 |
// Walk through each blog and get the most recent post |
|
16 | 1829 |
// published by $user_id. |
0 | 1830 |
foreach ( (array) $user_blogs as $blog ) { |
9 | 1831 |
$prefix = $wpdb->get_blog_prefix( $blog->userblog_id ); |
1832 |
$recent_post = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author = %d AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1", $user_id ), ARRAY_A ); |
|
0 | 1833 |
|
16 | 1834 |
// Make sure we found a post. |
9 | 1835 |
if ( isset( $recent_post['ID'] ) ) { |
1836 |
$post_gmt_ts = strtotime( $recent_post['post_date_gmt'] ); |
|
0 | 1837 |
|
16 | 1838 |
/* |
1839 |
* If this is the first post checked |
|
1840 |
* or if this post is newer than the current recent post, |
|
1841 |
* make it the new most recent post. |
|
1842 |
*/ |
|
9 | 1843 |
if ( ! isset( $most_recent_post['post_gmt_ts'] ) || ( $post_gmt_ts > $most_recent_post['post_gmt_ts'] ) ) { |
0 | 1844 |
$most_recent_post = array( |
9 | 1845 |
'blog_id' => $blog->userblog_id, |
1846 |
'post_id' => $recent_post['ID'], |
|
1847 |
'post_date_gmt' => $recent_post['post_date_gmt'], |
|
1848 |
'post_gmt_ts' => $post_gmt_ts, |
|
0 | 1849 |
); |
1850 |
} |
|
1851 |
} |
|
1852 |
} |
|
1853 |
||
1854 |
return $most_recent_post; |
|
1855 |
} |
|
1856 |
||
16 | 1857 |
// |
1858 |
// Misc functions. |
|
1859 |
// |
|
0 | 1860 |
|
1861 |
/** |
|
16 | 1862 |
* Check an array of MIME types against a list of allowed types. |
0 | 1863 |
* |
1864 |
* WordPress ships with a set of allowed upload filetypes, |
|
1865 |
* which is defined in wp-includes/functions.php in |
|
1866 |
* get_allowed_mime_types(). This function is used to filter |
|
16 | 1867 |
* that list against the filetypes allowed provided by Multisite |
0 | 1868 |
* Super Admins at wp-admin/network/settings.php. |
1869 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1870 |
* @since MU (3.0.0) |
0 | 1871 |
* |
1872 |
* @param array $mimes |
|
1873 |
* @return array |
|
1874 |
*/ |
|
1875 |
function check_upload_mimes( $mimes ) { |
|
9 | 1876 |
$site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) ); |
5 | 1877 |
$site_mimes = array(); |
0 | 1878 |
foreach ( $site_exts as $ext ) { |
1879 |
foreach ( $mimes as $ext_pattern => $mime ) { |
|
16 | 1880 |
if ( '' !== $ext && false !== strpos( $ext_pattern, $ext ) ) { |
9 | 1881 |
$site_mimes[ $ext_pattern ] = $mime; |
1882 |
} |
|
0 | 1883 |
} |
1884 |
} |
|
1885 |
return $site_mimes; |
|
1886 |
} |
|
1887 |
||
1888 |
/** |
|
1889 |
* Update a blog's post count. |
|
1890 |
* |
|
1891 |
* WordPress MS stores a blog's post count as an option so as |
|
1892 |
* to avoid extraneous COUNTs when a blog's details are fetched |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1893 |
* with get_site(). This function is called when posts are published |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1894 |
* or unpublished to make sure the count stays current. |
0 | 1895 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1896 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1897 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1898 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1899 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1900 |
* @param string $deprecated Not used. |
0 | 1901 |
*/ |
1902 |
function update_posts_count( $deprecated = '' ) { |
|
1903 |
global $wpdb; |
|
1904 |
update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ) ); |
|
1905 |
} |
|
1906 |
||
1907 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1908 |
* Logs the user email, IP, and registration date of a new site. |
0 | 1909 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1910 |
* @since MU (3.0.0) |
9 | 1911 |
* @since 5.1.0 Parameters now support input from the {@see 'wp_initialize_site'} action. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1912 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1913 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 1914 |
* |
9 | 1915 |
* @param WP_Site|int $blog_id The new site's object or ID. |
1916 |
* @param int|array $user_id User ID, or array of arguments including 'user_id'. |
|
0 | 1917 |
*/ |
1918 |
function wpmu_log_new_registrations( $blog_id, $user_id ) { |
|
1919 |
global $wpdb; |
|
9 | 1920 |
|
1921 |
if ( is_object( $blog_id ) ) { |
|
1922 |
$blog_id = $blog_id->blog_id; |
|
1923 |
} |
|
1924 |
||
1925 |
if ( is_array( $user_id ) ) { |
|
1926 |
$user_id = ! empty( $user_id['user_id'] ) ? $user_id['user_id'] : 0; |
|
1927 |
} |
|
1928 |
||
0 | 1929 |
$user = get_userdata( (int) $user_id ); |
9 | 1930 |
if ( $user ) { |
1931 |
$wpdb->insert( |
|
1932 |
$wpdb->registration_log, |
|
1933 |
array( |
|
1934 |
'email' => $user->user_email, |
|
1935 |
'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ), |
|
1936 |
'blog_id' => $blog_id, |
|
1937 |
'date_registered' => current_time( 'mysql' ), |
|
1938 |
) |
|
1939 |
); |
|
1940 |
} |
|
0 | 1941 |
} |
1942 |
||
1943 |
/** |
|
1944 |
* Maintains a canonical list of terms by syncing terms created for each blog with the global terms table. |
|
1945 |
* |
|
1946 |
* @since 3.0.0 |
|
1947 |
* |
|
1948 |
* @see term_id_filter |
|
1949 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1950 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1951 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1952 |
* @param int $term_id An ID for a term on the current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1953 |
* @param string $deprecated Not used. |
0 | 1954 |
* @return int An ID from the global terms table mapped from $term_id. |
1955 |
*/ |
|
1956 |
function global_terms( $term_id, $deprecated = '' ) { |
|
1957 |
global $wpdb; |
|
1958 |
static $global_terms_recurse = null; |
|
1959 |
||
9 | 1960 |
if ( ! global_terms_enabled() ) { |
0 | 1961 |
return $term_id; |
9 | 1962 |
} |
0 | 1963 |
|
16 | 1964 |
// Prevent a race condition. |
0 | 1965 |
$recurse_start = false; |
16 | 1966 |
if ( null === $global_terms_recurse ) { |
9 | 1967 |
$recurse_start = true; |
0 | 1968 |
$global_terms_recurse = 1; |
1969 |
} elseif ( 10 < $global_terms_recurse++ ) { |
|
1970 |
return $term_id; |
|
1971 |
} |
|
1972 |
||
1973 |
$term_id = intval( $term_id ); |
|
9 | 1974 |
$c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) ); |
0 | 1975 |
|
1976 |
$global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) ); |
|
16 | 1977 |
if ( null == $global_id ) { |
0 | 1978 |
$used_global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE cat_ID = %d", $c->term_id ) ); |
1979 |
if ( null == $used_global_id ) { |
|
9 | 1980 |
$wpdb->insert( |
1981 |
$wpdb->sitecategories, |
|
1982 |
array( |
|
1983 |
'cat_ID' => $term_id, |
|
1984 |
'cat_name' => $c->name, |
|
1985 |
'category_nicename' => $c->slug, |
|
1986 |
) |
|
1987 |
); |
|
0 | 1988 |
$global_id = $wpdb->insert_id; |
9 | 1989 |
if ( empty( $global_id ) ) { |
0 | 1990 |
return $term_id; |
9 | 1991 |
} |
0 | 1992 |
} else { |
1993 |
$max_global_id = $wpdb->get_var( "SELECT MAX(cat_ID) FROM $wpdb->sitecategories" ); |
|
9 | 1994 |
$max_local_id = $wpdb->get_var( "SELECT MAX(term_id) FROM $wpdb->terms" ); |
0 | 1995 |
$new_global_id = max( $max_global_id, $max_local_id ) + mt_rand( 100, 400 ); |
9 | 1996 |
$wpdb->insert( |
1997 |
$wpdb->sitecategories, |
|
1998 |
array( |
|
1999 |
'cat_ID' => $new_global_id, |
|
2000 |
'cat_name' => $c->name, |
|
2001 |
'category_nicename' => $c->slug, |
|
2002 |
) |
|
2003 |
); |
|
0 | 2004 |
$global_id = $wpdb->insert_id; |
2005 |
} |
|
2006 |
} elseif ( $global_id != $term_id ) { |
|
5 | 2007 |
$local_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE term_id = %d", $global_id ) ); |
2008 |
if ( null != $local_id ) { |
|
2009 |
global_terms( $local_id ); |
|
2010 |
if ( 10 < $global_terms_recurse ) { |
|
0 | 2011 |
$global_id = $term_id; |
5 | 2012 |
} |
2013 |
} |
|
0 | 2014 |
} |
2015 |
||
2016 |
if ( $global_id != $term_id ) { |
|
9 | 2017 |
if ( get_option( 'default_category' ) == $term_id ) { |
0 | 2018 |
update_option( 'default_category', $global_id ); |
9 | 2019 |
} |
0 | 2020 |
|
9 | 2021 |
$wpdb->update( $wpdb->terms, array( 'term_id' => $global_id ), array( 'term_id' => $term_id ) ); |
2022 |
$wpdb->update( $wpdb->term_taxonomy, array( 'term_id' => $global_id ), array( 'term_id' => $term_id ) ); |
|
2023 |
$wpdb->update( $wpdb->term_taxonomy, array( 'parent' => $global_id ), array( 'parent' => $term_id ) ); |
|
0 | 2024 |
|
9 | 2025 |
clean_term_cache( $term_id ); |
0 | 2026 |
} |
9 | 2027 |
if ( $recurse_start ) { |
0 | 2028 |
$global_terms_recurse = null; |
9 | 2029 |
} |
0 | 2030 |
|
2031 |
return $global_id; |
|
2032 |
} |
|
2033 |
||
2034 |
/** |
|
2035 |
* Ensure that the current site's domain is listed in the allowed redirect host list. |
|
2036 |
* |
|
2037 |
* @see wp_validate_redirect() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2038 |
* @since MU (3.0.0) |
0 | 2039 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2040 |
* @param array|string $deprecated Not used. |
16 | 2041 |
* @return string[] { |
2042 |
* An array containing the current site's domain. |
|
2043 |
* |
|
2044 |
* @type string $0 The current site's domain. |
|
2045 |
* } |
|
0 | 2046 |
*/ |
2047 |
function redirect_this_site( $deprecated = '' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2048 |
return array( get_network()->domain ); |
0 | 2049 |
} |
2050 |
||
2051 |
/** |
|
2052 |
* Check whether an upload is too big. |
|
2053 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2054 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2055 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2056 |
* @blessed |
0 | 2057 |
* |
2058 |
* @param array $upload |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2059 |
* @return string|array If the upload is under the size limit, $upload is returned. Otherwise returns an error message. |
0 | 2060 |
*/ |
2061 |
function upload_is_file_too_big( $upload ) { |
|
9 | 2062 |
if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) ) { |
0 | 2063 |
return $upload; |
9 | 2064 |
} |
0 | 2065 |
|
9 | 2066 |
if ( strlen( $upload['bits'] ) > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) { |
16 | 2067 |
/* translators: %s: Maximum allowed file size in kilobytes. */ |
9 | 2068 |
return sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2069 |
} |
0 | 2070 |
|
2071 |
return $upload; |
|
2072 |
} |
|
2073 |
||
2074 |
/** |
|
2075 |
* Add a nonce field to the signup page. |
|
2076 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2077 |
* @since MU (3.0.0) |
0 | 2078 |
*/ |
2079 |
function signup_nonce_fields() { |
|
2080 |
$id = mt_rand(); |
|
2081 |
echo "<input type='hidden' name='signup_form_id' value='{$id}' />"; |
|
9 | 2082 |
wp_nonce_field( 'signup_form_' . $id, '_signup_form', false ); |
0 | 2083 |
} |
2084 |
||
2085 |
/** |
|
2086 |
* Process the signup nonce created in signup_nonce_fields(). |
|
2087 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2088 |
* @since MU (3.0.0) |
0 | 2089 |
* |
2090 |
* @param array $result |
|
2091 |
* @return array |
|
2092 |
*/ |
|
2093 |
function signup_nonce_check( $result ) { |
|
9 | 2094 |
if ( ! strpos( $_SERVER['PHP_SELF'], 'wp-signup.php' ) ) { |
0 | 2095 |
return $result; |
9 | 2096 |
} |
0 | 2097 |
|
9 | 2098 |
if ( ! wp_verify_nonce( $_POST['_signup_form'], 'signup_form_' . $_POST['signup_form_id'] ) ) { |
2099 |
$result['errors']->add( 'invalid_nonce', __( 'Unable to submit this form, please try again.' ) ); |
|
2100 |
} |
|
0 | 2101 |
|
2102 |
return $result; |
|
2103 |
} |
|
2104 |
||
2105 |
/** |
|
2106 |
* Correct 404 redirects when NOBLOGREDIRECT is defined. |
|
2107 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2108 |
* @since MU (3.0.0) |
0 | 2109 |
*/ |
2110 |
function maybe_redirect_404() { |
|
16 | 2111 |
if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) ) { |
2112 |
/** |
|
2113 |
* Filters the redirect URL for 404s on the main site. |
|
2114 |
* |
|
2115 |
* The filter is only evaluated if the NOBLOGREDIRECT constant is defined. |
|
2116 |
* |
|
2117 |
* @since 3.0.0 |
|
2118 |
* |
|
2119 |
* @param string $no_blog_redirect The redirect URL defined in NOBLOGREDIRECT. |
|
2120 |
*/ |
|
2121 |
$destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT ); |
|
2122 |
||
2123 |
if ( $destination ) { |
|
2124 |
if ( '%siteurl%' === $destination ) { |
|
2125 |
$destination = network_home_url(); |
|
2126 |
} |
|
2127 |
||
2128 |
wp_redirect( $destination ); |
|
2129 |
exit; |
|
9 | 2130 |
} |
0 | 2131 |
} |
2132 |
} |
|
2133 |
||
2134 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2135 |
* Add a new user to a blog by visiting /newbloguser/{key}/. |
0 | 2136 |
* |
2137 |
* This will only work when the user's details are saved as an option |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2138 |
* keyed as 'new_user_{key}', where '{key}' is a hash generated for the user to be |
0 | 2139 |
* added, as when a user is invited through the regular WP Add User interface. |
2140 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2141 |
* @since MU (3.0.0) |
0 | 2142 |
*/ |
2143 |
function maybe_add_existing_user_to_blog() { |
|
9 | 2144 |
if ( false === strpos( $_SERVER['REQUEST_URI'], '/newbloguser/' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2145 |
return; |
9 | 2146 |
} |
0 | 2147 |
|
9 | 2148 |
$parts = explode( '/', $_SERVER['REQUEST_URI'] ); |
2149 |
$key = array_pop( $parts ); |
|
0 | 2150 |
|
16 | 2151 |
if ( '' === $key ) { |
0 | 2152 |
$key = array_pop( $parts ); |
9 | 2153 |
} |
0 | 2154 |
|
2155 |
$details = get_option( 'new_user_' . $key ); |
|
9 | 2156 |
if ( ! empty( $details ) ) { |
0 | 2157 |
delete_option( 'new_user_' . $key ); |
9 | 2158 |
} |
0 | 2159 |
|
9 | 2160 |
if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) { |
16 | 2161 |
wp_die( |
2162 |
sprintf( |
|
2163 |
/* translators: %s: Home URL. */ |
|
2164 |
__( 'An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.' ), |
|
2165 |
home_url() |
|
2166 |
) |
|
2167 |
); |
|
9 | 2168 |
} |
0 | 2169 |
|
16 | 2170 |
wp_die( |
2171 |
sprintf( |
|
2172 |
/* translators: 1: Home URL, 2: Admin URL. */ |
|
2173 |
__( 'You have been added to this site. Please visit the <a href="%1$s">homepage</a> or <a href="%2$s">log in</a> using your username and password.' ), |
|
2174 |
home_url(), |
|
2175 |
admin_url() |
|
2176 |
), |
|
2177 |
__( 'WordPress › Success' ), |
|
2178 |
array( 'response' => 200 ) |
|
2179 |
); |
|
0 | 2180 |
} |
2181 |
||
2182 |
/** |
|
2183 |
* Add a user to a blog based on details from maybe_add_existing_user_to_blog(). |
|
2184 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2185 |
* @since MU (3.0.0) |
0 | 2186 |
* |
16 | 2187 |
* @param array $details { |
2188 |
* User details. Must at least contain values for the keys listed below. |
|
2189 |
* |
|
2190 |
* @type int $user_id The ID of the user being added to the current blog. |
|
2191 |
* @type string $role The role to be assigned to the user. |
|
2192 |
* } |
|
2193 |
* @return true|WP_Error|void True on success or a WP_Error object if the user doesn't exist |
|
2194 |
* or could not be added. Void if $details array was not provided. |
|
0 | 2195 |
*/ |
2196 |
function add_existing_user_to_blog( $details = false ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2197 |
if ( is_array( $details ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2198 |
$blog_id = get_current_blog_id(); |
9 | 2199 |
$result = add_user_to_blog( $blog_id, $details['user_id'], $details['role'] ); |
0 | 2200 |
|
5 | 2201 |
/** |
2202 |
* Fires immediately after an existing user is added to a site. |
|
2203 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2204 |
* @since MU (3.0.0) |
5 | 2205 |
* |
16 | 2206 |
* @param int $user_id User ID. |
2207 |
* @param true|WP_Error $result True on success or a WP_Error object if the user doesn't exist |
|
2208 |
* or could not be added. |
|
5 | 2209 |
*/ |
2210 |
do_action( 'added_existing_user', $details['user_id'], $result ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2211 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2212 |
return $result; |
0 | 2213 |
} |
2214 |
} |
|
2215 |
||
2216 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2217 |
* Adds a newly created user to the appropriate blog |
0 | 2218 |
* |
2219 |
* To add a user in general, use add_user_to_blog(). This function |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2220 |
* is specifically hooked into the {@see 'wpmu_activate_user'} action. |
0 | 2221 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2222 |
* @since MU (3.0.0) |
16 | 2223 |
* |
0 | 2224 |
* @see add_user_to_blog() |
2225 |
* |
|
16 | 2226 |
* @param int $user_id User ID. |
2227 |
* @param string $password User password. Ignored. |
|
2228 |
* @param array $meta Signup meta data. |
|
0 | 2229 |
*/ |
2230 |
function add_new_user_to_blog( $user_id, $password, $meta ) { |
|
9 | 2231 |
if ( ! empty( $meta['add_to_blog'] ) ) { |
2232 |
$blog_id = $meta['add_to_blog']; |
|
2233 |
$role = $meta['new_role']; |
|
16 | 2234 |
remove_user_from_blog( $user_id, get_network()->site_id ); // Remove user from main blog. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2235 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2236 |
$result = add_user_to_blog( $blog_id, $user_id, $role ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2237 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2238 |
if ( ! is_wp_error( $result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2239 |
update_user_meta( $user_id, 'primary_blog', $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2240 |
} |
0 | 2241 |
} |
2242 |
} |
|
2243 |
||
2244 |
/** |
|
2245 |
* Correct From host on outgoing mail to match the site domain |
|
2246 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2247 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2248 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2249 |
* @param PHPMailer $phpmailer The PHPMailer instance (passed by reference). |
0 | 2250 |
*/ |
2251 |
function fix_phpmailer_messageid( $phpmailer ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2252 |
$phpmailer->Hostname = get_network()->domain; |
0 | 2253 |
} |
2254 |
||
2255 |
/** |
|
2256 |
* Check to see whether a user is marked as a spammer, based on user login. |
|
2257 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2258 |
* @since MU (3.0.0) |
0 | 2259 |
* |
2260 |
* @param string|WP_User $user Optional. Defaults to current user. WP_User object, |
|
9 | 2261 |
* or user login name as a string. |
0 | 2262 |
* @return bool |
2263 |
*/ |
|
2264 |
function is_user_spammy( $user = null ) { |
|
9 | 2265 |
if ( ! ( $user instanceof WP_User ) ) { |
5 | 2266 |
if ( $user ) { |
0 | 2267 |
$user = get_user_by( 'login', $user ); |
5 | 2268 |
} else { |
0 | 2269 |
$user = wp_get_current_user(); |
5 | 2270 |
} |
0 | 2271 |
} |
2272 |
||
2273 |
return $user && isset( $user->spam ) && 1 == $user->spam; |
|
2274 |
} |
|
2275 |
||
2276 |
/** |
|
2277 |
* Update this blog's 'public' setting in the global blogs table. |
|
2278 |
* |
|
2279 |
* Public blogs have a setting of 1, private blogs are 0. |
|
2280 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2281 |
* @since MU (3.0.0) |
0 | 2282 |
* |
2283 |
* @param int $old_value |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2284 |
* @param int $value The new public value |
0 | 2285 |
*/ |
2286 |
function update_blog_public( $old_value, $value ) { |
|
2287 |
update_blog_status( get_current_blog_id(), 'public', (int) $value ); |
|
2288 |
} |
|
2289 |
||
2290 |
/** |
|
2291 |
* Check whether users can self-register, based on Network settings. |
|
2292 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2293 |
* @since MU (3.0.0) |
0 | 2294 |
* |
2295 |
* @return bool |
|
2296 |
*/ |
|
2297 |
function users_can_register_signup_filter() { |
|
9 | 2298 |
$registration = get_site_option( 'registration' ); |
16 | 2299 |
return ( 'all' === $registration || 'user' === $registration ); |
0 | 2300 |
} |
2301 |
||
2302 |
/** |
|
2303 |
* Ensure that the welcome message is not empty. Currently unused. |
|
2304 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2305 |
* @since MU (3.0.0) |
0 | 2306 |
* |
2307 |
* @param string $text |
|
2308 |
* @return string |
|
2309 |
*/ |
|
2310 |
function welcome_user_msg_filter( $text ) { |
|
9 | 2311 |
if ( ! $text ) { |
0 | 2312 |
remove_filter( 'site_option_welcome_user_email', 'welcome_user_msg_filter' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2313 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2314 |
/* translators: Do not translate USERNAME, PASSWORD, LOGINLINK, SITE_NAME: those are placeholders. */ |
9 | 2315 |
$text = __( |
2316 |
'Howdy USERNAME, |
|
0 | 2317 |
|
2318 |
Your new account is set up. |
|
2319 |
||
2320 |
You can log in with the following information: |
|
2321 |
Username: USERNAME |
|
2322 |
Password: PASSWORD |
|
2323 |
LOGINLINK |
|
2324 |
||
2325 |
Thanks! |
|
2326 |
||
9 | 2327 |
--The Team @ SITE_NAME' |
2328 |
); |
|
0 | 2329 |
update_site_option( 'welcome_user_email', $text ); |
2330 |
} |
|
2331 |
return $text; |
|
2332 |
} |
|
2333 |
||
2334 |
/** |
|
2335 |
* Whether to force SSL on content. |
|
2336 |
* |
|
2337 |
* @since 2.8.5 |
|
2338 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2339 |
* @param bool $force |
0 | 2340 |
* @return bool True if forced, false if not forced. |
2341 |
*/ |
|
2342 |
function force_ssl_content( $force = '' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2343 |
static $forced_content = false; |
0 | 2344 |
|
16 | 2345 |
if ( ! $force ) { |
9 | 2346 |
$old_forced = $forced_content; |
0 | 2347 |
$forced_content = $force; |
2348 |
return $old_forced; |
|
2349 |
} |
|
2350 |
||
2351 |
return $forced_content; |
|
2352 |
} |
|
2353 |
||
2354 |
/** |
|
2355 |
* Formats a URL to use https. |
|
2356 |
* |
|
2357 |
* Useful as a filter. |
|
2358 |
* |
|
2359 |
* @since 2.8.5 |
|
2360 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2361 |
* @param string $url URL |
0 | 2362 |
* @return string URL with https as the scheme |
2363 |
*/ |
|
16 | 2364 |
function filter_SSL( $url ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
9 | 2365 |
if ( ! is_string( $url ) ) { |
16 | 2366 |
return get_bloginfo( 'url' ); // Return home blog URL with proper scheme. |
9 | 2367 |
} |
0 | 2368 |
|
9 | 2369 |
if ( force_ssl_content() && is_ssl() ) { |
0 | 2370 |
$url = set_url_scheme( $url, 'https' ); |
9 | 2371 |
} |
0 | 2372 |
|
2373 |
return $url; |
|
2374 |
} |
|
2375 |
||
2376 |
/** |
|
2377 |
* Schedule update of the network-wide counts for the current network. |
|
2378 |
* |
|
2379 |
* @since 3.1.0 |
|
2380 |
*/ |
|
2381 |
function wp_schedule_update_network_counts() { |
|
9 | 2382 |
if ( ! is_main_site() ) { |
0 | 2383 |
return; |
9 | 2384 |
} |
0 | 2385 |
|
9 | 2386 |
if ( ! wp_next_scheduled( 'update_network_counts' ) && ! wp_installing() ) { |
2387 |
wp_schedule_event( time(), 'twicedaily', 'update_network_counts' ); |
|
2388 |
} |
|
0 | 2389 |
} |
2390 |
||
2391 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2392 |
* Update the network-wide counts for the current network. |
0 | 2393 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2394 |
* @since 3.1.0 |
9 | 2395 |
* @since 4.8.0 The `$network_id` parameter has been added. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2396 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2397 |
* @param int|null $network_id ID of the network. Default is the current network. |
0 | 2398 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2399 |
function wp_update_network_counts( $network_id = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2400 |
wp_update_network_user_counts( $network_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2401 |
wp_update_network_site_counts( $network_id ); |
0 | 2402 |
} |
2403 |
||
2404 |
/** |
|
2405 |
* Update the count of sites for the current network. |
|
2406 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2407 |
* If enabled through the {@see 'enable_live_network_counts'} filter, update the sites count |
0 | 2408 |
* on a network when a site is created or its status is updated. |
2409 |
* |
|
2410 |
* @since 3.7.0 |
|
9 | 2411 |
* @since 4.8.0 The `$network_id` parameter has been added. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2412 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2413 |
* @param int|null $network_id ID of the network. Default is the current network. |
0 | 2414 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2415 |
function wp_maybe_update_network_site_counts( $network_id = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2416 |
$is_small_network = ! wp_is_large_network( 'sites', $network_id ); |
0 | 2417 |
|
2418 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2419 |
* Filters whether to update network site or user counts when a new site is created. |
0 | 2420 |
* |
2421 |
* @since 3.7.0 |
|
2422 |
* |
|
5 | 2423 |
* @see wp_is_large_network() |
2424 |
* |
|
2425 |
* @param bool $small_network Whether the network is considered small. |
|
0 | 2426 |
* @param string $context Context. Either 'users' or 'sites'. |
2427 |
*/ |
|
9 | 2428 |
if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'sites' ) ) { |
0 | 2429 |
return; |
9 | 2430 |
} |
0 | 2431 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2432 |
wp_update_network_site_counts( $network_id ); |
0 | 2433 |
} |
2434 |
||
2435 |
/** |
|
2436 |
* Update the network-wide users count. |
|
2437 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2438 |
* If enabled through the {@see 'enable_live_network_counts'} filter, update the users count |
0 | 2439 |
* on a network when a user is created or its status is updated. |
2440 |
* |
|
2441 |
* @since 3.7.0 |
|
9 | 2442 |
* @since 4.8.0 The `$network_id` parameter has been added. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2443 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2444 |
* @param int|null $network_id ID of the network. Default is the current network. |
0 | 2445 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2446 |
function wp_maybe_update_network_user_counts( $network_id = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2447 |
$is_small_network = ! wp_is_large_network( 'users', $network_id ); |
0 | 2448 |
|
5 | 2449 |
/** This filter is documented in wp-includes/ms-functions.php */ |
9 | 2450 |
if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) { |
0 | 2451 |
return; |
9 | 2452 |
} |
0 | 2453 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2454 |
wp_update_network_user_counts( $network_id ); |
0 | 2455 |
} |
2456 |
||
2457 |
/** |
|
2458 |
* Update the network-wide site count. |
|
2459 |
* |
|
2460 |
* @since 3.7.0 |
|
9 | 2461 |
* @since 4.8.0 The `$network_id` parameter has been added. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2462 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2463 |
* @param int|null $network_id ID of the network. Default is the current network. |
0 | 2464 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2465 |
function wp_update_network_site_counts( $network_id = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2466 |
$network_id = (int) $network_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2467 |
if ( ! $network_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2468 |
$network_id = get_current_network_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2469 |
} |
0 | 2470 |
|
9 | 2471 |
$count = get_sites( |
2472 |
array( |
|
2473 |
'network_id' => $network_id, |
|
2474 |
'spam' => 0, |
|
2475 |
'deleted' => 0, |
|
2476 |
'archived' => 0, |
|
2477 |
'count' => true, |
|
2478 |
'update_site_meta_cache' => false, |
|
2479 |
) |
|
2480 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2481 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2482 |
update_network_option( $network_id, 'blog_count', $count ); |
0 | 2483 |
} |
2484 |
||
2485 |
/** |
|
2486 |
* Update the network-wide user count. |
|
2487 |
* |
|
2488 |
* @since 3.7.0 |
|
9 | 2489 |
* @since 4.8.0 The `$network_id` parameter has been added. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2490 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2491 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2492 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2493 |
* @param int|null $network_id ID of the network. Default is the current network. |
0 | 2494 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2495 |
function wp_update_network_user_counts( $network_id = null ) { |
0 | 2496 |
global $wpdb; |
2497 |
||
2498 |
$count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2499 |
update_network_option( $network_id, 'user_count', $count ); |
0 | 2500 |
} |
2501 |
||
2502 |
/** |
|
16 | 2503 |
* Returns the space used by the current site. |
0 | 2504 |
* |
2505 |
* @since 3.5.0 |
|
2506 |
* |
|
16 | 2507 |
* @return int Used space in megabytes. |
0 | 2508 |
*/ |
2509 |
function get_space_used() { |
|
5 | 2510 |
/** |
16 | 2511 |
* Filters the amount of storage space used by the current site, in megabytes. |
5 | 2512 |
* |
2513 |
* @since 3.5.0 |
|
2514 |
* |
|
16 | 2515 |
* @param int|false $space_used The amount of used space, in megabytes. Default false. |
5 | 2516 |
*/ |
0 | 2517 |
$space_used = apply_filters( 'pre_get_space_used', false ); |
2518 |
if ( false === $space_used ) { |
|
2519 |
$upload_dir = wp_upload_dir(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2520 |
$space_used = get_dirsize( $upload_dir['basedir'] ) / MB_IN_BYTES; |
0 | 2521 |
} |
2522 |
||
2523 |
return $space_used; |
|
2524 |
} |
|
2525 |
||
2526 |
/** |
|
2527 |
* Returns the upload quota for the current blog. |
|
2528 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2529 |
* @since MU (3.0.0) |
0 | 2530 |
* |
2531 |
* @return int Quota in megabytes |
|
2532 |
*/ |
|
2533 |
function get_space_allowed() { |
|
2534 |
$space_allowed = get_option( 'blog_upload_space' ); |
|
2535 |
||
9 | 2536 |
if ( ! is_numeric( $space_allowed ) ) { |
0 | 2537 |
$space_allowed = get_site_option( 'blog_upload_space' ); |
9 | 2538 |
} |
0 | 2539 |
|
9 | 2540 |
if ( ! is_numeric( $space_allowed ) ) { |
0 | 2541 |
$space_allowed = 100; |
9 | 2542 |
} |
0 | 2543 |
|
5 | 2544 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2545 |
* Filters the upload quota for the current site. |
5 | 2546 |
* |
2547 |
* @since 3.7.0 |
|
2548 |
* |
|
2549 |
* @param int $space_allowed Upload quota in megabytes for the current blog. |
|
2550 |
*/ |
|
0 | 2551 |
return apply_filters( 'get_space_allowed', $space_allowed ); |
2552 |
} |
|
2553 |
||
2554 |
/** |
|
2555 |
* Determines if there is any upload space left in the current blog's quota. |
|
2556 |
* |
|
2557 |
* @since 3.0.0 |
|
2558 |
* |
|
2559 |
* @return int of upload space available in bytes |
|
2560 |
*/ |
|
2561 |
function get_upload_space_available() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2562 |
$allowed = get_space_allowed(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2563 |
if ( $allowed < 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2564 |
$allowed = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2565 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2566 |
$space_allowed = $allowed * MB_IN_BYTES; |
9 | 2567 |
if ( get_site_option( 'upload_space_check_disabled' ) ) { |
0 | 2568 |
return $space_allowed; |
9 | 2569 |
} |
0 | 2570 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2571 |
$space_used = get_space_used() * MB_IN_BYTES; |
0 | 2572 |
|
9 | 2573 |
if ( ( $space_allowed - $space_used ) <= 0 ) { |
0 | 2574 |
return 0; |
9 | 2575 |
} |
0 | 2576 |
|
2577 |
return $space_allowed - $space_used; |
|
2578 |
} |
|
2579 |
||
2580 |
/** |
|
2581 |
* Determines if there is any upload space left in the current blog's quota. |
|
2582 |
* |
|
2583 |
* @since 3.0.0 |
|
2584 |
* @return bool True if space is available, false otherwise. |
|
2585 |
*/ |
|
2586 |
function is_upload_space_available() { |
|
9 | 2587 |
if ( get_site_option( 'upload_space_check_disabled' ) ) { |
0 | 2588 |
return true; |
9 | 2589 |
} |
0 | 2590 |
|
2591 |
return (bool) get_upload_space_available(); |
|
2592 |
} |
|
2593 |
||
2594 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2595 |
* Filters the maximum upload file size allowed, in bytes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2596 |
* |
0 | 2597 |
* @since 3.0.0 |
2598 |
* |
|
16 | 2599 |
* @param int $size Upload size limit in bytes. |
2600 |
* @return int Upload size limit in bytes. |
|
0 | 2601 |
*/ |
2602 |
function upload_size_limit_filter( $size ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2603 |
$fileupload_maxk = KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ); |
9 | 2604 |
if ( get_site_option( 'upload_space_check_disabled' ) ) { |
0 | 2605 |
return min( $size, $fileupload_maxk ); |
9 | 2606 |
} |
0 | 2607 |
|
2608 |
return min( $size, $fileupload_maxk, get_upload_space_available() ); |
|
2609 |
} |
|
2610 |
||
2611 |
/** |
|
2612 |
* Whether or not we have a large network. |
|
2613 |
* |
|
2614 |
* The default criteria for a large network is either more than 10,000 users or more than 10,000 sites. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2615 |
* Plugins can alter this criteria using the {@see 'wp_is_large_network'} filter. |
0 | 2616 |
* |
2617 |
* @since 3.3.0 |
|
9 | 2618 |
* @since 4.8.0 The `$network_id` parameter has been added. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2619 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2620 |
* @param string $using 'sites or 'users'. Default is 'sites'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2621 |
* @param int|null $network_id ID of the network. Default is the current network. |
0 | 2622 |
* @return bool True if the network meets the criteria for large. False otherwise. |
2623 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2624 |
function wp_is_large_network( $using = 'sites', $network_id = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2625 |
$network_id = (int) $network_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2626 |
if ( ! $network_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2627 |
$network_id = get_current_network_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2628 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2629 |
|
16 | 2630 |
if ( 'users' === $using ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2631 |
$count = get_user_count( $network_id ); |
5 | 2632 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2633 |
* Filters whether the network is considered large. |
5 | 2634 |
* |
2635 |
* @since 3.3.0 |
|
9 | 2636 |
* @since 4.8.0 The `$network_id` parameter has been added. |
5 | 2637 |
* |
2638 |
* @param bool $is_large_network Whether the network has more than 10000 users or sites. |
|
2639 |
* @param string $component The component to count. Accepts 'users', or 'sites'. |
|
2640 |
* @param int $count The count of items for the component. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2641 |
* @param int $network_id The ID of the network being checked. |
5 | 2642 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2643 |
return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count, $network_id ); |
0 | 2644 |
} |
2645 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2646 |
$count = get_blog_count( $network_id ); |
16 | 2647 |
|
5 | 2648 |
/** This filter is documented in wp-includes/ms-functions.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2649 |
return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count, $network_id ); |
0 | 2650 |
} |
2651 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2652 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2653 |
* Retrieves a list of reserved site on a sub-directory Multisite installation. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2654 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2655 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2656 |
* |
16 | 2657 |
* @return string[] Array of reserved names. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2658 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2659 |
function get_subdirectory_reserved_names() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2660 |
$names = array( |
9 | 2661 |
'page', |
2662 |
'comments', |
|
2663 |
'blog', |
|
2664 |
'files', |
|
2665 |
'feed', |
|
2666 |
'wp-admin', |
|
2667 |
'wp-content', |
|
2668 |
'wp-includes', |
|
2669 |
'wp-json', |
|
2670 |
'embed', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2671 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2672 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2673 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2674 |
* Filters reserved site names on a sub-directory Multisite installation. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2675 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2676 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2677 |
* @since 4.4.0 'wp-admin', 'wp-content', 'wp-includes', 'wp-json', and 'embed' were added |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2678 |
* to the reserved names list. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2679 |
* |
16 | 2680 |
* @param string[] $subdirectory_reserved_names Array of reserved names. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2681 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2682 |
return apply_filters( 'subdirectory_reserved_names', $names ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2683 |
} |
0 | 2684 |
|
2685 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2686 |
* Send a confirmation request email when a change of network admin email address is attempted. |
0 | 2687 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2688 |
* The new network admin address will not become active until confirmed. |
0 | 2689 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2690 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2691 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2692 |
* @param string $old_value The old network admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2693 |
* @param string $value The proposed new network admin email address. |
0 | 2694 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2695 |
function update_network_option_new_admin_email( $old_value, $value ) { |
16 | 2696 |
if ( get_site_option( 'admin_email' ) === $value || ! is_email( $value ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2697 |
return; |
0 | 2698 |
} |
2699 |
||
9 | 2700 |
$hash = md5( $value . time() . mt_rand() ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2701 |
$new_admin_email = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2702 |
'hash' => $hash, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2703 |
'newemail' => $value, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2704 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2705 |
update_site_option( 'network_admin_hash', $new_admin_email ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2706 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2707 |
$switched_locale = switch_to_locale( get_user_locale() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2708 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2709 |
/* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
9 | 2710 |
$email_text = __( |
2711 |
'Howdy ###USERNAME###, |
|
0 | 2712 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2713 |
You recently requested to have the network admin email address on |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2714 |
your network changed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2715 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2716 |
If this is correct, please click on the following link to change it: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2717 |
###ADMIN_URL### |
0 | 2718 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2719 |
You can safely ignore and delete this email if you do not want to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2720 |
take this action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2721 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2722 |
This email has been sent to ###EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2723 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2724 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2725 |
All at ###SITENAME### |
9 | 2726 |
###SITEURL###' |
2727 |
); |
|
0 | 2728 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2729 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2730 |
* Filters the text of the email sent when a change of network admin email address is attempted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2731 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2732 |
* The following strings have a special meaning and will get replaced dynamically: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2733 |
* ###USERNAME### The current user's username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2734 |
* ###ADMIN_URL### The link to click on to confirm the email change. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2735 |
* ###EMAIL### The proposed new network admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2736 |
* ###SITENAME### The name of the network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2737 |
* ###SITEURL### The URL to the network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2738 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2739 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2740 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2741 |
* @param string $email_text Text in the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2742 |
* @param array $new_admin_email { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2743 |
* Data relating to the new network admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2744 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2745 |
* @type string $hash The secure hash used in the confirmation link URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2746 |
* @type string $newemail The proposed new network admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2747 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2748 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2749 |
$content = apply_filters( 'new_network_admin_email_content', $email_text, $new_admin_email ); |
0 | 2750 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2751 |
$current_user = wp_get_current_user(); |
9 | 2752 |
$content = str_replace( '###USERNAME###', $current_user->user_login, $content ); |
2753 |
$content = str_replace( '###ADMIN_URL###', esc_url( network_admin_url( 'settings.php?network_admin_hash=' . $hash ) ), $content ); |
|
2754 |
$content = str_replace( '###EMAIL###', $value, $content ); |
|
2755 |
$content = str_replace( '###SITENAME###', wp_specialchars_decode( get_site_option( 'site_name' ), ENT_QUOTES ), $content ); |
|
2756 |
$content = str_replace( '###SITEURL###', network_home_url(), $content ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2757 |
|
16 | 2758 |
wp_mail( |
2759 |
$value, |
|
2760 |
sprintf( |
|
2761 |
/* translators: Email change notification email subject. %s: Network title. */ |
|
2762 |
__( '[%s] Network Admin Email Change Request' ), |
|
2763 |
wp_specialchars_decode( get_site_option( 'site_name' ), ENT_QUOTES ) |
|
2764 |
), |
|
2765 |
$content |
|
2766 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2767 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2768 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2769 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2770 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2771 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2772 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2773 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2774 |
* Send an email to the old network admin email address when the network admin email address changes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2775 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2776 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2777 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2778 |
* @param string $option_name The relevant database option name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2779 |
* @param string $new_email The new network admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2780 |
* @param string $old_email The old network admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2781 |
* @param int $network_id ID of the network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2782 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2783 |
function wp_network_admin_email_change_notification( $option_name, $new_email, $old_email, $network_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2784 |
$send = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2785 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2786 |
// Don't send the notification to the default 'admin_email' value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2787 |
if ( 'you@example.com' === $old_email ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2788 |
$send = false; |
0 | 2789 |
} |
2790 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2791 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2792 |
* Filters whether to send the network admin email change notification email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2793 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2794 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2795 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2796 |
* @param bool $send Whether to send the email notification. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2797 |
* @param string $old_email The old network admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2798 |
* @param string $new_email The new network admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2799 |
* @param int $network_id ID of the network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2800 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2801 |
$send = apply_filters( 'send_network_admin_email_change_email', $send, $old_email, $new_email, $network_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2802 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2803 |
if ( ! $send ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2804 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2805 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2806 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2807 |
/* translators: Do not translate OLD_EMAIL, NEW_EMAIL, SITENAME, SITEURL: those are placeholders. */ |
9 | 2808 |
$email_change_text = __( |
2809 |
'Hi, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2810 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2811 |
This notice confirms that the network admin email address was changed on ###SITENAME###. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2812 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2813 |
The new network admin email address is ###NEW_EMAIL###. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2814 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2815 |
This email has been sent to ###OLD_EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2816 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2817 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2818 |
All at ###SITENAME### |
9 | 2819 |
###SITEURL###' |
2820 |
); |
|
0 | 2821 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2822 |
$email_change_email = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2823 |
'to' => $old_email, |
16 | 2824 |
/* translators: Network admin email change notification email subject. %s: Network title. */ |
9 | 2825 |
'subject' => __( '[%s] Network Admin Email Changed' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2826 |
'message' => $email_change_text, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2827 |
'headers' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2828 |
); |
16 | 2829 |
// Get network name. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2830 |
$network_name = wp_specialchars_decode( get_site_option( 'site_name' ), ENT_QUOTES ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2831 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2832 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2833 |
* Filters the contents of the email notification sent when the network admin email address is changed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2834 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2835 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2836 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2837 |
* @param array $email_change_email { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2838 |
* Used to build wp_mail(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2839 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2840 |
* @type string $to The intended recipient. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2841 |
* @type string $subject The subject of the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2842 |
* @type string $message The content of the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2843 |
* The following strings have a special meaning and will get replaced dynamically: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2844 |
* - ###OLD_EMAIL### The old network admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2845 |
* - ###NEW_EMAIL### The new network admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2846 |
* - ###SITENAME### The name of the network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2847 |
* - ###SITEURL### The URL to the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2848 |
* @type string $headers Headers. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2849 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2850 |
* @param string $old_email The old network admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2851 |
* @param string $new_email The new network admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2852 |
* @param int $network_id ID of the network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2853 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2854 |
$email_change_email = apply_filters( 'network_admin_email_change_email', $email_change_email, $old_email, $new_email, $network_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2855 |
|
9 | 2856 |
$email_change_email['message'] = str_replace( '###OLD_EMAIL###', $old_email, $email_change_email['message'] ); |
2857 |
$email_change_email['message'] = str_replace( '###NEW_EMAIL###', $new_email, $email_change_email['message'] ); |
|
2858 |
$email_change_email['message'] = str_replace( '###SITENAME###', $network_name, $email_change_email['message'] ); |
|
2859 |
$email_change_email['message'] = str_replace( '###SITEURL###', home_url(), $email_change_email['message'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2860 |
|
9 | 2861 |
wp_mail( |
2862 |
$email_change_email['to'], |
|
2863 |
sprintf( |
|
2864 |
$email_change_email['subject'], |
|
2865 |
$network_name |
|
2866 |
), |
|
2867 |
$email_change_email['message'], |
|
2868 |
$email_change_email['headers'] |
|
2869 |
); |
|
0 | 2870 |
} |