defer_image_subsizes(); } } /** * Defer image subsizes. * * @return void */ public function defer_image_subsizes() { add_filter( 'intermediate_image_sizes_advanced', array( $this, 'buffer_images_for_processing' ), 10, 3 ); } /** * Force attachment size geenration in the background. * * @param array $new_sizes Array of image sizes. * @param array $image_meta Metadata of the image. * @param integer $attachment_id Attachment id. * * @return array */ public function buffer_images_for_processing( $new_sizes, $image_meta, $attachment_id ) { $all_attachments = get_option( 'st_attachments', array() ); // If the cron job is already scheduled, bail. if ( in_array( $attachment_id, $all_attachments, true ) ) { return $new_sizes; } $all_attachments[] = $attachment_id; update_option( 'st_attachments', $all_attachments, 'no' ); // Return blank array of sizes to not generate any sizes in this request. return array(); } } /** * Kicking this off by calling 'get_instance()' method */ Astra_Sites_Image_Processing::get_instance();