diff --git a/cimo.php b/cimo.php index c9d5bc5..d9e0c06 100644 --- a/cimo.php +++ b/cimo.php @@ -19,6 +19,7 @@ defined( 'CIMO_FILE' ) || define( 'CIMO_FILE', __FILE__ ); defined( 'CIMO_BUILD' ) || define( 'CIMO_BUILD', 'free' ); +defined( 'CIMO_SETTINGS_SLUG' ) || define( 'CIMO_SETTINGS_SLUG', 'cimo-settings' ); require_once __DIR__ . '/src/admin/class-script-loader.php'; require_once __DIR__ . '/src/admin/class-meta-box.php'; diff --git a/src/admin/class-admin.php b/src/admin/class-admin.php index 3aa0559..fec69a5 100644 --- a/src/admin/class-admin.php +++ b/src/admin/class-admin.php @@ -19,6 +19,7 @@ public function __construct() { // Our admin page. add_action( 'admin_menu', [ $this, 'add_admin_menu' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] ); + add_filter( 'plugin_action_links_' . plugin_basename( CIMO_FILE ), [ $this, 'add_admin_action_links' ] ); } // Disable thumbnail generation @@ -32,13 +33,35 @@ public function __construct() { * Add admin menu under Settings */ public function add_admin_menu() { + $settings = get_option( 'cimo_options', [] ); + add_options_page( __( 'Cimo Settings', 'cimo-image-optimizer' ), __( 'Cimo', 'cimo-image-optimizer' ), 'manage_options', - 'cimo-settings', + CIMO_SETTINGS_SLUG, [ $this, 'admin_page_callback' ] ); + + // Remove the menu page if stealth mode is enabled. + // The menu page is still accessible via the plugin actions links. + if ( CIMO_BUILD === 'premium' && + isset( $settings['stealth_mode_enabled'] ) && + $settings['stealth_mode_enabled'] === 1 ) { + remove_submenu_page( + 'options-general.php', + CIMO_SETTINGS_SLUG, + ); + } + } + + /** + * Add a Settings link to the plugin action links. + */ + public function add_admin_action_links( $links ) { + $settings_link = '' . esc_html__( 'Settings', 'cimo-image-optimizer' ) . ''; + array_unshift( $links, $settings_link ); + return $links; } /** @@ -118,6 +141,11 @@ public function register_settings() { 'svg_optimization_enabled' => [ 'type' => 'integer', ], + + // Stealth Mode + 'stealth_mode_enabled' => [ + 'type' => 'integer', + ], ], ], ], @@ -299,6 +327,11 @@ public function sanitize_options( $options ) { $sanitized['svg_optimization_enabled'] = $options['svg_optimization_enabled'] ? 1 : 0; } + // Sanitize stealth mode + if ( isset( $options['stealth_mode_enabled'] ) ) { + $sanitized['stealth_mode_enabled'] = $options['stealth_mode_enabled'] ? 1 : 0; + } + return $sanitized; } diff --git a/src/admin/class-meta-box.php b/src/admin/class-meta-box.php index bd19e7a..4704496 100644 --- a/src/admin/class-meta-box.php +++ b/src/admin/class-meta-box.php @@ -21,6 +21,10 @@ public function __construct() { } public function add_meta_box() { + if ( ! apply_filters( 'cimo/metabox/do_render', true ) ) { + return; + } + add_meta_box( 'cimo-data-meta-box', __( 'Cimo Optimization', 'cimo-image-optimizer' ), diff --git a/src/admin/class-script-loader.php b/src/admin/class-script-loader.php index 5169344..87cf265 100644 --- a/src/admin/class-script-loader.php +++ b/src/admin/class-script-loader.php @@ -84,6 +84,7 @@ public function enqueue_cimo_assets() { [ 'restUrl' => rest_url( 'cimo/v1/' ), 'nonce' => wp_create_nonce( 'wp_rest' ), + 'isPremium' => CIMO_BUILD === 'premium', 'webpQuality' => ! empty( $settings['webp_quality'] ) ? (int) $settings['webp_quality'] : 80, 'maxImageDimension' => ! empty( $settings['max_image_dimension'] ) ? (int) $settings['max_image_dimension'] : 0, 'videoOptimizationEnabled' => isset( $settings['video_optimization_enabled'] ) ? (int) $settings['video_optimization_enabled'] : 1, @@ -93,6 +94,7 @@ public function enqueue_cimo_assets() { 'audioQuality' => ! empty( $settings['audio_quality'] ) ? (int) $settings['audio_quality'] : 128, 'svgUpload' => isset( $settings['svg_upload'] ) ? (int) $settings['svg_upload'] : 0, 'svgOptimizationEnabled' => isset( $settings['svg_optimization_enabled'] ) ? (int) $settings['svg_optimization_enabled'] : 1, + 'stealthModeEnabled' => isset( $settings['stealth_mode_enabled'] ) ? (int) $settings['stealth_mode_enabled'] : 0, ] ); diff --git a/src/admin/js/media-manager/sidebar-info.js b/src/admin/js/media-manager/sidebar-info.js index 01d0e28..1051905 100644 --- a/src/admin/js/media-manager/sidebar-info.js +++ b/src/admin/js/media-manager/sidebar-info.js @@ -2,6 +2,7 @@ import { domReady } from '~cimo/shared/dom-ready' import { getCachedMetadata } from '~cimo/shared/metadata-saver' import { escape } from '~cimo/shared/util' import { __, sprintf } from '@wordpress/i18n' +import { applyFilters } from '@wordpress/hooks' /** * Format bytes into human readable format (KB, MB, etc.) @@ -205,6 +206,10 @@ function injectCimoMetadata( { } domReady( () => { + if ( ! applyFilters( 'cimo.mediaManager.sidebarInfo.doRender', true ) ) { + return + } + // Only proceed if wp.media is available (media library is loaded) if ( typeof wp === 'undefined' || diff --git a/src/admin/js/page/admin-settings.js b/src/admin/js/page/admin-settings.js index 2005eb6..b600463 100644 --- a/src/admin/js/page/admin-settings.js +++ b/src/admin/js/page/admin-settings.js @@ -40,6 +40,9 @@ const AdminSettings = () => { // SVG Optimization settings svgUpload: 0, svgOptimizationEnabled: 1, + + // Stealth Mode settings + stealthModeEnabled: 0, } ) const [ imageSizes, setImageSizes ] = useState( [] ) const [ isSaving, setIsSaving ] = useState( false ) @@ -100,6 +103,9 @@ const AdminSettings = () => { // SVG Optimization settings svgUpload: cimoOptions.svg_upload !== undefined ? cimoOptions.svg_upload : 0, svgOptimizationEnabled: cimoOptions.svg_optimization_enabled !== undefined ? cimoOptions.svg_optimization_enabled : 1, + + // Stealth Mode settings + stealthModeEnabled: cimoOptions.stealth_mode_enabled !== undefined ? cimoOptions.stealth_mode_enabled : 0, } setSettings( fetchedSettings ) setHasUnsavedChanges( false ) @@ -217,6 +223,15 @@ const AdminSettings = () => { } ) } + const applyStealthModeDefaultSettings = () => { + setSettings( settings => { + return { + ...settings, + stealthModeEnabled: 0, + } + } ) + } + const handleDismissRating = useCallback( async () => { setIsRatingDismissed( true ) @@ -272,6 +287,9 @@ const AdminSettings = () => { // SVG Optimization settings svg_upload: settings.svgUpload, svg_optimization_enabled: settings.svgOptimizationEnabled, + + // Stealth Mode settings + stealth_mode_enabled: settings.stealthModeEnabled, }, }, } ) @@ -892,6 +910,59 @@ const AdminSettings = () => { } + + { /* Stealth Mode Settings */ } + +
+
+

+ + { __( 'Stealth Mode', 'cimo-image-optimizer' ) } +

+ { buildType === 'free' && ( + + + { __( 'Premium', 'cimo-image-optimizer' ) } + + ) } +
+ + { buildType === 'free' && ( + + ) } + { buildType === 'premium' && <> +
+ handleInputChange( 'stealthModeEnabled', checked ? 1 : 0 ) } + help={ + <> + { __( 'When Stealth Mode is enabled, all Cimo branding and optimization stats will not be shown in the UI and dashboard. This settings page will not appear in the admin sidebar, you can access it by clicking the “Settings” link under Cimo in the plugins page. Stealth Mode will not affect how your media is optimized; everything continues to work as usual, just without any visual indicators of Cimo.', 'cimo-image-optimizer' ) } +   + + { __( 'Learn more', 'cimo-image-optimizer' ) } + + + } + /> +
+ + } +
{ /* Submit Button */ } @@ -992,6 +1063,15 @@ const AdminSettings = () => {
+
  • + + { /* Stealth Icon */ } + + + + { __( 'Stealth mode', 'cimo-image-optimizer' ) } + +
  • { /* Unlimited Icon */ } @@ -1001,15 +1081,6 @@ const AdminSettings = () => { { __( 'Still without limits', 'cimo-image-optimizer' ) }
  • - { /*
  • - */ } - { /* White label Icon */ } - { /* - - - { __( 'White label', 'cimo-image-optimizer' ) } - -
  • */ }