PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.3
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 5.2.2 5.3 All 153 releases
mainwp / pages / page-mainwp-plugins.php

page-mainwp-plugins.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.3, at pages/page-mainwp-plugins.php

3,007 lines 163.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Plugins Page.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_Plugins
12 *
13 * @package MainWP\Dashboard\
14 *
15 * @uses \MainWP\Dashboard\MainWP_Install_Bulk
16 */
17 class MainWP_Plugins { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
18
19 // phpcs:disable Generic.Metrics.CyclomaticComplexity -- This is the only way to achieve desired results, pull request solutions appreciated.
20
21 /**
22 * Get Class Name.
23 *
24 * @return string __CLASS__
25 */
26 public static function get_class_name() {
27 return __CLASS__;
28 }
29
30 /**
31 * MainWP Plugins sub-pages.
32 *
33 * @var array $subPages MainWP Plugins Sub Pages.
34 */
35 public static $subPages;
36
37 /**
38 * Plugins table.
39 *
40 * @var mixed $pluginsTable Plugins table.
41 */
42 public static $pluginsTable;
43
44 /** Instantiate Hooks. */
45 public static function init() {
46 /**
47 * This hook allows you to render the Plugins page header via the 'mainwp-pageheader-plugins' action.
48 *
49 * @link http://codex.mainwp.com/#mainwp-pageheader-plugins
50 *
51 * This hook is normally used in the same context of 'mainwp-getsubpages-plugins'
52 * @link http://codex.mainwp.com/#mainwp-getsubpages-plugins
53 *
54 * @see \MainWP_Plugins::render_header
55 */
56 add_action( 'mainwp-pageheader-plugins', array( static::get_class_name(), 'render_header' ) );
57
58 /**
59 * This hook allows you to render the Plugins page footer via the 'mainwp-pagefooter-plugins' action.
60 *
61 * @link http://codex.mainwp.com/#mainwp-pagefooter-plugins
62 *
63 * This hook is normally used in the same context of 'mainwp-getsubpages-plugins'
64 * @link http://codex.mainwp.com/#mainwp-getsubpages-plugins
65 *
66 * @see \MainWP_Plugins::render_footer
67 */
68 add_action( 'mainwp-pagefooter-plugins', array( static::get_class_name(), 'render_footer' ) );
69
70 add_action( 'mainwp_help_sidebar_content', array( static::get_class_name(), 'mainwp_help_content' ) );
71 }
72
73 /**
74 * Instantiate Main Plugins Menu.
75 *
76 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
77 */
78 public static function init_menu() {
79 add_submenu_page(
80 'mainwp_tab',
81 __( 'Plugins', 'mainwp' ),
82 '<span id="mainwp-Plugins">' . esc_html__( 'Plugins', 'mainwp' ) . '</span>',
83 'read',
84 'PluginsManage',
85 array(
86 static::get_class_name(),
87 'render',
88 )
89 );
90 if ( \mainwp_current_user_can( 'dashboard', 'install_plugins' ) ) {
91 $page = add_submenu_page(
92 'mainwp_tab',
93 __( 'Plugins', 'mainwp' ),
94 '<div class="mainwp-hidden">' . esc_html__( 'Install ', 'mainwp' ) . '</div>',
95 'read',
96 'PluginsInstall',
97 array(
98 static::get_class_name(),
99 'render_install',
100 )
101 );
102
103 add_action( 'load-' . $page, array( static::get_class_name(), 'load_page' ) );
104 }
105 add_submenu_page(
106 'mainwp_tab',
107 __( 'Plugins', 'mainwp' ),
108 '<div class="mainwp-hidden">' . esc_html__( 'Advanced Auto Updates', 'mainwp' ) . '</div>',
109 'read',
110 'PluginsAutoUpdate',
111 array(
112 static::get_class_name(),
113 'render_auto_update',
114 )
115 );
116 add_submenu_page(
117 'mainwp_tab',
118 __( 'Plugins', 'mainwp' ),
119 '<div class="mainwp-hidden">' . esc_html__( 'Ignored Updates', 'mainwp' ) . '</div>',
120 'read',
121 'PluginsIgnore',
122 array(
123 static::get_class_name(),
124 'render_ignore',
125 )
126 );
127 add_submenu_page(
128 'mainwp_tab',
129 __( 'Plugins', 'mainwp' ),
130 '<div class="mainwp-hidden">' . esc_html__( 'Ignored Abandoned', 'mainwp' ) . '</div>',
131 'read',
132 'PluginsIgnoredAbandoned',
133 array(
134 static::get_class_name(),
135 'render_ignored_abandoned',
136 )
137 );
138
139 /**
140 * Plugins Subpages
141 *
142 * Filters subpages for the Plugins page.
143 *
144 * @since Unknown
145 */
146 $sub_pages = apply_filters_deprecated( 'mainwp-getsubpages-plugins', array( array() ), '4.0.7.2', 'mainwp_getsubpages_plugins' ); // @deprecated Use 'mainwp_getsubpages_plugins' instead. NOSONAR - not IP.
147 static::$subPages = apply_filters( 'mainwp_getsubpages_plugins', $sub_pages );
148
149 if ( isset( static::$subPages ) && is_array( static::$subPages ) ) {
150 foreach ( static::$subPages as $subPage ) {
151 if ( MainWP_Menu::is_disable_menu_item( 3, 'Plugins' . $subPage['slug'] ) ) {
152 continue;
153 }
154 add_submenu_page( 'mainwp_tab', $subPage['title'], '<div class="mainwp-hidden">' . $subPage['title'] . '</div>', 'read', 'Plugins' . $subPage['slug'], $subPage['callback'] );
155 }
156 }
157 static::init_left_menu( static::$subPages );
158 }
159
160 /**
161 * Load the Plugins Page.
162 *
163 * @uses \MainWP\Dashboard\MainWP_Plugins_Install_List_Table
164 */
165 public static function load_page() {
166 static::$pluginsTable = new MainWP_Plugins_Install_List_Table();
167 $pagenum = static::$pluginsTable->get_pagenum();
168
169 static::$pluginsTable->prepare_items();
170
171 $total_pages = static::$pluginsTable->get_pagination_arg( 'total_pages' );
172
173 if ( $pagenum > $total_pages && 0 < $total_pages ) {
174 wp_safe_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
175 exit;
176 }
177 }
178
179 /**
180 * Instantiate Subpage "tabs".
181 *
182 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
183 */
184 public static function init_subpages_menu() {
185 ?>
186 <div id="menu-mainwp-Plugins" class="mainwp-submenu-wrapper" xmlns="http://www.w3.org/1999/html">
187 <div class="wp-submenu sub-open" >
188 <div class="mainwp_boxout">
189 <div class="mainwp_boxoutin"></div>
190 <a href="<?php echo esc_url( admin_url( 'admin.php?page=PluginsManage' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Manage Plugins', 'mainwp' ); ?></a>
191 <?php if ( \mainwp_current_user_can( 'dashboard', 'install_plugins' ) ) : ?>
192 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'PluginsInstall' ) ) : ?>
193 <a href="<?php echo esc_url( admin_url( 'admin.php?page=PluginsInstall' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Install Plugins', 'mainwp' ); ?></a>
194 <?php endif; ?>
195 <?php endif; ?>
196 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'PluginsAutoUpdate' ) ) : ?>
197 <a href="<?php echo esc_url( admin_url( 'admin.php?page=PluginsAutoUpdate' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Advanced Auto Updates', 'mainwp' ); ?></a>
198 <?php endif; ?>
199 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'PluginsIgnore' ) ) : ?>
200 <a href="<?php echo esc_url( admin_url( 'admin.php?page=PluginsIgnore' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Ignored Updates', 'mainwp' ); ?></a>
201 <?php endif; ?>
202 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'PluginsIgnoredAbandoned' ) ) : ?>
203 <a href="<?php echo esc_url( admin_url( 'admin.php?page=PluginsIgnoredAbandoned' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Ignored Abandoned', 'mainwp' ); ?></a>
204 <?php endif; ?>
205 <?php
206 if ( isset( static::$subPages ) && is_array( static::$subPages ) ) {
207 foreach ( static::$subPages as $subPage ) {
208 if ( MainWP_Menu::is_disable_menu_item( 3, 'Plugins' . $subPage['slug'] ) ) {
209 continue;
210 }
211 ?>
212 <a href="<?php echo esc_url( admin_url( 'admin.php?page=Plugins' . $subPage['slug'] ) ); ?>" class="mainwp-submenu"><?php echo esc_html( $subPage['title'] ); ?></a>
213 <?php
214 }
215 }
216 ?>
217 </div>
218 </div>
219 </div>
220 <?php
221 }
222
223 /**
224 * Instantiate MainWP main menu Subpages menu.
225 *
226 * @param array $subPages Subpages array.
227 *
228 * @uses MainWP_Menu::add_left_menu()
229 * @uses MainWP_Menu::init_subpages_left_menu()
230 * @uses MainWP_Menu::is_disable_menu_item()
231 * @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu()
232 */
233 public static function init_left_menu( $subPages = array() ) {
234 MainWP_Menu::add_left_menu(
235 array(
236 'title' => esc_html__( 'Plugins', 'mainwp' ),
237 'parent_key' => 'managesites',
238 'slug' => 'PluginsManage',
239 'href' => 'admin.php?page=PluginsManage',
240 'icon' => '<i class="plug icon"></i>',
241 'leftsub_order' => 5,
242 ),
243 1
244 );
245
246 $init_sub_subleftmenu = array(
247 array(
248 'title' => esc_html__( 'Manage Plugins', 'mainwp' ),
249 'parent_key' => 'PluginsManage',
250 'href' => 'admin.php?page=PluginsManage',
251 'slug' => 'PluginsManage',
252 'right' => '',
253 'leftsub_order_level2' => 1,
254 ),
255 array(
256 'title' => esc_html__( 'Install Plugins', 'mainwp' ),
257 'parent_key' => 'PluginsManage',
258 'href' => 'admin.php?page=PluginsInstall',
259 'slug' => 'PluginsInstall',
260 'right' => 'install_plugins',
261 'leftsub_order_level2' => 2,
262 ),
263 array(
264 'title' => esc_html__( 'Advanced Auto Updates', 'mainwp' ),
265 'parent_key' => 'PluginsManage',
266 'href' => 'admin.php?page=PluginsAutoUpdate',
267 'slug' => 'PluginsAutoUpdate',
268 'right' => '',
269 'leftsub_order_level2' => 3,
270 ),
271 array(
272 'title' => esc_html__( 'Ignored Updates', 'mainwp' ),
273 'parent_key' => 'PluginsManage',
274 'href' => 'admin.php?page=PluginsIgnore',
275 'slug' => 'PluginsIgnore',
276 'right' => '',
277 'leftsub_order_level2' => 4,
278 ),
279 array(
280 'title' => esc_html__( 'Abandoned Plugins', 'mainwp' ),
281 'parent_key' => 'PluginsManage',
282 'href' => 'admin.php?page=UpdatesManage&tab=abandoned-plugins',
283 'slug' => 'PluginsManage&tab=abandoned-plugins',
284 'right' => '',
285 'leftsub_order_level2' => 4.1,
286 ),
287 array(
288 'title' => esc_html__( 'Ignored Abandoned', 'mainwp' ),
289 'parent_key' => 'PluginsManage',
290 'href' => 'admin.php?page=PluginsIgnoredAbandoned',
291 'slug' => 'PluginsIgnoredAbandoned',
292 'right' => '',
293 'leftsub_order_level2' => 5,
294 ),
295
296 );
297
298 MainWP_Menu::init_subpages_left_menu( $subPages, $init_sub_subleftmenu, 'PluginsManage', 'Plugins' );
299
300 foreach ( $init_sub_subleftmenu as $item ) {
301 if ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) {
302 continue;
303 }
304 MainWP_Menu::add_left_menu( $item, 2 );
305 }
306 }
307
308 /**
309 * Render MainWP Plugins Page Header.
310 *
311 * @param string $shownPage The page slug shown at this moment.
312 *
313 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
314 * @uses \MainWP\Dashboard\MainWP_UI::render_top_header()
315 * @uses \MainWP\Dashboard\MainWP_UI::render_page_navigation()
316 */
317 public static function render_header( $shownPage = '' ) { // phpcs:ignore -- NOSONAR - complex.
318
319 $params = array(
320 'title' => esc_html__( 'Plugins', 'mainwp' ),
321 );
322
323 MainWP_UI::render_top_header( $params );
324
325 $renderItems = array();
326 $renderItems[] = array(
327 'title' => esc_html__( 'Manage Plugins', 'mainwp' ),
328 'href' => 'admin.php?page=PluginsManage',
329 'active' => ( 'Manage' === $shownPage ) ? true : false,
330 );
331
332 if ( \mainwp_current_user_can( 'dashboard', 'install_plugins' ) && ! MainWP_Menu::is_disable_menu_item( 3, 'PluginsInstall' ) ) {
333 $renderItems[] = array(
334 'title' => esc_html__( 'Install', 'mainwp' ),
335 'href' => 'admin.php?page=PluginsInstall',
336 'active' => ( 'Install' === $shownPage ) ? true : false,
337 );
338 }
339
340 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'PluginsAutoUpdate' ) ) {
341 $renderItems[] = array(
342 'title' => esc_html__( 'Advanced Auto Updates', 'mainwp' ),
343 'href' => 'admin.php?page=PluginsAutoUpdate',
344 'active' => ( 'AutoUpdate' === $shownPage ) ? true : false,
345 );
346 }
347
348 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'PluginsIgnore' ) ) {
349 $renderItems[] = array(
350 'title' => esc_html__( 'Ignored Updates', 'mainwp' ),
351 'href' => 'admin.php?page=PluginsIgnore',
352 'active' => ( 'Ignore' === $shownPage ) ? true : false,
353 );
354 }
355
356 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'PluginsIgnoredAbandoned' ) ) {
357 $renderItems[] = array(
358 'title' => esc_html__( 'Ignored Abandoned', 'mainwp' ),
359 'href' => 'admin.php?page=PluginsIgnoredAbandoned',
360 'active' => ( 'IgnoreAbandoned' === $shownPage ) ? true : false,
361 );
362 }
363
364 if ( isset( static::$subPages ) && is_array( static::$subPages ) ) {
365 foreach ( static::$subPages as $subPage ) {
366 if ( MainWP_Menu::is_disable_menu_item( 3, 'Plugins' . $subPage['slug'] ) ) {
367 continue;
368 }
369
370 $item = array();
371 $item['title'] = $subPage['title'];
372 $item['href'] = 'admin.php?page=Plugins' . $subPage['slug'];
373 $item['active'] = ( $subPage['slug'] === $shownPage ) ? true : false;
374 $renderItems[] = $item;
375 }
376 }
377
378 MainWP_UI::render_page_navigation( $renderItems );
379 }
380
381 /**
382 * Method render_footer()
383 *
384 * Render MainWP Plugins Page Footer.
385 */
386 public static function render_footer() {
387 echo '</div>';
388 }
389
390 /**
391 * Render MainWP Plugins Page.
392 *
393 * @uses \MainWP\Dashboard\MainWP_Cache::get_cached_context()
394 * @uses \MainWP\Dashboard\MainWP_Cache::get_cached_result()
395 * @uses \MainWP\Dashboard\MainWP_UI::render_empty_bulk_actions()
396 */
397 public static function render() { // phpcs:ignore -- NOSONAR - complex.
398 $cachedSearch = MainWP_Cache::get_cached_context( 'Plugins' );
399 $selected_sites = array();
400 $selected_groups = array();
401 $selected_clients = array();
402
403 if ( null !== $cachedSearch ) {
404 if ( is_array( $cachedSearch['sites'] ) ) {
405 $selected_sites = $cachedSearch['sites'];
406 } elseif ( is_array( $cachedSearch['groups'] ) ) {
407 $selected_groups = $cachedSearch['groups'];
408 } elseif ( is_array( $cachedSearch['clients'] ) ) {
409 $selected_clients = $cachedSearch['clients'];
410 }
411 }
412 $cachedResult = MainWP_Cache::get_cached_result( 'Plugins' );
413
414 if ( isset( $_POST['select_mainwp_options_plugintheme_view'] ) && check_admin_referer( 'mainwp-admin-nonce' ) && is_array( $cachedResult ) && isset( $cachedResult['result'] ) ) {
415 unset( $cachedResult['result'] ); // clear cached results.
416 }
417
418 static::render_header( 'Manage' );
419 ?>
420
421 <div id="mainwp-manage-plugins" class="ui alt segment">
422 <div class="mainwp-main-content">
423 <div class="ui mini form mainwp-actions-bar">
424 <div class="ui stackable grid">
425 <div class="ui two column row">
426 <div class="column" >
427 <span id="mainwp-plugins-bulk-actions-wapper" style="margin-right:1rem">
428 <?php
429 if ( is_array( $cachedResult ) && isset( $cachedResult['bulk_actions'] ) ) {
430 echo $cachedResult['bulk_actions']; // phpcs:ignore WordPress.Security.EscapeOutput
431 }
432 ?>
433 </span>
434 <button id="mainwp-install-to-selected-sites" class="ui mini green basic button" style="display: none; "><?php esc_html_e( 'Install to Selected Site(s)', 'mainwp' ); ?></button>
435 <?php
436 /**
437 * Action: mainwp_plugins_actions_bar_left
438 *
439 * Fires at the left side of the actions bar on the Plugins screen, after the Bulk Actions menu.
440 *
441 * @since 4.0
442 */
443 do_action( 'mainwp_plugins_actions_bar_left' );
444 ?>
445 </div>
446 <div class="right aligned column">
447 <?php static::render_select_manage_view(); ?>
448
449 <?php
450 /**
451 * Action: mainwp_plugins_actions_bar_right
452 *
453 * Fires at the right side of the actions bar on the Plugins screen.
454 *
455 * @since 4.0
456 */
457 do_action( 'mainwp_plugins_actions_bar_right' );
458 ?>
459 </div>
460 </div>
461 </div>
462 </div>
463 <div class="ui segment" id="mainwp-plugins-table-wrapper">
464 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-manage-plugins-info-message' ) ) : ?>
465 <div class="ui info message">
466 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-manage-plugins-info-message"></i>
467 <div><?php echo esc_html__( 'Manage installed plugins on your child sites. Here you can activate, deactivate, and delete installed plugins.', 'mainwp' ); ?></div>
468 <p><?php echo esc_html__( 'To Activate or Delete a specific plugin, you must search only for Inactive plugin on your child sites. If you search for Active or both Active and Inactive, the Activate and Delete actions will be disabled.', 'mainwp' ); ?></p>
469 <p><?php echo esc_html__( 'To Deactivate a specific plugin, you must search only for Active plugins on your child sites. If you search for Inactive or both Active and Inactive, the Deactivate action will be disabled.', 'mainwp' ); ?></p>
470 <p><?php printf( esc_html__( 'For additional help, please check this %1$shelp documentation%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/managing-plugins-with-mainwp/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); ?></p>
471 </div>
472 <?php endif; ?>
473 <div id="mainwp-message-zone" class="ui message" style="display:none"></div>
474 <div id="mainwp-loading-plugins-row" class="ui active inverted dimmer" style="display:none">
475 <div class="ui large text loader"><?php esc_html_e( 'Loading Plugins...', 'mainwp' ); ?></div>
476 </div>
477 <div id="mainwp-plugins-main-content" <?php echo ( null !== $cachedSearch ) ? 'style="display: block;"' : ''; ?> >
478 <div id="mainwp-plugins-content">
479 <?php if ( is_array( $cachedResult ) && isset( $cachedResult['result'] ) ) : ?>
480 <?php echo $cachedResult['result']; // phpcs:ignore WordPress.Security.EscapeOutput ?>
481 <?php else : ?>
482 <div class="ui hidden divider"></div>
483 <div class="ui hidden divider"></div>
484 <div class="ui hidden divider"></div>
485 <?php MainWP_UI::render_empty_element_placeholder( __( 'Use the search options to find the plugin you want to manage', 'mainwp' ) ); ?>
486 <?php endif; ?>
487 </div>
488 </div>
489 </div>
490 </div>
491
492 <div class="mainwp-side-content mainwp-no-padding">
493 <?php
494 /**
495 * Action: mainwp_manage_plugins_sidebar_top
496 *
497 * Fires at the top of the sidebar on Manage themes.
498 *
499 * @since 4.1
500 */
501 do_action( 'mainwp_manage_plugins_sidebar_top' );
502 ?>
503
504 <div class="mainwp-select-sites ui accordion mainwp-sidebar-accordion">
505 <?php
506 /**
507 * Action: mainwp_manage_plugins_before_select_sites
508 *
509 * Fires before the Select Sites elemnt on Manage plugins.
510 *
511 * @since 4.1
512 */
513 do_action( 'mainwp_manage_plugins_before_select_sites' );
514 ?>
515 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Sites', 'mainwp' ); ?></div>
516 <div class="content active">
517 <?php
518 $sel_params = array(
519 'class' => 'mainwp_select_sites_box_left',
520 'selected_sites' => $selected_sites,
521 'selected_groups' => $selected_groups,
522 'selected_clients' => $selected_clients,
523 'show_client' => true,
524 );
525 MainWP_UI_Select_Sites::select_sites_box( $sel_params );
526 ?>
527 </div>
528 <?php
529 /**
530 * Action: mainwp_manage_plugins_after_select_sites
531 *
532 * Fires after the Select Sites elemnt on Manage plugins.
533 *
534 * @since 4.1
535 */
536 do_action( 'mainwp_manage_plugins_after_select_sites' );
537 ?>
538 </div>
539 <div class="ui fitted divider"></div>
540 <div class="mainwp-search-options ui accordion mainwp-sidebar-accordion">
541 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Status', 'mainwp' ); ?></div>
542 <div class="content active">
543 <?php
544 /**
545 * Action: mainwp_manage_plugins_before_search_options
546 *
547 * Fires before the Search Options elemnt on Manage plugins.
548 *
549 * @since 4.1
550 */
551 do_action( 'mainwp_manage_plugins_before_search_options' );
552 ?>
553 <div class="ui info message">
554 <i class="close icon mainwp-notice-dismiss" notice-id="plugins-manage-info"></i>
555 <?php esc_html_e( 'A plugin needs to be Inactive for it to be Activated or Deleted.', 'mainwp' ); ?>
556 </div>
557 <div class="ui mini form">
558 <div class="field">
559 <select class="ui fluid dropdown" id="mainwp_plugins_search_by_status">
560 <option value=""><?php esc_html_e( 'Select status', 'mainwp' ); ?></option>
561 <option value="active" selected><?php esc_html_e( 'Active', 'mainwp' ); ?></option>
562 <option value="inactive"><?php esc_html_e( 'Inactive', 'mainwp' ); ?></option>
563 <option value="installed"><?php esc_html_e( 'Active & Inactive', 'mainwp' ); ?></option>
564 <option value="not_installed"><?php esc_html_e( 'Not installed', 'mainwp' ); ?></option>
565 </select>
566 </div>
567 </div>
568 <?php
569 /**
570 * Action: mainwp_manage_plugins_after_search_options
571 *
572 * Fires after the Search Options elemnt on Manage plugins.
573 *
574 * @since 4.1
575 */
576 do_action( 'mainwp_manage_plugins_after_search_options' );
577 ?>
578 </div>
579 </div>
580 <div class="ui fitted divider"></div>
581 <?php static::render_search_options(); ?>
582 <div class="ui fitted divider"></div>
583 <div class="mainwp-search-submit">
584 <?php
585 /**
586 * Action: mainwp_manage_plugins_before_submit_button
587 *
588 * Fires before the Submit Button elemnt on Manage plugins.
589 *
590 * @since 4.1
591 */
592 do_action( 'mainwp_manage_plugins_before_submit_button' );
593 ?>
594 <input type="button" name="mainwp-show-plugins" id="mainwp-show-plugins" class="ui green big fluid button" value="<?php esc_attr_e( 'Show Plugins', 'mainwp' ); ?>"/>
595 <?php
596 /**
597 * Action: mainwp_manage_plugins_after_submit_button
598 *
599 * Fires after the Submit Button elemnt on Manage plugins.
600 *
601 * @since 4.1
602 */
603 do_action( 'mainwp_manage_plugins_after_submit_button' );
604 ?>
605 </div>
606 <?php
607 /**
608 * Action: mainwp_manage_plugins_sidebar_bottom
609 *
610 * Fires at the bottom of the sidebar on Manage themes.
611 *
612 * @since 4.1
613 */
614 do_action( 'mainwp_manage_plugins_sidebar_bottom' );
615 ?>
616 </div>
617 <div style="clear:both"></div>
618 </div>
619 <?php
620 static::render_footer( 'Manage' );
621 }
622
623 /**
624 * Render MainWP plugins page search options.
625 *
626 * @uses \MainWP\Dashboard\MainWP_Cache::get_cached_context()
627 */
628 public static function render_search_options() {
629 $cachedSearch = MainWP_Cache::get_cached_context( 'Plugins' );
630 $statuses = isset( $cachedSearch['status'] ) ? $cachedSearch['status'] : array();
631 if ( $cachedSearch && isset( $cachedSearch['keyword'] ) ) {
632 $cachedSearch['keyword'] = trim( $cachedSearch['keyword'] );
633 }
634 $disabledNegative = ( null !== $cachedSearch ) && ! empty( $cachedSearch['keyword'] ) ? false : true;
635 $checkedNegative = ! $disabledNegative && ( null !== $cachedSearch ) && ! empty( $cachedSearch['not_criteria'] ) ? true : false;
636 ?>
637 <div class="mainwp-search-options ui accordion mainwp-sidebar-accordion">
638 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Search Options', 'mainwp' ); ?></div>
639 <div class="content active">
640 <div class="ui mini form">
641 <div class="field">
642 <div class="ui input fluid">
643 <input type="text" placeholder="<?php esc_attr_e( 'Plugin name', 'mainwp' ); ?>" id="mainwp_plugin_search_by_keyword" class="text" value="<?php echo ( null !== $cachedSearch ) ? esc_attr( $cachedSearch['keyword'] ) : ''; //phpcs:ignore -- escaped. ?>" />
644 </div>
645 </div>
646 <div class="ui hidden fitted divider"></div>
647 <div class="field">
648 <div class="ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Display sites not meeting the above search criteria.', 'mainwp' ); ?>" data-position="left center" data-inverted="">
649 <input type="checkbox" <?php echo $disabledNegative ? 'disabled' : ''; ?> <?php echo $checkedNegative ? 'checked="true"' : ''; ?> value="1" id="display_sites_not_meeting_criteria" />
650 <label for="display_sites_not_meeting_criteria"><?php esc_html_e( 'Exclude plugin', 'mainwp' ); ?></label>
651 </div>
652 </div>
653 </div>
654 </div>
655 </div>
656 <?php
657 if ( is_array( $statuses ) && ! empty( $statuses ) ) {
658 $status = '';
659 foreach ( $statuses as $st ) {
660 $status .= "'" . esc_html( $st ) . "',";
661 }
662 $status = rtrim( $status, ',' );
663 ?>
664 <script type="text/javascript">
665 jQuery( document ).ready( function () {
666 jQuery( '#mainwp_plugins_search_by_status' ).dropdown( 'set selected', [<?php echo $status; // phpcs:ignore -- safe output, to fix incorrect characters. ?>] );
667 } );
668 </script>
669 <?php
670 }
671 ?>
672 <script type="text/javascript">
673 jQuery( document ).on( 'keyup', '#mainwp_plugin_search_by_keyword', function () {
674 if( jQuery(this).val() != '' ){
675 jQuery( '#display_sites_not_meeting_criteria' ).prop("disabled", false);
676 } else {
677 jQuery( '#display_sites_not_meeting_criteria' ).closest('.checkbox').checkbox('set unchecked');
678 jQuery( '#display_sites_not_meeting_criteria' ).attr('disabled', 'true');
679 }
680 });
681 </script>
682 <?php
683 }
684
685 /**
686 * Render Plugins Table.
687 *
688 * @param mixed $keyword Search Terms.
689 * @param mixed $status active|inactive Whether the plugin is active or inactive.
690 * @param mixed $groups Selected Child Site Groups.
691 * @param mixed $sites Selected individual Child Sites.
692 * @param mixed $not_criteria Show not criteria result.
693 * @param mixed $clients Selected Clients.
694 *
695 * @return string Plugin Table.
696 *
697 * @uses MainWP_Cache::init_cache()
698 * @uses MainWP_Utility::ctype_digit()
699 * @uses MainWP_DB::instance()
700 * @uses MainWP_DB::free_result()
701 * @uses MainWP_DB::fetch_object()
702 * @uses MainWP_Utility::map_site()
703 * @uses MainWP_Utility::fetch_urls_authed()
704 * @uses MainWP_Utility::get_nice_url()
705 * @uses MainWP_Cache::add_result()
706 * @uses \MainWP\Dashboard\MainWP_Cache::init_cache()
707 * @uses \MainWP\Dashboard\MainWP_Cache::add_context()
708 * @uses \MainWP\Dashboard\MainWP_Cache::add_result()
709 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
710 * @uses \MainWP\Dashboard\MainWP_DB::query()
711 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
712 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_by_group_id()
713 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
714 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
715 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::get_class_name()
716 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
717 * @uses \MainWP\Dashboard\MainWP_Utility::map_site()
718 */
719 public static function render_table( $keyword, $status, $groups, $sites, $not_criteria, $clients ) { // phpcs:ignore -- NOSONAR -Current complexity required to achieve desired results. Pull request solutions appreciated.
720 $keyword = trim( $keyword );
721 MainWP_Cache::init_cache( 'Plugins' );
722
723 $output = new \stdClass();
724 $output->errors = array();
725 $output->plugins = array();
726 $output->plugins_installed = array();
727 $output->status = $status;
728 $output->roll_items = array();
729 $error_results = '';
730
731 $data_fields = MainWP_System_Utility::get_default_map_site_fields();
732 $data_fields[] = 'plugins';
733 $data_fields[] = 'rollback_updates_data';
734
735 if ( 1 === (int) get_option( 'mainwp_optimize', 1 ) || MainWP_Demo_Handle::is_demo_mode() ) {
736
737 $multi_kws = explode( ',', $keyword );
738 $multi_kws = array_filter( array_map( 'trim', $multi_kws ) );
739
740 if ( ! empty( $sites ) ) {
741 foreach ( $sites as $v ) {
742 if ( MainWP_Utility::ctype_digit( $v ) ) {
743 $website = MainWP_DB::instance()->get_website_by_id( $v, false, array( 'rollback_updates_data' ) );
744 $allPlugins = json_decode( $website->plugins, true );
745 $_count = count( $allPlugins );
746 $_count_installed = 0;
747 for ( $i = 0; $i < $_count; $i++ ) {
748 $plugin = $allPlugins[ $i ];
749 $is_active = 'active' === $status ? 1 : 0;
750 if ( ( 'active' === $status || 'inactive' === $status ) && $is_active !== (int) $plugin['active'] ) {
751 continue;
752 }
753
754 if ( ! empty( $keyword ) ) {
755 if ( $not_criteria ) {
756 if ( MainWP_Utility::multi_find_keywords( $plugin['name'], $multi_kws ) ) {
757 continue;
758 }
759 } elseif ( ! MainWP_Utility::multi_find_keywords( $plugin['name'], $multi_kws ) ) {
760 continue;
761 }
762 }
763
764 $plugin['websiteid'] = $website->id;
765 $plugin['websiteurl'] = $website->url;
766 $plugin['websitename'] = $website->name;
767 $output->plugins[] = $plugin;
768 ++$_count_installed;
769 }
770
771 if ( 0 === $_count_installed && 'not_installed' === $status ) {
772 for ( $i = 0; $i < $_count; $i++ ) {
773 $plugin = $allPlugins[ $i ];
774 $plugin['websiteid'] = $website->id;
775 $plugin['websiteurl'] = $website->url;
776 $plugin['websitename'] = $website->name;
777 $output->plugins_installed[] = $plugin;
778 }
779 }
780 $output->roll_items[ $website->id ] = MainWP_Updates_Helper::get_roll_update_plugintheme_items( 'plugin', $website->rollback_updates_data );
781 }
782 }
783 }
784
785 if ( '' !== $groups ) {
786 foreach ( $groups as $v ) {
787 if ( MainWP_Utility::ctype_digit( $v ) ) {
788 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $v, false, 'wp.url', false, false, null, null, array( 'extra_view' => array( 'site_info', 'rollback_updates_data' ) ) ) );
789 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
790 if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) {
791 continue;
792 }
793 $allPlugins = json_decode( $website->plugins, true );
794 $_count = count( $allPlugins );
795 $_count_installed = 0;
796 for ( $i = 0; $i < $_count; $i++ ) {
797 $plugin = $allPlugins[ $i ];
798 $is_active = 'active' === $status ? 1 : 0;
799 if ( ( 'active' === $status || 'inactive' === $status ) && $is_active !== (int) $plugin['active'] ) {
800 continue;
801 }
802
803 if ( ! empty( $keyword ) ) {
804 if ( $not_criteria ) {
805 if ( MainWP_Utility::multi_find_keywords( $plugin['name'], $multi_kws ) ) {
806 continue;
807 }
808 } elseif ( ! MainWP_Utility::multi_find_keywords( $plugin['name'], $multi_kws ) ) {
809 continue;
810 }
811 }
812
813 $plugin['websiteid'] = $website->id;
814 $plugin['websiteurl'] = $website->url;
815 $plugin['websitename'] = $website->name;
816 $output->plugins[] = $plugin;
817 ++$_count_installed;
818 }
819
820 if ( 0 === $_count_installed && 'not_installed' === $status ) {
821 for ( $i = 0; $i < $_count; $i++ ) {
822 $plugin = $allPlugins[ $i ];
823 $plugin['websiteid'] = $website->id;
824 $plugin['websiteurl'] = $website->url;
825 $plugin['websitename'] = $website->name;
826 $output->plugins_installed[] = $plugin;
827 }
828 }
829 $output->roll_items[ $website->id ] = MainWP_Updates_Helper::get_roll_update_plugintheme_items( 'plugin', $website->rollback_updates_data );
830 }
831 MainWP_DB::free_result( $websites );
832 }
833 }
834 }
835
836 if ( '' !== $clients && is_array( $clients ) ) {
837 $websites = MainWP_DB_Client::instance()->get_websites_by_client_ids(
838 $clients,
839 array(
840 'select_data' => $data_fields,
841 'extra_view' => array( 'rollback_updates_data' ),
842 )
843 );
844 if ( $websites ) {
845 foreach ( $websites as $website ) {
846 if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) {
847 continue;
848 }
849 $allPlugins = json_decode( $website->plugins, true );
850 $_count = count( $allPlugins );
851 $_count_installed = 0;
852 for ( $i = 0; $i < $_count; $i++ ) {
853 $plugin = $allPlugins[ $i ];
854
855 $is_active = ( 'active' === $status ) ? 1 : 0;
856
857 if ( ( ( 'active' === $status ) || ( 'inactive' === $status ) ) && ( $is_active !== (int) $plugin['active'] ) ) {
858 continue;
859 }
860
861 if ( ! empty( $keyword ) ) {
862 if ( $not_criteria ) {
863 if ( MainWP_Utility::multi_find_keywords( $plugin['name'], $multi_kws ) ) {
864 continue;
865 }
866 } elseif ( ! MainWP_Utility::multi_find_keywords( $plugin['name'], $multi_kws ) ) {
867 continue;
868 }
869 }
870
871 $plugin['websiteid'] = $website->id;
872 $plugin['websiteurl'] = $website->url;
873 $plugin['websitename'] = $website->name;
874 $output->plugins[] = $plugin;
875 ++$_count_installed;
876 }
877 if ( 0 === $_count_installed && 'not_installed' === $status ) {
878 for ( $i = 0; $i < $_count; $i++ ) {
879 $plugin = $allPlugins[ $i ];
880 $plugin['websiteid'] = $website->id;
881 $plugin['websiteurl'] = $website->url;
882 $plugin['websitename'] = $website->name;
883 $output->plugins_installed[] = $plugin;
884 }
885 }
886 $output->roll_items[ $website->id ] = MainWP_Updates_Helper::get_roll_update_plugintheme_items( 'plugin', $website->rollback_updates_data );
887 }
888 }
889 }
890 } else {
891 $dbwebsites = array();
892
893 if ( '' !== $sites ) {
894 foreach ( $sites as $v ) {
895 if ( MainWP_Utility::ctype_digit( $v ) ) {
896 $website = MainWP_DB::instance()->get_website_by_id( $v, false, array( 'rollback_updates_data' ) );
897
898 if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) {
899 continue;
900 }
901
902 $dbwebsites[ $website->id ] = MainWP_Utility::map_site(
903 $website,
904 $data_fields
905 );
906 }
907 }
908 }
909
910 if ( '' !== $groups ) {
911 foreach ( $groups as $v ) {
912 if ( MainWP_Utility::ctype_digit( $v ) ) {
913 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $v, false, 'wp.url', false, false, null, null, array( 'extra_view' => array( 'site_info', 'rollback_updates_data' ) ) ) );
914 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
915 if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) {
916 continue;
917 }
918 $dbwebsites[ $website->id ] = MainWP_Utility::map_site(
919 $website,
920 $data_fields
921 );
922 }
923 MainWP_DB::free_result( $websites );
924 }
925 }
926 }
927
928 if ( '' !== $clients && is_array( $clients ) ) {
929 $websites = MainWP_DB_Client::instance()->get_websites_by_client_ids(
930 $clients,
931 array(
932 'select_data' => $data_fields,
933 'extra_view' => array( 'rollback_updates_data' ),
934 )
935 );
936 if ( $websites ) {
937 foreach ( $websites as $website ) {
938 if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) {
939 continue;
940 }
941 $dbwebsites[ $website->id ] = MainWP_Utility::map_site(
942 $website,
943 $data_fields
944 );
945 }
946 }
947 }
948
949 $post_data = array(
950 'keyword' => $keyword,
951 );
952
953 if ( 'active' === $status || 'inactive' === $status ) {
954 $post_data['status'] = $status;
955 $post_data['filter'] = true;
956 } else {
957 $post_data['status'] = '';
958 $post_data['filter'] = false;
959 }
960
961 if ( 'not_installed' === $status ) {
962 $post_data['not_installed'] = true;
963 }
964
965 $post_data['not_criteria'] = $not_criteria ? true : false;
966 MainWP_Connect::fetch_urls_authed( $dbwebsites, 'get_all_plugins', $post_data, array( MainWP_Plugins_Handler::get_class_name(), 'plugins_search_handler' ), $output );
967 // phpcs:disable WordPress.Security.EscapeOutput
968 if ( ! empty( $output->errors ) ) {
969 foreach ( $output->errors as $siteid => $error ) {
970 $error_results .= MainWP_Utility::get_nice_url( $dbwebsites[ $siteid ]->url ) . ': ' . $error . ' <br/>';
971 }
972 }
973 // phpcs:enable
974 }
975
976 MainWP_Cache::add_context(
977 'Plugins',
978 array(
979 'keyword' => $keyword,
980 'status' => $status,
981 'sites' => ( '' !== $sites ) ? $sites : '',
982 'groups' => ( '' !== $groups ) ? $groups : '',
983 'clients' => ( '' !== $clients ) ? $clients : '',
984 'not_criteria' => $not_criteria ? true : false,
985 )
986 );
987
988 $view_mode = static::get_manage_view();
989
990 $bulkActions = static::render_bulk_actions( $status );
991 $roll_items_list = array();
992 $plugins_list = array();
993
994 ob_start();
995
996 if ( ! empty( $error_results ) ) {
997 // phpcs:disable WordPress.Security.EscapeOutput
998 ?>
999 <div class="ui message yellow"><?php echo $error_results; ?></div>
1000 <?php
1001 // phpcs:enable
1002 }
1003
1004 if ( 'not_installed' === $status ) {
1005 if ( empty( $output->plugins_installed ) ) {
1006 ?>
1007 <div class="ui message yellow"><?php esc_html_e( 'No websites found.', 'mainwp' ); ?></div>
1008 <?php
1009 } else {
1010 $plugins_list = $output->plugins_installed;
1011 $roll_items_list = ! empty( $output->roll_items ) ? $output->roll_items : array();
1012 $view_mode = MAINWP_VIEW_PER_SITE;
1013 }
1014 } elseif ( empty( $output->plugins ) ) {
1015 ?>
1016 <div class="ui message yellow"><?php esc_html_e( 'No plugins found.', 'mainwp' ); ?></div>
1017 <?php
1018 } else {
1019 $plugins_list = $output->plugins;
1020 $roll_items_list = ! empty( $output->roll_items ) ? $output->roll_items : array();
1021 }
1022
1023 if ( ! is_array( $roll_items_list ) ) {
1024 $roll_items_list = array();
1025 }
1026
1027 $sites = array();
1028 $sitePlugins = array();
1029 $pluginsNameSites = array();
1030 $muPlugins = array();
1031 $pluginsName = array();
1032 $pluginsMainWP = array();
1033 $pluginsRealVersion = array();
1034 $pluginsSlug = array();
1035
1036 if ( ! empty( $plugins_list ) ) {
1037
1038 foreach ( $plugins_list as $plugin ) {
1039 $slug_ver = esc_html( $plugin['slug'] . '_' . $plugin['version'] );
1040 $sites[ $plugin['websiteid'] ] = array(
1041 'websiteurl' => esc_html( $plugin['websiteurl'] ),
1042 'websitename' => $plugin['websitename'],
1043 );
1044
1045 $pluginsSlug[ $slug_ver ] = isset( $plugin['slug'] ) ? $plugin['slug'] : '';
1046 $muPlugins[ $slug_ver ] = isset( $plugin['mu'] ) ? esc_html( $plugin['mu'] ) : 0;
1047 $pluginsName[ $slug_ver ] = esc_html( $plugin['name'] );
1048
1049 $pluginsNameSites[ $plugin['name'] ][ $plugin['websiteid'] ][] = $slug_ver;
1050
1051 $pluginsMainWP[ $slug_ver ] = isset( $plugin['mainwp'] ) ? esc_html( $plugin['mainwp'] ) : 'F';
1052 $pluginsRealVersion[ $slug_ver ] = rawurlencode( $plugin['version'] );
1053
1054 if ( ! isset( $sitePlugins[ $plugin['websiteid'] ] ) || ! is_array( $sitePlugins[ $plugin['websiteid'] ] ) ) {
1055 $sitePlugins[ $plugin['websiteid'] ] = array();
1056 }
1057
1058 $sitePlugins[ $plugin['websiteid'] ][ $slug_ver ] = $plugin;
1059 }
1060
1061 ksort( $pluginsNameSites, SORT_STRING );
1062
1063 if ( MAINWP_VIEW_PER_PLUGIN_THEME === (int) $view_mode ) {
1064 static::render_manage_table( $sites, $pluginsSlug, $sitePlugins, $pluginsMainWP, $muPlugins, $pluginsName, $pluginsNameSites, $pluginsRealVersion, $roll_items_list );
1065 } else {
1066 static::render_manage_per_site_table( $sites, $pluginsSlug, $sitePlugins, $pluginsMainWP, $muPlugins, $pluginsName, $pluginsNameSites, $pluginsRealVersion, $roll_items_list );
1067 }
1068 MainWP_Updates::render_plugin_details_modal();
1069 MainWP_UI::render_modal_upload_icon();
1070 }
1071
1072 $newOutput = ob_get_clean();
1073 $result = array(
1074 'result' => $newOutput,
1075 'bulk_actions' => $bulkActions,
1076 );
1077
1078 MainWP_Cache::add_result( 'Plugins', $result );
1079 return $result;
1080 }
1081
1082
1083 /**
1084 * Render Bulk Actions.
1085 *
1086 * @param mixed $status active|inactive|all.
1087 *
1088 * @return string Plugin Bulk Actions Menu.
1089 */
1090 public static function render_bulk_actions( $status ) {
1091 ob_start();
1092 ?>
1093 <select class="ui dropdown" id="mainwp-bulk-actions">
1094 <option value="none"><?php esc_html_e( 'Bulk Actions', 'mainwp' ); ?></option>
1095 <?php if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
1096 <option value="ignore_updates" data-value="ignore_updates"><?php esc_html_e( 'Ignore updates', 'mainwp' ); ?></option>
1097 <?php endif; ?>
1098 <?php if ( \mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) : ?>
1099 <?php if ( 'active' === $status ) : ?>
1100 <option value="deactivate" data-value="deactivate"><?php esc_html_e( 'Deactivate', 'mainwp' ); ?></option>
1101 <?php else : ?>
1102 <option value="deactivate" disabled data-value="deactivate"><?php esc_html_e( 'Deactivate', 'mainwp' ); ?></option>
1103 <?php endif; ?>
1104 <?php endif; ?>
1105 <?php if ( 'inactive' === $status ) : ?>
1106 <?php if ( \mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) : ?>
1107 <option value="activate" data-value="activate"><?php esc_html_e( 'Activate', 'mainwp' ); ?></option>
1108 <?php endif; ?>
1109 <?php if ( \mainwp_current_user_can( 'dashboard', 'delete_plugins' ) ) : ?>
1110 <option value="delete" data-value="delete"><?php esc_html_e( 'Delete', 'mainwp' ); ?></option>
1111 <?php endif; ?>
1112 <?php else : ?>
1113 <?php if ( \mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) : ?>
1114 <option value="activate" disabled data-value="activate"><?php esc_html_e( 'Activate', 'mainwp' ); ?></option>
1115 <?php endif; ?>
1116 <?php if ( \mainwp_current_user_can( 'dashboard', 'delete_plugins' ) ) : ?>
1117 <option value="delete" disabled data-value="delete"><?php esc_html_e( 'Delete', 'mainwp' ); ?></option>
1118 <?php endif; ?>
1119 <?php endif; ?>
1120 <?php
1121 /**
1122 * Action: mainwp_plugins_bulk_action
1123 *
1124 * Adds a new action to the Manage Plugins bulk actions menu.
1125 *
1126 * @param string $status Status search parameter.
1127 *
1128 * @since 4.1
1129 */
1130 do_action( 'mainwp_plugins_bulk_action' );
1131 ?>
1132 </select>
1133 <button class="ui mini basic button" href="javascript:void(0)" id="mainwp-do-plugins-bulk-actions"><?php esc_html_e( 'Apply', 'mainwp' ); ?></button>
1134 <span id="mainwp_bulk_action_loading"><i class="ui active inline loader tiny"></i></span>
1135 <?php
1136 return ob_get_clean();
1137 }
1138
1139 /**
1140 * Method get_manage_view().
1141 *
1142 * Get view mode.
1143 *
1144 * @param string $which plugin|theme.
1145 *
1146 * @return int view mode value.
1147 */
1148 public static function get_manage_view( $which = 'plugin' ) {
1149 if ( 'plugin' === $which ) {
1150 return get_user_option( 'mainwp_manage_plugin_view', MAINWP_VIEW_PER_PLUGIN_THEME );
1151 } else {
1152 return get_user_option( 'mainwp_manage_theme_view', MAINWP_VIEW_PER_PLUGIN_THEME );
1153 }
1154 }
1155
1156 /**
1157 * Method render_select_manage_view().
1158 *
1159 * Handle render view mode selection.
1160 *
1161 * @param string $which plugin|theme.
1162 *
1163 * @return void.
1164 */
1165 public static function render_select_manage_view( $which = 'plugin' ) {
1166
1167 $view_mode = static::get_manage_view( $which );
1168
1169 $hide_show_updates_per = apply_filters( 'mainwp_manage_plugin_theme_hide_show_updates_per', false, $which );
1170
1171 if ( ! $hide_show_updates_per ) {
1172 ?>
1173 <form method="post" action="" class="ui mini form right aligned">
1174 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
1175 <input type="hidden" name="whichview" value="<?php echo esc_attr( $which ); ?>" />
1176 <div class="inline field">
1177 <select class="ui dropdown" onchange="mainwp_siteview_onchange(this)" name="select_mainwp_options_plugintheme_view">
1178 <option value="0" class="item" <?php echo MAINWP_VIEW_PER_PLUGIN_THEME === (int) $view_mode ? 'selected' : ''; ?>><?php echo esc_html( 'plugin' === $which ? esc_html__( 'Show Plugins per Item', 'mainwp' ) : esc_html__( 'Show Themes per Item', 'mainwp' ) ); ?></option>
1179 <option value="1" class="item" <?php echo MAINWP_VIEW_PER_SITE === (int) $view_mode ? 'selected' : ''; ?>><?php echo esc_html( 'plugin' === $which ? esc_html__( 'Show Plugins per Site', 'mainwp' ) : esc_html__( 'Show Themes per Site', 'mainwp' ) ); ?></option>
1180 </select>
1181 </div>
1182 </form>
1183 <?php
1184 }
1185 }
1186
1187
1188 /**
1189 * Method render_manage_per_site_table()
1190 *
1191 * Render Manage Plugins Table.
1192 *
1193 * @param array $sites Child Sites array.
1194 * @param array $pluginsSlug Plugins slug array.
1195 * @param array $sitePlugins Site plugins array.
1196 * @param array $pluginsMainWP MainWP plugins array.
1197 * @param array $muPlugins Must use plugins array.
1198 * @param array $pluginsName Plugin names array.
1199 * @param array $pluginsNameSites Plugin names with Sites array.
1200 * @param array $pluginsRealVersion Latest plugin release version.
1201 * @param array $roll_list rool items list.
1202 */
1203 public static function render_manage_per_site_table( $sites, $pluginsSlug = array(), $sitePlugins = array(), $pluginsMainWP = array(), $muPlugins = array(), $pluginsName = array(), $pluginsNameSites = array(), $pluginsRealVersion = array(), $roll_list = array() ) { //phpcs:ignore -- NOSONAR - complex method.
1204
1205 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1206 $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true );
1207 $trustedPlugins = json_decode( $userExtension->trusted_plugins, true );
1208 $is_demo = MainWP_Demo_Handle::is_demo_mode();
1209
1210 if ( ! is_array( $trustedPlugins ) ) {
1211 $trustedPlugins = array();
1212 }
1213
1214 $updateWebsites = array();
1215
1216 foreach ( $sites as $site_id => $info ) {
1217
1218 $plugin_upgrades = array();
1219 $website = MainWP_DB::instance()->get_website_by_id( $site_id, false, array( 'rollback_updates_data' ) );
1220
1221 if ( $website && ! $website->is_ignorePluginUpdates ) {
1222 $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
1223 $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' );
1224 $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array();
1225
1226 if ( is_array( $decodedPremiumUpgrades ) ) {
1227 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
1228 $premiumUpgrade['premium'] = true;
1229
1230 if ( 'plugin' === $premiumUpgrade['type'] ) {
1231 if ( ! is_array( $plugin_upgrades ) ) {
1232 $plugin_upgrades = array();
1233 }
1234
1235 $premiumUpgrade = array_filter( $premiumUpgrade );
1236
1237 if ( ! isset( $plugin_upgrades[ $crrSlug ] ) ) {
1238 $plugin_upgrades[ $crrSlug ] = array();
1239 }
1240 $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade );
1241 }
1242 }
1243 }
1244 $ignored_plugins = json_decode( $website->ignored_plugins, true );
1245 if ( is_array( $ignored_plugins ) ) {
1246 $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
1247
1248 }
1249
1250 if ( is_array( $decodedIgnoredPlugins ) ) {
1251 $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $decodedIgnoredPlugins );
1252 }
1253 }
1254 $updateWebsites[ $site_id ] = $plugin_upgrades;
1255 }
1256
1257 /**
1258 * Action: mainwp_before_plugins_table
1259 *
1260 * Fires before the Plugins table.
1261 *
1262 * @since 4.1
1263 */
1264 do_action( 'mainwp_before_plugins_table' );
1265 ?>
1266 <div class="ui secondary segment main-master-checkbox">
1267 <div class="ui stackable grid">
1268 <div class="one wide left aligned middle aligned column">
1269 <span class="trigger-all-accordion"><span class="trigger-handle-arrow"><i class="caret right icon"></i><i class="caret down icon"></i></span></span>
1270 </div>
1271 <div class="one wide center aligned middle aligned column"><div class="ui checkbox main-master not-auto-init"><input type="checkbox"/><label></label></div></div>
1272 <div class="six wide middle aligned column"><?php esc_html_e( 'Website', 'mainwp' ); ?></div>
1273 <div class="two wide center aligned middle aligned column"></div>
1274 <div class="two wide center aligned middle aligned column"></div>
1275 <div class="two wide center aligned middle aligned column"></div>
1276 <div class="two wide right aligned middle aligned column"><?php esc_html_e( 'Plugins', 'mainwp' ); ?></div>
1277 </div>
1278 </div>
1279
1280 <div class="mainwp-manage-plugins-wrapper main-child-checkbox">
1281 <?php foreach ( $sites as $site_id => $website ) : ?>
1282 <?php
1283 $site_name = $website['websitename'];
1284 $slugVersions = isset( $sitePlugins[ $site_id ] ) ? $sitePlugins[ $site_id ] : array();
1285
1286 if ( ! is_array( $slugVersions ) ) {
1287 $slugVersions = array();
1288 }
1289
1290 $item_id = $site_id;
1291 $count_plugins = count( $slugVersions );
1292
1293 // phpcs:disable WordPress.Security.EscapeOutput
1294 ?>
1295 <div class="ui accordion mainwp-manage-plugin-accordion mainwp-manage-plugin-item main-child-checkbox" id="<?php echo esc_html( $item_id ); ?>">
1296 <div class="title master-checkbox">
1297 <div class="ui stackable grid">
1298 <div class="one wide left aligned middle aligned column"><i class="dropdown icon dropdown-trigger"></i></div>
1299 <div class="one wide center aligned middle aligned column">
1300 <div class="ui checkbox master">
1301 <input type="checkbox"/>
1302 <label></label>
1303 </div>
1304 </div>
1305 <div class="four wide middle aligned column"><a target="_blank" href="admin.php?page=SiteOpen&newWindow=yes&websiteid=<?php echo intval( $site_id ); ?>&_opennonce=<?php echo esc_html( wp_create_nonce( 'mainwp-admin-nonce' ) ); ?>"><i class="sign in icon"></i></a> <a href="admin.php?page=managesites&dashboard=<?php echo intval( $site_id ); ?>"><?php echo esc_html( $site_name ); ?></a></div>
1306 <div class="two wide center aligned middle aligned column"></div>
1307 <div class="two wide center aligned middle aligned column"></div>
1308 <div class="two wide center aligned middle aligned column"></div>
1309 <div class="two wide center aligned middle aligned column"></div>
1310 <div class="two wide right aligned middle aligned column"><div class="ui label"><?php echo intval( $count_plugins ) . ' ' . esc_html( _n( 'Plugin', 'Plugins', intval( $count_plugins ), 'mainwp' ) ); ?></div></div>
1311 </div>
1312 </div>
1313 <div class="content child-checkbox">
1314 <?php
1315 // phpcs:enable
1316 foreach ( $slugVersions as $slug_ver => $plugin ) :
1317
1318 $plugin_title = wp_strip_all_tags( $pluginsName[ $slug_ver ] );
1319
1320 $plugin_slug = $pluginsSlug[ $slug_ver ];
1321 $trusted = in_array( $plugin_slug, $trustedPlugins ) ? true : false;
1322 $child_plugin = ( isset( $pluginsMainWP[ $slug_ver ] ) && 'T' === $pluginsMainWP[ $slug_ver ] ) ? true : false;
1323
1324 $plugin_mu = false;
1325
1326 $plugin_version = $sitePlugins[ $site_id ][ $slug_ver ]['version'];
1327
1328 $plugin_upgrades = isset( $updateWebsites[ $site_id ] ) ? $updateWebsites[ $site_id ] : array();
1329 if ( ! is_array( $plugin_upgrades ) ) {
1330 $plugin_upgrades = array();
1331 }
1332
1333 $upgradeInfo = isset( $plugin_upgrades[ $plugin_slug ] ) ? $plugin_upgrades[ $plugin_slug ] : false;
1334
1335 $new_version = '';
1336 if ( ! empty( $upgradeInfo ) && isset( $upgradeInfo['update']['new_version'] ) ) {
1337 $new_version = $upgradeInfo['update']['new_version'];
1338 }
1339
1340 if ( isset( $sitePlugins[ $site_id ][ $slug_ver ] ) && ( empty( $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) || 1 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) ) {
1341 $actived = true;
1342 if ( isset( $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) && 1 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) {
1343 $plugin_status = '<span class="ui small green basic label">' . esc_html__( 'Active', 'mainwp' ) . '</span>';
1344 } elseif ( isset( $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) && 0 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) {
1345 $plugin_status = '<span class="ui small red basic label">' . esc_html__( 'Inactive', 'mainwp' ) . '</span>';
1346 $actived = false;
1347 } else {
1348 $plugin_status = '';
1349 }
1350
1351 if ( isset( $sitePlugins[ $site_id ][ $slug_ver ] ) && ( 1 === (int) $muPlugins[ $slug_ver ] ) ) {
1352 $plugin_mu = true;
1353 }
1354
1355 if ( $plugin_mu ) {
1356 $actived = true; // always.
1357 }
1358
1359 $item_id = $slug_ver . '_' . $site_id;
1360 $item_id = strtolower( $item_id );
1361 $item_id = preg_replace( '/[[:space:]]+/', '_', $item_id );
1362
1363 $plugin_directory = MainWP_Utility::get_dir_slug( $plugin_slug );
1364 $details_link = self_admin_url( 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $site_id ) . '&plugin=' . rawurlencode( $plugin_directory ) . '&section=changelog' );
1365 ?>
1366 <div class="ui very compact stackable grid mainwp-manage-plugin-item-website" plugin-slug="<?php echo esc_attr( rawurlencode( $plugin_slug ) ); ?>" plugin-name="<?php echo esc_html( $plugin_title ); ?>" site-id="<?php echo intval( $site_id ); ?>" site-name="<?php echo esc_html( $site_name ); ?>" id="<?php echo esc_html( $item_id ); ?>">
1367 <div class="one wide center aligned middle aligned column"></div>
1368 <div class="one wide left aligned middle aligned column">
1369 <div class="ui checkbox child <?php echo 'mainwp-child' === $plugin_directory ? 'disabled' : ''; ?>">
1370 <input type="checkbox"
1371 <?php
1372 echo 'mainwp-child' === $plugin_directory ? 'disabled="disabled"' : 'class="mainwp-selected-plugin-site"';
1373 ?>
1374 ><label></label>
1375 </div>
1376 </div>
1377 <?php // phpcs:disable WordPress.Security.EscapeOutput ?>
1378 <div class="one wide center aligned middle aligned column"><?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); ?></div>
1379 <?php // phpcs:enable ?>
1380 <div class="three wide middle aligned column"><a class="open-plugin-details-modal" href="<?php echo esc_url( $details_link ); ?>" target="_blank" ><?php echo esc_html( $plugin_title ); ?></a></div>
1381 <div class="one wide center aligned middle aligned column"><?php echo $plugin_status; //phpcs:ignore -- escaped. ?></div>
1382 <div class="two wide center aligned middle aligned column"><?php echo $trusted ? '<span class="ui tiny basic green label">' . esc_html__( 'Trusted', 'mainwp' ) . '</span>' : '<span class="ui tiny basic grey label">' . esc_html__( 'Not Trusted', 'mainwp' ) . '</span>'; ?></div>
1383 <div class="one wide center aligned middle aligned column"><?php echo $plugin_mu ? '<span class="ui small label"><i class="exclamation orange triangle icon"></i> MU</span>' : ''; ?></div>
1384 <div class="two wide right aligned middle aligned column current-version">
1385 <?php echo esc_html( $plugin_version ); ?>
1386 <?php if ( ! empty( $new_version ) ) : ?>
1387 &rarr;
1388 <?php
1389 if ( ! empty( $roll_list[ $site_id ][ $plugin_slug ][ $new_version ] ) ) {
1390 echo MainWP_Updates_Helper::get_roll_msg( $roll_list[ $site_id ][ $plugin_slug ][ $new_version ], true, 'notice' ); //phpcs:ignore -- NOSONAR -- ok.
1391 }
1392 echo esc_html( $new_version );
1393 ?>
1394 <?php endif; ?>
1395 </div>
1396 <div class="two wide right aligned middle aligned column update-column" updated="0">
1397 <?php if ( ! empty( $upgradeInfo ) && MainWP_Updates::user_can_update_plugins() ) : ?>
1398 <span data-position="top right" data-tooltip="<?php echo esc_attr__( 'Update ', 'mainwp' ) . esc_html( $plugin_title ) . ' ' . esc_attr__( 'plugin on this child site.', 'mainwp' ); ?>" data-inverted=""><a href="javascript:void(0)" class="ui mini green basic button <?php echo $is_demo ? 'disabled' : ''; ?>" onClick="return manage_plugins_upgrade( '<?php echo esc_js( rawurlencode( $plugin_slug ) ); ?>', <?php echo esc_attr( $site_id ); ?> )"><?php esc_html_e( 'Update Now', 'mainwp' ); ?></a></span>
1399 <?php endif; ?>
1400 </div>
1401 <div class="two wide center aligned middle aligned column column-actions">
1402 <?php if ( ! $child_plugin ) : ?>
1403 <?php if ( $actived ) { ?>
1404 <?php if ( ! $plugin_mu && \mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) { ?>
1405 <a href="#" class="mainwp-manage-plugin-deactivate ui mini fluid button <?php echo $is_demo ? 'disabled' : ''; ?>" data-position="top right" data-tooltip="<?php echo esc_attr__( 'Deactivate ', 'mainwp' ) . esc_html( $plugin_title ) . ' ' . esc_attr__( 'plugin on this child site.', 'mainwp' ); ?>" data-inverted=""><?php esc_html_e( 'Deactivate', 'mainwp' ); ?></a>
1406 <?php } ?>
1407 <?php } else { ?>
1408 <div class="ui mini fluid buttons">
1409 <?php if ( \mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) { ?>
1410 <a href="#" class="mainwp-manage-plugin-activate ui green button <?php echo $is_demo ? 'disabled' : ''; ?>" data-position="top right" data-tooltip="<?php echo esc_attr__( 'Activate ', 'mainwp' ) . esc_html( wp_strip_all_tags( $plugin_title ) ) . ' ' . esc_attr__( 'plugin on this child site.', 'mainwp' ); ?>" data-inverted=""><?php esc_html_e( 'Activate', 'mainwp' ); ?></a>
1411 <?php } ?>
1412 <?php if ( \mainwp_current_user_can( 'dashboard', 'delete_plugins' ) ) { ?>
1413 <a href="#" class="mainwp-manage-plugin-delete ui button <?php echo $is_demo ? 'disabled' : ''; ?>" data-position="top right" data-tooltip="<?php echo esc_attr__( 'Delete ', 'mainwp' ) . ' ' . esc_html( wp_strip_all_tags( $plugin_title ) ) . ' ' . esc_attr__( 'plugin from this child site.', 'mainwp' ); ?>" data-inverted=""><?php esc_html_e( 'Delete', 'mainwp' ); ?></a>
1414 <?php } ?>
1415 </div>
1416 <?php } ?>
1417 <?php endif; ?>
1418 </div>
1419 </div>
1420 <?php
1421
1422 }
1423 endforeach;
1424 ?>
1425 </div>
1426 </div>
1427 <?php endforeach; ?>
1428 </div>
1429
1430 <script type="text/javascript">
1431 jQuery( '.mainwp-manage-plugin-accordion' ).accordion( {
1432 "selector": {
1433 "trigger" : '.dropdown-trigger',
1434 }
1435 } );
1436
1437 jQuery( '.trigger-all-accordion' ).on( 'click', function() { // not use document here.
1438 if ( jQuery( this ).hasClass( 'active' ) ) {
1439 jQuery( this ).removeClass( 'active' );
1440 jQuery( '.mainwp-manage-plugins-wrapper .ui.accordion div.title' ).each( function( i ) {
1441 if ( jQuery( this ).hasClass( 'active' ) ) {
1442 jQuery( this ).find('.dropdown-trigger').trigger( 'click' );
1443 }
1444 } );
1445 } else {
1446 jQuery( this ).addClass( 'active' );
1447 jQuery( '.mainwp-manage-plugins-wrapper .ui.accordion div.title' ).each( function( i ) {
1448 if ( !jQuery( this ).hasClass( 'active' ) ) {
1449 jQuery( this ).find('.dropdown-trigger').trigger( 'click' );
1450 }
1451 } );
1452 }
1453 return false;
1454 } );
1455
1456 jQuery(function($) {
1457 mainwp_master_checkbox_init($);
1458 mainwp_get_icon_start();
1459 mainwp_show_hide_install_to_selected_sites( 'plugin' );
1460 } );
1461
1462 </script>
1463
1464 <?php
1465 /**
1466 * Action: mainwp_after_plugins_table
1467 *
1468 * Fires after the Plugins table.
1469 *
1470 * @since 4.1
1471 */
1472 do_action( 'mainwp_after_plugins_table' );
1473 }
1474
1475
1476
1477 /**
1478 * Method render_manage_table()
1479 *
1480 * Render Manage Plugins Table.
1481 *
1482 * @param array $sites Child Sites array.
1483 * @param array $pluginsSlug Plugins slug array.
1484 * @param array $sitePlugins Site plugins array.
1485 * @param array $pluginsMainWP MainWP plugins array.
1486 * @param array $muPlugins Must use plugins array.
1487 * @param array $pluginsName Plugin names array.
1488 * @param array $pluginsNameSites Plugin names with Sites array.
1489 * @param array $pluginsRealVersion Latest plugin release version.
1490 * @param array $roll_list rool items list.
1491 */
1492 public static function render_manage_table( $sites, $pluginsSlug, $sitePlugins, $pluginsMainWP, $muPlugins, $pluginsName, $pluginsNameSites, $pluginsRealVersion, $roll_list = array() ) { //phpcs:ignore -- NOSONAR - complex method.
1493
1494 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1495 $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true );
1496 $trustedPlugins = json_decode( $userExtension->trusted_plugins, true );
1497 $is_demo = MainWP_Demo_Handle::is_demo_mode();
1498
1499 if ( ! is_array( $trustedPlugins ) ) {
1500 $trustedPlugins = array();
1501 }
1502
1503 $updateWebsites = array();
1504
1505 foreach ( $sites as $site_id => $info ) {
1506
1507 $plugin_upgrades = array();
1508 $website = MainWP_DB::instance()->get_website_by_id( $site_id );
1509 if ( $website && ! $website->is_ignorePluginUpdates ) {
1510 $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
1511 if ( ! is_array( $plugin_upgrades ) ) {
1512 $plugin_upgrades = array();
1513 }
1514 $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' );
1515 $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array();
1516 if ( is_array( $decodedPremiumUpgrades ) ) {
1517 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
1518 $premiumUpgrade['premium'] = true;
1519 if ( 'plugin' === $premiumUpgrade['type'] ) {
1520 $premiumUpgrade = array_filter( $premiumUpgrade );
1521
1522 if ( ! isset( $plugin_upgrades[ $crrSlug ] ) ) {
1523 $plugin_upgrades[ $crrSlug ] = array();
1524 }
1525 $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade );
1526 }
1527 }
1528 }
1529 $ignored_plugins = json_decode( $website->ignored_plugins, true );
1530 if ( is_array( $ignored_plugins ) ) {
1531 $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
1532
1533 }
1534
1535 if ( is_array( $decodedIgnoredPlugins ) ) {
1536 $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $decodedIgnoredPlugins );
1537 }
1538 }
1539 $updateWebsites[ $site_id ] = $plugin_upgrades;
1540 }
1541
1542 /**
1543 * Action: mainwp_before_plugins_table
1544 *
1545 * Fires before the Plugins table.
1546 *
1547 * @since 4.1
1548 */
1549 do_action( 'mainwp_before_plugins_table' );
1550 ?>
1551 <div class="ui secondary segment main-master-checkbox">
1552 <div class="ui stackable grid">
1553 <div class="one wide left aligned middle aligned column">
1554 <span class="trigger-all-accordion"><span class="trigger-handle-arrow"><i class="caret right icon"></i><i class="caret down icon"></i></span></span>
1555 </div>
1556 <div class="one wide center aligned middle aligned column"><div class="ui checkbox main-master not-auto-init"><input type="checkbox"/><label></label></div></div>
1557 <div class="one wide center aligned middle aligned column"></div>
1558 <div class="five wide middle aligned column"><?php esc_html_e( 'Plugin', 'mainwp' ); ?></div>
1559 <div class="two wide center aligned middle aligned column"></div>
1560 <div class="two wide right aligned middle aligned column"><?php esc_html_e( 'Latest Version', 'mainwp' ); ?></div>
1561 <div class="two wide center aligned middle aligned column"></div>
1562 <div class="two wide right aligned middle aligned column"><?php esc_html_e( 'Websites', 'mainwp' ); ?></div>
1563 </div>
1564 </div>
1565
1566 <div class="mainwp-manage-plugins-wrapper main-child-checkbox">
1567 <?php foreach ( $pluginsNameSites as $plugin_title => $pluginSites ) : ?>
1568 <?php
1569 $slugVersions = current( $pluginSites );
1570 $slug_ver_first = $slugVersions[0]; // get the first one [slug]_[version] to get plugin [slug].
1571 $plugin_slug_first = $pluginsSlug[ $slug_ver_first ];
1572 $plugin_directory = MainWP_Utility::get_dir_slug( $plugin_slug_first );
1573
1574 $plugin_status = '';
1575
1576 $item_id = strtolower( $plugin_title );
1577 $item_id = preg_replace( '/[[:space:]]+/', '_', $item_id );
1578
1579 $count_sites = count( $pluginSites );
1580
1581 reset( $pluginSites );
1582 $first_siteid = key( $pluginSites );
1583
1584 $details_link = self_admin_url( 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $first_siteid ) . '&plugin=' . rawurlencode( $plugin_directory ) . '&section=changelog' );
1585 $lastest_version = '';
1586 // phpcs:disable WordPress.Security.EscapeOutput
1587 ?>
1588 <div class="ui accordion mainwp-manage-plugin-accordion mainwp-manage-plugin-item main-child-checkbox" id="<?php echo esc_html( $item_id ); ?>">
1589 <div class="title master-checkbox">
1590 <div class="ui grid">
1591 <div class="one wide left aligned middle aligned column"><i class="dropdown icon dropdown-trigger"></i></div>
1592 <div class="one wide center aligned middle aligned column">
1593 <div class="ui checkbox <?php echo 'mainwp-child' === $plugin_directory ? 'disabled' : ''; ?> master"><input type="checkbox" <?php echo 'mainwp-child' === $plugin_directory ? 'disabled="disabled"' : ''; ?>><label></label></div>
1594 </div>
1595 <div class="one wide center aligned middle aligned column"><?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); // phpcs:ignore WordPress.Security.EscapeOutput ?></div>
1596 <div class="five wide middle aligned column"><a class="open-plugin-details-modal" href="<?php echo esc_url( $details_link ); ?>" target="_blank" ><?php echo esc_html( $plugin_title ); ?></a></div>
1597 <div class="two wide center aligned middle aligned column"></div>
1598 <div class="two wide right aligned middle aligned column lastest-version-info"></div>
1599 <div class="two wide center aligned middle aligned column"></div>
1600 <div class="two wide right aligned middle aligned column"><div class="ui label"><?php echo intval( $count_sites ) . ' ' . esc_html( _n( 'Site', 'Sites', intval( $count_sites ), 'mainwp' ) ); ?></div></div>
1601 </div>
1602 </div>
1603 <div class="content child-checkbox">
1604 <?php
1605 // phpcs:enable
1606 foreach ( $pluginSites as $site_id => $slugVersions ) :
1607 $site_name = $sites[ $site_id ]['websitename'];
1608
1609 foreach ( $slugVersions as $slug_ver ) :
1610
1611 $plugin_slug = $pluginsSlug[ $slug_ver ];
1612 $trusted = in_array( $plugin_slug, $trustedPlugins ) ? true : false;
1613 $child_plugin = ( isset( $pluginsMainWP[ $slug_ver ] ) && 'T' === $pluginsMainWP[ $slug_ver ] ) ? true : false;
1614
1615 $plugin_mu = false;
1616
1617 $plugin_version = $sitePlugins[ $site_id ][ $slug_ver ]['version'];
1618
1619 $plugin_upgrades = isset( $updateWebsites[ $site_id ] ) ? $updateWebsites[ $site_id ] : array();
1620 if ( ! is_array( $plugin_upgrades ) ) {
1621 $plugin_upgrades = array();
1622 }
1623
1624 $upgradeInfo = isset( $plugin_upgrades[ $plugin_slug ] ) ? $plugin_upgrades[ $plugin_slug ] : false;
1625
1626 $new_version = '';
1627 if ( ! empty( $upgradeInfo ) && isset( $upgradeInfo['update']['new_version'] ) ) {
1628 $new_version = $upgradeInfo['update']['new_version'];
1629 }
1630
1631 if ( '' === $lastest_version || version_compare( $plugin_version, $lastest_version, '>' ) ) {
1632 $lastest_version = $plugin_version;
1633 }
1634
1635 if ( '' !== $new_version && version_compare( $new_version, $lastest_version, '>' ) ) {
1636 $lastest_version = $new_version;
1637 }
1638
1639 if ( isset( $sitePlugins[ $site_id ][ $slug_ver ] ) && ( 0 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] || 1 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) ) {
1640 $actived = true;
1641 if ( isset( $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) && 1 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) {
1642 $plugin_status = '<span class="ui small green basic label">' . esc_html__( 'Active', 'mainwp' ) . '</span>';
1643 } elseif ( isset( $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) && 0 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) {
1644 $plugin_status = '<span class="ui small red basic label">' . esc_html__( 'Inactive', 'mainwp' ) . '</span>';
1645 $actived = false;
1646 } else {
1647 $plugin_status = '';
1648 }
1649
1650 if ( isset( $sitePlugins[ $site_id ][ $slug_ver ] ) && ( 1 === (int) $muPlugins[ $slug_ver ] ) ) {
1651 $plugin_mu = true;
1652 }
1653 if ( $plugin_mu ) {
1654 $actived = true; // always.
1655 }
1656 $item_id = $slug_ver . '_' . $site_id;
1657 $item_id = strtolower( $item_id );
1658 $item_id = preg_replace( '/[[:space:]]+/', '_', $item_id );
1659
1660 ?>
1661 <div class="ui stackable grid very compact mainwp-manage-plugin-item-website" plugin-slug="<?php echo esc_attr( rawurlencode( $plugin_slug ) ); ?>" plugin-name="<?php echo esc_html( wp_strip_all_tags( $pluginsName[ $slug_ver ] ) ); ?>" site-id="<?php echo intval( $site_id ); ?>" site-name="<?php echo esc_html( $site_name ); ?>" id="<?php echo esc_html( $item_id ); ?>">
1662 <div class="one wide left aligned middle aligned column"></div>
1663 <div class="one wide center aligned middle aligned column">
1664 <?php if ( $child_plugin ) { ?>
1665 <div class="ui disabled checkbox"><input type="checkbox" disabled="disabled"><label></label></div>
1666 <?php } else { ?>
1667 <div class="ui checkbox child">
1668 <input type="checkbox" class="mainwp-selected-plugin-site" />
1669 <label></label>
1670 </div>
1671 <?php
1672 }
1673 ?>
1674 </div>
1675 <div class="three wide middle aligned column"><a target="_blank" href="admin.php?page=SiteOpen&newWindow=yes&websiteid=<?php echo intval( $site_id ); ?>&_opennonce=<?php echo esc_html( wp_create_nonce( 'mainwp-admin-nonce' ) ); ?>"><i class="sign in icon"></i></a> <a href="admin.php?page=managesites&dashboard=<?php echo intval( $site_id ); ?>"><?php echo esc_html( $site_name ); ?></a></div>
1676 <div class="one wide middle aligned column"></div>
1677 <div class="one wide center aligned middle aligned column"><?php echo $plugin_status; //phpcs:ignore -- escaped. ?></div>
1678 <div class="two wide center aligned middle aligned column"><?php echo $trusted ? '<span class="ui tiny basic green label">' . esc_html__( 'Trusted', 'mainwp' ) . '</span>' : '<span class="ui tiny basic grey label">' . esc_html__( 'Not Trusted', 'mainwp' ) . '</span>'; ?></div>
1679
1680
1681 <div class="one wide center aligned middle aligned column"><?php echo $plugin_mu ? '<span class="ui small label"><i class="exclamation orange triangle icon"></i> MU</span>' : ''; ?></div>
1682
1683 <div class="two wide center aligned middle aligned column current-version">
1684 <?php echo esc_html( $plugin_version ); ?>
1685 <?php if ( ! empty( $new_version ) ) : ?>
1686 &rarr;
1687 <?php
1688 if ( ! empty( $roll_list[ $site_id ][ $plugin_slug ][ $new_version ] ) ) {
1689 echo MainWP_Updates_Helper::get_roll_msg( $roll_list[ $site_id ][ $plugin_slug ][ $new_version ], true, 'notice' ); //phpcs:ignore -- NOSONAR -- ok.
1690 }
1691 echo esc_html( $new_version );
1692 ?>
1693 <?php endif; ?>
1694 </div>
1695 <div class="two wide right aligned middle aligned column update-column" updated="0">
1696 <?php if ( ! empty( $upgradeInfo ) && MainWP_Updates::user_can_update_plugins() ) : ?>
1697 <span data-position="top right" data-tooltip="<?php echo esc_attr__( 'Update ', 'mainwp' ) . esc_html( $plugin_title ) . ' ' . esc_attr__( 'lugin on this child site.', 'mainwp' ); ?>" data-inverted="" ><a href="javascript:void(0)" class="ui mini green basic button <?php echo $is_demo ? 'disabled' : ''; ?>" onClick="return manage_plugins_upgrade( '<?php echo esc_js( rawurlencode( $plugin_slug ) ); ?>', <?php echo esc_attr( $site_id ); ?> )"><?php esc_html_e( 'Update Now', 'mainwp' ); ?></a></span>
1698 <?php endif; ?>
1699 </div>
1700 <div class="two wide center aligned middle aligned column column-actions">
1701 <?php if ( ! $child_plugin ) : ?>
1702 <?php if ( $actived ) { ?>
1703 <?php if ( ! $plugin_mu && \mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) { ?>
1704 <a href="#" class="mainwp-manage-plugin-deactivate ui mini fluid button <?php echo $is_demo ? 'disabled' : ''; ?>"><?php esc_html_e( 'Deactivate', 'mainwp' ); ?></a>
1705 <?php } ?>
1706 <?php } else { ?>
1707 <div class="ui mini fluid buttons">
1708 <?php if ( \mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) { ?>
1709 <a href="#" class="mainwp-manage-plugin-activate ui green button <?php echo $is_demo ? 'disabled' : ''; ?>" ><?php esc_html_e( 'Activate', 'mainwp' ); ?></a>
1710 <?php } ?>
1711 <?php if ( \mainwp_current_user_can( 'dashboard', 'delete_plugins' ) ) { ?>
1712 <a href="#" class="mainwp-manage-plugin-delete ui button <?php echo $is_demo ? 'disabled' : ''; ?>" ><?php esc_html_e( 'Delete', 'mainwp' ); ?></a>
1713 <?php } ?>
1714 </div>
1715 <?php } ?>
1716 <?php endif; ?>
1717 </div>
1718 </div>
1719 <?php
1720
1721 }
1722 endforeach;
1723 ?>
1724 <span style="display:none" class="lastest-version-hidden" lastest-version="<?php echo esc_html( $lastest_version ); ?>"></span>
1725 <?php
1726 endforeach;
1727 ?>
1728 </div>
1729 </div>
1730 <?php endforeach; ?>
1731 </div>
1732
1733 <script type="text/javascript">
1734 jQuery( '.mainwp-manage-plugin-accordion' ).accordion( {
1735 "selector": {
1736 "trigger" : '.dropdown-trigger',
1737 }
1738 } );
1739
1740 jQuery( '.trigger-all-accordion' ).on( 'click', function() { // not use document here.
1741 if ( jQuery( this ).hasClass( 'active' ) ) {
1742 jQuery( this ).removeClass( 'active' );
1743 jQuery( '.mainwp-manage-plugins-wrapper .ui.accordion div.title' ).each( function( i ) {
1744 if ( jQuery( this ).hasClass( 'active' ) ) {
1745 jQuery( this ).find('.dropdown-trigger').trigger( 'click' );
1746 }
1747 } );
1748 } else {
1749 jQuery( this ).addClass( 'active' );
1750 jQuery( '.mainwp-manage-plugins-wrapper .ui.accordion div.title' ).each( function( i ) {
1751 if ( !jQuery( this ).hasClass( 'active' ) ) {
1752 jQuery( this ).find('.dropdown-trigger').trigger( 'click' );
1753 }
1754 } );
1755 }
1756 return false;
1757 } );
1758
1759
1760
1761 jQuery(function($) {
1762 $( '.lastest-version-hidden' ).each(function(){
1763 $(this).closest('.mainwp-manage-plugin-item').find('.lastest-version-info').html( $(this).attr('lastest-version') );
1764 });
1765 mainwp_master_checkbox_init($);
1766 mainwp_get_icon_start();
1767 mainwp_show_hide_install_to_selected_sites( 'plugin' );
1768 } );
1769
1770 </script>
1771
1772 <?php
1773 /**
1774 * Action: mainwp_after_plugins_table
1775 *
1776 * Fires after the Plugins table.
1777 *
1778 * @since 4.1
1779 */
1780 do_action( 'mainwp_after_plugins_table' );
1781 }
1782
1783
1784 /** Render Install Subpage. */
1785 public static function render_install() {
1786 static::render_header( 'Install' );
1787 static::render_plugins_table();
1788 static::render_footer( 'Install' );
1789 }
1790
1791
1792 /**
1793 * Render Install plugins Table.
1794 *
1795 * @uses \MainWP\Dashboard\MainWP_UI::render_modal_install_plugin_theme()
1796 *
1797 * @uses \MainWP\Dashboard\MainWP_Install_Bulk::render_upload()
1798 */
1799 public static function render_plugins_table() {
1800
1801 /**
1802 * Tab array.
1803 *
1804 * @global object
1805 */
1806 global $tab;
1807
1808 if ( ! \mainwp_current_user_can( 'dashboard', 'install_plugins' ) ) {
1809 \mainwp_do_not_have_permissions( esc_html__( 'install plugins', 'mainwp' ) );
1810 return;
1811 }
1812 ?>
1813
1814 <div class="ui alt segment" id="mainwp-install-plugins">
1815 <div class="mainwp-main-content">
1816 <div class="mainwp-actions-bar">
1817 <div class="ui stackable grid">
1818 <div class="ui two column row">
1819 <div class="column">
1820 <div id="mainwp-search-plugins-form" class="ui fluid search focus">
1821 <div class="ui icon fluid input">
1822 <input id="mainwp-search-plugins-form-field" class="fluid prompt" type="text" placeholder="<?php esc_attr_e( 'Search plugins...', 'mainwp' ); ?>" value="<?php echo isset( $_GET['s'] ) ? esc_html( sanitize_text_field( wp_unslash( $_GET['s'] ) ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>">
1823 <i class="search icon"></i>
1824 </div>
1825 <div class="results"></div>
1826 </div>
1827 <script type="text/javascript">
1828 jQuery( document ).ready(function () {
1829 jQuery( '#mainwp-search-plugins-form-field' ).on( 'keypress', function(e) {
1830 let search = jQuery( '#mainwp-search-plugins-form-field' ).val();
1831 let sel_ids = jQuery( '#plugin_install_selected_sites' ).val();
1832 if ( '' != sel_ids )
1833 sel_ids = '&selected_sites=' + sel_ids;
1834 let origin = '<?php echo esc_url( get_admin_url() ); ?>';
1835 if ( 13 === e.which ) {
1836 location.href = origin + 'admin.php?page=PluginsInstall&tab=search&s=' + encodeURIComponent(search) + sel_ids;
1837 }
1838 } );
1839 } );
1840 </script>
1841 <?php
1842 /**
1843 * Install Plugins actions bar (left)
1844 *
1845 * Fires at the left side of the actions bar on the Install Plugins screen, after the Search bar.
1846 *
1847 * @since 4.0
1848 */
1849 do_action( 'mainwp_install_plugins_actions_bar_left' );
1850 ?>
1851 </div>
1852 <div class="right aligned column">
1853 <div class="ui buttons">
1854 <a href="#" id="MainWPInstallBulkNavSearch" class="ui button" ><?php esc_html_e( 'Install from WordPress.org', 'mainwp' ); ?></a>
1855 <div class="or"></div>
1856 <a href="#" id="MainWPInstallBulkNavUpload" class="ui button" ><?php esc_html_e( 'Upload .zip file', 'mainwp' ); ?></a>
1857 </div>
1858 <?php
1859 /**
1860 * Install Plugins actions bar (right)
1861 *
1862 * Fires at the left side of the actions bar on the Install Plugins screen, after the Nav buttons.
1863 *
1864 * @since 4.0
1865 */
1866 do_action( 'mainwp_install_plugins_actions_bar_right' );
1867 ?>
1868 </div>
1869 </div>
1870 </div>
1871 </div>
1872 <div class="ui segment">
1873 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-install-plugins-info-message' ) ) : ?>
1874 <div class="ui info message">
1875 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-install-plugins-info-message"></i>
1876 <?php printf( esc_html__( 'Install plugins on your child sites. You can install plugins from the WordPress.org repository or by uploading a ZIP file. For additional help, please check this %1$shelp documentation%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/install-plugins/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); ?>
1877 </div>
1878 <?php endif; ?>
1879 <div id="mainwp-message-zone" class="ui message" style="display:none;"></div>
1880 <div class="mainwp-upload-plugin" style="display:none;">
1881 <?php MainWP_Install_Bulk::render_upload( 'plugin' ); ?>
1882 </div>
1883 <div class="mainwp-browse-plugins">
1884 <form id="plugin-filter" method="post">
1885 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
1886 <?php static::$pluginsTable->display(); ?>
1887 </form>
1888 </div>
1889 <?php
1890 MainWP_UI::render_modal_install_plugin_theme();
1891 MainWP_Updates::render_plugin_details_modal();
1892 ?>
1893 </div>
1894 </div>
1895 <?php
1896 $selected_sites = array();
1897
1898 if ( isset( $_GET['selected_sites'] ) && ! empty( $_GET['selected_sites'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1899 $selected_sites = explode( '-', sanitize_text_field( wp_unslash( $_GET['selected_sites'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitize ok.
1900 $selected_sites = array_map( 'intval', $selected_sites );
1901 $selected_sites = array_filter( $selected_sites );
1902 }
1903 ?>
1904 <div class="mainwp-side-content mainwp-no-padding">
1905 <?php do_action( 'mainwp_manage_plugins_sidebar_top' ); ?>
1906 <div class="mainwp-select-sites ui accordion mainwp-sidebar-accordion">
1907 <?php do_action( 'mainwp_manage_plugins_before_select_sites' ); ?>
1908 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Sites', 'mainwp' ); ?></div>
1909 <div class="content active">
1910 <?php
1911 $sel_params = array(
1912 'class' => 'mainwp_select_sites_box_left',
1913 'selected_sites' => $selected_sites,
1914 'show_client' => true,
1915 );
1916 MainWP_UI_Select_Sites::select_sites_box( $sel_params );
1917 ?>
1918 </div>
1919 <?php do_action( 'mainwp_manage_plugins_after_select_sites' ); ?>
1920 </div>
1921 <input type="hidden" id="plugin_install_selected_sites" name="plugin_install_selected_sites" value="<?php echo esc_html( implode( '-', $selected_sites ) ); ?>" />
1922 <div class="ui fitted divider"></div>
1923 <div class="mainwp-search-options ui accordion mainwp-sidebar-accordion">
1924 <?php do_action( 'mainwp_manage_plugins_before_search_options' ); ?>
1925 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Installation Options', 'mainwp' ); ?></div>
1926 <div class="content active">
1927 <div class="ui form">
1928 <div class="field">
1929 <div class="ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, the plugin will be automatically activated after the installation.', 'mainwp' ); ?>" data-position="left center" data-inverted="">
1930 <input type="checkbox" value="1" checked="checked" id="chk_activate_plugin" />
1931 <label for="chk_activate_plugin"><?php esc_html_e( 'Activate after installation', 'mainwp' ); ?></label>
1932 </div>
1933 </div>
1934 <div class="field">
1935 <div class="ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled and the plugin already installed on the sites, the already installed version will be overwritten.', 'mainwp' ); ?>" data-position="left center" data-inverted="">
1936 <input type="checkbox" value="2" checked="checked" id="chk_overwrite" />
1937 <label for="chk_overwrite"><?php esc_html_e( 'Overwrite existing version', 'mainwp' ); ?></label>
1938 </div>
1939 </div>
1940 </div>
1941 </div>
1942 <?php do_action( 'mainwp_manage_plugins_after_search_options' ); ?>
1943 </div>
1944 <div class="ui fitted divider"></div>
1945 <div class="mainwp-search-submit">
1946 <?php do_action( 'mainwp_manage_plugins_before_submit_button' ); ?>
1947 <?php
1948 /**
1949 * Disables plugin installation
1950 *
1951 * Filters whether file modifications are allowed on the Dashboard site. If not, installation process will be disabled too.
1952 *
1953 * @since 4.1
1954 */
1955 $allow_install = apply_filters( 'file_mod_allowed', true, 'mainwp_install_plugin' );
1956 if ( $allow_install ) {
1957 $is_demo = MainWP_Demo_Handle::is_demo_mode();
1958 if ( $is_demo ) {
1959 MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<input type="button" disabled="disabled" class="ui green big fluid button disabled" value="' . esc_html__( 'Complete Installation', 'mainwp' ) . '">' );
1960 } else {
1961 ?>
1962 <input type="button" value="<?php esc_attr_e( 'Complete Installation', 'mainwp' ); ?>" class="ui green big fluid button" id="mainwp_plugin_bulk_install_btn" bulk-action="install" name="bulk-install">
1963 <?php
1964 }
1965 }
1966 ?>
1967 <?php do_action( 'mainwp_manage_plugins_before_submit_button' ); ?>
1968 </div>
1969 <?php do_action( 'mainwp_manage_plugins_sidebar_bottom', 'install' ); ?>
1970 </div>
1971 <div class="ui clearing hidden divider"></div>
1972 </div>
1973 <?php
1974 }
1975
1976 /**
1977 * Render Autoupdate SubPage.
1978 *
1979 * @uses \MainWP\Dashboard\MainWP_UI::render_modal_edit_notes()
1980 */
1981 public static function render_auto_update() { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
1982
1983 $cachedAUSearch = isset( $_SESSION['MainWP_PluginsActiveStatus'] ) ? $_SESSION['MainWP_PluginsActiveStatus'] : null; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized --- ok.
1984
1985 static::render_header( 'AutoUpdate' );
1986
1987 if ( ! \mainwp_current_user_can( 'dashboard', 'trust_untrust_updates' ) ) {
1988 \mainwp_do_not_have_permissions( esc_html__( 'trust/untrust updates', 'mainwp' ) );
1989 } else {
1990 $snPluginAutomaticDailyUpdate = get_option( 'mainwp_pluginAutomaticDailyUpdate' );
1991
1992 if ( false === $snPluginAutomaticDailyUpdate ) {
1993 $snPluginAutomaticDailyUpdate = get_option( 'mainwp_automaticDailyUpdate' );
1994 update_option( 'mainwp_pluginAutomaticDailyUpdate', $snPluginAutomaticDailyUpdate );
1995 }
1996
1997 ?>
1998 <div class="ui alt segment" id="mainwp-plugin-auto-updates">
1999 <div class="mainwp-main-content">
2000 <div class="mainwp-actions-bar">
2001 <div class="ui mini form stackable grid">
2002 <div class="ui two column row">
2003 <div class="left aligned column">
2004 <select id="mainwp-bulk-actions" name="bulk_action" class="ui mini selection dropdown">
2005 <option class="item" value=""><?php esc_html_e( 'Bulk Actions', 'mainwp' ); ?></option>
2006 <option class="item" value="trust"><?php esc_html_e( 'Trust', 'mainwp' ); ?></option>
2007 <option class="item" value="untrust"><?php esc_html_e( 'Untrust', 'mainwp' ); ?></option>
2008 <?php
2009 /**
2010 * Action: mainwp_plugins_auto_updates_bulk_action
2011 *
2012 * Adds new action to the bulk actions menu on Plugins Auto Updates.
2013 *
2014 * @since 4.1
2015 */
2016 do_action( 'mainwp_plugins_auto_updates_bulk_action' );
2017 ?>
2018 </select>
2019 <input type="button" name="" id="mainwp-bulk-trust-plugins-action-apply" class="ui mini basic button" value="<?php esc_attr_e( 'Apply', 'mainwp' ); ?>"/>
2020 </div>
2021 <div class="right aligned column"></div>
2022 </div>
2023 </div>
2024 </div>
2025
2026 <?php if ( isset( $_GET['message'] ) && 'saved' === $_GET['message'] ) : // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>
2027 <div class="ui message green"><?php esc_html_e( 'Settings have been saved.', 'mainwp' ); ?></div>
2028 <?php endif; ?>
2029 <div id="mainwp-message-zone" class="ui message" style="display:none"></div>
2030 <div id="mainwp-auto-updates-plugins-content" class="ui segment">
2031 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-disable-auto-updates-info-message' ) ) : ?>
2032 <div class="ui info message">
2033 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-disable-auto-updates-info-message"></i>
2034 <div><?php printf( esc_html__( 'Check out %1$show to disable the WordPress built in auto-updates feature%2$s.', 'mainwp' ), '<a href="https://mainwp.com/how-to-disable-automatic-plugin-and-theme-updates-on-your-child-sites/" target="_blank">', '</a>' ); // NOSONAR - noopener - open safe. ?></div>
2035 </div>
2036 <?php endif; ?>
2037 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-plugins-auto-updates-info-message' ) ) : ?>
2038 <div class="ui info message">
2039 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-plugins-auto-updates-info-message"></i>
2040 <div><?php esc_html_e( 'The MainWP Advanced Auto Updates feature is a tool for your Dashboard to automatically update plugins that you trust to be updated without breaking your Child sites.', 'mainwp' ); ?></div>
2041 <div><?php esc_html_e( 'Only mark plugins as trusted if you are absolutely sure they can be automatically updated by your MainWP Dashboard without causing issues on the Child sites!', 'mainwp' ); ?></div>
2042 <div><strong><?php esc_html_e( 'Advanced Auto Updates a delayed approximately 24 hours from the update release. Ignored plugins can not be automatically updated.', 'mainwp' ); ?></strong></div>
2043 </div>
2044 <?php endif; ?>
2045 <div class="ui inverted dimmer">
2046 <div class="ui text loader"><?php esc_html_e( 'Loading plugins', 'mainwp' ); ?></div>
2047 </div>
2048 <div id="mainwp-auto-updates-plugins-table-wrapper">
2049 <?php
2050 if ( isset( $_SESSION['MainWP_PluginsActive'] ) ) {
2051 static::render_all_active_table( $_SESSION['MainWP_PluginsActive'] ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2052 }
2053 ?>
2054 </div>
2055 </div>
2056 </div>
2057 <div class="mainwp-side-content mainwp-no-padding">
2058 <?php do_action( 'mainwp_manage_plugins_sidebar_top' ); ?>
2059 <div class="mainwp-search-options ui accordion mainwp-sidebar-accordion">
2060 <?php do_action( 'mainwp_manage_plugins_before_search_options' ); ?>
2061 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Plugin Status to Search', 'mainwp' ); ?></div>
2062 <div class="content active">
2063 <div class="ui mini form">
2064 <div class="field">
2065 <select class="ui fluid dropdown" id="mainwp_au_plugin_status">
2066 <option value="all" <?php echo ( null !== $cachedAUSearch && 'all' === $cachedAUSearch['plugin_status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Active and Inactive', 'mainwp' ); ?></option>
2067 <option value="active" <?php echo ( null !== $cachedAUSearch && 'active' === $cachedAUSearch['plugin_status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Active', 'mainwp' ); ?></option>
2068 <option value="inactive" <?php echo ( null !== $cachedAUSearch && 'inactive' === $cachedAUSearch['plugin_status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Inactive', 'mainwp' ); ?></option>
2069 </select>
2070 </div>
2071 </div>
2072 </div>
2073 <?php do_action( 'mainwp_manage_plugins_after_search_options' ); ?>
2074 </div>
2075 <div class="ui fitted divider"></div>
2076 <div class="mainwp-search-options ui accordion mainwp-sidebar-accordion">
2077 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Search Options', 'mainwp' ); ?></div>
2078 <div class="content active">
2079 <div class="ui mini form">
2080 <div class="field">
2081 <select class="ui fluid dropdown" id="mainwp_au_plugin_trust_status">
2082 <option value="all" <?php echo ( null !== $cachedAUSearch && 'all' === $cachedAUSearch['status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Trusted, Not trusted and Ignored', 'mainwp' ); ?></option>
2083 <option value="trust" <?php echo ( null !== $cachedAUSearch && 'trust' === $cachedAUSearch['status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Trusted', 'mainwp' ); ?></option>
2084 <option value="untrust" <?php echo ( null !== $cachedAUSearch && 'untrust' === $cachedAUSearch['status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Not trusted', 'mainwp' ); ?></option>
2085 <option value="ignored" <?php echo ( null !== $cachedAUSearch && 'ignored' === $cachedAUSearch['status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Ignored', 'mainwp' ); ?></option>
2086 </select>
2087 </div>
2088 <div class="field">
2089 <div class="ui input fluid">
2090 <input type="text" placeholder="<?php esc_attr_e( 'Plugin name', 'mainwp' ); ?>" id="mainwp_au_plugin_keyword" class="text" value="<?php echo ( null !== $cachedAUSearch ) ? esc_attr( $cachedAUSearch['keyword'] ) : ''; ?>">
2091 </div>
2092 </div>
2093 </div>
2094 </div>
2095 </div>
2096 <div class="ui fitted divider"></div>
2097 <div class="mainwp-search-submit">
2098 <?php do_action( 'mainwp_manage_plugins_before_submit_button' ); ?>
2099 <a href="#" class="ui green big fluid button" id="mainwp_show_all_active_plugins"><?php esc_html_e( 'Show Plugins', 'mainwp' ); ?></a>
2100 <?php do_action( 'mainwp_manage_plugins_after_submit_button' ); ?>
2101 </div>
2102 <?php do_action( 'mainwp_manage_plugins_sidebar_bottom' ); ?>
2103 </div>
2104 </div>
2105 <?php
2106 MainWP_UI::render_modal_edit_notes( 'plugin' );
2107 }
2108 static::render_footer( 'AutoUpdate' );
2109 }
2110
2111 /**
2112 * Method render_all_active_table()
2113 *
2114 * Render all active Plugins table.
2115 *
2116 * @param null $output function output.
2117 *
2118 * @return void
2119 *
2120 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
2121 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
2122 * @uses \MainWP\Dashboard\MainWP_DB::query()
2123 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
2124 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
2125 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
2126 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::get_class_name()
2127 * @uses \MainWP\Dashboard\MainWP_Utility::map_site()
2128 * @uses \MainWP\Dashboard\MainWP_Utility::get_nice_url()
2129 */
2130 public static function render_all_active_table( $output = null ) { // phpcs:ignore -- NOSONAR - complex.
2131 $keyword = null;
2132 $search_status = 'all';
2133
2134 $data_fields = MainWP_System_Utility::get_default_map_site_fields();
2135
2136 if ( null === $output ) {
2137 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2138 $keyword = isset( $_POST['keyword'] ) && ! empty( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : null;
2139 $search_status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : 'all';
2140 $search_plugin_status = isset( $_POST['plugin_status'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_status'] ) ) : 'all';
2141 // phpcs:enable
2142
2143 $output = new \stdClass();
2144 $output->errors = array();
2145 $output->plugins = array();
2146 $output->plugins_installed = array(); // to fix.
2147
2148 if ( 1 === (int) get_option( 'mainwp_optimize', 1 ) || MainWP_Demo_Handle::is_demo_mode() ) {
2149 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
2150 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2151 $allPlugins = json_decode( $website->plugins, true );
2152 $_count = count( $allPlugins );
2153 for ( $i = 0; $i < $_count; $i++ ) {
2154 $plugin = $allPlugins[ $i ];
2155
2156 $all = true;
2157 if ( 'all' !== $search_plugin_status ) {
2158 $all = false;
2159 }
2160
2161 if ( ! $all && ( ( 1 === (int) $plugin['active'] && 'active' !== $search_plugin_status ) || ( 1 !== (int) $plugin['active'] && 'inactive' !== $search_plugin_status ) ) ) {
2162 continue;
2163 }
2164
2165 if ( ! empty( $keyword ) ) {
2166 $keyword = trim( $keyword );
2167 $multi_kws = explode( ',', $keyword );
2168 $multi_kws = array_filter( array_map( 'trim', $multi_kws ) );
2169 if ( ! MainWP_Utility::multi_find_keywords( $plugin['name'], $multi_kws ) ) {
2170 continue;
2171 }
2172 }
2173 $plugin['websiteid'] = $website->id;
2174 $plugin['websiteurl'] = $website->url;
2175 $output->plugins[] = $plugin;
2176 }
2177 }
2178 MainWP_DB::free_result( $websites );
2179 } else {
2180 $dbwebsites = array();
2181 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
2182 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2183 if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) {
2184 continue;
2185 }
2186
2187 $dbwebsites[ $website->id ] = MainWP_Utility::map_site(
2188 $website,
2189 $data_fields
2190 );
2191 }
2192 MainWP_DB::free_result( $websites );
2193
2194 $post_data = array( 'keyword' => $keyword );
2195
2196 if ( 'active' === $search_plugin_status || 'inactive' === $search_plugin_status ) {
2197 $post_data['status'] = $search_plugin_status;
2198 $post_data['filter'] = true;
2199 } else {
2200 $post_data['status'] = '';
2201 $post_data['filter'] = false;
2202 }
2203 $output->status = $search_plugin_status;
2204 MainWP_Connect::fetch_urls_authed( $dbwebsites, 'get_all_plugins', $post_data, array( MainWP_Plugins_Handler::get_class_name(), 'plugins_search_handler' ), $output );
2205 // phpcs:disable WordPress.Security.EscapeOutput
2206 if ( ! empty( $output->errors ) ) {
2207 foreach ( $output->errors as $siteid => $error ) {
2208 echo MainWP_Utility::get_nice_url( $dbwebsites[ $siteid ]->url ) . ' - ' . $error . ' <br/>';
2209
2210 }
2211 echo '<div class="ui hidden divider"></div>';
2212
2213 if ( count( $output->errors ) === count( $dbwebsites ) ) {
2214 $_SESSION['MainWP_PluginsActive'] = $output;
2215 $_SESSION['MainWP_PluginsActiveStatus'] = array(
2216 'keyword' => $keyword,
2217 'status' => $search_status,
2218 'plugin_status' => $search_plugin_status,
2219 );
2220 return;
2221 }
2222 }
2223 // phpcs:enable
2224 }
2225
2226 $_SESSION['MainWP_PluginsActive'] = $output;
2227 $_SESSION['MainWP_PluginsActiveStatus'] = array(
2228 'keyword' => $keyword,
2229 'status' => $search_status,
2230 'plugin_status' => $search_plugin_status,
2231 );
2232 } elseif ( isset( $_SESSION['MainWP_PluginsActiveStatus'] ) ) {
2233 //phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2234 $keyword = isset( $_SESSION['MainWP_PluginsActiveStatus']['keyword'] ) ? $_SESSION['MainWP_PluginsActiveStatus']['keyword'] : null;
2235 $search_status = isset( $_SESSION['MainWP_PluginsActiveStatus']['status'] ) ? $_SESSION['MainWP_PluginsActiveStatus']['status'] : null;
2236 $search_plugin_status = isset( $_SESSION['MainWP_PluginsActiveStatus']['plugin_status'] ) ? $_SESSION['MainWP_PluginsActiveStatus']['plugin_status'] : null;
2237 //phpcs:enable
2238 }
2239
2240 if ( 'inactive' !== $search_plugin_status && ( empty( $keyword ) || ( ! empty( $keyword ) && false !== stristr( 'MainWP Child', $keyword ) ) ) ) {
2241 $output->plugins[] = array(
2242 'slug' => 'mainwp-child/mainwp-child.php',
2243 'name' => 'MainWP Child',
2244 'active' => 1,
2245 );
2246 }
2247
2248 if ( empty( $output->plugins ) ) {
2249 ?>
2250 <div class="ui message yellow"><?php esc_html_e( 'No plugins found.', 'mainwp' ); ?></div>
2251 <?php
2252 return;
2253 }
2254
2255 $plugins = array();
2256 foreach ( $output->plugins as $plugin ) {
2257 $plugins[ $plugin['slug'] ] = $plugin;
2258 }
2259 asort( $plugins );
2260
2261 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
2262 $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true );
2263 $trustedPlugins = json_decode( $userExtension->trusted_plugins, true );
2264
2265 if ( ! is_array( $trustedPlugins ) ) {
2266 $trustedPlugins = array();
2267 }
2268 $trustedPluginsNotes = json_decode( $userExtension->trusted_plugins_notes, true );
2269 if ( ! is_array( $trustedPluginsNotes ) ) {
2270 $trustedPluginsNotes = array();
2271 }
2272 static::render_all_active_html( $plugins, $trustedPlugins, $search_status, $decodedIgnoredPlugins, $trustedPluginsNotes );
2273 MainWP_UI::render_modal_upload_icon();
2274 }
2275
2276
2277 /**
2278 * Method render_all_active_html()
2279 *
2280 * Render all active plugins html.
2281 *
2282 * @param array $plugins Plugins array.
2283 * @param array $trustedPlugins Trusted plugins array.
2284 * @param mixed $search_status trust|untrust|ignored.
2285 * @param array $decodedIgnoredPlugins Decoded ignored plugins array.
2286 * @param array $trustedPluginsNotes Trusted plugins notes.
2287 *
2288 * @uses \MainWP\Dashboard\MainWP_Utility::esc_content()
2289 */
2290 public static function render_all_active_html( $plugins, $trustedPlugins, $search_status, $decodedIgnoredPlugins, $trustedPluginsNotes ) { // phpcs:ignore -- NOSONAR - complex.
2291
2292 /**
2293 * Action: mainwp_plugins_before_auto_updates_table
2294 *
2295 * Fires before the Auto Update Plugins table.
2296 *
2297 * @since 4.1
2298 */
2299 do_action( 'mainwp_plugins_before_auto_updates_table' );
2300 ?>
2301 <table class="ui unstackable table" id="mainwp-all-active-plugins-table">
2302 <thead>
2303 <tr>
2304 <th scope="col" class="no-sort check-column collapsing"><span class="ui checkbox"><input id="cb-select-all-top" type="checkbox" /></span></th>
2305 <th scope="col" class="no-sort"></th>
2306 <th scope="col" data-priority="1"><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
2307 <th scope="col" ><?php esc_html_e( 'Status', 'mainwp' ); ?></th>
2308 <th scope="col" class="collapsing" data-priority="2"><?php esc_html_e( 'Trust Status', 'mainwp' ); ?></th>
2309 <th scope="col"><?php esc_html_e( 'Ignored Status', 'mainwp' ); ?></th>
2310 <th scope="col" class="collapsing"></th>
2311 <th scope="col" class="collapsing"><?php esc_html_e( 'Notes', 'mainwp' ); ?></th>
2312 </tr>
2313 </thead>
2314 <tbody>
2315 <?php foreach ( $plugins as $slug => $plugin ) : ?>
2316 <?php
2317 $name = $plugin['name'];
2318 $wpid = isset( $plugin['websiteid'] ) ? intval( $plugin['websiteid'] ) : 0;
2319
2320 if ( ! empty( $search_status ) && 'all' !== $search_status ) {
2321 if ( 'trust' === $search_status && ! in_array( $slug, $trustedPlugins ) ) {
2322 continue;
2323 }
2324
2325 if ( 'untrust' === $search_status && in_array( $slug, $trustedPlugins ) ) {
2326 continue;
2327 }
2328
2329 if ( 'ignored' === $search_status && ! MainWP_Common_Functions::instance()->is_ignored_updates( $plugin, $decodedIgnoredPlugins, 'plugin' ) ) {
2330 continue;
2331 }
2332 }
2333 $esc_note = '';
2334 $strip_note = '';
2335 if ( isset( $trustedPluginsNotes[ $slug ] ) ) {
2336 $esc_note = MainWP_Utility::esc_content( $trustedPluginsNotes[ $slug ] );
2337 $strip_note = wp_strip_all_tags( $esc_note );
2338 }
2339
2340 $plugin_directory = dirname( $slug );
2341 ?>
2342 <?php // phpcs:disable WordPress.Security.EscapeOutput ?>
2343 <tr plugin-slug="<?php echo esc_attr( rawurlencode( $slug ) ); ?>" plugin-name="<?php echo esc_html( wp_strip_all_tags( $name ) ); ?>">
2344 <td class="check-column"><span class="ui checkbox"><input type="checkbox" name="plugin[]" value="<?php echo esc_attr( rawurlencode( $slug ) ); ?>"></span></td>
2345 <td class="collapsing"><?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); ?></td>
2346 <td><a href="<?php echo esc_url( admin_url() ) . 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $wpid ) . '&plugin=' . rawurlencode( dirname( $slug ) ); ?>" target="_blank" class="open-plugin-details-modal"><?php echo esc_html( $name ); ?></a></td>
2347 <td><?php echo ( 1 === (int) $plugin['active'] ) ? esc_html__( 'Active', 'mainwp' ) : esc_html__( 'Inactive', 'mainwp' ); //phpcs:ignore -- escaped. ?></td>
2348 <td><?php echo ( in_array( $slug, $trustedPlugins ) ) ? '<span class="ui mini green fluid center aligned label">' . esc_html__( 'Trusted', 'mainwp' ) . '</span>' : '<span class="ui mini red fluid center aligned label">' . esc_html__( 'Not Trusted', 'mainwp' ) . '</span>'; ?></td>
2349 <td><?php echo MainWP_Common_Functions::instance()->is_ignored_updates( $plugin, $decodedIgnoredPlugins, 'plugin' ) ? '<span class="ui mini label">' . esc_html__( 'Ignored', 'mainwp' ) . '</span>' : ''; ?></td>
2350 <td><?php echo MainWP_Common_Functions::instance()->is_ignored_updates( $plugin, $decodedIgnoredPlugins, 'plugin' ) ? '<span data-tooltip="Ignored plugins will not be automatically updated." data-inverted=""><i class="info red circle icon" ></i></span>' : ''; ?></td>
2351 <td class="collapsing center aligned">
2352 <?php if ( '' === $esc_note ) : ?>
2353 <a href="javascript:void(0)" class="mainwp-edit-plugin-note" ><i class="sticky note outline icon"></i></a>
2354 <?php else : ?>
2355 <a href="javascript:void(0)" class="mainwp-edit-plugin-note" data-tooltip="<?php echo substr( $strip_note, 0, 100 ); //phpcs:ignore -- escaped. ?>" data-position="left center" data-inverted=""><i class="sticky green note icon"></i></a>
2356 <?php endif; ?>
2357 <span style="display: none" class="esc-content-note"><?php echo $esc_note; //phpcs:ignore -- escaped. ?></span>
2358 </td>
2359 </tr>
2360 <?php // phpcs:enable ?>
2361 <?php endforeach; ?>
2362 </tbody>
2363 <tfoot>
2364 <tr>
2365 <th scope="col" class="no-sort check-column"><span class="ui checkbox"><input id="cb-select-all-bottom" type="checkbox" /></span></th>
2366 <th scope="col" ></th>
2367 <th scope="col" ><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
2368 <th scope="col" ><?php esc_html_e( 'Status', 'mainwp' ); ?></th>
2369 <th scope="col" ><?php esc_html_e( 'Trust Status', 'mainwp' ); ?></th>
2370 <th scope="col" ><?php esc_html_e( 'Ignored Status', 'mainwp' ); ?></th>
2371 <th scope="col" class="collapsing"></th>
2372 <th scope="col" ><?php esc_html_e( 'Notes', 'mainwp' ); ?></th>
2373 </tr>
2374 </tfoot>
2375 </table>
2376 <?php
2377 /**
2378 * Action: mainwp_plugins_after_auto_updates_table
2379 *
2380 * Fires after the Auto Update Plugins table.
2381 *
2382 * @since 4.1
2383 */
2384 do_action( 'mainwp_plugins_after_auto_updates_table' );
2385
2386 $table_features = array(
2387 'searching' => 'true',
2388 'stateSave' => 'true',
2389 'colReorder' => 'true',
2390 'info' => 'true',
2391 'paging' => 'false',
2392 'ordering' => 'true',
2393 'order' => '[ [ 2, "asc" ] ]',
2394 'responsive' => 'true',
2395 );
2396
2397 /**
2398 * Filter: mainwp_plugin_auto_updates_table_fatures
2399 *
2400 * Filters the Plugin Auto Updates table features.
2401 *
2402 * @since 4.1
2403 */
2404 $table_features = apply_filters( 'mainwp_plugin_auto_updates_table_fatures', $table_features );
2405 ?>
2406 <script type="text/javascript">
2407 jQuery( document ).ready( function() {
2408 let responsive = <?php echo esc_html( $table_features['responsive'] ); ?>;
2409 if( jQuery( window ).width() > 1140 ) {
2410 responsive = false;
2411 }
2412 jQuery( '#mainwp-all-active-plugins-table' ).DataTable( {
2413 "searching" : <?php echo esc_html( $table_features['searching'] ); ?>,
2414 "stateSave" : <?php echo esc_html( $table_features['stateSave'] ); ?>,
2415 "colReorder" : <?php echo $table_features['colReorder']; // phpcs:ignore -- specical chars. ?>,
2416 "info" : <?php echo esc_html( $table_features['info'] ); ?>,
2417 "paging" : <?php echo esc_html( $table_features['paging'] ); ?>,
2418 "ordering" : <?php echo esc_html( $table_features['ordering'] ); ?>,
2419 "order" : <?php echo $table_features['order']; // phpcs:ignore -- specical chars. ?>,
2420 "columnDefs": [ { "orderable": false, "targets": [ 0, 1, 6 ] } ],
2421 "responsive": responsive,
2422 } );
2423 } );
2424 </script>
2425
2426 <script type="text/javascript">
2427 jQuery( document ).ready( function () {
2428 jQuery( '.mainwp-ui-page .ui.checkbox:not(.not-auto-init)' ).checkbox();
2429 } );
2430 </script>
2431 <?php
2432 }
2433
2434 /**
2435 * Render Ignore Subpage.
2436 *
2437 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
2438 * @uses \MainWP\Dashboard\MainWP_DB::query()
2439 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
2440 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
2441 */
2442 public static function render_ignore() {
2443 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
2444 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
2445 $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true );
2446 $ignoredPlugins = is_array( $decodedIgnoredPlugins ) && ( ! empty( $decodedIgnoredPlugins ) );
2447
2448 $cnt = 0;
2449
2450 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2451 if ( $website->is_ignorePluginUpdates ) {
2452 continue;
2453 }
2454
2455 $tmpDecodedIgnoredPlugins = json_decode( $website->ignored_plugins, true );
2456
2457 if ( ! is_array( $tmpDecodedIgnoredPlugins ) || empty( $tmpDecodedIgnoredPlugins ) ) {
2458 continue;
2459 }
2460 ++$cnt;
2461 }
2462
2463 static::render_header( 'Ignore' );
2464 ?>
2465 <div id="mainwp-ignored-plugins" class="ui segment">
2466 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-ignored-plugins-info-message' ) ) : ?>
2467 <div class="ui info message">
2468 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-ignored-plugins-info-message"></i>
2469 <?php printf( esc_html__( 'Manage plugins you have told your MainWP Dashboard to ignore updates on global or per site level. For additional help, please check this %1$shelp documentation%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/ignore-plugin-updates/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); ?>
2470 </div>
2471 <?php endif; ?>
2472 <?php
2473 /**
2474 * Action: mainwp_plugins_before_ignored_updates
2475 *
2476 * Fires on the top of the Ignored Plugin Updates page.
2477 *
2478 * @since 4.1
2479 */
2480 do_action( 'mainwp_plugins_before_ignored_updates', $ignoredPlugins, $websites );
2481 ?>
2482 <h3 class="ui header">
2483 <?php esc_html_e( 'Globally Ignored Plugins', 'mainwp' ); ?>
2484 <div class="sub header"><?php esc_html_e( 'These are plugins you have told your MainWP Dashboard to ignore updates on global level and not notify you about pending updates.', 'mainwp' ); ?></div>
2485 </h3>
2486 <?php static::render_global_ignored( $ignoredPlugins, $decodedIgnoredPlugins ); ?>
2487 <div class="ui hidden divider"></div>
2488 <h3 class="ui header">
2489 <?php esc_html_e( 'Per Site Ignored Plugins' ); ?>
2490 <div class="sub header"><?php esc_html_e( 'These are plugins you have told your MainWP Dashboard to ignore updates per site level and not notify you about pending updates.', 'mainwp' ); ?></div>
2491 </h3>
2492 <?php static::render_sites_ignored( $cnt, $websites ); ?>
2493 <?php
2494 /**
2495 * Action: mainwp_plugins_after_ignored_updates
2496 *
2497 * Fires on the bottom of the Ignored Plugin Updates page.
2498 *
2499 * @since 4.1
2500 */
2501 do_action( 'mainwp_plugins_after_ignored_updates', $ignoredPlugins, $websites );
2502 ?>
2503 </div>
2504 <?php
2505 MainWP_Updates::render_plugin_details_modal();
2506 static::render_footer( 'Ignore' );
2507 }
2508
2509 /**
2510 * Method render_global_ignored()
2511 *
2512 * Render Global Ignored plugins list.
2513 *
2514 * @param array $ignoredPlugins Ignored plugins array.
2515 * @param array $decodedIgnoredPlugins Decoded ignored plugins array.
2516 */
2517 public static function render_global_ignored( $ignoredPlugins, $decodedIgnoredPlugins ) { //phpcs:ignore -- NOSONAR - complex.
2518 ?>
2519 <table id="mainwp-globally-ignored-plugins" class="ui compact selectable table unstackable">
2520 <thead>
2521 <tr>
2522 <th scope="col" class="no-sort"></th>
2523 <th scope="col" ><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
2524 <th scope="col" ><?php esc_html_e( 'Plugin slug', 'mainwp' ); ?></th>
2525 <th scope="col" ><?php esc_html_e( 'Ignored version', 'mainwp' ); ?></th>
2526 <th scope="col" ></th>
2527 </tr>
2528 </thead>
2529 <tbody id="globally-ignored-plugins-list">
2530 <?php if ( $ignoredPlugins ) : ?>
2531 <?php // phpcs:disable WordPress.Security.EscapeOutput ?>
2532 <?php
2533 foreach ( $decodedIgnoredPlugins as $ignoredPlugin => $ignoredPluginName ) :
2534
2535 $ignore_name = 'N/A';
2536 $ignored_vers = array( 'all_versions' );
2537 if ( is_string( $ignoredPluginName ) ) {
2538 $ignore_name = $ignoredPluginName;
2539 } elseif ( is_array( $ignoredPluginName ) ) {
2540 $ignore_name = ! empty( $ignoredPluginName['Name'] ) ? $ignoredPluginName['Name'] : $ignore_name;
2541 $ig_vers = ! empty( $ignoredPluginName['ignored_versions'] ) ? $ignoredPluginName['ignored_versions'] : '';
2542 if ( ! empty( $ig_vers ) && is_array( $ig_vers ) && ! in_array( 'all_versions', $ig_vers ) ) {
2543 $ignored_vers = $ig_vers;
2544 }
2545 }
2546 ?>
2547 <?php $plugin_directory = dirname( $ignoredPlugin ); ?>
2548 <?php foreach ( $ignored_vers as $ignored_ver ) { ?>
2549 <tr plugin-slug="<?php echo esc_attr( rawurlencode( $ignoredPlugin ) ); ?>">
2550 <td class="collapsing"><?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); ?></td>
2551 <td><a href="<?php echo esc_url( admin_url() ) . 'plugin-install.php?tab=plugin-information&plugin=' . esc_html( rawurlencode( dirname( $ignoredPlugin ) ) ); ?>" target="_blank" class="open-plugin-details-modal"><?php echo esc_html( $ignore_name ); ?></a></td>
2552 <td><?php echo esc_html( $ignoredPlugin ); ?></td>
2553 <td><?php echo 'all_versions' === $ignored_ver ? esc_html__( 'All', 'mainwp' ) : esc_html( $ignored_ver ); ?></td>
2554 <td class="right aligned">
2555 <?php if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2556 <a href="#" class="ui mini button" onClick="return updatesoverview_plugins_unignore_globally( '<?php echo esc_html( rawurlencode( $ignoredPlugin ) ); ?>', '<?php echo esc_js( rawurlencode( $ignored_ver ) ); ?>' )"><?php esc_html_e( 'Unignore', 'mainwp' ); ?></a>
2557 <?php endif; ?>
2558 </td>
2559 </tr>
2560 <?php } ?>
2561 <?php endforeach; ?>
2562 <?php // phpcs:enable ?>
2563 <?php endif; ?>
2564 </tbody>
2565 <?php if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2566 <?php if ( $ignoredPlugins ) : ?>
2567 <tfoot class="full-width">
2568 <tr>
2569 <th scope="col" colspan="5">
2570 <a class="ui right floated small green labeled icon button" onClick="return updatesoverview_plugins_unignore_globally_all();" id="mainwp-unignore-globally-all">
2571 <i class="check icon"></i> <?php esc_html_e( 'Unignore All', 'mainwp' ); ?>
2572 </a>
2573 </th>
2574 </tr>
2575 </tfoot>
2576 <?php endif; ?>
2577 <?php endif; ?>
2578 </table>
2579 <script type="text/javascript">
2580 jQuery( document ).ready( function() {
2581 jQuery( '#mainwp-globally-ignored-plugins' ).DataTable( {
2582 "searching": false,
2583 "paging": false,
2584 "info": false,
2585 "responsive": true,
2586 "columnDefs": [ {
2587 "targets": 'no-sort',
2588 "orderable": false
2589 } ],
2590 "language": {
2591 "emptyTable": "<?php esc_html_e( 'No ignored plugins.', 'mainwp' ); ?>"
2592 }
2593 } );
2594 } );
2595 </script>
2596 <?php
2597 }
2598
2599 /**
2600 * Render Per Site Ignored table.
2601 *
2602 * @param mixed $cnt Plugin count.
2603 * @param mixed $websites Child Sites.
2604 *
2605 * @return void
2606 *
2607 * @uses \MainWP\Dashboard\MainWP_DB::data_seek()
2608 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
2609 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
2610 */
2611 public static function render_sites_ignored( $cnt, $websites ) { // phpcs:ignore -- NOSONAR - complex.
2612 ?>
2613 <table id="mainwp-per-site-ignored-plugins" class="ui unstackable compact selectable table ">
2614 <thead>
2615 <tr>
2616 <th scope="col" ><?php esc_html_e( 'Site', 'mainwp' ); ?></th>
2617 <th scope="col" class="no-sort"></th>
2618 <th scope="col" ><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
2619 <th scope="col" ><?php esc_html_e( 'Plugin slug', 'mainwp' ); ?></th>
2620 <th scope="col" ><?php esc_html_e( 'Ignored version', 'mainwp' ); ?></th>
2621 <th scope="col" ></th>
2622 </tr>
2623 </thead>
2624 <tbody id="ignored-plugins-list">
2625 <?php if ( 0 < $cnt ) : ?>
2626 <?php
2627 MainWP_DB::data_seek( $websites, 0 );
2628
2629 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2630 if ( $website->is_ignorePluginUpdates ) {
2631 continue;
2632 }
2633
2634 $decodedIgnoredPlugins = json_decode( $website->ignored_plugins, true );
2635 if ( ! is_array( $decodedIgnoredPlugins ) || empty( $decodedIgnoredPlugins ) ) {
2636 continue;
2637 }
2638 $first = true;
2639 // phpcs:disable WordPress.Security.EscapeOutput
2640 foreach ( $decodedIgnoredPlugins as $ignoredPlugin => $ignoredPluginName ) {
2641
2642 $ignore_name = 'N/A';
2643 $ignored_vers = array( 'all_versions' );
2644 if ( is_string( $ignoredPluginName ) ) {
2645 $ignore_name = $ignoredPluginName;
2646 } elseif ( is_array( $ignoredPluginName ) ) {
2647 $ignore_name = ! empty( $ignoredPluginName['Name'] ) ? $ignoredPluginName['Name'] : $ignore_name;
2648 $ig_vers = ! empty( $ignoredPluginName['ignored_versions'] ) ? $ignoredPluginName['ignored_versions'] : '';
2649 if ( ! empty( $ig_vers ) && is_array( $ig_vers ) && ! in_array( 'all_versions', $ig_vers ) ) {
2650 $ignored_vers = $ig_vers;
2651 }
2652 }
2653 $plugin_directory = MainWP_Utility::get_dir_slug( rawurldecode( $ignoredPlugin ) );
2654 foreach ( $ignored_vers as $ignored_ver ) {
2655 ?>
2656 <tr site-id="<?php echo intval( $website->id ); ?>" plugin-slug="<?php echo esc_attr( rawurlencode( $ignoredPlugin ) ); ?>">
2657 <?php if ( $first ) : ?>
2658 <td><div><a href="<?php echo esc_url( admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) ); ?>"><?php echo esc_html( stripslashes( $website->name ) ); ?></a></div></td>
2659 <?php $first = false; ?>
2660 <?php else : ?>
2661 <td><div style="display:none;"><a href="<?php echo esc_url( admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) ); ?>"><?php echo esc_html( stripslashes( $website->name ) ); ?></a></div></td>
2662 <?php endif; ?>
2663 <td class="collapsing"><?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); ?></td>
2664 <td><a href="<?php echo esc_url( admin_url() ) . 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $website->id ) . '&plugin=' . esc_html( rawurlencode( $plugin_directory ) ); ?>" target="_blank" class="open-plugin-details-modal"><?php echo esc_html( $ignore_name ); ?></a></td>
2665 <td><?php echo esc_html( rawurldecode( $ignoredPlugin ) ); ?></td>
2666 <td><?php echo 'all_versions' === $ignored_ver ? esc_html__( 'All', 'mainwp' ) : esc_html( $ignored_ver ); ?></td>
2667 <?php if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2668 <td class="right aligned"><a href="#" class="ui mini button" onClick="return updatesoverview_plugins_unignore_detail( '<?php echo esc_js( rawurlencode( $ignoredPlugin ) ); ?>', <?php echo intval( $website->id ); ?>, '<?php echo esc_js( rawurlencode( $ignored_ver ) ); ?>' )"> <?php esc_html_e( 'Unignore', 'mainwp' ); ?></a></td>
2669 <?php endif; ?>
2670 <?php } ?>
2671 </tr>
2672 <?php
2673 }
2674 // phpcs:enable
2675 }
2676
2677 MainWP_DB::free_result( $websites );
2678 ?>
2679 <?php endif; ?>
2680 </tbody>
2681 <?php if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2682 <?php if ( 0 < $cnt ) : ?>
2683 <tfoot class="full-width">
2684 <tr>
2685 <th scope="col" colspan="6">
2686 <a class="ui right floated small green labeled icon button" onClick="return updatesoverview_plugins_unignore_detail_all();" id="mainwp-unignore-detail-all">
2687 <i class="check icon"></i> <?php esc_html_e( 'Unignore All', 'mainwp' ); ?>
2688 </a>
2689 </th>
2690 </tr>
2691 </tfoot>
2692 <?php endif; ?>
2693 <?php endif; ?>
2694 </table>
2695 <script type="text/javascript">
2696 jQuery( document ).ready( function() {
2697 jQuery( '#mainwp-per-site-ignored-plugins' ).DataTable( {
2698 "responsive": true,
2699 "searching": false,
2700 "paging": false,
2701 "info": false,
2702 "columnDefs": [ {
2703 "targets": 'no-sort',
2704 "orderable": false
2705 } ],
2706 "language": {
2707 "emptyTable": "<?php esc_html_e( 'No ignored plugins', 'mainwp' ); ?>"
2708 }
2709 } );
2710 } );
2711 </script>
2712 <?php
2713 }
2714
2715 /**
2716 * Render Ignored Abandoned Page.
2717 *
2718 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
2719 * @uses \MainWP\Dashboard\MainWP_DB::query()
2720 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
2721 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
2722 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
2723 */
2724 public static function render_ignored_abandoned() {
2725 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
2726 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
2727 $decodedIgnoredPlugins = json_decode( $userExtension->dismissed_plugins, true );
2728 $ignoredPlugins = is_array( $decodedIgnoredPlugins ) && ( ! empty( $decodedIgnoredPlugins ) );
2729 $cnt = 0;
2730 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2731 $tmpDecodedDismissedPlugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' );
2732 $tmpDecodedDismissedPlugins = ! empty( $tmpDecodedDismissedPlugins ) ? json_decode( $tmpDecodedDismissedPlugins, true ) : array();
2733
2734 if ( ! is_array( $tmpDecodedDismissedPlugins ) || empty( $tmpDecodedDismissedPlugins ) ) {
2735 continue;
2736 }
2737 ++$cnt;
2738 }
2739
2740 static::render_header( 'IgnoreAbandoned' );
2741 ?>
2742 <div id="mainwp-ignored-abandoned-plugins" class="ui segment">
2743 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-ignored-abandoned-plugins-info-message' ) ) : ?>
2744 <div class="ui info message">
2745 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-ignored-abandoned-plugins-info-message"></i>
2746 <?php printf( esc_html__( 'Manage abandoned plugins you have told your MainWP Dashboard to ignore on global or per site level. For additional help, please check this %1$shelp documentation%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/abandoned-plugins/" target="_blank">', '</a> <i class="external alternate icon"></i> ' ); ?>
2747 </div>
2748 <?php endif; ?>
2749 <?php
2750 /**
2751 * Action: mainwp_plugins_before_ignored_abandoned
2752 *
2753 * Fires on the top of the Ignored Plugins Abandoned page.
2754 *
2755 * @since 4.1
2756 */
2757 do_action( 'mainwp_plugins_before_ignored_abandoned', $ignoredPlugins, $websites );
2758 ?>
2759 <h3 class="ui header">
2760 <?php esc_html_e( 'Globally Ignored Abandoned Plugins' ); ?>
2761 <div class="sub header"><?php esc_html_e( 'These are plugins you have told your MainWP Dashboard to ignore on global level even though they have passed your Abandoned Plugin Tolerance date', 'mainwp' ); ?></div>
2762 </h3>
2763 <?php static::render_global_ignored_abandoned( $ignoredPlugins, $decodedIgnoredPlugins ); ?>
2764 <div class="ui hidden divider"></div>
2765 <h3 class="ui header">
2766 <?php esc_html_e( 'Per Site Ignored Abandoned Plugins' ); ?>
2767 <div class="sub header"><?php esc_html_e( 'These are plugins you have told your MainWP Dashboard to ignore per site level even though they have passed your Abandoned Plugin Tolerance date', 'mainwp' ); ?></div>
2768 </h3>
2769 <?php static::render_sites_ignored_abandoned( $cnt, $websites ); ?>
2770 <?php
2771 /**
2772 * Action: mainwp_plugins_after_ignored_abandoned
2773 *
2774 * Fires on the bottom of the Ignored Plugins Abandoned page.
2775 *
2776 * @since 4.1
2777 */
2778 do_action( 'mainwp_plugins_after_ignored_abandoned', $ignoredPlugins, $websites );
2779 ?>
2780 </div>
2781 <?php
2782 static::render_footer( 'IgnoreAbandoned' );
2783 }
2784
2785 /**
2786 * Method render_global_ignored_abandoned()
2787 *
2788 * Render Global Ignored Abandoned table.
2789 *
2790 * @param array $ignoredPlugins Ignored plugins array.
2791 * @param array $decodedIgnoredPlugins Decoded dgnored plugins array.
2792 */
2793 public static function render_global_ignored_abandoned( $ignoredPlugins, $decodedIgnoredPlugins ) {
2794 ?>
2795 <table id="mainwp-globally-ignored-abandoned-plugins" class="ui compact selectable table unstackable">
2796 <thead>
2797 <tr>
2798 <th scope="col" class="no-sort"><?php esc_html_e( ' ', 'mainwp' ); ?></th>
2799 <th scope="col" ><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
2800 <th scope="col" ><?php esc_html_e( 'Plugin slug', 'mainwp' ); ?></th>
2801 <th scope="col" ></th>
2802 </tr>
2803 </thead>
2804 <tbody id="ignored-globally-abandoned-plugins-list">
2805 <?php if ( $ignoredPlugins ) : ?>
2806 <?php
2807 // phpcs:disable WordPress.Security.EscapeOutput
2808 foreach ( $decodedIgnoredPlugins as $ignoredPlugin => $ignoredPluginName ) :
2809 $ignore_name = 'N/A';
2810 if ( is_string( $ignoredPluginName ) ) {
2811 $ignore_name = $ignoredPluginName;
2812 } elseif ( is_array( $ignoredPluginName ) && ! empty( $ignoredPluginName['Name'] ) ) {
2813 $ignore_name = $ignoredPluginName['Name'];
2814 }
2815
2816 $plugin_directory = MainWP_Utility::get_dir_slug( rawurldecode( $ignoredPlugin ) );
2817 ?>
2818 <tr plugin-slug="<?php echo esc_attr( rawurlencode( $ignoredPlugin ) ); ?>">
2819 <td class="collapsing"><?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); ?></td>
2820 <td><a href="<?php echo esc_url( admin_url() ) . 'plugin-install.php?tab=plugin-information&plugin=' . esc_html( rawurlencode( $plugin_directory ) ); ?>" target="_blank" class="open-plugin-details-modal"><?php echo esc_html( $ignore_name ); ?></a></td>
2821 <td><?php echo esc_html( $ignoredPlugin ); ?></td>
2822 <td class="right aligned">
2823 <?php if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2824 <a href="#" class="ui mini button" onClick="return updatesoverview_plugins_abandoned_unignore_globally( '<?php echo esc_html( rawurlencode( $ignoredPlugin ) ); ?>' )"><?php esc_html_e( 'Unignore', 'mainwp' ); ?></a>
2825 <?php endif; ?>
2826 </td>
2827 </tr>
2828 <?php endforeach; ?>
2829 <?php // phpcs:enable ?>
2830 <?php endif; ?>
2831 </tbody>
2832 <?php if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2833 <?php if ( $ignoredPlugins ) : ?>
2834 <tfoot class="full-width">
2835 <tr>
2836 <th scope="col" colspan="4">
2837 <a class="ui right floated small green labeled icon button" onClick="return updatesoverview_plugins_abandoned_unignore_globally_all();" id="mainwp-unignore-globally-all">
2838 <i class="check icon"></i> <?php esc_html_e( 'Unignore All', 'mainwp' ); ?>
2839 </a>
2840 </th>
2841 </tr>
2842 </tfoot>
2843 <?php endif; ?>
2844 <?php endif; ?>
2845 </table>
2846 <script type="text/javascript">
2847 jQuery( document ).ready( function() {
2848 jQuery( '#mainwp-globally-ignored-abandoned-plugins' ).DataTable( {
2849 "responsive": true,
2850 "searching": false,
2851 "paging": false,
2852 "info": false,
2853 "columnDefs": [ {
2854 "targets": 'no-sort',
2855 "orderable": false
2856 } ],
2857 "language": {
2858 "emptyTable": "<?php esc_html_e( 'No ignored abandoned plugins.', 'mainwp' ); ?>"
2859 }
2860 } );
2861 } );
2862 </script>
2863 <?php
2864 }
2865
2866 /**
2867 * Method render_sites_ignored_abandoned()
2868 *
2869 * Render Per Site Ignored Abandoned Table.
2870 *
2871 * @param int $cnt Plugins count.
2872 * @param object $websites The websites object.
2873 *
2874 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
2875 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
2876 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
2877 */
2878 public static function render_sites_ignored_abandoned( $cnt, $websites ) { // phpcs:ignore -- NOSONAR - complex.
2879 ?>
2880 <table id="mainwp-per-site-ignored-abandoned-plugins" class="ui compact selectable table unstackable">
2881 <thead>
2882 <tr>
2883 <th scope="col" ><?php esc_html_e( 'Site', 'mainwp' ); ?></th>
2884 <th scope="col" class="no-sort"><?php esc_html_e( ' ', 'mainwp' ); ?></th>
2885 <th scope="col" ><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
2886 <th scope="col" ><?php esc_html_e( 'Plugin slug', 'mainwp' ); ?></th>
2887 <th scope="col" ></th>
2888 </tr>
2889 </thead>
2890 <tbody id="ignored-abandoned-plugins-list">
2891 <?php if ( 0 < $cnt ) : ?>
2892 <?php
2893 MainWP_DB::data_seek( $websites, 0 );
2894
2895 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2896 $decodedIgnoredPlugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' );
2897 $decodedIgnoredPlugins = ! empty( $decodedIgnoredPlugins ) ? json_decode( $decodedIgnoredPlugins, true ) : array();
2898
2899 if ( ! is_array( $decodedIgnoredPlugins ) || empty( $decodedIgnoredPlugins ) ) {
2900 continue;
2901 }
2902 $first = true;
2903 // phpcs:disable WordPress.Security.EscapeOutput
2904 foreach ( $decodedIgnoredPlugins as $ignoredPlugin => $ignoredPluginName ) {
2905 $ignore_name = 'N/A';
2906 if ( is_string( $ignoredPluginName ) ) {
2907 $ignore_name = $ignoredPluginName;
2908 } elseif ( is_array( $ignoredPluginName ) && ! empty( $ignoredPluginName['Name'] ) ) {
2909 $ignore_name = $ignoredPluginName['Name'];
2910 }
2911
2912 $plugin_directory = MainWP_Utility::get_dir_slug( rawurldecode( $ignoredPlugin ) );
2913 ?>
2914 <tr site-id="<?php echo esc_attr( $website->id ); ?>" plugin-slug="<?php echo esc_attr( rawurlencode( $ignoredPlugin ) ); ?>">
2915 <?php if ( $first ) : ?>
2916 <td>
2917 <a href="<?php echo esc_url( admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) ); ?>"><?php echo esc_html( stripslashes( $website->name ) ); ?></a>
2918 </td>
2919 <?php $first = false; ?>
2920 <?php else : ?>
2921 <td><div style="display:none;"><a href="<?php echo esc_url( admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) ); ?>"><?php echo esc_html( stripslashes( $website->name ) ); ?></a></div></td>
2922 <?php endif; ?>
2923 <td class="collapsing"><?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); ?></td>
2924 <td><a href="<?php echo esc_url( admin_url() ) . 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $website->id ) . '&plugin=' . esc_html( rawurlencode( $plugin_directory ) ); ?>" target="_blank" class="open-plugin-details-modal"><?php echo esc_html( $ignore_name ); ?></a></td>
2925 <td><?php echo esc_html( $ignoredPlugin ); ?></td>
2926 <td class="right aligned"><a href="#" class="ui mini button" onClick="return updatesoverview_plugins_unignore_abandoned_detail( '<?php echo esc_html( rawurlencode( $ignoredPlugin ) ); ?>', <?php echo intval( $website->id ); ?> )"> <?php esc_html_e( 'Unignore', 'mainwp' ); ?></a></td>
2927 </tr>
2928 <?php
2929 }
2930 // phpcs:enable
2931 }
2932 MainWP_DB::free_result( $websites );
2933 ?>
2934 <?php endif; ?>
2935 </tbody>
2936 <?php if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2937 <?php if ( 0 < $cnt ) : ?>
2938 <tfoot class="full-width">
2939 <tr>
2940 <th scope="col" colspan="5">
2941 <a class="ui right floated small green labeled icon button" onClick="return updatesoverview_plugins_unignore_abandoned_detail_all();" id="mainwp-unignore-detail-all">
2942 <i class="check icon"></i> <?php esc_html_e( 'Unignore All', 'mainwp' ); ?>
2943 </a>
2944 </th>
2945 </tr>
2946 </tfoot>
2947 <?php endif; ?>
2948 <?php endif; ?>
2949 </table>
2950 <script type="text/javascript">
2951 jQuery( document ).ready( function() {
2952 jQuery( '#mainwp-per-site-ignored-abandoned-plugins' ).DataTable( {
2953 "responsive": true,
2954 "searching": false,
2955 "paging": false,
2956 "info": false,
2957 "columnDefs": [ {
2958 "targets": 'no-sort',
2959 "orderable": false
2960 } ],
2961 "language": {
2962 "emptyTable": "<?php esc_html_e( 'No ignored abandoned plugins.', 'mainwp' ); ?>"
2963 }
2964 } );
2965 } );
2966 </script>
2967 <?php
2968 }
2969
2970 /**
2971 * Method mainwp_help_content()
2972 *
2973 * Creates the MainWP Help Documentation List for the help component in the sidebar.
2974 */
2975 public static function mainwp_help_content() {
2976 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2977 if ( isset( $_GET['page'] ) && ( 'PluginsManage' === $_GET['page'] || 'PluginsInstall' === $_GET['page'] || 'PluginsAutoUpdate' === $_GET['page'] || 'PluginsIgnore' === $_GET['page'] || 'PluginsIgnoredAbandoned' === $_GET['page'] ) ) {
2978 ?>
2979 <p><?php esc_html_e( 'If you need help with managing plugins, please review following help documents', 'mainwp' ); ?></p>
2980 <div class="ui list">
2981 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/managing-plugins-with-mainwp/" target="_blank">Managing Plugins with MainWP</a></div>
2982 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/managing-plugins-with-mainwp/#install-plugins" target="_blank">Install Plugins</a></div>
2983 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/managing-plugins-with-mainwp/#activate-plugins" target="_blank">Activate Plugins</a></div>
2984 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/managing-plugins-with-mainwp/#delete-plugins" target="_blank">Delete Plugins</a></div>
2985 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/managing-plugins-with-mainwp/#update-plugins" target="_blank">Update Plugins</a></div>
2986 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/managing-plugins-with-mainwp/#plugins-auto-updates" target="_blank">Plugins Auto Updates</a></div>
2987 <?php
2988 /**
2989 * Action: mainwp_plugins_help_item
2990 *
2991 * Fires at the bottom of the help articles list in the Help sidebar on the Plugins page.
2992 *
2993 * Suggested HTML markup:
2994 *
2995 * <div class="item"><a href="Your custom URL">Your custom text</a></div>
2996 *
2997 * @since 4.1
2998 */
2999 do_action( 'mainwp_plugins_help_item' );
3000 ?>
3001 </div>
3002 <?php
3003 }
3004 // phpcs:enable
3005 }
3006 }
3007