slug = $slug; $this->settings = Settings::get_instance(); if ( ! $parent ) { $this->page_id = add_menu_page( $title, $title, 'manage_options', $this->slug, $parent ? array( $this, 'render' ) : null, $this->get_menu_icon() ); } else { $this->page_id = add_submenu_page( $parent, $title, $title, $nextgen ? 'NextGEN Manage gallery' : 'manage_options', $this->slug, array( $this, 'render' ) ); } // No need to load these action on parent pages, as they are just placeholders for sub pages. if ( $parent ) { add_filter( 'load-' . $this->page_id, array( $this, 'on_load' ) ); add_action( 'load-' . $this->page_id, array( $this, 'register_meta_boxes' ) ); add_filter( 'load-' . $this->page_id, array( $this, 'add_action_hooks' ) ); } } /** * Common hooks for all screens * * @since 2.9.0 */ public function add_action_hooks() { // Notices. add_action( 'admin_notices', array( $this, 'smush_upgrade_notice' ) ); add_action( 'admin_notices', array( $this, 'smush_deactivated' ) ); add_action( 'network_admin_notices', array( $this, 'smush_deactivated' ) ); add_action( 'admin_notices', array( $this, 'smush_dash_required' ) ); add_action( 'network_admin_notices', array( $this, 'smush_dash_required' ) ); add_filter( 'admin_body_class', array( $this, 'smush_body_classes' ) ); // Filter built-in wpmudev branding script. add_filter( 'wpmudev_whitelabel_plugin_pages', array( $this, 'builtin_wpmudev_branding' ) ); } /** * Return the admin menu slug * * @return string */ public function get_slug() { return $this->slug; } /** * Load an admin view. * * @param string $name View name = file name. * @param array $args Arguments. * @param string $dir Directory for the views. Default: views. */ public function view( $name, $args = array(), $dir = 'views' ) { $file = WP_SMUSH_DIR . "app/{$dir}/{$name}.php"; $content = ''; if ( is_file( $file ) ) { ob_start(); if ( isset( $args['id'] ) ) { $args['orig_id'] = $args['id']; $args['id'] = str_replace( '/', '-', $args['id'] ); } extract( $args ); /* @noinspection PhpIncludeInspection */ include $file; $content = ob_get_clean(); } echo $content; } /** * Shows Notice for free users, displays a discount coupon */ public function smush_upgrade_notice() { // Return, If a pro user, or not super admin, or don't have the admin privileges. if ( WP_Smush::is_pro() || ! current_user_can( 'edit_others_posts' ) || ! is_super_admin() ) { return; } // Return if notice is already dismissed. if ( get_site_option( WP_SMUSH_PREFIX . 'hide_upgrade_notice' ) ) { return; } $core = WP_Smush::get_instance()->core(); $install_type = get_site_option( 'wp-smush-install-type', false ); if ( ! $install_type ) { $install_type = $core->smushed_count > 0 ? 'existing' : 'new'; update_site_option( 'wp-smush-install-type', $install_type ); } // Prepare notice. if ( 'new' === $install_type ) { $notice_heading = __( 'Thanks for installing Smush. We hope you like it!', 'wp-smushit' ); $notice_content = __( '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 = __( 'Try Smush Pro Free', 'wp-smushit' ); } else { $notice_heading = __( 'Thanks for updating Smush!', 'wp-smushit' ); $notice_content = __( 'Did you know she has secret super powers? Yes, she can super-smush images for double the savings, store original images, bulk smush thousands of images in one go, and serve \'em up in a next-gen format(WebP) with one-click via her blazing-fast CDN. Get started with a free WPMU DEV trial to access these advanced features.', 'wp-smushit' ); $button_content = __( 'Try Smush Pro Free', 'wp-smushit' ); } $upgrade_url = add_query_arg( array( 'utm_source' => 'smush', 'utm_medium' => 'plugin', 'utm_campaign' => 'smush_dashboard_upgrade_notice', ), $this->upgrade_url ); ?>

