esc_html__( 'Map Settings', 'cbxgooglemap' ), 'maplocation' => esc_html__( 'Primary Marker', 'cbxgooglemap' ), ]; return apply_filters( 'cbxgooglemap_sections', $sections ); }//end method meta_field_sections /** * Meta fields for sessions * * @param int $post_id * * @return array */ public static function cbxgooglemap_meta_fields( $post_id = 0 ) { $meta_fields = []; $settings = new CBXGooglemapSettings(); $general_settings = get_option( 'cbxgooglemap_general', [] ); $zoom_level = intval( $settings->get_field( 'zoom', 'cbxgooglemap_general', '8' ) ); if ( $zoom_level == 0 ) { $zoom_level = 8; } $width_default = $settings->get_field( 'width', 'cbxgooglemap_general', '100%' ); if ( $width_default == '' || $width_default == 0 ) { $width_default = '100%'; } $height_default = intval( $settings->get_field( 'height', 'cbxgooglemap_general', '300' ) ); if ( $height_default == 0 ) { $height_default = 300; } $scrollwheel = intval( $settings->get_field( 'scrollwheel', 'cbxgooglemap_general', 1 ) ); $showinfo = intval( $settings->get_field( 'showinfo', 'cbxgooglemap_general', 1 ) ); $infow_open = intval( $settings->get_field( 'infow_open', 'cbxgooglemap_general', 1 ) ); $maptype = $settings->get_field( 'maptype', 'cbxgooglemap_general', 'roadmap' ); $meta_fields['mapsettings'] = apply_filters( 'cbxgooglemap_mapsettings_fields', [ 'maptype' => [ 'label' => esc_html__( 'Map Type', 'cbxgooglemap' ), 'type' => 'select', 'default' => $maptype, 'options' => [ 'roadmap' => esc_html__( 'Road Map', 'cbxgooglemap' ), 'satellite' => esc_html__( 'Satellite Map', 'cbxgooglemap' ), 'hybrid' => esc_html__( 'Hybrid Map', 'cbxgooglemap' ), 'terrain' => esc_html__( 'Terrain Map', 'cbxgooglemap' ), ], 'desc' => esc_html__( 'Google Map only', 'cbxgooglemap' ), 'sanitize_callback' => 'sanitize_text_field' ], 'zoom' => [ 'label' => esc_html__( 'Zoom Level', 'cbxgooglemap' ), 'desc' => esc_html__( 'Plain address with road no etc', 'cbxgooglemap' ), 'type' => 'text', 'default' => $zoom_level, 'sanitize_callback' => 'sanitize_text_field' ], 'width' => [ 'label' => esc_html__( 'Width', 'cbxgooglemap' ), 'desc' => esc_html__( 'Map width, use % if need, don\'t use px as it will be automatically if no % used.', 'cbxgooglemap' ), 'type' => 'text', 'default' => $width_default, 'sanitize_callback' => 'sanitize_text_field' ], 'height' => [ 'label' => esc_html__( 'Height', 'cbxgooglemap' ), 'desc' => esc_html__( 'Map height, don\'t use px', 'cbxgooglemap' ), 'type' => 'text', 'default' => $height_default, 'sanitize_callback' => 'sanitize_text_field' ], 'scrollwheel' => [ 'label' => esc_html__( 'Mouse Scroll Wheel', 'cbxgooglemap' ), 'desc' => esc_html__( 'Enable/disable mouse scroll whell', 'cbxgooglemap' ), 'type' => 'radio', 'default' => $scrollwheel, 'desc_tip' => true, 'options' => [ '1' => esc_html__( 'Enable', 'cbxgooglemap' ), '0' => esc_html__( 'Disable', 'cbxgooglemap' ), ], 'inline' => true, 'sanitize_callback' => 'absint' ], 'showinfo' => [ 'label' => esc_html__( 'Show Info window', 'cbxgooglemap' ), 'desc' => esc_html__( 'Show information on click of marker', 'cbxgooglemap' ), 'type' => 'radio', 'default' => $showinfo, 'desc_tip' => true, 'options' => [ '1' => esc_html__( 'Enable', 'cbxgooglemap' ), '0' => esc_html__( 'Disable', 'cbxgooglemap' ), ], 'inline' => true, 'sanitize_callback' => 'absint' ], 'infow_open' => [ 'label' => esc_html__( 'Info/Popup Window', 'cbxgooglemap' ), 'type' => 'radio', 'default' => $infow_open, 'desc_tip' => true, 'options' => [ '1' => esc_html__( 'Open(Default)', 'cbxgooglemap' ), '0' => esc_html__( 'On Click', 'cbxgooglemap' ), ], 'inline' => true, 'sanitize_callback' => 'absint' ], ] ); $meta_fields['maplocation'] = apply_filters( 'cbxgooglemap_maplocation_fields', [ 'title' => [ 'label' => esc_html__( 'Marker Heading', 'cbxgooglemap' ), 'desc' => esc_html__( 'Heading title will be used for marker pop info', 'cbxgooglemap' ), 'type' => 'text', 'default' => esc_html__('Default Title', 'cbxgooglemap'), 'sanitize_callback' => 'sanitize_text_field' ], 'address' => [ 'label' => esc_html__( 'Address', 'cbxgooglemap' ), 'desc' => esc_html__( 'Plain address with road no etc', 'cbxgooglemap' ), 'type' => 'text', 'default' => '', 'sanitize_callback' => 'sanitize_text_field' ], 'website' => [ 'label' => esc_html__( 'Website Link', 'cbxgooglemap' ), 'desc' => esc_html__( 'If website link is given then market popup will show the Title as linked with this address', 'cbxgooglemap' ), 'type' => 'text', 'default' => '', 'sanitize_callback' => 'sanitize_text_field' ], 'location' => [ 'label' => esc_html__( 'Map Location', 'cbxgooglemap' ), 'desc' => esc_html__( 'Type location and select from google map auto suggest.', 'cbxgooglemap' ), 'type' => 'location', 'default' => '', 'sanitize_callback' => 'sanitize_text_field' ], 'lat' => [ 'label' => esc_html__( 'Latitude', 'cbxgooglemap' ), 'desc' => esc_html__( 'If you select location from google map then latitude will be picked automatically but still you can put manually', 'cbxgooglemap' ), 'type' => 'lat', 'default' => '', 'sortable' => true, 'sanitize_callback' => 'sanitize_text_field' ], 'lng' => [ 'label' => esc_html__( 'Longitude', 'cbxgooglemap' ), 'desc' => esc_html__( 'If you select location from google map then longitude will be picked automatically but still you can put manually', 'cbxgooglemap' ), 'type' => 'lng', 'default' => '', 'sortable' => true, 'sanitize_callback' => 'sanitize_text_field' ], 'mapicon' => [ 'label' => esc_html__( 'Map Icon', 'cbxgooglemap' ), 'desc' => esc_html__( 'Map marker custom icon', 'cbxgooglemap' ), 'type' => 'file', 'default' => '', 'desc_tip' => true, 'sanitize_callback' => 'sanitize_text_field' ], ] ); return apply_filters( 'cbxgooglemap_fields', $meta_fields ); }//end method cbxgooglemap_meta_fields /** * Render the meta fields html * * @param $post * @param $meta_fields * @param $combined_field * @param $meta_prefix * @param $sectionable * * @return void\ */ public static function render_meta_fields( $post, $meta_fields, $combined_field, $meta_prefix, $sectionable = false ) { $settings = new CBXGooglemapSettings(); $general_settings = get_option( 'cbxgooglemap_general', [] ); $api_key = esc_attr( $settings->get_field( 'apikey', 'cbxgooglemap_general', '' ) ); $map_source = absint( $settings->get_field( 'mapsource', 'cbxgooglemap_general', 1 ) ); $scrollwheel_default = absint( $settings->get_field( 'scrollwheel', 'cbxgooglemap_general', 1 ) ); $showinfo_default = absint( $settings->get_field( 'showinfo', 'cbxgooglemap_general', 1 ) ); $mapicon_default = esc_url( $settings->get_field( 'mapicon', 'cbxgooglemap_general', '' ) ); if ( isset( $post->ID ) && $post->ID > 0 ) { $post_id = $post->ID; $post_type = $post->post_type; wp_nonce_field( 'cbxmetahelper_' . $post_type . '_meta_box', 'cbxmetahelper_' . $post_type . '_meta_box_nonce' ); $meta_combined = get_post_meta( $post_id, $combined_field, true ); //meta fields not sortable $mapicon = isset( $meta_combined['_cbxgooglemapmapicon'] ) ? esc_url( $meta_combined['_cbxgooglemapmapicon'] ) : $mapicon_default; $sections_found = false; $sections = []; $sections = CBXGooglemapMetaHelper::meta_field_sections( $post_id, $post_type ); echo '
'; //print the sections if ( $sectionable ) { $sections_html = ''; echo $sections_html;//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } echo '
'; foreach ( $meta_fields as $section_id => $fields ) { echo '
'; echo ''; foreach ( $fields as $id => $field ) { $is_sortable = isset( $field['sortable'] ) ? ( $field['sortable'] ) : false; $multiple_select = ( isset( $field['multiple'] ) ) ? $field['multiple'] : false; if ( $is_sortable ) { $meta = get_post_meta( $post_id, $meta_prefix . $id, true ); } else { //for combined field $meta = isset( $meta_combined[ $meta_prefix . $id ] ) ? $meta_combined[ $meta_prefix . $id ] : ''; } if ( $meta == '' && isset( $field['default'] ) ) { $meta = $field['default']; } $label = isset( $field['label'] ) ? $field['label'] : ''; echo ''; $colspan = 1; if ( $label == '' ) { $colspan = 2; } echo ( $label != '' ) ? '' : ''; echo ''; echo ''; } echo '
'; switch ( $field['type'] ) { case 'text': echo ''; if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } break; case 'location': if ( $map_source == 1 && $api_key == '' ) { echo ''; echo '
'; echo '
'.esc_html__('Googlemap Api Key Missing', 'cbxgooglemap').'
'; /* translators: %s: Admin URL */ echo '

