author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* These functions can be replaced via plugins. If plugins do not redefine these |
|
4 |
* functions, then these will be used instead. |
|
5 |
* |
|
6 |
* @package WordPress |
|
7 |
*/ |
|
8 |
||
9 | 9 |
if ( ! function_exists( 'wp_set_current_user' ) ) : |
10 |
/** |
|
11 |
* Changes the current user by ID or name. |
|
12 |
* |
|
13 |
* Set $id to null and specify a name if you do not know a user's ID. |
|
14 |
* |
|
15 |
* Some WordPress functionality is based on the current user and not based on |
|
16 |
* the signed in user. Therefore, it opens the ability to edit and perform |
|
17 |
* actions on users who aren't signed in. |
|
18 |
* |
|
19 |
* @since 2.0.3 |
|
16 | 20 |
* |
9 | 21 |
* @global WP_User $current_user The current user object which holds the user data. |
22 |
* |
|
19 | 23 |
* @param int|null $id User ID. |
24 |
* @param string $name User's username. |
|
25 |
* @return WP_User Current user User object. |
|
9 | 26 |
*/ |
27 |
function wp_set_current_user( $id, $name = '' ) { |
|
28 |
global $current_user; |
|
0 | 29 |
|
9 | 30 |
// If `$id` matches the current user, there is nothing to do. |
31 |
if ( isset( $current_user ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
&& ( $current_user instanceof WP_User ) |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
33 |
&& ( $id === $current_user->ID ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
&& ( null !== $id ) |
9 | 35 |
) { |
36 |
return $current_user; |
|
37 |
} |
|
38 |
||
39 |
$current_user = new WP_User( $id, $name ); |
|
40 |
||
41 |
setup_userdata( $current_user->ID ); |
|
42 |
||
43 |
/** |
|
44 |
* Fires after the current user is set. |
|
45 |
* |
|
46 |
* @since 2.0.1 |
|
47 |
*/ |
|
48 |
do_action( 'set_current_user' ); |
|
49 |
||
0 | 50 |
return $current_user; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
} |
0 | 52 |
endif; |
53 |
||
9 | 54 |
if ( ! function_exists( 'wp_get_current_user' ) ) : |
55 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
56 |
* Retrieves the current user object. |
9 | 57 |
* |
58 |
* Will set the current user, if the current user is not set. The current user |
|
59 |
* will be set to the logged-in person. If no user is logged-in, then it will |
|
60 |
* set the current user to 0, which is invalid and won't have any permissions. |
|
61 |
* |
|
62 |
* @since 2.0.3 |
|
63 |
* |
|
64 |
* @see _wp_get_current_user() |
|
65 |
* @global WP_User $current_user Checks if the current user is set. |
|
66 |
* |
|
67 |
* @return WP_User Current WP_User instance. |
|
68 |
*/ |
|
69 |
function wp_get_current_user() { |
|
70 |
return _wp_get_current_user(); |
|
71 |
} |
|
0 | 72 |
endif; |
73 |
||
9 | 74 |
if ( ! function_exists( 'get_userdata' ) ) : |
75 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
76 |
* Retrieves user info by user ID. |
9 | 77 |
* |
78 |
* @since 0.71 |
|
79 |
* |
|
80 |
* @param int $user_id User ID |
|
81 |
* @return WP_User|false WP_User object on success, false on failure. |
|
82 |
*/ |
|
83 |
function get_userdata( $user_id ) { |
|
84 |
return get_user_by( 'id', $user_id ); |
|
85 |
} |
|
0 | 86 |
endif; |
87 |
||
9 | 88 |
if ( ! function_exists( 'get_user_by' ) ) : |
89 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
90 |
* Retrieves user info by a given field. |
9 | 91 |
* |
92 |
* @since 2.8.0 |
|
93 |
* @since 4.4.0 Added 'ID' as an alias of 'id' for the `$field` parameter. |
|
18 | 94 |
* |
95 |
* @global WP_User $current_user The current user object which holds the user data. |
|
9 | 96 |
* |
97 |
* @param string $field The field to retrieve the user with. id | ID | slug | email | login. |
|
98 |
* @param int|string $value A value for $field. A user ID, slug, email address, or login name. |
|
99 |
* @return WP_User|false WP_User object on success, false on failure. |
|
100 |
*/ |
|
101 |
function get_user_by( $field, $value ) { |
|
102 |
$userdata = WP_User::get_data_by( $field, $value ); |
|
0 | 103 |
|
9 | 104 |
if ( ! $userdata ) { |
105 |
return false; |
|
106 |
} |
|
0 | 107 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
108 |
$user = new WP_User(); |
9 | 109 |
$user->init( $userdata ); |
0 | 110 |
|
9 | 111 |
return $user; |
112 |
} |
|
0 | 113 |
endif; |
114 |
||
9 | 115 |
if ( ! function_exists( 'cache_users' ) ) : |
116 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
117 |
* Retrieves info for user lists to prevent multiple queries by get_userdata(). |
9 | 118 |
* |
119 |
* @since 3.0.0 |
|
120 |
* |
|
121 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
122 |
* |
|
19 | 123 |
* @param int[] $user_ids User ID numbers list |
9 | 124 |
*/ |
125 |
function cache_users( $user_ids ) { |
|
126 |
global $wpdb; |
|
0 | 127 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
128 |
update_meta_cache( 'user', $user_ids ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
129 |
|
9 | 130 |
$clean = _get_non_cached_ids( $user_ids, 'users' ); |
0 | 131 |
|
9 | 132 |
if ( empty( $clean ) ) { |
133 |
return; |
|
134 |
} |
|
0 | 135 |
|
9 | 136 |
$list = implode( ',', $clean ); |
0 | 137 |
|
9 | 138 |
$users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" ); |
0 | 139 |
|
9 | 140 |
foreach ( $users as $user ) { |
141 |
update_user_caches( $user ); |
|
142 |
} |
|
0 | 143 |
} |
144 |
endif; |
|
145 |
||
9 | 146 |
if ( ! function_exists( 'wp_mail' ) ) : |
5 | 147 |
/** |
16 | 148 |
* Sends an email, similar to PHP's mail function. |
9 | 149 |
* |
150 |
* A true return value does not automatically mean that the user received the |
|
151 |
* email successfully. It just only means that the method used was able to |
|
152 |
* process the request without any errors. |
|
153 |
* |
|
16 | 154 |
* The default content type is `text/plain` which does not allow using HTML. |
9 | 155 |
* However, you can set the content type of the email by using the |
156 |
* {@see 'wp_mail_content_type'} filter. |
|
157 |
* |
|
158 |
* The default charset is based on the charset used on the blog. The charset can |
|
159 |
* be set using the {@see 'wp_mail_charset'} filter. |
|
160 |
* |
|
161 |
* @since 1.2.1 |
|
18 | 162 |
* @since 5.5.0 is_email() is used for email validation, |
163 |
* instead of PHPMailer's default validator. |
|
9 | 164 |
* |
16 | 165 |
* @global PHPMailer\PHPMailer\PHPMailer $phpmailer |
5 | 166 |
* |
18 | 167 |
* @param string|string[] $to Array or comma-separated list of email addresses to send message. |
168 |
* @param string $subject Email subject. |
|
169 |
* @param string $message Message contents. |
|
170 |
* @param string|string[] $headers Optional. Additional headers. |
|
171 |
* @param string|string[] $attachments Optional. Paths to files to attach. |
|
172 |
* @return bool Whether the email was sent successfully. |
|
5 | 173 |
*/ |
9 | 174 |
function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { |
16 | 175 |
// Compact the input, apply the filters, and extract them back out. |
5 | 176 |
|
9 | 177 |
/** |
178 |
* Filters the wp_mail() arguments. |
|
179 |
* |
|
180 |
* @since 2.2.0 |
|
181 |
* |
|
18 | 182 |
* @param array $args { |
183 |
* Array of the `wp_mail()` arguments. |
|
184 |
* |
|
185 |
* @type string|string[] $to Array or comma-separated list of email addresses to send message. |
|
186 |
* @type string $subject Email subject. |
|
187 |
* @type string $message Message contents. |
|
188 |
* @type string|string[] $headers Additional headers. |
|
189 |
* @type string|string[] $attachments Paths to files to attach. |
|
190 |
* } |
|
9 | 191 |
*/ |
192 |
$atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ); |
|
0 | 193 |
|
18 | 194 |
/** |
195 |
* Filters whether to preempt sending an email. |
|
196 |
* |
|
197 |
* Returning a non-null value will short-circuit {@see wp_mail()}, returning |
|
198 |
* that value instead. A boolean return value should be used to indicate whether |
|
199 |
* the email was successfully sent. |
|
200 |
* |
|
201 |
* @since 5.7.0 |
|
202 |
* |
|
203 |
* @param null|bool $return Short-circuit return value. |
|
204 |
* @param array $atts { |
|
205 |
* Array of the `wp_mail()` arguments. |
|
206 |
* |
|
207 |
* @type string|string[] $to Array or comma-separated list of email addresses to send message. |
|
208 |
* @type string $subject Email subject. |
|
209 |
* @type string $message Message contents. |
|
210 |
* @type string|string[] $headers Additional headers. |
|
211 |
* @type string|string[] $attachments Paths to files to attach. |
|
212 |
* } |
|
213 |
*/ |
|
214 |
$pre_wp_mail = apply_filters( 'pre_wp_mail', null, $atts ); |
|
215 |
||
216 |
if ( null !== $pre_wp_mail ) { |
|
217 |
return $pre_wp_mail; |
|
218 |
} |
|
219 |
||
9 | 220 |
if ( isset( $atts['to'] ) ) { |
221 |
$to = $atts['to']; |
|
222 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
|
9 | 224 |
if ( ! is_array( $to ) ) { |
225 |
$to = explode( ',', $to ); |
|
226 |
} |
|
5 | 227 |
|
9 | 228 |
if ( isset( $atts['subject'] ) ) { |
229 |
$subject = $atts['subject']; |
|
230 |
} |
|
5 | 231 |
|
9 | 232 |
if ( isset( $atts['message'] ) ) { |
233 |
$message = $atts['message']; |
|
234 |
} |
|
5 | 235 |
|
9 | 236 |
if ( isset( $atts['headers'] ) ) { |
237 |
$headers = $atts['headers']; |
|
238 |
} |
|
5 | 239 |
|
9 | 240 |
if ( isset( $atts['attachments'] ) ) { |
241 |
$attachments = $atts['attachments']; |
|
242 |
} |
|
0 | 243 |
|
9 | 244 |
if ( ! is_array( $attachments ) ) { |
245 |
$attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) ); |
|
246 |
} |
|
247 |
global $phpmailer; |
|
248 |
||
16 | 249 |
// (Re)create it, if it's gone missing. |
250 |
if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) ) { |
|
251 |
require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php'; |
|
252 |
require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php'; |
|
253 |
require_once ABSPATH . WPINC . '/PHPMailer/Exception.php'; |
|
254 |
$phpmailer = new PHPMailer\PHPMailer\PHPMailer( true ); |
|
255 |
||
256 |
$phpmailer::$validator = static function ( $email ) { |
|
257 |
return (bool) is_email( $email ); |
|
258 |
}; |
|
9 | 259 |
} |
0 | 260 |
|
16 | 261 |
// Headers. |
262 |
$cc = array(); |
|
263 |
$bcc = array(); |
|
264 |
$reply_to = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
|
9 | 266 |
if ( empty( $headers ) ) { |
267 |
$headers = array(); |
|
0 | 268 |
} else { |
9 | 269 |
if ( ! is_array( $headers ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
270 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
271 |
* Explode the headers out, so this function can take |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
272 |
* both string headers and an array of headers. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
273 |
*/ |
9 | 274 |
$tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) ); |
275 |
} else { |
|
276 |
$tempheaders = $headers; |
|
277 |
} |
|
278 |
$headers = array(); |
|
0 | 279 |
|
16 | 280 |
// If it's actually got contents. |
9 | 281 |
if ( ! empty( $tempheaders ) ) { |
16 | 282 |
// Iterate through the raw headers. |
9 | 283 |
foreach ( (array) $tempheaders as $header ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
284 |
if ( ! str_contains( $header, ':' ) ) { |
9 | 285 |
if ( false !== stripos( $header, 'boundary=' ) ) { |
286 |
$parts = preg_split( '/boundary=/i', trim( $header ) ); |
|
287 |
$boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) ); |
|
288 |
} |
|
289 |
continue; |
|
0 | 290 |
} |
16 | 291 |
// Explode them out. |
9 | 292 |
list( $name, $content ) = explode( ':', trim( $header ), 2 ); |
0 | 293 |
|
16 | 294 |
// Cleanup crew. |
9 | 295 |
$name = trim( $name ); |
296 |
$content = trim( $content ); |
|
0 | 297 |
|
9 | 298 |
switch ( strtolower( $name ) ) { |
16 | 299 |
// Mainly for legacy -- process a "From:" header if it's there. |
9 | 300 |
case 'from': |
301 |
$bracket_pos = strpos( $content, '<' ); |
|
16 | 302 |
if ( false !== $bracket_pos ) { |
9 | 303 |
// Text before the bracketed email is the "From" name. |
304 |
if ( $bracket_pos > 0 ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
305 |
$from_name = substr( $content, 0, $bracket_pos ); |
9 | 306 |
$from_name = str_replace( '"', '', $from_name ); |
307 |
$from_name = trim( $from_name ); |
|
308 |
} |
|
0 | 309 |
|
9 | 310 |
$from_email = substr( $content, $bracket_pos + 1 ); |
311 |
$from_email = str_replace( '>', '', $from_email ); |
|
312 |
$from_email = trim( $from_email ); |
|
5 | 313 |
|
9 | 314 |
// Avoid setting an empty $from_email. |
315 |
} elseif ( '' !== trim( $content ) ) { |
|
316 |
$from_email = trim( $content ); |
|
0 | 317 |
} |
9 | 318 |
break; |
319 |
case 'content-type': |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
320 |
if ( str_contains( $content, ';' ) ) { |
9 | 321 |
list( $type, $charset_content ) = explode( ';', $content ); |
322 |
$content_type = trim( $type ); |
|
323 |
if ( false !== stripos( $charset_content, 'charset=' ) ) { |
|
324 |
$charset = trim( str_replace( array( 'charset=', '"' ), '', $charset_content ) ); |
|
325 |
} elseif ( false !== stripos( $charset_content, 'boundary=' ) ) { |
|
326 |
$boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) ); |
|
327 |
$charset = ''; |
|
328 |
} |
|
5 | 329 |
|
9 | 330 |
// Avoid setting an empty $content_type. |
331 |
} elseif ( '' !== trim( $content ) ) { |
|
332 |
$content_type = trim( $content ); |
|
333 |
} |
|
334 |
break; |
|
335 |
case 'cc': |
|
336 |
$cc = array_merge( (array) $cc, explode( ',', $content ) ); |
|
337 |
break; |
|
338 |
case 'bcc': |
|
339 |
$bcc = array_merge( (array) $bcc, explode( ',', $content ) ); |
|
340 |
break; |
|
341 |
case 'reply-to': |
|
342 |
$reply_to = array_merge( (array) $reply_to, explode( ',', $content ) ); |
|
343 |
break; |
|
344 |
default: |
|
16 | 345 |
// Add it to our grand headers array. |
9 | 346 |
$headers[ trim( $name ) ] = trim( $content ); |
347 |
break; |
|
348 |
} |
|
0 | 349 |
} |
350 |
} |
|
351 |
} |
|
9 | 352 |
|
16 | 353 |
// Empty out the values that may be set. |
9 | 354 |
$phpmailer->clearAllRecipients(); |
355 |
$phpmailer->clearAttachments(); |
|
356 |
$phpmailer->clearCustomHeaders(); |
|
357 |
$phpmailer->clearReplyTos(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
358 |
$phpmailer->Body = ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
359 |
$phpmailer->AltBody = ''; |
9 | 360 |
|
16 | 361 |
// Set "From" name and email. |
362 |
||
363 |
// If we don't have a name from the input headers. |
|
9 | 364 |
if ( ! isset( $from_name ) ) { |
365 |
$from_name = 'WordPress'; |
|
366 |
} |
|
0 | 367 |
|
16 | 368 |
/* |
369 |
* If we don't have an email from the input headers, default to wordpress@$sitename |
|
370 |
* Some hosts will block outgoing mail from this address if it doesn't exist, |
|
371 |
* but there's no easy alternative. Defaulting to admin_email might appear to be |
|
372 |
* another option, but some hosts may refuse to relay mail from an unknown domain. |
|
373 |
* See https://core.trac.wordpress.org/ticket/5007. |
|
9 | 374 |
*/ |
375 |
if ( ! isset( $from_email ) ) { |
|
376 |
// Get the site domain and get rid of www. |
|
19 | 377 |
$sitename = wp_parse_url( network_home_url(), PHP_URL_HOST ); |
378 |
$from_email = 'wordpress@'; |
|
379 |
||
380 |
if ( null !== $sitename ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
381 |
if ( str_starts_with( $sitename, 'www.' ) ) { |
19 | 382 |
$sitename = substr( $sitename, 4 ); |
383 |
} |
|
384 |
||
385 |
$from_email .= $sitename; |
|
9 | 386 |
} |
387 |
} |
|
388 |
||
389 |
/** |
|
390 |
* Filters the email address to send from. |
|
391 |
* |
|
392 |
* @since 2.2.0 |
|
393 |
* |
|
394 |
* @param string $from_email Email address to send from. |
|
395 |
*/ |
|
396 |
$from_email = apply_filters( 'wp_mail_from', $from_email ); |
|
0 | 397 |
|
9 | 398 |
/** |
399 |
* Filters the name to associate with the "from" email address. |
|
400 |
* |
|
401 |
* @since 2.3.0 |
|
402 |
* |
|
403 |
* @param string $from_name Name associated with the "from" email address. |
|
404 |
*/ |
|
405 |
$from_name = apply_filters( 'wp_mail_from_name', $from_name ); |
|
406 |
||
407 |
try { |
|
408 |
$phpmailer->setFrom( $from_email, $from_name, false ); |
|
16 | 409 |
} catch ( PHPMailer\PHPMailer\Exception $e ) { |
9 | 410 |
$mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' ); |
411 |
$mail_error_data['phpmailer_exception_code'] = $e->getCode(); |
|
412 |
||
413 |
/** This filter is documented in wp-includes/pluggable.php */ |
|
414 |
do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) ); |
|
415 |
||
416 |
return false; |
|
0 | 417 |
} |
418 |
||
16 | 419 |
// Set mail's subject and body. |
9 | 420 |
$phpmailer->Subject = $subject; |
421 |
$phpmailer->Body = $message; |
|
422 |
||
16 | 423 |
// Set destination addresses, using appropriate methods for handling addresses. |
9 | 424 |
$address_headers = compact( 'to', 'cc', 'bcc', 'reply_to' ); |
425 |
||
426 |
foreach ( $address_headers as $address_header => $addresses ) { |
|
427 |
if ( empty( $addresses ) ) { |
|
428 |
continue; |
|
429 |
} |
|
0 | 430 |
|
9 | 431 |
foreach ( (array) $addresses as $address ) { |
432 |
try { |
|
16 | 433 |
// Break $recipient into name and address parts if in the format "Foo <bar@baz.com>". |
9 | 434 |
$recipient_name = ''; |
5 | 435 |
|
9 | 436 |
if ( preg_match( '/(.*)<(.+)>/', $address, $matches ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
437 |
if ( count( $matches ) === 3 ) { |
9 | 438 |
$recipient_name = $matches[1]; |
439 |
$address = $matches[2]; |
|
440 |
} |
|
441 |
} |
|
0 | 442 |
|
9 | 443 |
switch ( $address_header ) { |
444 |
case 'to': |
|
445 |
$phpmailer->addAddress( $address, $recipient_name ); |
|
446 |
break; |
|
447 |
case 'cc': |
|
448 |
$phpmailer->addCc( $address, $recipient_name ); |
|
449 |
break; |
|
450 |
case 'bcc': |
|
451 |
$phpmailer->addBcc( $address, $recipient_name ); |
|
452 |
break; |
|
453 |
case 'reply_to': |
|
454 |
$phpmailer->addReplyTo( $address, $recipient_name ); |
|
455 |
break; |
|
456 |
} |
|
16 | 457 |
} catch ( PHPMailer\PHPMailer\Exception $e ) { |
9 | 458 |
continue; |
459 |
} |
|
460 |
} |
|
461 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
|
16 | 463 |
// Set to use PHP's mail(). |
9 | 464 |
$phpmailer->isMail(); |
0 | 465 |
|
16 | 466 |
// Set Content-Type and charset. |
467 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
468 |
// If we don't have a Content-Type from the input headers. |
9 | 469 |
if ( ! isset( $content_type ) ) { |
470 |
$content_type = 'text/plain'; |
|
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 |
|
9 | 473 |
/** |
474 |
* Filters the wp_mail() content type. |
|
475 |
* |
|
476 |
* @since 2.3.0 |
|
477 |
* |
|
478 |
* @param string $content_type Default wp_mail() content type. |
|
479 |
*/ |
|
480 |
$content_type = apply_filters( 'wp_mail_content_type', $content_type ); |
|
481 |
||
482 |
$phpmailer->ContentType = $content_type; |
|
483 |
||
16 | 484 |
// Set whether it's plaintext, depending on $content_type. |
485 |
if ( 'text/html' === $content_type ) { |
|
9 | 486 |
$phpmailer->isHTML( true ); |
487 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
|
16 | 489 |
// If we don't have a charset from the input headers. |
9 | 490 |
if ( ! isset( $charset ) ) { |
491 |
$charset = get_bloginfo( 'charset' ); |
|
492 |
} |
|
493 |
||
494 |
/** |
|
495 |
* Filters the default wp_mail() charset. |
|
496 |
* |
|
497 |
* @since 2.3.0 |
|
498 |
* |
|
499 |
* @param string $charset Default email charset. |
|
500 |
*/ |
|
501 |
$phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset ); |
|
502 |
||
16 | 503 |
// Set custom headers. |
9 | 504 |
if ( ! empty( $headers ) ) { |
505 |
foreach ( (array) $headers as $name => $content ) { |
|
16 | 506 |
// Only add custom headers not added automatically by PHPMailer. |
507 |
if ( ! in_array( $name, array( 'MIME-Version', 'X-Mailer' ), true ) ) { |
|
508 |
try { |
|
509 |
$phpmailer->addCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) ); |
|
510 |
} catch ( PHPMailer\PHPMailer\Exception $e ) { |
|
511 |
continue; |
|
512 |
} |
|
513 |
} |
|
9 | 514 |
} |
0 | 515 |
|
9 | 516 |
if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) { |
16 | 517 |
$phpmailer->addCustomHeader( sprintf( 'Content-Type: %s; boundary="%s"', $content_type, $boundary ) ); |
9 | 518 |
} |
519 |
} |
|
520 |
||
521 |
if ( ! empty( $attachments ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
522 |
foreach ( $attachments as $filename => $attachment ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
523 |
$filename = is_string( $filename ) ? $filename : ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
524 |
|
9 | 525 |
try { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
526 |
$phpmailer->addAttachment( $attachment, $filename ); |
16 | 527 |
} catch ( PHPMailer\PHPMailer\Exception $e ) { |
9 | 528 |
continue; |
0 | 529 |
} |
530 |
} |
|
531 |
} |
|
9 | 532 |
|
533 |
/** |
|
534 |
* Fires after PHPMailer is initialized. |
|
535 |
* |
|
536 |
* @since 2.2.0 |
|
537 |
* |
|
538 |
* @param PHPMailer $phpmailer The PHPMailer instance (passed by reference). |
|
539 |
*/ |
|
540 |
do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); |
|
541 |
||
19 | 542 |
$mail_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' ); |
543 |
||
9 | 544 |
// Send! |
545 |
try { |
|
19 | 546 |
$send = $phpmailer->send(); |
547 |
||
548 |
/** |
|
549 |
* Fires after PHPMailer has successfully sent an email. |
|
550 |
* |
|
551 |
* The firing of this action does not necessarily mean that the recipient(s) received the |
|
552 |
* email successfully. It only means that the `send` method above was able to |
|
553 |
* process the request without any errors. |
|
554 |
* |
|
555 |
* @since 5.9.0 |
|
556 |
* |
|
557 |
* @param array $mail_data { |
|
558 |
* An array containing the email recipient(s), subject, message, headers, and attachments. |
|
559 |
* |
|
560 |
* @type string[] $to Email addresses to send message. |
|
561 |
* @type string $subject Email subject. |
|
562 |
* @type string $message Message contents. |
|
563 |
* @type string[] $headers Additional headers. |
|
564 |
* @type string[] $attachments Paths to files to attach. |
|
565 |
* } |
|
566 |
*/ |
|
567 |
do_action( 'wp_mail_succeeded', $mail_data ); |
|
568 |
||
569 |
return $send; |
|
16 | 570 |
} catch ( PHPMailer\PHPMailer\Exception $e ) { |
19 | 571 |
$mail_data['phpmailer_exception_code'] = $e->getCode(); |
9 | 572 |
|
573 |
/** |
|
16 | 574 |
* Fires after a PHPMailer\PHPMailer\Exception is caught. |
9 | 575 |
* |
576 |
* @since 4.4.0 |
|
577 |
* |
|
16 | 578 |
* @param WP_Error $error A WP_Error object with the PHPMailer\PHPMailer\Exception message, and an array |
9 | 579 |
* containing the mail recipient, subject, message, headers, and attachments. |
580 |
*/ |
|
19 | 581 |
do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_data ) ); |
9 | 582 |
|
583 |
return false; |
|
584 |
} |
|
0 | 585 |
} |
9 | 586 |
endif; |
0 | 587 |
|
9 | 588 |
if ( ! function_exists( 'wp_authenticate' ) ) : |
5 | 589 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
590 |
* Authenticates a user, confirming the login credentials are valid. |
5 | 591 |
* |
9 | 592 |
* @since 2.5.0 |
593 |
* @since 4.5.0 `$username` now accepts an email address. |
|
5 | 594 |
* |
9 | 595 |
* @param string $username User's username or email address. |
596 |
* @param string $password User's password. |
|
597 |
* @return WP_User|WP_Error WP_User object if the credentials are valid, |
|
598 |
* otherwise WP_Error. |
|
5 | 599 |
*/ |
9 | 600 |
function wp_authenticate( $username, $password ) { |
601 |
$username = sanitize_user( $username ); |
|
602 |
$password = trim( $password ); |
|
0 | 603 |
|
9 | 604 |
/** |
605 |
* Filters whether a set of user login credentials are valid. |
|
606 |
* |
|
607 |
* A WP_User object is returned if the credentials authenticate a user. |
|
608 |
* WP_Error or null otherwise. |
|
609 |
* |
|
610 |
* @since 2.8.0 |
|
611 |
* @since 4.5.0 `$username` now accepts an email address. |
|
612 |
* |
|
613 |
* @param null|WP_User|WP_Error $user WP_User if the user is authenticated. |
|
614 |
* WP_Error or null otherwise. |
|
615 |
* @param string $username Username or email address. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
616 |
* @param string $password User password. |
9 | 617 |
*/ |
618 |
$user = apply_filters( 'authenticate', null, $username, $password ); |
|
5 | 619 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
620 |
if ( null === $user || false === $user ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
621 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
622 |
* TODO: What should the error message be? (Or would these even happen?) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
623 |
* Only needed if all authentication handlers fail to return anything. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
624 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
625 |
$user = new WP_Error( 'authentication_failed', __( '<strong>Error:</strong> Invalid username, email address or incorrect password.' ) ); |
0 | 626 |
} |
627 |
||
9 | 628 |
$ignore_codes = array( 'empty_username', 'empty_password' ); |
0 | 629 |
|
16 | 630 |
if ( is_wp_error( $user ) && ! in_array( $user->get_error_code(), $ignore_codes, true ) ) { |
631 |
$error = $user; |
|
632 |
||
9 | 633 |
/** |
634 |
* Fires after a user login has failed. |
|
635 |
* |
|
636 |
* @since 2.5.0 |
|
637 |
* @since 4.5.0 The value of `$username` can now be an email address. |
|
16 | 638 |
* @since 5.4.0 The `$error` parameter was added. |
9 | 639 |
* |
16 | 640 |
* @param string $username Username or email address. |
641 |
* @param WP_Error $error A WP_Error object with the authentication failure details. |
|
9 | 642 |
*/ |
16 | 643 |
do_action( 'wp_login_failed', $username, $error ); |
0 | 644 |
} |
9 | 645 |
|
646 |
return $user; |
|
0 | 647 |
} |
9 | 648 |
endif; |
0 | 649 |
|
9 | 650 |
if ( ! function_exists( 'wp_logout' ) ) : |
5 | 651 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
652 |
* Logs the current user out. |
5 | 653 |
* |
9 | 654 |
* @since 2.5.0 |
5 | 655 |
*/ |
9 | 656 |
function wp_logout() { |
16 | 657 |
$user_id = get_current_user_id(); |
658 |
||
9 | 659 |
wp_destroy_current_session(); |
660 |
wp_clear_auth_cookie(); |
|
16 | 661 |
wp_set_current_user( 0 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
662 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
663 |
/** |
16 | 664 |
* Fires after a user is logged out. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
665 |
* |
9 | 666 |
* @since 1.5.0 |
16 | 667 |
* @since 5.5.0 Added the `$user_id` parameter. |
668 |
* |
|
669 |
* @param int $user_id ID of the user that was logged out. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
670 |
*/ |
16 | 671 |
do_action( 'wp_logout', $user_id ); |
0 | 672 |
} |
673 |
endif; |
|
674 |
||
9 | 675 |
if ( ! function_exists( 'wp_validate_auth_cookie' ) ) : |
5 | 676 |
/** |
9 | 677 |
* Validates authentication cookie. |
678 |
* |
|
679 |
* The checks include making sure that the authentication cookie is set and |
|
680 |
* pulling in the contents (if $cookie is not used). |
|
681 |
* |
|
682 |
* Makes sure the cookie is not expired. Verifies the hash in cookie is what is |
|
683 |
* should be and compares the two. |
|
684 |
* |
|
685 |
* @since 2.5.0 |
|
686 |
* |
|
687 |
* @global int $login_grace_period |
|
5 | 688 |
* |
16 | 689 |
* @param string $cookie Optional. If used, will validate contents instead of cookie's. |
690 |
* @param string $scheme Optional. The cookie scheme to use: 'auth', 'secure_auth', or 'logged_in'. |
|
691 |
* @return int|false User ID if valid cookie, false if invalid. |
|
5 | 692 |
*/ |
9 | 693 |
function wp_validate_auth_cookie( $cookie = '', $scheme = '' ) { |
16 | 694 |
$cookie_elements = wp_parse_auth_cookie( $cookie, $scheme ); |
695 |
if ( ! $cookie_elements ) { |
|
9 | 696 |
/** |
697 |
* Fires if an authentication cookie is malformed. |
|
698 |
* |
|
699 |
* @since 2.7.0 |
|
700 |
* |
|
701 |
* @param string $cookie Malformed auth cookie. |
|
702 |
* @param string $scheme Authentication scheme. Values include 'auth', 'secure_auth', |
|
703 |
* or 'logged_in'. |
|
704 |
*/ |
|
705 |
do_action( 'auth_cookie_malformed', $cookie, $scheme ); |
|
706 |
return false; |
|
707 |
} |
|
708 |
||
16 | 709 |
$scheme = $cookie_elements['scheme']; |
710 |
$username = $cookie_elements['username']; |
|
711 |
$hmac = $cookie_elements['hmac']; |
|
712 |
$token = $cookie_elements['token']; |
|
713 |
$expired = $cookie_elements['expiration']; |
|
714 |
$expiration = $cookie_elements['expiration']; |
|
9 | 715 |
|
16 | 716 |
// Allow a grace period for POST and Ajax requests. |
717 |
if ( wp_doing_ajax() || 'POST' === $_SERVER['REQUEST_METHOD'] ) { |
|
9 | 718 |
$expired += HOUR_IN_SECONDS; |
719 |
} |
|
720 |
||
16 | 721 |
// Quick check to see if an honest cookie has expired. |
9 | 722 |
if ( $expired < time() ) { |
723 |
/** |
|
724 |
* Fires once an authentication cookie has expired. |
|
725 |
* |
|
726 |
* @since 2.7.0 |
|
727 |
* |
|
19 | 728 |
* @param string[] $cookie_elements { |
729 |
* Authentication cookie components. None of the components should be assumed |
|
730 |
* to be valid as they come directly from a client-provided cookie value. |
|
731 |
* |
|
732 |
* @type string $username User's username. |
|
733 |
* @type string $expiration The time the cookie expires as a UNIX timestamp. |
|
734 |
* @type string $token User's session token used. |
|
735 |
* @type string $hmac The security hash for the cookie. |
|
736 |
* @type string $scheme The cookie scheme to use. |
|
737 |
* } |
|
9 | 738 |
*/ |
739 |
do_action( 'auth_cookie_expired', $cookie_elements ); |
|
740 |
return false; |
|
741 |
} |
|
0 | 742 |
|
9 | 743 |
$user = get_user_by( 'login', $username ); |
744 |
if ( ! $user ) { |
|
745 |
/** |
|
746 |
* Fires if a bad username is entered in the user authentication process. |
|
747 |
* |
|
748 |
* @since 2.7.0 |
|
749 |
* |
|
19 | 750 |
* @param string[] $cookie_elements { |
751 |
* Authentication cookie components. None of the components should be assumed |
|
752 |
* to be valid as they come directly from a client-provided cookie value. |
|
753 |
* |
|
754 |
* @type string $username User's username. |
|
755 |
* @type string $expiration The time the cookie expires as a UNIX timestamp. |
|
756 |
* @type string $token User's session token used. |
|
757 |
* @type string $hmac The security hash for the cookie. |
|
758 |
* @type string $scheme The cookie scheme to use. |
|
759 |
* } |
|
9 | 760 |
*/ |
761 |
do_action( 'auth_cookie_bad_username', $cookie_elements ); |
|
762 |
return false; |
|
763 |
} |
|
764 |
||
765 |
$pass_frag = substr( $user->user_pass, 8, 4 ); |
|
766 |
||
767 |
$key = wp_hash( $username . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme ); |
|
768 |
||
769 |
// If ext/hash is not present, compat.php's hash_hmac() does not support sha256. |
|
770 |
$algo = function_exists( 'hash' ) ? 'sha256' : 'sha1'; |
|
771 |
$hash = hash_hmac( $algo, $username . '|' . $expiration . '|' . $token, $key ); |
|
0 | 772 |
|
9 | 773 |
if ( ! hash_equals( $hash, $hmac ) ) { |
774 |
/** |
|
775 |
* Fires if a bad authentication cookie hash is encountered. |
|
776 |
* |
|
777 |
* @since 2.7.0 |
|
778 |
* |
|
19 | 779 |
* @param string[] $cookie_elements { |
780 |
* Authentication cookie components. None of the components should be assumed |
|
781 |
* to be valid as they come directly from a client-provided cookie value. |
|
782 |
* |
|
783 |
* @type string $username User's username. |
|
784 |
* @type string $expiration The time the cookie expires as a UNIX timestamp. |
|
785 |
* @type string $token User's session token used. |
|
786 |
* @type string $hmac The security hash for the cookie. |
|
787 |
* @type string $scheme The cookie scheme to use. |
|
788 |
* } |
|
9 | 789 |
*/ |
790 |
do_action( 'auth_cookie_bad_hash', $cookie_elements ); |
|
791 |
return false; |
|
792 |
} |
|
0 | 793 |
|
9 | 794 |
$manager = WP_Session_Tokens::get_instance( $user->ID ); |
795 |
if ( ! $manager->verify( $token ) ) { |
|
16 | 796 |
/** |
797 |
* Fires if a bad session token is encountered. |
|
798 |
* |
|
799 |
* @since 4.0.0 |
|
800 |
* |
|
19 | 801 |
* @param string[] $cookie_elements { |
802 |
* Authentication cookie components. None of the components should be assumed |
|
803 |
* to be valid as they come directly from a client-provided cookie value. |
|
804 |
* |
|
805 |
* @type string $username User's username. |
|
806 |
* @type string $expiration The time the cookie expires as a UNIX timestamp. |
|
807 |
* @type string $token User's session token used. |
|
808 |
* @type string $hmac The security hash for the cookie. |
|
809 |
* @type string $scheme The cookie scheme to use. |
|
810 |
* } |
|
16 | 811 |
*/ |
9 | 812 |
do_action( 'auth_cookie_bad_session_token', $cookie_elements ); |
813 |
return false; |
|
814 |
} |
|
815 |
||
16 | 816 |
// Ajax/POST grace period set above. |
9 | 817 |
if ( $expiration < time() ) { |
818 |
$GLOBALS['login_grace_period'] = 1; |
|
819 |
} |
|
820 |
||
5 | 821 |
/** |
9 | 822 |
* Fires once an authentication cookie has been validated. |
5 | 823 |
* |
824 |
* @since 2.7.0 |
|
825 |
* |
|
19 | 826 |
* @param string[] $cookie_elements { |
827 |
* Authentication cookie components. |
|
828 |
* |
|
829 |
* @type string $username User's username. |
|
830 |
* @type string $expiration The time the cookie expires as a UNIX timestamp. |
|
831 |
* @type string $token User's session token used. |
|
832 |
* @type string $hmac The security hash for the cookie. |
|
833 |
* @type string $scheme The cookie scheme to use. |
|
834 |
* } |
|
16 | 835 |
* @param WP_User $user User object. |
5 | 836 |
*/ |
9 | 837 |
do_action( 'auth_cookie_valid', $cookie_elements, $user ); |
0 | 838 |
|
9 | 839 |
return $user->ID; |
0 | 840 |
} |
841 |
endif; |
|
842 |
||
9 | 843 |
if ( ! function_exists( 'wp_generate_auth_cookie' ) ) : |
5 | 844 |
/** |
16 | 845 |
* Generates authentication cookie contents. |
5 | 846 |
* |
847 |
* @since 2.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
* @since 4.0.0 The `$token` parameter was added. |
5 | 849 |
* |
16 | 850 |
* @param int $user_id User ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
* @param int $expiration The time the cookie expires as a UNIX timestamp. |
16 | 852 |
* @param string $scheme Optional. The cookie scheme to use: 'auth', 'secure_auth', or 'logged_in'. |
853 |
* Default 'auth'. |
|
854 |
* @param string $token User's session token to use for this cookie. |
|
9 | 855 |
* @return string Authentication cookie contents. Empty string if user does not exist. |
5 | 856 |
*/ |
9 | 857 |
function wp_generate_auth_cookie( $user_id, $expiration, $scheme = 'auth', $token = '' ) { |
858 |
$user = get_userdata( $user_id ); |
|
859 |
if ( ! $user ) { |
|
860 |
return ''; |
|
861 |
} |
|
862 |
||
863 |
if ( ! $token ) { |
|
864 |
$manager = WP_Session_Tokens::get_instance( $user_id ); |
|
865 |
$token = $manager->create( $expiration ); |
|
866 |
} |
|
867 |
||
868 |
$pass_frag = substr( $user->user_pass, 8, 4 ); |
|
869 |
||
870 |
$key = wp_hash( $user->user_login . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme ); |
|
0 | 871 |
|
9 | 872 |
// If ext/hash is not present, compat.php's hash_hmac() does not support sha256. |
873 |
$algo = function_exists( 'hash' ) ? 'sha256' : 'sha1'; |
|
874 |
$hash = hash_hmac( $algo, $user->user_login . '|' . $expiration . '|' . $token, $key ); |
|
875 |
||
876 |
$cookie = $user->user_login . '|' . $expiration . '|' . $token . '|' . $hash; |
|
0 | 877 |
|
9 | 878 |
/** |
879 |
* Filters the authentication cookie. |
|
880 |
* |
|
881 |
* @since 2.5.0 |
|
882 |
* @since 4.0.0 The `$token` parameter was added. |
|
883 |
* |
|
884 |
* @param string $cookie Authentication cookie. |
|
885 |
* @param int $user_id User ID. |
|
886 |
* @param int $expiration The time the cookie expires as a UNIX timestamp. |
|
887 |
* @param string $scheme Cookie scheme used. Accepts 'auth', 'secure_auth', or 'logged_in'. |
|
888 |
* @param string $token User's session token used. |
|
889 |
*/ |
|
890 |
return apply_filters( 'auth_cookie', $cookie, $user_id, $expiration, $scheme, $token ); |
|
0 | 891 |
} |
892 |
endif; |
|
893 |
||
9 | 894 |
if ( ! function_exists( 'wp_parse_auth_cookie' ) ) : |
895 |
/** |
|
16 | 896 |
* Parses a cookie into its components. |
9 | 897 |
* |
898 |
* @since 2.7.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
899 |
* @since 4.0.0 The `$token` element was added to the return value. |
9 | 900 |
* |
16 | 901 |
* @param string $cookie Authentication cookie. |
902 |
* @param string $scheme Optional. The cookie scheme to use: 'auth', 'secure_auth', or 'logged_in'. |
|
19 | 903 |
* @return string[]|false { |
904 |
* Authentication cookie components. None of the components should be assumed |
|
905 |
* to be valid as they come directly from a client-provided cookie value. If |
|
906 |
* the cookie value is malformed, false is returned. |
|
907 |
* |
|
908 |
* @type string $username User's username. |
|
909 |
* @type string $expiration The time the cookie expires as a UNIX timestamp. |
|
910 |
* @type string $token User's session token used. |
|
911 |
* @type string $hmac The security hash for the cookie. |
|
912 |
* @type string $scheme The cookie scheme to use. |
|
913 |
* } |
|
9 | 914 |
*/ |
915 |
function wp_parse_auth_cookie( $cookie = '', $scheme = '' ) { |
|
916 |
if ( empty( $cookie ) ) { |
|
917 |
switch ( $scheme ) { |
|
918 |
case 'auth': |
|
919 |
$cookie_name = AUTH_COOKIE; |
|
920 |
break; |
|
921 |
case 'secure_auth': |
|
922 |
$cookie_name = SECURE_AUTH_COOKIE; |
|
923 |
break; |
|
924 |
case 'logged_in': |
|
925 |
$cookie_name = LOGGED_IN_COOKIE; |
|
926 |
break; |
|
927 |
default: |
|
928 |
if ( is_ssl() ) { |
|
929 |
$cookie_name = SECURE_AUTH_COOKIE; |
|
930 |
$scheme = 'secure_auth'; |
|
931 |
} else { |
|
932 |
$cookie_name = AUTH_COOKIE; |
|
933 |
$scheme = 'auth'; |
|
934 |
} |
|
935 |
} |
|
5 | 936 |
|
9 | 937 |
if ( empty( $_COOKIE[ $cookie_name ] ) ) { |
938 |
return false; |
|
939 |
} |
|
940 |
$cookie = $_COOKIE[ $cookie_name ]; |
|
941 |
} |
|
0 | 942 |
|
9 | 943 |
$cookie_elements = explode( '|', $cookie ); |
944 |
if ( count( $cookie_elements ) !== 4 ) { |
|
945 |
return false; |
|
946 |
} |
|
947 |
||
948 |
list( $username, $expiration, $token, $hmac ) = $cookie_elements; |
|
949 |
||
950 |
return compact( 'username', 'expiration', 'token', 'hmac', 'scheme' ); |
|
5 | 951 |
} |
9 | 952 |
endif; |
5 | 953 |
|
9 | 954 |
if ( ! function_exists( 'wp_set_auth_cookie' ) ) : |
5 | 955 |
/** |
16 | 956 |
* Sets the authentication cookies based on user ID. |
5 | 957 |
* |
9 | 958 |
* The $remember parameter increases the time that the cookie will be kept. The |
959 |
* default the cookie is kept without remembering is two days. When $remember is |
|
960 |
* set, the cookies will be kept for 14 days or two weeks. |
|
5 | 961 |
* |
962 |
* @since 2.5.0 |
|
9 | 963 |
* @since 4.3.0 Added the `$token` parameter. |
5 | 964 |
* |
16 | 965 |
* @param int $user_id User ID. |
966 |
* @param bool $remember Whether to remember the user. |
|
967 |
* @param bool|string $secure Whether the auth cookie should only be sent over HTTPS. Default is an empty |
|
968 |
* string which means the value of `is_ssl()` will be used. |
|
969 |
* @param string $token Optional. User's session token to use for this cookie. |
|
5 | 970 |
*/ |
9 | 971 |
function wp_set_auth_cookie( $user_id, $remember = false, $secure = '', $token = '' ) { |
972 |
if ( $remember ) { |
|
973 |
/** |
|
974 |
* Filters the duration of the authentication cookie expiration period. |
|
975 |
* |
|
976 |
* @since 2.8.0 |
|
977 |
* |
|
978 |
* @param int $length Duration of the expiration period in seconds. |
|
979 |
* @param int $user_id User ID. |
|
980 |
* @param bool $remember Whether to remember the user login. Default false. |
|
981 |
*/ |
|
982 |
$expiration = time() + apply_filters( 'auth_cookie_expiration', 14 * DAY_IN_SECONDS, $user_id, $remember ); |
|
983 |
||
984 |
/* |
|
985 |
* Ensure the browser will continue to send the cookie after the expiration time is reached. |
|
986 |
* Needed for the login grace period in wp_validate_auth_cookie(). |
|
987 |
*/ |
|
988 |
$expire = $expiration + ( 12 * HOUR_IN_SECONDS ); |
|
989 |
} else { |
|
990 |
/** This filter is documented in wp-includes/pluggable.php */ |
|
991 |
$expiration = time() + apply_filters( 'auth_cookie_expiration', 2 * DAY_IN_SECONDS, $user_id, $remember ); |
|
992 |
$expire = 0; |
|
993 |
} |
|
994 |
||
995 |
if ( '' === $secure ) { |
|
996 |
$secure = is_ssl(); |
|
997 |
} |
|
998 |
||
16 | 999 |
// Front-end cookie is secure when the auth cookie is secure and the site's home URL uses HTTPS. |
9 | 1000 |
$secure_logged_in_cookie = $secure && 'https' === parse_url( get_option( 'home' ), PHP_URL_SCHEME ); |
1001 |
||
1002 |
/** |
|
16 | 1003 |
* Filters whether the auth cookie should only be sent over HTTPS. |
9 | 1004 |
* |
1005 |
* @since 3.1.0 |
|
1006 |
* |
|
16 | 1007 |
* @param bool $secure Whether the cookie should only be sent over HTTPS. |
9 | 1008 |
* @param int $user_id User ID. |
1009 |
*/ |
|
1010 |
$secure = apply_filters( 'secure_auth_cookie', $secure, $user_id ); |
|
1011 |
||
1012 |
/** |
|
16 | 1013 |
* Filters whether the logged in cookie should only be sent over HTTPS. |
9 | 1014 |
* |
1015 |
* @since 3.1.0 |
|
1016 |
* |
|
16 | 1017 |
* @param bool $secure_logged_in_cookie Whether the logged in cookie should only be sent over HTTPS. |
9 | 1018 |
* @param int $user_id User ID. |
16 | 1019 |
* @param bool $secure Whether the auth cookie should only be sent over HTTPS. |
9 | 1020 |
*/ |
1021 |
$secure_logged_in_cookie = apply_filters( 'secure_logged_in_cookie', $secure_logged_in_cookie, $user_id, $secure ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1022 |
|
9 | 1023 |
if ( $secure ) { |
1024 |
$auth_cookie_name = SECURE_AUTH_COOKIE; |
|
1025 |
$scheme = 'secure_auth'; |
|
1026 |
} else { |
|
1027 |
$auth_cookie_name = AUTH_COOKIE; |
|
1028 |
$scheme = 'auth'; |
|
1029 |
} |
|
1030 |
||
1031 |
if ( '' === $token ) { |
|
1032 |
$manager = WP_Session_Tokens::get_instance( $user_id ); |
|
1033 |
$token = $manager->create( $expiration ); |
|
1034 |
} |
|
1035 |
||
1036 |
$auth_cookie = wp_generate_auth_cookie( $user_id, $expiration, $scheme, $token ); |
|
1037 |
$logged_in_cookie = wp_generate_auth_cookie( $user_id, $expiration, 'logged_in', $token ); |
|
1038 |
||
1039 |
/** |
|
1040 |
* Fires immediately before the authentication cookie is set. |
|
1041 |
* |
|
1042 |
* @since 2.5.0 |
|
1043 |
* @since 4.9.0 The `$token` parameter was added. |
|
1044 |
* |
|
1045 |
* @param string $auth_cookie Authentication cookie value. |
|
1046 |
* @param int $expire The time the login grace period expires as a UNIX timestamp. |
|
1047 |
* Default is 12 hours past the cookie's expiration time. |
|
1048 |
* @param int $expiration The time when the authentication cookie expires as a UNIX timestamp. |
|
1049 |
* Default is 14 days from now. |
|
1050 |
* @param int $user_id User ID. |
|
1051 |
* @param string $scheme Authentication scheme. Values include 'auth' or 'secure_auth'. |
|
1052 |
* @param string $token User's session token to use for this cookie. |
|
1053 |
*/ |
|
1054 |
do_action( 'set_auth_cookie', $auth_cookie, $expire, $expiration, $user_id, $scheme, $token ); |
|
1055 |
||
1056 |
/** |
|
1057 |
* Fires immediately before the logged-in authentication cookie is set. |
|
1058 |
* |
|
1059 |
* @since 2.6.0 |
|
1060 |
* @since 4.9.0 The `$token` parameter was added. |
|
1061 |
* |
|
1062 |
* @param string $logged_in_cookie The logged-in cookie value. |
|
1063 |
* @param int $expire The time the login grace period expires as a UNIX timestamp. |
|
1064 |
* Default is 12 hours past the cookie's expiration time. |
|
1065 |
* @param int $expiration The time when the logged-in authentication cookie expires as a UNIX timestamp. |
|
1066 |
* Default is 14 days from now. |
|
1067 |
* @param int $user_id User ID. |
|
1068 |
* @param string $scheme Authentication scheme. Default 'logged_in'. |
|
1069 |
* @param string $token User's session token to use for this cookie. |
|
1070 |
*/ |
|
1071 |
do_action( 'set_logged_in_cookie', $logged_in_cookie, $expire, $expiration, $user_id, 'logged_in', $token ); |
|
1072 |
||
1073 |
/** |
|
1074 |
* Allows preventing auth cookies from actually being sent to the client. |
|
1075 |
* |
|
1076 |
* @since 4.7.4 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1077 |
* @since 6.2.0 The `$expire`, `$expiration`, `$user_id`, `$scheme`, and `$token` parameters were added. |
9 | 1078 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1079 |
* @param bool $send Whether to send auth cookies to the client. Default true. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1080 |
* @param int $expire The time the login grace period expires as a UNIX timestamp. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1081 |
* Default is 12 hours past the cookie's expiration time. Zero when clearing cookies. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1082 |
* @param int $expiration The time when the logged-in authentication cookie expires as a UNIX timestamp. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1083 |
* Default is 14 days from now. Zero when clearing cookies. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1084 |
* @param int $user_id User ID. Zero when clearing cookies. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1085 |
* @param string $scheme Authentication scheme. Values include 'auth' or 'secure_auth'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1086 |
* Empty string when clearing cookies. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1087 |
* @param string $token User's session token to use for this cookie. Empty string when clearing cookies. |
9 | 1088 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1089 |
if ( ! apply_filters( 'send_auth_cookies', true, $expire, $expiration, $user_id, $scheme, $token ) ) { |
9 | 1090 |
return; |
1091 |
} |
|
1092 |
||
1093 |
setcookie( $auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true ); |
|
1094 |
setcookie( $auth_cookie_name, $auth_cookie, $expire, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, $secure, true ); |
|
1095 |
setcookie( LOGGED_IN_COOKIE, $logged_in_cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1096 |
if ( COOKIEPATH !== SITECOOKIEPATH ) { |
9 | 1097 |
setcookie( LOGGED_IN_COOKIE, $logged_in_cookie, $expire, SITECOOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true ); |
1098 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
} |
0 | 1100 |
endif; |
1101 |
||
9 | 1102 |
if ( ! function_exists( 'wp_clear_auth_cookie' ) ) : |
5 | 1103 |
/** |
9 | 1104 |
* Removes all of the cookies associated with authentication. |
5 | 1105 |
* |
9 | 1106 |
* @since 2.5.0 |
5 | 1107 |
*/ |
9 | 1108 |
function wp_clear_auth_cookie() { |
1109 |
/** |
|
1110 |
* Fires just before the authentication cookies are cleared. |
|
1111 |
* |
|
1112 |
* @since 2.7.0 |
|
1113 |
*/ |
|
1114 |
do_action( 'clear_auth_cookie' ); |
|
0 | 1115 |
|
9 | 1116 |
/** This filter is documented in wp-includes/pluggable.php */ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1117 |
if ( ! apply_filters( 'send_auth_cookies', true, 0, 0, 0, '', '' ) ) { |
9 | 1118 |
return; |
1119 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1120 |
|
16 | 1121 |
// Auth cookies. |
9 | 1122 |
setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN ); |
1123 |
setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN ); |
|
1124 |
setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN ); |
|
1125 |
setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN ); |
|
1126 |
setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
|
1127 |
setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
|
0 | 1128 |
|
16 | 1129 |
// Settings cookies. |
9 | 1130 |
setcookie( 'wp-settings-' . get_current_user_id(), ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH ); |
1131 |
setcookie( 'wp-settings-time-' . get_current_user_id(), ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1132 |
|
16 | 1133 |
// Old cookies. |
9 | 1134 |
setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
1135 |
setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
|
1136 |
setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
|
1137 |
setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
|
0 | 1138 |
|
16 | 1139 |
// Even older cookies. |
9 | 1140 |
setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
1141 |
setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
|
1142 |
setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
|
1143 |
setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1144 |
|
16 | 1145 |
// Post password cookie. |
9 | 1146 |
setcookie( 'wp-postpass_' . COOKIEHASH, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
1147 |
} |
|
0 | 1148 |
endif; |
1149 |
||
9 | 1150 |
if ( ! function_exists( 'is_user_logged_in' ) ) : |
1151 |
/** |
|
1152 |
* Determines whether the current visitor is a logged in user. |
|
1153 |
* |
|
1154 |
* For more information on this and similar theme functions, check out |
|
1155 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
1156 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
1157 |
* |
|
1158 |
* @since 2.0.0 |
|
1159 |
* |
|
1160 |
* @return bool True if user is logged in, false if not logged in. |
|
1161 |
*/ |
|
1162 |
function is_user_logged_in() { |
|
1163 |
$user = wp_get_current_user(); |
|
0 | 1164 |
|
9 | 1165 |
return $user->exists(); |
1166 |
} |
|
0 | 1167 |
endif; |
1168 |
||
9 | 1169 |
if ( ! function_exists( 'auth_redirect' ) ) : |
1170 |
/** |
|
1171 |
* Checks if a user is logged in, if not it redirects them to the login page. |
|
1172 |
* |
|
16 | 1173 |
* When this code is called from a page, it checks to see if the user viewing the page is logged in. |
1174 |
* If the user is not logged in, they are redirected to the login page. The user is redirected |
|
1175 |
* in such a way that, upon logging in, they will be sent directly to the page they were originally |
|
1176 |
* trying to access. |
|
1177 |
* |
|
9 | 1178 |
* @since 1.5.0 |
1179 |
*/ |
|
1180 |
function auth_redirect() { |
|
1181 |
$secure = ( is_ssl() || force_ssl_admin() ); |
|
0 | 1182 |
|
9 | 1183 |
/** |
1184 |
* Filters whether to use a secure authentication redirect. |
|
1185 |
* |
|
1186 |
* @since 3.1.0 |
|
1187 |
* |
|
1188 |
* @param bool $secure Whether to use a secure authentication redirect. Default false. |
|
1189 |
*/ |
|
1190 |
$secure = apply_filters( 'secure_auth_redirect', $secure ); |
|
0 | 1191 |
|
16 | 1192 |
// If https is required and request is http, redirect. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1193 |
if ( $secure && ! is_ssl() && str_contains( $_SERVER['REQUEST_URI'], 'wp-admin' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1194 |
if ( str_starts_with( $_SERVER['REQUEST_URI'], 'http' ) ) { |
0 | 1195 |
wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); |
16 | 1196 |
exit; |
0 | 1197 |
} else { |
1198 |
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
|
16 | 1199 |
exit; |
0 | 1200 |
} |
1201 |
} |
|
1202 |
||
9 | 1203 |
/** |
1204 |
* Filters the authentication redirect scheme. |
|
1205 |
* |
|
1206 |
* @since 2.9.0 |
|
1207 |
* |
|
1208 |
* @param string $scheme Authentication redirect scheme. Default empty. |
|
1209 |
*/ |
|
1210 |
$scheme = apply_filters( 'auth_redirect_scheme', '' ); |
|
0 | 1211 |
|
16 | 1212 |
$user_id = wp_validate_auth_cookie( '', $scheme ); |
1213 |
if ( $user_id ) { |
|
9 | 1214 |
/** |
1215 |
* Fires before the authentication redirect. |
|
1216 |
* |
|
1217 |
* @since 2.8.0 |
|
1218 |
* |
|
1219 |
* @param int $user_id User ID. |
|
1220 |
*/ |
|
1221 |
do_action( 'auth_redirect', $user_id ); |
|
0 | 1222 |
|
9 | 1223 |
// If the user wants ssl but the session is not ssl, redirect. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1224 |
if ( ! $secure && get_user_option( 'use_ssl', $user_id ) && str_contains( $_SERVER['REQUEST_URI'], 'wp-admin' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1225 |
if ( str_starts_with( $_SERVER['REQUEST_URI'], 'http' ) ) { |
9 | 1226 |
wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); |
16 | 1227 |
exit; |
9 | 1228 |
} else { |
1229 |
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
|
16 | 1230 |
exit; |
9 | 1231 |
} |
1232 |
} |
|
0 | 1233 |
|
16 | 1234 |
return; // The cookie is good, so we're done. |
9 | 1235 |
} |
1236 |
||
16 | 1237 |
// The cookie is no good, so force login. |
9 | 1238 |
nocache_headers(); |
1239 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1240 |
if ( str_contains( $_SERVER['REQUEST_URI'], '/options.php' ) && wp_get_referer() ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1241 |
$redirect = wp_get_referer(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1242 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1243 |
$redirect = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1244 |
} |
9 | 1245 |
|
1246 |
$login_url = wp_login_url( $redirect, true ); |
|
1247 |
||
1248 |
wp_redirect( $login_url ); |
|
16 | 1249 |
exit; |
9 | 1250 |
} |
0 | 1251 |
endif; |
1252 |
||
9 | 1253 |
if ( ! function_exists( 'check_admin_referer' ) ) : |
1254 |
/** |
|
16 | 1255 |
* Ensures intent by verifying that a user was referred from another admin page with the correct security nonce. |
9 | 1256 |
* |
16 | 1257 |
* This function ensures the user intends to perform a given action, which helps protect against clickjacking style |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1258 |
* attacks. It verifies intent, not authorization, therefore it does not verify the user's capabilities. This should |
16 | 1259 |
* be performed with `current_user_can()` or similar. |
1260 |
* |
|
1261 |
* If the nonce value is invalid, the function will exit with an "Are You Sure?" style message. |
|
9 | 1262 |
* |
1263 |
* @since 1.2.0 |
|
16 | 1264 |
* @since 2.5.0 The `$query_arg` parameter was added. |
9 | 1265 |
* |
16 | 1266 |
* @param int|string $action The nonce action. |
1267 |
* @param string $query_arg Optional. Key to check for nonce in `$_REQUEST`. Default '_wpnonce'. |
|
1268 |
* @return int|false 1 if the nonce is valid and generated between 0-12 hours ago, |
|
1269 |
* 2 if the nonce is valid and generated between 12-24 hours ago. |
|
1270 |
* False if the nonce is invalid. |
|
9 | 1271 |
*/ |
1272 |
function check_admin_referer( $action = -1, $query_arg = '_wpnonce' ) { |
|
13 | 1273 |
if ( -1 === $action ) { |
18 | 1274 |
_doing_it_wrong( __FUNCTION__, __( 'You should specify an action to be verified by using the first parameter.' ), '3.2.0' ); |
9 | 1275 |
} |
0 | 1276 |
|
9 | 1277 |
$adminurl = strtolower( admin_url() ); |
1278 |
$referer = strtolower( wp_get_referer() ); |
|
1279 |
$result = isset( $_REQUEST[ $query_arg ] ) ? wp_verify_nonce( $_REQUEST[ $query_arg ], $action ) : false; |
|
5 | 1280 |
|
9 | 1281 |
/** |
1282 |
* Fires once the admin request has been validated or not. |
|
1283 |
* |
|
1284 |
* @since 1.5.1 |
|
1285 |
* |
|
1286 |
* @param string $action The nonce action. |
|
1287 |
* @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between |
|
1288 |
* 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago. |
|
1289 |
*/ |
|
1290 |
do_action( 'check_admin_referer', $action, $result ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1291 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1292 |
if ( ! $result && ! ( -1 === $action && str_starts_with( $referer, $adminurl ) ) ) { |
9 | 1293 |
wp_nonce_ays( $action ); |
1294 |
die(); |
|
1295 |
} |
|
1296 |
||
1297 |
return $result; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1298 |
} |
0 | 1299 |
endif; |
1300 |
||
9 | 1301 |
if ( ! function_exists( 'check_ajax_referer' ) ) : |
1302 |
/** |
|
1303 |
* Verifies the Ajax request to prevent processing requests external of the blog. |
|
1304 |
* |
|
1305 |
* @since 2.0.3 |
|
1306 |
* |
|
1307 |
* @param int|string $action Action nonce. |
|
1308 |
* @param false|string $query_arg Optional. Key to check for the nonce in `$_REQUEST` (since 2.5). If false, |
|
1309 |
* `$_REQUEST` values will be evaluated for '_ajax_nonce', and '_wpnonce' |
|
1310 |
* (in that order). Default false. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1311 |
* @param bool $stop Optional. Whether to stop early when the nonce cannot be verified. |
9 | 1312 |
* Default true. |
16 | 1313 |
* @return int|false 1 if the nonce is valid and generated between 0-12 hours ago, |
1314 |
* 2 if the nonce is valid and generated between 12-24 hours ago. |
|
1315 |
* False if the nonce is invalid. |
|
9 | 1316 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1317 |
function check_ajax_referer( $action = -1, $query_arg = false, $stop = true ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1318 |
if ( -1 === $action ) { |
18 | 1319 |
_doing_it_wrong( __FUNCTION__, __( 'You should specify an action to be verified by using the first parameter.' ), '4.7.0' ); |
9 | 1320 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
|
9 | 1322 |
$nonce = ''; |
0 | 1323 |
|
9 | 1324 |
if ( $query_arg && isset( $_REQUEST[ $query_arg ] ) ) { |
1325 |
$nonce = $_REQUEST[ $query_arg ]; |
|
1326 |
} elseif ( isset( $_REQUEST['_ajax_nonce'] ) ) { |
|
1327 |
$nonce = $_REQUEST['_ajax_nonce']; |
|
1328 |
} elseif ( isset( $_REQUEST['_wpnonce'] ) ) { |
|
1329 |
$nonce = $_REQUEST['_wpnonce']; |
|
1330 |
} |
|
0 | 1331 |
|
9 | 1332 |
$result = wp_verify_nonce( $nonce, $action ); |
0 | 1333 |
|
9 | 1334 |
/** |
1335 |
* Fires once the Ajax request has been validated or not. |
|
1336 |
* |
|
1337 |
* @since 2.1.0 |
|
1338 |
* |
|
1339 |
* @param string $action The Ajax nonce action. |
|
1340 |
* @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between |
|
1341 |
* 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago. |
|
1342 |
*/ |
|
1343 |
do_action( 'check_ajax_referer', $action, $result ); |
|
0 | 1344 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1345 |
if ( $stop && false === $result ) { |
9 | 1346 |
if ( wp_doing_ajax() ) { |
1347 |
wp_die( -1, 403 ); |
|
1348 |
} else { |
|
1349 |
die( '-1' ); |
|
1350 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1351 |
} |
9 | 1352 |
|
1353 |
return $result; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1354 |
} |
0 | 1355 |
endif; |
1356 |
||
9 | 1357 |
if ( ! function_exists( 'wp_redirect' ) ) : |
1358 |
/** |
|
1359 |
* Redirects to another page. |
|
1360 |
* |
|
1361 |
* Note: wp_redirect() does not exit automatically, and should almost always be |
|
1362 |
* followed by a call to `exit;`: |
|
1363 |
* |
|
1364 |
* wp_redirect( $url ); |
|
1365 |
* exit; |
|
1366 |
* |
|
1367 |
* Exiting can also be selectively manipulated by using wp_redirect() as a conditional |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1368 |
* in conjunction with the {@see 'wp_redirect'} and {@see 'wp_redirect_status'} filters: |
9 | 1369 |
* |
1370 |
* if ( wp_redirect( $url ) ) { |
|
1371 |
* exit; |
|
1372 |
* } |
|
1373 |
* |
|
1374 |
* @since 1.5.1 |
|
1375 |
* @since 5.1.0 The `$x_redirect_by` parameter was added. |
|
16 | 1376 |
* @since 5.4.0 On invalid status codes, wp_die() is called. |
9 | 1377 |
* |
1378 |
* @global bool $is_IIS |
|
1379 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1380 |
* @param string $location The path or URL to redirect to. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1381 |
* @param int $status Optional. HTTP response status code to use. Default '302' (Moved Temporarily). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1382 |
* @param string|false $x_redirect_by Optional. The application doing the redirect or false to omit. Default 'WordPress'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1383 |
* @return bool False if the redirect was canceled, true otherwise. |
9 | 1384 |
*/ |
1385 |
function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) { |
|
1386 |
global $is_IIS; |
|
1387 |
||
1388 |
/** |
|
1389 |
* Filters the redirect location. |
|
1390 |
* |
|
1391 |
* @since 2.1.0 |
|
1392 |
* |
|
1393 |
* @param string $location The path or URL to redirect to. |
|
1394 |
* @param int $status The HTTP response status code to use. |
|
1395 |
*/ |
|
1396 |
$location = apply_filters( 'wp_redirect', $location, $status ); |
|
0 | 1397 |
|
9 | 1398 |
/** |
1399 |
* Filters the redirect HTTP response status code to use. |
|
1400 |
* |
|
1401 |
* @since 2.3.0 |
|
1402 |
* |
|
1403 |
* @param int $status The HTTP response status code to use. |
|
1404 |
* @param string $location The path or URL to redirect to. |
|
1405 |
*/ |
|
1406 |
$status = apply_filters( 'wp_redirect_status', $status, $location ); |
|
1407 |
||
1408 |
if ( ! $location ) { |
|
1409 |
return false; |
|
1410 |
} |
|
1411 |
||
16 | 1412 |
if ( $status < 300 || 399 < $status ) { |
1413 |
wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) ); |
|
1414 |
} |
|
1415 |
||
9 | 1416 |
$location = wp_sanitize_redirect( $location ); |
1417 |
||
16 | 1418 |
if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) { |
1419 |
status_header( $status ); // This causes problems on IIS and some FastCGI setups. |
|
9 | 1420 |
} |
1421 |
||
1422 |
/** |
|
1423 |
* Filters the X-Redirect-By header. |
|
1424 |
* |
|
1425 |
* Allows applications to identify themselves when they're doing a redirect. |
|
1426 |
* |
|
1427 |
* @since 5.1.0 |
|
1428 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1429 |
* @param string|false $x_redirect_by The application doing the redirect or false to omit the header. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1430 |
* @param int $status Status code to use. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1431 |
* @param string $location The path to redirect to. |
9 | 1432 |
*/ |
1433 |
$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location ); |
|
1434 |
if ( is_string( $x_redirect_by ) ) { |
|
1435 |
header( "X-Redirect-By: $x_redirect_by" ); |
|
1436 |
} |
|
1437 |
||
1438 |
header( "Location: $location", true, $status ); |
|
1439 |
||
1440 |
return true; |
|
1441 |
} |
|
1442 |
endif; |
|
1443 |
||
1444 |
if ( ! function_exists( 'wp_sanitize_redirect' ) ) : |
|
0 | 1445 |
/** |
9 | 1446 |
* Sanitizes a URL for use in a redirect. |
0 | 1447 |
* |
1448 |
* @since 2.3.0 |
|
1449 |
* |
|
1450 |
* @param string $location The path to redirect to. |
|
9 | 1451 |
* @return string Redirect-sanitized URL. |
0 | 1452 |
*/ |
9 | 1453 |
function wp_sanitize_redirect( $location ) { |
16 | 1454 |
// Encode spaces. |
1455 |
$location = str_replace( ' ', '%20', $location ); |
|
1456 |
||
9 | 1457 |
$regex = '/ |
5 | 1458 |
( |
1459 |
(?: [\xC2-\xDF][\x80-\xBF] # double-byte sequences 110xxxxx 10xxxxxx |
|
1460 |
| \xE0[\xA0-\xBF][\x80-\xBF] # triple-byte sequences 1110xxxx 10xxxxxx * 2 |
|
1461 |
| [\xE1-\xEC][\x80-\xBF]{2} |
|
1462 |
| \xED[\x80-\x9F][\x80-\xBF] |
|
1463 |
| [\xEE-\xEF][\x80-\xBF]{2} |
|
1464 |
| \xF0[\x90-\xBF][\x80-\xBF]{2} # four-byte sequences 11110xxx 10xxxxxx * 3 |
|
1465 |
| [\xF1-\xF3][\x80-\xBF]{3} |
|
1466 |
| \xF4[\x80-\x8F][\x80-\xBF]{2} |
|
1467 |
){1,40} # ...one or more times |
|
1468 |
)/x'; |
|
9 | 1469 |
$location = preg_replace_callback( $regex, '_wp_sanitize_utf8_in_redirect', $location ); |
1470 |
$location = preg_replace( '|[^a-z0-9-~+_.?#=&;,/:%!*\[\]()@]|i', '', $location ); |
|
1471 |
$location = wp_kses_no_null( $location ); |
|
0 | 1472 |
|
16 | 1473 |
// Remove %0D and %0A from location. |
9 | 1474 |
$strip = array( '%0d', '%0a', '%0D', '%0A' ); |
1475 |
return _deep_replace( $strip, $location ); |
|
5 | 1476 |
} |
1477 |
||
1478 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1479 |
* URL encodes UTF-8 characters in a URL. |
5 | 1480 |
* |
9 | 1481 |
* @ignore |
1482 |
* @since 4.2.0 |
|
1483 |
* @access private |
|
5 | 1484 |
* |
9 | 1485 |
* @see wp_sanitize_redirect() |
5 | 1486 |
* |
9 | 1487 |
* @param array $matches RegEx matches against the redirect location. |
1488 |
* @return string URL-encoded version of the first RegEx match. |
|
5 | 1489 |
*/ |
9 | 1490 |
function _wp_sanitize_utf8_in_redirect( $matches ) { |
1491 |
return urlencode( $matches[0] ); |
|
5 | 1492 |
} |
9 | 1493 |
endif; |
0 | 1494 |
|
9 | 1495 |
if ( ! function_exists( 'wp_safe_redirect' ) ) : |
1496 |
/** |
|
1497 |
* Performs a safe (local) redirect, using wp_redirect(). |
|
1498 |
* |
|
1499 |
* Checks whether the $location is using an allowed host, if it has an absolute |
|
1500 |
* path. A plugin can therefore set or remove allowed host(s) to or from the |
|
1501 |
* list. |
|
1502 |
* |
|
1503 |
* If the host is not allowed, then the redirect defaults to wp-admin on the siteurl |
|
1504 |
* instead. This prevents malicious redirects which redirect to another host, |
|
1505 |
* but only used in a few places. |
|
1506 |
* |
|
1507 |
* Note: wp_safe_redirect() does not exit automatically, and should almost always be |
|
1508 |
* followed by a call to `exit;`: |
|
1509 |
* |
|
1510 |
* wp_safe_redirect( $url ); |
|
1511 |
* exit; |
|
1512 |
* |
|
1513 |
* Exiting can also be selectively manipulated by using wp_safe_redirect() as a conditional |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1514 |
* in conjunction with the {@see 'wp_redirect'} and {@see 'wp_redirect_status'} filters: |
9 | 1515 |
* |
1516 |
* if ( wp_safe_redirect( $url ) ) { |
|
1517 |
* exit; |
|
1518 |
* } |
|
1519 |
* |
|
1520 |
* @since 2.3.0 |
|
1521 |
* @since 5.1.0 The return value from wp_redirect() is now passed on, and the `$x_redirect_by` parameter was added. |
|
1522 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1523 |
* @param string $location The path or URL to redirect to. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1524 |
* @param int $status Optional. HTTP response status code to use. Default '302' (Moved Temporarily). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1525 |
* @param string|false $x_redirect_by Optional. The application doing the redirect or false to omit. Default 'WordPress'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1526 |
* @return bool False if the redirect was canceled, true otherwise. |
9 | 1527 |
*/ |
1528 |
function wp_safe_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) { |
|
0 | 1529 |
|
16 | 1530 |
// Need to look at the URL the way it will end up in wp_redirect(). |
9 | 1531 |
$location = wp_sanitize_redirect( $location ); |
1532 |
||
1533 |
/** |
|
1534 |
* Filters the redirect fallback URL for when the provided redirect is not safe (local). |
|
1535 |
* |
|
1536 |
* @since 4.3.0 |
|
1537 |
* |
|
1538 |
* @param string $fallback_url The fallback URL to use by default. |
|
1539 |
* @param int $status The HTTP response status code to use. |
|
1540 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1541 |
$fallback_url = apply_filters( 'wp_safe_redirect_fallback', admin_url(), $status ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1542 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1543 |
$location = wp_validate_redirect( $location, $fallback_url ); |
9 | 1544 |
|
1545 |
return wp_redirect( $location, $status, $x_redirect_by ); |
|
1546 |
} |
|
1547 |
endif; |
|
0 | 1548 |
|
9 | 1549 |
if ( ! function_exists( 'wp_validate_redirect' ) ) : |
1550 |
/** |
|
1551 |
* Validates a URL for use in a redirect. |
|
1552 |
* |
|
1553 |
* Checks whether the $location is using an allowed host, if it has an absolute |
|
1554 |
* path. A plugin can therefore set or remove allowed host(s) to or from the |
|
1555 |
* list. |
|
1556 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1557 |
* If the host is not allowed, then the redirect is to $fallback_url supplied. |
9 | 1558 |
* |
1559 |
* @since 2.8.1 |
|
1560 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1561 |
* @param string $location The redirect to validate. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1562 |
* @param string $fallback_url The value to return if $location is not allowed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1563 |
* @return string Redirect-sanitized URL. |
9 | 1564 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1565 |
function wp_validate_redirect( $location, $fallback_url = '' ) { |
16 | 1566 |
$location = wp_sanitize_redirect( trim( $location, " \t\n\r\0\x08\x0B" ) ); |
1567 |
// Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1568 |
if ( str_starts_with( $location, '//' ) ) { |
9 | 1569 |
$location = 'http:' . $location; |
1570 |
} |
|
0 | 1571 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1572 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1573 |
* In PHP 5 parse_url() may fail if the URL query part contains 'http://'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1574 |
* See https://bugs.php.net/bug.php?id=38143 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1575 |
*/ |
16 | 1576 |
$cut = strpos( $location, '?' ); |
1577 |
$test = $cut ? substr( $location, 0, $cut ) : $location; |
|
9 | 1578 |
|
16 | 1579 |
$lp = parse_url( $test ); |
9 | 1580 |
|
16 | 1581 |
// Give up if malformed URL. |
9 | 1582 |
if ( false === $lp ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1583 |
return $fallback_url; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1584 |
} |
0 | 1585 |
|
16 | 1586 |
// Allow only 'http' and 'https' schemes. No 'data:', etc. |
1587 |
if ( isset( $lp['scheme'] ) && ! ( 'http' === $lp['scheme'] || 'https' === $lp['scheme'] ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1588 |
return $fallback_url; |
9 | 1589 |
} |
0 | 1590 |
|
9 | 1591 |
if ( ! isset( $lp['host'] ) && ! empty( $lp['path'] ) && '/' !== $lp['path'][0] ) { |
1592 |
$path = ''; |
|
1593 |
if ( ! empty( $_SERVER['REQUEST_URI'] ) ) { |
|
1594 |
$path = dirname( parse_url( 'http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH ) . '?' ); |
|
13 | 1595 |
$path = wp_normalize_path( $path ); |
9 | 1596 |
} |
1597 |
$location = '/' . ltrim( $path . '/', '/' ) . $location; |
|
1598 |
} |
|
0 | 1599 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1600 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1601 |
* Reject if certain components are set but host is not. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1602 |
* This catches URLs like https:host.com for which parse_url() does not set the host field. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1603 |
*/ |
9 | 1604 |
if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1605 |
return $fallback_url; |
9 | 1606 |
} |
0 | 1607 |
|
9 | 1608 |
// Reject malformed components parse_url() can return on odd inputs. |
1609 |
foreach ( array( 'user', 'pass', 'host' ) as $component ) { |
|
1610 |
if ( isset( $lp[ $component ] ) && strpbrk( $lp[ $component ], ':/?#@' ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1611 |
return $fallback_url; |
9 | 1612 |
} |
1613 |
} |
|
1614 |
||
1615 |
$wpp = parse_url( home_url() ); |
|
5 | 1616 |
|
9 | 1617 |
/** |
16 | 1618 |
* Filters the list of allowed hosts to redirect to. |
9 | 1619 |
* |
1620 |
* @since 2.3.0 |
|
1621 |
* |
|
16 | 1622 |
* @param string[] $hosts An array of allowed host names. |
1623 |
* @param string $host The host name of the redirect destination; empty string if not set. |
|
9 | 1624 |
*/ |
1625 |
$allowed_hosts = (array) apply_filters( 'allowed_redirect_hosts', array( $wpp['host'] ), isset( $lp['host'] ) ? $lp['host'] : '' ); |
|
0 | 1626 |
|
16 | 1627 |
if ( isset( $lp['host'] ) && ( ! in_array( $lp['host'], $allowed_hosts, true ) && strtolower( $wpp['host'] ) !== $lp['host'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1628 |
$location = $fallback_url; |
9 | 1629 |
} |
0 | 1630 |
|
9 | 1631 |
return $location; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1632 |
} |
0 | 1633 |
endif; |
1634 |
||
9 | 1635 |
if ( ! function_exists( 'wp_notify_postauthor' ) ) : |
1636 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1637 |
* Notifies an author (and/or others) of a comment/trackback/pingback on a post. |
9 | 1638 |
* |
1639 |
* @since 1.0.0 |
|
1640 |
* |
|
16 | 1641 |
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1642 |
* @param string $deprecated Not used. |
9 | 1643 |
* @return bool True on completion. False if no email addresses were specified. |
1644 |
*/ |
|
1645 |
function wp_notify_postauthor( $comment_id, $deprecated = null ) { |
|
1646 |
if ( null !== $deprecated ) { |
|
1647 |
_deprecated_argument( __FUNCTION__, '3.8.0' ); |
|
1648 |
} |
|
1649 |
||
1650 |
$comment = get_comment( $comment_id ); |
|
1651 |
if ( empty( $comment ) || empty( $comment->comment_post_ID ) ) { |
|
1652 |
return false; |
|
1653 |
} |
|
1654 |
||
1655 |
$post = get_post( $comment->comment_post_ID ); |
|
1656 |
$author = get_userdata( $post->post_author ); |
|
1657 |
||
1658 |
// Who to notify? By default, just the post author, but others can be added. |
|
1659 |
$emails = array(); |
|
1660 |
if ( $author ) { |
|
1661 |
$emails[] = $author->user_email; |
|
1662 |
} |
|
1663 |
||
1664 |
/** |
|
1665 |
* Filters the list of email addresses to receive a comment notification. |
|
1666 |
* |
|
1667 |
* By default, only post authors are notified of comments. This filter allows |
|
1668 |
* others to be added. |
|
1669 |
* |
|
1670 |
* @since 3.7.0 |
|
1671 |
* |
|
16 | 1672 |
* @param string[] $emails An array of email addresses to receive a comment notification. |
19 | 1673 |
* @param string $comment_id The comment ID as a numeric string. |
9 | 1674 |
*/ |
1675 |
$emails = apply_filters( 'comment_notification_recipients', $emails, $comment->comment_ID ); |
|
1676 |
$emails = array_filter( $emails ); |
|
1677 |
||
1678 |
// If there are no addresses to send the comment to, bail. |
|
1679 |
if ( ! count( $emails ) ) { |
|
1680 |
return false; |
|
1681 |
} |
|
1682 |
||
1683 |
// Facilitate unsetting below without knowing the keys. |
|
1684 |
$emails = array_flip( $emails ); |
|
1685 |
||
1686 |
/** |
|
1687 |
* Filters whether to notify comment authors of their comments on their own posts. |
|
1688 |
* |
|
1689 |
* By default, comment authors aren't notified of their comments on their own |
|
1690 |
* posts. This filter allows you to override that. |
|
1691 |
* |
|
1692 |
* @since 3.8.0 |
|
1693 |
* |
|
19 | 1694 |
* @param bool $notify Whether to notify the post author of their own comment. |
1695 |
* Default false. |
|
1696 |
* @param string $comment_id The comment ID as a numeric string. |
|
9 | 1697 |
*/ |
1698 |
$notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID ); |
|
1699 |
||
16 | 1700 |
// The comment was left by the author. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1701 |
if ( $author && ! $notify_author && (int) $comment->user_id === (int) $post->post_author ) { |
9 | 1702 |
unset( $emails[ $author->user_email ] ); |
1703 |
} |
|
1704 |
||
16 | 1705 |
// The author moderated a comment on their own post. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1706 |
if ( $author && ! $notify_author && get_current_user_id() === (int) $post->post_author ) { |
9 | 1707 |
unset( $emails[ $author->user_email ] ); |
1708 |
} |
|
1709 |
||
16 | 1710 |
// The post author is no longer a member of the blog. |
9 | 1711 |
if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) { |
1712 |
unset( $emails[ $author->user_email ] ); |
|
1713 |
} |
|
1714 |
||
16 | 1715 |
// If there's no email to send the comment to, bail, otherwise flip array back around for use below. |
9 | 1716 |
if ( ! count( $emails ) ) { |
1717 |
return false; |
|
1718 |
} else { |
|
1719 |
$emails = array_flip( $emails ); |
|
1720 |
} |
|
1721 |
||
1722 |
$switched_locale = switch_to_locale( get_locale() ); |
|
1723 |
||
16 | 1724 |
$comment_author_domain = ''; |
1725 |
if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) { |
|
1726 |
$comment_author_domain = gethostbyaddr( $comment->comment_author_IP ); |
|
1727 |
} |
|
9 | 1728 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1729 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1730 |
* The blogname option is escaped with esc_html() on the way into the database in sanitize_option(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1731 |
* We want to reverse this for the plain text arena of emails. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1732 |
*/ |
9 | 1733 |
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
1734 |
$comment_content = wp_specialchars_decode( $comment->comment_content ); |
|
0 | 1735 |
|
9 | 1736 |
switch ( $comment->comment_type ) { |
1737 |
case 'trackback': |
|
16 | 1738 |
/* translators: %s: Post title. */ |
9 | 1739 |
$notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n"; |
16 | 1740 |
/* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */ |
9 | 1741 |
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
16 | 1742 |
/* translators: %s: Trackback/pingback/comment author URL. */ |
9 | 1743 |
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
16 | 1744 |
/* translators: %s: Comment text. */ |
9 | 1745 |
$notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; |
1746 |
$notify_message .= __( 'You can see all trackbacks on this post here:' ) . "\r\n"; |
|
16 | 1747 |
/* translators: Trackback notification email subject. 1: Site title, 2: Post title. */ |
9 | 1748 |
$subject = sprintf( __( '[%1$s] Trackback: "%2$s"' ), $blogname, $post->post_title ); |
1749 |
break; |
|
16 | 1750 |
|
9 | 1751 |
case 'pingback': |
16 | 1752 |
/* translators: %s: Post title. */ |
9 | 1753 |
$notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n"; |
16 | 1754 |
/* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */ |
9 | 1755 |
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
16 | 1756 |
/* translators: %s: Trackback/pingback/comment author URL. */ |
9 | 1757 |
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
16 | 1758 |
/* translators: %s: Comment text. */ |
9 | 1759 |
$notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; |
1760 |
$notify_message .= __( 'You can see all pingbacks on this post here:' ) . "\r\n"; |
|
16 | 1761 |
/* translators: Pingback notification email subject. 1: Site title, 2: Post title. */ |
9 | 1762 |
$subject = sprintf( __( '[%1$s] Pingback: "%2$s"' ), $blogname, $post->post_title ); |
1763 |
break; |
|
16 | 1764 |
|
1765 |
default: // Comments. |
|
1766 |
/* translators: %s: Post title. */ |
|
9 | 1767 |
$notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n"; |
16 | 1768 |
/* translators: 1: Comment author's name, 2: Comment author's IP address, 3: Comment author's hostname. */ |
9 | 1769 |
$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
16 | 1770 |
/* translators: %s: Comment author email. */ |
9 | 1771 |
$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; |
16 | 1772 |
/* translators: %s: Trackback/pingback/comment author URL. */ |
9 | 1773 |
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
16 | 1774 |
|
1775 |
if ( $comment->comment_parent && user_can( $post->post_author, 'edit_comment', $comment->comment_parent ) ) { |
|
1776 |
/* translators: Comment moderation. %s: Parent comment edit URL. */ |
|
1777 |
$notify_message .= sprintf( __( 'In reply to: %s' ), admin_url( "comment.php?action=editcomment&c={$comment->comment_parent}#wpbody-content" ) ) . "\r\n"; |
|
1778 |
} |
|
1779 |
||
1780 |
/* translators: %s: Comment text. */ |
|
9 | 1781 |
$notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; |
1782 |
$notify_message .= __( 'You can see all comments on this post here:' ) . "\r\n"; |
|
16 | 1783 |
/* translators: Comment notification email subject. 1: Site title, 2: Post title. */ |
9 | 1784 |
$subject = sprintf( __( '[%1$s] Comment: "%2$s"' ), $blogname, $post->post_title ); |
1785 |
break; |
|
1786 |
} |
|
16 | 1787 |
|
9 | 1788 |
$notify_message .= get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n"; |
16 | 1789 |
/* translators: %s: Comment URL. */ |
9 | 1790 |
$notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n"; |
1791 |
||
1792 |
if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) { |
|
1793 |
if ( EMPTY_TRASH_DAYS ) { |
|
16 | 1794 |
/* translators: Comment moderation. %s: Comment action URL. */ |
9 | 1795 |
$notify_message .= sprintf( __( 'Trash it: %s' ), admin_url( "comment.php?action=trash&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n"; |
1796 |
} else { |
|
16 | 1797 |
/* translators: Comment moderation. %s: Comment action URL. */ |
9 | 1798 |
$notify_message .= sprintf( __( 'Delete it: %s' ), admin_url( "comment.php?action=delete&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n"; |
1799 |
} |
|
16 | 1800 |
/* translators: Comment moderation. %s: Comment action URL. */ |
9 | 1801 |
$notify_message .= sprintf( __( 'Spam it: %s' ), admin_url( "comment.php?action=spam&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n"; |
1802 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1803 |
|
16 | 1804 |
$wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', wp_parse_url( network_home_url(), PHP_URL_HOST ) ); |
9 | 1805 |
|
16 | 1806 |
if ( '' === $comment->comment_author ) { |
9 | 1807 |
$from = "From: \"$blogname\" <$wp_email>"; |
16 | 1808 |
if ( '' !== $comment->comment_author_email ) { |
9 | 1809 |
$reply_to = "Reply-To: $comment->comment_author_email"; |
1810 |
} |
|
1811 |
} else { |
|
1812 |
$from = "From: \"$comment->comment_author\" <$wp_email>"; |
|
16 | 1813 |
if ( '' !== $comment->comment_author_email ) { |
9 | 1814 |
$reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; |
1815 |
} |
|
1816 |
} |
|
1817 |
||
1818 |
$message_headers = "$from\n" |
|
1819 |
. 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
|
1820 |
||
1821 |
if ( isset( $reply_to ) ) { |
|
1822 |
$message_headers .= $reply_to . "\n"; |
|
1823 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1824 |
|
9 | 1825 |
/** |
1826 |
* Filters the comment notification email text. |
|
1827 |
* |
|
1828 |
* @since 1.5.2 |
|
1829 |
* |
|
1830 |
* @param string $notify_message The comment notification email text. |
|
19 | 1831 |
* @param string $comment_id Comment ID as a numeric string. |
9 | 1832 |
*/ |
1833 |
$notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID ); |
|
1834 |
||
1835 |
/** |
|
1836 |
* Filters the comment notification email subject. |
|
1837 |
* |
|
1838 |
* @since 1.5.2 |
|
1839 |
* |
|
1840 |
* @param string $subject The comment notification email subject. |
|
19 | 1841 |
* @param string $comment_id Comment ID as a numeric string. |
9 | 1842 |
*/ |
1843 |
$subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID ); |
|
1844 |
||
1845 |
/** |
|
1846 |
* Filters the comment notification email headers. |
|
1847 |
* |
|
1848 |
* @since 1.5.2 |
|
1849 |
* |
|
1850 |
* @param string $message_headers Headers for the comment notification email. |
|
19 | 1851 |
* @param string $comment_id Comment ID as a numeric string. |
9 | 1852 |
*/ |
1853 |
$message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID ); |
|
1854 |
||
1855 |
foreach ( $emails as $email ) { |
|
16 | 1856 |
wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); |
9 | 1857 |
} |
1858 |
||
1859 |
if ( $switched_locale ) { |
|
1860 |
restore_previous_locale(); |
|
1861 |
} |
|
1862 |
||
0 | 1863 |
return true; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1864 |
} |
0 | 1865 |
endif; |
1866 |
||
9 | 1867 |
if ( ! function_exists( 'wp_notify_moderator' ) ) : |
1868 |
/** |
|
1869 |
* Notifies the moderator of the site about a new comment that is awaiting approval. |
|
1870 |
* |
|
1871 |
* @since 1.0.0 |
|
1872 |
* |
|
1873 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
1874 |
* |
|
1875 |
* Uses the {@see 'notify_moderator'} filter to determine whether the site moderator |
|
1876 |
* should be notified, overriding the site setting. |
|
1877 |
* |
|
1878 |
* @param int $comment_id Comment ID. |
|
1879 |
* @return true Always returns true. |
|
1880 |
*/ |
|
1881 |
function wp_notify_moderator( $comment_id ) { |
|
1882 |
global $wpdb; |
|
1883 |
||
1884 |
$maybe_notify = get_option( 'moderation_notify' ); |
|
1885 |
||
1886 |
/** |
|
1887 |
* Filters whether to send the site moderator email notifications, overriding the site setting. |
|
1888 |
* |
|
1889 |
* @since 4.4.0 |
|
1890 |
* |
|
1891 |
* @param bool $maybe_notify Whether to notify blog moderator. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1892 |
* @param int $comment_id The ID of the comment for the notification. |
9 | 1893 |
*/ |
1894 |
$maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id ); |
|
1895 |
||
1896 |
if ( ! $maybe_notify ) { |
|
1897 |
return true; |
|
1898 |
} |
|
1899 |
||
1900 |
$comment = get_comment( $comment_id ); |
|
1901 |
$post = get_post( $comment->comment_post_ID ); |
|
1902 |
$user = get_userdata( $post->post_author ); |
|
1903 |
// Send to the administration and to the post author if the author can modify the comment. |
|
1904 |
$emails = array( get_option( 'admin_email' ) ); |
|
1905 |
if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { |
|
1906 |
if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) { |
|
1907 |
$emails[] = $user->user_email; |
|
1908 |
} |
|
1909 |
} |
|
1910 |
||
1911 |
$switched_locale = switch_to_locale( get_locale() ); |
|
1912 |
||
16 | 1913 |
$comment_author_domain = ''; |
1914 |
if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) { |
|
1915 |
$comment_author_domain = gethostbyaddr( $comment->comment_author_IP ); |
|
1916 |
} |
|
9 | 1917 |
|
16 | 1918 |
$comments_waiting = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'" ); |
1919 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1920 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1921 |
* The blogname option is escaped with esc_html() on the way into the database in sanitize_option(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1922 |
* We want to reverse this for the plain text arena of emails. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1923 |
*/ |
9 | 1924 |
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
1925 |
$comment_content = wp_specialchars_decode( $comment->comment_content ); |
|
1926 |
||
1927 |
switch ( $comment->comment_type ) { |
|
1928 |
case 'trackback': |
|
16 | 1929 |
/* translators: %s: Post title. */ |
9 | 1930 |
$notify_message = sprintf( __( 'A new trackback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; |
1931 |
$notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; |
|
16 | 1932 |
/* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */ |
9 | 1933 |
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
16 | 1934 |
/* translators: %s: Trackback/pingback/comment author URL. */ |
9 | 1935 |
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
1936 |
$notify_message .= __( 'Trackback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n"; |
|
1937 |
break; |
|
16 | 1938 |
|
9 | 1939 |
case 'pingback': |
16 | 1940 |
/* translators: %s: Post title. */ |
9 | 1941 |
$notify_message = sprintf( __( 'A new pingback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; |
1942 |
$notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; |
|
16 | 1943 |
/* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */ |
9 | 1944 |
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
16 | 1945 |
/* translators: %s: Trackback/pingback/comment author URL. */ |
9 | 1946 |
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
1947 |
$notify_message .= __( 'Pingback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n"; |
|
1948 |
break; |
|
16 | 1949 |
|
1950 |
default: // Comments. |
|
1951 |
/* translators: %s: Post title. */ |
|
9 | 1952 |
$notify_message = sprintf( __( 'A new comment on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; |
1953 |
$notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; |
|
16 | 1954 |
/* translators: 1: Comment author's name, 2: Comment author's IP address, 3: Comment author's hostname. */ |
9 | 1955 |
$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
16 | 1956 |
/* translators: %s: Comment author email. */ |
9 | 1957 |
$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; |
16 | 1958 |
/* translators: %s: Trackback/pingback/comment author URL. */ |
9 | 1959 |
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
16 | 1960 |
|
1961 |
if ( $comment->comment_parent ) { |
|
1962 |
/* translators: Comment moderation. %s: Parent comment edit URL. */ |
|
1963 |
$notify_message .= sprintf( __( 'In reply to: %s' ), admin_url( "comment.php?action=editcomment&c={$comment->comment_parent}#wpbody-content" ) ) . "\r\n"; |
|
1964 |
} |
|
1965 |
||
1966 |
/* translators: %s: Comment text. */ |
|
9 | 1967 |
$notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; |
1968 |
break; |
|
1969 |
} |
|
1970 |
||
16 | 1971 |
/* translators: Comment moderation. %s: Comment action URL. */ |
9 | 1972 |
$notify_message .= sprintf( __( 'Approve it: %s' ), admin_url( "comment.php?action=approve&c={$comment_id}#wpbody-content" ) ) . "\r\n"; |
1973 |
||
1974 |
if ( EMPTY_TRASH_DAYS ) { |
|
16 | 1975 |
/* translators: Comment moderation. %s: Comment action URL. */ |
9 | 1976 |
$notify_message .= sprintf( __( 'Trash it: %s' ), admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" ) ) . "\r\n"; |
1977 |
} else { |
|
16 | 1978 |
/* translators: Comment moderation. %s: Comment action URL. */ |
9 | 1979 |
$notify_message .= sprintf( __( 'Delete it: %s' ), admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" ) ) . "\r\n"; |
1980 |
} |
|
1981 |
||
16 | 1982 |
/* translators: Comment moderation. %s: Comment action URL. */ |
9 | 1983 |
$notify_message .= sprintf( __( 'Spam it: %s' ), admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ) ) . "\r\n"; |
1984 |
||
1985 |
$notify_message .= sprintf( |
|
16 | 1986 |
/* translators: Comment moderation. %s: Number of comments awaiting approval. */ |
9 | 1987 |
_n( |
1988 |
'Currently %s comment is waiting for approval. Please visit the moderation panel:', |
|
1989 |
'Currently %s comments are waiting for approval. Please visit the moderation panel:', |
|
1990 |
$comments_waiting |
|
1991 |
), |
|
1992 |
number_format_i18n( $comments_waiting ) |
|
1993 |
) . "\r\n"; |
|
1994 |
$notify_message .= admin_url( 'edit-comments.php?comment_status=moderated#wpbody-content' ) . "\r\n"; |
|
1995 |
||
16 | 1996 |
/* translators: Comment moderation notification email subject. 1: Site title, 2: Post title. */ |
9 | 1997 |
$subject = sprintf( __( '[%1$s] Please moderate: "%2$s"' ), $blogname, $post->post_title ); |
1998 |
$message_headers = ''; |
|
1999 |
||
2000 |
/** |
|
2001 |
* Filters the list of recipients for comment moderation emails. |
|
2002 |
* |
|
2003 |
* @since 3.7.0 |
|
2004 |
* |
|
16 | 2005 |
* @param string[] $emails List of email addresses to notify for comment moderation. |
2006 |
* @param int $comment_id Comment ID. |
|
9 | 2007 |
*/ |
2008 |
$emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id ); |
|
2009 |
||
2010 |
/** |
|
2011 |
* Filters the comment moderation email text. |
|
2012 |
* |
|
2013 |
* @since 1.5.2 |
|
2014 |
* |
|
2015 |
* @param string $notify_message Text of the comment moderation email. |
|
2016 |
* @param int $comment_id Comment ID. |
|
2017 |
*/ |
|
2018 |
$notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id ); |
|
2019 |
||
2020 |
/** |
|
2021 |
* Filters the comment moderation email subject. |
|
2022 |
* |
|
2023 |
* @since 1.5.2 |
|
2024 |
* |
|
2025 |
* @param string $subject Subject of the comment moderation email. |
|
2026 |
* @param int $comment_id Comment ID. |
|
2027 |
*/ |
|
2028 |
$subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id ); |
|
2029 |
||
2030 |
/** |
|
2031 |
* Filters the comment moderation email headers. |
|
2032 |
* |
|
2033 |
* @since 2.8.0 |
|
2034 |
* |
|
2035 |
* @param string $message_headers Headers for the comment moderation email. |
|
2036 |
* @param int $comment_id Comment ID. |
|
2037 |
*/ |
|
2038 |
$message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); |
|
2039 |
||
2040 |
foreach ( $emails as $email ) { |
|
16 | 2041 |
wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); |
9 | 2042 |
} |
2043 |
||
2044 |
if ( $switched_locale ) { |
|
2045 |
restore_previous_locale(); |
|
2046 |
} |
|
2047 |
||
2048 |
return true; |
|
2049 |
} |
|
2050 |
endif; |
|
2051 |
||
2052 |
if ( ! function_exists( 'wp_password_change_notification' ) ) : |
|
2053 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2054 |
* Notifies the blog admin of a user changing password, normally via email. |
9 | 2055 |
* |
2056 |
* @since 2.7.0 |
|
2057 |
* |
|
2058 |
* @param WP_User $user User object. |
|
2059 |
*/ |
|
2060 |
function wp_password_change_notification( $user ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2061 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2062 |
* Send a copy of password change notification to the admin, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2063 |
* but check to see if it's the admin whose password we're changing, and skip this. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2064 |
*/ |
9 | 2065 |
if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) { |
16 | 2066 |
/* translators: %s: User name. */ |
9 | 2067 |
$message = sprintf( __( 'Password changed for user: %s' ), $user->user_login ) . "\r\n"; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2068 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2069 |
* The blogname option is escaped with esc_html() on the way into the database in sanitize_option(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2070 |
* We want to reverse this for the plain text arena of emails. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2071 |
*/ |
9 | 2072 |
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2073 |
|
9 | 2074 |
$wp_password_change_notification_email = array( |
2075 |
'to' => get_option( 'admin_email' ), |
|
16 | 2076 |
/* translators: Password change notification email subject. %s: Site title. */ |
9 | 2077 |
'subject' => __( '[%s] Password Changed' ), |
2078 |
'message' => $message, |
|
2079 |
'headers' => '', |
|
2080 |
); |
|
2081 |
||
2082 |
/** |
|
2083 |
* Filters the contents of the password change notification email sent to the site admin. |
|
2084 |
* |
|
2085 |
* @since 4.9.0 |
|
2086 |
* |
|
2087 |
* @param array $wp_password_change_notification_email { |
|
2088 |
* Used to build wp_mail(). |
|
2089 |
* |
|
2090 |
* @type string $to The intended recipient - site admin email address. |
|
2091 |
* @type string $subject The subject of the email. |
|
2092 |
* @type string $message The body of the email. |
|
2093 |
* @type string $headers The headers of the email. |
|
2094 |
* } |
|
2095 |
* @param WP_User $user User object for user whose password was changed. |
|
2096 |
* @param string $blogname The site title. |
|
2097 |
*/ |
|
2098 |
$wp_password_change_notification_email = apply_filters( 'wp_password_change_notification_email', $wp_password_change_notification_email, $user, $blogname ); |
|
2099 |
||
2100 |
wp_mail( |
|
2101 |
$wp_password_change_notification_email['to'], |
|
2102 |
wp_specialchars_decode( sprintf( $wp_password_change_notification_email['subject'], $blogname ) ), |
|
2103 |
$wp_password_change_notification_email['message'], |
|
2104 |
$wp_password_change_notification_email['headers'] |
|
2105 |
); |
|
2106 |
} |
|
2107 |
} |
|
2108 |
endif; |
|
2109 |
||
2110 |
if ( ! function_exists( 'wp_new_user_notification' ) ) : |
|
2111 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2112 |
* Emails login credentials to a newly-registered user. |
9 | 2113 |
* |
2114 |
* A new user registration notification is also sent to admin email. |
|
2115 |
* |
|
2116 |
* @since 2.0.0 |
|
2117 |
* @since 4.3.0 The `$plaintext_pass` parameter was changed to `$notify`. |
|
2118 |
* @since 4.3.1 The `$plaintext_pass` parameter was deprecated. `$notify` added as a third parameter. |
|
2119 |
* @since 4.6.0 The `$notify` parameter accepts 'user' for sending notification only to the user created. |
|
2120 |
* |
|
2121 |
* @param int $user_id User ID. |
|
2122 |
* @param null $deprecated Not used (argument deprecated). |
|
2123 |
* @param string $notify Optional. Type of notification that should happen. Accepts 'admin' or an empty |
|
2124 |
* string (admin only), 'user', or 'both' (admin and user). Default empty. |
|
2125 |
*/ |
|
2126 |
function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) { |
|
16 | 2127 |
if ( null !== $deprecated ) { |
9 | 2128 |
_deprecated_argument( __FUNCTION__, '4.3.1' ); |
2129 |
} |
|
2130 |
||
16 | 2131 |
// Accepts only 'user', 'admin' , 'both' or default '' as $notify. |
9 | 2132 |
if ( ! in_array( $notify, array( 'user', 'admin', 'both', '' ), true ) ) { |
2133 |
return; |
|
2134 |
} |
|
2135 |
||
2136 |
$user = get_userdata( $user_id ); |
|
2137 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2138 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2139 |
* The blogname option is escaped with esc_html() on the way into the database in sanitize_option(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2140 |
* We want to reverse this for the plain text arena of emails. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2141 |
*/ |
9 | 2142 |
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
2143 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2144 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2145 |
* Filters whether the admin is notified of a new user registration. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2146 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2147 |
* @since 6.1.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2148 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2149 |
* @param bool $send Whether to send the email. Default true. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2150 |
* @param WP_User $user User object for new user. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2151 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2152 |
$send_notification_to_admin = apply_filters( 'wp_send_new_user_notification_to_admin', true, $user ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2153 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2154 |
if ( 'user' !== $notify && true === $send_notification_to_admin ) { |
9 | 2155 |
$switched_locale = switch_to_locale( get_locale() ); |
2156 |
||
16 | 2157 |
/* translators: %s: Site title. */ |
9 | 2158 |
$message = sprintf( __( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n"; |
16 | 2159 |
/* translators: %s: User login. */ |
9 | 2160 |
$message .= sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n"; |
16 | 2161 |
/* translators: %s: User email address. */ |
9 | 2162 |
$message .= sprintf( __( 'Email: %s' ), $user->user_email ) . "\r\n"; |
2163 |
||
2164 |
$wp_new_user_notification_email_admin = array( |
|
2165 |
'to' => get_option( 'admin_email' ), |
|
16 | 2166 |
/* translators: New user registration notification email subject. %s: Site title. */ |
9 | 2167 |
'subject' => __( '[%s] New User Registration' ), |
2168 |
'message' => $message, |
|
2169 |
'headers' => '', |
|
2170 |
); |
|
2171 |
||
2172 |
/** |
|
2173 |
* Filters the contents of the new user notification email sent to the site admin. |
|
2174 |
* |
|
2175 |
* @since 4.9.0 |
|
2176 |
* |
|
16 | 2177 |
* @param array $wp_new_user_notification_email_admin { |
9 | 2178 |
* Used to build wp_mail(). |
2179 |
* |
|
2180 |
* @type string $to The intended recipient - site admin email address. |
|
2181 |
* @type string $subject The subject of the email. |
|
2182 |
* @type string $message The body of the email. |
|
2183 |
* @type string $headers The headers of the email. |
|
2184 |
* } |
|
2185 |
* @param WP_User $user User object for new user. |
|
2186 |
* @param string $blogname The site title. |
|
2187 |
*/ |
|
2188 |
$wp_new_user_notification_email_admin = apply_filters( 'wp_new_user_notification_email_admin', $wp_new_user_notification_email_admin, $user, $blogname ); |
|
2189 |
||
16 | 2190 |
wp_mail( |
9 | 2191 |
$wp_new_user_notification_email_admin['to'], |
2192 |
wp_specialchars_decode( sprintf( $wp_new_user_notification_email_admin['subject'], $blogname ) ), |
|
2193 |
$wp_new_user_notification_email_admin['message'], |
|
2194 |
$wp_new_user_notification_email_admin['headers'] |
|
2195 |
); |
|
2196 |
||
2197 |
if ( $switched_locale ) { |
|
2198 |
restore_previous_locale(); |
|
2199 |
} |
|
2200 |
} |
|
2201 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2202 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2203 |
* Filters whether the user is notified of their new user registration. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2204 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2205 |
* @since 6.1.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2206 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2207 |
* @param bool $send Whether to send the email. Default true. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2208 |
* @param WP_User $user User object for new user. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2209 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2210 |
$send_notification_to_user = apply_filters( 'wp_send_new_user_notification_to_user', true, $user ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2211 |
|
16 | 2212 |
// `$deprecated` was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notification. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2213 |
if ( 'admin' === $notify || true !== $send_notification_to_user || ( empty( $deprecated ) && empty( $notify ) ) ) { |
9 | 2214 |
return; |
2215 |
} |
|
2216 |
||
16 | 2217 |
$key = get_password_reset_key( $user ); |
2218 |
if ( is_wp_error( $key ) ) { |
|
2219 |
return; |
|
9 | 2220 |
} |
2221 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2222 |
$switched_locale = switch_to_user_locale( $user_id ); |
9 | 2223 |
|
16 | 2224 |
/* translators: %s: User login. */ |
9 | 2225 |
$message = sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n"; |
2226 |
$message .= __( 'To set your password, visit the following address:' ) . "\r\n\r\n"; |
|
16 | 2227 |
$message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user->user_login ), 'login' ) . "\r\n\r\n"; |
9 | 2228 |
|
2229 |
$message .= wp_login_url() . "\r\n"; |
|
2230 |
||
2231 |
$wp_new_user_notification_email = array( |
|
2232 |
'to' => $user->user_email, |
|
16 | 2233 |
/* translators: Login details notification email subject. %s: Site title. */ |
9 | 2234 |
'subject' => __( '[%s] Login Details' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2235 |
'message' => $message, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2236 |
'headers' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2237 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2238 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2239 |
/** |
9 | 2240 |
* Filters the contents of the new user notification email sent to the new user. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2241 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2242 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2243 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2244 |
* @param array $wp_new_user_notification_email { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2245 |
* Used to build wp_mail(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2246 |
* |
9 | 2247 |
* @type string $to The intended recipient - New user email address. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2248 |
* @type string $subject The subject of the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2249 |
* @type string $message The body of the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2250 |
* @type string $headers The headers of the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2251 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2252 |
* @param WP_User $user User object for new user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2253 |
* @param string $blogname The site title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2254 |
*/ |
9 | 2255 |
$wp_new_user_notification_email = apply_filters( 'wp_new_user_notification_email', $wp_new_user_notification_email, $user, $blogname ); |
0 | 2256 |
|
9 | 2257 |
wp_mail( |
2258 |
$wp_new_user_notification_email['to'], |
|
2259 |
wp_specialchars_decode( sprintf( $wp_new_user_notification_email['subject'], $blogname ) ), |
|
2260 |
$wp_new_user_notification_email['message'], |
|
2261 |
$wp_new_user_notification_email['headers'] |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2262 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2263 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2264 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2265 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2266 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2267 |
} |
0 | 2268 |
endif; |
2269 |
||
9 | 2270 |
if ( ! function_exists( 'wp_nonce_tick' ) ) : |
5 | 2271 |
/** |
16 | 2272 |
* Returns the time-dependent variable for nonce creation. |
9 | 2273 |
* |
2274 |
* A nonce has a lifespan of two ticks. Nonces in their second tick may be |
|
2275 |
* updated, e.g. by autosave. |
|
5 | 2276 |
* |
2277 |
* @since 2.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2278 |
* @since 6.1.0 Added `$action` argument. |
5 | 2279 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2280 |
* @param string|int $action Optional. The nonce action. Default -1. |
9 | 2281 |
* @return float Float value rounded up to the next highest integer. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2282 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2283 |
function wp_nonce_tick( $action = -1 ) { |
5 | 2284 |
/** |
9 | 2285 |
* Filters the lifespan of nonces in seconds. |
5 | 2286 |
* |
2287 |
* @since 2.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2288 |
* @since 6.1.0 Added `$action` argument to allow for more targeted filters. |
5 | 2289 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2290 |
* @param int $lifespan Lifespan of nonces in seconds. Default 86,400 seconds, or one day. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2291 |
* @param string|int $action The nonce action, or -1 if none was provided. |
5 | 2292 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2293 |
$nonce_life = apply_filters( 'nonce_life', DAY_IN_SECONDS, $action ); |
0 | 2294 |
|
9 | 2295 |
return ceil( time() / ( $nonce_life / 2 ) ); |
0 | 2296 |
} |
2297 |
endif; |
|
2298 |
||
9 | 2299 |
if ( ! function_exists( 'wp_verify_nonce' ) ) : |
2300 |
/** |
|
16 | 2301 |
* Verifies that a correct security nonce was used with time limit. |
9 | 2302 |
* |
16 | 2303 |
* A nonce is valid for 24 hours (by default). |
9 | 2304 |
* |
2305 |
* @since 2.0.3 |
|
2306 |
* |
|
16 | 2307 |
* @param string $nonce Nonce value that was used for verification, usually via a form field. |
9 | 2308 |
* @param string|int $action Should give context to what is taking place and be the same when nonce was created. |
16 | 2309 |
* @return int|false 1 if the nonce is valid and generated between 0-12 hours ago, |
2310 |
* 2 if the nonce is valid and generated between 12-24 hours ago. |
|
2311 |
* False if the nonce is invalid. |
|
9 | 2312 |
*/ |
2313 |
function wp_verify_nonce( $nonce, $action = -1 ) { |
|
2314 |
$nonce = (string) $nonce; |
|
2315 |
$user = wp_get_current_user(); |
|
2316 |
$uid = (int) $user->ID; |
|
2317 |
if ( ! $uid ) { |
|
2318 |
/** |
|
2319 |
* Filters whether the user who generated the nonce is logged out. |
|
2320 |
* |
|
2321 |
* @since 3.5.0 |
|
2322 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2323 |
* @param int $uid ID of the nonce-owning user. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2324 |
* @param string|int $action The nonce action, or -1 if none was provided. |
9 | 2325 |
*/ |
2326 |
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); |
|
2327 |
} |
|
2328 |
||
2329 |
if ( empty( $nonce ) ) { |
|
2330 |
return false; |
|
2331 |
} |
|
2332 |
||
2333 |
$token = wp_get_session_token(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2334 |
$i = wp_nonce_tick( $action ); |
9 | 2335 |
|
16 | 2336 |
// Nonce generated 0-12 hours ago. |
9 | 2337 |
$expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); |
2338 |
if ( hash_equals( $expected, $nonce ) ) { |
|
2339 |
return 1; |
|
2340 |
} |
|
0 | 2341 |
|
16 | 2342 |
// Nonce generated 12-24 hours ago. |
9 | 2343 |
$expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); |
2344 |
if ( hash_equals( $expected, $nonce ) ) { |
|
2345 |
return 2; |
|
2346 |
} |
|
2347 |
||
2348 |
/** |
|
2349 |
* Fires when nonce verification fails. |
|
2350 |
* |
|
2351 |
* @since 4.4.0 |
|
2352 |
* |
|
2353 |
* @param string $nonce The invalid nonce. |
|
2354 |
* @param string|int $action The nonce action. |
|
2355 |
* @param WP_User $user The current user object. |
|
2356 |
* @param string $token The user's session token. |
|
2357 |
*/ |
|
2358 |
do_action( 'wp_verify_nonce_failed', $nonce, $action, $user, $token ); |
|
2359 |
||
16 | 2360 |
// Invalid nonce. |
9 | 2361 |
return false; |
0 | 2362 |
} |
9 | 2363 |
endif; |
0 | 2364 |
|
9 | 2365 |
if ( ! function_exists( 'wp_create_nonce' ) ) : |
5 | 2366 |
/** |
9 | 2367 |
* Creates a cryptographic token tied to a specific action, user, user session, |
2368 |
* and window of time. |
|
5 | 2369 |
* |
9 | 2370 |
* @since 2.0.3 |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2371 |
* @since 4.0.0 Session tokens were integrated with nonce creation. |
5 | 2372 |
* |
9 | 2373 |
* @param string|int $action Scalar value to add context to the nonce. |
2374 |
* @return string The token. |
|
5 | 2375 |
*/ |
9 | 2376 |
function wp_create_nonce( $action = -1 ) { |
2377 |
$user = wp_get_current_user(); |
|
2378 |
$uid = (int) $user->ID; |
|
2379 |
if ( ! $uid ) { |
|
2380 |
/** This filter is documented in wp-includes/pluggable.php */ |
|
2381 |
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); |
|
2382 |
} |
|
2383 |
||
2384 |
$token = wp_get_session_token(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2385 |
$i = wp_nonce_tick( $action ); |
9 | 2386 |
|
2387 |
return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); |
|
2388 |
} |
|
0 | 2389 |
endif; |
2390 |
||
9 | 2391 |
if ( ! function_exists( 'wp_salt' ) ) : |
2392 |
/** |
|
16 | 2393 |
* Returns a salt to add to hashes. |
9 | 2394 |
* |
2395 |
* Salts are created using secret keys. Secret keys are located in two places: |
|
2396 |
* in the database and in the wp-config.php file. The secret key in the database |
|
2397 |
* is randomly generated and will be appended to the secret keys in wp-config.php. |
|
2398 |
* |
|
2399 |
* The secret keys in wp-config.php should be updated to strong, random keys to maximize |
|
2400 |
* security. Below is an example of how the secret key constants are defined. |
|
2401 |
* Do not paste this example directly into wp-config.php. Instead, have a |
|
2402 |
* {@link https://api.wordpress.org/secret-key/1.1/salt/ secret key created} just |
|
2403 |
* for you. |
|
2404 |
* |
|
2405 |
* define('AUTH_KEY', ' Xakm<o xQy rw4EMsLKM-?!T+,PFF})H4lzcW57AF0U@N@< >M%G4Yt>f`z]MON'); |
|
2406 |
* define('SECURE_AUTH_KEY', 'LzJ}op]mr|6+![P}Ak:uNdJCJZd>(Hx.-Mh#Tz)pCIU#uGEnfFz|f ;;eU%/U^O~'); |
|
2407 |
* define('LOGGED_IN_KEY', '|i|Ux`9<p-h$aFf(qnT:sDO:D1P^wZ$$/Ra@miTJi9G;ddp_<q}6H1)o|a +&JCM'); |
|
2408 |
* define('NONCE_KEY', '%:R{[P|,s.KuMltH5}cI;/k<Gx~j!f0I)m_sIyu+&NJZ)-iO>z7X>QYR0Z_XnZ@|'); |
|
2409 |
* define('AUTH_SALT', 'eZyT)-Naw]F8CwA*VaW#q*|.)g@o}||wf~@C-YSt}(dh_r6EbI#A,y|nU2{B#JBW'); |
|
2410 |
* define('SECURE_AUTH_SALT', '!=oLUTXh,QW=H `}`L|9/^4-3 STz},T(w}W<I`.JjPi)<Bmf1v,HpGe}T1:Xt7n'); |
|
2411 |
* define('LOGGED_IN_SALT', '+XSqHc;@Q*K_b|Z?NC[3H!!EONbh.n<+=uKR:>*c(u`g~EJBf#8u#R{mUEZrozmm'); |
|
2412 |
* define('NONCE_SALT', 'h`GXHhD>SLWVfg1(1(N{;.V!MoE(SfbA_ksP@&`+AycHcAV$+?@3q+rxV{%^VyKT'); |
|
2413 |
* |
|
2414 |
* Salting passwords helps against tools which has stored hashed values of |
|
2415 |
* common dictionary strings. The added values makes it harder to crack. |
|
2416 |
* |
|
2417 |
* @since 2.5.0 |
|
2418 |
* |
|
2419 |
* @link https://api.wordpress.org/secret-key/1.1/salt/ Create secrets for wp-config.php |
|
2420 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2421 |
* @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce). |
9 | 2422 |
* @return string Salt value |
2423 |
*/ |
|
2424 |
function wp_salt( $scheme = 'auth' ) { |
|
2425 |
static $cached_salts = array(); |
|
2426 |
if ( isset( $cached_salts[ $scheme ] ) ) { |
|
2427 |
/** |
|
2428 |
* Filters the WordPress salt. |
|
2429 |
* |
|
2430 |
* @since 2.5.0 |
|
2431 |
* |
|
2432 |
* @param string $cached_salt Cached salt for the given scheme. |
|
2433 |
* @param string $scheme Authentication scheme. Values include 'auth', |
|
2434 |
* 'secure_auth', 'logged_in', and 'nonce'. |
|
2435 |
*/ |
|
2436 |
return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme ); |
|
2437 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2438 |
|
9 | 2439 |
static $duplicated_keys; |
2440 |
if ( null === $duplicated_keys ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2441 |
$duplicated_keys = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2442 |
'put your unique phrase here' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2443 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2444 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2445 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2446 |
* translators: This string should only be translated if wp-config-sample.php is localized. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2447 |
* You can check the localized release package or |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2448 |
* https://i18n.svn.wordpress.org/<locale code>/branches/<wp version>/dist/wp-config-sample.php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2449 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2450 |
$duplicated_keys[ __( 'put your unique phrase here' ) ] = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2451 |
|
9 | 2452 |
foreach ( array( 'AUTH', 'SECURE_AUTH', 'LOGGED_IN', 'NONCE', 'SECRET' ) as $first ) { |
2453 |
foreach ( array( 'KEY', 'SALT' ) as $second ) { |
|
2454 |
if ( ! defined( "{$first}_{$second}" ) ) { |
|
2455 |
continue; |
|
2456 |
} |
|
2457 |
$value = constant( "{$first}_{$second}" ); |
|
2458 |
$duplicated_keys[ $value ] = isset( $duplicated_keys[ $value ] ); |
|
2459 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2460 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2461 |
} |
9 | 2462 |
|
2463 |
$values = array( |
|
2464 |
'key' => '', |
|
2465 |
'salt' => '', |
|
2466 |
); |
|
2467 |
if ( defined( 'SECRET_KEY' ) && SECRET_KEY && empty( $duplicated_keys[ SECRET_KEY ] ) ) { |
|
2468 |
$values['key'] = SECRET_KEY; |
|
2469 |
} |
|
16 | 2470 |
if ( 'auth' === $scheme && defined( 'SECRET_SALT' ) && SECRET_SALT && empty( $duplicated_keys[ SECRET_SALT ] ) ) { |
9 | 2471 |
$values['salt'] = SECRET_SALT; |
2472 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2473 |
|
16 | 2474 |
if ( in_array( $scheme, array( 'auth', 'secure_auth', 'logged_in', 'nonce' ), true ) ) { |
9 | 2475 |
foreach ( array( 'key', 'salt' ) as $type ) { |
2476 |
$const = strtoupper( "{$scheme}_{$type}" ); |
|
2477 |
if ( defined( $const ) && constant( $const ) && empty( $duplicated_keys[ constant( $const ) ] ) ) { |
|
2478 |
$values[ $type ] = constant( $const ); |
|
2479 |
} elseif ( ! $values[ $type ] ) { |
|
2480 |
$values[ $type ] = get_site_option( "{$scheme}_{$type}" ); |
|
2481 |
if ( ! $values[ $type ] ) { |
|
2482 |
$values[ $type ] = wp_generate_password( 64, true, true ); |
|
2483 |
update_site_option( "{$scheme}_{$type}", $values[ $type ] ); |
|
2484 |
} |
|
2485 |
} |
|
2486 |
} |
|
2487 |
} else { |
|
2488 |
if ( ! $values['key'] ) { |
|
2489 |
$values['key'] = get_site_option( 'secret_key' ); |
|
2490 |
if ( ! $values['key'] ) { |
|
2491 |
$values['key'] = wp_generate_password( 64, true, true ); |
|
2492 |
update_site_option( 'secret_key', $values['key'] ); |
|
2493 |
} |
|
2494 |
} |
|
2495 |
$values['salt'] = hash_hmac( 'md5', $scheme, $values['key'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2496 |
} |
9 | 2497 |
|
2498 |
$cached_salts[ $scheme ] = $values['key'] . $values['salt']; |
|
2499 |
||
2500 |
/** This filter is documented in wp-includes/pluggable.php */ |
|
2501 |
return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme ); |
|
0 | 2502 |
} |
2503 |
endif; |
|
2504 |
||
9 | 2505 |
if ( ! function_exists( 'wp_hash' ) ) : |
2506 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2507 |
* Gets hash of given string. |
9 | 2508 |
* |
2509 |
* @since 2.0.3 |
|
2510 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2511 |
* @param string $data Plain text to hash. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2512 |
* @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2513 |
* @return string Hash of $data. |
9 | 2514 |
*/ |
2515 |
function wp_hash( $data, $scheme = 'auth' ) { |
|
2516 |
$salt = wp_salt( $scheme ); |
|
2517 |
||
2518 |
return hash_hmac( 'md5', $data, $salt ); |
|
2519 |
} |
|
2520 |
endif; |
|
2521 |
||
2522 |
if ( ! function_exists( 'wp_hash_password' ) ) : |
|
2523 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2524 |
* Creates a hash (encrypt) of a plain text password. |
9 | 2525 |
* |
2526 |
* For integration with other applications, this function can be overwritten to |
|
2527 |
* instead use the other package password checking algorithm. |
|
2528 |
* |
|
2529 |
* @since 2.5.0 |
|
2530 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2531 |
* @global PasswordHash $wp_hasher PHPass object. |
9 | 2532 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2533 |
* @param string $password Plain text user password to hash. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2534 |
* @return string The hash string of the password. |
9 | 2535 |
*/ |
2536 |
function wp_hash_password( $password ) { |
|
2537 |
global $wp_hasher; |
|
2538 |
||
2539 |
if ( empty( $wp_hasher ) ) { |
|
16 | 2540 |
require_once ABSPATH . WPINC . '/class-phpass.php'; |
2541 |
// By default, use the portable hash from phpass. |
|
9 | 2542 |
$wp_hasher = new PasswordHash( 8, true ); |
2543 |
} |
|
2544 |
||
2545 |
return $wp_hasher->HashPassword( trim( $password ) ); |
|
2546 |
} |
|
2547 |
endif; |
|
0 | 2548 |
|
9 | 2549 |
if ( ! function_exists( 'wp_check_password' ) ) : |
2550 |
/** |
|
2551 |
* Checks the plaintext password against the encrypted Password. |
|
2552 |
* |
|
2553 |
* Maintains compatibility between old version and the new cookie authentication |
|
2554 |
* protocol using PHPass library. The $hash parameter is the encrypted password |
|
2555 |
* and the function compares the plain text password when encrypted similarly |
|
2556 |
* against the already encrypted password to see if they match. |
|
2557 |
* |
|
2558 |
* For integration with other applications, this function can be overwritten to |
|
2559 |
* instead use the other package password checking algorithm. |
|
2560 |
* |
|
2561 |
* @since 2.5.0 |
|
2562 |
* |
|
2563 |
* @global PasswordHash $wp_hasher PHPass object used for checking the password |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2564 |
* against the $hash + $password. |
9 | 2565 |
* @uses PasswordHash::CheckPassword |
2566 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2567 |
* @param string $password Plaintext user's password. |
9 | 2568 |
* @param string $hash Hash of the user's password to check against. |
2569 |
* @param string|int $user_id Optional. User ID. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2570 |
* @return bool False, if the $password does not match the hashed password. |
9 | 2571 |
*/ |
2572 |
function wp_check_password( $password, $hash, $user_id = '' ) { |
|
2573 |
global $wp_hasher; |
|
0 | 2574 |
|
9 | 2575 |
// If the hash is still md5... |
2576 |
if ( strlen( $hash ) <= 32 ) { |
|
2577 |
$check = hash_equals( $hash, md5( $password ) ); |
|
2578 |
if ( $check && $user_id ) { |
|
2579 |
// Rehash using new hash. |
|
2580 |
wp_set_password( $password, $user_id ); |
|
2581 |
$hash = wp_hash_password( $password ); |
|
2582 |
} |
|
2583 |
||
2584 |
/** |
|
2585 |
* Filters whether the plaintext password matches the encrypted password. |
|
2586 |
* |
|
2587 |
* @since 2.5.0 |
|
2588 |
* |
|
2589 |
* @param bool $check Whether the passwords match. |
|
2590 |
* @param string $password The plaintext password. |
|
2591 |
* @param string $hash The hashed password. |
|
2592 |
* @param string|int $user_id User ID. Can be empty. |
|
2593 |
*/ |
|
2594 |
return apply_filters( 'check_password', $check, $password, $hash, $user_id ); |
|
2595 |
} |
|
2596 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2597 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2598 |
* If the stored hash is longer than an MD5, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2599 |
* presume the new style phpass portable hash. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2600 |
*/ |
9 | 2601 |
if ( empty( $wp_hasher ) ) { |
16 | 2602 |
require_once ABSPATH . WPINC . '/class-phpass.php'; |
2603 |
// By default, use the portable hash from phpass. |
|
9 | 2604 |
$wp_hasher = new PasswordHash( 8, true ); |
2605 |
} |
|
2606 |
||
2607 |
$check = $wp_hasher->CheckPassword( $password, $hash ); |
|
2608 |
||
2609 |
/** This filter is documented in wp-includes/pluggable.php */ |
|
2610 |
return apply_filters( 'check_password', $check, $password, $hash, $user_id ); |
|
2611 |
} |
|
0 | 2612 |
endif; |
2613 |
||
9 | 2614 |
if ( ! function_exists( 'wp_generate_password' ) ) : |
2615 |
/** |
|
2616 |
* Generates a random password drawn from the defined set of characters. |
|
2617 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2618 |
* Uses wp_rand() to create passwords with far less predictability |
9 | 2619 |
* than similar native PHP functions like `rand()` or `mt_rand()`. |
2620 |
* |
|
2621 |
* @since 2.5.0 |
|
2622 |
* |
|
2623 |
* @param int $length Optional. The length of password to generate. Default 12. |
|
2624 |
* @param bool $special_chars Optional. Whether to include standard special characters. |
|
2625 |
* Default true. |
|
2626 |
* @param bool $extra_special_chars Optional. Whether to include other special characters. |
|
2627 |
* Used when generating secret keys and salts. Default false. |
|
2628 |
* @return string The random password. |
|
2629 |
*/ |
|
2630 |
function wp_generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) { |
|
2631 |
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; |
|
2632 |
if ( $special_chars ) { |
|
2633 |
$chars .= '!@#$%^&*()'; |
|
2634 |
} |
|
2635 |
if ( $extra_special_chars ) { |
|
2636 |
$chars .= '-_ []{}<>~`+=,.;:/?|'; |
|
2637 |
} |
|
2638 |
||
2639 |
$password = ''; |
|
2640 |
for ( $i = 0; $i < $length; $i++ ) { |
|
2641 |
$password .= substr( $chars, wp_rand( 0, strlen( $chars ) - 1 ), 1 ); |
|
2642 |
} |
|
2643 |
||
2644 |
/** |
|
2645 |
* Filters the randomly-generated password. |
|
2646 |
* |
|
2647 |
* @since 3.0.0 |
|
16 | 2648 |
* @since 5.3.0 Added the `$length`, `$special_chars`, and `$extra_special_chars` parameters. |
9 | 2649 |
* |
16 | 2650 |
* @param string $password The generated password. |
2651 |
* @param int $length The length of password to generate. |
|
2652 |
* @param bool $special_chars Whether to include standard special characters. |
|
2653 |
* @param bool $extra_special_chars Whether to include other special characters. |
|
9 | 2654 |
*/ |
16 | 2655 |
return apply_filters( 'random_password', $password, $length, $special_chars, $extra_special_chars ); |
9 | 2656 |
} |
2657 |
endif; |
|
2658 |
||
2659 |
if ( ! function_exists( 'wp_rand' ) ) : |
|
2660 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2661 |
* Generates a random non-negative number. |
9 | 2662 |
* |
2663 |
* @since 2.6.2 |
|
2664 |
* @since 4.4.0 Uses PHP7 random_int() or the random_compat library if available. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2665 |
* @since 6.1.0 Returns zero instead of a random number if both `$min` and `$max` are zero. |
9 | 2666 |
* |
2667 |
* @global string $rnd_value |
|
2668 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2669 |
* @param int $min Optional. Lower limit for the generated number. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2670 |
* Accepts positive integers or zero. Defaults to 0. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2671 |
* @param int $max Optional. Upper limit for the generated number. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2672 |
* Accepts positive integers. Defaults to 4294967295. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2673 |
* @return int A random non-negative number between min and max. |
9 | 2674 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2675 |
function wp_rand( $min = null, $max = null ) { |
9 | 2676 |
global $rnd_value; |
2677 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2678 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2679 |
* Some misconfigured 32-bit environments (Entropy PHP, for example) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2680 |
* truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2681 |
*/ |
9 | 2682 |
$max_random_number = 3000000000 === 2147483647 ? (float) '4294967295' : 4294967295; // 4294967295 = 0xffffffff |
2683 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2684 |
if ( null === $min ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2685 |
$min = 0; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2686 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2687 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2688 |
if ( null === $max ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2689 |
$max = $max_random_number; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2690 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2691 |
|
16 | 2692 |
// We only handle ints, floats are truncated to their integer value. |
9 | 2693 |
$min = (int) $min; |
2694 |
$max = (int) $max; |
|
2695 |
||
16 | 2696 |
// Use PHP's CSPRNG, or a compatible method. |
9 | 2697 |
static $use_random_int_functionality = true; |
2698 |
if ( $use_random_int_functionality ) { |
|
2699 |
try { |
|
2700 |
// wp_rand() can accept arguments in either order, PHP cannot. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2701 |
$_max = max( $min, $max ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2702 |
$_min = min( $min, $max ); |
9 | 2703 |
$val = random_int( $_min, $_max ); |
2704 |
if ( false !== $val ) { |
|
2705 |
return absint( $val ); |
|
2706 |
} else { |
|
2707 |
$use_random_int_functionality = false; |
|
2708 |
} |
|
2709 |
} catch ( Error $e ) { |
|
2710 |
$use_random_int_functionality = false; |
|
2711 |
} catch ( Exception $e ) { |
|
2712 |
$use_random_int_functionality = false; |
|
2713 |
} |
|
2714 |
} |
|
2715 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2716 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2717 |
* Reset $rnd_value after 14 uses. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2718 |
* 32 (md5) + 40 (sha1) + 40 (sha1) / 8 = 14 random numbers from $rnd_value. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2719 |
*/ |
9 | 2720 |
if ( strlen( $rnd_value ) < 8 ) { |
2721 |
if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
2722 |
static $seed = ''; |
|
2723 |
} else { |
|
2724 |
$seed = get_transient( 'random_seed' ); |
|
2725 |
} |
|
2726 |
$rnd_value = md5( uniqid( microtime() . mt_rand(), true ) . $seed ); |
|
2727 |
$rnd_value .= sha1( $rnd_value ); |
|
2728 |
$rnd_value .= sha1( $rnd_value . $seed ); |
|
2729 |
$seed = md5( $seed . $rnd_value ); |
|
2730 |
if ( ! defined( 'WP_SETUP_CONFIG' ) && ! defined( 'WP_INSTALLING' ) ) { |
|
2731 |
set_transient( 'random_seed', $seed ); |
|
2732 |
} |
|
2733 |
} |
|
2734 |
||
16 | 2735 |
// Take the first 8 digits for our value. |
9 | 2736 |
$value = substr( $rnd_value, 0, 8 ); |
2737 |
||
2738 |
// Strip the first eight, leaving the remainder for the next call to wp_rand(). |
|
2739 |
$rnd_value = substr( $rnd_value, 8 ); |
|
2740 |
||
2741 |
$value = abs( hexdec( $value ) ); |
|
2742 |
||
16 | 2743 |
// Reduce the value to be within the min - max range. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2744 |
$value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 ); |
9 | 2745 |
|
18 | 2746 |
return abs( (int) $value ); |
9 | 2747 |
} |
2748 |
endif; |
|
2749 |
||
2750 |
if ( ! function_exists( 'wp_set_password' ) ) : |
|
2751 |
/** |
|
2752 |
* Updates the user's password with a new encrypted one. |
|
2753 |
* |
|
2754 |
* For integration with other applications, this function can be overwritten to |
|
2755 |
* instead use the other package password checking algorithm. |
|
2756 |
* |
|
2757 |
* Please note: This function should be used sparingly and is really only meant for single-time |
|
2758 |
* application. Leveraging this improperly in a plugin or theme could result in an endless loop |
|
2759 |
* of password resets if precautions are not taken to ensure it does not execute on every page load. |
|
2760 |
* |
|
2761 |
* @since 2.5.0 |
|
2762 |
* |
|
2763 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
2764 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2765 |
* @param string $password The plaintext new user password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2766 |
* @param int $user_id User ID. |
9 | 2767 |
*/ |
2768 |
function wp_set_password( $password, $user_id ) { |
|
2769 |
global $wpdb; |
|
2770 |
||
2771 |
$hash = wp_hash_password( $password ); |
|
2772 |
$wpdb->update( |
|
2773 |
$wpdb->users, |
|
2774 |
array( |
|
2775 |
'user_pass' => $hash, |
|
2776 |
'user_activation_key' => '', |
|
2777 |
), |
|
2778 |
array( 'ID' => $user_id ) |
|
2779 |
); |
|
0 | 2780 |
|
16 | 2781 |
clean_user_cache( $user_id ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2782 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2783 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2784 |
* Fires after the user password is set. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2785 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2786 |
* @since 6.2.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2787 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2788 |
* @param string $password The plaintext password just set. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2789 |
* @param int $user_id The ID of the user whose password was just set. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2790 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2791 |
do_action( 'wp_set_password', $password, $user_id ); |
5 | 2792 |
} |
9 | 2793 |
endif; |
0 | 2794 |
|
9 | 2795 |
if ( ! function_exists( 'get_avatar' ) ) : |
2796 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2797 |
* Retrieves the avatar `<img>` tag for a user, email address, MD5 hash, comment, or post. |
9 | 2798 |
* |
2799 |
* @since 2.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2800 |
* @since 4.2.0 Added the optional `$args` parameter. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2801 |
* @since 5.5.0 Added the `loading` argument. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2802 |
* @since 6.1.0 Added the `decoding` argument. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2803 |
* @since 6.3.0 Added the `fetchpriority` argument. |
9 | 2804 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2805 |
* @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2806 |
* user email, WP_User object, WP_Post object, or WP_Comment object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2807 |
* @param int $size Optional. Height and width of the avatar in pixels. Default 96. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2808 |
* @param string $default_value URL for the default image or a default type. Accepts: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2809 |
* - '404' (return a 404 instead of a default image) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2810 |
* - 'retro' (a 8-bit arcade-style pixelated face) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2811 |
* - 'robohash' (a robot) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2812 |
* - 'monsterid' (a monster) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2813 |
* - 'wavatar' (a cartoon face) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2814 |
* - 'identicon' (the "quilt", a geometric pattern) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2815 |
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2816 |
* - 'blank' (transparent GIF) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2817 |
* - 'gravatar_default' (the Gravatar logo) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2818 |
* Default is the value of the 'avatar_default' option, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2819 |
* with a fallback of 'mystery'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2820 |
* @param string $alt Optional. Alternative text to use in the avatar image tag. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2821 |
* Default empty. |
16 | 2822 |
* @param array $args { |
9 | 2823 |
* Optional. Extra arguments to retrieve the avatar. |
2824 |
* |
|
2825 |
* @type int $height Display height of the avatar in pixels. Defaults to $size. |
|
2826 |
* @type int $width Display width of the avatar in pixels. Defaults to $size. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2827 |
* @type bool $force_default Whether to always show the default image, never the Gravatar. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2828 |
* Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2829 |
* @type string $rating What rating to display avatars up to. Accepts: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2830 |
* - 'G' (suitable for all audiences) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2831 |
* - 'PG' (possibly offensive, usually for audiences 13 and above) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2832 |
* - 'R' (intended for adult audiences above 17) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2833 |
* - 'X' (even more mature than above) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2834 |
* Default is the value of the 'avatar_rating' option. |
9 | 2835 |
* @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. |
2836 |
* Default null. |
|
16 | 2837 |
* @type array|string $class Array or string of additional classes to add to the img element. |
9 | 2838 |
* Default null. |
2839 |
* @type bool $force_display Whether to always show the avatar - ignores the show_avatars option. |
|
2840 |
* Default false. |
|
16 | 2841 |
* @type string $loading Value for the `loading` attribute. |
2842 |
* Default null. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2843 |
* @type string $fetchpriority Value for the `fetchpriority` attribute. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2844 |
* Default null. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2845 |
* @type string $decoding Value for the `decoding` attribute. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2846 |
* Default null. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2847 |
* @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2848 |
* Default empty. |
9 | 2849 |
* } |
16 | 2850 |
* @return string|false `<img>` tag for the user's avatar. False on failure. |
9 | 2851 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2852 |
function get_avatar( $id_or_email, $size = 96, $default_value = '', $alt = '', $args = null ) { |
9 | 2853 |
$defaults = array( |
2854 |
// get_avatar_data() args. |
|
2855 |
'size' => 96, |
|
2856 |
'height' => null, |
|
2857 |
'width' => null, |
|
2858 |
'default' => get_option( 'avatar_default', 'mystery' ), |
|
2859 |
'force_default' => false, |
|
2860 |
'rating' => get_option( 'avatar_rating' ), |
|
2861 |
'scheme' => null, |
|
2862 |
'alt' => '', |
|
2863 |
'class' => null, |
|
2864 |
'force_display' => false, |
|
16 | 2865 |
'loading' => null, |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2866 |
'fetchpriority' => null, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2867 |
'decoding' => null, |
9 | 2868 |
'extra_attr' => '', |
2869 |
); |
|
5 | 2870 |
|
9 | 2871 |
if ( empty( $args ) ) { |
2872 |
$args = array(); |
|
2873 |
} |
|
2874 |
||
2875 |
$args['size'] = (int) $size; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2876 |
$args['default'] = $default_value; |
9 | 2877 |
$args['alt'] = $alt; |
2878 |
||
2879 |
$args = wp_parse_args( $args, $defaults ); |
|
2880 |
||
2881 |
if ( empty( $args['height'] ) ) { |
|
2882 |
$args['height'] = $args['size']; |
|
2883 |
} |
|
2884 |
if ( empty( $args['width'] ) ) { |
|
2885 |
$args['width'] = $args['size']; |
|
2886 |
} |
|
2887 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2888 |
// Update args with loading optimized attributes. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2889 |
$loading_optimization_attr = wp_get_loading_optimization_attributes( 'img', $args, 'get_avatar' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2890 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2891 |
$args = array_merge( $args, $loading_optimization_attr ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2892 |
|
9 | 2893 |
if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) { |
2894 |
$id_or_email = get_comment( $id_or_email ); |
|
2895 |
} |
|
0 | 2896 |
|
9 | 2897 |
/** |
16 | 2898 |
* Allows the HTML for a user's avatar to be returned early. |
9 | 2899 |
* |
19 | 2900 |
* Returning a non-null value will effectively short-circuit get_avatar(), passing |
9 | 2901 |
* the value through the {@see 'get_avatar'} filter and returning early. |
2902 |
* |
|
2903 |
* @since 4.2.0 |
|
2904 |
* |
|
16 | 2905 |
* @param string|null $avatar HTML for the user's avatar. Default null. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2906 |
* @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
16 | 2907 |
* user email, WP_User object, WP_Post object, or WP_Comment object. |
2908 |
* @param array $args Arguments passed to get_avatar_url(), after processing. |
|
9 | 2909 |
*/ |
2910 |
$avatar = apply_filters( 'pre_get_avatar', null, $id_or_email, $args ); |
|
2911 |
||
2912 |
if ( ! is_null( $avatar ) ) { |
|
2913 |
/** This filter is documented in wp-includes/pluggable.php */ |
|
2914 |
return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args ); |
|
2915 |
} |
|
2916 |
||
2917 |
if ( ! $args['force_display'] && ! get_option( 'show_avatars' ) ) { |
|
2918 |
return false; |
|
2919 |
} |
|
2920 |
||
2921 |
$url2x = get_avatar_url( $id_or_email, array_merge( $args, array( 'size' => $args['size'] * 2 ) ) ); |
|
2922 |
||
2923 |
$args = get_avatar_data( $id_or_email, $args ); |
|
2924 |
||
2925 |
$url = $args['url']; |
|
2926 |
||
2927 |
if ( ! $url || is_wp_error( $url ) ) { |
|
2928 |
return false; |
|
2929 |
} |
|
2930 |
||
2931 |
$class = array( 'avatar', 'avatar-' . (int) $args['size'], 'photo' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2932 |
|
9 | 2933 |
if ( ! $args['found_avatar'] || $args['force_default'] ) { |
2934 |
$class[] = 'avatar-default'; |
|
2935 |
} |
|
2936 |
||
2937 |
if ( $args['class'] ) { |
|
2938 |
if ( is_array( $args['class'] ) ) { |
|
2939 |
$class = array_merge( $class, $args['class'] ); |
|
2940 |
} else { |
|
2941 |
$class[] = $args['class']; |
|
2942 |
} |
|
2943 |
} |
|
5 | 2944 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2945 |
// Add `loading`, `fetchpriority`, and `decoding` attributes. |
16 | 2946 |
$extra_attr = $args['extra_attr']; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2947 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2948 |
if ( in_array( $args['loading'], array( 'lazy', 'eager' ), true ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2949 |
&& ! preg_match( '/\bloading\s*=/', $extra_attr ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2950 |
) { |
16 | 2951 |
if ( ! empty( $extra_attr ) ) { |
2952 |
$extra_attr .= ' '; |
|
2953 |
} |
|
2954 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2955 |
$extra_attr .= "loading='{$args['loading']}'"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2956 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2957 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2958 |
if ( in_array( $args['fetchpriority'], array( 'high', 'low', 'auto' ), true ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2959 |
&& ! preg_match( '/\bfetchpriority\s*=/', $extra_attr ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2960 |
) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2961 |
if ( ! empty( $extra_attr ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2962 |
$extra_attr .= ' '; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2963 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2964 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2965 |
$extra_attr .= "fetchpriority='{$args['fetchpriority']}'"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2966 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2967 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2968 |
if ( in_array( $args['decoding'], array( 'async', 'sync', 'auto' ), true ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2969 |
&& ! preg_match( '/\bdecoding\s*=/', $extra_attr ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2970 |
) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2971 |
if ( ! empty( $extra_attr ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2972 |
$extra_attr .= ' '; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2973 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2974 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2975 |
$extra_attr .= "decoding='{$args['decoding']}'"; |
16 | 2976 |
} |
2977 |
||
9 | 2978 |
$avatar = sprintf( |
2979 |
"<img alt='%s' src='%s' srcset='%s' class='%s' height='%d' width='%d' %s/>", |
|
2980 |
esc_attr( $args['alt'] ), |
|
2981 |
esc_url( $url ), |
|
2982 |
esc_url( $url2x ) . ' 2x', |
|
18 | 2983 |
esc_attr( implode( ' ', $class ) ), |
9 | 2984 |
(int) $args['height'], |
2985 |
(int) $args['width'], |
|
16 | 2986 |
$extra_attr |
9 | 2987 |
); |
2988 |
||
2989 |
/** |
|
16 | 2990 |
* Filters the HTML for a user's avatar. |
9 | 2991 |
* |
2992 |
* @since 2.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2993 |
* @since 4.2.0 Added the `$args` parameter. |
9 | 2994 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2995 |
* @param string $avatar HTML for the user's avatar. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2996 |
* @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2997 |
* user email, WP_User object, WP_Post object, or WP_Comment object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2998 |
* @param int $size Height and width of the avatar in pixels. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2999 |
* @param string $default_value URL for the default image or a default type. Accepts: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3000 |
* - '404' (return a 404 instead of a default image) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3001 |
* - 'retro' (a 8-bit arcade-style pixelated face) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3002 |
* - 'robohash' (a robot) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3003 |
* - 'monsterid' (a monster) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3004 |
* - 'wavatar' (a cartoon face) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3005 |
* - 'identicon' (the "quilt", a geometric pattern) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3006 |
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3007 |
* - 'blank' (transparent GIF) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3008 |
* - 'gravatar_default' (the Gravatar logo) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3009 |
* @param string $alt Alternative text to use in the avatar image tag. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3010 |
* @param array $args Arguments passed to get_avatar_data(), after processing. |
9 | 3011 |
*/ |
5 | 3012 |
return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args ); |
0 | 3013 |
} |
3014 |
endif; |
|
3015 |
||
9 | 3016 |
if ( ! function_exists( 'wp_text_diff' ) ) : |
3017 |
/** |
|
3018 |
* Displays a human readable HTML representation of the difference between two strings. |
|
3019 |
* |
|
3020 |
* The Diff is available for getting the changes between versions. The output is |
|
3021 |
* HTML, so the primary use is for displaying the changes. If the two strings |
|
3022 |
* are equivalent, then an empty string will be returned. |
|
3023 |
* |
|
3024 |
* @since 2.6.0 |
|
3025 |
* |
|
3026 |
* @see wp_parse_args() Used to change defaults to user defined settings. |
|
3027 |
* @uses Text_Diff |
|
3028 |
* @uses WP_Text_Diff_Renderer_Table |
|
3029 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3030 |
* @param string $left_string "old" (left) version of string. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3031 |
* @param string $right_string "new" (right) version of string. |
16 | 3032 |
* @param string|array $args { |
3033 |
* Associative array of options to pass to WP_Text_Diff_Renderer_Table(). |
|
3034 |
* |
|
3035 |
* @type string $title Titles the diff in a manner compatible |
|
3036 |
* with the output. Default empty. |
|
3037 |
* @type string $title_left Change the HTML to the left of the title. |
|
3038 |
* Default empty. |
|
3039 |
* @type string $title_right Change the HTML to the right of the title. |
|
3040 |
* Default empty. |
|
3041 |
* @type bool $show_split_view True for split view (two columns), false for |
|
3042 |
* un-split view (single column). Default true. |
|
3043 |
* } |
|
9 | 3044 |
* @return string Empty string if strings are equivalent or HTML with differences. |
3045 |
*/ |
|
3046 |
function wp_text_diff( $left_string, $right_string, $args = null ) { |
|
3047 |
$defaults = array( |
|
16 | 3048 |
'title' => '', |
3049 |
'title_left' => '', |
|
3050 |
'title_right' => '', |
|
3051 |
'show_split_view' => true, |
|
9 | 3052 |
); |
3053 |
$args = wp_parse_args( $args, $defaults ); |
|
0 | 3054 |
|
9 | 3055 |
if ( ! class_exists( 'WP_Text_Diff_Renderer_Table', false ) ) { |
16 | 3056 |
require ABSPATH . WPINC . '/wp-diff.php'; |
9 | 3057 |
} |
0 | 3058 |
|
9 | 3059 |
$left_string = normalize_whitespace( $left_string ); |
3060 |
$right_string = normalize_whitespace( $right_string ); |
|
3061 |
||
3062 |
$left_lines = explode( "\n", $left_string ); |
|
3063 |
$right_lines = explode( "\n", $right_string ); |
|
3064 |
$text_diff = new Text_Diff( $left_lines, $right_lines ); |
|
3065 |
$renderer = new WP_Text_Diff_Renderer_Table( $args ); |
|
3066 |
$diff = $renderer->render( $text_diff ); |
|
0 | 3067 |
|
9 | 3068 |
if ( ! $diff ) { |
3069 |
return ''; |
|
3070 |
} |
|
3071 |
||
18 | 3072 |
$is_split_view = ! empty( $args['show_split_view'] ); |
3073 |
$is_split_view_class = $is_split_view ? ' is-split-view' : ''; |
|
9 | 3074 |
|
18 | 3075 |
$r = "<table class='diff$is_split_view_class'>\n"; |
3076 |
||
3077 |
if ( $args['title'] ) { |
|
3078 |
$r .= "<caption class='diff-title'>$args[title]</caption>\n"; |
|
9 | 3079 |
} |
0 | 3080 |
|
18 | 3081 |
if ( $args['title_left'] || $args['title_right'] ) { |
9 | 3082 |
$r .= '<thead>'; |
3083 |
} |
|
18 | 3084 |
|
9 | 3085 |
if ( $args['title_left'] || $args['title_right'] ) { |
18 | 3086 |
$th_or_td_left = empty( $args['title_left'] ) ? 'td' : 'th'; |
3087 |
$th_or_td_right = empty( $args['title_right'] ) ? 'td' : 'th'; |
|
3088 |
||
9 | 3089 |
$r .= "<tr class='diff-sub-title'>\n"; |
18 | 3090 |
$r .= "\t<$th_or_td_left>$args[title_left]</$th_or_td_left>\n"; |
3091 |
if ( $is_split_view ) { |
|
3092 |
$r .= "\t<$th_or_td_right>$args[title_right]</$th_or_td_right>\n"; |
|
3093 |
} |
|
9 | 3094 |
$r .= "</tr>\n"; |
3095 |
} |
|
18 | 3096 |
|
3097 |
if ( $args['title_left'] || $args['title_right'] ) { |
|
9 | 3098 |
$r .= "</thead>\n"; |
3099 |
} |
|
0 | 3100 |
|
9 | 3101 |
$r .= "<tbody>\n$diff\n</tbody>\n"; |
3102 |
$r .= '</table>'; |
|
3103 |
||
3104 |
return $r; |
|
0 | 3105 |
} |
3106 |
endif; |