PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 4.2.13
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v4.2.13
4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 3.12.1 All 134 releases
← All changes | inc/cli/cli_setting.php +32 -14 3.1.04.2.13 View file →
@@ -31,14 +31,13 @@
31 31 $data = $request->get_user_data( $api_key );
32 32 if ( $data === false || is_wp_error( $data ) ) {
33 33 $extra = '';
34 34 if ( is_wp_error( $data ) ) {
35 - /**
36 - * Error from api.
37 - *
38 - * @var WP_Error $data Error object.
39 - */
40 - $extra = sprintf( __( '. ERROR details: %s', 'optimole-wp' ), $data->get_error_message() );
35 + $extra = sprintf(
36 + /* translators: Error details */
37 + __( '. ERROR details: %s', 'optimole-wp' ),
38 + $data->get_error_message()
39 + );
41 40 }
42 41
43 42 return \WP_CLI::error( __( 'Can not connect to Optimole service', 'optimole-wp' ) . $extra );
44 43 }
@@ -68,14 +67,12 @@
68 67 * : The setting value to update.
69 68 */
70 69 public function update( $args ) {
71 70 if ( empty( $args ) || ! isset( Optml_Settings::$whitelisted_settings[ $args[0] ] ) ) {
72 - \WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( Optml_Settings::$whitelisted_settings ) ) ) );
73 -
74 - return false;
71 + return \WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( Optml_Settings::$whitelisted_settings ) ) ) );
75 72 }
76 73
77 - if ( Optml_Settings::$whitelisted_settings[ $args[0] ] === 'bool' && ( empty( $args ) || ! isset( $args[1] ) || $args[1] === '' || ! in_array(
74 + if ( Optml_Settings::$whitelisted_settings[ $args[0] ] === 'bool' && ( ! isset( $args[1] ) || $args[1] === '' || ! in_array(
78 75 $args[1],
79 76 [
80 77 'on',
81 78 'off',
@@ -84,9 +81,9 @@
84 81 ) ) ) {
85 82 return \WP_CLI::error( 'No argument passed. Required one argument ( on/off )' );
86 83 }
87 84
88 - if ( Optml_Settings::$whitelisted_settings[ $args[0] ] === 'int' && ( empty( $args ) || ! isset( $args[1] ) || $args[1] === '' || (int) $args[1] > 100 || (int) $args[1] < 0 ) ) {
85 + if ( Optml_Settings::$whitelisted_settings[ $args[0] ] === 'int' && ( ! isset( $args[1] ) || $args[1] === '' || (int) $args[1] > 100 || (int) $args[1] < 0 ) ) {
89 86 return \WP_CLI::error( 'Invalid argument, must be between 0 and 100.' );
90 87 }
91 88
92 89 $value = ( Optml_Settings::$whitelisted_settings[ $args[0] ] === 'bool' ) ? ( $args[1] === 'on' ? 'enabled' : 'disabled' ) : (int) $args[1];
@@ -102,11 +99,9 @@
102 99 * : The setting name to check.
103 100 */
104 101 public function get( $args ) {
105 102 if ( empty( $args ) || ! isset( Optml_Settings::$whitelisted_settings[ $args[0] ] ) ) {
106 - \WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( Optml_Settings::$whitelisted_settings ) ) ) );
107 -
108 - return false;
103 + return \WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( Optml_Settings::$whitelisted_settings ) ) ) );
109 104 }
110 105
111 106 $value = ( new Optml_Settings() )->get( $args[0] );
112 107
@@ -129,5 +124,28 @@
129 124
130 125 return $settings->parse_settings( $new_setting );
131 126 }
132 127
128 + /**
129 + * Clear cache.
130 + *
131 + * [--type=<type>]
132 + * : The type of cache to clear. Default is images.
133 + */
134 + public function clear_cache( $args, $assoc_args ) {
135 + $type = 'images';
136 +
137 + // If assoc_args has a type key, use that.
138 + if ( isset( $assoc_args['type'] ) && $assoc_args['type'] === 'assets' ) {
139 + $type = $assoc_args['type'];
140 + }
141 +
142 + $settings = new Optml_Settings();
143 + $token = $settings->clear_cache( $type );
144 +
145 + if ( is_wp_error( $token ) ) {
146 + \WP_CLI::error( $token->get_error_message() );
147 + }
148 +
149 + \WP_CLI::success( sprintf( 'Cache type %s cleared', $type ) );
150 + }
133 151 }