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