' . wp_kses(sprintf( __( 'Google map api key missing, alternative openstreet map can be enabled from global setting', 'cbxgooglemap' ), esc_url( admin_url( 'edit.php?post_type=cbxgooglemap&page=cbxgooglemap_settings' ) ) ), ['a' => ['href' => [], 'target' => []]]) . '

'; echo '
'; //echo $map_api_key_missing;//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } elseif ( $map_source == 1 ) { $data_custom_attrs = []; $data_custom_attrs = apply_filters( 'cbxgooglemap_data_custom_attrs', $data_custom_attrs, $post_id, [] ); $data_custom_attrs_html = ' '; foreach ( $data_custom_attrs as $custom_attr_key => $custom_attr_value ) { $data_custom_attrs_html .= ' ' . $custom_attr_key . '="' . $custom_attr_value . '" '; } echo '
'; if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } } else { $data_custom_attrs = []; $data_custom_attrs = apply_filters( 'cbxgooglemap_data_custom_attrs', $data_custom_attrs, $post_id, [] ); $data_custom_attrs_html = ' '; foreach ( $data_custom_attrs as $custom_attr_key => $custom_attr_value ) { $data_custom_attrs_html .= ' ' . $custom_attr_key . '="' . $custom_attr_value . '" '; } echo '
'; if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } } break; case 'lat': echo ''; if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } break; case 'lng': echo ''; if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } break; case 'number': echo '

