* * @copyright (c) 2016, Incsub (http://incsub.com) */ if ( ! class_exists( 'WpSmushBulkUi' ) ) { /** * Class WpSmushBulkUi * * Handle the UI part for the plugin. */ class WpSmushBulkUi { /** * Settings group for resize options. * * @var array */ public $resize_group = array( 'detection', ); /** * Settings group for full size image options. * * @var array */ public $full_size_group = array( 'backup', ); /** * Settings group for integration options. * * @var array */ public $intgration_group = array(); /** * Tabs that can be shown in network admin networkwide. * * @var array */ public $network_tabs = array( 'bulk', 'integrations', 'cdn', ); /** * Tabs that can be shown in subsites if networkwide. * * @var array */ public $subsite_tabs = array( 'bulk', 'directory', ); /** * Setting tabs. * * @var array */ public $tabs = array(); /** * Current tab. * * @var string */ public $current_tab = 'bulk'; /** * WpSmushBulkUi constructor. */ public function __construct() { add_action( 'smush_setting_column_right_inside', array( $this, 'settings_desc' ), 10, 2 ); add_action( 'smush_setting_column_right_inside', array( $this, 'image_sizes' ), 15, 2 ); add_action( 'smush_setting_column_right_inside', array( $this, 'resize_settings' ), 20, 2 ); add_action( 'smush_setting_column_right_outside', array( $this, 'full_size_options' ), 20, 2 ); add_action( 'smush_setting_column_right_outside', array( $this, 'detect_size_options' ), 25, 2 ); add_action( 'smush_settings_ui_bottom', array( $this, 'pro_features_container' ) ); // Add stats to stats box. add_action( 'stats_ui_after_resize_savings', array( $this, 'pro_savings_stats' ), 15 ); add_action( 'stats_ui_after_resize_savings', array( $this, 'conversion_savings_stats' ), 15 ); } /** * Display the whole admin page ui. * * Load all sub sections such as stats container, settings * bulk smush container, integrations CDN etc, under this function. * This function directory echo the output. * * @return void */ public function ui() { global $wp_smush, $wpsmushit_admin, $wpsmush_settings; // Hook into integration settings. $this->intgration_group = apply_filters( 'wp_smush_integration_settings', array() ); // Set current active tab. $this->set_current_tab(); // If a free user, update the limits. if ( ! $wp_smush->validate_install() ) { // Reset transient. $wpsmushit_admin->check_bulk_limit( true ); } // Shared UI wrapper. echo '
'; // Load page header. $this->smush_page_header(); // Check if current page network admin page. $is_network = is_network_admin(); $is_networkwide = $wpsmush_settings->settings['networkwide']; // Show stats section only to subsite admins. if ( ! $is_network ) { // Show configure screen for only a new installation and for only network admins. if ( ( '1' !== get_site_option( 'skip-smush-setup' ) && '1' !== get_option( 'wp-smush-hide_smush_welcome' ) ) && '1' !== get_option( 'hide_smush_features' ) && is_super_admin() ) { $this->quick_setup(); } // Show status box. $this->smush_stats_container(); // If not a pro user. if ( ! $wp_smush->validate_install() ) { /** * Allows to hook in additional containers after stats box for free version * Pro Version has a full width settings box, so we don't want to do it there. */ do_action( 'wp_smush_after_stats_box' ); } } // Start the nav bar for settings. echo '
'; // Load the settings nav. $this->settings_nav(); // Nonce field. wp_nonce_field( 'save_wp_smush_options', 'wp_smush_options_nonce', '' ); // If network wide option is disabled, show only bulk page. if ( $is_network && ! $is_networkwide ) { // Show settings box. $this->settings_container(); } else { switch ( $this->current_tab ) { case 'directory': // Action hook to add settings to directory smush. do_action( 'smush_directory_settings_ui' ); break; case 'integrations': // Show integrations box. $this->integrations_ui(); break; case 'cdn': // Action hook to add settings to cdn section. do_action( 'smush_cdn_settings_ui' ); break; case 'bulk': default: // Show bulk smush box if a subsite admin. if ( ! $is_network ) { // Bulk smush box. $this->bulk_smush_container(); } if ( $is_network || ! $is_networkwide ) { // Show settings box. $this->settings_container(); } break; } } // End if(). // Close nav bar box. echo '
'; /** * Action hook to add extra containers at bottom of admin UI. */ do_action( 'smush_admin_ui_bottom' ); // Close shared ui wrapper. echo '
'; } /** * Prints the header section for a container as per the Shared UI * * @param string $heading Box Heading. * @param string $sub_heading Any additional text to be shown by the side of Heading. * * @return string */ public function container_header( $heading = '', $sub_heading = '' ) { if ( empty( $heading ) ) { return ''; } ?>

