Suppose if you copy an image from another site to your site using the php copy function, then only one copied image is created in the uploads folder.
Tell me, how do I copy images from another site, so that all intermediate dimensions are created, which are selected in media settings?
those. 150x150, 300x300, 100x100, etc.

$attach_id = wp_insert_attachment( $attachment, $guid . $nameImg ); $attach_data = wp_generate_attachment_metadata( $attach_id, $guid . $nameImg ); wp_update_attachment_metadata( $attach_id, $attach_data ); 

This code only writes to the database.
Plugins do not fit, you need to make your plugin

  • wp_generate_attachment_metadata () generates metadata for the attachment image and creates intermediate copies of the image - thumbnails of all registered sizes. Source wp-kama.ru/function/wp_generate_attachment_metadata - so it's not about the code, but somewhere outside it. For example, no rights to create files in the upoloads folder. Or the file name is incorrectly transferred. Need debugging, viewing the values ​​of variables. - KAGG Design
  • > For example, no rights to create files in the upoloads folder. Or the file name is incorrectly transferred. - word
  • Well, if one image is copied without intermediate sizes, then it is logical that there are rights. Prompt, in the above code, the same file wp_generate_attachment_metadata are passed to the wp_insert_attachment and wp_generate_attachment_metadata functions. In theory, the file name is identical in calls to two functions. What could be the problem yet? - word
  • It does not follow from the code that copying is performed in this or a neighboring function. Copying can be a separate php application in general, I don’t know about it. What about $ attach_id and $ attach_data? - KAGG Design
  • > It does not follow from the code that copying is done in this or an adjacent function - word

0