PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | class/class-mainwp-ui-select-sites.php +477 -428 5.0 → 6.2.2 View file →
@@ -6,472 +6,521 @@
6 6 */
7 7
8 8 namespace MainWP\Dashboard;
9 9
10 +// Exit if accessed directly.
11 +if ( ! defined( 'ABSPATH' ) ) {
12 + exit;
13 +}
14 +
10 15 /**
11 16 * Class MainWP_UI_Select_Sites
12 17 *
13 18 * @package MainWP\Dashboard
14 19 */
15 -class MainWP_UI_Select_Sites {
20 +class MainWP_UI_Select_Sites { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
16 21
17 - /**
18 - * Method get_class_name()
19 - *
20 - * Get Class Name.
21 - *
22 - * @return object
23 - */
24 - public static function get_class_name() {
25 - return __CLASS__;
26 - }
22 + /**
23 + * Method get_class_name()
24 + *
25 + * Get Class Name.
26 + *
27 + * @return object
28 + */
29 + public static function get_class_name() {
30 + return __CLASS__;
31 + }
27 32
28 - /**
29 - * Method select_sites_box()
30 - *
31 - * Select sites box.
32 - *
33 - * @param array $params {
34 - * An array of params for sites selection. Default empty array.
35 - * @type string $type Input type, radio.
36 - * @type bool $show_group Whether or not to show group, Default: true.
37 - * @type bool $show_select_all Whether to show select all.
38 - * @type string $class Default = ''.
39 - * @type string $style Default = ''.
40 - * @type array $selected_sites Selected Child Sites.
41 - * @type array $selected_groups Selected Groups.
42 - * @type bool $enableOfflineSites (bool) True, if offline sites is enabled. False if not.
43 - * @type integer $postId Post Meta ID.
44 - * @type bool $show_client (bool) True, if show clients. False if not.
45 - * @type bool $enable_suspended_clients (bool) True, if enable suspended clients. False if not.
46 - * @type array $selected_clients Selected Clients.
47 - * }
48 - *
49 - * @uses \MainWP\Dashboard\MainWP_System_Utility::maybe_unserialyze()
50 - */
51 - public static function select_sites_box( $params = array() ) { // phpcs:ignore -- complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
33 + /**
34 + * Method select_sites_box()
35 + *
36 + * Select sites box.
37 + *
38 + * @param array $params {
39 + * An array of params for sites selection. Default empty array.
40 + * @type string $type Input type, radio.
41 + * @type bool $show_group Whether or not to show group, Default: true.
42 + * @type bool $show_select_all Whether to show select all.
43 + * @type string $class Default = ''.
44 + * @type string $style Default = ''.
45 + * @type array $selected_sites Selected Child Sites.
46 + * @type array $selected_groups Selected Groups.
47 + * @type bool $enableOfflineSites (bool) True, if offline sites is enabled. False if not.
48 + * @type integer $postId Post Meta ID.
49 + * @type bool $show_client (bool) True, if show clients. False if not.
50 + * @type bool $enable_suspended_clients (bool) True, if enable suspended clients. False if not.
51 + * @type array $selected_clients Selected Clients.
52 + * }
53 + *
54 + * @uses \MainWP\Dashboard\MainWP_System_Utility::maybe_unserialyze()
55 + */
56 + public static function select_sites_box( $params = array() ) { // phpcs:ignore -- NOSONAR - complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
52 57
53 - $type = isset( $params['type'] ) ? $params['type'] : 'checkbox';
54 - $show_group = isset( $params['show_group'] ) ? $params['show_group'] : true;
55 - $show_select_all = isset( $params['show_select_all'] ) ? $params['show_select_all'] : true;
56 - $show_selectall_disc = isset( $params['show_select_all_disconnect'] ) ? $params['show_select_all_disconnect'] : false;
57 - $show_new_tag = isset( $params['show_create_tag'] ) ? $params['show_create_tag'] : true;
58 - $class = isset( $params['class'] ) ? $params['class'] : '';
59 - $style = isset( $params['style'] ) ? $params['style'] : '';
60 - $selected_sites = isset( $params['selected_sites'] ) ? $params['selected_sites'] : array();
61 - $selected_groups = isset( $params['selected_groups'] ) ? $params['selected_groups'] : array();
62 - $enableOfflineSites = isset( $params['enable_offline_sites'] ) ? $params['enable_offline_sites'] : false;
63 - $postId = isset( $params['post_id'] ) ? $params['post_id'] : 0;
64 - $show_client = isset( $params['show_client'] ) ? $params['show_client'] : false;
65 - $enableSuspendedClients = isset( $params['enable_suspended_clients'] ) ? $params['enable_suspended_clients'] : false;
66 - $selected_clients = isset( $params['selected_clients'] ) ? $params['selected_clients'] : array();
67 - $selected_clients = isset( $params['selected_clients'] ) ? $params['selected_clients'] : array();
68 - $add_edit_client_id = isset( $params['add_edit_client_id'] ) ? $params['add_edit_client_id'] : false;
58 + $type = isset( $params['type'] ) ? $params['type'] : 'checkbox';
59 + $show_group = isset( $params['show_group'] ) ? $params['show_group'] : true;
60 + $show_select_all = isset( $params['show_select_all'] ) ? $params['show_select_all'] : true;
61 + $show_selectall_disc = isset( $params['show_select_all_disconnect'] ) ? $params['show_select_all_disconnect'] : false;
62 + $show_new_tag = isset( $params['show_create_tag'] ) ? $params['show_create_tag'] : true;
63 + $selected_sites = isset( $params['selected_sites'] ) ? $params['selected_sites'] : array();
64 + $selected_groups = isset( $params['selected_groups'] ) ? $params['selected_groups'] : array();
65 + $enableOfflineSites = isset( $params['enable_offline_sites'] ) ? $params['enable_offline_sites'] : false;
66 + $postId = isset( $params['post_id'] ) ? $params['post_id'] : 0;
67 + $show_client = isset( $params['show_client'] ) ? $params['show_client'] : false;
68 + $enableSuspendedClients = isset( $params['enable_suspended_clients'] ) ? $params['enable_suspended_clients'] : false;
69 + $selected_clients = isset( $params['selected_clients'] ) ? $params['selected_clients'] : array();
70 + $add_edit_client_id = isset( $params['add_edit_client_id'] ) ? $params['add_edit_client_id'] : false;
69 71
70 - if ( $postId ) {
72 + if ( $postId ) {
71 73
72 - $sites_val = get_post_meta( $postId, '_selected_sites', true );
73 - $selected_sites = MainWP_System_Utility::maybe_unserialyze( $sites_val );
74 + $sites_val = get_post_meta( $postId, '_selected_sites', true );
75 + $selected_sites = MainWP_System_Utility::maybe_unserialyze( $sites_val );
74 76
75 - if ( empty( $selected_sites ) ) {
76 - $selected_sites = array();
77 - }
77 + if ( empty( $selected_sites ) ) {
78 + $selected_sites = array();
79 + }
78 80
79 - $groups_val = get_post_meta( $postId, '_selected_groups', true );
80 - $selected_groups = MainWP_System_Utility::maybe_unserialyze( $groups_val );
81 + $groups_val = get_post_meta( $postId, '_selected_groups', true );
82 + $selected_groups = MainWP_System_Utility::maybe_unserialyze( $groups_val );
81 83
82 - if ( empty( $selected_groups ) ) {
83 - $selected_groups = array();
84 - }
84 + if ( empty( $selected_groups ) ) {
85 + $selected_groups = array();
86 + }
85 87
86 - $selected_clients = get_post_meta( $postId, '_selected_clients', true );
88 + $selected_clients = get_post_meta( $postId, '_selected_clients', true );
87 89
88 - if ( empty( $selected_clients ) ) {
89 - $selected_clients = array();
90 - }
91 - }
90 + if ( empty( $selected_clients ) ) {
91 + $selected_clients = array();
92 + }
93 + }
92 94
93 - if ( empty( $selected_sites ) && isset( $_GET['selected_sites'] ) && ! empty( $_GET['selected_sites'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
94 - $selected_sites = explode( '-', sanitize_text_field( wp_unslash( $_GET['selected_sites'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitize ok.
95 - $selected_sites = array_map( 'intval', $selected_sites );
96 - $selected_sites = array_filter( $selected_sites );
97 - }
95 + if ( empty( $selected_sites ) && isset( $_GET['selected_sites'] ) && ! empty( $_GET['selected_sites'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
96 + $selected_sites = explode( '-', sanitize_text_field( wp_unslash( $_GET['selected_sites'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitize ok.
97 + $selected_sites = array_map( 'intval', $selected_sites );
98 + $selected_sites = array_filter( $selected_sites );
99 + }
98 100
99 - /**
100 - * Action: mainwp_before_seclect_sites
101 - *
102 - * Fires before the Select Sites box.
103 - *
104 - * @since 4.1
105 - */
106 - do_action( 'mainwp_before_seclect_sites' );
107 - $params = array(
108 - 'type' => $type,
109 - 'show_group' => $show_group,
110 - 'show_select_all' => $show_select_all,
111 - 'show_select_all_disconnect' => $show_selectall_disc,
112 - 'show_create_tag' => $show_new_tag,
113 - 'selected_sites' => $selected_sites,
114 - 'selected_groups' => $selected_groups,
115 - 'enable_offline_sites' => $enableOfflineSites,
116 - 'post_id' => $postId,
117 - 'show_client' => $show_client,
118 - 'enable_suspended_clients' => $enableSuspendedClients,
119 - 'selected_clients' => $selected_clients,
120 - 'add_edit_client_id' => $add_edit_client_id,
121 - );
122 - ?>
123 - <div id="mainwp-select-sites" class="mainwp_select_sites_wrapper">
124 - <?php self::select_sites_box_body( $params ); ?>
125 - </div>
126 - <?php
127 - /**
128 - * Action: mainwp_after_seclect_sites
129 - *
130 - * Fires after the Select Sites box.
131 - *
132 - * @since 4.1
133 - */
134 - do_action( 'mainwp_after_seclect_sites' );
135 - }
101 + /**
102 + * Action: mainwp_before_seclect_sites
103 + *
104 + * Fires before the Select Sites box.
105 + *
106 + * @since 4.1
107 + */
108 + do_action( 'mainwp_before_seclect_sites' );
109 + $params = array(
110 + 'type' => $type,
111 + 'show_group' => $show_group,
112 + 'show_select_all' => $show_select_all,
113 + 'show_select_all_disconnect' => $show_selectall_disc,
114 + 'show_create_tag' => $show_new_tag,
115 + 'selected_sites' => $selected_sites,
116 + 'selected_groups' => $selected_groups,
117 + 'enable_offline_sites' => $enableOfflineSites,
118 + 'post_id' => $postId,
119 + 'show_client' => $show_client,
120 + 'enable_suspended_clients' => $enableSuspendedClients,
121 + 'selected_clients' => $selected_clients,
122 + 'add_edit_client_id' => $add_edit_client_id,
123 + );
124 + ?>
125 + <div id="mainwp-select-sites" class="mainwp_select_sites_wrapper">
126 + <?php static::select_sites_box_body( $params ); ?>
127 + </div>
128 + <?php
129 + /**
130 + * Action: mainwp_after_seclect_sites
131 + *
132 + * Fires after the Select Sites box.
133 + *
134 + * @since 4.1
135 + */
136 + do_action( 'mainwp_after_seclect_sites' );
137 + }
136 138
137 - /**
138 - * Method select_sites_box_body()
139 - *
140 - * Select sites box Body.
141 - *
142 - * @param array $params {
143 - *
144 - * An array of params for sites selection. Default empty array.
145 - *
146 - * @type string $type Input type, radio.
147 - * @type bool $show_group Whether or not to show group, Default: true.
148 - * @type bool $show_select_all Whether to show select all.
149 - * @type array $selected_sites Selected Child Sites.
150 - * @type array $selected_groups Selected Groups.
151 - * @type bool $enableOfflineSites (bool) True, if offline sites is enabled. False if not.
152 - * @type integer $postId Post Meta ID.
153 - * @type bool $show_client (bool) True, if show clients. False if not.
154 - * @type array $selected_clients Selected clients.
155 - * @type bool $enable_suspended_clients (bool) True, if suspended clients is enabled. False if not.
156 - * }
157 - */
158 - public static function select_sites_box_body( $params = array() ) { // phpcs:ignore -- complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
139 + /**
140 + * Method select_sites_box_body()
141 + *
142 + * Select sites box Body.
143 + *
144 + * @param array $params {
145 + *
146 + * An array of params for sites selection. Default empty array.
147 + *
148 + * @type string $type Input type, radio.
149 + * @type bool $show_group Whether or not to show group, Default: true.
150 + * @type bool $show_select_all Whether to show select all.
151 + * @type array $selected_sites Selected Child Sites.
152 + * @type array $selected_groups Selected Groups.
153 + * @type bool $enableOfflineSites (bool) True, if offline sites is enabled. False if not.
154 + * @type integer $postId Post Meta ID.
155 + * @type bool $show_client (bool) True, if show clients. False if not.
156 + * @type array $selected_clients Selected clients.
157 + * @type bool $enable_suspended_clients (bool) True, if suspended clients is enabled. False if not.
158 + * }
159 + */
160 + public static function select_sites_box_body( $params = array() ) { // phpcs:ignore -- NOSONAR - complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
159 161
160 - $type = isset( $params['type'] ) ? $params['type'] : 'checkbox';
161 - $show_group = isset( $params['show_group'] ) ? $params['show_group'] : true;
162 - $show_select_all = isset( $params['show_select_all'] ) ? $params['show_select_all'] : true;
163 - $show_selectall_disc = isset( $params['show_select_all_disconnect'] ) ? $params['show_select_all_disconnect'] : false;
164 - $show_new_tag = isset( $params['show_create_tag'] ) ? $params['show_create_tag'] : true;
165 - $selected_sites = isset( $params['selected_sites'] ) ? $params['selected_sites'] : array();
166 - $selected_groups = isset( $params['selected_groups'] ) ? $params['selected_groups'] : array();
167 - $enableOfflineSites = isset( $params['enable_offline_sites'] ) ? $params['enable_offline_sites'] : false;
168 - $postId = isset( $params['post_id'] ) ? $params['post_id'] : 0;
169 - $show_client = isset( $params['show_client'] ) ? $params['show_client'] : false;
170 - $enableSuspendedClients = isset( $params['enable_suspended_clients'] ) ? $params['enable_suspended_clients'] : false;
171 - $selected_clients = isset( $params['selected_clients'] ) ? $params['selected_clients'] : array();
172 - $add_edit_client_id = isset( $params['add_edit_client_id'] ) ? $params['add_edit_client_id'] : false;
162 + $type = isset( $params['type'] ) ? $params['type'] : 'checkbox';
163 + $show_group = isset( $params['show_group'] ) ? $params['show_group'] : true;
164 + $show_select_all = isset( $params['show_select_all'] ) ? $params['show_select_all'] : true;
165 + $show_selectall_disc = isset( $params['show_select_all_disconnect'] ) ? $params['show_select_all_disconnect'] : false;
166 + $show_new_tag = isset( $params['show_create_tag'] ) ? $params['show_create_tag'] : true;
167 + $selected_sites = isset( $params['selected_sites'] ) ? $params['selected_sites'] : array();
168 + $selected_groups = isset( $params['selected_groups'] ) ? $params['selected_groups'] : array();
169 + $enableOfflineSites = isset( $params['enable_offline_sites'] ) ? $params['enable_offline_sites'] : false;
170 + $postId = isset( $params['post_id'] ) ? $params['post_id'] : 0;
171 + $show_client = isset( $params['show_client'] ) ? $params['show_client'] : false;
172 + $enableSuspendedClients = isset( $params['enable_suspended_clients'] ) ? $params['enable_suspended_clients'] : false;
173 + $selected_clients = isset( $params['selected_clients'] ) ? $params['selected_clients'] : array();
174 + $add_edit_client_id = isset( $params['add_edit_client_id'] ) ? $params['add_edit_client_id'] : false;
173 175
174 - if ( 'all' !== $selected_sites && ! is_array( $selected_sites ) ) {
175 - $selected_sites = array();
176 - }
176 + if ( ! \mainwp_current_user_can( 'dashboard', 'manage_clients' ) ) {
177 + $show_client = false;
178 + }
177 179
178 - if ( ! is_array( $selected_groups ) ) {
179 - $selected_groups = array();
180 - }
180 + if ( 'all' !== $selected_sites && ! is_array( $selected_sites ) ) {
181 + $selected_sites = array();
182 + }
181 183
182 - $selectedby = 'site';
183 - if ( ! empty( $selected_groups ) ) {
184 - $selectedby = 'group';
185 - } elseif ( ! empty( $selected_clients ) ) {
186 - $selectedby = 'client';
187 - }
184 + if ( ! is_array( $selected_groups ) ) {
185 + $selected_groups = array();
186 + }
188 187
189 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
190 - $groups = MainWP_DB_Common::instance()->get_not_empty_groups( null, $enableOfflineSites );
188 + $selectedby = 'site';
189 + if ( ! empty( $selected_groups ) ) {
190 + $selectedby = 'group';
191 + } elseif ( ! empty( $selected_clients ) ) {
192 + $selectedby = 'client';
193 + }
191 194
192 - // support staging extension.
193 - $staging_enabled = is_plugin_active( 'mainwp-staging-extension/mainwp-staging-extension.php' ) || is_plugin_active( 'mainwp-timecapsule-extension/mainwp-timecapsule-extension.php' );
195 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.name' ) );
196 + $groups = MainWP_DB_Common::instance()->get_not_empty_groups( null, $enableOfflineSites );
194 197
195 - $edit_site_id = false;
196 - if ( $postId ) {
197 - $edit_site_id = get_post_meta( $postId, '_mainwp_edit_post_site_id', true );
198 - $edit_site_id = intval( $edit_site_id );
199 - }
198 + // support staging extension.
199 + $staging_enabled = is_plugin_active( 'mainwp-staging-extension/mainwp-staging-extension.php' ) || is_plugin_active( 'mainwp-timecapsule-extension/mainwp-timecapsule-extension.php' );
200 200
201 - if ( $edit_site_id ) {
202 - $show_group = false;
203 - }
204 - // to fix layout with multi sites selector.
205 - $tab_id = wp_rand();
201 + $edit_site_id = false;
202 + if ( $postId ) {
203 + $edit_site_id = get_post_meta( $postId, '_mainwp_edit_post_site_id', true );
204 + $edit_site_id = intval( $edit_site_id );
205 + }
206 206
207 - MainWP_UI::render_select_sites_header( $tab_id, $staging_enabled, $selectedby, $show_group, $show_client );
207 + if ( $edit_site_id ) {
208 + $show_group = false;
209 + }
210 + // to fix layout with multi sites selector.
211 + $tab_id = wp_rand();
208 212
209 - $select_all_disconnected = '';
213 + MainWP_UI::render_select_sites_header( $tab_id, $staging_enabled, $selectedby, $show_group, $show_client );
210 214
211 - if ( $show_selectall_disc ) {
212 - $select_all_disconnected = '<div onClick="return mainwp_ss_select_disconnected( this, true )" class="mainwp-ss-select-disconnected"><i class="square outline icon"></i> ' . esc_attr__( 'Select All Disconnected', 'mainwp' ) . '</div>';
213 - $select_all_disconnected .= '<div onClick="return mainwp_ss_select_disconnected( this, false )" class="mainwp-ss-deselect-disconnected" style="display:none;padding-top:0;"><i class="check square outline icon"></i> ' . esc_attr__( 'Deselect All Disconnected', 'mainwp' ) . '</div>';
214 - }
215 + $select_all_disconnected = '';
215 216
216 - if ( $show_select_all || $show_selectall_disc || $show_new_tag ) :
217 - ?>
218 - <div id="mainwp-select-sites-select-all-actions" class="ui two columns grid">
219 - <div class="ui middle aligned column">
220 - <?php if ( $show_select_all ) : ?>
221 - <div onClick="return mainwp_ss_select( this, true )" class="mainwp-ss-select"><i class="square outline icon"></i> <?php esc_attr_e( 'Select All', 'mainwp' ); ?></div>
222 - <div onClick="return mainwp_ss_select( this, false )" class="mainwp-ss-deselect" style="display:none;padding-top:0;"><i class="check square outline icon"></i> <?php esc_attr_e( 'Deselect All', 'mainwp' ); ?></div>
223 - <?php endif; ?>
224 - <?php echo $select_all_disconnected; //phpcs:ignore WordPress.Security.EscapeOutput ?>
225 - </div>
226 - <div class="ui right aligned middle aligned column">
227 - <?php if ( $show_new_tag ) { ?>
228 - <a class="ui mini basic icon button" href="javascript:void(0)" id="mainwp-create-new-tag-button" data-tooltip="<?php esc_attr_e( 'Create a tag with selected sites.', 'mainwp' ); ?>" data-position="left center" data-inverted=""><i class="tag icon"></i></a>
229 - <?php } ?>
230 - </div>
231 - </div>
232 - <div class="ui hidden divider"></div>
233 - <?php
234 - endif;
235 - ?>
236 - <div class="ui tab <?php echo 'site' === $selectedby ? 'active' : ''; ?>" data-tab="mainwp-select-sites-<?php echo esc_attr( $tab_id ); ?>" id="mainwp-select-sites">
237 - <?php
238 - MainWP_UI::render_select_sites( $websites, $type, $selected_sites, $enableOfflineSites, $edit_site_id, $show_select_all, $add_edit_client_id, $show_selectall_disc );
239 - ?>
240 - </div>
241 - <?php if ( $staging_enabled ) { ?>
242 - <div class="ui tab <?php echo 'staging' === $selectedby ? 'active' : ''; ?>" data-tab="mainwp-select-staging-sites-<?php echo esc_attr( $tab_id ); ?>">
243 - <?php
244 - MainWP_UI::render_select_sites_staging( $selected_sites, $edit_site_id, $type );
245 - ?>
246 - </div>
247 - <?php
248 - }
217 + if ( $show_selectall_disc ) {
218 + $select_all_disconnected = '<div onClick="return mainwp_ss_select_disconnected( this, true )" class="mainwp-ss-select-disconnected"><i class="square outline icon"></i> ' . esc_attr__( 'Select All Disconnected', 'mainwp' ) . '</div>';
219 + $select_all_disconnected .= '<div onClick="return mainwp_ss_select_disconnected( this, false )" class="mainwp-ss-deselect-disconnected" style="display:none;padding-top:0;"><i class="check square outline icon"></i> ' . esc_attr__( 'Deselect All Disconnected', 'mainwp' ) . '</div>';
220 + }
249 221
250 - if ( $show_group ) {
251 - ?>
252 - <div class="ui tab <?php echo 'group' === $selectedby ? 'active' : ''; ?>" data-tab="mainwp-select-groups-<?php echo esc_attr( $tab_id ); ?>" id="mainwp-select-groups">
253 - <?php
254 - MainWP_UI::render_select_sites_group( $groups, $selected_groups, $type );
255 - ?>
256 - </div>
257 - <?php
258 - }
222 + static $rendered_count = 0;
259 223
260 - if ( $show_client ) {
261 - $clients = MainWP_DB_Client::instance()->get_wp_client_by( 'all' );
262 - $params = array(
263 - 'clients' => $clients,
264 - 'type' => $type,
265 - 'selected_clients' => $selected_clients,
266 - 'enable_suspended_clients' => $enableSuspendedClients,
267 - );
268 - ?>
269 - <div class="ui tab <?php echo 'client' === $selectedby ? 'active' : ''; ?>" data-tab="mainwp-select-clients-<?php echo esc_attr( $tab_id ); ?>" id="mainwp-select-clients">
270 - <?php
271 - self::render_select_clients( $params );
272 - ?>
273 - </div>
274 - <?php
275 - }
224 + $rand_id_prefix = '';
276 225
277 - if ( $show_new_tag ) {
278 - self::render_create_tag_modal();
279 - }
280 - ?>
281 - <script type="text/javascript">
282 - jQuery( document ).ready( function () {
283 - jQuery('#mainwp-select-sites-header .ui.menu .item').tab( {'onVisible': function() { mainwp_sites_selection_onvisible_callback( this ); } } );
284 - jQuery( '#mainwp-create-new-tag-button' ).on( 'click', function() {
285 - jQuery( '#mainwp-create-group-sites-modal' ).modal( {
286 - onHide: function () {
287 - window.location.href = location.href;
288 - return false;
289 - },
290 - } ).modal( 'show' );
291 - } );
292 - // Create a new group (Select Sites UI)
293 - jQuery( document ).on( 'click', '#mainwp-save-new-tag-button', function () {
294 - var newName = jQuery( '#mainwp-create-group-sites-modal' ).find( '#mainwp-group-name' ).val().trim();
295 - var newColor = jQuery( '#mainwp-create-group-sites-modal' ).find( '#mainwp-group-color' ).val();
296 - if('' == newName ){
297 - return false;
298 - }
299 - jQuery(this).attr('disabled', 'disabled');
300 - var selected_sites = [ ];
301 - jQuery( "input[name='selected_sites[]']:checked" ).each( function () {
302 - selected_sites.push( jQuery( this ).val() );
303 - } );
304 - var data = mainwp_secure_data( {
305 - action: 'mainwp_group_sites_add',
306 - selected_sites: selected_sites,
307 - newName: newName,
308 - newColor: newColor
309 - } );
310 - jQuery.post( ajaxurl, data, function ( response ) {
311 - try {
312 - if ( response.error != undefined ){
313 - jQuery('#mainwp-message-zone-tag').show().find('.ui.message').html(response.error);
314 - return;
315 - }
316 - } catch ( err ) {
317 - // to fix js error.
318 - }
319 - jQuery( '#mainwp-create-group-sites-modal' ).modal( 'hide' );
320 - }, 'json' );
321 - return false;
322 - } );
323 - } );
324 - </script>
325 - <?php
326 - }
226 + if ( ! empty( $rendered_count ) ) {
227 + $rand_id_prefix = '-' . MainWP_Utility::gen_rand_id();
228 + }
327 229
328 - /**
329 - * Method render_select_clients()
330 - *
331 - * @param array $params {
332 - *
333 - * An array of params for clients selection. Default empty array.
334 - *
335 - * @type object $clients Object containing Clients info.
336 - * @type string $type Selector type.
337 - * @type array $selected_clients Selected clients.
338 - * @type bool $enable_suspended_clients (bool) True, if suspended clients is enabled. False if not.
339 - * @type mixed $tab_id Datatab ID.
340 - * }
341 - *
342 - * @return void Render Select Clients html.
343 - */
344 - public static function render_select_clients( $params = array() ) {
230 + ++$rendered_count;
345 231
346 - $clients = isset( $params['clients'] ) ? $params['clients'] : array();
347 - $type = isset( $params['type'] ) ? $params['type'] : 'checkbox';
348 - $selected_clients = isset( $params['selected_clients'] ) ? $params['selected_clients'] : array();
349 - $enableSuspendedClients = isset( $params['enable_suspended_clients'] ) ? $params['enable_suspended_clients'] : false;
232 + ?>
233 + <div id="mainwp-select-sites-select-all-actions<?php echo esc_attr( $rand_id_prefix ); ?>" class="mainwp-select-sites-select-all-actions">
234 + <div class="ui grid">
235 + <div class="ten wide middle aligned column">
236 + <span class="ui small grey text"><?php esc_html_e( 'Select:', 'mainwp' ); ?></span>
237 + <?php if ( $show_select_all ) : ?>
238 + <a href="javascript:void(0)" onClick="return mainwp_ss_select( this, true )" class="mainwp-ss-select"><span class="ui small green text"><?php esc_html_e( 'All', 'mainwp' ); ?></span></a>
239 + <span class="mainwp-ss-select ui small grey text"> · </span>
240 + <a href="javascript:void(0)" onClick="return mainwp_ss_select( this, false )" class="mainwp-ss-deselect"><span class="ui small green text"><?php esc_html_e( 'None', 'mainwp' ); ?></span></a>
241 + <?php endif; ?>
242 + </div>
243 + <div class="six wide right aligned middle aligned column">
244 + <?php if ( $show_new_tag ) : ?>
245 + <span class="mainwp-selection-counter-wrapper" id="mainwp-selection-counter-wrapper<?php echo esc_attr( $rand_id_prefix ); ?>" style="cursor:default;">
246 + <span class="mainwp-sites-selection-counter ui small grey text">0</span> <span class="ui small grey text mainwp-selected-text"><?php esc_html_e( 'selected', 'mainwp' ); ?></span>
247 + </span>
248 + <?php else : ?>
249 + <span class="mainwp-sites-selection-counter ui small grey text">0</span> <span class="ui small grey text"><?php esc_html_e( 'selected', 'mainwp' ); ?></span>
250 + <?php endif; ?>
251 + </div>
252 + </div>
253 + </div>
254 + <?php
255 + ?>
256 + <div class="ui tab <?php echo 'site' === $selectedby ? 'active' : ''; ?>" data-tab="mainwp-select-sites-<?php echo esc_attr( $tab_id ); ?>" id="mainwp-select-sites">
257 + <?php
258 + MainWP_UI::render_select_sites( $websites, $type, $selected_sites, $enableOfflineSites, $edit_site_id, $show_select_all, $add_edit_client_id, $show_selectall_disc );
259 + ?>
260 + </div>
261 + <?php if ( $staging_enabled ) { ?>
262 + <div class="ui tab <?php echo 'staging' === $selectedby ? 'active' : ''; ?>" data-tab="mainwp-select-staging-sites-<?php echo esc_attr( $tab_id ); ?>">
263 + <?php
264 + MainWP_UI::render_select_sites_staging( $selected_sites, $edit_site_id, $type );
265 + ?>
266 + </div>
267 + <?php
268 + }
350 269
351 - if ( ! is_array( $clients ) ) {
352 - $clients = array();
353 - }
270 + if ( $show_group ) {
271 + ?>
272 + <div class="ui tab <?php echo 'group' === $selectedby ? 'active' : ''; ?>" data-tab="mainwp-select-groups-<?php echo esc_attr( $tab_id ); ?>" id="mainwp-select-groups">
273 + <?php
274 + MainWP_UI::render_select_sites_group( $groups, $selected_groups, $type );
275 + ?>
276 + </div>
277 + <?php
278 + }
354 279
355 - if ( ! is_array( $selected_clients ) && ( 'all' !== $selected_clients ) ) {
356 - $selected_clients = array();
357 - }
280 + if ( $show_client ) {
281 + $clients = MainWP_DB_Client::instance()->get_wp_client_by( 'all' );
282 + $params = array(
283 + 'clients' => $clients,
284 + 'type' => $type,
285 + 'selected_clients' => $selected_clients,
286 + 'enable_suspended_clients' => $enableSuspendedClients,
287 + );
288 + ?>
289 + <div class="ui tab <?php echo 'client' === $selectedby ? 'active' : ''; ?>" data-tab="mainwp-select-clients-<?php echo esc_attr( $tab_id ); ?>" id="mainwp-select-clients">
290 + <?php
291 + static::render_select_clients( $params );
292 + ?>
293 + </div>
294 + <?php
295 + }
358 296
359 - /**
360 - * Action: mainwp_before_select_clients_list
361 - *
362 - * Fires before the Select Clients list.
363 - *
364 - * @param object $clients Object containing Clients info.
365 - *
366 - * @since 4.1
367 - */
368 - do_action( 'mainwp_before_select_clients_list', $clients );
369 - ?>
370 - <div id="mainwp-select-sites-body">
371 - <div class="ui relaxed divided list" id="mainwp-select-clients-list">
372 - <?php if ( ! $clients ) : ?>
373 - <h2 class="ui icon header">
374 - <i class="folder open outline icon"></i>
375 - <div class="content"><?php esc_html_e( 'No Clients!', 'mainwp' ); ?></div>
376 - <div class="ui divider hidden"></div>
377 - <a href="admin.php?page=ClientAddNew" class="ui green button basic"><?php esc_html_e( 'Add Client', 'mainwp' ); ?></a>
378 - </h2>
379 - <?php
380 - else :
381 - foreach ( $clients as $client ) {
382 - $selected = false;
383 - if ( 0 === (int) $client->suspended || $enableSuspendedClients ) {
384 - $selected = ( 'all' === $selected_clients || in_array( $client->client_id, $selected_clients ) );
385 - ?>
386 - <div title="<?php echo esc_html( $client->name ); ?>" class="mainwp_selected_clients_item ui <?php echo esc_html( $type ); ?> item <?php echo ( $selected ? 'selected_clients_item_checked' : '' ); ?>">
387 - <input type="<?php echo esc_attr( $type ); ?>" name="<?php echo ( 'radio' === $type ? 'selected_clients' : 'selected_clients[]' ); ?>" siteid="<?php echo intval( $client->client_id ); ?>" value="<?php echo intval( $client->client_id ); ?>" id="selected_clients_<?php echo intval( $client->client_id ); ?>" <?php echo ( $selected ? 'checked="true"' : '' ); ?> />
388 - <label for="selected_clients_<?php echo intval( $client->client_id ); ?>">
389 - <span class="client-contact-name"><?php echo esc_html( $client->name ); ?></span>
390 - </label>
391 - </div>
392 - <?php
393 - } else {
394 - ?>
395 - <div title="<?php echo esc_html( $client->name ); ?>" class="mainwp_selected_clients_item item ui <?php echo esc_html( $type ); ?> <?php echo ( $selected ? 'selected_clients_item_checked' : '' ); ?>">
396 - <input type="<?php echo esc_html( $type ); ?>" disabled="disabled"/>
397 - <label for="selected_clients_<?php echo intval( $client->client_id ); ?>">
398 - <span class="client-contact-name"><?php echo esc_html( stripslashes( $client->name ) ); ?></span>
399 - </label>
400 - </div>
401 - <?php
402 - }
403 - }
404 - endif;
405 - ?>
406 - </div>
407 - </div>
408 - <?php
409 - /**
410 - * Action: mainwp_after_select_clients_list
411 - *
412 - * Fires after the Select Clients list.
413 - *
414 - * @param object $clients Object containing Clients info.
415 - *
416 - * @since 4.1
417 - */
418 - do_action( 'mainwp_after_select_clients_list', $clients );
419 - }
297 + if ( $show_new_tag ) {
298 + static::render_create_tag_modal();
299 + }
300 + ?>
301 + <script type="text/javascript">
302 + jQuery( document ).ready( function () {
303 + // Create a new group (Select Sites UI)
304 + jQuery( document ).on( 'click', '.mainwp-save-new-tag-button', function () {
305 + let newName = jQuery( '.mainwp-create-group-sites-modal' ).find( 'input[name="mainwp-group-name"]' ).val().trim();
306 + let newColor = jQuery( '.mainwp-create-group-sites-modal' ).find( 'input[name="mainwp-group-color"]' ).val();
307 + if('' == newName ){
308 + return false;
309 + }
310 + jQuery(this).attr('disabled', 'disabled');
311 + let selected_sites = [ ];
312 + jQuery( "input[name='selected_sites[]']:checked" ).each( function () {
313 + selected_sites.push( jQuery( this ).val() );
314 + } );
315 + let data = mainwp_secure_data( {
316 + action: 'mainwp_group_sites_add',
317 + selected_sites: selected_sites,
318 + newName: newName,
319 + newColor: newColor
320 + } );
321 + jQuery.post( ajaxurl, data, function ( response ) {
322 + try {
323 + if ( response.error != undefined ){
324 + jQuery('.mainwp-message-zone-tag').show().find('.ui.message').html(response.error);
325 + return;
326 + }
327 + } catch ( err ) {
328 + // to fix js error.
329 + }
330 + jQuery( '.mainwp-create-group-sites-modal' ).modal( 'hide' );
331 + }, 'json' );
332 + return false;
333 + } );
420 334
421 - /**
422 - * Method render_create_tag_modal()
423 - *
424 - * Renders the Create Tag modal.
425 - */
426 - public static function render_create_tag_modal() {
427 - ?>
428 - <div class="ui mini modal" id="mainwp-create-group-sites-modal">
429 - <i class="close icon"></i>
430 - <div class="header"><?php echo esc_html__( 'Create Tag', 'mainwp' ); ?></div>
431 - <div class="content">
432 - <div id="mainwp-message-zone-tag" style="display: none;">
433 - <div class="ui message red"></div>
434 - </div>
435 - <div class="ui form">
436 - <div class="field">
437 - <label><?php esc_html_e( 'Enter tag name', 'mainwp' ); ?></label>
438 - <input type="text" value="" name="mainwp-group-name" id="mainwp-group-name">
439 - </div>
440 - <div class="field">
441 - <label><?php esc_html_e( 'Select tag color', 'mainwp' ); ?></label>
442 - <input type="text" name="mainwp-group-color" class="mainwp-tag-color-picker" id="mainwp-group-color" value="" />
443 - </div>
444 - </div>
445 - </div>
446 - <div class="actions">
447 - <div class="ui two columns grid">
448 - <div class="left aligned column">
449 -
450 - </div>
451 - <div class="right aligned column">
452 - <a class="ui green button" id="mainwp-save-new-tag-button" href="javascript:void(0);"><?php echo esc_html__( 'Create Tag', 'mainwp' ); ?></a>
453 - </div>
454 - </div>
455 - </div>
456 - <style>
457 - .mainwp-ui .ui.modal .wp-picker-clear {
458 - display:none;
459 - }
460 - .mainwp-ui .ui.modal #mainwp-group-color {
461 - height: 28px;
462 - margin-left: 5px;
463 - }
464 - </style>
465 - <script type="text/javascript">
466 - jQuery( document ).ready( function() {
467 - jQuery('.mainwp-tag-color-picker').wpColorPicker({
468 - hide: true,
469 - clear: false,
470 - palettes: [ '#18a4e0','#0253b3','#7fb100','#446200','#ad0000','#ffd300','#2d3b44','#6435c9','#e03997','#00b5ad' ],
471 - });
472 - } );
473 - </script>
474 - </div>
475 - <?php
476 - }
335 + if ( typeof mainwp_update_selection_counter === 'function' ) {
336 + mainwp_update_selection_counter();
337 + }
338 +
339 + jQuery( document ).on( 'click', '.mainwp-selection-counter-wrapper', function() {
340 + let counter = jQuery( this ).find( '.mainwp-sites-selection-counter' );
341 + let count = Number.parseInt( counter.text() );
342 + if ( count > 0 ) {
343 + jQuery( '.mainwp-create-group-sites-modal' ).modal( {
344 + onHide: function () {
345 + mainwp_forceReload();
346 + return false;
347 + },
348 + } ).modal( 'show' );
349 + }
350 + } );
351 +
352 + jQuery( '#mainwp-select-sites-menu .item.tab' ).on( 'click', function() {
353 + setTimeout( function() {
354 + if ( typeof mainwp_update_selection_counter === 'function' ) {
355 + mainwp_update_selection_counter();
356 + }
357 + }, 100 );
358 + } );
359 + } );
360 + </script>
361 + <?php
362 + }
363 +
364 + /**
365 + * Method render_select_clients()
366 + *
367 + * @param array $params {
368 + *
369 + * An array of params for clients selection. Default empty array.
370 + *
371 + * @type object $clients Object containing Clients info.
372 + * @type string $type Selector type.
373 + * @type array $selected_clients Selected clients.
374 + * @type bool $enable_suspended_clients (bool) True, if suspended clients is enabled. False if not.
375 + * @type mixed $tab_id Datatab ID.
376 + * }
377 + *
378 + * @return void Render Select Clients html.
379 + */
380 + public static function render_select_clients( $params = array() ) { // phpcs:ignore -- NOSONAR - complex.
381 +
382 + $clients = isset( $params['clients'] ) ? $params['clients'] : array();
383 + $type = isset( $params['type'] ) ? $params['type'] : 'checkbox';
384 + $selected_clients = isset( $params['selected_clients'] ) ? $params['selected_clients'] : array();
385 + $enableSuspendedClients = isset( $params['enable_suspended_clients'] ) ? $params['enable_suspended_clients'] : false;
386 +
387 + if ( ! is_array( $clients ) ) {
388 + $clients = array();
389 + }
390 +
391 + if ( ! is_array( $selected_clients ) && ( 'all' !== $selected_clients ) ) {
392 + $selected_clients = array();
393 + }
394 +
395 + /**
396 + * Action: mainwp_before_select_clients_list
397 + *
398 + * Fires before the Select Clients list.
399 + *
400 + * @param object $clients Object containing Clients info.
401 + *
402 + * @since 4.1
403 + */
404 + do_action( 'mainwp_before_select_clients_list', $clients );
405 +
406 + static $rendered_count = 0;
407 +
408 + $rand_id_prefix = '';
409 +
410 + if ( ! empty( $rendered_count ) ) {
411 + $rand_id_prefix = '-' . MainWP_Utility::gen_rand_id();
412 + }
413 +
414 + ++$rendered_count;
415 +
416 + ?>
417 + <div id="mainwp-select-sites-body<?php echo esc_attr( $rand_id_prefix ); ?>" class="mainwp-select-sites-items-body">
418 + <div class="ui relaxed selection list" id="mainwp-select-clients-list">
419 + <?php if ( ! $clients ) : ?>
420 + <h2 class="ui icon header">
421 + <i class="folder open outline icon"></i>
422 + <div class="content"><?php esc_html_e( 'No Clients!', 'mainwp' ); ?></div>
423 + <div class="ui divider hidden"></div>
424 + <a href="admin.php?page=ClientAddNew" class="ui green button basic"><?php esc_html_e( 'Add Client', 'mainwp' ); ?></a>
425 + </h2>
426 + <?php
427 + else :
428 + foreach ( $clients as $client ) {
429 + $selected = false;
430 + if ( 0 === (int) $client->suspended || $enableSuspendedClients ) {
431 + $selected = ( 'all' === $selected_clients || in_array( $client->client_id, $selected_clients ) );
432 + ?>
433 + <div title="<?php echo esc_html( $client->name ); ?>" class="mainwp_selected_clients_item ui <?php echo esc_html( $type ); ?> item <?php echo $selected ? 'selected_clients_item_checked' : ''; ?>">
434 + <input type="<?php echo esc_attr( $type ); ?>" name="<?php echo 'radio' === $type ? 'selected_clients' : 'selected_clients[]'; ?>" siteid="<?php echo intval( $client->client_id ); ?>" value="<?php echo intval( $client->client_id ); ?>" id="selected_clients_<?php echo intval( $client->client_id ); ?>" <?php echo $selected ? 'checked="true"' : ''; ?> />
435 + <label for="selected_clients_<?php echo intval( $client->client_id ); ?>">
436 + <span class="client-contact-name"><?php echo esc_html( $client->name ); ?></span>
437 + </label>
438 + </div>
439 + <?php
440 + } else {
441 + ?>
442 + <div title="<?php echo esc_html( $client->name ); ?>" class="mainwp_selected_clients_item item ui <?php echo esc_html( $type ); ?> <?php echo $selected ? 'selected_clients_item_checked' : ''; ?>">
443 + <input type="<?php echo esc_html( $type ); ?>" disabled="disabled"/>
444 + <label for="selected_clients_<?php echo intval( $client->client_id ); ?>">
445 + <span class="client-contact-name"><?php echo esc_html( stripslashes( $client->name ) ); ?></span>
446 + </label>
447 + </div>
448 + <?php
449 + }
450 + }
451 + endif;
452 + ?>
453 + </div>
454 + </div>
455 + <?php
456 + /**
457 + * Action: mainwp_after_select_clients_list
458 + *
459 + * Fires after the Select Clients list.
460 + *
461 + * @param object $clients Object containing Clients info.
462 + *
463 + * @since 4.1
464 + */
465 + do_action( 'mainwp_after_select_clients_list', $clients );
466 + }
467 +
468 + /**
469 + * Method render_create_tag_modal()
470 + *
471 + * Renders the Create Tag modal.
472 + */
473 + public static function render_create_tag_modal() {
474 +
475 + static $rendered_count = 0;
476 +
477 + $rand_id_prefix = '';
478 +
479 + if ( ! empty( $rendered_count ) ) {
480 + $rand_id_prefix = '-' . MainWP_Utility::gen_rand_id();
481 + }
482 +
483 + ++$rendered_count;
484 +
485 + ?>
486 + <div class="ui mini modal mainwp-create-group-sites-modal" id="mainwp-create-group-sites-modal<?php echo esc_attr( $rand_id_prefix ); ?>">
487 + <i class="close icon"></i>
488 + <div class="header"><?php echo esc_html__( 'Create Tag', 'mainwp' ); ?></div>
489 + <div class="content">
490 + <div class="mainwp-message-zone-tag" style="display: none;">
491 + <div class="ui message red"></div>
492 + </div>
493 + <div class="ui form">
494 + <div class="field">
495 + <label><?php esc_html_e( 'Enter tag name', 'mainwp' ); ?></label>
496 + <input type="text" value="" name="mainwp-group-name" id="mainwp-group-name<?php echo esc_attr( $rand_id_prefix ); ?>">
497 + </div>
498 + <div class="field">
499 + <label><?php esc_html_e( 'Select tag color', 'mainwp' ); ?></label>
500 + <input type="color" name="mainwp-group-color" class="mainwp-color-picker-input mainwp-group-color-picker" id="mainwp-group-color<?php echo esc_attr( $rand_id_prefix ); ?>" value="#ffffff" />
501 + </div>
502 + </div>
503 + </div>
504 + <div class="actions">
505 + <div class="ui two columns grid">
506 + <div class="left aligned column">
507 +
508 + </div>
509 + <div class="right aligned column">
510 + <a class="ui green button mainwp-save-new-tag-button" href="javascript:void(0);"><?php echo esc_html__( 'Create Tag', 'mainwp' ); ?></a>
511 + </div>
512 + </div>
513 + </div>
514 + <style>
515 + .mainwp-ui .ui.modal .wp-picker-clear {
516 + display:none;
517 + }
518 + .mainwp-ui .ui.modal .mainwp-group-color-picker {
519 + height: 28px;
520 + margin-left: 5px;
521 + }
522 + </style>
523 + </div>
524 + <?php
525 + }
477 526 }