', '' ); // Class for bulk smush box. $class = $wp_smush->validate_install() ? 'bulk-smush-wrapper wp-smush-pro-install' : 'bulk-smush-wrapper'; echo '
'; // Container header. $this->container_header( esc_html__( 'Bulk Smush', 'wp-smushit' ), $smush_individual_msg ); echo '
'; // Bulk smush box. $this->bulk_smush_content(); echo '
'; echo '
'; } /** * All the settings for basic and advanced users. * * @return void */ public function settings_container() { global $wp_smush; // Class for box. $class = $wp_smush->validate_install() ? 'smush-settings-wrapper wp-smush-pro' : 'smush-settings-wrapper'; echo '
'; // Container header. $this->container_header( esc_html__( 'Settings', 'wp-smushit' ) ); echo '
'; // Load settings content. $this->options_ui(); // Close box body. echo '
'; // Footer content including buttons. $div_end = ' ' . esc_html__( 'Smush will automatically check for any images that need re-smushing.', 'wp-smushit' ) . ' '; // Container footer. $this->container_footer( '', $div_end ); // Close settings container. echo '
'; /** * Action hook to add extra containers after settings. */ do_action( 'smush_settings_ui_bottom' ); } /** * Integration settings for Smush. * * All integrations suhc as S3, NextGen can be added to this container. * * @return void */ public function integrations_ui() { global $wp_smush; // If no integration settings found, bail. if ( empty( $this->intgration_group ) ) { return; } $is_pro = $wp_smush->validate_install(); // Container box class. $class = $is_pro ? 'smush-integrations-wrapper wp-smush-pro' : 'smush-integrations-wrapper'; echo '
'; // Container header. $this->container_header( esc_html__( 'Integrations', 'wp-smushit' ) ); // Box body class. $box_body_class = $is_pro ? 'sui-box-body' : 'sui-box-body sui-upsell-items'; echo '
'; // Integration settings content. $this->integrations_settings(); if ( ! $is_pro ) { $this->integrations_upsell(); } echo '
'; /** * Filter to enable/disable submit button in integration settings. * * @param bool $show_submit Should show submit? */ $show_submit = apply_filters( 'wp_smush_integration_show_submit', false ); // Box footer content including buttons. $div_end = ' ' . esc_html__( 'Smush will automatically check for any images that need re-smushing.', 'wp-smushit' ) . ' '; // Container footer if pro. if ( $show_submit ) { $this->container_footer( '', $div_end ); } echo '
'; /** * Action hook to add extra containers after integration settings. */ do_action( 'smush_integrations_ui_bottom' ); } /** * Outputs the smush stats for the site. * * @return void */ public function smush_stats_container() { global $wpsmushit_admin, $wpsmush_db, $wpsmush_settings; $settings = $wpsmush_settings->settings; $networkwide = (bool) $settings['networkwide']; $resize_enabled = (bool) $settings['resize']; $resize_count = $wpsmush_db->resize_savings( false, false, true ); $resize_count = ! $resize_count ? 0 : $resize_count; $remaining = $wpsmushit_admin->remaining_count; // Split human size to get format and size. $human = explode( ' ', $wpsmushit_admin->stats['human'] ); $human_size = empty( $human[0] ) ? '0' : $human[0]; $human_format = empty( $human[1] ) ? 'B' : $human[1]; ?>
/ stats['percent'] > 0 ? number_format_i18n( $wpsmushit_admin->stats['percent'], 1, '.', '' ) : 0; ?>% stats['total_images']; ?> 0 ) { ?>
settings; $networkwide = (bool) $settings['networkwide']; if ( ! $wp_smush->validate_install() ) { if ( empty( $wpsmushit_admin->stats ) || empty( $wpsmushit_admin->stats['pro_savings'] ) ) { $wpsmushit_admin->set_pro_savings(); } $pro_savings = $wpsmushit_admin->stats['pro_savings']; $show_pro_savings = $pro_savings['savings'] > 0 ? true : false; if ( $show_pro_savings ) { ?>
  • / %
  • stats ) && ! empty( $wpsmushit_admin->stats['bytes'] ) ) { $compression_savings = $wpsmushit_admin->stats['bytes'] - $wpsmushit_admin->stats['resize_savings']; } ?>
  • lossy_enabled ) { ?>

    settings_link( array(), true, true ) . '#enable-lossy'; } elseif ( 'bulk' !== $this->current_tab ) { $settings_link = $wpsmushit_admin->settings_link( array(), true ) . '#enable-lossy'; } else { $settings_link = '#'; $link_class = 'wp-smush-lossy-enable'; } printf( esc_html__( 'Compress images up to 2x more than regular smush with almost no visible drop in quality. %1$sEnable Super-smush%2$s', 'wp-smushit' ), '', '' . __( 'Clicking this link will toggle the Super Smush checkbox.', 'wp-smushit' ) . '' ); ?>

    lossy_enabled ) { ?>
  • validate_install() && ! empty( $wpsmushit_admin->stats['conversion_savings'] ) && $wpsmushit_admin->stats['conversion_savings'] > 0 ) { ?>
  • stats['conversion_savings'] > 0 ? size_format( $wpsmushit_admin->stats['conversion_savings'], 1 ) : '0MB'; ?>
  • resize_group, $this->full_size_group, $this->intgration_group ); // Get settings values. $settings = empty( $wpsmush_settings->settings ) ? $wpsmush_settings->init_settings() : $wpsmush_settings->settings; ?>
    settings['networkwide']; ?> settings['networkwide'] ? '' : ' sui-hidden'; ?>
    settings['networkwide'] && ! is_network_admin() ) || is_network_admin() ) { foreach ( $wpsmushit_admin->settings as $name => $values ) { // Skip networkwide settings, we already printed it. if ( 'networkwide' == $name ) { continue; } // Skip premium features if not a member. if ( ! in_array( $name, $wpsmushit_admin->basic_features ) && ! $wp_smush->validate_install() ) { continue; } $setting_m_key = WP_SMUSH_PREFIX . $name; $setting_val = empty( $settings[ $name ] ) ? 0 : $settings[ $name ]; // Set the default value 1 for auto smush. if ( 'auto' == $name && ( false === $setting_val || ! isset( $setting_val ) ) ) { $setting_val = 1; } // Group Original, Resize and Backup for pro users if ( in_array( $name, $grouped_settings ) ) { continue; } $label = ! empty( $wpsmushit_admin->settings[ $name ]['short_label'] ) ? $wpsmushit_admin->settings[ $name ]['short_label'] : $wpsmushit_admin->settings[ $name ]['label']; // Show settings option. $this->settings_row( $setting_m_key, $label, $name, $setting_val ); } // Hook after general settings. do_action( 'wp_smush_after_basic_settings' ); } if ( is_multisite() && is_network_admin() ) { echo '
    '; } ?>
    settings ) ? $wpsmush_settings->init_settings() : $wpsmush_settings->settings; ?>
    settings['networkwide'] && ! is_network_admin() ) || is_network_admin() ) { foreach ( $this->intgration_group as $name ) { // Settings key. $setting_m_key = WP_SMUSH_PREFIX . $name; // Disable setting. $disable = apply_filters( 'wp_smush_integration_status_' . $name, false ); // Gray out row, disable setting. $upsell = ( ! in_array( $name, $wpsmushit_admin->basic_features ) && ! $wp_smush->validate_install() ); // Current setting value. $setting_val = ( $upsell || empty( $settings[ $name ] ) || $disable ) ? 0 : $settings[ $name ]; // Current setting label. $label = ! empty( $wpsmushit_admin->settings[ $name ]['short_label'] ) ? $wpsmushit_admin->settings[ $name ]['short_label'] : $wpsmushit_admin->settings[ $name ]['label']; // Show settings option. $this->settings_row( $setting_m_key, $label, $name, $setting_val, true, $disable, $upsell ); } // Hook after showing integration settings. do_action( 'wp_smush_after_integration_settings' ); } ?>
    'smush', 'utm_medium' => 'plugin', 'utm_campaign' => 'smush-nextgen-settings-upsell', ), $wpsmushit_admin->upgrade_url ); ?>

    ', '' ); ?>

    resize_group, $this->full_size_group, $this->intgration_group ); ?>
    settings[ $name ]['desc']; ?>
    validate_install(); // Check if all items are smushed. $all_done = ( $wpsmushit_admin->smushed_count == $wpsmushit_admin->total_count ) && 0 == count( $wpsmushit_admin->resmush_ids ); // Show re-smush notice. echo $this->bulk_resmush_content(); $upgrade_url = add_query_arg( array( 'utm_source' => 'smush', 'utm_medium' => 'plugin', 'utm_campaign' => 'smush_stats_enable_lossy', ), $wpsmushit_admin->upgrade_url ); // Check whether to show pagespeed recommendation or not. $hide_pagespeed = get_site_option( WP_SMUSH_PREFIX . 'hide_pagespeed_suggestion' ); // If there are no images in media library. if ( 0 >= $wpsmushit_admin->total_count ) : ?> <?php esc_html_e( 'No attachments found - Upload some images', 'wp-smushit' ); ?>


    progress_bar( $wpsmushit_admin ); ?>
    1. ', '' ); ?>
    2. settings['lossy'] ) : ?>
    3. ', '' ); ?>
    4. ', '' ); ?>
    5. settings['resize'] ) : ?>
    6. ', '' ); ?>
    remaining_count > 0 ) : $class = count( $wpsmushit_admin->resmush_ids ) > 0 ? ' sui-hidden' : ''; $upgrade_url = add_query_arg( array( 'utm_source' => 'smush', 'utm_medium' => 'plugin', 'utm_campaign' => 'smush_bulksmush_limit_notice', ), $wpsmushit_admin->upgrade_url ); ?>

    remaining_count, 'wp-smushit' ), $wpsmushit_admin->get_user_name(), '', '', $wpsmushit_admin->remaining_count, '', '' ); ?> remaining_count > 50 ) : ?> ', '' ); ?>

    lossy_enabled ) { ?>

    super_smush_promo(); } /** * Show nav side bars for settings box. * * Usign Shared UI nav box to show sidebar navigation. * * @return void */ public function settings_nav() { global $wpsmushit_admin, $wpsmush_settings; $remaining = $wpsmushit_admin->remaining_count; $is_network = is_network_admin(); $networkwide = $wpsmush_settings->settings['networkwide']; $bulk_tag_content = $bulk_tag_class = ''; if ( $remaining > 0 && ! $is_network ) { $bulk_tag_class = ' sui-tag sui-tag-warning wp-smush-remaining-count'; $bulk_tag_content = $remaining; } ?>
    tabs as $tab => $label ) : ?> intgration_group ) ) ) : ?> network_tabs ) ) : ?> subsite_tabs ) ) : ?> current_tab ? ' current' : '' ) . '">'; $main_nav_li .= '' . $label . ''; $main_nav_li .= ''; $main_nav_li .= ''; // Mobile nav if ( is_multisite() && is_network_admin() ) { $url = network_admin_url( 'admin.php?page=smush' . '&tab=' . $tab ); } else { $url = admin_url( 'admin.php?page=smush' . '&tab=' . $tab ); } $select_nav .= ''; $mob_nav_li .= '
  • ' . $label . '
  • '; ?>

    ', '' ); ?>

    0%
    0/remaining_count ); ?>
    0 ? true : false; // Get the actual remainaing count. if ( ! isset( $wpsmushit_admin->remaining_count ) ) { $wpsmushit_admin->setup_global_stats(); } $count = $wpsmushit_admin->remaining_count; } } // Show only if we have any images to ber resmushed. if ( $show ) { return '

    ' . sprintf( _n( '%1$s, you have %2$s%3$s%4$d%5$s attachment%6$s that needs re-compressing!', '%1$s, you have %2$s%3$s%4$d%5$s attachments%6$s that need re-compressing!', $count, 'wp-smushit' ), $wpsmushit_admin->get_user_name(), '', '', $count, '', '' ) . '

    '; } } /** * Pro features list box to show after settings. * * @return void */ public function pro_features_container() { global $wp_smush, $wpsmush_settings, $wpsmushit_admin; // Do not show if pro user. if ( $wp_smush->validate_install() || ( is_network_admin() && ! $wpsmush_settings->settings['networkwide'] ) ) { return; } // Upgrade url with analytics keys. $upgrade_url = add_query_arg( array( 'utm_source' => 'smush', 'utm_medium' => 'plugin', 'utm_campaign' => 'smush_advancedsettings_profeature_tag', ), $wpsmushit_admin->upgrade_url ); // Upgrade url for upsell. $upsell_url = add_query_arg( array( 'utm_source' => 'smush', 'utm_medium' => 'plugin', 'utm_campaign' => 'smush-advanced-settings-upsell', ), $wpsmushit_admin->upgrade_url ); ?>

    ', '' ); ?>

    ', esc_url( 'https://premium.wpmudev.org/contact' ) ); $attr_message = esc_html__( 'Validating..', 'wp-smushit' ); $recheck_link = ''; $message = sprintf( esc_html__( 'It looks like Smush couldn’t verify your WPMU DEV membership so Pro features have been disabled for now. If you think this is an error, run a %1$sre-check%2$s or get in touch with our %3$ssupport team%4$s.', 'wp-smushit' ), $recheck_link, '', $wpmu_contact, '' ); $content = sprintf( '

    %s

    ', $attr_message, $message ); return $content; } /** * Prints Resize, Smush Original, and Backup settings. * * @param string $name Name of the current setting being processed * @param string $section Section name. * * @return void */ public function full_size_options( $name = '' ) { global $wp_smush, $wpsmushit_admin, $wpsmush_settings; // Continue only if orginal image option. if ( 'original' !== $name || ! $wp_smush->validate_install() ) { return; } foreach ( $this->full_size_group as $name ) { $setting_val = $wpsmush_settings->settings[ $name ]; $setting_key = WP_SMUSH_PREFIX . $name; ?>
    settings[ $name ]['desc']; ?>
    resize_group as $name ) { // Do not continue if setting is not found. if ( ! isset( $wpsmush_settings->settings[ $name ] ) ) { continue; } $setting_val = $wpsmush_settings->settings[ $name ]; $setting_key = WP_SMUSH_PREFIX . $name; ?>
    settings[ $name ]['desc']; ?>

    ', '' ); ?>

    Note: This feature is only visible on screens wider than 800px.
    remaining_count === 0 || $wpsmushit_admin->smushed_count === 0 ) { // Initialize global stats. $wpsmushit_admin->setup_global_stats(); } // Page heading for free and pro version. $page_heading = esc_html__( 'DASHBOARD', 'wp-smushit' ); // Re-check images notice. $recheck_notice = $this->get_recheck_message(); // User API check, and display a message if not valid $user_validation = $this->get_user_validation_message(); ?>

    current_tab ) : ?> id ? ' data-type="nextgen"' : ''; ?>
    should_continue() ) { echo $wpsmush_dir->show_table_error(); } // Check for any stored API message and show it. $this->show_api_message(); $this->settings_updated(); // Show S3 integration message, if user hasn't enabled it. if ( is_object( $wpsmush_s3 ) && method_exists( $wpsmush_s3, 's3_support_required_notice' ) ) { $wpsmush_s3->s3_support_required_notice(); } } /** * Show additional descriptions for settings. * * @param string $setting_key Setting key. * * @return void */ public function settings_desc( $setting_key = '' ) { if ( empty( $setting_key ) || ! in_array( $setting_key, array( 'resize', 'original', 'strip_exif', 'png_to_jpg', 's3', ) ) ) { return; } ?> settings['networkwide'] ) { return; } // Check the last settings stored in db. $run_recheck = get_site_option( WP_SMUSH_PREFIX . 'run_recheck', false ); // If not same, Display notice if ( ! $run_recheck ) { return; } $message = '
    '; $message .= '

    ' . esc_html__( 'Smush settings were updated, performing a quick scan to check if any of the images need to be Smushed again.', 'wp-smushit' ) . '

    '; $message .= '' . esc_html__( 'Dismiss', 'wp-smushit' ) . ''; $message .= '
    '; return $message; } /** * Prints all the registererd image sizes, to be selected/unselected for smushing. * * @param string $name Setting key. * * @return void */ public function image_sizes( $name = '' ) { // Add only to auto smush settings. if ( 'auto' !== $name ) { return; } global $wpsmushit_admin, $wpsmush_settings, $wp_smush; // Additional Image sizes. $image_sizes = $wpsmush_settings->get_setting( WP_SMUSH_PREFIX . 'image_sizes', false ); $sizes = $wpsmushit_admin->image_dimensions(); /** * Add an additional item for full size. * Do not use intermediate_image_sizes filter. */ $sizes['full'] = array(); $is_pro = $wp_smush->validate_install(); $disabled = ''; $setting_status = empty( $wpsmush_settings->settings['auto'] ) ? 0 : $wpsmush_settings->settings['auto']; if ( ! empty( $sizes ) ) { ?>
    $size ) { // If image sizes array isn't set, mark all checked ( Default Values ). if ( false === $image_sizes ) { $checked = true; } else { $checked = is_array( $image_sizes ) ? in_array( $size_k, $image_sizes ) : false; } // For free users, disable full size option. if ( $size_k === 'full' ) { $disabled = $is_pro ? '' : 'disabled'; $checked = $is_pro ? $checked : false; } ?>
    get_setting( WP_SMUSH_PREFIX . 'resize_sizes', array( 'width' => '', 'height' => '', ) ); // Set default prefix is custom prefix is empty. $prefix = empty( $class_prefix ) ? WP_SMUSH_PREFIX : $class_prefix; // Get max dimensions. $max_sizes = $wpsmushit_admin->get_max_image_dimensions(); $setting_status = empty( $wpsmush_settings->settings['resize'] ) ? 0 : $wpsmush_settings->settings['resize']; // Placeholder width and Height. $p_width = $p_height = 2048; ?>
    ', $max_sizes['width'], '×', $max_sizes['height'], '' ); ?>
    http://gifgifs.com/resizer/' ); ?> smushed_count > 0 ? 'existing' : 'new'; update_site_option( 'wp-smush-install-type', $install_type ); } // Prepare notice. if ( 'new' === $install_type ) { $notice_heading = esc_html__( 'Thanks for installing Smush. We hope you like it!', 'wp-smushit' ); $notice_content = esc_html__( 'And hey, if you do, you can join WPMU DEV for a free 30 day trial and get access to even more features!', 'wp-smushit' ); $button_content = esc_html__( 'Try Smush Pro Free', 'wp-smushit' ); } else { $notice_heading = esc_html__( 'Thanks for upgrading Smush!', 'wp-smushit' ); $notice_content = esc_html__( 'Did you know she has secret super powers? Yes, she can super-smush images for double the savings, store original images, and bulk smush thousands of images in one go. Get started with a free WPMU DEV trial to access these advanced features.', 'wp-smushit' ); $button_content = esc_html__( 'Try Smush Pro Free', 'wp-smushit' ); } $upgrade_url = add_query_arg( array( 'utm_source' => 'smush', 'utm_medium' => 'plugin', 'utm_campaign' => 'smush_dashboard_upgrade_notice', ), $wpsmushit_admin->upgrade_url ); ?> validate_install() ) { return; } // Upgrade url with analytics keys. $upgrade_url = add_query_arg( array( 'utm_source' => 'smush', 'utm_medium' => 'plugin', 'utm_campaign' => 'smush_bulksmush_upsell_notice', ), $wpsmushit_admin->upgrade_url ); ?>

    ', '' ); ?>

    settings['networkwide'] && ! is_network_admin() ) { return; } // Show setttings saved message. if ( 1 == $wpsmush_settings->get_setting( 'wp-smush-settings_updated', false ) ) { // Default message. $message = esc_html__( 'Your settings have been updated!', 'wp-smushit' ); // Notice class. $message_class = ' sui-notice-success'; // Additonal message if we got work to do! $resmush_count = is_array( $wpsmushit_admin->resmush_ids ) && count( $wpsmushit_admin->resmush_ids ) > 0; $smush_count = is_array( $wpsmushit_admin->remaining_count ) && $wpsmushit_admin->remaining_count > 0; if ( $smush_count || $resmush_count ) { $message_class = ' sui-notice-warning'; // Show link to bulk smush tab from other tabs. $bulk_smush_link = 'bulk' === $this->current_tab ? '' : ''; $message .= ' ' . sprintf( esc_html__( 'You have images that need smushing. %1$sBulk smush now!%2$s', 'wp-smushit' ), $bulk_smush_link, '' ); } echo '

    ' . $message . '

    '; // Remove the option. $wpsmush_settings->delete_setting( 'wp-smush-settings_updated' ); } } /** * Set current active tab. * * @return void */ public function set_current_tab() { global $wpsmush_settings, $wpsmush_dir; /** * Filter to alter setting tabs. * * @param array Tabs. */ $this->tabs = apply_filters( 'smush_setting_tabs', array( 'bulk' => esc_html__( 'Bulk Smush', 'wp-smushit' ), 'directory' => esc_html__( 'Directory Smush', 'wp-smushit' ), 'integrations' => esc_html__( 'Integrations', 'wp-smushit' ), // 'cdn' => esc_html__( 'CDN', 'wp-smushit' ), ) ); // Check if current page network admin page. $is_network = is_network_admin(); $is_networkwide = $wpsmush_settings->settings['networkwide']; // Set the current tab. $this->current_tab = isset( $_GET['tab'] ) && in_array( $_GET['tab'], array_keys( $this->tabs ) ) ? $_GET['tab'] : 'bulk'; // If no integration found, set current tab as bulk smush. if ( ( empty( $this->intgration_group ) && 'integrations' === $this->current_tab ) || ( $is_network && ! $is_networkwide ) || ( ! $is_network && $is_networkwide && ! in_array( $this->current_tab, $this->subsite_tabs ) ) || ( 'directory' === $this->current_tab && ! $wpsmush_dir->should_continue() ) ) { // If networkwide option is enabled only show bulk and directory smush. $this->current_tab = 'bulk'; } /** * Filter to change current tab. * * @param string Current tab key. */ $this->current_tab = apply_filters( 'smush_setting_current_tab', $this->current_tab ); } /** * Display a stored API message. * * @return null */ public function show_api_message() { // Do not show message for any other users. if ( ! is_network_admin() && ! is_super_admin() ) { return null; } $api_message = get_site_option( WP_SMUSH_PREFIX . 'api_message', array() ); $api_message = current( $api_message ); // Return if the API message is not set or user dismissed it earlier if ( empty( $api_message ) || ! is_array( $api_message ) || $api_message['status'] !== 'show' ) { return null; } $message = empty( $api_message['message'] ) ? '' : $api_message['message']; $message_type = ( is_array( $api_message ) && ! empty( $api_message['type'] ) ) ? $api_message['type'] : 'info'; $type_class = 'warning' === $message_type ? 'sui-notice-warning' : 'sui-notice-info'; echo '

    ' . $message . '

    ' . esc_html__( 'Dismiss', 'wp-smushit' ) . '
    '; } } global $wpsmush_bulkui; $wpsmush_bulkui = new WpSmushBulkUi(); }