| @@ -50,9 +50,8 @@ | ||
| 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 | |
| @@ -60,9 +59,9 @@ | ||
| 60 | 59 | add_shortcode( 'responsive_menu', array( $this, 'responsive_menu_shortcode' ) ); |
| 61 | 60 | add_action( 'init', array( $this, 'rmp_menu_cpt' ), 0 ); |
| 62 | 61 | |
| 63 | 62 | add_filter( 'post_row_actions', array( $this, 'rmp_menu_row_actions' ), 10, 2 ); |
| 64 | - 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 ); | |
| 65 | 64 | |
| 66 | 65 | add_filter( 'manage_rmp_menu_posts_columns', array( $this, 'set_custom_edit_menu_columns' ) ); |
| 67 | 66 | add_action( 'manage_rmp_menu_posts_custom_column', array( $this, 'add_custom_columns' ), 10, 2 ); |
| 68 | 67 | add_action( 'admin_footer', array( $this, 'add_new_menu_widget' ) ); |
| @@ -77,8 +76,11 @@ | ||
| 77 | 76 | * @return json |
| 78 | 77 | */ |
| 79 | 78 | public function save_menu_global_settings() { |
| 80 | 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 | + } | |
| 81 | 83 | |
| 82 | 84 | $options = array(); |
| 83 | 85 | $form_data = isset( $_POST['form'] ) ? rm_sanitize_rec_array( wp_unslash( $_POST['form'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 84 | 86 | wp_parse_str( $form_data, $options ); |
| @@ -97,27 +99,12 @@ | ||
| 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. | |
| 106 | - * | |
| 107 | - * @since 4.0.0 | |
| 108 | - * | |
| 109 | - * @return void | |
| 110 | - */ | |
| 111 | - public function rollback_version() { | |
| 112 | - if ( empty( update_option( 'is_rmp_new_version', 0 ) ) ) { | |
| 113 | - add_option( 'is_rmp_new_version', 0 ); | |
| 114 | - } | |
| 115 | - | |
| 116 | - wp_send_json_success( array( 'redirect' => admin_url( 'admin.php?page=responsive-menu' ) ) ); | |
| 117 | - } | |
| 118 | - | |
| 119 | - /** | |
| 120 | 107 | * Function to create a new theme. |
| 121 | 108 | * |
| 122 | 109 | * @since 4.0.0 |
| 123 | 110 | * |
| @@ -125,16 +112,20 @@ | ||
| 125 | 112 | */ |
| 126 | 113 | public function create_new_menu() { |
| 127 | 114 | check_ajax_referer( 'rmp_nonce', 'ajax_nonce' ); |
| 128 | 115 | |
| 116 | + if ( ! current_user_can( 'administrator' ) ) { | |
| 117 | + wp_send_json_error( array( 'message' => __( 'You can not create menu !', 'responsive-menu' ) ) ); | |
| 118 | + } | |
| 119 | + | |
| 129 | 120 | $menu_name = isset( $_POST['menu_name'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_name'] ) ) : ''; |
| 130 | 121 | if ( empty( $menu_name ) ) { |
| 131 | - 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' ) ) ); | |
| 132 | 123 | } |
| 133 | 124 | |
| 134 | 125 | $menu_to_use = isset( $_POST['menu_to_use'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_to_use'] ) ) : ''; |
| 135 | 126 | if ( empty( $menu_to_use ) ) { |
| 136 | - 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' ) ) ); | |
| 137 | 128 | } |
| 138 | 129 | |
| 139 | 130 | $menu_to_hide = isset( $_POST['menu_to_hide'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_to_hide'] ) ) : ''; |
| 140 | 131 | |
| @@ -196,9 +187,9 @@ | ||
| 196 | 187 | do_action( 'rmp_create_new_menu', $menu_id ); |
| 197 | 188 | |
| 198 | 189 | wp_send_json_success( |
| 199 | 190 | array( |
| 200 | - 'message' => esc_html__( 'Menu is created successfully', 'responsive-menu' ), | |
| 191 | + 'message' => __( 'Menu is created successfully', 'responsive-menu' ), | |
| 201 | 192 | 'customize_url' => sprintf( |
| 202 | 193 | '%spost.php?post=%s&action=edit&editor=true', |
| 203 | 194 | get_admin_url(), |
| 204 | 195 | $menu_id |
| @@ -205,9 +196,9 @@ | ||
| 205 | 196 | ), |
| 206 | 197 | ) |
| 207 | 198 | ); |
| 208 | 199 | } else { |
| 209 | - 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' ) ) ); | |
| 210 | 201 | } |
| 211 | 202 | } |
| 212 | 203 | |
| 213 | 204 | /** |
| @@ -214,9 +205,9 @@ | ||
| 214 | 205 | * This function register the shortcode for menu. |
| 215 | 206 | * |
| 216 | 207 | * @since 4.0.0 |
| 217 | 208 | * |
| 218 | - * @param Array $atts Attributes List. | |
| 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 | |
| @@ -260,10 +251,10 @@ | ||
| 260 | 251 | */ |
| 261 | 252 | public function responsive_menu_shortcode() { |
| 262 | 253 | |
| 263 | 254 | // Check shortcode option is activated or not. |
| 264 | - $options = Option_Manager::get_instance(); | |
| 265 | - $menu_ids = get_all_rmp_menu_ids(); | |
| 255 | + $options = Option_Manager::get_instance(); | |
| 256 | + $menu_ids = get_all_rmp_menu_ids(); | |
| 266 | 257 | |
| 267 | 258 | if ( ! empty( $menu_ids ) ) { |
| 268 | 259 | foreach ( $menu_ids as $menu_id ) { |
| 269 | 260 | |
| @@ -277,9 +268,9 @@ | ||
| 277 | 268 | $menu->build_menu(); |
| 278 | 269 | return ob_get_clean(); |
| 279 | 270 | } |
| 280 | 271 | } else { |
| 281 | - return esc_html__( 'Shortcode deactivated', 'responsive-menu' ); | |
| 272 | + return __( 'Shortcode deactivated', 'responsive-menu' ); | |
| 282 | 273 | } |
| 283 | 274 | } |
| 284 | 275 | |
| 285 | 276 | /** |
| @@ -304,10 +295,10 @@ | ||
| 304 | 295 | */ |
| 305 | 296 | public function rmp_register_submenu_page() { |
| 306 | 297 | add_submenu_page( |
| 307 | 298 | 'edit.php?post_type=rmp_menu', |
| 308 | - esc_html__( 'Settings', 'responsive-menu' ), | |
| 309 | - esc_html__( 'Settings', 'responsive-menu' ), | |
| 299 | + __( 'Settings', 'responsive-menu' ), | |
| 300 | + __( 'Settings', 'responsive-menu' ), | |
| 310 | 301 | 'manage_options', |
| 311 | 302 | 'settings', |
| 312 | 303 | array( $this, 'rmp_global_settings_page' ) |
| 313 | 304 | ); |
| @@ -313,10 +304,10 @@ | ||
| 313 | 304 | ); |
| 314 | 305 | |
| 315 | 306 | add_submenu_page( |
| 316 | 307 | 'edit.php?post_type=rmp_menu', |
| 317 | - esc_html__( 'Themes', 'responsive-menu' ), | |
| 318 | - esc_html__( 'Themes', 'responsive-menu' ), | |
| 308 | + __( 'Themes', 'responsive-menu' ), | |
| 309 | + __( 'Themes', 'responsive-menu' ), | |
| 319 | 310 | 'manage_options', |
| 320 | 311 | 'themes', |
| 321 | 312 | array( $this, 'rmp_theme_admin_page' ) |
| 322 | 313 | ); |
| @@ -393,9 +384,9 @@ | ||
| 393 | 384 | if ( 'rmp_menu' == $post->post_type ) { |
| 394 | 385 | $actions['edit'] = sprintf( |
| 395 | 386 | '<a href="%s" aria-label="Edit">%s</a>', |
| 396 | 387 | esc_url( get_edit_post_link( $post->ID ) ), |
| 397 | - esc_html__( 'Customize', 'responsive-menu' ) | |
| 388 | + __( 'Customize', 'responsive-menu' ) | |
| 398 | 389 | ); |
| 399 | 390 | } |
| 400 | 391 | |
| 401 | 392 | return $actions; |
| @@ -411,11 +402,11 @@ | ||
| 411 | 402 | * @return array $columns Edited columns list. |
| 412 | 403 | */ |
| 413 | 404 | public function set_custom_edit_menu_columns( $columns ) { |
| 414 | 405 | unset( $columns['date'] ); |
| 415 | - $columns['shortcode_place'] = esc_html__( 'Shortcode', 'responsive-menu' ); | |
| 416 | - $columns['actions'] = esc_html__( 'Actions', 'responsive-menu' ); | |
| 417 | - $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' ); | |
| 418 | 409 | |
| 419 | 410 | return $columns; |
| 420 | 411 | } |
| 421 | 412 | |
| @@ -428,10 +419,10 @@ | ||
| 428 | 419 | * @param int $post_id Post ID |
| 429 | 420 | * |
| 430 | 421 | * @return string $url Edited post url URL |
| 431 | 422 | */ |
| 432 | - public function my_edit_post_link( $url, $post_id ) { | |
| 433 | - 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 ) ) { | |
| 434 | 425 | $url = get_admin_url() . 'post.php?post=' . $post_id . '&action=edit&editor=true'; |
| 435 | 426 | } |
| 436 | 427 | |
| 437 | 428 | return $url; |
| @@ -481,26 +472,26 @@ | ||
| 481 | 472 | return; |
| 482 | 473 | } |
| 483 | 474 | |
| 484 | 475 | $labels = array( |
| 485 | - 'name' => esc_html__( 'Responsive Menu', 'responsive-menu' ), | |
| 486 | - 'singular_name' => 'Rmp_Menu', | |
| 487 | - 'menu_name' => esc_html__( 'Responsive Menu', 'responsive-menu' ), | |
| 488 | - 'parent_item_colon' => esc_html__( 'Parent Menu', 'responsive-menu' ), | |
| 489 | - 'all_items' => esc_html__( 'Menus', 'responsive-menu' ), | |
| 490 | - 'view_item' => esc_html__( 'View Menu', 'responsive-menu' ), | |
| 491 | - 'add_new_item' => esc_html__( 'Add New Menu', 'responsive-menu' ), | |
| 492 | - 'add_new' => esc_html__( 'Create New Menu', 'responsive-menu' ), | |
| 493 | - 'edit_item' => esc_html__( 'Edit Menu', 'responsive-menu' ), | |
| 494 | - 'update_item' => esc_html__( 'Update Menu', 'responsive-menu' ), | |
| 495 | - 'search_items' => esc_html__( 'Search Menu', 'responsive-menu' ), | |
| 496 | - 'not_found' => esc_html__( 'Not Found', 'responsive-menu' ), | |
| 497 | - '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' ), | |
| 498 | 489 | ); |
| 499 | 490 | |
| 500 | 491 | $args = array( |
| 501 | - 'label' => esc_html__( 'Responsive Menu', 'responsive-menu' ), | |
| 502 | - 'description' => esc_html__( 'Responsive Menu', 'responsive-menu' ), | |
| 492 | + 'label' => __( 'Responsive Menu', 'responsive-menu' ), | |
| 493 | + 'description' => __( 'Responsive Menu', 'responsive-menu' ), | |
| 503 | 494 | 'labels' => $labels, |
| 504 | 495 | 'supports' => array( 'title', 'author' ), |
| 505 | 496 | 'public' => false, |
| 506 | 497 | 'hierarchical' => false, |
| @@ -537,12 +528,17 @@ | ||
| 537 | 528 | public function rmp_export_menu() { |
| 538 | 529 | check_ajax_referer( 'rmp_nonce', 'ajax_nonce' ); |
| 539 | 530 | |
| 540 | 531 | $menu_id = isset( $_POST['menu_id'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_id'] ) ) : ''; |
| 532 | + | |
| 541 | 533 | if ( empty( $menu_id ) ) { |
| 542 | - wp_send_json_error( array( 'message' => esc_html__( 'Select menu !', 'responsive-menu' ) ) ); | |
| 534 | + wp_send_json_error( array( 'message' => __( 'Select menu !', 'responsive-menu' ) ) ); | |
| 543 | 535 | } |
| 544 | 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 | + | |
| 545 | 541 | $option_manager = Option_Manager::get_instance(); |
| 546 | 542 | $option = $option_manager->get_options( $menu_id ); |
| 547 | 543 | |
| 548 | 544 | wp_send_json_success( wp_json_encode( $option ) ); |
| @@ -558,23 +554,41 @@ | ||
| 558 | 554 | public function rmp_import_menu() { |
| 559 | 555 | check_ajax_referer( 'rmp_nonce', 'ajax_nonce' ); |
| 560 | 556 | |
| 561 | 557 | if ( empty( $_FILES['file']['name'] ) ) { |
| 562 | - 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' ) ) ); | |
| 563 | 559 | } |
| 564 | 560 | |
| 565 | 561 | if ( empty( $_FILES['file']['type'] ) || 'application/json' != $_FILES['file']['type'] ) { |
| 566 | - 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' ) ) ); | |
| 567 | 563 | } |
| 568 | 564 | |
| 569 | 565 | $menu_id = isset( $_POST['menu_id'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_id'] ) ) : ''; |
| 570 | 566 | if ( empty( $menu_id ) ) { |
| 571 | - wp_send_json_error( array( 'message' => esc_html__( 'Select menu !', 'responsive-menu' ) ) ); | |
| 567 | + wp_send_json_error( array( 'message' => __( 'Select menu !', 'responsive-menu' ) ) ); | |
| 572 | 568 | } |
| 573 | 569 | |
| 574 | - $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 | |
| 575 | 581 | $import_options = json_decode( $file_contents, true ); |
| 576 | 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 | + | |
| 577 | 591 | $option_manager = Option_Manager::get_instance(); |
| 578 | 592 | $exist_option = $option_manager->get_options( $menu_id ); |
| 579 | 593 | |
| 580 | 594 | // Some required options replced in imported settings with existing menu settings. |
| @@ -593,7 +607,7 @@ | ||
| 593 | 607 | * @param int $menu_id |
| 594 | 608 | */ |
| 595 | 609 | do_action( 'rmp_import_menu', $menu_id ); |
| 596 | 610 | |
| 597 | - 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' ) ) ); | |
| 598 | 612 | } |
| 599 | 613 | } |