PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 4.7.4
Responsive Menu – Create Mobile-Friendly Menu 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 +248 -211 4.0.0 → 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,126 +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_theme = '';
142 - if ( ! empty( $_POST['menu_theme'] ) ) {
143 - $menu_theme = sanitize_text_field( $_POST['menu_theme'] );
144 - }
130 + $menu_to_hide = isset( $_POST['menu_to_hide'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_to_hide'] ) ) : '';
145 131
146 - $theme_type = '';
147 - if ( ! empty( $_POST['theme_type'] ) ) {
148 - $theme_type = sanitize_text_field( $_POST['theme_type'] );
149 - }
132 + $menu_theme = isset( $_POST['menu_theme'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_theme'] ) ) : '';
150 133
151 - $menu_show_on = sanitize_text_field( $_POST['menu_show_on'] );
134 + $theme_type = isset( $_POST['theme_type'] ) ? sanitize_text_field( wp_unslash( $_POST['theme_type'] ) ) : '';
152 135
153 - $menu_show_on_pages = [];
136 + $menu_show_on = isset( $_POST['menu_show_on'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_show_on'] ) ) : '';
137 +
138 + $menu_show_on_pages = array();
154 139 if ( ! empty( $_POST['menu_show_on_pages'] ) && is_array( $_POST['menu_show_on_pages'] ) ) {
155 - foreach ( $_POST['menu_show_on_pages'] as $key => $val ) {
156 - $menu_show_on_pages[ $key ] = sanitize_text_field( $val );
157 - }
140 + $menu_show_on_pages = rm_sanitize_rec_array( wp_unslash( $_POST['menu_show_on_pages'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
158 141 }
159 142
160 - $theme_options = [];
143 + $theme_options = array();
161 144
162 145 // Get appropriate theme as per theme type and theme name.
163 146 if ( ! empty( $theme_type ) && 'downloaded' == $theme_type ) {
164 - $theme_manager = Theme_Manager::get_instance();
165 - $theme_options = $theme_manager->get_downloaded_theme_settings( $menu_theme );
166 - } else if ( ! empty( $theme_type ) && 'template' == $theme_type ) {
167 - $theme_manager = Theme_Manager::get_instance();
168 - $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 );
169 152 } else {
170 - $theme_options = rmp_get_default_options();
153 + $theme_options = rmp_get_default_options();
171 154 }
172 155
173 156 // Create menu as post with rmp_menu cpt.
174 157 $new_menu = array(
@@ -180,37 +163,43 @@
180 163
181 164 $menu_id = wp_insert_post( $new_menu );
182 165
183 166 $new_options = array(
184 - 'menu_name' => $menu_name,
185 - 'menu_to_use' => $menu_to_use,
186 - 'menu_theme' => $menu_theme,
187 - 'theme_type' => $theme_type,
188 - 'menu_display_on' => $menu_show_on,
189 - 'menu_show_on_pages' => $menu_show_on_pages,
190 - 'menu_id' => $menu_id
191 - );
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 + );
192 176
193 - $new_options = array_merge( $theme_options , $new_options );
177 + $new_options = array_merge( $theme_options, $new_options );
194 178
195 179 if ( ! empty( $menu_id ) ) {
180 + update_post_meta( $menu_id, 'rmp_menu_meta', $new_options );
196 181
197 - update_post_meta( $menu_id, 'rmp_menu_meta', $new_options);
198 -
199 182 /**
200 183 * Fires when menu is created and options is saved.
201 - *
184 + *
202 185 * @param int $menu_id Menu ID.
203 186 */
204 187 do_action( 'rmp_create_new_menu', $menu_id );
205 188
206 - $status = __('Menu is created successfully', 'responsive-menu-pro');
207 -
189 + wp_send_json_success(
190 + array(
191 + 'message' => __( 'Menu is created successfully', 'responsive-menu' ),
192 + 'customize_url' => sprintf(
193 + '%spost.php?post=%s&action=edit&editor=true',
194 + get_admin_url(),
195 + $menu_id
196 + ),
197 + )
198 + );
208 199 } else {
209 - $status = __('Unable to create new Menu', 'responsive-menu-pro');
200 + wp_send_json_error( array( 'message' => __( 'Unable to create new Menu !', 'responsive-menu' ) ) );
210 201 }
211 -
212 - wp_send_json_success( ['message' => $status ] );
213 202 }
214 203
215 204 /**
216 205 * This function register the shortcode for menu.
@@ -215,28 +204,27 @@
215 204 /**
216 205 * This function register the shortcode for menu.
217 206 *
218 207 * @since 4.0.0
219 - *
220 - * @param Array $atts Attributes List.
221 - * @param string $content It contain text from shortcode.
222 - *
208 + *
209 + * @param Array $atts Attributes List.
210 + *
223 211 * @return HTML $output Menu contents.
224 212 */
225 - public function register_menu_shortcode( $attrs = [] ) {
213 + public function register_menu_shortcode( $attrs = array() ) {
214 + $attrs = shortcode_atts( array( 'id' => '' ), $attrs );
226 215
227 - $attrs = shortcode_atts( [ 'id' => '' ], $attrs );
228 -
229 216 $attrs = array_change_key_case( (array) $attrs, CASE_LOWER );
230 217
231 218 // Check given id is valid.
232 219 if ( empty( $attrs['id'] ) ) {
233 - return __( 'Please pass menu id as attribute.', 'responsive-menu-pro' );
220 + return __( 'Please pass menu id as attribute.', 'responsive-menu' );
234 221 }
235 222
236 - $menu_id = $attrs['id'];
223 + $menu_id = $attrs['id'];
237 224 if ( 'publish' !== get_post_status( $menu_id ) ) {
238 - 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 ) );
239 227 }
240 228
241 229 // Check shortcode option is activated or not.
242 230 $option_manager = Option_Manager::get_instance();
@@ -242,9 +230,9 @@
242 230 $option_manager = Option_Manager::get_instance();
243 231 $option = $option_manager->get_option( $menu_id, 'menu_display_on' );
244 232
245 233 if ( 'shortcode' !== $option ) {
246 - return __( 'Shortcode deactivated', 'responsive-menu-pro' );
234 + return __( 'Shortcode deactivated', 'responsive-menu' );
247 235 }
248 236
249 237 ob_start();
250 238
@@ -254,20 +242,50 @@
254 242 return ob_get_clean();
255 243 }
256 244
257 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 + /**
258 277 * Function to update the global options.
259 - *
278 + *
260 279 * @since 4.0.0
261 - *
280 + *
262 281 * @return void
263 282 */
264 283 public function set_global_options() {
265 -
266 284 $global_settings = get_option( 'rmp_global_setting_options' );
267 - if( empty( $global_settings ) ) {
285 + if ( empty( $global_settings ) ) {
268 286 $default_options = rmp_global_default_setting_options();
269 - update_option( 'rmp_global_setting_options', $default_options );
287 + update_option( 'rmp_global_setting_options', $default_options );
270 288 }
271 289 }
272 290
273 291 /**
@@ -272,36 +290,34 @@
272 290
273 291 /**
274 292 * Add sub menu pages in responsive menu admin.
275 293 *
276 - * @since 4.0.0
294 + * @since 4.0.0
277 295 */
278 296 public function rmp_register_submenu_page() {
279 -
280 297 add_submenu_page(
281 298 'edit.php?post_type=rmp_menu',
282 - __( 'Settings', 'responsive-menu-pro' ),
283 - __( 'Settings', 'responsive-menu-pro' ),
299 + __( 'Settings', 'responsive-menu' ),
300 + __( 'Settings', 'responsive-menu' ),
284 301 'manage_options',
285 302 'settings',
286 303 array( $this, 'rmp_global_settings_page' )
287 304 );
288 305
289 - add_submenu_page (
306 + add_submenu_page(
290 307 'edit.php?post_type=rmp_menu',
291 - __( 'Themes', 'responsive-menu-pro' ),
292 - __( 'Themes', 'responsive-menu-pro' ),
308 + __( 'Themes', 'responsive-menu' ),
309 + __( 'Themes', 'responsive-menu' ),
293 310 'manage_options',
294 311 'themes',
295 312 array( $this, 'rmp_theme_admin_page' )
296 313 );
297 -
298 314 }
299 315
300 316 /**
301 317 * Add template to the themes page.
302 318 *
303 - * @since 4.0.0
319 + * @since 4.0.0
304 320 */
305 321 public function rmp_theme_admin_page() {
306 322
307 323 // Check user capabilities.
@@ -314,10 +330,10 @@
314 330
315 331 /**
316 332 * Add template to the setting page.
317 333 *
318 - * @since 4.0.0
319 - *
334 + * @since 4.0.0
335 + *
320 336 * @return void
321 337 */
322 338 public function rmp_global_settings_page() {
323 339
@@ -330,44 +346,47 @@
330 346 }
331 347
332 348 /**
333 349 * Remove create new menu default link of rmp_menu post type.
334 - *
350 + *
335 351 * @since 4.0.0
336 - *
352 + *
337 353 * @return void
338 354 */
339 - function remove_default_add_cpt_page() {
355 + public function remove_default_add_cpt_page() {
340 356 remove_submenu_page( 'edit.php?post_type=rmp_menu', 'post-new.php?post_type=rmp_menu' );
341 357 }
342 358
343 359 /**
344 360 * Function to add the new menu wizard template.
345 - *
361 + *
346 362 * @since 4.0.0
347 - *
363 + *
348 364 * @return void
349 365 */
350 366 public function add_new_menu_widget() {
351 - include_once RMP_PLUGIN_PATH_V4 . '/templates/new-menu-wizard.php';
367 + $screen = get_current_screen();
368 + if ( 'edit-rmp_menu' === $screen->id ) {
369 + include_once RMP_PLUGIN_PATH_V4 . '/templates/new-menu-wizard.php';
370 + }
352 371 }
353 372
354 373 /**
355 374 * Function to change the edit label and url.
375 + *
356 376 * @since 4.0.0
357 - *
358 - * @param array $actions List of post row actions.
377 + *
378 + * @param array $actions List of post row actions.
359 379 * @param Object $post Post object
360 - *
380 + *
361 381 * @return array $actions
362 382 */
363 383 public function rmp_menu_row_actions( $actions, $post ) {
364 -
365 384 if ( 'rmp_menu' == $post->post_type ) {
366 385 $actions['edit'] = sprintf(
367 - '<a href="%s" aria-label="Edit"> %s </a>',
386 + '<a href="%s" aria-label="Edit">%s</a>',
368 387 esc_url( get_edit_post_link( $post->ID ) ),
369 - __( 'Customize', 'responsive-menu-pro' )
388 + __( 'Customize', 'responsive-menu' )
370 389 );
371 390 }
372 391
373 392 return $actions;
@@ -374,21 +393,20 @@
374 393 }
375 394
376 395 /**
377 396 * Function to add the custom column.
378 - *
397 + *
379 398 * @since 4.0.0
380 - *
399 + *
381 400 * @param array $columns List of columns.
382 - *
383 - * @return array $columns Edited columns list.
401 + *
402 + * @return array $columns Edited columns list.
384 403 */
385 - public function set_custom_edit_menu_columns($columns) {
386 -
404 + public function set_custom_edit_menu_columns( $columns ) {
387 405 unset( $columns['date'] );
388 - $columns['shortcode_place'] = __( 'Shortcode', 'responsive-menu-pro' );
389 - $columns['actions'] = __( 'Actions', 'responsive-menu-pro' );
390 - $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' );
391 409
392 410 return $columns;
393 411 }
394 412
@@ -393,20 +411,19 @@
393 411 }
394 412
395 413 /**
396 414 * Function to change the edit url of post type rmp_menu
397 - *
415 + *
398 416 * @since 4.0.0
399 - *
417 + *
400 418 * @param string $url Post edit URL.
401 419 * @param int $post_id Post ID
402 - *
420 + *
403 421 * @return string $url Edited post url URL
404 422 */
405 - public function my_edit_post_link( $url, $post_id ) {
406 -
407 - if ( 'rmp_menu' == get_post_type() ) {
408 - $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';
409 426 }
410 427
411 428 return $url;
412 429 }
@@ -412,39 +429,35 @@
412 429 }
413 430
414 431 /**
415 432 * Function to add the data to the custom columns for the rmp_menu post type.
416 - *
433 + *
417 434 * @since 4.0.0
418 - *
435 + *
419 436 * @param string $column Column Name
420 437 * @param int $post_id Post ID
421 - *
438 + *
422 439 * @return void
423 440 */
424 - function add_custom_columns( $column, $post_id ) {
441 + public function add_custom_columns( $column, $post_id ) {
425 442 $option_manager = Option_Manager::get_instance();
426 443
427 444 switch ( $column ) {
428 445
429 - case 'actions' :
430 - echo sprintf(
431 - '<a href="%s" class="button" aria-label="Customize"> %s </a>',
432 - esc_url( get_edit_post_link( $post_id) ),
433 - __( 'Customize', 'responsive-menu-pro' )
434 - );
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
435 449 break;
436 - case 'shortcode_place' :
437 -
438 - $option = $option_manager->get_option( $post_id, 'menu_display_on' );
439 - if( 'shortcode' === $option ) {
440 - 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
441 456 } else {
442 - esc_html_e( 'Shortcode deactivated', 'responsive-menu-pro' );
457 + esc_html_e( 'Shortcode deactivated', 'responsive-menu' );
443 458 }
444 -
445 - break;
446 -
459 + break;
447 460 }
448 461 }
449 462
450 463 /**
@@ -453,29 +466,34 @@
453 466 * @since 4.0.0
454 467 */
455 468 public function rmp_menu_cpt() {
456 469
470 + // Check user capabilities.
471 + if ( ! current_user_can( 'manage_options' ) ) {
472 + return;
473 + }
474 +
457 475 $labels = array(
458 - 'name' => __( 'Responsive Menu', 'responsive-menu-pro' ),
459 - 'singular_name' => 'Rmp_Menu',
460 - 'menu_name' => __( 'Responsive Menu', 'responsive-menu-pro' ),
461 - 'parent_item_colon' => __( 'Parent Menu', 'responsive-menu-pro' ),
462 - 'all_items' => __( 'Menus', 'responsive-menu-pro' ),
463 - 'view_item' => __( 'View Menu', 'responsive-menu-pro' ),
464 - 'add_new_item' => __( 'Add New Menu', 'responsive-menu-pro' ),
465 - 'add_new' => __( 'Create New Menu', 'responsive-menu-pro' ),
466 - 'edit_item' => __( 'Edit Menu', 'responsive-menu-pro' ),
467 - 'update_item' => __( 'Update Menu', 'responsive-menu-pro' ),
468 - 'search_items' => __( 'Search Menu', 'responsive-menu-pro' ),
469 - 'not_found' => __( 'Not Found', 'responsive-menu-pro' ),
470 - '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' ),
471 489 );
472 490
473 491 $args = array(
474 - 'label' => __( 'Responsive Menu', 'responsive-menu-pro' ),
475 - 'description' => __( 'Responsive Menu' , 'responsive-menu-pro' ),
492 + 'label' => __( 'Responsive Menu', 'responsive-menu' ),
493 + 'description' => __( 'Responsive Menu', 'responsive-menu' ),
476 494 'labels' => $labels,
477 - 'supports' => array( 'title', 'author'),
495 + 'supports' => array( 'title', 'author' ),
478 496 'public' => false,
479 497 'hierarchical' => false,
480 498 'show_ui' => true,
481 499 'show_in_menu' => true,
@@ -483,12 +501,12 @@
483 501 'show_in_admin_bar' => false,
484 502 'has_archive' => false,
485 503 'can_export' => false,
486 504 'exclude_from_search' => true,
487 - 'taxonomies' => array(),
505 + 'taxonomies' => array(),
488 506 'publicly_queryable' => false,
489 507 'capability_type' => 'post',
490 - 'menu_icon' => RMP_PLUGIN_URL_V4 .'/assets/images/rmp-logo.png'
508 + 'menu_icon' => RMP_PLUGIN_URL_V4 . '/assets/images/rmp-logo.png',
491 509 );
492 510
493 511 register_post_type( 'rmp_menu', $args );
494 512
@@ -493,8 +511,9 @@
493 511 register_post_type( 'rmp_menu', $args );
494 512
495 513 /**
496 514 * This action will be useful when need hooks after cpt register.
515 + *
497 516 * @param CPT rmp_menu
498 517 */
499 518 do_action( 'rmp_after_cpt_registered', 'rmp_menu' );
500 519 }
@@ -501,76 +520,94 @@
501 520
502 521 /**
503 522 * Function to export the menu
504 523 *
505 - * @since 4.0.0
506 - *
524 + * @since 4.0.0
525 + *
507 526 * @return json
508 527 */
509 528 public function rmp_export_menu() {
529 + check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
510 530
511 - check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
531 + $menu_id = isset( $_POST['menu_id'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_id'] ) ) : '';
512 532
513 - $menu_id = sanitize_text_field( $_POST['menu_id'] );
514 533 if ( empty( $menu_id ) ) {
515 - wp_send_json_error( [ 'message' => __('Select menu !', 'responsive-menu-pro') ] );
534 + wp_send_json_error( array( 'message' => __( 'Select menu !', 'responsive-menu' ) ) );
516 535 }
517 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 +
518 541 $option_manager = Option_Manager::get_instance();
519 542 $option = $option_manager->get_options( $menu_id );
520 543
521 - wp_send_json_success( json_encode( $option ) );
544 + wp_send_json_success( wp_json_encode( $option ) );
522 545 }
523 546
524 547 /**
525 548 * Function to import the menu settings.
526 549 *
527 - * @since 4.0.0
528 - *
550 + * @since 4.0.0
551 + *
529 552 * @return json
530 553 */
531 554 public function rmp_import_menu() {
555 + check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
532 556
533 - 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 + }
534 560
535 - if( empty( $_FILES['file']['name'] ) ) {
536 - 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' ) ) );
537 563 }
538 564
539 - $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 + }
540 569
541 - if( empty( $_FILES['file']['tmp_name'] ) || 'json' != $file_type ) {
542 - 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' ) ) );
543 572 }
544 573
545 - $menu_id = sanitize_text_field( $_POST['menu_id'] );
546 - if ( empty( $menu_id ) ) {
547 - 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';
548 577 }
578 + WP_Filesystem();
549 579
550 - $file_contents = file_get_contents( $_FILES['file']['tmp_name'] );
551 - $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 );
552 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 +
553 591 $option_manager = Option_Manager::get_instance();
554 - $exist_option = $option_manager->get_options( $menu_id );
592 + $exist_option = $option_manager->get_options( $menu_id );
555 593
556 594 // Some required options replced in imported settings with existing menu settings.
557 - $import_options['menu_name'] = $exist_option['menu_name'];
558 - $import_options['theme_type'] = 'default';
559 - $import_options['menu_theme'] = null;
560 - $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'];
561 599 $import_options['menu_to_use_in_mobile'] = $exist_option['menu_to_use_in_mobile'];
562 600
563 - update_post_meta( $menu_id, 'rmp_menu_meta' , $import_options );
601 + update_post_meta( $menu_id, 'rmp_menu_meta', $import_options );
564 602 /**
565 603 * Fires when menu is imported.
566 - *
604 + *
567 605 * @since 4.0.0
568 - *
606 + *
569 607 * @param int $menu_id
570 608 */
571 609 do_action( 'rmp_import_menu', $menu_id );
572 610
573 - 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' ) ) );
574 612 }
575 -
576 613 }