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