Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload to custom folder fails when using Themosis framework #1315

Open
martinkrcho opened this issue Jun 13, 2019 · 0 comments
Open

File upload to custom folder fails when using Themosis framework #1315

martinkrcho opened this issue Jun 13, 2019 · 0 comments

Comments

@martinkrcho
Copy link

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant