PluginProbe
Property Hive / 2.3.0
Property Hive v2.3.0
2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 1.4.62 All 260 releases
propertyhive / includes / admin / ph-meta-box-functions.php

ph-meta-box-functions.php in Property Hive 2.3.0, at includes/admin/ph-meta-box-functions.php

584 lines 25.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Meta Box Functions
4 *
5 * @author PropertyHive
6 * @category Core
7 * @package PropertyHive/Admin/Functions
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
13 /**
14 * Output a text input box.
15 *
16 * @access public
17 * @param array $field
18 * @return void
19 */
20 function propertyhive_wp_text_input( $field ) {
21 global $thepostid, $post, $propertyhive;
22
23 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared meta-box global contract; $thepostid is intentionally carried into the public Property Hive field-rendering helpers.
24 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
25
26 $field = apply_filters( 'propertyhive_meta_box_wp_text_field', $field, $thepostid );
27
28 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
29 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
30 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
31 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
32 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
33 $field['type'] = isset( $field['type'] ) ? $field['type'] : 'text';
34 $data_type = empty( $field['data_type'] ) ? '' : $field['data_type'];
35
36 switch ( $data_type ) {
37 case 'price' :
38 $field['class'] .= ' ph_input_price';
39 $field['value'] = ph_format_localized_price( $field['value'] );
40 break;
41 case 'decimal' :
42 $field['class'] .= ' ph_input_decimal';
43 $field['value'] = ph_format_localized_decimal( $field['value'] );
44 break;
45 }
46
47 // Custom attribute handling
48 $custom_attributes = array();
49
50 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) )
51 foreach ( $field['custom_attributes'] as $attribute => $value )
52 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
53
54 echo '
55 <p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '">
56 <label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>
57 <input type="' . esc_attr( $field['type'] ) . '" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ';
58 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Custom attributes come from the PHP field definition/filter; every name and value is escaped above before assembling this attribute fragment.
59 echo implode( ' ', $custom_attributes );
60 echo ' /> ';
61
62 if ( ! empty( $field['description'] ) ) {
63
64 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
65 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( PH()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
66 } else {
67 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
68 }
69
70 }
71 echo '</p>';
72 }
73
74 /**
75 * Output a photo input box.
76 *
77 * @access public
78 * @param array $field
79 * @return void
80 */
81 function propertyhive_wp_photo_upload( $field ) {
82 global $thepostid, $post, $propertyhive;
83
84 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared meta-box global contract; $thepostid is intentionally carried into the public Property Hive field-rendering helpers.
85 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
86
87 $field = apply_filters( 'propertyhive_meta_box_wp_photo_upload_field', $field, $thepostid );
88
89 $field['id'] = isset( $field['id'] ) ? $field['id'] : '';
90 $field['button_label'] = isset( $field['button_label'] ) ? $field['button_label'] : __('Select Photo', 'propertyhive');
91 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
92 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
93 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
94 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
95 $data_type = empty( $field['data_type'] ) ? '' : $field['data_type'];
96
97 // Custom attribute handling
98 $custom_attributes = array();
99
100 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) )
101 foreach ( $field['custom_attributes'] as $attribute => $value )
102 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
103
104 propertyhive_wp_hidden_input( $field );
105
106 echo '
107 <p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"';
108 if ( $field['value'] == '' )
109 {
110 echo ' style="display:none;"';
111 }
112 echo '>
113 <label for="' . esc_attr( $field['id'] ) . '">' . esc_html(__( 'Uploaded', 'propertyhive' )) . ' ' . wp_kses_post( $field['label'] ) . '</label>
114 <span>';
115 if ( $field['value'] != '' )
116 {
117 $image = wp_get_attachment_image_src( $field['value'], 'thumbnail' );
118 if ($image !== FALSE)
119 {
120 echo '<img src="' . esc_url($image[0]) . '" width="150" alt="">';
121 }
122 else
123 {
124 echo 'Image doesn\'t exist';
125 }
126 }
127 echo '</span>
128 </p>';
129
130 echo '
131 <p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '">
132 <label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>
133 <a href="" class="button button-primary ph_upload_photo_button' . esc_attr($field['id']) . '">' . esc_html($field['button_label']) . '</a>';
134
135 if ( ! empty( $field['description'] ) ) {
136
137 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
138 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( PH()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
139 } else {
140 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
141 }
142
143 }
144 echo '</p>';
145
146 echo '<script>
147
148 var file_frame' . esc_js($field['id']) . ';
149
150 jQuery(document).ready(function()
151 {
152 jQuery(\'body\').on(\'click\', \'.ph_upload_photo_button' . esc_js($field['id']) . '\', function( event ){
153
154 event.preventDefault();
155
156 // If the media frame already exists, reopen it.
157 if ( file_frame' . esc_js($field['id']) . ' ) {
158 file_frame' . esc_js($field['id']) . '.open();
159 return;
160 }
161
162 // Create the media frame.
163 file_frame' . esc_js($field['id']) . ' = wp.media.frames.file_frame' . esc_js($field['id']) . ' = wp.media({
164 title: jQuery( this ).data( \'uploader_title\' ),
165 button: {
166 text: jQuery( this ).data( \'uploader_button_text\' ),
167 },
168 multiple: false // Set to true to allow multiple files to be selected
169 });
170
171 // When an image is selected, run a callback.
172 file_frame' . esc_js($field['id']) . '.on( \'select\', function() {
173 var selection = file_frame' . esc_js($field['id']) . '.state().get(\'selection\');
174
175 selection.map( function( attachment ) {
176
177 attachment = attachment.toJSON();
178
179 // Do something with attachment.id and/or attachment.url here
180 console.log(attachment);
181
182 jQuery(\'.form-field.' . esc_js( $field['id'] ) . '_field\').show();
183 jQuery(\'.form-field.' . esc_js( $field['id'] ) . '_field span\').html(\'<img src="\' + attachment.url + \'" width="150" alt="">\');
184 jQuery(\'#' . esc_js( $field['id'] ) . '\').val(attachment.id);
185 });
186 });
187
188 // Finally, open the modal
189 file_frame' . esc_js($field['id']) . '.open();
190 });
191 });
192
193 </script>';
194 }
195
196 /**
197 * Output a file input box.
198 *
199 * @access public
200 * @param array $field
201 * @return void
202 */
203 function propertyhive_wp_file_upload( $field ) {
204 global $thepostid, $post, $propertyhive;
205
206 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared meta-box global contract; $thepostid is intentionally carried into the public Property Hive field-rendering helpers.
207 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
208
209 $field = apply_filters( 'propertyhive_meta_box_wp_file_upload_field', $field, $thepostid );
210
211 $field['id'] = isset( $field['id'] ) ? $field['id'] : '';
212 $field['button_label'] = isset( $field['button_label'] ) ? $field['button_label'] : __('Select Photo', 'propertyhive');
213 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
214 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
215 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
216 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
217 $data_type = empty( $field['data_type'] ) ? '' : $field['data_type'];
218
219 // Custom attribute handling
220 $custom_attributes = array();
221
222 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) )
223 foreach ( $field['custom_attributes'] as $attribute => $value )
224 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
225
226 propertyhive_wp_hidden_input( $field );
227
228 echo '
229 <p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"';
230 if ( $field['value'] == '' )
231 {
232 echo ' style="display:none;"';
233 }
234 echo '>
235 <label for="' . esc_attr( $field['id'] ) . '">' . esc_html(__( 'Uploaded', 'propertyhive' )) . ' ' . wp_kses_post( $field['label'] ) . '</label>
236 <span>';
237 if ( $field['value'] != '' )
238 {
239 $file = get_attached_file( $field['value'] );
240 if ( $file !== FALSE )
241 {
242 $filename = basename( $file );
243 echo '<a href="' . esc_url(wp_get_attachment_url($field['value'])) . '" target="_blank">' . esc_html($filename) . '</a>';
244 }
245 else
246 {
247 echo 'Image doesn\'t exist';
248 }
249 }
250 echo '</span>
251 </p>';
252
253 echo '
254 <p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '">
255 <label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>
256 <a href="" class="button button-primary ph_upload_file_button' . esc_attr($field['id']) . '">' . esc_html($field['button_label']) . '</a>';
257
258 if ( ! empty( $field['description'] ) ) {
259
260 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
261 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( PH()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
262 } else {
263 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
264 }
265
266 }
267 echo '</p>';
268
269 echo '<script>
270
271 var file_frame' . esc_js($field['id']) . ';
272
273 jQuery(document).ready(function()
274 {
275 jQuery(\'body\').on(\'click\', \'.ph_upload_file_button' . esc_js($field['id']) . '\', function( event ){
276
277 event.preventDefault();
278
279 // If the media frame already exists, reopen it.
280 if ( file_frame' . esc_js($field['id']) . ' ) {
281 file_frame' . esc_js($field['id']) . '.open();
282 return;
283 }
284
285 // Create the media frame.
286 file_frame' . esc_js($field['id']) . ' = wp.media.frames.file_frame' . esc_js($field['id']) . ' = wp.media({
287 title: jQuery( this ).data( \'uploader_title\' ),
288 button: {
289 text: jQuery( this ).data( \'uploader_button_text\' ),
290 },
291 multiple: false // Set to true to allow multiple files to be selected
292 });
293
294 // When an image is selected, run a callback.
295 file_frame' . esc_js($field['id']) . '.on( \'select\', function() {
296 var selection = file_frame' . esc_js($field['id']) . '.state().get(\'selection\');
297
298 selection.map( function( attachment ) {
299
300 attachment = attachment.toJSON();
301
302 // Do something with attachment.id and/or attachment.url here
303 console.log(attachment);
304
305 jQuery(\'.form-field.' . esc_js($field['id']) . '_field\').show();
306 jQuery(\'.form-field.' . esc_js($field['id']) . '_field span\').html(\'<a href="\' + attachment.url + \'" target="_blank">\' + attachment.filename + \'</a>\');
307 jQuery(\'#' . esc_js($field['id']) . '\').val(attachment.id);
308 });
309 });
310
311 // Finally, open the modal
312 file_frame' . esc_js($field['id']) . '.open();
313 });
314 });
315
316 </script>';
317 }
318
319 /**
320 * Output a hidden input box.
321 *
322 * @access public
323 * @param array $field
324 * @return void
325 */
326 function propertyhive_wp_hidden_input( $field ) {
327 global $thepostid, $post;
328
329 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared meta-box global contract; $thepostid is intentionally carried into the public Property Hive field-rendering helpers.
330 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
331
332 $field = apply_filters( 'propertyhive_meta_box_wp_hidden_field', $field, $thepostid );
333
334 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
335
336 echo '<input type="hidden" name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" /> ';
337 }
338
339 /**
340 * Output a textarea input box.
341 *
342 * @access public
343 * @param array $field
344 * @return void
345 */
346 function propertyhive_wp_textarea_input( $field ) {
347 global $thepostid, $post, $propertyhive;
348
349 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared meta-box global contract; $thepostid is intentionally carried into the public Property Hive field-rendering helpers.
350 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
351
352 $field = apply_filters( 'propertyhive_meta_box_wp_textarea_field', $field, $thepostid );
353
354 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
355 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
356 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
357 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
358 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
359
360 // Custom attribute handling
361 $custom_attributes = array();
362
363 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) )
364 foreach ( $field['custom_attributes'] as $attribute => $value )
365 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
366
367 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><textarea class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" rows="2" cols="20" ';
368 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Custom attributes come from the PHP field definition/filter; every name and value is escaped above before assembling this attribute fragment.
369 echo implode( ' ', $custom_attributes );
370 echo '>' . esc_textarea( $field['value'] ) . '</textarea> ';
371
372 if ( ! empty( $field['description'] ) ) {
373
374 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
375 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( PH()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
376 } else {
377 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
378 }
379
380 }
381 echo '</p>';
382 }
383
384 /**
385 * Output a checkbox input box.
386 *
387 * @access public
388 * @param array $field
389 * @return void
390 */
391 function propertyhive_wp_checkbox( $field ) {
392 global $thepostid, $post;
393
394 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared meta-box global contract; $thepostid is intentionally carried into the public Property Hive field-rendering helpers.
395 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
396
397 $field = apply_filters( 'propertyhive_meta_box_wp_checkbox_field', $field, $thepostid );
398
399 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'checkbox';
400 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
401 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
402 $field['cbvalue'] = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'yes';
403 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
404
405 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><input type="checkbox" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['cbvalue'] ) . '" ' . checked( $field['value'], $field['cbvalue'], false ) . ' /> ';
406
407 if ( ! empty( $field['description'] ) ) echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
408
409 echo '</p>';
410 }
411
412 /**
413 * Output a groupd of checkbox input boxes.
414 *
415 * @access public
416 * @param array $field
417 * @return void
418 */
419 function propertyhive_wp_checkboxes( $field ) {
420 global $thepostid, $post;
421
422 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared meta-box global contract; $thepostid is intentionally carried into the public Property Hive field-rendering helpers.
423 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
424
425 $field = apply_filters( 'propertyhive_meta_box_wp_checkboxes_field', $field, $thepostid );
426
427 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'checkbox';
428 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
429 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
430 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['name'], true );
431
432 echo '<fieldset class="form-field ' . esc_attr( $field['wrapper_class'] ) . '"><legend>' . wp_kses_post( $field['label'] ) . '</legend><ul class="ph-radios">';
433
434 foreach ( $field['options'] as $key => $value ) {
435 echo '<li><label><input type="checkbox" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '[]" id="' . esc_attr( $field['name'] . '_' . $key ) . '" value="' . esc_attr( $key ) . '" ' . ( ( !empty($field['value']) && in_array( $key, $field['value'] ) ) ? 'checked' : '' ) . ' /> ' . esc_html($value) . '</label></li>';
436 }
437
438 echo '</ul>';
439
440 if ( ! empty( $field['description'] ) ) echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
441
442 echo '</fieldset>';
443 }
444
445 /**
446 * Output a select input box.
447 *
448 * @access public
449 * @param array $field
450 * @return void
451 */
452 function propertyhive_wp_select( $field ) {
453 global $thepostid, $post, $propertyhive;
454
455 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared meta-box global contract; $thepostid is intentionally carried into the public Property Hive field-rendering helpers.
456 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
457
458 $field = apply_filters( 'propertyhive_meta_box_wp_select_field', $field, $thepostid );
459
460 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
461 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
462 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
463 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
464
465 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><select id="' . esc_attr( $field['id'] ) . '" name="' . esc_attr( $field['name'] ) . '" class="' . esc_attr( $field['class'] ) . '">';
466
467 foreach ( $field['options'] as $key => $value ) {
468
469 echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
470
471 }
472
473 echo '</select> ';
474
475 if ( ! empty( $field['description'] ) ) {
476
477 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
478 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( PH()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
479 } else {
480 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
481 }
482
483 }
484 echo '</p>';
485 }
486
487 /**
488 * Output a select input box with optgroups.
489 *
490 * @access public
491 * @param array $field
492 * @return void
493 */
494 function propertyhive_wp_select_optgroups( $field ) {
495 global $thepostid, $post, $propertyhive;
496
497 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared meta-box global contract; $thepostid is intentionally carried into the public Property Hive field-rendering helpers.
498 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
499
500 $field = apply_filters( 'propertyhive_meta_box_wp_select_optgroups_field', $field, $thepostid );
501
502 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
503 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
504 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
505
506 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><select id="' . esc_attr( $field['id'] ) . '" name="' . esc_attr( $field['id'] ) . '" class="' . esc_attr( $field['class'] ) . '">';
507
508 echo '<option value="" ' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . '></option>';
509
510 foreach ( $field['options'] as $optgroup => $options ) {
511
512 echo '<optgroup label="' . esc_html( $optgroup ) . '">';
513
514 foreach ( $options as $key => $value ) {
515
516 echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
517
518 }
519
520 echo '</optgroup>';
521
522 }
523
524 echo '</select> ';
525
526 if ( ! empty( $field['description'] ) ) {
527
528 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
529 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( PH()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
530 } else {
531 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
532 }
533
534 }
535 echo '</p>';
536 }
537
538 /**
539 * Output a radio input box.
540 *
541 * @access public
542 * @param array $field
543 * @return void
544 */
545 function propertyhive_wp_radio( $field ) {
546 global $thepostid, $post, $propertyhive;
547
548 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared meta-box global contract; $thepostid is intentionally carried into the public Property Hive field-rendering helpers.
549 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
550
551 $field = apply_filters( 'propertyhive_meta_box_wp_radio_field', $field, $thepostid );
552
553 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
554 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
555 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
556 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
557
558 echo '<fieldset class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><legend>' . wp_kses_post( $field['label'] ) . '</legend><ul class="ph-radios">';
559
560 foreach ( $field['options'] as $key => $value ) {
561
562 echo '<li><label><input
563 name="' . esc_attr( $field['name'] ) . '"
564 value="' . esc_attr( $key ) . '"
565 type="radio"
566 class="' . esc_attr( $field['class'] ) . '"
567 ' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '
568 /> ' . esc_html( $value ) . '</label>
569 </li>';
570 }
571 echo '</ul>';
572
573 if ( ! empty( $field['description'] ) ) {
574
575 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
576 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( PH()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
577 } else {
578 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
579 }
580
581 }
582
583 echo '</fieldset>';
584 }