init(); $directory_ui_controller = new Directory_UI_Controller(); $directory_ui_controller->init(); } /** * Render the bulk smush page. * * @return void */ public function render() { if ( Hub_Connector::should_render() ) { Hub_Connector::render(); return; } if ( Membership::get_instance()->is_api_hub_access_required() ) { $this->open_page_wrapper(); $this->render_modals(); $this->render_inner_content(); $this->close_page_wrapper(); return; } parent::render(); } public function enqueue_scripts( $hook ) { parent::enqueue_scripts( $hook ); $this->enqueue_lib_scanner_scripts(); } protected function enqueue_lib_scanner_scripts() { wp_enqueue_script( 'smush-library-scanner', WP_SMUSH_URL . 'app/assets/js/smush-library-scanner.min.js', array( 'wp-i18n' ), WP_SMUSH_VERSION, true ); wp_localize_script( 'smush-library-scanner', 'mediaLibraryScan', array( 'nonce' => wp_create_nonce( 'wp_smush_media_library_scanner' ), ) ); } public function render_hub_connection_prompt() { $media_item_query = new Media_Item_Query(); $attachment_count = (int) $media_item_query->get_image_attachment_count(); $smushed_count = (int) $media_item_query->get_smushed_count(); $remaining_count = $attachment_count - $smushed_count; $this->view( 'bulk/hub-connect', array( 'images_count' => $remaining_count, 'connect_url' => \Smush\Core\Hub_Connector::get_connect_site_url( 'smush-bulk', 'smush_bulk_smush_connect' ), ) ); } /** * Register meta boxes. */ public function register_meta_boxes() { if ( Membership::get_instance()->is_api_hub_access_required() ) { $this->add_meta_box( 'smush-hub-connect', '', array( $this, 'render_hub_connection_prompt' ), null, null, 'main', array( 'box_content_class' => false, ) ); return; } if ( ! is_network_admin() ) { $this->add_meta_box( 'ajax-bulk-smush-in-progressing-notice', null, array( $this, 'ajax_bulk_smush_in_progressing_notice' ), null, null, 'main', array( 'box_class' => 'sui-box ajax-bulk-smush-in-progressing-notice sui-hidden', 'box_content_class' => false, ) ); $background_health = Background_Pre_Flight_Controller::get_instance(); if ( ! $background_health->is_cron_healthy() ) { $this->add_meta_box( 'cron-disabled-notice', null, array( $this, 'cron_disabled_notice_meta_box' ), null, null, 'main', array( 'box_class' => 'sui-box wp-smush-cron-disabled-notice-box', 'box_content_class' => false, ) ); } $this->add_meta_box( 'recheck-images-notice', null, array( $this, 'recheck_images_notice_meta_box' ), null, null, 'main', array( 'box_class' => 'sui-box wp-smush-recheck-images-notice-box sui-hidden', 'box_content_class' => false, ) ); } parent::register_meta_boxes(); if ( ! is_network_admin() ) { $this->add_meta_box( 'bulk', __( 'Bulk Smush', 'wp-smushit' ), array( $this, 'bulk_smush_metabox' ), null, null, 'main', array( 'box_class' => 'sui-box bulk-smush-wrapper', ) ); } $this->add_meta_box( 'bulk-settings', __( 'Settings', 'wp-smushit' ), array( $this, 'bulk_settings_meta_box' ), null, array( $this, 'common_meta_box_footer' ), 'main', array( 'box_class' => 'sui-box smush-settings-wrapper', ) ); $restore_ids = WP_Smush::get_instance()->core()->mod->backup->get_attachments_with_backups(); $this->modals['restore-images'] = array( 'restore_image_count' => count( $restore_ids ), ); $this->modals['disable-backup-original-image'] = array(); } /************************** * META BOXES */ /** * Common footer meta box. * * @since 3.2.0 */ public function common_meta_box_footer() { $this->view( 'meta-box-footer', array(), 'common' ); } /** * Bulk smush meta box. * * Container box to handle bulk smush actions. Show progress bars, * bulk smush action buttons etc. in this box. */ public function bulk_smush_metabox() { $core = WP_Smush::get_instance()->core(); $global_stats = $core->get_global_stats(); $array_utils = new Array_Utils(); $bulk_upgrade_url = $this->get_utm_link( array( 'utm_campaign' => 'smush_bulk_smush_complete_global', ) ); $in_progress_upsell_url = $this->get_utm_link( array( 'utm_campaign' => 'smush_bulk_smush_progress_BO', ) ); $upsell_cdn_url = $this->get_utm_link( array( 'utm_campaign' => 'smush_bulksmush_cdn', ) ); $upsell_text = sprintf( /* translators: 1: Open the link, 2: Close the link */ __( 'Want to close this tab? Smush Pro lets you optimize in the background — %1$sGet Smush Pro!%2$s', 'wp-smushit' ), '', '' ); $in_processing_notice = sprintf( /* translators: %s: Upsell text */ __( 'Bulk Smush is currently running. Please keep this page open until the process is complete. %s', 'wp-smushit' ), $upsell_text ); $this->view( 'bulk/meta-box', array( 'core' => $core, 'unsmushed_count' => (int) $array_utils->get_array_value( $global_stats, 'count_unsmushed' ), 'resmush_count' => (int) $array_utils->get_array_value( $global_stats, 'count_resmush' ), 'remaining_count' => (int) $array_utils->get_array_value( $global_stats, 'remaining_count' ), 'total_count' => (int) $array_utils->get_array_value( $global_stats, 'count_total' ), 'bulk_upgrade_url' => $bulk_upgrade_url, 'upsell_cdn_url' => $upsell_cdn_url, 'in_processing_notice' => $in_processing_notice, ) ); } /** * Settings meta box. * * Free and pro version settings are shown in same section. For free users, pro settings won't be shown. * To print full size smush, resize and backup in group, we hook at `smush_setting_column_right_end`. */ public function bulk_settings_meta_box() { $fields = $this->settings->get_bulk_fields(); // Remove backups setting, as it's added separately. $key = array_search( 'backup', $fields, true ); if ( false !== $key ) { unset( $fields[ $key ] ); } // Remove no_scale setting, as it's added separately. $key = array_search( 'no_scale', $fields, true ); if ( false !== $key ) { unset( $fields[ $key ] ); } $this->view( 'bulk-settings/meta-box', array( 'basic_features' => Settings::$basic_features, 'cdn_enabled' => $this->settings->get( 'cdn' ), 'grouped_settings' => $fields, 'settings' => $this->settings->get(), ) ); } public function add_pro_tag( $name ) { $settings = Settings::get_instance(); if ( ! $settings->is_pro_field( $name ) ) { return; } ?> view( 'recheck-images-notice', array(), 'common' ); } public function ajax_bulk_smush_in_progressing_notice() { $this->view( 'ajax-bulk-smush-in-progressing-notice', array(), 'views/bulk' ); } public function cron_disabled_notice_meta_box() { $this->view( 'bulk/cron-disabled-notice' ); } }