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

fix image upload #1807

Merged
merged 4 commits into from
Aug 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion includes/rest-api/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,23 @@ function directorist_rest_upload_image_from_url( $image_url ) {
);
}

$allowed_mime_types = get_allowed_mime_types();

// Add extension to the name when downloaded from extension less url
if ( strrpos( $file_array['name'], '.' ) === false ) {
$mime_type = mime_content_type( $file_array['tmp_name'] );
$_mime_types = array_flip( $allowed_mime_types );
$extensions = $_mime_types[ $mime_type ] ?? '';
$extensions = explode( '|', $extensions, 2 );
$file_array['name'] .= '.' . $extensions[0];
}

// Do the validation and storage stuff.
$file = wp_handle_sideload(
$file_array,
array(
'test_form' => false,
'mimes' => directorist_rest_allowed_image_mime_types(),
'mimes' => $allowed_mime_types,
),
current_time( 'Y/m' )
);
Expand Down