Added dependency plugins

This commit is contained in:
Moris Zen
2018-06-25 00:00:37 +02:00
parent 720a1c31a4
commit f069f6782f
698 changed files with 289637 additions and 1 deletions

View File

@@ -0,0 +1,167 @@
<?php
if( ! class_exists('acf_field__accordion') ) :
class acf_field__accordion extends acf_field {
/**
* initialize
*
* This function will setup the field type data
*
* @date 30/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'accordion';
$this->label = __("Accordion",'acf');
$this->category = 'layout';
$this->defaults = array(
'open' => 0,
'multi_expand' => 0,
'endpoint' => 0
);
}
/**
* render_field
*
* Create the HTML interface for your field
*
* @date 30/10/17
* @since 5.6.3
*
* @param array $field
* @return n/a
*/
function render_field( $field ) {
// vars
$atts = array(
'class' => 'acf-fields',
'data-open' => $field['open'],
'data-multi_expand' => $field['multi_expand'],
'data-endpoint' => $field['endpoint']
);
?>
<div <?php acf_esc_attr_e($atts); ?>></div>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) to save extra data to the $field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field_settings( $field ) {
/*
// message
$message = '';
$message .= '<p>' . __( 'Accordions help you organize fields into panels that open and close.', 'acf') . '</p>';
$message .= '<p>' . __( 'All fields following this accordion (or until another accordion is defined) will be grouped together.','acf') . '</p>';
// default_value
acf_render_field_setting( $field, array(
'label' => __('Instructions','acf'),
'instructions' => '',
'name' => 'notes',
'type' => 'message',
'message' => $message,
));
*/
// active
acf_render_field_setting( $field, array(
'label' => __('Open','acf'),
'instructions' => __('Display this accordion as open on page load.','acf'),
'name' => 'open',
'type' => 'true_false',
'ui' => 1,
));
// multi_expand
acf_render_field_setting( $field, array(
'label' => __('Multi-expand','acf'),
'instructions' => __('Allow this accordion to open without closing others.','acf'),
'name' => 'multi_expand',
'type' => 'true_false',
'ui' => 1,
));
// endpoint
acf_render_field_setting( $field, array(
'label' => __('Endpoint','acf'),
'instructions' => __('Define an endpoint for the previous accordion to stop. This accordion will not be visible.','acf'),
'name' => 'endpoint',
'type' => 'true_false',
'ui' => 1,
));
}
/*
* load_field()
*
* This filter is appied to the $field after it is loaded from the database
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $field - the field array holding all the field options
*
* @return $field - the field array holding all the field options
*/
function load_field( $field ) {
// remove name to avoid caching issue
$field['name'] = '';
// remove required to avoid JS issues
$field['required'] = 0;
// set value other than 'null' to avoid ACF loading / caching issue
$field['value'] = false;
// return
return $field;
}
}
// initialize
acf_register_field_type( 'acf_field__accordion' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,292 @@
<?php
if( ! class_exists('acf_field_button_group') ) :
class acf_field_button_group extends acf_field {
/**
* initialize()
*
* This function will setup the field type data
*
* @date 18/9/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'button_group';
$this->label = __("Button Group",'acf');
$this->category = 'choice';
$this->defaults = array(
'choices' => array(),
'default_value' => '',
'allow_null' => 0,
'return_format' => 'value',
'layout' => 'horizontal',
);
}
/**
* render_field()
*
* Creates the field's input HTML
*
* @date 18/9/17
* @since 5.6.3
*
* @param array $field The field settings array
* @return n/a
*/
function render_field( $field ) {
// vars
$html = '';
$selected = null;
$buttons = array();
$value = esc_attr( $field['value'] );
// bail ealrly if no choices
if( empty($field['choices']) ) return;
// buttons
foreach( $field['choices'] as $_value => $_label ) {
// checked
$checked = ( $value === esc_attr($_value) );
if( $checked ) $selected = true;
// append
$buttons[] = array(
'name' => $field['name'],
'value' => $_value,
'label' => $_label,
'checked' => $checked
);
}
// maybe select initial value
if( !$field['allow_null'] && $selected === null ) {
$buttons[0]['checked'] = true;
}
// div
$div = array( 'class' => 'acf-button-group' );
if( $field['layout'] == 'vertical' ) { $div['class'] .= ' -vertical'; }
if( $field['class'] ) { $div['class'] .= ' ' . $field['class']; }
if( $field['allow_null'] ) { $div['data-allow_null'] = 1; }
// hdden input
$html .= acf_get_hidden_input( array('name' => $field['name']) );
// open
$html .= '<div ' . acf_esc_attr($div) . '>';
// loop
foreach( $buttons as $button ) {
// checked
if( $button['checked'] ) {
$button['checked'] = 'checked';
} else {
unset($button['checked']);
}
// append
$html .= acf_get_radio_input( $button );
}
// close
$html .= '</div>';
// return
echo $html;
}
/**
* render_field_settings()
*
* Creates the field's settings HTML
*
* @date 18/9/17
* @since 5.6.3
*
* @param array $field The field settings array
* @return n/a
*/
function render_field_settings( $field ) {
// encode choices (convert from array)
$field['choices'] = acf_encode_choices($field['choices']);
// choices
acf_render_field_setting( $field, array(
'label' => __('Choices','acf'),
'instructions' => __('Enter each choice on a new line.','acf') . '<br /><br />' . __('For more control, you may specify both a value and label like this:','acf'). '<br /><br />' . __('red : Red','acf'),
'type' => 'textarea',
'name' => 'choices',
));
// allow_null
acf_render_field_setting( $field, array(
'label' => __('Allow Null?','acf'),
'instructions' => '',
'name' => 'allow_null',
'type' => 'true_false',
'ui' => 1,
));
// default_value
acf_render_field_setting( $field, array(
'label' => __('Default Value','acf'),
'instructions' => __('Appears when creating a new post','acf'),
'type' => 'text',
'name' => 'default_value',
));
// layout
acf_render_field_setting( $field, array(
'label' => __('Layout','acf'),
'instructions' => '',
'type' => 'radio',
'name' => 'layout',
'layout' => 'horizontal',
'choices' => array(
'horizontal' => __("Horizontal",'acf'),
'vertical' => __("Vertical",'acf'),
)
));
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Value','acf'),
'instructions' => __('Specify the returned value on front end','acf'),
'type' => 'radio',
'name' => 'return_format',
'layout' => 'horizontal',
'choices' => array(
'value' => __('Value','acf'),
'label' => __('Label','acf'),
'array' => __('Both (Array)','acf')
)
));
}
/*
* update_field()
*
* This filter is appied to the $field before it is saved to the database
*
* @date 18/9/17
* @since 5.6.3
*
* @param array $field The field array holding all the field options
* @return $field
*/
function update_field( $field ) {
return acf_get_field_type('radio')->update_field( $field );
}
/*
* load_value()
*
* This filter is appied to the $value after it is loaded from the db
*
* @date 18/9/17
* @since 5.6.3
*
* @param mixed $value The value found in the database
* @param mixed $post_id The post ID from which the value was loaded from
* @param array $field The field array holding all the field options
* @return $value
*/
function load_value( $value, $post_id, $field ) {
return acf_get_field_type('radio')->load_value( $value, $post_id, $field );
}
/*
* translate_field
*
* This function will translate field settings
*
* @date 18/9/17
* @since 5.6.3
*
* @param array $field The field array holding all the field options
* @return $field
*/
function translate_field( $field ) {
return acf_get_field_type('radio')->translate_field( $field );
}
/*
* format_value()
*
* This filter is appied to the $value after it is loaded from the db and before it is returned to the template
*
* @date 18/9/17
* @since 5.6.3
*
* @param mixed $value The value found in the database
* @param mixed $post_id The post ID from which the value was loaded from
* @param array $field The field array holding all the field options
* @return $value
*/
function format_value( $value, $post_id, $field ) {
return acf_get_field_type('radio')->format_value( $value, $post_id, $field );
}
}
// initialize
acf_register_field_type( 'acf_field_button_group' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,567 @@
<?php
if( ! class_exists('acf_field_checkbox') ) :
class acf_field_checkbox extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'checkbox';
$this->label = __("Checkbox",'acf');
$this->category = 'choice';
$this->defaults = array(
'layout' => 'vertical',
'choices' => array(),
'default_value' => '',
'allow_custom' => 0,
'save_custom' => 0,
'toggle' => 0,
'return_format' => 'value'
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field (array) the $field being rendered
*
* @type action
* @since 3.6
* @date 23/01/13
*
* @param $field (array) the $field being edited
* @return n/a
*/
function render_field( $field ) {
// reset vars
$this->_values = array();
$this->_all_checked = true;
// ensure array
$field['value'] = acf_get_array($field['value']);
$field['choices'] = acf_get_array($field['choices']);
// hiden input
acf_hidden_input( array('name' => $field['name']) );
// vars
$li = '';
$ul = array(
'class' => 'acf-checkbox-list',
);
// append to class
$ul['class'] .= ' ' . ($field['layout'] == 'horizontal' ? 'acf-hl' : 'acf-bl');
$ul['class'] .= ' ' . $field['class'];
// checkbox saves an array
$field['name'] .= '[]';
// choices
if( !empty($field['choices']) ) {
// choices
$li .= $this->render_field_choices( $field );
// toggle
if( $field['toggle'] ) {
$li = $this->render_field_toggle( $field ) . $li;
}
}
// custom
if( $field['allow_custom'] ) {
$li .= $this->render_field_custom( $field );
}
// return
echo '<ul ' . acf_esc_attr( $ul ) . '>' . "\n" . $li . '</ul>' . "\n";
}
/*
* render_field_choices
*
* description
*
* @type function
* @date 15/7/17
* @since 5.6.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function render_field_choices( $field ) {
// walk
return $this->walk( $field['choices'], $field );
}
/*
* render_field_toggle
*
* description
*
* @type function
* @date 15/7/17
* @since 5.6.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function render_field_toggle( $field ) {
// vars
$atts = array(
'type' => 'checkbox',
'class' => 'acf-checkbox-toggle',
'label' => __("Toggle All", 'acf')
);
// custom label
if( is_string($field['toggle']) ) {
$atts['label'] = $field['toggle'];
}
// checked
if( $this->_all_checked ) {
$atts['checked'] = 'checked';
}
// return
return '<li>' . acf_get_checkbox_input($atts) . '</li>' . "\n";
}
/*
* render_field_custom
*
* description
*
* @type function
* @date 15/7/17
* @since 5.6.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function render_field_custom( $field ) {
// vars
$html = '';
// loop
foreach( $field['value'] as $value ) {
// ignore if already eixsts
if( isset($field['choices'][ $value ]) ) continue;
// vars
$esc_value = esc_attr($value);
$text_input = array(
'name' => $field['name'],
'value' => $value,
);
// bail ealry if choice already exists
if( in_array( $esc_value, $this->_values ) ) continue;
// append
$html .= '<li><input class="acf-checkbox-custom" type="checkbox" checked="checked" />' . acf_get_text_input($text_input) . '</li>' . "\n";
}
// append button
$html .= '<li><a href="#" class="button acf-add-checkbox">' . esc_attr__('Add new choice', 'acf') . '</a></li>' . "\n";
// return
return $html;
}
function walk( $choices = array(), $args = array(), $depth = 0 ) {
// bail ealry if no choices
if( empty($choices) ) return '';
// defaults
$args = wp_parse_args($args, array(
'id' => '',
'type' => 'checkbox',
'name' => '',
'value' => array(),
'disabled' => array(),
));
// vars
$html = '';
// sanitize values for 'selected' matching
if( $depth == 0 ) {
$args['value'] = array_map('esc_attr', $args['value']);
$args['disabled'] = array_map('esc_attr', $args['disabled']);
}
// loop
foreach( $choices as $value => $label ) {
// open
$html .= '<li>';
// optgroup
if( is_array($label) ){
$html .= '<ul>' . "\n";
$html .= $this->walk( $label, $args, $depth+1 );
$html .= '</ul>';
// option
} else {
// vars
$esc_value = esc_attr($value);
$atts = array(
'id' => $args['id'] . '-' . str_replace(' ', '-', $value),
'type' => $args['type'],
'name' => $args['name'],
'value' => $value,
'label' => $label,
);
// selected
if( in_array( $esc_value, $args['value'] ) ) {
$atts['checked'] = 'checked';
} else {
$this->_all_checked = false;
}
// disabled
if( in_array( $esc_value, $args['disabled'] ) ) {
$atts['disabled'] = 'disabled';
}
// store value added
$this->_values[] = $esc_value;
// append
$html .= acf_get_checkbox_input($atts);
}
// close
$html .= '</li>' . "\n";
}
// return
return $html;
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// encode choices (convert from array)
$field['choices'] = acf_encode_choices($field['choices']);
$field['default_value'] = acf_encode_choices($field['default_value'], false);
// choices
acf_render_field_setting( $field, array(
'label' => __('Choices','acf'),
'instructions' => __('Enter each choice on a new line.','acf') . '<br /><br />' . __('For more control, you may specify both a value and label like this:','acf'). '<br /><br />' . __('red : Red','acf'),
'type' => 'textarea',
'name' => 'choices',
));
// other_choice
acf_render_field_setting( $field, array(
'label' => __('Allow Custom','acf'),
'instructions' => '',
'name' => 'allow_custom',
'type' => 'true_false',
'ui' => 1,
'message' => __("Allow 'custom' values to be added", 'acf'),
));
// save_other_choice
acf_render_field_setting( $field, array(
'label' => __('Save Custom','acf'),
'instructions' => '',
'name' => 'save_custom',
'type' => 'true_false',
'ui' => 1,
'message' => __("Save 'custom' values to the field's choices", 'acf')
));
// default_value
acf_render_field_setting( $field, array(
'label' => __('Default Value','acf'),
'instructions' => __('Enter each default value on a new line','acf'),
'type' => 'textarea',
'name' => 'default_value',
));
// layout
acf_render_field_setting( $field, array(
'label' => __('Layout','acf'),
'instructions' => '',
'type' => 'radio',
'name' => 'layout',
'layout' => 'horizontal',
'choices' => array(
'vertical' => __("Vertical",'acf'),
'horizontal' => __("Horizontal",'acf')
)
));
// layout
acf_render_field_setting( $field, array(
'label' => __('Toggle','acf'),
'instructions' => __('Prepend an extra checkbox to toggle all choices','acf'),
'name' => 'toggle',
'type' => 'true_false',
'ui' => 1,
));
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Value','acf'),
'instructions' => __('Specify the returned value on front end','acf'),
'type' => 'radio',
'name' => 'return_format',
'layout' => 'horizontal',
'choices' => array(
'value' => __('Value','acf'),
'label' => __('Label','acf'),
'array' => __('Both (Array)','acf')
)
));
}
/*
* update_field()
*
* This filter is appied to the $field before it is saved to the database
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $field - the field array holding all the field options
* @param $post_id - the field group ID (post_type = acf)
*
* @return $field - the modified field
*/
function update_field( $field ) {
return acf_get_field_type('select')->update_field( $field );
}
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
// bail early if is empty
if( empty($value) ) return $value;
// select -> update_value()
$value = acf_get_field_type('select')->update_value( $value, $post_id, $field );
// save_other_choice
if( $field['save_custom'] ) {
// get raw $field (may have been changed via repeater field)
// if field is local, it won't have an ID
$selector = $field['ID'] ? $field['ID'] : $field['key'];
$field = acf_get_field( $selector, true );
// bail early if no ID (JSON only)
if( !$field['ID'] ) return $value;
// loop
foreach( $value as $v ) {
// ignore if already eixsts
if( isset($field['choices'][ $v ]) ) continue;
// unslash (fixes serialize single quote issue)
$v = wp_unslash($v);
// sanitize (remove tags)
$v = sanitize_text_field($v);
// append
$field['choices'][ $v ] = $v;
}
// save
acf_update_field( $field );
}
// return
return $value;
}
/*
* translate_field
*
* This function will translate field settings
*
* @type function
* @date 8/03/2016
* @since 5.3.2
*
* @param $field (array)
* @return $field
*/
function translate_field( $field ) {
return acf_get_field_type('select')->translate_field( $field );
}
/*
* 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 ) {
return acf_get_field_type('select')->format_value( $value, $post_id, $field );
}
}
// initialize
acf_register_field_type( 'acf_field_checkbox' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,148 @@
<?php
if( ! class_exists('acf_field_color_picker') ) :
class acf_field_color_picker extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'color_picker';
$this->label = __("Color Picker",'acf');
$this->category = 'jquery';
$this->defaults = array(
'default_value' => '',
);
}
/*
* input_admin_enqueue_scripts
*
* description
*
* @type function
* @date 16/12/2015
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_enqueue_scripts() {
// globals
global $wp_scripts;
// register if not already (on front end)
// http://wordpress.stackexchange.com/questions/82718/how-do-i-implement-the-wordpress-iris-picker-into-my-plugin-on-the-front-end
if( !isset($wp_scripts->registered['iris']) ) {
// styles
wp_register_style('wp-color-picker', admin_url('css/color-picker.css'), array(), '', true);
// scripts
wp_register_script('iris', admin_url('js/iris.min.js'), array('jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch'), '1.0.7', true);
wp_register_script('wp-color-picker', admin_url('js/color-picker.min.js'), array('iris'), '', true);
// localize
wp_localize_script('wp-color-picker', 'wpColorPickerL10n', array(
'clear' => __('Clear', 'acf' ),
'defaultString' => __('Default', 'acf' ),
'pick' => __('Select Color', 'acf' ),
'current' => __('Current Color', 'acf' )
));
}
// enqueue
wp_enqueue_style('wp-color-picker');
wp_enqueue_script('wp-color-picker');
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// vars
$text_input = acf_get_sub_array( $field, array('id', 'class', 'name', 'value') );
$hidden_input = acf_get_sub_array( $field, array('name', 'value') );
// html
?>
<div class="acf-color-picker">
<?php acf_hidden_input( $hidden_input ); ?>
<?php acf_text_input( $text_input ); ?>
</div>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// display_format
acf_render_field_setting( $field, array(
'label' => __('Default Value','acf'),
'instructions' => '',
'type' => 'text',
'name' => 'default_value',
'placeholder' => '#FFFFFF'
));
}
}
// initialize
acf_register_field_type( 'acf_field_color_picker' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,305 @@
<?php
if( ! class_exists('acf_field_date_picker') ) :
class acf_field_date_picker extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'date_picker';
$this->label = __("Date Picker",'acf');
$this->category = 'jquery';
$this->defaults = array(
'display_format' => 'd/m/Y',
'return_format' => 'd/m/Y',
'first_day' => 1
);
$this->l10n = array(
'closeText' => _x('Done', 'Date Picker JS closeText', 'acf'),
'currentText' => _x('Today', 'Date Picker JS currentText', 'acf'),
'nextText' => _x('Next', 'Date Picker JS nextText', 'acf'),
'prevText' => _x('Prev', 'Date Picker JS prevText', 'acf'),
'weekHeader' => _x('Wk', 'Date Picker JS weekHeader', 'acf'),
);
// actions
add_action('init', array($this, 'init'));
}
/*
* init
*
* This function is run on the 'init' action to set the field's $l10n data. Before the init action,
* access to the $wp_locale variable is not possible.
*
* @type action (init)
* @date 3/09/13
*
* @param n/a
* @return n/a
*/
function init() {
// globals
global $wp_locale;
// append
$this->l10n = array_merge($this->l10n, array(
'monthNames' => array_values( $wp_locale->month ),
'monthNamesShort' => array_values( $wp_locale->month_abbrev ),
'dayNames' => array_values( $wp_locale->weekday ),
'dayNamesMin' => array_values( $wp_locale->weekday_initial ),
'dayNamesShort' => array_values( $wp_locale->weekday_abbrev )
));
}
/*
* input_admin_enqueue_scripts
*
* description
*
* @type function
* @date 16/12/2015
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_enqueue_scripts() {
// bail ealry if no enqueue
if( !acf_get_setting('enqueue_datepicker') ) return;
// script
wp_enqueue_script('jquery-ui-datepicker');
// style
wp_enqueue_style('acf-datepicker', acf_get_dir('assets/inc/datepicker/jquery-ui.min.css'), '', '1.11.4' );
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// format value
$hidden_value = '';
$display_value = '';
if( $field['value'] ) {
$hidden_value = acf_format_date( $field['value'], 'Ymd' );
$display_value = acf_format_date( $field['value'], $field['display_format'] );
}
// vars
$div = array(
'class' => 'acf-date-picker acf-input-wrap',
'data-date_format' => acf_convert_date_to_js($field['display_format']),
'data-first_day' => $field['first_day'],
);
$hidden_input = array(
'id' => $field['id'],
'class' => 'input-alt',
'name' => $field['name'],
'value' => $hidden_value,
);
$text_input = array(
'class' => 'input',
'value' => $display_value,
);
// save_format - compatibility with ACF < 5.0.0
if( !empty($field['save_format']) ) {
// add custom JS save format
$div['data-save_format'] = $field['save_format'];
// revert hidden input value to raw DB value
$hidden_input['value'] = $field['value'];
// remove formatted value (will do this via JS)
$text_input['value'] = '';
}
// html
?>
<div <?php acf_esc_attr_e( $div ); ?>>
<?php acf_hidden_input( $hidden_input ); ?>
<?php acf_text_input( $text_input ); ?>
</div>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// global
global $wp_locale;
// vars
$d_m_Y = date_i18n('d/m/Y');
$m_d_Y = date_i18n('m/d/Y');
$F_j_Y = date_i18n('F j, Y');
$Ymd = date_i18n('Ymd');
// display_format
acf_render_field_setting( $field, array(
'label' => __('Display Format','acf'),
'instructions' => __('The format displayed when editing a post','acf'),
'type' => 'radio',
'name' => 'display_format',
'other_choice' => 1,
'choices' => array(
'd/m/Y' => '<span>' . $d_m_Y . '</span><code>d/m/Y</code>',
'm/d/Y' => '<span>' . $m_d_Y . '</span><code>m/d/Y</code>',
'F j, Y' => '<span>' . $F_j_Y . '</span><code>F j, Y</code>',
'other' => '<span>' . __('Custom:','acf') . '</span>'
)
));
// save_format - compatibility with ACF < 5.0.0
if( !empty($field['save_format']) ) {
// save_format
acf_render_field_setting( $field, array(
'label' => __('Save Format','acf'),
'instructions' => __('The format used when saving a value','acf'),
'type' => 'text',
'name' => 'save_format',
//'readonly' => 1 // this setting was not readonly in v4
));
} else {
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Format','acf'),
'instructions' => __('The format returned via template functions','acf'),
'type' => 'radio',
'name' => 'return_format',
'other_choice' => 1,
'choices' => array(
'd/m/Y' => '<span>' . $d_m_Y . '</span><code>d/m/Y</code>',
'm/d/Y' => '<span>' . $m_d_Y . '</span><code>m/d/Y</code>',
'F j, Y' => '<span>' . $F_j_Y . '</span><code>F j, Y</code>',
'Ymd' => '<span>' . $Ymd . '</span><code>Ymd</code>',
'other' => '<span>' . __('Custom:','acf') . '</span>'
)
));
}
// first_day
acf_render_field_setting( $field, array(
'label' => __('Week Starts On','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'first_day',
'choices' => array_values( $wp_locale->weekday )
));
}
/*
* 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 ) {
// save_format - compatibility with ACF < 5.0.0
if( !empty($field['save_format']) ) {
return $value;
}
// return
return acf_format_date( $value, $field['return_format'] );
}
}
// initialize
acf_register_field_type( 'acf_field_date_picker' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,255 @@
<?php
if( ! class_exists('acf_field_date_and_time_picker') ) :
class acf_field_date_and_time_picker extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'date_time_picker';
$this->label = __("Date Time Picker",'acf');
$this->category = 'jquery';
$this->defaults = array(
'display_format' => 'd/m/Y g:i a',
'return_format' => 'd/m/Y g:i a',
'first_day' => 1
);
$this->l10n = array(
'timeOnlyTitle' => _x('Choose Time', 'Date Time Picker JS timeOnlyTitle', 'acf'),
'timeText' => _x('Time', 'Date Time Picker JS timeText', 'acf'),
'hourText' => _x('Hour', 'Date Time Picker JS hourText', 'acf'),
'minuteText' => _x('Minute', 'Date Time Picker JS minuteText', 'acf'),
'secondText' => _x('Second', 'Date Time Picker JS secondText', 'acf'),
'millisecText' => _x('Millisecond', 'Date Time Picker JS millisecText', 'acf'),
'microsecText' => _x('Microsecond', 'Date Time Picker JS microsecText', 'acf'),
'timezoneText' => _x('Time Zone', 'Date Time Picker JS timezoneText', 'acf'),
'currentText' => _x('Now', 'Date Time Picker JS currentText', 'acf'),
'closeText' => _x('Done', 'Date Time Picker JS closeText', 'acf'),
'selectText' => _x('Select', 'Date Time Picker JS selectText', 'acf'),
'amNames' => array(
_x('AM', 'Date Time Picker JS amText', 'acf'),
_x('A', 'Date Time Picker JS amTextShort', 'acf'),
),
'pmNames' => array(
_x('PM', 'Date Time Picker JS pmText', 'acf'),
_x('P', 'Date Time Picker JS pmTextShort', 'acf'),
)
);
}
/*
* input_admin_enqueue_scripts
*
* description
*
* @type function
* @date 16/12/2015
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_enqueue_scripts() {
// bail ealry if no enqueue
if( !acf_get_setting('enqueue_datetimepicker') ) return;
// vars
$version = '1.6.1';
// script
wp_enqueue_script('acf-timepicker', acf_get_dir('assets/inc/timepicker/jquery-ui-timepicker-addon.min.js'), array('jquery-ui-datepicker'), $version);
// style
wp_enqueue_style('acf-timepicker', acf_get_dir('assets/inc/timepicker/jquery-ui-timepicker-addon.min.css'), '', $version);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// format value
$hidden_value = '';
$display_value = '';
if( $field['value'] ) {
$hidden_value = acf_format_date( $field['value'], 'Y-m-d H:i:s' );
$display_value = acf_format_date( $field['value'], $field['display_format'] );
}
// convert display_format to date and time
// the letter 'm' is used for date and minute in JS, so this must be done here in PHP
$formats = acf_split_date_time($field['display_format']);
// vars
$div = array(
'class' => 'acf-date-time-picker acf-input-wrap',
'data-date_format' => acf_convert_date_to_js($formats['date']),
'data-time_format' => acf_convert_time_to_js($formats['time']),
'data-first_day' => $field['first_day'],
);
$hidden_input = array(
'id' => $field['id'],
'class' => 'input-alt',
'name' => $field['name'],
'value' => $hidden_value,
);
$text_input = array(
'class' => 'input',
'value' => $display_value,
);
// html
?>
<div <?php acf_esc_attr_e( $div ); ?>>
<?php acf_hidden_input( $hidden_input ); ?>
<?php acf_text_input( $text_input ); ?>
</div>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// global
global $wp_locale;
// vars
$d_m_Y = date_i18n('d/m/Y g:i a');
$m_d_Y = date_i18n('m/d/Y g:i a');
$F_j_Y = date_i18n('F j, Y g:i a');
$Ymd = date_i18n('Y-m-d H:i:s');
// display_format
acf_render_field_setting( $field, array(
'label' => __('Display Format','acf'),
'instructions' => __('The format displayed when editing a post','acf'),
'type' => 'radio',
'name' => 'display_format',
'other_choice' => 1,
'choices' => array(
'd/m/Y g:i a' => '<span>' . $d_m_Y . '</span><code>d/m/Y g:i a</code>',
'm/d/Y g:i a' => '<span>' . $m_d_Y . '</span><code>m/d/Y g:i a</code>',
'F j, Y g:i a' => '<span>' . $F_j_Y . '</span><code>F j, Y g:i a</code>',
'Y-m-d H:i:s' => '<span>' . $Ymd . '</span><code>Y-m-d H:i:s</code>',
'other' => '<span>' . __('Custom:','acf') . '</span>'
)
));
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Format','acf'),
'instructions' => __('The format returned via template functions','acf'),
'type' => 'radio',
'name' => 'return_format',
'other_choice' => 1,
'choices' => array(
'd/m/Y g:i a' => '<span>' . $d_m_Y . '</span><code>d/m/Y g:i a</code>',
'm/d/Y g:i a' => '<span>' . $m_d_Y . '</span><code>m/d/Y g:i a</code>',
'F j, Y g:i a' => '<span>' . $F_j_Y . '</span><code>F j, Y g:i a</code>',
'Y-m-d H:i:s' => '<span>' . $Ymd . '</span><code>Y-m-d H:i:s</code>',
'other' => '<span>' . __('Custom:','acf') . '</span>'
)
));
// first_day
acf_render_field_setting( $field, array(
'label' => __('Week Starts On','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'first_day',
'choices' => array_values( $wp_locale->weekday )
));
}
/*
* 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 ) {
return acf_format_date( $value, $field['return_format'] );
}
}
// initialize
acf_register_field_type( 'acf_field_date_and_time_picker' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,161 @@
<?php
if( ! class_exists('acf_field_email') ) :
class acf_field_email extends acf_field {
/*
* initialize
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'email';
$this->label = __("Email",'acf');
$this->defaults = array(
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => ''
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// vars
$atts = array();
$keys = array( 'type', 'id', 'class', 'name', 'value', 'placeholder', 'pattern' );
$keys2 = array( 'readonly', 'disabled', 'required' );
$html = '';
// prepend
if( $field['prepend'] !== '' ) {
$field['class'] .= ' acf-is-prepended';
$html .= '<div class="acf-input-prepend">' . acf_esc_html($field['prepend']) . '</div>';
}
// append
if( $field['append'] !== '' ) {
$field['class'] .= ' acf-is-appended';
$html .= '<div class="acf-input-append">' . acf_esc_html($field['append']) . '</div>';
}
// atts (value="123")
foreach( $keys as $k ) {
if( isset($field[ $k ]) ) $atts[ $k ] = $field[ $k ];
}
// atts2 (disabled="disabled")
foreach( $keys2 as $k ) {
if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
}
// remove empty atts
$atts = acf_clean_atts( $atts );
// render
$html .= '<div class="acf-input-wrap">' . acf_get_text_input( $atts ) . '</div>';
// return
echo $html;
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// default_value
acf_render_field_setting( $field, array(
'label' => __('Default Value','acf'),
'instructions' => __('Appears when creating a new post','acf'),
'type' => 'text',
'name' => 'default_value',
));
// placeholder
acf_render_field_setting( $field, array(
'label' => __('Placeholder Text','acf'),
'instructions' => __('Appears within the input','acf'),
'type' => 'text',
'name' => 'placeholder',
));
// prepend
acf_render_field_setting( $field, array(
'label' => __('Prepend','acf'),
'instructions' => __('Appears before the input','acf'),
'type' => 'text',
'name' => 'prepend',
));
// append
acf_render_field_setting( $field, array(
'label' => __('Append','acf'),
'instructions' => __('Appears after the input','acf'),
'type' => 'text',
'name' => 'append',
));
}
}
// initialize
acf_register_field_type( 'acf_field_email' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,445 @@
<?php
if( ! class_exists('acf_field_file') ) :
class acf_field_file extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'file';
$this->label = __("File",'acf');
$this->category = 'content';
$this->defaults = array(
'return_format' => 'array',
'library' => 'all',
'min_size' => 0,
'max_size' => 0,
'mime_types' => ''
);
$this->l10n = array(
'select' => __("Select File",'acf'),
'edit' => __("Edit File",'acf'),
'update' => __("Update File",'acf'),
'uploadedTo' => __("Uploaded to this post",'acf'),
);
// filters
add_filter('get_media_item_args', array($this, 'get_media_item_args'));
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// vars
$uploader = acf_get_setting('uploader');
// allow custom uploader
$uploader = acf_maybe_get($field, 'uploader', $uploader);
// enqueue
if( $uploader == 'wp' ) {
acf_enqueue_uploader();
}
// vars
$o = array(
'icon' => '',
'title' => '',
'url' => '',
'filesize' => '',
'filename' => '',
);
$div = array(
'class' => 'acf-file-uploader',
'data-library' => $field['library'],
'data-mime_types' => $field['mime_types'],
'data-uploader' => $uploader
);
// has value?
if( $field['value'] ) {
$file = get_post( $field['value'] );
if( $file ) {
$o['icon'] = wp_mime_type_icon( $file->ID );
$o['title'] = $file->post_title;
$o['filesize'] = @size_format(filesize( get_attached_file( $file->ID ) ));
$o['url'] = wp_get_attachment_url( $file->ID );
$explode = explode('/', $o['url']);
$o['filename'] = end( $explode );
}
// url exists
if( $o['url'] ) {
$div['class'] .= ' has-value';
}
}
?>
<div <?php acf_esc_attr_e( $div ); ?>>
<?php acf_hidden_input(array( 'name' => $field['name'], 'value' => $field['value'], 'data-name' => 'id' )); ?>
<div class="show-if-value file-wrap">
<div class="file-icon">
<img data-name="icon" src="<?php echo esc_url($o['icon']); ?>" alt=""/>
</div>
<div class="file-info">
<p>
<strong data-name="title"><?php echo esc_html($o['title']); ?></strong>
</p>
<p>
<strong><?php _e('File name', 'acf'); ?>:</strong>
<a data-name="filename" href="<?php echo esc_url($o['url']); ?>" target="_blank"><?php echo esc_html($o['filename']); ?></a>
</p>
<p>
<strong><?php _e('File size', 'acf'); ?>:</strong>
<span data-name="filesize"><?php echo esc_html($o['filesize']); ?></span>
</p>
</div>
<div class="acf-actions -hover">
<?php
if( $uploader != 'basic' ):
?><a class="acf-icon -pencil dark" data-name="edit" href="#" title="<?php _e('Edit', 'acf'); ?>"></a><?php
endif;
?><a class="acf-icon -cancel dark" data-name="remove" href="#" title="<?php _e('Remove', 'acf'); ?>"></a>
</div>
</div>
<div class="hide-if-value">
<?php if( $uploader == 'basic' ): ?>
<?php if( $field['value'] && !is_numeric($field['value']) ): ?>
<div class="acf-error-message"><p><?php echo acf_esc_html($field['value']); ?></p></div>
<?php endif; ?>
<label class="acf-basic-uploader">
<?php acf_file_input(array( 'name' => $field['name'], 'id' => $field['id'] )); ?>
</label>
<?php else: ?>
<p><?php _e('No file selected','acf'); ?> <a data-name="add" class="acf-button button" href="#"><?php _e('Add File','acf'); ?></a></p>
<?php endif; ?>
</div>
</div>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// clear numeric settings
$clear = array(
'min_size',
'max_size'
);
foreach( $clear as $k ) {
if( empty($field[$k]) ) {
$field[$k] = '';
}
}
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Value','acf'),
'instructions' => __('Specify the returned value on front end','acf'),
'type' => 'radio',
'name' => 'return_format',
'layout' => 'horizontal',
'choices' => array(
'array' => __("File Array",'acf'),
'url' => __("File URL",'acf'),
'id' => __("File ID",'acf')
)
));
// library
acf_render_field_setting( $field, array(
'label' => __('Library','acf'),
'instructions' => __('Limit the media library choice','acf'),
'type' => 'radio',
'name' => 'library',
'layout' => 'horizontal',
'choices' => array(
'all' => __('All', 'acf'),
'uploadedTo' => __('Uploaded to post', 'acf')
)
));
// min
acf_render_field_setting( $field, array(
'label' => __('Minimum','acf'),
'instructions' => __('Restrict which files can be uploaded','acf'),
'type' => 'text',
'name' => 'min_size',
'prepend' => __('File size', 'acf'),
'append' => 'MB',
));
// max
acf_render_field_setting( $field, array(
'label' => __('Maximum','acf'),
'instructions' => __('Restrict which files can be uploaded','acf'),
'type' => 'text',
'name' => 'max_size',
'prepend' => __('File size', 'acf'),
'append' => 'MB',
));
// allowed type
acf_render_field_setting( $field, array(
'label' => __('Allowed file types','acf'),
'instructions' => __('Comma separated list. Leave blank for all types','acf'),
'type' => 'text',
'name' => 'mime_types',
));
}
/*
* 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 false;
// bail early if not numeric (error message)
if( !is_numeric($value) ) return false;
// convert to int
$value = intval($value);
// format
if( $field['return_format'] == 'url' ) {
return wp_get_attachment_url($value);
} elseif( $field['return_format'] == 'array' ) {
return acf_get_attachment( $value );
}
// return
return $value;
}
/*
* get_media_item_args
*
* description
*
* @type function
* @date 27/01/13
* @since 3.6.0
*
* @param $vars (array)
* @return $vars
*/
function get_media_item_args( $vars ) {
$vars['send'] = true;
return($vars);
}
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
// bail early if is empty
if( empty($value) ) return false;
// validate
if( is_array($value) && isset($value['ID']) ) {
$value = $value['ID'];
} elseif( is_object($value) && isset($value->ID) ) {
$value = $value->ID;
}
// bail early if not attachment ID
if( !$value || !is_numeric($value) ) return false;
// confirm type
$value = (int) $value;
// maybe connect attacment to post
acf_connect_attachment_to_post( $value, $post_id );
// return
return $value;
}
/*
* validate_value
*
* This function will validate a basic file input
*
* @type function
* @date 11/02/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function validate_value( $valid, $value, $field, $input ){
// bail early if empty
if( empty($value) ) return $valid;
// bail ealry if is numeric
if( is_numeric($value) ) return $valid;
// bail ealry if not basic string
if( !is_string($value) ) return $valid;
// decode value
$file = null;
parse_str($value, $file);
// bail early if no attachment
if( empty($file) ) return $valid;
// get errors
$errors = acf_validate_attachment( $file, $field, 'basic_upload' );
// append error
if( !empty($errors) ) {
$valid = implode("\n", $errors);
}
// return
return $valid;
}
}
// initialize
acf_register_field_type( 'acf_field_file' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,314 @@
<?php
if( ! class_exists('acf_field_google_map') ) :
class acf_field_google_map extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'google_map';
$this->label = __("Google Map",'acf');
$this->category = 'jquery';
$this->defaults = array(
'height' => '',
'center_lat' => '',
'center_lng' => '',
'zoom' => ''
);
$this->default_values = array(
'height' => '400',
'center_lat' => '-37.81411',
'center_lng' => '144.96328',
'zoom' => '14'
);
$this->l10n = array(
'locating' => __("Locating",'acf'),
'browser_support' => __("Sorry, this browser does not support geolocation",'acf'),
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// validate value
if( empty($field['value']) ) {
$field['value'] = array();
}
// value
$field['value'] = wp_parse_args($field['value'], array(
'address' => '',
'lat' => '',
'lng' => ''
));
// default options
foreach( $this->default_values as $k => $v ) {
if( empty($field[ $k ]) ) {
$field[ $k ] = $v;
}
}
// vars
$atts = array(
'id' => $field['id'],
'class' => "acf-google-map {$field['class']}",
'data-lat' => $field['center_lat'],
'data-lng' => $field['center_lng'],
'data-zoom' => $field['zoom'],
);
// has value
if( $field['value']['address'] ) {
$atts['class'] .= ' -value';
}
?>
<div <?php acf_esc_attr_e($atts); ?>>
<div class="acf-hidden">
<?php foreach( $field['value'] as $k => $v ):
acf_hidden_input(array( 'name' => $field['name'].'['.$k.']', 'value' => $v, 'class' => 'input-'.$k ));
endforeach; ?>
</div>
<div class="title">
<div class="acf-actions -hover">
<a href="#" data-name="search" class="acf-icon -search grey" title="<?php _e("Search", 'acf'); ?>"></a><?php
?><a href="#" data-name="clear" class="acf-icon -cancel grey" title="<?php _e("Clear location", 'acf'); ?>"></a><?php
?><a href="#" data-name="locate" class="acf-icon -location grey" title="<?php _e("Find current location", 'acf'); ?>"></a>
</div>
<input class="search" type="text" placeholder="<?php _e("Search for address...",'acf'); ?>" value="<?php echo esc_attr($field['value']['address']); ?>" />
<i class="acf-loading"></i>
</div>
<div class="canvas" style="<?php echo esc_attr('height: '.$field['height'].'px'); ?>"></div>
</div>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// center_lat
acf_render_field_setting( $field, array(
'label' => __('Center','acf'),
'instructions' => __('Center the initial map','acf'),
'type' => 'text',
'name' => 'center_lat',
'prepend' => 'lat',
'placeholder' => $this->default_values['center_lat']
));
// center_lng
acf_render_field_setting( $field, array(
'label' => __('Center','acf'),
'instructions' => __('Center the initial map','acf'),
'type' => 'text',
'name' => 'center_lng',
'prepend' => 'lng',
'placeholder' => $this->default_values['center_lng'],
'_append' => 'center_lat'
));
// zoom
acf_render_field_setting( $field, array(
'label' => __('Zoom','acf'),
'instructions' => __('Set the initial zoom level','acf'),
'type' => 'text',
'name' => 'zoom',
'placeholder' => $this->default_values['zoom']
));
// allow_null
acf_render_field_setting( $field, array(
'label' => __('Height','acf'),
'instructions' => __('Customise the map height','acf'),
'type' => 'text',
'name' => 'height',
'append' => 'px',
'placeholder' => $this->default_values['height']
));
}
/*
* validate_value
*
* description
*
* @type function
* @date 11/02/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function validate_value( $valid, $value, $field, $input ){
// bail early if not required
if( ! $field['required'] ) {
return $valid;
}
if( empty($value) || empty($value['lat']) || empty($value['lng']) ) {
return false;
}
// return
return $valid;
}
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
if( empty($value) || empty($value['lat']) || empty($value['lng']) ) {
return false;
}
// return
return $value;
}
/*
* input_admin_footer
*
* description
*
* @type function
* @date 6/03/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_footer() {
// bail ealry if no qneueu
if( !acf_get_setting('enqueue_google_maps') ) return;
// vars
$api = array(
'key' => acf_get_setting('google_api_key'),
'client' => acf_get_setting('google_api_client'),
'libraries' => 'places',
'ver' => 3,
'callback' => ''
);
// filter
$api = apply_filters('acf/fields/google_map/api', $api);
// remove empty
if( empty($api['key']) ) unset($api['key']);
if( empty($api['client']) ) unset($api['client']);
// construct url
$url = add_query_arg($api, 'https://maps.googleapis.com/maps/api/js');
?>
<script type="text/javascript">
if( acf ) acf.fields.google_map.url = '<?php echo $url; ?>';
</script>
<?php
}
}
// initialize
acf_register_field_type( 'acf_field_google_map' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,656 @@
<?php
if( ! class_exists('acf_field__group') ) :
class acf_field__group extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'group';
$this->label = __("Group",'acf');
$this->category = 'layout';
$this->defaults = array(
'sub_fields' => array(),
'layout' => 'block'
);
$this->have_rows = 'single';
// field filters
$this->add_field_filter('acf/prepare_field_for_export', array($this, 'prepare_field_for_export'));
$this->add_field_filter('acf/prepare_field_for_import', array($this, 'prepare_field_for_import'));
}
/*
* load_field()
*
* This filter is appied to the $field after it is loaded from the database
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $field - the field array holding all the field options
*
* @return $field - the field array holding all the field options
*/
function load_field( $field ) {
// vars
$sub_fields = acf_get_fields( $field );
// append
if( $sub_fields ) {
$field['sub_fields'] = $sub_fields;
}
// return
return $field;
}
/*
* 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 ) {
// bail early if no sub fields
if( empty($field['sub_fields']) ) return $value;
// modify names
$field = $this->prepare_field_for_db( $field );
// load sub fields
$value = array();
// loop
foreach( $field['sub_fields'] as $sub_field ) {
// load
$value[ $sub_field['key'] ] = acf_get_value( $post_id, $sub_field );
}
// return
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 false;
// modify names
$field = $this->prepare_field_for_db( $field );
// loop
foreach( $field['sub_fields'] as $sub_field ) {
// extract value
$sub_value = acf_extract_var( $value, $sub_field['key'] );
// format value
$sub_value = acf_format_value( $sub_value, $post_id, $sub_field );
// append to $row
$value[ $sub_field['_name'] ] = $sub_value;
}
// return
return $value;
}
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which will be saved in the database
* @param $field - the field array holding all the field options
* @param $post_id - the $post_id of which the value will be saved
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
// bail early if no value
if( !acf_is_array($value) ) return null;
// bail ealry if no sub fields
if( empty($field['sub_fields']) ) return null;
// modify names
$field = $this->prepare_field_for_db( $field );
// loop
foreach( $field['sub_fields'] as $sub_field ) {
// vars
$v = false;
// key (backend)
if( isset($value[ $sub_field['key'] ]) ) {
$v = $value[ $sub_field['key'] ];
// name (frontend)
} elseif( isset($value[ $sub_field['_name'] ]) ) {
$v = $value[ $sub_field['_name'] ];
// empty
} else {
// input is not set (hidden by conditioanl logic)
continue;
}
// update value
acf_update_value( $v, $post_id, $sub_field );
}
// return
return '';
}
/*
* prepare_field_for_db
*
* This function will modify sub fields ready for update / load
*
* @type function
* @date 4/11/16
* @since 5.5.0
*
* @param $field (array)
* @return $field
*/
function prepare_field_for_db( $field ) {
// bail early if no sub fields
if( empty($field['sub_fields']) ) return $field;
// loop
foreach( $field['sub_fields'] as &$sub_field ) {
// prefix name
$sub_field['name'] = $field['name'] . '_' . $sub_field['_name'];
}
// return
return $field;
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// bail early if no sub fields
if( empty($field['sub_fields']) ) return;
// load values
foreach( $field['sub_fields'] as &$sub_field ) {
// add value
if( isset($field['value'][ $sub_field['key'] ]) ) {
// this is a normal value
$sub_field['value'] = $field['value'][ $sub_field['key'] ];
} elseif( isset($sub_field['default_value']) ) {
// no value, but this sub field has a default value
$sub_field['value'] = $sub_field['default_value'];
}
// update prefix to allow for nested values
$sub_field['prefix'] = $field['name'];
// restore required
if( $field['required'] ) $sub_field['required'] = 0;
}
// render
if( $field['layout'] == 'table' ) {
$this->render_field_table( $field );
} else {
$this->render_field_block( $field );
}
}
/*
* render_field_block
*
* description
*
* @type function
* @date 12/07/2016
* @since 5.4.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function render_field_block( $field ) {
// vars
$label_placement = ($field['layout'] == 'block') ? 'top' : 'left';
// html
echo '<div class="acf-fields -' . $label_placement . ' -border">';
foreach( $field['sub_fields'] as $sub_field ) {
acf_render_field_wrap( $sub_field );
}
echo '</div>';
}
/*
* render_field_table
*
* description
*
* @type function
* @date 12/07/2016
* @since 5.4.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function render_field_table( $field ) {
?>
<table class="acf-table">
<thead>
<tr>
<?php foreach( $field['sub_fields'] as $sub_field ):
// prepare field (allow sub fields to be removed)
$sub_field = acf_prepare_field($sub_field);
// bail ealry if no field
if( !$sub_field ) continue;
// vars
$atts = array();
$atts['class'] = 'acf-th';
$atts['data-name'] = $sub_field['_name'];
$atts['data-type'] = $sub_field['type'];
$atts['data-key'] = $sub_field['key'];
// Add custom width
if( $sub_field['wrapper']['width'] ) {
$atts['data-width'] = $sub_field['wrapper']['width'];
$atts['style'] = 'width: ' . $sub_field['wrapper']['width'] . '%;';
}
?>
<th <?php acf_esc_attr_e( $atts ); ?>>
<?php acf_render_field_label( $sub_field ); ?>
<?php acf_render_field_instructions( $sub_field ); ?>
</th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<tr class="acf-row">
<?php
foreach( $field['sub_fields'] as $sub_field ) {
acf_render_field_wrap( $sub_field, 'td' );
}
?>
</tr>
</tbody>
</table>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// vars
$args = array(
'fields' => $field['sub_fields'],
'parent' => $field['ID']
);
?><tr class="acf-field acf-field-setting-sub_fields" data-setting="group" data-name="sub_fields">
<td class="acf-label">
<label><?php _e("Sub Fields",'acf'); ?></label>
</td>
<td class="acf-input">
<?php
acf_get_view('field-group-fields', $args);
?>
</td>
</tr>
<?php
// layout
acf_render_field_setting( $field, array(
'label' => __('Layout','acf'),
'instructions' => __('Specify the style used to render the selected fields', 'acf'),
'type' => 'radio',
'name' => 'layout',
'layout' => 'horizontal',
'choices' => array(
'block' => __('Block','acf'),
'table' => __('Table','acf'),
'row' => __('Row','acf')
)
));
}
/*
* validate_value
*
* description
*
* @type function
* @date 11/02/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function validate_value( $valid, $value, $field, $input ){
// bail early if no $value
if( empty($value) ) return $valid;
// bail early if no sub fields
if( empty($field['sub_fields']) ) return $valid;
// loop
foreach( $field['sub_fields'] as $sub_field ) {
// get sub field
$k = $sub_field['key'];
// bail early if value not set (conditional logic?)
if( !isset($value[ $k ]) ) continue;
// required
if( $field['required'] ) {
$sub_field['required'] = 1;
}
// validate
acf_validate_value( $value[ $k ], $sub_field, "{$input}[{$k}]" );
}
// return
return $valid;
}
/*
* duplicate_field()
*
* This filter is appied to the $field before it is duplicated and saved to the database
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $field - the field array holding all the field options
*
* @return $field - the modified field
*/
function duplicate_field( $field ) {
// get sub fields
$sub_fields = acf_extract_var( $field, 'sub_fields' );
// save field to get ID
$field = acf_update_field( $field );
// duplicate sub fields
acf_duplicate_fields( $sub_fields, $field['ID'] );
// return
return $field;
}
/*
* prepare_field_for_export
*
* description
*
* @type function
* @date 11/03/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function prepare_field_for_export( $field ) {
// bail early if no sub fields
if( empty($field['sub_fields']) ) return $field;
// prepare
$field['sub_fields'] = acf_prepare_fields_for_export( $field['sub_fields'] );
// return
return $field;
}
/*
* prepare_field_for_import
*
* description
*
* @type function
* @date 11/03/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function prepare_field_for_import( $field ) {
// bail early if no sub fields
if( empty($field['sub_fields']) ) return $field;
// vars
$sub_fields = $field['sub_fields'];
// reset field setting
$field['sub_fields'] = array();
// loop
foreach( $sub_fields as &$sub_field ) {
$sub_field['parent'] = $field['key'];
}
// merge
array_unshift($sub_fields, $field);
// return
return $sub_fields;
}
}
// initialize
acf_register_field_type( 'acf_field__group' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,472 @@
<?php
if( ! class_exists('acf_field_image') ) :
class acf_field_image extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'image';
$this->label = __("Image",'acf');
$this->category = 'content';
$this->defaults = array(
'return_format' => 'array',
'preview_size' => 'thumbnail',
'library' => 'all',
'min_width' => 0,
'min_height' => 0,
'min_size' => 0,
'max_width' => 0,
'max_height' => 0,
'max_size' => 0,
'mime_types' => ''
);
$this->l10n = array(
'select' => __("Select Image",'acf'),
'edit' => __("Edit Image",'acf'),
'update' => __("Update Image",'acf'),
'uploadedTo' => __("Uploaded to this post",'acf'),
'all' => __("All images",'acf'),
);
// filters
add_filter('get_media_item_args', array($this, 'get_media_item_args'));
add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// vars
$uploader = acf_get_setting('uploader');
// enqueue
if( $uploader == 'wp' ) {
acf_enqueue_uploader();
}
// vars
$url = '';
$alt = '';
$div = array(
'class' => 'acf-image-uploader',
'data-preview_size' => $field['preview_size'],
'data-library' => $field['library'],
'data-mime_types' => $field['mime_types'],
'data-uploader' => $uploader
);
// has value?
if( $field['value'] ) {
// update vars
$url = wp_get_attachment_image_src($field['value'], $field['preview_size']);
$alt = get_post_meta($field['value'], '_wp_attachment_image_alt', true);
// url exists
if( $url ) $url = $url[0];
// url exists
if( $url ) {
$div['class'] .= ' has-value';
}
}
// get size of preview value
$size = acf_get_image_size($field['preview_size']);
?>
<div <?php acf_esc_attr_e( $div ); ?>>
<?php acf_hidden_input(array( 'name' => $field['name'], 'value' => $field['value'] )); ?>
<div class="show-if-value image-wrap" <?php if( $size['width'] ): ?>style="<?php echo esc_attr('max-width: '.$size['width'].'px'); ?>"<?php endif; ?>>
<img data-name="image" src="<?php echo esc_url($url); ?>" alt="<?php echo esc_attr($alt); ?>"/>
<div class="acf-actions -hover">
<?php
if( $uploader != 'basic' ):
?><a class="acf-icon -pencil dark" data-name="edit" href="#" title="<?php _e('Edit', 'acf'); ?>"></a><?php
endif;
?><a class="acf-icon -cancel dark" data-name="remove" href="#" title="<?php _e('Remove', 'acf'); ?>"></a>
</div>
</div>
<div class="hide-if-value">
<?php if( $uploader == 'basic' ): ?>
<?php if( $field['value'] && !is_numeric($field['value']) ): ?>
<div class="acf-error-message"><p><?php echo acf_esc_html($field['value']); ?></p></div>
<?php endif; ?>
<label class="acf-basic-uploader">
<?php acf_file_input(array( 'name' => $field['name'], 'id' => $field['id'] )); ?>
</label>
<?php else: ?>
<p><?php _e('No image selected','acf'); ?> <a data-name="add" class="acf-button button" href="#"><?php _e('Add Image','acf'); ?></a></p>
<?php endif; ?>
</div>
</div>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// clear numeric settings
$clear = array(
'min_width',
'min_height',
'min_size',
'max_width',
'max_height',
'max_size'
);
foreach( $clear as $k ) {
if( empty($field[$k]) ) {
$field[$k] = '';
}
}
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Value','acf'),
'instructions' => __('Specify the returned value on front end','acf'),
'type' => 'radio',
'name' => 'return_format',
'layout' => 'horizontal',
'choices' => array(
'array' => __("Image Array",'acf'),
'url' => __("Image URL",'acf'),
'id' => __("Image ID",'acf')
)
));
// preview_size
acf_render_field_setting( $field, array(
'label' => __('Preview Size','acf'),
'instructions' => __('Shown when entering data','acf'),
'type' => 'select',
'name' => 'preview_size',
'choices' => acf_get_image_sizes()
));
// library
acf_render_field_setting( $field, array(
'label' => __('Library','acf'),
'instructions' => __('Limit the media library choice','acf'),
'type' => 'radio',
'name' => 'library',
'layout' => 'horizontal',
'choices' => array(
'all' => __('All', 'acf'),
'uploadedTo' => __('Uploaded to post', 'acf')
)
));
// min
acf_render_field_setting( $field, array(
'label' => __('Minimum','acf'),
'instructions' => __('Restrict which images can be uploaded','acf'),
'type' => 'text',
'name' => 'min_width',
'prepend' => __('Width', 'acf'),
'append' => 'px',
));
acf_render_field_setting( $field, array(
'label' => '',
'type' => 'text',
'name' => 'min_height',
'prepend' => __('Height', 'acf'),
'append' => 'px',
'_append' => 'min_width'
));
acf_render_field_setting( $field, array(
'label' => '',
'type' => 'text',
'name' => 'min_size',
'prepend' => __('File size', 'acf'),
'append' => 'MB',
'_append' => 'min_width'
));
// max
acf_render_field_setting( $field, array(
'label' => __('Maximum','acf'),
'instructions' => __('Restrict which images can be uploaded','acf'),
'type' => 'text',
'name' => 'max_width',
'prepend' => __('Width', 'acf'),
'append' => 'px',
));
acf_render_field_setting( $field, array(
'label' => '',
'type' => 'text',
'name' => 'max_height',
'prepend' => __('Height', 'acf'),
'append' => 'px',
'_append' => 'max_width'
));
acf_render_field_setting( $field, array(
'label' => '',
'type' => 'text',
'name' => 'max_size',
'prepend' => __('File size', 'acf'),
'append' => 'MB',
'_append' => 'max_width'
));
// allowed type
acf_render_field_setting( $field, array(
'label' => __('Allowed file types','acf'),
'instructions' => __('Comma separated list. Leave blank for all types','acf'),
'type' => 'text',
'name' => 'mime_types',
));
}
/*
* 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 false;
// bail early if not numeric (error message)
if( !is_numeric($value) ) return false;
// convert to int
$value = intval($value);
// format
if( $field['return_format'] == 'url' ) {
return wp_get_attachment_url( $value );
} elseif( $field['return_format'] == 'array' ) {
return acf_get_attachment( $value );
}
// return
return $value;
}
/*
* get_media_item_args
*
* description
*
* @type function
* @date 27/01/13
* @since 3.6.0
*
* @param $vars (array)
* @return $vars
*/
function get_media_item_args( $vars ) {
$vars['send'] = true;
return($vars);
}
/*
* wp_prepare_attachment_for_js
*
* this filter allows ACF to add in extra data to an attachment JS object
* This sneaky hook adds the missing sizes to each attachment in the 3.5 uploader.
* It would be a lot easier to add all the sizes to the 'image_size_names_choose' filter but
* then it will show up on the normal the_content editor
*
* @type function
* @since: 3.5.7
* @date 13/01/13
*
* @param {int} $post_id
* @return {int} $post_id
*/
function wp_prepare_attachment_for_js( $response, $attachment, $meta ) {
// only for image
if( $response['type'] != 'image' ) {
return $response;
}
// make sure sizes exist. Perhaps they dont?
if( !isset($meta['sizes']) ) {
return $response;
}
$attachment_url = $response['url'];
$base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url );
if( isset($meta['sizes']) && is_array($meta['sizes']) ) {
foreach( $meta['sizes'] as $k => $v ) {
if( !isset($response['sizes'][ $k ]) ) {
$response['sizes'][ $k ] = array(
'height' => $v['height'],
'width' => $v['width'],
'url' => $base_url . $v['file'],
'orientation' => $v['height'] > $v['width'] ? 'portrait' : 'landscape',
);
}
}
}
return $response;
}
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
return acf_get_field_type('file')->update_value( $value, $post_id, $field );
}
/*
* validate_value
*
* This function will validate a basic file input
*
* @type function
* @date 11/02/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function validate_value( $valid, $value, $field, $input ){
return acf_get_field_type('file')->validate_value( $valid, $value, $field, $input );
}
}
// initialize
acf_register_field_type( 'acf_field_image' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,292 @@
<?php
if( ! class_exists('acf_field_link') ) :
class acf_field_link extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'link';
$this->label = __("Link",'acf');
$this->category = 'relational';
$this->defaults = array(
'return_format' => 'array',
);
}
/*
* get_link
*
* description
*
* @type function
* @date 16/5/17
* @since 5.5.13
*
* @param $post_id (int)
* @return $post_id (int)
*/
function get_link( $value = '' ) {
// vars
$link = array(
'title' => '',
'url' => '',
'target' => ''
);
// array (ACF 5.6.0)
if( is_array($value) ) {
$link = array_merge($link, $value);
// post id (ACF < 5.6.0)
} elseif( is_numeric($value) ) {
$link['title'] = get_the_title( $value );
$link['url'] = get_permalink( $value );
// string (ACF < 5.6.0)
} elseif( is_string($value) ) {
$link['url'] = $value;
}
// return
return $link;
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ){
// vars
$div = array(
'id' => $field['id'],
'class' => $field['class'] . ' acf-link',
);
// render scripts/styles
acf_enqueue_uploader();
// get link
$link = $this->get_link( $field['value'] );
// classes
if( $link['url'] ) {
$div['class'] .= ' -value';
}
if( $link['target'] === '_blank' ) {
$div['class'] .= ' -external';
}
/*<textarea id="<?php echo esc_attr($field['id']); ?>-textarea"><?php
echo esc_textarea('<a href="'.$link['url'].'" target="'.$link['target'].'">'.$link['title'].'</a>');
?></textarea>*/
?>
<div <?php acf_esc_attr_e($div); ?>>
<div class="acf-hidden">
<a class="link-node" href="<?php echo esc_url($link['url']); ?>" target="<?php echo esc_attr($link['target']); ?>"><?php echo esc_html($link['title']); ?></a>
<?php foreach( $link as $k => $v ): ?>
<?php acf_hidden_input(array( 'class' => "input-$k", 'name' => $field['name'] . "[$k]", 'value' => $v )); ?>
<?php endforeach; ?>
</div>
<a href="#" class="button" data-name="add" target=""><?php _e('Select Link', 'acf'); ?></a>
<div class="link-wrap">
<span class="link-title"><?php echo esc_html($link['title']); ?></span>
<a class="link-url" href="<?php echo esc_url($link['url']); ?>" target="_blank"><?php echo esc_html($link['url']); ?></a>
<i class="acf-icon -link-ext acf-js-tooltip" title="<?php _e('Opens in a new window/tab', 'acf'); ?>"></i><?php
?><a class="acf-icon -pencil -clear acf-js-tooltip" data-name="edit" href="#" title="<?php _e('Edit', 'acf'); ?>"></a><?php
?><a class="acf-icon -cancel -clear acf-js-tooltip" data-name="remove" href="#" title="<?php _e('Remove', 'acf'); ?>"></a>
</div>
</div>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Value','acf'),
'instructions' => __('Specify the returned value on front end','acf'),
'type' => 'radio',
'name' => 'return_format',
'layout' => 'horizontal',
'choices' => array(
'array' => __("Link Array",'acf'),
'url' => __("Link URL",'acf'),
)
));
}
/*
* 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;
// get link
$link = $this->get_link( $value );
// format value
if( $field['return_format'] == 'url' ) {
return $link['url'];
}
// return link
return $link;
}
/*
* validate_value
*
* description
*
* @type function
* @date 11/02/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function validate_value( $valid, $value, $field, $input ){
// bail early if not required
if( !$field['required'] ) return $valid;
// URL is required
if( empty($value) || empty($value['url']) ) {
return false;
}
// return
return $valid;
}
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
// URL is required
if( empty($value) || empty($value['url']) ) {
return false;
}
// return
return $value;
}
}
// initialize
acf_register_field_type( 'acf_field_link' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,200 @@
<?php
if( ! class_exists('acf_field_message') ) :
class acf_field_message extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'message';
$this->label = __("Message",'acf');
$this->category = 'layout';
$this->defaults = array(
'message' => '',
'esc_html' => 0,
'new_lines' => 'wpautop',
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// vars
$m = $field['message'];
// wptexturize (improves "quotes")
$m = wptexturize( $m );
// esc_html
if( $field['esc_html'] ) {
$m = esc_html( $m );
}
// new lines
if( $field['new_lines'] == 'wpautop' ) {
$m = wpautop($m);
} elseif( $field['new_lines'] == 'br' ) {
$m = nl2br($m);
}
// return
echo acf_esc_html( $m );
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) to save extra data to the $field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field_settings( $field ) {
// default_value
acf_render_field_setting( $field, array(
'label' => __('Message','acf'),
'instructions' => '',
'type' => 'textarea',
'name' => 'message',
));
// formatting
acf_render_field_setting( $field, array(
'label' => __('New Lines','acf'),
'instructions' => __('Controls how new lines are rendered','acf'),
'type' => 'select',
'name' => 'new_lines',
'choices' => array(
'wpautop' => __("Automatically add paragraphs",'acf'),
'br' => __("Automatically add &lt;br&gt;",'acf'),
'' => __("No Formatting",'acf')
)
));
// HTML
acf_render_field_setting( $field, array(
'label' => __('Escape HTML','acf'),
'instructions' => __('Allow HTML markup to display as visible text instead of rendering','acf'),
'name' => 'esc_html',
'type' => 'true_false',
'ui' => 1,
));
}
/*
* translate_field
*
* This function will translate field settings
*
* @type function
* @date 8/03/2016
* @since 5.3.2
*
* @param $field (array)
* @return $field
*/
function translate_field( $field ) {
// translate
$field['message'] = acf_translate( $field['message'] );
// return
return $field;
}
/*
* load_field()
*
* This filter is appied to the $field after it is loaded from the database
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $field - the field array holding all the field options
*
* @return $field - the field array holding all the field options
*/
function load_field( $field ) {
// remove name to avoid caching issue
$field['name'] = '';
// remove required to avoid JS issues
$field['required'] = 0;
// set value other than 'null' to avoid ACF loading / caching issue
$field['value'] = false;
// return
return $field;
}
}
// initialize
acf_register_field_type( 'acf_field_message' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,304 @@
<?php
if( ! class_exists('acf_field_number') ) :
class acf_field_number extends acf_field {
/*
* initialize
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'number';
$this->label = __("Number",'acf');
$this->defaults = array(
'default_value' => '',
'min' => '',
'max' => '',
'step' => '',
'placeholder' => '',
'prepend' => '',
'append' => ''
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// vars
$atts = array();
$keys = array( 'type', 'id', 'class', 'name', 'value', 'min', 'max', 'step', 'placeholder', 'pattern' );
$keys2 = array( 'readonly', 'disabled', 'required' );
$html = '';
// step
if( !$field['step'] ) {
$field['step'] = 'any';
}
// prepend
if( $field['prepend'] !== '' ) {
$field['class'] .= ' acf-is-prepended';
$html .= '<div class="acf-input-prepend">' . acf_esc_html($field['prepend']) . '</div>';
}
// append
if( $field['append'] !== '' ) {
$field['class'] .= ' acf-is-appended';
$html .= '<div class="acf-input-append">' . acf_esc_html($field['append']) . '</div>';
}
// atts (value="123")
foreach( $keys as $k ) {
if( isset($field[ $k ]) ) $atts[ $k ] = $field[ $k ];
}
// atts2 (disabled="disabled")
foreach( $keys2 as $k ) {
if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
}
// remove empty atts
$atts = acf_clean_atts( $atts );
// render
$html .= '<div class="acf-input-wrap">' . acf_get_text_input( $atts ) . '</div>';
// return
echo $html;
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// default_value
acf_render_field_setting( $field, array(
'label' => __('Default Value','acf'),
'instructions' => __('Appears when creating a new post','acf'),
'type' => 'text',
'name' => 'default_value',
));
// placeholder
acf_render_field_setting( $field, array(
'label' => __('Placeholder Text','acf'),
'instructions' => __('Appears within the input','acf'),
'type' => 'text',
'name' => 'placeholder',
));
// prepend
acf_render_field_setting( $field, array(
'label' => __('Prepend','acf'),
'instructions' => __('Appears before the input','acf'),
'type' => 'text',
'name' => 'prepend',
));
// append
acf_render_field_setting( $field, array(
'label' => __('Append','acf'),
'instructions' => __('Appears after the input','acf'),
'type' => 'text',
'name' => 'append',
));
// min
acf_render_field_setting( $field, array(
'label' => __('Minimum Value','acf'),
'instructions' => '',
'type' => 'number',
'name' => 'min',
));
// max
acf_render_field_setting( $field, array(
'label' => __('Maximum Value','acf'),
'instructions' => '',
'type' => 'number',
'name' => 'max',
));
// max
acf_render_field_setting( $field, array(
'label' => __('Step Size','acf'),
'instructions' => '',
'type' => 'number',
'name' => 'step',
));
}
/*
* validate_value
*
* description
*
* @type function
* @date 11/02/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function validate_value( $valid, $value, $field, $input ){
// remove ','
if( acf_str_exists(',', $value) ) {
$value = str_replace(',', '', $value);
}
// if value is not numeric...
if( !is_numeric($value) ) {
// allow blank to be saved
if( !empty($value) ) {
$valid = __('Value must be a number', 'acf');
}
// return early
return $valid;
}
// convert
$value = floatval($value);
// min
if( is_numeric($field['min']) && $value < floatval($field['min'])) {
$valid = sprintf(__('Value must be equal to or higher than %d', 'acf'), $field['min'] );
}
// max
if( is_numeric($field['max']) && $value > floatval($field['max']) ) {
$valid = sprintf(__('Value must be equal to or lower than %d', 'acf'), $field['max'] );
}
// return
return $valid;
}
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which will be saved in the database
* @param $field - the field array holding all the field options
* @param $post_id - the $post_id of which the value will be saved
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
// no formatting needed for empty value
if( empty($value) ) {
return $value;
}
// remove ','
if( acf_str_exists(',', $value) ) {
$value = str_replace(',', '', $value);
}
// return
return $value;
}
}
// initialize
acf_register_field_type( 'acf_field_number' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,333 @@
<?php
if( ! class_exists('acf_field_oembed') ) :
class acf_field_oembed extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'oembed';
$this->label = __("oEmbed",'acf');
$this->category = 'content';
$this->defaults = array(
'width' => '',
'height' => '',
);
$this->width = 640;
$this->height = 390;
// extra
add_action('wp_ajax_acf/fields/oembed/search', array($this, 'ajax_query'));
add_action('wp_ajax_nopriv_acf/fields/oembed/search', array($this, 'ajax_query'));
}
/*
* prepare_field
*
* This function will prepare the field for input
*
* @type function
* @date 14/2/17
* @since 5.5.8
*
* @param $field (array)
* @return (int)
*/
function prepare_field( $field ) {
// defaults
if( !$field['width'] ) $field['width'] = $this->width;
if( !$field['height'] ) $field['height'] = $this->height;
// return
return $field;
}
/*
* wp_oembed_get
*
* description
*
* @type function
* @date 24/01/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function wp_oembed_get( $url = '', $width = 0, $height = 0 ) {
// vars
$embed = '';
$res = array(
'width' => $width,
'height' => $height
);
// get emebed
$embed = @wp_oembed_get( $url, $res );
// try shortcode
if( !$embed ) {
// global
global $wp_embed;
// get emebed
$embed = $wp_embed->shortcode($res, $url);
}
// return
return $embed;
}
/*
* ajax_query
*
* description
*
* @type function
* @date 24/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function ajax_query() {
// validate
if( !acf_verify_ajax() ) die();
// get choices
$response = $this->get_ajax_query( $_POST );
// return
wp_send_json($response);
}
/*
* get_ajax_query
*
* This function will return an array of data formatted for use in a select2 AJAX response
*
* @type function
* @date 15/10/2014
* @since 5.0.9
*
* @param $options (array)
* @return (array)
*/
function get_ajax_query( $args = array() ) {
// defaults
$args = acf_parse_args($args, array(
's' => '',
'field_key' => '',
));
// load field
$field = acf_get_field( $args['field_key'] );
if( !$field ) return false;
// prepare field to correct width and height
$field = $this->prepare_field($field);
// vars
$response = array(
'url' => $args['s'],
'html' => $this->wp_oembed_get($args['s'], $field['width'], $field['height'])
);
// return
return $response;
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// atts
$atts = array(
'class' => 'acf-oembed',
);
// value
if( $field['value'] ) $atts['class'] .= ' has-value';
?>
<div <?php acf_esc_attr_e($atts) ?>>
<?php acf_hidden_input(array( 'name' => $field['name'], 'value' => $field['value'], 'data-name' => 'value-input' )); ?>
<div class="title">
<div class="title-value">
<h4 data-name="value-title"><?php echo esc_html( $field['value'] ); ?></h4>
</div>
<div class="title-search">
<input data-name="search-input" type="text" placeholder="<?php _e("Enter URL", 'acf'); ?>" autocomplete="off" />
</div>
<div class="acf-actions -hover">
<a data-name="clear-button" href="#" class="acf-icon -cancel grey"></a>
</div>
</div>
<div class="canvas">
<div class="canvas-loading">
<i class="acf-loading"></i>
</div>
<div class="canvas-error">
<p><strong><?php _e("Error.", 'acf'); ?></strong> <?php _e("No embed found for the given URL.", 'acf'); ?></p>
</div>
<div class="canvas-media" data-name="value-embed">
<?php if( $field['value'] ) echo $this->wp_oembed_get($field['value'], $field['width'], $field['height']); ?>
</div>
<i class="acf-icon -picture hide-if-value"></i>
</div>
</div>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) to save extra data to the $field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field_settings( $field ) {
// width
acf_render_field_setting( $field, array(
'label' => __('Embed Size','acf'),
'type' => 'text',
'name' => 'width',
'prepend' => __('Width', 'acf'),
'append' => 'px',
'placeholder' => $this->width
));
// height
acf_render_field_setting( $field, array(
'label' => __('Embed Size','acf'),
'type' => 'text',
'name' => 'height',
'prepend' => __('Height', 'acf'),
'append' => 'px',
'placeholder' => $this->height,
'_append' => 'width'
));
}
/*
* 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;
// prepare field to correct width and height
$field = $this->prepare_field($field);
// get oembed
$value = $this->wp_oembed_get($value, $field['width'], $field['height']);
// return
return $value;
}
}
// initialize
acf_register_field_type( 'acf_field_oembed' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,77 @@
<?php
if( ! class_exists('acf_field_output') ) :
class acf_field_output extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'output';
$this->label = 'output';
$this->public = false;
$this->defaults = array(
'html' => false
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field (array) the $field being rendered
*
* @type action
* @since 3.6
* @date 23/01/13
*
* @param $field (array) the $field being edited
* @return n/a
*/
function render_field( $field ) {
// bail early if no html
if( !$field['html'] ) return;
// html
if( is_string($field['html']) && !function_exists($field['html']) ) {
echo $field['html'];
// function
} else {
call_user_func_array($field['html'], array($field));
}
}
}
// initialize
acf_register_field_type( 'acf_field_output' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,680 @@
<?php
if( ! class_exists('acf_field_page_link') ) :
class acf_field_page_link extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'page_link';
$this->label = __("Page Link",'acf');
$this->category = 'relational';
$this->defaults = array(
'post_type' => array(),
'taxonomy' => array(),
'allow_null' => 0,
'multiple' => 0,
'allow_archives' => 1
);
// extra
add_action('wp_ajax_acf/fields/page_link/query', array($this, 'ajax_query'));
add_action('wp_ajax_nopriv_acf/fields/page_link/query', array($this, 'ajax_query'));
}
/*
* ajax_query
*
* description
*
* @type function
* @date 24/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function ajax_query() {
// validate
if( !acf_verify_ajax() ) die();
// defaults
$options = acf_parse_args($_POST, array(
'post_id' => 0,
's' => '',
'field_key' => '',
'paged' => 1
));
// vars
$results = array();
$args = array();
$s = false;
$is_search = false;
// paged
$args['posts_per_page'] = 20;
$args['paged'] = $options['paged'];
// search
if( $options['s'] !== '' ) {
// strip slashes (search may be integer)
$s = wp_unslash( strval($options['s']) );
// update vars
$args['s'] = $s;
$is_search = true;
}
// load field
$field = acf_get_field( $options['field_key'] );
if( !$field ) die();
// update $args
if( !empty($field['post_type']) ) {
$args['post_type'] = acf_get_array( $field['post_type'] );
} else {
$args['post_type'] = acf_get_post_types();
}
// create tax queries
if( !empty($field['taxonomy']) ) {
// append to $args
$args['tax_query'] = array();
// decode terms
$taxonomies = acf_decode_taxonomy_terms( $field['taxonomy'] );
// now create the tax queries
foreach( $taxonomies as $taxonomy => $terms ) {
$args['tax_query'][] = array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $terms,
);
}
}
// filters
$args = apply_filters('acf/fields/page_link/query', $args, $field, $options['post_id']);
$args = apply_filters('acf/fields/page_link/query/name=' . $field['name'], $args, $field, $options['post_id'] );
$args = apply_filters('acf/fields/page_link/query/key=' . $field['key'], $args, $field, $options['post_id'] );
// add archives to $results
if( $field['allow_archives'] && $args['paged'] == 1 ) {
$archives = array();
$archives[] = array(
'id' => home_url(),
'text' => home_url()
);
foreach( $args['post_type'] as $post_type ) {
// vars
$archive_link = get_post_type_archive_link( $post_type );
// bail ealry if no link
if( !$archive_link ) continue;
// bail early if no search match
if( $is_search && stripos($archive_link, $s) === false ) continue;
// append
$archives[] = array(
'id' => $archive_link,
'text' => $archive_link
);
}
// append
$results[] = array(
'text' => __('Archives', 'acf'),
'children' => $archives
);
}
// get posts grouped by post type
$groups = acf_get_grouped_posts( $args );
// loop
if( !empty($groups) ) {
foreach( array_keys($groups) as $group_title ) {
// vars
$posts = acf_extract_var( $groups, $group_title );
// data
$data = array(
'text' => $group_title,
'children' => array()
);
// convert post objects to post titles
foreach( array_keys($posts) as $post_id ) {
$posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'], $is_search );
}
// order posts by search
if( $is_search && empty($args['orderby']) ) {
$posts = acf_order_by_search( $posts, $args['s'] );
}
// append to $data
foreach( array_keys($posts) as $post_id ) {
$data['children'][] = $this->get_post_result( $post_id, $posts[ $post_id ]);
}
// append to $results
$results[] = $data;
}
}
// return
acf_send_ajax_results(array(
'results' => $results,
'limit' => $args['posts_per_page']
));
}
/*
* get_post_result
*
* This function will return an array containing id, text and maybe description data
*
* @type function
* @date 7/07/2016
* @since 5.4.0
*
* @param $id (mixed)
* @param $text (string)
* @return (array)
*/
function get_post_result( $id, $text ) {
// vars
$result = array(
'id' => $id,
'text' => $text
);
// look for parent
$search = '| ' . __('Parent', 'acf') . ':';
$pos = strpos($text, $search);
if( $pos !== false ) {
$result['description'] = substr($text, $pos+2);
$result['text'] = substr($text, 0, $pos);
}
// return
return $result;
}
/*
* get_post_title
*
* This function returns the HTML for a result
*
* @type function
* @date 1/11/2013
* @since 5.0.0
*
* @param $post (object)
* @param $field (array)
* @param $post_id (int) the post_id to which this value is saved to
* @return (string)
*/
function get_post_title( $post, $field, $post_id = 0, $is_search = 0 ) {
// get post_id
if( !$post_id ) $post_id = acf_get_form_data('post_id');
// vars
$title = acf_get_post_title( $post, $is_search );
// filters
$title = apply_filters('acf/fields/page_link/result', $title, $post, $field, $post_id);
$title = apply_filters('acf/fields/page_link/result/name=' . $field['_name'], $title, $post, $field, $post_id);
$title = apply_filters('acf/fields/page_link/result/key=' . $field['key'], $title, $post, $field, $post_id);
// return
return $title;
}
/*
* get_posts
*
* This function will return an array of posts for a given field value
*
* @type function
* @date 13/06/2014
* @since 5.0.0
*
* @param $value (array)
* @return $value
*/
function get_posts( $value, $field ) {
// force value to array
$value = acf_get_array( $value );
// get selected post ID's
$post__in = array();
foreach( $value as $k => $v ) {
if( is_numeric($v) ) {
// append to $post__in
$post__in[] = (int) $v;
}
}
// bail early if no posts
if( empty($post__in) ) {
return $value;
}
// get posts
$posts = acf_get_posts(array(
'post__in' => $post__in,
'post_type' => $field['post_type']
));
// override value with post
$return = array();
// append to $return
foreach( $value as $k => $v ) {
if( is_numeric($v) ) {
// extract first post
$post = array_shift( $posts );
// append
if( $post ) {
$return[] = $post;
}
} else {
$return[] = $v;
}
}
// return
return $return;
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ){
// Change Field into a select
$field['type'] = 'select';
$field['ui'] = 1;
$field['ajax'] = 1;
$field['choices'] = array();
// populate choices if value exists
if( !empty($field['value']) ) {
// get posts
$posts = $this->get_posts( $field['value'], $field );
// set choices
if( !empty($posts) ) {
foreach( array_keys($posts) as $i ) {
// vars
$post = acf_extract_var( $posts, $i );
if( is_object($post) ) {
// append to choices
$field['choices'][ $post->ID ] = $this->get_post_title( $post, $field );
} else {
// append to choices
$field['choices'][ $post ] = $post;
}
}
}
}
// render
acf_render_field( $field );
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// post_type
acf_render_field_setting( $field, array(
'label' => __('Filter by Post Type','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'post_type',
'choices' => acf_get_pretty_post_types(),
'multiple' => 1,
'ui' => 1,
'allow_null' => 1,
'placeholder' => __("All post types",'acf'),
));
// taxonomy
acf_render_field_setting( $field, array(
'label' => __('Filter by Taxonomy','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'taxonomy',
'choices' => acf_get_taxonomy_terms(),
'multiple' => 1,
'ui' => 1,
'allow_null' => 1,
'placeholder' => __("All taxonomies",'acf'),
));
// allow_null
acf_render_field_setting( $field, array(
'label' => __('Allow Null?','acf'),
'instructions' => '',
'name' => 'allow_null',
'type' => 'true_false',
'ui' => 1,
));
// allow_archives
acf_render_field_setting( $field, array(
'label' => __('Allow Archives URLs','acf'),
'instructions' => '',
'name' => 'allow_archives',
'type' => 'true_false',
'ui' => 1,
));
// multiple
acf_render_field_setting( $field, array(
'label' => __('Select multiple values?','acf'),
'instructions' => '',
'name' => 'multiple',
'type' => 'true_false',
'ui' => 1,
));
}
/*
* 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 ) {
// ACF4 null
if( $value === 'null' ) {
return false;
}
// bail early if no value
if( empty($value) ) {
return $value;
}
// get posts
$value = $this->get_posts( $value, $field );
// set choices
foreach( array_keys($value) as $i ) {
// vars
$post = acf_extract_var( $value, $i );
// convert $post to permalink
if( is_object($post) ) {
$post = get_permalink( $post );
}
// append back to $value
$value[ $i ] = $post;
}
// convert back from array if neccessary
if( !$field['multiple'] ) {
$value = array_shift($value);
}
// return value
return $value;
}
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
// validate
if( empty($value) ) {
return $value;
}
// format
if( is_array($value) ) {
// array
foreach( $value as $k => $v ){
// object?
if( is_object($v) && isset($v->ID) )
{
$value[ $k ] = $v->ID;
}
}
// save value as strings, so we can clearly search for them in SQL LIKE statements
$value = array_map('strval', $value);
} elseif( is_object($value) && isset($value->ID) ) {
// object
$value = $value->ID;
}
// return
return $value;
}
}
// initialize
acf_register_field_type( 'acf_field_page_link' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,104 @@
<?php
if( ! class_exists('acf_field_password') ) :
class acf_field_password extends acf_field {
/*
* initialize
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'password';
$this->label = __("Password",'acf');
$this->defaults = array(
'placeholder' => '',
'prepend' => '',
'append' => '',
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
acf_get_field_type('text')->render_field( $field );
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// placeholder
acf_render_field_setting( $field, array(
'label' => __('Placeholder Text','acf'),
'instructions' => __('Appears within the input','acf'),
'type' => 'text',
'name' => 'placeholder',
));
// prepend
acf_render_field_setting( $field, array(
'label' => __('Prepend','acf'),
'instructions' => __('Appears before the input','acf'),
'type' => 'text',
'name' => 'prepend',
));
// append
acf_render_field_setting( $field, array(
'label' => __('Append','acf'),
'instructions' => __('Appears after the input','acf'),
'type' => 'text',
'name' => 'append',
));
}
}
// initialize
acf_register_field_type( 'acf_field_password' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,623 @@
<?php
if( ! class_exists('acf_field_post_object') ) :
class acf_field_post_object extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post_object';
$this->label = __("Post Object",'acf');
$this->category = 'relational';
$this->defaults = array(
'post_type' => array(),
'taxonomy' => array(),
'allow_null' => 0,
'multiple' => 0,
'return_format' => 'object',
'ui' => 1,
);
// extra
add_action('wp_ajax_acf/fields/post_object/query', array($this, 'ajax_query'));
add_action('wp_ajax_nopriv_acf/fields/post_object/query', array($this, 'ajax_query'));
}
/*
* ajax_query
*
* description
*
* @type function
* @date 24/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function ajax_query() {
// validate
if( !acf_verify_ajax() ) die();
// get choices
$response = $this->get_ajax_query( $_POST );
// return
acf_send_ajax_results($response);
}
/*
* get_ajax_query
*
* This function will return an array of data formatted for use in a select2 AJAX response
*
* @type function
* @date 15/10/2014
* @since 5.0.9
*
* @param $options (array)
* @return (array)
*/
function get_ajax_query( $options = array() ) {
// defaults
$options = acf_parse_args($options, array(
'post_id' => 0,
's' => '',
'field_key' => '',
'paged' => 1
));
// load field
$field = acf_get_field( $options['field_key'] );
if( !$field ) return false;
// vars
$results = array();
$args = array();
$s = false;
$is_search = false;
// paged
$args['posts_per_page'] = 20;
$args['paged'] = $options['paged'];
// search
if( $options['s'] !== '' ) {
// strip slashes (search may be integer)
$s = wp_unslash( strval($options['s']) );
// update vars
$args['s'] = $s;
$is_search = true;
}
// post_type
if( !empty($field['post_type']) ) {
$args['post_type'] = acf_get_array( $field['post_type'] );
} else {
$args['post_type'] = acf_get_post_types();
}
// taxonomy
if( !empty($field['taxonomy']) ) {
// vars
$terms = acf_decode_taxonomy_terms( $field['taxonomy'] );
// append to $args
$args['tax_query'] = array();
// now create the tax queries
foreach( $terms as $k => $v ) {
$args['tax_query'][] = array(
'taxonomy' => $k,
'field' => 'slug',
'terms' => $v,
);
}
}
// filters
$args = apply_filters('acf/fields/post_object/query', $args, $field, $options['post_id']);
$args = apply_filters('acf/fields/post_object/query/name=' . $field['name'], $args, $field, $options['post_id'] );
$args = apply_filters('acf/fields/post_object/query/key=' . $field['key'], $args, $field, $options['post_id'] );
// get posts grouped by post type
$groups = acf_get_grouped_posts( $args );
// bail early if no posts
if( empty($groups) ) return false;
// loop
foreach( array_keys($groups) as $group_title ) {
// vars
$posts = acf_extract_var( $groups, $group_title );
// data
$data = array(
'text' => $group_title,
'children' => array()
);
// convert post objects to post titles
foreach( array_keys($posts) as $post_id ) {
$posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'], $is_search );
}
// order posts by search
if( $is_search && empty($args['orderby']) ) {
$posts = acf_order_by_search( $posts, $args['s'] );
}
// append to $data
foreach( array_keys($posts) as $post_id ) {
$data['children'][] = $this->get_post_result( $post_id, $posts[ $post_id ]);
}
// append to $results
$results[] = $data;
}
// optgroup or single
if( count($args['post_type']) == 1 ) {
$results = $results[0]['children'];
}
// vars
$response = array(
'results' => $results,
'limit' => $args['posts_per_page']
);
// return
return $response;
}
/*
* get_post_result
*
* This function will return an array containing id, text and maybe description data
*
* @type function
* @date 7/07/2016
* @since 5.4.0
*
* @param $id (mixed)
* @param $text (string)
* @return (array)
*/
function get_post_result( $id, $text ) {
// vars
$result = array(
'id' => $id,
'text' => $text
);
// look for parent
$search = '| ' . __('Parent', 'acf') . ':';
$pos = strpos($text, $search);
if( $pos !== false ) {
$result['description'] = substr($text, $pos+2);
$result['text'] = substr($text, 0, $pos);
}
// return
return $result;
}
/*
* get_post_title
*
* This function returns the HTML for a result
*
* @type function
* @date 1/11/2013
* @since 5.0.0
*
* @param $post (object)
* @param $field (array)
* @param $post_id (int) the post_id to which this value is saved to
* @return (string)
*/
function get_post_title( $post, $field, $post_id = 0, $is_search = 0 ) {
// get post_id
if( !$post_id ) $post_id = acf_get_form_data('post_id');
// vars
$title = acf_get_post_title( $post, $is_search );
// filters
$title = apply_filters('acf/fields/post_object/result', $title, $post, $field, $post_id);
$title = apply_filters('acf/fields/post_object/result/name=' . $field['_name'], $title, $post, $field, $post_id);
$title = apply_filters('acf/fields/post_object/result/key=' . $field['key'], $title, $post, $field, $post_id);
// return
return $title;
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// Change Field into a select
$field['type'] = 'select';
$field['ui'] = 1;
$field['ajax'] = 1;
$field['choices'] = array();
// load posts
$posts = $this->get_posts( $field['value'], $field );
if( $posts ) {
foreach( array_keys($posts) as $i ) {
// vars
$post = acf_extract_var( $posts, $i );
// append to choices
$field['choices'][ $post->ID ] = $this->get_post_title( $post, $field );
}
}
// render
acf_render_field( $field );
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// default_value
acf_render_field_setting( $field, array(
'label' => __('Filter by Post Type','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'post_type',
'choices' => acf_get_pretty_post_types(),
'multiple' => 1,
'ui' => 1,
'allow_null' => 1,
'placeholder' => __("All post types",'acf'),
));
// default_value
acf_render_field_setting( $field, array(
'label' => __('Filter by Taxonomy','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'taxonomy',
'choices' => acf_get_taxonomy_terms(),
'multiple' => 1,
'ui' => 1,
'allow_null' => 1,
'placeholder' => __("All taxonomies",'acf'),
));
// allow_null
acf_render_field_setting( $field, array(
'label' => __('Allow Null?','acf'),
'instructions' => '',
'name' => 'allow_null',
'type' => 'true_false',
'ui' => 1,
));
// multiple
acf_render_field_setting( $field, array(
'label' => __('Select multiple values?','acf'),
'instructions' => '',
'name' => 'multiple',
'type' => 'true_false',
'ui' => 1,
));
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Format','acf'),
'instructions' => '',
'type' => 'radio',
'name' => 'return_format',
'choices' => array(
'object' => __("Post Object",'acf'),
'id' => __("Post ID",'acf'),
),
'layout' => 'horizontal',
));
}
/*
* 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 ) {
// ACF4 null
if( $value === 'null' ) return false;
// return
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 ) {
// numeric
$value = acf_get_numeric($value);
// bail early if no value
if( empty($value) ) return false;
// load posts if needed
if( $field['return_format'] == 'object' ) {
$value = $this->get_posts( $value, $field );
}
// convert back from array if neccessary
if( !$field['multiple'] && acf_is_array($value) ) {
$value = current($value);
}
// return value
return $value;
}
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
// validate
if( empty($value) ) {
return $value;
}
// format
if( is_array($value) ) {
// array
foreach( $value as $k => $v ){
// object?
if( is_object($v) && isset($v->ID) ) {
$value[ $k ] = $v->ID;
}
}
// save value as strings, so we can clearly search for them in SQL LIKE statements
$value = array_map('strval', $value);
} elseif( is_object($value) && isset($value->ID) ) {
// object
$value = $value->ID;
}
// return
return $value;
}
/*
* get_posts
*
* This function will return an array of posts for a given field value
*
* @type function
* @date 13/06/2014
* @since 5.0.0
*
* @param $value (array)
* @return $value
*/
function get_posts( $value, $field ) {
// numeric
$value = acf_get_numeric($value);
// bail early if no value
if( empty($value) ) return false;
// get posts
$posts = acf_get_posts(array(
'post__in' => $value,
'post_type' => $field['post_type']
));
// return
return $posts;
}
}
// initialize
acf_register_field_type( 'acf_field_post_object' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,486 @@
<?php
if( ! class_exists('acf_field_radio') ) :
class acf_field_radio extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'radio';
$this->label = __("Radio Button",'acf');
$this->category = 'choice';
$this->defaults = array(
'layout' => 'vertical',
'choices' => array(),
'default_value' => '',
'other_choice' => 0,
'save_other_choice' => 0,
'allow_null' => 0,
'return_format' => 'value'
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field (array) the $field being rendered
*
* @type action
* @since 3.6
* @date 23/01/13
*
* @param $field (array) the $field being edited
* @return n/a
*/
function render_field( $field ) {
// vars
$i = 0;
$e = '';
$ul = array(
'class' => 'acf-radio-list',
'data-allow_null' => $field['allow_null'],
'data-other_choice' => $field['other_choice']
);
// append to class
$ul['class'] .= ' ' . ($field['layout'] == 'horizontal' ? 'acf-hl' : 'acf-bl');
$ul['class'] .= ' ' . $field['class'];
// select value
$checked = '';
$value = strval($field['value']);
// selected choice
if( isset($field['choices'][ $value ]) ) {
$checked = $value;
// custom choice
} elseif( $field['other_choice'] && $value !== '' ) {
$checked = 'other';
// allow null
} elseif( $field['allow_null'] ) {
// do nothing
// select first input by default
} else {
$checked = key($field['choices']);
}
// ensure $checked is a string (could be an int)
$checked = strval($checked);
// other choice
if( $field['other_choice'] ) {
// vars
$input = array(
'type' => 'text',
'name' => $field['name'],
'value' => '',
'disabled' => 'disabled',
'class' => 'acf-disabled'
);
// select other choice if value is not a valid choice
if( $checked === 'other' ) {
unset($input['disabled']);
$input['value'] = $field['value'];
}
// allow custom 'other' choice to be defined
if( !isset($field['choices']['other']) ) {
$field['choices']['other'] = '';
}
// append other choice
$field['choices']['other'] .= '</label><input type="text" ' . acf_esc_attr($input) . ' /><label>';
}
// bail early if no choices
if( empty($field['choices']) ) return;
// hiden input
$e .= acf_get_hidden_input( array('name' => $field['name']) );
// open
$e .= '<ul ' . acf_esc_attr($ul) . '>';
// foreach choices
foreach( $field['choices'] as $value => $label ) {
// ensure value is a string
$value = strval($value);
$class = '';
// increase counter
$i++;
// vars
$atts = array(
'type' => 'radio',
'id' => $field['id'],
'name' => $field['name'],
'value' => $value
);
// checked
if( $value === $checked ) {
$atts['checked'] = 'checked';
$class = ' class="selected"';
}
// deisabled
if( isset($field['disabled']) && acf_in_array($value, $field['disabled']) ) {
$atts['disabled'] = 'disabled';
}
// id (use crounter for each input)
if( $i > 1 ) {
$atts['id'] .= '-' . $value;
}
// append
$e .= '<li><label' . $class . '><input ' . acf_esc_attr( $atts ) . '/>' . $label . '</label></li>';
}
// close
$e .= '</ul>';
// return
echo $e;
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// encode choices (convert from array)
$field['choices'] = acf_encode_choices($field['choices']);
// choices
acf_render_field_setting( $field, array(
'label' => __('Choices','acf'),
'instructions' => __('Enter each choice on a new line.','acf') . '<br /><br />' . __('For more control, you may specify both a value and label like this:','acf'). '<br /><br />' . __('red : Red','acf'),
'type' => 'textarea',
'name' => 'choices',
));
// allow_null
acf_render_field_setting( $field, array(
'label' => __('Allow Null?','acf'),
'instructions' => '',
'name' => 'allow_null',
'type' => 'true_false',
'ui' => 1,
));
// other_choice
acf_render_field_setting( $field, array(
'label' => __('Other','acf'),
'instructions' => '',
'name' => 'other_choice',
'type' => 'true_false',
'ui' => 1,
'message' => __("Add 'other' choice to allow for custom values", 'acf'),
));
// save_other_choice
acf_render_field_setting( $field, array(
'label' => __('Save Other','acf'),
'instructions' => '',
'name' => 'save_other_choice',
'type' => 'true_false',
'ui' => 1,
'message' => __("Save 'other' values to the field's choices", 'acf')
));
// default_value
acf_render_field_setting( $field, array(
'label' => __('Default Value','acf'),
'instructions' => __('Appears when creating a new post','acf'),
'type' => 'text',
'name' => 'default_value',
));
// layout
acf_render_field_setting( $field, array(
'label' => __('Layout','acf'),
'instructions' => '',
'type' => 'radio',
'name' => 'layout',
'layout' => 'horizontal',
'choices' => array(
'vertical' => __("Vertical",'acf'),
'horizontal' => __("Horizontal",'acf')
)
));
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Value','acf'),
'instructions' => __('Specify the returned value on front end','acf'),
'type' => 'radio',
'name' => 'return_format',
'layout' => 'horizontal',
'choices' => array(
'value' => __('Value','acf'),
'label' => __('Label','acf'),
'array' => __('Both (Array)','acf')
)
));
}
/*
* update_field()
*
* This filter is appied to the $field before it is saved to the database
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $field - the field array holding all the field options
* @param $post_id - the field group ID (post_type = acf)
*
* @return $field - the modified field
*/
function update_field( $field ) {
// decode choices (convert to array)
$field['choices'] = acf_decode_choices($field['choices']);
// return
return $field;
}
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
* @todo Fix bug where $field was found via json and has no ID
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
// bail early if no value (allow 0 to be saved)
if( !$value && !is_numeric($value) ) return $value;
// save_other_choice
if( $field['save_other_choice'] ) {
// value isn't in choices yet
if( !isset($field['choices'][ $value ]) ) {
// get raw $field (may have been changed via repeater field)
// if field is local, it won't have an ID
$selector = $field['ID'] ? $field['ID'] : $field['key'];
$field = acf_get_field( $selector, true );
// bail early if no ID (JSON only)
if( !$field['ID'] ) return $value;
// unslash (fixes serialize single quote issue)
$value = wp_unslash($value);
// sanitize (remove tags)
$value = sanitize_text_field($value);
// update $field
$field['choices'][ $value ] = $value;
// save
acf_update_field( $field );
}
}
// return
return $value;
}
/*
* load_value()
*
* This filter is appied to the $value after it is loaded from the db
*
* @type filter
* @since 5.2.9
* @date 23/01/13
*
* @param $value - the value found in the database
* @param $post_id - the $post_id from which the value was loaded from
* @param $field - the field array holding all the field options
*
* @return $value - the value to be saved in te database
*/
function load_value( $value, $post_id, $field ) {
// must be single value
if( is_array($value) ) {
$value = array_pop($value);
}
// return
return $value;
}
/*
* translate_field
*
* This function will translate field settings
*
* @type function
* @date 8/03/2016
* @since 5.3.2
*
* @param $field (array)
* @return $field
*/
function translate_field( $field ) {
return acf_get_field_type('select')->translate_field( $field );
}
/*
* 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 ) {
return acf_get_field_type('select')->format_value( $value, $post_id, $field );
}
}
// initialize
acf_register_field_type( 'acf_field_radio' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,213 @@
<?php
if( ! class_exists('acf_field_range') ) :
class acf_field_range extends acf_field_number {
/*
* initialize
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'range';
$this->label = __("Range",'acf');
$this->defaults = array(
'default_value' => '',
'min' => '',
'max' => '',
'step' => '',
'prepend' => '',
'append' => ''
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// vars
$atts = array();
$keys = array( 'type', 'id', 'class', 'name', 'value', 'min', 'max', 'step' );
$keys2 = array( 'readonly', 'disabled', 'required' );
$html = '';
// step
if( !$field['step'] ) $field['step'] = 1;
// min / max
if( !$field['min'] ) $field['min'] = 0;
if( !$field['max'] ) $field['max'] = 100;
// value
if( !is_numeric($field['value']) ) {
$field['value'] = 0;
}
// atts (value="123")
foreach( $keys as $k ) {
if( isset($field[ $k ]) ) $atts[ $k ] = $field[ $k ];
}
// atts2 (disabled="disabled")
foreach( $keys2 as $k ) {
if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
}
// remove empty atts
$atts = acf_clean_atts( $atts );
// open
$html .= '<div class="acf-range-wrap">';
// prepend
if( $field['prepend'] !== '' ) {
$html .= '<div class="acf-prepend">' . acf_esc_html($field['prepend']) . '</div>';
}
// range
$html .= acf_get_text_input( $atts );
// input
$len = strlen( (string) $field['max'] );
$html .= acf_get_text_input(array(
'type' => 'number',
'id' => $atts['id'] . '-alt',
'value' => $atts['value'],
'step' => $atts['step'],
'style' => 'width: ' . (1.8 + $len*0.7) . 'em;'
));
// append
if( $field['append'] !== '' ) {
$html .= '<div class="acf-append">' . acf_esc_html($field['append']) . '</div>';
}
// close
$html .= '</div>';
// return
echo $html;
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// default_value
acf_render_field_setting( $field, array(
'label' => __('Default Value','acf'),
'instructions' => __('Appears when creating a new post','acf'),
'type' => 'number',
'name' => 'default_value',
));
// min
acf_render_field_setting( $field, array(
'label' => __('Minimum Value','acf'),
'instructions' => '',
'type' => 'number',
'name' => 'min',
'placeholder' => '0'
));
// max
acf_render_field_setting( $field, array(
'label' => __('Maximum Value','acf'),
'instructions' => '',
'type' => 'number',
'name' => 'max',
'placeholder' => '100'
));
// step
acf_render_field_setting( $field, array(
'label' => __('Step Size','acf'),
'instructions' => '',
'type' => 'number',
'name' => 'step',
'placeholder' => '1'
));
// prepend
acf_render_field_setting( $field, array(
'label' => __('Prepend','acf'),
'instructions' => __('Appears before the input','acf'),
'type' => 'text',
'name' => 'prepend',
));
// append
acf_render_field_setting( $field, array(
'label' => __('Append','acf'),
'instructions' => __('Appears after the input','acf'),
'type' => 'text',
'name' => 'append',
));
}
}
// initialize
acf_register_field_type( 'acf_field_range' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,862 @@
<?php
if( ! class_exists('acf_field_relationship') ) :
class acf_field_relationship extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'relationship';
$this->label = __("Relationship",'acf');
$this->category = 'relational';
$this->defaults = array(
'post_type' => array(),
'taxonomy' => array(),
'min' => 0,
'max' => 0,
'filters' => array('search', 'post_type', 'taxonomy'),
'elements' => array(),
'return_format' => 'object'
);
$this->l10n = array(
'min' => __("Minimum values reached ( {min} values )",'acf'),
'max' => __("Maximum values reached ( {max} values )",'acf'),
'loading' => __('Loading','acf'),
'empty' => __('No matches found','acf'),
);
// extra
add_action('wp_ajax_acf/fields/relationship/query', array($this, 'ajax_query'));
add_action('wp_ajax_nopriv_acf/fields/relationship/query', array($this, 'ajax_query'));
}
/*
* ajax_query
*
* description
*
* @type function
* @date 24/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function ajax_query() {
// validate
if( !acf_verify_ajax() ) die();
// get choices
$response = $this->get_ajax_query( $_POST );
// return
acf_send_ajax_results($response);
}
/*
* get_ajax_query
*
* This function will return an array of data formatted for use in a select2 AJAX response
*
* @type function
* @date 15/10/2014
* @since 5.0.9
*
* @param $options (array)
* @return (array)
*/
function get_ajax_query( $options = array() ) {
// defaults
$options = acf_parse_args($options, array(
'post_id' => 0,
's' => '',
'field_key' => '',
'paged' => 1,
'post_type' => '',
'taxonomy' => ''
));
// load field
$field = acf_get_field( $options['field_key'] );
if( !$field ) return false;
// vars
$results = array();
$args = array();
$s = false;
$is_search = false;
// paged
$args['posts_per_page'] = 20;
$args['paged'] = $options['paged'];
// search
if( $options['s'] !== '' ) {
// strip slashes (search may be integer)
$s = wp_unslash( strval($options['s']) );
// update vars
$args['s'] = $s;
$is_search = true;
}
// post_type
if( !empty($options['post_type']) ) {
$args['post_type'] = acf_get_array( $options['post_type'] );
} elseif( !empty($field['post_type']) ) {
$args['post_type'] = acf_get_array( $field['post_type'] );
} else {
$args['post_type'] = acf_get_post_types();
}
// taxonomy
if( !empty($options['taxonomy']) ) {
// vars
$term = acf_decode_taxonomy_term($options['taxonomy']);
// tax query
$args['tax_query'] = array();
// append
$args['tax_query'][] = array(
'taxonomy' => $term['taxonomy'],
'field' => 'slug',
'terms' => $term['term'],
);
} elseif( !empty($field['taxonomy']) ) {
// vars
$terms = acf_decode_taxonomy_terms( $field['taxonomy'] );
// append to $args
$args['tax_query'] = array();
// now create the tax queries
foreach( $terms as $k => $v ) {
$args['tax_query'][] = array(
'taxonomy' => $k,
'field' => 'slug',
'terms' => $v,
);
}
}
// filters
$args = apply_filters('acf/fields/relationship/query', $args, $field, $options['post_id']);
$args = apply_filters('acf/fields/relationship/query/name=' . $field['name'], $args, $field, $options['post_id'] );
$args = apply_filters('acf/fields/relationship/query/key=' . $field['key'], $args, $field, $options['post_id'] );
// get posts grouped by post type
$groups = acf_get_grouped_posts( $args );
// bail early if no posts
if( empty($groups) ) return false;
// loop
foreach( array_keys($groups) as $group_title ) {
// vars
$posts = acf_extract_var( $groups, $group_title );
// data
$data = array(
'text' => $group_title,
'children' => array()
);
// convert post objects to post titles
foreach( array_keys($posts) as $post_id ) {
$posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'] );
}
// order posts by search
if( $is_search && empty($args['orderby']) ) {
$posts = acf_order_by_search( $posts, $args['s'] );
}
// append to $data
foreach( array_keys($posts) as $post_id ) {
$data['children'][] = $this->get_post_result( $post_id, $posts[ $post_id ]);
}
// append to $results
$results[] = $data;
}
// add as optgroup or results
if( count($args['post_type']) == 1 ) {
$results = $results[0]['children'];
}
// vars
$response = array(
'results' => $results,
'limit' => $args['posts_per_page']
);
// return
return $response;
}
/*
* get_post_result
*
* This function will return an array containing id, text and maybe description data
*
* @type function
* @date 7/07/2016
* @since 5.4.0
*
* @param $id (mixed)
* @param $text (string)
* @return (array)
*/
function get_post_result( $id, $text ) {
// vars
$result = array(
'id' => $id,
'text' => $text
);
// return
return $result;
}
/*
* get_post_title
*
* This function returns the HTML for a result
*
* @type function
* @date 1/11/2013
* @since 5.0.0
*
* @param $post (object)
* @param $field (array)
* @param $post_id (int) the post_id to which this value is saved to
* @return (string)
*/
function get_post_title( $post, $field, $post_id = 0, $is_search = 0 ) {
// get post_id
if( !$post_id ) $post_id = acf_get_form_data('post_id');
// vars
$title = acf_get_post_title( $post, $is_search );
// featured_image
if( acf_in_array('featured_image', $field['elements']) ) {
// vars
$class = 'thumbnail';
$thumbnail = acf_get_post_thumbnail($post->ID, array(17, 17));
// icon
if( $thumbnail['type'] == 'icon' ) {
$class .= ' -' . $thumbnail['type'];
}
// append
$title = '<div class="' . $class . '">' . $thumbnail['html'] . '</div>' . $title;
}
// filters
$title = apply_filters('acf/fields/relationship/result', $title, $post, $field, $post_id);
$title = apply_filters('acf/fields/relationship/result/name=' . $field['_name'], $title, $post, $field, $post_id);
$title = apply_filters('acf/fields/relationship/result/key=' . $field['key'], $title, $post, $field, $post_id);
// return
return $title;
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// vars
$values = array();
$atts = array(
'id' => $field['id'],
'class' => "acf-relationship {$field['class']}",
'data-min' => $field['min'],
'data-max' => $field['max'],
'data-s' => '',
'data-post_type' => '',
'data-taxonomy' => '',
'data-paged' => 1,
);
// Lang
if( defined('ICL_LANGUAGE_CODE') ) {
$atts['data-lang'] = ICL_LANGUAGE_CODE;
}
// data types
$field['post_type'] = acf_get_array( $field['post_type'] );
$field['taxonomy'] = acf_get_array( $field['taxonomy'] );
$field['filters'] = acf_get_array( $field['filters'] );
// filters
$filters = array(
'count' => count($field['filters']),
'search' => false,
'post_type' => false,
'taxonomy' => false
);
foreach( $field['filters'] as $filter ) {
$filters[ $filter ] = true;
}
// filter - post_type
if( $filters['post_type'] ) {
// choices
$choices = array(
'' => __('Select post type', 'acf')
);
// get post types
$post_types = acf_get_pretty_post_types($field['post_type']);
// append
$choices = $choices + $post_types;
// set filter
$filters['post_type'] = $choices;
}
// taxonomy filter
if( $filters['taxonomy'] ) {
// vars
$groups = array();
$taxonomies = array();
$choices = array(
'' => __('Select taxonomy', 'acf')
);
// get taxonomies from setting
if( !empty($field['taxonomy']) ) {
$term_groups = acf_decode_taxonomy_terms( $field['taxonomy'] );
$taxonomies = array_keys($term_groups);
// check empty
$taxonomies = empty($taxonomies) ? false : $taxonomies;
} elseif( !empty($field['post_type']) ) {
// loop
foreach( $field['post_type'] as $post_type ) {
// get connected taxonomies
$post_taxonomies = get_object_taxonomies( $post_type );
// loop
foreach( $post_taxonomies as $name ) {
$taxonomies[ $name ] = 1;
}
}
// convert back to array
$taxonomies = array_keys($taxonomies);
// check empty
$taxonomies = empty($taxonomies) ? false : $taxonomies;
}
// terms
if( $taxonomies !== false ) {
$groups = acf_get_taxonomy_terms( $taxonomies );
}
// update $term_groups with specific terms
if( !empty($field['taxonomy']) ) {
foreach( $groups as $taxonomy => $terms ) {
foreach( $terms as $slug => $name ) {
if( !in_array($slug, $field['taxonomy']) ) {
unset($groups[ $taxonomy ][ $slug ]);
}
}
}
}
// append
$choices = $choices + $groups;
// set filter
$filters['taxonomy'] = $choices;
}
?>
<div <?php acf_esc_attr_e($atts); ?>>
<?php acf_hidden_input( array('name' => $field['name'], 'value' => '') ); ?>
<?php
/* filters */
if( $filters['count'] ): ?>
<div class="filters -f<?php echo esc_attr($filters['count']); ?>">
<?php
/* search */
if( $filters['search'] ): ?>
<div class="filter -search">
<span>
<?php acf_text_input( array('placeholder' => __("Search...",'acf'), 'data-filter' => 's') ); ?>
</span>
</div>
<?php endif;
/* post_type */
if( $filters['post_type'] ): ?>
<div class="filter -post_type">
<span>
<?php acf_select_input( array('choices' => $filters['post_type'], 'data-filter' => 'post_type') ); ?>
</span>
</div>
<?php endif;
/* post_type */
if( $filters['taxonomy'] ): ?>
<div class="filter -taxonomy">
<span>
<?php acf_select_input( array('choices' => $filters['taxonomy'], 'data-filter' => 'taxonomy') ); ?>
</span>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="selection">
<div class="choices">
<ul class="acf-bl list"></ul>
</div>
<div class="values">
<ul class="acf-bl list">
<?php if( !empty($field['value']) ):
// get posts
$posts = acf_get_posts(array(
'post__in' => $field['value'],
'post_type' => $field['post_type']
));
// loop
foreach( $posts as $post ): ?>
<li>
<?php acf_hidden_input( array('name' => $field['name'].'[]', 'value' => $post->ID) ); ?>
<span data-id="<?php echo esc_attr($post->ID); ?>" class="acf-rel-item">
<?php echo $this->get_post_title( $post, $field ); ?>
<a href="#" class="acf-icon -minus small dark" data-name="remove_item"></a>
</span>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</div>
</div>
</div>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// vars
$field['min'] = empty($field['min']) ? '' : $field['min'];
$field['max'] = empty($field['max']) ? '' : $field['max'];
// post_type
acf_render_field_setting( $field, array(
'label' => __('Filter by Post Type','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'post_type',
'choices' => acf_get_pretty_post_types(),
'multiple' => 1,
'ui' => 1,
'allow_null' => 1,
'placeholder' => __("All post types",'acf'),
));
// taxonomy
acf_render_field_setting( $field, array(
'label' => __('Filter by Taxonomy','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'taxonomy',
'choices' => acf_get_taxonomy_terms(),
'multiple' => 1,
'ui' => 1,
'allow_null' => 1,
'placeholder' => __("All taxonomies",'acf'),
));
// filters
acf_render_field_setting( $field, array(
'label' => __('Filters','acf'),
'instructions' => '',
'type' => 'checkbox',
'name' => 'filters',
'choices' => array(
'search' => __("Search",'acf'),
'post_type' => __("Post Type",'acf'),
'taxonomy' => __("Taxonomy",'acf'),
),
));
// filters
acf_render_field_setting( $field, array(
'label' => __('Elements','acf'),
'instructions' => __('Selected elements will be displayed in each result','acf'),
'type' => 'checkbox',
'name' => 'elements',
'choices' => array(
'featured_image' => __("Featured Image",'acf'),
),
));
// min
acf_render_field_setting( $field, array(
'label' => __('Minimum posts','acf'),
'instructions' => '',
'type' => 'number',
'name' => 'min',
));
// max
acf_render_field_setting( $field, array(
'label' => __('Maximum posts','acf'),
'instructions' => '',
'type' => 'number',
'name' => 'max',
));
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Format','acf'),
'instructions' => '',
'type' => 'radio',
'name' => 'return_format',
'choices' => array(
'object' => __("Post Object",'acf'),
'id' => __("Post ID",'acf'),
),
'layout' => 'horizontal',
));
}
/*
* 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;
}
// force value to array
$value = acf_get_array( $value );
// convert to int
$value = array_map('intval', $value);
// load posts if needed
if( $field['return_format'] == 'object' ) {
// get posts
$value = acf_get_posts(array(
'post__in' => $value,
'post_type' => $field['post_type']
));
}
// return
return $value;
}
/*
* validate_value
*
* description
*
* @type function
* @date 11/02/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function validate_value( $valid, $value, $field, $input ){
// default
if( empty($value) || !is_array($value) ) {
$value = array();
}
// min
if( count($value) < $field['min'] ) {
$valid = _n( '%s requires at least %s selection', '%s requires at least %s selections', $field['min'], 'acf' );
$valid = sprintf( $valid, $field['label'], $field['min'] );
}
// return
return $valid;
}
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
// validate
if( empty($value) ) {
return $value;
}
// force value to array
$value = acf_get_array( $value );
// array
foreach( $value as $k => $v ){
// object?
if( is_object($v) && isset($v->ID) ) {
$value[ $k ] = $v->ID;
}
}
// save value as strings, so we can clearly search for them in SQL LIKE statements
$value = array_map('strval', $value);
// return
return $value;
}
}
// initialize
acf_register_field_type( 'acf_field_relationship' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,642 @@
<?php
if( ! class_exists('acf_field_select') ) :
class acf_field_select extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'select';
$this->label = _x('Select', 'noun', 'acf');
$this->category = 'choice';
$this->defaults = array(
'multiple' => 0,
'allow_null' => 0,
'choices' => array(),
'default_value' => '',
'ui' => 0,
'ajax' => 0,
'placeholder' => '',
'return_format' => 'value'
);
$this->l10n = array(
'matches_1' => _x('One result is available, press enter to select it.', 'Select2 JS matches_1', 'acf'),
'matches_n' => _x('%d results are available, use up and down arrow keys to navigate.', 'Select2 JS matches_n', 'acf'),
'matches_0' => _x('No matches found', 'Select2 JS matches_0', 'acf'),
'input_too_short_1' => _x('Please enter 1 or more characters', 'Select2 JS input_too_short_1', 'acf' ),
'input_too_short_n' => _x('Please enter %d or more characters', 'Select2 JS input_too_short_n', 'acf' ),
'input_too_long_1' => _x('Please delete 1 character', 'Select2 JS input_too_long_1', 'acf' ),
'input_too_long_n' => _x('Please delete %d characters', 'Select2 JS input_too_long_n', 'acf' ),
'selection_too_long_1' => _x('You can only select 1 item', 'Select2 JS selection_too_long_1', 'acf' ),
'selection_too_long_n' => _x('You can only select %d items', 'Select2 JS selection_too_long_n', 'acf' ),
'load_more' => _x('Loading more results&hellip;', 'Select2 JS load_more', 'acf' ),
'searching' => _x('Searching&hellip;', 'Select2 JS searching', 'acf' ),
'load_fail' => _x('Loading failed', 'Select2 JS load_fail', 'acf' ),
);
// ajax
add_action('wp_ajax_acf/fields/select/query', array($this, 'ajax_query'));
add_action('wp_ajax_nopriv_acf/fields/select/query', array($this, 'ajax_query'));
}
/*
* input_admin_enqueue_scripts
*
* description
*
* @type function
* @date 16/12/2015
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_enqueue_scripts() {
// bail ealry if no enqueue
if( !acf_get_setting('enqueue_select2') ) return;
// globals
global $wp_scripts, $wp_styles;
// vars
$min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
$major = acf_get_setting('select2_version');
$version = '';
$script = '';
$style = '';
// attempt to find 3rd party Select2 version
// - avoid including v3 CSS when v4 JS is already enququed
if( isset($wp_scripts->registered['select2']) ) {
$major = (int) $wp_scripts->registered['select2']->ver;
}
// v4
if( $major == 4 ) {
$version = '4.0';
$script = acf_get_dir("assets/inc/select2/4/select2.full{$min}.js");
$style = acf_get_dir("assets/inc/select2/4/select2{$min}.css");
// v3
} else {
$version = '3.5.2';
$script = acf_get_dir("assets/inc/select2/3/select2{$min}.js");
$style = acf_get_dir("assets/inc/select2/3/select2.css");
}
// enqueue
wp_enqueue_script('select2', $script, array('jquery'), $version );
wp_enqueue_style('select2', $style, '', $version );
}
/*
* ajax_query
*
* description
*
* @type function
* @date 24/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function ajax_query() {
// validate
if( !acf_verify_ajax() ) die();
// get choices
$response = $this->get_ajax_query( $_POST );
// return
acf_send_ajax_results($response);
}
/*
* get_ajax_query
*
* This function will return an array of data formatted for use in a select2 AJAX response
*
* @type function
* @date 15/10/2014
* @since 5.0.9
*
* @param $options (array)
* @return (array)
*/
function get_ajax_query( $options = array() ) {
// defaults
$options = acf_parse_args($options, array(
'post_id' => 0,
's' => '',
'field_key' => '',
'paged' => 1
));
// load field
$field = acf_get_field( $options['field_key'] );
if( !$field ) return false;
// get choices
$choices = acf_get_array($field['choices']);
if( empty($field['choices']) ) return false;
// vars
$results = array();
$s = null;
// search
if( $options['s'] !== '' ) {
// strip slashes (search may be integer)
$s = strval( $options['s'] );
$s = wp_unslash( $s );
}
// loop
foreach( $field['choices'] as $k => $v ) {
// ensure $v is a string
$v = strval( $v );
// if searching, but doesn't exist
if( is_string($s) && stripos($v, $s) === false ) continue;
// append
$results[] = array(
'id' => $k,
'text' => $v
);
}
// vars
$response = array(
'results' => $results
);
// return
return $response;
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// convert
$value = acf_get_array($field['value']);
$choices = acf_get_array($field['choices']);
// placeholder
if( empty($field['placeholder']) ) {
$field['placeholder'] = _x('Select', 'verb', 'acf');
}
// add empty value (allows '' to be selected)
if( empty($value) ) {
$value = array('');
}
// allow null
// - have tried array_merge but this causes keys to re-index if is numeric (post ID's)
if( $field['allow_null'] && !$field['multiple'] ) {
$prepend = array('' => '- ' . $field['placeholder'] . ' -');
$choices = $prepend + $choices;
}
// vars
$select = array(
'id' => $field['id'],
'class' => $field['class'],
'name' => $field['name'],
'data-ui' => $field['ui'],
'data-ajax' => $field['ajax'],
'data-multiple' => $field['multiple'],
'data-placeholder' => $field['placeholder'],
'data-allow_null' => $field['allow_null']
);
// multiple
if( $field['multiple'] ) {
$select['multiple'] = 'multiple';
$select['size'] = 5;
$select['name'] .= '[]';
}
// special atts
if( !empty($field['readonly']) ) $select['readonly'] = 'readonly';
if( !empty($field['disabled']) ) $select['disabled'] = 'disabled';
if( !empty($field['ajax_action']) ) $select['data-ajax_action'] = $field['ajax_action'];
// hidden input
if( $field['ui'] ) {
$v = $value;
if( $field['multiple'] ) {
$v = implode('||', $v);
} else {
$v = acf_maybe_get($v, 0, '');
}
acf_hidden_input(array(
'id' => $field['id'] . '-input',
'name' => $field['name'],
'value' => $v
));
} elseif( $field['multiple'] ) {
acf_hidden_input(array(
'id' => $field['id'] . '-input',
'name' => $field['name']
));
}
// append
$select['value'] = $value;
$select['choices'] = $choices;
// render
acf_select_input( $select );
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// encode choices (convert from array)
$field['choices'] = acf_encode_choices($field['choices']);
$field['default_value'] = acf_encode_choices($field['default_value'], false);
// choices
acf_render_field_setting( $field, array(
'label' => __('Choices','acf'),
'instructions' => __('Enter each choice on a new line.','acf') . '<br /><br />' . __('For more control, you may specify both a value and label like this:','acf'). '<br /><br />' . __('red : Red','acf'),
'name' => 'choices',
'type' => 'textarea',
));
// default_value
acf_render_field_setting( $field, array(
'label' => __('Default Value','acf'),
'instructions' => __('Enter each default value on a new line','acf'),
'name' => 'default_value',
'type' => 'textarea',
));
// allow_null
acf_render_field_setting( $field, array(
'label' => __('Allow Null?','acf'),
'instructions' => '',
'name' => 'allow_null',
'type' => 'true_false',
'ui' => 1,
));
// multiple
acf_render_field_setting( $field, array(
'label' => __('Select multiple values?','acf'),
'instructions' => '',
'name' => 'multiple',
'type' => 'true_false',
'ui' => 1,
));
// ui
acf_render_field_setting( $field, array(
'label' => __('Stylised UI','acf'),
'instructions' => '',
'name' => 'ui',
'type' => 'true_false',
'ui' => 1,
));
// ajax
acf_render_field_setting( $field, array(
'label' => __('Use AJAX to lazy load choices?','acf'),
'instructions' => '',
'name' => 'ajax',
'type' => 'true_false',
'ui' => 1,
));
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Format','acf'),
'instructions' => __('Specify the value returned','acf'),
'type' => 'select',
'name' => 'return_format',
'choices' => array(
'value' => __('Value','acf'),
'label' => __('Label','acf'),
'array' => __('Both (Array)','acf')
)
));
}
/*
* 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 ) {
// ACF4 null
if( $value === 'null' ) return false;
// return
return $value;
}
/*
* update_field()
*
* This filter is appied to the $field before it is saved to the database
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $field - the field array holding all the field options
* @param $post_id - the field group ID (post_type = acf)
*
* @return $field - the modified field
*/
function update_field( $field ) {
// decode choices (convert to array)
$field['choices'] = acf_decode_choices($field['choices']);
$field['default_value'] = acf_decode_choices($field['default_value'], true);
// return
return $field;
}
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
// validate
if( empty($value) ) {
return $value;
}
// array
if( is_array($value) ) {
// save value as strings, so we can clearly search for them in SQL LIKE statements
$value = array_map('strval', $value);
}
// return
return $value;
}
/*
* translate_field
*
* This function will translate field settings
*
* @type function
* @date 8/03/2016
* @since 5.3.2
*
* @param $field (array)
* @return $field
*/
function translate_field( $field ) {
// translate
$field['choices'] = acf_translate( $field['choices'] );
// return
return $field;
}
/*
* 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 ) {
// array
if( acf_is_array($value) ) {
foreach( $value as $i => $v ) {
$value[ $i ] = $this->format_value_single( $v, $post_id, $field );
}
} else {
$value = $this->format_value_single( $value, $post_id, $field );
}
// return
return $value;
}
function format_value_single( $value, $post_id, $field ) {
// bail ealry if is empty
if( acf_is_empty($value) ) return $value;
// vars
$label = acf_maybe_get($field['choices'], $value, $value);
// value
if( $field['return_format'] == 'value' ) {
// do nothing
// label
} elseif( $field['return_format'] == 'label' ) {
$value = $label;
// array
} elseif( $field['return_format'] == 'array' ) {
$value = array(
'value' => $value,
'label' => $label
);
}
// return
return $value;
}
}
// initialize
acf_register_field_type( 'acf_field_select' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,91 @@
<?php
if( ! class_exists('acf_field_separator') ) :
class acf_field_separator extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'separator';
$this->label = __("Separator",'acf');
$this->category = 'layout';
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
/* do nothing */
}
/*
* load_field()
*
* This filter is appied to the $field after it is loaded from the database
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $field - the field array holding all the field options
*
* @return $field - the field array holding all the field options
*/
function load_field( $field ) {
// remove name to avoid caching issue
$field['name'] = '';
// remove required to avoid JS issues
$field['required'] = 0;
// set value other than 'null' to avoid ACF loading / caching issue
$field['value'] = false;
// return
return $field;
}
}
// initialize
acf_register_field_type( 'acf_field_separator' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,162 @@
<?php
if( ! class_exists('acf_field_tab') ) :
class acf_field_tab extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'tab';
$this->label = __("Tab",'acf');
$this->category = 'layout';
$this->defaults = array(
'placement' => 'top',
'endpoint' => 0 // added in 5.2.8
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// vars
$atts = array(
'href' => '',
'class' => 'acf-tab-button',
'data-placement' => $field['placement'],
'data-endpoint' => $field['endpoint'],
'data-key' => $field['key']
);
?>
<a <?php acf_esc_attr_e( $atts ); ?>><?php echo acf_esc_html($field['label']); ?></a>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) to save extra data to the $field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field_settings( $field ) {
/*
// message
$message = '';
$message .= '<p>' . __( 'Use "Tab Fields" to better organize your edit screen by grouping fields together.', 'acf') . '</p>';
$message .= '<p>' . __( 'All fields following this "tab field" (or until another "tab field" is defined) will be grouped together using this field\'s label as the tab heading.','acf') . '</p>';
// default_value
acf_render_field_setting( $field, array(
'label' => __('Instructions','acf'),
'instructions' => '',
'name' => 'notes',
'type' => 'message',
'message' => $message,
));
*/
// preview_size
acf_render_field_setting( $field, array(
'label' => __('Placement','acf'),
'type' => 'select',
'name' => 'placement',
'choices' => array(
'top' => __("Top aligned", 'acf'),
'left' => __("Left Aligned", 'acf'),
)
));
// endpoint
acf_render_field_setting( $field, array(
'label' => __('Endpoint','acf'),
'instructions' => __('Define an endpoint for the previous tabs to stop. This will start a new group of tabs.', 'acf'),
'name' => 'endpoint',
'type' => 'true_false',
'ui' => 1,
));
}
/*
* load_field()
*
* This filter is appied to the $field after it is loaded from the database
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $field - the field array holding all the field options
*
* @return $field - the field array holding all the field options
*/
function load_field( $field ) {
// remove name to avoid caching issue
$field['name'] = '';
// remove required to avoid JS issues
$field['required'] = 0;
// set value other than 'null' to avoid ACF loading / caching issue
$field['value'] = false;
// return
return $field;
}
}
// initialize
acf_register_field_type( 'acf_field_tab' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,171 @@
<?php
if( ! class_exists('acf_field_text') ) :
class acf_field_text extends acf_field {
/*
* initialize
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'text';
$this->label = __("Text",'acf');
$this->defaults = array(
'default_value' => '',
'maxlength' => '',
'placeholder' => '',
'prepend' => '',
'append' => ''
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// vars
$atts = array();
$keys = array( 'type', 'id', 'class', 'name', 'value', 'placeholder', 'maxlength', 'pattern' );
$keys2 = array( 'readonly', 'disabled', 'required' );
$html = '';
// prepend
if( $field['prepend'] !== '' ) {
$field['class'] .= ' acf-is-prepended';
$html .= '<div class="acf-input-prepend">' . acf_esc_html($field['prepend']) . '</div>';
}
// append
if( $field['append'] !== '' ) {
$field['class'] .= ' acf-is-appended';
$html .= '<div class="acf-input-append">' . acf_esc_html($field['append']) . '</div>';
}
// atts (value="123")
foreach( $keys as $k ) {
if( isset($field[ $k ]) ) $atts[ $k ] = $field[ $k ];
}
// atts2 (disabled="disabled")
foreach( $keys2 as $k ) {
if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
}
// remove empty atts
$atts = acf_clean_atts( $atts );
// render
$html .= '<div class="acf-input-wrap">' . acf_get_text_input( $atts ) . '</div>';
// return
echo $html;
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) to save extra data to the $field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field_settings( $field ) {
// default_value
acf_render_field_setting( $field, array(
'label' => __('Default Value','acf'),
'instructions' => __('Appears when creating a new post','acf'),
'type' => 'text',
'name' => 'default_value',
));
// placeholder
acf_render_field_setting( $field, array(
'label' => __('Placeholder Text','acf'),
'instructions' => __('Appears within the input','acf'),
'type' => 'text',
'name' => 'placeholder',
));
// prepend
acf_render_field_setting( $field, array(
'label' => __('Prepend','acf'),
'instructions' => __('Appears before the input','acf'),
'type' => 'text',
'name' => 'prepend',
));
// append
acf_render_field_setting( $field, array(
'label' => __('Append','acf'),
'instructions' => __('Appears after the input','acf'),
'type' => 'text',
'name' => 'append',
));
// maxlength
acf_render_field_setting( $field, array(
'label' => __('Character Limit','acf'),
'instructions' => __('Leave blank for no limit','acf'),
'type' => 'number',
'name' => 'maxlength',
));
}
}
// initialize
acf_register_field_type( 'acf_field_text' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,203 @@
<?php
if( ! class_exists('acf_field_textarea') ) :
class acf_field_textarea extends acf_field {
/*
* initialize
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'textarea';
$this->label = __("Text Area",'acf');
$this->defaults = array(
'default_value' => '',
'new_lines' => '',
'maxlength' => '',
'placeholder' => '',
'rows' => ''
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// vars
$atts = array();
$keys = array( 'id', 'class', 'name', 'value', 'placeholder', 'rows', 'maxlength' );
$keys2 = array( 'readonly', 'disabled', 'required' );
// rows
if( !$field['rows'] ) {
$field['rows'] = 8;
}
// atts (value="123")
foreach( $keys as $k ) {
if( isset($field[ $k ]) ) $atts[ $k ] = $field[ $k ];
}
// atts2 (disabled="disabled")
foreach( $keys2 as $k ) {
if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
}
// remove empty atts
$atts = acf_clean_atts( $atts );
// return
acf_textarea_input( $atts );
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) to save extra data to the $field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field_settings( $field ) {
// default_value
acf_render_field_setting( $field, array(
'label' => __('Default Value','acf'),
'instructions' => __('Appears when creating a new post','acf'),
'type' => 'textarea',
'name' => 'default_value',
));
// placeholder
acf_render_field_setting( $field, array(
'label' => __('Placeholder Text','acf'),
'instructions' => __('Appears within the input','acf'),
'type' => 'text',
'name' => 'placeholder',
));
// maxlength
acf_render_field_setting( $field, array(
'label' => __('Character Limit','acf'),
'instructions' => __('Leave blank for no limit','acf'),
'type' => 'number',
'name' => 'maxlength',
));
// rows
acf_render_field_setting( $field, array(
'label' => __('Rows','acf'),
'instructions' => __('Sets the textarea height','acf'),
'type' => 'number',
'name' => 'rows',
'placeholder' => 8
));
// formatting
acf_render_field_setting( $field, array(
'label' => __('New Lines','acf'),
'instructions' => __('Controls how new lines are rendered','acf'),
'type' => 'select',
'name' => 'new_lines',
'choices' => array(
'wpautop' => __("Automatically add paragraphs",'acf'),
'br' => __("Automatically add &lt;br&gt;",'acf'),
'' => __("No Formatting",'acf')
)
));
}
/*
* format_value()
*
* This filter is applied 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 or not for template
if( empty($value) || !is_string($value) ) {
return $value;
}
// new lines
if( $field['new_lines'] == 'wpautop' ) {
$value = wpautop($value);
} elseif( $field['new_lines'] == 'br' ) {
$value = nl2br($value);
}
// return
return $value;
}
}
// initialize
acf_register_field_type( 'acf_field_textarea' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,169 @@
<?php
if( ! class_exists('acf_field_time_picker') ) :
class acf_field_time_picker extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'time_picker';
$this->label = __("Time Picker",'acf');
$this->category = 'jquery';
$this->defaults = array(
'display_format' => 'g:i a',
'return_format' => 'g:i a'
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// format value
$display_value = '';
if( $field['value'] ) {
$display_value = acf_format_date( $field['value'], $field['display_format'] );
}
// vars
$div = array(
'class' => 'acf-time-picker acf-input-wrap',
'data-time_format' => acf_convert_time_to_js($field['display_format'])
);
$hidden_input = array(
'id' => $field['id'],
'class' => 'input-alt',
'type' => 'hidden',
'name' => $field['name'],
'value' => $field['value'],
);
$text_input = array(
'class' => 'input',
'type' => 'text',
'value' => $display_value,
);
// html
?>
<div <?php acf_esc_attr_e( $div ); ?>>
<?php acf_hidden_input( $hidden_input ); ?>
<?php acf_text_input( $text_input ); ?>
</div>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// vars
$g_i_a = date('g:i a');
$H_i_s = date('H:i:s');
// display_format
acf_render_field_setting( $field, array(
'label' => __('Display Format','acf'),
'instructions' => __('The format displayed when editing a post','acf'),
'type' => 'radio',
'name' => 'display_format',
'other_choice' => 1,
'choices' => array(
'g:i a' => '<span>' . $g_i_a . '</span><code>g:i a</code>',
'H:i:s' => '<span>' . $H_i_s . '</span><code>H:i:s</code>',
'other' => '<span>' . __('Custom:','acf') . '</span>'
)
));
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Format','acf'),
'instructions' => __('The format returned via template functions','acf'),
'type' => 'radio',
'name' => 'return_format',
'other_choice' => 1,
'choices' => array(
'g:i a' => '<span>' . $g_i_a . '</span><code>g:i a</code>',
'H:i:s' => '<span>' . $H_i_s . '</span><code>H:i:s</code>',
'other' => '<span>' . __('Custom:','acf') . '</span>'
)
));
}
/*
* 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 ) {
return acf_format_date( $value, $field['return_format'] );
}
}
// initialize
acf_register_field_type( 'acf_field_time_picker' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,269 @@
<?php
if( ! class_exists('acf_field_true_false') ) :
class acf_field_true_false extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'true_false';
$this->label = __('True / False','acf');
$this->category = 'choice';
$this->defaults = array(
'default_value' => 0,
'message' => '',
'ui' => 0,
'ui_on_text' => '',
'ui_off_text' => '',
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// vars
$input = array(
'type' => 'checkbox',
'id' => $field['id'],
'name' => $field['name'],
'value' => '1',
'class' => $field['class'],
'autocomplete' => 'off'
);
$hidden = array(
'name' => $field['name'],
'value' => 0
);
$active = $field['value'] ? true : false;
$switch = '';
// checked
if( $active ) $input['checked'] = 'checked';
// ui
if( $field['ui'] ) {
// vars
if( $field['ui_on_text'] === '' ) $field['ui_on_text'] = __('Yes', 'acf');
if( $field['ui_off_text'] === '' ) $field['ui_off_text'] = __('No', 'acf');
// update input
$input['class'] .= ' acf-switch-input';
//$input['style'] = 'display:none;';
$switch .= '<div class="acf-switch' . ($active ? ' -on' : '') . '">';
$switch .= '<span class="acf-switch-on">'.$field['ui_on_text'].'</span>';
$switch .= '<span class="acf-switch-off">'.$field['ui_off_text'].'</span>';
$switch .= '<div class="acf-switch-slider"></div>';
$switch .= '</div>';
}
?>
<div class="acf-true-false">
<?php acf_hidden_input($hidden); ?>
<label>
<input <?php echo acf_esc_attr($input); ?>/>
<?php if( $switch ) echo acf_esc_html($switch); ?>
<?php if( $field['message'] ): ?><span class="message"><?php echo acf_esc_html($field['message']); ?></span><?php endif; ?>
</label>
</div>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// message
acf_render_field_setting( $field, array(
'label' => __('Message','acf'),
'instructions' => __('Displays text alongside the checkbox','acf'),
'type' => 'text',
'name' => 'message',
));
// default_value
acf_render_field_setting( $field, array(
'label' => __('Default Value','acf'),
'instructions' => '',
'type' => 'true_false',
'name' => 'default_value',
));
// ui
acf_render_field_setting( $field, array(
'label' => __('Stylised UI','acf'),
'instructions' => '',
'type' => 'true_false',
'name' => 'ui',
'ui' => 1,
'class' => 'acf-field-object-true-false-ui'
));
// on_text
acf_render_field_setting( $field, array(
'label' => __('On Text','acf'),
'instructions' => __('Text shown when active','acf'),
'type' => 'text',
'name' => 'ui_on_text',
'placeholder' => __('Yes', 'acf')
));
// on_text
acf_render_field_setting( $field, array(
'label' => __('Off Text','acf'),
'instructions' => __('Text shown when inactive','acf'),
'type' => 'text',
'name' => 'ui_off_text',
'placeholder' => __('No', 'acf')
));
}
/*
* 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 ) {
return empty($value) ? false : true;
}
/*
* validate_value
*
* description
*
* @type function
* @date 11/02/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function validate_value( $valid, $value, $field, $input ){
// bail early if not required
if( ! $field['required'] ) {
return $valid;
}
// value may be '0'
if( !$value ) {
return false;
}
// return
return $valid;
}
/*
* translate_field
*
* This function will translate field settings
*
* @type function
* @date 8/03/2016
* @since 5.3.2
*
* @param $field (array)
* @return $field
*/
function translate_field( $field ) {
// translate
$field['message'] = acf_translate( $field['message'] );
$field['ui_on_text'] = acf_translate( $field['ui_on_text'] );
$field['ui_off_text'] = acf_translate( $field['ui_off_text'] );
// return
return $field;
}
}
// initialize
acf_register_field_type( 'acf_field_true_false' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,169 @@
<?php
if( ! class_exists('acf_field_url') ) :
class acf_field_url extends acf_field {
/*
* initialize
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'url';
$this->label = __("Url",'acf');
$this->defaults = array(
'default_value' => '',
'placeholder' => '',
);
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// vars
$atts = array();
$keys = array( 'type', 'id', 'class', 'name', 'value', 'placeholder', 'pattern' );
$keys2 = array( 'readonly', 'disabled', 'required' );
$html = '';
// atts (value="123")
foreach( $keys as $k ) {
if( isset($field[ $k ]) ) $atts[ $k ] = $field[ $k ];
}
// atts2 (disabled="disabled")
foreach( $keys2 as $k ) {
if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
}
// remove empty atts
$atts = acf_clean_atts( $atts );
// render
$html .= '<div class="acf-input-wrap acf-url">';
$html .= '<i class="acf-icon -globe -small"></i>' . acf_get_text_input( $atts ) ;
$html .= '</div>';
// return
echo $html;
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// default_value
acf_render_field_setting( $field, array(
'label' => __('Default Value','acf'),
'instructions' => __('Appears when creating a new post','acf'),
'type' => 'text',
'name' => 'default_value',
));
// placeholder
acf_render_field_setting( $field, array(
'label' => __('Placeholder Text','acf'),
'instructions' => __('Appears within the input','acf'),
'type' => 'text',
'name' => 'placeholder',
));
}
/*
* validate_value
*
* description
*
* @type function
* @date 11/02/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function validate_value( $valid, $value, $field, $input ){
// bail early if empty
if( empty($value) ) {
return $valid;
}
if( strpos($value, '://') !== false ) {
// url
} elseif( strpos($value, '//') === 0 ) {
// protocol relative url
} else {
$valid = __('Value must be a valid URL', 'acf');
}
// return
return $valid;
}
}
// initialize
acf_register_field_type( 'acf_field_url' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,586 @@
<?php
if( ! class_exists('acf_field_user') ) :
class acf_field_user extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'user';
$this->label = __("User",'acf');
$this->category = 'relational';
$this->defaults = array(
'role' => '',
'multiple' => 0,
'allow_null' => 0,
);
// extra
add_action('wp_ajax_acf/fields/user/query', array($this, 'ajax_query'));
add_action('wp_ajax_nopriv_acf/fields/user/query', array($this, 'ajax_query'));
}
/*
* ajax_query
*
* description
*
* @type function
* @date 24/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function ajax_query() {
// validate
if( !acf_verify_ajax() ) die();
// get choices
$response = $this->get_ajax_query( $_POST );
// return
acf_send_ajax_results($response);
}
/*
* get_ajax_query
*
* This function will return an array of data formatted for use in a select2 AJAX response
*
* @type function
* @date 15/10/2014
* @since 5.0.9
*
* @param $options (array)
* @return (array)
*/
function get_ajax_query( $options = array() ) {
// defaults
$options = acf_parse_args($options, array(
'post_id' => 0,
's' => '',
'field_key' => '',
'paged' => 1
));
// load field
$field = acf_get_field( $options['field_key'] );
if( !$field ) return false;
// vars
$results = array();
$args = array();
$s = false;
$is_search = false;
// paged
$args['users_per_page'] = 20;
$args['paged'] = $options['paged'];
// search
if( $options['s'] !== '' ) {
// strip slashes (search may be integer)
$s = wp_unslash( strval($options['s']) );
// update vars
$args['s'] = $s;
$is_search = true;
}
// role
if( !empty($field['role']) ) {
$args['role'] = acf_get_array( $field['role'] );
}
// search
if( $is_search ) {
// append to $args
$args['search'] = '*' . $options['s'] . '*';
// add reference
$this->field = $field;
// add filter to modify search colums
add_filter('user_search_columns', array($this, 'user_search_columns'), 10, 3);
}
// filters
$args = apply_filters("acf/fields/user/query", $args, $field, $options['post_id']);
$args = apply_filters("acf/fields/user/query/name={$field['_name']}", $args, $field, $options['post_id']);
$args = apply_filters("acf/fields/user/query/key={$field['key']}", $args, $field, $options['post_id']);
// get users
$groups = acf_get_grouped_users( $args );
// loop
if( !empty($groups) ) {
foreach( array_keys($groups) as $group_title ) {
// vars
$users = acf_extract_var( $groups, $group_title );
$data = array(
'text' => $group_title,
'children' => array()
);
// append users
foreach( array_keys($users) as $user_id ) {
$users[ $user_id ] = $this->get_result( $users[ $user_id ], $field, $options['post_id'] );
};
// order by search
if( $is_search && empty($args['orderby']) ) {
$users = acf_order_by_search( $users, $args['s'] );
}
// append to $data
foreach( $users as $id => $title ) {
$data['children'][] = array(
'id' => $id,
'text' => $title
);
}
// append to $r
$results[] = $data;
}
}
// optgroup or single
if( !empty($args['role']) && count($args['role']) == 1 ) {
$results = $results[0]['children'];
}
// vars
$response = array(
'results' => $results,
'limit' => $args['users_per_page']
);
// return
return $response;
}
/*
* get_result
*
* This function returns the HTML for a result
*
* @type function
* @date 1/11/2013
* @since 5.0.0
*
* @param $post (object)
* @param $field (array)
* @param $post_id (int) the post_id to which this value is saved to
* @return (string)
*/
function get_result( $user, $field, $post_id = 0 ) {
// get post_id
if( !$post_id ) $post_id = acf_get_form_data('post_id');
// vars
$result = $user->user_login;
// append name
if( $user->first_name ) {
$result .= ' (' . $user->first_name;
if( $user->last_name ) {
$result .= ' ' . $user->last_name;
}
$result .= ')';
}
// filters
$result = apply_filters("acf/fields/user/result", $result, $user, $field, $post_id);
$result = apply_filters("acf/fields/user/result/name={$field['_name']}", $result, $user, $field, $post_id);
$result = apply_filters("acf/fields/user/result/key={$field['key']}", $result, $user, $field, $post_id);
// return
return $result;
}
/*
* user_search_columns
*
* This function will modify the columns which the user AJAX search looks in
*
* @type function
* @date 17/06/2014
* @since 5.0.0
*
* @param $columns (array)
* @return $columns
*/
function user_search_columns( $columns, $search, $WP_User_Query ) {
// bail early if no field
if( empty($this->field) ) {
return $columns;
}
// vars
$field = $this->field;
// filter for 3rd party customization
$columns = apply_filters("acf/fields/user/search_columns", $columns, $search, $WP_User_Query, $field);
$columns = apply_filters("acf/fields/user/search_columns/name={$field['_name']}", $columns, $search, $WP_User_Query, $field);
$columns = apply_filters("acf/fields/user/search_columns/key={$field['key']}", $columns, $search, $WP_User_Query, $field);
// return
return $columns;
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @type action
* @since 3.6
* @date 23/01/13
*
* @param $field - an array holding all the field's data
*/
function render_field( $field ) {
// Change Field into a select
$field['type'] = 'select';
$field['ui'] = 1;
$field['ajax'] = 1;
$field['choices'] = array();
// populate choices
if( !empty($field['value']) ) {
// force value to array
$field['value'] = acf_get_array( $field['value'] );
// convert values to int
$field['value'] = array_map('intval', $field['value']);
$users = get_users(array(
'include' => $field['value']
));
if( !empty($users) ) {
foreach( $users as $user ) {
$field['choices'][ $user->ID ] = $this->get_result( $user, $field );
}
}
}
// render
acf_render_field( $field );
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
acf_render_field_setting( $field, array(
'label' => __('Filter by role','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'role',
'choices' => acf_get_pretty_user_roles(),
'multiple' => 1,
'ui' => 1,
'allow_null' => 1,
'placeholder' => __("All user roles",'acf'),
));
// allow_null
acf_render_field_setting( $field, array(
'label' => __('Allow Null?','acf'),
'instructions' => '',
'name' => 'allow_null',
'type' => 'true_false',
'ui' => 1,
));
// multiple
acf_render_field_setting( $field, array(
'label' => __('Select multiple values?','acf'),
'instructions' => '',
'name' => 'multiple',
'type' => 'true_false',
'ui' => 1,
));
}
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
// array?
if( is_array($value) && isset($value['ID']) ) {
$value = $value['ID'];
}
// object?
if( is_object($value) && isset($value->ID) ) {
$value = $value->ID;
}
// return
return $value;
}
/*
* 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 ) {
// ACF4 null
if( $value === 'null' ) {
return false;
}
// return
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;
}
// force value to array
$value = acf_get_array( $value );
// convert values to int
$value = array_map('intval', $value);
// load users
foreach( array_keys($value) as $i ) {
// vars
$user_id = $value[ $i ];
$user_data = get_userdata( $user_id );
//cope with deleted users by @adampope
if( !is_object($user_data) ) {
unset( $value[ $i ] );
continue;
}
// append to array
$value[ $i ] = array();
$value[ $i ]['ID'] = $user_id;
$value[ $i ]['user_firstname'] = $user_data->user_firstname;
$value[ $i ]['user_lastname'] = $user_data->user_lastname;
$value[ $i ]['nickname'] = $user_data->nickname;
$value[ $i ]['user_nicename'] = $user_data->user_nicename;
$value[ $i ]['display_name'] = $user_data->display_name;
$value[ $i ]['user_email'] = $user_data->user_email;
$value[ $i ]['user_url'] = $user_data->user_url;
$value[ $i ]['user_registered'] = $user_data->user_registered;
$value[ $i ]['user_description'] = $user_data->user_description;
$value[ $i ]['user_avatar'] = get_avatar( $user_id );
}
// convert back from array if neccessary
if( !$field['multiple'] ) {
$value = array_shift($value);
}
// return value
return $value;
}
}
// initialize
acf_register_field_type( 'acf_field_user' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,508 @@
<?php
if( ! class_exists('acf_field_wysiwyg') ) :
class acf_field_wysiwyg extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'wysiwyg';
$this->label = __("Wysiwyg Editor",'acf');
$this->category = 'content';
$this->defaults = array(
'tabs' => 'all',
'toolbar' => 'full',
'media_upload' => 1,
'default_value' => '',
'delay' => 0
);
// add acf_the_content filters
$this->add_filters();
}
/*
* add_filters
*
* This function will add filters to 'acf_the_content'
*
* @type function
* @date 20/09/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function add_filters() {
// wp-includes/class-wp-embed.php
if( !empty($GLOBALS['wp_embed']) ) {
add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 );
add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
}
// wp-includes/default-filters.php
add_filter( 'acf_the_content', 'capital_P_dangit', 11 );
add_filter( 'acf_the_content', 'wptexturize' );
add_filter( 'acf_the_content', 'convert_smilies', 20 );
// Removed in 4.4
if( acf_version_compare('wp', '<', '4.4') ) {
add_filter( 'acf_the_content', 'convert_chars' );
}
add_filter( 'acf_the_content', 'wpautop' );
add_filter( 'acf_the_content', 'shortcode_unautop' );
// should only be for the_content (causes double image on attachment page)
//add_filter( 'acf_the_content', 'prepend_attachment' );
// Added in 4.4
if( function_exists('wp_make_content_images_responsive') ) {
add_filter( 'acf_the_content', 'wp_make_content_images_responsive' );
}
add_filter( 'acf_the_content', 'do_shortcode', 11);
}
/*
* get_toolbars
*
* This function will return an array of toolbars for the WYSIWYG field
*
* @type function
* @date 18/04/2014
* @since 5.0.0
*
* @param n/a
* @return (array)
*/
function get_toolbars() {
// vars
$editor_id = 'acf_content';
// toolbars
$toolbars = array();
$mce_buttons = 'formatselect, bold, italic, bullist, numlist, blockquote, alignleft, aligncenter, alignright, link, unlink, wp_more, spellchecker, fullscreen, wp_adv';
$mce_buttons_2 = 'strikethrough, hr, forecolor, pastetext, removeformat, charmap, outdent, indent, undo, redo, wp_help';
$teeny_mce_buttons = 'bold, italic, underline, blockquote, strikethrough, bullist, numlist, alignleft, aligncenter, alignright, undo, redo, link, unlink, fullscreen';
// WP < 3.9
if( acf_version_compare('wp', '<', '3.9') ) {
$mce_buttons = 'bold, italic, strikethrough, bullist, numlist, blockquote, justifyleft, justifycenter, justifyright, link, unlink, wp_more, spellchecker, fullscreen, wp_adv';
$mce_buttons_2 = 'formatselect, underline, justifyfull, forecolor, pastetext, pasteword, removeformat, charmap, outdent, indent, undo, redo, wp_help';
$teeny_mce_buttons = 'bold, italic, underline, blockquote, strikethrough, bullist, numlist, justifyleft, justifycenter, justifyright, undo, redo, link, unlink, fullscreen';
// WP < 4.7
} elseif( acf_version_compare('wp', '<', '4.7') ) {
$mce_buttons = 'bold, italic, strikethrough, bullist, numlist, blockquote, hr, alignleft, aligncenter, alignright, link, unlink, wp_more, spellchecker, fullscreen, wp_adv';
$mce_buttons_2 = 'formatselect, underline, alignjustify, forecolor, pastetext, removeformat, charmap, outdent, indent, undo, redo, wp_help';
//$teeny_mce_buttons = 'bold, italic, underline, blockquote, strikethrough, bullist, numlist, alignleft, aligncenter, alignright, undo, redo, link, unlink, fullscreen';
}
// explode
$mce_buttons = explode(', ', $mce_buttons);
$mce_buttons_2 = explode(', ', $mce_buttons_2);
$teeny_mce_buttons = explode(', ', $teeny_mce_buttons);
// Full
$toolbars['Full'] = array(
1 => apply_filters('mce_buttons', $mce_buttons, $editor_id),
2 => apply_filters('mce_buttons_2', $mce_buttons_2, $editor_id),
3 => apply_filters('mce_buttons_3', array(), $editor_id),
4 => apply_filters('mce_buttons_4', array(), $editor_id)
);
// Basic
$toolbars['Basic'] = array(
1 => apply_filters('teeny_mce_buttons', $teeny_mce_buttons, $editor_id)
);
// Filter for 3rd party
$toolbars = apply_filters( 'acf/fields/wysiwyg/toolbars', $toolbars );
// return
return $toolbars;
}
/*
* input_admin_footer
*
* description
*
* @type function
* @date 6/03/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function input_admin_footer() {
// vars
$json = array();
$toolbars = $this->get_toolbars();
// bail ealry if no toolbars
if( empty($toolbars) ) {
return;
}
// loop through toolbars
foreach( $toolbars as $label => $rows ) {
// vars
$label = sanitize_title( $label );
$label = str_replace('-', '_', $label);
// append to $json
$json[ $label ] = array();
// convert to strings
if( !empty($rows) ) {
foreach( $rows as $i => $row ) {
$json[ $label ][ $i ] = implode(',', $row);
}
}
}
?>
<script type="text/javascript">
if( acf ) acf.tinymce.toolbars = <?php echo wp_json_encode($json); ?>;
</script>
<?php
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function render_field( $field ) {
// enqueue
acf_enqueue_uploader();
// vars
$id = uniqid('acf-editor-');
$default_editor = 'html';
$show_tabs = true;
$button = '';
// get height
$height = acf_get_user_setting('wysiwyg_height', 300);
$height = max( $height, 300 ); // minimum height is 300
// detect mode
if( !user_can_richedit() ) {
$show_tabs = false;
} elseif( $field['tabs'] == 'visual' ) {
// case: visual tab only
$default_editor = 'tinymce';
$show_tabs = false;
} elseif( $field['tabs'] == 'text' ) {
// case: text tab only
$show_tabs = false;
} elseif( wp_default_editor() == 'tinymce' ) {
// case: both tabs
$default_editor = 'tinymce';
}
// must be logged in tp upload
if( !current_user_can('upload_files') ) {
$field['media_upload'] = 0;
}
// mode
$switch_class = ($default_editor === 'html') ? 'html-active' : 'tmce-active';
// filter value for editor
remove_filter( 'acf_the_editor_content', 'format_for_editor', 10, 2 );
remove_filter( 'acf_the_editor_content', 'wp_htmledit_pre', 10, 1 );
remove_filter( 'acf_the_editor_content', 'wp_richedit_pre', 10, 1 );
// WP 4.3
if( acf_version_compare('wp', '>=', '4.3') ) {
add_filter( 'acf_the_editor_content', 'format_for_editor', 10, 2 );
$button = 'data-wp-editor-id="' . $id . '"';
// WP < 4.3
} else {
$function = ($default_editor === 'html') ? 'wp_htmledit_pre' : 'wp_richedit_pre';
add_filter('acf_the_editor_content', $function, 10, 1);
$button = 'onclick="switchEditors.switchto(this);"';
}
// filter
$field['value'] = apply_filters( 'acf_the_editor_content', $field['value'], $default_editor );
// attr
$wrap = array(
'id' => 'wp-' . $id . '-wrap',
'class' => 'acf-editor-wrap wp-core-ui wp-editor-wrap ' . $switch_class,
'data-toolbar' => $field['toolbar']
);
// delay
if( $field['delay'] ) {
$wrap['class'] .= ' delay';
}
// vars
$textarea = acf_get_textarea_input(array(
'id' => $id,
'class' => 'wp-editor-area',
'name' => $field['name'],
'style' => $height ? "height:{$height}px;" : '',
'value' => '%s'
));
?>
<div <?php acf_esc_attr_e($wrap); ?>>
<div id="wp-<?php echo $id; ?>-editor-tools" class="wp-editor-tools hide-if-no-js">
<?php if( $field['media_upload'] ): ?>
<div id="wp-<?php echo $id; ?>-media-buttons" class="wp-media-buttons">
<?php do_action( 'media_buttons', $id ); ?>
</div>
<?php endif; ?>
<?php if( user_can_richedit() && $show_tabs ): ?>
<div class="wp-editor-tabs">
<button id="<?php echo $id; ?>-tmce" class="wp-switch-editor switch-tmce" <?php echo $button; ?> type="button"><?php echo __('Visual', 'acf'); ?></button>
<button id="<?php echo $id; ?>-html" class="wp-switch-editor switch-html" <?php echo $button; ?> type="button"><?php echo _x( 'Text', 'Name for the Text editor tab (formerly HTML)', 'acf' ); ?></button>
</div>
<?php endif; ?>
</div>
<div id="wp-<?php echo $id; ?>-editor-container" class="wp-editor-container">
<?php if( $field['delay'] ): ?>
<div class="acf-editor-toolbar"><?php _e('Click to initialize TinyMCE', 'acf'); ?></div>
<?php endif; ?>
<?php printf( $textarea, $field['value'] ); ?>
</div>
</div>
<?php
}
/*
* render_field_settings()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) 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 render_field_settings( $field ) {
// vars
$toolbars = $this->get_toolbars();
$choices = array();
if( !empty($toolbars) ) {
foreach( $toolbars as $k => $v ) {
$label = $k;
$name = sanitize_title( $label );
$name = str_replace('-', '_', $name);
$choices[ $name ] = $label;
}
}
// default_value
acf_render_field_setting( $field, array(
'label' => __('Default Value','acf'),
'instructions' => __('Appears when creating a new post','acf'),
'type' => 'textarea',
'name' => 'default_value',
));
// tabs
acf_render_field_setting( $field, array(
'label' => __('Tabs','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'tabs',
'choices' => array(
'all' => __("Visual & Text",'acf'),
'visual' => __("Visual Only",'acf'),
'text' => __("Text Only",'acf'),
)
));
// toolbar
acf_render_field_setting( $field, array(
'label' => __('Toolbar','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'toolbar',
'choices' => $choices
));
// media_upload
acf_render_field_setting( $field, array(
'label' => __('Show Media Upload Buttons?','acf'),
'instructions' => '',
'name' => 'media_upload',
'type' => 'true_false',
'ui' => 1,
));
// delay
acf_render_field_setting( $field, array(
'label' => __('Delay initialization?','acf'),
'instructions' => __('TinyMCE will not be initalized until field is clicked','acf'),
'name' => 'delay',
'type' => 'true_false',
'ui' => 1,
));
}
/*
* 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 filters
$value = apply_filters( 'acf_the_content', $value );
// follow the_content function in /wp-includes/post-template.php
$value = str_replace(']]>', ']]&gt;', $value);
return $value;
}
}
// initialize
acf_register_field_type( 'acf_field_wysiwyg' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,277 @@
<?php
if( ! class_exists('acf_field') ) :
class acf_field {
// vars
var $name = '',
$label = '',
$category = 'basic',
$defaults = array(),
$l10n = array(),
$public = true;
/*
* __construct
*
* This function will initialize the field type
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// initialize
$this->initialize();
// register info
acf_register_field_type_info(array(
'label' => $this->label,
'name' => $this->name,
'category' => $this->category,
'public' => $this->public
));
// value
$this->add_field_filter('acf/load_value', array($this, 'load_value'), 10, 3);
$this->add_field_filter('acf/update_value', array($this, 'update_value'), 10, 3);
$this->add_field_filter('acf/format_value', array($this, 'format_value'), 10, 3);
$this->add_field_filter('acf/validate_value', array($this, 'validate_value'), 10, 4);
$this->add_field_action('acf/delete_value', array($this, 'delete_value'), 10, 3);
// field
$this->add_field_filter('acf/validate_field', array($this, 'validate_field'), 10, 1);
$this->add_field_filter('acf/load_field', array($this, 'load_field'), 10, 1);
$this->add_field_filter('acf/update_field', array($this, 'update_field'), 10, 1);
$this->add_field_filter('acf/duplicate_field', array($this, 'duplicate_field'), 10, 1);
$this->add_field_action('acf/delete_field', array($this, 'delete_field'), 10, 1);
$this->add_field_action('acf/render_field', array($this, 'render_field'), 9, 1);
$this->add_field_action('acf/render_field_settings', array($this, 'render_field_settings'), 9, 1);
$this->add_field_filter('acf/prepare_field', array($this, 'prepare_field'), 10, 1);
$this->add_field_filter('acf/translate_field', array($this, 'translate_field'), 10, 1);
// input actions
$this->add_action("acf/input/admin_enqueue_scripts", array($this, 'input_admin_enqueue_scripts'), 10, 0);
$this->add_action("acf/input/admin_head", array($this, 'input_admin_head'), 10, 0);
$this->add_action("acf/input/form_data", array($this, 'input_form_data'), 10, 1);
$this->add_filter("acf/input/admin_l10n", array($this, 'input_admin_l10n'), 10, 1);
$this->add_action("acf/input/admin_footer", array($this, 'input_admin_footer'), 10, 1);
// field group actions
$this->add_action("acf/field_group/admin_enqueue_scripts", array($this, 'field_group_admin_enqueue_scripts'), 10, 0);
$this->add_action("acf/field_group/admin_head", array($this, 'field_group_admin_head'), 10, 0);
$this->add_action("acf/field_group/admin_footer", array($this, 'field_group_admin_footer'), 10, 0);
}
/*
* initialize
*
* This function will initialize the field type
*
* @type function
* @date 27/6/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function initialize() {
/* do nothing */
}
/*
* add_filter
*
* This function checks if the function is_callable before adding the filter
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param $tag (string)
* @param $function_to_add (string)
* @param $priority (int)
* @param $accepted_args (int)
* @return n/a
*/
function add_filter( $tag = '', $function_to_add = '', $priority = 10, $accepted_args = 1 ) {
// bail early if no callable
if( !is_callable($function_to_add) ) return;
// add
add_filter( $tag, $function_to_add, $priority, $accepted_args );
}
/*
* add_field_filter
*
* This function will add a field type specific filter
*
* @type function
* @date 29/09/2016
* @since 5.4.0
*
* @param $tag (string)
* @param $function_to_add (string)
* @param $priority (int)
* @param $accepted_args (int)
* @return n/a
*/
function add_field_filter( $tag = '', $function_to_add = '', $priority = 10, $accepted_args = 1 ) {
// append
$tag .= '/type=' . $this->name;
// add
$this->add_filter( $tag, $function_to_add, $priority, $accepted_args );
}
/*
* add_action
*
* This function checks if the function is_callable before adding the action
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param $tag (string)
* @param $function_to_add (string)
* @param $priority (int)
* @param $accepted_args (int)
* @return n/a
*/
function add_action( $tag = '', $function_to_add = '', $priority = 10, $accepted_args = 1 ) {
// bail early if no callable
if( !is_callable($function_to_add) ) return;
// add
add_action( $tag, $function_to_add, $priority, $accepted_args );
}
/*
* add_field_action
*
* This function will add a field type specific filter
*
* @type function
* @date 29/09/2016
* @since 5.4.0
*
* @param $tag (string)
* @param $function_to_add (string)
* @param $priority (int)
* @param $accepted_args (int)
* @return n/a
*/
function add_field_action( $tag = '', $function_to_add = '', $priority = 10, $accepted_args = 1 ) {
// append
$tag .= '/type=' . $this->name;
// add
$this->add_action( $tag, $function_to_add, $priority, $accepted_args );
}
/*
* validate_field
*
* This function will append default settings to a field
*
* @type filter ("acf/validate_field/type={$this->name}")
* @since 3.6
* @date 23/01/13
*
* @param $field (array)
* @return $field (array)
*/
function validate_field( $field ) {
// bail early if no defaults
if( !is_array($this->defaults) ) return $field;
// merge in defaults but keep order of $field keys
foreach( $this->defaults as $k => $v ) {
if( !isset($field[ $k ]) ) $field[ $k ] = $v;
}
// return
return $field;
}
/*
* admin_l10n
*
* This function will append l10n text translations to an array which is later passed to JS
*
* @type filter ("acf/input/admin_l10n")
* @since 3.6
* @date 23/01/13
*
* @param $l10n (array)
* @return $l10n (array)
*/
function input_admin_l10n( $l10n ) {
// bail early if no defaults
if( empty($this->l10n) ) return $l10n;
// append
$l10n[ $this->name ] = $this->l10n;
// return
return $l10n;
}
}
endif; // class_exists check
?>