RWMB_Map_Field::the_value PHP Метод

the_value() статический публичный Метод

Output the field value Display Google maps
static public the_value ( array $field, array $args = [], integer | null $post_id = null ) : mixed
$field array Field parameters
$args array Additional arguments. Not used for these fields.
$post_id integer | null Post ID. null for current post. Optional.
Результат mixed Field value
    static function the_value($field, $args = array(), $post_id = null)
    {
        $value = self::get_value($field, $args, $post_id);
        if (!$value['latitude'] || !$value['longitude']) {
            return '';
        }
        if (!$value['zoom']) {
            $value['zoom'] = 14;
        }
        $args = wp_parse_args($args, array('latitude' => $value['latitude'], 'longitude' => $value['longitude'], 'width' => '100%', 'height' => '480px', 'marker' => true, 'marker_title' => '', 'info_window' => '', 'js_options' => array(), 'api_key' => 'AIzaSyC1mUh87SGFyf133tpZQJa-s96p0tgnraQ'));
        /*
         * Enqueue scripts
         * API key is get from $field (if found by RWMB_Helper::find_field()) or $args as a fallback
         * Note: We still can enqueue script which outputs in the footer
         */
        $api_key = isset($field['api_key']) ? $field['api_key'] : $args['api_key'];
        $google_maps_url = add_query_arg('key', $api_key, 'https://maps.google.com/maps/api/js');
        /*
         * Allows developers load more libraries via a filter.
         * @link https://developers.google.com/maps/documentation/javascript/libraries
         */
        $google_maps_url = apply_filters('rwmb_google_maps_url', $google_maps_url);
        wp_register_script('google-maps', esc_url_raw($google_maps_url), array(), '', true);
        wp_enqueue_script('rwmb-map-frontend', RWMB_JS_URL . 'map-frontend.js', array('google-maps'), '', true);
        /*
         * Google Maps options
         * Option name is the same as specified in Google Maps documentation
         * This array will be convert to Javascript Object and pass as map options
         * @link https://developers.google.com/maps/documentation/javascript/reference
         */
        $args['js_options'] = wp_parse_args($args['js_options'], array('zoom' => $value['zoom'], 'mapTypeId' => 'ROADMAP'));
        $output = sprintf('<div class="rwmb-map-canvas" data-map_options="%s" style="width:%s;height:%s"></div>', esc_attr(wp_json_encode($args)), esc_attr($args['width']), esc_attr($args['height']));
        return $output;
    }

Usage Example

Пример #1
0
 /**
  * Get post meta
  *
  * @param string   $key     Meta key. Required.
  * @param int|null $post_id Post ID. null for current post. Optional
  * @param array    $args    Array of arguments. Optional.
  *
  * @return mixed
  */
 public static function meta($key, $args = array(), $post_id = null)
 {
     $post_id = empty($post_id) ? get_the_ID() : $post_id;
     $args = wp_parse_args($args, array('type' => 'text', 'multiple' => false, 'clone' => false));
     // Always set 'multiple' true for following field types
     if (in_array($args['type'], array('checkbox_list', 'autocomplete', 'file', 'file_advanced', 'image', 'image_advanced', 'plupload_image', 'thickbox_image'))) {
         $args['multiple'] = true;
     }
     $field = array('id' => $key, 'type' => $args['type'], 'clone' => $args['clone'], 'multiple' => $args['multiple']);
     $class = RW_Meta_Box::get_class_name($field);
     switch ($args['type']) {
         case 'taxonomy_advanced':
             if (empty($args['taxonomy'])) {
                 break;
             }
             $meta = get_post_meta($post_id, $key, !$args['multiple']);
             $term_ids = wp_parse_id_list($meta);
             // Allow to pass more arguments to "get_terms"
             $func_args = wp_parse_args(array('include' => $term_ids, 'hide_empty' => false), $args);
             unset($func_args['type'], $func_args['taxonomy'], $func_args['multiple']);
             $meta = get_terms($args['taxonomy'], $func_args);
             break;
         case 'taxonomy':
             $meta = empty($args['taxonomy']) ? array() : get_the_terms($post_id, $args['taxonomy']);
             break;
         case 'map':
             $field = array('id' => $key, 'multiple' => false, 'clone' => false);
             $meta = RWMB_Map_Field::the_value($field, $args, $post_id);
             break;
         case 'oembed':
             $meta = RWMB_OEmbed_Field::the_value($field, $args, $post_id);
             break;
         default:
             $meta = call_user_func(array($class, 'get_value'), $field, $args, $post_id);
             break;
     }
     return apply_filters('rwmb_meta', $meta, $key, $args, $post_id);
 }
All Usage Examples Of RWMB_Map_Field::the_value