Per User Upload Prefilter

add_filter(‘wp_handle_upload_prefilter’, ‘per_user_upload_prefilter’); function per_user_upload_prefilter($errors) { if( ( isset( $_REQUEST[‘action’] ) && ( “um_resize_image” == $_REQUEST[‘action’] || “um_imageupload” == $_REQUEST[‘action’] ) ) || isset( $_REQUEST[‘um_action’] ) ){ return $errors; } // in this filter we add a WP filter that alters…Continue reading

ACF Image Upload Size Restrictions

//add_filter(‘wp_handle_upload_prefilter’,’tps_validate_image_size’); add_filter(‘acf/validate_attachment/name=gallery_post_featured_image’, ‘tps_validate_gallery_image_size’, 10, 5); function tps_validate_gallery_image_size( $errors, $file, $attachment, $field, $context ){ $image_type = $file[‘type’]; $image_filesize = $file[‘size’]; $image_width = $file[‘width’]; $image_height = $file[‘height’]; if ( ( $image_type != ‘jpg’ ) && ( $image_type != ‘jpeg’ ) && (…Continue reading

Upload Directories Per User (reference)

function per_user_upload_dir( $original ){ $modified = $original; if( ( isset( $_REQUEST[‘action’] ) && ( “um_resize_image” == $_REQUEST[‘action’] || “um_imageupload” == $_REQUEST[‘action’] ) ) || isset( $_REQUEST[‘um_action’] ) ){ return $original; } elseif ( is_user_logged_in() && !current_user_can( ‘manage_options’ ) ) {…Continue reading

Per User ACF Upload Directory (reference)

add_filter(‘acf/upload_prefilter/name=gallery_post_featured_image’, ‘per_user_upload_prefilter’); function per_user_upload_prefilter($errors) { // in this filter we add a WP filter that alters the upload path add_filter(‘upload_dir’, ‘per_user_upload_dir’); return $errors; } // second filter function per_user_upload_dir($uploads) { // here is where we alter the path $current_user =…Continue reading

Allow ICO Files Upload

function custom_allow_ico_upload($mimes) { $allowed_mime_types = array( ‘ico’ => ‘image/x-icon’ ); // Merge the allowed MIME types with the existing list $mimes = array_merge($mimes, $allowed_mime_types); return $mimes; } add_filter(‘upload_mimes’, ‘custom_allow_ico_upload’); function custom_handle_ico_upload_errors($file, $uploaded_file) { if (!empty($file[‘type’]) && $file[‘type’] === ‘image/x-icon’ &&…Continue reading

Allow WebP Files Upload

// Add WebP MIME type support function add_webp_mime_type($mime_types) { $mime_types[‘webp’] = ‘image/webp’; return $mime_types; } add_filter(‘upload_mimes’, ‘add_webp_mime_type’); // Enable WebP in the Media Library function enable_webp_upload($data, $file) { $file[‘ext’] = ‘webp’; return $data; } add_filter(‘wp_handle_upload_prefilter’, ‘enable_webp_upload’, 10, 2); // Enable…Continue reading