WordPress.org

Make WordPress Core

Ticket #28059: 28059.diff

File 28059.diff, 1.8 KB (added by jesin, 7 years ago)

Add inline images using wp_mail()

  • wp-includes/pluggable.php

     
    220220 * @param string $message Message contents
    221221 * @param string|array $headers Optional. Additional headers.
    222222 * @param string|array $attachments Optional. Files to attach.
     223 * @param string|array $embeds Optional. Files to embed inline.
    223224 * @return bool Whether the email contents were sent successfully.
    224225 */
    225 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
     226function wp_mail( $to, $subject, $message, $headers = '', $attachments = array(), $embeds = array() ) {
    226227        // Compact the input, apply the filters, and extract them back out
    227228
    228229        /**
     
    231232         * @since 2.2.0
    232233         *
    233234         * @param array $args A compacted array of wp_mail() arguments, including the "to" email,
    234          *                    subject, message, headers, and attachments values.
     235         *                    subject, message, headers, attachments and embeds values.
    235236         */
    236         extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
     237        extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments', 'embeds' ) ) );
    237238
    238239        if ( !is_array($attachments) )
    239240                $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
    240241
     242        if ( !is_array($embeds) )
     243                $embeds = explode( "\n", str_replace( "\r\n", "\n", $embeds ) );
     244
    241245        global $phpmailer;
    242246
    243247        // (Re)create it, if it's gone missing
     
    490494                }
    491495        }
    492496
     497        if ( !empty( $embeds ) ) {
     498                foreach ( $embeds as $embed ) {
     499                        try {
     500                                $phpmailer->addEmbeddedImage($embed, basename($embed));
     501                        } catch ( phpmailerException $e ) {
     502                                continue;
     503                        }
     504                }
     505        }
     506
    493507        /**
    494508         * Fires after PHPMailer is initialized.
    495509         *