Make WordPress Core


Ignore:
Timestamp:
01/05/2023 10:47:06 AM (4 years ago)
Author:
johnjamesjacoby
Message:

Mail: allow custom attachment filenames in wp_mail().

Previous to this change, attachment filenames in outgoing emails could only ever be derived from their paths (passed in as a numerically indexed array of $attachments).

This changeset adds support for passing an associative $attachments array, where the key strings will be used as filenames instead.

Includes 2 new unit tests to ensure both array formats continue to work as intended.

Props johnjamesjacoby, ritteshpatel, swissspidy, syntaxart.
Fixes #28407.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r54952 r55030  
    518518
    519519                if ( ! empty( $attachments ) ) {
    520                         foreach ( $attachments as $attachment ) {
     520                        foreach ( $attachments as $filename => $attachment ) {
     521                                $filename = is_string( $filename ) ? $filename : '';
     522
    521523                                try {
    522                                         $phpmailer->addAttachment( $attachment );
     524                                        $phpmailer->addAttachment( $attachment, $filename );
    523525                                } catch ( PHPMailer\PHPMailer\Exception $e ) {
    524526                                        continue;
Note: See TracChangeset for help on using the changeset viewer.