class acf_fields {
/** @var array Contains an array of field type instances */
var $types = array();
/**
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function __construct() {
/* do nothing */
}
/**
* This function will register a field type instance based on a class name or instance.
* It will return the instance for further use.
*
* @since 5.4.0
*
* @param mixed $field_class Either a class name (string) or instance of acf_field.
* @return acf_field The instance of acf_field.
*/
public function register_field_type( $field_class ) {
// Allow registering an instance.
if ( $field_class instanceof acf_field ) {
$this->types[ $field_class->name ] = $field_class;
return $field_class;
}
// Allow registering a loaded class name.
$instance = new $field_class();
$this->types[ $instance->name ] = $instance;
return $instance;
}
/**
* This function will return a field type instance
*
* @type function
* @date 6/07/2016
* @since 5.4.0
*
* @param $name (string)
* @return (mixed)
*/
function get_field_type( $name ) {
return isset( $this->types[ $name ] ) ? $this->types[ $name ] : null;
}
/**
* This function will return true if a field type exists
*
* @type function
* @date 6/07/2016
* @since 5.4.0
*
* @param $name (string)
* @return (mixed)
*/
function is_field_type( $name ) {
return isset( $this->types[ $name ] );
}
/**
* This function will store a basic array of info about the field type
* to later be overriden by the above register_field_type function
*
* @type function
* @date 29/5/17
* @since 5.6.0
*
* @param $info (array)
* @return n/a
*/
function register_field_type_info( $info ) {
// convert to object
$instance = (object) $info;
$this->types[ $instance->name ] = $instance;
}
/**
* This function will return an array of all field types
*
* @type function
* @date 6/07/2016
* @since 5.4.0
*
* @param $name (string)
* @return (mixed)
*/
function get_field_types() {
return $this->types;
}
}