PluginProbe
Easy Hotel – Powerful Hotel Booking / 2.0.2
Easy Hotel – Powerful Hotel Booking v2.0.2
2.0.8 2.0.7 2.0.6 2.0.5 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.9.9 1.9.8 1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 All 110 releases
easy-hotel / admin / includes / framework / classes / nav-menu-options.class.php

nav-menu-options.class.php in Easy Hotel – Powerful Hotel Booking 2.0.2, at admin/includes/framework/classes/nav-menu-options.class.php

261 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
2 /**
3 *
4 * Nav Menu Options Class
5 *
6 * @since 1.0.0
7 * @version 1.0.0
8 *
9 */
10 if ( ! class_exists( 'ESHB_Nav_Menu_Options' ) ) {
11 class ESHB_Nav_Menu_Options extends ESHB_Abstract{
12
13 // constans
14 public $unique = '';
15 public $abstract = 'menu';
16 public $sections = array();
17 public $pre_fields = array();
18 public $args = array(
19 'data_type' => 'serialize',
20 'class' => '',
21 'defaults' => array(),
22 );
23
24 // run menu construct
25 public function __construct( $key, $params ) {
26
27 $this->unique = $key;
28 $this->args = apply_filters( "eshb_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this );
29 $this->sections = apply_filters( "eshb_{$this->unique}_sections", $params['sections'], $this );
30 $this->pre_fields = $this->pre_fields( $this->sections );
31
32 add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'wp_nav_menu_item_custom_fields' ), 10, 4 );
33 add_action( 'wp_update_nav_menu_item', array( $this, 'wp_update_nav_menu_item' ), 10, 3 );
34
35 add_filter( 'wp_edit_nav_menu_walker', array( $this, 'wp_edit_nav_menu_walker' ), 10, 2 );
36
37 }
38
39 // instance
40 public static function instance( $key, $params ) {
41 return new self( $key, $params );
42 }
43
44 public function wp_edit_nav_menu_walker( $class, $menu_id ) {
45
46 global $wp_version;
47
48 if( version_compare( $wp_version, '5.4.0', '<' ) ) {
49
50 if ( ! class_exists( 'ESHB_Walker_Nav_Menu_Edit' ) ) {
51 ESHB::include_plugin_file( 'functions/walker.php' );
52 }
53
54 return 'ESHB_Walker_Nav_Menu_Edit';
55
56 }
57
58 return $class;
59
60 }
61
62 // get default value
63 public function get_default( $field ) {
64
65 $default = ( isset( $field['default'] ) ) ? $field['default'] : '';
66 $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default;
67
68 return $default;
69
70 }
71
72 // get meta value
73 public function get_meta_value( $menu_item_id, $field ) {
74
75 $value = null;
76
77 if ( ! empty( $menu_item_id ) && ! empty( $field['id'] ) ) {
78
79 if ( $this->args['data_type'] !== 'serialize' ) {
80 $meta = get_post_meta( $menu_item_id, $field['id'] );
81 $value = ( isset( $meta[0] ) ) ? $meta[0] : null;
82 } else {
83 $meta = get_post_meta( $menu_item_id, $this->unique, true );
84 $value = ( isset( $meta[$field['id']] ) ) ? $meta[$field['id']] : null;
85 }
86
87 }
88
89 $default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : '';
90 $value = ( isset( $value ) ) ? $value : $default;
91
92 return $value;
93
94 }
95
96 //
97 public function wp_nav_menu_item_custom_fields( $menu_item_id, $item, $depth, $args ) {
98
99 $errors = ( ! empty( $menu_item_id ) ) ? get_post_meta( $menu_item_id, '_eshb_errors_'. $this->unique, true ) : array();
100 $errors = ( ! empty( $errors ) ) ? $errors : array();
101 $class = ( $this->args['class'] ) ? ' '. $this->args['class'] : '';
102
103 if ( ! empty( $errors ) ) {
104 delete_post_meta( $menu_item_id, '_eshb_errors_'. $this->unique );
105 }
106
107 echo '<div class="csf csf-nav-menu-options'. esc_attr( $class ) .'">';
108
109 foreach ( $this->sections as $section ) {
110
111 $section_icon = ( ! empty( $section['icon'] ) ) ? '<i class="csf-nav-menu-icon '. esc_attr( $section['icon'] ) .'"></i>' : '';
112 $section_title = ( ! empty( $section['title'] ) ) ? $section['title'] : '';
113
114 echo '<div class="csf-fields">';
115
116 echo ( $section_title || $section_icon ) ? '<div class="csf-nav-menu-title"><h4>'. wp_kses_post($section_icon) . esc_html($section_title) .'</h4></div>' : '';
117 echo ( ! empty( $section['description'] ) ) ? '<div class="csf-field csf-section-description">'. esc_html($section['description']) .'</div>' : '';
118
119
120 if ( ! empty( $section['fields'] ) ) {
121
122 foreach ( $section['fields'] as $field ) {
123
124 if ( ! empty( $field['id'] ) && ! empty( $errors['fields'][$field['id']] ) ) {
125 $field['_error'] = $errors['fields'][$field['id']];
126 }
127
128 if ( ! empty( $field['id'] ) ) {
129 $field['default'] = $this->get_default( $field );
130 }
131
132 ESHB::field( $field, $this->get_meta_value( $menu_item_id, $field ), $this->unique .'['. $menu_item_id .']', 'menu' );
133
134 }
135
136 }
137
138 echo '</div>';
139
140 }
141
142 echo '</div>';
143
144 }
145
146 public function wp_update_nav_menu_item( $menu_id, $menu_item_db_id, $menu_item_args ) {
147
148 $count = 1;
149 $data = array();
150 $errors = array();
151 $noncekey = 'update-nav-menu-nonce';
152 $nonce = ( ! empty( $_POST[ $noncekey ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ $noncekey ] ) ) : '';
153
154 if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! wp_verify_nonce( $nonce, 'update-nav_menu' ) ) {
155 return $menu_item_db_id;
156 }
157
158 // XSS ok.
159 // No worries, This "POST" requests is sanitizing in the below foreach.
160 $request = ( ! empty( $_POST[ $this->unique ][ $menu_item_db_id ] ) ) ? sanitize_text_field( wp_unslash($_POST[ $this->unique ]))[ $menu_item_db_id ] : array();
161
162 if ( ! empty( $request ) ) {
163
164 foreach ( $this->sections as $section ) {
165
166 if ( ! empty( $section['fields'] ) ) {
167
168 foreach ( $section['fields'] as $field ) {
169
170 if ( ! empty( $field['id'] ) ) {
171
172 $field_id = $field['id'];
173 $field_value = isset( $request[$field_id] ) ? $request[$field_id] : '';
174
175 // Sanitize "post" request of field.
176 if ( ! isset( $field['sanitize'] ) ) {
177
178 if( is_array( $field_value ) ) {
179 $data[$field_id] = wp_kses_post_deep( $field_value );
180 } else {
181 $data[$field_id] = wp_kses_post( $field_value );
182 }
183
184 } else if( isset( $field['sanitize'] ) && is_callable( $field['sanitize'] ) ) {
185
186 $data[$field_id] = call_user_func( $field['sanitize'], $field_value );
187
188 } else {
189
190 $data[$field_id] = $field_value;
191
192 }
193
194 // Validate "post" request of field.
195 if ( isset( $field['validate'] ) && is_callable( $field['validate'] ) ) {
196
197 $has_validated = call_user_func( $field['validate'], $field_value );
198
199 if ( ! empty( $has_validated ) ) {
200
201 $errors['sections'][$count] = true;
202 $errors['fields'][$field_id] = $has_validated;
203 $data[$field_id] = $this->get_meta_value( $menu_item_db_id, $field );
204
205 }
206
207 }
208
209 }
210
211 }
212
213 }
214
215 $count++;
216
217 }
218
219 }
220
221 $data = apply_filters( "eshb_{$this->unique}_save", $data, $menu_item_db_id, $this );
222
223 do_action( "eshb_{$this->unique}_save_before", $data, $menu_item_db_id, $this );
224
225 if ( empty( $data ) ) {
226
227 if ( $this->args['data_type'] !== 'serialize' ) {
228 foreach ( $this->pre_fields as $field ) {
229 if ( ! empty( $field['id'] ) ) {
230 delete_post_meta( $menu_item_db_id, $field['id'] );
231 }
232 }
233 } else {
234 delete_post_meta( $menu_item_db_id, $this->unique );
235 }
236
237 } else {
238
239 if ( $this->args['data_type'] !== 'serialize' ) {
240 foreach ( $data as $key => $value ) {
241 update_post_meta( $menu_item_db_id, $key, $value );
242 }
243 } else {
244 update_post_meta( $menu_item_db_id, $this->unique, $data );
245 }
246
247 if ( ! empty( $errors ) ) {
248 update_post_meta( $menu_item_db_id, '_eshb_errors_'. $this->unique, $errors );
249 }
250
251 }
252
253 do_action( "eshb_{$this->unique}_saved", $data, $menu_item_db_id, $this );
254
255 do_action( "eshb_{$this->unique}_save_after", $data, $menu_item_db_id, $this );
256
257 }
258
259 }
260 }
261