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