acf_field

Acf_field.

Defined (1)

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

/core/fields/_base.php  
  1. class acf_field 
  2. /** 
  3. * Vars 
  4. * @description:  
  5. * @since: 3.6 
  6. * @created: 30/01/13 
  7. */ 
  8.  
  9. var $name,  
  10. $title,  
  11. $category,  
  12. $defaults,  
  13. $l10n; 
  14.  
  15.  
  16. /** 
  17. * __construct() 
  18. * Adds neccessary Actions / Filters 
  19. * @since 3.6 
  20. * @date 30/01/13 
  21. */ 
  22.  
  23. function __construct() 
  24. // register field 
  25. add_filter('acf/registered_fields', array($this, 'registered_fields'), 10, 1); 
  26. add_filter('acf/load_field_defaults/type=' . $this->name, array($this, 'load_field_defaults'), 10, 1); 
  27.  
  28.  
  29. // value 
  30. $this->add_filter('acf/load_value/type=' . $this->name, array($this, 'load_value'), 10, 3); 
  31. $this->add_filter('acf/update_value/type=' . $this->name, array($this, 'update_value'), 10, 3); 
  32. $this->add_filter('acf/format_value/type=' . $this->name, array($this, 'format_value'), 10, 3); 
  33. $this->add_filter('acf/format_value_for_api/type=' . $this->name, array($this, 'format_value_for_api'), 10, 3); 
  34.  
  35.  
  36. // field 
  37. $this->add_filter('acf/load_field/type=' . $this->name, array($this, 'load_field'), 10, 3); 
  38. $this->add_filter('acf/update_field/type=' . $this->name, array($this, 'update_field'), 10, 2); 
  39. $this->add_action('acf/create_field/type=' . $this->name, array($this, 'create_field'), 10, 1); 
  40. $this->add_action('acf/create_field_options/type=' . $this->name, array($this, 'create_options'), 10, 1); 
  41.  
  42.  
  43. // input actions 
  44. $this->add_action('acf/input/admin_enqueue_scripts', array($this, 'input_admin_enqueue_scripts'), 10, 0); 
  45. $this->add_action('acf/input/admin_head', array($this, 'input_admin_head'), 10, 0); 
  46. $this->add_filter('acf/input/admin_l10n', array($this, 'input_admin_l10n'), 10, 1); 
  47.  
  48.  
  49. // field group actions 
  50. $this->add_action('acf/field_group/admin_enqueue_scripts', array($this, 'field_group_admin_enqueue_scripts'), 10, 0); 
  51. $this->add_action('acf/field_group/admin_head', array($this, 'field_group_admin_head'), 10, 0); 
  52.  
  53.  
  54.  
  55. /** 
  56. * add_filter 
  57. * @description: checks if the function is_callable before adding the filter 
  58. * @since: 3.6 
  59. * @created: 30/01/13 
  60. */ 
  61.  
  62. function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) 
  63. if( is_callable($function_to_add) ) 
  64. add_filter($tag, $function_to_add, $priority, $accepted_args); 
  65.  
  66.  
  67. /** 
  68. * add_action 
  69. * @description: checks if the function is_callable before adding the action 
  70. * @since: 3.6 
  71. * @created: 30/01/13 
  72. */ 
  73.  
  74. function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) 
  75. if( is_callable($function_to_add) ) 
  76. add_action($tag, $function_to_add, $priority, $accepted_args); 
  77.  
  78.  
  79. /** 
  80. * registered_fields() 
  81. * Adds this field to the select list when creating a new field 
  82. * @type filter 
  83. * @since 3.6 
  84. * @date 23/01/13 
  85. * @param $fields - the array of all registered fields 
  86. * @return $fields - the array of all registered fields 
  87. */ 
  88.  
  89. function registered_fields( $fields ) 
  90. // defaults 
  91. if( !$this->category ) 
  92. $this->category = __('Basic', 'acf'); 
  93.  
  94.  
  95. // add to array 
  96. $fields[ $this->category ][ $this->name ] = $this->label; 
  97.  
  98.  
  99. // return array 
  100. return $fields; 
  101.  
  102.  
  103. /** 
  104. * load_field_defaults 
  105. * action called when rendering the head of an admin screen. Used primarily for passing PHP to JS 
  106. * @type filer 
  107. * @date 1/06/13 
  108. * @param $field {array} 
  109. * @return $field {array} 
  110. */ 
  111.  
  112. function load_field_defaults( $field ) 
  113. if( !empty($this->defaults) ) 
  114. foreach( $this->defaults as $k => $v ) 
  115. if( !isset($field[ $k ]) ) 
  116. $field[ $k ] = $v; 
  117.  
  118. return $field; 
  119.  
  120.  
  121. /** 
  122. * admin_l10n 
  123. * filter is called to load all l10n text translations into the admin head script tag 
  124. * @type filer 
  125. * @date 1/06/13 
  126. * @param $field {array} 
  127. * @return $field {array} 
  128. */ 
  129.  
  130. function input_admin_l10n( $l10n ) 
  131. if( !empty($this->l10n) ) 
  132. $l10n[ $this->name ] = $this->l10n; 
  133.  
  134. return $l10n; 
  135.  
  136.