I’ve modified method wp_update_attachment_metadata
from wp-includes/post.php
(line 5070) to this, just during the Import:
/**
* Update metadata for an attachment.
*
* @since 2.1.0
*
* @param int $attachment_id Attachment post ID.
* @param array $data Attachment meta data.
* @return int|bool False if $post is invalid.
*/
function wp_update_attachment_metadata( $attachment_id, $data ) {
$attachment_id = (int) $attachment_id;
if ( ! $post = get_post( $attachment_id ) ) {
return false;
}
/**
* Filters the updated attachment meta data.
*
* @since 2.1.0
*
* @param array $data Array of updated attachment meta data.
* @param int $attachment_id Attachment post ID.
*/
return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
}
Media Upload Before:
'uploadtimedebug_start' => 0 seconds
'uploadtimedebug_after_requires' => 0.006 seconds
'uploadtimedebug_after_tmp_filled' => 0.597 seconds
'uploadtimedebug_before_media_handle_sideload' => 0.597 seconds
'uploadtimedebug_after_media_handle_sideload' => 5.370 seconds
'uploadtimedebug_finish' => 5.370 seconds
Media Upload After:
'uploadtimedebug_inicio' => 0 seconds
'uploadtimedebug_after_requires' => 0.007 seconds
'uploadtimedebug_after_tmp_filled' => 0.620 seconds
'uploadtimedebug_before_media_handle_sideload' => 0.620 seconds
'uploadtimedebug_after_media_handle_sideload' => 0.723 seconds
'uploadtimedebug_finish' => 0.723 seconds
No side effects, everything works just fine. Keep in mind though, that this should be a temporary hack, when you’re done uploading your thousand images, revert wp_update_attachment_metadata
to it’s original code.
Edit – Please ignore everything I said.
The culript was the plugin “Smush It”, hooked into the wp_update_attachment_metadata
filter. Upon disabling Smush It, the filter took zero seconds.