3 * These functions can be replaced via plugins. If plugins do not redefine these
4 * functions, then these will be used instead.
9 if ( !function_exists('wp_set_current_user') ) :
11 * Changes the current user by ID or name.
13 * Set $id to null and specify a name if you do not know a user's ID.
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.
20 * @global object $current_user The current user object which holds the user data.
22 * @param int $id User ID
23 * @param string $name User's username
24 * @return WP_User Current user User object
26 function wp_set_current_user($id, $name = '') {
29 if ( isset( $current_user ) && ( $current_user instanceof WP_User ) && ( $id == $current_user->ID ) )
32 $current_user = new WP_User( $id, $name );
34 setup_userdata( $current_user->ID );
37 * Fires after the current user is set.
41 do_action( 'set_current_user' );
47 if ( !function_exists('wp_get_current_user') ) :
49 * Retrieve the current user object.
53 * @return WP_User Current user WP_User object
55 function wp_get_current_user() {
58 get_currentuserinfo();
64 if ( !function_exists('get_currentuserinfo') ) :
66 * Populate global variables with information about the currently logged in user.
68 * Will set the current user, if the current user is not set. The current user
69 * will be set to the logged-in person. If no user is logged-in, then it will
70 * set the current user to 0, which is invalid and won't have any permissions.
74 * @uses $current_user Checks if the current user is set
75 * @uses wp_validate_auth_cookie() Retrieves current logged in user.
77 * @return bool|null False on XML-RPC Request and invalid auth cookie. Null when current user set.
79 function get_currentuserinfo() {
82 if ( ! empty( $current_user ) ) {
83 if ( $current_user instanceof WP_User )
86 // Upgrade stdClass to WP_User
87 if ( is_object( $current_user ) && isset( $current_user->ID ) ) {
88 $cur_id = $current_user->ID;
90 wp_set_current_user( $cur_id );
94 // $current_user has a junk value. Force to WP_User with ID 0.
96 wp_set_current_user( 0 );
100 if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) {
101 wp_set_current_user( 0 );
106 * Filter the current user.
108 * The default filters use this to determine the current user from the
109 * request's cookies, if available.
111 * Returning a value of false will effectively short-circuit setting
116 * @param int|bool $user_id User ID if one has been determined, false otherwise.
118 $user_id = apply_filters( 'determine_current_user', false );
120 wp_set_current_user( 0 );
124 wp_set_current_user( $user_id );
128 if ( !function_exists('get_userdata') ) :
130 * Retrieve user info by user ID.
134 * @param int $user_id User ID
135 * @return WP_User|bool WP_User object on success, false on failure.
137 function get_userdata( $user_id ) {
138 return get_user_by( 'id', $user_id );
142 if ( !function_exists('get_user_by') ) :
144 * Retrieve user info by a given field
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 WP_User|bool WP_User object on success, false on failure.
152 function get_user_by( $field, $value ) {
153 $userdata = WP_User::get_data_by( $field, $value );
159 $user->init( $userdata );
165 if ( !function_exists('cache_users') ) :
167 * Retrieve info for user lists to prevent multiple queries by get_userdata()
171 * @param array $user_ids User ID numbers list
173 function cache_users( $user_ids ) {
176 $clean = _get_non_cached_ids( $user_ids, 'users' );
178 if ( empty( $clean ) )
181 $list = implode( ',', $clean );
183 $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" );
186 foreach ( $users as $user ) {
187 update_user_caches( $user );
190 update_meta_cache( 'user', $ids );
194 if ( !function_exists( 'wp_mail' ) ) :
196 * Send mail, similar to PHP's mail
198 * A true return value does not automatically mean that the user received the
199 * email successfully. It just only means that the method used was able to
200 * process the request without any errors.
202 * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from
203 * creating a from address like 'Name <email@address.com>' when both are set. If
204 * just 'wp_mail_from' is set, then just the email address will be used with no
207 * The default content type is 'text/plain' which does not allow using HTML.
208 * However, you can set the content type of the email by using the
209 * 'wp_mail_content_type' filter.
211 * The default charset is based on the charset used on the blog. The charset can
212 * be set using the 'wp_mail_charset' filter.
218 * @param string|array $to Array or comma-separated list of email addresses to send message.
219 * @param string $subject Email subject
220 * @param string $message Message contents
221 * @param string|array $headers Optional. Additional headers.
222 * @param string|array $attachments Optional. Files to attach.
223 * @return bool Whether the email contents were sent successfully.
225 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
226 // Compact the input, apply the filters, and extract them back out
229 * Filter the wp_mail() arguments.
233 * @param array $args A compacted array of wp_mail() arguments, including the "to" email,
234 * subject, message, headers, and attachments values.
236 $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) );
238 if ( isset( $atts['to'] ) ) {
242 if ( isset( $atts['subject'] ) ) {
243 $subject = $atts['subject'];
246 if ( isset( $atts['message'] ) ) {
247 $message = $atts['message'];
250 if ( isset( $atts['headers'] ) ) {
251 $headers = $atts['headers'];
254 if ( isset( $atts['attachments'] ) ) {
255 $attachments = $atts['attachments'];
258 if ( ! is_array( $attachments ) ) {
259 $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
263 // (Re)create it, if it's gone missing
264 if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
265 require_once ABSPATH . WPINC . '/class-phpmailer.php';
266 require_once ABSPATH . WPINC . '/class-smtp.php';
267 $phpmailer = new PHPMailer( true );
271 if ( empty( $headers ) ) {
274 if ( !is_array( $headers ) ) {
275 // Explode the headers out, so this function can take both
276 // string headers and an array of headers.
277 $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
279 $tempheaders = $headers;
285 // If it's actually got contents
286 if ( !empty( $tempheaders ) ) {
287 // Iterate through the raw headers
288 foreach ( (array) $tempheaders as $header ) {
289 if ( strpos($header, ':') === false ) {
290 if ( false !== stripos( $header, 'boundary=' ) ) {
291 $parts = preg_split('/boundary=/i', trim( $header ) );
292 $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
297 list( $name, $content ) = explode( ':', trim( $header ), 2 );
300 $name = trim( $name );
301 $content = trim( $content );
303 switch ( strtolower( $name ) ) {
304 // Mainly for legacy -- process a From: header if it's there
306 if ( strpos($content, '<' ) !== false ) {
307 // So... making my life hard again?
308 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
309 $from_name = str_replace( '"', '', $from_name );
310 $from_name = trim( $from_name );
312 $from_email = substr( $content, strpos( $content, '<' ) + 1 );
313 $from_email = str_replace( '>', '', $from_email );
314 $from_email = trim( $from_email );
316 $from_email = trim( $content );
320 if ( strpos( $content, ';' ) !== false ) {
321 list( $type, $charset ) = explode( ';', $content );
322 $content_type = trim( $type );
323 if ( false !== stripos( $charset, 'charset=' ) ) {
324 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) );
325 } elseif ( false !== stripos( $charset, 'boundary=' ) ) {
326 $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset ) );
330 $content_type = trim( $content );
334 $cc = array_merge( (array) $cc, explode( ',', $content ) );
337 $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
340 // Add it to our grand headers array
341 $headers[trim( $name )] = trim( $content );
348 // Empty out the values that may be set
349 $phpmailer->ClearAllRecipients();
350 $phpmailer->ClearAttachments();
351 $phpmailer->ClearCustomHeaders();
352 $phpmailer->ClearReplyTos();
354 // From email and name
355 // If we don't have a name from the input headers
356 if ( !isset( $from_name ) )
357 $from_name = 'WordPress';
359 /* If we don't have an email from the input headers default to wordpress@$sitename
360 * Some hosts will block outgoing mail from this address if it doesn't exist but
361 * there's no easy alternative. Defaulting to admin_email might appear to be another
362 * option but some hosts may refuse to relay mail from an unknown domain. See
363 * http://trac.wordpress.org/ticket/5007.
366 if ( !isset( $from_email ) ) {
367 // Get the site domain and get rid of www.
368 $sitename = strtolower( $_SERVER['SERVER_NAME'] );
369 if ( substr( $sitename, 0, 4 ) == 'www.' ) {
370 $sitename = substr( $sitename, 4 );
373 $from_email = 'wordpress@' . $sitename;
377 * Filter the email address to send from.
381 * @param string $from_email Email address to send from.
383 $phpmailer->From = apply_filters( 'wp_mail_from', $from_email );
386 * Filter the name to associate with the "from" email address.
390 * @param string $from_name Name associated with the "from" email address.
392 $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name );
394 // Set destination addresses
395 if ( !is_array( $to ) )
396 $to = explode( ',', $to );
398 foreach ( (array) $to as $recipient ) {
400 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
401 $recipient_name = '';
402 if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
403 if ( count( $matches ) == 3 ) {
404 $recipient_name = $matches[1];
405 $recipient = $matches[2];
408 $phpmailer->AddAddress( $recipient, $recipient_name);
409 } catch ( phpmailerException $e ) {
414 // Set mail's subject and body
415 $phpmailer->Subject = $subject;
416 $phpmailer->Body = $message;
418 // Add any CC and BCC recipients
419 if ( !empty( $cc ) ) {
420 foreach ( (array) $cc as $recipient ) {
422 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
423 $recipient_name = '';
424 if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
425 if ( count( $matches ) == 3 ) {
426 $recipient_name = $matches[1];
427 $recipient = $matches[2];
430 $phpmailer->AddCc( $recipient, $recipient_name );
431 } catch ( phpmailerException $e ) {
437 if ( !empty( $bcc ) ) {
438 foreach ( (array) $bcc as $recipient) {
440 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
441 $recipient_name = '';
442 if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
443 if ( count( $matches ) == 3 ) {
444 $recipient_name = $matches[1];
445 $recipient = $matches[2];
448 $phpmailer->AddBcc( $recipient, $recipient_name );
449 } catch ( phpmailerException $e ) {
455 // Set to use PHP's mail()
456 $phpmailer->IsMail();
458 // Set Content-Type and charset
459 // If we don't have a content-type from the input headers
460 if ( !isset( $content_type ) )
461 $content_type = 'text/plain';
464 * Filter the wp_mail() content type.
468 * @param string $content_type Default wp_mail() content type.
470 $content_type = apply_filters( 'wp_mail_content_type', $content_type );
472 $phpmailer->ContentType = $content_type;
474 // Set whether it's plaintext, depending on $content_type
475 if ( 'text/html' == $content_type )
476 $phpmailer->IsHTML( true );
478 // If we don't have a charset from the input headers
479 if ( !isset( $charset ) )
480 $charset = get_bloginfo( 'charset' );
482 // Set the content-type and charset
485 * Filter the default wp_mail() charset.
489 * @param string $charset Default email charset.
491 $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
493 // Set custom headers
494 if ( !empty( $headers ) ) {
495 foreach( (array) $headers as $name => $content ) {
496 $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
499 if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) )
500 $phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) );
503 if ( !empty( $attachments ) ) {
504 foreach ( $attachments as $attachment ) {
506 $phpmailer->AddAttachment($attachment);
507 } catch ( phpmailerException $e ) {
514 * Fires after PHPMailer is initialized.
518 * @param PHPMailer &$phpmailer The PHPMailer instance, passed by reference.
520 do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
524 return $phpmailer->Send();
525 } catch ( phpmailerException $e ) {
531 if ( !function_exists('wp_authenticate') ) :
533 * Checks a user's login information and logs them in if it checks out.
537 * @param string $username User's username
538 * @param string $password User's password
539 * @return WP_User|WP_Error WP_User object if login successful, otherwise WP_Error object.
541 function wp_authenticate($username, $password) {
542 $username = sanitize_user($username);
543 $password = trim($password);
546 * Filter the user to authenticate.
548 * If a non-null value is passed, the filter will effectively short-circuit
549 * authentication, returning an error instead.
553 * @param null|WP_User $user User to authenticate.
554 * @param string $username User login.
555 * @param string $password User password
557 $user = apply_filters( 'authenticate', null, $username, $password );
559 if ( $user == null ) {
560 // TODO what should the error message be? (Or would these even happen?)
561 // Only needed if all authentication handlers fail to return anything.
562 $user = new WP_Error('authentication_failed', __('<strong>ERROR</strong>: Invalid username or incorrect password.'));
565 $ignore_codes = array('empty_username', 'empty_password');
567 if (is_wp_error($user) && !in_array($user->get_error_code(), $ignore_codes) ) {
569 * Fires after a user login has failed.
573 * @param string $username User login.
575 do_action( 'wp_login_failed', $username );
582 if ( !function_exists('wp_logout') ) :
584 * Log the current user out.
588 function wp_logout() {
589 wp_destroy_current_session();
590 wp_clear_auth_cookie();
593 * Fires after a user is logged-out.
597 do_action( 'wp_logout' );
601 if ( !function_exists('wp_validate_auth_cookie') ) :
603 * Validates authentication cookie.
605 * The checks include making sure that the authentication cookie is set and
606 * pulling in the contents (if $cookie is not used).
608 * Makes sure the cookie is not expired. Verifies the hash in cookie is what is
609 * should be and compares the two.
613 * @param string $cookie Optional. If used, will validate contents instead of cookie's
614 * @param string $scheme Optional. The cookie scheme to use: auth, secure_auth, or logged_in
615 * @return bool|int False if invalid cookie, User ID if valid.
617 function wp_validate_auth_cookie($cookie = '', $scheme = '') {
618 if ( ! $cookie_elements = wp_parse_auth_cookie($cookie, $scheme) ) {
620 * Fires if an authentication cookie is malformed.
624 * @param string $cookie Malformed auth cookie.
625 * @param string $scheme Authentication scheme. Values include 'auth', 'secure_auth',
628 do_action( 'auth_cookie_malformed', $cookie, $scheme );
632 $scheme = $cookie_elements['scheme'];
633 $username = $cookie_elements['username'];
634 $hmac = $cookie_elements['hmac'];
635 $token = $cookie_elements['token'];
636 $expired = $expiration = $cookie_elements['expiration'];
638 // Allow a grace period for POST and AJAX requests
639 if ( defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD'] ) {
640 $expired += HOUR_IN_SECONDS;
643 // Quick check to see if an honest cookie has expired
644 if ( $expired < time() ) {
646 * Fires once an authentication cookie has expired.
650 * @param array $cookie_elements An array of data for the authentication cookie.
652 do_action( 'auth_cookie_expired', $cookie_elements );
656 $user = get_user_by('login', $username);
659 * Fires if a bad username is entered in the user authentication process.
663 * @param array $cookie_elements An array of data for the authentication cookie.
665 do_action( 'auth_cookie_bad_username', $cookie_elements );
669 $pass_frag = substr($user->user_pass, 8, 4);
671 $key = wp_hash( $username . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme );
673 // If ext/hash is not present, compat.php's hash_hmac() does not support sha256.
674 $algo = function_exists( 'hash' ) ? 'sha256' : 'sha1';
675 $hash = hash_hmac( $algo, $username . '|' . $expiration . '|' . $token, $key );
677 if ( ! hash_equals( $hash, $hmac ) ) {
679 * Fires if a bad authentication cookie hash is encountered.
683 * @param array $cookie_elements An array of data for the authentication cookie.
685 do_action( 'auth_cookie_bad_hash', $cookie_elements );
689 $manager = WP_Session_Tokens::get_instance( $user->ID );
690 if ( ! $manager->verify( $token ) ) {
691 do_action( 'auth_cookie_bad_session_token', $cookie_elements );
695 // AJAX/POST grace period set above
696 if ( $expiration < time() ) {
697 $GLOBALS['login_grace_period'] = 1;
701 * Fires once an authentication cookie has been validated.
705 * @param array $cookie_elements An array of data for the authentication cookie.
706 * @param WP_User $user User object.
708 do_action( 'auth_cookie_valid', $cookie_elements, $user );
714 if ( !function_exists('wp_generate_auth_cookie') ) :
716 * Generate authentication cookie contents.
720 * @param int $user_id User ID
721 * @param int $expiration Cookie expiration in seconds
722 * @param string $scheme Optional. The cookie scheme to use: auth, secure_auth, or logged_in
723 * @param string $token User's session token to use for this cookie
724 * @return string Authentication cookie contents. Empty string if user does not exist.
726 function wp_generate_auth_cookie( $user_id, $expiration, $scheme = 'auth', $token = '' ) {
727 $user = get_userdata($user_id);
733 $manager = WP_Session_Tokens::get_instance( $user_id );
734 $token = $manager->create( $expiration );
737 $pass_frag = substr($user->user_pass, 8, 4);
739 $key = wp_hash( $user->user_login . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme );
741 // If ext/hash is not present, compat.php's hash_hmac() does not support sha256.
742 $algo = function_exists( 'hash' ) ? 'sha256' : 'sha1';
743 $hash = hash_hmac( $algo, $user->user_login . '|' . $expiration . '|' . $token, $key );
745 $cookie = $user->user_login . '|' . $expiration . '|' . $token . '|' . $hash;
748 * Filter the authentication cookie.
752 * @param string $cookie Authentication cookie.
753 * @param int $user_id User ID.
754 * @param int $expiration Authentication cookie expiration in seconds.
755 * @param string $scheme Cookie scheme used. Accepts 'auth', 'secure_auth', or 'logged_in'.
756 * @param string $token User's session token used.
758 return apply_filters( 'auth_cookie', $cookie, $user_id, $expiration, $scheme, $token );
762 if ( !function_exists('wp_parse_auth_cookie') ) :
764 * Parse a cookie into its components
768 * @param string $cookie
769 * @param string $scheme Optional. The cookie scheme to use: auth, secure_auth, or logged_in
770 * @return array Authentication cookie components
772 function wp_parse_auth_cookie($cookie = '', $scheme = '') {
773 if ( empty($cookie) ) {
776 $cookie_name = AUTH_COOKIE;
779 $cookie_name = SECURE_AUTH_COOKIE;
782 $cookie_name = LOGGED_IN_COOKIE;
786 $cookie_name = SECURE_AUTH_COOKIE;
787 $scheme = 'secure_auth';
789 $cookie_name = AUTH_COOKIE;
794 if ( empty($_COOKIE[$cookie_name]) )
796 $cookie = $_COOKIE[$cookie_name];
799 $cookie_elements = explode('|', $cookie);
800 if ( count( $cookie_elements ) !== 4 ) {
804 list( $username, $expiration, $token, $hmac ) = $cookie_elements;
806 return compact( 'username', 'expiration', 'token', 'hmac', 'scheme' );
810 if ( !function_exists('wp_set_auth_cookie') ) :
812 * Sets the authentication cookies based on user ID.
814 * The $remember parameter increases the time that the cookie will be kept. The
815 * default the cookie is kept without remembering is two days. When $remember is
816 * set, the cookies will be kept for 14 days or two weeks.
820 * @param int $user_id User ID
821 * @param bool $remember Whether to remember the user
822 * @param mixed $secure Whether the admin cookies should only be sent over HTTPS.
825 function wp_set_auth_cookie($user_id, $remember = false, $secure = '') {
828 * Filter the duration of the authentication cookie expiration period.
832 * @param int $length Duration of the expiration period in seconds.
833 * @param int $user_id User ID.
834 * @param bool $remember Whether to remember the user login. Default false.
836 $expiration = time() + apply_filters( 'auth_cookie_expiration', 14 * DAY_IN_SECONDS, $user_id, $remember );
839 * Ensure the browser will continue to send the cookie after the expiration time is reached.
840 * Needed for the login grace period in wp_validate_auth_cookie().
842 $expire = $expiration + ( 12 * HOUR_IN_SECONDS );
844 /** This filter is documented in wp-includes/pluggable.php */
845 $expiration = time() + apply_filters( 'auth_cookie_expiration', 2 * DAY_IN_SECONDS, $user_id, $remember );
849 if ( '' === $secure ) {
853 // Frontend cookie is secure when the auth cookie is secure and the site's home URL is forced HTTPS.
854 $secure_logged_in_cookie = $secure && 'https' === parse_url( get_option( 'home' ), PHP_URL_SCHEME );
857 * Filter whether the connection is secure.
861 * @param bool $secure Whether the connection is secure.
862 * @param int $user_id User ID.
864 $secure = apply_filters( 'secure_auth_cookie', $secure, $user_id );
867 * Filter whether to use a secure cookie when logged-in.
871 * @param bool $secure_logged_in_cookie Whether to use a secure cookie when logged-in.
872 * @param int $user_id User ID.
873 * @param bool $secure Whether the connection is secure.
875 $secure_logged_in_cookie = apply_filters( 'secure_logged_in_cookie', $secure_logged_in_cookie, $user_id, $secure );
878 $auth_cookie_name = SECURE_AUTH_COOKIE;
879 $scheme = 'secure_auth';
881 $auth_cookie_name = AUTH_COOKIE;
885 $manager = WP_Session_Tokens::get_instance( $user_id );
886 $token = $manager->create( $expiration );
888 $auth_cookie = wp_generate_auth_cookie( $user_id, $expiration, $scheme, $token );
889 $logged_in_cookie = wp_generate_auth_cookie( $user_id, $expiration, 'logged_in', $token );
892 * Fires immediately before the authentication cookie is set.
896 * @param string $auth_cookie Authentication cookie.
897 * @param int $expire Login grace period in seconds. Default 43,200 seconds, or 12 hours.
898 * @param int $expiration Duration in seconds the authentication cookie should be valid.
899 * Default 1,209,600 seconds, or 14 days.
900 * @param int $user_id User ID.
901 * @param string $scheme Authentication scheme. Values include 'auth', 'secure_auth', or 'logged_in'.
903 do_action( 'set_auth_cookie', $auth_cookie, $expire, $expiration, $user_id, $scheme );
906 * Fires immediately before the secure authentication cookie is set.
910 * @param string $logged_in_cookie The logged-in cookie.
911 * @param int $expire Login grace period in seconds. Default 43,200 seconds, or 12 hours.
912 * @param int $expiration Duration in seconds the authentication cookie should be valid.
913 * Default 1,209,600 seconds, or 14 days.
914 * @param int $user_id User ID.
915 * @param string $scheme Authentication scheme. Default 'logged_in'.
917 do_action( 'set_logged_in_cookie', $logged_in_cookie, $expire, $expiration, $user_id, 'logged_in' );
919 setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true);
920 setcookie($auth_cookie_name, $auth_cookie, $expire, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, $secure, true);
921 setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true);
922 if ( COOKIEPATH != SITECOOKIEPATH )
923 setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, SITECOOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true);
927 if ( !function_exists('wp_clear_auth_cookie') ) :
929 * Removes all of the cookies associated with authentication.
933 function wp_clear_auth_cookie() {
935 * Fires just before the authentication cookies are cleared.
939 do_action( 'clear_auth_cookie' );
941 setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN );
942 setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN );
943 setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN );
944 setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN );
945 setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
946 setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
949 setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
950 setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
951 setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
952 setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
954 // Even older cookies
955 setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
956 setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
957 setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
958 setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
962 if ( !function_exists('is_user_logged_in') ) :
964 * Checks if the current visitor is a logged in user.
968 * @return bool True if user is logged in, false if not logged in.
970 function is_user_logged_in() {
971 $user = wp_get_current_user();
973 if ( ! $user->exists() )
980 if ( !function_exists('auth_redirect') ) :
982 * Checks if a user is logged in, if not it redirects them to the login page.
986 function auth_redirect() {
987 // Checks if a user is logged in, if not redirects them to the login page
989 $secure = ( is_ssl() || force_ssl_admin() );
992 * Filter whether to use a secure authentication redirect.
996 * @param bool $secure Whether to use a secure authentication redirect. Default false.
998 $secure = apply_filters( 'secure_auth_redirect', $secure );
1000 // If https is required and request is http, redirect
1001 if ( $secure && !is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
1002 if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
1003 wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
1006 wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1011 if ( is_user_admin() ) {
1012 $scheme = 'logged_in';
1015 * Filter the authentication redirect scheme.
1019 * @param string $scheme Authentication redirect scheme. Default empty.
1021 $scheme = apply_filters( 'auth_redirect_scheme', '' );
1024 if ( $user_id = wp_validate_auth_cookie( '', $scheme) ) {
1026 * Fires before the authentication redirect.
1030 * @param int $user_id User ID.
1032 do_action( 'auth_redirect', $user_id );
1034 // If the user wants ssl but the session is not ssl, redirect.
1035 if ( !$secure && get_user_option('use_ssl', $user_id) && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
1036 if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
1037 wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
1040 wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1045 return; // The cookie is good so we're done
1048 // The cookie is no good so force login
1051 $redirect = ( strpos( $_SERVER['REQUEST_URI'], '/options.php' ) && wp_get_referer() ) ? wp_get_referer() : set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1053 $login_url = wp_login_url($redirect, true);
1055 wp_redirect($login_url);
1060 if ( !function_exists('check_admin_referer') ) :
1062 * Makes sure that a user was referred from another admin page.
1064 * To avoid security exploits.
1068 * @param string $action Action nonce
1069 * @param string $query_arg where to look for nonce in $_REQUEST (since 2.5)
1071 function check_admin_referer($action = -1, $query_arg = '_wpnonce') {
1072 if ( -1 == $action )
1073 _doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '3.2' );
1075 $adminurl = strtolower(admin_url());
1076 $referer = strtolower(wp_get_referer());
1077 $result = isset($_REQUEST[$query_arg]) ? wp_verify_nonce($_REQUEST[$query_arg], $action) : false;
1078 if ( !$result && !(-1 == $action && strpos($referer, $adminurl) === 0) ) {
1079 wp_nonce_ays($action);
1084 * Fires once the admin request has been validated or not.
1088 * @param string $action The nonce action.
1089 * @param bool $result Whether the admin request nonce was validated.
1091 do_action( 'check_admin_referer', $action, $result );
1096 if ( !function_exists('check_ajax_referer') ) :
1098 * Verifies the AJAX request to prevent processing requests external of the blog.
1102 * @param string $action Action nonce
1103 * @param string $query_arg where to look for nonce in $_REQUEST (since 2.5)
1105 function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) {
1108 if ( $query_arg && isset( $_REQUEST[ $query_arg ] ) )
1109 $nonce = $_REQUEST[ $query_arg ];
1110 elseif ( isset( $_REQUEST['_ajax_nonce'] ) )
1111 $nonce = $_REQUEST['_ajax_nonce'];
1112 elseif ( isset( $_REQUEST['_wpnonce'] ) )
1113 $nonce = $_REQUEST['_wpnonce'];
1115 $result = wp_verify_nonce( $nonce, $action );
1117 if ( $die && false == $result ) {
1118 if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
1125 * Fires once the AJAX request has been validated or not.
1129 * @param string $action The AJAX nonce action.
1130 * @param bool $result Whether the AJAX request nonce was validated.
1132 do_action( 'check_ajax_referer', $action, $result );
1138 if ( !function_exists('wp_redirect') ) :
1140 * Redirects to another page.
1144 * @param string $location The path to redirect to.
1145 * @param int $status Status code to use.
1146 * @return bool False if $location is not provided, true otherwise.
1148 function wp_redirect($location, $status = 302) {
1152 * Filter the redirect location.
1156 * @param string $location The path to redirect to.
1157 * @param int $status Status code to use.
1159 $location = apply_filters( 'wp_redirect', $location, $status );
1162 * Filter the redirect status code.
1166 * @param int $status Status code to use.
1167 * @param string $location The path to redirect to.
1169 $status = apply_filters( 'wp_redirect_status', $status, $location );
1174 $location = wp_sanitize_redirect($location);
1176 if ( !$is_IIS && php_sapi_name() != 'cgi-fcgi' )
1177 status_header($status); // This causes problems on IIS and some FastCGI setups
1179 header("Location: $location", true, $status);
1185 if ( !function_exists('wp_sanitize_redirect') ) :
1187 * Sanitizes a URL for use in a redirect.
1191 * @return string redirect-sanitized URL
1193 function wp_sanitize_redirect($location) {
1194 $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%!*]|i', '', $location);
1195 $location = wp_kses_no_null($location);
1197 // remove %0d and %0a from location
1198 $strip = array('%0d', '%0a', '%0D', '%0A');
1199 $location = _deep_replace($strip, $location);
1204 if ( !function_exists('wp_safe_redirect') ) :
1206 * Performs a safe (local) redirect, using wp_redirect().
1208 * Checks whether the $location is using an allowed host, if it has an absolute
1209 * path. A plugin can therefore set or remove allowed host(s) to or from the
1212 * If the host is not allowed, then the redirect is to wp-admin on the siteurl
1213 * instead. This prevents malicious redirects which redirect to another host,
1214 * but only used in a few places.
1218 * @uses wp_validate_redirect() To validate the redirect is to an allowed host.
1220 * @return void Does not return anything
1222 function wp_safe_redirect($location, $status = 302) {
1224 // Need to look at the URL the way it will end up in wp_redirect()
1225 $location = wp_sanitize_redirect($location);
1227 $location = wp_validate_redirect($location, admin_url());
1229 wp_redirect($location, $status);
1233 if ( !function_exists('wp_validate_redirect') ) :
1235 * Validates a URL for use in a redirect.
1237 * Checks whether the $location is using an allowed host, if it has an absolute
1238 * path. A plugin can therefore set or remove allowed host(s) to or from the
1241 * If the host is not allowed, then the redirect is to $default supplied
1245 * @param string $location The redirect to validate
1246 * @param string $default The value to return if $location is not allowed
1247 * @return string redirect-sanitized URL
1249 function wp_validate_redirect($location, $default = '') {
1250 $location = trim( $location );
1251 // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
1252 if ( substr($location, 0, 2) == '//' )
1253 $location = 'http:' . $location;
1255 // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
1256 $test = ( $cut = strpos($location, '?') ) ? substr( $location, 0, $cut ) : $location;
1258 $lp = parse_url($test);
1260 // Give up if malformed URL
1261 if ( false === $lp )
1264 // Allow only http and https schemes. No data:, etc.
1265 if ( isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme']) )
1268 // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
1269 if ( isset($lp['scheme']) && !isset($lp['host']) )
1272 $wpp = parse_url(home_url());
1275 * Filter the whitelist of hosts to redirect to.
1279 * @param array $hosts An array of allowed hosts.
1280 * @param bool|string $host The parsed host; empty if not isset.
1282 $allowed_hosts = (array) apply_filters( 'allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '' );
1284 if ( isset($lp['host']) && ( !in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host'])) )
1285 $location = $default;
1291 if ( ! function_exists('wp_notify_postauthor') ) :
1293 * Notify an author (and/or others) of a comment/trackback/pingback on a post.
1297 * @param int $comment_id Comment ID
1298 * @param string $deprecated Not used
1299 * @return bool True on completion. False if no email addresses were specified.
1301 function wp_notify_postauthor( $comment_id, $deprecated = null ) {
1302 if ( null !== $deprecated ) {
1303 _deprecated_argument( __FUNCTION__, '3.8' );
1306 $comment = get_comment( $comment_id );
1307 if ( empty( $comment ) )
1310 $post = get_post( $comment->comment_post_ID );
1311 $author = get_userdata( $post->post_author );
1313 // Who to notify? By default, just the post author, but others can be added.
1316 $emails[] = $author->user_email;
1320 * Filter the list of email addresses to receive a comment notification.
1322 * By default, only post authors are notified of comments. This filter allows
1323 * others to be added.
1327 * @param array $emails An array of email addresses to receive a comment notification.
1328 * @param int $comment_id The comment ID.
1330 $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id );
1331 $emails = array_filter( $emails );
1333 // If there are no addresses to send the comment to, bail.
1334 if ( ! count( $emails ) ) {
1338 // Facilitate unsetting below without knowing the keys.
1339 $emails = array_flip( $emails );
1342 * Filter whether to notify comment authors of their comments on their own posts.
1344 * By default, comment authors aren't notified of their comments on their own
1345 * posts. This filter allows you to override that.
1349 * @param bool $notify Whether to notify the post author of their own comment.
1351 * @param int $comment_id The comment ID.
1353 $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment_id );
1355 // The comment was left by the author
1356 if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) {
1357 unset( $emails[ $author->user_email ] );
1360 // The author moderated a comment on their own post
1361 if ( $author && ! $notify_author && $post->post_author == get_current_user_id() ) {
1362 unset( $emails[ $author->user_email ] );
1365 // The post author is no longer a member of the blog
1366 if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) {
1367 unset( $emails[ $author->user_email ] );
1370 // If there's no email to send the comment to, bail, otherwise flip array back around for use below
1371 if ( ! count( $emails ) ) {
1374 $emails = array_flip( $emails );
1377 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
1379 // The blogname option is escaped with esc_html on the way into the database in sanitize_option
1380 // we want to reverse this for the plain text arena of emails.
1381 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
1383 switch ( $comment->comment_type ) {
1385 $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n";
1386 /* translators: 1: website name, 2: author IP, 3: author domain */
1387 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1388 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
1389 $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
1390 $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n";
1391 /* translators: 1: blog name, 2: post title */
1392 $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
1395 $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n";
1396 /* translators: 1: comment author, 2: author IP, 3: author domain */
1397 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1398 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
1399 $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n";
1400 $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n";
1401 /* translators: 1: blog name, 2: post title */
1402 $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
1404 default: // Comments
1405 $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
1406 /* translators: 1: comment author, 2: author IP, 3: author domain */
1407 $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1408 $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
1409 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
1410 $notify_message .= sprintf( __('Whois : http://whois.arin.net/rest/ip/%s'), $comment->comment_author_IP ) . "\r\n";
1411 $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
1412 $notify_message .= __('You can see all comments on this post here: ') . "\r\n";
1413 /* translators: 1: blog name, 2: post title */
1414 $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
1417 $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
1418 $notify_message .= sprintf( __('Permalink: %s'), get_comment_link( $comment_id ) ) . "\r\n";
1420 if ( user_can( $post->post_author, 'edit_comment', $comment_id ) ) {
1421 if ( EMPTY_TRASH_DAYS )
1422 $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n";
1424 $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n";
1425 $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n";
1428 $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
1430 if ( '' == $comment->comment_author ) {
1431 $from = "From: \"$blogname\" <$wp_email>";
1432 if ( '' != $comment->comment_author_email )
1433 $reply_to = "Reply-To: $comment->comment_author_email";
1435 $from = "From: \"$comment->comment_author\" <$wp_email>";
1436 if ( '' != $comment->comment_author_email )
1437 $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
1440 $message_headers = "$from\n"
1441 . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
1443 if ( isset($reply_to) )
1444 $message_headers .= $reply_to . "\n";
1447 * Filter the comment notification email text.
1451 * @param string $notify_message The comment notification email text.
1452 * @param int $comment_id Comment ID.
1454 $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment_id );
1457 * Filter the comment notification email subject.
1461 * @param string $subject The comment notification email subject.
1462 * @param int $comment_id Comment ID.
1464 $subject = apply_filters( 'comment_notification_subject', $subject, $comment_id );
1467 * Filter the comment notification email headers.
1471 * @param string $message_headers Headers for the comment notification email.
1472 * @param int $comment_id Comment ID.
1474 $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment_id );
1476 foreach ( $emails as $email ) {
1477 @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
1484 if ( !function_exists('wp_notify_moderator') ) :
1486 * Notifies the moderator of the blog about a new comment that is awaiting approval.
1492 * @param int $comment_id Comment ID
1493 * @return bool Always returns true
1495 function wp_notify_moderator($comment_id) {
1498 if ( 0 == get_option( 'moderation_notify' ) )
1501 $comment = get_comment($comment_id);
1502 $post = get_post($comment->comment_post_ID);
1503 $user = get_userdata( $post->post_author );
1504 // Send to the administration and to the post author if the author can modify the comment.
1505 $emails = array( get_option( 'admin_email' ) );
1506 if ( user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) {
1507 if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) )
1508 $emails[] = $user->user_email;
1511 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
1512 $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
1514 // The blogname option is escaped with esc_html on the way into the database in sanitize_option
1515 // we want to reverse this for the plain text arena of emails.
1516 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
1518 switch ( $comment->comment_type ) {
1520 $notify_message = sprintf( __('A new trackback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n";
1521 $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
1522 $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1523 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
1524 $notify_message .= __('Trackback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
1527 $notify_message = sprintf( __('A new pingback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n";
1528 $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
1529 $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1530 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
1531 $notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
1533 default: // Comments
1534 $notify_message = sprintf( __('A new comment on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n";
1535 $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
1536 $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1537 $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
1538 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
1539 $notify_message .= sprintf( __('Whois : http://whois.arin.net/rest/ip/%s'), $comment->comment_author_IP ) . "\r\n";
1540 $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
1544 $notify_message .= sprintf( __('Approve it: %s'), admin_url("comment.php?action=approve&c=$comment_id") ) . "\r\n";
1545 if ( EMPTY_TRASH_DAYS )
1546 $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n";
1548 $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n";
1549 $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n";
1551 $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:',
1552 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting) ) . "\r\n";
1553 $notify_message .= admin_url("edit-comments.php?comment_status=moderated") . "\r\n";
1555 $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title );
1556 $message_headers = '';
1559 * Filter the list of recipients for comment moderation emails.
1563 * @param array $emails List of email addresses to notify for comment moderation.
1564 * @param int $comment_id Comment ID.
1566 $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id );
1569 * Filter the comment moderation email text.
1573 * @param string $notify_message Text of the comment moderation email.
1574 * @param int $comment_id Comment ID.
1576 $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id );
1579 * Filter the comment moderation email subject.
1583 * @param string $subject Subject of the comment moderation email.
1584 * @param int $comment_id Comment ID.
1586 $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id );
1589 * Filter the comment moderation email headers.
1593 * @param string $message_headers Headers for the comment moderation email.
1594 * @param int $comment_id Comment ID.
1596 $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id );
1598 foreach ( $emails as $email ) {
1599 @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
1606 if ( !function_exists('wp_password_change_notification') ) :
1608 * Notify the blog admin of a user changing password, normally via email.
1612 * @param object $user User Object
1614 function wp_password_change_notification(&$user) {
1615 // send a copy of password change notification to the admin
1616 // but check to see if it's the admin whose password we're changing, and skip this
1617 if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) {
1618 $message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "\r\n";
1619 // The blogname option is escaped with esc_html on the way into the database in sanitize_option
1620 // we want to reverse this for the plain text arena of emails.
1621 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
1622 wp_mail(get_option('admin_email'), sprintf(__('[%s] Password Lost/Changed'), $blogname), $message);
1627 if ( !function_exists('wp_new_user_notification') ) :
1629 * Email login credentials to a newly-registered user.
1631 * A new user registration notification is also sent to admin email.
1635 * @param int $user_id User ID.
1636 * @param string $plaintext_pass Optional. The user's plaintext password. Default empty.
1638 function wp_new_user_notification($user_id, $plaintext_pass = '') {
1639 $user = get_userdata( $user_id );
1641 // The blogname option is escaped with esc_html on the way into the database in sanitize_option
1642 // we want to reverse this for the plain text arena of emails.
1643 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
1645 $message = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
1646 $message .= sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
1647 $message .= sprintf(__('E-mail: %s'), $user->user_email) . "\r\n";
1649 @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
1651 if ( empty($plaintext_pass) )
1654 $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
1655 $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
1656 $message .= wp_login_url() . "\r\n";
1658 wp_mail($user->user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
1663 if ( !function_exists('wp_nonce_tick') ) :
1665 * Get the time-dependent variable for nonce creation.
1667 * A nonce has a lifespan of two ticks. Nonces in their second tick may be
1668 * updated, e.g. by autosave.
1674 function wp_nonce_tick() {
1676 * Filter the lifespan of nonces in seconds.
1680 * @param int $lifespan Lifespan of nonces in seconds. Default 86,400 seconds, or one day.
1682 $nonce_life = apply_filters( 'nonce_life', DAY_IN_SECONDS );
1684 return ceil(time() / ( $nonce_life / 2 ));
1688 if ( !function_exists('wp_verify_nonce') ) :
1690 * Verify that correct nonce was used with time limit.
1692 * The user is given an amount of time to use the token, so therefore, since the
1693 * UID and $action remain the same, the independent variable is the time.
1697 * @param string $nonce Nonce that was used in the form to verify
1698 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
1699 * @return bool Whether the nonce check passed or failed.
1701 function wp_verify_nonce($nonce, $action = -1) {
1702 $user = wp_get_current_user();
1703 $uid = (int) $user->ID;
1706 * Filter whether the user who generated the nonce is logged out.
1710 * @param int $uid ID of the nonce-owning user.
1711 * @param string $action The nonce action.
1713 $uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
1716 if ( empty( $nonce ) ) {
1720 $token = wp_get_session_token();
1721 $i = wp_nonce_tick();
1723 // Nonce generated 0-12 hours ago
1724 $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10 );
1725 if ( hash_equals( $expected, $nonce ) ) {
1729 // Nonce generated 12-24 hours ago
1730 $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
1731 if ( hash_equals( $expected, $nonce ) ) {
1740 if ( !function_exists('wp_create_nonce') ) :
1742 * Creates a cryptographic token tied to a specific action, user, and window of time.
1746 * @param string $action Scalar value to add context to the nonce.
1747 * @return string The token.
1749 function wp_create_nonce($action = -1) {
1750 $user = wp_get_current_user();
1751 $uid = (int) $user->ID;
1753 /** This filter is documented in wp-includes/pluggable.php */
1754 $uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
1757 $token = wp_get_session_token();
1758 $i = wp_nonce_tick();
1760 return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
1764 if ( !function_exists('wp_salt') ) :
1766 * Get salt to add to hashes.
1768 * Salts are created using secret keys. Secret keys are located in two places:
1769 * in the database and in the wp-config.php file. The secret key in the database
1770 * is randomly generated and will be appended to the secret keys in wp-config.php.
1772 * The secret keys in wp-config.php should be updated to strong, random keys to maximize
1773 * security. Below is an example of how the secret key constants are defined.
1774 * Do not paste this example directly into wp-config.php. Instead, have a
1775 * {@link https://api.wordpress.org/secret-key/1.1/salt/ secret key created} just
1779 * define('AUTH_KEY', ' Xakm<o xQy rw4EMsLKM-?!T+,PFF})H4lzcW57AF0U@N@< >M%G4Yt>f`z]MON');
1780 * define('SECURE_AUTH_KEY', 'LzJ}op]mr|6+![P}Ak:uNdJCJZd>(Hx.-Mh#Tz)pCIU#uGEnfFz|f ;;eU%/U^O~');
1781 * define('LOGGED_IN_KEY', '|i|Ux`9<p-h$aFf(qnT:sDO:D1P^wZ$$/Ra@miTJi9G;ddp_<q}6H1)o|a +&JCM');
1782 * define('NONCE_KEY', '%:R{[P|,s.KuMltH5}cI;/k<Gx~j!f0I)m_sIyu+&NJZ)-iO>z7X>QYR0Z_XnZ@|');
1783 * define('AUTH_SALT', 'eZyT)-Naw]F8CwA*VaW#q*|.)g@o}||wf~@C-YSt}(dh_r6EbI#A,y|nU2{B#JBW');
1784 * define('SECURE_AUTH_SALT', '!=oLUTXh,QW=H `}`L|9/^4-3 STz},T(w}W<I`.JjPi)<Bmf1v,HpGe}T1:Xt7n');
1785 * define('LOGGED_IN_SALT', '+XSqHc;@Q*K_b|Z?NC[3H!!EONbh.n<+=uKR:>*c(u`g~EJBf#8u#R{mUEZrozmm');
1786 * define('NONCE_SALT', 'h`GXHhD>SLWVfg1(1(N{;.V!MoE(SfbA_ksP@&`+AycHcAV$+?@3q+rxV{%^VyKT');
1789 * Salting passwords helps against tools which has stored hashed values of
1790 * common dictionary strings. The added values makes it harder to crack.
1794 * @link https://api.wordpress.org/secret-key/1.1/salt/ Create secrets for wp-config.php
1796 * @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce)
1797 * @return string Salt value
1799 function wp_salt( $scheme = 'auth' ) {
1800 static $cached_salts = array();
1801 if ( isset( $cached_salts[ $scheme ] ) ) {
1803 * Filter the WordPress salt.
1807 * @param string $cached_salt Cached salt for the given scheme.
1808 * @param string $scheme Authentication scheme. Values include 'auth',
1809 * 'secure_auth', 'logged_in', and 'nonce'.
1811 return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme );
1814 static $duplicated_keys;
1815 if ( null === $duplicated_keys ) {
1816 $duplicated_keys = array( 'put your unique phrase here' => true );
1817 foreach ( array( 'AUTH', 'SECURE_AUTH', 'LOGGED_IN', 'NONCE', 'SECRET' ) as $first ) {
1818 foreach ( array( 'KEY', 'SALT' ) as $second ) {
1819 if ( ! defined( "{$first}_{$second}" ) ) {
1822 $value = constant( "{$first}_{$second}" );
1823 $duplicated_keys[ $value ] = isset( $duplicated_keys[ $value ] );
1832 if ( defined( 'SECRET_KEY' ) && SECRET_KEY && empty( $duplicated_keys[ SECRET_KEY ] ) ) {
1833 $values['key'] = SECRET_KEY;
1835 if ( 'auth' == $scheme && defined( 'SECRET_SALT' ) && SECRET_SALT && empty( $duplicated_keys[ SECRET_SALT ] ) ) {
1836 $values['salt'] = SECRET_SALT;
1839 if ( in_array( $scheme, array( 'auth', 'secure_auth', 'logged_in', 'nonce' ) ) ) {
1840 foreach ( array( 'key', 'salt' ) as $type ) {
1841 $const = strtoupper( "{$scheme}_{$type}" );
1842 if ( defined( $const ) && constant( $const ) && empty( $duplicated_keys[ constant( $const ) ] ) ) {
1843 $values[ $type ] = constant( $const );
1844 } elseif ( ! $values[ $type ] ) {
1845 $values[ $type ] = get_site_option( "{$scheme}_{$type}" );
1846 if ( ! $values[ $type ] ) {
1847 $values[ $type ] = wp_generate_password( 64, true, true );
1848 update_site_option( "{$scheme}_{$type}", $values[ $type ] );
1853 if ( ! $values['key'] ) {
1854 $values['key'] = get_site_option( 'secret_key' );
1855 if ( ! $values['key'] ) {
1856 $values['key'] = wp_generate_password( 64, true, true );
1857 update_site_option( 'secret_key', $values['key'] );
1860 $values['salt'] = hash_hmac( 'md5', $scheme, $values['key'] );
1863 $cached_salts[ $scheme ] = $values['key'] . $values['salt'];
1865 /** This filter is documented in wp-includes/pluggable.php */
1866 return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme );
1870 if ( !function_exists('wp_hash') ) :
1872 * Get hash of given string.
1875 * @uses wp_salt() Get WordPress salt
1877 * @param string $data Plain text to hash
1878 * @return string Hash of $data
1880 function wp_hash($data, $scheme = 'auth') {
1881 $salt = wp_salt($scheme);
1883 return hash_hmac('md5', $data, $salt);
1887 if ( !function_exists('wp_hash_password') ) :
1889 * Create a hash (encrypt) of a plain text password.
1891 * For integration with other applications, this function can be overwritten to
1892 * instead use the other package password checking algorithm.
1896 * @global object $wp_hasher PHPass object
1897 * @uses PasswordHash::HashPassword
1899 * @param string $password Plain text user password to hash
1900 * @return string The hash string of the password
1902 function wp_hash_password($password) {
1905 if ( empty($wp_hasher) ) {
1906 require_once( ABSPATH . WPINC . '/class-phpass.php');
1907 // By default, use the portable hash from phpass
1908 $wp_hasher = new PasswordHash(8, true);
1911 return $wp_hasher->HashPassword( trim( $password ) );
1915 if ( !function_exists('wp_check_password') ) :
1917 * Checks the plaintext password against the encrypted Password.
1919 * Maintains compatibility between old version and the new cookie authentication
1920 * protocol using PHPass library. The $hash parameter is the encrypted password
1921 * and the function compares the plain text password when encrypted similarly
1922 * against the already encrypted password to see if they match.
1924 * For integration with other applications, this function can be overwritten to
1925 * instead use the other package password checking algorithm.
1929 * @global object $wp_hasher PHPass object used for checking the password
1930 * against the $hash + $password
1931 * @uses PasswordHash::CheckPassword
1933 * @param string $password Plaintext user's password
1934 * @param string $hash Hash of the user's password to check against.
1935 * @return bool False, if the $password does not match the hashed password
1937 function wp_check_password($password, $hash, $user_id = '') {
1940 // If the hash is still md5...
1941 if ( strlen($hash) <= 32 ) {
1942 $check = hash_equals( $hash, md5( $password ) );
1943 if ( $check && $user_id ) {
1944 // Rehash using new hash.
1945 wp_set_password($password, $user_id);
1946 $hash = wp_hash_password($password);
1950 * Filter whether the plaintext password matches the encrypted password.
1954 * @param bool $check Whether the passwords match.
1955 * @param string $hash The hashed password.
1956 * @param int $user_id User ID.
1958 return apply_filters( 'check_password', $check, $password, $hash, $user_id );
1961 // If the stored hash is longer than an MD5, presume the
1962 // new style phpass portable hash.
1963 if ( empty($wp_hasher) ) {
1964 require_once( ABSPATH . WPINC . '/class-phpass.php');
1965 // By default, use the portable hash from phpass
1966 $wp_hasher = new PasswordHash(8, true);
1969 $check = $wp_hasher->CheckPassword($password, $hash);
1971 /** This filter is documented in wp-includes/pluggable.php */
1972 return apply_filters( 'check_password', $check, $password, $hash, $user_id );
1976 if ( !function_exists('wp_generate_password') ) :
1978 * Generates a random password drawn from the defined set of characters.
1982 * @param int $length The length of password to generate
1983 * @param bool $special_chars Whether to include standard special characters. Default true.
1984 * @param bool $extra_special_chars Whether to include other special characters. Used when
1985 * generating secret keys and salts. Default false.
1986 * @return string The random password
1988 function wp_generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) {
1989 $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
1990 if ( $special_chars )
1991 $chars .= '!@#$%^&*()';
1992 if ( $extra_special_chars )
1993 $chars .= '-_ []{}<>~`+=,.;:/?|';
1996 for ( $i = 0; $i < $length; $i++ ) {
1997 $password .= substr($chars, wp_rand(0, strlen($chars) - 1), 1);
2001 * Filter the randomly-generated password.
2005 * @param string $password The generated password.
2007 return apply_filters( 'random_password', $password );
2011 if ( !function_exists('wp_rand') ) :
2013 * Generates a random number
2017 * @param int $min Lower limit for the generated number
2018 * @param int $max Upper limit for the generated number
2019 * @return int A random number between min and max
2021 function wp_rand( $min = 0, $max = 0 ) {
2024 // Reset $rnd_value after 14 uses
2025 // 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value
2026 if ( strlen($rnd_value) < 8 ) {
2027 if ( defined( 'WP_SETUP_CONFIG' ) )
2030 $seed = get_transient('random_seed');
2031 $rnd_value = md5( uniqid(microtime() . mt_rand(), true ) . $seed );
2032 $rnd_value .= sha1($rnd_value);
2033 $rnd_value .= sha1($rnd_value . $seed);
2034 $seed = md5($seed . $rnd_value);
2035 if ( ! defined( 'WP_SETUP_CONFIG' ) )
2036 set_transient('random_seed', $seed);
2039 // Take the first 8 digits for our value
2040 $value = substr($rnd_value, 0, 8);
2042 // Strip the first eight, leaving the remainder for the next call to wp_rand().
2043 $rnd_value = substr($rnd_value, 8);
2045 $value = abs(hexdec($value));
2047 // Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
2048 $max_random_number = 3000000000 === 2147483647 ? (float) "4294967295" : 4294967295; // 4294967295 = 0xffffffff
2050 // Reduce the value to be within the min - max range
2052 $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 );
2054 return abs(intval($value));
2058 if ( !function_exists('wp_set_password') ) :
2060 * Updates the user's password with a new encrypted one.
2062 * For integration with other applications, this function can be overwritten to
2063 * instead use the other package password checking algorithm.
2065 * Please note: This function should be used sparingly and is really only meant for single-time
2066 * application. Leveraging this improperly in a plugin or theme could result in an endless loop
2067 * of password resets if precautions are not taken to ensure it does not execute on every page load.
2071 * @uses $wpdb WordPress database object for queries
2072 * @uses wp_hash_password() Used to encrypt the user's password before passing to the database
2074 * @param string $password The plaintext new user password
2075 * @param int $user_id User ID
2077 function wp_set_password( $password, $user_id ) {
2080 $hash = wp_hash_password( $password );
2081 $wpdb->update($wpdb->users, array('user_pass' => $hash, 'user_activation_key' => ''), array('ID' => $user_id) );
2083 wp_cache_delete($user_id, 'users');
2087 if ( !function_exists( 'get_avatar' ) ) :
2089 * Retrieve the avatar for a user who provided a user ID or email address.
2093 * @param int|string|object $id_or_email A user ID, email address, or comment object
2094 * @param int $size Size of the avatar image
2095 * @param string $default URL to a default image to use if no avatar is available
2096 * @param string $alt Alternative text to use in image tag. Defaults to blank
2097 * @return string <img> tag for the user's avatar
2099 function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false ) {
2100 if ( ! get_option('show_avatars') )
2103 if ( false === $alt)
2106 $safe_alt = esc_attr( $alt );
2108 if ( !is_numeric($size) )
2112 if ( is_numeric($id_or_email) ) {
2113 $id = (int) $id_or_email;
2114 $user = get_userdata($id);
2116 $email = $user->user_email;
2117 } elseif ( is_object($id_or_email) ) {
2118 // No avatar for pingbacks or trackbacks
2121 * Filter the list of allowed comment types for retrieving avatars.
2125 * @param array $types An array of content types. Default only contains 'comment'.
2127 $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
2128 if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) )
2131 if ( ! empty( $id_or_email->user_id ) ) {
2132 $id = (int) $id_or_email->user_id;
2133 $user = get_userdata($id);
2135 $email = $user->user_email;
2138 if ( ! $email && ! empty( $id_or_email->comment_author_email ) )
2139 $email = $id_or_email->comment_author_email;
2141 $email = $id_or_email;
2144 if ( empty($default) ) {
2145 $avatar_default = get_option('avatar_default');
2146 if ( empty($avatar_default) )
2147 $default = 'mystery';
2149 $default = $avatar_default;
2152 if ( !empty($email) )
2153 $email_hash = md5( strtolower( trim( $email ) ) );
2156 $host = 'https://secure.gravatar.com';
2158 if ( !empty($email) )
2159 $host = sprintf( "http://%d.gravatar.com", ( hexdec( $email_hash[0] ) % 2 ) );
2161 $host = 'http://0.gravatar.com';
2164 if ( 'mystery' == $default )
2165 $default = "$host/avatar/ad516503a11cd5ca435acc9bb6523536?s={$size}"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com')
2166 elseif ( 'blank' == $default )
2167 $default = $email ? 'blank' : includes_url( 'images/blank.gif' );
2168 elseif ( !empty($email) && 'gravatar_default' == $default )
2170 elseif ( 'gravatar_default' == $default )
2171 $default = "$host/avatar/?s={$size}";
2172 elseif ( empty($email) )
2173 $default = "$host/avatar/?d=$default&s={$size}";
2174 elseif ( strpos($default, 'http://') === 0 )
2175 $default = add_query_arg( 's', $size, $default );
2177 if ( !empty($email) ) {
2178 $out = "$host/avatar/";
2179 $out .= $email_hash;
2180 $out .= '?s='.$size;
2181 $out .= '&d=' . urlencode( $default );
2183 $rating = get_option('avatar_rating');
2184 if ( !empty( $rating ) )
2185 $out .= "&r={$rating}";
2187 $out = str_replace( '&', '&', esc_url( $out ) );
2188 $avatar = "<img alt='{$safe_alt}' src='{$out}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
2190 $out = esc_url( $default );
2191 $avatar = "<img alt='{$safe_alt}' src='{$out}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
2195 * Filter the avatar to retrieve.
2199 * @param string $avatar Image tag for the user's avatar.
2200 * @param int|object|string $id_or_email A user ID, email address, or comment object.
2201 * @param int $size Square avatar width and height in pixels to retrieve.
2202 * @param string $alt Alternative text to use in the avatar image tag.
2205 return apply_filters( 'get_avatar', $avatar, $id_or_email, $size, $default, $alt );
2209 if ( !function_exists( 'wp_text_diff' ) ) :
2211 * Displays a human readable HTML representation of the difference between two strings.
2213 * The Diff is available for getting the changes between versions. The output is
2214 * HTML, so the primary use is for displaying the changes. If the two strings
2215 * are equivalent, then an empty string will be returned.
2217 * The arguments supported and can be changed are listed below.
2219 * 'title' : Default is an empty string. Titles the diff in a manner compatible
2221 * 'title_left' : Default is an empty string. Change the HTML to the left of the
2223 * 'title_right' : Default is an empty string. Change the HTML to the right of
2228 * @see wp_parse_args() Used to change defaults to user defined settings.
2230 * @uses WP_Text_Diff_Renderer_Table
2232 * @param string $left_string "old" (left) version of string
2233 * @param string $right_string "new" (right) version of string
2234 * @param string|array $args Optional. Change 'title', 'title_left', and 'title_right' defaults.
2235 * @return string Empty string if strings are equivalent or HTML with differences.
2237 function wp_text_diff( $left_string, $right_string, $args = null ) {
2238 $defaults = array( 'title' => '', 'title_left' => '', 'title_right' => '' );
2239 $args = wp_parse_args( $args, $defaults );
2241 if ( !class_exists( 'WP_Text_Diff_Renderer_Table' ) )
2242 require( ABSPATH . WPINC . '/wp-diff.php' );
2244 $left_string = normalize_whitespace($left_string);
2245 $right_string = normalize_whitespace($right_string);
2247 $left_lines = explode("\n", $left_string);
2248 $right_lines = explode("\n", $right_string);
2249 $text_diff = new Text_Diff($left_lines, $right_lines);
2250 $renderer = new WP_Text_Diff_Renderer_Table( $args );
2251 $diff = $renderer->render($text_diff);
2256 $r = "<table class='diff'>\n";
2258 if ( ! empty( $args[ 'show_split_view' ] ) ) {
2259 $r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />";
2261 $r .= "<col class='content' />";
2264 if ( $args['title'] || $args['title_left'] || $args['title_right'] )
2266 if ( $args['title'] )
2267 $r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n";
2268 if ( $args['title_left'] || $args['title_right'] ) {
2269 $r .= "<tr class='diff-sub-title'>\n";
2270 $r .= "\t<td></td><th>$args[title_left]</th>\n";
2271 $r .= "\t<td></td><th>$args[title_right]</th>\n";
2274 if ( $args['title'] || $args['title_left'] || $args['title_right'] )
2277 $r .= "<tbody>\n$diff\n</tbody>\n";