Front-End Upload media with category

Maybe you can assign attachment to those categories after upload? Check this example. function add_category_automatically($post_ID) { $attach = get_post($post_ID); if ($attach->post_parent) { $cats = get_the_category()($attach->post_parent); foreach ($cats as $cat) { wp_set_object_terms($post_ID, $cat->slug, ‘category’, true); } } } add_action(‘add_attachment’, ‘add_category_automatically’); Source

How to trigger “wp_handle_upload_prefilter” filter when uploading an image programatically?

I eventually got this. Solution was to use wp_handle_upload() function. Kinda obvious, when I come to think about it… function handle_upload( string $path ): array { $filename = basename( $path ); $random_filename = rand( 0, 1000 ) . $filename; $tmp_path = str_replace( $filename, $random_filename, $path ); /** Create a temporary copy of the original file, … Read more

How to Protect Uploads, if User is not Logged In?

Only checking if the cookie exists, is not much of a strict protection. To get a stronger protection, you can pass or “proxy” all requests to the uploaded folder (exemplary uploads in the following example) through a php script: RewriteCond %{REQUEST_FILENAME} -s RewriteRule ^wp-content/uploads/(.*)$ dl-file.php?file=$1 [QSA,L] All requests to uploaded files (which includes images in … Read more

multiple image upload using wp_enqueue_media

I solved it here is my code: image.on(‘select’, function() { let selection = image.state().get(‘selection’); let _getImage = []; selection.map( function( getImage ) { _getImage.push(getImage.toJSON()) getImage = getImage.toJSON(); jQuery(“#show-image”).after(“<img src=”https://wordpress.stackexchange.com/questions/336524/+getImage.url+” style=”height:50px;width:50px;”/>”); }) jQuery(“#trade_pic”).after(“<input type=”hidden” name=”trade_pic” value=””+_getImage.map(val=> val.url)+””/>”) }); image.open();