the_leaflet_field

The_leaflet_field().

Description

the_leaflet_field( (string) $field_name, (bool) $post_id = false ); 

Renders leaflet field

Parameters (2)

0. $field_name — Optional. (string)
- Required, The name of the field @param $post_id - Optional, the id of the post (will try to render for the current page if no id is specified) @since 0.1.0 @date 10/04/13
1. $post_id — Optional. (bool) => false
The post id.

Usage

  1. if ( !function_exists( 'the_leaflet_field' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'advanced-custom-fields-leaflet-field/acf-leaflet_field.php'; 
  3. $field_name = ''; 
  4.  
  5. // The post id. 
  6. $post_id = false; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = the_leaflet_field($field_name, $post_id); 
  10.  

Defined (1)

The function is defined in the following location(s).

/acf-leaflet_field.php  
  1. function the_leaflet_field( $field_name, $post_id = false ) { 
  2. if( !$post_id ) { 
  3. global $post; 
  4. $post_id = $post->ID; 
  5.  
  6. $field_obj = get_field_object( 
  7. $field_name,  
  8. $post_id,  
  9. array( 
  10. 'load_value' => true 
  11. ); 
  12.  
  13. $field_obj['map_provider'] = acf_field_leaflet_field::$map_providers[$field_obj['map_provider']]; 
  14.  
  15. if( $field_obj['map_provider']['requires_key'] ) { 
  16. $field_obj['map_provider']['url'] = str_replace( '{api_key}', $field_obj['api_key'], $field_obj['map_provider']['url'] ); 
  17.  
  18. if( $field_obj['value'] ) { 
  19. // enqueue styles 
  20. wp_enqueue_style( 'leaflet', plugins_url( '/js/leaflet/leaflet.css', __FILE__ ), array(), '0.7.3', 'all' ); 
  21.  
  22. // enqueue scripts 
  23. wp_enqueue_script( 'jquery' ); 
  24. wp_enqueue_script( 'leaflet', plugins_url( '/js/leaflet/leaflet.js', __FILE__ ), array(), '0.7.3', true ); 
  25. wp_enqueue_script( 'leaflet-frontend', plugins_url( '/js/leaflet-frontend.js', __FILE__ ), array( 'jquery', 'leaflet' ), '1.2.1', true ); 
  26. wp_localize_script( 'leaflet-frontend', 'leaflet_field', $field_obj ); 
  27. echo '<div id="' . $field_obj['id'] . '_map" class="leaflet-map" style="height:' . $field_obj['height'] . 'px;"></div>';