PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.1
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 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.1, at pages/page-mainwp-plugins.php

2,956 lines 159.7 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_have_right( '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_have_right( '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_have_right( '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
1035 if ( ! empty( $plugins_list ) ) {
1036
1037 foreach ( $plugins_list as $plugin ) {
1038 $slug_ver = esc_html( $plugin['slug'] . '_' . $plugin['version'] );
1039 $sites[ $plugin['websiteid'] ] = array(
1040 'websiteurl' => esc_html( $plugin['websiteurl'] ),
1041 'websitename' => $plugin['websitename'],
1042 );
1043
1044 $pluginsSlug[ $slug_ver ] = isset( $plugin['slug'] ) ? $plugin['slug'] : '';
1045 $muPlugins[ $slug_ver ] = isset( $plugin['mu'] ) ? esc_html( $plugin['mu'] ) : 0;
1046 $pluginsName[ $slug_ver ] = esc_html( $plugin['name'] );
1047
1048 $pluginsNameSites[ $plugin['name'] ][ $plugin['websiteid'] ][] = $slug_ver;
1049
1050 $pluginsMainWP[ $slug_ver ] = isset( $plugin['mainwp'] ) ? esc_html( $plugin['mainwp'] ) : 'F';
1051 $pluginsRealVersion[ $slug_ver ] = rawurlencode( $plugin['version'] );
1052
1053 if ( ! isset( $sitePlugins[ $plugin['websiteid'] ] ) || ! is_array( $sitePlugins[ $plugin['websiteid'] ] ) ) {
1054 $sitePlugins[ $plugin['websiteid'] ] = array();
1055 }
1056
1057 $sitePlugins[ $plugin['websiteid'] ][ $slug_ver ] = $plugin;
1058 }
1059
1060 ksort( $pluginsNameSites, SORT_STRING );
1061
1062 if ( MAINWP_VIEW_PER_PLUGIN_THEME === (int) $view_mode ) {
1063 static::render_manage_table( $sites, $pluginsSlug, $sitePlugins, $pluginsMainWP, $muPlugins, $pluginsName, $pluginsNameSites, $pluginsRealVersion, $roll_items_list );
1064 } else {
1065 static::render_manage_per_site_table( $sites, $pluginsSlug, $sitePlugins, $pluginsMainWP, $muPlugins, $pluginsName, $pluginsNameSites, $pluginsRealVersion, $roll_items_list );
1066 }
1067 MainWP_Updates::render_plugin_details_modal();
1068 MainWP_UI::render_modal_upload_icon();
1069 }
1070
1071 $newOutput = ob_get_clean();
1072 $result = array(
1073 'result' => $newOutput,
1074 'bulk_actions' => $bulkActions,
1075 );
1076
1077 MainWP_Cache::add_result( 'Plugins', $result );
1078 return $result;
1079 }
1080
1081
1082 /**
1083 * Render Bulk Actions.
1084 *
1085 * @param mixed $status active|inactive|all.
1086 *
1087 * @return string Plugin Bulk Actions Menu.
1088 */
1089 public static function render_bulk_actions( $status ) {
1090 ob_start();
1091 ?>
1092 <select class="ui dropdown" id="mainwp-bulk-actions">
1093 <option value="none"><?php esc_html_e( 'Bulk Actions', 'mainwp' ); ?></option>
1094 <?php if ( mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
1095 <option value="ignore_updates" data-value="ignore_updates"><?php esc_html_e( 'Ignore updates', 'mainwp' ); ?></option>
1096 <?php endif; ?>
1097 <?php if ( mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) : ?>
1098 <?php if ( 'active' === $status ) : ?>
1099 <option value="deactivate" data-value="deactivate"><?php esc_html_e( 'Deactivate', 'mainwp' ); ?></option>
1100 <?php else : ?>
1101 <option value="deactivate" disabled data-value="deactivate"><?php esc_html_e( 'Deactivate', 'mainwp' ); ?></option>
1102 <?php endif; ?>
1103 <?php endif; ?>
1104 <?php if ( 'inactive' === $status ) : ?>
1105 <?php if ( mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) : ?>
1106 <option value="activate" data-value="activate"><?php esc_html_e( 'Activate', 'mainwp' ); ?></option>
1107 <?php endif; ?>
1108 <?php if ( mainwp_current_user_have_right( 'dashboard', 'delete_plugins' ) ) : ?>
1109 <option value="delete" data-value="delete"><?php esc_html_e( 'Delete', 'mainwp' ); ?></option>
1110 <?php endif; ?>
1111 <?php else : ?>
1112 <?php if ( mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) : ?>
1113 <option value="activate" disabled data-value="activate"><?php esc_html_e( 'Activate', 'mainwp' ); ?></option>
1114 <?php endif; ?>
1115 <?php if ( mainwp_current_user_have_right( 'dashboard', 'delete_plugins' ) ) : ?>
1116 <option value="delete" disabled data-value="delete"><?php esc_html_e( 'Delete', 'mainwp' ); ?></option>
1117 <?php endif; ?>
1118 <?php endif; ?>
1119 <?php
1120 /**
1121 * Action: mainwp_plugins_bulk_action
1122 *
1123 * Adds a new action to the Manage Plugins bulk actions menu.
1124 *
1125 * @param string $status Status search parameter.
1126 *
1127 * @since 4.1
1128 */
1129 do_action( 'mainwp_plugins_bulk_action' );
1130 ?>
1131 </select>
1132 <button class="ui mini basic button" href="javascript:void(0)" id="mainwp-do-plugins-bulk-actions"><?php esc_html_e( 'Apply', 'mainwp' ); ?></button>
1133 <span id="mainwp_bulk_action_loading"><i class="ui active inline loader tiny"></i></span>
1134 <?php
1135 return ob_get_clean();
1136 }
1137
1138 /**
1139 * Method get_manage_view().
1140 *
1141 * Get view mode.
1142 *
1143 * @param string $which plugin|theme.
1144 *
1145 * @return int view mode value.
1146 */
1147 public static function get_manage_view( $which = 'plugin' ) {
1148 if ( 'plugin' === $which ) {
1149 return get_user_option( 'mainwp_manage_plugin_view', MAINWP_VIEW_PER_PLUGIN_THEME );
1150 } else {
1151 return get_user_option( 'mainwp_manage_theme_view', MAINWP_VIEW_PER_PLUGIN_THEME );
1152 }
1153 }
1154
1155 /**
1156 * Method render_select_manage_view().
1157 *
1158 * Handle render view mode selection.
1159 *
1160 * @param string $which plugin|theme.
1161 *
1162 * @return void.
1163 */
1164 public static function render_select_manage_view( $which = 'plugin' ) {
1165
1166 $view_mode = static::get_manage_view( $which );
1167
1168 $hide_show_updates_per = apply_filters( 'mainwp_manage_plugin_theme_hide_show_updates_per', false, $which );
1169
1170 if ( ! $hide_show_updates_per ) {
1171 ?>
1172 <form method="post" action="" class="ui mini form right aligned">
1173 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
1174 <input type="hidden" name="whichview" value="<?php echo esc_attr( $which ); ?>" />
1175 <div class="inline field">
1176 <select class="ui dropdown" onchange="mainwp_siteview_onchange(this)" name="select_mainwp_options_plugintheme_view">
1177 <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>
1178 <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>
1179 </select>
1180 </div>
1181 </form>
1182 <?php
1183 }
1184 }
1185
1186
1187 /**
1188 * Method render_manage_per_site_table()
1189 *
1190 * Render Manage Plugins Table.
1191 *
1192 * @param array $sites Child Sites array.
1193 * @param array $pluginsSlug Plugins slug array.
1194 * @param array $sitePlugins Site plugins array.
1195 * @param array $pluginsMainWP MainWP plugins array.
1196 * @param array $muPlugins Must use plugins array.
1197 * @param array $pluginsName Plugin names array.
1198 * @param array $pluginsNameSites Plugin names with Sites array.
1199 * @param array $pluginsRealVersion Latest plugin release version.
1200 * @param array $roll_list rool items list.
1201 */
1202 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.
1203
1204 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1205 $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true );
1206 $trustedPlugins = json_decode( $userExtension->trusted_plugins, true );
1207 $is_demo = MainWP_Demo_Handle::is_demo_mode();
1208
1209 if ( ! is_array( $trustedPlugins ) ) {
1210 $trustedPlugins = array();
1211 }
1212
1213 $updateWebsites = array();
1214
1215 foreach ( $sites as $site_id => $info ) {
1216
1217 $plugin_upgrades = array();
1218 $website = MainWP_DB::instance()->get_website_by_id( $site_id, false, array( 'rollback_updates_data' ) );
1219
1220 if ( $website && ! $website->is_ignorePluginUpdates ) {
1221 $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
1222 $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' );
1223 $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array();
1224
1225 if ( is_array( $decodedPremiumUpgrades ) ) {
1226 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
1227 $premiumUpgrade['premium'] = true;
1228
1229 if ( 'plugin' === $premiumUpgrade['type'] ) {
1230 if ( ! is_array( $plugin_upgrades ) ) {
1231 $plugin_upgrades = array();
1232 }
1233
1234 $premiumUpgrade = array_filter( $premiumUpgrade );
1235
1236 if ( ! isset( $plugin_upgrades[ $crrSlug ] ) ) {
1237 $plugin_upgrades[ $crrSlug ] = array();
1238 }
1239 $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade );
1240 }
1241 }
1242 }
1243 $ignored_plugins = json_decode( $website->ignored_plugins, true );
1244 if ( is_array( $ignored_plugins ) ) {
1245 $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
1246 }
1247
1248 if ( is_array( $decodedIgnoredPlugins ) ) {
1249 $plugin_upgrades = array_diff_key( $plugin_upgrades, $decodedIgnoredPlugins );
1250 }
1251 }
1252 $updateWebsites[ $site_id ] = $plugin_upgrades;
1253 }
1254
1255 /**
1256 * Action: mainwp_before_plugins_table
1257 *
1258 * Fires before the Plugins table.
1259 *
1260 * @since 4.1
1261 */
1262 do_action( 'mainwp_before_plugins_table' );
1263 ?>
1264 <div class="ui secondary segment main-master-checkbox">
1265 <div class="ui stackable grid">
1266 <div class="one wide center aligned middle aligned column">
1267 <span class="trigger-all-accordion"><span class="trigger-handle-arrow"><i class="caret right icon"></i><i class="caret down icon"></i></span></span>
1268 </div>
1269 <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>
1270 <div class="five wide middle aligned column"><?php esc_html_e( 'Website', 'mainwp' ); ?></div>
1271 <div class="two wide center aligned middle aligned column"></div>
1272 <div class="two wide center aligned middle aligned column"></div>
1273 <div class="two wide center aligned middle aligned column"></div>
1274 <div class="two wide center aligned middle aligned column"><?php esc_html_e( 'Plugins', 'mainwp' ); ?></div>
1275 </div>
1276 </div>
1277
1278 <div class="mainwp-manage-plugins-wrapper main-child-checkbox">
1279 <?php foreach ( $sites as $site_id => $website ) : ?>
1280 <?php
1281 $site_name = $website['websitename'];
1282 $slugVersions = isset( $sitePlugins[ $site_id ] ) ? $sitePlugins[ $site_id ] : array();
1283
1284 if ( ! is_array( $slugVersions ) ) {
1285 $slugVersions = array();
1286 }
1287
1288 $item_id = $site_id;
1289 $count_plugins = count( $slugVersions );
1290
1291 // phpcs:disable WordPress.Security.EscapeOutput
1292 ?>
1293 <div class="ui accordion mainwp-manage-plugin-accordion mainwp-manage-plugin-item main-child-checkbox" id="<?php echo esc_html( $item_id ); ?>">
1294 <div class="title master-checkbox">
1295 <div class="ui stackable grid">
1296 <div class="one wide center aligned middle aligned column"><i class="dropdown icon dropdown-trigger"></i></div>
1297 <div class="one wide center aligned middle aligned column">
1298 <div class="ui checkbox master">
1299 <input type="checkbox"/>
1300 <label></label>
1301 </div>
1302 </div>
1303 <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>
1304 <div class="two wide center aligned middle aligned column"></div>
1305 <div class="two wide center aligned middle aligned column"></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 class="ui label"><i class="icon plug"></i> <?php echo intval( $count_plugins ); ?></div></div>
1309 </div>
1310 </div>
1311 <div class="content child-checkbox">
1312 <?php
1313 // phpcs:enable
1314 foreach ( $slugVersions as $slug_ver => $plugin ) :
1315
1316 $plugin_title = wp_strip_all_tags( $pluginsName[ $slug_ver ] );
1317
1318 $plugin_slug = $pluginsSlug[ $slug_ver ];
1319 $trusted = in_array( $plugin_slug, $trustedPlugins ) ? true : false;
1320 $child_plugin = ( isset( $pluginsMainWP[ $slug_ver ] ) && 'T' === $pluginsMainWP[ $slug_ver ] ) ? true : false;
1321
1322 $plugin_mu = false;
1323
1324 $plugin_version = $sitePlugins[ $site_id ][ $slug_ver ]['version'];
1325
1326 $plugin_upgrades = isset( $updateWebsites[ $site_id ] ) ? $updateWebsites[ $site_id ] : array();
1327 if ( ! is_array( $plugin_upgrades ) ) {
1328 $plugin_upgrades = array();
1329 }
1330
1331 $upgradeInfo = isset( $plugin_upgrades[ $plugin_slug ] ) ? $plugin_upgrades[ $plugin_slug ] : false;
1332
1333 $new_version = '';
1334 if ( ! empty( $upgradeInfo ) && isset( $upgradeInfo['update']['new_version'] ) ) {
1335 $new_version = $upgradeInfo['update']['new_version'];
1336 }
1337
1338 if ( isset( $sitePlugins[ $site_id ][ $slug_ver ] ) && ( empty( $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) || 1 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) ) {
1339 $actived = true;
1340 if ( isset( $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) && 1 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) {
1341 $plugin_status = '<span class="ui small green basic label">' . esc_html__( 'Active', 'mainwp' ) . '</span>';
1342 } elseif ( isset( $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) && 0 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) {
1343 $plugin_status = '<span class="ui small red basic label">' . esc_html__( 'Inactive', 'mainwp' ) . '</span>';
1344 $actived = false;
1345 } else {
1346 $plugin_status = '';
1347 }
1348
1349 if ( isset( $sitePlugins[ $site_id ][ $slug_ver ] ) && ( 1 === (int) $muPlugins[ $slug_ver ] ) ) {
1350 $plugin_mu = true;
1351 }
1352
1353 if ( $plugin_mu ) {
1354 $actived = true; // always.
1355 }
1356
1357 $item_id = $slug_ver . '_' . $site_id;
1358 $item_id = strtolower( $item_id );
1359 $item_id = preg_replace( '/[[:space:]]+/', '_', $item_id );
1360
1361 $plugin_directory = MainWP_Utility::get_dir_slug( $plugin_slug );
1362 $details_link = self_admin_url( 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $site_id ) . '&plugin=' . rawurlencode( $plugin_directory ) . '&section=changelog' );
1363 ?>
1364 <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 ); ?>">
1365 <div class="one wide center aligned middle aligned column"></div>
1366 <div class="one wide center aligned middle aligned column">
1367 <div class="ui checkbox child <?php echo 'mainwp-child' === $plugin_directory ? 'disabled' : ''; ?>">
1368 <input type="checkbox"
1369 <?php
1370 echo 'mainwp-child' === $plugin_directory ? 'disabled="disabled"' : 'class="mainwp-selected-plugin-site"';
1371 ?>
1372 ><label></label>
1373 </div>
1374 </div>
1375 <?php // phpcs:disable WordPress.Security.EscapeOutput ?>
1376 <div class="one wide center aligned middle aligned column"><?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); ?></div>
1377 <?php // phpcs:enable ?>
1378 <div class="three wide middle aligned column"><a class="open-plugin-details-modal" href="<?php echo esc_url( $details_link ); ?>" target="_blank" ><strong><?php echo esc_html( $plugin_title ); ?></strong></a></div>
1379 <div class="one wide center aligned middle aligned column"><?php echo $plugin_status; //phpcs:ignore -- escaped. ?></div>
1380 <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>
1381 <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>
1382 <div class="two wide center aligned middle aligned column current-version">
1383 <?php echo esc_html( $plugin_version ); ?>
1384 <?php if ( ! empty( $new_version ) ) : ?>
1385 &rarr;
1386 <?php
1387 if ( ! empty( $roll_list[ $site_id ][ $plugin_slug ][ $new_version ] ) ) {
1388 echo MainWP_Updates_Helper::get_roll_msg( $roll_list[ $site_id ][ $plugin_slug ][ $new_version ], true, 'notice' ); //phpcs:ignore -- NOSONAR -- ok.
1389 }
1390 echo esc_html( $new_version );
1391 ?>
1392 <?php endif; ?>
1393 </div>
1394 <div class="two wide right aligned middle aligned column update-column" updated="0">
1395 <?php if ( ! empty( $upgradeInfo ) && MainWP_Updates::user_can_update_plugins() ) : ?>
1396 <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>
1397 <?php endif; ?>
1398 </div>
1399 <div class="two wide center aligned middle aligned column column-actions">
1400 <?php if ( ! $child_plugin ) : ?>
1401 <?php if ( $actived ) { ?>
1402 <?php if ( ! $plugin_mu && mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) { ?>
1403 <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>
1404 <?php } ?>
1405 <?php } else { ?>
1406 <div class="ui mini fluid buttons">
1407 <?php if ( mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) { ?>
1408 <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>
1409 <?php } ?>
1410 <?php if ( mainwp_current_user_have_right( 'dashboard', 'delete_plugins' ) ) { ?>
1411 <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>
1412 <?php } ?>
1413 </div>
1414 <?php } ?>
1415 <?php endif; ?>
1416 </div>
1417 </div>
1418 <?php
1419
1420 }
1421 endforeach;
1422 ?>
1423 </div>
1424 </div>
1425 <?php endforeach; ?>
1426 </div>
1427
1428 <script type="text/javascript">
1429 jQuery( '.mainwp-manage-plugin-accordion' ).accordion( {
1430 "selector": {
1431 "trigger" : '.dropdown-trigger',
1432 }
1433 } );
1434
1435 jQuery( '.trigger-all-accordion' ).on( 'click', function() { // not use document here.
1436 if ( jQuery( this ).hasClass( 'active' ) ) {
1437 jQuery( this ).removeClass( 'active' );
1438 jQuery( '.mainwp-manage-plugins-wrapper .ui.accordion div.title' ).each( function( i ) {
1439 if ( jQuery( this ).hasClass( 'active' ) ) {
1440 jQuery( this ).find('.dropdown-trigger').trigger( 'click' );
1441 }
1442 } );
1443 } else {
1444 jQuery( this ).addClass( 'active' );
1445 jQuery( '.mainwp-manage-plugins-wrapper .ui.accordion div.title' ).each( function( i ) {
1446 if ( !jQuery( this ).hasClass( 'active' ) ) {
1447 jQuery( this ).find('.dropdown-trigger').trigger( 'click' );
1448 }
1449 } );
1450 }
1451 return false;
1452 } );
1453
1454 jQuery(function($) {
1455 mainwp_master_checkbox_init($);
1456 mainwp_get_icon_start();
1457 mainwp_show_hide_install_to_selected_sites( 'plugin' );
1458 } );
1459
1460 </script>
1461
1462 <?php
1463 /**
1464 * Action: mainwp_after_plugins_table
1465 *
1466 * Fires after the Plugins table.
1467 *
1468 * @since 4.1
1469 */
1470 do_action( 'mainwp_after_plugins_table' );
1471 }
1472
1473
1474
1475 /**
1476 * Method render_manage_table()
1477 *
1478 * Render Manage Plugins Table.
1479 *
1480 * @param array $sites Child Sites array.
1481 * @param array $pluginsSlug Plugins slug array.
1482 * @param array $sitePlugins Site plugins array.
1483 * @param array $pluginsMainWP MainWP plugins array.
1484 * @param array $muPlugins Must use plugins array.
1485 * @param array $pluginsName Plugin names array.
1486 * @param array $pluginsNameSites Plugin names with Sites array.
1487 * @param array $pluginsRealVersion Latest plugin release version.
1488 * @param array $roll_list rool items list.
1489 */
1490 public static function render_manage_table( $sites, $pluginsSlug, $sitePlugins, $pluginsMainWP, $muPlugins, $pluginsName, $pluginsNameSites, $pluginsRealVersion, $roll_list = array() ) { //phpcs:ignore -- NOSONAR - complex method.
1491
1492 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1493 $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true );
1494 $trustedPlugins = json_decode( $userExtension->trusted_plugins, true );
1495 $is_demo = MainWP_Demo_Handle::is_demo_mode();
1496
1497 if ( ! is_array( $trustedPlugins ) ) {
1498 $trustedPlugins = array();
1499 }
1500
1501 $updateWebsites = array();
1502
1503 foreach ( $sites as $site_id => $info ) {
1504
1505 $plugin_upgrades = array();
1506 $website = MainWP_DB::instance()->get_website_by_id( $site_id );
1507 if ( $website && ! $website->is_ignorePluginUpdates ) {
1508 $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
1509 if ( ! is_array( $plugin_upgrades ) ) {
1510 $plugin_upgrades = array();
1511 }
1512 $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' );
1513 $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array();
1514 if ( is_array( $decodedPremiumUpgrades ) ) {
1515 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
1516 $premiumUpgrade['premium'] = true;
1517 if ( 'plugin' === $premiumUpgrade['type'] ) {
1518 $premiumUpgrade = array_filter( $premiumUpgrade );
1519
1520 if ( ! isset( $plugin_upgrades[ $crrSlug ] ) ) {
1521 $plugin_upgrades[ $crrSlug ] = array();
1522 }
1523 $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade );
1524 }
1525 }
1526 }
1527 $ignored_plugins = json_decode( $website->ignored_plugins, true );
1528 if ( is_array( $ignored_plugins ) ) {
1529 $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
1530 }
1531
1532 if ( is_array( $decodedIgnoredPlugins ) ) {
1533 $plugin_upgrades = array_diff_key( $plugin_upgrades, $decodedIgnoredPlugins );
1534 }
1535 }
1536 $updateWebsites[ $site_id ] = $plugin_upgrades;
1537 }
1538
1539 /**
1540 * Action: mainwp_before_plugins_table
1541 *
1542 * Fires before the Plugins table.
1543 *
1544 * @since 4.1
1545 */
1546 do_action( 'mainwp_before_plugins_table' );
1547 ?>
1548 <div class="ui secondary segment main-master-checkbox">
1549 <div class="ui stackable grid">
1550 <div class="one wide center aligned middle aligned column">
1551 <span class="trigger-all-accordion"><span class="trigger-handle-arrow"><i class="caret right icon"></i><i class="caret down icon"></i></span></span>
1552 </div>
1553 <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>
1554 <div class="one wide center aligned middle aligned column"></div>
1555 <div class="five wide middle aligned column"><?php esc_html_e( 'Plugin', 'mainwp' ); ?></div>
1556 <div class="two wide center aligned middle aligned column"></div>
1557 <div class="two wide center aligned middle aligned column"><?php esc_html_e( 'Latest Version', 'mainwp' ); ?></div>
1558 <div class="two wide center aligned middle aligned column"></div>
1559 <div class="two wide center aligned middle aligned column"><?php esc_html_e( 'Websites', 'mainwp' ); ?></div>
1560 </div>
1561 </div>
1562
1563 <div class="mainwp-manage-plugins-wrapper main-child-checkbox">
1564 <?php foreach ( $pluginsNameSites as $plugin_title => $pluginSites ) : ?>
1565 <?php
1566 $slugVersions = current( $pluginSites );
1567 $slug_ver_first = $slugVersions[0]; // get the first one [slug]_[version] to get plugin [slug].
1568 $plugin_slug_first = $pluginsSlug[ $slug_ver_first ];
1569 $plugin_directory = MainWP_Utility::get_dir_slug( $plugin_slug_first );
1570
1571 $plugin_status = '';
1572
1573 $item_id = strtolower( $plugin_title );
1574 $item_id = preg_replace( '/[[:space:]]+/', '_', $item_id );
1575
1576 $count_sites = count( $pluginSites );
1577
1578 reset( $pluginSites );
1579 $first_siteid = key( $pluginSites );
1580
1581 $details_link = self_admin_url( 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $first_siteid ) . '&plugin=' . rawurlencode( $plugin_directory ) . '&section=changelog' );
1582 $lastest_version = '';
1583 // phpcs:disable WordPress.Security.EscapeOutput
1584 ?>
1585 <div class="ui accordion mainwp-manage-plugin-accordion mainwp-manage-plugin-item main-child-checkbox" id="<?php echo esc_html( $item_id ); ?>">
1586 <div class="title master-checkbox">
1587 <div class="ui grid">
1588 <div class="one wide center aligned middle aligned column"><i class="dropdown icon dropdown-trigger"></i></div>
1589 <div class="one wide center aligned middle aligned column">
1590 <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>
1591 </div>
1592 <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>
1593 <div class="five wide middle aligned column"><a class="open-plugin-details-modal" href="<?php echo esc_url( $details_link ); ?>" target="_blank" ><strong><?php echo esc_html( $plugin_title ); ?></strong></a></div>
1594 <div class="two wide center aligned middle aligned column"></div>
1595 <div class="two wide center aligned middle aligned column lastest-version-info"></div>
1596 <div class="two wide center aligned middle aligned column"></div>
1597 <div class="two wide center aligned middle aligned column"><div class="ui label"><i class="icon wordpress"></i> <?php echo intval( $count_sites ); // phpcs:ignore -- Prevent modify WP icon. ?></div></div>
1598 </div>
1599 </div>
1600 <div class="content child-checkbox">
1601 <?php
1602 // phpcs:enable
1603 foreach ( $pluginSites as $site_id => $slugVersions ) :
1604 $site_name = $sites[ $site_id ]['websitename'];
1605
1606 foreach ( $slugVersions as $slug_ver ) :
1607
1608 $plugin_slug = $pluginsSlug[ $slug_ver ];
1609 $trusted = in_array( $plugin_slug, $trustedPlugins ) ? true : false;
1610 $child_plugin = ( isset( $pluginsMainWP[ $slug_ver ] ) && 'T' === $pluginsMainWP[ $slug_ver ] ) ? true : false;
1611
1612 $plugin_mu = false;
1613
1614 $plugin_version = $sitePlugins[ $site_id ][ $slug_ver ]['version'];
1615
1616 $plugin_upgrades = isset( $updateWebsites[ $site_id ] ) ? $updateWebsites[ $site_id ] : array();
1617 if ( ! is_array( $plugin_upgrades ) ) {
1618 $plugin_upgrades = array();
1619 }
1620
1621 $upgradeInfo = isset( $plugin_upgrades[ $plugin_slug ] ) ? $plugin_upgrades[ $plugin_slug ] : false;
1622
1623 $new_version = '';
1624 if ( ! empty( $upgradeInfo ) && isset( $upgradeInfo['update']['new_version'] ) ) {
1625 $new_version = $upgradeInfo['update']['new_version'];
1626 }
1627
1628 if ( '' === $lastest_version || version_compare( $plugin_version, $lastest_version, '>' ) ) {
1629 $lastest_version = $plugin_version;
1630 }
1631
1632 if ( '' !== $new_version && version_compare( $new_version, $lastest_version, '>' ) ) {
1633 $lastest_version = $new_version;
1634 }
1635
1636 if ( isset( $sitePlugins[ $site_id ][ $slug_ver ] ) && ( 0 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] || 1 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) ) {
1637 $actived = true;
1638 if ( isset( $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) && 1 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) {
1639 $plugin_status = '<span class="ui small green basic label">' . esc_html__( 'Active', 'mainwp' ) . '</span>';
1640 } elseif ( isset( $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) && 0 === (int) $sitePlugins[ $site_id ][ $slug_ver ]['active'] ) {
1641 $plugin_status = '<span class="ui small red basic label">' . esc_html__( 'Inactive', 'mainwp' ) . '</span>';
1642 $actived = false;
1643 } else {
1644 $plugin_status = '';
1645 }
1646
1647 if ( isset( $sitePlugins[ $site_id ][ $slug_ver ] ) && ( 1 === (int) $muPlugins[ $slug_ver ] ) ) {
1648 $plugin_mu = true;
1649 }
1650 if ( $plugin_mu ) {
1651 $actived = true; // always.
1652 }
1653 $item_id = $slug_ver . '_' . $site_id;
1654 $item_id = strtolower( $item_id );
1655 $item_id = preg_replace( '/[[:space:]]+/', '_', $item_id );
1656
1657 ?>
1658 <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 ); ?>">
1659 <div class="one wide center aligned middle aligned column"></div>
1660 <div class="one wide center aligned middle aligned column">
1661 <?php if ( $child_plugin ) { ?>
1662 <div class="ui disabled checkbox"><input type="checkbox" disabled="disabled"><label></label></div>
1663 <?php } else { ?>
1664 <div class="ui checkbox child">
1665 <input type="checkbox" class="mainwp-selected-plugin-site" />
1666 <label></label>
1667 </div>
1668 <?php
1669 }
1670 ?>
1671 </div>
1672 <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>
1673 <div class="one wide middle aligned column"></div>
1674 <div class="one wide center aligned middle aligned column"><?php echo $plugin_status; //phpcs:ignore -- escaped. ?></div>
1675 <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>
1676
1677
1678 <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>
1679
1680 <div class="two wide center aligned middle aligned column current-version">
1681 <?php echo esc_html( $plugin_version ); ?>
1682 <?php if ( ! empty( $new_version ) ) : ?>
1683 &rarr;
1684 <?php
1685 if ( ! empty( $roll_list[ $site_id ][ $plugin_slug ][ $new_version ] ) ) {
1686 echo MainWP_Updates_Helper::get_roll_msg( $roll_list[ $site_id ][ $plugin_slug ][ $new_version ], true, 'notice' ); //phpcs:ignore -- NOSONAR -- ok.
1687 }
1688 echo esc_html( $new_version );
1689 ?>
1690 <?php endif; ?>
1691 </div>
1692 <div class="two wide right aligned middle aligned column update-column" updated="0">
1693 <?php if ( ! empty( $upgradeInfo ) && MainWP_Updates::user_can_update_plugins() ) : ?>
1694 <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>
1695 <?php endif; ?>
1696 </div>
1697 <div class="two wide center aligned middle aligned column column-actions">
1698 <?php if ( ! $child_plugin ) : ?>
1699 <?php if ( $actived ) { ?>
1700 <?php if ( ! $plugin_mu && mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) { ?>
1701 <a href="#" class="mainwp-manage-plugin-deactivate ui mini fluid button <?php echo $is_demo ? 'disabled' : ''; ?>"><?php esc_html_e( 'Deactivate', 'mainwp' ); ?></a>
1702 <?php } ?>
1703 <?php } else { ?>
1704 <div class="ui mini fluid buttons">
1705 <?php if ( mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) { ?>
1706 <a href="#" class="mainwp-manage-plugin-activate ui green button <?php echo $is_demo ? 'disabled' : ''; ?>" ><?php esc_html_e( 'Activate', 'mainwp' ); ?></a>
1707 <?php } ?>
1708 <?php if ( mainwp_current_user_have_right( 'dashboard', 'delete_plugins' ) ) { ?>
1709 <a href="#" class="mainwp-manage-plugin-delete ui button <?php echo $is_demo ? 'disabled' : ''; ?>" ><?php esc_html_e( 'Delete', 'mainwp' ); ?></a>
1710 <?php } ?>
1711 </div>
1712 <?php } ?>
1713 <?php endif; ?>
1714 </div>
1715 </div>
1716 <?php
1717
1718 }
1719 endforeach;
1720 ?>
1721 <span style="display:none" class="lastest-version-hidden" lastest-version="<?php echo esc_html( $lastest_version ); ?>"></span>
1722 <?php
1723 endforeach;
1724 ?>
1725 </div>
1726 </div>
1727 <?php endforeach; ?>
1728 </div>
1729
1730 <script type="text/javascript">
1731 jQuery( '.mainwp-manage-plugin-accordion' ).accordion( {
1732 "selector": {
1733 "trigger" : '.dropdown-trigger',
1734 }
1735 } );
1736
1737 jQuery( '.trigger-all-accordion' ).on( 'click', function() { // not use document here.
1738 if ( jQuery( this ).hasClass( 'active' ) ) {
1739 jQuery( this ).removeClass( 'active' );
1740 jQuery( '.mainwp-manage-plugins-wrapper .ui.accordion div.title' ).each( function( i ) {
1741 if ( jQuery( this ).hasClass( 'active' ) ) {
1742 jQuery( this ).find('.dropdown-trigger').trigger( 'click' );
1743 }
1744 } );
1745 } else {
1746 jQuery( this ).addClass( 'active' );
1747 jQuery( '.mainwp-manage-plugins-wrapper .ui.accordion div.title' ).each( function( i ) {
1748 if ( !jQuery( this ).hasClass( 'active' ) ) {
1749 jQuery( this ).find('.dropdown-trigger').trigger( 'click' );
1750 }
1751 } );
1752 }
1753 return false;
1754 } );
1755
1756
1757
1758 jQuery(function($) {
1759 $( '.lastest-version-hidden' ).each(function(){
1760 $(this).closest('.mainwp-manage-plugin-item').find('.lastest-version-info').html( $(this).attr('lastest-version') );
1761 });
1762 mainwp_master_checkbox_init($);
1763 mainwp_get_icon_start();
1764 mainwp_show_hide_install_to_selected_sites( 'plugin' );
1765 } );
1766
1767 </script>
1768
1769 <?php
1770 /**
1771 * Action: mainwp_after_plugins_table
1772 *
1773 * Fires after the Plugins table.
1774 *
1775 * @since 4.1
1776 */
1777 do_action( 'mainwp_after_plugins_table' );
1778 }
1779
1780
1781 /** Render Install Subpage. */
1782 public static function render_install() {
1783 static::render_header( 'Install' );
1784 static::render_plugins_table();
1785 static::render_footer( 'Install' );
1786 }
1787
1788
1789 /**
1790 * Render Install plugins Table.
1791 *
1792 * @uses \MainWP\Dashboard\MainWP_UI::render_modal_install_plugin_theme()
1793 *
1794 * @uses \MainWP\Dashboard\MainWP_Install_Bulk::render_upload()
1795 */
1796 public static function render_plugins_table() {
1797
1798 /**
1799 * Tab array.
1800 *
1801 * @global object
1802 */
1803 global $tab;
1804
1805 if ( ! mainwp_current_user_have_right( 'dashboard', 'install_plugins' ) ) {
1806 mainwp_do_not_have_permissions( esc_html__( 'install plugins', 'mainwp' ) );
1807 return;
1808 }
1809 ?>
1810
1811 <div class="ui alt segment" id="mainwp-install-plugins">
1812 <div class="mainwp-main-content">
1813 <div class="mainwp-actions-bar">
1814 <div class="ui stackable grid">
1815 <div class="ui two column row">
1816 <div class="column">
1817 <div id="mainwp-search-plugins-form" class="ui fluid search focus">
1818 <div class="ui icon fluid input">
1819 <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 ?>">
1820 <i class="search icon"></i>
1821 </div>
1822 <div class="results"></div>
1823 </div>
1824 <script type="text/javascript">
1825 jQuery( document ).ready(function () {
1826 jQuery( '#mainwp-search-plugins-form-field' ).on( 'keypress', function(e) {
1827 let search = jQuery( '#mainwp-search-plugins-form-field' ).val();
1828 let sel_ids = jQuery( '#plugin_install_selected_sites' ).val();
1829 if ( '' != sel_ids )
1830 sel_ids = '&selected_sites=' + sel_ids;
1831 let origin = '<?php echo esc_url( get_admin_url() ); ?>';
1832 if ( 13 === e.which ) {
1833 location.href = origin + 'admin.php?page=PluginsInstall&tab=search&s=' + encodeURIComponent(search) + sel_ids;
1834 }
1835 } );
1836 } );
1837 </script>
1838 <?php
1839 /**
1840 * Install Plugins actions bar (left)
1841 *
1842 * Fires at the left side of the actions bar on the Install Plugins screen, after the Search bar.
1843 *
1844 * @since 4.0
1845 */
1846 do_action( 'mainwp_install_plugins_actions_bar_left' );
1847 ?>
1848 </div>
1849 <div class="right aligned column">
1850 <div class="ui buttons">
1851 <a href="#" id="MainWPInstallBulkNavSearch" class="ui button" ><?php esc_html_e( 'Install from WordPress.org', 'mainwp' ); ?></a>
1852 <div class="or"></div>
1853 <a href="#" id="MainWPInstallBulkNavUpload" class="ui button" ><?php esc_html_e( 'Upload .zip file', 'mainwp' ); ?></a>
1854 </div>
1855 <?php
1856 /**
1857 * Install Plugins actions bar (right)
1858 *
1859 * Fires at the left side of the actions bar on the Install Plugins screen, after the Nav buttons.
1860 *
1861 * @since 4.0
1862 */
1863 do_action( 'mainwp_install_plugins_actions_bar_right' );
1864 ?>
1865 </div>
1866 </div>
1867 </div>
1868 </div>
1869 <div class="ui segment">
1870 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-install-plugins-info-message' ) ) : ?>
1871 <div class="ui info message">
1872 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-install-plugins-info-message"></i>
1873 <?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>' ); ?>
1874 </div>
1875 <?php endif; ?>
1876 <div id="mainwp-message-zone" class="ui message" style="display:none;"></div>
1877 <div class="mainwp-upload-plugin" style="display:none;">
1878 <?php MainWP_Install_Bulk::render_upload( 'plugin' ); ?>
1879 </div>
1880 <div class="mainwp-browse-plugins">
1881 <form id="plugin-filter" method="post">
1882 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
1883 <?php static::$pluginsTable->display(); ?>
1884 </form>
1885 </div>
1886 <?php
1887 MainWP_UI::render_modal_install_plugin_theme();
1888 MainWP_Updates::render_plugin_details_modal();
1889 ?>
1890 </div>
1891 </div>
1892 <?php
1893 $selected_sites = array();
1894
1895 if ( isset( $_GET['selected_sites'] ) && ! empty( $_GET['selected_sites'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1896 $selected_sites = explode( '-', sanitize_text_field( wp_unslash( $_GET['selected_sites'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitize ok.
1897 $selected_sites = array_map( 'intval', $selected_sites );
1898 $selected_sites = array_filter( $selected_sites );
1899 }
1900 ?>
1901 <div class="mainwp-side-content mainwp-no-padding">
1902 <?php do_action( 'mainwp_manage_plugins_sidebar_top' ); ?>
1903 <div class="mainwp-select-sites ui accordion mainwp-sidebar-accordion">
1904 <?php do_action( 'mainwp_manage_plugins_before_select_sites' ); ?>
1905 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Sites', 'mainwp' ); ?></div>
1906 <div class="content active">
1907 <?php
1908 $sel_params = array(
1909 'class' => 'mainwp_select_sites_box_left',
1910 'selected_sites' => $selected_sites,
1911 'show_client' => true,
1912 );
1913 MainWP_UI_Select_Sites::select_sites_box( $sel_params );
1914 ?>
1915 </div>
1916 <?php do_action( 'mainwp_manage_plugins_after_select_sites' ); ?>
1917 </div>
1918 <input type="hidden" id="plugin_install_selected_sites" name="plugin_install_selected_sites" value="<?php echo esc_html( implode( '-', $selected_sites ) ); ?>" />
1919 <div class="ui fitted divider"></div>
1920 <div class="mainwp-search-options ui accordion mainwp-sidebar-accordion">
1921 <?php do_action( 'mainwp_manage_plugins_before_search_options' ); ?>
1922 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Installation Options', 'mainwp' ); ?></div>
1923 <div class="content active">
1924 <div class="ui form">
1925 <div class="field">
1926 <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="">
1927 <input type="checkbox" value="1" checked="checked" id="chk_activate_plugin" />
1928 <label for="chk_activate_plugin"><?php esc_html_e( 'Activate after installation', 'mainwp' ); ?></label>
1929 </div>
1930 </div>
1931 <div class="field">
1932 <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="">
1933 <input type="checkbox" value="2" checked="checked" id="chk_overwrite" />
1934 <label for="chk_overwrite"><?php esc_html_e( 'Overwrite existing version', 'mainwp' ); ?></label>
1935 </div>
1936 </div>
1937 </div>
1938 </div>
1939 <?php do_action( 'mainwp_manage_plugins_after_search_options' ); ?>
1940 </div>
1941 <div class="ui fitted divider"></div>
1942 <div class="mainwp-search-submit">
1943 <?php do_action( 'mainwp_manage_plugins_before_submit_button' ); ?>
1944 <?php
1945 /**
1946 * Disables plugin installation
1947 *
1948 * Filters whether file modifications are allowed on the Dashboard site. If not, installation process will be disabled too.
1949 *
1950 * @since 4.1
1951 */
1952 $allow_install = apply_filters( 'file_mod_allowed', true, 'mainwp_install_plugin' );
1953 if ( $allow_install ) {
1954 $is_demo = MainWP_Demo_Handle::is_demo_mode();
1955 if ( $is_demo ) {
1956 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' ) . '">' );
1957 } else {
1958 ?>
1959 <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">
1960 <?php
1961 }
1962 }
1963 ?>
1964 <?php do_action( 'mainwp_manage_plugins_before_submit_button' ); ?>
1965 </div>
1966 <?php do_action( 'mainwp_manage_plugins_sidebar_bottom', 'install' ); ?>
1967 </div>
1968 <div class="ui clearing hidden divider"></div>
1969 </div>
1970 <?php
1971 }
1972
1973 /**
1974 * Render Autoupdate SubPage.
1975 *
1976 * @uses \MainWP\Dashboard\MainWP_UI::render_modal_edit_notes()
1977 */
1978 public static function render_auto_update() { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
1979
1980 $cachedAUSearch = isset( $_SESSION['MainWP_PluginsActiveStatus'] ) ? $_SESSION['MainWP_PluginsActiveStatus'] : null; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized --- ok.
1981
1982 static::render_header( 'AutoUpdate' );
1983
1984 if ( ! mainwp_current_user_have_right( 'dashboard', 'trust_untrust_updates' ) ) {
1985 mainwp_do_not_have_permissions( esc_html__( 'trust/untrust updates', 'mainwp' ) );
1986 } else {
1987 $snPluginAutomaticDailyUpdate = get_option( 'mainwp_pluginAutomaticDailyUpdate' );
1988
1989 if ( false === $snPluginAutomaticDailyUpdate ) {
1990 $snPluginAutomaticDailyUpdate = get_option( 'mainwp_automaticDailyUpdate' );
1991 update_option( 'mainwp_pluginAutomaticDailyUpdate', $snPluginAutomaticDailyUpdate );
1992 }
1993
1994 ?>
1995 <div class="ui alt segment" id="mainwp-plugin-auto-updates">
1996 <div class="mainwp-main-content">
1997 <div class="mainwp-actions-bar">
1998 <div class="ui mini form stackable grid">
1999 <div class="ui two column row">
2000 <div class="left aligned column">
2001 <select id="mainwp-bulk-actions" name="bulk_action" class="ui mini selection dropdown">
2002 <option class="item" value=""><?php esc_html_e( 'Bulk Actions', 'mainwp' ); ?></option>
2003 <option class="item" value="trust"><?php esc_html_e( 'Trust', 'mainwp' ); ?></option>
2004 <option class="item" value="untrust"><?php esc_html_e( 'Untrust', 'mainwp' ); ?></option>
2005 <?php
2006 /**
2007 * Action: mainwp_plugins_auto_updates_bulk_action
2008 *
2009 * Adds new action to the bulk actions menu on Plugins Auto Updates.
2010 *
2011 * @since 4.1
2012 */
2013 do_action( 'mainwp_plugins_auto_updates_bulk_action' );
2014 ?>
2015 </select>
2016 <input type="button" name="" id="mainwp-bulk-trust-plugins-action-apply" class="ui mini basic button" value="<?php esc_attr_e( 'Apply', 'mainwp' ); ?>"/>
2017 </div>
2018 <div class="right aligned column"></div>
2019 </div>
2020 </div>
2021 </div>
2022
2023 <?php if ( isset( $_GET['message'] ) && 'saved' === $_GET['message'] ) : // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>
2024 <div class="ui message green"><?php esc_html_e( 'Settings have been saved.', 'mainwp' ); ?></div>
2025 <?php endif; ?>
2026 <div id="mainwp-message-zone" class="ui message" style="display:none"></div>
2027 <div id="mainwp-auto-updates-plugins-content" class="ui segment">
2028 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-disable-auto-updates-info-message' ) ) : ?>
2029 <div class="ui info message">
2030 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-disable-auto-updates-info-message"></i>
2031 <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>
2032 </div>
2033 <?php endif; ?>
2034 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-plugins-auto-updates-info-message' ) ) : ?>
2035 <div class="ui info message">
2036 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-plugins-auto-updates-info-message"></i>
2037 <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>
2038 <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>
2039 <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>
2040 </div>
2041 <?php endif; ?>
2042 <div class="ui inverted dimmer">
2043 <div class="ui text loader"><?php esc_html_e( 'Loading plugins', 'mainwp' ); ?></div>
2044 </div>
2045 <div id="mainwp-auto-updates-plugins-table-wrapper">
2046 <?php
2047 if ( isset( $_SESSION['MainWP_PluginsActive'] ) ) {
2048 static::render_all_active_table( $_SESSION['MainWP_PluginsActive'] ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2049 }
2050 ?>
2051 </div>
2052 </div>
2053 </div>
2054 <div class="mainwp-side-content mainwp-no-padding">
2055 <?php do_action( 'mainwp_manage_plugins_sidebar_top' ); ?>
2056 <div class="mainwp-search-options ui accordion mainwp-sidebar-accordion">
2057 <?php do_action( 'mainwp_manage_plugins_before_search_options' ); ?>
2058 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Plugin Status to Search', 'mainwp' ); ?></div>
2059 <div class="content active">
2060 <div class="ui mini form">
2061 <div class="field">
2062 <select class="ui fluid dropdown" id="mainwp_au_plugin_status">
2063 <option value="all" <?php echo ( null !== $cachedAUSearch && 'all' === $cachedAUSearch['plugin_status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Active and Inactive', 'mainwp' ); ?></option>
2064 <option value="active" <?php echo ( null !== $cachedAUSearch && 'active' === $cachedAUSearch['plugin_status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Active', 'mainwp' ); ?></option>
2065 <option value="inactive" <?php echo ( null !== $cachedAUSearch && 'inactive' === $cachedAUSearch['plugin_status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Inactive', 'mainwp' ); ?></option>
2066 </select>
2067 </div>
2068 </div>
2069 </div>
2070 <?php do_action( 'mainwp_manage_plugins_after_search_options' ); ?>
2071 </div>
2072 <div class="ui fitted divider"></div>
2073 <div class="mainwp-search-options ui accordion mainwp-sidebar-accordion">
2074 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Search Options', 'mainwp' ); ?></div>
2075 <div class="content active">
2076 <div class="ui mini form">
2077 <div class="field">
2078 <select class="ui fluid dropdown" id="mainwp_au_plugin_trust_status">
2079 <option value="all" <?php echo ( null !== $cachedAUSearch && 'all' === $cachedAUSearch['status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Trusted, Not trusted and Ignored', 'mainwp' ); ?></option>
2080 <option value="trust" <?php echo ( null !== $cachedAUSearch && 'trust' === $cachedAUSearch['status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Trusted', 'mainwp' ); ?></option>
2081 <option value="untrust" <?php echo ( null !== $cachedAUSearch && 'untrust' === $cachedAUSearch['status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Not trusted', 'mainwp' ); ?></option>
2082 <option value="ignored" <?php echo ( null !== $cachedAUSearch && 'ignored' === $cachedAUSearch['status'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Ignored', 'mainwp' ); ?></option>
2083 </select>
2084 </div>
2085 <div class="field">
2086 <div class="ui input fluid">
2087 <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'] ) : ''; ?>">
2088 </div>
2089 </div>
2090 </div>
2091 </div>
2092 </div>
2093 <div class="ui fitted divider"></div>
2094 <div class="mainwp-search-submit">
2095 <?php do_action( 'mainwp_manage_plugins_before_submit_button' ); ?>
2096 <a href="#" class="ui green big fluid button" id="mainwp_show_all_active_plugins"><?php esc_html_e( 'Show Plugins', 'mainwp' ); ?></a>
2097 <?php do_action( 'mainwp_manage_plugins_after_submit_button' ); ?>
2098 </div>
2099 <?php do_action( 'mainwp_manage_plugins_sidebar_bottom' ); ?>
2100 </div>
2101 </div>
2102 <?php
2103 MainWP_UI::render_modal_edit_notes( 'plugin' );
2104 }
2105 static::render_footer( 'AutoUpdate' );
2106 }
2107
2108 /**
2109 * Method render_all_active_table()
2110 *
2111 * Render all active Plugins table.
2112 *
2113 * @param null $output function output.
2114 *
2115 * @return void
2116 *
2117 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
2118 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
2119 * @uses \MainWP\Dashboard\MainWP_DB::query()
2120 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
2121 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
2122 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
2123 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::get_class_name()
2124 * @uses \MainWP\Dashboard\MainWP_Utility::map_site()
2125 * @uses \MainWP\Dashboard\MainWP_Utility::get_nice_url()
2126 */
2127 public static function render_all_active_table( $output = null ) { // phpcs:ignore -- NOSONAR - complex.
2128 $keyword = null;
2129 $search_status = 'all';
2130
2131 $data_fields = MainWP_System_Utility::get_default_map_site_fields();
2132
2133 if ( null === $output ) {
2134 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2135 $keyword = isset( $_POST['keyword'] ) && ! empty( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : null;
2136 $search_status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : 'all';
2137 $search_plugin_status = isset( $_POST['plugin_status'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_status'] ) ) : 'all';
2138 // phpcs:enable
2139
2140 $output = new \stdClass();
2141 $output->errors = array();
2142 $output->plugins = array();
2143 $output->plugins_installed = array(); // to fix.
2144
2145 if ( 1 === (int) get_option( 'mainwp_optimize', 1 ) || MainWP_Demo_Handle::is_demo_mode() ) {
2146 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
2147 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2148 $allPlugins = json_decode( $website->plugins, true );
2149 $_count = count( $allPlugins );
2150 for ( $i = 0; $i < $_count; $i++ ) {
2151 $plugin = $allPlugins[ $i ];
2152
2153 $all = true;
2154 if ( 'all' !== $search_plugin_status ) {
2155 $all = false;
2156 }
2157
2158 if ( ! $all && ( ( 1 === (int) $plugin['active'] && 'active' !== $search_plugin_status ) || ( 1 !== (int) $plugin['active'] && 'inactive' !== $search_plugin_status ) ) ) {
2159 continue;
2160 }
2161
2162 if ( ! empty( $keyword ) ) {
2163 $keyword = trim( $keyword );
2164 $multi_kws = explode( ',', $keyword );
2165 $multi_kws = array_filter( array_map( 'trim', $multi_kws ) );
2166 if ( ! MainWP_Utility::multi_find_keywords( $plugin['name'], $multi_kws ) ) {
2167 continue;
2168 }
2169 }
2170 $plugin['websiteid'] = $website->id;
2171 $plugin['websiteurl'] = $website->url;
2172 $output->plugins[] = $plugin;
2173 }
2174 }
2175 MainWP_DB::free_result( $websites );
2176 } else {
2177 $dbwebsites = array();
2178 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
2179 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2180 if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) {
2181 continue;
2182 }
2183
2184 $dbwebsites[ $website->id ] = MainWP_Utility::map_site(
2185 $website,
2186 $data_fields
2187 );
2188 }
2189 MainWP_DB::free_result( $websites );
2190
2191 $post_data = array( 'keyword' => $keyword );
2192
2193 if ( 'active' === $search_plugin_status || 'inactive' === $search_plugin_status ) {
2194 $post_data['status'] = $search_plugin_status;
2195 $post_data['filter'] = true;
2196 } else {
2197 $post_data['status'] = '';
2198 $post_data['filter'] = false;
2199 }
2200 $output->status = $search_plugin_status;
2201 MainWP_Connect::fetch_urls_authed( $dbwebsites, 'get_all_plugins', $post_data, array( MainWP_Plugins_Handler::get_class_name(), 'plugins_search_handler' ), $output );
2202 // phpcs:disable WordPress.Security.EscapeOutput
2203 if ( ! empty( $output->errors ) ) {
2204 foreach ( $output->errors as $siteid => $error ) {
2205 echo MainWP_Utility::get_nice_url( $dbwebsites[ $siteid ]->url ) . ' - ' . $error . ' <br/>';
2206
2207 }
2208 echo '<div class="ui hidden divider"></div>';
2209
2210 if ( count( $output->errors ) === count( $dbwebsites ) ) {
2211 $_SESSION['MainWP_PluginsActive'] = $output;
2212 $_SESSION['MainWP_PluginsActiveStatus'] = array(
2213 'keyword' => $keyword,
2214 'status' => $search_status,
2215 'plugin_status' => $search_plugin_status,
2216 );
2217 return;
2218 }
2219 }
2220 // phpcs:enable
2221 }
2222
2223 $_SESSION['MainWP_PluginsActive'] = $output;
2224 $_SESSION['MainWP_PluginsActiveStatus'] = array(
2225 'keyword' => $keyword,
2226 'status' => $search_status,
2227 'plugin_status' => $search_plugin_status,
2228 );
2229 } elseif ( isset( $_SESSION['MainWP_PluginsActiveStatus'] ) ) {
2230 //phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2231 $keyword = isset( $_SESSION['MainWP_PluginsActiveStatus']['keyword'] ) ? $_SESSION['MainWP_PluginsActiveStatus']['keyword'] : null;
2232 $search_status = isset( $_SESSION['MainWP_PluginsActiveStatus']['status'] ) ? $_SESSION['MainWP_PluginsActiveStatus']['status'] : null;
2233 $search_plugin_status = isset( $_SESSION['MainWP_PluginsActiveStatus']['plugin_status'] ) ? $_SESSION['MainWP_PluginsActiveStatus']['plugin_status'] : null;
2234 //phpcs:enable
2235 }
2236
2237 if ( 'inactive' !== $search_plugin_status && ( empty( $keyword ) || ( ! empty( $keyword ) && false !== stristr( 'MainWP Child', $keyword ) ) ) ) {
2238 $output->plugins[] = array(
2239 'slug' => 'mainwp-child/mainwp-child.php',
2240 'name' => 'MainWP Child',
2241 'active' => 1,
2242 );
2243 }
2244
2245 if ( empty( $output->plugins ) ) {
2246 ?>
2247 <div class="ui message yellow"><?php esc_html_e( 'No plugins found.', 'mainwp' ); ?></div>
2248 <?php
2249 return;
2250 }
2251
2252 $plugins = array();
2253 foreach ( $output->plugins as $plugin ) {
2254 $plugins[ $plugin['slug'] ] = $plugin;
2255 }
2256 asort( $plugins );
2257
2258 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
2259 $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true );
2260 $trustedPlugins = json_decode( $userExtension->trusted_plugins, true );
2261
2262 if ( ! is_array( $trustedPlugins ) ) {
2263 $trustedPlugins = array();
2264 }
2265 $trustedPluginsNotes = json_decode( $userExtension->trusted_plugins_notes, true );
2266 if ( ! is_array( $trustedPluginsNotes ) ) {
2267 $trustedPluginsNotes = array();
2268 }
2269 static::render_all_active_html( $plugins, $trustedPlugins, $search_status, $decodedIgnoredPlugins, $trustedPluginsNotes );
2270 MainWP_UI::render_modal_upload_icon();
2271 }
2272
2273
2274 /**
2275 * Method render_all_active_html()
2276 *
2277 * Render all active plugins html.
2278 *
2279 * @param array $plugins Plugins array.
2280 * @param array $trustedPlugins Trusted plugins array.
2281 * @param mixed $search_status trust|untrust|ignored.
2282 * @param array $decodedIgnoredPlugins Decoded ignored plugins array.
2283 * @param array $trustedPluginsNotes Trusted plugins notes.
2284 *
2285 * @uses \MainWP\Dashboard\MainWP_Utility::esc_content()
2286 */
2287 public static function render_all_active_html( $plugins, $trustedPlugins, $search_status, $decodedIgnoredPlugins, $trustedPluginsNotes ) { // phpcs:ignore -- NOSONAR - complex.
2288
2289 /**
2290 * Action: mainwp_plugins_before_auto_updates_table
2291 *
2292 * Fires before the Auto Update Plugins table.
2293 *
2294 * @since 4.1
2295 */
2296 do_action( 'mainwp_plugins_before_auto_updates_table' );
2297 ?>
2298 <table class="ui unstackable table" id="mainwp-all-active-plugins-table">
2299 <thead>
2300 <tr>
2301 <th scope="col" class="no-sort check-column collapsing"><span class="ui checkbox"><input id="cb-select-all-top" type="checkbox" /></span></th>
2302 <th scope="col" class="no-sort"><?php esc_html_e( '', 'mainwp' ); ?></th>
2303 <th scope="col" data-priority="1"><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
2304 <th scope="col" ><?php esc_html_e( 'Status', 'mainwp' ); ?></th>
2305 <th scope="col" class="collapsing" data-priority="2"><?php esc_html_e( 'Trust Status', 'mainwp' ); ?></th>
2306 <th scope="col"><?php esc_html_e( 'Ignored Status', 'mainwp' ); ?></th>
2307 <th scope="col" class="collapsing"></th>
2308 <th scope="col" class="collapsing"><?php esc_html_e( 'Notes', 'mainwp' ); ?></th>
2309 </tr>
2310 </thead>
2311 <tbody>
2312 <?php foreach ( $plugins as $slug => $plugin ) : ?>
2313 <?php
2314 $name = $plugin['name'];
2315 $wpid = isset( $plugin['websiteid'] ) ? intval( $plugin['websiteid'] ) : 0;
2316
2317 if ( ! empty( $search_status ) && 'all' !== $search_status ) {
2318 if ( 'trust' === $search_status && ! in_array( $slug, $trustedPlugins ) ) {
2319 continue;
2320 }
2321
2322 if ( 'untrust' === $search_status && in_array( $slug, $trustedPlugins ) ) {
2323 continue;
2324 }
2325
2326 if ( 'ignored' === $search_status && ! isset( $decodedIgnoredPlugins[ $slug ] ) ) {
2327 continue;
2328 }
2329 }
2330 $esc_note = '';
2331 $strip_note = '';
2332 if ( isset( $trustedPluginsNotes[ $slug ] ) ) {
2333 $esc_note = MainWP_Utility::esc_content( $trustedPluginsNotes[ $slug ] );
2334 $strip_note = wp_strip_all_tags( $esc_note );
2335 }
2336
2337 $plugin_directory = dirname( $slug );
2338 ?>
2339 <?php // phpcs:disable WordPress.Security.EscapeOutput ?>
2340 <tr plugin-slug="<?php echo esc_attr( rawurlencode( $slug ) ); ?>" plugin-name="<?php echo esc_html( wp_strip_all_tags( $name ) ); ?>">
2341 <td class="check-column"><span class="ui checkbox"><input type="checkbox" name="plugin[]" value="<?php echo esc_attr( rawurlencode( $slug ) ); ?>"></span></td>
2342 <td class="collapsing"><?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); ?></td>
2343 <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>
2344 <td><?php echo ( 1 === (int) $plugin['active'] ) ? esc_html__( 'Active', 'mainwp' ) : esc_html__( 'Inactive', 'mainwp' ); //phpcs:ignore -- escaped. ?></td>
2345 <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>
2346 <td><?php echo ( isset( $decodedIgnoredPlugins[ $slug ] ) ) ? '<span class="ui mini label">' . esc_html__( 'Ignored', 'mainwp' ) . '</span>' : ''; ?></td>
2347 <td><?php echo ( isset( $decodedIgnoredPlugins[ $slug ] ) ) ? '<span data-tooltip="Ignored plugins will not be automatically updated." data-inverted=""><i class="info red circle icon" ></i></span>' : ''; ?></td>
2348 <td class="collapsing center aligned">
2349 <?php if ( '' === $esc_note ) : ?>
2350 <a href="javascript:void(0)" class="mainwp-edit-plugin-note" ><i class="sticky note outline icon"></i></a>
2351 <?php else : ?>
2352 <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>
2353 <?php endif; ?>
2354 <span style="display: none" class="esc-content-note"><?php echo $esc_note; //phpcs:ignore -- escaped. ?></span>
2355 </td>
2356 </tr>
2357 <?php // phpcs:enable ?>
2358 <?php endforeach; ?>
2359 </tbody>
2360 <tfoot>
2361 <tr>
2362 <th scope="col" class="no-sort check-column"><span class="ui checkbox"><input id="cb-select-all-bottom" type="checkbox" /></span></th>
2363 <th scope="col" ></th>
2364 <th scope="col" ><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
2365 <th scope="col" ><?php esc_html_e( 'Status', 'mainwp' ); ?></th>
2366 <th scope="col" ><?php esc_html_e( 'Trust Status', 'mainwp' ); ?></th>
2367 <th scope="col" ><?php esc_html_e( 'Ignored Status', 'mainwp' ); ?></th>
2368 <th scope="col" class="collapsing"></th>
2369 <th scope="col" ><?php esc_html_e( 'Notes', 'mainwp' ); ?></th>
2370 </tr>
2371 </tfoot>
2372 </table>
2373 <?php
2374 /**
2375 * Action: mainwp_plugins_after_auto_updates_table
2376 *
2377 * Fires after the Auto Update Plugins table.
2378 *
2379 * @since 4.1
2380 */
2381 do_action( 'mainwp_plugins_after_auto_updates_table' );
2382
2383 $table_features = array(
2384 'searching' => 'true',
2385 'stateSave' => 'true',
2386 'colReorder' => 'true',
2387 'info' => 'true',
2388 'paging' => 'false',
2389 'ordering' => 'true',
2390 'order' => '[ [ 2, "asc" ] ]',
2391 'responsive' => 'true',
2392 );
2393
2394 /**
2395 * Filter: mainwp_plugin_auto_updates_table_fatures
2396 *
2397 * Filters the Plugin Auto Updates table features.
2398 *
2399 * @since 4.1
2400 */
2401 $table_features = apply_filters( 'mainwp_plugin_auto_updates_table_fatures', $table_features );
2402 ?>
2403 <script type="text/javascript">
2404 jQuery( document ).ready( function() {
2405 let responsive = <?php echo esc_html( $table_features['responsive'] ); ?>;
2406 if( jQuery( window ).width() > 1140 ) {
2407 responsive = false;
2408 }
2409 jQuery( '#mainwp-all-active-plugins-table' ).DataTable( {
2410 "searching" : <?php echo esc_html( $table_features['searching'] ); ?>,
2411 "stateSave" : <?php echo esc_html( $table_features['stateSave'] ); ?>,
2412 "colReorder" : <?php echo $table_features['colReorder']; // phpcs:ignore -- specical chars. ?>,
2413 "info" : <?php echo esc_html( $table_features['info'] ); ?>,
2414 "paging" : <?php echo esc_html( $table_features['paging'] ); ?>,
2415 "ordering" : <?php echo esc_html( $table_features['ordering'] ); ?>,
2416 "order" : <?php echo $table_features['order']; // phpcs:ignore -- specical chars. ?>,
2417 "columnDefs": [ { "orderable": false, "targets": [ 0, 1, 6 ] } ],
2418 "responsive": responsive,
2419 } );
2420 } );
2421 </script>
2422
2423 <script type="text/javascript">
2424 jQuery( document ).ready( function () {
2425 jQuery( '.mainwp-ui-page .ui.checkbox:not(.not-auto-init)' ).checkbox();
2426 } );
2427 </script>
2428 <?php
2429 }
2430
2431 /**
2432 * Render Ignore Subpage.
2433 *
2434 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
2435 * @uses \MainWP\Dashboard\MainWP_DB::query()
2436 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
2437 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
2438 */
2439 public static function render_ignore() {
2440 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
2441 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
2442 $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true );
2443 $ignoredPlugins = is_array( $decodedIgnoredPlugins ) && ( ! empty( $decodedIgnoredPlugins ) );
2444
2445 $cnt = 0;
2446
2447 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2448 if ( $website->is_ignorePluginUpdates ) {
2449 continue;
2450 }
2451
2452 $tmpDecodedIgnoredPlugins = json_decode( $website->ignored_plugins, true );
2453
2454 if ( ! is_array( $tmpDecodedIgnoredPlugins ) || empty( $tmpDecodedIgnoredPlugins ) ) {
2455 continue;
2456 }
2457 ++$cnt;
2458 }
2459
2460 static::render_header( 'Ignore' );
2461 ?>
2462 <div id="mainwp-ignored-plugins" class="ui segment">
2463 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-ignored-plugins-info-message' ) ) : ?>
2464 <div class="ui info message">
2465 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-ignored-plugins-info-message"></i>
2466 <?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>' ); ?>
2467 </div>
2468 <?php endif; ?>
2469 <?php
2470 /**
2471 * Action: mainwp_plugins_before_ignored_updates
2472 *
2473 * Fires on the top of the Ignored Plugins Updates page.
2474 *
2475 * @since 4.1
2476 */
2477 do_action( 'mainwp_plugins_before_ignored_updates', $ignoredPlugins, $websites );
2478 ?>
2479 <h3 class="ui header">
2480 <?php esc_html_e( 'Globally Ignored Plugins', 'mainwp' ); ?>
2481 <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>
2482 </h3>
2483 <?php static::render_global_ignored( $ignoredPlugins, $decodedIgnoredPlugins ); ?>
2484 <div class="ui hidden divider"></div>
2485 <h3 class="ui header">
2486 <?php esc_html_e( 'Per Site Ignored Plugins' ); ?>
2487 <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>
2488 </h3>
2489 <?php static::render_sites_ignored( $cnt, $websites ); ?>
2490 <?php
2491 /**
2492 * Action: mainwp_plugins_after_ignored_updates
2493 *
2494 * Fires on the bottom of the Ignored Plugins Updates page.
2495 *
2496 * @since 4.1
2497 */
2498 do_action( 'mainwp_plugins_after_ignored_updates', $ignoredPlugins, $websites );
2499 ?>
2500 </div>
2501 <?php
2502 MainWP_Updates::render_plugin_details_modal();
2503 static::render_footer( 'Ignore' );
2504 }
2505
2506 /**
2507 * Method render_global_ignored()
2508 *
2509 * Render Global Ignored plugins list.
2510 *
2511 * @param array $ignoredPlugins Ignored plugins array.
2512 * @param array $decodedIgnoredPlugins Decoded ignored plugins array.
2513 */
2514 public static function render_global_ignored( $ignoredPlugins, $decodedIgnoredPlugins ) {
2515 ?>
2516 <table id="mainwp-globally-ignored-plugins" class="ui compact selectable table unstackable">
2517 <thead>
2518 <tr>
2519 <th scope="col" class="no-sort"></th>
2520 <th scope="col" ><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
2521 <th scope="col" ><?php esc_html_e( 'Plugin slug', 'mainwp' ); ?></th>
2522 <th scope="col" ></th>
2523 </tr>
2524 </thead>
2525 <tbody id="globally-ignored-plugins-list">
2526 <?php if ( $ignoredPlugins ) : ?>
2527 <?php // phpcs:disable WordPress.Security.EscapeOutput ?>
2528 <?php foreach ( $decodedIgnoredPlugins as $ignoredPlugin => $ignoredPluginName ) : ?>
2529 <?php $plugin_directory = dirname( $ignoredPlugin ); ?>
2530 <tr plugin-slug="<?php echo esc_attr( rawurlencode( $ignoredPlugin ) ); ?>">
2531 <td class="collapsing"><?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); ?></td>
2532 <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( $ignoredPluginName ); ?></a></td>
2533 <td><?php echo esc_html( $ignoredPlugin ); ?></td>
2534 <td class="right aligned">
2535 <?php if ( mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2536 <a href="#" class="ui mini button" onClick="return updatesoverview_plugins_unignore_globally( '<?php echo esc_html( rawurlencode( $ignoredPlugin ) ); ?>' )"><?php esc_html_e( 'Unignore', 'mainwp' ); ?></a>
2537 <?php endif; ?>
2538 </td>
2539 </tr>
2540 <?php endforeach; ?>
2541 <?php // phpcs:enable ?>
2542 <?php endif; ?>
2543 </tbody>
2544 <?php if ( mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2545 <?php if ( $ignoredPlugins ) : ?>
2546 <tfoot class="full-width">
2547 <tr>
2548 <th scope="col" colspan="4">
2549 <a class="ui right floated small green labeled icon button" onClick="return updatesoverview_plugins_unignore_globally_all();" id="mainwp-unignore-globally-all">
2550 <i class="check icon"></i> <?php esc_html_e( 'Unignore All', 'mainwp' ); ?>
2551 </a>
2552 </th>
2553 </tr>
2554 </tfoot>
2555 <?php endif; ?>
2556 <?php endif; ?>
2557 </table>
2558 <script type="text/javascript">
2559 jQuery( document ).ready( function() {
2560 jQuery( '#mainwp-globally-ignored-plugins' ).DataTable( {
2561 "searching": false,
2562 "paging": false,
2563 "info": false,
2564 "responsive": true,
2565 "columnDefs": [ {
2566 "targets": 'no-sort',
2567 "orderable": false
2568 } ],
2569 "language": {
2570 "emptyTable": "<?php esc_html_e( 'No ignored plugins.', 'mainwp' ); ?>"
2571 }
2572 } );
2573 } );
2574 </script>
2575 <?php
2576 }
2577
2578 /**
2579 * Render Per Site Ignored table.
2580 *
2581 * @param mixed $cnt Plugin count.
2582 * @param mixed $websites Child Sites.
2583 *
2584 * @return void
2585 *
2586 * @uses \MainWP\Dashboard\MainWP_DB::data_seek()
2587 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
2588 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
2589 */
2590 public static function render_sites_ignored( $cnt, $websites ) { // phpcs:ignore -- NOSONAR - complex.
2591 ?>
2592 <table id="mainwp-per-site-ignored-plugins" class="ui unstackable compact selectable table ">
2593 <thead>
2594 <tr>
2595 <th scope="col" ><?php esc_html_e( 'Site', 'mainwp' ); ?></th>
2596 <th scope="col" class="no-sort"><?php esc_html_e( '', 'mainwp' ); ?></th>
2597 <th scope="col" ><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
2598 <th scope="col" ><?php esc_html_e( 'Plugin slug', 'mainwp' ); ?></th>
2599 <th scope="col" ></th>
2600 </tr>
2601 </thead>
2602 <tbody id="ignored-plugins-list">
2603 <?php if ( 0 < $cnt ) : ?>
2604 <?php
2605 MainWP_DB::data_seek( $websites, 0 );
2606
2607 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2608 if ( $website->is_ignorePluginUpdates ) {
2609 continue;
2610 }
2611
2612 $decodedIgnoredPlugins = json_decode( $website->ignored_plugins, true );
2613 if ( ! is_array( $decodedIgnoredPlugins ) || empty( $decodedIgnoredPlugins ) ) {
2614 continue;
2615 }
2616 $first = true;
2617 // phpcs:disable WordPress.Security.EscapeOutput
2618 foreach ( $decodedIgnoredPlugins as $ignoredPlugin => $ignoredPluginName ) {
2619 $plugin_directory = MainWP_Utility::get_dir_slug( rawurldecode( $ignoredPlugin ) );
2620 ?>
2621 <tr site-id="<?php echo intval( $website->id ); ?>" plugin-slug="<?php echo esc_attr( rawurlencode( $ignoredPlugin ) ); ?>">
2622 <?php if ( $first ) : ?>
2623 <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>
2624 <?php $first = false; ?>
2625 <?php else : ?>
2626 <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>
2627 <?php endif; ?>
2628 <td class="collapsing"><?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); ?></td>
2629 <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( $ignoredPluginName ); ?></a></td>
2630 <td><?php echo esc_html( rawurldecode( $ignoredPlugin ) ); ?></td>
2631 <?php if ( mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2632 <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 esc_html_e( 'Unignore', 'mainwp' ); ?></a></td>
2633 <?php endif; ?>
2634 </tr>
2635 <?php
2636 }
2637 // phpcs:enable
2638 }
2639
2640 MainWP_DB::free_result( $websites );
2641 ?>
2642 <?php endif; ?>
2643 </tbody>
2644 <?php if ( mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2645 <?php if ( 0 < $cnt ) : ?>
2646 <tfoot class="full-width">
2647 <tr>
2648 <th scope="col" colspan="5">
2649 <a class="ui right floated small green labeled icon button" onClick="return updatesoverview_plugins_unignore_detail_all();" id="mainwp-unignore-detail-all">
2650 <i class="check icon"></i> <?php esc_html_e( 'Unignore All', 'mainwp' ); ?>
2651 </a>
2652 </th>
2653 </tr>
2654 </tfoot>
2655 <?php endif; ?>
2656 <?php endif; ?>
2657 </table>
2658 <script type="text/javascript">
2659 jQuery( document ).ready( function() {
2660 jQuery( '#mainwp-per-site-ignored-plugins' ).DataTable( {
2661 "responsive": true,
2662 "searching": false,
2663 "paging": false,
2664 "info": false,
2665 "columnDefs": [ {
2666 "targets": 'no-sort',
2667 "orderable": false
2668 } ],
2669 "language": {
2670 "emptyTable": "<?php esc_html_e( 'No ignored plugins', 'mainwp' ); ?>"
2671 }
2672 } );
2673 } );
2674 </script>
2675 <?php
2676 }
2677
2678 /**
2679 * Render Ignored Abandoned Page.
2680 *
2681 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
2682 * @uses \MainWP\Dashboard\MainWP_DB::query()
2683 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
2684 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
2685 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
2686 */
2687 public static function render_ignored_abandoned() {
2688 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
2689 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
2690 $decodedIgnoredPlugins = json_decode( $userExtension->dismissed_plugins, true );
2691 $ignoredPlugins = is_array( $decodedIgnoredPlugins ) && ( ! empty( $decodedIgnoredPlugins ) );
2692 $cnt = 0;
2693 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2694 $tmpDecodedDismissedPlugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' );
2695 $tmpDecodedDismissedPlugins = ! empty( $tmpDecodedDismissedPlugins ) ? json_decode( $tmpDecodedDismissedPlugins, true ) : array();
2696
2697 if ( ! is_array( $tmpDecodedDismissedPlugins ) || empty( $tmpDecodedDismissedPlugins ) ) {
2698 continue;
2699 }
2700 ++$cnt;
2701 }
2702
2703 static::render_header( 'IgnoreAbandoned' );
2704 ?>
2705 <div id="mainwp-ignored-abandoned-plugins" class="ui segment">
2706 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-ignored-abandoned-plugins-info-message' ) ) : ?>
2707 <div class="ui info message">
2708 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-ignored-abandoned-plugins-info-message"></i>
2709 <?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> ' ); ?>
2710 </div>
2711 <?php endif; ?>
2712 <?php
2713 /**
2714 * Action: mainwp_plugins_before_ignored_abandoned
2715 *
2716 * Fires on the top of the Ignored Plugins Abandoned page.
2717 *
2718 * @since 4.1
2719 */
2720 do_action( 'mainwp_plugins_before_ignored_abandoned', $ignoredPlugins, $websites );
2721 ?>
2722 <h3 class="ui header">
2723 <?php esc_html_e( 'Globally Ignored Abandoned Plugins' ); ?>
2724 <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>
2725 </h3>
2726 <?php static::render_global_ignored_abandoned( $ignoredPlugins, $decodedIgnoredPlugins ); ?>
2727 <div class="ui hidden divider"></div>
2728 <h3 class="ui header">
2729 <?php esc_html_e( 'Per Site Ignored Abandoned Plugins' ); ?>
2730 <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>
2731 </h3>
2732 <?php static::render_sites_ignored_abandoned( $cnt, $websites ); ?>
2733 <?php
2734 /**
2735 * Action: mainwp_plugins_after_ignored_abandoned
2736 *
2737 * Fires on the bottom of the Ignored Plugins Abandoned page.
2738 *
2739 * @since 4.1
2740 */
2741 do_action( 'mainwp_plugins_after_ignored_abandoned', $ignoredPlugins, $websites );
2742 ?>
2743 </div>
2744 <?php
2745 static::render_footer( 'IgnoreAbandoned' );
2746 }
2747
2748 /**
2749 * Method render_global_ignored_abandoned()
2750 *
2751 * Render Global Ignored Abandoned table.
2752 *
2753 * @param array $ignoredPlugins Ignored plugins array.
2754 * @param array $decodedIgnoredPlugins Decoded dgnored plugins array.
2755 */
2756 public static function render_global_ignored_abandoned( $ignoredPlugins, $decodedIgnoredPlugins ) {
2757 ?>
2758 <table id="mainwp-globally-ignored-abandoned-plugins" class="ui compact selectable table unstackable">
2759 <thead>
2760 <tr>
2761 <th scope="col" class="no-sort"><?php esc_html_e( ' ', 'mainwp' ); ?></th>
2762 <th scope="col" ><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
2763 <th scope="col" ><?php esc_html_e( 'Plugin slug', 'mainwp' ); ?></th>
2764 <th scope="col" ></th>
2765 </tr>
2766 </thead>
2767 <tbody id="ignored-globally-abandoned-plugins-list">
2768 <?php if ( $ignoredPlugins ) : ?>
2769 <?php
2770 // phpcs:disable WordPress.Security.EscapeOutput
2771 foreach ( $decodedIgnoredPlugins as $ignoredPlugin => $ignoredPluginName ) :
2772 $plugin_directory = MainWP_Utility::get_dir_slug( rawurldecode( $ignoredPlugin ) );
2773 ?>
2774 <tr plugin-slug="<?php echo esc_attr( rawurlencode( $ignoredPlugin ) ); ?>">
2775 <td class="collapsing"><?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); ?></td>
2776 <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( $ignoredPluginName ); ?></a></td>
2777 <td><?php echo esc_html( $ignoredPlugin ); ?></td>
2778 <td class="right aligned">
2779 <?php if ( mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2780 <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>
2781 <?php endif; ?>
2782 </td>
2783 </tr>
2784 <?php endforeach; ?>
2785 <?php // phpcs:enable ?>
2786 <?php endif; ?>
2787 </tbody>
2788 <?php if ( mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2789 <?php if ( $ignoredPlugins ) : ?>
2790 <tfoot class="full-width">
2791 <tr>
2792 <th scope="col" colspan="4">
2793 <a class="ui right floated small green labeled icon button" onClick="return updatesoverview_plugins_abandoned_unignore_globally_all();" id="mainwp-unignore-globally-all">
2794 <i class="check icon"></i> <?php esc_html_e( 'Unignore All', 'mainwp' ); ?>
2795 </a>
2796 </th>
2797 </tr>
2798 </tfoot>
2799 <?php endif; ?>
2800 <?php endif; ?>
2801 </table>
2802 <script type="text/javascript">
2803 jQuery( document ).ready( function() {
2804 jQuery( '#mainwp-globally-ignored-abandoned-plugins' ).DataTable( {
2805 "responsive": true,
2806 "searching": false,
2807 "paging": false,
2808 "info": false,
2809 "columnDefs": [ {
2810 "targets": 'no-sort',
2811 "orderable": false
2812 } ],
2813 "language": {
2814 "emptyTable": "<?php esc_html_e( 'No ignored abandoned plugins.', 'mainwp' ); ?>"
2815 }
2816 } );
2817 } );
2818 </script>
2819 <?php
2820 }
2821
2822 /**
2823 * Method render_sites_ignored_abandoned()
2824 *
2825 * Render Per Site Ignored Abandoned Table.
2826 *
2827 * @param int $cnt Plugins count.
2828 * @param object $websites The websites object.
2829 *
2830 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
2831 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
2832 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
2833 */
2834 public static function render_sites_ignored_abandoned( $cnt, $websites ) { // phpcs:ignore -- NOSONAR - complex.
2835 ?>
2836 <table id="mainwp-per-site-ignored-abandoned-plugins" class="ui compact selectable table unstackable">
2837 <thead>
2838 <tr>
2839 <th scope="col" ><?php esc_html_e( 'Site', 'mainwp' ); ?></th>
2840 <th scope="col" class="no-sort"><?php esc_html_e( ' ', 'mainwp' ); ?></th>
2841 <th scope="col" ><?php esc_html_e( 'Plugin', 'mainwp' ); ?></th>
2842 <th scope="col" ><?php esc_html_e( 'Plugin slug', 'mainwp' ); ?></th>
2843 <th scope="col" ></th>
2844 </tr>
2845 </thead>
2846 <tbody id="ignored-abandoned-plugins-list">
2847 <?php if ( 0 < $cnt ) : ?>
2848 <?php
2849 MainWP_DB::data_seek( $websites, 0 );
2850
2851 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2852 $decodedIgnoredPlugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' );
2853 $decodedIgnoredPlugins = ! empty( $decodedIgnoredPlugins ) ? json_decode( $decodedIgnoredPlugins, true ) : array();
2854
2855 if ( ! is_array( $decodedIgnoredPlugins ) || empty( $decodedIgnoredPlugins ) ) {
2856 continue;
2857 }
2858 $first = true;
2859 // phpcs:disable WordPress.Security.EscapeOutput
2860 foreach ( $decodedIgnoredPlugins as $ignoredPlugin => $ignoredPluginName ) {
2861 $plugin_directory = MainWP_Utility::get_dir_slug( rawurldecode( $ignoredPlugin ) );
2862 ?>
2863 <tr site-id="<?php echo esc_attr( $website->id ); ?>" plugin-slug="<?php echo esc_attr( rawurlencode( $ignoredPlugin ) ); ?>">
2864 <?php if ( $first ) : ?>
2865 <td>
2866 <a href="<?php echo esc_url( admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) ); ?>"><?php echo esc_html( stripslashes( $website->name ) ); ?></a>
2867 </td>
2868 <?php $first = false; ?>
2869 <?php else : ?>
2870 <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>
2871 <?php endif; ?>
2872 <td class="collapsing"><?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); ?></td>
2873 <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( $ignoredPluginName ); ?></a></td>
2874 <td><?php echo esc_html( $ignoredPlugin ); ?></td>
2875 <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>
2876 </tr>
2877 <?php
2878 }
2879 // phpcs:enable
2880 }
2881 MainWP_DB::free_result( $websites );
2882 ?>
2883 <?php endif; ?>
2884 </tbody>
2885 <?php if ( mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) : ?>
2886 <?php if ( 0 < $cnt ) : ?>
2887 <tfoot class="full-width">
2888 <tr>
2889 <th scope="col" colspan="5">
2890 <a class="ui right floated small green labeled icon button" onClick="return updatesoverview_plugins_unignore_abandoned_detail_all();" id="mainwp-unignore-detail-all">
2891 <i class="check icon"></i> <?php esc_html_e( 'Unignore All', 'mainwp' ); ?>
2892 </a>
2893 </th>
2894 </tr>
2895 </tfoot>
2896 <?php endif; ?>
2897 <?php endif; ?>
2898 </table>
2899 <script type="text/javascript">
2900 jQuery( document ).ready( function() {
2901 jQuery( '#mainwp-per-site-ignored-abandoned-plugins' ).DataTable( {
2902 "responsive": true,
2903 "searching": false,
2904 "paging": false,
2905 "info": false,
2906 "columnDefs": [ {
2907 "targets": 'no-sort',
2908 "orderable": false
2909 } ],
2910 "language": {
2911 "emptyTable": "<?php esc_html_e( 'No ignored abandoned plugins.', 'mainwp' ); ?>"
2912 }
2913 } );
2914 } );
2915 </script>
2916 <?php
2917 }
2918
2919 /**
2920 * Hooks the section help content to the Help Sidebar element.
2921 */
2922 public static function mainwp_help_content() {
2923 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2924 if ( isset( $_GET['page'] ) && ( 'PluginsManage' === $_GET['page'] || 'PluginsInstall' === $_GET['page'] || 'PluginsAutoUpdate' === $_GET['page'] || 'PluginsIgnore' === $_GET['page'] || 'PluginsIgnoredAbandoned' === $_GET['page'] ) ) {
2925 ?>
2926 <p><?php esc_html_e( 'If you need help with managing plugins, please review following help documents', 'mainwp' ); ?></p>
2927 <div class="ui relaxed bulleted list">
2928 <div class="item"><a href="https://kb.mainwp.com/docs/managing-plugins-with-mainwp/" target="_blank">Managing Plugins with MainWP</a> <i class="external alternate icon"></i></div>
2929 <div class="item"><a href="https://kb.mainwp.com/docs/install-plugins/" target="_blank">Install Plugins</a> <i class="external alternate icon"></i></div>
2930 <div class="item"><a href="https://kb.mainwp.com/docs/activate-plugins/" target="_blank">Activate Plugins</a> <i class="external alternate icon"></i></div>
2931 <div class="item"><a href="https://kb.mainwp.com/docs/delete-plugins/" target="_blank">Delete Plugins</a> <i class="external alternate icon"></i></div>
2932 <div class="item"><a href="https://kb.mainwp.com/docs/abandoned-plugins/" target="_blank">Abandoned Plugins</a> <i class="external alternate icon"></i></div>
2933 <div class="item"><a href="https://kb.mainwp.com/docs/update-plugins/" target="_blank">Update Plugins</a> <i class="external alternate icon"></i></div>
2934 <div class="item"><a href="https://kb.mainwp.com/docs/plugins-auto-updates/" target="_blank">Plugins Auto Updates</a> <i class="external alternate icon"></i></div>
2935 <div class="item"><a href="https://kb.mainwp.com/docs/ignore-plugin-updates/" target="_blank">Ignore Plugin Updates</a> <i class="external alternate icon"></i></div>
2936 <?php
2937 /**
2938 * Action: mainwp_plugins_help_item
2939 *
2940 * Fires at the bottom of the help articles list in the Help sidebar on the Plugins page.
2941 *
2942 * Suggested HTML markup:
2943 *
2944 * <div class="item"><a href="Your custom URL">Your custom text</a></div>
2945 *
2946 * @since 4.1
2947 */
2948 do_action( 'mainwp_plugins_help_item' );
2949 ?>
2950 </div>
2951 <?php
2952 }
2953 // phpcs:enable
2954 }
2955 }
2956