acf_field_leaflet_field

The Advanced Custom Fields: Leaflet Field acf field leaflet class.

Defined (3)

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

/leaflet_field-v3.php  
  1. class acf_field_leaflet_field extends acf_Field 
  2.  
  3. // vars 
  4. var $settings, // will hold info such as dir / path 
  5. $defaults; // will hold default field options 
  6.  
  7. // holds information about supported tile-providers 
  8. static $map_providers = array( 
  9. 'openstreetmap' => array( 
  10. 'url' => 'http://tile.openstreetmap.org/{z}/{x}/{y}.png',  
  11. 'requires_key' => false,  
  12. 'nicename' => 'OpenStreetMap',  
  13. 'attribution' => 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors' 
  14. ),  
  15. 'openstreetmap_blackandwhite' => array( 
  16. 'url' => 'http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png',  
  17. 'requires_key' => false,  
  18. 'nicename' => 'OpenStreetMap Black and White',  
  19. 'attribution' => '© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>' 
  20. ),  
  21. 'cloudmade' => array( 
  22. 'url' => "http://{s}.tile.cloudmade.com/{api_key}/997/256/{z}/{x}/{y}.png",  
  23. 'requires_key' => true,  
  24. 'nicename' => 'CloudMade',  
  25. 'attribution' => 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery <a href="http://cloudmade.com">CloudMade</a>' 
  26. ); 
  27.  
  28. /**-------------------------------------------------------------------------------------- 
  29. * Constructor 
  30. * - This function is called when the field class is initalized on each page. 
  31. * - Here you can add filters / actions and setup any other functionality for your field 
  32. * @author Elliot Condon 
  33. * @since 2.2.0 
  34. *-------------------------------------------------------------------------------------*/ 
  35.  
  36. function __construct($parent) 
  37. // do not delete! 
  38. parent::__construct($parent); 
  39.  
  40. // set name / title 
  41. $this->name = 'leaflet_field'; 
  42. $this->title = __('Leaflet Field'); 
  43. $this->defaults = array( 
  44. 'lat' => '55.606',  
  45. 'lng' => '13.002',  
  46. 'zoom_level' => 13,  
  47. 'height' => 400,  
  48. 'api_key' => '',  
  49. 'map_provider' => 'openstreetmap' 
  50. ); 
  51.  
  52.  
  53. // settings 
  54. // settings 
  55. $this->settings = array( 
  56. 'path' => $this->helpers_get_path( __FILE__ ),  
  57. 'dir' => $this->helpers_get_dir( __FILE__ ),  
  58. 'version' => '1.2.1' 
  59. ); 
  60.  
  61.  
  62.  
  63. /** 
  64. * helpers_get_path 
  65. * @description: calculates the path (works for plugin / theme folders) 
  66. * @since: 3.6 
  67. * @created: 30/01/13 
  68. */ 
  69.  
  70. function helpers_get_path( $file ) 
  71. return trailingslashit(dirname($file)); 
  72.  
  73.  
  74.  
  75. /** 
  76. * helpers_get_dir 
  77. * @description: calculates the directory (works for plugin / theme folders) 
  78. * @since: 3.6 
  79. * @created: 30/01/13 
  80. */ 
  81.  
  82. function helpers_get_dir( $file ) 
  83. $dir = trailingslashit(dirname($file)); 
  84. $count = 0; 
  85.  
  86.  
  87. // sanitize for Win32 installs 
  88. $dir = str_replace('\\' , '/', $dir); 
  89.  
  90.  
  91. // if file is in plugins folder 
  92. $wp_plugin_dir = str_replace('\\' , '/', WP_PLUGIN_DIR); 
  93. $dir = str_replace($wp_plugin_dir, WP_PLUGIN_URL, $dir, $count); 
  94.  
  95.  
  96. if( $count < 1 ) 
  97. // if file is in wp-content folder 
  98. $wp_content_dir = str_replace('\\' , '/', WP_CONTENT_DIR); 
  99. $dir = str_replace($wp_content_dir, WP_CONTENT_URL, $dir, $count); 
  100.  
  101.  
  102. if( $count < 1 ) 
  103. // if file is in ??? folder 
  104. $wp_dir = str_replace('\\' , '/', ABSPATH); 
  105. $dir = str_replace($wp_dir, site_url('/'), $dir); 
  106.  
  107.  
  108. return $dir; 
  109.  
  110.  
  111. /**-------------------------------------------------------------------------------------- 
  112. * create_options 
  113. * - this function is called from core/field_meta_box.php to create extra options 
  114. * for your field 
  115. * @params 
  116. * - $key (int) - the $_POST obejct key required to save the options to the field 
  117. * - $field (array) - the field object 
  118. * @author Elliot Condon 
  119. * @since 2.2.0 
  120. *-------------------------------------------------------------------------------------*/ 
  121.  
  122. function create_options($key, $field) 
  123. // defaults? 
  124. $field = array_merge($this->defaults, $field); 
  125.  
  126. // Create Field Options HTML 
  127. ?> 
  128. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  129. <td class="label"> 
  130. <label><?php _e('Cloudmade API-key', 'acf'); ?></label> 
  131. <p class="description"><?php _e('Register for an API-key at ', 'acf'); ?><a href="http://account.cloudmade.com/register" target="_blank">CloudMade</a>.</p> 
  132. </td> 
  133. <td> 
  134. <?php 
  135. $this->parent->create_field(array( 
  136. 'type' => 'text',  
  137. 'name' => 'fields['.$key.'][api_key]',  
  138. 'value' => $field['api_key'] 
  139. )); 
  140. ?> 
  141. </td> 
  142. </tr> 
  143.  
  144. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  145. <td class="label"> 
  146. <label><?php _e('Zoom level', 'acf'); ?></label> 
  147. <p class="description"><?php _e('', 'acf'); ?></p> 
  148. </td> 
  149. <td> 
  150. <?php 
  151. $this->parent->create_field(array( 
  152. 'type' => 'number',  
  153. 'name' => 'fields['.$key.'][zoom_level]',  
  154. 'value' => $field['zoom_level'] 
  155. )); 
  156. ?> 
  157. </td> 
  158. </tr> 
  159.  
  160. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  161. <td class="label"> 
  162. <label><?php _e('Latitude', 'acf'); ?></label> 
  163. <p class="description"><?php _e('', 'acf'); ?></p> 
  164. </td> 
  165. <td> 
  166. <?php 
  167. $this->parent->create_field(array( 
  168. 'type' => 'number',  
  169. 'name' => 'fields['.$key.'][lat]',  
  170. 'value' => $field['lat'] 
  171. )); 
  172. ?> 
  173. </td> 
  174. </tr> 
  175.  
  176. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  177. <td class="label"> 
  178. <label><?php _e('Longitude', 'acf'); ?></label> 
  179. <p class="description"><?php _e('', 'acf'); ?></p> 
  180. </td> 
  181. <td> 
  182. <?php 
  183. $this->parent->create_field(array( 
  184. 'type' => 'number',  
  185. 'name' => 'fields['.$key.'][lng]',  
  186. 'value' => $field['lng'] 
  187. )); 
  188. ?> 
  189. </td> 
  190. </tr> 
  191.  
  192. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  193. <td class="label"> 
  194. <label><?php _e('Height', 'acf'); ?></label> 
  195. <p class="description"><?php _e('The map needs a specified height to be rendered correctly.', 'acf'); ?></p> 
  196. </td> 
  197. <td> 
  198. <?php 
  199. $this->parent->create_field(array( 
  200. 'type' => 'number',  
  201. 'name' => 'fields['.$key.'][height]',  
  202. 'value' => $field['height'] 
  203. )); 
  204. ?> 
  205. </td> 
  206. </tr> 
  207. <?php 
  208.  
  209.  
  210. /**-------------------------------------------------------------------------------------- 
  211. * pre_save_field 
  212. * - this function is called when saving your acf object. Here you can manipulate the 
  213. * field object and it's options before it gets saved to the database. 
  214. * @author Elliot Condon 
  215. * @since 2.2.0 
  216. *-------------------------------------------------------------------------------------*/ 
  217.  
  218. function pre_save_field($field) 
  219. // Note: This function can be removed if not used 
  220.  
  221. // do stuff with field (mostly format options data) 
  222.  
  223. return parent::pre_save_field($field); 
  224.  
  225.  
  226. /**-------------------------------------------------------------------------------------- 
  227. * create_field 
  228. * - this function is called on edit screens to produce the html for this field 
  229. * @author Elliot Condon 
  230. * @since 2.2.0 
  231. *-------------------------------------------------------------------------------------*/ 
  232.  
  233. function create_field($field) 
  234. // defaults 
  235. $field = array_merge($this->defaults, $field); 
  236.  
  237. // Build an unique id based on ACF's one. 
  238. $pattern = array('/\[/', '/\]/'); 
  239. $replace = array('_', ''); 
  240. $uid = preg_replace($pattern, $replace, $field['name']); 
  241. $field['id'] = $uid; 
  242.  
  243. // include the javascript 
  244. include_once("js/input.js.php"); 
  245. ?> 
  246. <div id="leaflet_field-wrapper_<?php echo $uid; ?>" class="tool-marker-active"> 
  247. <input type="hidden" value='<?php echo $field['value']; ?>' id="field_<?php echo $uid; ?>" name="<?php echo $field['name']; ?>" data-zoom-level="<?php echo $field['zoom_level']; ?>" data-lat="<?php echo $field['lat']; ?>" data-lng="<?php echo $field['lng']; ?>" /> 
  248. <div class="leaflet-map" data-uid="<?php echo $uid; ?>"> 
  249. <div id="map_<?php echo $uid; ?>" style="height:<?php echo $field['height']; ?>px;"></div> 
  250. </div> 
  251. </div> 
  252. <?php 
  253.  
  254.  
  255. /**-------------------------------------------------------------------------------------- 
  256. * admin_head 
  257. * - this function is called in the admin_head of the edit screen where your field 
  258. * is created. Use this function to create css and javascript to assist your 
  259. * create_field() function. 
  260. * @author Elliot Condon 
  261. * @since 2.2.0 
  262. *-------------------------------------------------------------------------------------*/ 
  263.  
  264. function admin_head() 
  265. // Note: This function can be removed if not used 
  266.  
  267.  
  268. /**-------------------------------------------------------------------------------------- 
  269. * admin_print_scripts / admin_print_styles 
  270. * - this function is called in the admin_print_scripts / admin_print_styles where 
  271. * your field is created. Use this function to register css and javascript to assist 
  272. * your create_field() function. 
  273. * @author Elliot Condon 
  274. * @since 3.0.0 
  275. *-------------------------------------------------------------------------------------*/ 
  276.  
  277. function admin_print_scripts() 
  278. // scripts 
  279. wp_enqueue_script( 'jquery' ); 
  280. wp_register_script( 'leaflet', plugins_url( '/js/leaflet/leaflet.js', __FILE__ ), array(), '0.7.3', true ); 
  281. wp_register_script( 'leaflet.draw', plugins_url( '/js/Leaflet.draw/dist/leaflet.draw.js', __FILE__ ), array( 'leaflet' ), 'ccca4b11ba4ff545433bf70f610b215053a2615e', true ); 
  282. wp_enqueue_script( 'leaflet' ); 
  283. wp_enqueue_script( 'leaflet.draw' ); 
  284.  
  285. function admin_print_styles() 
  286. // styles 
  287. wp_enqueue_style( 'leaflet', plugins_url( '/js/leaflet/leaflet.css', __FILE__ ), array(), '0.7.3', 'all' ); 
  288. wp_enqueue_style( 'leaflet.draw', plugins_url( '/js/Leaflet.draw/dist/leaflet.draw.css', __FILE__ ), array(), 'ccca4b11ba4ff545433bf70f610b215053a2615e', 'all' ); 
  289. wp_enqueue_style( 'icomoon', plugins_url( '/css/icomoon/style.css', __FILE__ ), array(), '1.0.0', 'all' ); 
  290. wp_enqueue_style( 'leaflet-field', plugins_url( '/css/input.css', __FILE__ ), array( 'leaflet', 'icomoon' ), '1', 'all' ); 
  291.  
  292.  
  293. /**-------------------------------------------------------------------------------------- 
  294. * update_value 
  295. * - this function is called when saving a post object that your field is assigned to. 
  296. * the function will pass through the 3 parameters for you to use. 
  297. * @params 
  298. * - $post_id (int) - usefull if you need to save extra data or manipulate the current 
  299. * post object 
  300. * - $field (array) - usefull if you need to manipulate the $value based on a field option 
  301. * - $value (mixed) - the new value of your field. 
  302. * @author Elliot Condon 
  303. * @since 2.2.0 
  304. *-------------------------------------------------------------------------------------*/ 
  305.  
  306. function update_value($post_id, $field, $value) 
  307. // Note: This function can be removed if not used 
  308.  
  309. // do stuff with value 
  310.  
  311. // save value 
  312. parent::update_value($post_id, $field, $value); 
  313.  
  314.  
  315.  
  316.  
  317.  
  318. /**-------------------------------------------------------------------------------------- 
  319. * get_value 
  320. * - called from the edit page to get the value of your field. This function is useful 
  321. * if your field needs to collect extra data for your create_field() function. 
  322. * @params 
  323. * - $post_id (int) - the post ID which your value is attached to 
  324. * - $field (array) - the field object. 
  325. * @author Elliot Condon 
  326. * @since 2.2.0 
  327. *-------------------------------------------------------------------------------------*/ 
  328.  
  329. function get_value($post_id, $field) 
  330. // Note: This function can be removed if not used 
  331.  
  332. // get value 
  333. $value = parent::get_value($post_id, $field); 
  334.  
  335. // format value 
  336.  
  337. // return value 
  338. return $value; 
  339.  
  340.  
  341. /**-------------------------------------------------------------------------------------- 
  342. * get_value_for_api 
  343. * - called from your template file when using the API functions (get_field, etc). 
  344. * This function is useful if your field needs to format the returned value 
  345. * @params 
  346. * - $post_id (int) - the post ID which your value is attached to 
  347. * - $field (array) - the field object. 
  348. * @author Elliot Condon 
  349. * @since 3.0.0 
  350. *-------------------------------------------------------------------------------------*/ 
  351.  
  352. function get_value_for_api($post_id, $field) 
  353. // Note: This function can be removed if not used 
  354.  
  355. // get value 
  356. $value = $this->get_value($post_id, $field); 
  357.  
  358. // format value 
  359. $value = json_decode($value); 
  360.  
  361. // return value 
  362. return $value; 
  363.  
  364.  
/leaflet_field-v5.php  
  1. class acf_field_leaflet_field extends acf_field 
  2.  
  3. // vars 
  4. var $settings, // will hold info such as dir / path 
  5. $defaults; // will hold default field options 
  6.  
  7. // holds information about supported tile-providers 
  8. static $map_providers = array( 
  9. 'openstreetmap' => array( 
  10. 'url' => 'http://tile.openstreetmap.org/{z}/{x}/{y}.png',  
  11. 'requires_key' => false,  
  12. 'nicename' => 'OpenStreetMap',  
  13. 'attribution' => 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors' 
  14. ),  
  15. 'openstreetmap_blackandwhite' => array( 
  16. 'url' => 'http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png',  
  17. 'requires_key' => false,  
  18. 'nicename' => 'OpenStreetMap Black and White',  
  19. 'attribution' => '© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>' 
  20. ),  
  21. 'cloudmade' => array( 
  22. 'url' => "http://{s}.tile.cloudmade.com/{api_key}/997/256/{z}/{x}/{y}.png",  
  23. 'requires_key' => true,  
  24. 'nicename' => 'CloudMade',  
  25. 'attribution' => 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery <a href="http://cloudmade.com">CloudMade</a>' 
  26. ); 
  27.  
  28. /** 
  29. * __construct 
  30. * This function will setup the field type data 
  31. * @type function 
  32. * @date 5/03/2014 
  33. * @since 5.0.0 
  34. * @param n/a 
  35. * @return n/a 
  36. */ 
  37.  
  38. function __construct() { 
  39. // vars 
  40. $this->name = 'leaflet_field'; 
  41. $this->label = __( 'Leaflet Field' ); 
  42. $this->category = __( 'Content', 'acf' ); // Basic, Content, Choice, etc 
  43. $this->defaults = array( 
  44. 'lat' => '55.606',  
  45. 'lng' => '13.002',  
  46. 'zoom_level' => 13,  
  47. 'height' => 400,  
  48. 'api_key' => '',  
  49. 'map_provider' => 'openstreetmap',  
  50. ); 
  51.  
  52.  
  53. // do not delete! 
  54. parent::__construct(); 
  55.  
  56.  
  57. // settings 
  58. $this->settings = array( 
  59. 'path' => apply_filters( 'acf/helpers/get_path', __FILE__ ),  
  60. 'dir' => apply_filters( 'acf/helpers/get_dir', __FILE__ ),  
  61. 'version' => '1.2.1' 
  62. ); 
  63.  
  64. add_action( 'acf/field_group/admin_head', array( $this, 'conditional_options' ) ); 
  65.  
  66.  
  67.  
  68. /** 
  69. * render_field_settings() 
  70. * Create extra settings for your field. These are visible when editing a field 
  71. * @type action 
  72. * @since 3.6 
  73. * @date 23/01/13 
  74. * @param $field (array) the $field being edited 
  75. * @return n/a 
  76. */ 
  77.  
  78. function render_field_settings( $field ) { 
  79.  
  80. /** 
  81. * acf_render_field_setting 
  82. * This function will create a setting for your field. Simply pass the $field parameter and an array of field settings. 
  83. * The array of settings does not require a `value` or `prefix`; These settings are found from the $field array. 
  84. * More than one setting can be added by copy/paste the above code. 
  85. * Please note that you must also have a matching $defaults value for the field name (font_size) 
  86. */ 
  87.  
  88. //error_log(print_r($field, true)); 
  89.  
  90. $providers = array(); 
  91.  
  92. foreach( acf_field_leaflet_field::$map_providers as $key => $value ) { 
  93. $providers[$key] = $value['nicename']; 
  94.  
  95. acf_render_field_setting( $field, array( 
  96. 'label' => __('Map Provider', 'acf-leaflet-field'),  
  97. 'instructions' => __('Select map provider', 'acf-leaflet-field'),  
  98. 'type' => 'radio',  
  99. 'name' => 'map_provider',  
  100. 'layout' => 'horizontal',  
  101. 'choices' => $providers 
  102. )); 
  103.  
  104. acf_render_field_setting( $field, array( 
  105. 'label' => __('Cloudmade API-key', 'acf-leaflet-field'),  
  106. 'instructions' => __('Register for an API-key at <a href="http://account.cloudmade.com/register" target="_blank">CloudMade</a>.', 'acf-leaflet-field'),  
  107. 'type' => 'text',  
  108. 'name' => 'api_key' 
  109. )); 
  110.  
  111. acf_render_field_setting( $field, array( 
  112. 'label' => __('Zoom level', 'acf-leaflet-field'),  
  113. //'instructions' => __('', 'acf-leaflet-field'),  
  114. 'type' => 'number',  
  115. 'name' => 'zoom_level' 
  116. )); 
  117.  
  118. acf_render_field_setting( $field, array( 
  119. 'label' => __('Default latitude', 'acf-leaflet-field'),  
  120. //'instructions' => __('', 'acf-leaflet-field'),  
  121. 'prepend' => 'lat',  
  122. 'type' => 'number',  
  123. 'name' => 'lat' 
  124. )); 
  125.  
  126. acf_render_field_setting( $field, array( 
  127. 'label' => __('Default longitude', 'acf-leaflet-field'),  
  128. //'instructions' => __('', 'acf-leaflet-field'),  
  129. 'prepend' => 'lng',  
  130. 'type' => 'number',  
  131. 'name' => 'lng' 
  132. )); 
  133.  
  134. acf_render_field_setting( $field, array( 
  135. 'label' => __('Height', 'acf-leaflet-field'),  
  136. 'instructions' => __('The map needs a specified height to be rendered correctly.', 'acf-leaflet-field'),  
  137. 'prepend' => 'px',  
  138. 'type' => 'number',  
  139. 'name' => 'height' 
  140. )); 
  141.  
  142.  
  143. /** 
  144. * ACF { Conditional Logic 
  145. * @description: hide / show fields based on a "trigger" field 
  146. * @created: 17/07/12 
  147. */ 
  148.  
  149. function conditional_options() 
  150. ?> 
  151. <style type="text/css"> 
  152. [data-type="leaflet_field"] [data-name="api_key"] { 
  153. display: none; 
  154. </style> 
  155. <script type="text/javascript"> 
  156. (function($) { 
  157. /* 
  158. * Map provider change 
  159. */ 
  160.  
  161. $(document).on('change', '[data-name="map_provider"] input' , function() { 
  162. // vars 
  163. var value = $(this).val(); 
  164.  
  165. <?php 
  166. // iterate map providers and check if they require an api-key 
  167. $conditions = ''; 
  168. foreach( acf_field_leaflet_field::$map_providers as $key => $map_provider ) 
  169. $conditions .= 'if( value == "' . $key . '" ) { $(this).parents("[data-name=\'map_provider\']").siblings("[data-name=\'api_key\']").'; 
  170.  
  171. if( $map_provider['requires_key'] ) 
  172. $conditions .= 'show'; 
  173. else { 
  174. $conditions .= 'hide'; 
  175.  
  176. $conditions .= '(); }'; 
  177.  
  178. echo $conditions; 
  179. ?> 
  180. }); 
  181.  
  182. })(jQuery); 
  183. </script> 
  184. <?php 
  185.  
  186.  
  187.  
  188. /** 
  189. * render_field() 
  190. * Create the HTML interface for your field 
  191. * @param $field (array) the $field being rendered 
  192. * @type action 
  193. * @since 3.6 
  194. * @date 23/01/13 
  195. * @param $field (array) the $field being edited 
  196. * @return n/a 
  197. */ 
  198.  
  199. function render_field( $field ) { 
  200.  
  201.  
  202. // defaults 
  203. $field = array_merge($this->defaults, $field); 
  204.  
  205. // Build an unique id based on ACF's one. 
  206. $pattern = array( '/\[/', '/\]/' ); 
  207. $replace = array( '_', '' ); 
  208. $uid = preg_replace($pattern, $replace, $field['name']); 
  209.  
  210. $field['id'] = $uid; 
  211.  
  212. // resolve tile-layer and attribution 
  213. $tile_layer = str_replace( '{api_key}', $field['api_key'], acf_field_leaflet_field::$map_providers[$field['map_provider']]['url'] ); 
  214. $attribution = acf_field_leaflet_field::$map_providers[$field['map_provider']]['attribution']; 
  215.  
  216. // include the javascript 
  217. include_once("js/input.js.php"); 
  218.  
  219. // render the field container,  
  220. ?> 
  221. <div id="leaflet_field-wrapper_<?php echo $uid; ?>" class="tool-marker-active"> 
  222. <input type="hidden" value='<?php echo $field['value']; ?>' id="field_<?php echo $uid; ?>" name="<?php echo $field['name']; ?>" data-zoom-level="<?php echo $field['zoom_level']; ?>" data-lat="<?php echo $field['lat']; ?>" data-lng="<?php echo $field['lng']; ?>" /> 
  223. <div class="leaflet-map" data-uid="<?php echo $uid; ?>" data-tile-layer="<?php echo $tile_layer; ?>" data-attribution='<?php echo $attribution; ?>'> 
  224. <div id="map_<?php echo $uid; ?>" style="height:<?php echo $field['height']; ?>px;"></div> 
  225. </div> 
  226. </div> 
  227. <?php 
  228.  
  229.  
  230. /** 
  231. * input_admin_enqueue_scripts() 
  232. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created. 
  233. * Use this action to add CSS + JavaScript to assist your render_field() action. 
  234. * @type action (admin_enqueue_scripts) 
  235. * @since 3.6 
  236. * @date 23/01/13 
  237. * @param n/a 
  238. * @return n/a 
  239. */ 
  240.  
  241. function input_admin_enqueue_scripts() { 
  242.  
  243. // styles 
  244. wp_enqueue_style( 'leaflet', plugins_url( '/js/leaflet/leaflet.css', __FILE__ ), array(), '0.7.3', 'all' ); 
  245. wp_enqueue_style( 'leaflet.draw', plugins_url( '/js/Leaflet.draw/dist/leaflet.draw.css', __FILE__ ), array(), 'ccca4b11ba4ff545433bf70f610b215053a2615e', 'all' ); 
  246. wp_enqueue_style( 'icomoon', plugins_url( '/css/icomoon/style.css', __FILE__ ), array(), '1.0.0', 'all' ); 
  247. wp_enqueue_style( 'leaflet-field', plugins_url( '/css/input.css', __FILE__ ), array( 'leaflet', 'icomoon' ), '1', 'all' ); 
  248.  
  249. // scripts 
  250. wp_enqueue_script( 'jquery' ); 
  251. wp_register_script( 'leaflet', plugins_url( '/js/leaflet/leaflet.js', __FILE__ ), array(), '0.7.3', true ); 
  252. wp_register_script( 'leaflet.draw', plugins_url( '/js/Leaflet.draw/dist/leaflet.draw.js', __FILE__ ), array( 'leaflet' ), 'ccca4b11ba4ff545433bf70f610b215053a2615e', true ); 
  253. wp_enqueue_script( 'leaflet' ); 
  254. wp_enqueue_script( 'leaflet.draw' ); 
  255.  
  256.  
  257.  
  258.  
  259. /** 
  260. * input_admin_head() 
  261. * This action is called in the admin_head action on the edit screen where your field is created. 
  262. * Use this action to add CSS and JavaScript to assist your render_field() action. 
  263. * @type action (admin_head) 
  264. * @since 3.6 
  265. * @date 23/01/13 
  266. * @param n/a 
  267. * @return n/a 
  268. */ 
  269.  
  270. /** 
  271.   
  272. function input_admin_head() { 
  273.   
  274.   
  275.   
  276.   
  277. */ 
  278.  
  279.  
  280. /** 
  281. * input_form_data() 
  282. * This function is called once on the 'input' page between the head and footer 
  283. * There are 2 situations where ACF did not load during the 'acf/input_admin_enqueue_scripts' and 
  284. * 'acf/input_admin_head' actions because ACF did not know it was going to be used. These situations are 
  285. * seen on comments / user edit forms on the front end. This function will always be called, and includes 
  286. * $args that related to the current screen such as $args['post_id'] 
  287. * @type function 
  288. * @date 6/03/2014 
  289. * @since 5.0.0 
  290. * @param $args (array) 
  291. * @return n/a 
  292. */ 
  293.  
  294. /** 
  295.   
  296. function input_form_data( $args ) { 
  297.   
  298.   
  299.   
  300.   
  301. */ 
  302.  
  303.  
  304. /** 
  305. * input_admin_footer() 
  306. * This action is called in the admin_footer action on the edit screen where your field is created. 
  307. * Use this action to add CSS and JavaScript to assist your render_field() action. 
  308. * @type action (admin_footer) 
  309. * @since 3.6 
  310. * @date 23/01/13 
  311. * @param n/a 
  312. * @return n/a 
  313. */ 
  314.  
  315. /** 
  316.   
  317. function input_admin_footer() { 
  318.   
  319.   
  320.   
  321.   
  322. */ 
  323.  
  324.  
  325. /** 
  326. * field_group_admin_enqueue_scripts() 
  327. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited. 
  328. * Use this action to add CSS + JavaScript to assist your render_field_options() action. 
  329. * @type action (admin_enqueue_scripts) 
  330. * @since 3.6 
  331. * @date 23/01/13 
  332. * @param n/a 
  333. * @return n/a 
  334. */ 
  335.  
  336. /** 
  337.   
  338. function field_group_admin_enqueue_scripts() { 
  339.   
  340.   
  341. */ 
  342.  
  343.  
  344. /** 
  345. * field_group_admin_head() 
  346. * This action is called in the admin_head action on the edit screen where your field is edited. 
  347. * Use this action to add CSS and JavaScript to assist your render_field_options() action. 
  348. * @type action (admin_head) 
  349. * @since 3.6 
  350. * @date 23/01/13 
  351. * @param n/a 
  352. * @return n/a 
  353. */ 
  354.  
  355. /** 
  356.   
  357. function field_group_admin_head() { 
  358.   
  359.   
  360. */ 
  361.  
  362.  
  363. /** 
  364. * load_value() 
  365. * This filter is applied to the $value after it is loaded from the db 
  366. * @type filter 
  367. * @since 3.6 
  368. * @date 23/01/13 
  369. * @param $value (mixed) the value found in the database 
  370. * @param $post_id (mixed) the $post_id from which the value was loaded 
  371. * @param $field (array) the field array holding all the field options 
  372. * @return $value 
  373. */ 
  374.  
  375. /** 
  376.   
  377. function load_value( $value, $post_id, $field ) { 
  378.   
  379. return $value; 
  380.   
  381.   
  382. */ 
  383.  
  384.  
  385. /** 
  386. * update_value() 
  387. * This filter is applied to the $value before it is saved in the db 
  388. * @type filter 
  389. * @since 3.6 
  390. * @date 23/01/13 
  391. * @param $value (mixed) the value found in the database 
  392. * @param $post_id (mixed) the $post_id from which the value was loaded 
  393. * @param $field (array) the field array holding all the field options 
  394. * @return $value 
  395. */ 
  396.  
  397. /** 
  398.   
  399. function update_value( $value, $post_id, $field ) { 
  400.   
  401. return $value; 
  402.   
  403.   
  404. */ 
  405.  
  406.  
  407. /** 
  408. * format_value() 
  409. * This filter is appied to the $value after it is loaded from the db and before it is returned to the template 
  410. * @type filter 
  411. * @since 3.6 
  412. * @date 23/01/13 
  413. * @param $value (mixed) the value which was loaded from the database 
  414. * @param $post_id (mixed) the $post_id from which the value was loaded 
  415. * @param $field (array) the field array holding all the field options 
  416. * @return $value (mixed) the modified value 
  417. */ 
  418.  
  419. /** 
  420.   
  421. function format_value( $value, $post_id, $field ) { 
  422.   
  423. // bail early if no value 
  424. if( empty($value) ) { 
  425.   
  426. return $value; 
  427.   
  428.   
  429.   
  430. // apply setting 
  431. if( $field['font_size'] > 12 ) { 
  432.   
  433. // format the value 
  434. // $value = 'something'; 
  435.   
  436.   
  437.   
  438. // return 
  439. return $value; 
  440.   
  441. */ 
  442.  
  443.  
  444. /** 
  445. * validate_value() 
  446. * This filter is used to perform validation on the value prior to saving. 
  447. * All values are validated regardless of the field's required setting. This allows you to validate and return 
  448. * messages to the user if the value is not correct 
  449. * @type filter 
  450. * @date 11/02/2014 
  451. * @since 5.0.0 
  452. * @param $valid (boolean) validation status based on the value and the field's required setting 
  453. * @param $value (mixed) the $_POST value 
  454. * @param $field (array) the field array holding all the field options 
  455. * @param $input (string) the corresponding input name for $_POST value 
  456. * @return $valid 
  457. */ 
  458.  
  459. /** 
  460.   
  461. function validate_value( $valid, $value, $field, $input ) { 
  462.   
  463. // Basic usage 
  464. if( $value < $field['custom_minimum_setting'] ) 
  465. $valid = false; 
  466.   
  467.   
  468. // Advanced usage 
  469. if( $value < $field['custom_minimum_setting'] ) 
  470. $valid = __('The value is too little!', 'acf-FIELD_NAME'),  
  471.   
  472.   
  473. // return 
  474. return $valid; 
  475.   
  476.   
  477. */ 
  478.  
  479.  
  480. /** 
  481. * delete_value() 
  482. * This action is fired after a value has been deleted from the db. 
  483. * Please note that saving a blank value is treated as an update, not a delete 
  484. * @type action 
  485. * @date 6/03/2014 
  486. * @since 5.0.0 
  487. * @param $post_id (mixed) the $post_id from which the value was deleted 
  488. * @param $key (string) the $meta_key which the value was deleted 
  489. * @return n/a 
  490. */ 
  491.  
  492. /** 
  493.   
  494. function delete_value( $post_id, $key ) { 
  495.   
  496.   
  497.   
  498.   
  499. */ 
  500.  
  501.  
  502. /** 
  503. * load_field() 
  504. * This filter is applied to the $field after it is loaded from the database 
  505. * @type filter 
  506. * @date 23/01/2013 
  507. * @since 3.6.0 
  508. * @param $field (array) the field array holding all the field options 
  509. * @return $field 
  510. */ 
  511.  
  512. /** 
  513.   
  514. function load_field( $field ) { 
  515.   
  516. return $field; 
  517.   
  518.   
  519. */ 
  520.  
  521.  
  522. /** 
  523. * update_field() 
  524. * This filter is applied to the $field before it is saved to the database 
  525. * @type filter 
  526. * @date 23/01/2013 
  527. * @since 3.6.0 
  528. * @param $field (array) the field array holding all the field options 
  529. * @return $field 
  530. */ 
  531.  
  532. /** 
  533.   
  534. function update_field( $field ) { 
  535.   
  536. return $field; 
  537.   
  538.   
  539. */ 
  540.  
  541.  
  542. /** 
  543. * delete_field() 
  544. * This action is fired after a field is deleted from the database 
  545. * @type action 
  546. * @date 11/02/2014 
  547. * @since 5.0.0 
  548. * @param $field (array) the field array holding all the field options 
  549. * @return n/a 
  550. */ 
  551.  
  552. /** 
  553.   
  554. function delete_field( $field ) { 
  555.   
  556.   
  557.   
  558.   
  559. */ 
  560.  
  561.  
/leaflet_field-v4.php  
  1. class acf_field_leaflet_field extends acf_field 
  2.  
  3. // vars 
  4. var $settings, // will hold info such as dir / path 
  5. $defaults; // will hold default field options 
  6.  
  7. // holds information about supported tile-providers 
  8. static $map_providers = array( 
  9. 'openstreetmap' => array( 
  10. 'url' => 'http://tile.openstreetmap.org/{z}/{x}/{y}.png',  
  11. 'requires_key' => false,  
  12. 'nicename' => 'OpenStreetMap',  
  13. 'attribution' => 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors' 
  14. ),  
  15. 'openstreetmap_blackandwhite' => array( 
  16. 'url' => 'http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png',  
  17. 'requires_key' => false,  
  18. 'nicename' => 'OpenStreetMap Black and White',  
  19. 'attribution' => '© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>' 
  20. ),  
  21. 'cloudmade' => array( 
  22. 'url' => "http://{s}.tile.cloudmade.com/{api_key}/997/256/{z}/{x}/{y}.png",  
  23. 'requires_key' => true,  
  24. 'nicename' => 'CloudMade',  
  25. 'attribution' => 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery <a href="http://cloudmade.com">CloudMade</a>' 
  26. ); 
  27.  
  28. /** 
  29. * __construct 
  30. * Set name / label needed for actions / filters 
  31. * @since 3.6 
  32. * @date 23/01/13 
  33. */ 
  34.  
  35. function __construct() 
  36. // vars 
  37. $this->name = 'leaflet_field'; 
  38. $this->label = __( 'Leaflet Field' ); 
  39. $this->category = __( 'Content', 'acf' ); // Basic, Content, Choice, etc 
  40. $this->defaults = array( 
  41. 'lat' => '55.606',  
  42. 'lng' => '13.002',  
  43. 'zoom_level' => 13,  
  44. 'height' => 400,  
  45. 'api_key' => '',  
  46. 'map_provider' => 'openstreetmap',  
  47. ); 
  48.  
  49.  
  50. // do not delete! 
  51. parent::__construct(); 
  52.  
  53.  
  54. // settings 
  55. $this->settings = array( 
  56. 'path' => apply_filters( 'acf/helpers/get_path', __FILE__ ),  
  57. 'dir' => apply_filters( 'acf/helpers/get_dir', __FILE__ ),  
  58. 'version' => '1.2.1' 
  59. ); 
  60.  
  61. add_action( 'acf/field_group/admin_head', array( $this, 'conditional_options' ) ); 
  62.  
  63.  
  64. /** 
  65. * create_options() 
  66. * Create extra options for your field. This is rendered when editing a field. 
  67. * The value of $field['name'] can be used (like below) to save extra data to the $field 
  68. * @type action 
  69. * @since 3.6 
  70. * @date 23/01/13 
  71. * @param $field - an array holding all the field's data 
  72. */ 
  73.  
  74. function create_options( $field ) 
  75. // defaults 
  76. $field = array_merge($this->defaults, $field); 
  77.  
  78. // key is needed in the field names to correctly save the data 
  79. $key = $field['name']; 
  80.  
  81. $providers = array(); 
  82.  
  83. foreach( acf_field_leaflet_field::$map_providers as $key => $value ) { 
  84. $providers[$key] = $value['nicename']; 
  85.  
  86. // Create Field Options HTML 
  87. ?> 
  88. <tr class="leaflet_field_map_provider_field field_option field_option_<?php echo $this->name; ?>"> 
  89. <td class="label"> 
  90. <label><?php _e('Map provider', 'acf-leaflet-field'); ?></label> 
  91. <p class="description"><?php _e('Select map provider', 'acf-leaflet-field'); ?></p> 
  92. </td> 
  93. <td> 
  94. <?php 
  95. do_action('acf/create_field', array( 
  96. 'type' => 'radio',  
  97. 'name' => 'fields['.$key.'][map_provider]',  
  98. 'value' => $field['map_provider'],  
  99. 'layout' => 'horizontal',  
  100. 'choices' => $providers 
  101. )); 
  102. ?> 
  103. </td> 
  104. </tr> 
  105.  
  106. <tr class="leaflet_field_api_key_field field_option field_option_<?php echo $this->name; ?>"> 
  107. <td class="label"> 
  108. <label><?php _e('Cloudmade API-key', 'acf-leaflet-field'); ?></label> 
  109. <p class="description"><?php _e('Register for an API-key at ', 'acf-leaflet-field'); ?><a href="http://account.cloudmade.com/register" target="_blank">CloudMade</a>.</p> 
  110. </td> 
  111. <td> 
  112. <?php 
  113. do_action('acf/create_field', array( 
  114. 'type' => 'text',  
  115. 'name' => 'fields['.$key.'][api_key]',  
  116. 'value' => $field['api_key'] 
  117. )); 
  118. ?> 
  119. </td> 
  120. </tr> 
  121.  
  122. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  123. <td class="label"> 
  124. <label><?php _e('Zoom level', 'acf-leaflet-field'); ?></label> 
  125. <p class="description"><?php _e('', 'acf-leaflet-field'); ?></p> 
  126. </td> 
  127. <td> 
  128. <?php 
  129. do_action('acf/create_field', array( 
  130. 'type' => 'number',  
  131. 'name' => 'fields['.$key.'][zoom_level]',  
  132. 'value' => $field['zoom_level'] 
  133. )); 
  134. ?> 
  135. </td> 
  136. </tr> 
  137.  
  138. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  139. <td class="label"> 
  140. <label><?php _e('Latitude', 'acf-leaflet-field'); ?></label> 
  141. <p class="description"><?php _e('', 'acf-leaflet-field'); ?></p> 
  142. </td> 
  143. <td> 
  144. <?php 
  145. do_action('acf/create_field', array( 
  146. 'type' => 'number',  
  147. 'name' => 'fields['.$key.'][lat]',  
  148. 'value' => $field['lat'] 
  149. )); 
  150. ?> 
  151. </td> 
  152. </tr> 
  153.  
  154. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  155. <td class="label"> 
  156. <label><?php _e('Longitude', 'acf-leaflet-field'); ?></label> 
  157. <p class="description"><?php _e('', 'acf-leaflet-field'); ?></p> 
  158. </td> 
  159. <td> 
  160. <?php 
  161. do_action('acf/create_field', array( 
  162. 'type' => 'number',  
  163. 'name' => 'fields['.$key.'][lng]',  
  164. 'value' => $field['lng'] 
  165. )); 
  166. ?> 
  167. </td> 
  168. </tr> 
  169.  
  170. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  171. <td class="label"> 
  172. <label><?php _e('Height', 'acf-leaflet-field'); ?></label> 
  173. <p class="description"><?php _e('The map needs a specified height to be rendered correctly.', 'acf-leaflet-field'); ?></p> 
  174. </td> 
  175. <td> 
  176. <?php 
  177. do_action('acf/create_field', array( 
  178. 'type' => 'number',  
  179. 'name' => 'fields['.$key.'][height]',  
  180. 'value' => $field['height'] 
  181. )); 
  182. ?> 
  183. </td> 
  184. </tr> 
  185. <?php 
  186.  
  187.  
  188. /** 
  189. * ACF { Conditional Logic 
  190. * @description: hide / show fields based on a "trigger" field 
  191. * @created: 17/07/12 
  192. */ 
  193.  
  194. function conditional_options() 
  195. ?> 
  196. <style type="text/css"> 
  197. .leaflet_field_api_key_field { 
  198. display: none; 
  199. </style> 
  200. <script type="text/javascript"> 
  201. (function($) { 
  202. /* 
  203. * Map provider change 
  204. */ 
  205.  
  206. $(document).on('change', '.leaflet_field_map_provider_field input' , function() { 
  207. // vars 
  208. var value = $(this).val(); 
  209.  
  210. <?php 
  211. // iterate map providers and check if they require an api-key 
  212. $conditions = ''; 
  213. foreach( acf_field_leaflet_field::$map_providers as $key => $map_provider ) 
  214. $conditions .= 'if( value == "' . $key . '" ) { $(this).parents(".leaflet_field_map_provider_field").siblings(".leaflet_field_api_key_field").'; 
  215.  
  216. if( $map_provider['requires_key'] ) 
  217. $conditions .= 'show'; 
  218. else { 
  219. $conditions .= 'hide'; 
  220.  
  221. $conditions .= '(); }'; 
  222.  
  223. echo $conditions; 
  224. ?> 
  225. }); 
  226.  
  227. })(jQuery); 
  228. </script> 
  229. <?php 
  230.  
  231. /** 
  232. * create_field() 
  233. * Create the HTML interface for your field 
  234. * @param $field - an array holding all the field's data 
  235. * @type action 
  236. * @since 3.6 
  237. * @date 23/01/13 
  238. */ 
  239.  
  240. function create_field( $field ) 
  241. // defaults 
  242. $field = array_merge($this->defaults, $field); 
  243.  
  244. // Build an unique id based on ACF's one. 
  245. $pattern = array( '/\[/', '/\]/' ); 
  246. $replace = array( '_', '' ); 
  247. $uid = preg_replace($pattern, $replace, $field['name']); 
  248.  
  249. $field['id'] = $uid; 
  250.  
  251. // resolve tile-layer and attribution 
  252. $tile_layer = str_replace( '{api_key}', $field['api_key'], acf_field_leaflet_field::$map_providers[$field['map_provider']]['url'] ); 
  253. $attribution = acf_field_leaflet_field::$map_providers[$field['map_provider']]['attribution']; 
  254.  
  255. // include the javascript 
  256. include_once("js/input.js.php"); 
  257.  
  258. // render the field container,  
  259. ?> 
  260. <div id="leaflet_field-wrapper_<?php echo $uid; ?>" class="tool-marker-active"> 
  261. <input type="hidden" value='<?php echo $field['value']; ?>' id="field_<?php echo $uid; ?>" name="<?php echo $field['name']; ?>" data-zoom-level="<?php echo $field['zoom_level']; ?>" data-lat="<?php echo $field['lat']; ?>" data-lng="<?php echo $field['lng']; ?>" /> 
  262. <div class="leaflet-map" data-uid="<?php echo $uid; ?>" data-tile-layer="<?php echo $tile_layer; ?>" data-attribution='<?php echo $attribution; ?>'> 
  263. <div id="map_<?php echo $uid; ?>" style="height:<?php echo $field['height']; ?>px;"></div> 
  264. </div> 
  265. </div> 
  266. <?php 
  267.  
  268.  
  269. /** 
  270. * input_admin_enqueue_scripts() 
  271. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created. 
  272. * Use this action to add css + javascript to assist your create_field() action. 
  273. * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts 
  274. * @type action 
  275. * @since 3.6 
  276. * @date 23/01/13 
  277. */ 
  278.  
  279. function input_admin_enqueue_scripts() 
  280. // styles 
  281. wp_enqueue_style( 'leaflet', plugins_url( '/js/leaflet/leaflet.css', __FILE__ ), array(), '0.7.3', 'all' ); 
  282. wp_enqueue_style( 'leaflet.draw', plugins_url( '/js/Leaflet.draw/dist/leaflet.draw.css', __FILE__ ), array(), 'ccca4b11ba4ff545433bf70f610b215053a2615e', 'all' ); 
  283. wp_enqueue_style( 'icomoon', plugins_url( '/css/icomoon/style.css', __FILE__ ), array(), '1.0.0', 'all' ); 
  284. wp_enqueue_style( 'leaflet-field', plugins_url( '/css/input.css', __FILE__ ), array( 'leaflet', 'icomoon' ), '1', 'all' ); 
  285.  
  286. // scripts 
  287. wp_enqueue_script( 'jquery' ); 
  288. wp_register_script( 'leaflet', plugins_url( '/js/leaflet/leaflet.js', __FILE__ ), array(), '0.7.3', false ); 
  289. wp_register_script( 'leaflet.draw', plugins_url( '/js/Leaflet.draw/dist/leaflet.draw.js', __FILE__ ), array( 'leaflet' ), 'ccca4b11ba4ff545433bf70f610b215053a2615e', false ); 
  290. wp_enqueue_script( 'leaflet' ); 
  291. wp_enqueue_script( 'leaflet.draw' ); 
  292.  
  293.  
  294. /** 
  295. * input_admin_head() 
  296. * This action is called in the admin_head action on the edit screen where your field is created. 
  297. * Use this action to add css and javascript to assist your create_field() action. 
  298. * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head 
  299. * @type action 
  300. * @since 3.6 
  301. * @date 23/01/13 
  302. */ 
  303.  
  304. function input_admin_head() 
  305. // Note: This function can be removed if not used 
  306.  
  307.  
  308. /** 
  309. * field_group_admin_enqueue_scripts() 
  310. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited. 
  311. * Use this action to add css + javascript to assist your create_field_options() action. 
  312. * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts 
  313. * @type action 
  314. * @since 3.6 
  315. * @date 23/01/13 
  316. */ 
  317.  
  318. function field_group_admin_enqueue_scripts() 
  319. // Note: This function can be removed if not used 
  320.  
  321.  
  322. /** 
  323. * field_group_admin_head() 
  324. * This action is called in the admin_head action on the edit screen where your field is edited. 
  325. * Use this action to add css and javascript to assist your create_field_options() action. 
  326. * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head 
  327. * @type action 
  328. * @since 3.6 
  329. * @date 23/01/13 
  330. */ 
  331.  
  332. function field_group_admin_head() 
  333. // Note: This function can be removed if not used 
  334.  
  335.  
  336. /** 
  337. * load_value() 
  338. * This filter is appied to the $value after it is loaded from the db 
  339. * @type filter 
  340. * @since 3.6 
  341. * @date 23/01/13 
  342. * @param $value - the value found in the database 
  343. * @param $post_id - the $post_id from which the value was loaded from 
  344. * @param $field - the field array holding all the field options 
  345. * @return $value - the value to be saved in te database 
  346. */ 
  347.  
  348. function load_value( $value, $post_id, $field ) 
  349. // Note: This function can be removed if not used 
  350. return $value; 
  351.  
  352.  
  353. /** 
  354. * update_value() 
  355. * This filter is appied to the $value before it is updated in the db 
  356. * @type filter 
  357. * @since 3.6 
  358. * @date 23/01/13 
  359. * @param $value - the value which will be saved in the database 
  360. * @param $post_id - the $post_id of which the value will be saved 
  361. * @param $field - the field array holding all the field options 
  362. * @return $value - the modified value 
  363. */ 
  364.  
  365. function update_value( $value, $post_id, $field ) 
  366. // Note: This function can be removed if not used 
  367. return $value; 
  368.  
  369.  
  370. /** 
  371. * format_value() 
  372. * This filter is appied to the $value after it is loaded from the db and before it is passed to the create_field action 
  373. * @type filter 
  374. * @since 3.6 
  375. * @date 23/01/13 
  376. * @param $value - the value which was loaded from the database 
  377. * @param $post_id - the $post_id from which the value was loaded 
  378. * @param $field - the field array holding all the field options 
  379. * @return $value - the modified value 
  380. */ 
  381.  
  382. function format_value( $value, $post_id, $field ) 
  383. // defaults? 
  384. /** 
  385. $field = array_merge($this->defaults, $field); 
  386. */ 
  387.  
  388. // perhaps use $field['preview_size'] to alter the $value? 
  389.  
  390.  
  391. // Note: This function can be removed if not used 
  392. return $value; 
  393.  
  394.  
  395. /** 
  396. * format_value_for_api() 
  397. * 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 
  398. * @type filter 
  399. * @since 3.6 
  400. * @date 23/01/13 
  401. * @param $value - the value which was loaded from the database 
  402. * @param $post_id - the $post_id from which the value was loaded 
  403. * @param $field - the field array holding all the field options 
  404. * @return $value - the modified value 
  405. */ 
  406.  
  407. function format_value_for_api( $value, $post_id, $field ) 
  408. // defaults? 
  409. $field = array_merge( $this->defaults, $field ); 
  410.  
  411. // format value 
  412. $value = json_decode( $value ); 
  413.  
  414. // Note: This function can be removed if not used 
  415. return $value; 
  416.  
  417.  
  418. /** 
  419. * load_field() 
  420. * This filter is appied to the $field after it is loaded from the database 
  421. * @type filter 
  422. * @since 3.6 
  423. * @date 23/01/13 
  424. * @param $field - the field array holding all the field options 
  425. * @return $field - the field array holding all the field options 
  426. */ 
  427.  
  428. function load_field( $field ) 
  429. // Note: This function can be removed if not used 
  430. return $field; 
  431.  
  432.  
  433. /** 
  434. * update_field() 
  435. * This filter is appied to the $field before it is saved to the database 
  436. * @type filter 
  437. * @since 3.6 
  438. * @date 23/01/13 
  439. * @param $field - the field array holding all the field options 
  440. * @param $post_id - the field group ID (post_type = acf) 
  441. * @return $field - the modified field 
  442. */ 
  443.  
  444. function update_field( $field, $post_id ) 
  445. // Note: This function can be removed if not used 
  446. return $field; 
  447.  
  448.