PluginProbe
CBX Map for Google Map & OpenStreetMap / 2.0.0
CBX Map for Google Map & OpenStreetMap v2.0.0
trunk 1.1.10 1.1.11 1.1.12 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5
cbxgooglemap / includes / Helpers / CBXGooglemapMetaHelper.php

CBXGooglemapMetaHelper.php in CBX Map for Google Map & OpenStreetMap 2.0.0, at includes/Helpers/CBXGooglemapMetaHelper.php

563 lines 24.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Cbx\Googlemap\Helpers;
3
4 // If this file is called directly, abort.
5 if ( ! defined( 'WPINC' ) ) {
6 die;
7 }
8
9 use Cbx\Googlemap\CBXGooglemapSettings;
10
11
12 class CBXGooglemapMetaHelper {
13 /**
14 * Session field sections
15 *
16 * @param int $post_id
17 *
18 * @return array
19 */
20 public static function meta_field_sections( $post_id = 0, $post_type = 'cbxgooglemap' ) {
21 $sections = [
22 'mapsettings' => esc_html__( 'Map Settings', 'cbxgooglemap' ),
23 'maplocation' => esc_html__( 'Primary Marker', 'cbxgooglemap' ),
24 ];
25
26 return apply_filters( 'cbxgooglemap_sections', $sections );
27 }//end method meta_field_sections
28
29 /**
30 * Meta fields for sessions
31 *
32 * @param int $post_id
33 *
34 * @return array
35 */
36 public static function cbxgooglemap_meta_fields( $post_id = 0 ) {
37 $meta_fields = [];
38 $settings = new CBXGooglemapSettings();
39 $general_settings = get_option( 'cbxgooglemap_general', [] );
40
41 $zoom_level = intval( $settings->get_field( 'zoom', 'cbxgooglemap_general', '8' ) );
42 if ( $zoom_level == 0 ) {
43 $zoom_level = 8;
44 }
45
46
47 $width_default = $settings->get_field( 'width', 'cbxgooglemap_general', '100%' );
48 if ( $width_default == '' || $width_default == 0 ) {
49 $width_default = '100%';
50 }
51
52
53 $height_default = intval( $settings->get_field( 'height', 'cbxgooglemap_general', '300' ) );
54 if ( $height_default == 0 ) {
55 $height_default = 300;
56 }
57
58 $scrollwheel = intval( $settings->get_field( 'scrollwheel', 'cbxgooglemap_general', 1 ) );
59 $showinfo = intval( $settings->get_field( 'showinfo', 'cbxgooglemap_general', 1 ) );
60 $infow_open = intval( $settings->get_field( 'infow_open', 'cbxgooglemap_general', 1 ) );
61 $maptype = $settings->get_field( 'maptype', 'cbxgooglemap_general', 'roadmap' );
62
63
64 $meta_fields['mapsettings'] = apply_filters( 'cbxgooglemap_mapsettings_fields', [
65 'maptype' => [
66 'label' => esc_html__( 'Map Type', 'cbxgooglemap' ),
67 'type' => 'select',
68 'default' => $maptype,
69 'options' => [
70 'roadmap' => esc_html__( 'Road Map', 'cbxgooglemap' ),
71 'satellite' => esc_html__( 'Satellite Map', 'cbxgooglemap' ),
72 'hybrid' => esc_html__( 'Hybrid Map', 'cbxgooglemap' ),
73 'terrain' => esc_html__( 'Terrain Map', 'cbxgooglemap' ),
74 ],
75 'desc' => esc_html__( 'Google Map only', 'cbxgooglemap' ),
76 'sanitize_callback' => 'sanitize_text_field'
77 ],
78 'zoom' => [
79 'label' => esc_html__( 'Zoom Level', 'cbxgooglemap' ),
80 'desc' => esc_html__( 'Plain address with road no etc', 'cbxgooglemap' ),
81 'type' => 'text',
82 'default' => $zoom_level,
83 'sanitize_callback' => 'sanitize_text_field'
84 ],
85 'width' => [
86 'label' => esc_html__( 'Width', 'cbxgooglemap' ),
87 'desc' => esc_html__( 'Map width, use % if need, don\'t use px as it will be automatically if no % used.', 'cbxgooglemap' ),
88 'type' => 'text',
89 'default' => $width_default,
90 ],
91 'height' => [
92 'label' => esc_html__( 'Height', 'cbxgooglemap' ),
93 'desc' => esc_html__( 'Map height, don\'t use px', 'cbxgooglemap' ),
94 'type' => 'text',
95 'default' => $height_default,
96 'sanitize_callback' => 'sanitize_text_field'
97 ],
98 'scrollwheel' => [
99 'label' => esc_html__( 'Mouse Scroll Wheel', 'cbxgooglemap' ),
100 'desc' => esc_html__( 'Enable/disable mouse scroll whell', 'cbxgooglemap' ),
101 'type' => 'radio',
102 'default' => $scrollwheel,
103 'desc_tip' => true,
104 'options' => [
105 '1' => esc_html__( 'Enable', 'cbxgooglemap' ),
106 '0' => esc_html__( 'Disable', 'cbxgooglemap' ),
107 ],
108 'inline' => true,
109 'sanitize_callback' => 'absint'
110 ],
111 'showinfo' => [
112 'label' => esc_html__( 'Show Info window', 'cbxgooglemap' ),
113 'desc' => esc_html__( 'Show information on click of marker', 'cbxgooglemap' ),
114 'type' => 'radio',
115 'default' => $showinfo,
116 'desc_tip' => true,
117 'options' => [
118 '1' => esc_html__( 'Enable', 'cbxgooglemap' ),
119 '0' => esc_html__( 'Disable', 'cbxgooglemap' ),
120 ],
121 'inline' => true,
122 'sanitize_callback' => 'absint'
123 ],
124 'infow_open' => [
125 'label' => esc_html__( 'Info/Popup Window', 'cbxgooglemap' ),
126 'type' => 'radio',
127 'default' => $infow_open,
128 'desc_tip' => true,
129 'options' => [
130 '1' => esc_html__( 'Open(Default)', 'cbxgooglemap' ),
131 '0' => esc_html__( 'On Click', 'cbxgooglemap' ),
132 ],
133 'inline' => true,
134 'sanitize_callback' => 'absint'
135 ],
136 ] );
137
138 $meta_fields['maplocation'] = apply_filters( 'cbxgooglemap_maplocation_fields', [
139 'title' => [
140 'label' => esc_html__( 'Marker Heading', 'cbxgooglemap' ),
141 'desc' => esc_html__( 'Heading title will be used for marker pop info', 'cbxgooglemap' ),
142 'type' => 'text',
143 'default' => 'Default Title',
144 'sanitize_callback' => 'sanitize_text_field'
145 ],
146 'address' => [
147 'label' => esc_html__( 'Address', 'cbxgooglemap' ),
148 'desc' => esc_html__( 'Plain address with road no etc', 'cbxgooglemap' ),
149 'type' => 'text',
150 'default' => '',
151 'sanitize_callback' => 'sanitize_text_field'
152 ],
153 'website' => [
154 'label' => esc_html__( 'Website Link', 'cbxgooglemap' ),
155 'desc' => esc_html__( 'If website link is given then market popup will show the Title as linked with this address', 'cbxgooglemap' ),
156 'type' => 'text',
157 'default' => '',
158 'sanitize_callback' => 'sanitize_text_field'
159 ],
160 'location' => [
161 'label' => esc_html__( 'Map Location', 'cbxgooglemap' ),
162 'desc' => esc_html__( 'Type location and select from google map auto suggest.', 'cbxgooglemap' ),
163 'type' => 'location',
164 'default' => '',
165 ],
166 'lat' => [
167 'label' => esc_html__( 'Latitude', 'cbxgooglemap' ),
168 'desc' => esc_html__( 'If you select location from google map then latitude will be picked automatically but still you can put manually', 'cbxgooglemap' ),
169 'type' => 'lat',
170 'default' => '',
171 'sortable' => true,
172 'sanitize_callback' => 'sanitize_text_field'
173 ],
174 'lng' => [
175 'label' => esc_html__( 'Longitude', 'cbxgooglemap' ),
176 'desc' => esc_html__( 'If you select location from google map then longitude will be picked automatically but still you can put manually', 'cbxgooglemap' ),
177 'type' => 'lng',
178 'default' => '',
179 'sortable' => true,
180 'sanitize_callback' => 'sanitize_text_field'
181 ],
182
183 'mapicon' => [
184 'label' => esc_html__( 'Map Icon', 'cbxgooglemap' ),
185 'desc' => esc_html__( 'Map marker custom icon', 'cbxgooglemap' ),
186 'type' => 'file',
187 'default' => '',
188 'desc_tip' => true,
189 'sanitize_callback' => 'sanitize_text_field'
190 ],
191
192 ] );
193
194 return apply_filters( 'cbxgooglemap_fields', $meta_fields );
195 }//end method cbxgooglemap_meta_fields
196
197 /**
198 * Render the meta fields html
199 *
200 * @param $post
201 * @param $meta_fields
202 * @param $combined_field
203 * @param $meta_prefix
204 * @param $sectionable
205 *
206 * @return void\
207 */
208 public static function render_meta_fields( $post, $meta_fields, $combined_field, $meta_prefix, $sectionable = false ) {
209 $settings = new CBXGooglemapSettings();
210
211 $general_settings = get_option( 'cbxgooglemap_general', [] );
212
213 $api_key = esc_attr( $settings->get_field( 'apikey', 'cbxgooglemap_general', '' ) );
214 $map_source = absint( $settings->get_field( 'mapsource', 'cbxgooglemap_general', 1 ) );
215 $scrollwheel_default = absint( $settings->get_field( 'scrollwheel', 'cbxgooglemap_general', 1 ) );
216 $showinfo_default = absint( $settings->get_field( 'showinfo', 'cbxgooglemap_general', 1 ) );
217
218 $mapicon_default = esc_url( $settings->get_field( 'mapicon', 'cbxgooglemap_general', '' ) );
219
220 if ( isset( $post->ID ) && $post->ID > 0 ) {
221 $post_id = $post->ID;
222 $post_type = $post->post_type;
223
224
225 wp_nonce_field( 'cbxmetahelper_' . $post_type . '_meta_box', 'cbxmetahelper_' . $post_type . '_meta_box_nonce' );
226
227 $meta_combined = get_post_meta( $post_id, $combined_field, true ); //meta fields not sortable
228
229 $mapicon = isset( $meta_combined['_cbxgooglemapmapicon'] ) ? esc_url( $meta_combined['_cbxgooglemapmapicon'] ) : $mapicon_default;
230
231 $sections_found = false;
232 $sections = [];
233
234 $sections = CBXGooglemapMetaHelper::meta_field_sections( $post_id, $post_type );
235
236 echo '<div class="metabox-holder-wrapper">';
237
238 //print the sections
239 if ( $sectionable ) {
240
241 $sections_html = '<h2 class="nav-tab-wrapper" id="cbxgooglemap_meta_tabs">';
242 foreach ( $meta_fields as $section_id => $fields ) {
243 $sections_html .= '<a id="metabox-content' . esc_attr( $section_id ) . '-tab" class="nav-tab" href="#metabox-content' . esc_attr( $section_id ) . '">' . ( isset( $sections[ $section_id ] ) ? $sections[ $section_id ] : ucfirst( $section_id ) ) . '</a>';
244 }
245
246 $sections_html .= '</h2>';
247 echo $sections_html;//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
248 }
249
250 echo '<div class="metabox-holder metabox-holder-cbxgooglemap metabox-holder-cbxgooglemap-' . esc_attr( $post_type ) . '">';
251
252 foreach ( $meta_fields as $section_id => $fields ) {
253 echo '<div id="metabox-content' . esc_attr( $section_id ) . '" class="metabox-content metabox-content-cbxgooglemap metabox-content-cbxgooglemap-' . esc_attr( $post_type ) . '">';
254 echo '<table class="form-table">';
255
256 foreach ( $fields as $id => $field ) {
257
258 $is_sortable = isset( $field['sortable'] ) ? ( $field['sortable'] ) : false;
259 $multiple_select = ( isset( $field['multiple'] ) ) ? $field['multiple'] : false;
260
261 if ( $is_sortable ) {
262 $meta = get_post_meta( $post_id, $meta_prefix . $id, true );
263 } else {
264 //for combined field
265 $meta = isset( $meta_combined[ $meta_prefix . $id ] ) ? $meta_combined[ $meta_prefix . $id ] : '';
266 }
267
268
269 if ( $meta == '' && isset( $field['default'] ) ) {
270 $meta = $field['default'];
271 }
272
273 $label = isset( $field['label'] ) ? $field['label'] : '';
274
275 echo '<tr>';
276 $colspan = 1;
277 if ( $label == '' ) {
278 $colspan = 2;
279 }
280 echo ( $label != '' ) ? '<th><label for="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '">' . esc_attr( $label ) . '</label></th>' : '';
281
282 echo '<td colspan="' . esc_attr( $colspan ) . '">';
283
284 switch ( $field['type'] ) {
285 case 'text':
286 echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_text cbxgooglemapmeta_input_' . esc_attr( $id ) . '" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-text-' . esc_attr( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
287 if ( isset( $field['desc'] ) ) {
288 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
289 }
290 break;
291
292 case 'location':
293
294 if ( $map_source == 1 && $api_key == '' ) {
295
296 echo '<input type="text" class="cbxeventzmeta_input cbxeventzmeta_input_location" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-location-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
297 /* translators: %s: Admin URL */
298 echo '<p>' . sprintf( esc_html__( 'Google map api key missing, alternative openstreet map can be enabled from <a href="%s" target="_blank">global setting</a>', 'cbxgooglemap' ), esc_url( admin_url( 'edit.php?post_type=cbxgooglemap&page=cbxgooglemap_settings' ) ) ) . '</p>';
299 } elseif (
300 $map_source == 1 ) {
301 $data_custom_attrs = [];
302
303 $data_custom_attrs = apply_filters( 'cbxgooglemap_data_custom_attrs', $data_custom_attrs, $post_id, [] );
304 $data_custom_attrs_html = ' ';
305 foreach ( $data_custom_attrs as $custom_attr_key => $custom_attr_value ) {
306 $data_custom_attrs_html .= ' ' . $custom_attr_key . '="' . $custom_attr_value . '" ';
307 }
308
309 echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_location" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-location-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" /><div ' . esc_html( $data_custom_attrs_html ) . ' data-apikey="' . esc_attr( $api_key ) . '" data-mapsource="1" class="map_canvas"></div>';
310
311 if ( isset( $field['desc'] ) ) {
312 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
313 }
314 } else {
315 $data_custom_attrs = [];
316
317 $data_custom_attrs = apply_filters( 'cbxgooglemap_data_custom_attrs', $data_custom_attrs, $post_id, [] );
318 $data_custom_attrs_html = ' ';
319 foreach ( $data_custom_attrs as $custom_attr_key => $custom_attr_value ) {
320 $data_custom_attrs_html .= ' ' . $custom_attr_key . '="' . $custom_attr_value . '" ';
321 }
322
323 echo '<input style="width:100%;" type="hidden" placeholder="' . esc_html__( 'Type full address and enter to find the lat, lon of the location', 'cbxgooglemap' ) . '" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_location" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-location-' . esc_attr( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" /><div ' . esc_html( $data_custom_attrs_html ) . ' data-mapsource="0" class="map_canvas"></div>';
324 if ( isset( $field['desc'] ) ) {
325 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
326 }
327 }
328
329 break;
330 case 'lat':
331 echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_lat" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-lat-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
332 if ( isset( $field['desc'] ) ) {
333 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
334 }
335 break;
336 case 'lng':
337 echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_lng" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-lng-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
338 if ( isset( $field['desc'] ) ) {
339 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
340 }
341 break;
342 case 'number':
343 echo '<input type="number" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_number" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-text-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />
344 <p class="description">' . esc_html( $field['desc'] ) . '</p>';
345 break;
346
347 case 'url':
348 echo '<input type="url" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_url" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-url-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
349 if ( isset( $field['desc'] ) ) {
350 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
351 }
352 break;
353
354 case 'file':
355 echo '<div class="cbxgooglemapmeta_input_file_wrap">';
356 echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_file cbxgooglemapmeta_filepicker" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-file-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
357
358 $icon_extra_class = '';
359 $marker_icon = '';
360 $trash_extra_class = '';
361
362 if ( $meta == '' ) {
363 $icon_extra_class = 'cbxgooglemapmeta_marker_hide';
364 $file_picked_class = 'cbxgooglemapmeta_left_space';
365 $trash_extra_class = 'cbxgooglemapmeta_trash_hide';
366 } else {
367 $marker_icon = ' background-image: url(\'' . esc_url( $meta ) . '\') ;';
368 $file_picked_class = 'cbxgooglemapmeta_filepicked';
369 }
370
371 echo '<span style="' . esc_attr( $marker_icon ) . '" class="cbxgooglemapmeta_marker ' . esc_attr( $icon_extra_class ) . '"></span>';
372
373 echo '<input type="button" class="button cbxgooglemapmeta_filepicker_btn ' . esc_attr( $file_picked_class ) . '" value="' . esc_attr( $label ) . '" />';
374 echo '<span class="cbxgooglemapmeta_trash dashicons dashicons-no-alt ' . esc_attr( $trash_extra_class ) . '"></span>';
375 echo '</div>';
376 if ( isset( $field['desc'] ) ) {
377 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
378 }
379 break;
380
381 case 'color':
382
383 echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_color cbxgooglemapmeta_colorpicker" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-color-' . esc_attr( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
384 if ( isset( $field['desc'] ) ) {
385 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
386 }
387 break;
388
389 case 'select':
390 echo '<select name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-select-' . intval( $post_id ) . '" class="selecttwo-select">';
391
392 if ( isset( $field['optgroup'] ) && intval( $field['optgroup'] ) ) {
393
394 foreach ( $field['options'] as $optlabel => $data ) {
395 echo '<optgroup label="' . esc_attr( $optlabel ) . '">';
396 foreach ( $data as $index => $option ) {
397 echo '<option ' . ( ( $meta == $index ) ? ' selected="selected"' : '' ) . ' value="' . esc_attr( $index ) . '">' . esc_attr( $option ) . '</option>';
398 }
399
400 }
401 } else {
402 foreach ( $field['options'] as $index => $option ) {
403 echo '<option ' . ( ( $meta == $index ) ? ' selected="selected"' : '' ) . ' value="' . esc_attr( $index ) . '">' . esc_attr( $option ) . '</option>';
404 }
405 }
406 echo '</select><br/>';
407 if ( isset( $field['desc'] ) ) {
408 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
409 }
410 break;
411 case 'multiselect':
412
413 echo '<select name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '[]" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-multiselect-' . esc_attr( $post_id ) . '" class="selecttwo-select" multiple>';
414 if ( isset( $field['optgroup'] ) && intval( $field['optgroup'] ) ) {
415
416 foreach ( $field['options'] as $optlabel => $data ) {
417 echo '<optgroup label="' . esc_attr( $optlabel ) . '">';
418 foreach ( $data as $key => $val ) {
419 echo '<option value="' . $key . '"', is_array( $meta ) && in_array( $key, $meta ) ? ' selected="selected"' : '', ' >' . esc_html( $val ) . '</option>';
420 }
421 echo '<optgroup>';
422 }
423
424 } else {
425 foreach ( $field['options'] as $key => $val ) {
426 echo '<option value="' . $key . '"', is_array( $meta ) && in_array( $key, $meta ) ? ' selected="selected"' : '', ' >' . esc_html( $val ) . '</option>';
427 }
428 }
429
430 echo '</select>';
431 if ( isset( $field['desc'] ) ) {
432 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
433 }
434 break;
435
436 case 'radio':
437 if ( in_array( 'inline', $field ) ) {
438 $inline = isset( $field['inline'] ) ? intval( $field['inline'] ) : 0;
439 $inline_class = ( $inline ) ? 'cbxgooglemap-metabox-label-radio-inline' : '';
440 $br_html = ( ! $inline ) ? '<br/>' : '';
441 $last_class = '';
442 }
443 $last_element = array_key_last( $field['options'] );
444 echo '<fieldset>
445 <legend class="screen-reader-text"><span>input type="radio"</span></legend>';
446 foreach ( $field['options'] as $key => $value ) {
447 if ( $key === $last_element ) {
448 $last_class = 'label-margin-none';
449 }
450 echo '<label title="g:i a" for="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-radio-' . esc_attr( $post_id ) . '-' . esc_attr( $key ) . '" class="' . esc_attr( $inline_class ) . ' ' . esc_attr( $last_class ) . '">
451 <input id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-radio-' . esc_attr( $post_id ) . '-' . esc_attr( $key ) . '" type="radio" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" value="' . esc_attr( $key ) . '" ' . ( ( $meta == $key ) ? ' checked="checked" ' : '' ) . ' />
452 <span>' . esc_html( $value ) . '</span>
453 </label>' . esc_html( $br_html );
454
455
456 }
457 echo '</fieldset>';
458 echo esc_html( $br_html );
459 if ( isset( $field['desc'] ) ) {
460 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
461 }
462 break;
463
464 case 'checkbox':
465 echo '<input type="checkbox" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-checkbox-' . esc_attr( $post_id ) . '" class="cb-checkbox checkbox-' . esc_attr( $post_id ) . '" ' . ( $meta ? ' checked="checked"' : '' ) . '/>';
466 if ( isset( $field['desc'] ) ) {
467 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
468 }
469 break;
470 // checkbox_group
471 case 'multicheck':
472 if ( $meta == '' ) {
473 $meta = [];
474 foreach ( $field['options'] as $option ) {
475 array_push( $meta, $option['value'] );
476 }
477 }
478
479 foreach ( $field['options'] as $option ) {
480 echo '<input type="checkbox" value="' . $option['value'] . '" name="' . esc_attr( $meta_prefix ) . $id . '[]" id="' . $option['value'] . '-mult-chk-' . $post_id . '-field-' . esc_attr( $meta_prefix ) . $id . '" class="cb-multi-check mult-check-' . $post_id . '"', $meta && in_array( $option['value'], $meta ) ? ' checked="checked"' : '', ' />
481 <label for="' . esc_attr( $option['value'] ) . '">' . esc_html( $option['label'] ) . '</label><br/>';
482 }
483
484 if ( isset( $field['desc'] ) ) {
485 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
486 }
487 break;
488
489 case 'post_type':
490 $post_type_ = ( isset( $field['post_type'] ) ) ? $field['post_type'] : [ 'post' ];
491 $post_order_ = ( isset( $field['post_order'] ) ) ? $field['post_order'] : 'DESC';
492 $post_orderby_ = ( isset( $field['post_orderby'] ) ) ? $field['post_orderby'] : 'ID';
493
494 if ( ! is_array( $post_type_ ) ) {
495 $post_type_ = (array) $post_type_;
496 }
497
498 // WP_Query arguments
499
500 $args = [
501 'post_type' => $post_type_,
502 'post_status' => [ 'publish' ],
503 'order' => $post_order_,
504 'orderby ' => $post_orderby_,
505 'posts_per_page' => '-1',
506 ];
507
508 // The Query
509 $query_post_types = get_posts( $args );
510
511 // The Loop
512
513 $posts_found = [];
514 foreach ( $query_post_types as $post ) : CBXGooglemapHelper::setup_admin_postdata( $post );
515
516 $post_id_ = get_the_ID();
517 $post_title_ = get_the_title( $post_id_ );
518 $posts_found[ $post_id_ ] = $post_title_;
519
520 endforeach;
521 CBXGooglemapHelper::wp_reset_admin_postdata();
522
523
524 if ( $multiple_select ) {
525 echo '<select name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '[]" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-post_type-' . intval( $post_id ) . '" class="selecttwo-select" multiple >';
526 foreach ( $posts_found as $key => $val ) {
527 echo '<option value="' . esc_attr( $key ) . '"', is_array( $meta ) && in_array( $key, $meta ) ? ' selected="selected"' : '', ' >' . esc_attr( $val ) . '</option>';
528 }
529 echo '</select>';
530 } else {
531 echo '<select name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-post_type-' . intval( $post_id ) . '" class="selecttwo-select" >';
532 foreach ( $posts_found as $index => $option ) {
533 echo '<option ' . ( ( $meta == $index ) ? ' selected="selected"' : '' ) . ' value="' . esc_attr( $index ) . '">' . esc_attr( $option ) . '</option>';
534 }
535 echo '</select>';
536 }
537
538 if ( isset( $field['desc'] ) ) {
539 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
540 }
541 break;
542 }
543
544 do_action( 'cbxgooglemap_meta_fields_render', $field['type'], $field, $post, $meta_combined );
545
546 echo '</td>';
547
548 echo '</tr>';
549 }
550 echo '</table>';
551
552 echo '</div>';
553 }
554
555 echo '</div>';
556 echo '</div>';
557
558 } else {
559 echo esc_html__( 'Please save first to add extra information.', 'cbxgooglemap' );
560 }
561 }//end method render_meta_fields
562
563 }//end class CBXGooglemapHelper