Bulk Optimize via WP-CLI?
-
I’ve been trying to write a script so I can invoke the bulk optimize feature on a large multisite.
I’ve written this, and it looks like this is the right routine, but when I’m testing it on individual files, I’m not seeing any reduction in file size.
Am I on the right track, or is there a better way to do this?
$sites = get_sites(); foreach($sites as $site){ switch_to_blog($site->blog_id); $args = ['post_type' => 'attachment', 'numberposts' => -1]; $attachments = get_posts($args); foreach($attachments as $attachment){ $id = $attachment->ID; $metadata = wp_get_attachment_metadata($id); $optimus_metadata = Optimus_Request::optimize_upload_images($metadata, $id); if ( !empty($optimus_metadata['optimus']['error']) ) { var_dump(array('error' => $optimus_metadata['optimus']['error'])); exit; } /* check if optimus array empty */ if ( empty($optimus_metadata['optimus']) ) { var_dump(array('error' => __("Internal error", "optimus"))); exit; } /* update metadata */ update_post_meta($id, '_wp_attachment_metadata', $optimus_metadata); } restore_current_blog(); }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Bulk Optimize via WP-CLI?’ is closed to new replies.