meta-box icon indicating copy to clipboard operation
meta-box copied to clipboard

File upload to custom folder fails when using Themosis framework

Open martinkrcho opened this issue 5 years ago • 0 comments

Issue Overview

File upload to custom folder in uploads folder is not allowed when using Themosis framework.

Steps to Reproduce (for bugs)

  1. Create file upload field and set "upload_dir" parameter to upload files to uploads/acme-import
  2. Try to upload a file
  3. File upload fails

Expected Behavior

File upload should succeed.

Current Behavior

File upload fails.

Possible Solution

Add a filter to RWMB_File_Field::handle_upload_custom_dir to allow third parties to override the following check:

// Make sure upload dir is inside WordPress.
$upload_dir = wp_normalize_path( untrailingslashit( $field['upload_dir'] ) );
$root       = wp_normalize_path( untrailingslashit( ABSPATH ) );
if ( 0 !== strpos( $upload_dir, $root ) ) {
	return;
}

Default Themosis setup gives me something like this: $root - /var/www/my-themosis-site/htdocs/cms $upload_dir - /var/www/my-themosis-site/htdocs/content/uploads

I suggest to add the following filter to allow Themosis developers to implement exception for this.

// Make sure upload dir is inside WordPress.
$upload_dir = wp_normalize_path( untrailingslashit( $field['upload_dir'] ) );
$root       = wp_normalize_path( untrailingslashit( ABSPATH ) );
$inside_wp = (0 === strpos( $upload_dir, $root ));
if ( ! apply_filters( 'rwmb_file_inside_wp', $inside_wp, $upload_dir, $root) ) {
	return;
}

martinkrcho avatar Jun 13 '19 14:06 martinkrcho