Closed axi closed 2 weeks ago
Here is how I "fixed" it. I set the WP_TEMP_DIR to something.
define('WP_TEMP_DIR', '/path/to/physical/temp_dir');
and
add_action(
'wpcf7_before_send_mail',
static function ($contact_form, $abort, $submission): void {
$pdfPath = "uploads/2024/11/my.pdf";
$path = path_join(WP_CONTENT_DIR, $pdfPath);
if (file_exists($path)) {
// Create temp file path
$tmpFilePath = path_join(WP_TEMP_DIR, basename($pdfPath));
// Copy file to a place cf7 will accept
if (!file_exists($tmpFilePath)) {
// Make sure the temp dir exists
wp_mkdir_p(WP_TEMP_DIR);
copy($path, $tmpFilePath);
}
$submission->add_extra_attachments($tmpFilePath, 'mail');
}
},
10,
3
);
Describe the bug This seems to have previously been addressed in #707, #475 but it still doesn't work.
Here is my config:
I'm using the
wpcf7_before_send_mail
to add an attachment (my usecase is a bit more complexe but simplified example is valid):That means that realpaths found withing the static callback function in function
wpcf7_is_file_path_in_content_dir()
method are:and that
wpcf7_is_file_path_in_content_dir()
return false.I don't know what would be the best way to fix it. Would a new filter be appropriate ? I mean something like: