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