' . esc_html( $field['desc'] ) . '

'; break; case 'url': echo ''; if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } break; case 'file': echo '
'; echo ''; $icon_extra_class = ''; $marker_icon = ''; $trash_extra_class = ''; if ( $meta == '' ) { $icon_extra_class = 'cbxgooglemapmeta_marker_hide'; $file_picked_class = 'cbxgooglemapmeta_left_space'; $trash_extra_class = 'cbxgooglemapmeta_trash_hide'; } else { $marker_icon = ' background-image: url(\'' . esc_url( $meta ) . '\') ;'; $file_picked_class = 'cbxgooglemapmeta_filepicked'; } echo ''; echo ''; echo ''; echo '
'; if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } break; case 'color': echo ''; if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } break; case 'select': echo '
'; if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } break; case 'multiselect': echo ''; if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } break; case 'radio': if ( in_array( 'inline', $field ) ) { $inline = isset( $field['inline'] ) ? intval( $field['inline'] ) : 0; $inline_class = ( $inline ) ? 'cbxgooglemap-metabox-label-radio-inline' : ''; $br_html = ( ! $inline ) ? '
' : ''; $last_class = ''; } $last_element = array_key_last( $field['options'] ); echo '
input type="radio"'; foreach ( $field['options'] as $key => $value ) { if ( $key === $last_element ) { $last_class = 'label-margin-none'; } echo '' . esc_html( $br_html ); } echo '
'; echo esc_html( $br_html ); if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } break; case 'checkbox': echo ''; if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } break; // checkbox_group case 'multicheck': if ( $meta == '' ) { $meta = []; foreach ( $field['options'] as $option ) { array_push( $meta, $option['value'] ); } } foreach ( $field['options'] as $option ) { echo '
'; } if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } break; case 'post_type': $post_type_ = ( isset( $field['post_type'] ) ) ? $field['post_type'] : [ 'post' ]; $post_order_ = ( isset( $field['post_order'] ) ) ? $field['post_order'] : 'DESC'; $post_orderby_ = ( isset( $field['post_orderby'] ) ) ? $field['post_orderby'] : 'ID'; if ( ! is_array( $post_type_ ) ) { $post_type_ = (array) $post_type_; } // WP_Query arguments $args = [ 'post_type' => $post_type_, 'post_status' => [ 'publish' ], 'order' => $post_order_, 'orderby ' => $post_orderby_, 'posts_per_page' => '-1', ]; // The Query $query_post_types = get_posts( $args ); // The Loop $posts_found = []; foreach ( $query_post_types as $post ) : CBXGooglemapHelper::setup_admin_postdata( $post ); $post_id_ = get_the_ID(); $post_title_ = get_the_title( $post_id_ ); $posts_found[ $post_id_ ] = $post_title_; endforeach; CBXGooglemapHelper::wp_reset_admin_postdata(); if ( $multiple_select ) { echo ''; } else { echo ''; } if ( isset( $field['desc'] ) ) { echo '

' . esc_html( $field['desc'] ) . '

'; } break; } do_action( 'cbxgooglemap_meta_fields_render', $field['type'], $field, $post, $meta_combined ); echo '
'; echo '
'; } echo '
'; echo '
'; } else { echo esc_html__( 'Please save first to add extra information.', 'cbxgooglemap' ); } }//end method render_meta_fields }//end class CBXGooglemapHelper