array( 'url' => 'http://tile.openstreetmap.org/{z}/{x}/{y}.png', 'requires_key' => false, 'nicename' => 'OpenStreetMap', 'attribution' => 'Map data © OpenStreetMap contributors' ), 'cloudmade' => array( 'url' => "http://{s}.tile.cloudmade.com/{api_key}/997/256/{z}/{x}/{y}.png", 'requires_key' => true, 'nicename' => 'CloudMade', 'attribution' => 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © CloudMade' ) ); /* * __construct * * Set name / label needed for actions / filters * * @since 3.6 * @date 23/01/13 */ function __construct() { // vars $this->name = 'leaflet_field'; $this->label = __( 'Leaflet Field' ); $this->category = __( 'Content','acf' ); // Basic, Content, Choice, etc $this->defaults = array( 'lat' => '55.606', 'lng' => '13.002', 'zoom_level' => 13, 'height' => 350, 'api_key' => '', 'map_provider' => 'openstreetmap', ); // do not delete! parent::__construct(); // settings $this->settings = array( 'path' => apply_filters( 'acf/helpers/get_path', __FILE__ ), 'dir' => apply_filters( 'acf/helpers/get_dir', __FILE__ ), 'version' => '1.1.1' ); add_action( 'acf/field_group/admin_head', array( $this, 'conditional_options' ) ); } /* * create_options() * * Create extra options for your field. This is rendered when editing a field. * The value of $field['name'] can be used (like below) to save extra data to the $field * * @type action * @since 3.6 * @date 23/01/13 * * @param $field - an array holding all the field's data */ function create_options( $field ) { // defaults $field = array_merge($this->defaults, $field); // key is needed in the field names to correctly save the data $key = $field['name']; // Create Field Options HTML ?>

'radio', 'name' => 'fields['.$key.'][map_provider]', 'value' => $field['map_provider'], 'layout' => 'horizontal', 'choices' => array( 'openstreetmap' => acf_field_leaflet_field::$map_providers['openstreetmap']['nicename'], 'cloudmade' => acf_field_leaflet_field::$map_providers['cloudmade']['nicename'] ) )); ?>

CloudMade.

'text', 'name' => 'fields['.$key.'][api_key]', 'value' => $field['api_key'] )); ?>

'number', 'name' => 'fields['.$key.'][zoom_level]', 'value' => $field['zoom_level'] )); ?>

'number', 'name' => 'fields['.$key.'][lat]', 'value' => $field['lat'] )); ?>

'number', 'name' => 'fields['.$key.'][lng]', 'value' => $field['lng'] )); ?>

'number', 'name' => 'fields['.$key.'][height]', 'value' => $field['height'] )); ?> defaults, $field); // Build an unique id based on ACF's one. $pattern = array( '/\[/', '/\]/' ); $replace = array( '_', '' ); $uid = preg_replace($pattern, $replace, $field['name']); $field['id'] = $uid; // resolve tile-layer and attribution $tile_layer = str_replace( '{api_key}', $field['api_key'], acf_field_leaflet_field::$map_providers[$field['map_provider']]['url'] ); $attribution = acf_field_leaflet_field::$map_providers[$field['map_provider']]['attribution']; // include the javascript include_once("js/input.js.php"); // render the field container, ?>
' id="field_" name="" data-zoom-level="" data-lat="" data-lng="" />
defaults, $field); */ // perhaps use $field['preview_size'] to alter the $value? // Note: This function can be removed if not used return $value; } /* * format_value_for_api() * * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field * * @type filter * @since 3.6 * @date 23/01/13 * * @param $value - the value which was loaded from the database * @param $post_id - the $post_id from which the value was loaded * @param $field - the field array holding all the field options * * @return $value - the modified value */ function format_value_for_api( $value, $post_id, $field ) { // defaults? $field = array_merge( $this->defaults, $field ); // format value $value = json_decode( $value ); // Note: This function can be removed if not used return $value; } /* * load_field() * * This filter is appied to the $field after it is loaded from the database * * @type filter * @since 3.6 * @date 23/01/13 * * @param $field - the field array holding all the field options * * @return $field - the field array holding all the field options */ function load_field( $field ) { // Note: This function can be removed if not used return $field; } /* * update_field() * * This filter is appied to the $field before it is saved to the database * * @type filter * @since 3.6 * @date 23/01/13 * * @param $field - the field array holding all the field options * @param $post_id - the field group ID (post_type = acf) * * @return $field - the modified field */ function update_field( $field, $post_id ) { // Note: This function can be removed if not used return $field; } } // create field new acf_field_leaflet_field(); ?>