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