90 * @return bool|null False on XMLRPC Request and invalid auth cookie. Null when current user set |
72 * @return bool|null False on XMLRPC Request and invalid auth cookie. Null when current user set |
91 */ |
73 */ |
92 function get_currentuserinfo() { |
74 function get_currentuserinfo() { |
93 global $current_user; |
75 global $current_user; |
94 |
76 |
95 if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) |
77 if ( ! empty( $current_user ) ) { |
|
78 if ( $current_user instanceof WP_User ) |
|
79 return; |
|
80 |
|
81 // Upgrade stdClass to WP_User |
|
82 if ( is_object( $current_user ) && isset( $current_user->ID ) ) { |
|
83 $cur_id = $current_user->ID; |
|
84 $current_user = null; |
|
85 wp_set_current_user( $cur_id ); |
|
86 return; |
|
87 } |
|
88 |
|
89 // $current_user has a junk value. Force to WP_User with ID 0. |
|
90 $current_user = null; |
|
91 wp_set_current_user( 0 ); |
96 return false; |
92 return false; |
97 |
93 } |
98 if ( ! empty($current_user) ) |
94 |
99 return; |
95 if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) { |
|
96 wp_set_current_user( 0 ); |
|
97 return false; |
|
98 } |
100 |
99 |
101 if ( ! $user = wp_validate_auth_cookie() ) { |
100 if ( ! $user = wp_validate_auth_cookie() ) { |
102 if ( is_admin() || empty($_COOKIE[LOGGED_IN_COOKIE]) || !$user = wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in') ) { |
101 if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[LOGGED_IN_COOKIE] ) || !$user = wp_validate_auth_cookie( $_COOKIE[LOGGED_IN_COOKIE], 'logged_in' ) ) { |
103 wp_set_current_user(0); |
102 wp_set_current_user( 0 ); |
104 return false; |
103 return false; |
105 } |
104 } |
106 } |
105 } |
107 |
106 |
108 wp_set_current_user($user); |
107 wp_set_current_user( $user ); |
109 } |
108 } |
110 endif; |
109 endif; |
111 |
110 |
112 if ( !function_exists('get_userdata') ) : |
111 if ( !function_exists('get_userdata') ) : |
113 /** |
112 /** |
114 * Retrieve user info by user ID. |
113 * Retrieve user info by user ID. |
115 * |
114 * |
116 * @since 0.71 |
115 * @since 0.71 |
117 * |
116 * |
118 * @param int $user_id User ID |
117 * @param int $user_id User ID |
119 * @return bool|object False on failure, User DB row object |
118 * @return bool|object False on failure, WP_User object on success |
120 */ |
119 */ |
121 function get_userdata( $user_id ) { |
120 function get_userdata( $user_id ) { |
|
121 return get_user_by( 'id', $user_id ); |
|
122 } |
|
123 endif; |
|
124 |
|
125 if ( !function_exists('get_user_by') ) : |
|
126 /** |
|
127 * Retrieve user info by a given field |
|
128 * |
|
129 * @since 2.8.0 |
|
130 * |
|
131 * @param string $field The field to retrieve the user with. id | slug | email | login |
|
132 * @param int|string $value A value for $field. A user ID, slug, email address, or login name. |
|
133 * @return bool|object False on failure, WP_User object on success |
|
134 */ |
|
135 function get_user_by( $field, $value ) { |
|
136 $userdata = WP_User::get_data_by( $field, $value ); |
|
137 |
|
138 if ( !$userdata ) |
|
139 return false; |
|
140 |
|
141 $user = new WP_User; |
|
142 $user->init( $userdata ); |
|
143 |
|
144 return $user; |
|
145 } |
|
146 endif; |
|
147 |
|
148 if ( !function_exists('cache_users') ) : |
|
149 /** |
|
150 * Retrieve info for user lists to prevent multiple queries by get_userdata() |
|
151 * |
|
152 * @since 3.0.0 |
|
153 * |
|
154 * @param array $user_ids User ID numbers list |
|
155 */ |
|
156 function cache_users( $user_ids ) { |
122 global $wpdb; |
157 global $wpdb; |
123 |
158 |
124 $user_id = absint($user_id); |
159 $clean = _get_non_cached_ids( $user_ids, 'users' ); |
125 if ( $user_id == 0 ) |
160 |
126 return false; |
161 if ( empty( $clean ) ) |
127 |
162 return; |
128 $user = wp_cache_get($user_id, 'users'); |
163 |
129 |
164 $list = implode( ',', $clean ); |
130 if ( $user ) |
165 |
131 return $user; |
166 $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" ); |
132 |
167 |
133 if ( !$user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE ID = %d LIMIT 1", $user_id)) ) |
168 $ids = array(); |
134 return false; |
169 foreach ( $users as $user ) { |
135 |
170 update_user_caches( $user ); |
136 _fill_user($user); |
171 $ids[] = $user->ID; |
137 |
172 } |
138 return $user; |
173 update_meta_cache( 'user', $ids ); |
139 } |
|
140 endif; |
|
141 |
|
142 if ( !function_exists('get_user_by') ) : |
|
143 /** |
|
144 * Retrieve user info by a given field |
|
145 * |
|
146 * @since 2.8.0 |
|
147 * |
|
148 * @param string $field The field to retrieve the user with. id | slug | email | login |
|
149 * @param int|string $value A value for $field. A user ID, slug, email address, or login name. |
|
150 * @return bool|object False on failure, User DB row object |
|
151 */ |
|
152 function get_user_by($field, $value) { |
|
153 global $wpdb; |
|
154 |
|
155 switch ($field) { |
|
156 case 'id': |
|
157 return get_userdata($value); |
|
158 break; |
|
159 case 'slug': |
|
160 $user_id = wp_cache_get($value, 'userslugs'); |
|
161 $field = 'user_nicename'; |
|
162 break; |
|
163 case 'email': |
|
164 $user_id = wp_cache_get($value, 'useremail'); |
|
165 $field = 'user_email'; |
|
166 break; |
|
167 case 'login': |
|
168 $value = sanitize_user( $value ); |
|
169 $user_id = wp_cache_get($value, 'userlogins'); |
|
170 $field = 'user_login'; |
|
171 break; |
|
172 default: |
|
173 return false; |
|
174 } |
|
175 |
|
176 if ( false !== $user_id ) |
|
177 return get_userdata($user_id); |
|
178 |
|
179 if ( !$user = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->users WHERE $field = %s", $value) ) ) |
|
180 return false; |
|
181 |
|
182 _fill_user($user); |
|
183 |
|
184 return $user; |
|
185 } |
|
186 endif; |
|
187 |
|
188 if ( !function_exists('get_userdatabylogin') ) : |
|
189 /** |
|
190 * Retrieve user info by login name. |
|
191 * |
|
192 * @since 0.71 |
|
193 * |
|
194 * @param string $user_login User's username |
|
195 * @return bool|object False on failure, User DB row object |
|
196 */ |
|
197 function get_userdatabylogin($user_login) { |
|
198 return get_user_by('login', $user_login); |
|
199 } |
|
200 endif; |
|
201 |
|
202 if ( !function_exists('get_user_by_email') ) : |
|
203 /** |
|
204 * Retrieve user info by email. |
|
205 * |
|
206 * @since 2.5 |
|
207 * |
|
208 * @param string $email User's email address |
|
209 * @return bool|object False on failure, User DB row object |
|
210 */ |
|
211 function get_user_by_email($email) { |
|
212 return get_user_by('email', $email); |
|
213 } |
174 } |
214 endif; |
175 endif; |
215 |
176 |
216 if ( !function_exists( 'wp_mail' ) ) : |
177 if ( !function_exists( 'wp_mail' ) ) : |
217 /** |
178 /** |
254 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { |
214 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { |
255 // Compact the input, apply the filters, and extract them back out |
215 // Compact the input, apply the filters, and extract them back out |
256 extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) ); |
216 extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) ); |
257 |
217 |
258 if ( !is_array($attachments) ) |
218 if ( !is_array($attachments) ) |
259 $attachments = explode( "\n", $attachments ); |
219 $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) ); |
260 |
220 |
261 global $phpmailer; |
221 global $phpmailer; |
262 |
222 |
263 // (Re)create it, if it's gone missing |
223 // (Re)create it, if it's gone missing |
264 if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) { |
224 if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) { |
265 require_once ABSPATH . WPINC . '/class-phpmailer.php'; |
225 require_once ABSPATH . WPINC . '/class-phpmailer.php'; |
266 require_once ABSPATH . WPINC . '/class-smtp.php'; |
226 require_once ABSPATH . WPINC . '/class-smtp.php'; |
267 $phpmailer = new PHPMailer(); |
227 $phpmailer = new PHPMailer( true ); |
268 } |
228 } |
269 |
229 |
270 // Headers |
230 // Headers |
271 if ( empty( $headers ) ) { |
231 if ( empty( $headers ) ) { |
272 $headers = array(); |
232 $headers = array(); |
273 } else { |
233 } else { |
274 if ( !is_array( $headers ) ) { |
234 if ( !is_array( $headers ) ) { |
275 // Explode the headers out, so this function can take both |
235 // Explode the headers out, so this function can take both |
276 // string headers and an array of headers. |
236 // string headers and an array of headers. |
277 $tempheaders = (array) explode( "\n", $headers ); |
237 $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) ); |
278 } else { |
238 } else { |
279 $tempheaders = $headers; |
239 $tempheaders = $headers; |
280 } |
240 } |
281 $headers = array(); |
241 $headers = array(); |
|
242 $cc = array(); |
|
243 $bcc = array(); |
282 |
244 |
283 // If it's actually got contents |
245 // If it's actually got contents |
284 if ( !empty( $tempheaders ) ) { |
246 if ( !empty( $tempheaders ) ) { |
285 // Iterate through the raw headers |
247 // Iterate through the raw headers |
286 foreach ( (array) $tempheaders as $header ) { |
248 foreach ( (array) $tempheaders as $header ) { |
293 } |
255 } |
294 // Explode them out |
256 // Explode them out |
295 list( $name, $content ) = explode( ':', trim( $header ), 2 ); |
257 list( $name, $content ) = explode( ':', trim( $header ), 2 ); |
296 |
258 |
297 // Cleanup crew |
259 // Cleanup crew |
298 $name = trim( $name ); |
260 $name = trim( $name ); |
299 $content = trim( $content ); |
261 $content = trim( $content ); |
300 |
262 |
301 // Mainly for legacy -- process a From: header if it's there |
263 switch ( strtolower( $name ) ) { |
302 if ( 'from' == strtolower($name) ) { |
264 // Mainly for legacy -- process a From: header if it's there |
303 if ( strpos($content, '<' ) !== false ) { |
265 case 'from': |
304 // So... making my life hard again? |
266 if ( strpos($content, '<' ) !== false ) { |
305 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 ); |
267 // So... making my life hard again? |
306 $from_name = str_replace( '"', '', $from_name ); |
268 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 ); |
307 $from_name = trim( $from_name ); |
269 $from_name = str_replace( '"', '', $from_name ); |
308 |
270 $from_name = trim( $from_name ); |
309 $from_email = substr( $content, strpos( $content, '<' ) + 1 ); |
271 |
310 $from_email = str_replace( '>', '', $from_email ); |
272 $from_email = substr( $content, strpos( $content, '<' ) + 1 ); |
311 $from_email = trim( $from_email ); |
273 $from_email = str_replace( '>', '', $from_email ); |
312 } else { |
274 $from_email = trim( $from_email ); |
313 $from_email = trim( $content ); |
275 } else { |
314 } |
276 $from_email = trim( $content ); |
315 } elseif ( 'content-type' == strtolower($name) ) { |
|
316 if ( strpos( $content,';' ) !== false ) { |
|
317 list( $type, $charset ) = explode( ';', $content ); |
|
318 $content_type = trim( $type ); |
|
319 if ( false !== stripos( $charset, 'charset=' ) ) { |
|
320 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) ); |
|
321 } elseif ( false !== stripos( $charset, 'boundary=' ) ) { |
|
322 $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset ) ); |
|
323 $charset = ''; |
|
324 } |
277 } |
325 } else { |
278 break; |
326 $content_type = trim( $content ); |
279 case 'content-type': |
327 } |
280 if ( strpos( $content, ';' ) !== false ) { |
328 } elseif ( 'cc' == strtolower($name) ) { |
281 list( $type, $charset ) = explode( ';', $content ); |
329 $cc = explode(",", $content); |
282 $content_type = trim( $type ); |
330 } elseif ( 'bcc' == strtolower($name) ) { |
283 if ( false !== stripos( $charset, 'charset=' ) ) { |
331 $bcc = explode(",", $content); |
284 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) ); |
332 } else { |
285 } elseif ( false !== stripos( $charset, 'boundary=' ) ) { |
333 // Add it to our grand headers array |
286 $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset ) ); |
334 $headers[trim( $name )] = trim( $content ); |
287 $charset = ''; |
|
288 } |
|
289 } else { |
|
290 $content_type = trim( $content ); |
|
291 } |
|
292 break; |
|
293 case 'cc': |
|
294 $cc = array_merge( (array) $cc, explode( ',', $content ) ); |
|
295 break; |
|
296 case 'bcc': |
|
297 $bcc = array_merge( (array) $bcc, explode( ',', $content ) ); |
|
298 break; |
|
299 default: |
|
300 // Add it to our grand headers array |
|
301 $headers[trim( $name )] = trim( $content ); |
|
302 break; |
335 } |
303 } |
336 } |
304 } |
337 } |
305 } |
338 } |
306 } |
339 |
307 |
368 |
335 |
369 $from_email = 'wordpress@' . $sitename; |
336 $from_email = 'wordpress@' . $sitename; |
370 } |
337 } |
371 |
338 |
372 // Plugin authors can override the potentially troublesome default |
339 // Plugin authors can override the potentially troublesome default |
373 $phpmailer->From = apply_filters( 'wp_mail_from', $from_email ); |
340 $phpmailer->From = apply_filters( 'wp_mail_from' , $from_email ); |
374 $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name ); |
341 $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name ); |
375 |
342 |
376 // Set destination address |
343 // Set destination addresses |
377 $phpmailer->AddAddress( $to ); |
344 if ( !is_array( $to ) ) |
|
345 $to = explode( ',', $to ); |
|
346 |
|
347 foreach ( (array) $to as $recipient ) { |
|
348 try { |
|
349 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>" |
|
350 $recipient_name = ''; |
|
351 if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) { |
|
352 if ( count( $matches ) == 3 ) { |
|
353 $recipient_name = $matches[1]; |
|
354 $recipient = $matches[2]; |
|
355 } |
|
356 } |
|
357 $phpmailer->AddAddress( $recipient, $recipient_name); |
|
358 } catch ( phpmailerException $e ) { |
|
359 continue; |
|
360 } |
|
361 } |
378 |
362 |
379 // Set mail's subject and body |
363 // Set mail's subject and body |
380 $phpmailer->Subject = $subject; |
364 $phpmailer->Subject = $subject; |
381 $phpmailer->Body = $message; |
365 $phpmailer->Body = $message; |
382 |
366 |
383 // Add any CC and BCC recipients |
367 // Add any CC and BCC recipients |
384 if ( !empty($cc) ) { |
368 if ( !empty( $cc ) ) { |
385 foreach ( (array) $cc as $recipient ) { |
369 foreach ( (array) $cc as $recipient ) { |
386 $phpmailer->AddCc( trim($recipient) ); |
370 try { |
|
371 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>" |
|
372 $recipient_name = ''; |
|
373 if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) { |
|
374 if ( count( $matches ) == 3 ) { |
|
375 $recipient_name = $matches[1]; |
|
376 $recipient = $matches[2]; |
|
377 } |
|
378 } |
|
379 $phpmailer->AddCc( $recipient, $recipient_name ); |
|
380 } catch ( phpmailerException $e ) { |
|
381 continue; |
|
382 } |
387 } |
383 } |
388 } |
384 } |
389 if ( !empty($bcc) ) { |
385 |
|
386 if ( !empty( $bcc ) ) { |
390 foreach ( (array) $bcc as $recipient) { |
387 foreach ( (array) $bcc as $recipient) { |
391 $phpmailer->AddBcc( trim($recipient) ); |
388 try { |
|
389 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>" |
|
390 $recipient_name = ''; |
|
391 if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) { |
|
392 if ( count( $matches ) == 3 ) { |
|
393 $recipient_name = $matches[1]; |
|
394 $recipient = $matches[2]; |
|
395 } |
|
396 } |
|
397 $phpmailer->AddBcc( $recipient, $recipient_name ); |
|
398 } catch ( phpmailerException $e ) { |
|
399 continue; |
|
400 } |
392 } |
401 } |
393 } |
402 } |
394 |
403 |
395 // Set to use PHP's mail() |
404 // Set to use PHP's mail() |
396 $phpmailer->IsMail(); |
405 $phpmailer->IsMail(); |
397 |
406 |
398 // Set Content-Type and charset |
407 // Set Content-Type and charset |
399 // If we don't have a content-type from the input headers |
408 // If we don't have a content-type from the input headers |
400 if ( !isset( $content_type ) ) { |
409 if ( !isset( $content_type ) ) |
401 $content_type = 'text/plain'; |
410 $content_type = 'text/plain'; |
402 } |
|
403 |
411 |
404 $content_type = apply_filters( 'wp_mail_content_type', $content_type ); |
412 $content_type = apply_filters( 'wp_mail_content_type', $content_type ); |
405 |
413 |
406 $phpmailer->ContentType = $content_type; |
414 $phpmailer->ContentType = $content_type; |
407 |
415 |
408 // Set whether it's plaintext or not, depending on $content_type |
416 // Set whether it's plaintext, depending on $content_type |
409 if ( $content_type == 'text/html' ) { |
417 if ( 'text/html' == $content_type ) |
410 $phpmailer->IsHTML( true ); |
418 $phpmailer->IsHTML( true ); |
411 } |
|
412 |
419 |
413 // If we don't have a charset from the input headers |
420 // If we don't have a charset from the input headers |
414 if ( !isset( $charset ) ) { |
421 if ( !isset( $charset ) ) |
415 $charset = get_bloginfo( 'charset' ); |
422 $charset = get_bloginfo( 'charset' ); |
416 } |
|
417 |
423 |
418 // Set the content-type and charset |
424 // Set the content-type and charset |
419 $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset ); |
425 $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset ); |
420 |
426 |
421 // Set custom headers |
427 // Set custom headers |
422 if ( !empty( $headers ) ) { |
428 if ( !empty( $headers ) ) { |
423 foreach( (array) $headers as $name => $content ) { |
429 foreach( (array) $headers as $name => $content ) { |
424 $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) ); |
430 $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) ); |
425 } |
431 } |
426 if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) ) { |
432 |
|
433 if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) ) |
427 $phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) ); |
434 $phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) ); |
428 } |
|
429 } |
435 } |
430 |
436 |
431 if ( !empty( $attachments ) ) { |
437 if ( !empty( $attachments ) ) { |
432 foreach ( $attachments as $attachment ) { |
438 foreach ( $attachments as $attachment ) { |
433 $phpmailer->AddAttachment($attachment); |
439 try { |
|
440 $phpmailer->AddAttachment($attachment); |
|
441 } catch ( phpmailerException $e ) { |
|
442 continue; |
|
443 } |
434 } |
444 } |
435 } |
445 } |
436 |
446 |
437 do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); |
447 do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); |
438 |
448 |
439 // Send! |
449 // Send! |
440 $result = @$phpmailer->Send(); |
450 try { |
441 |
451 $phpmailer->Send(); |
442 return $result; |
452 } catch ( phpmailerException $e ) { |
|
453 return false; |
|
454 } |
|
455 |
|
456 return true; |
443 } |
457 } |
444 endif; |
458 endif; |
445 |
459 |
446 if ( !function_exists('wp_authenticate') ) : |
460 if ( !function_exists('wp_authenticate') ) : |
447 /** |
461 /** |
658 $logged_in_cookie = wp_generate_auth_cookie($user_id, $expiration, 'logged_in'); |
675 $logged_in_cookie = wp_generate_auth_cookie($user_id, $expiration, 'logged_in'); |
659 |
676 |
660 do_action('set_auth_cookie', $auth_cookie, $expire, $expiration, $user_id, $scheme); |
677 do_action('set_auth_cookie', $auth_cookie, $expire, $expiration, $user_id, $scheme); |
661 do_action('set_logged_in_cookie', $logged_in_cookie, $expire, $expiration, $user_id, 'logged_in'); |
678 do_action('set_logged_in_cookie', $logged_in_cookie, $expire, $expiration, $user_id, 'logged_in'); |
662 |
679 |
663 // Set httponly if the php version is >= 5.2.0 |
680 setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true); |
664 if ( version_compare(phpversion(), '5.2.0', 'ge') ) { |
681 setcookie($auth_cookie_name, $auth_cookie, $expire, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, $secure, true); |
665 setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true); |
682 setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true); |
666 setcookie($auth_cookie_name, $auth_cookie, $expire, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, $secure, true); |
683 if ( COOKIEPATH != SITECOOKIEPATH ) |
667 setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, false, true); |
684 setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, SITECOOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true); |
668 if ( COOKIEPATH != SITECOOKIEPATH ) |
|
669 setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, SITECOOKIEPATH, COOKIE_DOMAIN, false, true); |
|
670 } else { |
|
671 $cookie_domain = COOKIE_DOMAIN; |
|
672 if ( !empty($cookie_domain) ) |
|
673 $cookie_domain .= '; HttpOnly'; |
|
674 setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, $cookie_domain, $secure); |
|
675 setcookie($auth_cookie_name, $auth_cookie, $expire, ADMIN_COOKIE_PATH, $cookie_domain, $secure); |
|
676 setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, COOKIEPATH, $cookie_domain); |
|
677 if ( COOKIEPATH != SITECOOKIEPATH ) |
|
678 setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, SITECOOKIEPATH, $cookie_domain); |
|
679 } |
|
680 } |
685 } |
681 endif; |
686 endif; |
682 |
687 |
683 if ( !function_exists('wp_clear_auth_cookie') ) : |
688 if ( !function_exists('wp_clear_auth_cookie') ) : |
684 /** |
689 /** |
963 * |
988 * |
964 * @param int $comment_id Comment ID |
989 * @param int $comment_id Comment ID |
965 * @param string $comment_type Optional. The comment type either 'comment' (default), 'trackback', or 'pingback' |
990 * @param string $comment_type Optional. The comment type either 'comment' (default), 'trackback', or 'pingback' |
966 * @return bool False if user email does not exist. True on completion. |
991 * @return bool False if user email does not exist. True on completion. |
967 */ |
992 */ |
968 function wp_notify_postauthor($comment_id, $comment_type='') { |
993 function wp_notify_postauthor( $comment_id, $comment_type = '' ) { |
969 $comment = get_comment($comment_id); |
994 $comment = get_comment( $comment_id ); |
970 $post = get_post($comment->comment_post_ID); |
995 $post = get_post( $comment->comment_post_ID ); |
971 $user = get_userdata( $post->post_author ); |
996 $author = get_userdata( $post->post_author ); |
972 $current_user = wp_get_current_user(); |
997 |
973 |
998 // The comment was left by the author |
974 if ( $comment->user_id == $post->post_author ) return false; // The author moderated a comment on his own post |
999 if ( $comment->user_id == $post->post_author ) |
975 |
1000 return false; |
976 if ('' == $user->user_email) return false; // If there's no email to send the comment to |
1001 |
|
1002 // The author moderated a comment on his own post |
|
1003 if ( $post->post_author == get_current_user_id() ) |
|
1004 return false; |
|
1005 |
|
1006 // If there's no email to send the comment to |
|
1007 if ( '' == $author->user_email ) |
|
1008 return false; |
977 |
1009 |
978 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); |
1010 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); |
979 |
1011 |
980 // The blogname option is escaped with esc_html on the way into the database in sanitize_option |
1012 // The blogname option is escaped with esc_html on the way into the database in sanitize_option |
981 // we want to reverse this for the plain text arena of emails. |
1013 // we want to reverse this for the plain text arena of emails. |
982 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
1014 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
983 |
1015 |
984 if ( empty( $comment_type ) ) $comment_type = 'comment'; |
1016 if ( empty( $comment_type ) ) $comment_type = 'comment'; |
985 |
1017 |
986 if ('comment' == $comment_type) { |
1018 if ('comment' == $comment_type) { |
987 /* translators: 1: post id, 2: post title */ |
1019 $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n"; |
988 $notify_message = sprintf( __('New comment on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n"; |
|
989 /* translators: 1: comment author, 2: author IP, 3: author domain */ |
1020 /* translators: 1: comment author, 2: author IP, 3: author domain */ |
990 $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
1021 $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
991 $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n"; |
1022 $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n"; |
992 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
1023 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
993 $notify_message .= sprintf( __('Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n"; |
1024 $notify_message .= sprintf( __('Whois : http://whois.arin.net/rest/ip/%s'), $comment->comment_author_IP ) . "\r\n"; |
994 $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
1025 $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
995 $notify_message .= __('You can see all comments on this post here: ') . "\r\n"; |
1026 $notify_message .= __('You can see all comments on this post here: ') . "\r\n"; |
996 /* translators: 1: blog name, 2: post title */ |
1027 /* translators: 1: blog name, 2: post title */ |
997 $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title ); |
1028 $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title ); |
998 } elseif ('trackback' == $comment_type) { |
1029 } elseif ('trackback' == $comment_type) { |
999 /* translators: 1: post id, 2: post title */ |
1030 $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n"; |
1000 $notify_message = sprintf( __('New trackback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n"; |
|
1001 /* translators: 1: website name, 2: author IP, 3: author domain */ |
1031 /* translators: 1: website name, 2: author IP, 3: author domain */ |
1002 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
1032 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
1003 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
1033 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
1004 $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
1034 $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
1005 $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n"; |
1035 $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n"; |
1006 /* translators: 1: blog name, 2: post title */ |
1036 /* translators: 1: blog name, 2: post title */ |
1007 $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title ); |
1037 $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title ); |
1008 } elseif ('pingback' == $comment_type) { |
1038 } elseif ('pingback' == $comment_type) { |
1009 /* translators: 1: post id, 2: post title */ |
1039 $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n"; |
1010 $notify_message = sprintf( __('New pingback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n"; |
|
1011 /* translators: 1: comment author, 2: author IP, 3: author domain */ |
1040 /* translators: 1: comment author, 2: author IP, 3: author domain */ |
1012 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
1041 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
1013 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
1042 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
1014 $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n"; |
1043 $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n"; |
1015 $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n"; |
1044 $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n"; |
1016 /* translators: 1: blog name, 2: post title */ |
1045 /* translators: 1: blog name, 2: post title */ |
1017 $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title ); |
1046 $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title ); |
1018 } |
1047 } |
1019 $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n"; |
1048 $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n"; |
|
1049 $notify_message .= sprintf( __('Permalink: %s'), get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id ) . "\r\n"; |
1020 if ( EMPTY_TRASH_DAYS ) |
1050 if ( EMPTY_TRASH_DAYS ) |
1021 $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; |
1051 $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; |
1022 else |
1052 else |
1023 $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; |
1053 $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; |
1024 $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; |
1054 $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; |
1062 * @return bool Always returns true |
1092 * @return bool Always returns true |
1063 */ |
1093 */ |
1064 function wp_notify_moderator($comment_id) { |
1094 function wp_notify_moderator($comment_id) { |
1065 global $wpdb; |
1095 global $wpdb; |
1066 |
1096 |
1067 if( get_option( "moderation_notify" ) == 0 ) |
1097 if ( 0 == get_option( 'moderation_notify' ) ) |
1068 return true; |
1098 return true; |
1069 |
1099 |
1070 $comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_ID=%d LIMIT 1", $comment_id)); |
1100 $comment = get_comment($comment_id); |
1071 $post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID=%d LIMIT 1", $comment->comment_post_ID)); |
1101 $post = get_post($comment->comment_post_ID); |
|
1102 $user = get_userdata( $post->post_author ); |
|
1103 // Send to the administration and to the post author if the author can modify the comment. |
|
1104 $email_to = array( get_option('admin_email') ); |
|
1105 if ( user_can($user->ID, 'edit_comment', $comment_id) && !empty($user->user_email) && ( get_option('admin_email') != $user->user_email) ) |
|
1106 $email_to[] = $user->user_email; |
1072 |
1107 |
1073 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); |
1108 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); |
1074 $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'"); |
1109 $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'"); |
1075 |
1110 |
1076 // The blogname option is escaped with esc_html on the way into the database in sanitize_option |
1111 // The blogname option is escaped with esc_html on the way into the database in sanitize_option |
1077 // we want to reverse this for the plain text arena of emails. |
1112 // we want to reverse this for the plain text arena of emails. |
1078 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
1113 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
1079 |
1114 |
1080 switch ($comment->comment_type) |
1115 switch ($comment->comment_type) |
1081 { |
1116 { |
1082 case 'trackback': |
1117 case 'trackback': |
1083 $notify_message = sprintf( __('A new trackback on the post #%1$s "%2$s" is waiting for your approval'), $post->ID, $post->post_title ) . "\r\n"; |
1118 $notify_message = sprintf( __('A new trackback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; |
1084 $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; |
1119 $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; |
1085 $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
1120 $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
1086 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
1121 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
1087 $notify_message .= __('Trackback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
1122 $notify_message .= __('Trackback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
1088 break; |
1123 break; |
1089 case 'pingback': |
1124 case 'pingback': |
1090 $notify_message = sprintf( __('A new pingback on the post #%1$s "%2$s" is waiting for your approval'), $post->ID, $post->post_title ) . "\r\n"; |
1125 $notify_message = sprintf( __('A new pingback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; |
1091 $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; |
1126 $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; |
1092 $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
1127 $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
1093 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
1128 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
1094 $notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
1129 $notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
1095 break; |
1130 break; |
1096 default: //Comments |
1131 default: //Comments |
1097 $notify_message = sprintf( __('A new comment on the post #%1$s "%2$s" is waiting for your approval'), $post->ID, $post->post_title ) . "\r\n"; |
1132 $notify_message = sprintf( __('A new comment on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; |
1098 $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; |
1133 $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; |
1099 $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
1134 $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
1100 $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n"; |
1135 $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n"; |
1101 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
1136 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
1102 $notify_message .= sprintf( __('Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n"; |
1137 $notify_message .= sprintf( __('Whois : http://whois.arin.net/rest/ip/%s'), $comment->comment_author_IP ) . "\r\n"; |
1103 $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
1138 $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
1104 break; |
1139 break; |
1105 } |
1140 } |
1106 |
1141 |
1107 $notify_message .= sprintf( __('Approve it: %s'), admin_url("comment.php?action=approve&c=$comment_id") ) . "\r\n"; |
1142 $notify_message .= sprintf( __('Approve it: %s'), admin_url("comment.php?action=approve&c=$comment_id") ) . "\r\n"; |
1114 $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:', |
1149 $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:', |
1115 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting) ) . "\r\n"; |
1150 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting) ) . "\r\n"; |
1116 $notify_message .= admin_url("edit-comments.php?comment_status=moderated") . "\r\n"; |
1151 $notify_message .= admin_url("edit-comments.php?comment_status=moderated") . "\r\n"; |
1117 |
1152 |
1118 $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title ); |
1153 $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title ); |
1119 $admin_email = get_option('admin_email'); |
|
1120 $message_headers = ''; |
1154 $message_headers = ''; |
1121 |
1155 |
1122 $notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id); |
1156 $notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id); |
1123 $subject = apply_filters('comment_moderation_subject', $subject, $comment_id); |
1157 $subject = apply_filters('comment_moderation_subject', $subject, $comment_id); |
1124 $message_headers = apply_filters('comment_moderation_headers', $message_headers); |
1158 $message_headers = apply_filters('comment_moderation_headers', $message_headers); |
1125 |
1159 |
1126 @wp_mail($admin_email, $subject, $notify_message, $message_headers); |
1160 foreach ( $email_to as $email ) |
|
1161 @wp_mail($email, $subject, $notify_message, $message_headers); |
1127 |
1162 |
1128 return true; |
1163 return true; |
1129 } |
1164 } |
1130 endif; |
1165 endif; |
1131 |
1166 |
1244 * @param string|int $action Scalar value to add context to the nonce. |
1279 * @param string|int $action Scalar value to add context to the nonce. |
1245 * @return string The one use form token |
1280 * @return string The one use form token |
1246 */ |
1281 */ |
1247 function wp_create_nonce($action = -1) { |
1282 function wp_create_nonce($action = -1) { |
1248 $user = wp_get_current_user(); |
1283 $user = wp_get_current_user(); |
1249 $uid = (int) $user->id; |
1284 $uid = (int) $user->ID; |
1250 |
1285 |
1251 $i = wp_nonce_tick(); |
1286 $i = wp_nonce_tick(); |
1252 |
1287 |
1253 return substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10); |
1288 return substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10); |
1254 } |
1289 } |
1255 endif; |
1290 endif; |
1256 |
1291 |
1257 if ( !function_exists('wp_salt') ) : |
1292 if ( !function_exists('wp_salt') ) : |
1258 /** |
1293 /** |
1259 * Get salt to add to hashes to help prevent attacks. |
1294 * Get salt to add to hashes. |
1260 * |
1295 * |
1261 * The secret key is located in two places: the database in case the secret key |
1296 * Salts are created using secret keys. Secret keys are located in two places: |
1262 * isn't defined in the second place, which is in the wp-config.php file. If you |
1297 * in the database and in the wp-config.php file. The secret key in the database |
1263 * are going to set the secret key, then you must do so in the wp-config.php |
1298 * is randomly generated and will be appended to the secret keys in wp-config.php. |
1264 * file. |
1299 * |
1265 * |
1300 * The secret keys in wp-config.php should be updated to strong, random keys to maximize |
1266 * The secret key in the database is randomly generated and will be appended to |
1301 * security. Below is an example of how the secret key constants are defined. |
1267 * the secret key that is in wp-config.php file in some instances. It is |
1302 * Do not paste this example directly into wp-config.php. Instead, have a |
1268 * important to have the secret key defined or changed in wp-config.php. |
1303 * {@link https://api.wordpress.org/secret-key/1.1/salt/ secret key created} just |
1269 * |
1304 * for you. |
1270 * If you have installed WordPress 2.5 or later, then you will have the |
|
1271 * SECRET_KEY defined in the wp-config.php already. You will want to change the |
|
1272 * value in it because hackers will know what it is. If you have upgraded to |
|
1273 * WordPress 2.5 or later version from a version before WordPress 2.5, then you |
|
1274 * should add the constant to your wp-config.php file. |
|
1275 * |
|
1276 * Below is an example of how the SECRET_KEY constant is defined with a value. |
|
1277 * You must not copy the below example and paste into your wp-config.php. If you |
|
1278 * need an example, then you can have a |
|
1279 * {@link https://api.wordpress.org/secret-key/1.1/ secret key created} for you. |
|
1280 * |
1305 * |
1281 * <code> |
1306 * <code> |
1282 * define('SECRET_KEY', 'mAry1HadA15|\/|b17w55w1t3asSn09w'); |
1307 * define('AUTH_KEY', ' Xakm<o xQy rw4EMsLKM-?!T+,PFF})H4lzcW57AF0U@N@< >M%G4Yt>f`z]MON'); |
|
1308 * define('SECURE_AUTH_KEY', 'LzJ}op]mr|6+![P}Ak:uNdJCJZd>(Hx.-Mh#Tz)pCIU#uGEnfFz|f ;;eU%/U^O~'); |
|
1309 * define('LOGGED_IN_KEY', '|i|Ux`9<p-h$aFf(qnT:sDO:D1P^wZ$$/Ra@miTJi9G;ddp_<q}6H1)o|a +&JCM'); |
|
1310 * define('NONCE_KEY', '%:R{[P|,s.KuMltH5}cI;/k<Gx~j!f0I)m_sIyu+&NJZ)-iO>z7X>QYR0Z_XnZ@|'); |
|
1311 * define('AUTH_SALT', 'eZyT)-Naw]F8CwA*VaW#q*|.)g@o}||wf~@C-YSt}(dh_r6EbI#A,y|nU2{B#JBW'); |
|
1312 * define('SECURE_AUTH_SALT', '!=oLUTXh,QW=H `}`L|9/^4-3 STz},T(w}W<I`.JjPi)<Bmf1v,HpGe}T1:Xt7n'); |
|
1313 * define('LOGGED_IN_SALT', '+XSqHc;@Q*K_b|Z?NC[3H!!EONbh.n<+=uKR:>*c(u`g~EJBf#8u#R{mUEZrozmm'); |
|
1314 * define('NONCE_SALT', 'h`GXHhD>SLWVfg1(1(N{;.V!MoE(SfbA_ksP@&`+AycHcAV$+?@3q+rxV{%^VyKT'); |
1283 * </code> |
1315 * </code> |
1284 * |
1316 * |
1285 * Salting passwords helps against tools which has stored hashed values of |
1317 * Salting passwords helps against tools which has stored hashed values of |
1286 * common dictionary strings. The added values makes it harder to crack if given |
1318 * common dictionary strings. The added values makes it harder to crack. |
1287 * salt string is not weak. |
|
1288 * |
1319 * |
1289 * @since 2.5 |
1320 * @since 2.5 |
1290 * @link https://api.wordpress.org/secret-key/1.1/ Create a Secret Key for wp-config.php |
1321 * |
1291 * |
1322 * @link https://api.wordpress.org/secret-key/1.1/salt/ Create secrets for wp-config.php |
1292 * @return string Salt value from either 'SECRET_KEY' or 'secret' option |
1323 * |
1293 */ |
1324 * @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce) |
1294 function wp_salt($scheme = 'auth') { |
1325 * @return string Salt value |
1295 global $wp_default_secret_key; |
1326 */ |
1296 $secret_key = ''; |
1327 function wp_salt( $scheme = 'auth' ) { |
1297 if ( defined('SECRET_KEY') && ('' != SECRET_KEY) && ( $wp_default_secret_key != SECRET_KEY) ) |
1328 static $cached_salts = array(); |
1298 $secret_key = SECRET_KEY; |
1329 if ( isset( $cached_salts[ $scheme ] ) ) |
1299 |
1330 return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme ); |
1300 if ( 'auth' == $scheme ) { |
1331 |
1301 if ( defined('AUTH_KEY') && ('' != AUTH_KEY) && ( $wp_default_secret_key != AUTH_KEY) ) |
1332 static $duplicated_keys; |
1302 $secret_key = AUTH_KEY; |
1333 if ( null === $duplicated_keys ) { |
1303 |
1334 $duplicated_keys = array( 'put your unique phrase here' => true ); |
1304 if ( defined('AUTH_SALT') ) { |
1335 foreach ( array( 'AUTH', 'SECURE_AUTH', 'LOGGED_IN', 'NONCE', 'SECRET' ) as $first ) { |
1305 $salt = AUTH_SALT; |
1336 foreach ( array( 'KEY', 'SALT' ) as $second ) { |
1306 } elseif ( defined('SECRET_SALT') ) { |
1337 if ( ! defined( "{$first}_{$second}" ) ) |
1307 $salt = SECRET_SALT; |
1338 continue; |
1308 } else { |
1339 $value = constant( "{$first}_{$second}" ); |
1309 $salt = get_option('auth_salt'); |
1340 $duplicated_keys[ $value ] = isset( $duplicated_keys[ $value ] ); |
1310 if ( empty($salt) ) { |
|
1311 $salt = wp_generate_password(64); |
|
1312 update_option('auth_salt', $salt); |
|
1313 } |
1341 } |
1314 } |
1342 } |
1315 } elseif ( 'secure_auth' == $scheme ) { |
1343 } |
1316 if ( defined('SECURE_AUTH_KEY') && ('' != SECURE_AUTH_KEY) && ( $wp_default_secret_key != SECURE_AUTH_KEY) ) |
1344 |
1317 $secret_key = SECURE_AUTH_KEY; |
1345 $key = $salt = ''; |
1318 |
1346 if ( defined( 'SECRET_KEY' ) && SECRET_KEY && empty( $duplicated_keys[ SECRET_KEY ] ) ) |
1319 if ( defined('SECURE_AUTH_SALT') ) { |
1347 $key = SECRET_KEY; |
1320 $salt = SECURE_AUTH_SALT; |
1348 if ( 'auth' == $scheme && defined( 'SECRET_SALT' ) && SECRET_SALT && empty( $duplicated_keys[ SECRET_SALT ] ) ) |
1321 } else { |
1349 $salt = SECRET_SALT; |
1322 $salt = get_option('secure_auth_salt'); |
1350 |
1323 if ( empty($salt) ) { |
1351 if ( in_array( $scheme, array( 'auth', 'secure_auth', 'logged_in', 'nonce' ) ) ) { |
1324 $salt = wp_generate_password(64); |
1352 foreach ( array( 'key', 'salt' ) as $type ) { |
1325 update_option('secure_auth_salt', $salt); |
1353 $const = strtoupper( "{$scheme}_{$type}" ); |
1326 } |
1354 if ( defined( $const ) && constant( $const ) && empty( $duplicated_keys[ constant( $const ) ] ) ) { |
1327 } |
1355 $$type = constant( $const ); |
1328 } elseif ( 'logged_in' == $scheme ) { |
1356 } elseif ( ! $$type ) { |
1329 if ( defined('LOGGED_IN_KEY') && ('' != LOGGED_IN_KEY) && ( $wp_default_secret_key != LOGGED_IN_KEY) ) |
1357 $$type = get_site_option( "{$scheme}_{$type}" ); |
1330 $secret_key = LOGGED_IN_KEY; |
1358 if ( ! $$type ) { |
1331 |
1359 $$type = wp_generate_password( 64, true, true ); |
1332 if ( defined('LOGGED_IN_SALT') ) { |
1360 update_site_option( "{$scheme}_{$type}", $$type ); |
1333 $salt = LOGGED_IN_SALT; |
1361 } |
1334 } else { |
|
1335 $salt = get_option('logged_in_salt'); |
|
1336 if ( empty($salt) ) { |
|
1337 $salt = wp_generate_password(64); |
|
1338 update_option('logged_in_salt', $salt); |
|
1339 } |
|
1340 } |
|
1341 } elseif ( 'nonce' == $scheme ) { |
|
1342 if ( defined('NONCE_KEY') && ('' != NONCE_KEY) && ( $wp_default_secret_key != NONCE_KEY) ) |
|
1343 $secret_key = NONCE_KEY; |
|
1344 |
|
1345 if ( defined('NONCE_SALT') ) { |
|
1346 $salt = NONCE_SALT; |
|
1347 } else { |
|
1348 $salt = get_option('nonce_salt'); |
|
1349 if ( empty($salt) ) { |
|
1350 $salt = wp_generate_password(64); |
|
1351 update_option('nonce_salt', $salt); |
|
1352 } |
1362 } |
1353 } |
1363 } |
1354 } else { |
1364 } else { |
1355 // ensure each auth scheme has its own unique salt |
1365 if ( ! $key ) { |
1356 $salt = hash_hmac('md5', $scheme, $secret_key); |
1366 $key = get_site_option( 'secret_key' ); |
1357 } |
1367 if ( ! $key ) { |
1358 |
1368 $key = wp_generate_password( 64, true, true ); |
1359 return apply_filters('salt', $secret_key . $salt, $scheme); |
1369 update_site_option( 'secret_key', $key ); |
|
1370 } |
|
1371 } |
|
1372 $salt = hash_hmac( 'md5', $scheme, $key ); |
|
1373 } |
|
1374 |
|
1375 $cached_salts[ $scheme ] = $key . $salt; |
|
1376 return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme ); |
1360 } |
1377 } |
1361 endif; |
1378 endif; |
1362 |
1379 |
1363 if ( !function_exists('wp_hash') ) : |
1380 if ( !function_exists('wp_hash') ) : |
1364 /** |
1381 /** |
1459 * Generates a random password drawn from the defined set of characters. |
1476 * Generates a random password drawn from the defined set of characters. |
1460 * |
1477 * |
1461 * @since 2.5 |
1478 * @since 2.5 |
1462 * |
1479 * |
1463 * @param int $length The length of password to generate |
1480 * @param int $length The length of password to generate |
1464 * @param bool $special_chars Whether to include standard special characters |
1481 * @param bool $special_chars Whether to include standard special characters. Default true. |
|
1482 * @param bool $extra_special_chars Whether to include other special characters. Used when |
|
1483 * generating secret keys and salts. Default false. |
1465 * @return string The random password |
1484 * @return string The random password |
1466 **/ |
1485 **/ |
1467 function wp_generate_password($length = 12, $special_chars = true) { |
1486 function wp_generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) { |
1468 $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; |
1487 $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; |
1469 if ( $special_chars ) |
1488 if ( $special_chars ) |
1470 $chars .= '!@#$%^&*()'; |
1489 $chars .= '!@#$%^&*()'; |
|
1490 if ( $extra_special_chars ) |
|
1491 $chars .= '-_ []{}<>~`+=,.;:/?|'; |
1471 |
1492 |
1472 $password = ''; |
1493 $password = ''; |
1473 for ( $i = 0; $i < $length; $i++ ) |
1494 for ( $i = 0; $i < $length; $i++ ) { |
1474 $password .= substr($chars, wp_rand(0, strlen($chars) - 1), 1); |
1495 $password .= substr($chars, wp_rand(0, strlen($chars) - 1), 1); |
1475 return $password; |
1496 } |
|
1497 |
|
1498 // random_password filter was previously in random_password function which was deprecated |
|
1499 return apply_filters('random_password', $password); |
1476 } |
1500 } |
1477 endif; |
1501 endif; |
1478 |
1502 |
1479 if ( !function_exists('wp_rand') ) : |
1503 if ( !function_exists('wp_rand') ) : |
1480 /** |
1504 /** |
1593 $default = 'mystery'; |
1622 $default = 'mystery'; |
1594 else |
1623 else |
1595 $default = $avatar_default; |
1624 $default = $avatar_default; |
1596 } |
1625 } |
1597 |
1626 |
1598 if ( is_ssl() ) |
1627 if ( !empty($email) ) |
|
1628 $email_hash = md5( strtolower( trim( $email ) ) ); |
|
1629 |
|
1630 if ( is_ssl() ) { |
1599 $host = 'https://secure.gravatar.com'; |
1631 $host = 'https://secure.gravatar.com'; |
1600 else |
1632 } else { |
1601 $host = 'http://www.gravatar.com'; |
1633 if ( !empty($email) ) |
|
1634 $host = sprintf( "http://%d.gravatar.com", ( hexdec( $email_hash[0] ) % 2 ) ); |
|
1635 else |
|
1636 $host = 'http://0.gravatar.com'; |
|
1637 } |
1602 |
1638 |
1603 if ( 'mystery' == $default ) |
1639 if ( 'mystery' == $default ) |
1604 $default = "$host/avatar/ad516503a11cd5ca435acc9bb6523536?s={$size}"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com') |
1640 $default = "$host/avatar/ad516503a11cd5ca435acc9bb6523536?s={$size}"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com') |
1605 elseif ( 'blank' == $default ) |
1641 elseif ( 'blank' == $default ) |
1606 $default = includes_url('images/blank.gif'); |
1642 $default = includes_url('images/blank.gif'); |
1607 elseif ( !empty($email) && 'gravatar_default' == $default ) |
1643 elseif ( !empty($email) && 'gravatar_default' == $default ) |
1608 $default = ''; |
1644 $default = ''; |
1609 elseif ( 'gravatar_default' == $default ) |
1645 elseif ( 'gravatar_default' == $default ) |
1610 $default = "$host/avatar/s={$size}"; |
1646 $default = "$host/avatar/?s={$size}"; |
1611 elseif ( empty($email) ) |
1647 elseif ( empty($email) ) |
1612 $default = "$host/avatar/?d=$default&s={$size}"; |
1648 $default = "$host/avatar/?d=$default&s={$size}"; |
1613 elseif ( strpos($default, 'http://') === 0 ) |
1649 elseif ( strpos($default, 'http://') === 0 ) |
1614 $default = add_query_arg( 's', $size, $default ); |
1650 $default = add_query_arg( 's', $size, $default ); |
1615 |
1651 |
1616 if ( !empty($email) ) { |
1652 if ( !empty($email) ) { |
1617 $out = "$host/avatar/"; |
1653 $out = "$host/avatar/"; |
1618 $out .= md5( strtolower( $email ) ); |
1654 $out .= $email_hash; |
1619 $out .= '?s='.$size; |
1655 $out .= '?s='.$size; |
1620 $out .= '&d=' . urlencode( $default ); |
1656 $out .= '&d=' . urlencode( $default ); |
1621 |
1657 |
1622 $rating = get_option('avatar_rating'); |
1658 $rating = get_option('avatar_rating'); |
1623 if ( !empty( $rating ) ) |
1659 if ( !empty( $rating ) ) |
1627 } else { |
1663 } else { |
1628 $avatar = "<img alt='{$safe_alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />"; |
1664 $avatar = "<img alt='{$safe_alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />"; |
1629 } |
1665 } |
1630 |
1666 |
1631 return apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt); |
1667 return apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt); |
1632 } |
|
1633 endif; |
|
1634 |
|
1635 if ( !function_exists('wp_setcookie') ) : |
|
1636 /** |
|
1637 * Sets a cookie for a user who just logged in. |
|
1638 * |
|
1639 * @since 1.5 |
|
1640 * @deprecated Use wp_set_auth_cookie() |
|
1641 * @see wp_set_auth_cookie() |
|
1642 * |
|
1643 * @param string $username The user's username |
|
1644 * @param string $password Optional. The user's password |
|
1645 * @param bool $already_md5 Optional. Whether the password has already been through MD5 |
|
1646 * @param string $home Optional. Will be used instead of COOKIEPATH if set |
|
1647 * @param string $siteurl Optional. Will be used instead of SITECOOKIEPATH if set |
|
1648 * @param bool $remember Optional. Remember that the user is logged in |
|
1649 */ |
|
1650 function wp_setcookie($username, $password = '', $already_md5 = false, $home = '', $siteurl = '', $remember = false) { |
|
1651 _deprecated_function( __FUNCTION__, '2.5', 'wp_set_auth_cookie()' ); |
|
1652 $user = get_userdatabylogin($username); |
|
1653 wp_set_auth_cookie($user->ID, $remember); |
|
1654 } |
|
1655 endif; |
|
1656 |
|
1657 if ( !function_exists('wp_clearcookie') ) : |
|
1658 /** |
|
1659 * Clears the authentication cookie, logging the user out. |
|
1660 * |
|
1661 * @since 1.5 |
|
1662 * @deprecated Use wp_clear_auth_cookie() |
|
1663 * @see wp_clear_auth_cookie() |
|
1664 */ |
|
1665 function wp_clearcookie() { |
|
1666 _deprecated_function( __FUNCTION__, '2.5', 'wp_clear_auth_cookie()' ); |
|
1667 wp_clear_auth_cookie(); |
|
1668 } |
|
1669 endif; |
|
1670 |
|
1671 if ( !function_exists('wp_get_cookie_login') ): |
|
1672 /** |
|
1673 * Gets the user cookie login. |
|
1674 * |
|
1675 * This function is deprecated and should no longer be extended as it won't be |
|
1676 * used anywhere in WordPress. Also, plugins shouldn't use it either. |
|
1677 * |
|
1678 * @since 2.0.3 |
|
1679 * @deprecated No alternative |
|
1680 * |
|
1681 * @return bool Always returns false |
|
1682 */ |
|
1683 function wp_get_cookie_login() { |
|
1684 _deprecated_function( __FUNCTION__, '2.5', '' ); |
|
1685 return false; |
|
1686 } |
|
1687 endif; |
|
1688 |
|
1689 if ( !function_exists('wp_login') ) : |
|
1690 /** |
|
1691 * Checks a users login information and logs them in if it checks out. |
|
1692 * |
|
1693 * Use the global $error to get the reason why the login failed. If the username |
|
1694 * is blank, no error will be set, so assume blank username on that case. |
|
1695 * |
|
1696 * Plugins extending this function should also provide the global $error and set |
|
1697 * what the error is, so that those checking the global for why there was a |
|
1698 * failure can utilize it later. |
|
1699 * |
|
1700 * @since 1.2.2 |
|
1701 * @deprecated Use wp_signon() |
|
1702 * @global string $error Error when false is returned |
|
1703 * |
|
1704 * @param string $username User's username |
|
1705 * @param string $password User's password |
|
1706 * @param bool $deprecated Not used |
|
1707 * @return bool False on login failure, true on successful check |
|
1708 */ |
|
1709 function wp_login($username, $password, $deprecated = '') { |
|
1710 global $error; |
|
1711 |
|
1712 $user = wp_authenticate($username, $password); |
|
1713 |
|
1714 if ( ! is_wp_error($user) ) |
|
1715 return true; |
|
1716 |
|
1717 $error = $user->get_error_message(); |
|
1718 return false; |
|
1719 } |
1668 } |
1720 endif; |
1669 endif; |
1721 |
1670 |
1722 if ( !function_exists( 'wp_text_diff' ) ) : |
1671 if ( !function_exists( 'wp_text_diff' ) ) : |
1723 /** |
1672 /** |