Skip to content

Instantly share code, notes, and snippets.

@grantalltodavid
Created May 31, 2025 23:25
Show Gist options
  • Select an option

  • Save grantalltodavid/dd9e7376a2d5a124fffc798c527df9ce to your computer and use it in GitHub Desktop.

Select an option

Save grantalltodavid/dd9e7376a2d5a124fffc798c527df9ce to your computer and use it in GitHub Desktop.
WP Wham Checkout Files Upload -- restore normal file type validation
add_filter( 'wpwham_checkout_files_upload_validate_file_type', 'wpw20250531_restore_normal_file_type_validation', 10, 3 );
function wpw20250531_restore_normal_file_type_validation( $result, $file_uploader, $file ) {
$result = true;
$files_accepted = get_option( 'alg_checkout_files_upload_file_accept_' . $file_uploader, '.jpg,.jpeg,.png' );
if ( $files_accepted > '' ) {
$files_accepted = array_map( 'trim', explode( ',', strtolower( $files_accepted ) ) );
if ( is_array( $files_accepted ) && ! empty( $files_accepted ) ) {
$file_type = strtolower( '.' . pathinfo( $file['name'], PATHINFO_EXTENSION ) );
if ( ! in_array( $file_type, $files_accepted ) ) {
$result = array(
'code' => 'fail_file_type',
'message' => sprintf(
( get_option( 'alg_checkout_files_upload_notice_wrong_file_type_' . $file_uploader ) > '' ?
get_option( 'alg_checkout_files_upload_notice_wrong_file_type_' . $file_uploader )
: __( 'Wrong file type: "%s"', 'checkout-files-upload-woocommerce' ) ),
$file['name']
),
);
}
}
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment