[Solved] how make duplicate of an specific file in wordpress media library programatically [closed]

finally solved my problem by this code: require_once( ABSPATH . ‘wp-admin/includes/image.php’ ); $wp_upload_dir = wp_upload_dir(); $imgMeta = wp_get_attachment_metadata( $wordpress_media_attachment_id ); $imgMime = $imgMeta[‘sizes’][‘thumbnail’][‘mime-type’]; $absolutePath = “$wp_upload_dir[basedir]/$imgMeta[file]”; $name = basename($imgMeta[‘file’]); do{ $rnd = mt_rand(); $name2 = “_$rnd$name”; $path2 = “$wp_upload_dir[path]/$name2”; } while (file_exists($path2)); @copy($absolutePath,$path2); $attachment = array( ‘guid’=> “$wp_upload_dir[url]/$name2”, ‘post_mime_type’ => $imgMime, ‘post_title’ => $name2, ‘post_content’ … Read more

[Solved] 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