has_key() ) ) { return; } // Do not show on free versions of the plugin. if ( false !== strpos( WP_SMUSH_DIR, 'wp-smushit' ) ) { return; } $function = is_multisite() ? 'network_admin_url' : 'admin_url'; $url = wp_nonce_url( $function( 'update.php?action=install-plugin&plugin=install_wpmudev_dash' ), 'install-plugin_install_wpmudev_dash' ); ?>
has_key() ) : ?>
id, Admin::$plugin_pages, true ) ) { return $classes; } // Remove old wpmud class from body of smush page to avoid style conflict. $classes = str_replace( 'wpmud ', '', $classes ); $classes .= ' ' . WP_SHARED_UI_VERSION; return $classes; } /** * Allows to register meta boxes for the page. * * @since 2.9.0 */ public function register_meta_boxes() {} /** * Add meta box. * * @param string $id Meta box ID. * @param string $title Meta box title. * @param string $callback Callback for meta box content. * @param string $callback_header Callback for meta box header. * @param string $callback_footer Callback for meta box footer. * @param string $context Meta box context. * @param array $args Arguments. */ public function add_meta_box( $id, $title, $callback = '', $callback_header = '', $callback_footer = '', $context = 'main', $args = array() ) { $default_args = array( 'box_class' => 'sui-box', 'box_header_class' => 'sui-box-header', 'box_content_class' => 'sui-box-body', 'box_footer_class' => 'sui-box-footer', ); $args = wp_parse_args( $args, $default_args ); if ( ! isset( $this->meta_boxes[ $this->slug ] ) ) { $this->meta_boxes[ $this->slug ] = array(); } if ( ! isset( $this->meta_boxes[ $this->slug ][ $context ] ) ) { $this->meta_boxes[ $this->slug ][ $context ] = array(); } if ( ! isset( $this->meta_boxes[ $this->slug ][ $context ] ) ) { $this->meta_boxes[ $this->slug ][ $context ] = array(); } $meta_box = array( 'id' => $id, 'title' => $title, 'callback' => $callback, 'callback_header' => $callback_header, 'callback_footer' => $callback_footer, 'args' => $args, ); if ( $meta_box ) { $this->meta_boxes[ $this->slug ][ $context ][ $id ] = $meta_box; } } /** * Render the page */ public function render() { // Shared UI wrapper with accessible color option. $classes = $this->settings->get( 'accessible_colors' ) ? 'sui-wrap sui-color-accessible' : 'sui-wrap'; echo '
'; // Load page header. $this->render_page_header(); $this->add_update_dialog(); $hide_quick_setup = false !== get_option( 'skip-smush-setup' ); // Show configure screen for only a new installation and for only network admins. if ( ( ! is_multisite() && ! $hide_quick_setup ) || ( is_multisite() && ! is_network_admin() && ! $this->settings->is_network_enabled() && ! $hide_quick_setup ) ) { $this->view( 'onboarding', array(), 'modals' ); $this->view( 'checking-files', array(), 'modals' ); } $this->render_inner_content(); // Nonce field. wp_nonce_field( 'save_wp_smush_options', 'wp_smush_options_nonce', '' ); // Close shared ui wrapper. echo '
'; } /** * Show an update dialog. * * @since 3.3.2 */ private function add_update_dialog() { $show_modal = get_site_transient( 'wp-smush-update-modal' ); if ( ! $show_modal ) { return; } delete_site_transient( 'wp-smush-update-modal' ); $this->view( 'resizing-update', array(), 'modals' ); ?> get_tabs(); if ( isset( $_GET['view'] ) && array_key_exists( wp_unslash( $_GET['view'] ), $tabs ) ) { // Input var ok. return wp_unslash( $_GET['view'] ); // Input var ok. } if ( empty( $tabs ) ) { return false; } reset( $tabs ); return key( $tabs ); } /** * Display tabs navigation */ public function show_tabs() { $this->view( 'tabs', array( 'tabs' => $this->get_tabs(), ) ); } /** * Get a tab URL * * @param string $tab Tab ID. * * @return string */ public function get_tab_url( $tab ) { $tabs = $this->get_tabs(); if ( ! isset( $tabs[ $tab ] ) ) { return ''; } if ( is_multisite() && is_network_admin() ) { return network_admin_url( 'admin.php?page=' . $this->slug . '&view=' . $tab ); } else { return admin_url( 'admin.php?page=' . $this->slug . '&view=' . $tab ); } } /** * Get the list of tabs for this screen * * @return array */ protected function get_tabs() { return apply_filters( 'wp_smush_admin_page_tabs_' . $this->slug, $this->tabs ); } /** * Render inner content. */ protected function render_inner_content() { $this->view( $this->slug . '-page' ); } /** * Render meta box. * * @param string $context Meta box context. Default: main. */ protected function do_meta_boxes( $context = 'main' ) { if ( empty( $this->meta_boxes[ $this->slug ][ $context ] ) ) { return; } do_action_ref_array( 'wp_smush_admin_do_meta_boxes_' . $this->slug, array( &$this ) ); foreach ( $this->meta_boxes[ $this->slug ][ $context ] as $id => $box ) { $args = array( 'title' => $box['title'], 'id' => $id, 'callback' => $box['callback'], 'callback_header' => $box['callback_header'], 'callback_footer' => $box['callback_footer'], 'args' => $box['args'], ); $this->view( 'meta-box', $args ); } } /** * Check if view exists. * * @param string $name View name = file name. * * @return bool */ protected function view_exists( $name ) { $file = WP_SMUSH_DIR . "app/views/{$name}.php"; return is_file( $file ); } /** * Smush icon svg image * * @return string */ private function get_menu_icon() { ob_start(); ?>

