wip
This commit is contained in:
+126
-21
@@ -158,9 +158,23 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
* The default charset is based on the charset used on the blog. The charset can
|
||||
* be set using the {@see 'wp_mail_charset'} filter.
|
||||
*
|
||||
* When using the `$embeds` parameter to embed images for use in HTML emails,
|
||||
* reference the embedded file in your HTML with a `cid:` URL whose value
|
||||
* matches the file's Content-ID. By default, the Content-ID (`cid`) used for
|
||||
* each embedded file is the key in the embeds array, unless modified via the
|
||||
* {@see 'wp_mail_embed_args'} filter. For example:
|
||||
*
|
||||
* `<img src="cid:0" alt="Logo">`
|
||||
* `<img src="cid:my-image" alt="Image">`
|
||||
*
|
||||
* You may also customize the Content-ID for each file by using the
|
||||
* {@see 'wp_mail_embed_args'} filter and setting the `cid` value.
|
||||
*
|
||||
* @since 1.2.1
|
||||
* @since 5.5.0 is_email() is used for email validation,
|
||||
* instead of PHPMailer's default validator.
|
||||
* @since 6.9.0 Added $embeds parameter.
|
||||
* @since 6.9.0 Improved Content-Type header handling for multipart messages.
|
||||
*
|
||||
* @global PHPMailer\PHPMailer\PHPMailer $phpmailer
|
||||
*
|
||||
@@ -169,9 +183,10 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
* @param string $message Message contents.
|
||||
* @param string|string[] $headers Optional. Additional headers.
|
||||
* @param string|string[] $attachments Optional. Paths to files to attach.
|
||||
* @param string|string[] $embeds Optional. Paths to files to embed.
|
||||
* @return bool Whether the email was sent successfully.
|
||||
*/
|
||||
function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
|
||||
function wp_mail( $to, $subject, $message, $headers = '', $attachments = array(), $embeds = array() ) {
|
||||
// Compact the input, apply the filters, and extract them back out.
|
||||
|
||||
/**
|
||||
@@ -187,9 +202,10 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
* @type string $message Message contents.
|
||||
* @type string|string[] $headers Additional headers.
|
||||
* @type string|string[] $attachments Paths to files to attach.
|
||||
* @type string|string[] $embeds Paths to files to embed.
|
||||
* }
|
||||
*/
|
||||
$atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) );
|
||||
$atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments', 'embeds' ) );
|
||||
|
||||
/**
|
||||
* Filters whether to preempt sending an email.
|
||||
@@ -209,6 +225,7 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
* @type string $message Message contents.
|
||||
* @type string|string[] $headers Additional headers.
|
||||
* @type string|string[] $attachments Paths to files to attach.
|
||||
* @type string|string[] $embeds Paths to files to embed.
|
||||
* }
|
||||
*/
|
||||
$pre_wp_mail = apply_filters( 'pre_wp_mail', null, $atts );
|
||||
@@ -244,6 +261,15 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
if ( ! is_array( $attachments ) ) {
|
||||
$attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
|
||||
}
|
||||
|
||||
if ( isset( $atts['embeds'] ) ) {
|
||||
$embeds = $atts['embeds'];
|
||||
}
|
||||
|
||||
if ( ! is_array( $embeds ) ) {
|
||||
$embeds = explode( "\n", str_replace( "\r\n", "\n", $embeds ) );
|
||||
}
|
||||
|
||||
global $phpmailer;
|
||||
|
||||
// (Re)create it, if it's gone missing.
|
||||
@@ -326,6 +352,9 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
} elseif ( false !== stripos( $charset_content, 'boundary=' ) ) {
|
||||
$boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) );
|
||||
$charset = '';
|
||||
if ( preg_match( '~^multipart/(\S+)~', $content_type, $matches ) ) {
|
||||
$content_type = 'multipart/' . strtolower( $matches[1] ) . '; boundary="' . $boundary . '"';
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid setting an empty $content_type.
|
||||
@@ -359,6 +388,15 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
$phpmailer->Body = '';
|
||||
$phpmailer->AltBody = '';
|
||||
|
||||
/*
|
||||
* Reset encoding to 8-bit, as it may have been automatically downgraded
|
||||
* to 7-bit by PHPMailer (based on the body contents) in a previous call
|
||||
* to wp_mail().
|
||||
*
|
||||
* See https://core.trac.wordpress.org/ticket/33972
|
||||
*/
|
||||
$phpmailer->Encoding = PHPMailer\PHPMailer\PHPMailer::ENCODING_8BIT;
|
||||
|
||||
// Set "From" name and email.
|
||||
|
||||
// If we don't have a name from the input headers.
|
||||
@@ -406,7 +444,7 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
$from_name = apply_filters( 'wp_mail_from_name', $from_name );
|
||||
|
||||
try {
|
||||
$phpmailer->setFrom( $from_email, $from_name, false );
|
||||
$phpmailer->setFrom( $from_email, $from_name );
|
||||
} catch ( PHPMailer\PHPMailer\Exception $e ) {
|
||||
$mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
|
||||
$mail_error_data['phpmailer_exception_code'] = $e->getCode();
|
||||
@@ -446,10 +484,10 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
$phpmailer->addAddress( $address, $recipient_name );
|
||||
break;
|
||||
case 'cc':
|
||||
$phpmailer->addCc( $address, $recipient_name );
|
||||
$phpmailer->addCC( $address, $recipient_name );
|
||||
break;
|
||||
case 'bcc':
|
||||
$phpmailer->addBcc( $address, $recipient_name );
|
||||
$phpmailer->addBCC( $address, $recipient_name );
|
||||
break;
|
||||
case 'reply_to':
|
||||
$phpmailer->addReplyTo( $address, $recipient_name );
|
||||
@@ -513,10 +551,6 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) {
|
||||
$phpmailer->addCustomHeader( sprintf( 'Content-Type: %s; boundary="%s"', $content_type, $boundary ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $attachments ) ) {
|
||||
@@ -531,6 +565,50 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $embeds ) ) {
|
||||
foreach ( $embeds as $key => $embed_path ) {
|
||||
/**
|
||||
* Filters the arguments for PHPMailer's addEmbeddedImage() method.
|
||||
*
|
||||
* @since 6.9.0
|
||||
*
|
||||
* @param array $args {
|
||||
* An array of arguments for `addEmbeddedImage()`.
|
||||
* @type string $path The path to the file.
|
||||
* @type string $cid The Content-ID of the image. Default: The key in the embeds array.
|
||||
* @type string $name The filename of the image.
|
||||
* @type string $encoding The encoding of the image. Default: 'base64'.
|
||||
* @type string $type The MIME type of the image. Default: empty string, which lets PHPMailer auto-detect.
|
||||
* @type string $disposition The disposition of the image. Default: 'inline'.
|
||||
* }
|
||||
*/
|
||||
$embed_args = apply_filters(
|
||||
'wp_mail_embed_args',
|
||||
array(
|
||||
'path' => $embed_path,
|
||||
'cid' => (string) $key,
|
||||
'name' => basename( $embed_path ),
|
||||
'encoding' => 'base64',
|
||||
'type' => '',
|
||||
'disposition' => 'inline',
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
$phpmailer->addEmbeddedImage(
|
||||
$embed_args['path'],
|
||||
$embed_args['cid'],
|
||||
$embed_args['name'],
|
||||
$embed_args['encoding'],
|
||||
$embed_args['type'],
|
||||
$embed_args['disposition']
|
||||
);
|
||||
} catch ( PHPMailer\PHPMailer\Exception $e ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires after PHPMailer is initialized.
|
||||
*
|
||||
@@ -563,6 +641,7 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
* @type string $message Message contents.
|
||||
* @type string[] $headers Additional headers.
|
||||
* @type string[] $attachments Paths to files to attach.
|
||||
* @type string[] $embeds Paths to files to embed.
|
||||
* }
|
||||
*/
|
||||
do_action( 'wp_mail_succeeded', $mail_data );
|
||||
@@ -968,11 +1047,13 @@ endif;
|
||||
|
||||
if ( ! function_exists( 'wp_set_auth_cookie' ) ) :
|
||||
/**
|
||||
* Sets the authentication cookies based on user ID.
|
||||
* Sets the authentication cookies for a given user ID.
|
||||
*
|
||||
* The $remember parameter increases the time that the cookie will be kept. The
|
||||
* default the cookie is kept without remembering is two days. When $remember is
|
||||
* set, the cookies will be kept for 14 days or two weeks.
|
||||
* The `$remember` parameter controls cookie persistence:
|
||||
* - If true, the cookie is persistent (default 14 days, filterable via {@see 'auth_cookie_expiration'}).
|
||||
* - If false, the cookie is a browser session cookie (expires when the browser closes).
|
||||
* Internally, {@see 'auth_cookie_expiration'} is still applied, to expire the login after
|
||||
* two days or when the browser is closed, whichever occurs first.
|
||||
*
|
||||
* @since 2.5.0
|
||||
* @since 4.3.0 Added the `$token` parameter.
|
||||
@@ -1815,6 +1896,20 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) :
|
||||
$subject = sprintf( __( '[%1$s] Pingback: "%2$s"' ), $blogname, $post->post_title );
|
||||
break;
|
||||
|
||||
case 'note':
|
||||
/* translators: %s: Post title. */
|
||||
$notify_message = sprintf( __( 'New note on your post "%s"' ), $post->post_title ) . "\r\n";
|
||||
/* translators: 1: Note author's name, 2: Note author's IP address, 3: Note author's hostname. */
|
||||
$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
|
||||
/* translators: %s: Note author email. */
|
||||
$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
|
||||
/* translators: %s: Note text. */
|
||||
$notify_message .= sprintf( __( 'Note: %s' ), "\r\n" . ( empty( $comment_content ) ? __( 'resolved/reopened' ) : $comment_content ) ) . "\r\n\r\n";
|
||||
$notify_message .= __( 'You can see all notes on this post here:' ) . "\r\n";
|
||||
/* translators: Note notification email subject. 1: Site title, 2: Post title. */
|
||||
$subject = sprintf( __( '[%1$s] Note: "%2$s"' ), $blogname, $post->post_title );
|
||||
break;
|
||||
|
||||
default: // Comments.
|
||||
/* translators: %s: Post title. */
|
||||
$notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
|
||||
@@ -1838,11 +1933,15 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) :
|
||||
break;
|
||||
}
|
||||
|
||||
$notify_message .= get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n";
|
||||
/* translators: %s: Comment URL. */
|
||||
$notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n";
|
||||
if ( 'note' === $comment->comment_type ) {
|
||||
$notify_message .= get_edit_post_link( $comment->comment_post_ID, 'url' ) . "\r\n";
|
||||
} else {
|
||||
$notify_message .= get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n";
|
||||
$notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n";
|
||||
}
|
||||
|
||||
if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) {
|
||||
if ( 'note' !== $comment->comment_type && user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) {
|
||||
if ( EMPTY_TRASH_DAYS ) {
|
||||
/* translators: Comment moderation. %s: Comment action URL. */
|
||||
$notify_message .= sprintf( __( 'Trash it: %s' ), admin_url( "comment.php?action=trash&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n";
|
||||
@@ -2676,9 +2775,11 @@ if ( ! function_exists( 'wp_hash_password' ) ) :
|
||||
* - `PASSWORD_ARGON2ID`
|
||||
* - `PASSWORD_DEFAULT`
|
||||
*
|
||||
* The values of the algorithm constants are strings in PHP 7.4+ and integers in PHP 7.3 and earlier.
|
||||
*
|
||||
* @since 6.8.0
|
||||
*
|
||||
* @param string $algorithm The hashing algorithm. Default is the value of the `PASSWORD_BCRYPT` constant.
|
||||
* @param string|int $algorithm The hashing algorithm. Default is the value of the `PASSWORD_BCRYPT` constant.
|
||||
*/
|
||||
$algorithm = apply_filters( 'wp_hash_password_algorithm', PASSWORD_BCRYPT );
|
||||
|
||||
@@ -2688,12 +2789,14 @@ if ( ! function_exists( 'wp_hash_password' ) ) :
|
||||
* The default hashing algorithm is bcrypt, but this can be changed via the {@see 'wp_hash_password_algorithm'}
|
||||
* filter. You must ensure that the options are appropriate for the algorithm in use.
|
||||
*
|
||||
* The values of the algorithm constants are strings in PHP 7.4+ and integers in PHP 7.3 and earlier.
|
||||
*
|
||||
* @since 6.8.0
|
||||
*
|
||||
* @param array $options Array of options to pass to the password hashing functions.
|
||||
* By default this is an empty array which means the default
|
||||
* options will be used.
|
||||
* @param string $algorithm The hashing algorithm in use.
|
||||
* @param array $options Array of options to pass to the password hashing functions.
|
||||
* By default this is an empty array which means the default
|
||||
* options will be used.
|
||||
* @param string|int $algorithm The hashing algorithm in use.
|
||||
*/
|
||||
$options = apply_filters( 'wp_hash_password_options', array(), $algorithm );
|
||||
|
||||
@@ -3048,6 +3151,8 @@ if ( ! function_exists( 'get_avatar' ) ) :
|
||||
* - 'monsterid' (a monster)
|
||||
* - 'wavatar' (a cartoon face)
|
||||
* - 'identicon' (the "quilt", a geometric pattern)
|
||||
* - 'initials' (initials based avatar with background color)
|
||||
* - 'color' (generated background color)
|
||||
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man)
|
||||
* - 'blank' (transparent GIF)
|
||||
* - 'gravatar_default' (the Gravatar logo)
|
||||
|
||||
Reference in New Issue
Block a user