123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly
- }
- if ( ! class_exists( 'acf_fields' ) ) :
- class acf_fields {
- /** @var array Contains an array of field type instances */
- var $types = array();
- /*
- * __construct
- *
- * 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 */
- }
- /*
- * register_field_type
- *
- * This function will register a field type instance
- *
- * @type function
- * @date 6/07/2016
- * @since 5.4.0
- *
- * @param $class (string)
- * @return n/a
- */
- function register_field_type( $class ) {
- // allow instance
- if ( $class instanceof acf_field ) {
- $this->types[ $class->name ] = $class;
- // allow class name
- } else {
- $instance = new $class();
- $this->types[ $instance->name ] = $instance;
- }
- }
- /*
- * get_field_type
- *
- * 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;
- }
- /*
- * is_field_type
- *
- * 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 ] );
- }
- /*
- * register_field_type_info
- *
- * 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;
- }
- /*
- * get_field_types
- *
- * 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;
- }
- }
- // initialize
- acf()->fields = new acf_fields();
- endif; // class_exists check
- /*
- * acf_register_field_type
- *
- * alias of acf()->fields->register_field_type()
- *
- * @type function
- * @date 31/5/17
- * @since 5.6.0
- *
- * @param n/a
- * @return n/a
- */
- function acf_register_field_type( $class ) {
- return acf()->fields->register_field_type( $class );
- }
- /*
- * acf_register_field_type_info
- *
- * alias of acf()->fields->register_field_type_info()
- *
- * @type function
- * @date 31/5/17
- * @since 5.6.0
- *
- * @param n/a
- * @return n/a
- */
- function acf_register_field_type_info( $info ) {
- return acf()->fields->register_field_type_info( $info );
- }
- /*
- * acf_get_field_type
- *
- * alias of acf()->fields->get_field_type()
- *
- * @type function
- * @date 31/5/17
- * @since 5.6.0
- *
- * @param n/a
- * @return n/a
- */
- function acf_get_field_type( $name ) {
- return acf()->fields->get_field_type( $name );
- }
- /*
- * acf_get_field_types
- *
- * alias of acf()->fields->get_field_types()
- *
- * @type function
- * @date 31/5/17
- * @since 5.6.0
- *
- * @param n/a
- * @return n/a
- */
- function acf_get_field_types( $args = array() ) {
- // default
- $args = wp_parse_args(
- $args,
- array(
- 'public' => true, // true, false
- )
- );
- // get field types
- $field_types = acf()->fields->get_field_types();
- // filter
- return wp_filter_object_list( $field_types, $args );
- }
- /**
- * acf_get_field_types_info
- *
- * Returns an array containing information about each field type
- *
- * @date 18/6/18
- * @since 5.6.9
- *
- * @param type $var Description. Default.
- * @return type Description.
- */
- function acf_get_field_types_info( $args = array() ) {
- // vars
- $data = array();
- $field_types = acf_get_field_types();
- // loop
- foreach ( $field_types as $type ) {
- $data[ $type->name ] = array(
- 'label' => $type->label,
- 'name' => $type->name,
- 'category' => $type->category,
- 'public' => $type->public,
- );
- }
- // return
- return $data;
- }
- /*
- * acf_is_field_type
- *
- * alias of acf()->fields->is_field_type()
- *
- * @type function
- * @date 31/5/17
- * @since 5.6.0
- *
- * @param n/a
- * @return n/a
- */
- function acf_is_field_type( $name = '' ) {
- return acf()->fields->is_field_type( $name );
- }
- /*
- * acf_get_field_type_prop
- *
- * This function will return a field type's property
- *
- * @type function
- * @date 1/10/13
- * @since 5.0.0
- *
- * @param n/a
- * @return (array)
- */
- function acf_get_field_type_prop( $name = '', $prop = '' ) {
- $type = acf_get_field_type( $name );
- return ( $type && isset( $type->$prop ) ) ? $type->$prop : null;
- }
- /*
- * acf_get_field_type_label
- *
- * This function will return the label of a field type
- *
- * @type function
- * @date 1/10/13
- * @since 5.0.0
- *
- * @param n/a
- * @return (array)
- */
- function acf_get_field_type_label( $name = '' ) {
- $label = acf_get_field_type_prop( $name, 'label' );
- return $label ? $label : '<span class="acf-tooltip-js" title="' . __( 'Field type does not exist', 'acf' ) . '">' . __( 'Unknown', 'acf' ) . '</span>';
- }
- /*
- * acf_field_type_exists (deprecated)
- *
- * deprecated in favour of acf_is_field_type()
- *
- * @type function
- * @date 1/10/13
- * @since 5.0.0
- *
- * @param $type (string)
- * @return (boolean)
- */
- function acf_field_type_exists( $type = '' ) {
- return acf_is_field_type( $type );
- }
- /*
- * acf_get_grouped_field_types
- *
- * Returns an multi-dimentional array of field types "name => label" grouped by category
- *
- * @type function
- * @date 1/10/13
- * @since 5.0.0
- *
- * @param n/a
- * @return (array)
- */
- function acf_get_grouped_field_types() {
- // vars
- $types = acf_get_field_types();
- $groups = array();
- $l10n = array(
- 'basic' => __( 'Basic', 'acf' ),
- 'content' => __( 'Content', 'acf' ),
- 'choice' => __( 'Choice', 'acf' ),
- 'relational' => __( 'Relational', 'acf' ),
- 'jquery' => __( 'jQuery', 'acf' ),
- 'layout' => __( 'Layout', 'acf' ),
- );
- // loop
- foreach ( $types as $type ) {
- // translate
- $cat = $type->category;
- $cat = isset( $l10n[ $cat ] ) ? $l10n[ $cat ] : $cat;
- // append
- $groups[ $cat ][ $type->name ] = $type->label;
- }
- // filter
- $groups = apply_filters( 'acf/get_field_types', $groups );
- // return
- return $groups;
- }
|