Edit File by line
/home/zeestwma/richards.../wp-inclu...
File: pluggable.php
*/
[500] Fix | Delete
$phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
[501] Fix | Delete
[502] Fix | Delete
// Set custom headers.
[503] Fix | Delete
if ( ! empty( $headers ) ) {
[504] Fix | Delete
foreach ( (array) $headers as $name => $content ) {
[505] Fix | Delete
// Only add custom headers not added automatically by PHPMailer.
[506] Fix | Delete
if ( ! in_array( $name, array( 'MIME-Version', 'X-Mailer' ), true ) ) {
[507] Fix | Delete
try {
[508] Fix | Delete
$phpmailer->addCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
[509] Fix | Delete
} catch ( PHPMailer\PHPMailer\Exception $e ) {
[510] Fix | Delete
continue;
[511] Fix | Delete
}
[512] Fix | Delete
}
[513] Fix | Delete
}
[514] Fix | Delete
[515] Fix | Delete
if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) {
[516] Fix | Delete
$phpmailer->addCustomHeader( sprintf( 'Content-Type: %s; boundary="%s"', $content_type, $boundary ) );
[517] Fix | Delete
}
[518] Fix | Delete
}
[519] Fix | Delete
[520] Fix | Delete
if ( ! empty( $attachments ) ) {
[521] Fix | Delete
foreach ( $attachments as $filename => $attachment ) {
[522] Fix | Delete
$filename = is_string( $filename ) ? $filename : '';
[523] Fix | Delete
[524] Fix | Delete
try {
[525] Fix | Delete
$phpmailer->addAttachment( $attachment, $filename );
[526] Fix | Delete
} catch ( PHPMailer\PHPMailer\Exception $e ) {
[527] Fix | Delete
continue;
[528] Fix | Delete
}
[529] Fix | Delete
}
[530] Fix | Delete
}
[531] Fix | Delete
[532] Fix | Delete
/**
[533] Fix | Delete
* Fires after PHPMailer is initialized.
[534] Fix | Delete
*
[535] Fix | Delete
* @since 2.2.0
[536] Fix | Delete
*
[537] Fix | Delete
* @param PHPMailer $phpmailer The PHPMailer instance (passed by reference).
[538] Fix | Delete
*/
[539] Fix | Delete
do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
[540] Fix | Delete
[541] Fix | Delete
$mail_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
[542] Fix | Delete
[543] Fix | Delete
// Send!
[544] Fix | Delete
try {
[545] Fix | Delete
$send = $phpmailer->send();
[546] Fix | Delete
[547] Fix | Delete
/**
[548] Fix | Delete
* Fires after PHPMailer has successfully sent an email.
[549] Fix | Delete
*
[550] Fix | Delete
* The firing of this action does not necessarily mean that the recipient(s) received the
[551] Fix | Delete
* email successfully. It only means that the `send` method above was able to
[552] Fix | Delete
* process the request without any errors.
[553] Fix | Delete
*
[554] Fix | Delete
* @since 5.9.0
[555] Fix | Delete
*
[556] Fix | Delete
* @param array $mail_data {
[557] Fix | Delete
* An array containing the email recipient(s), subject, message, headers, and attachments.
[558] Fix | Delete
*
[559] Fix | Delete
* @type string[] $to Email addresses to send message.
[560] Fix | Delete
* @type string $subject Email subject.
[561] Fix | Delete
* @type string $message Message contents.
[562] Fix | Delete
* @type string[] $headers Additional headers.
[563] Fix | Delete
* @type string[] $attachments Paths to files to attach.
[564] Fix | Delete
* }
[565] Fix | Delete
*/
[566] Fix | Delete
do_action( 'wp_mail_succeeded', $mail_data );
[567] Fix | Delete
[568] Fix | Delete
return $send;
[569] Fix | Delete
} catch ( PHPMailer\PHPMailer\Exception $e ) {
[570] Fix | Delete
$mail_data['phpmailer_exception_code'] = $e->getCode();
[571] Fix | Delete
[572] Fix | Delete
/**
[573] Fix | Delete
* Fires after a PHPMailer\PHPMailer\Exception is caught.
[574] Fix | Delete
*
[575] Fix | Delete
* @since 4.4.0
[576] Fix | Delete
*
[577] Fix | Delete
* @param WP_Error $error A WP_Error object with the PHPMailer\PHPMailer\Exception message, and an array
[578] Fix | Delete
* containing the mail recipient, subject, message, headers, and attachments.
[579] Fix | Delete
*/
[580] Fix | Delete
do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_data ) );
[581] Fix | Delete
[582] Fix | Delete
return false;
[583] Fix | Delete
}
[584] Fix | Delete
}
[585] Fix | Delete
endif;
[586] Fix | Delete
[587] Fix | Delete
if ( ! function_exists( 'wp_authenticate' ) ) :
[588] Fix | Delete
/**
[589] Fix | Delete
* Authenticates a user, confirming the login credentials are valid.
[590] Fix | Delete
*
[591] Fix | Delete
* @since 2.5.0
[592] Fix | Delete
* @since 4.5.0 `$username` now accepts an email address.
[593] Fix | Delete
*
[594] Fix | Delete
* @param string $username User's username or email address.
[595] Fix | Delete
* @param string $password User's password.
[596] Fix | Delete
* @return WP_User|WP_Error WP_User object if the credentials are valid,
[597] Fix | Delete
* otherwise WP_Error.
[598] Fix | Delete
*/
[599] Fix | Delete
function wp_authenticate(
[600] Fix | Delete
$username,
[601] Fix | Delete
#[\SensitiveParameter]
[602] Fix | Delete
$password
[603] Fix | Delete
) {
[604] Fix | Delete
$username = sanitize_user( $username );
[605] Fix | Delete
$password = trim( $password );
[606] Fix | Delete
[607] Fix | Delete
/**
[608] Fix | Delete
* Filters whether a set of user login credentials are valid.
[609] Fix | Delete
*
[610] Fix | Delete
* A WP_User object is returned if the credentials authenticate a user.
[611] Fix | Delete
* WP_Error or null otherwise.
[612] Fix | Delete
*
[613] Fix | Delete
* @since 2.8.0
[614] Fix | Delete
* @since 4.5.0 `$username` now accepts an email address.
[615] Fix | Delete
*
[616] Fix | Delete
* @param null|WP_User|WP_Error $user WP_User if the user is authenticated.
[617] Fix | Delete
* WP_Error or null otherwise.
[618] Fix | Delete
* @param string $username Username or email address.
[619] Fix | Delete
* @param string $password User password.
[620] Fix | Delete
*/
[621] Fix | Delete
$user = apply_filters( 'authenticate', null, $username, $password );
[622] Fix | Delete
[623] Fix | Delete
if ( null === $user || false === $user ) {
[624] Fix | Delete
/*
[625] Fix | Delete
* TODO: What should the error message be? (Or would these even happen?)
[626] Fix | Delete
* Only needed if all authentication handlers fail to return anything.
[627] Fix | Delete
*/
[628] Fix | Delete
$user = new WP_Error( 'authentication_failed', __( '<strong>Error:</strong> Invalid username, email address or incorrect password.' ) );
[629] Fix | Delete
}
[630] Fix | Delete
[631] Fix | Delete
$ignore_codes = array( 'empty_username', 'empty_password' );
[632] Fix | Delete
[633] Fix | Delete
if ( is_wp_error( $user ) && ! in_array( $user->get_error_code(), $ignore_codes, true ) ) {
[634] Fix | Delete
$error = $user;
[635] Fix | Delete
[636] Fix | Delete
/**
[637] Fix | Delete
* Fires after a user login has failed.
[638] Fix | Delete
*
[639] Fix | Delete
* @since 2.5.0
[640] Fix | Delete
* @since 4.5.0 The value of `$username` can now be an email address.
[641] Fix | Delete
* @since 5.4.0 The `$error` parameter was added.
[642] Fix | Delete
*
[643] Fix | Delete
* @param string $username Username or email address.
[644] Fix | Delete
* @param WP_Error $error A WP_Error object with the authentication failure details.
[645] Fix | Delete
*/
[646] Fix | Delete
do_action( 'wp_login_failed', $username, $error );
[647] Fix | Delete
}
[648] Fix | Delete
[649] Fix | Delete
return $user;
[650] Fix | Delete
}
[651] Fix | Delete
endif;
[652] Fix | Delete
[653] Fix | Delete
if ( ! function_exists( 'wp_logout' ) ) :
[654] Fix | Delete
/**
[655] Fix | Delete
* Logs the current user out.
[656] Fix | Delete
*
[657] Fix | Delete
* @since 2.5.0
[658] Fix | Delete
*/
[659] Fix | Delete
function wp_logout() {
[660] Fix | Delete
$user_id = get_current_user_id();
[661] Fix | Delete
[662] Fix | Delete
wp_destroy_current_session();
[663] Fix | Delete
wp_clear_auth_cookie();
[664] Fix | Delete
wp_set_current_user( 0 );
[665] Fix | Delete
[666] Fix | Delete
/**
[667] Fix | Delete
* Fires after a user is logged out.
[668] Fix | Delete
*
[669] Fix | Delete
* @since 1.5.0
[670] Fix | Delete
* @since 5.5.0 Added the `$user_id` parameter.
[671] Fix | Delete
*
[672] Fix | Delete
* @param int $user_id ID of the user that was logged out.
[673] Fix | Delete
*/
[674] Fix | Delete
do_action( 'wp_logout', $user_id );
[675] Fix | Delete
}
[676] Fix | Delete
endif;
[677] Fix | Delete
[678] Fix | Delete
if ( ! function_exists( 'wp_validate_auth_cookie' ) ) :
[679] Fix | Delete
/**
[680] Fix | Delete
* Validates authentication cookie.
[681] Fix | Delete
*
[682] Fix | Delete
* The checks include making sure that the authentication cookie is set and
[683] Fix | Delete
* pulling in the contents (if $cookie is not used).
[684] Fix | Delete
*
[685] Fix | Delete
* Makes sure the cookie is not expired. Verifies the hash in cookie is what is
[686] Fix | Delete
* should be and compares the two.
[687] Fix | Delete
*
[688] Fix | Delete
* @since 2.5.0
[689] Fix | Delete
*
[690] Fix | Delete
* @global int $login_grace_period
[691] Fix | Delete
*
[692] Fix | Delete
* @param string $cookie Optional. If used, will validate contents instead of cookie's.
[693] Fix | Delete
* @param string $scheme Optional. The cookie scheme to use: 'auth', 'secure_auth', or 'logged_in'.
[694] Fix | Delete
* Note: This does *not* default to 'auth' like other cookie functions.
[695] Fix | Delete
* @return int|false User ID if valid cookie, false if invalid.
[696] Fix | Delete
*/
[697] Fix | Delete
function wp_validate_auth_cookie( $cookie = '', $scheme = '' ) {
[698] Fix | Delete
$cookie_elements = wp_parse_auth_cookie( $cookie, $scheme );
[699] Fix | Delete
if ( ! $cookie_elements ) {
[700] Fix | Delete
/**
[701] Fix | Delete
* Fires if an authentication cookie is malformed.
[702] Fix | Delete
*
[703] Fix | Delete
* @since 2.7.0
[704] Fix | Delete
*
[705] Fix | Delete
* @param string $cookie Malformed auth cookie.
[706] Fix | Delete
* @param string $scheme Authentication scheme. Values include 'auth', 'secure_auth',
[707] Fix | Delete
* or 'logged_in'.
[708] Fix | Delete
*/
[709] Fix | Delete
do_action( 'auth_cookie_malformed', $cookie, $scheme );
[710] Fix | Delete
return false;
[711] Fix | Delete
}
[712] Fix | Delete
[713] Fix | Delete
$scheme = $cookie_elements['scheme'];
[714] Fix | Delete
$username = $cookie_elements['username'];
[715] Fix | Delete
$hmac = $cookie_elements['hmac'];
[716] Fix | Delete
$token = $cookie_elements['token'];
[717] Fix | Delete
$expiration = $cookie_elements['expiration'];
[718] Fix | Delete
[719] Fix | Delete
$expired = (int) $expiration;
[720] Fix | Delete
[721] Fix | Delete
// Allow a grace period for POST and Ajax requests.
[722] Fix | Delete
if ( wp_doing_ajax() || 'POST' === $_SERVER['REQUEST_METHOD'] ) {
[723] Fix | Delete
$expired += HOUR_IN_SECONDS;
[724] Fix | Delete
}
[725] Fix | Delete
[726] Fix | Delete
// Quick check to see if an honest cookie has expired.
[727] Fix | Delete
if ( $expired < time() ) {
[728] Fix | Delete
/**
[729] Fix | Delete
* Fires once an authentication cookie has expired.
[730] Fix | Delete
*
[731] Fix | Delete
* @since 2.7.0
[732] Fix | Delete
*
[733] Fix | Delete
* @param string[] $cookie_elements {
[734] Fix | Delete
* Authentication cookie components. None of the components should be assumed
[735] Fix | Delete
* to be valid as they come directly from a client-provided cookie value.
[736] Fix | Delete
*
[737] Fix | Delete
* @type string $username User's username.
[738] Fix | Delete
* @type string $expiration The time the cookie expires as a UNIX timestamp.
[739] Fix | Delete
* @type string $token User's session token used.
[740] Fix | Delete
* @type string $hmac The security hash for the cookie.
[741] Fix | Delete
* @type string $scheme The cookie scheme to use.
[742] Fix | Delete
* }
[743] Fix | Delete
*/
[744] Fix | Delete
do_action( 'auth_cookie_expired', $cookie_elements );
[745] Fix | Delete
return false;
[746] Fix | Delete
}
[747] Fix | Delete
[748] Fix | Delete
$user = get_user_by( 'login', $username );
[749] Fix | Delete
if ( ! $user ) {
[750] Fix | Delete
/**
[751] Fix | Delete
* Fires if a bad username is entered in the user authentication process.
[752] Fix | Delete
*
[753] Fix | Delete
* @since 2.7.0
[754] Fix | Delete
*
[755] Fix | Delete
* @param string[] $cookie_elements {
[756] Fix | Delete
* Authentication cookie components. None of the components should be assumed
[757] Fix | Delete
* to be valid as they come directly from a client-provided cookie value.
[758] Fix | Delete
*
[759] Fix | Delete
* @type string $username User's username.
[760] Fix | Delete
* @type string $expiration The time the cookie expires as a UNIX timestamp.
[761] Fix | Delete
* @type string $token User's session token used.
[762] Fix | Delete
* @type string $hmac The security hash for the cookie.
[763] Fix | Delete
* @type string $scheme The cookie scheme to use.
[764] Fix | Delete
* }
[765] Fix | Delete
*/
[766] Fix | Delete
do_action( 'auth_cookie_bad_username', $cookie_elements );
[767] Fix | Delete
return false;
[768] Fix | Delete
}
[769] Fix | Delete
[770] Fix | Delete
if ( str_starts_with( $user->user_pass, '$P$' ) || str_starts_with( $user->user_pass, '$2y$' ) ) {
[771] Fix | Delete
// Retain previous behaviour of phpass or vanilla bcrypt hashed passwords.
[772] Fix | Delete
$pass_frag = substr( $user->user_pass, 8, 4 );
[773] Fix | Delete
} else {
[774] Fix | Delete
// Otherwise, use a substring from the end of the hash to avoid dealing with potentially long hash prefixes.
[775] Fix | Delete
$pass_frag = substr( $user->user_pass, -4 );
[776] Fix | Delete
}
[777] Fix | Delete
[778] Fix | Delete
$key = wp_hash( $username . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme );
[779] Fix | Delete
[780] Fix | Delete
$hash = hash_hmac( 'sha256', $username . '|' . $expiration . '|' . $token, $key );
[781] Fix | Delete
[782] Fix | Delete
if ( ! hash_equals( $hash, $hmac ) ) {
[783] Fix | Delete
/**
[784] Fix | Delete
* Fires if a bad authentication cookie hash is encountered.
[785] Fix | Delete
*
[786] Fix | Delete
* @since 2.7.0
[787] Fix | Delete
*
[788] Fix | Delete
* @param string[] $cookie_elements {
[789] Fix | Delete
* Authentication cookie components. None of the components should be assumed
[790] Fix | Delete
* to be valid as they come directly from a client-provided cookie value.
[791] Fix | Delete
*
[792] Fix | Delete
* @type string $username User's username.
[793] Fix | Delete
* @type string $expiration The time the cookie expires as a UNIX timestamp.
[794] Fix | Delete
* @type string $token User's session token used.
[795] Fix | Delete
* @type string $hmac The security hash for the cookie.
[796] Fix | Delete
* @type string $scheme The cookie scheme to use.
[797] Fix | Delete
* }
[798] Fix | Delete
*/
[799] Fix | Delete
do_action( 'auth_cookie_bad_hash', $cookie_elements );
[800] Fix | Delete
return false;
[801] Fix | Delete
}
[802] Fix | Delete
[803] Fix | Delete
$manager = WP_Session_Tokens::get_instance( $user->ID );
[804] Fix | Delete
if ( ! $manager->verify( $token ) ) {
[805] Fix | Delete
/**
[806] Fix | Delete
* Fires if a bad session token is encountered.
[807] Fix | Delete
*
[808] Fix | Delete
* @since 4.0.0
[809] Fix | Delete
*
[810] Fix | Delete
* @param string[] $cookie_elements {
[811] Fix | Delete
* Authentication cookie components. None of the components should be assumed
[812] Fix | Delete
* to be valid as they come directly from a client-provided cookie value.
[813] Fix | Delete
*
[814] Fix | Delete
* @type string $username User's username.
[815] Fix | Delete
* @type string $expiration The time the cookie expires as a UNIX timestamp.
[816] Fix | Delete
* @type string $token User's session token used.
[817] Fix | Delete
* @type string $hmac The security hash for the cookie.
[818] Fix | Delete
* @type string $scheme The cookie scheme to use.
[819] Fix | Delete
* }
[820] Fix | Delete
*/
[821] Fix | Delete
do_action( 'auth_cookie_bad_session_token', $cookie_elements );
[822] Fix | Delete
return false;
[823] Fix | Delete
}
[824] Fix | Delete
[825] Fix | Delete
// Ajax/POST grace period set above.
[826] Fix | Delete
if ( $expiration < time() ) {
[827] Fix | Delete
$GLOBALS['login_grace_period'] = 1;
[828] Fix | Delete
}
[829] Fix | Delete
[830] Fix | Delete
/**
[831] Fix | Delete
* Fires once an authentication cookie has been validated.
[832] Fix | Delete
*
[833] Fix | Delete
* @since 2.7.0
[834] Fix | Delete
*
[835] Fix | Delete
* @param string[] $cookie_elements {
[836] Fix | Delete
* Authentication cookie components.
[837] Fix | Delete
*
[838] Fix | Delete
* @type string $username User's username.
[839] Fix | Delete
* @type string $expiration The time the cookie expires as a UNIX timestamp.
[840] Fix | Delete
* @type string $token User's session token used.
[841] Fix | Delete
* @type string $hmac The security hash for the cookie.
[842] Fix | Delete
* @type string $scheme The cookie scheme to use.
[843] Fix | Delete
* }
[844] Fix | Delete
* @param WP_User $user User object.
[845] Fix | Delete
*/
[846] Fix | Delete
do_action( 'auth_cookie_valid', $cookie_elements, $user );
[847] Fix | Delete
[848] Fix | Delete
return $user->ID;
[849] Fix | Delete
}
[850] Fix | Delete
endif;
[851] Fix | Delete
[852] Fix | Delete
if ( ! function_exists( 'wp_generate_auth_cookie' ) ) :
[853] Fix | Delete
/**
[854] Fix | Delete
* Generates authentication cookie contents.
[855] Fix | Delete
*
[856] Fix | Delete
* @since 2.5.0
[857] Fix | Delete
* @since 4.0.0 The `$token` parameter was added.
[858] Fix | Delete
*
[859] Fix | Delete
* @param int $user_id User ID.
[860] Fix | Delete
* @param int $expiration The time the cookie expires as a UNIX timestamp.
[861] Fix | Delete
* @param string $scheme Optional. The cookie scheme to use: 'auth', 'secure_auth', or 'logged_in'.
[862] Fix | Delete
* Default 'auth'.
[863] Fix | Delete
* @param string $token User's session token to use for this cookie.
[864] Fix | Delete
* @return string Authentication cookie contents. Empty string if user does not exist.
[865] Fix | Delete
*/
[866] Fix | Delete
function wp_generate_auth_cookie( $user_id, $expiration, $scheme = 'auth', $token = '' ) {
[867] Fix | Delete
$user = get_userdata( $user_id );
[868] Fix | Delete
if ( ! $user ) {
[869] Fix | Delete
return '';
[870] Fix | Delete
}
[871] Fix | Delete
[872] Fix | Delete
if ( ! $token ) {
[873] Fix | Delete
$manager = WP_Session_Tokens::get_instance( $user_id );
[874] Fix | Delete
$token = $manager->create( $expiration );
[875] Fix | Delete
}
[876] Fix | Delete
[877] Fix | Delete
if ( str_starts_with( $user->user_pass, '$P$' ) || str_starts_with( $user->user_pass, '$2y$' ) ) {
[878] Fix | Delete
// Retain previous behaviour of phpass or vanilla bcrypt hashed passwords.
[879] Fix | Delete
$pass_frag = substr( $user->user_pass, 8, 4 );
[880] Fix | Delete
} else {
[881] Fix | Delete
// Otherwise, use a substring from the end of the hash to avoid dealing with potentially long hash prefixes.
[882] Fix | Delete
$pass_frag = substr( $user->user_pass, -4 );
[883] Fix | Delete
}
[884] Fix | Delete
[885] Fix | Delete
$key = wp_hash( $user->user_login . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme );
[886] Fix | Delete
[887] Fix | Delete
$hash = hash_hmac( 'sha256', $user->user_login . '|' . $expiration . '|' . $token, $key );
[888] Fix | Delete
[889] Fix | Delete
$cookie = $user->user_login . '|' . $expiration . '|' . $token . '|' . $hash;
[890] Fix | Delete
[891] Fix | Delete
/**
[892] Fix | Delete
* Filters the authentication cookie.
[893] Fix | Delete
*
[894] Fix | Delete
* @since 2.5.0
[895] Fix | Delete
* @since 4.0.0 The `$token` parameter was added.
[896] Fix | Delete
*
[897] Fix | Delete
* @param string $cookie Authentication cookie.
[898] Fix | Delete
* @param int $user_id User ID.
[899] Fix | Delete
* @param int $expiration The time the cookie expires as a UNIX timestamp.
[900] Fix | Delete
* @param string $scheme Cookie scheme used. Accepts 'auth', 'secure_auth', or 'logged_in'.
[901] Fix | Delete
* @param string $token User's session token used.
[902] Fix | Delete
*/
[903] Fix | Delete
return apply_filters( 'auth_cookie', $cookie, $user_id, $expiration, $scheme, $token );
[904] Fix | Delete
}
[905] Fix | Delete
endif;
[906] Fix | Delete
[907] Fix | Delete
if ( ! function_exists( 'wp_parse_auth_cookie' ) ) :
[908] Fix | Delete
/**
[909] Fix | Delete
* Parses a cookie into its components.
[910] Fix | Delete
*
[911] Fix | Delete
* @since 2.7.0
[912] Fix | Delete
* @since 4.0.0 The `$token` element was added to the return value.
[913] Fix | Delete
*
[914] Fix | Delete
* @param string $cookie Authentication cookie.
[915] Fix | Delete
* @param string $scheme Optional. The cookie scheme to use: 'auth', 'secure_auth', or 'logged_in'.
[916] Fix | Delete
* @return string[]|false {
[917] Fix | Delete
* Authentication cookie components. None of the components should be assumed
[918] Fix | Delete
* to be valid as they come directly from a client-provided cookie value. If
[919] Fix | Delete
* the cookie value is malformed, false is returned.
[920] Fix | Delete
*
[921] Fix | Delete
* @type string $username User's username.
[922] Fix | Delete
* @type string $expiration The time the cookie expires as a UNIX timestamp.
[923] Fix | Delete
* @type string $token User's session token used.
[924] Fix | Delete
* @type string $hmac The security hash for the cookie.
[925] Fix | Delete
* @type string $scheme The cookie scheme to use.
[926] Fix | Delete
* }
[927] Fix | Delete
*/
[928] Fix | Delete
function wp_parse_auth_cookie( $cookie = '', $scheme = '' ) {
[929] Fix | Delete
if ( empty( $cookie ) ) {
[930] Fix | Delete
switch ( $scheme ) {
[931] Fix | Delete
case 'auth':
[932] Fix | Delete
$cookie_name = AUTH_COOKIE;
[933] Fix | Delete
break;
[934] Fix | Delete
case 'secure_auth':
[935] Fix | Delete
$cookie_name = SECURE_AUTH_COOKIE;
[936] Fix | Delete
break;
[937] Fix | Delete
case 'logged_in':
[938] Fix | Delete
$cookie_name = LOGGED_IN_COOKIE;
[939] Fix | Delete
break;
[940] Fix | Delete
default:
[941] Fix | Delete
if ( is_ssl() ) {
[942] Fix | Delete
$cookie_name = SECURE_AUTH_COOKIE;
[943] Fix | Delete
$scheme = 'secure_auth';
[944] Fix | Delete
} else {
[945] Fix | Delete
$cookie_name = AUTH_COOKIE;
[946] Fix | Delete
$scheme = 'auth';
[947] Fix | Delete
}
[948] Fix | Delete
}
[949] Fix | Delete
[950] Fix | Delete
if ( empty( $_COOKIE[ $cookie_name ] ) ) {
[951] Fix | Delete
return false;
[952] Fix | Delete
}
[953] Fix | Delete
$cookie = $_COOKIE[ $cookie_name ];
[954] Fix | Delete
}
[955] Fix | Delete
[956] Fix | Delete
$cookie_elements = explode( '|', $cookie );
[957] Fix | Delete
if ( count( $cookie_elements ) !== 4 ) {
[958] Fix | Delete
return false;
[959] Fix | Delete
}
[960] Fix | Delete
[961] Fix | Delete
list( $username, $expiration, $token, $hmac ) = $cookie_elements;
[962] Fix | Delete
[963] Fix | Delete
return compact( 'username', 'expiration', 'token', 'hmac', 'scheme' );
[964] Fix | Delete
}
[965] Fix | Delete
endif;
[966] Fix | Delete
[967] Fix | Delete
if ( ! function_exists( 'wp_set_auth_cookie' ) ) :
[968] Fix | Delete
/**
[969] Fix | Delete
* Sets the authentication cookies based on user ID.
[970] Fix | Delete
*
[971] Fix | Delete
* The $remember parameter increases the time that the cookie will be kept. The
[972] Fix | Delete
* default the cookie is kept without remembering is two days. When $remember is
[973] Fix | Delete
* set, the cookies will be kept for 14 days or two weeks.
[974] Fix | Delete
*
[975] Fix | Delete
* @since 2.5.0
[976] Fix | Delete
* @since 4.3.0 Added the `$token` parameter.
[977] Fix | Delete
*
[978] Fix | Delete
* @param int $user_id User ID.
[979] Fix | Delete
* @param bool $remember Whether to remember the user.
[980] Fix | Delete
* @param bool|string $secure Whether the auth cookie should only be sent over HTTPS. Default is an empty
[981] Fix | Delete
* string which means the value of `is_ssl()` will be used.
[982] Fix | Delete
* @param string $token Optional. User's session token to use for this cookie.
[983] Fix | Delete
*/
[984] Fix | Delete
function wp_set_auth_cookie( $user_id, $remember = false, $secure = '', $token = '' ) {
[985] Fix | Delete
if ( $remember ) {
[986] Fix | Delete
/**
[987] Fix | Delete
* Filters the duration of the authentication cookie expiration period.
[988] Fix | Delete
*
[989] Fix | Delete
* @since 2.8.0
[990] Fix | Delete
*
[991] Fix | Delete
* @param int $length Duration of the expiration period in seconds.
[992] Fix | Delete
* @param int $user_id User ID.
[993] Fix | Delete
* @param bool $remember Whether to remember the user login. Default false.
[994] Fix | Delete
*/
[995] Fix | Delete
$expiration = time() + apply_filters( 'auth_cookie_expiration', 14 * DAY_IN_SECONDS, $user_id, $remember );
[996] Fix | Delete
[997] Fix | Delete
/*
[998] Fix | Delete
* Ensure the browser will continue to send the cookie after the expiration time is reached.
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function