[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