PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | pages/page-mainwp-themes-handler.php +276 -264 5.0 → 6.2.1 View file →
@@ -7,303 +7,315 @@
7 7 */
8 8
9 9 namespace MainWP\Dashboard;
10 10
11 +// Exit if accessed directly.
12 +if ( ! defined( 'ABSPATH' ) ) {
13 + exit;
14 +}
15 +
11 16 /**
12 17 * Class MainWP_Themes_Handler
13 18 *
14 19 * @uses MainWP_Install_Bulk
15 20 */
16 -class MainWP_Themes_Handler {
21 +class MainWP_Themes_Handler { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
17 22
18 - /**
19 - * Get Class Name
20 - *
21 - * @return string __CLASS__
22 - */
23 - public static function get_class_name() {
24 - return __CLASS__;
25 - }
23 + /**
24 + * Get Class Name
25 + *
26 + * @return string __CLASS__
27 + */
28 + public static function get_class_name() {
29 + return __CLASS__;
30 + }
26 31
27 - /**
28 - * Method themes_search_handler()
29 - *
30 - * Theme Search Handler.
31 - *
32 - * @param mixed $data Search data.
33 - * @param object $website The website object.
34 - * @param object $output Search results object.
35 - *
36 - * @return mixed Exception|Theme
37 - *
38 - * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message()
39 - * @uses \MainWP\Dashboard\MainWP_Exception
40 - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_child_response()
41 - */
42 - public static function themes_search_handler( $data, $website, &$output ) {
43 - if ( MainWP_Demo_Handle::get_instance()->is_demo_website( $website ) ) {
44 - return;
45 - }
46 - if ( 0 < preg_match( '/<mainwp>(.*)<\/mainwp>/', $data, $results ) ) {
47 - $result = $results[1];
48 - $result_data = MainWP_System_Utility::get_child_response( base64_decode( $result ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
49 - unset( $results );
50 - if ( isset( $result_data['error'] ) ) {
51 - $output->errors[ $website->id ] = MainWP_Error_Helper::get_error_message( new MainWP_Exception( $result_data['error'], $website->url ) );
52 - return;
53 - }
32 + /**
33 + * Method themes_search_handler()
34 + *
35 + * Theme Search Handler.
36 + *
37 + * @param mixed $data Search data.
38 + * @param object $website The website object.
39 + * @param object $output Search results object.
40 + *
41 + * @return mixed Exception|Theme
42 + *
43 + * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message()
44 + * @uses \MainWP\Dashboard\MainWP_Exception
45 + * @uses \MainWP\Dashboard\MainWP_System_Utility::get_child_response()
46 + */
47 + public static function themes_search_handler( $data, $website, &$output ) { // phpcs:ignore -- NOSONAR - complex.
48 + if ( MainWP_Demo_Handle::get_instance()->is_demo_website( $website ) ) {
49 + return;
50 + }
51 + if ( 0 < preg_match( '/<mainwp>(.*)<\/mainwp>/', $data, $results ) ) {
52 + $result = $results[1];
53 + $result_data = MainWP_System_Utility::get_child_response( base64_decode( $result ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
54 + unset( $results );
55 + if ( isset( $result_data['error'] ) ) {
56 + $output->errors[ $website->id ] = MainWP_Error_Helper::get_error_message( new MainWP_Exception( $result_data['error'], $website->url ) );
57 + return;
58 + }
54 59
55 - $themes = isset( $result_data['data'] ) && is_array( $result_data['data'] ) ? $result_data['data'] : array();
60 + $themes = isset( $result_data['data'] ) && is_array( $result_data['data'] ) ? $result_data['data'] : array();
56 61
57 - $not_found = true;
58 - foreach ( $themes as $theme ) {
59 - if ( ! isset( $theme['name'] ) ) {
60 - continue;
61 - }
62 - $theme['websiteid'] = $website->id;
63 - $theme['websiteurl'] = $website->url;
64 - $theme['websitename'] = $website->name;
62 + $not_found = true;
63 + foreach ( $themes as $theme ) {
64 + if ( ! isset( $theme['name'] ) ) {
65 + continue;
66 + }
67 + $theme['websiteid'] = $website->id;
68 + $theme['websiteurl'] = $website->url;
69 + $theme['websitename'] = $website->name;
70 + $theme['site_info'] = $website->site_info;
65 71
66 - $output->themes[] = $theme;
67 - $not_found = false;
68 - }
72 + $output->themes[] = $theme;
73 + $not_found = false;
74 + }
69 75
70 - if ( 'not_installed' === $output->status ) {
71 - if ( $not_found ) {
72 - $installed = isset( $result_data['installed_themes'] ) && is_array( $result_data['installed_themes'] ) ? $result_data['installed_themes'] : array();
73 - foreach ( $installed as $theme ) {
74 - if ( ! isset( $theme['name'] ) ) {
75 - continue;
76 - }
77 - $theme['websiteid'] = $website->id;
78 - $theme['websiteurl'] = $website->url;
79 - $theme['websitename'] = $website->name;
80 - $output->themes_installed[] = $theme;
81 - }
82 - }
83 - }
76 + if ( 'not_installed' === $output->status && $not_found ) {
77 + $installed = isset( $result_data['installed_themes'] ) && is_array( $result_data['installed_themes'] ) ? $result_data['installed_themes'] : array();
78 + foreach ( $installed as $theme ) {
79 + if ( ! isset( $theme['name'] ) ) {
80 + continue;
81 + }
82 + $theme['websiteid'] = $website->id;
83 + $theme['websiteurl'] = $website->url;
84 + $theme['websitename'] = $website->name;
85 + $theme['site_info'] = $website->site_info;
86 + $output->themes_installed[] = $theme;
87 + }
88 + }
89 + if ( ! empty( $website->rollback_updates_data ) ) {
90 + $output->roll_items[ $website->id ] = MainWP_Updates_Helper::get_roll_update_plugintheme_items( 'theme', $website->rollback_updates_data );
91 + }
92 + unset( $themes );
93 + } else {
94 + $output->errors[ $website->id ] = MainWP_Error_Helper::get_error_message( new MainWP_Exception( 'NOMAINWP', $website->url ) );
95 + }
96 + }
84 97
85 - unset( $themes );
86 - } else {
87 - $output->errors[ $website->id ] = MainWP_Error_Helper::get_error_message( new MainWP_Exception( 'NOMAINWP', $website->url ) );
88 - }
89 - }
98 + /**
99 + * Activate the selected theme.
100 + */
101 + public static function activate_theme() {
102 + $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
103 + static::action( 'activate', $theme );
104 + die( 'SUCCESS' );
105 + }
90 106
91 - /**
92 - * Activate the selected theme.
93 - */
94 - public static function activate_theme() {
95 - $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
96 - self::action( 'activate', $theme );
97 - die( 'SUCCESS' );
98 - }
107 + /**
108 + * Delete the selected theme.
109 + */
110 + public static function delete_themes() {
111 + $themes = isset( $_POST['themes'] ) ? wp_unslash( $_POST['themes'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
112 + static::action( 'delete', implode( '||', $themes ) );
113 + die( 'SUCCESS' );
114 + }
99 115
100 - /**
101 - * Delete the selected theme.
102 - */
103 - public static function delete_themes() {
104 - $themes = isset( $_POST['themes'] ) ? wp_unslash( $_POST['themes'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
105 - self::action( 'delete', implode( '||', $themes ) );
106 - die( 'SUCCESS' );
107 - }
116 + /**
117 + * Checks to see if Theme exists, current user can edit settings, check for any errors.
118 + *
119 + * @param mixed $pAction Action to perform.
120 + * @param mixed $theme Theme to perform action on.
121 + *
122 + * @throws \MainWP_Exception Error message.
123 + *
124 + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
125 + * @uses \MainWP\Dashboard\MainWP_Exception
126 + * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
127 + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
128 + */
129 + public static function action( $pAction, $theme ) {
130 + $websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
108 131
109 - /**
110 - * Checks to see if Theme exists, current user can edit settings, check for any errors.
111 - *
112 - * @param mixed $pAction Action to perform.
113 - * @param mixed $theme Theme to perform action on.
114 - *
115 - * @throws \Exception Error message.
116 - *
117 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
118 - * @uses \MainWP\Dashboard\MainWP_Exception
119 - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
120 - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
121 - */
122 - public static function action( $pAction, $theme ) {
123 - $websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
132 + if ( empty( $websiteId ) ) {
133 + die( 'FAIL' );
134 + }
124 135
125 - if ( empty( $websiteId ) ) {
126 - die( 'FAIL' );
127 - }
136 + $website = MainWP_DB::instance()->get_website_by_id( $websiteId );
137 + if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
138 + die( 'FAIL' );
139 + }
128 140
129 - $website = MainWP_DB::instance()->get_website_by_id( $websiteId );
130 - if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
131 - die( 'FAIL' );
132 - }
141 + if ( MainWP_System_Utility::is_suspended_site( $website ) ) {
142 + die(
143 + wp_json_encode(
144 + array(
145 + 'error' => esc_html__( 'Suspended site.', 'mainwp' ),
146 + 'errorCode' => 'SUSPENDED_SITE',
147 + )
148 + )
149 + );
150 + }
133 151
134 - if ( MainWP_System_Utility::is_suspended_site( $website ) ) {
135 - die(
136 - wp_json_encode(
137 - array(
138 - 'error' => esc_html__( 'Suspended site.', 'mainwp' ),
139 - 'errorCode' => 'SUSPENDED_SITE',
140 - )
141 - )
142 - );
143 - }
152 + /**
153 + * Action: mainwp_before_theme_action
154 + *
155 + * Fires before theme activate/delete actions.
156 + *
157 + * @since 4.1
158 + */
159 + do_action( 'mainwp_before_theme_action', $pAction, $theme, $website );
144 160
145 - /**
146 - * Action: mainwp_before_theme_action
147 - *
148 - * Fires before theme activate/delete actions.
149 - *
150 - * @since 4.1
151 - */
152 - do_action( 'mainwp_before_theme_action', $pAction, $theme, $website );
161 + try {
162 + $information = MainWP_Connect::fetch_url_authed(
163 + $website,
164 + 'theme_action',
165 + array(
166 + 'action' => $pAction,
167 + 'theme' => $theme,
168 + )
169 + );
170 + } catch ( MainWP_Exception $e ) {
171 + die( 'FAIL' );
172 + }
153 173
154 - try {
155 - $information = MainWP_Connect::fetch_url_authed(
156 - $website,
157 - 'theme_action',
158 - array(
159 - 'action' => $pAction,
160 - 'theme' => $theme,
161 - )
162 - );
163 - } catch ( MainWP_Exception $e ) {
164 - die( 'FAIL' );
165 - }
174 + /**
175 + * Action: mainwp_after_theme_action
176 + *
177 + * Fires after theme activate/delete actions.
178 + *
179 + * @since 4.1
180 + */
181 + do_action( 'mainwp_after_theme_action', $information, $pAction, $theme, $website );
166 182
167 - /**
168 - * Action: mainwp_after_theme_action
169 - *
170 - * Fires after theme activate/delete actions.
171 - *
172 - * @since 4.1
173 - */
174 - do_action( 'mainwp_after_theme_action', $information, $pAction, $theme, $website );
183 + if ( isset( $information['error'] ) ) {
184 + if ( is_string( $information['error'] ) ) {
185 + $information['error'] = esc_html( $information['error'] );
186 + }
187 + wp_send_json( $information );
188 + }
175 189
176 - if ( isset( $information['error'] ) ) {
177 - if ( is_string( $information['error'] ) ) {
178 - $information['error'] = esc_html( $information['error'] );
179 - }
180 - wp_send_json( $information );
181 - }
190 + if ( ! isset( $information['status'] ) || ( 'SUCCESS' !== $information['status'] ) ) {
191 + die( 'FAIL' );
192 + }
182 193
183 - if ( ! isset( $information['status'] ) || ( 'SUCCESS' !== $information['status'] ) ) {
184 - die( 'FAIL' );
185 - }
194 + die( wp_json_encode( array( 'result' => true ) ) );
195 + }
186 196
187 - die( wp_json_encode( array( 'result' => true ) ) );
188 - }
197 + /**
198 + * Check to see if Theme is on the Ignore List.
199 + *
200 + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
201 + * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
202 + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
203 + * @uses \MainWP\Dashboard\MainWP_Utility::esc_content()
204 + */
205 + public static function ignore_updates() {
206 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
207 + $websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false;
189 208
190 - /**
191 - * Check to see if Theme is on the Ignore List.
192 - *
193 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
194 - * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
195 - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
196 - * @uses \MainWP\Dashboard\MainWP_Utility::esc_content()
197 - */
198 - public static function ignore_updates() {
199 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
200 - $websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false;
209 + if ( empty( $websiteId ) ) {
210 + die( 'FAIL' );
211 + }
201 212
202 - if ( empty( $websiteId ) ) {
203 - die( 'FAIL' );
204 - }
213 + $website = MainWP_DB::instance()->get_website_by_id( $websiteId );
214 + if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
215 + die( 'FAIL' );
216 + }
205 217
206 - $website = MainWP_DB::instance()->get_website_by_id( $websiteId );
207 - if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
208 - die( 'FAIL' );
209 - }
218 + $themes = isset( $_POST['themes'] ) ? wp_unslash( $_POST['themes'] ) : array();
219 + $names = isset( $_POST['names'] ) ? wp_unslash( $_POST['names'] ) : array();
220 + // phpcs:enable
210 221
211 - $themes = isset( $_POST['themes'] ) ? wp_unslash( $_POST['themes'] ) : array();
212 - $names = isset( $_POST['names'] ) ? wp_unslash( $_POST['names'] ) : array();
213 - // phpcs:enable
222 + $decodedIgnoredThemes = json_decode( $website->ignored_themes, true );
223 + if ( ! is_array( $decodedIgnoredThemes ) ) {
224 + $decodedIgnoredThemes = array();
225 + }
214 226
215 - $decodedIgnoredThemes = json_decode( $website->ignored_themes, true );
216 - if ( ! is_array( $decodedIgnoredThemes ) ) {
217 - $decodedIgnoredThemes = array();
218 - }
227 + if ( is_array( $themes ) ) {
228 + $_count = count( $themes );
229 + for ( $i = 0; $i < $_count; $i++ ) {
230 + $slug = $themes[ $i ];
231 + $name = $names[ $i ];
232 + if ( ! isset( $decodedIgnoredThemes[ $slug ] ) ) {
233 + $decodedIgnoredThemes[ $slug ] = urldecode( $name );
234 + }
235 + }
219 236
220 - if ( is_array( $themes ) ) {
221 - $_count = count( $themes );
222 - for ( $i = 0; $i < $_count; $i++ ) {
223 - $slug = $themes[ $i ];
224 - $name = $names[ $i ];
225 - if ( ! isset( $decodedIgnoredThemes[ $slug ] ) ) {
226 - $decodedIgnoredThemes[ $slug ] = urldecode( $name );
227 - }
228 - }
237 + /**
238 + * Action: mainwp_before_theme_ignore
239 + *
240 + * Fires before theme ignore.
241 + *
242 + * @since 4.1
243 + */
244 + do_action( 'mainwp_before_theme_ignore', $website, $decodedIgnoredThemes );
245 + MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ) ) );
229 246
230 - /**
231 - * Action: mainwp_before_theme_ignore
232 - *
233 - * Fires before theme ignore.
234 - *
235 - * @since 4.1
236 - */
237 - do_action( 'mainwp_before_theme_ignore', $website, $decodedIgnoredThemes );
238 - MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ) ) );
247 + /**
248 + * Action: mainwp_after_theme_ignore
249 + *
250 + * Fires after theme ignore.
251 + *
252 + * @since 4.1
253 + */
254 + do_action( 'mainwp_after_theme_ignore', $website, $decodedIgnoredThemes );
255 + }
239 256
240 - /**
241 - * Action: mainwp_after_theme_ignore
242 - *
243 - * Fires after theme ignore.
244 - *
245 - * @since 4.1
246 - */
247 - do_action( 'mainwp_after_theme_ignore', $website, $decodedIgnoredThemes );
248 - }
257 + die( wp_json_encode( array( 'result' => true ) ) );
258 + }
249 259
250 - die( wp_json_encode( array( 'result' => true ) ) );
251 - }
260 + /**
261 + * This is the Bulk Method to Trust A Theme.
262 + *
263 + * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
264 + * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension()
265 + */
266 + public static function trust_post() { // phpcs:ignore -- NOSONAR - complex.
267 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
268 + $trustedThemes = json_decode( $userExtension->trusted_themes, true );
269 + if ( ! is_array( $trustedThemes ) ) {
270 + $trustedThemes = array();
271 + }
272 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
273 + $action = isset( $_POST['do'] ) ? sanitize_text_field( wp_unslash( $_POST['do'] ) ) : '';
274 + $slugs = isset( $_POST['slugs'] ) && is_array( $_POST['slugs'] ) ? wp_unslash( $_POST['slugs'] ) : false;
275 + // phpcs:enable
276 + if ( ! is_array( $slugs ) ) {
277 + return;
278 + }
279 + if ( 'trust' !== $action && 'untrust' !== $action ) {
280 + return;
281 + }
282 + if ( 'trust' === $action ) {
283 + foreach ( $slugs as $slug ) {
284 + $idx = array_search( urldecode( $slug ), $trustedThemes );
285 + if ( false === $idx ) {
286 + $trustedThemes[] = urldecode( $slug );
287 + }
288 + }
289 + } elseif ( 'untrust' === $action ) {
290 + foreach ( $slugs as $slug ) {
291 + if ( in_array( urldecode( $slug ), $trustedThemes ) ) {
292 + $trustedThemes = array_diff( $trustedThemes, array( urldecode( $slug ) ) );
293 + }
294 + }
295 + }
296 + $userExtension->trusted_themes = wp_json_encode( $trustedThemes );
297 + MainWP_DB_Common::instance()->update_user_extension( $userExtension );
298 + }
252 299
253 - /**
254 - * This is the Bulk Method to Trust A Theme.
255 - *
256 - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
257 - * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension()
258 - */
259 - public static function trust_post() {
260 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
261 - $trustedThemes = json_decode( $userExtension->trusted_themes, true );
262 - if ( ! is_array( $trustedThemes ) ) {
263 - $trustedThemes = array();
264 - }
265 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
266 - $action = isset( $_POST['do'] ) ? sanitize_text_field( wp_unslash( $_POST['do'] ) ) : '';
267 - $slugs = isset( $_POST['slugs'] ) && is_array( $_POST['slugs'] ) ? wp_unslash( $_POST['slugs'] ) : false;
268 - // phpcs:enable
269 - if ( ! is_array( $slugs ) ) {
270 - return;
271 - }
272 - if ( 'trust' !== $action && 'untrust' !== $action ) {
273 - return;
274 - }
275 - if ( 'trust' === $action ) {
276 - foreach ( $slugs as $slug ) {
277 - $idx = array_search( urldecode( $slug ), $trustedThemes );
278 - if ( false === $idx ) {
279 - $trustedThemes[] = urldecode( $slug );
280 - }
281 - }
282 - } elseif ( 'untrust' === $action ) {
283 - foreach ( $slugs as $slug ) {
284 - if ( in_array( urldecode( $slug ), $trustedThemes ) ) {
285 - $trustedThemes = array_diff( $trustedThemes, array( urldecode( $slug ) ) );
286 - }
287 - }
288 - }
289 - $userExtension->trusted_themes = wp_json_encode( $trustedThemes );
290 - MainWP_DB_Common::instance()->update_user_extension( $userExtension );
291 - }
292 -
293 - /** This Method Saves a Trusted theme note. */
294 - public static function save_trusted_theme_note() {
295 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
296 - $slug = isset( $_POST['slug'] ) ? urldecode( sanitize_text_field( wp_unslash( $_POST['slug'] ) ) ) : '';
297 - $note = isset( $_POST['note'] ) ? wp_unslash( $_POST['note'] ) : '';
298 - // phpcs:enable
299 - $esc_note = MainWP_Utility::esc_content( $note );
300 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
301 - $trustedThemesNotes = json_decode( $userExtension->trusted_themes_notes, true );
302 - if ( ! is_array( $trustedThemesNotes ) ) {
303 - $trustedThemesNotes = array();
304 - }
305 - $trustedThemesNotes[ $slug ] = $esc_note;
306 - $userExtension->trusted_themes_notes = wp_json_encode( $trustedThemesNotes );
307 - MainWP_DB_Common::instance()->update_user_extension( $userExtension );
308 - }
300 + /**
301 + * This Method Saves a Trusted theme note.
302 + *
303 + * @return string Escaped note.
304 + */
305 + public static function save_trusted_theme_note() {
306 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
307 + $slug = isset( $_POST['slug'] ) ? urldecode( sanitize_text_field( wp_unslash( $_POST['slug'] ) ) ) : '';
308 + $note = isset( $_POST['note'] ) ? wp_unslash( $_POST['note'] ) : '';
309 + // phpcs:enable
310 + $esc_note = MainWP_Utility::esc_content( $note );
311 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
312 + $trustedThemesNotes = json_decode( $userExtension->trusted_themes_notes, true );
313 + if ( ! is_array( $trustedThemesNotes ) ) {
314 + $trustedThemesNotes = array();
315 + }
316 + $trustedThemesNotes[ $slug ] = $esc_note;
317 + $userExtension->trusted_themes_notes = wp_json_encode( $trustedThemesNotes );
318 + MainWP_DB_Common::instance()->update_user_extension( $userExtension );
319 + return $esc_note;
320 + }
309 321 }