PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 4.7.4
Responsive Menu – Create Mobile-Friendly Menu v4.7.4
4.7.4 4.7.3 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 All 91 releases
responsive-menu / v4.0.0 / inc / classes / class-editor-manager.php

class-editor-manager.php in Responsive Menu – Create Mobile-Friendly Menu 4.7.4, at v4.0.0/inc/classes/class-editor-manager.php

179 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Editor_Manager class.
4 * This class is responsible for editing the menu functionality.
5 *
6 * @version 4.0.0
7 * @author Expresstech System
8 *
9 * @package responsive-menu
10 */
11
12 namespace RMP\Features\Inc;
13
14 use RMP\Features\Inc\Traits\Singleton;
15 use RMP\Features\Inc\Option_Manager;
16
17 // Disable the direct access to this class.
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 /**
23 * Class Editor_Manager
24 */
25 class Editor_Manager {
26
27 use Singleton;
28
29 /**
30 * Construct method.
31 */
32 protected function __construct() {
33 $this->setup_hooks();
34 }
35
36 /**
37 * To setup action/filter.
38 *
39 * @version 4.0.0
40 *
41 * @return void
42 */
43 protected function setup_hooks() {
44 add_action( 'wp_ajax_rmp_save_menu_action', array( $this, 'rmp_save_options' ) );
45 add_action( 'wp_ajax_rmp_mega_menu_item_enable', array( $this, 'enable_mega_menu_item' ) );
46 add_action( 'wp_ajax_rmp_save_mega_menu_item', array( $this, 'rmp_save_mega_menu_item' ) );
47
48 // Hide the wp admin bar from preview iframe.
49 if ( ! empty( $_GET['rmp_preview_mode'] ) ) {
50 add_filter( 'show_admin_bar', '__return_false' );
51 }
52 }
53
54 /**
55 * This function save the settings and meta of mega menu item.
56 *
57 * @version 4.0.0
58 *
59 * @return json
60 */
61 public function rmp_save_mega_menu_item() {
62 check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
63
64 $item_id = isset( $_POST['item_id'] ) ? sanitize_text_field( wp_unslash( $_POST['item_id'] ) ) : '';
65 if ( empty( $item_id ) ) {
66 wp_send_json_error( array( 'message' => esc_html__( 'Menu Item ID missing', 'responsive-menu' ) ) );
67 }
68
69 $menu_id = isset( $_POST['menu_id'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_id'] ) ) : '';
70 if ( empty( $menu_id ) ) {
71 wp_send_json_error(
72 array( 'message' => esc_html__( 'Menu ID missing !', 'responsive-menu' ) )
73 );
74 }
75
76 if ( empty( $_POST['item_meta'] ) ) {
77 wp_send_json_error( array( 'message' => esc_html__( 'Unable to get mega menu settings', 'responsive-menu' ) ) );
78 }
79
80 $item_meta = array();
81
82 // Don't forget to sanitize the data using recursive.
83 if ( is_array( $_POST['item_meta'] ) ) {
84 $item_meta = intval( wp_unslash( $_POST['item_meta'] ) );
85 }
86
87 update_post_meta( $menu_id, '_rmp_mega_menu_' . $item_id, $item_meta );
88
89 /**
90 * Fires when mega menu item settings update.
91 *
92 * @version 4.0.0
93 *
94 * @param int $menu_id Menu Id.
95 * @param int $item_id Item ID for which mega menu settings are updated
96 * @param array $item_meta List of mega menu settings of an item.
97 */
98 do_action( 'rmp_update_mega_menu_item', $menu_id, $item_id, $item_meta );
99
100 wp_send_json_success( array( 'message' => 'success' ) );
101 }
102
103 /**
104 * Function to update the enable option of mega menu item.
105 *
106 * @version 4.0.0
107 *
108 * @return json
109 */
110 public function enable_mega_menu_item() {
111 check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
112
113 $menu_id = isset( $_POST['menu_id'] ) ? sanitize_text_field( wp_unslash( $_POST['menu_id'] ) ) : '';
114 $item_id = isset( $_POST['item_id'] ) ? sanitize_text_field( wp_unslash( $_POST['item_id'] ) ) : '';
115 $value = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
116
117 if ( ! current_user_can( 'edit_post', $menu_id ) ) {
118 wp_send_json_error( array( 'message' => __( 'You can not update menu !', 'responsive-menu' ) ) );
119 }
120
121 $options = get_post_meta( $menu_id, 'rmp_menu_meta' );
122
123 if ( ! empty( $options ) ) {
124 $options = $options[0];
125 $options['mega_menu'][ $item_id ] = $value;
126 $options = update_post_meta( $menu_id, 'rmp_menu_meta', $options );
127
128 wp_send_json_success( array( 'message' => esc_html__( 'Success', 'responsive-menu' ) ) );
129 }
130
131 wp_send_json_error(
132 array( 'message' => esc_html__( 'Menu not found', 'responsive-menu' ) )
133 );
134 }
135
136 /**
137 * This function saved the menu options when click update in the menu editor.
138 *
139 * @since 4.0.0
140 *
141 * @return json
142 */
143 public function rmp_save_options() {
144 check_ajax_referer( 'rmp_nonce', 'ajax_nonce' );
145 $options = array();
146 $form_data = isset( $_POST['form'] ) ? wp_unslash( $_POST['form'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
147 wp_parse_str( $form_data, $options );
148 $options = rm_sanitize_rec_array( $options, true );
149 if ( empty( $options['menu_id'] ) ) {
150 wp_send_json_error( array( 'message' => esc_html__( 'Menu ID missing !', 'responsive-menu' ) ) );
151 }
152
153 $menu_id = intval( $options['menu_id'] );
154
155 if ( ! current_user_can( 'edit_post', $menu_id ) ) {
156 wp_send_json_error( array( 'message' => __( 'You can not edit menu !', 'responsive-menu' ) ) );
157 }
158
159 $options = $options['menu'];
160
161 // Merge the default and update options.
162 $options = array_merge( rmp_get_default_options(), $options );
163
164 update_post_meta( $menu_id, 'rmp_menu_meta', $options );
165 update_post_meta( $menu_id, 'rmp_lagecy_menu_line_space', 1 );
166
167 /**
168 * Fires when saved the options.
169 *
170 * @version 4.0.0
171 * @param int $menu_id Menu ID.
172 */
173 do_action( 'rmp_save_menu', $menu_id );
174
175 // Return the response after success.
176 wp_send_json_success();
177 }
178 }
179