| @@ -50,18 +50,18 @@ | ||
| 50 | 50 | * @return void |
| 51 | 51 | */ |
| 52 | 52 | protected function setup_hooks() { |
| 53 | 53 | add_action( 'wp_ajax_rmp_save_global_settings', array( $this, 'save_menu_global_settings' ) ); |
| 54 | - add_action( 'wp_ajax_rmp_rollback_version', array( $this, 'rollback_version' ) ); | |
| 55 | 54 | add_action( 'wp_ajax_rmp_create_new_menu', array( $this, 'create_new_menu' ) ); |
| 56 | 55 | add_action( 'wp_ajax_rmp_export_menu', array( $this, 'rmp_export_menu' ) ); |
| 57 | 56 | add_action( 'wp_ajax_rmp_import_menu', array( $this, 'rmp_import_menu' ) ); |
| 58 | 57 | |
| 59 | 58 | add_shortcode( 'rmp_menu', array( $this, 'register_menu_shortcode' ) ); |
| 59 | + add_shortcode( 'responsive_menu', array( $this, 'responsive_menu_shortcode' ) ); | |
| 60 | 60 | add_action( 'init', array( $this, 'rmp_menu_cpt' ), 0 ); |
| 61 | 61 | |
| 62 | 62 | add_filter( 'post_row_actions', array( $this, 'rmp_menu_row_actions' ), 10, 2 ); |
| 63 | - add_filter( 'get_edit_post_link', array( $this, 'my_edit_post_link' ), 10, 2 ); | |
| 63 | + add_filter( 'get_edit_post_link', array( $this, 'rmp_edit_post_link' ), 10, 2 ); | |
| 64 | 64 | |
| 65 | 65 | add_filter( 'manage_rmp_menu_posts_columns', array( $this, 'set_custom_edit_menu_columns' ) ); |
| 66 | 66 | add_action( 'manage_rmp_menu_posts_custom_column', array( $this, 'add_custom_columns' ), 10, 2 ); |
| 67 | 67 | add_action( 'admin_footer', array( $this, 'add_new_menu_widget' ) ); |
| @@ -76,8 +76,11 @@ | ||
| 76 | 76 | * @return json |
| 77 | 77 | */ |
| 78 | 78 | public function save_menu_global_settings() { |
| 79 | 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 | + } | |
| 80 | 83 | |
| 81 | 84 | $options = array(); |
| 82 | 85 | $form_data = isset( $_POST['form'] ) ? rm_sanitize_rec_array( wp_unslash( $_POST['form'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 83 | 86 | wp_parse_str( $form_data, $options ); |
| @@ -96,27 +99,12 @@ | ||
| 96 | 99 | * @param array $option List of global settings. |
| 97 | 100 | */ |
| 98 | 101 | do_action( 'rmp_save_global_settings', $options ); |
| 99 | 102 | |
| 100 | - wp_send_json_success( 'Saved' ); | |
| 103 | + wp_send_json_success( __( 'Saved', 'responsive-menu' ) ); | |
| 101 | 104 | } |
| 102 | 105 | |
| 103 | 106 | /** |
| 104 | - * Rollback to older version from setting page. | |
| 105 | - * | |
| 106 | - * @since 4.0.0 | |
| 107 | - * | |
| 108 | - * @return void | |
| 109 | - */ | |
| 110 | - public function rollback_version() { | |
| 111 | - if ( empty( update_option( 'is_rmp_new_version', 0 ) ) ) { | |
| 112 | - add_option( 'is_rmp_new_version', 0 ); | |
| 113 | - } | |
| 114 | - | |
| 115 | - wp_send_json_success( array( 'redirect' => admin_url( 'admin.php?page=responsive-menu' ) ) ); | |
| 116 | - } | |
| 117 | - | |
| 118 | - /** | |
| 119 | 107 | * Function to create a new theme. |
| 120 | 108 | * |
| 121 | 109 | * @since 4.0.0 |
| 122 | 110 | * |
| @@ -124,16 +112,20 @@ | ||
| 124 | 112 | */ |
| 125 | 113 | public function create_new_menu() { |
| 126 | 114 | check_ajax_referer( 'rmp_nonce', 'ajax_nonce' ); |
| 127 | 115 | |
| 116 | + if ( ! current_user_can( 'administrator' ) ) { | |
| 117 | + wp_send_json_error( array( 'message' => __( 'You can not create menu !', 'responsive-menu' ) ) ); | |
| 118 | + } | |
| 119 | + | |
| 128 | 120 | $menu_name = isset( $_POST['menu_name'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_name'] ) ) : ''; |
| 129 | 121 | if ( empty( $menu_name ) ) { |
| 130 | - wp_send_json_error( array( 'message' => esc_html__( 'Enter the Menu name !', 'responsive-menu' ) ) ); | |
| 122 | + wp_send_json_error( array( 'message' => __( 'Enter the Menu name !', 'responsive-menu' ) ) ); | |
| 131 | 123 | } |
| 132 | 124 | |
| 133 | 125 | $menu_to_use = isset( $_POST['menu_to_use'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_to_use'] ) ) : ''; |
| 134 | 126 | if ( empty( $menu_to_use ) ) { |
| 135 | - wp_send_json_error( array( 'message' => esc_html__( 'Select menu to use !', 'responsive-menu' ) ) ); | |
| 127 | + wp_send_json_error( array( 'message' => __( 'Select menu to use !', 'responsive-menu' ) ) ); | |
| 136 | 128 | } |
| 137 | 129 | |
| 138 | 130 | $menu_to_hide = isset( $_POST['menu_to_hide'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_to_hide'] ) ) : ''; |
| 139 | 131 | |
| @@ -195,9 +187,9 @@ | ||
| 195 | 187 | do_action( 'rmp_create_new_menu', $menu_id ); |
| 196 | 188 | |
| 197 | 189 | wp_send_json_success( |
| 198 | 190 | array( |
| 199 | - 'message' => esc_html__( 'Menu is created successfully', 'responsive-menu' ), | |
| 191 | + 'message' => __( 'Menu is created successfully', 'responsive-menu' ), | |
| 200 | 192 | 'customize_url' => sprintf( |
| 201 | 193 | '%spost.php?post=%s&action=edit&editor=true', |
| 202 | 194 | get_admin_url(), |
| 203 | 195 | $menu_id |
| @@ -204,9 +196,9 @@ | ||
| 204 | 196 | ), |
| 205 | 197 | ) |
| 206 | 198 | ); |
| 207 | 199 | } else { |
| 208 | - wp_send_json_error( array( 'message' => esc_html__( 'Unable to create new Menu !', 'responsive-menu' ) ) ); | |
| 200 | + wp_send_json_error( array( 'message' => __( 'Unable to create new Menu !', 'responsive-menu' ) ) ); | |
| 209 | 201 | } |
| 210 | 202 | } |
| 211 | 203 | |
| 212 | 204 | /** |
| @@ -213,10 +205,9 @@ | ||
| 213 | 205 | * This function register the shortcode for menu. |
| 214 | 206 | * |
| 215 | 207 | * @since 4.0.0 |
| 216 | 208 | * |
| 217 | - * @param Array $atts Attributes List. | |
| 218 | - * @param string $content It contain text from shortcode. | |
| 209 | + * @param Array $atts Attributes List. | |
| 219 | 210 | * |
| 220 | 211 | * @return HTML $output Menu contents. |
| 221 | 212 | */ |
| 222 | 213 | public function register_menu_shortcode( $attrs = array() ) { |
| @@ -225,15 +216,15 @@ | ||
| 225 | 216 | $attrs = array_change_key_case( (array) $attrs, CASE_LOWER ); |
| 226 | 217 | |
| 227 | 218 | // Check given id is valid. |
| 228 | 219 | if ( empty( $attrs['id'] ) ) { |
| 229 | - return esc_html__( 'Please pass menu id as attribute.', 'responsive-menu' ); | |
| 220 | + return __( 'Please pass menu id as attribute.', 'responsive-menu' ); | |
| 230 | 221 | } |
| 231 | 222 | |
| 232 | 223 | $menu_id = $attrs['id']; |
| 233 | 224 | if ( 'publish' !== get_post_status( $menu_id ) ) { |
| 234 | 225 | /* translators: %d: Menu id */ |
| 235 | - return sprintf( esc_html__( 'Shortcode with menu id %d is not published.', 'responsive-menu' ), esc_html( $menu_id ) ); | |
| 226 | + return sprintf( __( 'Shortcode with menu id %d is not published.', 'responsive-menu' ), esc_html( $menu_id ) ); | |
| 236 | 227 | } |
| 237 | 228 | |
| 238 | 229 | // Check shortcode option is activated or not. |
| 239 | 230 | $option_manager = Option_Manager::get_instance(); |
| @@ -239,9 +230,9 @@ | ||
| 239 | 230 | $option_manager = Option_Manager::get_instance(); |
| 240 | 231 | $option = $option_manager->get_option( $menu_id, 'menu_display_on' ); |
| 241 | 232 | |
| 242 | 233 | if ( 'shortcode' !== $option ) { |
| 243 | - return esc_html__( 'Shortcode deactivated', 'responsive-menu' ); | |
| 234 | + return __( 'Shortcode deactivated', 'responsive-menu' ); | |
| 244 | 235 | } |
| 245 | 236 | |
| 246 | 237 | ob_start(); |
| 247 | 238 | |
| @@ -251,8 +242,39 @@ | ||
| 251 | 242 | return ob_get_clean(); |
| 252 | 243 | } |
| 253 | 244 | |
| 254 | 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 | + /** | |
| 255 | 277 | * Function to update the global options. |
| 256 | 278 | * |
| 257 | 279 | * @since 4.0.0 |
| 258 | 280 | * |
| @@ -273,10 +295,10 @@ | ||
| 273 | 295 | */ |
| 274 | 296 | public function rmp_register_submenu_page() { |
| 275 | 297 | add_submenu_page( |
| 276 | 298 | 'edit.php?post_type=rmp_menu', |
| 277 | - esc_html__( 'Settings', 'responsive-menu' ), | |
| 278 | - esc_html__( 'Settings', 'responsive-menu' ), | |
| 299 | + __( 'Settings', 'responsive-menu' ), | |
| 300 | + __( 'Settings', 'responsive-menu' ), | |
| 279 | 301 | 'manage_options', |
| 280 | 302 | 'settings', |
| 281 | 303 | array( $this, 'rmp_global_settings_page' ) |
| 282 | 304 | ); |
| @@ -282,10 +304,10 @@ | ||
| 282 | 304 | ); |
| 283 | 305 | |
| 284 | 306 | add_submenu_page( |
| 285 | 307 | 'edit.php?post_type=rmp_menu', |
| 286 | - esc_html__( 'Themes', 'responsive-menu' ), | |
| 287 | - esc_html__( 'Themes', 'responsive-menu' ), | |
| 308 | + __( 'Themes', 'responsive-menu' ), | |
| 309 | + __( 'Themes', 'responsive-menu' ), | |
| 288 | 310 | 'manage_options', |
| 289 | 311 | 'themes', |
| 290 | 312 | array( $this, 'rmp_theme_admin_page' ) |
| 291 | 313 | ); |
| @@ -362,9 +384,9 @@ | ||
| 362 | 384 | if ( 'rmp_menu' == $post->post_type ) { |
| 363 | 385 | $actions['edit'] = sprintf( |
| 364 | 386 | '<a href="%s" aria-label="Edit">%s</a>', |
| 365 | 387 | esc_url( get_edit_post_link( $post->ID ) ), |
| 366 | - esc_html__( 'Customize', 'responsive-menu' ) | |
| 388 | + __( 'Customize', 'responsive-menu' ) | |
| 367 | 389 | ); |
| 368 | 390 | } |
| 369 | 391 | |
| 370 | 392 | return $actions; |
| @@ -380,11 +402,11 @@ | ||
| 380 | 402 | * @return array $columns Edited columns list. |
| 381 | 403 | */ |
| 382 | 404 | public function set_custom_edit_menu_columns( $columns ) { |
| 383 | 405 | unset( $columns['date'] ); |
| 384 | - $columns['shortcode_place'] = esc_html__( 'Shortcode', 'responsive-menu' ); | |
| 385 | - $columns['actions'] = esc_html__( 'Actions', 'responsive-menu' ); | |
| 386 | - $columns['date'] = esc_html__( 'Date', 'responsive-menu' ); | |
| 406 | + $columns['shortcode_place'] = __( 'Shortcode', 'responsive-menu' ); | |
| 407 | + $columns['actions'] = __( 'Actions', 'responsive-menu' ); | |
| 408 | + $columns['date'] = __( 'Date', 'responsive-menu' ); | |
| 387 | 409 | |
| 388 | 410 | return $columns; |
| 389 | 411 | } |
| 390 | 412 | |
| @@ -397,10 +419,10 @@ | ||
| 397 | 419 | * @param int $post_id Post ID |
| 398 | 420 | * |
| 399 | 421 | * @return string $url Edited post url URL |
| 400 | 422 | */ |
| 401 | - public function my_edit_post_link( $url, $post_id ) { | |
| 402 | - if ( 'rmp_menu' == get_post_type() ) { | |
| 423 | + public function rmp_edit_post_link( $url, $post_id ) { | |
| 424 | + if ( 'rmp_menu' === get_post_type() && current_user_can( 'edit_post', $post_id ) ) { | |
| 403 | 425 | $url = get_admin_url() . 'post.php?post=' . $post_id . '&action=edit&editor=true'; |
| 404 | 426 | } |
| 405 | 427 | |
| 406 | 428 | return $url; |
| @@ -450,26 +472,26 @@ | ||
| 450 | 472 | return; |
| 451 | 473 | } |
| 452 | 474 | |
| 453 | 475 | $labels = array( |
| 454 | - 'name' => esc_html__( 'Responsive Menu', 'responsive-menu' ), | |
| 455 | - 'singular_name' => 'Rmp_Menu', | |
| 456 | - 'menu_name' => esc_html__( 'Responsive Menu', 'responsive-menu' ), | |
| 457 | - 'parent_item_colon' => esc_html__( 'Parent Menu', 'responsive-menu' ), | |
| 458 | - 'all_items' => esc_html__( 'Menus', 'responsive-menu' ), | |
| 459 | - 'view_item' => esc_html__( 'View Menu', 'responsive-menu' ), | |
| 460 | - 'add_new_item' => esc_html__( 'Add New Menu', 'responsive-menu' ), | |
| 461 | - 'add_new' => esc_html__( 'Create New Menu', 'responsive-menu' ), | |
| 462 | - 'edit_item' => esc_html__( 'Edit Menu', 'responsive-menu' ), | |
| 463 | - 'update_item' => esc_html__( 'Update Menu', 'responsive-menu' ), | |
| 464 | - 'search_items' => esc_html__( 'Search Menu', 'responsive-menu' ), | |
| 465 | - 'not_found' => esc_html__( 'Not Found', 'responsive-menu' ), | |
| 466 | - 'not_found_in_trash' => esc_html__( 'Not found in Trash', 'responsive-menu' ), | |
| 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' ), | |
| 467 | 489 | ); |
| 468 | 490 | |
| 469 | 491 | $args = array( |
| 470 | - 'label' => esc_html__( 'Responsive Menu', 'responsive-menu' ), | |
| 471 | - 'description' => esc_html__( 'Responsive Menu', 'responsive-menu' ), | |
| 492 | + 'label' => __( 'Responsive Menu', 'responsive-menu' ), | |
| 493 | + 'description' => __( 'Responsive Menu', 'responsive-menu' ), | |
| 472 | 494 | 'labels' => $labels, |
| 473 | 495 | 'supports' => array( 'title', 'author' ), |
| 474 | 496 | 'public' => false, |
| 475 | 497 | 'hierarchical' => false, |
| @@ -506,12 +528,17 @@ | ||
| 506 | 528 | public function rmp_export_menu() { |
| 507 | 529 | check_ajax_referer( 'rmp_nonce', 'ajax_nonce' ); |
| 508 | 530 | |
| 509 | 531 | $menu_id = isset( $_POST['menu_id'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_id'] ) ) : ''; |
| 532 | + | |
| 510 | 533 | if ( empty( $menu_id ) ) { |
| 511 | - wp_send_json_error( array( 'message' => esc_html__( 'Select menu !', 'responsive-menu' ) ) ); | |
| 534 | + wp_send_json_error( array( 'message' => __( 'Select menu !', 'responsive-menu' ) ) ); | |
| 512 | 535 | } |
| 513 | 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 | + | |
| 514 | 541 | $option_manager = Option_Manager::get_instance(); |
| 515 | 542 | $option = $option_manager->get_options( $menu_id ); |
| 516 | 543 | |
| 517 | 544 | wp_send_json_success( wp_json_encode( $option ) ); |
| @@ -527,23 +554,41 @@ | ||
| 527 | 554 | public function rmp_import_menu() { |
| 528 | 555 | check_ajax_referer( 'rmp_nonce', 'ajax_nonce' ); |
| 529 | 556 | |
| 530 | 557 | if ( empty( $_FILES['file']['name'] ) ) { |
| 531 | - wp_send_json_error( array( 'message' => esc_html__( 'Please add file !', 'responsive-menu' ) ) ); | |
| 558 | + wp_send_json_error( array( 'message' => __( 'Please add file !', 'responsive-menu' ) ) ); | |
| 532 | 559 | } |
| 533 | 560 | |
| 534 | 561 | if ( empty( $_FILES['file']['type'] ) || 'application/json' != $_FILES['file']['type'] ) { |
| 535 | - wp_send_json_error( array( 'message' => esc_html__( 'Please add json file !', 'responsive-menu' ) ) ); | |
| 562 | + wp_send_json_error( array( 'message' => __( 'Please add json file !', 'responsive-menu' ) ) ); | |
| 536 | 563 | } |
| 537 | 564 | |
| 538 | 565 | $menu_id = isset( $_POST['menu_id'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_id'] ) ) : ''; |
| 539 | 566 | if ( empty( $menu_id ) ) { |
| 540 | - wp_send_json_error( array( 'message' => esc_html__( 'Select menu !', 'responsive-menu' ) ) ); | |
| 567 | + wp_send_json_error( array( 'message' => __( 'Select menu !', 'responsive-menu' ) ) ); | |
| 541 | 568 | } |
| 542 | 569 | |
| 543 | - $file_contents = isset( $_FILES['file']['tmp_name'] ) ? file_get_contents( wp_unslash( $_FILES['file']['tmp_name'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 570 | + if ( ! current_user_can( 'edit_post', $menu_id ) ) { | |
| 571 | + wp_send_json_error( array( 'message' => __( 'You can not import menu !', 'responsive-menu' ) ) ); | |
| 572 | + } | |
| 573 | + | |
| 574 | + global $wp_filesystem; | |
| 575 | + if ( empty( $wp_filesystem ) ) { | |
| 576 | + require_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 577 | + } | |
| 578 | + WP_Filesystem(); | |
| 579 | + | |
| 580 | + $file_contents = isset( $_FILES['file']['tmp_name'] ) ? $wp_filesystem->get_contents( wp_unslash( $_FILES['file']['tmp_name'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 544 | 581 | $import_options = json_decode( $file_contents, true ); |
| 545 | 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 | + | |
| 546 | 591 | $option_manager = Option_Manager::get_instance(); |
| 547 | 592 | $exist_option = $option_manager->get_options( $menu_id ); |
| 548 | 593 | |
| 549 | 594 | // Some required options replced in imported settings with existing menu settings. |
| @@ -562,7 +607,7 @@ | ||
| 562 | 607 | * @param int $menu_id |
| 563 | 608 | */ |
| 564 | 609 | do_action( 'rmp_import_menu', $menu_id ); |
| 565 | 610 | |
| 566 | - wp_send_json_success( array( 'message' => esc_html__( 'Menu settings imported successfully!', 'responsive-menu' ) ) ); | |
| 611 | + wp_send_json_success( array( 'message' => __( 'Menu settings imported successfully!', 'responsive-menu' ) ) ); | |
| 567 | 612 | } |
| 568 | 613 | } |