' . __METHOD__ . '()' ); if ( ! class_exists( '\Imagely\NGG\DataMappers\Image' ) && ! class_exists( 'C_Image_Mapper' ) ) { ewwwio_debug_message( 'incompatible NGG, no C_Image_Mapper or \Imagely\* class' ); return; } add_filter( 'ngg_manage_images_number_of_columns', array( $this, 'ewww_manage_images_number_of_columns' ) ); add_filter( 'ngg_manage_images_columns', array( $this, 'manage_images_columns' ) ); add_filter( 'ngg_manage_images_row_actions', array( $this, 'ewww_manage_images_row_actions' ) ); if ( ewww_image_optimizer_test_background_opt() ) { add_action( 'ngg_added_new_image', array( $this, 'queue_new_image' ) ); ewwwio_debug_message( 'background mode enabled for nextgen' ); } else { add_action( 'ngg_added_new_image', array( $this, 'ewww_added_new_image' ) ); ewwwio_debug_message( 'background mode NOT enabled for nextgen' ); } add_action( 'wp_ajax_ewww_ngg_manual', array( $this, 'ewww_ngg_manual' ) ); add_action( 'wp_ajax_ewww_ngg_image_restore', array( $this, 'ewww_ngg_image_restore' ) ); add_action( 'admin_action_ewww_ngg_manual', array( $this, 'ewww_ngg_manual' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'ewww_ngg_manual_actions_script' ) ); add_action( 'admin_menu', array( $this, 'ewww_ngg_bulk_menu' ) ); add_action( 'admin_menu', array( $this, 'ewww_ngg_update_menu' ), PHP_INT_MAX - 1 ); add_action( 'admin_head', array( $this, 'ewww_ngg_bulk_actions_script' ) ); add_action( 'admin_init', array( $this, 'ewww_ngg_bulk_action_handler' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'ewww_ngg_bulk_script' ), 20 ); add_action( 'wp_ajax_bulk_ngg_preview', array( $this, 'ewww_ngg_bulk_preview' ) ); add_action( 'wp_ajax_bulk_ngg_init', array( $this, 'ewww_ngg_bulk_init' ) ); add_action( 'wp_ajax_bulk_ngg_filename', array( $this, 'ewww_ngg_bulk_filename' ) ); add_action( 'wp_ajax_bulk_ngg_loop', array( $this, 'ewww_ngg_bulk_loop' ) ); add_action( 'wp_ajax_bulk_ngg_cleanup', array( $this, 'ewww_ngg_bulk_cleanup' ) ); add_action( 'ngg_generated_image', array( $this, 'ewww_ngg_generated_image' ), 10, 2 ); add_filter( 'ngg_get_image_size_params', array( $this, 'ewww_ngg_quality_param' ), 10, 2 ); } /** * Get an Ngg Image object. * * @param int $id The image ID number. * @return object|bool The Image object on success, false otherwise. */ public function get_ngg_image( $id ) { ewwwio_debug_message( '' . __METHOD__ . '()' ); if ( class_exists( '\Imagely\NGG\DataMappers\Image' ) ) { return \Imagely\NGG\DataMappers\Image::get_instance()->find( $id ); } elseif ( class_exists( 'C_Image_Mapper' ) ) { return C_Image_Mapper::get_instance()->find( $id ); } return false; } /** * Get the image sizes for a given Ngg Image. * * @param object $image An Ngg Image object. * @return array An array of image sub-sizes. */ public function get_image_sizes( $image = false ) { ewwwio_debug_message( '' . __METHOD__ . '()' ); if ( class_exists( '\Imagely\NGG\DataStorage\Manager' ) ) { return \Imagely\NGG\DataStorage\Manager::get_instance()->get_image_sizes( $image ); } elseif ( class_exists( 'C_Gallery_Storage' ) ) { return C_Gallery_Storage::get_instance()->get_image_sizes( $image ); } return array(); } /** * Get the absolute path for a given image sub-size for a particular Ngg Image. * * @param object $image An Ngg Image object. * @param string $size The name of a particiular sub-size. * @return string The absolute path for an image file. */ public function get_image_abspath( $image, $size ) { ewwwio_debug_message( '' . __METHOD__ . '()' ); if ( class_exists( '\Imagely\NGG\DataStorage\Manager' ) ) { return \Imagely\NGG\DataStorage\Manager::get_instance()->get_image_abspath( $image, $size ); } elseif ( class_exists( 'C_Gallery_Storage' ) ) { return C_Gallery_Storage::get_instance()->get_image_abspath( $image, $size ); } return ''; } /** * Adds the Bulk Optimize page to the NextGEN menu. */ public function ewww_ngg_bulk_menu() { if ( ! defined( 'NGGFOLDER' ) ) { return; } add_submenu_page( NGGFOLDER, esc_html__( 'Bulk Optimize', 'ewww-image-optimizer' ), esc_html__( 'Bulk Optimize', 'ewww-image-optimizer' ), apply_filters( 'ewww_image_optimizer_bulk_permissions', '' ), 'ewww-ngg-bulk', array( &$this, 'ewww_ngg_bulk_preview' ) ); remove_submenu_page( 'nextgen-gallery', 'ngg_imagify' ); } /** * Removes unnecessary menu items from the NextGEN menu. */ public function ewww_ngg_update_menu() { if ( ! defined( 'NGGFOLDER' ) ) { return; } remove_submenu_page( NGGFOLDER, 'ngg_imagify' ); } /** * Keep the NextGEN quality level sane and inline with user settings. * * @param array $params The image sizing parameters. * @param string $size The name of the size being processed. * @return array The image sizing parameters, sanitized. */ public function ewww_ngg_quality_param( $params, $size ) { ewwwio_debug_message( '' . __METHOD__ . '()' ); $ngg_quality = false; if ( class_exists( '\Imagely\NGG\Settings\Settings' ) ) { $settings = Imagely\NGG\Settings\Settings::get_instance(); if ( 'full' === $size ) { $ngg_quality = (int) $settings->get( 'imgQuality' ); } else { $ngg_quality = (int) $settings->get( 'thumbquality' ); } } elseif ( class_exists( 'C_NextGen_Settings' ) ) { $settings = C_NextGen_Settings::get_instance(); if ( 'full' === $size ) { $ngg_quality = (int) $settings->imgQuality; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase } else { $ngg_quality = (int) $settings->thumbquality; } } if ( is_array( $params ) ) { ewwwio_debug_message( 'params is an array' ); if ( ! empty( $params['quality'] ) && 100 === (int) $params['quality'] ) { $wp_quality = (int) apply_filters( 'jpeg_quality', 82, 'image_resize' ); // If the size is full and the WP default has not been altered, go for higher quality. Otherwise, obey the current WP setting. $params['quality'] = 'full' === $size && 82 === $wp_quality ? 90 : $wp_quality; ewwwio_debug_message( "setting quality for ngg to {$params['quality']} for $size" ); } } if ( empty( $params ) || empty( $params['quality'] ) ) { $wp_quality = (int) apply_filters( 'jpeg_quality', 82, 'image_resize' ); if ( empty( $ngg_quality ) || 100 === $ngg_quality ) { $params['quality'] = 'full' === $size && 82 === $wp_quality ? 90 : $wp_quality; ewwwio_debug_message( "setting quality for ngg to {$params['quality']} for $size" ); } } return $params; } /** * Looks for more sizes to optimize in the image metadata. * * @param array $sizes The image sizes NextGEN gave us. * @param array $meta The image metadata from NextGEN. * @return array The full list of known image sizes for this image. */ public function maybe_get_more_sizes( $sizes, $meta ) { if ( 2 === count( $sizes ) && ewww_image_optimizer_iterable( $meta ) ) { foreach ( $meta as $meta_key => $meta_val ) { if ( 'backup' !== $meta_key && is_array( $meta_val ) && isset( $meta_val['width'] ) && ! in_array( $meta_key, $sizes, true ) ) { $sizes[] = $meta_key; } } } return $sizes; } /** * Adds a newly uploaded image to the optimization queue. * * @param object|array $image The new image. */ public function queue_new_image( $image ) { ewwwio_debug_message( '' . __METHOD__ . '()' ); // Find the image id. if ( is_array( $image ) ) { $image_id = $image['id']; } else { $image_id = $image->pid; } ewwwio_debug_message( "backgrounding optimization for $image_id" ); ewwwio()->background_ngg2->push_to_queue( array( 'id' => $image_id ) ); ewwwio()->background_ngg2->dispatch(); } /** * Optimizes an image (and derivatives). * * @global object $ewww_image Contains more information about the image currently being processed. * * @param object|array $image The new image. * @return object The image object with any modifications necessary. */ public function ewww_added_new_image( $image ) { ewwwio_debug_message( '' . __METHOD__ . '()' ); global $ewww_image; $this->bulk_sizes = array(); // Find the image id. if ( is_array( $image ) ) { $image_id = $image['id']; $ngg_image = $this->get_ngg_image( $image_id ); if ( ! $ngg_image ) { return $image; } $image = $ngg_image; } else { if ( empty( $image->pid ) ) { ewwwio_debug_message( 'image missing pid' ); return $image; } $image_id = $image->pid; } ewwwio_debug_message( "image id: $image_id" ); // Get an array of sizes available for the $image. $sizes = $this->get_image_sizes( $image ); $sizes = $this->maybe_get_more_sizes( $sizes, $image->meta_data ); // Run the optimizer on the image for each $size. if ( ewww_image_optimizer_iterable( $sizes ) ) { foreach ( $sizes as $size ) { if ( 'full' === $size ) { $full_size = true; } else { $full_size = false; } if ( 'backup' === $size ) { continue; } // Get the absolute path. $file_path = $this->get_image_abspath( $image, $size ); if ( empty( $file_path ) ) { ewwwio_debug_message( "no file found for $size" ); continue; } ewwwio_debug_message( "optimizing (nextgen) $size: $file_path" ); $ewww_image = new EWWW_Image( $image_id, 'nextgen', $file_path ); $ewww_image->resize = $size; // Optimize the image and grab the results. $res = ewww_image_optimizer( $file_path, 2, false, false, $full_size ); ewwwio_debug_message( "results {$res[1]}" ); $this->bulk_sizes[ $size ] = $res[1]; } } return $image; } /** * Optimizes a generated image. * * @global object $ewww_image Contains more information about the image currently being processed. * * @param object $image A nextgen image object. * @param object $size The name of the size generated. */ public function ewww_ngg_generated_image( $image, $size ) { ewwwio_debug_message( '' . __METHOD__ . '()' ); global $ewww_image; $filename = $this->get_image_abspath( $image, $size ); $ewww_image = new EWWW_Image( $image->pid, 'nextgen', $filename ); $ewww_image->resize = $size; if ( is_file( $filename ) ) { ewww_image_optimizer( $filename, 2 ); ewwwio_debug_message( "nextgen dynamic thumb saved: $filename" ); $image_size = ewww_image_optimizer_filesize( $filename ); ewwwio_debug_message( "optimized size: $image_size" ); } } /** * Manually process an image from the NextGEN Gallery. */ public function ewww_ngg_manual() { ewwwio_debug_message( '' . __METHOD__ . '()' ); // Check permission of current user. $permissions = apply_filters( 'ewww_image_optimizer_manual_permissions', '' ); if ( false === current_user_can( $permissions ) ) { if ( ! wp_doing_ajax() ) { wp_die( esc_html__( 'You do not have permission to optimize images.', 'ewww-image-optimizer' ) ); } ewwwio_ob_clean(); wp_die( wp_json_encode( array( 'error' => esc_html__( 'You do not have permission to optimize images.', 'ewww-image-optimizer' ) ) ) ); } // Make sure function wasn't called without an attachment to work with. if ( false === isset( $_REQUEST['ewww_attachment_ID'] ) ) { if ( ! wp_doing_ajax() ) { wp_die( esc_html__( 'No attachment ID was provided.', 'ewww-image-optimizer' ) ); } ewwwio_ob_clean(); wp_die( wp_json_encode( array( 'error' => esc_html__( 'No attachment ID was provided.', 'ewww-image-optimizer' ) ) ) ); } // Sanitize the attachment $id. $id = (int) $_REQUEST['ewww_attachment_ID']; if ( empty( $_REQUEST['ewww_manual_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['ewww_manual_nonce'] ), "ewww-manual-$id" ) ) { if ( ! wp_doing_ajax() ) { wp_die( esc_html__( 'Access denied.', 'ewww-image-optimizer' ) ); } ewwwio_ob_clean(); wp_die( wp_json_encode( array( 'error' => esc_html__( 'Access denied.', 'ewww-image-optimizer' ) ) ) ); } global $ewww_force; $ewww_force = ! empty( $_REQUEST['ewww_force'] ) ? true : false; // Get an image object. $image = $this->get_ngg_image( $id ); $image = $this->ewww_added_new_image( $image ); $success = $this->ewww_manage_image_custom_column( '', $image ); if ( 'exceeded' === get_transient( 'ewww_image_optimizer_cloud_status' ) || ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_exceeded' ) > time() ) { ewwwio_ob_clean(); wp_die( wp_json_encode( array( 'error' => '' . esc_html__( 'License exceeded', 'ewww-image-optimizer' ) . '', ) ) ); } if ( 'exceeded quota' === get_transient( 'ewww_image_optimizer_cloud_status' ) ) { ewwwio_ob_clean(); wp_die( wp_json_encode( array( 'error' => '' . esc_html__( 'Soft quota reached, contact us for more', 'ewww-image-optimizer' ) . '', ) ) ); } if ( ! wp_doing_ajax() ) { // Get the referring page, and send the user back there. wp_safe_redirect( wp_get_referer() ); die; } ewwwio_ob_clean(); wp_die( wp_json_encode( array( 'success' => $success ) ) ); } /** * Restore an image from the NextGEN Gallery. */ public function ewww_ngg_image_restore() { ewwwio_debug_message( '' . __METHOD__ . '()' ); // Check permission of current user. $permissions = apply_filters( 'ewww_image_optimizer_manual_permissions', '' ); if ( false === current_user_can( $permissions ) ) { if ( ! wp_doing_ajax() ) { wp_die( esc_html__( 'You do not have permission to optimize images.', 'ewww-image-optimizer' ) ); } ewwwio_ob_clean(); wp_die( wp_json_encode( array( 'error' => esc_html__( 'You do not have permission to optimize images.', 'ewww-image-optimizer' ) ) ) ); } // Make sure function wasn't called without an attachment to work with. if ( false === isset( $_REQUEST['ewww_attachment_ID'] ) ) { if ( ! wp_doing_ajax() ) { wp_die( esc_html__( 'No attachment ID was provided.', 'ewww-image-optimizer' ) ); } ewwwio_ob_clean(); wp_die( wp_json_encode( array( 'error' => esc_html__( 'No attachment ID was provided.', 'ewww-image-optimizer' ) ) ) ); } // Sanitize the attachment $id. $id = intval( $_REQUEST['ewww_attachment_ID'] ); if ( empty( $_REQUEST['ewww_manual_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['ewww_manual_nonce'] ), "ewww-manual-$id" ) ) { if ( ! wp_doing_ajax() ) { wp_die( esc_html__( 'Access denied.', 'ewww-image-optimizer' ) ); } ewwwio_ob_clean(); wp_die( wp_json_encode( array( 'error' => esc_html__( 'Access denied.', 'ewww-image-optimizer' ) ) ) ); } // Get an image object. $image = $this->get_ngg_image( $id ); global $eio_backup; $eio_backup->restore_backup_from_meta_data( $image->pid, 'nextgen' ); $success = $this->ewww_manage_image_custom_column( '', $image ); ewwwio_ob_clean(); wp_die( wp_json_encode( array( 'success' => $success ) ) ); } /** * Prepare javascript for one-click actions on manage gallery page. * * @param string $hook The hook value for the current page. */ public function ewww_ngg_manual_actions_script( $hook ) { $screen = get_current_screen(); if ( is_null( $screen ) ) { return; } if ( 'nextgen-gallery_page_nggallery-manage-gallery' !== $screen->id && 'nggallery-manage-images' !== $screen->id ) { return; } if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) { return; } add_thickbox(); wp_enqueue_script( 'ewwwnextgenscript', plugins_url( '/includes/nextgen.js', EWWW_IMAGE_OPTIMIZER_PLUGIN_FILE ), array( 'jquery' ), EWWW_IMAGE_OPTIMIZER_VERSION ); wp_enqueue_style( 'jquery-ui-tooltip-custom', plugins_url( '/includes/jquery-ui-1.10.1.custom.css', EWWW_IMAGE_OPTIMIZER_PLUGIN_FILE ), array(), EWWW_IMAGE_OPTIMIZER_VERSION ); // Submit a couple variables needed for javascript functions. $loading_image = plugins_url( '/images/spinner.gif', EWWW_IMAGE_OPTIMIZER_PLUGIN_FILE ); wp_localize_script( 'ewwwnextgenscript', 'ewww_vars', array( 'optimizing' => '
' . esc_html__( 'Optimizing', 'ewww-image-optimizer' ) . "
", 'restoring' => '' . esc_html__( 'Restoring', 'ewww-image-optimizer' ) . "
", ) ); } /** * Adds our column to the list for users to toggle via Screen Options. * * @param array $columns A list of existing column names. * @return array The revised list of column names. */ public function manage_images_columns( $columns ) { if ( is_array( $columns ) ) { $columns['ewww_image_optimizer'] = esc_html__( 'Image Optimizer', 'ewww-image-optimizer' ); } return $columns; } /** * Filter for ngg_manage_images_number_of_columns hook, changed in NGG 2.0.50ish. * * @param int $count The number of columns for the table display. * @return int The new number of columns. */ public function ewww_manage_images_number_of_columns( $count ) { ++$count; add_filter( "ngg_manage_images_column_{$count}_header", array( $this, 'ewww_manage_images_columns' ) ); add_filter( "ngg_manage_images_column_{$count}_content", array( $this, 'ewww_manage_image_custom_column' ), 10, 2 ); return $count; } /** * Outputs column header via ngg_manage_images_column_x_header hook. * * @param array|null $columns List of headers for the table. * @return array|string The new list of headers, or the single header for EWWW IO. */ public function ewww_manage_images_columns( $columns = null ) { if ( is_array( $columns ) ) { $columns['ewww_image_optimizer'] = esc_html__( 'Image Optimizer', 'ewww-image-optimizer' ); return $columns; } return esc_html__( 'Image Optimizer', 'ewww-image-optimizer' ); } /** * Outputs the image optimizer column data via ngg_manage_images_column_x_content hook. * * @global object $wpdb * * @param string $column_name The name of the current column. * @param int $id The image id for the current row. * @return string The column output, potentially echoed instead. */ public function ewww_manage_image_custom_column( $column_name, $id ) { // Once we've found our custom column (newer versions will be blank). if ( 'ewww_image_optimizer' === $column_name || ! $column_name ) { ewwwio_debug_message( '' . __METHOD__ . '()' ); ob_start(); if ( is_object( $id ) ) { $image = $id; } else { // Get an image object. $image = $this->get_ngg_image( $id ); } echo '' . esc_html__( 'You do not appear to have uploaded any images yet.', 'ewww-image-optimizer' ) . '
'; return; } ?>' . esc_html__( 'Bulk Optimization will alter your original images and cannot be undone. Please be sure you have a backup of your images before proceeding.', 'ewww-image-optimizer' ) . '
' . esc_html__( 'Debugging Information', 'ewww-image-optimizer' ) . ':
' . esc_html__( 'Optimizing', 'ewww-image-optimizer' ) . "
"; } else { $output['results'] = '' . esc_html__( 'Optimizing', 'ewww-image-optimizer' ) . " $file
"; } ewwwio_ob_clean(); wp_die( wp_json_encode( $output ) ); } /** * Retrieve the filename of the image being optimized. * * @param int $id The ID number of the image. * @return string|bool The name of the current file or false. */ public function ewww_ngg_bulk_filename( $id ) { // Get the filename for the image, and output our current status. $file_path = esc_html( $this->get_image_abspath( $id, 'full' ) ); if ( ! empty( $file_path ) ) { return $file_path; } else { return false; } } /** * Process each image in the bulk queue. * * @global bool $ewww_defer Set to false to avoid deferring image optimization. */ public function ewww_ngg_bulk_loop() { global $ewww_defer; $ewww_defer = false; $output = array(); $permissions = apply_filters( 'ewww_image_optimizer_bulk_permissions', '' ); if ( empty( $_REQUEST['ewww_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['ewww_wpnonce'] ), 'ewww-image-optimizer-bulk' ) || ! current_user_can( $permissions ) ) { $output['error'] = esc_html__( 'Access token has expired, please reload the page.', 'ewww-image-optimizer' ); ewwwio_ob_clean(); wp_die( wp_json_encode( $output ) ); } session_write_close(); // Find out if our nonce is on it's last leg/tick. $tick = wp_verify_nonce( sanitize_key( $_REQUEST['ewww_wpnonce'] ), 'ewww-image-optimizer-bulk' ); if ( 2 === $tick ) { $output['new_nonce'] = wp_create_nonce( 'ewww-image-optimizer-bulk' ); } else { $output['new_nonce'] = ''; } // Find out what time we started, in microseconds. $started = microtime( true ); // Get the list of attachments remaining from the db. $attachments = get_option( 'ewww_image_optimizer_bulk_ngg_attachments' ); $id = array_shift( $attachments ); // Get an image object. $image = $this->get_ngg_image( $id ); $image = $this->ewww_added_new_image( $image ); $ewww_status = get_transient( 'ewww_image_optimizer_cloud_status' ); if ( ! empty( $ewww_status ) && preg_match( '/exceeded/', $ewww_status ) ) { $output['error'] = esc_html__( 'License Exceeded', 'ewww-image-optimizer' ); ewwwio_ob_clean(); wp_die( wp_json_encode( $output ) ); } // Output the results of the optimization. $output['results'] = sprintf( '' . esc_html__( 'Optimized image:', 'ewww-image-optimizer' ) . ' %s
', esc_html( wp_basename( $this->get_image_abspath( $image, 'full' ) ) ) );
if ( ewww_image_optimizer_iterable( $this->bulk_sizes ) ) {
foreach ( $this->bulk_sizes as $size => $results_msg ) {
if ( 'backup' === $size ) {
continue;
} elseif ( 'full' === $size ) {
/* Translators: %s: The compression results/savings */
$output['results'] .= sprintf( esc_html__( 'Full size - %s', 'ewww-image-optimizer' ) . '
', esc_html( $results_msg ) );
} elseif ( 'thumbnail' === $size ) {
// Output the results of the thumb optimization.
/* Translators: %s: The compression results/savings */
$output['results'] .= sprintf( esc_html__( 'Thumbnail - %s', 'ewww-image-optimizer' ) . '
', esc_html( $results_msg ) );
} else {
// Output savings for any other sizes, if they ever exist...
$output['results'] .= ucfirst( $size ) . ' - ' . esc_html( $results_msg ) . '
';
}
}
$this->bulk_sizes = array();
}
// Output how much time we spent.
$elapsed = microtime( true ) - $started;
/* Translators: %s: The localized number of seconds */
$output['results'] .= sprintf( esc_html( _n( 'Elapsed: %s second', 'Elapsed: %s seconds', $elapsed, 'ewww-image-optimizer' ) ) . '
' . esc_html__( 'Optimizing', 'ewww-image-optimizer' ) . " $next_file
"; } else { $output['next_file'] = '' . esc_html__( 'Optimizing', 'ewww-image-optimizer' ) . "
"; } } else { $output['done'] = 1; } ewwwio_ob_clean(); wp_die( wp_json_encode( $output ) ); } /** * Finish the bulk operation. */ public function ewww_ngg_bulk_cleanup() { $permissions = apply_filters( 'ewww_image_optimizer_bulk_permissions', '' ); if ( empty( $_REQUEST['ewww_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['ewww_wpnonce'] ), 'ewww-image-optimizer-bulk' ) || ! current_user_can( $permissions ) ) { ewwwio_ob_clean(); wp_die( esc_html__( 'Access token has expired, please reload the page.', 'ewww-image-optimizer' ) ); } // Reset all the bulk options in the db. update_option( 'ewww_image_optimizer_bulk_ngg_resume', '' ); update_option( 'ewww_image_optimizer_bulk_ngg_attachments', '', false ); ewwwio_ob_clean(); wp_die( '' . esc_html__( 'Finished Optimization!', 'ewww-image-optimizer' ) . '
' ); } /** * Insert a bulk optimize option in the actions list for the gallery and image management pages (via javascript, since we have no hooks). */ public function ewww_ngg_bulk_actions_script() { global $current_screen; if ( ( strpos( $current_screen->id, 'nggallery-manage-images' ) === false && strpos( $current_screen->id, 'nggallery-manage-gallery' ) === false ) || ! current_user_can( apply_filters( 'ewww_image_optimizer_bulk_permissions', '' ) ) ) { return; } ?> ' . __METHOD__ . '()' ); if ( empty( $_REQUEST['_wpnonce'] ) || ( ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'ngg_bulkgallery' ) && ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'ngg_updategallery' ) ) ) { ewwwio_debug_message( 'nonce verify failed' ); return; } // If the requested page is blank, or not a bulk_optimize, do nothing. if ( empty( $_REQUEST['nggpage'] ) || empty( $_REQUEST['bulkaction'] ) || 'bulk_optimize' !== $_REQUEST['bulkaction'] ) { return; } // If there is no media to optimize, do nothing. if ( empty( $_REQUEST['doaction'] ) || ! is_array( $_REQUEST['doaction'] ) ) { return; } // If the requested page does not match, do nothing. if ( 'manage-galleries' !== $_REQUEST['nggpage'] && 'manage-images' !== $_REQUEST['nggpage'] ) { return; } $type = 'images'; if ( 'manage-galleries' === $_REQUEST['nggpage'] ) { $type = 'galleries'; } wp_safe_redirect( add_query_arg( array( 'page' => 'ewww-ngg-bulk', '_wpnonce' => sanitize_key( $_REQUEST['_wpnonce'] ), 'bulk_type' => $type, 'bulkaction' => 'bulk_optimize', 'doaction' => array_map( 'intval', wp_unslash( $_REQUEST['doaction'] ) ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ), admin_url( 'admin.php' ) ) ); ewwwio_memory( __METHOD__ ); exit(); } } // Initialize the plugin and the class. global $ewwwngg; $ewwwngg = new EWWW_Nextgen(); } // End if().