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.3 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 All 156 releases
← All changes | class/class-mainwp-meta-boxes.php +241 -236 5.0.1 → 6.2.2 View file →
@@ -6,272 +6,277 @@
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_Meta_Boxes
12 17 *
13 18 * @package MainWP\Dashboard
14 19 */
15 -class MainWP_Meta_Boxes {
20 +class MainWP_Meta_Boxes { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
16 21
17 - /**
18 - * Method select_sites_handle()
19 - *
20 - * Update Post meta for Select Sites Meta boxes.
21 - *
22 - * @param mixed $post_id Post ID.
23 - * @param mixed $post_type Post type.
24 - *
25 - * @return int $post_id Post ID.
26 - */
27 - public function select_sites_handle( $post_id, $post_type ) { // phpcs:ignore -- complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
22 + /**
23 + * Method select_sites_handle()
24 + *
25 + * Update Post meta for Select Sites Meta boxes.
26 + *
27 + * @param mixed $post_id Post ID.
28 + * @param mixed $post_type Post type.
29 + *
30 + * @return int $post_id Post ID.
31 + */
32 + public function select_sites_handle( $post_id, $post_type ) { // phpcs:ignore -- NOSONAR - complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
28 33
29 - /**
30 - * Verify this came from the our screen and with proper authorization.
31 - */
32 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
33 - if ( ! isset( $_POST['select_sites_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['select_sites_nonce'] ), 'select_sites_' . $post_id ) ) {
34 - return $post_id;
35 - }
34 + /**
35 + * Verify this came from the our screen and with proper authorization.
36 + */
37 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
38 + if ( ! isset( $_POST['select_sites_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['select_sites_nonce'] ), 'select_sites_' . $post_id ) ) {
39 + return $post_id;
40 + }
36 41
37 - /**
38 - * Verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything.
39 - */
40 - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
41 - return $post_id;
42 - }
42 + /**
43 + * Verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything.
44 + */
45 + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
46 + return $post_id;
47 + }
43 48
44 - /**
45 - * Check permissions.
46 - */
47 - if ( ! current_user_can( 'edit_post', $post_id ) ) {
48 - return $post_id;
49 - }
49 + /**
50 + * Check permissions.
51 + */
52 + if ( ! current_user_can( 'edit_post', $post_id ) ) {
53 + return $post_id;
54 + }
50 55
51 - /**
52 - * OK, we're authenticated: we need to find and save the data.
53 - */
54 - $_post = get_post( $post_id );
55 - if ( $_post->post_type === $post_type && isset( $_POST['select_by'] ) ) {
56 - $selected_wp = array();
57 - if ( isset( $_POST['selected_sites'] ) ) {
58 - if ( is_array( $_POST['selected_sites'] ) ) {
59 - $selected_wp = ! empty( $_POST['selected_sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['selected_sites'] ) ) : array();
60 - } else { // radio selection.
61 - $selected_wp = ! empty( $_POST['selected_sites'] ) ? array( sanitize_text_field( wp_unslash( $_POST['selected_sites'] ) ) ) : array();
62 - }
63 - }
64 - update_post_meta( $post_id, '_selected_sites', $selected_wp );
65 - $selected_groups = array();
66 - if ( isset( $_POST['selected_groups'] ) ) {
67 - if ( is_array( $_POST['selected_groups'] ) ) {
68 - $selected_groups = ! empty( $_POST['selected_groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['selected_groups'] ) ) : array();
69 - } else { // radio selection.
70 - $selected_groups = ! empty( $_POST['selected_groups'] ) ? array( sanitize_text_field( wp_unslash( $_POST['selected_groups'] ) ) ) : array();
71 - }
72 - }
73 - update_post_meta( $post_id, '_selected_groups', $selected_groups );
74 - $selected_clients = array();
75 - if ( isset( $_POST['selected_clients'] ) ) {
76 - if ( is_array( $_POST['selected_clients'] ) ) {
77 - $selected_clients = ! empty( $_POST['selected_clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['selected_clients'] ) ) : array();
78 - } else { // radio selection.
79 - $selected_clients = ! empty( $_POST['selected_clients'] ) ? array( sanitize_text_field( wp_unslash( $_POST['selected_clients'] ) ) ) : array();
80 - }
81 - }
82 - update_post_meta( $post_id, '_selected_clients', $selected_clients );
83 - update_post_meta( $post_id, '_selected_by', sanitize_text_field( wp_unslash( $_POST['select_by'] ) ) );
56 + /**
57 + * OK, we're authenticated: we need to find and save the data.
58 + */
59 + $_post = get_post( $post_id );
60 + if ( $_post->post_type === $post_type && isset( $_POST['select_by'] ) ) {
61 + $selected_wp = array();
62 + if ( isset( $_POST['selected_sites'] ) ) {
63 + if ( is_array( $_POST['selected_sites'] ) ) {
64 + $selected_wp = ! empty( $_POST['selected_sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['selected_sites'] ) ) : array();
65 + } else { // radio selection.
66 + $selected_wp = ! empty( $_POST['selected_sites'] ) ? array( sanitize_text_field( wp_unslash( $_POST['selected_sites'] ) ) ) : array();
67 + }
68 + }
69 + update_post_meta( $post_id, '_selected_sites', $selected_wp );
70 + $selected_groups = array();
71 + if ( isset( $_POST['selected_groups'] ) ) {
72 + if ( is_array( $_POST['selected_groups'] ) ) {
73 + $selected_groups = ! empty( $_POST['selected_groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['selected_groups'] ) ) : array();
74 + } else { // radio selection.
75 + $selected_groups = ! empty( $_POST['selected_groups'] ) ? array( sanitize_text_field( wp_unslash( $_POST['selected_groups'] ) ) ) : array();
76 + }
77 + }
78 + update_post_meta( $post_id, '_selected_groups', $selected_groups );
79 + $selected_clients = array();
80 + if ( isset( $_POST['selected_clients'] ) ) {
81 + if ( is_array( $_POST['selected_clients'] ) ) {
82 + $selected_clients = ! empty( $_POST['selected_clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['selected_clients'] ) ) : array();
83 + } else { // radio selection.
84 + $selected_clients = ! empty( $_POST['selected_clients'] ) ? array( sanitize_text_field( wp_unslash( $_POST['selected_clients'] ) ) ) : array();
85 + }
86 + }
87 + update_post_meta( $post_id, '_selected_clients', $selected_clients );
88 + update_post_meta( $post_id, '_selected_by', sanitize_text_field( wp_unslash( $_POST['select_by'] ) ) );
84 89
85 - if ( ( 'group' === $_POST['select_by'] && 0 < count( $selected_groups ) ) || ( 'site' === $_POST['select_by'] && 0 < count( $selected_wp ) ) || ( 'client' === $_POST['select_by'] && 0 < count( $selected_clients ) ) ) {
86 - return sanitize_text_field( wp_unslash( $_POST['select_by'] ) );
87 - }
88 - }
89 - // phpcs:enable
90 + if ( ( 'group' === $_POST['select_by'] && ! empty( $selected_groups ) ) || ( 'site' === $_POST['select_by'] && ! empty( $selected_wp ) ) || ( 'client' === $_POST['select_by'] && ! empty( $selected_clients ) ) ) {
91 + return sanitize_text_field( wp_unslash( $_POST['select_by'] ) );
92 + }
93 + }
94 + // phpcs:enable
90 95
91 - return $post_id;
92 - }
96 + return $post_id;
97 + }
93 98
94 - /**
95 - * Method add_categories()
96 - *
97 - * Add categories.
98 - *
99 - * @param int $post_id Post ID.
100 - */
101 - public function add_categories( $post_id = false ) {
102 - if ( empty( $post_id ) ) {
103 - return;
104 - }
105 - $post = get_post( $post_id );
106 - MainWP_Post::render_categories( $post );
107 - }
99 + /**
100 + * Method add_categories()
101 + *
102 + * Add categories.
103 + *
104 + * @param int $post_id Post ID.
105 + */
106 + public function add_categories( $post_id = false ) {
107 + if ( empty( $post_id ) ) {
108 + return;
109 + }
110 + $post = get_post( $post_id );
111 + MainWP_Post::render_categories_list( $post );
112 + }
108 113
109 - /**
110 - * Method add_categories_handle()
111 - *
112 - * Handle adding categories.
113 - *
114 - * @param int $post_id Post ID.
115 - * @param string $post_type Post type.
116 - */
117 - public function add_categories_handle( $post_id, $post_type ) {
118 - /**
119 - * Verify this came from the our screen and with proper authorization.
120 - */
114 + /**
115 + * Method add_categories_handle()
116 + *
117 + * Handle adding categories.
118 + *
119 + * @param int $post_id Post ID.
120 + * @param string $post_type Post type.
121 + */
122 + public function add_categories_handle( $post_id, $post_type ) {
123 + /**
124 + * Verify this came from the our screen and with proper authorization.
125 + */
121 126
122 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
123 - if ( ! isset( $_POST['post_category_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['post_category_nonce'] ), 'post_category_' . $post_id ) ) {
124 - return;
125 - }
127 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
128 + if ( ! isset( $_POST['post_category_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['post_category_nonce'] ), 'post_category_' . $post_id ) ) {
129 + return;
130 + }
126 131
127 - /**
128 - * Verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything.
129 - */
130 - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
131 - return;
132 - }
132 + /**
133 + * Verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything.
134 + */
135 + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
136 + return;
137 + }
133 138
134 - /**
135 - * Check permissions.
136 - */
137 - if ( ! current_user_can( 'edit_post', $post_id ) ) {
138 - return;
139 - }
139 + /**
140 + * Check permissions.
141 + */
142 + if ( ! current_user_can( 'edit_post', $post_id ) ) {
143 + return;
144 + }
140 145
141 - /**
142 - * OK, we're authenticated: we need to find and save the data.
143 - */
144 - $_post = get_post( $post_id );
145 - if ( $_post->post_type === $post_type ) {
146 - if ( isset( $_POST['post_category'] ) && is_array( $_POST['post_category'] ) ) {
147 - update_post_meta( $post_id, '_categories', base64_encode( implode( ',', wp_unslash( $_POST['post_category'] ) ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
148 - do_action( 'mainwp_bulkpost_categories_handle', $post_id, wp_unslash( $_POST['post_category'] ) );
149 - }
146 + /**
147 + * OK, we're authenticated: we need to find and save the data.
148 + */
149 + $_post = get_post( $post_id );
150 + if ( $_post->post_type === $post_type ) {
151 + if ( isset( $_POST['post_category'] ) && is_array( $_POST['post_category'] ) ) {
152 + update_post_meta( $post_id, '_categories', base64_encode( implode( ',', wp_unslash( $_POST['post_category'] ) ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
153 + do_action( 'mainwp_bulkpost_categories_handle', $post_id, wp_unslash( $_POST['post_category'] ) );
154 + }
150 155
151 - $post_existing = ! empty( $_POST['post_only_existing'] ) ? 1 : 0;
152 - update_post_meta( $post_id, '_post_to_only_existing_categories', $post_existing );
156 + $post_existing = ! empty( $_POST['post_only_existing'] ) ? 1 : 0;
157 + update_post_meta( $post_id, '_post_to_only_existing_categories', $post_existing );
158 + }
159 + // phpcs:enable
160 + }
153 161
154 - return;
155 - }
156 - // phpcs:enable
157 - }
162 + /**
163 + * Method add_tags()
164 + *
165 + * Add tags to Post array.
166 + *
167 + * @param object $post Post object.
168 + */
169 + public function add_tags( $post ) {
170 + $this->add_extra( 'Tags', '_tags', 'add_tags', $post );
171 + }
158 172
159 - /**
160 - * Method add_tags()
161 - *
162 - * Add tags to Post array.
163 - *
164 - * @param object $post Post object.
165 - */
166 - public function add_tags( $post ) {
167 - $this->add_extra( 'Tags', '_tags', 'add_tags', $post );
168 - }
173 + /**
174 + * Method add_tags_handle()
175 + *
176 + * Add Tags to post array handler.
177 + *
178 + * @param int $post_id Post ID.
179 + * @param string $post_type Post type.
180 + */
181 + public function add_tags_handle( $post_id, $post_type ) {
182 + $this->add_extra_handle( 'Tags', '_tags', 'add_tags', $post_id, $post_type );
183 + if ( isset( $_POST['add_tags'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
184 + do_action( 'mainwp_bulkpost_tags_handle', $post_id, $post_type, wp_strip_all_tags( wp_unslash( $_POST['add_tags'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
185 + }
186 + }
169 187
170 - /**
171 - * Method add_tags_handle()
172 - *
173 - * Add Tags to post array handler.
174 - *
175 - * @param int $post_id Post ID.
176 - * @param string $post_type Post type.
177 - */
178 - public function add_tags_handle( $post_id, $post_type ) {
179 - $this->add_extra_handle( 'Tags', '_tags', 'add_tags', $post_id, $post_type );
180 - if ( isset( $_POST['add_tags'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
181 - do_action( 'mainwp_bulkpost_tags_handle', $post_id, $post_type, wp_strip_all_tags( wp_unslash( $_POST['add_tags'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
182 - }
183 - }
188 + /**
189 + * Method add_slug()
190 + *
191 + * Add Slug to Post object.
192 + *
193 + * @param object $post Post object.
194 + */
195 + public function add_slug( $post ) {
196 + $this->add_extra( 'Slug', '_slug', 'add_slug', $post );
197 + }
184 198
185 - /**
186 - * Method add_slug()
187 - *
188 - * Add Slug to Post object.
189 - *
190 - * @param object $post Post object.
191 - */
192 - public function add_slug( $post ) {
193 - $this->add_extra( 'Slug', '_slug', 'add_slug', $post );
194 - }
199 + /**
200 + * Method add_extra()
201 + *
202 + * Add nounce to post object.
203 + *
204 + * @param string $title Post title.
205 + * @param string $saveto Save to.
206 + * @param string $prefix Custom prefix.
207 + * @param object $post Post object.
208 + */
209 + private function add_extra( $title, $saveto, $prefix, $post ) {
210 + unset( $title );
211 + $extra = base64_decode( get_post_meta( $post->ID, $saveto, true ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_decode used for http encoding compatible.
212 + ?>
213 + <input type="hidden" name="<?php echo esc_attr( $prefix ); ?>_nonce" value="<?php echo esc_attr( wp_create_nonce( $prefix . '_' . $post->ID ) ); ?>"/>
214 + <input type="text" name="<?php echo esc_attr( $prefix ); ?>" value="<?php echo esc_attr( $extra ); ?>"/>
215 + <?php
216 + }
195 217
196 - /**
197 - * Method add_extra()
198 - *
199 - * Add nounce to post object.
200 - *
201 - * @param string $title Post title.
202 - * @param string $saveto Save to.
203 - * @param string $prefix Custom prefix.
204 - * @param object $post Post object.
205 - */
206 - private function add_extra( $title, $saveto, $prefix, $post ) {
207 - $extra = base64_decode( get_post_meta( $post->ID, $saveto, true ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_decode used for http encoding compatible.
208 - ?>
209 - <input type="hidden" name="<?php echo esc_attr( $prefix ); ?>_nonce" value="<?php echo esc_attr( wp_create_nonce( $prefix . '_' . $post->ID ) ); ?>"/>
210 - <input type="text" name="<?php echo esc_attr( $prefix ); ?>" value="<?php echo esc_attr( $extra ); ?>"/>
211 - <?php
212 - }
213 218
219 + /**
220 + * Method add_slug_handle()
221 + *
222 + * Add post slug.
223 + *
224 + * @param int $post_id Post ID.
225 + * @param string $post_type Post type.
226 + */
227 + public function add_slug_handle( $post_id, $post_type ) {
228 + $this->add_extra_handle( 'Slug', '_slug', 'add_slug', $post_id, $post_type );
229 + }
214 230
215 - /**
216 - * Method add_slug_handle()
217 - *
218 - * Add post slug.
219 - *
220 - * @param int $post_id Post ID.
221 - * @param string $post_type Post type.
222 - */
223 - public function add_slug_handle( $post_id, $post_type ) {
224 - $this->add_extra_handle( 'Slug', '_slug', 'add_slug', $post_id, $post_type );
225 - }
231 + /**
232 + * Method add_extra_handle()
233 + *
234 + * Update Post meta & add Security Nonce Prefix.
235 + *
236 + * @param string $title Post title.
237 + * @param string $saveto Where to save.
238 + * @param string $prefix Custom prefix.
239 + * @param int $post_id Post ID.
240 + * @param string $post_type Post type.
241 + *
242 + * @return int $post_id Post ID.
243 + */
244 + private function add_extra_handle( $title, $saveto, $prefix, $post_id, $post_type ) {
245 + unset( $title );
246 + /**
247 + * Verify this came from the our screen and with proper authorization.
248 + */
249 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
250 + if ( ! isset( $_POST[ $prefix . '_nonce' ] ) || ! wp_verify_nonce( sanitize_key( $_POST[ $prefix . '_nonce' ] ), $prefix . '_' . $post_id ) ) {
251 + return $post_id;
252 + }
226 253
227 - /**
228 - * Method add_extra_handle()
229 - *
230 - * Update Post meta & add Security Nonce Prefix.
231 - *
232 - * @param string $title Post title.
233 - * @param string $saveto Where to save.
234 - * @param string $prefix Custom prefix.
235 - * @param int $post_id Post ID.
236 - * @param string $post_type Post type.
237 - *
238 - * @return int $post_id Post ID.
239 - */
240 - private function add_extra_handle( $title, $saveto, $prefix, $post_id, $post_type ) {
241 - /**
242 - * Verify this came from the our screen and with proper authorization.
243 - */
244 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
245 - if ( ! isset( $_POST[ $prefix . '_nonce' ] ) || ! wp_verify_nonce( sanitize_key( $_POST[ $prefix . '_nonce' ] ), $prefix . '_' . $post_id ) ) {
246 - return $post_id;
247 - }
254 + /**
255 + * Verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything.
256 + */
257 + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
258 + return $post_id;
259 + }
248 260
249 - /**
250 - * Verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything.
251 - */
252 - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
253 - return $post_id;
254 - }
261 + /**
262 + * Check permissions.
263 + */
264 + if ( ! current_user_can( 'edit_post', $post_id ) ) {
265 + return $post_id;
266 + }
255 267
256 - /**
257 - * Check permissions.
258 - */
259 - if ( ! current_user_can( 'edit_post', $post_id ) ) {
260 - return $post_id;
261 - }
268 + /**
269 + * OK, we're authenticated: we need to find and save the data.
270 + */
271 + $_post = get_post( $post_id );
272 + if ( $_post->post_type === $post_type && isset( $_POST[ $prefix ] ) ) {
273 + $value = isset( $_POST[ $prefix ] ) ? base64_encode( wp_unslash( $_POST[ $prefix ] ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
274 + update_post_meta( $post_id, $saveto, $value );
275 + return $value;
276 + }
277 + // phpcs:enable
262 278
263 - /**
264 - * OK, we're authenticated: we need to find and save the data.
265 - */
266 - $_post = get_post( $post_id );
267 - if ( $_post->post_type === $post_type && isset( $_POST[ $prefix ] ) ) {
268 - $value = isset( $_POST[ $prefix ] ) ? base64_encode( wp_unslash( $_POST[ $prefix ] ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
269 - update_post_meta( $post_id, $saveto, $value );
270 - return $value;
271 - }
272 - // phpcs:enable
273 -
274 - return $post_id;
275 - }
279 + return $post_id;
280 + }
276 281 }
277 282 ?>