Repository: AdvancedCustomFields/acf-field-type-template Branch: master Commit: edb3b661a164 Files: 14 Total size: 23.5 KB Directory structure: gitextract_5m9lcrwj/ ├── .gitignore ├── README.md └── acf-FIELD-NAME/ ├── README.md ├── acf-FIELD-NAME.php ├── assets/ │ ├── README.md │ ├── css/ │ │ ├── README.md │ │ └── input.css │ ├── images/ │ │ └── README.md │ └── js/ │ ├── README.md │ └── input.js ├── fields/ │ ├── class-NAMESPACE-acf-field-FIELD-NAME-v4.php │ └── class-NAMESPACE-acf-field-FIELD-NAME-v5.php ├── lang/ │ └── README.md └── readme.txt ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # OS generated files # ###################### .DS_Store .DS_Store? ._* .Spotlight-V100 .Trashes ehthumbs.db Thumbs.db ================================================ FILE: README.md ================================================ # ACF Field Type Template (Deprecated) This is an archived repository for the ACF Field Type Template for ACF v4 and V5. A new field type template for ACF v6 is now available at https://github.com/AdvancedCustomFields/acf-example-field-type. Looking for documentation? Please read the [Creating a new field type guide](https://www.advancedcustomfields.com/resources/creating-a-new-field-type/). ================================================ FILE: acf-FIELD-NAME/README.md ================================================ # ACF FIELD_LABEL Field Welcome to the Advanced Custom Fields FIELD_LABEL repository on Github. EXTENDED_DESCRIPTION ================================================ FILE: acf-FIELD-NAME/acf-FIELD-NAME.php ================================================ settings = array( 'version' => '1.0.0', 'url' => plugin_dir_url( __FILE__ ), 'path' => plugin_dir_path( __FILE__ ) ); // include field add_action('acf/include_field_types', array($this, 'include_field')); // v5 add_action('acf/register_fields', array($this, 'include_field')); // v4 } /* * include_field * * This function will include the field type class * * @type function * @date 17/02/2016 * @since 1.0.0 * * @param $version (int) major ACF version. Defaults to false * @return void */ function include_field( $version = false ) { // support empty $version if( !$version ) $version = 4; // load textdomain load_plugin_textdomain( 'TEXTDOMAIN', false, plugin_basename( dirname( __FILE__ ) ) . '/lang' ); // include include_once('fields/class-NAMESPACE-acf-field-FIELD-NAME-v' . $version . '.php'); } } // initialize new NAMESPACE_acf_plugin_FIELD_NAME(); // class_exists check endif; ?> ================================================ FILE: acf-FIELD-NAME/assets/README.md ================================================ # assets directory Use this directory to store asset files such as CSS, JS and images. This directory can be removed if not used. ================================================ FILE: acf-FIELD-NAME/assets/css/README.md ================================================ # CSS directory Use this directory to store CSS files. This directory can be removed if not used. ================================================ FILE: acf-FIELD-NAME/assets/css/input.css ================================================ ================================================ FILE: acf-FIELD-NAME/assets/images/README.md ================================================ # Images directory Use this directory to store images. This directory can be removed if not used. ================================================ FILE: acf-FIELD-NAME/assets/js/README.md ================================================ # JS directory Use this directory to store JS files. This directory can be removed if not used. ================================================ FILE: acf-FIELD-NAME/assets/js/input.js ================================================ (function($){ /** * initialize_field * * This function will initialize the $field. * * @date 30/11/17 * @since 5.6.5 * * @param n/a * @return n/a */ function initialize_field( $field ) { //$field.doStuff(); } if( typeof acf.add_action !== 'undefined' ) { /* * ready & append (ACF5) * * These two events are called when a field element is ready for initizliation. * - ready: on page load similar to $(document).ready() * - append: on new DOM elements appended via repeater field or other AJAX calls * * @param n/a * @return n/a */ acf.add_action('ready_field/type=FIELD_NAME', initialize_field); acf.add_action('append_field/type=FIELD_NAME', initialize_field); } else { /* * acf/setup_fields (ACF4) * * These single event is called when a field element is ready for initizliation. * * @param event an event object. This can be ignored * @param element An element which contains the new HTML * @return n/a */ $(document).on('acf/setup_fields', function(e, postbox){ // find all relevant fields $(postbox).find('.field[data-field_type="FIELD_NAME"]').each(function(){ // initialize initialize_field( $(this) ); }); }); } })(jQuery); ================================================ FILE: acf-FIELD-NAME/fields/class-NAMESPACE-acf-field-FIELD-NAME-v4.php ================================================ name = 'FIELD_NAME'; $this->label = __('FIELD_LABEL'); $this->category = __("Basic",'TEXTDOMAIN'); // Basic, Content, Choice, etc $this->defaults = array( // add default here to merge into your field. // This makes life easy when creating the field options as you don't need to use any if( isset('') ) logic. eg: //'preview_size' => 'thumbnail' ); // do not delete! parent::__construct(); // settings $this->settings = $settings; } /* * create_options() * * Create extra options for your field. This is rendered when editing a field. * The value of $field['name'] can be used (like below) to save extra data to the $field * * @type action * @since 3.6 * @date 23/01/13 * * @param $field - an array holding all the field's data */ function create_options( $field ) { // defaults? /* $field = array_merge($this->defaults, $field); */ // key is needed in the field names to correctly save the data $key = $field['name']; // Create Field Options HTML ?>
'; print_r( $field ); echo ''; /* * Create a simple text input using the 'font_size' setting. */ ?> settings['url']; $version = $this->settings['version']; // register & include JS wp_register_script('TEXTDOMAIN', "{$url}assets/js/input.js", array('acf-input'), $version); wp_enqueue_script('TEXTDOMAIN'); // register & include CSS wp_register_style('TEXTDOMAIN', "{$url}assets/css/input.css", array('acf-input'), $version); wp_enqueue_style('TEXTDOMAIN'); } */ /* * input_admin_head() * * This action is called in the admin_head action on the edit screen where your field is created. * Use this action to add CSS and JavaScript to assist your render_field() action. * * @type action (admin_head) * @since 3.6 * @date 23/01/13 * * @param n/a * @return n/a */ /* function input_admin_head() { } */ /* * input_form_data() * * This function is called once on the 'input' page between the head and footer * There are 2 situations where ACF did not load during the 'acf/input_admin_enqueue_scripts' and * 'acf/input_admin_head' actions because ACF did not know it was going to be used. These situations are * seen on comments / user edit forms on the front end. This function will always be called, and includes * $args that related to the current screen such as $args['post_id'] * * @type function * @date 6/03/2014 * @since 5.0.0 * * @param $args (array) * @return n/a */ /* function input_form_data( $args ) { } */ /* * input_admin_footer() * * This action is called in the admin_footer action on the edit screen where your field is created. * Use this action to add CSS and JavaScript to assist your render_field() action. * * @type action (admin_footer) * @since 3.6 * @date 23/01/13 * * @param n/a * @return n/a */ /* function input_admin_footer() { } */ /* * field_group_admin_enqueue_scripts() * * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited. * Use this action to add CSS + JavaScript to assist your render_field_options() action. * * @type action (admin_enqueue_scripts) * @since 3.6 * @date 23/01/13 * * @param n/a * @return n/a */ /* function field_group_admin_enqueue_scripts() { } */ /* * field_group_admin_head() * * This action is called in the admin_head action on the edit screen where your field is edited. * Use this action to add CSS and JavaScript to assist your render_field_options() action. * * @type action (admin_head) * @since 3.6 * @date 23/01/13 * * @param n/a * @return n/a */ /* function field_group_admin_head() { } */ /* * load_value() * * This filter is applied to the $value after it is loaded from the db * * @type filter * @since 3.6 * @date 23/01/13 * * @param $value (mixed) the value found in the database * @param $post_id (mixed) the $post_id from which the value was loaded * @param $field (array) the field array holding all the field options * @return $value */ /* function load_value( $value, $post_id, $field ) { return $value; } */ /* * update_value() * * This filter is applied to the $value before it is saved in the db * * @type filter * @since 3.6 * @date 23/01/13 * * @param $value (mixed) the value found in the database * @param $post_id (mixed) the $post_id from which the value was loaded * @param $field (array) the field array holding all the field options * @return $value */ /* function update_value( $value, $post_id, $field ) { return $value; } */ /* * format_value() * * This filter is appied to the $value after it is loaded from the db and before it is returned to the template * * @type filter * @since 3.6 * @date 23/01/13 * * @param $value (mixed) the value which was loaded from the database * @param $post_id (mixed) the $post_id from which the value was loaded * @param $field (array) the field array holding all the field options * * @return $value (mixed) the modified value */ /* function format_value( $value, $post_id, $field ) { // bail early if no value if( empty($value) ) { return $value; } // apply setting if( $field['font_size'] > 12 ) { // format the value // $value = 'something'; } // return return $value; } */ /* * validate_value() * * This filter is used to perform validation on the value prior to saving. * All values are validated regardless of the field's required setting. This allows you to validate and return * messages to the user if the value is not correct * * @type filter * @date 11/02/2014 * @since 5.0.0 * * @param $valid (boolean) validation status based on the value and the field's required setting * @param $value (mixed) the $_POST value * @param $field (array) the field array holding all the field options * @param $input (string) the corresponding input name for $_POST value * @return $valid */ /* function validate_value( $valid, $value, $field, $input ){ // Basic usage if( $value < $field['custom_minimum_setting'] ) { $valid = false; } // Advanced usage if( $value < $field['custom_minimum_setting'] ) { $valid = __('The value is too little!','TEXTDOMAIN'), } // return return $valid; } */ /* * delete_value() * * This action is fired after a value has been deleted from the db. * Please note that saving a blank value is treated as an update, not a delete * * @type action * @date 6/03/2014 * @since 5.0.0 * * @param $post_id (mixed) the $post_id from which the value was deleted * @param $key (string) the $meta_key which the value was deleted * @return n/a */ /* function delete_value( $post_id, $key ) { } */ /* * load_field() * * This filter is applied to the $field after it is loaded from the database * * @type filter * @date 23/01/2013 * @since 3.6.0 * * @param $field (array) the field array holding all the field options * @return $field */ /* function load_field( $field ) { return $field; } */ /* * update_field() * * This filter is applied to the $field before it is saved to the database * * @type filter * @date 23/01/2013 * @since 3.6.0 * * @param $field (array) the field array holding all the field options * @return $field */ /* function update_field( $field ) { return $field; } */ /* * delete_field() * * This action is fired after a field is deleted from the database * * @type action * @date 11/02/2014 * @since 5.0.0 * * @param $field (array) the field array holding all the field options * @return n/a */ /* function delete_field( $field ) { } */ } // initialize new NAMESPACE_acf_field_FIELD_NAME( $this->settings ); // class_exists check endif; ?> ================================================ FILE: acf-FIELD-NAME/lang/README.md ================================================ # Translations directory Use this directory to store .po and .mo files. This directory can be removed if not used. ================================================ FILE: acf-FIELD-NAME/readme.txt ================================================ === Advanced Custom Fields: FIELD_LABEL Field === Contributors: AUTHOR_NAME Tags: PLUGIN_TAGS Requires at least: 3.6.0 Tested up to: 4.9.0 Stable tag: trunk License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html SHORT_DESCRIPTION == Description == EXTENDED_DESCRIPTION = Compatibility = This ACF field type is compatible with: * ACF 5 * ACF 4 == Installation == 1. Copy the `acf-FIELD-NAME` folder into your `wp-content/plugins` folder 2. Activate the FIELD_LABEL plugin via the plugins admin page 3. Create a new field via ACF and select the FIELD_LABEL type 4. Read the description above for usage instructions == Changelog == = 1.0.0 = * Initial Release.