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 +243 -234 4.0.4 → 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,59 +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 - add_submenu_page (
299 - 'edit.php?post_type=rmp_menu',
300 - __( 'Roadmap', 'responsive-menu-pro' ),
301 - __( 'Roadmap', 'responsive-menu-pro' ),
302 - 'manage_options',
303 - 'roadmap',
304 - array( $this, 'rmp_roadmap_admin_page' )
305 - );
306 -
307 314 }
308 315
309 316 /**
310 - * Add template for roadmap page.
311 - *
312 - * @since 4.0.1
313 - */
314 - public function rmp_roadmap_admin_page() {
315 - // Check user capabilities.
316 - if ( ! current_user_can( 'manage_options' ) ) {
317 - return;
318 - }
319 -
320 - include_once RMP_PLUGIN_PATH_V4 . '/templates/rmp-roadmap.php';
321 - }
322 -
323 - /**
324 317 * Add template to the themes page.
325 318 *
326 - * @since 4.0.0
319 + * @since 4.0.0
327 320 */
328 321 public function rmp_theme_admin_page() {
329 322
330 323 // Check user capabilities.
@@ -337,10 +330,10 @@
337 330
338 331 /**
339 332 * Add template to the setting page.
340 333 *
341 - * @since 4.0.0
342 - *
334 + * @since 4.0.0
335 + *
343 336 * @return void
344 337 */
345 338 public function rmp_global_settings_page() {
346 339
@@ -353,44 +346,47 @@
353 346 }
354 347
355 348 /**
356 349 * Remove create new menu default link of rmp_menu post type.
357 - *
350 + *
358 351 * @since 4.0.0
359 - *
352 + *
360 353 * @return void
361 354 */
362 - function remove_default_add_cpt_page() {
355 + public function remove_default_add_cpt_page() {
363 356 remove_submenu_page( 'edit.php?post_type=rmp_menu', 'post-new.php?post_type=rmp_menu' );
364 357 }
365 358
366 359 /**
367 360 * Function to add the new menu wizard template.
368 - *
361 + *
369 362 * @since 4.0.0
370 - *
363 + *
371 364 * @return void
372 365 */
373 366 public function add_new_menu_widget() {
374 - 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 + }
375 371 }
376 372
377 373 /**
378 374 * Function to change the edit label and url.
375 + *
379 376 * @since 4.0.0
380 - *
381 - * @param array $actions List of post row actions.
377 + *
378 + * @param array $actions List of post row actions.
382 379 * @param Object $post Post object
383 - *
380 + *
384 381 * @return array $actions
385 382 */
386 383 public function rmp_menu_row_actions( $actions, $post ) {
387 -
388 384 if ( 'rmp_menu' == $post->post_type ) {
389 385 $actions['edit'] = sprintf(
390 - '<a href="%s" aria-label="Edit"> %s </a>',
386 + '<a href="%s" aria-label="Edit">%s</a>',
391 387 esc_url( get_edit_post_link( $post->ID ) ),
392 - __( 'Customize', 'responsive-menu-pro' )
388 + __( 'Customize', 'responsive-menu' )
393 389 );
394 390 }
395 391
396 392 return $actions;
@@ -397,21 +393,20 @@
397 393 }
398 394
399 395 /**
400 396 * Function to add the custom column.
401 - *
397 + *
402 398 * @since 4.0.0
403 - *
399 + *
404 400 * @param array $columns List of columns.
405 - *
406 - * @return array $columns Edited columns list.
401 + *
402 + * @return array $columns Edited columns list.
407 403 */
408 - public function set_custom_edit_menu_columns($columns) {
409 -
404 + public function set_custom_edit_menu_columns( $columns ) {
410 405 unset( $columns['date'] );
411 - $columns['shortcode_place'] = __( 'Shortcode', 'responsive-menu-pro' );
412 - $columns['actions'] = __( 'Actions', 'responsive-menu-pro' );
413 - $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' );
414 409
415 410 return $columns;
416 411 }
417 412
@@ -416,20 +411,19 @@
416 411 }
417 412
418 413 /**
419 414 * Function to change the edit url of post type rmp_menu
420 - *
415 + *
421 416 * @since 4.0.0
422 - *
417 + *
423 418 * @param string $url Post edit URL.
424 419 * @param int $post_id Post ID
425 - *
420 + *
426 421 * @return string $url Edited post url URL
427 422 */
428 - public function my_edit_post_link( $url, $post_id ) {
429 -
430 - if ( 'rmp_menu' == get_post_type() ) {
431 - $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';
432 426 }
433 427
434 428 return $url;
435 429 }
@@ -435,39 +429,35 @@
435 429 }
436 430
437 431 /**
438 432 * Function to add the data to the custom columns for the rmp_menu post type.
439 - *
433 + *
440 434 * @since 4.0.0
441 - *
435 + *
442 436 * @param string $column Column Name
443 437 * @param int $post_id Post ID
444 - *
438 + *
445 439 * @return void
446 440 */
447 - function add_custom_columns( $column, $post_id ) {
441 + public function add_custom_columns( $column, $post_id ) {
448 442 $option_manager = Option_Manager::get_instance();
449 443
450 444 switch ( $column ) {
451 445
452 - case 'actions' :
453 - echo sprintf(
454 - '<a href="%s" class="button" aria-label="Customize"> %s </a>',
455 - esc_url( get_edit_post_link( $post_id) ),
456 - __( 'Customize', 'responsive-menu-pro' )
457 - );
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
458 449 break;
459 - case 'shortcode_place' :
460 -
461 - $option = $option_manager->get_option( $post_id, 'menu_display_on' );
462 - if( 'shortcode' === $option ) {
463 - 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
464 456 } else {
465 - esc_html_e( 'Shortcode deactivated', 'responsive-menu-pro' );
457 + esc_html_e( 'Shortcode deactivated', 'responsive-menu' );
466 458 }
467 -
468 - break;
469 -
459 + break;
470 460 }
471 461 }
472 462
473 463 /**
@@ -482,28 +472,28 @@
482 472 return;
483 473 }
484 474
485 475 $labels = array(
486 - 'name' => __( 'Responsive Menu', 'responsive-menu-pro' ),
487 - 'singular_name' => 'Rmp_Menu',
488 - 'menu_name' => __( 'Responsive Menu', 'responsive-menu-pro' ),
489 - 'parent_item_colon' => __( 'Parent Menu', 'responsive-menu-pro' ),
490 - 'all_items' => __( 'Menus', 'responsive-menu-pro' ),
491 - 'view_item' => __( 'View Menu', 'responsive-menu-pro' ),
492 - 'add_new_item' => __( 'Add New Menu', 'responsive-menu-pro' ),
493 - 'add_new' => __( 'Create New Menu', 'responsive-menu-pro' ),
494 - 'edit_item' => __( 'Edit Menu', 'responsive-menu-pro' ),
495 - 'update_item' => __( 'Update Menu', 'responsive-menu-pro' ),
496 - 'search_items' => __( 'Search Menu', 'responsive-menu-pro' ),
497 - 'not_found' => __( 'Not Found', 'responsive-menu-pro' ),
498 - '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' ),
499 489 );
500 490
501 491 $args = array(
502 - 'label' => __( 'Responsive Menu', 'responsive-menu-pro' ),
503 - 'description' => __( 'Responsive Menu' , 'responsive-menu-pro' ),
492 + 'label' => __( 'Responsive Menu', 'responsive-menu' ),
493 + 'description' => __( 'Responsive Menu', 'responsive-menu' ),
504 494 'labels' => $labels,
505 - 'supports' => array( 'title', 'author'),
495 + 'supports' => array( 'title', 'author' ),
506 496 'public' => false,
507 497 'hierarchical' => false,
508 498 'show_ui' => true,
509 499 'show_in_menu' => true,
@@ -511,12 +501,12 @@
511 501 'show_in_admin_bar' => false,
512 502 'has_archive' => false,
513 503 'can_export' => false,
514 504 'exclude_from_search' => true,
515 - 'taxonomies' => array(),
505 + 'taxonomies' => array(),
516 506 'publicly_queryable' => false,
517 507 'capability_type' => 'post',
518 - 'menu_icon' => RMP_PLUGIN_URL_V4 .'/assets/images/rmp-logo.png'
508 + 'menu_icon' => RMP_PLUGIN_URL_V4 . '/assets/images/rmp-logo.png',
519 509 );
520 510
521 511 register_post_type( 'rmp_menu', $args );
522 512
@@ -521,8 +511,9 @@
521 511 register_post_type( 'rmp_menu', $args );
522 512
523 513 /**
524 514 * This action will be useful when need hooks after cpt register.
515 + *
525 516 * @param CPT rmp_menu
526 517 */
527 518 do_action( 'rmp_after_cpt_registered', 'rmp_menu' );
528 519 }
@@ -529,76 +520,94 @@
529 520
530 521 /**
531 522 * Function to export the menu
532 523 *
533 - * @since 4.0.0
534 - *
524 + * @since 4.0.0
525 + *
535 526 * @return json
536 527 */
537 528 public function rmp_export_menu() {
529 + check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
538 530
539 - check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
531 + $menu_id = isset( $_POST['menu_id'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_id'] ) ) : '';
540 532
541 - $menu_id = sanitize_text_field( $_POST['menu_id'] );
542 533 if ( empty( $menu_id ) ) {
543 - wp_send_json_error( [ 'message' => __('Select menu !', 'responsive-menu-pro') ] );
534 + wp_send_json_error( array( 'message' => __( 'Select menu !', 'responsive-menu' ) ) );
544 535 }
545 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 +
546 541 $option_manager = Option_Manager::get_instance();
547 542 $option = $option_manager->get_options( $menu_id );
548 543
549 - wp_send_json_success( json_encode( $option ) );
544 + wp_send_json_success( wp_json_encode( $option ) );
550 545 }
551 546
552 547 /**
553 548 * Function to import the menu settings.
554 549 *
555 - * @since 4.0.0
556 - *
550 + * @since 4.0.0
551 + *
557 552 * @return json
558 553 */
559 554 public function rmp_import_menu() {
555 + check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
560 556
561 - 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 + }
562 560
563 - if( empty( $_FILES['file']['name'] ) ) {
564 - 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' ) ) );
565 563 }
566 564
567 - $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 + }
568 569
569 - if( empty( $_FILES['file']['tmp_name'] ) || 'json' != $file_type ) {
570 - 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' ) ) );
571 572 }
572 573
573 - $menu_id = sanitize_text_field( $_POST['menu_id'] );
574 - if ( empty( $menu_id ) ) {
575 - 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';
576 577 }
578 + WP_Filesystem();
577 579
578 - $file_contents = file_get_contents( $_FILES['file']['tmp_name'] );
579 - $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 );
580 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 +
581 591 $option_manager = Option_Manager::get_instance();
582 - $exist_option = $option_manager->get_options( $menu_id );
592 + $exist_option = $option_manager->get_options( $menu_id );
583 593
584 594 // Some required options replced in imported settings with existing menu settings.
585 - $import_options['menu_name'] = $exist_option['menu_name'];
586 - $import_options['theme_type'] = 'default';
587 - $import_options['menu_theme'] = null;
588 - $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'];
589 599 $import_options['menu_to_use_in_mobile'] = $exist_option['menu_to_use_in_mobile'];
590 600
591 - update_post_meta( $menu_id, 'rmp_menu_meta' , $import_options );
601 + update_post_meta( $menu_id, 'rmp_menu_meta', $import_options );
592 602 /**
593 603 * Fires when menu is imported.
594 - *
604 + *
595 605 * @since 4.0.0
596 - *
606 + *
597 607 * @param int $menu_id
598 608 */
599 609 do_action( 'rmp_import_menu', $menu_id );
600 610
601 - 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' ) ) );
602 612 }
603 -
604 613 }