PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | class/class-mainwp-wp-cli-handle.php +1734 -1709 5.0.3.2 → 6.2.1 View file →
@@ -9,11 +9,16 @@
9 9 */
10 10
11 11 namespace MainWP\Dashboard;
12 12
13 +// Exit if accessed directly.
14 +if ( ! defined( 'ABSPATH' ) ) {
15 + exit;
16 +}
17 +
13 18 // Exit if access directly.
14 19 if ( ! defined( 'WP_CLI' ) ) {
15 - return;
20 + return; // NOSONAR - skip CLI.
16 21 }
17 22
18 23 /**
19 24 * Class MainWP_WP_CLI_Handle
@@ -21,1929 +26,1949 @@
21 26 * Manage all child sites added to the MainWP Dashboard via WP CLI.
22 27 *
23 28 * @package MainWP\Dashboard
24 29 */
25 -class MainWP_WP_CLI_Handle extends \WP_CLI_Command {
30 +class MainWP_WP_CLI_Handle extends \WP_CLI_Command { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
26 31
27 - // phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity.
32 + // phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity.
28 33
29 - /**
30 - * Singleton.
31 - *
32 - * @var null $instance
33 - */
34 - private static $instance = null;
34 + /**
35 + * Singleton.
36 + *
37 + * @var null $instance
38 + */
39 + private static $instance = null;
35 40
36 - /**
37 - * MainWP WP CLI Handle Instance.
38 - *
39 - * @return self $instance
40 - */
41 - public static function instance() {
42 - if ( null === self::$instance ) {
43 - self::$instance = new self();
44 - }
45 - return self::$instance;
46 - }
41 + /**
42 + * MainWP WP CLI Handle Instance.
43 + *
44 + * @return self $instance
45 + */
46 + public static function instance() {
47 + if ( null === static::$instance ) {
48 + static::$instance = new self();
49 + }
50 + return static::$instance;
51 + }
47 52
48 - /**
49 - * Return available MainWP WP CLI Commands.
50 - *
51 - * @param string $comm MainWP WP CLI Command.
52 - *
53 - * @return array $cli_commands CLI Commands.
54 - */
55 - public static function get_assoc_handle_commands( $comm ) {
56 - $cli_commands = array(
57 - 'sites' => array(
58 - 'all-sites',
59 - 'all-sites-count',
60 - 'connected-sites',
61 - 'connected-sites-count',
62 - 'disconnected-sites',
63 - 'disconnected-sites-count',
64 - 'sync-sites',
65 - 'check-sites',
66 - 'disconnect-sites',
67 - ),
68 - 'site' => array(
69 - 'site',
70 - 'site-info',
71 - 'site-installed-plugins',
72 - 'site-installed-plugins-count',
73 - 'site-active-plugins',
74 - 'site-active-plugins-count',
75 - 'site-inactive-plugins',
76 - 'site-inactive-plugins-count',
77 - 'site-installed-themes',
78 - 'site-installed-themes-count',
79 - 'site-active-themes',
80 - 'site-inactive-themes',
81 - 'site-inactive-themes-count',
82 - 'site-available-updates',
83 - 'site-available-updates-count',
84 - 'site-abandoned-plugins',
85 - 'site-abandoned-plugins-count',
86 - 'site-abandoned-themes',
87 - 'site-abandoned-themes-count',
88 - 'site-http-status',
89 - 'site-health-score',
90 - 'site-security-issues',
91 - 'add-site',
92 - 'edit-site',
93 - 'sync-site',
94 - 'reconnect-site',
95 - 'disconnect-site',
96 - 'remove-site',
97 - 'site-update-wordpress',
98 - 'site-update-plugins',
99 - 'site-update-themes',
100 - 'site-update-translations',
101 - 'site-update-item',
102 - 'site-manage-plugin',
103 - 'site-manage-theme',
104 - 'check-site-http-status',
105 - ),
106 - 'updates' => array(
107 - 'available-updates',
108 - 'ignored-plugins-updates',
109 - 'site-ignored-plugins-updates',
110 - 'ignored-themes-updates',
111 - 'site-ignored-themes-updates',
112 - 'ignore-updates',
113 - 'ignore-update',
114 - 'unignore-updates',
115 - 'unignore-update',
116 - ),
117 - );
118 - return isset( $cli_commands[ $comm ] ) ? $cli_commands[ $comm ] : array();
119 - }
53 + /**
54 + * Return available MainWP WP CLI Commands.
55 + *
56 + * @param string $comm MainWP WP CLI Command.
57 + *
58 + * @return array $cli_commands CLI Commands.
59 + */
60 + public static function get_assoc_handle_commands( $comm ) {
61 + $cli_commands = array(
62 + 'sites' => array(
63 + 'all-sites',
64 + 'all-sites-count',
65 + 'connected-sites',
66 + 'connected-sites-count',
67 + 'disconnected-sites',
68 + 'disconnected-sites-count',
69 + 'sync-sites',
70 + 'check-sites',
71 + 'disconnect-sites',
72 + ),
73 + 'site' => array(
74 + 'site',
75 + 'site-info',
76 + 'site-installed-plugins',
77 + 'site-installed-plugins-count',
78 + 'site-active-plugins',
79 + 'site-active-plugins-count',
80 + 'site-inactive-plugins',
81 + 'site-inactive-plugins-count',
82 + 'site-installed-themes',
83 + 'site-installed-themes-count',
84 + 'site-active-themes',
85 + 'site-inactive-themes',
86 + 'site-inactive-themes-count',
87 + 'site-available-updates',
88 + 'site-available-updates-count',
89 + 'site-abandoned-plugins',
90 + 'site-abandoned-plugins-count',
91 + 'site-abandoned-themes',
92 + 'site-abandoned-themes-count',
93 + 'site-http-status',
94 + 'site-health-score',
95 + 'site-security-issues',
96 + 'add-site',
97 + 'edit-site',
98 + 'sync-site',
99 + 'reconnect-site',
100 + 'disconnect-site',
101 + 'remove-site',
102 + 'site-update-wordpress',
103 + 'site-update-plugins',
104 + 'site-update-themes',
105 + 'site-update-translations',
106 + 'site-update-item',
107 + 'site-manage-plugin',
108 + 'site-manage-theme',
109 + 'check-site-http-status',
110 + ),
111 + 'updates' => array(
112 + 'available-updates',
113 + 'ignored-plugins-updates',
114 + 'site-ignored-plugins-updates',
115 + 'ignored-themes-updates',
116 + 'site-ignored-themes-updates',
117 + 'ignore-updates',
118 + 'ignore-update',
119 + 'unignore-updates',
120 + 'unignore-update',
121 + ),
122 + );
123 + return isset( $cli_commands[ $comm ] ) ? $cli_commands[ $comm ] : array();
124 + }
120 125
121 - /**
122 - * Gets associated agruments for the command.
123 - *
124 - * @param string $cli_com MainWP WP CLI command.
125 - * @param array $assoc_args Associated arguments for the command.
126 - *
127 - * @return string $callback Callback method.
128 - */
129 - public static function get_assoc_args_commands( $cli_com, $assoc_args ) {
130 - $commands = self::get_assoc_handle_commands( $cli_com );
131 - if ( empty( $commands ) ) {
132 - return false;
133 - }
134 - foreach ( $commands as $comm ) {
135 - if ( isset( $assoc_args[ $comm ] ) ) {
136 - $callback = str_replace( '-', '_', $comm );
137 - return $callback;
138 - }
139 - }
140 - return false;
141 - }
126 + /**
127 + * Gets associated agruments for the command.
128 + *
129 + * @param string $cli_com MainWP WP CLI command.
130 + * @param array $assoc_args Associated arguments for the command.
131 + *
132 + * @return string $callback Callback method.
133 + */
134 + public static function get_assoc_args_commands( $cli_com, $assoc_args ) {
135 + $commands = static::get_assoc_handle_commands( $cli_com );
136 + if ( empty( $commands ) ) {
137 + return false;
138 + }
139 + foreach ( $commands as $comm ) {
140 + if ( isset( $assoc_args[ $comm ] ) ) {
141 + return str_replace( '-', '_', $comm );
142 + }
143 + }
144 + return false;
145 + }
142 146
143 - /**
144 - * Calls correct Callback.
145 - *
146 - * @param string $cli_com CLI Command.
147 - * @param array $args Arguments.
148 - * @param array $assoc_args Correct callback.
149 - *
150 - * @return bool True on success, false or error.
151 - */
152 - public static function handle_cli_callback( $cli_com, $args, $assoc_args ) {
153 - $callback = self::get_assoc_args_commands( $cli_com, $assoc_args );
154 - if ( ! empty( $callback ) ) {
155 - if ( method_exists( self::class, 'callback_' . $cli_com . '_' . $callback ) ) {
156 - $website = false;
147 + /**
148 + * Calls correct Callback.
149 + *
150 + * @param string $cli_com CLI Command.
151 + * @param array $args Arguments.
152 + * @param array $assoc_args Correct callback.
153 + *
154 + * @return bool True on success, false or error.
155 + */
156 + public static function handle_cli_callback( $cli_com, $args, $assoc_args ) { // phpcs:ignore -- NOSONAR - complex.
157 + $callback = static::get_assoc_args_commands( $cli_com, $assoc_args );
158 + if ( ! empty( $callback ) && method_exists( static::class, 'callback_' . $cli_com . '_' . $callback ) ) {
159 + $website = false;
157 160
158 - $requires_site_id = false;
159 - $site_id = 0;
161 + $requires_site_id = false;
162 + $site_id = 0;
160 163
161 - if ( 'site' === $cli_com && ! isset( $assoc_args['add-site'] ) ) {
162 - $requires_site_id = true;
163 - } elseif ( 'updates' === $cli_com && ( isset( $assoc_args['site-ignored-plugins-updates'] ) || isset( $assoc_args['site-ignored-themes-updates'] ) || isset( $assoc_args['ignore-update'] ) || isset( $assoc_args['unignore_update'] ) ) ) {
164 - $requires_site_id = true;
165 - } elseif ( 'updates' === $cli_com && ( isset( $assoc_args['ignored-plugins-updates'] ) || isset( $assoc_args['ignored-themes-updates'] ) ) ) {
166 - $site_id = isset( $args[0] ) ? intval( $args[0] ) : false;
167 - }
164 + if ( 'site' === $cli_com && ! isset( $assoc_args['add-site'] ) ) {
165 + $requires_site_id = true;
166 + } elseif ( 'updates' === $cli_com && ( isset( $assoc_args['site-ignored-plugins-updates'] ) || isset( $assoc_args['site-ignored-themes-updates'] ) || isset( $assoc_args['ignore-update'] ) || isset( $assoc_args['unignore_update'] ) ) ) {
167 + $requires_site_id = true;
168 + } elseif ( 'updates' === $cli_com && ( isset( $assoc_args['ignored-plugins-updates'] ) || isset( $assoc_args['ignored-themes-updates'] ) ) ) {
169 + $site_id = isset( $args[0] ) ? intval( $args[0] ) : false;
170 + }
168 171
169 - if ( $requires_site_id ) {
170 - $site_id = self::get_cli_params( $args, $assoc_args, 'site_id' );
171 - if ( empty( $site_id ) ) {
172 - \WP_CLI::error( 'Empty site id.' );
173 - return false;
174 - }
175 - $website = MainWP_DB::instance()->get_website_by_id( $site_id );
176 - if ( empty( $website ) ) {
177 - \WP_CLI::error( 'Site not found.' );
178 - return false;
179 - }
180 - } elseif ( $site_id ) {
181 - $website = MainWP_DB::instance()->get_website_by_id( $site_id );
182 - if ( empty( $website ) ) {
183 - \WP_CLI::error( 'Site not found.' );
184 - return false;
185 - }
186 - }
187 - call_user_func_array( array( self::class, 'callback_' . $cli_com . '_' . $callback ), array( $args, $assoc_args, $website ) );
188 - return true;
189 - }
190 - }
191 - return false;
192 - }
172 + if ( $requires_site_id ) {
173 + $site_id = static::get_cli_params( $args, $assoc_args, 'site_id' );
174 + if ( empty( $site_id ) ) {
175 + \WP_CLI::error( 'Empty site id.' );
176 + return false;
177 + }
178 + $website = MainWP_DB::instance()->get_website_by_id( $site_id );
179 + if ( empty( $website ) ) {
180 + \WP_CLI::error( 'Site not found.' );
181 + return false;
182 + }
183 + } elseif ( $site_id ) {
184 + $website = MainWP_DB::instance()->get_website_by_id( $site_id );
185 + if ( empty( $website ) ) {
186 + \WP_CLI::error( 'Site not found.' );
187 + return false;
188 + }
189 + }
190 + call_user_func_array( array( static::class, 'callback_' . $cli_com . '_' . $callback ), array( $args, $assoc_args, $website ) );
191 + return true;
192 + }
193 + return false;
194 + }
193 195
194 196
195 - /**
196 - * Gets parameters.
197 - *
198 - * @param array $args Arguments.
199 - * @param array $assoc_args Arguments.
200 - * @param string $what Targetted action.
201 - *
202 - * @return array Required data.
203 - */
204 - public static function get_cli_params( $args, $assoc_args, $what ) {
205 - if ( is_string( $what ) ) {
206 - if ( 'sites' === $what ) {
207 - $sites = array();
208 - if ( 0 < count( $args ) ) {
209 - $args_exploded = explode( ',', $args[0] );
210 - foreach ( $args_exploded as $arg ) {
211 - if ( ! is_numeric( trim( $arg ) ) ) {
212 - \WP_CLI::error( 'Child site ids should be numeric.' );
213 - }
214 - $sites[] = trim( $arg );
215 - }
216 - }
217 - return $sites;
218 - } elseif ( 'site_id' === $what ) {
219 - $site_id = $args[0];
220 - if ( ! is_numeric( trim( $site_id ) ) ) {
221 - \WP_CLI::error( 'Child site id should be numeric.' );
222 - }
223 - return $site_id;
224 - } elseif ( 'add-site' === $what ) {
225 - $allow_fields = array(
226 - 'site-url',
227 - 'name',
228 - 'admin',
229 - 'uniqueid',
230 - 'ssl_verify',
231 - 'force_use_ipv4',
232 - 'ssl_version',
233 - 'http_user',
234 - 'http_pass',
235 - 'groupids',
236 - );
197 + /**
198 + * Gets parameters.
199 + *
200 + * @param array $args Arguments.
201 + * @param array $assoc_args Arguments.
202 + * @param string $what Targetted action.
203 + *
204 + * @return array Required data.
205 + */
206 + public static function get_cli_params( $args, $assoc_args, $what ) { // phpcs:ignore -- NOSONAR - complex.
207 + if ( is_string( $what ) ) {
208 + if ( 'sites' === $what ) {
209 + $sites = array();
210 + if ( ! empty( $args ) ) {
211 + $args_exploded = explode( ',', $args[0] );
212 + foreach ( $args_exploded as $arg ) {
213 + if ( ! is_numeric( trim( $arg ) ) ) {
214 + \WP_CLI::error( 'Child site ids should be numeric.' );
215 + }
216 + $sites[] = trim( $arg );
217 + }
218 + }
219 + return $sites;
220 + } elseif ( 'site_id' === $what ) {
221 + $site_id = $args[0];
222 + if ( ! is_numeric( trim( $site_id ) ) ) {
223 + \WP_CLI::error( 'Child site id should be numeric.' );
224 + }
225 + return $site_id;
226 + } elseif ( 'add-site' === $what ) {
227 + $allow_fields = array(
228 + 'site-url',
229 + 'name',
230 + 'admin',
231 + 'uniqueid',
232 + 'ssl_verify',
233 + 'force_use_ipv4',
234 + 'ssl_version',
235 + 'http_user',
236 + 'http_pass',
237 + 'groupids',
238 + );
237 239
238 - $required_fields = array(
239 - 'site-url',
240 - 'name',
241 - 'admin',
242 - );
240 + $required_fields = array(
241 + 'site-url',
242 + 'name',
243 + 'admin',
244 + );
243 245
244 - $data = self::map_assoc_args( $assoc_args, $allow_fields, $required_fields );
245 - if ( isset( $data['site-url'] ) ) {
246 - $data['url'] = $data['site-url'];
247 - unset( $data['site-url'] );
248 - }
249 - return $data;
250 - } elseif ( 'edit-site' === $what ) {
251 - $allow_fields = array(
252 - 'http_user',
253 - 'http_pass',
254 - 'name',
255 - 'admin',
256 - 'sslversion',
257 - 'uniqueid',
258 - );
259 - $required_fields = array(); // required_fields.
260 - return self::map_assoc_args( $assoc_args, $allow_fields, $required_fields );
261 - }
262 - } elseif ( is_array( $what ) && ! empty( $what ) ) {
263 - $map_fields = $what;
264 - return self::map_assoc_args( $assoc_args, $map_fields );
265 - }
246 + $data = static::map_assoc_args( $assoc_args, $allow_fields, $required_fields );
247 + if ( isset( $data['site-url'] ) ) {
248 + $data['url'] = $data['site-url'];
249 + unset( $data['site-url'] );
250 + }
251 + return $data;
252 + } elseif ( 'edit-site' === $what ) {
253 + $allow_fields = array(
254 + 'http_user',
255 + 'http_pass',
256 + 'name',
257 + 'admin',
258 + 'sslversion',
259 + 'uniqueid',
260 + );
261 + $required_fields = array(); // required_fields.
262 + return static::map_assoc_args( $assoc_args, $allow_fields, $required_fields );
263 + }
264 + } elseif ( is_array( $what ) && ! empty( $what ) ) {
265 + $map_fields = $what;
266 + return static::map_assoc_args( $assoc_args, $map_fields );
267 + }
266 268
267 - return false;
268 - }
269 + return false;
270 + }
269 271
270 - /**
271 - * Maps arguments.
272 - *
273 - * @param array $assoc_args Arguments.
274 - * @param array $fields Fields.
275 - * @param array|string $required_fields Fields that are required, default 'all': all fields are required.
276 - *
277 - * @return array $data Required data.
278 - */
279 - public static function map_assoc_args( $assoc_args, $fields, $required_fields = 'all' ) {
280 - $data = array();
281 - foreach ( $fields as $field ) {
282 - if ( isset( $assoc_args[ $field ] ) ) {
283 - $data[ $field ] = $assoc_args[ $field ];
284 - } elseif ( 'all' === $required_fields ) {
285 - \WP_CLI::error( 'Missing field: ' . $field );
286 - } elseif ( is_array( $required_fields ) && ! empty( $required_fields ) && in_array( $field, $required_fields ) ) {
287 - \WP_CLI::error( 'Missing field: ' . $field );
288 - }
289 - }
290 - return $data;
291 - }
272 + /**
273 + * Maps arguments.
274 + *
275 + * @param array $assoc_args Arguments.
276 + * @param array $fields Fields.
277 + * @param array|string $required_fields Fields that are required, default 'all': all fields are required.
278 + *
279 + * @return array $data Required data.
280 + */
281 + public static function map_assoc_args( $assoc_args, $fields, $required_fields = 'all' ) {
282 + $data = array();
283 + foreach ( $fields as $field ) {
284 + if ( isset( $assoc_args[ $field ] ) ) {
285 + $data[ $field ] = $assoc_args[ $field ];
286 + } elseif ( 'all' === $required_fields ) {
287 + \WP_CLI::error( 'Missing field: ' . $field );
288 + } elseif ( is_array( $required_fields ) && ! empty( $required_fields ) && in_array( $field, $required_fields ) ) {
289 + \WP_CLI::error( 'Missing field: ' . $field );
290 + }
291 + }
292 + return $data;
293 + }
292 294
293 295
294 - /**
295 - * Lists all sites.
296 - *
297 - * Command Example: wp mainwp sites --all-sites.
298 - */
299 - public static function callback_sites_all_sites() {
300 - // get data.
301 - $data = MainWP_DB::instance()->get_websites_for_current_user();
302 - if ( empty( $data ) ) {
303 - \WP_CLI::line( esc_html__( 'No child sites added to your MainWP Dashboard.', 'mainwp' ) );
304 - } else {
305 - self::print_sites( $data, true );
306 - }
307 - }
296 + /**
297 + * Lists all sites.
298 + *
299 + * Command Example: wp mainwp sites --all-sites.
300 + */
301 + public static function callback_sites_all_sites() {
302 + // get data.
303 + $data = MainWP_DB::instance()->get_websites_for_current_user();
304 + if ( empty( $data ) ) {
305 + \WP_CLI::line( esc_html__( 'No child sites added to your MainWP Dashboard.', 'mainwp' ) );
306 + } else {
307 + static::print_sites( $data, true );
308 + }
309 + }
308 310
309 311
310 - /**
311 - * Returns number of child sites.
312 - *
313 - * Command Example: wp mainwp sites --all-sites-count.
314 - */
315 - public static function callback_sites_all_sites_count() {
316 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
317 - $count = MainWP_DB::num_rows( $websites );
318 - MainWP_DB::free_result( $websites );
319 - \WP_CLI::line( '' );
320 - \WP_CLI::line( esc_html__( 'Number of child sites: ', 'mainwp' ) . $count );
321 - \WP_CLI::line( '' );
322 - }
312 + /**
313 + * Returns number of child sites.
314 + *
315 + * Command Example: wp mainwp sites --all-sites-count.
316 + */
317 + public static function callback_sites_all_sites_count() {
318 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
319 + $count = MainWP_DB::num_rows( $websites );
320 + MainWP_DB::free_result( $websites );
321 + \WP_CLI::line( '' );
322 + \WP_CLI::line( esc_html__( 'Number of child sites: ', 'mainwp' ) . $count );
323 + \WP_CLI::line( '' );
324 + }
323 325
324 - /**
325 - * Lists all connected child sites.
326 - *
327 - * Command Example: wp mainwp sites --connected-sites.
328 - */
329 - public static function callback_sites_connected_sites() {
330 - $data = MainWP_DB::instance()->get_connected_websites();
331 - if ( empty( $data ) ) {
332 - \WP_CLI::line( esc_html__( 'No connected child sites fount.', 'mainwp' ) );
333 - } else {
334 - self::print_sites( $data );
335 - }
336 - }
326 + /**
327 + * Lists all connected child sites.
328 + *
329 + * Command Example: wp mainwp sites --connected-sites.
330 + */
331 + public static function callback_sites_connected_sites() {
332 + $data = MainWP_DB::instance()->get_connected_websites();
333 + if ( empty( $data ) ) {
334 + \WP_CLI::line( esc_html__( 'No connected child sites fount.', 'mainwp' ) );
335 + } else {
336 + static::print_sites( $data );
337 + }
338 + }
337 339
338 - /**
339 - * Returns number of connected sites.
340 - *
341 - * Command Example: wp mainwp sites --connected-sites-count.
342 - */
343 - public static function callback_sites_connected_sites_count() {
344 - $websites = MainWP_DB::instance()->get_connected_websites();
345 - \WP_CLI::line( esc_html__( 'Number of connected child sites: ', 'mainwp' ) . count( $websites ) );
346 - }
340 + /**
341 + * Returns number of connected sites.
342 + *
343 + * Command Example: wp mainwp sites --connected-sites-count.
344 + */
345 + public static function callback_sites_connected_sites_count() {
346 + $websites = MainWP_DB::instance()->get_connected_websites();
347 + \WP_CLI::line( esc_html__( 'Number of connected child sites: ', 'mainwp' ) . count( $websites ) );
348 + }
347 349
348 - /**
349 - * Lists all disconnected child sites.
350 - *
351 - * Command Example: wp mainwp sites --disconnected-sites.
352 - */
353 - public static function callback_sites_disconnected_sites() {
354 - $data = MainWP_DB::instance()->get_disconnected_websites();
355 - if ( empty( $data ) ) {
356 - \WP_CLI::line( esc_html__( 'No disconnected child sites found.', 'mainwp' ) );
357 - } else {
358 - self::print_sites( $data );
359 - }
360 - }
350 + /**
351 + * Lists all disconnected child sites.
352 + *
353 + * Command Example: wp mainwp sites --disconnected-sites.
354 + */
355 + public static function callback_sites_disconnected_sites() {
356 + $data = MainWP_DB::instance()->get_disconnected_websites();
357 + if ( empty( $data ) ) {
358 + \WP_CLI::line( esc_html__( 'No disconnected child sites found.', 'mainwp' ) );
359 + } else {
360 + static::print_sites( $data );
361 + }
362 + }
361 363
362 - /**
363 - * Returns number of disconnected child sites.
364 - *
365 - * Command Example: wp mainwp sites --disconnected-sites-count.
366 - */
367 - public static function callback_sites_disconnected_sites_count() {
368 - $data = MainWP_DB::instance()->get_disconnected_websites();
369 - \WP_CLI::line( 'Number of disconnected child sites: ' . count( $data ) );
370 - }
364 + /**
365 + * Returns number of disconnected child sites.
366 + *
367 + * Command Example: wp mainwp sites --disconnected-sites-count.
368 + */
369 + public static function callback_sites_disconnected_sites_count() {
370 + $data = MainWP_DB::instance()->get_disconnected_websites();
371 + \WP_CLI::line( 'Number of disconnected child sites: ' . count( $data ) );
372 + }
371 373
372 - /**
373 - * Syncs all child sites.
374 - *
375 - * Command Example: wp mainwp sites --sync-sites.
376 - *
377 - * @uses handle_sync_sites();
378 - */
379 - public static function callback_sites_sync_sites() {
380 - self::handle_sync_sites();
381 - }
374 + /**
375 + * Syncs all child sites.
376 + *
377 + * Command Example: wp mainwp sites --sync-sites.
378 + *
379 + * @uses handle_sync_sites();
380 + */
381 + public static function callback_sites_sync_sites() {
382 + static::handle_sync_sites();
383 + }
382 384
383 - /**
384 - * Checks all child sites (HTTP Status).
385 - *
386 - * Command Example: wp mainwp sites --check-sites.
387 - *
388 - * @param array $args Arguments.
389 - * @param array $assoc_args Arguments.
390 - */
391 - public static function callback_sites_check_sites( $args, $assoc_args ) {
385 + /**
386 + * Checks all child sites (HTTP Status).
387 + *
388 + * Command Example: wp mainwp sites --check-sites.
389 + *
390 + * @param array $args Arguments.
391 + * @param array $assoc_args Arguments.
392 + */
393 + public static function callback_sites_check_sites( $args, $assoc_args ) {
392 394
393 - $sites = self::get_cli_params( $args, $assoc_args, 'sites' );
395 + $sites = static::get_cli_params( $args, $assoc_args, 'sites' );
394 396
395 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
396 - \WP_CLI::line( '' );
397 - \WP_CLI::line( esc_html__( 'Check started. Please wait...', 'mainwp' ) );
398 - \WP_CLI::line( '' );
399 - $errors = 0;
400 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
401 - if ( ( count( $sites ) > 0 ) && ( ! in_array( $website->id, $sites, true ) ) ) {
402 - continue;
403 - }
404 - \WP_CLI::line( ' -> ' . $website->name . ' (' . $website->url . ')' );
405 - try {
406 - MainWP_Monitoring_Handler::handle_check_website( $website );
407 - } catch ( \Exception $e ) {
408 - \WP_CLI::error( ' Check failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
409 - ++$errors;
410 - }
411 - }
412 - MainWP_DB::free_result( $websites );
413 - if ( $errors > 0 ) {
414 - \WP_CLI::error( 'Check completed with errors' );
415 - } else {
416 - \WP_CLI::success( 'Check completed' );
417 - }
418 - }
397 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
398 + \WP_CLI::line( '' );
399 + \WP_CLI::line( esc_html__( 'Check started. Please wait...', 'mainwp' ) );
400 + \WP_CLI::line( '' );
401 + $errors = 0;
402 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
403 + if ( ! empty( $sites ) && ( ! in_array( $website->id, $sites, true ) ) ) {
404 + continue;
405 + }
406 + \WP_CLI::line( ' -> ' . $website->name . ' (' . $website->url . ')' );
407 + try {
408 + MainWP_Monitoring_Handler::handle_check_website( $website );
409 + } catch ( \Exception $e ) {
410 + \WP_CLI::error( ' Check failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
411 + ++$errors;
412 + }
413 + }
414 + MainWP_DB::free_result( $websites );
415 + if ( $errors > 0 ) {
416 + \WP_CLI::error( 'Check completed with errors' );
417 + } else {
418 + \WP_CLI::success( 'Check completed' );
419 + }
420 + }
419 421
420 - /**
421 - * Disconnects all child sites.
422 - *
423 - * Command Example: wp mainwp sites --disconnect-sites.
424 - *
425 - * @param array $args Arguments.
426 - * @param array $assoc_args Arguments.
427 - */
428 - public static function callback_sites_disconnect_sites( $args = array(), $assoc_args = false ) {
422 + /**
423 + * Disconnects all child sites.
424 + *
425 + * Command Example: wp mainwp sites --disconnect-sites.
426 + *
427 + * @param array $args Arguments.
428 + * @param array $assoc_args Arguments.
429 + */
430 + public static function callback_sites_disconnect_sites( $args = array(), $assoc_args = false ) {
429 431
430 - $sites = self::get_cli_params( $args, $assoc_args, 'sites' );
432 + $sites = static::get_cli_params( $args, $assoc_args, 'sites' );
431 433
432 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
433 - \WP_CLI::line( 'Disconnect started' );
434 - $errors = 0;
435 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
436 - if ( ( count( $sites ) > 0 ) && ( ! in_array( $website->id, $sites, true ) ) ) {
437 - continue;
438 - }
439 - \WP_CLI::line( ' -> ' . $website->name . ' (' . $website->url . ')' );
440 - try {
441 - MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
442 - } catch ( \Exception $e ) {
443 - \WP_CLI::error( ' Disconnect failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
444 - ++$errors;
445 - }
446 - }
447 - MainWP_DB::free_result( $websites );
448 - if ( $errors > 0 ) {
449 - \WP_CLI::error( 'Disconnect completed with errors' );
450 - } else {
451 - \WP_CLI::success( 'Disconnect completed' );
452 - }
453 - }
434 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
435 + \WP_CLI::line( 'Disconnect started' );
436 + $errors = 0;
437 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
438 + if ( ! empty( $sites ) && ( ! in_array( $website->id, $sites, true ) ) ) {
439 + continue;
440 + }
441 + \WP_CLI::line( ' -> ' . $website->name . ' (' . $website->url . ')' );
442 + try {
443 + MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
444 + } catch ( \Exception $e ) {
445 + \WP_CLI::error( ' Disconnect failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
446 + ++$errors;
447 + }
448 + }
449 + MainWP_DB::free_result( $websites );
450 + if ( $errors > 0 ) {
451 + \WP_CLI::error( 'Disconnect completed with errors' );
452 + } else {
453 + \WP_CLI::success( 'Disconnect completed' );
454 + }
455 + }
454 456
455 - /**
456 - * Lists child site data.
457 - *
458 - * Command Example: wp mainwp site --site [<websiteid>].
459 - *
460 - * @param array $args Arguments.
461 - * @param array $assoc_args Arguments.
462 - * @param object $website Object containing child site data.
463 - */
464 - public static function callback_site_site( $args = array(), $assoc_args = array(), $website = false ) {
465 - \WP_CLI::line( \WP_CLI::colorize( '%gSite Name:%n ' ) . $website->name );
466 - \WP_CLI::line( \WP_CLI::colorize( '%gSite URL:%n ' ) . $website->url );
467 - \WP_CLI::line( \WP_CLI::colorize( '%gID:%n ' ) . $website->id );
468 - \WP_CLI::line( \WP_CLI::colorize( '%gAdmin Username:%n ' ) . $website->adminname );
469 - \WP_CLI::line( \WP_CLI::colorize( '%gHTTP Response:%n ' ) . $website->http_response_code );
470 - \WP_CLI::line( \WP_CLI::colorize( '%gNotes:%n ' ) . $website->note );
471 - \WP_CLI::line( \WP_CLI::colorize( '%gSecurity Issues:%n ' ) . $website->securityIssues );
472 - \WP_CLI::line( \WP_CLI::colorize( '%gHealth Issues Total:%n ' ) . $website->health_issues_total );
473 - \WP_CLI::line( \WP_CLI::colorize( '%gHealth Issues:%n ' ) . $website->health_issues );
474 - \WP_CLI::line( \WP_CLI::colorize( '%gHealth Value:%n ' ) . $website->health_value );
475 - }
457 + /**
458 + * Lists child site data.
459 + *
460 + * Command Example: wp mainwp site --site [<websiteid>].
461 + *
462 + * @param array $args Arguments.
463 + * @param array $assoc_args Arguments.
464 + * @param object $website Object containing child site data.
465 + */
466 + public static function callback_site_site( $args = array(), $assoc_args = array(), $website = false ) {
467 + \WP_CLI::line( \WP_CLI::colorize( '%gSite Name:%n ' ) . $website->name );
468 + \WP_CLI::line( \WP_CLI::colorize( '%gSite URL:%n ' ) . $website->url );
469 + \WP_CLI::line( \WP_CLI::colorize( '%gID:%n ' ) . $website->id );
470 + \WP_CLI::line( \WP_CLI::colorize( '%gAdmin Username:%n ' ) . $website->adminname );
471 + \WP_CLI::line( \WP_CLI::colorize( '%gHTTP Response:%n ' ) . $website->http_response_code );
472 + \WP_CLI::line( \WP_CLI::colorize( '%gNotes:%n ' ) . $website->note );
473 + \WP_CLI::line( \WP_CLI::colorize( '%gSecurity Issues:%n ' ) . $website->securityIssues );
474 + \WP_CLI::line( \WP_CLI::colorize( '%gHealth Issues Total:%n ' ) . $website->health_issues_total );
475 + \WP_CLI::line( \WP_CLI::colorize( '%gHealth Issues:%n ' ) . $website->health_issues );
476 + \WP_CLI::line( \WP_CLI::colorize( '%gHealth Value:%n ' ) . $website->health_value );
477 + }
476 478
477 - /**
478 - * Shows child site info.
479 - *
480 - * Command Example: wp mainwp site --site-info [<websiteid>].
481 - *
482 - * @param array $args Arguments.
483 - * @param array $assoc_args Arguments.
484 - * @param object $website Object containing child site data.
485 - */
486 - public static function callback_site_site_info( $args = array(), $assoc_args = array(), $website = false ) {
487 - $data = array(
488 - 'wpversion' => '',
489 - 'phpversion' => '',
490 - 'child_version' => '',
491 - 'memory_limit' => '',
492 - 'mysql_version' => '',
493 - 'themeactivated' => '',
494 - 'ip' => '',
495 - );
479 + /**
480 + * Shows child site info.
481 + *
482 + * Command Example: wp mainwp site --site-info [<websiteid>].
483 + *
484 + * @param array $args Arguments.
485 + * @param array $assoc_args Arguments.
486 + * @param object $website Object containing child site data.
487 + */
488 + public static function callback_site_site_info( $args = array(), $assoc_args = array(), $website = false ) {
489 + $data = array(
490 + 'wpversion' => '',
491 + 'phpversion' => '',
492 + 'child_version' => '',
493 + 'memory_limit' => '',
494 + 'mysql_version' => '',
495 + 'themeactivated' => '',
496 + 'ip' => '',
497 + );
496 498
497 - $site_info = MainWP_DB::instance()->get_website_option( $website, 'site_info' );
498 - $site_info = ! empty( $site_info ) ? json_decode( $site_info, true ) : array();
499 + $site_info = MainWP_DB::instance()->get_website_option( $website, 'site_info' );
500 + $site_info = ! empty( $site_info ) ? json_decode( $site_info, true ) : array();
499 501
500 - if ( ! is_array( $site_info ) ) {
501 - $site_info = array();
502 - }
502 + if ( ! is_array( $site_info ) ) {
503 + $site_info = array();
504 + }
503 505
504 - $data = array_merge( $data, $site_info );
506 + $data = array_merge( $data, $site_info );
505 507
506 - \WP_CLI::line( \WP_CLI::colorize( '%gSite Name:%n ' ) . $website->name );
507 - \WP_CLI::line( \WP_CLI::colorize( '%gSite URL:%n ' ) . $website->url );
508 - \WP_CLI::line( \WP_CLI::colorize( '%gWP Version:%n ' ) . $data['wpversion'] );
509 - \WP_CLI::line( \WP_CLI::colorize( '%gPHP Version:%n ' ) . $data['phpversion'] );
510 - \WP_CLI::line( \WP_CLI::colorize( '%gMainWP Child Version:%n ' ) . $data['child_version'] );
511 - \WP_CLI::line( \WP_CLI::colorize( '%gPHP Memory Limit:%n ' ) . $data['memory_limit'] );
512 - \WP_CLI::line( \WP_CLI::colorize( '%gMySQL Version:%n ' ) . $data['mysql_version'] );
513 - \WP_CLI::line( \WP_CLI::colorize( '%gActive Theme:%n ' ) . $data['themeactivated'] );
514 - \WP_CLI::line( \WP_CLI::colorize( '%gIP Address:%n ' ) . $data['ip'] );
515 - }
508 + \WP_CLI::line( \WP_CLI::colorize( '%gSite Name:%n ' ) . $website->name );
509 + \WP_CLI::line( \WP_CLI::colorize( '%gSite URL:%n ' ) . $website->url );
510 + \WP_CLI::line( \WP_CLI::colorize( '%gWP Version:%n ' ) . $data['wpversion'] );
511 + \WP_CLI::line( \WP_CLI::colorize( '%gPHP Version:%n ' ) . $data['phpversion'] );
512 + \WP_CLI::line( \WP_CLI::colorize( '%gMainWP Child Version:%n ' ) . $data['child_version'] );
513 + \WP_CLI::line( \WP_CLI::colorize( '%gPHP Memory Limit:%n ' ) . $data['memory_limit'] );
514 + \WP_CLI::line( \WP_CLI::colorize( '%gMySQL Version:%n ' ) . $data['mysql_version'] );
515 + \WP_CLI::line( \WP_CLI::colorize( '%gActive Theme:%n ' ) . $data['themeactivated'] );
516 + \WP_CLI::line( \WP_CLI::colorize( '%gIP Address:%n ' ) . $data['ip'] );
517 + }
516 518
517 - /**
518 - * Lists installed plugins on a child site.
519 - *
520 - * Command Example: wp mainwp site --site-installed-plugins [<websiteid>].
521 - *
522 - * @param array $args Arguments.
523 - * @param array $assoc_args Arguments.
524 - * @param object $website Object containing child site data.
525 - */
526 - public static function callback_site_site_installed_plugins( $args = array(), $assoc_args = array(), $website = false ) {
527 - $plugins = json_decode( $website->plugins, 1 );
519 + /**
520 + * Lists installed plugins on a child site.
521 + *
522 + * Command Example: wp mainwp site --site-installed-plugins [<websiteid>].
523 + *
524 + * @param array $args Arguments.
525 + * @param array $assoc_args Arguments.
526 + * @param object $website Object containing child site data.
527 + */
528 + public static function callback_site_site_installed_plugins( $args = array(), $assoc_args = array(), $website = false ) {
529 + $plugins = json_decode( $website->plugins, 1 );
528 530
529 - \WP_CLI::line( '' );
530 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Installed Plugins', 'mainwp' ) . '%n' ) );
531 - \WP_CLI::line( '' );
531 + \WP_CLI::line( '' );
532 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Installed Plugins', 'mainwp' ) . '%n' ) );
533 + \WP_CLI::line( '' );
532 534
533 - foreach ( $plugins as $plugin ) {
534 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Name:%n ' ) . $plugin['name'] );
535 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Slug:%n ' ) . $plugin['slug'] );
536 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Description:%n ' ) . $plugin['description'] );
537 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Version:%n ' ) . $plugin['version'] );
538 - if ( '1' === $plugin['active'] ) {
539 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Status:%n ' ) . esc_html__( 'Active', 'mainwp' ) );
540 - } else {
541 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Status:%n ' ) . esc_html__( 'Inactive', 'mainwp' ) );
542 - }
543 - \WP_CLI::line( '' );
544 - }
545 - }
535 + foreach ( $plugins as $plugin ) {
536 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Name:%n ' ) . $plugin['name'] );
537 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Slug:%n ' ) . $plugin['slug'] );
538 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Description:%n ' ) . $plugin['description'] );
539 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Version:%n ' ) . $plugin['version'] );
540 + if ( '1' === $plugin['active'] ) {
541 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Status:%n ' ) . esc_html__( 'Active', 'mainwp' ) );
542 + } else {
543 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Status:%n ' ) . esc_html__( 'Inactive', 'mainwp' ) );
544 + }
545 + \WP_CLI::line( '' );
546 + }
547 + }
546 548
547 - /**
548 - * Returns the number of installed plugins on a child site.
549 - *
550 - * Command Example: wp mainwp site --site-installed-plugins-count [<websiteid>].
551 - *
552 - * @param array $args Arguments.
553 - * @param array $assoc_args Arguments.
554 - * @param object $website Object containing child site data.
555 - */
556 - public static function callback_site_site_installed_plugins_count( $args = array(), $assoc_args = array(), $website = false ) {
557 - $plugins = json_decode( $website->plugins, 1 );
549 + /**
550 + * Returns the number of installed plugins on a child site.
551 + *
552 + * Command Example: wp mainwp site --site-installed-plugins-count [<websiteid>].
553 + *
554 + * @param array $args Arguments.
555 + * @param array $assoc_args Arguments.
556 + * @param object $website Object containing child site data.
557 + */
558 + public static function callback_site_site_installed_plugins_count( $args = array(), $assoc_args = array(), $website = false ) {
559 + $plugins = json_decode( $website->plugins, 1 );
558 560
559 - \WP_CLI::line( '' );
560 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Installed plugins: ', 'mainwp' ) . '%n' . count( $plugins ) ) );
561 - \WP_CLI::line( '' );
562 - }
561 + \WP_CLI::line( '' );
562 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Installed plugins: ', 'mainwp' ) . '%n' . count( $plugins ) ) );
563 + \WP_CLI::line( '' );
564 + }
563 565
564 566
565 - /**
566 - * Lists all active plugins on a child site.
567 - *
568 - * Command Example: wp mainwp site --site-active-plugins [<websiteid>].
569 - *
570 - * @param array $args Arguments.
571 - * @param array $assoc_args Arguments.
572 - * @param object $website Object containing child site data.
573 - */
574 - public static function callback_site_site_active_plugins( $args = array(), $assoc_args = array(), $website = false ) {
575 - $plugins = json_decode( $website->plugins, 1 );
576 - $data = MainWP_Utility::get_sub_array_having( $plugins, 'active', 1 );
567 + /**
568 + * Lists all active plugins on a child site.
569 + *
570 + * Command Example: wp mainwp site --site-active-plugins [<websiteid>].
571 + *
572 + * @param array $args Arguments.
573 + * @param array $assoc_args Arguments.
574 + * @param object $website Object containing child site data.
575 + */
576 + public static function callback_site_site_active_plugins( $args = array(), $assoc_args = array(), $website = false ) {
577 + $plugins = json_decode( $website->plugins, 1 );
578 + $data = MainWP_Utility::get_sub_array_having( $plugins, 'active', 1 );
577 579
578 - \WP_CLI::line( '' );
579 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Active Plugins', 'mainwp' ) . '%n' ) );
580 - \WP_CLI::line( '' );
580 + \WP_CLI::line( '' );
581 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Active Plugins', 'mainwp' ) . '%n' ) );
582 + \WP_CLI::line( '' );
581 583
582 - foreach ( $data as $plugin ) {
583 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Name:%n ' ) . $plugin['name'] );
584 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Slug:%n ' ) . $plugin['slug'] );
585 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Description:%n ' ) . $plugin['description'] );
586 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Version:%n ' ) . $plugin['version'] );
587 - \WP_CLI::line( '' );
588 - }
589 - }
584 + foreach ( $data as $plugin ) {
585 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Name:%n ' ) . $plugin['name'] );
586 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Slug:%n ' ) . $plugin['slug'] );
587 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Description:%n ' ) . $plugin['description'] );
588 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Version:%n ' ) . $plugin['version'] );
589 + \WP_CLI::line( '' );
590 + }
591 + }
590 592
591 - /**
592 - * Returns a number of active plugins on a child site.
593 - *
594 - * Command Example: wp mainwp site --site-active-plugins-count [<websiteid>].
595 - *
596 - * @param array $args Arguments.
597 - * @param array $assoc_args Arguments.
598 - * @param object $website Object containing child site data.
599 - */
600 - public static function callback_site_site_active_plugins_count( $args = array(), $assoc_args = array(), $website = false ) {
601 - $plugins = json_decode( $website->plugins, 1 );
602 - $data = MainWP_Utility::get_sub_array_having( $plugins, 'active', 1 );
593 + /**
594 + * Returns a number of active plugins on a child site.
595 + *
596 + * Command Example: wp mainwp site --site-active-plugins-count [<websiteid>].
597 + *
598 + * @param array $args Arguments.
599 + * @param array $assoc_args Arguments.
600 + * @param object $website Object containing child site data.
601 + */
602 + public static function callback_site_site_active_plugins_count( $args = array(), $assoc_args = array(), $website = false ) {
603 + $plugins = json_decode( $website->plugins, 1 );
604 + $data = MainWP_Utility::get_sub_array_having( $plugins, 'active', 1 );
603 605
604 - \WP_CLI::line( '' );
605 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Active plugins: ', 'mainwp' ) . '%n' . count( $data ) ) );
606 - \WP_CLI::line( '' );
607 - }
606 + \WP_CLI::line( '' );
607 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Active plugins: ', 'mainwp' ) . '%n' . count( $data ) ) );
608 + \WP_CLI::line( '' );
609 + }
608 610
609 - /**
610 - * Lists all inactive plugins on a child site.
611 - *
612 - * Command Example: wp mainwp site --site-inactive-plugins [<websiteid>].
613 - *
614 - * @param array $args Arguments.
615 - * @param array $assoc_args Arguments.
616 - * @param object $website Object containing child site data.
617 - */
618 - public static function callback_site_site_inactive_plugins( $args = array(), $assoc_args = array(), $website = false ) {
619 - $plugins = json_decode( $website->plugins, 1 );
620 - $data = MainWP_Utility::get_sub_array_having( $plugins, 'active', 0 );
611 + /**
612 + * Lists all inactive plugins on a child site.
613 + *
614 + * Command Example: wp mainwp site --site-inactive-plugins [<websiteid>].
615 + *
616 + * @param array $args Arguments.
617 + * @param array $assoc_args Arguments.
618 + * @param object $website Object containing child site data.
619 + */
620 + public static function callback_site_site_inactive_plugins( $args = array(), $assoc_args = array(), $website = false ) {
621 + $plugins = json_decode( $website->plugins, 1 );
622 + $data = MainWP_Utility::get_sub_array_having( $plugins, 'active', 0 );
621 623
622 - \WP_CLI::line( '' );
623 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Inactive Plugins', 'mainwp' ) . '%n' ) );
624 - \WP_CLI::line( '' );
624 + \WP_CLI::line( '' );
625 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Inactive Plugins', 'mainwp' ) . '%n' ) );
626 + \WP_CLI::line( '' );
625 627
626 - foreach ( $data as $plugin ) {
627 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Name:%n ' ) . $plugin['name'] );
628 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Slug:%n ' ) . $plugin['slug'] );
629 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Description:%n ' ) . $plugin['description'] );
630 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Version:%n ' ) . $plugin['version'] );
631 - \WP_CLI::line( '' );
632 - }
633 - }
628 + foreach ( $data as $plugin ) {
629 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Name:%n ' ) . $plugin['name'] );
630 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Slug:%n ' ) . $plugin['slug'] );
631 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Description:%n ' ) . $plugin['description'] );
632 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugin Version:%n ' ) . $plugin['version'] );
633 + \WP_CLI::line( '' );
634 + }
635 + }
634 636
635 - /**
636 - * Returns the number of inactive plugins on a child site.
637 - *
638 - * Command Example: wp mainwp site --site-inactive-plugins-count [<websiteid>].
639 - *
640 - * @param array $args Arguments.
641 - * @param array $assoc_args Arguments.
642 - * @param object $website Object containing child site data.
643 - */
644 - public static function callback_site_site_inactive_plugins_count( $args = array(), $assoc_args = array(), $website = false ) {
645 - $plugins = json_decode( $website->plugins, 1 );
646 - $data = MainWP_Utility::get_sub_array_having( $plugins, 'active', 0 );
637 + /**
638 + * Returns the number of inactive plugins on a child site.
639 + *
640 + * Command Example: wp mainwp site --site-inactive-plugins-count [<websiteid>].
641 + *
642 + * @param array $args Arguments.
643 + * @param array $assoc_args Arguments.
644 + * @param object $website Object containing child site data.
645 + */
646 + public static function callback_site_site_inactive_plugins_count( $args = array(), $assoc_args = array(), $website = false ) {
647 + $plugins = json_decode( $website->plugins, 1 );
648 + $data = MainWP_Utility::get_sub_array_having( $plugins, 'active', 0 );
647 649
648 - \WP_CLI::line( '' );
649 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Inctive plugins: ', 'mainwp' ) . '%n' . count( $data ) ) );
650 - \WP_CLI::line( '' );
651 - }
650 + \WP_CLI::line( '' );
651 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Inctive plugins: ', 'mainwp' ) . '%n' . count( $data ) ) );
652 + \WP_CLI::line( '' );
653 + }
652 654
653 655
654 - /**
655 - * Lists all installed themes on a child site.
656 - *
657 - * Command Example: wp mainwp site --site-installed-themes [<websiteid>].
658 - *
659 - * @param array $args Arguments.
660 - * @param array $assoc_args Arguments.
661 - * @param object $website Object containing child site data.
662 - */
663 - public static function callback_site_site_installed_themes( $args = array(), $assoc_args = array(), $website = false ) {
664 - $themes = json_decode( $website->themes, 1 );
656 + /**
657 + * Lists all installed themes on a child site.
658 + *
659 + * Command Example: wp mainwp site --site-installed-themes [<websiteid>].
660 + *
661 + * @param array $args Arguments.
662 + * @param array $assoc_args Arguments.
663 + * @param object $website Object containing child site data.
664 + */
665 + public static function callback_site_site_installed_themes( $args = array(), $assoc_args = array(), $website = false ) {
666 + $themes = json_decode( $website->themes, 1 );
665 667
666 - \WP_CLI::line( '' );
667 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Installed Themes', 'mainwp' ) . '%n' ) );
668 - \WP_CLI::line( '' );
668 + \WP_CLI::line( '' );
669 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Installed Themes', 'mainwp' ) . '%n' ) );
670 + \WP_CLI::line( '' );
669 671
670 - foreach ( $themes as $theme ) {
671 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Name:%n ' ) . $theme['name'] );
672 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Slug:%n ' ) . $theme['slug'] );
673 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Description:%n ' ) . $theme['description'] );
674 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Version:%n ' ) . $theme['version'] );
675 - if ( '1' === $theme['active'] ) {
676 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Status:%n ' ) . esc_html__( 'Active', 'mainwp' ) );
677 - } else {
678 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Status:%n ' ) . esc_html__( 'Inactive', 'mainwp' ) );
679 - }
680 - \WP_CLI::line( '' );
681 - }
682 - }
672 + foreach ( $themes as $theme ) {
673 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Name:%n ' ) . $theme['name'] );
674 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Slug:%n ' ) . $theme['slug'] );
675 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Description:%n ' ) . $theme['description'] );
676 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Version:%n ' ) . $theme['version'] );
677 + if ( '1' === $theme['active'] ) {
678 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Status:%n ' ) . esc_html__( 'Active', 'mainwp' ) );
679 + } else {
680 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Status:%n ' ) . esc_html__( 'Inactive', 'mainwp' ) );
681 + }
682 + \WP_CLI::line( '' );
683 + }
684 + }
683 685
684 - /**
685 - * Returns the number of installed themes.
686 - *
687 - * Command Example: wp mainwp site --site-installed-themes-count [<websiteid>].
688 - *
689 - * @param array $args Arguments.
690 - * @param array $assoc_args Arguments.
691 - * @param object $website Object containing child site data.
692 - */
693 - public static function callback_site_site_installed_themes_count( $args = array(), $assoc_args = array(), $website = false ) {
694 - $themes = json_decode( $website->themes, 1 );
686 + /**
687 + * Returns the number of installed themes.
688 + *
689 + * Command Example: wp mainwp site --site-installed-themes-count [<websiteid>].
690 + *
691 + * @param array $args Arguments.
692 + * @param array $assoc_args Arguments.
693 + * @param object $website Object containing child site data.
694 + */
695 + public static function callback_site_site_installed_themes_count( $args = array(), $assoc_args = array(), $website = false ) {
696 + $themes = json_decode( $website->themes, 1 );
695 697
696 - \WP_CLI::line( '' );
697 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Installed themes: ', 'mainwp' ) . '%n' . count( $themes ) ) );
698 - \WP_CLI::line( '' );
699 - }
698 + \WP_CLI::line( '' );
699 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Installed themes: ', 'mainwp' ) . '%n' . count( $themes ) ) );
700 + \WP_CLI::line( '' );
701 + }
700 702
701 703
702 - /**
703 - * Shows the active theme on the child site.
704 - *
705 - * Command Example: wp mainwp site --site-active-themes [<websiteid>].
706 - *
707 - * @param array $args Arguments.
708 - * @param array $assoc_args Arguments.
709 - * @param object $website Object containing child site data.
710 - */
711 - public static function callback_site_site_active_themes( $args = array(), $assoc_args = array(), $website = false ) {
712 - $themes = json_decode( $website->themes, 1 );
713 - $data = MainWP_Utility::get_sub_array_having( $themes, 'active', 1 );
704 + /**
705 + * Shows the active theme on the child site.
706 + *
707 + * Command Example: wp mainwp site --site-active-themes [<websiteid>].
708 + *
709 + * @param array $args Arguments.
710 + * @param array $assoc_args Arguments.
711 + * @param object $website Object containing child site data.
712 + */
713 + public static function callback_site_site_active_themes( $args = array(), $assoc_args = array(), $website = false ) {
714 + $themes = json_decode( $website->themes, 1 );
715 + $data = MainWP_Utility::get_sub_array_having( $themes, 'active', 1 );
714 716
715 - \WP_CLI::line( '' );
716 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Active Theme', 'mainwp' ) . '%n' ) );
717 - \WP_CLI::line( '' );
717 + \WP_CLI::line( '' );
718 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Active Theme', 'mainwp' ) . '%n' ) );
719 + \WP_CLI::line( '' );
718 720
719 - foreach ( $data as $theme ) {
720 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Name:%n ' ) . $theme['name'] );
721 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Slug:%n ' ) . $theme['slug'] );
722 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Description:%n ' ) . $theme['description'] );
723 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Version:%n ' ) . $theme['version'] );
724 - \WP_CLI::line( '' );
725 - }
726 - }
721 + foreach ( $data as $theme ) {
722 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Name:%n ' ) . $theme['name'] );
723 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Slug:%n ' ) . $theme['slug'] );
724 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Description:%n ' ) . $theme['description'] );
725 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Version:%n ' ) . $theme['version'] );
726 + \WP_CLI::line( '' );
727 + }
728 + }
727 729
728 - /**
729 - * Lists all inactive themes on a child site.
730 - *
731 - * Command Example: wp mainwp site --site-inactive-themes [<websiteid>].
732 - *
733 - * @param array $args Arguments.
734 - * @param array $assoc_args Arguments.
735 - * @param object $website Object containing child site data.
736 - */
737 - public static function callback_site_site_inactive_themes( $args = array(), $assoc_args = array(), $website = false ) {
738 - $themes = json_decode( $website->themes, 1 );
739 - $data = MainWP_Utility::get_sub_array_having( $themes, 'active', 0 );
730 + /**
731 + * Lists all inactive themes on a child site.
732 + *
733 + * Command Example: wp mainwp site --site-inactive-themes [<websiteid>].
734 + *
735 + * @param array $args Arguments.
736 + * @param array $assoc_args Arguments.
737 + * @param object $website Object containing child site data.
738 + */
739 + public static function callback_site_site_inactive_themes( $args = array(), $assoc_args = array(), $website = false ) {
740 + $themes = json_decode( $website->themes, 1 );
741 + $data = MainWP_Utility::get_sub_array_having( $themes, 'active', 0 );
740 742
741 - \WP_CLI::line( '' );
742 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Inactive Themes', 'mainwp' ) . '%n' ) );
743 - \WP_CLI::line( '' );
743 + \WP_CLI::line( '' );
744 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Inactive Themes', 'mainwp' ) . '%n' ) );
745 + \WP_CLI::line( '' );
744 746
745 - foreach ( $data as $theme ) {
746 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Name:%n ' ) . $theme['name'] );
747 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Slug:%n ' ) . $theme['slug'] );
748 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Description:%n ' ) . $theme['description'] );
749 - \WP_CLI::line( \WP_CLI::colorize( '%gTheme Version:%n ' ) . $theme['version'] );
750 - \WP_CLI::line( '' );
751 - }
752 - }
747 + foreach ( $data as $theme ) {
748 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Name:%n ' ) . $theme['name'] );
749 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Slug:%n ' ) . $theme['slug'] );
750 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Description:%n ' ) . $theme['description'] );
751 + \WP_CLI::line( \WP_CLI::colorize( '%gTheme Version:%n ' ) . $theme['version'] );
752 + \WP_CLI::line( '' );
753 + }
754 + }
753 755
754 - /**
755 - * Returns the number of inactive themes.
756 - *
757 - * Command Example: wp mainwp site --site-inactive-themes-count [<websiteid>].
758 - *
759 - * @param array $args Arguments.
760 - * @param array $assoc_args Arguments.
761 - * @param object $website Object containing child site data.
762 - */
763 - public static function callback_site_site_inactive_themes_count( $args = array(), $assoc_args = array(), $website = false ) {
764 - $themes = json_decode( $website->themes, 1 );
765 - $data = MainWP_Utility::get_sub_array_having( $themes, 'active', 0 );
756 + /**
757 + * Returns the number of inactive themes.
758 + *
759 + * Command Example: wp mainwp site --site-inactive-themes-count [<websiteid>].
760 + *
761 + * @param array $args Arguments.
762 + * @param array $assoc_args Arguments.
763 + * @param object $website Object containing child site data.
764 + */
765 + public static function callback_site_site_inactive_themes_count( $args = array(), $assoc_args = array(), $website = false ) {
766 + $themes = json_decode( $website->themes, 1 );
767 + $data = MainWP_Utility::get_sub_array_having( $themes, 'active', 0 );
766 768
767 - \WP_CLI::line( '' );
768 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Inactive themes: ', 'mainwp' ) . '%n' . count( $data ) ) );
769 - \WP_CLI::line( '' );
770 - }
769 + \WP_CLI::line( '' );
770 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Inactive themes: ', 'mainwp' ) . '%n' . count( $data ) ) );
771 + \WP_CLI::line( '' );
772 + }
771 773
772 - /**
773 - * Lists available updates for a child site.
774 - *
775 - * Command Example: wp mainwp site --site-available-updates [<websiteid>].
776 - *
777 - * @param array $args Arguments.
778 - * @param array $assoc_args Arguments.
779 - * @param object $website Object containing child site data.
780 - */
781 - public static function callback_site_site_available_updates( $args = array(), $assoc_args = array(), $website = false ) {
782 - $wp_upgrades = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' );
783 - $wp_upgrades = ! empty( $wp_upgrades ) ? json_decode( $wp_upgrades, true ) : array();
774 + /**
775 + * Lists available updates for a child site.
776 + *
777 + * Command Example: wp mainwp site --site-available-updates [<websiteid>].
778 + *
779 + * @param array $args Arguments.
780 + * @param array $assoc_args Arguments.
781 + * @param object $website Object containing child site data.
782 + */
783 + public static function callback_site_site_available_updates( $args = array(), $assoc_args = array(), $website = false ) { // phpcs:ignore -- NOSONAR - complex.
784 + $site_options = MainWP_DB::instance()->get_website_options_array( $website, array( 'wp_upgrades', 'ignored_trans_updates' ) );
785 + $wp_upgrades = isset( $site_options['wp_upgrades'] ) ? json_decode( $site_options['wp_upgrades'], true ) : array();
786 + $ignored_core_upgrades = isset( $site_options['ignored_wp_upgrades'] ) ? json_decode( $site_options['ignored_wp_upgrades'], true ) : array();
784 787
785 - $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
786 - $theme_upgrades = json_decode( $website->theme_upgrades, true );
787 - $translation_upgrades = json_decode( $website->translation_upgrades, true );
788 + if ( $website->is_ignoreCoreUpdates || MainWP_Common_Functions::instance()->is_ignored_updates( $wp_upgrades, $ignored_core_upgrades, 'core' ) ) {
789 + $wp_upgrades = array();
790 + }
788 791
789 - if ( $website->is_ignorePluginUpdates ) {
790 - $plugin_upgrades = array();
791 - }
792 - if ( $website->is_ignoreThemeUpdates ) {
793 - $theme_upgrades = array();
794 - }
792 + $ignored_trans_updates = isset( $site_options['ignored_trans_updates'] ) ? (int) $site_options['ignored_trans_updates'] : false;
795 793
796 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
797 - if ( is_array( $plugin_upgrades ) && ! empty( $plugin_upgrades ) ) {
798 - $ignored_plugins = json_decode( $website->ignored_plugins, true );
799 - if ( is_array( $ignored_plugins ) ) {
800 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
801 - }
802 - $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
803 - if ( is_array( $ignored_plugins ) ) {
804 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
805 - }
806 - }
794 + $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
795 + $theme_upgrades = json_decode( $website->theme_upgrades, true );
796 + $translation_upgrades = json_decode( $website->translation_upgrades, true );
807 797
808 - if ( is_array( $theme_upgrades ) && ! empty( $theme_upgrades ) ) {
809 - $ignored_themes = json_decode( $website->ignored_themes, true );
810 - if ( is_array( $ignored_themes ) ) {
811 - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
812 - }
798 + if ( $website->is_ignorePluginUpdates ) {
799 + $plugin_upgrades = array();
800 + }
801 + if ( $website->is_ignoreThemeUpdates ) {
802 + $theme_upgrades = array();
803 + }
813 804
814 - $ignored_themes = json_decode( $userExtension->ignored_themes, true );
815 - if ( is_array( $ignored_themes ) ) {
816 - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
817 - }
818 - }
805 + if ( $ignored_trans_updates ) {
806 + $translation_upgrades = array();
807 + }
819 808
820 - $data = array(
821 - 'wp_core' => $wp_upgrades,
822 - 'plugins' => $plugin_upgrades,
823 - 'themes' => $theme_upgrades,
824 - 'translation' => $translation_upgrades,
825 - );
809 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
810 + if ( is_array( $plugin_upgrades ) && ! empty( $plugin_upgrades ) ) {
811 + $ignored_plugins = json_decode( $website->ignored_plugins, true );
812 + if ( is_array( $ignored_plugins ) ) {
813 + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
826 814
827 - \WP_CLI::line( '' );
828 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Available Updates', 'mainwp' ) . '%n' ) );
829 - \WP_CLI::line( '' );
815 + }
816 + $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
817 + if ( is_array( $ignored_plugins ) ) {
818 + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
830 819
831 - if ( 0 < count( $wp_upgrades ) ) {
832 - \WP_CLI::line( '' );
833 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'WordPress Core', 'mainwp' ) . '%n' ) );
834 - \WP_CLI::line( '' );
820 + }
821 + }
835 822
836 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $wp_upgrades['current'] );
837 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $wp_upgrades['new'] );
838 - }
823 + if ( is_array( $theme_upgrades ) && ! empty( $theme_upgrades ) ) {
824 + $ignored_themes = json_decode( $website->ignored_themes, true );
825 + if ( is_array( $ignored_themes ) ) {
826 + $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
827 + }
839 828
840 - if ( 0 < count( $plugin_upgrades ) ) {
841 - \WP_CLI::line( '' );
842 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Plugin Updates', 'mainwp' ) . '%n' ) );
843 - \WP_CLI::line( '' );
829 + $ignored_themes = json_decode( $userExtension->ignored_themes, true );
830 + if ( is_array( $ignored_themes ) ) {
831 + $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
832 + }
833 + }
844 834
845 - foreach ( $plugin_upgrades as $plugin_upgrade ) {
846 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $plugin_upgrade['Name'] );
847 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $plugin_upgrade['Version'] );
848 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $plugin_upgrade['update']['new_version'] );
849 - \WP_CLI::line( '' );
850 - }
851 - }
835 + \WP_CLI::line( '' );
836 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Available Updates', 'mainwp' ) . '%n' ) );
837 + \WP_CLI::line( '' );
852 838
853 - if ( 0 < count( $theme_upgrades ) ) {
854 - \WP_CLI::line( '' );
855 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Theme Updates', 'mainwp' ) . '%n' ) );
856 - \WP_CLI::line( '' );
839 + if ( ! empty( $wp_upgrades ) ) {
840 + \WP_CLI::line( '' );
841 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'WordPress Core', 'mainwp' ) . '%n' ) );
842 + \WP_CLI::line( '' );
857 843
858 - foreach ( $theme_upgrades as $theme_upgrade ) {
859 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $theme_upgrade['Name'] );
860 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $theme_upgrade['Version'] );
861 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $theme_upgrade['update']['new_version'] );
862 - \WP_CLI::line( '' );
863 - }
864 - }
844 + \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $wp_upgrades['current'] );
845 + \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $wp_upgrades['new'] );
846 + }
865 847
866 - if ( 0 < count( $translation_upgrades ) ) {
867 - \WP_CLI::line( '' );
868 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Translation Updates', 'mainwp' ) . '%n' ) );
869 - \WP_CLI::line( '' );
848 + if ( ! empty( $plugin_upgrades ) ) {
849 + \WP_CLI::line( '' );
850 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Plugin Updates', 'mainwp' ) . '%n' ) );
851 + \WP_CLI::line( '' );
870 852
871 - foreach ( $translation_upgrades as $translation_upgrade ) {
872 - if ( ! is_array( $translation_upgrade ) ) {
873 - $translation_upgrade = array();
874 - }
875 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . ( isset( $translation_upgrade['Name'] ) ? $translation_upgrade['Name'] : '' ) );
876 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . ( isset( $translation_upgrade['Version'] ) ? $translation_upgrade['Version'] : '' ) );
877 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . ( isset( $translation_upgrade['update']['new_version'] ) ? $translation_upgrade['update']['new_version'] : '' ) );
878 - \WP_CLI::line( '' );
879 - }
880 - }
881 - }
853 + foreach ( $plugin_upgrades as $plugin_upgrade ) {
854 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $plugin_upgrade['Name'] );
855 + \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $plugin_upgrade['Version'] );
856 + \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $plugin_upgrade['update']['new_version'] );
857 + \WP_CLI::line( '' );
858 + }
859 + }
882 860
883 - /**
884 - * Returns the number of available updates for a child site.
885 - *
886 - * Command Example: wp mainwp site --site-available-updates-count [<websiteid>].
887 - *
888 - * @param array $args Arguments.
889 - * @param array $assoc_args Arguments.
890 - * @param object $website Object containing child site data.
891 - */
892 - public static function callback_site_site_available_updates_count( $args = array(), $assoc_args = array(), $website = false ) {
893 - $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
894 - $theme_upgrades = json_decode( $website->theme_upgrades, true );
861 + if ( ! empty( $theme_upgrades ) ) {
862 + \WP_CLI::line( '' );
863 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Theme Updates', 'mainwp' ) . '%n' ) );
864 + \WP_CLI::line( '' );
895 865
896 - if ( $website->is_ignorePluginUpdates ) {
897 - $plugin_upgrades = array();
898 - }
899 - if ( $website->is_ignoreThemeUpdates ) {
900 - $theme_upgrades = array();
901 - }
866 + foreach ( $theme_upgrades as $theme_upgrade ) {
867 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $theme_upgrade['Name'] );
868 + \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $theme_upgrade['Version'] );
869 + \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $theme_upgrade['update']['new_version'] );
870 + \WP_CLI::line( '' );
871 + }
872 + }
902 873
903 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
904 - if ( is_array( $plugin_upgrades ) && ! empty( $plugin_upgrades ) ) {
905 - $ignored_plugins = json_decode( $website->ignored_plugins, true );
906 - if ( is_array( $ignored_plugins ) ) {
907 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
908 - }
909 - $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
910 - if ( is_array( $ignored_plugins ) ) {
911 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
912 - }
913 - }
874 + if ( ! empty( $translation_upgrades ) ) {
875 + \WP_CLI::line( '' );
876 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Translation Updates', 'mainwp' ) . '%n' ) );
877 + \WP_CLI::line( '' );
914 878
915 - if ( is_array( $theme_upgrades ) && ! empty( $theme_upgrades ) ) {
916 - $ignored_themes = json_decode( $website->ignored_themes, true );
917 - if ( is_array( $ignored_themes ) ) {
918 - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
919 - }
879 + foreach ( $translation_upgrades as $translation_upgrade ) {
880 + if ( ! is_array( $translation_upgrade ) ) {
881 + $translation_upgrade = array();
882 + }
883 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . ( isset( $translation_upgrade['Name'] ) ? $translation_upgrade['Name'] : '' ) );
884 + \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . ( isset( $translation_upgrade['Version'] ) ? $translation_upgrade['Version'] : '' ) );
885 + \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . ( isset( $translation_upgrade['update']['new_version'] ) ? $translation_upgrade['update']['new_version'] : '' ) );
886 + \WP_CLI::line( '' );
887 + }
888 + }
889 + }
920 890
921 - $ignored_themes = json_decode( $userExtension->ignored_themes, true );
922 - if ( is_array( $ignored_themes ) ) {
923 - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
924 - }
925 - }
891 + /**
892 + * Returns the number of available updates for a child site.
893 + *
894 + * Command Example: wp mainwp site --site-available-updates-count [<websiteid>].
895 + *
896 + * @param array $args Arguments.
897 + * @param array $assoc_args Arguments.
898 + * @param object $website Object containing child site data.
899 + */
900 + public static function callback_site_site_available_updates_count( $args = array(), $assoc_args = array(), $website = false ) { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR - complexity.
901 + $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
902 + $theme_upgrades = json_decode( $website->theme_upgrades, true );
926 903
927 - $translations = json_decode( $website->translation_upgrades, true );
928 - $wp = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' );
929 - $wp = ! empty( $wp ) ? json_decode( $wp, true ) : array();
904 + if ( $website->is_ignorePluginUpdates ) {
905 + $plugin_upgrades = array();
906 + }
907 + if ( $website->is_ignoreThemeUpdates ) {
908 + $theme_upgrades = array();
909 + }
930 910
931 - if ( count( $wp ) > 0 ) {
932 - $wp = 1;
933 - } else {
934 - $wp = 0;
935 - }
936 - $total = array_merge( $plugin_upgrades, $theme_upgrades, $translations );
937 - $data = array(
938 - 'total' => count( $total ) + $wp,
939 - 'wp' => $wp,
940 - 'plugins' => count( $plugin_upgrades ),
941 - 'themes' => count( $themes ),
942 - 'translations' => count( $translations ),
943 - );
911 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
912 + if ( is_array( $plugin_upgrades ) && ! empty( $plugin_upgrades ) ) {
913 + $ignored_plugins = json_decode( $website->ignored_plugins, true );
914 + if ( is_array( $ignored_plugins ) ) {
915 + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
944 916
945 - \WP_CLI::line( '' );
946 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Updates', 'mainwp' ) . '%n' ) );
947 - \WP_CLI::line( '' );
917 + }
918 + $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
919 + if ( is_array( $ignored_plugins ) ) {
920 + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
948 921
949 - \WP_CLI::line( \WP_CLI::colorize( '%gWordPress:%n ' ) . $data['wp'] );
950 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugins:%n ' ) . $data['plugins'] );
951 - \WP_CLI::line( \WP_CLI::colorize( '%gThemes:%n ' ) . $data['themes'] );
952 - \WP_CLI::line( \WP_CLI::colorize( '%gTranslations:%n ' ) . $data['translations'] );
953 - \WP_CLI::line( '' );
954 - \WP_CLI::line( \WP_CLI::colorize( '%gTotal:%n ' ) . $data['total'] );
955 - \WP_CLI::line( '' );
956 - }
922 + }
923 + }
957 924
958 - /**
959 - * Lists all abandoned plugins on a child site.
960 - *
961 - * Command Example: wp mainwp site --site-abandoned-plugins [<websiteid>].
962 - *
963 - * @param array $args Arguments.
964 - * @param array $assoc_args Arguments.
965 - * @param object $website Object containing child site data.
966 - */
967 - public static function callback_site_site_abandoned_plugins( $args = array(), $assoc_args = array(), $website = false ) {
968 - $plugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_info' );
969 - $plugins = ! empty( $plugins ) ? json_decode( $plugins, true ) : array();
925 + if ( is_array( $theme_upgrades ) && ! empty( $theme_upgrades ) ) {
926 + $ignored_themes = json_decode( $website->ignored_themes, true );
927 + if ( is_array( $ignored_themes ) ) {
928 + $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
929 + }
970 930
971 - \WP_CLI::line( '' );
972 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Abandoned Plugins', 'mainwp' ) . '%n' ) );
973 - \WP_CLI::line( '' );
931 + $ignored_themes = json_decode( $userExtension->ignored_themes, true );
932 + if ( is_array( $ignored_themes ) ) {
933 + $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
934 + }
935 + }
974 936
975 - foreach ( $plugins as $plugin ) {
976 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $plugin['Name'] );
977 - \WP_CLI::line( \WP_CLI::colorize( '%gURI:%n ' ) . $plugin['PluginURI'] );
978 - \WP_CLI::line( \WP_CLI::colorize( '%gVersion:%n ' ) . $plugin['Version'] );
979 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest Update:%n ' ) . date( 'F j, Y', $plugin['last_updated'] ) ); // phpcs:ignore -- local time.
980 - \WP_CLI::line( '' );
981 - }
982 - }
937 + $translations = json_decode( $website->translation_upgrades, true );
938 + $wp = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' );
939 + $wp = ! empty( $wp ) ? json_decode( $wp, true ) : array();
983 940
984 - /**
985 - * Returns the number of abaindoned plugins on a child site.
986 - *
987 - * Command Example: wp mainwp site --site-abandoned-plugins-count [<websiteid>].
988 - *
989 - * @param array $args Arguments.
990 - * @param array $assoc_args Arguments.
991 - * @param object $website Object containing child site data.
992 - */
993 - public static function callback_site_site_abandoned_plugins_count( $args = array(), $assoc_args = array(), $website = false ) {
994 - $plugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_info' );
995 - $plugins = ! empty( $plugins ) ? json_decode( $plugins, true ) : array();
941 + if ( ! empty( $wp ) ) {
942 + $wp = 1;
943 + } else {
944 + $wp = 0;
945 + }
946 + $total = array_merge( $plugin_upgrades, $theme_upgrades, $translations );
947 + $data = array(
948 + 'total' => count( $total ) + $wp,
949 + 'wp' => $wp,
950 + 'plugins' => count( $plugin_upgrades ),
951 + 'themes' => count( $theme_upgrades ),
952 + 'translations' => count( $translations ),
953 + );
996 954
997 - \WP_CLI::line( '' );
998 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . ' ' . esc_html__( 'Abandoned plugins: ', 'mainwp' ) . '%n' . count( $plugins ) ) );
999 - \WP_CLI::line( '' );
1000 - }
955 + \WP_CLI::line( '' );
956 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Updates', 'mainwp' ) . '%n' ) );
957 + \WP_CLI::line( '' );
1001 958
1002 - /**
1003 - * Lists all abandoned themes on a child site.
1004 - *
1005 - * Command Example: wp mainwp site --site-abandoned-themes [<websiteid>].
1006 - *
1007 - * @param array $args Arguments.
1008 - * @param array $assoc_args Arguments.
1009 - * @param object $website Object containing child site data.
1010 - */
1011 - public static function callback_site_site_abandoned_themes( $args = array(), $assoc_args = array(), $website = false ) {
1012 - $themes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_info' );
1013 - $themes = ! empty( $themes ) ? json_decode( $themes, true ) : array();
959 + \WP_CLI::line( \WP_CLI::colorize( '%gWordPress:%n ' ) . $data['wp'] );
960 + \WP_CLI::line( \WP_CLI::colorize( '%gPlugins:%n ' ) . $data['plugins'] );
961 + \WP_CLI::line( \WP_CLI::colorize( '%gThemes:%n ' ) . $data['themes'] );
962 + \WP_CLI::line( \WP_CLI::colorize( '%gTranslations:%n ' ) . $data['translations'] );
963 + \WP_CLI::line( '' );
964 + \WP_CLI::line( \WP_CLI::colorize( '%gTotal:%n ' ) . $data['total'] );
965 + \WP_CLI::line( '' );
966 + }
1014 967
1015 - \WP_CLI::line( '' );
1016 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Abandoned Themes', 'mainwp' ) . '%n' ) );
1017 - \WP_CLI::line( '' );
968 + /**
969 + * Lists all abandoned plugins on a child site.
970 + *
971 + * Command Example: wp mainwp site --site-abandoned-plugins [<websiteid>].
972 + *
973 + * @param array $args Arguments.
974 + * @param array $assoc_args Arguments.
975 + * @param object $website Object containing child site data.
976 + */
977 + public static function callback_site_site_abandoned_plugins( $args = array(), $assoc_args = array(), $website = false ) {
978 + $plugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_info' );
979 + $plugins = ! empty( $plugins ) ? json_decode( $plugins, true ) : array();
1018 980
1019 - foreach ( $themes as $theme ) {
1020 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $theme['Name'] );
1021 - \WP_CLI::line( \WP_CLI::colorize( '%gVersion:%n ' ) . $theme['Version'] );
1022 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest Update:%n ' ) . date( 'F j, Y', $theme['last_updated'] ) ); // phpcs:ignore -- local time.
1023 - \WP_CLI::line( '' );
1024 - }
1025 - }
981 + \WP_CLI::line( '' );
982 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Abandoned Plugins', 'mainwp' ) . '%n' ) );
983 + \WP_CLI::line( '' );
1026 984
1027 - /**
1028 - * Returns the number of abandoned themes on a child site.
1029 - *
1030 - * Command Example: wp mainwp site --site-abandoned-themes-count [<websiteid>].
1031 - *
1032 - * @param array $args Arguments.
1033 - * @param array $assoc_args Arguments.
1034 - * @param object $website Object containing child site data.
1035 - */
1036 - public static function callback_site_site_abandoned_themes_count( $args = array(), $assoc_args = array(), $website = false ) {
1037 - $themes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_info' );
1038 - $themes = ! empty( $themes ) ? json_decode( $themes, true ) : array();
985 + foreach ( $plugins as $plugin ) {
986 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $plugin['Name'] );
987 + \WP_CLI::line( \WP_CLI::colorize( '%gURI:%n ' ) . $plugin['PluginURI'] );
988 + \WP_CLI::line( \WP_CLI::colorize( '%gVersion:%n ' ) . $plugin['Version'] );
989 + \WP_CLI::line( \WP_CLI::colorize( '%gLatest Update:%n ' ) . date( 'F j, Y', $plugin['last_updated'] ) ); // phpcs:ignore -- local time.
990 + \WP_CLI::line( '' );
991 + }
992 + }
1039 993
1040 - \WP_CLI::line( '' );
1041 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . ' ' . esc_html__( 'Abandoned themes: ', 'mainwp' ) . '%n' . count( $themes ) ) );
1042 - \WP_CLI::line( '' );
1043 - }
994 + /**
995 + * Returns the number of abaindoned plugins on a child site.
996 + *
997 + * Command Example: wp mainwp site --site-abandoned-plugins-count [<websiteid>].
998 + *
999 + * @param array $args Arguments.
1000 + * @param array $assoc_args Arguments.
1001 + * @param object $website Object containing child site data.
1002 + */
1003 + public static function callback_site_site_abandoned_plugins_count( $args = array(), $assoc_args = array(), $website = false ) {
1004 + $plugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_info' );
1005 + $plugins = ! empty( $plugins ) ? json_decode( $plugins, true ) : array();
1044 1006
1045 - /**
1046 - * Returns child site HTTP status.
1047 - *
1048 - * Command Example: wp mainwp site --site-http-status [<websiteid>].
1049 - *
1050 - * @param array $args Arguments.
1051 - * @param array $assoc_args Arguments.
1052 - * @param object $website Object containing child site data.
1053 - */
1054 - public static function callback_site_site_http_status( $args = array(), $assoc_args = array(), $website = false ) {
1055 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1056 - MainWP_Monitoring_Handler::handle_check_website( $website );
1057 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Process ran successfully on ', 'mainwp' ) . $website->name . '%n' ) );
1058 - }
1007 + \WP_CLI::line( '' );
1008 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . ' ' . esc_html__( 'Abandoned plugins: ', 'mainwp' ) . '%n' . count( $plugins ) ) );
1009 + \WP_CLI::line( '' );
1010 + }
1059 1011
1060 - /**
1061 - * Returns child site Health score.
1062 - *
1063 - * Command Example: wp mainwp site --site-health-score [<websiteid>].
1064 - *
1065 - * @param array $args Arguments.
1066 - * @param array $assoc_args Arguments.
1067 - * @param object $website Object containing child site data.
1068 - */
1069 - public static function callback_site_site_health_score( $args = array(), $assoc_args = array(), $website = false ) {
1070 - $website = MainWP_DB::instance()->get_website_by_id( $website->id, false, array( 'health_site_status' ) );
1071 - $health_status = isset( $website->health_site_status ) ? json_decode( $website->health_site_status, true ) : array();
1072 - $hstatus = MainWP_Utility::get_site_health( $health_status );
1073 - $hval = $hstatus['val'];
1074 - $critical = $hstatus['critical'];
1075 - if ( 80 <= $hval && empty( $critical ) ) {
1076 - $health_score = 'Good';
1077 - } else {
1078 - $health_score = 'Should be improved';
1079 - }
1012 + /**
1013 + * Lists all abandoned themes on a child site.
1014 + *
1015 + * Command Example: wp mainwp site --site-abandoned-themes [<websiteid>].
1016 + *
1017 + * @param array $args Arguments.
1018 + * @param array $assoc_args Arguments.
1019 + * @param object $website Object containing child site data.
1020 + */
1021 + public static function callback_site_site_abandoned_themes( $args = array(), $assoc_args = array(), $website = false ) {
1022 + $themes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_info' );
1023 + $themes = ! empty( $themes ) ? json_decode( $themes, true ) : array();
1080 1024
1081 - \WP_CLI::line( '' );
1082 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . ' Health: %n ' ) . $health_score );
1083 - \WP_CLI::line( '' );
1084 - }
1025 + \WP_CLI::line( '' );
1026 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Abandoned Themes', 'mainwp' ) . '%n' ) );
1027 + \WP_CLI::line( '' );
1085 1028
1086 - /**
1087 - * Lists child site security issues.
1088 - *
1089 - * Command Example: wp mainwp site --site-security-issues [<websiteid>].
1090 - *
1091 - * @param array $args Arguments.
1092 - * @param array $assoc_args Arguments.
1093 - * @param object $website Object containing child site data.
1094 - */
1095 - public static function callback_site_site_security_issues( $args = array(), $assoc_args = array(), $website = false ) {
1096 - $data = MainWP_Connect::fetch_url_authed( $website, 'security' );
1029 + foreach ( $themes as $theme ) {
1030 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $theme['Name'] );
1031 + \WP_CLI::line( \WP_CLI::colorize( '%gVersion:%n ' ) . $theme['Version'] );
1032 + \WP_CLI::line( \WP_CLI::colorize( '%gLatest Update:%n ' ) . date( 'F j, Y', $theme['last_updated'] ) ); // phpcs:ignore -- local time.
1033 + \WP_CLI::line( '' );
1034 + }
1035 + }
1097 1036
1098 - \WP_CLI::line( '' );
1099 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Security Issues', 'mainwp' ) . '%n' ) );
1100 - \WP_CLI::line( '' );
1037 + /**
1038 + * Returns the number of abandoned themes on a child site.
1039 + *
1040 + * Command Example: wp mainwp site --site-abandoned-themes-count [<websiteid>].
1041 + *
1042 + * @param array $args Arguments.
1043 + * @param array $assoc_args Arguments.
1044 + * @param object $website Object containing child site data.
1045 + */
1046 + public static function callback_site_site_abandoned_themes_count( $args = array(), $assoc_args = array(), $website = false ) {
1047 + $themes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_info' );
1048 + $themes = ! empty( $themes ) ? json_decode( $themes, true ) : array();
1101 1049
1102 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Directories listing prevented:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['listing'] ? 'NO' : 'YES' ) );
1103 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'WordPress version hidden:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['wp_version'] ? 'NO' : 'YES' ) );
1104 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Really Simple Discovery meta tag removed:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['rsd'] ? 'NO' : 'YES' ) );
1105 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Windows Live Writer meta tag removed:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['wlw'] ? 'NO' : 'YES' ) );
1106 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Database error reporting disabled:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['db_reporting'] ? 'NO' : 'YES' ) );
1107 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'PHP error reporting disabled:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['php_reporting'] ? 'NO' : 'YES' ) );
1108 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Version information removed from URLs:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['versions'] ? 'NO' : 'YES' ) );
1109 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Registered version information removed from URLs:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['registered_versions'] ? 'NO' : 'YES' ) );
1110 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'readme.html removed from WordPress root:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['readme'] ? 'NO' : 'YES' ) );
1111 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Administrator username is not "admin":', 'mainwp' ) . '%n ' ) . ( 'N' === $data['admin'] ? 'NO' : 'YES' ) );
1112 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'WordPress is not up to date:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['wp_uptodate'] ? 'NO' : 'YES' ) );
1113 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'PHP version does not match the WordPress requirement:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['phpversion_matched'] ? 'NO' : 'YES' ) );
1114 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'SSL protocol is not in place:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['sslprotocol'] ? 'NO' : 'YES' ) );
1115 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'WP Config debugging is enabled:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['debug_disabled'] ? 'NO' : 'YES' ) );
1116 - }
1050 + \WP_CLI::line( '' );
1051 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . ' ' . esc_html__( 'Abandoned themes: ', 'mainwp' ) . '%n' . count( $themes ) ) );
1052 + \WP_CLI::line( '' );
1053 + }
1117 1054
1118 - /**
1119 - * Adds child site.
1120 - *
1121 - * Command Example: wp mainwp site --add-site [<websiteid>].
1122 - *
1123 - * @param array $args Arguments.
1124 - * @param array $assoc_args Arguments.
1125 - * @param object $website Object containing child site data.
1126 - */
1127 - public static function callback_site_add_site( $args = array(), $assoc_args = array(), $website = false ) {
1128 - $fields = self::get_cli_params( $args, $assoc_args, 'add-site' );
1129 - $data = MainWP_Manage_Sites_Handler::rest_api_add_site( $fields );
1130 - if ( is_array( $data ) && ! empty( $data['siteid'] ) ) {
1131 - \WP_CLI::success( ' -> Add site result: ' . print_r( $data, true ) ); // phpcs:ignore -- for cli result.
1132 - } else {
1133 - \WP_CLI::error( ' -> Add site result: ' . print_r( $data, true ) ); // phpcs:ignore -- for cli result.
1134 - }
1135 - }
1055 + /**
1056 + * Returns child site HTTP status.
1057 + *
1058 + * Command Example: wp mainwp site --site-http-status [<websiteid>].
1059 + *
1060 + * @param array $args Arguments.
1061 + * @param array $assoc_args Arguments.
1062 + * @param object $website Object containing child site data.
1063 + */
1064 + public static function callback_site_site_http_status( $args = array(), $assoc_args = array(), $website = false ) {
1065 + \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1066 + MainWP_Monitoring_Handler::handle_check_website( $website );
1067 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Process ran successfully on ', 'mainwp' ) . $website->name . '%n' ) );
1068 + }
1136 1069
1137 - /**
1138 - * Edits child site.
1139 - *
1140 - * Command Example: wp mainwp site --edit-site [<websiteid>].
1141 - *
1142 - * @param array $args Arguments.
1143 - * @param array $assoc_args Arguments.
1144 - * @param object $website Object containing child site data.
1145 - */
1146 - public static function callback_site_edit_site( $args = array(), $assoc_args = array(), $website = false ) {
1147 - $fields = self::get_cli_params( $args, $assoc_args, 'edit-site' );
1148 - $data = MainWP_DB_Common::instance()->rest_api_update_website( $website->id, $fields );
1149 - $website = MainWP_DB::instance()->get_website_by_id( $website->id );
1150 - \WP_CLI::line( ' -> ' . $website->name . ' (' . $website->url . ')' );
1151 - \WP_CLI::line( ' -> Edit site result: ' . ( $data ? 'successed' : 'failed' ) );
1152 - }
1070 + /**
1071 + * Returns child site Health score.
1072 + *
1073 + * Command Example: wp mainwp site --site-health-score [<websiteid>].
1074 + *
1075 + * @param array $args Arguments.
1076 + * @param array $assoc_args Arguments.
1077 + * @param object $website Object containing child site data.
1078 + */
1079 + public static function callback_site_site_health_score( $args = array(), $assoc_args = array(), $website = false ) {
1080 + $website = MainWP_DB::instance()->get_website_by_id( $website->id, false, array( 'health_site_status' ) );
1081 + $health_status = isset( $website->health_site_status ) ? json_decode( $website->health_site_status, true ) : array();
1082 + $hstatus = MainWP_Utility::get_site_health( $health_status );
1083 + $hval = $hstatus['val'];
1084 + $critical = $hstatus['critical'];
1085 + if ( 80 <= $hval && empty( $critical ) ) {
1086 + $health_score = 'Good';
1087 + } else {
1088 + $health_score = 'Should be improved';
1089 + }
1153 1090
1154 - /**
1155 - * Syncs child site.
1156 - *
1157 - * Command Example: wp mainwp site --sync-site [<websiteid>].
1158 - *
1159 - * @param array $args Arguments.
1160 - * @param array $assoc_args Arguments.
1161 - * @param object $website Object containing child site data.
1162 - */
1163 - public static function callback_site_sync_site( $args = array(), $assoc_args = array(), $website = false ) {
1164 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1165 - $error = false;
1166 - try {
1167 - MainWP_Sync::sync_site( $website );
1168 - } catch ( \Exception $e ) {
1169 - $error = $e->getMessage();
1170 - }
1091 + \WP_CLI::line( '' );
1092 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . ' Health: %n ' ) . $health_score );
1093 + \WP_CLI::line( '' );
1094 + }
1171 1095
1172 - if ( empty( $error ) ) {
1173 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' synced successfully.', 'mainwp' ) . '%n' ) );
1174 - } else {
1175 - \WP_CLI::line( \WP_CLI::colorize( '%r' . esc_html__( 'Process failed with error:', 'mainwp' ) . '%n' ) );
1176 - \WP_CLI::line( $error );
1177 - }
1178 - }
1096 + /**
1097 + * Lists child site security issues.
1098 + *
1099 + * Command Example: wp mainwp site --site-security-issues [<websiteid>].
1100 + *
1101 + * @param array $args Arguments.
1102 + * @param array $assoc_args Arguments.
1103 + * @param object $website Object containing child site data.
1104 + */
1105 + public static function callback_site_site_security_issues( $args = array(), $assoc_args = array(), $website = false ) {
1106 + $data = MainWP_Connect::fetch_url_authed( $website, 'security' );
1179 1107
1180 - /**
1181 - * Reconnects child site.
1182 - *
1183 - * Command Example: wp mainwp site --reconnect-site [<websiteid>].
1184 - *
1185 - * @param array $args Arguments.
1186 - * @param array $assoc_args Arguments.
1187 - * @param object $website Object containing child site data.
1188 - */
1189 - public static function callback_site_reconnect_site( $args = array(), $assoc_args = array(), $website = false ) {
1190 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1191 - $error = false;
1192 - try {
1193 - MainWP_Manage_Sites_View::m_reconnect_site( $website );
1194 - } catch ( \Exception $e ) {
1195 - $error = $e->getMessage();
1196 - }
1108 + \WP_CLI::line( '' );
1109 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Potential Secuirty Issues', 'mainwp' ) . '%n' ) );
1110 + \WP_CLI::line( '' );
1197 1111
1198 - if ( empty( $error ) ) {
1199 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' reconnected successfully.', 'mainwp' ) . '%n' ) );
1200 - } else {
1201 - \WP_CLI::line( \WP_CLI::colorize( '%r' . esc_html__( 'Process failed with error:', 'mainwp' ) . '%n' ) );
1202 - \WP_CLI::line( $error );
1203 - }
1204 - }
1112 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Database error reporting disabled:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['db_reporting'] ? 'NO' : 'YES' ) );
1113 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'PHP error reporting disabled:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['php_reporting'] ? 'NO' : 'YES' ) );
1114 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'WordPress is not up to date:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['wp_uptodate'] ? 'NO' : 'YES' ) );
1115 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'PHP version does not match the WordPress requirement:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['phpversion_matched'] ? 'NO' : 'YES' ) );
1116 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'SSL protocol is not in place:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['sslprotocol'] ? 'NO' : 'YES' ) );
1117 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'WP Config debugging is enabled:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['debug_disabled'] ? 'NO' : 'YES' ) );
1118 + }
1205 1119
1206 - /**
1207 - * Disconnects child site.
1208 - *
1209 - * Command Example: wp mainwp site --disconnect-site [<websiteid>].
1210 - *
1211 - * @param array $args Arguments.
1212 - * @param array $assoc_args Arguments.
1213 - * @param object $website Object containing child site data.
1214 - */
1215 - public static function callback_site_disconnect_site( $args = array(), $assoc_args = array(), $website = false ) {
1216 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1120 + /**
1121 + * Adds child site.
1122 + *
1123 + * Command Example: wp mainwp site --add-site [<websiteid>].
1124 + *
1125 + * @param array $args Arguments.
1126 + * @param array $assoc_args Arguments.
1127 + * @param object $website Object containing child site data.
1128 + */
1129 + public static function callback_site_add_site( $args = array(), $assoc_args = array(), $website = false ) {
1130 + $fields = static::get_cli_params( $args, $assoc_args, 'add-site' );
1131 + $data = MainWP_Manage_Sites_Handler::rest_api_add_site( $fields );
1132 + if ( is_array( $data ) && ! empty( $data['siteid'] ) ) {
1133 + \WP_CLI::success( ' -> Add site result: ' . print_r( $data, true ) ); // phpcs:ignore -- for cli result.
1134 + } else {
1135 + \WP_CLI::error( ' -> Add site result: ' . print_r( $data, true ) ); // phpcs:ignore -- for cli result.
1136 + }
1137 + }
1217 1138
1218 - $error = false;
1219 - try {
1220 - MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
1221 - } catch ( \Exception $e ) {
1222 - $error = $e->getMessage();
1223 - }
1139 + /**
1140 + * Edits child site.
1141 + *
1142 + * Command Example: wp mainwp site --edit-site [<websiteid>].
1143 + *
1144 + * @param array $args Arguments.
1145 + * @param array $assoc_args Arguments.
1146 + * @param object $website Object containing child site data.
1147 + */
1148 + public static function callback_site_edit_site( $args = array(), $assoc_args = array(), $website = false ) {
1149 + $fields = static::get_cli_params( $args, $assoc_args, 'edit-site' );
1150 + $data = MainWP_DB_Common::instance()->rest_api_update_website( $website->id, $fields );
1151 + $website = MainWP_DB::instance()->get_website_by_id( $website->id );
1152 + \WP_CLI::line( ' -> ' . $website->name . ' (' . $website->url . ')' );
1153 + \WP_CLI::line( ' -> Edit site result: ' . ( $data ? 'successed' : 'failed' ) );
1154 + }
1224 1155
1225 - if ( empty( $error ) ) {
1226 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' disconnected successfully.', 'mainwp' ) . '%n' ) );
1227 - } else {
1228 - \WP_CLI::line( \WP_CLI::colorize( '%r' . esc_html__( 'Process failed with error:', 'mainwp' ) . '%n' ) );
1229 - \WP_CLI::line( $error );
1230 - }
1231 - }
1156 + /**
1157 + * Syncs child site.
1158 + *
1159 + * Command Example: wp mainwp site --sync-site [<websiteid>].
1160 + *
1161 + * @param array $args Arguments.
1162 + * @param array $assoc_args Arguments.
1163 + * @param object $website Object containing child site data.
1164 + */
1165 + public static function callback_site_sync_site( $args = array(), $assoc_args = array(), $website = false ) {
1166 + \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1167 + $error = false;
1168 + try {
1169 + MainWP_Sync::sync_site( $website );
1170 + } catch ( \Exception $e ) {
1171 + $error = $e->getMessage();
1172 + }
1232 1173
1233 - /**
1234 - * Removes child site from the MainWP Dashboard.
1235 - *
1236 - * Command Example: wp mainwp site --remove-site [<websiteid>].
1237 - *
1238 - * @param array $args Arguments.
1239 - * @param array $assoc_args Arguments.
1240 - * @param object $website Object containing child site data.
1241 - */
1242 - public static function callback_site_remove_site( $args = array(), $assoc_args = array(), $website = false ) {
1243 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1244 - $data = MainWP_Manage_Sites_Handler::remove_website( $website->id );
1245 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Site removed successfully.', 'mainwp' ) . '%n' ) );
1246 - }
1174 + if ( empty( $error ) ) {
1175 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' synced successfully.', 'mainwp' ) . '%n' ) );
1176 + } else {
1177 + \WP_CLI::line( \WP_CLI::colorize( '%r' . esc_html__( 'Process failed with error:', 'mainwp' ) . '%n' ) );
1178 + \WP_CLI::line( $error );
1179 + }
1180 + }
1247 1181
1248 - /**
1249 - * Updates WP Core on a child site.
1250 - *
1251 - * Command Example: wp mainwp site --site-update-wordpress [<websiteid>].
1252 - *
1253 - * @param array $args Arguments.
1254 - * @param array $assoc_args Arguments.
1255 - * @param object $website Object containing child site data.
1256 - */
1257 - public static function callback_site_site_update_wordpress( $args = array(), $assoc_args = array(), $website = false ) {
1258 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1259 - $error = false;
1260 - try {
1261 - $data = MainWP_Updates_Handler::upgrade_website( $website );
1262 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' updated successfully.', 'mainwp' ) . '%n' ) );
1263 - } catch ( \Exception $e ) {
1264 - \WP_CLI::error( 'Updates failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
1265 - if ( $e->getMesage() === 'WPERROR' ) {
1266 - \WP_CLI::debug( 'Error: ' . MainWP_Utility::value_to_string( $e->get_message_extra(), 1 ) );
1267 - }
1268 - }
1269 - }
1182 + /**
1183 + * Reconnects child site.
1184 + *
1185 + * Command Example: wp mainwp site --reconnect-site [<websiteid>].
1186 + *
1187 + * @param array $args Arguments.
1188 + * @param array $assoc_args Arguments.
1189 + * @param object $website Object containing child site data.
1190 + */
1191 + public static function callback_site_reconnect_site( $args = array(), $assoc_args = array(), $website = false ) {
1192 + \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1193 + $error = false;
1194 + try {
1195 + MainWP_Manage_Sites_View::m_reconnect_site( $website );
1196 + } catch ( \Exception $e ) {
1197 + $error = $e->getMessage();
1198 + }
1270 1199
1271 - /**
1272 - * Updates all plugins on a child site.
1273 - *
1274 - * Command Example: wp mainwp site --site-update-plugins [<websiteid>].
1275 - *
1276 - * @param array $args Arguments.
1277 - * @param array $assoc_args Arguments.
1278 - * @param object $website Object containing child site data.
1279 - */
1280 - public static function callback_site_site_update_plugins( $args = array(), $assoc_args = array(), $website = false ) {
1281 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1200 + if ( empty( $error ) ) {
1201 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' reconnected successfully.', 'mainwp' ) . '%n' ) );
1202 + } else {
1203 + \WP_CLI::line( \WP_CLI::colorize( '%r' . esc_html__( 'Process failed with error:', 'mainwp' ) . '%n' ) );
1204 + \WP_CLI::line( $error );
1205 + }
1206 + }
1282 1207
1283 - $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
1208 + /**
1209 + * Disconnects child site.
1210 + *
1211 + * Command Example: wp mainwp site --disconnect-site [<websiteid>].
1212 + *
1213 + * @param array $args Arguments.
1214 + * @param array $assoc_args Arguments.
1215 + * @param object $website Object containing child site data.
1216 + */
1217 + public static function callback_site_disconnect_site( $args = array(), $assoc_args = array(), $website = false ) {
1218 + \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1284 1219
1285 - if ( $website->is_ignorePluginUpdates ) {
1286 - $plugin_upgrades = array();
1287 - }
1220 + $error = false;
1221 + try {
1222 + MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
1223 + } catch ( \Exception $e ) {
1224 + $error = $e->getMessage();
1225 + }
1288 1226
1289 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1290 - if ( is_array( $plugin_upgrades ) && ! empty( $plugin_upgrades ) ) {
1291 - $ignored_plugins = json_decode( $website->ignored_plugins, true );
1292 - if ( is_array( $ignored_plugins ) ) {
1293 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
1294 - }
1295 - $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
1296 - if ( is_array( $ignored_plugins ) ) {
1297 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
1298 - }
1299 - }
1227 + if ( empty( $error ) ) {
1228 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' disconnected successfully.', 'mainwp' ) . '%n' ) );
1229 + } else {
1230 + \WP_CLI::line( \WP_CLI::colorize( '%r' . esc_html__( 'Process failed with error:', 'mainwp' ) . '%n' ) );
1231 + \WP_CLI::line( $error );
1232 + }
1233 + }
1300 1234
1301 - $slugs = array();
1302 - foreach ( $plugin_upgrades as $slug => $plugin ) {
1303 - $slugs[] = $slug;
1304 - }
1305 - $list = urldecode( implode( ',', $slugs ) );
1235 + /**
1236 + * Removes child site from the MainWP Dashboard.
1237 + *
1238 + * Command Example: wp mainwp site --remove-site [<websiteid>].
1239 + *
1240 + * @param array $args Arguments.
1241 + * @param array $assoc_args Arguments.
1242 + * @param object $website Object containing child site data.
1243 + */
1244 + public static function callback_site_remove_site( $args = array(), $assoc_args = array(), $website = false ) {
1245 + \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1246 + MainWP_Manage_Sites_Handler::remove_website( $website->id );
1247 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Site removed successfully.', 'mainwp' ) . '%n' ) );
1248 + }
1306 1249
1307 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' plugins updated successfully.', 'mainwp' ) . '%n' ) );
1250 + /**
1251 + * Updates WP Core on a child site.
1252 + *
1253 + * Command Example: wp mainwp site --site-update-wordpress [<websiteid>].
1254 + *
1255 + * @param array $args Arguments.
1256 + * @param array $assoc_args Arguments.
1257 + * @param object $website Object containing child site data.
1258 + */
1259 + public static function callback_site_site_update_wordpress( $args = array(), $assoc_args = array(), $website = false ) {
1260 + \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1261 + try {
1262 + MainWP_Updates_Handler::upgrade_website( $website );
1263 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' updated successfully.', 'mainwp' ) . '%n' ) );
1264 + } catch ( \Exception $e ) {
1265 + \WP_CLI::error( 'Updates failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
1266 + if ( $e->getMesage() === 'WPERROR' ) {
1267 + \WP_CLI::debug( 'Error: ' . MainWP_Utility::value_to_string( $e->get_message_extra(), 1 ) );
1268 + }
1269 + }
1270 + }
1308 1271
1309 - try {
1310 - MainWP_Connect::fetch_url_authed(
1311 - $website,
1312 - 'upgradeplugintheme',
1313 - array(
1314 - 'type' => 'plugin',
1315 - 'list' => $list,
1316 - )
1317 - );
1318 - } catch ( \Exception $e ) {
1319 - $error = MainWP_Error_Helper::get_console_error_message( $e );
1320 - }
1321 - }
1272 + /**
1273 + * Updates all plugins on a child site.
1274 + *
1275 + * Command Example: wp mainwp site --site-update-plugins [<websiteid>].
1276 + *
1277 + * @param array $args Arguments.
1278 + * @param array $assoc_args Arguments.
1279 + * @param object $website Object containing child site data.
1280 + */
1281 + public static function callback_site_site_update_plugins( $args = array(), $assoc_args = array(), $website = false ) {
1282 + \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1322 1283
1323 - /**
1324 - * Updates all themes on a child site.
1325 - *
1326 - * Command Example: wp mainwp site --site-update-themes [<websiteid>].
1327 - *
1328 - * @param array $args Arguments.
1329 - * @param array $assoc_args Arguments.
1330 - * @param object $website Object containing child site data.
1331 - */
1332 - public static function callback_site_site_update_themes( $args = array(), $assoc_args = array(), $website = false ) {
1333 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1334 - $theme_upgrades = json_decode( $website->theme_upgrades, true );
1335 - $slugs = array();
1336 - foreach ( $theme_upgrades as $slug => $theme ) {
1337 - $slugs[] = $slug;
1338 - }
1339 - $list = urldecode( implode( ',', $slugs ) );
1284 + $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
1340 1285
1341 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' themes updated successfully.', 'mainwp' ) . '%n' ) );
1286 + if ( $website->is_ignorePluginUpdates ) {
1287 + $plugin_upgrades = array();
1288 + }
1342 1289
1343 - try {
1344 - MainWP_Connect::fetch_url_authed(
1345 - $website,
1346 - 'upgradeplugintheme',
1347 - array(
1348 - 'type' => 'theme',
1349 - 'list' => $list,
1350 - )
1351 - );
1352 - } catch ( \Exception $e ) {
1353 - $error = MainWP_Error_Helper::get_console_error_message( $e );
1354 - }
1355 - }
1290 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1291 + if ( is_array( $plugin_upgrades ) && ! empty( $plugin_upgrades ) ) {
1292 + $ignored_plugins = json_decode( $website->ignored_plugins, true );
1293 + if ( is_array( $ignored_plugins ) ) {
1294 + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
1356 1295
1357 - /**
1358 - * Updates translations on a child site.
1359 - *
1360 - * Command Example: wp mainwp site --site-update-translations [<websiteid>].
1361 - *
1362 - * @param array $args Arguments.
1363 - * @param array $assoc_args Arguments.
1364 - * @param object $website Object containing child site data.
1365 - */
1366 - public static function callback_site_site_update_translations( $args = array(), $assoc_args = array(), $website = false ) {
1367 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1296 + }
1297 + $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
1298 + if ( is_array( $ignored_plugins ) ) {
1299 + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
1368 1300
1369 - $translation_upgrades = json_decode( $website->translation_upgrades, true );
1370 - $slugs = array();
1371 - foreach ( $translation_upgrades as $translation_upgrade ) {
1372 - $slugs[] = $translation_upgrade['slug'];
1373 - }
1374 - $list = urldecode( implode( ',', $slugs ) );
1301 + }
1302 + }
1375 1303
1376 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' translations updated successfully.', 'mainwp' ) . '%n' ) );
1304 + $slugs = array();
1305 + foreach ( $plugin_upgrades as $slug => $plugin ) {
1306 + $slugs[] = $slug;
1307 + }
1308 + $list = urldecode( implode( ',', $slugs ) );
1377 1309
1378 - try {
1379 - MainWP_Connect::fetch_url_authed(
1380 - $website,
1381 - 'upgradetranslation',
1382 - array(
1383 - 'type' => 'translation',
1384 - 'list' => $list,
1385 - )
1386 - );
1387 - } catch ( \Exception $e ) {
1388 - $error = MainWP_Error_Helper::get_console_error_message( $e );
1389 - }
1390 - }
1310 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' plugins updated successfully.', 'mainwp' ) . '%n' ) );
1391 1311
1392 - /**
1393 - * Updates single item on a child site.
1394 - *
1395 - * Command Example: wp mainwp site --site-update-item [<websiteid>] --type=[type] --slug=[slug].
1396 - *
1397 - * @param array $args Arguments.
1398 - * @param array $assoc_args Arguments.
1399 - * @param object $website Object containing child site data.
1400 - */
1401 - public static function callback_site_site_update_item( $args = array(), $assoc_args = array(), $website = false ) {
1312 + try {
1313 + MainWP_Connect::fetch_url_authed(
1314 + $website,
1315 + 'upgradeplugintheme',
1316 + array(
1317 + 'type' => 'plugin',
1318 + 'list' => $list,
1319 + )
1320 + );
1321 + } catch ( \Exception $e ) {
1322 + MainWP_Error_Helper::get_console_error_message( $e );
1323 + }
1324 + }
1402 1325
1403 - $params = self::get_cli_params( $args, $assoc_args, array( 'type', 'slug' ) );
1326 + /**
1327 + * Updates all themes on a child site.
1328 + *
1329 + * Command Example: wp mainwp site --site-update-themes [<websiteid>].
1330 + *
1331 + * @param array $args Arguments.
1332 + * @param array $assoc_args Arguments.
1333 + * @param object $website Object containing child site data.
1334 + */
1335 + public static function callback_site_site_update_themes( $args = array(), $assoc_args = array(), $website = false ) {
1336 + \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1337 + $theme_upgrades = json_decode( $website->theme_upgrades, true );
1338 + $slugs = array();
1339 + foreach ( $theme_upgrades as $slug => $theme ) {
1340 + $slugs[] = $slug;
1341 + }
1342 + $list = urldecode( implode( ',', $slugs ) );
1404 1343
1405 - $type = $params['type'];
1406 - $slug = $params['slug'];
1344 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' themes updated successfully.', 'mainwp' ) . '%n' ) );
1407 1345
1408 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1346 + try {
1347 + MainWP_Connect::fetch_url_authed(
1348 + $website,
1349 + 'upgradeplugintheme',
1350 + array(
1351 + 'type' => 'theme',
1352 + 'list' => $list,
1353 + )
1354 + );
1355 + } catch ( \Exception $e ) {
1356 + MainWP_Error_Helper::get_console_error_message( $e );
1357 + }
1358 + }
1409 1359
1410 - try {
1411 - $data = MainWP_Connect::fetch_url_authed(
1412 - $website,
1413 - 'upgradeplugintheme',
1414 - array(
1415 - 'type' => $type,
1416 - 'list' => urldecode( $slug ),
1417 - )
1418 - );
1419 - } catch ( \Exception $e ) {
1420 - $error = MainWP_Error_Helper::get_console_error_message( $e );
1421 - }
1360 + /**
1361 + * Updates translations on a child site.
1362 + *
1363 + * Command Example: wp mainwp site --site-update-translations [<websiteid>].
1364 + *
1365 + * @param array $args Arguments.
1366 + * @param array $assoc_args Arguments.
1367 + * @param object $website Object containing child site data.
1368 + */
1369 + public static function callback_site_site_update_translations( $args = array(), $assoc_args = array(), $website = false ) {
1370 + \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1422 1371
1423 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' item updated successfully.', 'mainwp' ) . '%n' ) );
1424 - }
1372 + $translation_upgrades = json_decode( $website->translation_upgrades, true );
1373 + $slugs = array();
1374 + foreach ( $translation_upgrades as $translation_upgrade ) {
1375 + $slugs[] = $translation_upgrade['slug'];
1376 + }
1377 + $list = urldecode( implode( ',', $slugs ) );
1425 1378
1426 - /**
1427 - * Manages plgins on a child site.
1428 - *
1429 - * Command Example: wp mainwp site --site-manage-plugin [<websiteid>] --action=[action] --plugin=[plugin].
1430 - *
1431 - * Action: activate|deactivate|delete
1432 - * Plugin: plugin slugs separated by ||.
1433 - *
1434 - * @param array $args Arguments.
1435 - * @param array $assoc_args Arguments.
1436 - * @param object $website Object containing child site data.
1437 - */
1438 - public static function callback_site_site_manage_plugin( $args = array(), $assoc_args = array(), $website = false ) {
1439 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1379 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' translations updated successfully.', 'mainwp' ) . '%n' ) );
1440 1380
1441 - $params = self::get_cli_params( $args, $assoc_args, array( 'plugin', 'action' ) );
1442 - $plugin = $params['plugin'];
1443 - $action = $params['action'];
1381 + try {
1382 + MainWP_Connect::fetch_url_authed(
1383 + $website,
1384 + 'upgradetranslation',
1385 + array(
1386 + 'type' => 'translation',
1387 + 'list' => $list,
1388 + )
1389 + );
1390 + } catch ( \Exception $e ) {
1391 + MainWP_Error_Helper::get_console_error_message( $e );
1392 + }
1393 + }
1444 1394
1445 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $plugin . ' ' . $action . 'd' . esc_html__( ' successfully.', 'mainwp' ) . '%n' ) );
1395 + /**
1396 + * Updates single item on a child site.
1397 + *
1398 + * Command Example: wp mainwp site --site-update-item [<websiteid>] --type=[type] --slug=[slug].
1399 + *
1400 + * @param array $args Arguments.
1401 + * @param array $assoc_args Arguments.
1402 + * @param object $website Object containing child site data.
1403 + */
1404 + public static function callback_site_site_update_item( $args = array(), $assoc_args = array(), $website = false ) {
1446 1405
1447 - try {
1448 - MainWP_Connect::fetch_url_authed(
1449 - $website,
1450 - 'plugin_action',
1451 - array(
1452 - 'action' => $action,
1453 - 'plugin' => $plugin,
1454 - )
1455 - );
1456 - } catch ( \Exception $e ) {
1457 - // ok.
1458 - }
1459 - }
1406 + $params = static::get_cli_params( $args, $assoc_args, array( 'type', 'slug' ) );
1460 1407
1461 - /**
1462 - * Manages themes on a child site.
1463 - *
1464 - * Command Example: wp mainwp site --site-manage-theme [<websiteid>] --action=[action] --theme=[theme].
1465 - *
1466 - * action: activate|delete.
1467 - * theme: theme name.
1468 - *
1469 - * @param array $args Arguments.
1470 - * @param array $assoc_args Arguments.
1471 - * @param object $website Object containing child site data.
1472 - */
1473 - public static function callback_site_site_manage_theme( $args = array(), $assoc_args = array(), $website = false ) {
1474 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1408 + $type = $params['type'];
1409 + $slug = $params['slug'];
1475 1410
1476 - $params = self::get_cli_params( $args, $assoc_args, array( 'theme', 'action' ) );
1477 - $theme = $params['theme'];
1478 - $action = $params['action'];
1411 + \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1479 1412
1480 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $theme . ' ' . $action . 'd' . esc_html__( ' successfully.', 'mainwp' ) . '%n' ) );
1413 + try {
1414 + MainWP_Connect::fetch_url_authed(
1415 + $website,
1416 + 'upgradeplugintheme',
1417 + array(
1418 + 'type' => $type,
1419 + 'list' => urldecode( $slug ),
1420 + )
1421 + );
1422 + } catch ( \Exception $e ) {
1423 + MainWP_Error_Helper::get_console_error_message( $e );
1424 + }
1481 1425
1482 - try {
1483 - MainWP_Connect::fetch_url_authed(
1484 - $website,
1485 - 'theme_action',
1486 - array(
1487 - 'action' => $action,
1488 - 'theme' => $theme,
1489 - )
1490 - );
1491 - } catch ( \Exception $e ) {
1492 - // ok.
1493 - }
1494 - }
1426 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' item updated successfully.', 'mainwp' ) . '%n' ) );
1427 + }
1495 1428
1496 - /**
1497 - * Checks child site for HTTP Status.
1498 - *
1499 - * Command Example: wp mainwp site --check-site-http-status [<websiteid>].
1500 - *
1501 - * @param array $args Arguments.
1502 - * @param array $assoc_args Arguments.
1503 - * @param object $website Object containing child site data.
1504 - */
1505 - public static function callback_site_check_site_http_status( $args = array(), $assoc_args = array(), $website = false ) {
1506 - \WP_CLI::line( '' );
1507 - \WP_CLI::line( esc_html__( 'Checking ', 'mainwp' ) . $website->name . ' (' . $website->url . '). ' . esc_html__( 'Please wait... ', 'mainwp' ) );
1508 - \WP_CLI::line( '' );
1509 - $data = MainWP_Monitoring_Handler::handle_check_website( $website );
1510 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'HTTP Status: ', 'mainwp' ) . '%n' . $data['httpCode'] . ' (' . $data['httpCodeString'] . ')' ) );
1511 - \WP_CLI::line( '' );
1512 - }
1429 + /**
1430 + * Manages plgins on a child site.
1431 + *
1432 + * Command Example: wp mainwp site --site-manage-plugin [<websiteid>] --action=[action] --plugin=[plugin].
1433 + *
1434 + * Action: activate|deactivate|delete
1435 + * Plugin: plugin slugs separated by ||.
1436 + *
1437 + * @param array $args Arguments.
1438 + * @param array $assoc_args Arguments.
1439 + * @param object $website Object containing child site data.
1440 + */
1441 + public static function callback_site_site_manage_plugin( $args = array(), $assoc_args = array(), $website = false ) {
1442 + \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1513 1443
1514 - /**
1515 - * Lists all available update for all sites.
1516 - *
1517 - * Command Example: wp mainwp updates --available-updates [<websiteid>].
1518 - *
1519 - * @param array $args Arguments.
1520 - * @param array $assoc_args Arguments.
1521 - */
1522 - public static function callback_updates_available_updates( $args = array(), $assoc_args = array() ) {
1444 + $params = static::get_cli_params( $args, $assoc_args, array( 'plugin', 'action' ) );
1445 + $plugin = $params['plugin'];
1446 + $action = $params['action'];
1523 1447
1524 - \WP_CLI::line( '' );
1525 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Updates', 'mainwp' ) . '%n' ) );
1526 - \WP_CLI::line( '' );
1448 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $plugin . ' ' . $action . 'd' . esc_html__( ' successfully.', 'mainwp' ) . '%n' ) );
1527 1449
1528 - $all_updates = array();
1529 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
1530 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1531 - $wp_upgrades = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' );
1532 - $wp_upgrades = ! empty( $wp_upgrades ) ? json_decode( $wp_upgrades, true ) : array();
1450 + try {
1451 + MainWP_Connect::fetch_url_authed(
1452 + $website,
1453 + 'plugin_action',
1454 + array(
1455 + 'action' => $action,
1456 + 'plugin' => $plugin,
1457 + )
1458 + );
1459 + } catch ( \Exception $e ) {
1460 + // ok.
1461 + }
1462 + }
1533 1463
1534 - $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
1535 - $theme_upgrades = json_decode( $website->theme_upgrades, true );
1536 - $translation_upgrades = json_decode( $website->translation_upgrades, true );
1464 + /**
1465 + * Manages themes on a child site.
1466 + *
1467 + * Command Example: wp mainwp site --site-manage-theme [<websiteid>] --action=[action] --theme=[theme].
1468 + *
1469 + * action: activate|delete.
1470 + * theme: theme name.
1471 + *
1472 + * @param array $args Arguments.
1473 + * @param array $assoc_args Arguments.
1474 + * @param object $website Object containing child site data.
1475 + */
1476 + public static function callback_site_site_manage_theme( $args = array(), $assoc_args = array(), $website = false ) {
1477 + \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1537 1478
1538 - if ( $website->is_ignorePluginUpdates ) {
1539 - $plugin_upgrades = array();
1540 - }
1541 - if ( $website->is_ignoreThemeUpdates ) {
1542 - $theme_upgrades = array();
1543 - }
1479 + $params = static::get_cli_params( $args, $assoc_args, array( 'theme', 'action' ) );
1480 + $theme = $params['theme'];
1481 + $action = $params['action'];
1544 1482
1545 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1546 - if ( is_array( $plugin_upgrades ) && ! empty( $plugin_upgrades ) ) {
1547 - $ignored_plugins = json_decode( $website->ignored_plugins, true );
1548 - if ( is_array( $ignored_plugins ) ) {
1549 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
1550 - }
1551 - $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
1552 - if ( is_array( $ignored_plugins ) ) {
1553 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
1554 - }
1555 - }
1483 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $theme . ' ' . $action . 'd' . esc_html__( ' successfully.', 'mainwp' ) . '%n' ) );
1556 1484
1557 - if ( is_array( $theme_upgrades ) && ! empty( $theme_upgrades ) ) {
1558 - $ignored_themes = json_decode( $website->ignored_themes, true );
1559 - if ( is_array( $ignored_themes ) ) {
1560 - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
1561 - }
1485 + try {
1486 + MainWP_Connect::fetch_url_authed(
1487 + $website,
1488 + 'theme_action',
1489 + array(
1490 + 'action' => $action,
1491 + 'theme' => $theme,
1492 + )
1493 + );
1494 + } catch ( \Exception $e ) {
1495 + // ok.
1496 + }
1497 + }
1562 1498
1563 - $ignored_themes = json_decode( $userExtension->ignored_themes, true );
1564 - if ( is_array( $ignored_themes ) ) {
1565 - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
1566 - }
1567 - }
1499 + /**
1500 + * Checks child site for HTTP Status.
1501 + *
1502 + * Command Example: wp mainwp site --check-site-http-status [<websiteid>].
1503 + *
1504 + * @param array $args Arguments.
1505 + * @param array $assoc_args Arguments.
1506 + * @param object $website Object containing child site data.
1507 + */
1508 + public static function callback_site_check_site_http_status( $args = array(), $assoc_args = array(), $website = false ) {
1509 + \WP_CLI::line( '' );
1510 + \WP_CLI::line( esc_html__( 'Checking ', 'mainwp' ) . $website->name . ' (' . $website->url . '). ' . esc_html__( 'Please wait... ', 'mainwp' ) );
1511 + \WP_CLI::line( '' );
1512 + $data = MainWP_Monitoring_Handler::handle_check_website( $website );
1513 + \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'HTTP Status: ', 'mainwp' ) . '%n' . $data['httpCode'] . ' (' . $data['httpCodeString'] . ')' ) );
1514 + \WP_CLI::line( '' );
1515 + }
1568 1516
1569 - \WP_CLI::line( \WP_CLI::colorize( '%B' . $website->name . ' (' . $website->url . ')%n' ) );
1570 - if ( 0 < count( $wp_upgrades ) ) {
1571 - \WP_CLI::line( '' );
1572 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'WordPress Core', 'mainwp' ) . '%n' ) );
1573 - \WP_CLI::line( '' );
1517 + /**
1518 + * Lists all available update for all sites.
1519 + *
1520 + * Command Example: wp mainwp updates --available-updates [<websiteid>].
1521 + *
1522 + * @param array $args Arguments.
1523 + * @param array $assoc_args Arguments.
1524 + */
1525 + public static function callback_updates_available_updates( $args = array(), $assoc_args = array() ) { // phpcs:ignore -- NOSONAR - complex.
1574 1526
1575 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $wp_upgrades['current'] );
1576 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $wp_upgrades['new'] );
1577 - }
1527 + \WP_CLI::line( '' );
1528 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Updates', 'mainwp' ) . '%n' ) );
1529 + \WP_CLI::line( '' );
1578 1530
1579 - if ( 0 < count( $plugin_upgrades ) ) {
1580 - \WP_CLI::line( '' );
1581 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Plugin Updates', 'mainwp' ) . '%n' ) );
1582 - \WP_CLI::line( '' );
1531 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
1532 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1583 1533
1584 - foreach ( $plugin_upgrades as $plugin_upgrade ) {
1585 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $plugin_upgrade['Name'] );
1586 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $plugin_upgrade['Version'] );
1587 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $plugin_upgrade['update']['new_version'] );
1588 - \WP_CLI::line( '' );
1589 - }
1590 - }
1534 + $site_options = MainWP_DB::instance()->get_website_options_array( $website, array( 'wp_upgrades', 'ignored_trans_updates' ) );
1535 + $wp_upgrades = isset( $site_options['wp_upgrades'] ) ? json_decode( $site_options['wp_upgrades'], true ) : array();
1536 + $ignored_core_upgrades = isset( $site_options['ignored_wp_upgrades'] ) ? json_decode( $site_options['ignored_wp_upgrades'], true ) : array();
1591 1537
1592 - if ( 0 < count( $theme_upgrades ) ) {
1593 - \WP_CLI::line( '' );
1594 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Theme Updates', 'mainwp' ) . '%n' ) );
1595 - \WP_CLI::line( '' );
1538 + if ( $website->is_ignoreCoreUpdates || MainWP_Common_Functions::instance()->is_ignored_updates( $wp_upgrades, $ignored_core_upgrades, 'core' ) ) {
1539 + $wp_upgrades = array();
1540 + }
1596 1541
1597 - foreach ( $theme_upgrades as $theme_upgrade ) {
1598 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $theme_upgrade['Name'] );
1599 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $theme_upgrade['Version'] );
1600 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $theme_upgrade['update']['new_version'] );
1601 - \WP_CLI::line( '' );
1602 - }
1603 - }
1542 + $ignored_trans_updates = isset( $site_options['ignored_trans_updates'] ) ? (int) $site_options['ignored_trans_updates'] : false;
1604 1543
1605 - if ( 0 < count( $translation_upgrades ) ) {
1606 - \WP_CLI::line( '' );
1607 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Translation Updates', 'mainwp' ) . '%n' ) );
1608 - \WP_CLI::line( '' );
1544 + $wp_upgrades = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' );
1545 + $wp_upgrades = ! empty( $wp_upgrades ) ? json_decode( $wp_upgrades, true ) : array();
1609 1546
1610 - foreach ( $translation_upgrades as $translation_upgrade ) {
1611 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $translation_upgrade['Name'] );
1612 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $translation_upgrade['Version'] );
1613 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $translation_upgrade['update']['new_version'] );
1614 - \WP_CLI::line( '' );
1615 - }
1616 - }
1617 - }
1618 - MainWP_DB::free_result( $websites );
1619 - }
1547 + $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
1548 + $theme_upgrades = json_decode( $website->theme_upgrades, true );
1549 + $translation_upgrades = json_decode( $website->translation_upgrades, true );
1620 1550
1621 - /**
1622 - * Lists all ignored plugins for a child site.
1623 - *
1624 - * Command Example: wp mainwp updates --ignored-plugins-updates [<websiteid>].
1625 - *
1626 - * @param array $args Arguments.
1627 - * @param array $assoc_args Arguments.
1628 - * @param object|bool $website Website object.
1629 - */
1630 - public static function callback_updates_ignored_plugins_updates( $args = array(), $assoc_args = array(), $website = false ) {
1631 - $ignored_all = false;
1632 - if ( $website ) {
1633 - \WP_CLI::line( '' );
1634 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1635 - \WP_CLI::line( '' );
1551 + if ( $website->is_ignorePluginUpdates ) {
1552 + $plugin_upgrades = array();
1553 + }
1554 + if ( $website->is_ignoreThemeUpdates ) {
1555 + $theme_upgrades = array();
1556 + }
1636 1557
1637 - if ( $website->is_ignorePluginUpdates ) {
1638 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'All ignored', 'mainwp' ) . '%n' ) );
1639 - $ignored_all = true;
1640 - }
1641 - }
1558 + if ( $ignored_trans_updates ) {
1559 + $translation_upgrades = array();
1560 + }
1642 1561
1643 - if ( ! $ignored_all ) {
1644 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1645 - $data = json_decode( $userExtension->ignored_plugins, true );
1646 - foreach ( $data as $plugin => $value ) {
1647 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $value );
1648 - }
1649 - if ( $website ) {
1650 - $ignored_plugins = json_decode( $website->ignored_plugins, true );
1651 - if ( is_array( $ignored_plugins ) ) {
1652 - foreach ( $ignored_plugins as $slug => $name ) {
1653 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $name );
1654 - }
1655 - }
1656 - }
1657 - }
1562 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1563 + if ( is_array( $plugin_upgrades ) && ! empty( $plugin_upgrades ) ) {
1564 + $ignored_plugins = json_decode( $website->ignored_plugins, true );
1565 + if ( is_array( $ignored_plugins ) ) {
1566 + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
1658 1567
1659 - \WP_CLI::line( '' );
1660 - }
1568 + }
1569 + $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
1570 + if ( is_array( $ignored_plugins ) ) {
1571 + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
1661 1572
1662 - /**
1663 - * Lists all per site ignored plugin updates for a child site.
1664 - *
1665 - * Command Example: wp mainwp updates --site-ignored-plugins-updates [<websiteid>].
1666 - *
1667 - * @param array $args Arguments.
1668 - * @param array $assoc_args Arguments.
1669 - * @param object $website Object containing child site data.
1670 - */
1671 - public static function callback_updates_site_ignored_plugins_updates( $args = array(), $assoc_args = array(), $website = false ) {
1672 - $data = json_decode( $website->ignored_plugins, true );
1573 + }
1574 + }
1673 1575
1674 - \WP_CLI::line( '' );
1675 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1676 - \WP_CLI::line( '' );
1576 + if ( is_array( $theme_upgrades ) && ! empty( $theme_upgrades ) ) {
1577 + $ignored_themes = json_decode( $website->ignored_themes, true );
1578 + if ( is_array( $ignored_themes ) ) {
1579 + $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
1580 + }
1677 1581
1678 - foreach ( $data as $plugin => $value ) {
1679 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $value );
1680 - }
1582 + $ignored_themes = json_decode( $userExtension->ignored_themes, true );
1583 + if ( is_array( $ignored_themes ) ) {
1584 + $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
1585 + }
1586 + }
1681 1587
1682 - \WP_CLI::line( '' );
1683 - }
1588 + \WP_CLI::line( \WP_CLI::colorize( '%B' . $website->name . ' (' . $website->url . ')%n' ) );
1589 + if ( ! empty( $wp_upgrades ) ) {
1590 + \WP_CLI::line( '' );
1591 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'WordPress Core', 'mainwp' ) . '%n' ) );
1592 + \WP_CLI::line( '' );
1684 1593
1685 - /**
1686 - * Lists all ignored theme updates for a child site.
1687 - *
1688 - * Command Example: wp mainwp updates --ignored-themes-updates [<websiteid>].
1689 - *
1690 - * @param array $args Arguments.
1691 - * @param array $assoc_args Arguments.
1692 - * @param object $website Object containing child site data.
1693 - */
1694 - public static function callback_updates_ignored_themes_updates( $args = array(), $assoc_args = array(), $website = false ) {
1594 + \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $wp_upgrades['current'] );
1595 + \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $wp_upgrades['new'] );
1596 + }
1695 1597
1696 - $ignored_all = false;
1697 - if ( $website ) {
1698 - if ( $website->is_ignoreThemeUpdates ) {
1699 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'All ignored', 'mainwp' ) . '%n' ) );
1700 - $ignored_all = true;
1701 - }
1702 - \WP_CLI::line( '' );
1703 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1704 - \WP_CLI::line( '' );
1705 - }
1598 + if ( ! empty( $plugin_upgrades ) ) {
1599 + \WP_CLI::line( '' );
1600 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Plugin Updates', 'mainwp' ) . '%n' ) );
1601 + \WP_CLI::line( '' );
1706 1602
1707 - if ( ! $ignored_all ) {
1708 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1709 - $data = json_decode( $userExtension->ignored_themes, true );
1710 - foreach ( $data as $theme => $value ) {
1711 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $value );
1712 - }
1713 - if ( $website ) {
1714 - $ignored_themes = json_decode( $website->ignored_themes, true );
1715 - if ( is_array( $ignored_themes ) ) {
1716 - foreach ( $ignored_themes as $slug => $name ) {
1717 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $name );
1718 - }
1719 - }
1720 - }
1721 - }
1603 + foreach ( $plugin_upgrades as $plugin_upgrade ) {
1604 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $plugin_upgrade['Name'] );
1605 + \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $plugin_upgrade['Version'] );
1606 + \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $plugin_upgrade['update']['new_version'] );
1607 + \WP_CLI::line( '' );
1608 + }
1609 + }
1722 1610
1723 - \WP_CLI::line( '' );
1724 - }
1611 + if ( ! empty( $theme_upgrades ) ) {
1612 + \WP_CLI::line( '' );
1613 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Theme Updates', 'mainwp' ) . '%n' ) );
1614 + \WP_CLI::line( '' );
1725 1615
1726 - /**
1727 - * Lists all per site ignored theme updates for a child site.
1728 - *
1729 - * Command Example: wp mainwp updates --site-ignored-themes-updates [<websiteid>].
1730 - *
1731 - * @param array $args Arguments.
1732 - * @param array $assoc_args Arguments.
1733 - * @param object $website Object containing child site data.
1734 - */
1735 - public static function callback_updates_site_ignored_themes_updates( $args = array(), $assoc_args = array(), $website = false ) {
1616 + foreach ( $theme_upgrades as $theme_upgrade ) {
1617 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $theme_upgrade['Name'] );
1618 + \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $theme_upgrade['Version'] );
1619 + \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $theme_upgrade['update']['new_version'] );
1620 + \WP_CLI::line( '' );
1621 + }
1622 + }
1736 1623
1737 - $data = json_decode( $website->ignored_themes, true );
1624 + if ( ! empty( $translation_upgrades ) ) {
1625 + \WP_CLI::line( '' );
1626 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Translation Updates', 'mainwp' ) . '%n' ) );
1627 + \WP_CLI::line( '' );
1738 1628
1739 - \WP_CLI::line( '' );
1740 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1741 - \WP_CLI::line( '' );
1629 + foreach ( $translation_upgrades as $translation_upgrade ) {
1630 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $translation_upgrade['Name'] );
1631 + \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $translation_upgrade['Version'] );
1632 + \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $translation_upgrade['update']['new_version'] );
1633 + \WP_CLI::line( '' );
1634 + }
1635 + }
1636 + }
1637 + MainWP_DB::free_result( $websites );
1638 + }
1742 1639
1743 - foreach ( $data as $theme => $value ) {
1744 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $value );
1745 - }
1640 + /**
1641 + * Lists all ignored plugins for a child site.
1642 + *
1643 + * Command Example: wp mainwp updates --ignored-plugins-updates [<websiteid>].
1644 + *
1645 + * @param array $args Arguments.
1646 + * @param array $assoc_args Arguments.
1647 + * @param object|bool $website Website object.
1648 + */
1649 + public static function callback_updates_ignored_plugins_updates( $args = array(), $assoc_args = array(), $website = false ) { //phpcs:ignore -- NOSONAR - complex.
1650 + $ignored_all = false;
1651 + if ( $website ) {
1652 + \WP_CLI::line( '' );
1653 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1654 + \WP_CLI::line( '' );
1746 1655
1747 - \WP_CLI::line( '' );
1748 - }
1656 + if ( $website->is_ignorePluginUpdates ) {
1657 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'All ignored', 'mainwp' ) . '%n' ) );
1658 + $ignored_all = true;
1659 + }
1660 + }
1749 1661
1750 - /**
1751 - * Ignores an update globally.
1752 - *
1753 - * Command Example: wp mainwp updates --ignore-updates --type=[type] --slug=[slug] --name=[name].
1754 - *
1755 - * type: plugin|theme
1756 - *
1757 - * @param array $args Arguments.
1758 - * @param array $assoc_args Arguments.
1759 - * @param object $website Object containing child site data.
1760 - */
1761 - public static function callback_updates_ignore_updates( $args = array(), $assoc_args = array(), $website = false ) {
1662 + if ( ! $ignored_all ) {
1663 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1664 + $data = json_decode( $userExtension->ignored_plugins, true );
1665 + foreach ( $data as $value ) {
1666 + $name = is_array( $value ) && ! empty( $value['Name'] ) ? $value['Name'] : '';
1667 + $name = empty( $name ) && is_string( $value ) ? $value : $name;
1762 1668
1763 - $params = self::get_cli_params( $args, $assoc_args, array( 'type', 'slug', 'name' ) );
1669 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $name );
1670 + }
1671 + if ( $website ) {
1672 + $ignored_plugins = json_decode( $website->ignored_plugins, true );
1673 + if ( is_array( $ignored_plugins ) ) {
1674 + foreach ( $ignored_plugins as $value ) {
1675 + $name = is_array( $value ) && ! empty( $value['Name'] ) ? $value['Name'] : '';
1676 + $name = empty( $name ) && is_string( $value ) ? $value : $name;
1677 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $name );
1678 + }
1679 + }
1680 + }
1681 + }
1764 1682
1765 - $type = $params['type'];
1766 - $slug = $params['slug'];
1767 - $name = $params['name'];
1683 + \WP_CLI::line( '' );
1684 + }
1768 1685
1769 - MainWP_Updates_Handler::ignore_plugins_themes( $type, $slug, $name );
1686 + /**
1687 + * Lists all per site ignored plugin updates for a child site.
1688 + *
1689 + * Command Example: wp mainwp updates --site-ignored-plugins-updates [<websiteid>].
1690 + *
1691 + * @param array $args Arguments.
1692 + * @param array $assoc_args Arguments.
1693 + * @param object $website Object containing child site data.
1694 + */
1695 + public static function callback_updates_site_ignored_plugins_updates( $args = array(), $assoc_args = array(), $website = false ) {
1696 + $data = json_decode( $website->ignored_plugins, true );
1770 1697
1771 - \WP_CLI::line( '' );
1772 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $name . esc_html__( ' ignorred successfully.', 'mainwp' ) . '%n' ) );
1773 - \WP_CLI::line( '' );
1774 - }
1698 + \WP_CLI::line( '' );
1699 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1700 + \WP_CLI::line( '' );
1775 1701
1702 + foreach ( $data as $value ) {
1703 + $name = is_array( $value ) && ! empty( $value['Name'] ) ? $value['Name'] : '';
1704 + $name = empty( $name ) && is_string( $value ) ? $value : $name;
1705 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $name );
1706 + }
1776 1707
1777 - /**
1778 - * Ignores an update on a child site.
1779 - *
1780 - * Command Example: wp mainwp updates --ignore-update [<websiteid>] --type=[type] --slug=[slug] --name=[name].
1781 - *
1782 - * @param array $args Arguments.
1783 - * @param array $assoc_args Arguments.
1784 - * @param object $website Object containing child site data.
1785 - */
1786 - public static function callback_updates_ignore_update( $args = array(), $assoc_args = array(), $website = false ) {
1708 + \WP_CLI::line( '' );
1709 + }
1787 1710
1788 - $params = self::get_cli_params( $args, $assoc_args, array( 'type', 'slug', 'name' ) );
1789 - $type = $params['type'];
1790 - $slug = $params['slug'];
1791 - $name = $params['name'];
1711 + /**
1712 + * Lists all ignored theme updates for a child site.
1713 + *
1714 + * Command Example: wp mainwp updates --ignored-themes-updates [<websiteid>].
1715 + *
1716 + * @param array $args Arguments.
1717 + * @param array $assoc_args Arguments.
1718 + * @param object $website Object containing child site data.
1719 + */
1720 + public static function callback_updates_ignored_themes_updates( $args = array(), $assoc_args = array(), $website = false ) {
1792 1721
1793 - MainWP_Updates_Handler::ignore_plugin_theme( $type, $slug, $name, $website->id );
1722 + $ignored_all = false;
1723 + if ( $website ) {
1724 + if ( $website->is_ignoreThemeUpdates ) {
1725 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'All ignored', 'mainwp' ) . '%n' ) );
1726 + $ignored_all = true;
1727 + }
1728 + \WP_CLI::line( '' );
1729 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1730 + \WP_CLI::line( '' );
1731 + }
1794 1732
1795 - \WP_CLI::line( '' );
1796 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $name . esc_html__( ' ignorred successfully.', 'mainwp' ) . '%n' ) );
1797 - \WP_CLI::line( '' );
1798 - }
1733 + if ( ! $ignored_all ) {
1734 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1735 + $data = json_decode( $userExtension->ignored_themes, true );
1736 + foreach ( $data as $value ) {
1737 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $value );
1738 + }
1739 + if ( $website ) {
1740 + $ignored_themes = json_decode( $website->ignored_themes, true );
1741 + if ( is_array( $ignored_themes ) ) {
1742 + foreach ( $ignored_themes as $name ) {
1743 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $name );
1744 + }
1745 + }
1746 + }
1747 + }
1799 1748
1800 - /**
1801 - * Unignores an update.
1802 - *
1803 - * Command Example: wp mainwp updates --unignore-updates --type=[type] --slug=[slug].
1804 - *
1805 - * @param array $args Arguments.
1806 - * @param array $assoc_args Arguments.
1807 - * @param object $website Object containing child site data.
1808 - */
1809 - public static function callback_updates_unignore_updates( $args = array(), $assoc_args = array(), $website = false ) {
1749 + \WP_CLI::line( '' );
1750 + }
1810 1751
1811 - $params = self::get_cli_params( $args, $assoc_args, array( 'type', 'slug' ) );
1812 - $type = $params['type'];
1813 - $slug = $params['slug'];
1752 + /**
1753 + * Lists all per site ignored theme updates for a child site.
1754 + *
1755 + * Command Example: wp mainwp updates --site-ignored-themes-updates [<websiteid>].
1756 + *
1757 + * @param array $args Arguments.
1758 + * @param array $assoc_args Arguments.
1759 + * @param object $website Object containing child site data.
1760 + */
1761 + public static function callback_updates_site_ignored_themes_updates( $args = array(), $assoc_args = array(), $website = false ) {
1814 1762
1815 - MainWP_Updates_Handler::unignore_plugins_themes( $type, $slug );
1763 + $data = json_decode( $website->ignored_themes, true );
1816 1764
1817 - \WP_CLI::line( '' );
1818 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $slug . esc_html__( ' unignorred successfully.', 'mainwp' ) . '%n' ) );
1819 - \WP_CLI::line( '' );
1820 - }
1765 + \WP_CLI::line( '' );
1766 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1767 + \WP_CLI::line( '' );
1821 1768
1769 + foreach ( $data as $value ) {
1770 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $value );
1771 + }
1822 1772
1823 - /**
1824 - * Unitnores an update on a child site.
1825 - *
1826 - * Command Example: wp mainwp updates --unignore-update [<websiteid>] --type=[type] --slug=[slug].
1827 - *
1828 - * @param array $args Arguments.
1829 - * @param array $assoc_args Arguments.
1830 - * @param object $website Object containing child site data.
1831 - */
1832 - public static function callback_updates_unignore_update( $args = array(), $assoc_args = array(), $website = false ) {
1773 + \WP_CLI::line( '' );
1774 + }
1833 1775
1834 - $params = self::get_cli_params( $args, $assoc_args, array( 'type', 'slug' ) );
1835 - $type = $params['type'];
1836 - $slug = $params['slug'];
1776 + /**
1777 + * Ignores an update globally.
1778 + *
1779 + * Command Example: wp mainwp updates --ignore-updates --type=[type] --slug=[slug] --name=[name].
1780 + *
1781 + * type: plugin|theme
1782 + *
1783 + * @param array $args Arguments.
1784 + * @param array $assoc_args Arguments.
1785 + * @param object $website Object containing child site data.
1786 + */
1787 + public static function callback_updates_ignore_updates( $args = array(), $assoc_args = array(), $website = false ) {
1837 1788
1838 - MainWP_Updates_Handler::unignore_plugin_theme( $type, $slug, $website->id );
1789 + $params = static::get_cli_params( $args, $assoc_args, array( 'type', 'slug', 'name' ) );
1839 1790
1840 - \WP_CLI::line( '' );
1841 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $slug . esc_html__( ' unignorred successfully.', 'mainwp' ) . '%n' ) );
1842 - \WP_CLI::line( '' );
1843 - }
1791 + $type = $params['type'];
1792 + $slug = $params['slug'];
1793 + $name = $params['name'];
1844 1794
1845 - /**
1846 - * Syncs all child sites.
1847 - *
1848 - * Command Example: wp mainwp sites --sync-sites.
1849 - *
1850 - * @param array $args Arguments.
1851 - * @param array $assoc_args Arguments.
1852 - */
1853 - public static function handle_sync_sites( $args = array(), $assoc_args = false ) {
1795 + MainWP_Updates_Handler::ignore_plugins_themes( $type, $slug, $name );
1854 1796
1855 - $sites = self::get_cli_params( $args, $assoc_args, 'sites' );
1856 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
1797 + \WP_CLI::line( '' );
1798 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $name . esc_html__( ' ignorred successfully.', 'mainwp' ) . '%n' ) );
1799 + \WP_CLI::line( '' );
1800 + }
1857 1801
1858 - $warnings = 0;
1859 - $errors = 0;
1860 1802
1861 - \WP_CLI::line( '' );
1862 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Syncing sites. Please wait...', 'mainwp' ) . '%n' ) );
1863 - \WP_CLI::line( '' );
1803 + /**
1804 + * Ignores an update on a child site.
1805 + *
1806 + * Command Example: wp mainwp updates --ignore-update [<websiteid>] --type=[type] --slug=[slug] --name=[name].
1807 + *
1808 + * @param array $args Arguments.
1809 + * @param array $assoc_args Arguments.
1810 + * @param object $website Object containing child site data.
1811 + */
1812 + public static function callback_updates_ignore_update( $args = array(), $assoc_args = array(), $website = false ) {
1864 1813
1865 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1866 - if ( ( count( $sites ) > 0 ) && ( ! in_array( $website->id, $sites, true ) ) ) {
1867 - continue;
1868 - }
1814 + $params = static::get_cli_params( $args, $assoc_args, array( 'type', 'slug', 'name' ) );
1815 + $type = $params['type'];
1816 + $slug = $params['slug'];
1817 + $name = $params['name'];
1869 1818
1870 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' (' . $website->url . ')%n' ) );
1819 + MainWP_Updates_Handler::ignore_plugin_theme( $type, $slug, $name, $website->id );
1871 1820
1872 - try {
1873 - if ( MainWP_Sync::sync_site( $website ) ) {
1874 - \WP_CLI::success( esc_html__( 'Sync succeeded', 'mainwp' ) );
1875 - } else {
1876 - \WP_CLI::warning( esc_html__( 'Sync failed', 'mainwp' ) );
1877 - ++$warnings;
1878 - }
1879 - } catch ( \Exception $e ) {
1880 - \WP_CLI::error( esc_html__( 'Sync failed: ', 'mainwp' ) . MainWP_Error_Helper::get_console_error_message( $e ) );
1881 - ++$errors;
1882 - }
1883 - \WP_CLI::line( '' );
1884 - }
1885 - MainWP_DB::free_result( $websites );
1821 + \WP_CLI::line( '' );
1822 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $name . esc_html__( ' ignorred successfully.', 'mainwp' ) . '%n' ) );
1823 + \WP_CLI::line( '' );
1824 + }
1886 1825
1887 - if ( $errors > 0 ) {
1888 - \WP_CLI::error( esc_html__( 'Sync process completed with errors.', 'mainwp' ) );
1889 - } elseif ( $warnings > 0 ) {
1890 - \WP_CLI::warning( esc_html__( 'Sync process completed with warnings.', 'mainwp' ) );
1891 - } else {
1892 - \WP_CLI::success( esc_html__( 'Sync process completed successfully.', 'mainwp' ) );
1893 - }
1894 - \WP_CLI::line( '' );
1895 - }
1826 + /**
1827 + * Unignores an update.
1828 + *
1829 + * Command Example: wp mainwp updates --unignore-updates --type=[type] --slug=[slug].
1830 + *
1831 + * @param array $args Arguments.
1832 + * @param array $assoc_args Arguments.
1833 + * @param object $website Object containing child site data.
1834 + */
1835 + public static function callback_updates_unignore_updates( $args = array(), $assoc_args = array(), $website = false ) {
1896 1836
1837 + $params = static::get_cli_params( $args, $assoc_args, array( 'type', 'slug' ) );
1838 + $type = $params['type'];
1839 + $slug = $params['slug'];
1897 1840
1898 - /**
1899 - * Prints process success message.
1900 - */
1901 - public static function print_process_success() {
1902 - \WP_CLI::success( 'Process ran.' );
1903 - }
1841 + MainWP_Updates_Handler::unignore_global_plugins_themes( $type, $slug );
1904 1842
1905 - /**
1906 - * Prints child sites list.
1907 - *
1908 - * @param array $websites Array containing child sites.
1909 - * @param bool $is_objs Array of objects.
1910 - */
1911 - public static function print_sites( $websites, $is_objs = false ) {
1912 - $data = array();
1913 - if ( $is_objs ) {
1914 - $fields = array( 'id', 'url', 'name' );
1915 - $dbwebsites = array();
1916 - foreach ( $websites as $site_id => $website ) {
1917 - $data[ $site_id ] = MainWP_Utility::map_site( $website, $fields, false );
1918 - }
1919 - } else {
1920 - $data = $websites;
1921 - }
1843 + \WP_CLI::line( '' );
1844 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $slug . esc_html__( ' unignorred successfully.', 'mainwp' ) . '%n' ) );
1845 + \WP_CLI::line( '' );
1846 + }
1922 1847
1923 - $idLength = strlen( 'id' );
1924 - $nameLength = strlen( 'name' );
1925 - $urlLength = strlen( 'url' );
1926 1848
1927 - foreach ( $data as $site ) {
1928 - if ( $idLength < strlen( $site['id'] ) ) {
1929 - $idLength = strlen( $site['id'] );
1930 - }
1931 - if ( $nameLength < strlen( $site['name'] ) ) {
1932 - $nameLength = strlen( $site['name'] );
1933 - }
1934 - if ( $urlLength < strlen( $site['url'] ) ) {
1935 - $urlLength = strlen( $site['url'] );
1936 - }
1937 - }
1849 + /**
1850 + * Unitnores an update on a child site.
1851 + *
1852 + * Command Example: wp mainwp updates --unignore-update [<websiteid>] --type=[type] --slug=[slug].
1853 + *
1854 + * @param array $args Arguments.
1855 + * @param array $assoc_args Arguments.
1856 + * @param object $website Object containing child site data.
1857 + */
1858 + public static function callback_updates_unignore_update( $args = array(), $assoc_args = array(), $website = false ) {
1938 1859
1939 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . 's+', '', '', '', '' ) );
1940 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $urlLength . 's |', 'id', 'name', 'url', 'version' ) );
1941 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . 's+', '', '', '', '' ) );
1860 + $params = static::get_cli_params( $args, $assoc_args, array( 'type', 'slug' ) );
1861 + $type = $params['type'];
1862 + $slug = $params['slug'];
1942 1863
1943 - foreach ( $data as $site ) {
1944 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $urlLength . 's |', $site['id'], $site['name'], $site['url'] ) );
1945 - }
1864 + MainWP_Updates_Handler::unignore_plugin_theme( $type, $slug, $website->id );
1946 1865
1947 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . 's+', '', '', '', '' ) );
1948 - }
1866 + \WP_CLI::line( '' );
1867 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $slug . esc_html__( ' unignorred successfully.', 'mainwp' ) . '%n' ) );
1868 + \WP_CLI::line( '' );
1869 + }
1870 +
1871 + /**
1872 + * Syncs all child sites.
1873 + *
1874 + * Command Example: wp mainwp sites --sync-sites.
1875 + *
1876 + * @param array $args Arguments.
1877 + * @param array $assoc_args Arguments.
1878 + */
1879 + public static function handle_sync_sites( $args = array(), $assoc_args = false ) {
1880 +
1881 + $sites = static::get_cli_params( $args, $assoc_args, 'sites' );
1882 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
1883 +
1884 + $warnings = 0;
1885 + $errors = 0;
1886 +
1887 + \WP_CLI::line( '' );
1888 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Syncing sites. Please wait...', 'mainwp' ) . '%n' ) );
1889 + \WP_CLI::line( '' );
1890 +
1891 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1892 + if ( ! empty( $sites ) && ( ! in_array( $website->id, $sites, true ) ) ) {
1893 + continue;
1894 + }
1895 +
1896 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' (' . $website->url . ')%n' ) );
1897 +
1898 + try {
1899 + if ( MainWP_Sync::sync_site( $website ) ) {
1900 + \WP_CLI::success( esc_html__( 'Sync succeeded', 'mainwp' ) );
1901 + } else {
1902 + \WP_CLI::warning( esc_html__( 'Sync failed', 'mainwp' ) );
1903 + ++$warnings;
1904 + }
1905 + } catch ( \Exception $e ) {
1906 + \WP_CLI::error( esc_html__( 'Sync failed: ', 'mainwp' ) . MainWP_Error_Helper::get_console_error_message( $e ) );
1907 + ++$errors;
1908 + }
1909 + \WP_CLI::line( '' );
1910 + }
1911 + MainWP_DB::free_result( $websites );
1912 +
1913 + if ( $errors > 0 ) {
1914 + \WP_CLI::error( esc_html__( 'Sync process completed with errors.', 'mainwp' ) );
1915 + } elseif ( $warnings > 0 ) {
1916 + \WP_CLI::warning( esc_html__( 'Sync process completed with warnings.', 'mainwp' ) );
1917 + } else {
1918 + \WP_CLI::success( esc_html__( 'Sync process completed successfully.', 'mainwp' ) );
1919 + }
1920 + \WP_CLI::line( '' );
1921 + }
1922 +
1923 +
1924 + /**
1925 + * Prints process success message.
1926 + */
1927 + public static function print_process_success() {
1928 + \WP_CLI::success( 'Process ran.' );
1929 + }
1930 +
1931 + /**
1932 + * Prints child sites list.
1933 + *
1934 + * @param array $websites Array containing child sites.
1935 + * @param bool $is_objs Array of objects.
1936 + */
1937 + public static function print_sites( $websites, $is_objs = false ) {
1938 + $data = array();
1939 + if ( $is_objs ) {
1940 + $fields = array( 'id', 'url', 'name' );
1941 + foreach ( $websites as $site_id => $website ) {
1942 + $data[ $site_id ] = MainWP_Utility::map_site( $website, $fields, false );
1943 + }
1944 + } else {
1945 + $data = $websites;
1946 + }
1947 +
1948 + $idLength = strlen( 'id' );
1949 + $nameLength = strlen( 'name' );
1950 + $urlLength = strlen( 'url' );
1951 +
1952 + foreach ( $data as $site ) {
1953 + if ( $idLength < strlen( $site['id'] ) ) {
1954 + $idLength = strlen( $site['id'] );
1955 + }
1956 + if ( $nameLength < strlen( $site['name'] ) ) {
1957 + $nameLength = strlen( $site['name'] );
1958 + }
1959 + if ( $urlLength < strlen( $site['url'] ) ) {
1960 + $urlLength = strlen( $site['url'] );
1961 + }
1962 + }
1963 +
1964 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . 's+', '', '', '', '' ) );
1965 + \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $urlLength . 's |', 'id', 'name', 'url', 'version' ) );
1966 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . 's+', '', '', '', '' ) );
1967 +
1968 + foreach ( $data as $site ) {
1969 + \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $urlLength . 's |', $site['id'], $site['name'], $site['url'] ) );
1970 + }
1971 +
1972 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . 's+', '', '', '', '' ) );
1973 + }
1949 1974 }