hash( $code, $token ) ); } /** * Email the code. * * @param WP_User $user The user. * @param string $code The code. * @return bool Whether wp_mail() reported success. */ public function send( WP_User $user, $code ) { $site = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); /* translators: %s: site name. */ $subject = sprintf( __( '[%s] Your login code', 'adminkeep' ), $site ); $minutes = (int) ( PendingLogin::TTL / 60 ); $text = sprintf( /* translators: 1: user display name, 2: the code, 3: minutes the code is valid, 4: site name. */ __( "Hi %1\$s,\n\nYour login code is:\n\n%2\$s\n\nIt is good for %3\$d minutes and works once. If you did not just enter your password on %4\$s, you can ignore this email; nobody is signed in without the code.", 'adminkeep' ), $user->display_name, $code, $minutes, $site ); // Always the Nice Default Emails layout, whether or not that feature is on: it is built // here from the same template, and declaring HTML keeps Nice Emails from wrapping it // again. A body the template cannot escape (HtmlEmail::body() returns '') falls back to // the plain text rather than sending nothing. $body = HtmlEmail::body( $text ); $message = '' === $body ? $text : HtmlEmail::document( $body ); $headers = '' === $body ? array() : array( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) ); // The Email Log drops the body of a message carrying this header (MailRow), so a login // code is never readable from the log table. $headers[] = 'X-Adminkeep-Secret: 1'; return (bool) wp_mail( $user->user_email, $subject, $message, $headers ); } }