Skip to content

Commit

Permalink
Set WP_TEMP_DIR for Contact Form 7 uploads (#4901)
Browse files Browse the repository at this point in the history
The plugin ignores the value of `WPCF7_UPLOADS_TMP_DIR` if it is not
within a set of paths allowed by the plugin. The plugin allows the path
defined in `WP_TEMP_DIR`, so this fix uses the plugin's `wpcf7_upload_dir`
filter to set `WP_TEMP_DIR` to `/tmp/` so that the plugin will allow the
path that we defined earlier in `WPCF7_UPLOADS_TMP_DIR`.
  • Loading branch information
raamdev authored Oct 12, 2023
1 parent c0b3a23 commit 00f0254
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions plugin-fixes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@
define( 'WPCF7_UPLOADS_TMP_DIR', get_temp_dir() . 'cf7/' );
}

/**
* Contact Form 7 (https://wordpress.org/plugins/contact-form-7/)
*
* The plugin ignores the value of `WPCF7_UPLOADS_TMP_DIR` if it is not
* within a set of paths allowed by the plugin. The plugin allows the path
* defined in `WP_TEMP_DIR`, so this fix uses the plugin's `wpcf7_upload_dir`
* filter to set `WP_TEMP_DIR` to `/tmp/` so that the plugin will allow the
* path that we defined earlier in `WPCF7_UPLOADS_TMP_DIR`.
*
* @param array $uploads See wp_upload_dir() for description.
* @return array Information about the upload directory.
*/
function vip_wpcf7_upload_dir( $uploads ) {
if ( ! defined( 'WP_TEMP_DIR' ) ) {
define( 'WP_TEMP_DIR', get_temp_dir() );
}

return $uploads;
}
add_filter( 'wpcf7_upload_dir', 'vip_wpcf7_upload_dir', 10, 1 );

/**
* Recent versions of CF7 attempt to clean-up uploaded attachments
* somewhere within `wp-content`, ignoring the value of WPCF7_UPLOADS_TMP_DIR if
Expand Down

0 comments on commit 00f0254

Please sign in to comment.