get_current_tab() || 'gallery_page_wp-smush-nextgen-bulk' === $this->page_id ) ) : ?> id ? 'nextgen' : 'media'; ?> hide_wpmudev_doc_link() ) : ?>
admin()->get_user_validation_message(); // Re-check images notice. $this->get_recheck_message(); // Check and show missing directory smush table error only on main site. if ( Dir::should_continue() ) { $this->show_table_error(); } // Check for any stored API message and show it. $this->show_api_message(); $this->settings_updated(); do_action( 'wp_smush_header_notices' ); } /** * Get re-check notice after settings update. */ private function get_recheck_message() { // Return if not multisite, or on network settings page, Netowrkwide settings is disabled. if ( ! is_multisite() || is_network_admin() || ! Settings::can_access( 'bulk' ) ) { return; } // Check the last settings stored in db. $run_recheck = $this->settings->get_setting( WP_SMUSH_PREFIX . 'run_recheck', false ); // If not same, display notice. if ( ! $run_recheck ) { return; } ?>

id && 'toplevel_page_smush-network' !== $current_screen->id ) { return $notice; } if ( ! Dir::table_exist() ) { // Display a notice. ?>

settings->get_setting( WP_SMUSH_PREFIX . 'settings_updated' ) ) { return; } $core = WP_Smush::get_instance()->core(); // Default message. $message = esc_html__( 'Your settings have been updated!', 'wp-smushit' ); // Notice class. $message_class = ' sui-notice-success'; if ( 'cdn' === $this->get_current_tab() ) { $cdn = $this->settings->get_setting( WP_SMUSH_PREFIX . 'cdn_status' ); if ( isset( $cdn->cdn_enabling ) && $cdn->cdn_enabling ) { $message = esc_html__( 'Your settings have been saved and changes are now propagating to the CDN. Changes can take up to 30 minutes to take effect but your images will continue to be served in the mean time, please be patient.', 'wp-smushit' ); } } // Additional message if we got work to do! $resmush_count = is_array( $core->resmush_ids ) && count( $core->resmush_ids ) > 0; $smush_count = is_array( $core->remaining_count ) && $core->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->get_current_tab() ? '' : ''; $message .= ' ' . sprintf( esc_html__( 'You have images that need smushing. %1$sBulk smush now!%2$s', 'wp-smushit' ), $bulk_smush_link, '' ); } ?>

settings->delete_setting( WP_SMUSH_PREFIX . 'settings_updated' ); } /** * Add more pages to builtin wpmudev branding. * * @since 3.0 * * @param array $plugin_pages Nextgen pages is not introduced in built in wpmudev branding. * * @return array */ public function builtin_wpmudev_branding( $plugin_pages ) { $plugin_pages['gallery_page_wp-smush-nextgen-bulk'] = array( 'wpmudev_whitelabel_sui_plugins_branding', 'wpmudev_whitelabel_sui_plugins_footer', 'wpmudev_whitelabel_sui_plugins_doc_links', ); return $plugin_pages; } /** * Flag to hide wpmudev branding image. * * @since 3.0 * * @return bool */ public function hide_wpmudev_branding() { return apply_filters( 'wpmudev_branding_hide_branding', false ); } /** * Flag to hide wpmudev doc link. * * @since 3.0 * * @return bool */ public function hide_wpmudev_doc_link() { return apply_filters( 'wpmudev_branding_hide_doc_link', false ); } /** * Check if the page should be rendered. * * @since 3.2.2 * * @return bool */ public function should_render() { // Render all pages on single site installs. if ( ! is_multisite() ) { return true; } $access = get_site_option( WP_SMUSH_PREFIX . 'networkwide' ); if ( ! $access ) { return is_network_admin() ? true : false; } if ( '1' === $access ) { return is_network_admin() ? false : true; } if ( is_array( $access ) ) { if ( is_network_admin() && ! in_array( $this->get_current_tab(), $access, true ) ) { return true; } if ( ! is_network_admin() && in_array( $this->get_current_tab(), $access, true ) ) { return true; } } return false; } }