PluginProbe
Responsive Menu – Mobile Menu & Hamburger Menu Builder / 4.7.4
Responsive Menu – Mobile Menu & Hamburger Menu Builder v4.7.4
4.7.4 4.7.3 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 All 91 releases
← All changes | v4.0.0/inc/classes/class-admin.php +233 -238 4.1.3 → 4.7.4 View file →
@@ -1,16 +1,17 @@
1 1 <?php
2 2 /**
3 3 * Admin class.
4 4 * This is core class which is responsible for admin functionality.
5 - *
5 + *
6 6 * @version 4.0.0
7 7 * @author Expresstech System
8 - *
9 - * @package responsive-menu-pro
8 + *
9 + * @package responsive-menu
10 10 */
11 11
12 12 namespace RMP\Features\Inc;
13 +
13 14 use RMP\Features\Inc\Traits\Singleton;
14 15 use RMP\Features\Inc\RMP_Menu;
15 16 use RMP\Features\Inc\Theme_Manager;
16 17 use RMP\Features\Inc\Option_Manager;
@@ -16,14 +17,13 @@
16 17 use RMP\Features\Inc\Option_Manager;
17 18
18 19 // Disable the direct access to this class.
19 20 if ( ! defined( 'ABSPATH' ) ) {
20 - exit;
21 + exit;
21 22 }
22 23
23 24 /**
24 25 * Class Admin
25 - *
26 26 */
27 27 class Admin {
28 28
29 29 use Singleton;
@@ -49,128 +49,109 @@
49 49 *
50 50 * @return void
51 51 */
52 52 protected function setup_hooks() {
53 + add_action( 'wp_ajax_rmp_save_global_settings', array( $this, 'save_menu_global_settings' ) );
54 + add_action( 'wp_ajax_rmp_create_new_menu', array( $this, 'create_new_menu' ) );
55 + add_action( 'wp_ajax_rmp_export_menu', array( $this, 'rmp_export_menu' ) );
56 + add_action( 'wp_ajax_rmp_import_menu', array( $this, 'rmp_import_menu' ) );
53 57
54 - add_action( 'wp_ajax_rmp_save_global_settings', [ $this, 'save_menu_global_settings' ] );
55 - add_action( 'wp_ajax_rmp_rollback_version', [ $this, 'rollback_version' ] );
56 - add_action( 'wp_ajax_rmp_create_new_menu', [ $this, 'create_new_menu' ] );
57 - add_action( 'wp_ajax_rmp_export_menu', [ $this, 'rmp_export_menu' ] );
58 - add_action( 'wp_ajax_rmp_import_menu', [ $this, 'rmp_import_menu' ] );
59 -
60 - add_shortcode( 'rmp_menu', [ $this, 'register_menu_shortcode' ] );
61 - add_action( 'init', array($this,'rmp_menu_cpt'), 0 );
58 + add_shortcode( 'rmp_menu', array( $this, 'register_menu_shortcode' ) );
59 + add_shortcode( 'responsive_menu', array( $this, 'responsive_menu_shortcode' ) );
60 + add_action( 'init', array( $this, 'rmp_menu_cpt' ), 0 );
62 61
63 - add_filter( 'post_row_actions', array($this,'rmp_menu_row_actions'), 10, 2 );
64 - add_filter( 'get_edit_post_link', [ $this, 'my_edit_post_link' ], 10, 2 );
62 + add_filter( 'post_row_actions', array( $this, 'rmp_menu_row_actions' ), 10, 2 );
63 + add_filter( 'get_edit_post_link', array( $this, 'rmp_edit_post_link' ), 10, 2 );
65 64
66 - add_filter( 'manage_rmp_menu_posts_columns', array($this,'set_custom_edit_menu_columns') );
67 - add_action( 'manage_rmp_menu_posts_custom_column' , array($this,'add_custom_columns'), 10, 2 );
68 - add_action( 'admin_footer' , array($this,'add_new_menu_widget') );
65 + add_filter( 'manage_rmp_menu_posts_columns', array( $this, 'set_custom_edit_menu_columns' ) );
66 + add_action( 'manage_rmp_menu_posts_custom_column', array( $this, 'add_custom_columns' ), 10, 2 );
67 + add_action( 'admin_footer', array( $this, 'add_new_menu_widget' ) );
69 68 add_action( 'admin_menu', array( $this, 'rmp_register_submenu_page' ) );
70 - add_action( 'admin_menu', [$this, 'remove_default_add_cpt_page']);
71 - add_action( 'rmp_create_new_menu', array( $this , 'set_global_options' ), 10 , 0 );
69 + add_action( 'admin_menu', array( $this, 'remove_default_add_cpt_page' ) );
70 + add_action( 'rmp_create_new_menu', array( $this, 'set_global_options' ), 10, 0 );
72 71 }
73 72
74 73 /**
75 74 * Function to save the global settings of setting page.
76 - *
75 + *
77 76 * @return json
78 77 */
79 78 public function save_menu_global_settings() {
80 -
81 79 check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
80 + if ( ! current_user_can( 'administrator' ) ) {
81 + wp_send_json_error( __( 'You can\'t edit global settings!', 'responsive-menu' ) );
82 + }
82 83
83 - $options = array();
84 - parse_str( $_POST['form'], $options );
84 + $options = array();
85 + $form_data = isset( $_POST['form'] ) ? rm_sanitize_rec_array( wp_unslash( $_POST['form'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
86 + wp_parse_str( $form_data, $options );
85 87
86 - foreach( $options as $key => $value ) {
87 - $options[$key] = sanitize_text_field( $value );
88 + foreach ( $options as $key => $value ) {
89 + $options[ $key ] = sanitize_text_field( $value );
88 90 }
89 91
90 92 update_option( 'rmp_global_setting_options', $options );
91 -
93 +
92 94 /**
93 95 * Fires after global settings is saved.
94 - *
96 + *
95 97 * @since 4.0.0
96 - *
98 + *
97 99 * @param array $option List of global settings.
98 100 */
99 101 do_action( 'rmp_save_global_settings', $options );
100 102
101 - wp_send_json_success( 'Saved' );
103 + wp_send_json_success( __( 'Saved', 'responsive-menu' ) );
102 104 }
103 105
104 106 /**
105 - * Rollback to older version from setting page.
107 + * Function to create a new theme.
106 108 *
107 - * @since 4.0.0
108 - *
109 - * @return void
110 - */
111 - public function rollback_version() {
112 -
113 - if ( empty ( update_option( 'is_rmp_new_version', 0 ) ) ) {
114 - add_option( 'is_rmp_new_version', 0 );
115 - }
116 -
117 - wp_send_json_success( ['redirect' => admin_url('admin.php?page=responsive-menu')] );
118 - }
119 -
120 - /**
121 - * Function to create a new theme.
109 + * @since 4.0.0
122 110 *
123 - * @since 4.0.0
124 - *
125 111 * @return json
126 112 */
127 113 public function create_new_menu() {
114 + check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
128 115
129 - check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
116 + if ( ! current_user_can( 'administrator' ) ) {
117 + wp_send_json_error( array( 'message' => __( 'You can not create menu !', 'responsive-menu' ) ) );
118 + }
130 119
131 - $menu_name = sanitize_text_field( $_POST['menu_name'] );
120 + $menu_name = isset( $_POST['menu_name'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_name'] ) ) : '';
132 121 if ( empty( $menu_name ) ) {
133 - wp_send_json_error( [ 'message' => __('Enter the Menu name !', 'responsive-menu-pro') ] );
122 + wp_send_json_error( array( 'message' => __( 'Enter the Menu name !', 'responsive-menu' ) ) );
134 123 }
135 124
136 - $menu_to_use = sanitize_text_field( $_POST['menu_to_use'] );
125 + $menu_to_use = isset( $_POST['menu_to_use'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_to_use'] ) ) : '';
137 126 if ( empty( $menu_to_use ) ) {
138 - wp_send_json_error( [ 'message' => __('Select menu to use !', 'responsive-menu-pro') ] );
127 + wp_send_json_error( array( 'message' => __( 'Select menu to use !', 'responsive-menu' ) ) );
139 128 }
140 129
141 - $menu_to_hide = sanitize_text_field( $_POST['menu_to_hide'] );
130 + $menu_to_hide = isset( $_POST['menu_to_hide'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_to_hide'] ) ) : '';
142 131
143 - $menu_theme = '';
144 - if ( ! empty( $_POST['menu_theme'] ) ) {
145 - $menu_theme = sanitize_text_field( $_POST['menu_theme'] );
146 - }
132 + $menu_theme = isset( $_POST['menu_theme'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_theme'] ) ) : '';
147 133
148 - $theme_type = '';
149 - if ( ! empty( $_POST['theme_type'] ) ) {
150 - $theme_type = sanitize_text_field( $_POST['theme_type'] );
151 - }
134 + $theme_type = isset( $_POST['theme_type'] ) ? sanitize_text_field( wp_unslash( $_POST['theme_type'] ) ) : '';
152 135
153 - $menu_show_on = sanitize_text_field( $_POST['menu_show_on'] );
136 + $menu_show_on = isset( $_POST['menu_show_on'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_show_on'] ) ) : '';
154 137
155 - $menu_show_on_pages = [];
138 + $menu_show_on_pages = array();
156 139 if ( ! empty( $_POST['menu_show_on_pages'] ) && is_array( $_POST['menu_show_on_pages'] ) ) {
157 - foreach ( $_POST['menu_show_on_pages'] as $key => $val ) {
158 - $menu_show_on_pages[ $key ] = sanitize_text_field( $val );
159 - }
140 + $menu_show_on_pages = rm_sanitize_rec_array( wp_unslash( $_POST['menu_show_on_pages'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
160 141 }
161 142
162 - $theme_options = [];
143 + $theme_options = array();
163 144
164 145 // Get appropriate theme as per theme type and theme name.
165 146 if ( ! empty( $theme_type ) && 'downloaded' == $theme_type ) {
166 - $theme_manager = Theme_Manager::get_instance();
167 - $theme_options = $theme_manager->get_available_theme_settings( $menu_theme );
168 - } else if ( ! empty( $theme_type ) && 'template' == $theme_type ) {
169 - $theme_manager = Theme_Manager::get_instance();
170 - $theme_options = $theme_manager->get_saved_theme_options( $menu_theme );
147 + $theme_manager = Theme_Manager::get_instance();
148 + $theme_options = $theme_manager->get_available_theme_settings( $menu_theme );
149 + } elseif ( ! empty( $theme_type ) && 'template' == $theme_type ) {
150 + $theme_manager = Theme_Manager::get_instance();
151 + $theme_options = $theme_manager->get_saved_theme_options( $menu_theme );
171 152 } else {
172 - $theme_options = rmp_get_default_options();
153 + $theme_options = rmp_get_default_options();
173 154 }
174 155
175 156 // Create menu as post with rmp_menu cpt.
176 157 $new_menu = array(
@@ -182,46 +163,43 @@
182 163
183 164 $menu_id = wp_insert_post( $new_menu );
184 165
185 166 $new_options = array(
186 - 'menu_name' => $menu_name,
187 - 'menu_to_use' => $menu_to_use,
188 - 'menu_theme' => $menu_theme,
189 - 'theme_type' => $theme_type,
190 - 'menu_display_on' => $menu_show_on,
191 - 'menu_show_on_pages' => $menu_show_on_pages,
192 - 'menu_id' => $menu_id,
193 - 'menu_to_hide' => $menu_to_hide
194 - );
167 + 'menu_name' => $menu_name,
168 + 'menu_to_use' => $menu_to_use,
169 + 'menu_theme' => $menu_theme,
170 + 'theme_type' => $theme_type,
171 + 'menu_display_on' => $menu_show_on,
172 + 'menu_show_on_pages' => $menu_show_on_pages,
173 + 'menu_id' => $menu_id,
174 + 'menu_to_hide' => $menu_to_hide,
175 + );
195 176
196 - $new_options = array_merge( $theme_options , $new_options );
177 + $new_options = array_merge( $theme_options, $new_options );
197 178
198 179 if ( ! empty( $menu_id ) ) {
180 + update_post_meta( $menu_id, 'rmp_menu_meta', $new_options );
199 181
200 - update_post_meta( $menu_id, 'rmp_menu_meta', $new_options);
201 -
202 182 /**
203 183 * Fires when menu is created and options is saved.
204 - *
184 + *
205 185 * @param int $menu_id Menu ID.
206 186 */
207 187 do_action( 'rmp_create_new_menu', $menu_id );
208 188
209 189 wp_send_json_success(
210 - [
211 - 'message' => __('Menu is created successfully', 'responsive-menu-pro'),
190 + array(
191 + 'message' => __( 'Menu is created successfully', 'responsive-menu' ),
212 192 'customize_url' => sprintf(
213 193 '%spost.php?post=%s&action=edit&editor=true',
214 194 get_admin_url(),
215 195 $menu_id
216 - )
217 - ]
196 + ),
197 + )
218 198 );
219 -
220 199 } else {
221 - wp_send_json_error( [ 'message' => __( 'Unable to create new Menu !', 'responsive-menu-pro' ) ] );
200 + wp_send_json_error( array( 'message' => __( 'Unable to create new Menu !', 'responsive-menu' ) ) );
222 201 }
223 -
224 202 }
225 203
226 204 /**
227 205 * This function register the shortcode for menu.
@@ -226,28 +204,27 @@
226 204 /**
227 205 * This function register the shortcode for menu.
228 206 *
229 207 * @since 4.0.0
230 - *
231 - * @param Array $atts Attributes List.
232 - * @param string $content It contain text from shortcode.
233 - *
208 + *
209 + * @param Array $atts Attributes List.
210 + *
234 211 * @return HTML $output Menu contents.
235 212 */
236 - public function register_menu_shortcode( $attrs = [] ) {
213 + public function register_menu_shortcode( $attrs = array() ) {
214 + $attrs = shortcode_atts( array( 'id' => '' ), $attrs );
237 215
238 - $attrs = shortcode_atts( [ 'id' => '' ], $attrs );
239 -
240 216 $attrs = array_change_key_case( (array) $attrs, CASE_LOWER );
241 217
242 218 // Check given id is valid.
243 219 if ( empty( $attrs['id'] ) ) {
244 - return __( 'Please pass menu id as attribute.', 'responsive-menu-pro' );
220 + return __( 'Please pass menu id as attribute.', 'responsive-menu' );
245 221 }
246 222
247 - $menu_id = $attrs['id'];
223 + $menu_id = $attrs['id'];
248 224 if ( 'publish' !== get_post_status( $menu_id ) ) {
249 - return __( "Shortcode with menu id $menu_id is not published.", 'responsive-menu-pro' );
225 + /* translators: %d: Menu id */
226 + return sprintf( __( 'Shortcode with menu id %d is not published.', 'responsive-menu' ), esc_html( $menu_id ) );
250 227 }
251 228
252 229 // Check shortcode option is activated or not.
253 230 $option_manager = Option_Manager::get_instance();
@@ -253,9 +230,9 @@
253 230 $option_manager = Option_Manager::get_instance();
254 231 $option = $option_manager->get_option( $menu_id, 'menu_display_on' );
255 232
256 233 if ( 'shortcode' !== $option ) {
257 - return __( 'Shortcode deactivated', 'responsive-menu-pro' );
234 + return __( 'Shortcode deactivated', 'responsive-menu' );
258 235 }
259 236
260 237 ob_start();
261 238
@@ -265,20 +242,50 @@
265 242 return ob_get_clean();
266 243 }
267 244
268 245 /**
246 + * This function register the shortcode for responsive_menu.
247 + *
248 + * @since 4.1.7
249 + *
250 + * @return HTML $output Menu contents.
251 + */
252 + public function responsive_menu_shortcode() {
253 +
254 + // Check shortcode option is activated or not.
255 + $options = Option_Manager::get_instance();
256 + $menu_ids = get_all_rmp_menu_ids();
257 +
258 + if ( ! empty( $menu_ids ) ) {
259 + foreach ( $menu_ids as $menu_id ) {
260 +
261 + $menu_show_on = $options->get_option( $menu_id, 'menu_display_on' );
262 + if ( ! empty( $menu_show_on ) && 'shortcode' !== $menu_show_on ) {
263 + continue;
264 + }
265 +
266 + ob_start();
267 + $menu = new RMP_Menu( $menu_id );
268 + $menu->build_menu();
269 + return ob_get_clean();
270 + }
271 + } else {
272 + return __( 'Shortcode deactivated', 'responsive-menu' );
273 + }
274 + }
275 +
276 + /**
269 277 * Function to update the global options.
270 - *
278 + *
271 279 * @since 4.0.0
272 - *
280 + *
273 281 * @return void
274 282 */
275 283 public function set_global_options() {
276 -
277 284 $global_settings = get_option( 'rmp_global_setting_options' );
278 - if( empty( $global_settings ) ) {
285 + if ( empty( $global_settings ) ) {
279 286 $default_options = rmp_global_default_setting_options();
280 - update_option( 'rmp_global_setting_options', $default_options );
287 + update_option( 'rmp_global_setting_options', $default_options );
281 288 }
282 289 }
283 290
284 291 /**
@@ -283,59 +290,34 @@
283 290
284 291 /**
285 292 * Add sub menu pages in responsive menu admin.
286 293 *
287 - * @since 4.0.0
294 + * @since 4.0.0
288 295 */
289 296 public function rmp_register_submenu_page() {
290 -
291 297 add_submenu_page(
292 298 'edit.php?post_type=rmp_menu',
293 - __( 'Settings', 'responsive-menu-pro' ),
294 - __( 'Settings', 'responsive-menu-pro' ),
299 + __( 'Settings', 'responsive-menu' ),
300 + __( 'Settings', 'responsive-menu' ),
295 301 'manage_options',
296 302 'settings',
297 303 array( $this, 'rmp_global_settings_page' )
298 304 );
299 305
300 - add_submenu_page (
306 + add_submenu_page(
301 307 'edit.php?post_type=rmp_menu',
302 - __( 'Themes', 'responsive-menu-pro' ),
303 - __( 'Themes', 'responsive-menu-pro' ),
308 + __( 'Themes', 'responsive-menu' ),
309 + __( 'Themes', 'responsive-menu' ),
304 310 'manage_options',
305 311 'themes',
306 312 array( $this, 'rmp_theme_admin_page' )
307 313 );
308 -
309 - add_submenu_page (
310 - 'edit.php?post_type=rmp_menu',
311 - __( 'What\'s Next', 'responsive-menu-pro' ),
312 - __( 'What\'s Next', 'responsive-menu-pro' ),
313 - 'manage_options',
314 - 'whats-next',
315 - array( $this, 'rmp_roadmap_admin_page' )
316 - );
317 -
318 314 }
319 315
320 316 /**
321 - * Add template for roadmap page.
322 - *
323 - * @since 4.0.1
324 - */
325 - public function rmp_roadmap_admin_page() {
326 - // Check user capabilities.
327 - if ( ! current_user_can( 'manage_options' ) ) {
328 - return;
329 - }
330 -
331 - include_once RMP_PLUGIN_PATH_V4 . '/templates/rmp-roadmap.php';
332 - }
333 -
334 - /**
335 317 * Add template to the themes page.
336 318 *
337 - * @since 4.0.0
319 + * @since 4.0.0
338 320 */
339 321 public function rmp_theme_admin_page() {
340 322
341 323 // Check user capabilities.
@@ -348,10 +330,10 @@
348 330
349 331 /**
350 332 * Add template to the setting page.
351 333 *
352 - * @since 4.0.0
353 - *
334 + * @since 4.0.0
335 + *
354 336 * @return void
355 337 */
356 338 public function rmp_global_settings_page() {
357 339
@@ -364,47 +346,47 @@
364 346 }
365 347
366 348 /**
367 349 * Remove create new menu default link of rmp_menu post type.
368 - *
350 + *
369 351 * @since 4.0.0
370 - *
352 + *
371 353 * @return void
372 354 */
373 - function remove_default_add_cpt_page() {
355 + public function remove_default_add_cpt_page() {
374 356 remove_submenu_page( 'edit.php?post_type=rmp_menu', 'post-new.php?post_type=rmp_menu' );
375 357 }
376 358
377 359 /**
378 360 * Function to add the new menu wizard template.
379 - *
361 + *
380 362 * @since 4.0.0
381 - *
363 + *
382 364 * @return void
383 365 */
384 366 public function add_new_menu_widget() {
385 367 $screen = get_current_screen();
386 - if ( $screen->id === 'edit-rmp_menu' ) {
387 - include_once RMP_PLUGIN_PATH_V4 . '/templates/new-menu-wizard.php';
368 + if ( 'edit-rmp_menu' === $screen->id ) {
369 + include_once RMP_PLUGIN_PATH_V4 . '/templates/new-menu-wizard.php';
388 370 }
389 371 }
390 372
391 373 /**
392 374 * Function to change the edit label and url.
375 + *
393 376 * @since 4.0.0
394 - *
395 - * @param array $actions List of post row actions.
377 + *
378 + * @param array $actions List of post row actions.
396 379 * @param Object $post Post object
397 - *
380 + *
398 381 * @return array $actions
399 382 */
400 383 public function rmp_menu_row_actions( $actions, $post ) {
401 -
402 384 if ( 'rmp_menu' == $post->post_type ) {
403 385 $actions['edit'] = sprintf(
404 386 '<a href="%s" aria-label="Edit">%s</a>',
405 387 esc_url( get_edit_post_link( $post->ID ) ),
406 - __( 'Customize', 'responsive-menu-pro' )
388 + __( 'Customize', 'responsive-menu' )
407 389 );
408 390 }
409 391
410 392 return $actions;
@@ -411,21 +393,20 @@
411 393 }
412 394
413 395 /**
414 396 * Function to add the custom column.
415 - *
397 + *
416 398 * @since 4.0.0
417 - *
399 + *
418 400 * @param array $columns List of columns.
419 - *
420 - * @return array $columns Edited columns list.
401 + *
402 + * @return array $columns Edited columns list.
421 403 */
422 - public function set_custom_edit_menu_columns($columns) {
423 -
404 + public function set_custom_edit_menu_columns( $columns ) {
424 405 unset( $columns['date'] );
425 - $columns['shortcode_place'] = __( 'Shortcode', 'responsive-menu-pro' );
426 - $columns['actions'] = __( 'Actions', 'responsive-menu-pro' );
427 - $columns['date'] = __( 'Date', 'responsive-menu-pro' );
406 + $columns['shortcode_place'] = __( 'Shortcode', 'responsive-menu' );
407 + $columns['actions'] = __( 'Actions', 'responsive-menu' );
408 + $columns['date'] = __( 'Date', 'responsive-menu' );
428 409
429 410 return $columns;
430 411 }
431 412
@@ -430,20 +411,19 @@
430 411 }
431 412
432 413 /**
433 414 * Function to change the edit url of post type rmp_menu
434 - *
415 + *
435 416 * @since 4.0.0
436 - *
417 + *
437 418 * @param string $url Post edit URL.
438 419 * @param int $post_id Post ID
439 - *
420 + *
440 421 * @return string $url Edited post url URL
441 422 */
442 - public function my_edit_post_link( $url, $post_id ) {
443 -
444 - if ( 'rmp_menu' == get_post_type() ) {
445 - $url = get_admin_url() .'post.php?post='. $post_id .'&action=edit&editor=true';
423 + public function rmp_edit_post_link( $url, $post_id ) {
424 + if ( 'rmp_menu' === get_post_type() && current_user_can( 'edit_post', $post_id ) ) {
425 + $url = get_admin_url() . 'post.php?post=' . $post_id . '&action=edit&editor=true';
446 426 }
447 427
448 428 return $url;
449 429 }
@@ -449,39 +429,35 @@
449 429 }
450 430
451 431 /**
452 432 * Function to add the data to the custom columns for the rmp_menu post type.
453 - *
433 + *
454 434 * @since 4.0.0
455 - *
435 + *
456 436 * @param string $column Column Name
457 437 * @param int $post_id Post ID
458 - *
438 + *
459 439 * @return void
460 440 */
461 - function add_custom_columns( $column, $post_id ) {
441 + public function add_custom_columns( $column, $post_id ) {
462 442 $option_manager = Option_Manager::get_instance();
463 443
464 444 switch ( $column ) {
465 445
466 - case 'actions' :
467 - echo sprintf(
468 - '<a href="%s" class="button" aria-label="Customize">%s</a>',
469 - esc_url( get_edit_post_link( $post_id) ),
470 - __( 'Customize', 'responsive-menu-pro' )
471 - );
446 + case 'actions':
447 + ?><a href="<?php echo esc_url( get_edit_post_link( $post_id ) ); ?>" class="button" aria-label="Customize"><?php esc_html_e( 'Customize', 'responsive-menu' ); ?></a>
448 + <?php
472 449 break;
473 - case 'shortcode_place' :
474 -
475 - $option = $option_manager->get_option( $post_id, 'menu_display_on' );
476 - if( 'shortcode' === $option ) {
477 - echo sprintf('<code>[rmp_menu id="%s"]</code>', $post_id );
450 + case 'shortcode_place':
451 + $option = $option_manager->get_option( $post_id, 'menu_display_on' );
452 + if ( 'shortcode' === $option ) {
453 + ?>
454 + <code>[rmp_menu id="<?php echo esc_attr( $post_id ); ?>"]</code>
455 + <?php
478 456 } else {
479 - esc_html_e( 'Shortcode deactivated', 'responsive-menu-pro' );
457 + esc_html_e( 'Shortcode deactivated', 'responsive-menu' );
480 458 }
481 -
482 - break;
483 -
459 + break;
484 460 }
485 461 }
486 462
487 463 /**
@@ -496,28 +472,28 @@
496 472 return;
497 473 }
498 474
499 475 $labels = array(
500 - 'name' => __( 'Responsive Menu', 'responsive-menu-pro' ),
501 - 'singular_name' => 'Rmp_Menu',
502 - 'menu_name' => __( 'Responsive Menu', 'responsive-menu-pro' ),
503 - 'parent_item_colon' => __( 'Parent Menu', 'responsive-menu-pro' ),
504 - 'all_items' => __( 'Menus', 'responsive-menu-pro' ),
505 - 'view_item' => __( 'View Menu', 'responsive-menu-pro' ),
506 - 'add_new_item' => __( 'Add New Menu', 'responsive-menu-pro' ),
507 - 'add_new' => __( 'Create New Menu', 'responsive-menu-pro' ),
508 - 'edit_item' => __( 'Edit Menu', 'responsive-menu-pro' ),
509 - 'update_item' => __( 'Update Menu', 'responsive-menu-pro' ),
510 - 'search_items' => __( 'Search Menu', 'responsive-menu-pro' ),
511 - 'not_found' => __( 'Not Found', 'responsive-menu-pro' ),
512 - 'not_found_in_trash' => __( 'Not found in Trash', 'responsive-menu-pro' )
476 + 'name' => __( 'Responsive Menu', 'responsive-menu' ),
477 + 'singular_name' => __( 'Responsive Menu', 'responsive-menu' ),
478 + 'menu_name' => __( 'Responsive Menu', 'responsive-menu' ),
479 + 'parent_item_colon' => __( 'Parent Menu', 'responsive-menu' ),
480 + 'all_items' => __( 'Menus', 'responsive-menu' ),
481 + 'view_item' => __( 'View Menu', 'responsive-menu' ),
482 + 'add_new_item' => __( 'Add New Menu', 'responsive-menu' ),
483 + 'add_new' => __( 'Create New Menu', 'responsive-menu' ),
484 + 'edit_item' => __( 'Edit Menu', 'responsive-menu' ),
485 + 'update_item' => __( 'Update Menu', 'responsive-menu' ),
486 + 'search_items' => __( 'Search Menu', 'responsive-menu' ),
487 + 'not_found' => __( 'Not Found', 'responsive-menu' ),
488 + 'not_found_in_trash' => __( 'Not found in Trash', 'responsive-menu' ),
513 489 );
514 490
515 491 $args = array(
516 - 'label' => __( 'Responsive Menu', 'responsive-menu-pro' ),
517 - 'description' => __( 'Responsive Menu' , 'responsive-menu-pro' ),
492 + 'label' => __( 'Responsive Menu', 'responsive-menu' ),
493 + 'description' => __( 'Responsive Menu', 'responsive-menu' ),
518 494 'labels' => $labels,
519 - 'supports' => array( 'title', 'author'),
495 + 'supports' => array( 'title', 'author' ),
520 496 'public' => false,
521 497 'hierarchical' => false,
522 498 'show_ui' => true,
523 499 'show_in_menu' => true,
@@ -525,12 +501,12 @@
525 501 'show_in_admin_bar' => false,
526 502 'has_archive' => false,
527 503 'can_export' => false,
528 504 'exclude_from_search' => true,
529 - 'taxonomies' => array(),
505 + 'taxonomies' => array(),
530 506 'publicly_queryable' => false,
531 507 'capability_type' => 'post',
532 - 'menu_icon' => RMP_PLUGIN_URL_V4 .'/assets/images/rmp-logo.png'
508 + 'menu_icon' => RMP_PLUGIN_URL_V4 . '/assets/images/rmp-logo.png',
533 509 );
534 510
535 511 register_post_type( 'rmp_menu', $args );
536 512
@@ -535,8 +511,9 @@
535 511 register_post_type( 'rmp_menu', $args );
536 512
537 513 /**
538 514 * This action will be useful when need hooks after cpt register.
515 + *
539 516 * @param CPT rmp_menu
540 517 */
541 518 do_action( 'rmp_after_cpt_registered', 'rmp_menu' );
542 519 }
@@ -543,76 +520,94 @@
543 520
544 521 /**
545 522 * Function to export the menu
546 523 *
547 - * @since 4.0.0
548 - *
524 + * @since 4.0.0
525 + *
549 526 * @return json
550 527 */
551 528 public function rmp_export_menu() {
529 + check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
552 530
553 - check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
531 + $menu_id = isset( $_POST['menu_id'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_id'] ) ) : '';
554 532
555 - $menu_id = sanitize_text_field( $_POST['menu_id'] );
556 533 if ( empty( $menu_id ) ) {
557 - wp_send_json_error( [ 'message' => __('Select menu !', 'responsive-menu-pro') ] );
534 + wp_send_json_error( array( 'message' => __( 'Select menu !', 'responsive-menu' ) ) );
558 535 }
559 536
537 + if ( ! current_user_can( 'edit_post', $menu_id ) ) {
538 + wp_send_json_error( array( 'message' => __( 'You can not export menu !', 'responsive-menu' ) ) );
539 + }
540 +
560 541 $option_manager = Option_Manager::get_instance();
561 542 $option = $option_manager->get_options( $menu_id );
562 543
563 - wp_send_json_success( json_encode( $option ) );
544 + wp_send_json_success( wp_json_encode( $option ) );
564 545 }
565 546
566 547 /**
567 548 * Function to import the menu settings.
568 549 *
569 - * @since 4.0.0
570 - *
550 + * @since 4.0.0
551 + *
571 552 * @return json
572 553 */
573 554 public function rmp_import_menu() {
555 + check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
574 556
575 - check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
557 + if ( empty( $_FILES['file']['name'] ) ) {
558 + wp_send_json_error( array( 'message' => __( 'Please add file !', 'responsive-menu' ) ) );
559 + }
576 560
577 - if( empty( $_FILES['file']['name'] ) ) {
578 - wp_send_json_error( [ 'message' => __('Please add file !', 'responsive-menu-pro') ] );
561 + if ( empty( $_FILES['file']['type'] ) || 'application/json' != $_FILES['file']['type'] ) {
562 + wp_send_json_error( array( 'message' => __( 'Please add json file !', 'responsive-menu' ) ) );
579 563 }
580 564
581 - $file_type = pathinfo( basename( $_FILES["file"]["name"] ), PATHINFO_EXTENSION );
565 + $menu_id = isset( $_POST['menu_id'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_id'] ) ) : '';
566 + if ( empty( $menu_id ) ) {
567 + wp_send_json_error( array( 'message' => __( 'Select menu !', 'responsive-menu' ) ) );
568 + }
582 569
583 - if( empty( $_FILES['file']['tmp_name'] ) || 'json' != $file_type ) {
584 - wp_send_json_error( [ 'message' => __('Please add json file !', 'responsive-menu-pro') ] );
570 + if ( ! current_user_can( 'edit_post', $menu_id ) ) {
571 + wp_send_json_error( array( 'message' => __( 'You can not import menu !', 'responsive-menu' ) ) );
585 572 }
586 573
587 - $menu_id = sanitize_text_field( $_POST['menu_id'] );
588 - if ( empty( $menu_id ) ) {
589 - wp_send_json_error( [ 'message' => __('Select menu !', 'responsive-menu-pro') ] );
574 + global $wp_filesystem;
575 + if ( empty( $wp_filesystem ) ) {
576 + require_once ABSPATH . 'wp-admin/includes/file.php';
590 577 }
578 + WP_Filesystem();
591 579
592 - $file_contents = file_get_contents( $_FILES['file']['tmp_name'] );
593 - $import_options = json_decode( $file_contents, true );
580 + $file_contents = isset( $_FILES['file']['tmp_name'] ) ? $wp_filesystem->get_contents( wp_unslash( $_FILES['file']['tmp_name'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
581 + $import_options = json_decode( $file_contents, true );
594 582
583 + if ( ! is_array( $import_options ) ) {
584 + wp_send_json_error( array( 'message' => __( 'Invalid import file format!', 'responsive-menu' ) ) );
585 + }
586 +
587 + // Sanitize all imported options — treat imported JSON as untrusted input.
588 + // Use the same sanitization as the normal save path (rm_sanitize_rec_array with HTML allowed).
589 + $import_options = rm_sanitize_rec_array( $import_options, true );
590 +
595 591 $option_manager = Option_Manager::get_instance();
596 - $exist_option = $option_manager->get_options( $menu_id );
592 + $exist_option = $option_manager->get_options( $menu_id );
597 593
598 594 // Some required options replced in imported settings with existing menu settings.
599 - $import_options['menu_name'] = $exist_option['menu_name'];
600 - $import_options['theme_type'] = 'default';
601 - $import_options['menu_theme'] = null;
602 - $import_options['menu_to_use'] = $exist_option['menu_to_use'];
595 + $import_options['menu_name'] = $exist_option['menu_name'];
596 + $import_options['theme_type'] = 'default';
597 + $import_options['menu_theme'] = null;
598 + $import_options['menu_to_use'] = $exist_option['menu_to_use'];
603 599 $import_options['menu_to_use_in_mobile'] = $exist_option['menu_to_use_in_mobile'];
604 600
605 - update_post_meta( $menu_id, 'rmp_menu_meta' , $import_options );
601 + update_post_meta( $menu_id, 'rmp_menu_meta', $import_options );
606 602 /**
607 603 * Fires when menu is imported.
608 - *
604 + *
609 605 * @since 4.0.0
610 - *
606 + *
611 607 * @param int $menu_id
612 608 */
613 609 do_action( 'rmp_import_menu', $menu_id );
614 610
615 - wp_send_json_success( [ 'message' => __( 'Menu settings imported successfully!', 'responsive-menu-pro') ] );
611 + wp_send_json_success( array( 'message' => __( 'Menu settings imported successfully!', 'responsive-menu' ) ) );
616 612 }
617 -
618 613 }