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