Skip to content
1 change: 1 addition & 0 deletions cimo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
35 changes: 34 additions & 1 deletion src/admin/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = '<a href="' . esc_url( admin_url( 'options-general.php?page=' . CIMO_SETTINGS_SLUG ) ) . '">' . esc_html__( 'Settings', 'cimo-image-optimizer' ) . '</a>';
array_unshift( $links, $settings_link );
return $links;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

/**
Expand Down Expand Up @@ -118,6 +141,11 @@ public function register_settings() {
'svg_optimization_enabled' => [
'type' => 'integer',
],

// Stealth Mode
'stealth_mode_enabled' => [
'type' => 'integer',
],
],
],
],
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions src/admin/class-meta-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
2 changes: 2 additions & 0 deletions src/admin/class-script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
]
);

Expand Down
5 changes: 5 additions & 0 deletions src/admin/js/media-manager/sidebar-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down Expand Up @@ -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' ||
Expand Down
89 changes: 80 additions & 9 deletions src/admin/js/page/admin-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -217,6 +223,15 @@ const AdminSettings = () => {
} )
}

const applyStealthModeDefaultSettings = () => {
setSettings( settings => {
return {
...settings,
stealthModeEnabled: 0,
}
} )
}

const handleDismissRating = useCallback( async () => {
setIsRatingDismissed( true )

Expand Down Expand Up @@ -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,
},
},
} )
Expand Down Expand Up @@ -892,6 +910,59 @@ const AdminSettings = () => {
</Button>
</> }
</div>

{ /* Stealth Mode Settings */ }

<div className="cimo-settings-section" style={ { gridColumn: '1 / 2' } }>
<div className="cimo-settings-header">
<h2>
<span aria-hidden="true">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-hat-glasses-icon lucide-hat-glasses"><path d="M14 18a2 2 0 0 0-4 0" /><path d="m19 11-2.11-6.657a2 2 0 0 0-2.752-1.148l-1.276.61A2 2 0 0 1 12 4H8.5a2 2 0 0 0-1.925 1.456L5 11" /><path d="M2 11h20" /><circle cx="17" cy="18" r="3" /><circle cx="7" cy="18" r="3" /></svg>
</span>
{ __( 'Stealth Mode', 'cimo-image-optimizer' ) }
</h2>
{ buildType === 'free' && (
<span
className="cimo-premium-feature-label"
>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-lock-icon lucide-lock"><rect width="18" height="11" x="3" y="11" rx="2" ry="2" /><path d="M7 11V7a5 5 0 0 1 10 0v4" /></svg>
{ __( 'Premium', 'cimo-image-optimizer' ) }
</span>
) }
</div>

{ buildType === 'free' && (
<PremiumPlaceholder
label={ __( 'Upgrade to Premium to enter stealth mode.', 'cimo-image-optimizer' ) }
/>
) }
{ buildType === 'premium' && <>
<div className="cimo-setting-field">
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Stealth Mode', 'cimo-image-optimizer' ) }
checked={ settings.stealthModeEnabled === 1 }
onChange={ checked => 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' ) }
&nbsp;
<a href="https://docs.wpcimo.com/article/782-stealth-mode" target="_blank" rel="noopener noreferrer">
{ __( 'Learn more', 'cimo-image-optimizer' ) }
</a>
</>
}
/>
</div>
<Button
variant="tertiary"
className="cimo-reset-button"
onClick={ applyStealthModeDefaultSettings }
>
{ __( 'Reset to Default', 'cimo-image-optimizer' ) }
</Button>
</> }
</div>
</div>

{ /* Submit Button */ }
Expand Down Expand Up @@ -992,6 +1063,15 @@ const AdminSettings = () => {
</span>
</li>
<hr />
<li>
<span className="cimo-premium-icon">
{ /* Stealth Icon */ }
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-hat-glasses-icon lucide-hat-glasses"><path d="M14 18a2 2 0 0 0-4 0" /><path d="m19 11-2.11-6.657a2 2 0 0 0-2.752-1.148l-1.276.61A2 2 0 0 1 12 4H8.5a2 2 0 0 0-1.925 1.456L5 11" /><path d="M2 11h20" /><circle cx="17" cy="18" r="3" /><circle cx="7" cy="18" r="3" /></svg>
</span>
<span>
{ __( 'Stealth mode', 'cimo-image-optimizer' ) }
</span>
</li>
<li>
<span className="cimo-premium-icon">
{ /* Unlimited Icon */ }
Expand All @@ -1001,15 +1081,6 @@ const AdminSettings = () => {
{ __( 'Still without limits', 'cimo-image-optimizer' ) }
</span>
</li>
{ /* <li>
<span className="cimo-premium-icon"> */ }
{ /* White label Icon */ }
{ /* <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-tag-icon lucide-tag"><path d="M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z" /><circle cx="7.5" cy="7.5" r=".5" fill="currentColor" /></svg>
</span>
<span>
{ __( 'White label', 'cimo-image-optimizer' ) }
</span>
</li> */ }
</ul>

<div className="cimo-premium-cta">
Expand Down
Loading