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 +1751 -1614 5.0 → 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,1817 +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 - $data = array(
789 - 'wp_core' => $wp_upgrades,
790 - 'plugins' => $plugin_upgrades,
791 - 'themes' => $theme_upgrades,
792 - 'translation' => $translation_upgrades,
793 - );
788 + if ( $website->is_ignoreCoreUpdates || MainWP_Common_Functions::instance()->is_ignored_updates( $wp_upgrades, $ignored_core_upgrades, 'core' ) ) {
789 + $wp_upgrades = array();
790 + }
794 791
795 - \WP_CLI::line( '' );
796 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Available Updates', 'mainwp' ) . '%n' ) );
797 - \WP_CLI::line( '' );
792 + $ignored_trans_updates = isset( $site_options['ignored_trans_updates'] ) ? (int) $site_options['ignored_trans_updates'] : false;
798 793
799 - if ( 0 < count( $wp_upgrades ) ) {
800 - \WP_CLI::line( '' );
801 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'WordPress Core', 'mainwp' ) . '%n' ) );
802 - \WP_CLI::line( '' );
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 );
803 797
804 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $wp_upgrades['current'] );
805 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $wp_upgrades['new'] );
806 - }
798 + if ( $website->is_ignorePluginUpdates ) {
799 + $plugin_upgrades = array();
800 + }
801 + if ( $website->is_ignoreThemeUpdates ) {
802 + $theme_upgrades = array();
803 + }
807 804
808 - if ( 0 < count( $plugin_upgrades ) ) {
809 - \WP_CLI::line( '' );
810 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Plugin Updates', 'mainwp' ) . '%n' ) );
811 - \WP_CLI::line( '' );
805 + if ( $ignored_trans_updates ) {
806 + $translation_upgrades = array();
807 + }
812 808
813 - foreach ( $plugin_upgrades as $plugin_upgrade ) {
814 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $plugin_upgrade['Name'] );
815 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $plugin_upgrade['Version'] );
816 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $plugin_upgrade['update']['new_version'] );
817 - \WP_CLI::line( '' );
818 - }
819 - }
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 );
820 814
821 - if ( 0 < count( $theme_upgrades ) ) {
822 - \WP_CLI::line( '' );
823 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Theme Updates', 'mainwp' ) . '%n' ) );
824 - \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 );
825 819
826 - foreach ( $theme_upgrades as $theme_upgrade ) {
827 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $theme_upgrade['Name'] );
828 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $theme_upgrade['Version'] );
829 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $theme_upgrade['update']['new_version'] );
830 - \WP_CLI::line( '' );
831 - }
832 - }
820 + }
821 + }
833 822
834 - if ( 0 < count( $translation_upgrades ) ) {
835 - \WP_CLI::line( '' );
836 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Translation Updates', 'mainwp' ) . '%n' ) );
837 - \WP_CLI::line( '' );
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 + }
838 828
839 - foreach ( $translation_upgrades as $translation_upgrade ) {
840 - if ( ! is_array( $translation_upgrade ) ) {
841 - $translation_upgrade = array();
842 - }
843 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . ( isset( $translation_upgrade['Name'] ) ? $translation_upgrade['Name'] : '' ) );
844 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . ( isset( $translation_upgrade['Version'] ) ? $translation_upgrade['Version'] : '' ) );
845 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . ( isset( $translation_upgrade['update']['new_version'] ) ? $translation_upgrade['update']['new_version'] : '' ) );
846 - \WP_CLI::line( '' );
847 - }
848 - }
849 - }
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 + }
850 834
851 - /**
852 - * Returns the number of available updates for a child site.
853 - *
854 - * Command Example: wp mainwp site --site-available-updates-count [<websiteid>].
855 - *
856 - * @param array $args Arguments.
857 - * @param array $assoc_args Arguments.
858 - * @param object $website Object containing child site data.
859 - */
860 - public static function callback_site_site_available_updates_count( $args = array(), $assoc_args = array(), $website = false ) {
861 - $plugins = json_decode( $website->plugin_upgrades, true );
862 - $themes = json_decode( $website->theme_upgrades, true );
863 - $translations = json_decode( $website->translation_upgrades, true );
864 - $wp = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' );
865 - $wp = ! empty( $wp ) ? json_decode( $wp, true ) : array();
835 + \WP_CLI::line( '' );
836 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Available Updates', 'mainwp' ) . '%n' ) );
837 + \WP_CLI::line( '' );
866 838
867 - if ( count( $wp ) > 0 ) {
868 - $wp = 1;
869 - } else {
870 - $wp = 0;
871 - }
872 - $total = array_merge( $plugins, $themes, $translations );
873 - $data = array(
874 - 'total' => count( $total ) + $wp,
875 - 'wp' => $wp,
876 - 'plugins' => count( $plugins ),
877 - 'themes' => count( $themes ),
878 - 'translations' => count( $translations ),
879 - );
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( '' );
880 843
881 - \WP_CLI::line( '' );
882 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Updates', 'mainwp' ) . '%n' ) );
883 - \WP_CLI::line( '' );
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 + }
884 847
885 - \WP_CLI::line( \WP_CLI::colorize( '%gWordPress:%n ' ) . $data['wp'] );
886 - \WP_CLI::line( \WP_CLI::colorize( '%gPlugins:%n ' ) . $data['plugins'] );
887 - \WP_CLI::line( \WP_CLI::colorize( '%gThemes:%n ' ) . $data['themes'] );
888 - \WP_CLI::line( \WP_CLI::colorize( '%gTranslations:%n ' ) . $data['translations'] );
889 - \WP_CLI::line( '' );
890 - \WP_CLI::line( \WP_CLI::colorize( '%gTotal:%n ' ) . $data['total'] );
891 - \WP_CLI::line( '' );
892 - }
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( '' );
893 852
894 - /**
895 - * Lists all abandoned plugins on a child site.
896 - *
897 - * Command Example: wp mainwp site --site-abandoned-plugins [<websiteid>].
898 - *
899 - * @param array $args Arguments.
900 - * @param array $assoc_args Arguments.
901 - * @param object $website Object containing child site data.
902 - */
903 - public static function callback_site_site_abandoned_plugins( $args = array(), $assoc_args = array(), $website = false ) {
904 - $plugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_info' );
905 - $plugins = ! empty( $plugins ) ? json_decode( $plugins, true ) : array();
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 + }
906 860
907 - \WP_CLI::line( '' );
908 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Abandoned Plugins', 'mainwp' ) . '%n' ) );
909 - \WP_CLI::line( '' );
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( '' );
910 865
911 - foreach ( $plugins as $plugin ) {
912 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $plugin['Name'] );
913 - \WP_CLI::line( \WP_CLI::colorize( '%gURI:%n ' ) . $plugin['PluginURI'] );
914 - \WP_CLI::line( \WP_CLI::colorize( '%gVersion:%n ' ) . $plugin['Version'] );
915 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest Update:%n ' ) . date( 'F j, Y', $plugin['last_updated'] ) ); // phpcs:ignore -- local time.
916 - \WP_CLI::line( '' );
917 - }
918 - }
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 + }
919 873
920 - /**
921 - * Returns the number of abaindoned plugins on a child site.
922 - *
923 - * Command Example: wp mainwp site --site-abandoned-plugins-count [<websiteid>].
924 - *
925 - * @param array $args Arguments.
926 - * @param array $assoc_args Arguments.
927 - * @param object $website Object containing child site data.
928 - */
929 - public static function callback_site_site_abandoned_plugins_count( $args = array(), $assoc_args = array(), $website = false ) {
930 - $plugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_info' );
931 - $plugins = ! empty( $plugins ) ? json_decode( $plugins, true ) : array();
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( '' );
932 878
933 - \WP_CLI::line( '' );
934 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . ' ' . esc_html__( 'Abandoned plugins: ', 'mainwp' ) . '%n' . count( $plugins ) ) );
935 - \WP_CLI::line( '' );
936 - }
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 + }
937 890
938 - /**
939 - * Lists all abandoned themes on a child site.
940 - *
941 - * Command Example: wp mainwp site --site-abandoned-themes [<websiteid>].
942 - *
943 - * @param array $args Arguments.
944 - * @param array $assoc_args Arguments.
945 - * @param object $website Object containing child site data.
946 - */
947 - public static function callback_site_site_abandoned_themes( $args = array(), $assoc_args = array(), $website = false ) {
948 - $themes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_info' );
949 - $themes = ! empty( $themes ) ? json_decode( $themes, true ) : array();
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 );
950 903
951 - \WP_CLI::line( '' );
952 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Abandoned Themes', 'mainwp' ) . '%n' ) );
953 - \WP_CLI::line( '' );
904 + if ( $website->is_ignorePluginUpdates ) {
905 + $plugin_upgrades = array();
906 + }
907 + if ( $website->is_ignoreThemeUpdates ) {
908 + $theme_upgrades = array();
909 + }
954 910
955 - foreach ( $themes as $theme ) {
956 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $theme['Name'] );
957 - \WP_CLI::line( \WP_CLI::colorize( '%gVersion:%n ' ) . $theme['Version'] );
958 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest Update:%n ' ) . date( 'F j, Y', $theme['last_updated'] ) ); // phpcs:ignore -- local time.
959 - \WP_CLI::line( '' );
960 - }
961 - }
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 );
962 916
963 - /**
964 - * Returns the number of abandoned themes on a child site.
965 - *
966 - * Command Example: wp mainwp site --site-abandoned-themes-count [<websiteid>].
967 - *
968 - * @param array $args Arguments.
969 - * @param array $assoc_args Arguments.
970 - * @param object $website Object containing child site data.
971 - */
972 - public static function callback_site_site_abandoned_themes_count( $args = array(), $assoc_args = array(), $website = false ) {
973 - $themes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_info' );
974 - $themes = ! empty( $themes ) ? json_decode( $themes, true ) : array();
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 );
975 921
976 - \WP_CLI::line( '' );
977 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . ' ' . esc_html__( 'Abandoned themes: ', 'mainwp' ) . '%n' . count( $themes ) ) );
978 - \WP_CLI::line( '' );
979 - }
922 + }
923 + }
980 924
981 - /**
982 - * Returns child site HTTP status.
983 - *
984 - * Command Example: wp mainwp site --site-http-status [<websiteid>].
985 - *
986 - * @param array $args Arguments.
987 - * @param array $assoc_args Arguments.
988 - * @param object $website Object containing child site data.
989 - */
990 - public static function callback_site_site_http_status( $args = array(), $assoc_args = array(), $website = false ) {
991 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
992 - MainWP_Monitoring_Handler::handle_check_website( $website );
993 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Process ran successfully on ', 'mainwp' ) . $website->name . '%n' ) );
994 - }
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 + }
995 930
996 - /**
997 - * Returns child site Health score.
998 - *
999 - * Command Example: wp mainwp site --site-health-score [<websiteid>].
1000 - *
1001 - * @param array $args Arguments.
1002 - * @param array $assoc_args Arguments.
1003 - * @param object $website Object containing child site data.
1004 - */
1005 - public static function callback_site_site_health_score( $args = array(), $assoc_args = array(), $website = false ) {
1006 - $website = MainWP_DB::instance()->get_website_by_id( $website->id, false, array( 'health_site_status' ) );
1007 - $health_status = isset( $website->health_site_status ) ? json_decode( $website->health_site_status, true ) : array();
1008 - $hstatus = MainWP_Utility::get_site_health( $health_status );
1009 - $hval = $hstatus['val'];
1010 - $critical = $hstatus['critical'];
1011 - if ( 80 <= $hval && empty( $critical ) ) {
1012 - $health_score = 'Good';
1013 - } else {
1014 - $health_score = 'Should be improved';
1015 - }
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 + }
1016 936
1017 - \WP_CLI::line( '' );
1018 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . ' Health: %n ' ) . $health_score );
1019 - \WP_CLI::line( '' );
1020 - }
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();
1021 940
1022 - /**
1023 - * Lists child site security issues.
1024 - *
1025 - * Command Example: wp mainwp site --site-security-issues [<websiteid>].
1026 - *
1027 - * @param array $args Arguments.
1028 - * @param array $assoc_args Arguments.
1029 - * @param object $website Object containing child site data.
1030 - */
1031 - public static function callback_site_site_security_issues( $args = array(), $assoc_args = array(), $website = false ) {
1032 - $data = MainWP_Connect::fetch_url_authed( $website, 'security' );
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 + );
1033 954
1034 - \WP_CLI::line( '' );
1035 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Security Issues', 'mainwp' ) . '%n' ) );
1036 - \WP_CLI::line( '' );
955 + \WP_CLI::line( '' );
956 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Updates', 'mainwp' ) . '%n' ) );
957 + \WP_CLI::line( '' );
1037 958
1038 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Directories listing prevented:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['listing'] ? 'NO' : 'YES' ) );
1039 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'WordPress version hidden:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['wp_version'] ? 'NO' : 'YES' ) );
1040 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Really Simple Discovery meta tag removed:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['rsd'] ? 'NO' : 'YES' ) );
1041 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Windows Live Writer meta tag removed:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['wlw'] ? 'NO' : 'YES' ) );
1042 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Database error reporting disabled:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['db_reporting'] ? 'NO' : 'YES' ) );
1043 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'PHP error reporting disabled:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['php_reporting'] ? 'NO' : 'YES' ) );
1044 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Version information removed from URLs:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['versions'] ? 'NO' : 'YES' ) );
1045 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Registered version information removed from URLs:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['registered_versions'] ? 'NO' : 'YES' ) );
1046 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'readme.html removed from WordPress root:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['readme'] ? 'NO' : 'YES' ) );
1047 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Administrator username is not "admin":', 'mainwp' ) . '%n ' ) . ( 'N' === $data['admin'] ? 'NO' : 'YES' ) );
1048 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'WordPress is not up to date:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['wp_uptodate'] ? 'NO' : 'YES' ) );
1049 - \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' ) );
1050 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'SSL protocol is not in place:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['sslprotocol'] ? 'NO' : 'YES' ) );
1051 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'WP Config debugging is enabled:', 'mainwp' ) . '%n ' ) . ( 'N' === $data['debug_disabled'] ? 'NO' : 'YES' ) );
1052 - }
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 + }
1053 967
1054 - /**
1055 - * Adds child site.
1056 - *
1057 - * Command Example: wp mainwp site --add-site [<websiteid>].
1058 - *
1059 - * @param array $args Arguments.
1060 - * @param array $assoc_args Arguments.
1061 - * @param object $website Object containing child site data.
1062 - */
1063 - public static function callback_site_add_site( $args = array(), $assoc_args = array(), $website = false ) {
1064 - $fields = self::get_cli_params( $args, $assoc_args, 'add-site' );
1065 - $data = MainWP_Manage_Sites_Handler::rest_api_add_site( $fields );
1066 - if ( is_array( $data ) && ! empty( $data['siteid'] ) ) {
1067 - \WP_CLI::success( ' -> Add site result: ' . print_r( $data, true ) ); // phpcs:ignore -- for cli result.
1068 - } else {
1069 - \WP_CLI::error( ' -> Add site result: ' . print_r( $data, true ) ); // phpcs:ignore -- for cli result.
1070 - }
1071 - }
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();
1072 980
1073 - /**
1074 - * Edits child site.
1075 - *
1076 - * Command Example: wp mainwp site --edit-site [<websiteid>].
1077 - *
1078 - * @param array $args Arguments.
1079 - * @param array $assoc_args Arguments.
1080 - * @param object $website Object containing child site data.
1081 - */
1082 - public static function callback_site_edit_site( $args = array(), $assoc_args = array(), $website = false ) {
1083 - $fields = self::get_cli_params( $args, $assoc_args, 'edit-site' );
1084 - $data = MainWP_DB_Common::instance()->rest_api_update_website( $website->id, $fields );
1085 - $website = MainWP_DB::instance()->get_website_by_id( $website->id );
1086 - \WP_CLI::line( ' -> ' . $website->name . ' (' . $website->url . ')' );
1087 - \WP_CLI::line( ' -> Edit site result: ' . ( $data ? 'successed' : 'failed' ) );
1088 - }
981 + \WP_CLI::line( '' );
982 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Abandoned Plugins', 'mainwp' ) . '%n' ) );
983 + \WP_CLI::line( '' );
1089 984
1090 - /**
1091 - * Syncs child site.
1092 - *
1093 - * Command Example: wp mainwp site --sync-site [<websiteid>].
1094 - *
1095 - * @param array $args Arguments.
1096 - * @param array $assoc_args Arguments.
1097 - * @param object $website Object containing child site data.
1098 - */
1099 - public static function callback_site_sync_site( $args = array(), $assoc_args = array(), $website = false ) {
1100 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1101 - $error = false;
1102 - try {
1103 - MainWP_Sync::sync_site( $website );
1104 - } catch ( \Exception $e ) {
1105 - $error = $e->getMessage();
1106 - }
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 + }
1107 993
1108 - if ( empty( $error ) ) {
1109 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' synced successfully.', 'mainwp' ) . '%n' ) );
1110 - } else {
1111 - \WP_CLI::line( \WP_CLI::colorize( '%r' . esc_html__( 'Process failed with error:', 'mainwp' ) . '%n' ) );
1112 - \WP_CLI::line( $error );
1113 - }
1114 - }
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();
1115 1006
1116 - /**
1117 - * Reconnects child site.
1118 - *
1119 - * Command Example: wp mainwp site --reconnect-site [<websiteid>].
1120 - *
1121 - * @param array $args Arguments.
1122 - * @param array $assoc_args Arguments.
1123 - * @param object $website Object containing child site data.
1124 - */
1125 - public static function callback_site_reconnect_site( $args = array(), $assoc_args = array(), $website = false ) {
1126 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1127 - $error = false;
1128 - try {
1129 - MainWP_Manage_Sites_View::m_reconnect_site( $website );
1130 - } catch ( \Exception $e ) {
1131 - $error = $e->getMessage();
1132 - }
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 + }
1133 1011
1134 - if ( empty( $error ) ) {
1135 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' reconnected successfully.', 'mainwp' ) . '%n' ) );
1136 - } else {
1137 - \WP_CLI::line( \WP_CLI::colorize( '%r' . esc_html__( 'Process failed with error:', 'mainwp' ) . '%n' ) );
1138 - \WP_CLI::line( $error );
1139 - }
1140 - }
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();
1141 1024
1142 - /**
1143 - * Disconnects child site.
1144 - *
1145 - * Command Example: wp mainwp site --disconnect-site [<websiteid>].
1146 - *
1147 - * @param array $args Arguments.
1148 - * @param array $assoc_args Arguments.
1149 - * @param object $website Object containing child site data.
1150 - */
1151 - public static function callback_site_disconnect_site( $args = array(), $assoc_args = array(), $website = false ) {
1152 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1025 + \WP_CLI::line( '' );
1026 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Abandoned Themes', 'mainwp' ) . '%n' ) );
1027 + \WP_CLI::line( '' );
1153 1028
1154 - $error = false;
1155 - try {
1156 - MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
1157 - } catch ( \Exception $e ) {
1158 - $error = $e->getMessage();
1159 - }
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 + }
1160 1036
1161 - if ( empty( $error ) ) {
1162 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' disconnected successfully.', 'mainwp' ) . '%n' ) );
1163 - } else {
1164 - \WP_CLI::line( \WP_CLI::colorize( '%r' . esc_html__( 'Process failed with error:', 'mainwp' ) . '%n' ) );
1165 - \WP_CLI::line( $error );
1166 - }
1167 - }
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();
1168 1049
1169 - /**
1170 - * Removes child site from the MainWP Dashboard.
1171 - *
1172 - * Command Example: wp mainwp site --remove-site [<websiteid>].
1173 - *
1174 - * @param array $args Arguments.
1175 - * @param array $assoc_args Arguments.
1176 - * @param object $website Object containing child site data.
1177 - */
1178 - public static function callback_site_remove_site( $args = array(), $assoc_args = array(), $website = false ) {
1179 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1180 - $data = MainWP_Manage_Sites_Handler::remove_website( $website->id );
1181 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'Site removed successfully.', 'mainwp' ) . '%n' ) );
1182 - }
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 + }
1183 1054
1184 - /**
1185 - * Updates WP Core on a child site.
1186 - *
1187 - * Command Example: wp mainwp site --site-update-wordpress [<websiteid>].
1188 - *
1189 - * @param array $args Arguments.
1190 - * @param array $assoc_args Arguments.
1191 - * @param object $website Object containing child site data.
1192 - */
1193 - public static function callback_site_site_update_wordpress( $args = array(), $assoc_args = array(), $website = false ) {
1194 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1195 - $error = false;
1196 - try {
1197 - $data = MainWP_Updates_Handler::upgrade_website( $website );
1198 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' updated successfully.', 'mainwp' ) . '%n' ) );
1199 - } catch ( \Exception $e ) {
1200 - \WP_CLI::error( 'Updates failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
1201 - if ( $e->getMesage() === 'WPERROR' ) {
1202 - \WP_CLI::debug( 'Error: ' . MainWP_Utility::value_to_string( $e->get_message_extra(), 1 ) );
1203 - }
1204 - }
1205 - }
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 + }
1206 1069
1207 - /**
1208 - * Updates all plugins on a child site.
1209 - *
1210 - * Command Example: wp mainwp site --site-update-plugins [<websiteid>].
1211 - *
1212 - * @param array $args Arguments.
1213 - * @param array $assoc_args Arguments.
1214 - * @param object $website Object containing child site data.
1215 - */
1216 - public static function callback_site_site_update_plugins( $args = array(), $assoc_args = array(), $website = false ) {
1217 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
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 + }
1218 1090
1219 - $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
1220 - $slugs = array();
1221 - foreach ( $plugin_upgrades as $slug => $plugin ) {
1222 - $slugs[] = $slug;
1223 - }
1224 - $list = urldecode( implode( ',', $slugs ) );
1091 + \WP_CLI::line( '' );
1092 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . ' Health: %n ' ) . $health_score );
1093 + \WP_CLI::line( '' );
1094 + }
1225 1095
1226 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' plugins updated successfully.', 'mainwp' ) . '%n' ) );
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' );
1227 1107
1228 - try {
1229 - MainWP_Connect::fetch_url_authed(
1230 - $website,
1231 - 'upgradeplugintheme',
1232 - array(
1233 - 'type' => 'plugin',
1234 - 'list' => $list,
1235 - )
1236 - );
1237 - } catch ( \Exception $e ) {
1238 - $error = MainWP_Error_Helper::get_console_error_message( $e );
1239 - }
1240 - }
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( '' );
1241 1111
1242 - /**
1243 - * Updates all themes on a child site.
1244 - *
1245 - * Command Example: wp mainwp site --site-update-themes [<websiteid>].
1246 - *
1247 - * @param array $args Arguments.
1248 - * @param array $assoc_args Arguments.
1249 - * @param object $website Object containing child site data.
1250 - */
1251 - public static function callback_site_site_update_themes( $args = array(), $assoc_args = array(), $website = false ) {
1252 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1253 - $theme_upgrades = json_decode( $website->theme_upgrades, true );
1254 - $slugs = array();
1255 - foreach ( $theme_upgrades as $slug => $theme ) {
1256 - $slugs[] = $slug;
1257 - }
1258 - $list = urldecode( implode( ',', $slugs ) );
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 + }
1259 1119
1260 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' themes updated successfully.', 'mainwp' ) . '%n' ) );
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 + }
1261 1138
1262 - try {
1263 - MainWP_Connect::fetch_url_authed(
1264 - $website,
1265 - 'upgradeplugintheme',
1266 - array(
1267 - 'type' => 'theme',
1268 - 'list' => $list,
1269 - )
1270 - );
1271 - } catch ( \Exception $e ) {
1272 - $error = MainWP_Error_Helper::get_console_error_message( $e );
1273 - }
1274 - }
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 + }
1275 1155
1276 - /**
1277 - * Updates translations on a child site.
1278 - *
1279 - * Command Example: wp mainwp site --site-update-translations [<websiteid>].
1280 - *
1281 - * @param array $args Arguments.
1282 - * @param array $assoc_args Arguments.
1283 - * @param object $website Object containing child site data.
1284 - */
1285 - public static function callback_site_site_update_translations( $args = array(), $assoc_args = array(), $website = false ) {
1286 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
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 + }
1287 1173
1288 - $translation_upgrades = json_decode( $website->translation_upgrades, true );
1289 - $slugs = array();
1290 - foreach ( $translation_upgrades as $translation_upgrade ) {
1291 - $slugs[] = $translation_upgrade['slug'];
1292 - }
1293 - $list = urldecode( implode( ',', $slugs ) );
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 + }
1294 1181
1295 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' translations updated successfully.', 'mainwp' ) . '%n' ) );
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 + }
1296 1199
1297 - try {
1298 - MainWP_Connect::fetch_url_authed(
1299 - $website,
1300 - 'upgradetranslation',
1301 - array(
1302 - 'type' => 'translation',
1303 - 'list' => $list,
1304 - )
1305 - );
1306 - } catch ( \Exception $e ) {
1307 - $error = MainWP_Error_Helper::get_console_error_message( $e );
1308 - }
1309 - }
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 + }
1310 1207
1311 - /**
1312 - * Updates single item on a child site.
1313 - *
1314 - * Command Example: wp mainwp site --site-update-item [<websiteid>] --type=[type] --slug=[slug].
1315 - *
1316 - * @param array $args Arguments.
1317 - * @param array $assoc_args Arguments.
1318 - * @param object $website Object containing child site data.
1319 - */
1320 - public static function callback_site_site_update_item( $args = array(), $assoc_args = array(), $website = false ) {
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' ) );
1321 1219
1322 - $params = self::get_cli_params( $args, $assoc_args, array( 'type', 'slug' ) );
1220 + $error = false;
1221 + try {
1222 + MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
1223 + } catch ( \Exception $e ) {
1224 + $error = $e->getMessage();
1225 + }
1323 1226
1324 - $type = $params['type'];
1325 - $slug = $params['slug'];
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 + }
1326 1234
1327 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
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 + }
1328 1249
1329 - try {
1330 - $data = MainWP_Connect::fetch_url_authed(
1331 - $website,
1332 - 'upgradeplugintheme',
1333 - array(
1334 - 'type' => $type,
1335 - 'list' => urldecode( $slug ),
1336 - )
1337 - );
1338 - } catch ( \Exception $e ) {
1339 - $error = MainWP_Error_Helper::get_console_error_message( $e );
1340 - }
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 + }
1341 1271
1342 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' item updated successfully.', 'mainwp' ) . '%n' ) );
1343 - }
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' ) );
1344 1283
1345 - /**
1346 - * Manages plgins on a child site.
1347 - *
1348 - * Command Example: wp mainwp site --site-manage-plugin [<websiteid>] --action=[action] --plugin=[plugin].
1349 - *
1350 - * Action: activate|deactivate|delete
1351 - * Plugin: plugin slugs separated by ||.
1352 - *
1353 - * @param array $args Arguments.
1354 - * @param array $assoc_args Arguments.
1355 - * @param object $website Object containing child site data.
1356 - */
1357 - public static function callback_site_site_manage_plugin( $args = array(), $assoc_args = array(), $website = false ) {
1358 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1284 + $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
1359 1285
1360 - $params = self::get_cli_params( $args, $assoc_args, array( 'plugin', 'action' ) );
1361 - $plugin = $params['plugin'];
1362 - $action = $params['action'];
1286 + if ( $website->is_ignorePluginUpdates ) {
1287 + $plugin_upgrades = array();
1288 + }
1363 1289
1364 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $plugin . ' ' . $action . 'd' . esc_html__( ' successfully.', 'mainwp' ) . '%n' ) );
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 );
1365 1295
1366 - try {
1367 - MainWP_Connect::fetch_url_authed(
1368 - $website,
1369 - 'plugin_action',
1370 - array(
1371 - 'action' => $action,
1372 - 'plugin' => $plugin,
1373 - )
1374 - );
1375 - } catch ( \Exception $e ) {
1376 - // ok.
1377 - }
1378 - }
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 );
1379 1300
1380 - /**
1381 - * Manages themes on a child site.
1382 - *
1383 - * Command Example: wp mainwp site --site-manage-theme [<websiteid>] --action=[action] --theme=[theme].
1384 - *
1385 - * action: activate|delete.
1386 - * theme: theme name.
1387 - *
1388 - * @param array $args Arguments.
1389 - * @param array $assoc_args Arguments.
1390 - * @param object $website Object containing child site data.
1391 - */
1392 - public static function callback_site_site_manage_theme( $args = array(), $assoc_args = array(), $website = false ) {
1393 - \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1301 + }
1302 + }
1394 1303
1395 - $params = self::get_cli_params( $args, $assoc_args, array( 'theme', 'action' ) );
1396 - $theme = $params['theme'];
1397 - $action = $params['action'];
1304 + $slugs = array();
1305 + foreach ( $plugin_upgrades as $slug => $plugin ) {
1306 + $slugs[] = $slug;
1307 + }
1308 + $list = urldecode( implode( ',', $slugs ) );
1398 1309
1399 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $theme . ' ' . $action . 'd' . esc_html__( ' successfully.', 'mainwp' ) . '%n' ) );
1310 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' plugins updated successfully.', 'mainwp' ) . '%n' ) );
1400 1311
1401 - try {
1402 - MainWP_Connect::fetch_url_authed(
1403 - $website,
1404 - 'theme_action',
1405 - array(
1406 - 'action' => $action,
1407 - 'theme' => $theme,
1408 - )
1409 - );
1410 - } catch ( \Exception $e ) {
1411 - // ok.
1412 - }
1413 - }
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 + }
1414 1325
1415 - /**
1416 - * Checks child site for HTTP Status.
1417 - *
1418 - * Command Example: wp mainwp site --check-site-http-status [<websiteid>].
1419 - *
1420 - * @param array $args Arguments.
1421 - * @param array $assoc_args Arguments.
1422 - * @param object $website Object containing child site data.
1423 - */
1424 - public static function callback_site_check_site_http_status( $args = array(), $assoc_args = array(), $website = false ) {
1425 - \WP_CLI::line( '' );
1426 - \WP_CLI::line( esc_html__( 'Checking ', 'mainwp' ) . $website->name . ' (' . $website->url . '). ' . esc_html__( 'Please wait... ', 'mainwp' ) );
1427 - \WP_CLI::line( '' );
1428 - $data = MainWP_Monitoring_Handler::handle_check_website( $website );
1429 - \WP_CLI::line( \WP_CLI::colorize( '%g' . esc_html__( 'HTTP Status: ', 'mainwp' ) . '%n' . $data['httpCode'] . ' (' . $data['httpCodeString'] . ')' ) );
1430 - \WP_CLI::line( '' );
1431 - }
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 ) );
1432 1343
1433 - /**
1434 - * Lists all available update for all sites.
1435 - *
1436 - * Command Example: wp mainwp updates --available-updates [<websiteid>].
1437 - *
1438 - * @param array $args Arguments.
1439 - * @param array $assoc_args Arguments.
1440 - */
1441 - public static function callback_updates_available_updates( $args = array(), $assoc_args = array() ) {
1344 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' themes updated successfully.', 'mainwp' ) . '%n' ) );
1442 1345
1443 - \WP_CLI::line( '' );
1444 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Updates', 'mainwp' ) . '%n' ) );
1445 - \WP_CLI::line( '' );
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 + }
1446 1359
1447 - $all_updates = array();
1448 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
1449 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1450 - $wp_upgrades = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' );
1451 - $wp_upgrades = ! empty( $wp_upgrades ) ? json_decode( $wp_upgrades, true ) : array();
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' ) );
1452 1371
1453 - $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
1454 - $theme_upgrades = json_decode( $website->theme_upgrades, true );
1455 - $translation_upgrades = json_decode( $website->translation_upgrades, true );
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 ) );
1456 1378
1457 - \WP_CLI::line( \WP_CLI::colorize( '%B' . $website->name . ' (' . $website->url . ')%n' ) );
1458 - if ( 0 < count( $wp_upgrades ) ) {
1459 - \WP_CLI::line( '' );
1460 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'WordPress Core', 'mainwp' ) . '%n' ) );
1461 - \WP_CLI::line( '' );
1379 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' translations updated successfully.', 'mainwp' ) . '%n' ) );
1462 1380
1463 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $wp_upgrades['current'] );
1464 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $wp_upgrades['new'] );
1465 - }
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 + }
1466 1394
1467 - if ( 0 < count( $plugin_upgrades ) ) {
1468 - \WP_CLI::line( '' );
1469 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Plugin Updates', 'mainwp' ) . '%n' ) );
1470 - \WP_CLI::line( '' );
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 ) {
1471 1405
1472 - foreach ( $plugin_upgrades as $plugin_upgrade ) {
1473 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $plugin_upgrade['Name'] );
1474 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $plugin_upgrade['Version'] );
1475 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $plugin_upgrade['update']['new_version'] );
1476 - \WP_CLI::line( '' );
1477 - }
1478 - }
1406 + $params = static::get_cli_params( $args, $assoc_args, array( 'type', 'slug' ) );
1479 1407
1480 - if ( 0 < count( $theme_upgrades ) ) {
1481 - \WP_CLI::line( '' );
1482 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Theme Updates', 'mainwp' ) . '%n' ) );
1483 - \WP_CLI::line( '' );
1408 + $type = $params['type'];
1409 + $slug = $params['slug'];
1484 1410
1485 - foreach ( $theme_upgrades as $theme_upgrade ) {
1486 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $theme_upgrade['Name'] );
1487 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $theme_upgrade['Version'] );
1488 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $theme_upgrade['update']['new_version'] );
1489 - \WP_CLI::line( '' );
1490 - }
1491 - }
1411 + \WP_CLI::line( esc_html__( 'Please wait... ', 'mainwp' ) );
1492 1412
1493 - if ( 0 < count( $translation_upgrades ) ) {
1494 - \WP_CLI::line( '' );
1495 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Translation Updates', 'mainwp' ) . '%n' ) );
1496 - \WP_CLI::line( '' );
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 + }
1497 1425
1498 - foreach ( $translation_upgrades as $translation_upgrade ) {
1499 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $translation_upgrade['Name'] );
1500 - \WP_CLI::line( \WP_CLI::colorize( '%gDetected:%n ' ) . $translation_upgrade['Version'] );
1501 - \WP_CLI::line( \WP_CLI::colorize( '%gLatest:%n ' ) . $translation_upgrade['update']['new_version'] );
1502 - \WP_CLI::line( '' );
1503 - }
1504 - }
1505 - }
1506 - MainWP_DB::free_result( $websites );
1507 - }
1426 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $website->name . esc_html__( ' item updated successfully.', 'mainwp' ) . '%n' ) );
1427 + }
1508 1428
1509 - /**
1510 - * Lists all ignored plugins for a child site.
1511 - *
1512 - * Command Example: wp mainwp updates --ignored-plugins-updates [<websiteid>].
1513 - *
1514 - * @param array $args Arguments.
1515 - * @param array $assoc_args Arguments.
1516 - * @param object|bool $website Website object.
1517 - */
1518 - public static function callback_updates_ignored_plugins_updates( $args = array(), $assoc_args = array(), $website = false ) {
1519 - $ignored_all = false;
1520 - if ( $website ) {
1521 - \WP_CLI::line( '' );
1522 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1523 - \WP_CLI::line( '' );
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' ) );
1524 1443
1525 - if ( $website->is_ignorePluginUpdates ) {
1526 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'All ignored', 'mainwp' ) . '%n' ) );
1527 - $ignored_all = true;
1528 - }
1529 - }
1444 + $params = static::get_cli_params( $args, $assoc_args, array( 'plugin', 'action' ) );
1445 + $plugin = $params['plugin'];
1446 + $action = $params['action'];
1530 1447
1531 - if ( ! $ignored_all ) {
1532 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1533 - $data = json_decode( $userExtension->ignored_plugins, true );
1534 - foreach ( $data as $plugin => $value ) {
1535 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $value );
1536 - }
1537 - if ( $website ) {
1538 - $ignored_plugins = json_decode( $website->ignored_plugins, true );
1539 - if ( is_array( $ignored_plugins ) ) {
1540 - foreach ( $ignored_plugins as $slug => $name ) {
1541 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $name );
1542 - }
1543 - }
1544 - }
1545 - }
1448 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $plugin . ' ' . $action . 'd' . esc_html__( ' successfully.', 'mainwp' ) . '%n' ) );
1546 1449
1547 - \WP_CLI::line( '' );
1548 - }
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 + }
1549 1463
1550 - /**
1551 - * Lists all per site ignored plugin updates for a child site.
1552 - *
1553 - * Command Example: wp mainwp updates --site-ignored-plugins-updates [<websiteid>].
1554 - *
1555 - * @param array $args Arguments.
1556 - * @param array $assoc_args Arguments.
1557 - * @param object $website Object containing child site data.
1558 - */
1559 - public static function callback_updates_site_ignored_plugins_updates( $args = array(), $assoc_args = array(), $website = false ) {
1560 - $data = json_decode( $website->ignored_plugins, 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' ) );
1561 1478
1562 - \WP_CLI::line( '' );
1563 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1564 - \WP_CLI::line( '' );
1479 + $params = static::get_cli_params( $args, $assoc_args, array( 'theme', 'action' ) );
1480 + $theme = $params['theme'];
1481 + $action = $params['action'];
1565 1482
1566 - foreach ( $data as $plugin => $value ) {
1567 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $value );
1568 - }
1483 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $theme . ' ' . $action . 'd' . esc_html__( ' successfully.', 'mainwp' ) . '%n' ) );
1569 1484
1570 - \WP_CLI::line( '' );
1571 - }
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 + }
1572 1498
1573 - /**
1574 - * Lists all ignored theme updates for a child site.
1575 - *
1576 - * Command Example: wp mainwp updates --ignored-themes-updates [<websiteid>].
1577 - *
1578 - * @param array $args Arguments.
1579 - * @param array $assoc_args Arguments.
1580 - * @param object $website Object containing child site data.
1581 - */
1582 - public static function callback_updates_ignored_themes_updates( $args = array(), $assoc_args = array(), $website = false ) {
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 + }
1583 1516
1584 - $ignored_all = false;
1585 - if ( $website ) {
1586 - if ( $website->is_ignoreThemeUpdates ) {
1587 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'All ignored', 'mainwp' ) . '%n' ) );
1588 - $ignored_all = true;
1589 - }
1590 - \WP_CLI::line( '' );
1591 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1592 - \WP_CLI::line( '' );
1593 - }
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.
1594 1526
1595 - if ( ! $ignored_all ) {
1596 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1597 - $data = json_decode( $userExtension->ignored_themes, true );
1598 - foreach ( $data as $theme => $value ) {
1599 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $value );
1600 - }
1601 - if ( $website ) {
1602 - $ignored_themes = json_decode( $website->ignored_themes, true );
1603 - if ( is_array( $ignored_themes ) ) {
1604 - foreach ( $ignored_themes as $slug => $name ) {
1605 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $name );
1606 - }
1607 - }
1608 - }
1609 - }
1527 + \WP_CLI::line( '' );
1528 + \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Available Updates', 'mainwp' ) . '%n' ) );
1529 + \WP_CLI::line( '' );
1610 1530
1611 - \WP_CLI::line( '' );
1612 - }
1531 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
1532 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1613 1533
1614 - /**
1615 - * Lists all per site ignored theme updates for a child site.
1616 - *
1617 - * Command Example: wp mainwp updates --site-ignored-themes-updates [<websiteid>].
1618 - *
1619 - * @param array $args Arguments.
1620 - * @param array $assoc_args Arguments.
1621 - * @param object $website Object containing child site data.
1622 - */
1623 - public static function callback_updates_site_ignored_themes_updates( $args = array(), $assoc_args = array(), $website = false ) {
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();
1624 1537
1625 - $data = json_decode( $website->ignored_themes, true );
1538 + if ( $website->is_ignoreCoreUpdates || MainWP_Common_Functions::instance()->is_ignored_updates( $wp_upgrades, $ignored_core_upgrades, 'core' ) ) {
1539 + $wp_upgrades = array();
1540 + }
1626 1541
1627 - \WP_CLI::line( '' );
1628 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1629 - \WP_CLI::line( '' );
1542 + $ignored_trans_updates = isset( $site_options['ignored_trans_updates'] ) ? (int) $site_options['ignored_trans_updates'] : false;
1630 1543
1631 - foreach ( $data as $theme => $value ) {
1632 - \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $value );
1633 - }
1544 + $wp_upgrades = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' );
1545 + $wp_upgrades = ! empty( $wp_upgrades ) ? json_decode( $wp_upgrades, true ) : array();
1634 1546
1635 - \WP_CLI::line( '' );
1636 - }
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 );
1637 1550
1638 - /**
1639 - * Ignores an update globally.
1640 - *
1641 - * Command Example: wp mainwp updates --ignore-updates --type=[type] --slug=[slug] --name=[name].
1642 - *
1643 - * type: plugin|theme
1644 - *
1645 - * @param array $args Arguments.
1646 - * @param array $assoc_args Arguments.
1647 - * @param object $website Object containing child site data.
1648 - */
1649 - public static function callback_updates_ignore_updates( $args = array(), $assoc_args = array(), $website = false ) {
1551 + if ( $website->is_ignorePluginUpdates ) {
1552 + $plugin_upgrades = array();
1553 + }
1554 + if ( $website->is_ignoreThemeUpdates ) {
1555 + $theme_upgrades = array();
1556 + }
1650 1557
1651 - $params = self::get_cli_params( $args, $assoc_args, array( 'type', 'slug', 'name' ) );
1558 + if ( $ignored_trans_updates ) {
1559 + $translation_upgrades = array();
1560 + }
1652 1561
1653 - $type = $params['type'];
1654 - $slug = $params['slug'];
1655 - $name = $params['name'];
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 );
1656 1567
1657 - MainWP_Updates_Handler::ignore_plugins_themes( $type, $slug, $name );
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 );
1658 1572
1659 - \WP_CLI::line( '' );
1660 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $name . esc_html__( ' ignorred successfully.', 'mainwp' ) . '%n' ) );
1661 - \WP_CLI::line( '' );
1662 - }
1573 + }
1574 + }
1663 1575
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 + }
1664 1581
1665 - /**
1666 - * Ignores an update on a child site.
1667 - *
1668 - * Command Example: wp mainwp updates --ignore-update [<websiteid>] --type=[type] --slug=[slug] --name=[name].
1669 - *
1670 - * @param array $args Arguments.
1671 - * @param array $assoc_args Arguments.
1672 - * @param object $website Object containing child site data.
1673 - */
1674 - public static function callback_updates_ignore_update( $args = array(), $assoc_args = array(), $website = false ) {
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 + }
1675 1587
1676 - $params = self::get_cli_params( $args, $assoc_args, array( 'type', 'slug', 'name' ) );
1677 - $type = $params['type'];
1678 - $slug = $params['slug'];
1679 - $name = $params['name'];
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( '' );
1680 1593
1681 - MainWP_Updates_Handler::ignore_plugin_theme( $type, $slug, $name, $website->id );
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 + }
1682 1597
1683 - \WP_CLI::line( '' );
1684 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $name . esc_html__( ' ignorred successfully.', 'mainwp' ) . '%n' ) );
1685 - \WP_CLI::line( '' );
1686 - }
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( '' );
1687 1602
1688 - /**
1689 - * Unignores an update.
1690 - *
1691 - * Command Example: wp mainwp updates --unignore-updates --type=[type] --slug=[slug].
1692 - *
1693 - * @param array $args Arguments.
1694 - * @param array $assoc_args Arguments.
1695 - * @param object $website Object containing child site data.
1696 - */
1697 - public static function callback_updates_unignore_updates( $args = array(), $assoc_args = array(), $website = false ) {
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 + }
1698 1610
1699 - $params = self::get_cli_params( $args, $assoc_args, array( 'type', 'slug' ) );
1700 - $type = $params['type'];
1701 - $slug = $params['slug'];
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( '' );
1702 1615
1703 - MainWP_Updates_Handler::unignore_plugins_themes( $type, $slug );
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 + }
1704 1623
1705 - \WP_CLI::line( '' );
1706 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $slug . esc_html__( ' unignorred successfully.', 'mainwp' ) . '%n' ) );
1707 - \WP_CLI::line( '' );
1708 - }
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( '' );
1709 1628
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 + }
1710 1639
1711 - /**
1712 - * Unitnores an update on a child site.
1713 - *
1714 - * Command Example: wp mainwp updates --unignore-update [<websiteid>] --type=[type] --slug=[slug].
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_unignore_update( $args = array(), $assoc_args = array(), $website = false ) {
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( '' );
1721 1655
1722 - $params = self::get_cli_params( $args, $assoc_args, array( 'type', 'slug' ) );
1723 - $type = $params['type'];
1724 - $slug = $params['slug'];
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 + }
1725 1661
1726 - MainWP_Updates_Handler::unignore_plugin_theme( $type, $slug, $website->id );
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;
1727 1668
1728 - \WP_CLI::line( '' );
1729 - \WP_CLI::line( \WP_CLI::colorize( '%g' . $slug . esc_html__( ' unignorred successfully.', 'mainwp' ) . '%n' ) );
1730 - \WP_CLI::line( '' );
1731 - }
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 + }
1732 1682
1733 - /**
1734 - * Syncs all child sites.
1735 - *
1736 - * Command Example: wp mainwp sites --sync-sites.
1737 - *
1738 - * @param array $args Arguments.
1739 - * @param array $assoc_args Arguments.
1740 - */
1741 - public static function handle_sync_sites( $args = array(), $assoc_args = false ) {
1683 + \WP_CLI::line( '' );
1684 + }
1742 1685
1743 - $sites = self::get_cli_params( $args, $assoc_args, 'sites' );
1744 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
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 );
1745 1697
1746 - $warnings = 0;
1747 - $errors = 0;
1698 + \WP_CLI::line( '' );
1699 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1700 + \WP_CLI::line( '' );
1748 1701
1749 - \WP_CLI::line( '' );
1750 - \WP_CLI::line( \WP_CLI::colorize( '%9' . esc_html__( 'Syncing sites. Please wait...', 'mainwp' ) . '%n' ) );
1751 - \WP_CLI::line( '' );
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 + }
1752 1707
1753 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1754 - if ( ( count( $sites ) > 0 ) && ( ! in_array( $website->id, $sites, true ) ) ) {
1755 - continue;
1756 - }
1708 + \WP_CLI::line( '' );
1709 + }
1757 1710
1758 - \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' (' . $website->url . ')%n' ) );
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 ) {
1759 1721
1760 - try {
1761 - if ( MainWP_Sync::sync_site( $website ) ) {
1762 - \WP_CLI::success( esc_html__( 'Sync succeeded', 'mainwp' ) );
1763 - } else {
1764 - \WP_CLI::warning( esc_html__( 'Sync failed', 'mainwp' ) );
1765 - ++$warnings;
1766 - }
1767 - } catch ( \Exception $e ) {
1768 - \WP_CLI::error( esc_html__( 'Sync failed: ', 'mainwp' ) . MainWP_Error_Helper::get_console_error_message( $e ) );
1769 - ++$errors;
1770 - }
1771 - \WP_CLI::line( '' );
1772 - }
1773 - MainWP_DB::free_result( $websites );
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 + }
1774 1732
1775 - if ( $errors > 0 ) {
1776 - \WP_CLI::error( esc_html__( 'Sync process completed with errors.', 'mainwp' ) );
1777 - } elseif ( $warnings > 0 ) {
1778 - \WP_CLI::warning( esc_html__( 'Sync process completed with warnings.', 'mainwp' ) );
1779 - } else {
1780 - \WP_CLI::success( esc_html__( 'Sync process completed successfully.', 'mainwp' ) );
1781 - }
1782 - \WP_CLI::line( '' );
1783 - }
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 + }
1784 1748
1749 + \WP_CLI::line( '' );
1750 + }
1785 1751
1786 - /**
1787 - * Prints process success message.
1788 - */
1789 - public static function print_process_success() {
1790 - \WP_CLI::success( 'Process ran.' );
1791 - }
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 ) {
1792 1762
1793 - /**
1794 - * Prints child sites list.
1795 - *
1796 - * @param array $websites Array containing child sites.
1797 - * @param bool $is_objs Array of objects.
1798 - */
1799 - public static function print_sites( $websites, $is_objs = false ) {
1800 - $data = array();
1801 - if ( $is_objs ) {
1802 - $fields = array( 'id', 'url', 'name' );
1803 - $dbwebsites = array();
1804 - foreach ( $websites as $site_id => $website ) {
1805 - $data[ $site_id ] = MainWP_Utility::map_site( $website, $fields, false );
1806 - }
1807 - } else {
1808 - $data = $websites;
1809 - }
1763 + $data = json_decode( $website->ignored_themes, true );
1810 1764
1811 - $idLength = strlen( 'id' );
1812 - $nameLength = strlen( 'name' );
1813 - $urlLength = strlen( 'url' );
1765 + \WP_CLI::line( '' );
1766 + \WP_CLI::line( \WP_CLI::colorize( '%9' . $website->name . ' ' . esc_html__( 'Ignored Updates', 'mainwp' ) . '%n' ) );
1767 + \WP_CLI::line( '' );
1814 1768
1815 - foreach ( $data as $site ) {
1816 - if ( $idLength < strlen( $site['id'] ) ) {
1817 - $idLength = strlen( $site['id'] );
1818 - }
1819 - if ( $nameLength < strlen( $site['name'] ) ) {
1820 - $nameLength = strlen( $site['name'] );
1821 - }
1822 - if ( $urlLength < strlen( $site['url'] ) ) {
1823 - $urlLength = strlen( $site['url'] );
1824 - }
1825 - }
1769 + foreach ( $data as $value ) {
1770 + \WP_CLI::line( \WP_CLI::colorize( '%gName:%n ' ) . $value );
1771 + }
1826 1772
1827 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . 's+', '', '', '', '' ) );
1828 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $urlLength . 's |', 'id', 'name', 'url', 'version' ) );
1829 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . 's+', '', '', '', '' ) );
1773 + \WP_CLI::line( '' );
1774 + }
1830 1775
1831 - foreach ( $data as $site ) {
1832 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $urlLength . 's |', $site['id'], $site['name'], $site['url'] ) );
1833 - }
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 ) {
1834 1788
1835 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . 's+', '', '', '', '' ) );
1836 - }
1789 + $params = static::get_cli_params( $args, $assoc_args, array( 'type', 'slug', 'name' ) );
1790 +
1791 + $type = $params['type'];
1792 + $slug = $params['slug'];
1793 + $name = $params['name'];
1794 +
1795 + MainWP_Updates_Handler::ignore_plugins_themes( $type, $slug, $name );
1796 +
1797 + \WP_CLI::line( '' );
1798 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $name . esc_html__( ' ignorred successfully.', 'mainwp' ) . '%n' ) );
1799 + \WP_CLI::line( '' );
1800 + }
1801 +
1802 +
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 ) {
1813 +
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'];
1818 +
1819 + MainWP_Updates_Handler::ignore_plugin_theme( $type, $slug, $name, $website->id );
1820 +
1821 + \WP_CLI::line( '' );
1822 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $name . esc_html__( ' ignorred successfully.', 'mainwp' ) . '%n' ) );
1823 + \WP_CLI::line( '' );
1824 + }
1825 +
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 ) {
1836 +
1837 + $params = static::get_cli_params( $args, $assoc_args, array( 'type', 'slug' ) );
1838 + $type = $params['type'];
1839 + $slug = $params['slug'];
1840 +
1841 + MainWP_Updates_Handler::unignore_global_plugins_themes( $type, $slug );
1842 +
1843 + \WP_CLI::line( '' );
1844 + \WP_CLI::line( \WP_CLI::colorize( '%g' . $slug . esc_html__( ' unignorred successfully.', 'mainwp' ) . '%n' ) );
1845 + \WP_CLI::line( '' );
1846 + }
1847 +
1848 +
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 ) {
1859 +
1860 + $params = static::get_cli_params( $args, $assoc_args, array( 'type', 'slug' ) );
1861 + $type = $params['type'];
1862 + $slug = $params['slug'];
1863 +
1864 + MainWP_Updates_Handler::unignore_plugin_theme( $type, $slug, $website->id );
1865 +
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 + }
1837 1974 }