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,868 @@
<?php
/*
* ACF Admin Field Group Class
*
* All the logic for editing a field group
*
* @class acf_admin_field_group
* @package ACF
* @subpackage Admin
*/
if( ! class_exists('acf_admin_field_group') ) :
class acf_admin_field_group {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action('current_screen', array($this, 'current_screen'));
add_action('save_post', array($this, 'save_post'), 10, 2);
// ajax
add_action('wp_ajax_acf/field_group/render_field_settings', array($this, 'ajax_render_field_settings'));
add_action('wp_ajax_acf/field_group/render_location_rule', array($this, 'ajax_render_location_rule'));
add_action('wp_ajax_acf/field_group/move_field', array($this, 'ajax_move_field'));
// filters
add_filter('post_updated_messages', array($this, 'post_updated_messages'));
}
/*
* post_updated_messages
*
* This function will customize the message shown when editing a field group
*
* @type action (post_updated_messages)
* @date 30/04/2014
* @since 5.0.0
*
* @param $messages (array)
* @return $messages
*/
function post_updated_messages( $messages ) {
// append to messages
$messages['acf-field-group'] = array(
0 => '', // Unused. Messages start at index 1.
1 => __('Field group updated.', 'acf'),
2 => __('Field group updated.', 'acf'),
3 => __('Field group deleted.', 'acf'),
4 => __('Field group updated.', 'acf'),
5 => false, // field group does not support revisions
6 => __('Field group published.', 'acf'),
7 => __('Field group saved.', 'acf'),
8 => __('Field group submitted.', 'acf'),
9 => __('Field group scheduled for.', 'acf'),
10 => __('Field group draft updated.', 'acf')
);
// return
return $messages;
}
/*
* current_screen
*
* This function is fired when loading the admin page before HTML has been rendered.
*
* @type action (current_screen)
* @date 21/07/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function current_screen() {
// validate screen
if( !acf_is_screen('acf-field-group') ) return;
// disable filters to ensure ACF loads raw data from DB
acf_disable_filters();
// enqueue scripts
acf_enqueue_scripts();
// actions
add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('acf/input/admin_head', array($this, 'admin_head'));
add_action('acf/input/form_data', array($this, 'form_data'));
add_action('acf/input/admin_footer', array($this, 'admin_footer'));
add_action('acf/input/admin_footer_js', array($this, 'admin_footer_js'));
// filters
add_filter('acf/input/admin_l10n', array($this, 'admin_l10n'));
}
/*
* admin_enqueue_scripts
*
* This action is run after post query but before any admin script / head actions.
* It is a good place to register all actions.
*
* @type action (admin_enqueue_scripts)
* @date 30/06/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_enqueue_scripts() {
// no autosave
wp_dequeue_script('autosave');
// custom scripts
wp_enqueue_style('acf-field-group');
wp_enqueue_script('acf-field-group');
// 3rd party hook
do_action('acf/field_group/admin_enqueue_scripts');
}
/*
* admin_head
*
* This function will setup all functionality for the field group edit page to work
*
* @type action (admin_head)
* @date 23/06/12
* @since 3.1.8
*
* @param $post_id (int)
* @return $post_id (int)
*/
function admin_head() {
// global
global $post, $field_group;
// set global var
$field_group = acf_get_field_group( $post );
// metaboxes
add_meta_box('acf-field-group-fields', __("Fields",'acf'), array($this, 'mb_fields'), 'acf-field-group', 'normal', 'high');
add_meta_box('acf-field-group-locations', __("Location",'acf'), array($this, 'mb_locations'), 'acf-field-group', 'normal', 'high');
add_meta_box('acf-field-group-options', __("Settings",'acf'), array($this, 'mb_options'), 'acf-field-group', 'normal', 'high');
// actions
add_action('post_submitbox_misc_actions', array($this, 'post_submitbox_misc_actions'), 10, 0);
add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10, 0);
// filters
add_filter('screen_settings', array($this, 'screen_settings'), 10, 1);
// 3rd party hook
do_action('acf/field_group/admin_head');
}
/*
* edit_form_after_title
*
* This action will allow ACF to render metaboxes after the title
*
* @type action
* @date 17/08/13
*
* @param n/a
* @return n/a
*/
function edit_form_after_title() {
// globals
global $post;
// render post data
acf_form_data(array(
'post_id' => $post->ID,
'nonce' => 'field_group',
'ajax' => 0,
'delete_fields' => 0
));
}
/*
* form_data
*
* This function will add extra HTML to the acf form data element
*
* @type function
* @date 31/05/2016
* @since 5.3.8
*
* @param n/a
* @return n/a
*/
function form_data( $args ) {
// do action
do_action('acf/field_group/form_data', $args);
}
/*
* admin_l10n
*
* This function will append extra l10n strings to the acf JS object
*
* @type function
* @date 31/05/2016
* @since 5.3.8
*
* @param $l10n (array)
* @return $l10n
*/
function admin_l10n( $l10n ) {
// merge in new strings
$l10n = array_merge($l10n, array(
'move_to_trash' => __("Move to trash. Are you sure?",'acf'),
'checked' => __("checked",'acf'),
'no_fields' => __("No toggle fields available",'acf'),
'title_is_required' => __("Field group title is required",'acf'),
'copy' => __("copy",'acf'),
'or' => __("or",'acf'),
'fields' => __("Fields",'acf'),
'parent_fields' => __("Parent fields",'acf'),
'sibling_fields' => __("Sibling fields",'acf'),
'move_field' => __("Move Custom Field",'acf'),
'move_field_warning' => __("This field cannot be moved until its changes have been saved",'acf'),
'null' => __("Null",'acf'),
'unload' => __('The changes you made will be lost if you navigate away from this page','acf'),
'field_name_start' => __('The string "field_" may not be used at the start of a field name','acf'),
));
// 3rd party hook
$l10n = apply_filters('acf/field_group/admin_l10n', $l10n);
// return
return $l10n;
}
/*
* admin_footer
*
* description
*
* @type function
* @date 11/01/2016
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function admin_footer() {
// 3rd party hook
do_action('acf/field_group/admin_footer');
}
/*
* admin_footer_js
*
* description
*
* @type function
* @date 31/05/2016
* @since 5.3.8
*
* @param $post_id (int)
* @return $post_id (int)
*/
function admin_footer_js() {
// 3rd party hook
do_action('acf/field_group/admin_footer_js');
}
/*
* screen_settings
*
* description
*
* @type function
* @date 26/01/13
* @since 3.6.0
*
* @param $current (string)
* @return $current
*/
function screen_settings( $html ) {
// vars
$checked = acf_get_user_setting('show_field_keys') ? 'checked="checked"' : '';
// append
$html .= '<div id="acf-append-show-on-screen" class="acf-hidden">';
$html .= '<label for="acf-field-key-hide"><input id="acf-field-key-hide" type="checkbox" value="1" name="show_field_keys" ' . $checked . ' /> ' . __('Field Keys','acf') . '</label>';
$html .= '</div>';
// return
return $html;
}
/*
* post_submitbox_misc_actions
*
* This function will customize the publish metabox
*
* @type function
* @date 17/07/2015
* @since 5.2.9
*
* @param n/a
* @return n/a
*/
function post_submitbox_misc_actions() {
// global
global $field_group;
// vars
$status = $field_group['active'] ? __("Active",'acf') : __("Inactive",'acf');
?>
<script type="text/javascript">
(function($) {
// modify status
$('#post-status-display').html('<?php echo $status; ?>');
// remove edit links
$('#misc-publishing-actions a').remove();
// remove editables (fixes status text changing on submit)
$('#misc-publishing-actions .hide-if-js').remove();
})(jQuery);
</script>
<?php
}
/*
* save_post
*
* This function will save all the field group data
*
* @type function
* @date 23/06/12
* @since 1.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function save_post( $post_id, $post ) {
// do not save if this is an auto save routine
if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
return $post_id;
}
// bail early if not acf-field-group
if( $post->post_type !== 'acf-field-group' ) {
return $post_id;
}
// only save once! WordPress save's a revision as well.
if( wp_is_post_revision($post_id) ) {
return $post_id;
}
// verify nonce
if( !acf_verify_nonce('field_group') ) {
return $post_id;
}
// disable filters to ensure ACF loads raw data from DB
acf_disable_filters();
// save fields
if( !empty($_POST['acf_fields']) ) {
foreach( $_POST['acf_fields'] as $field ) {
// vars
$specific = false;
$save = acf_extract_var( $field, 'save' );
// only saved field if has changed
if( $save == 'meta' ) {
$specific = array(
'menu_order',
'post_parent',
);
}
// set field parent
if( empty($field['parent']) ) {
$field['parent'] = $post_id;
}
// save field
acf_update_field( $field, $specific );
}
}
// delete fields
if( $_POST['_acf_delete_fields'] ) {
// clean
$ids = explode('|', $_POST['_acf_delete_fields']);
$ids = array_map( 'intval', $ids );
// loop
foreach( $ids as $id ) {
// bai early if no id
if( !$id ) continue;
// delete
acf_delete_field( $id );
}
}
// add args
$_POST['acf_field_group']['ID'] = $post_id;
$_POST['acf_field_group']['title'] = $_POST['post_title'];
// save field group
acf_update_field_group( $_POST['acf_field_group'] );
// return
return $post_id;
}
/*
* mb_fields
*
* This function will render the HTML for the medtabox 'acf-field-group-fields'
*
* @type function
* @date 28/09/13
* @since 5.0.0
*
* @param N/A
* @return N/A
*/
function mb_fields() {
// global
global $field_group;
// get fields
$view = array(
'fields' => acf_get_fields_by_id( $field_group['ID'] ),
'parent' => 0
);
// load view
acf_get_view('field-group-fields', $view);
}
/*
* mb_options
*
* This function will render the HTML for the medtabox 'acf-field-group-options'
*
* @type function
* @date 28/09/13
* @since 5.0.0
*
* @param N/A
* @return N/A
*/
function mb_options() {
// global
global $field_group;
// field key (leave in for compatibility)
if( !acf_is_field_group_key( $field_group['key']) ) {
$field_group['key'] = uniqid('group_');
}
// view
acf_get_view('field-group-options');
}
/*
* mb_locations
*
* This function will render the HTML for the medtabox 'acf-field-group-locations'
*
* @type function
* @date 28/09/13
* @since 5.0.0
*
* @param N/A
* @return N/A
*/
function mb_locations() {
// global
global $field_group;
// UI needs at lease 1 location rule
if( empty($field_group['location']) ) {
$field_group['location'] = array(
// group 0
array(
// rule 0
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
)
)
);
}
// view
acf_get_view('field-group-locations');
}
/*
* ajax_render_location_rule
*
* This function can be accessed via an AJAX action and will return the result from the render_location_value function
*
* @type function (ajax)
* @date 30/09/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function ajax_render_location_rule() {
// validate
if( !acf_verify_ajax() ) die();
// valid rule
$rule = acf_get_valid_location_rule($_POST['rule']);
// view
acf_get_view( 'html-location-rule', array(
'rule' => $rule
));
// die
die();
}
/*
* ajax_render_field_settings
*
* This function will return HTML containing the field's settings based on it's new type
*
* @type function (ajax)
* @date 30/09/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function ajax_render_field_settings() {
// vars
$options = array(
'nonce' => '',
'parent' => 0,
'field_group' => 0,
'prefix' => '',
'type' => '',
);
// load post options
$options = wp_parse_args($_POST, $options);
// verify nonce
if( !wp_verify_nonce($options['nonce'], 'acf_nonce') ) {
die(0);
}
// required
if( !$options['type'] ) {
die(0);
}
// render options
$field = acf_get_valid_field(array(
'type' => $options['type'],
'name' => 'temp',
'prefix' => $options['prefix'],
'parent' => $options['parent'],
'field_group' => $options['field_group'],
));
// render
do_action("acf/render_field_settings/type={$field['type']}", $field);
// die
die();
}
/*
* ajax_move_field
*
* description
*
* @type function
* @date 20/01/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function ajax_move_field() {
// disable filters to ensure ACF loads raw data from DB
acf_disable_filters();
$args = acf_parse_args($_POST, array(
'nonce' => '',
'post_id' => 0,
'field_id' => 0,
'field_group_id' => 0
));
// verify nonce
if( !wp_verify_nonce($args['nonce'], 'acf_nonce') ) die();
// confirm?
if( $args['field_id'] && $args['field_group_id'] ) {
// vars
$field = acf_get_field($args['field_id']);
$field_group = acf_get_field_group($args['field_group_id']);
// update parent
$field['parent'] = $field_group['ID'];
// remove conditional logic
$field['conditional_logic'] = 0;
// update field
acf_update_field($field);
// message
$a = '<a href="' . admin_url("post.php?post={$field_group['ID']}&action=edit") . '" target="_blank">' . $field_group['title'] . '</a>';
echo '<p><strong>' . __('Move Complete.', 'acf') . '</strong></p>';
echo '<p>' . sprintf( __('The %s field can now be found in the %s field group', 'acf'), $field['label'], $a ). '</p>';
echo '<a href="#" class="button button-primary acf-close-popup">' . __("Close Window",'acf') . '</a>';
die();
}
// get all field groups
$field_groups = acf_get_field_groups();
$choices = array();
// check
if( !empty($field_groups) ) {
// loop
foreach( $field_groups as $field_group ) {
// bail early if no ID
if( !$field_group['ID'] ) continue;
// bail ealry if is current
if( $field_group['ID'] == $args['post_id'] ) continue;
// append
$choices[ $field_group['ID'] ] = $field_group['title'];
}
}
// render options
$field = acf_get_valid_field(array(
'type' => 'select',
'name' => 'acf_field_group',
'choices' => $choices
));
echo '<p>' . __('Please select the destination for this field', 'acf') . '</p>';
echo '<form id="acf-move-field-form">';
// render
acf_render_field_wrap( $field );
echo '<button type="submit" class="button button-primary">' . __("Move Field",'acf') . '</button>';
echo '</form>';
// die
die();
}
}
// initialize
new acf_admin_field_group();
endif;
?>

View File

@@ -0,0 +1,811 @@
<?php
/*
* ACF Admin Field Groups Class
*
* All the logic for editing a list of field groups
*
* @class acf_admin_field_groups
* @package ACF
* @subpackage Admin
*/
if( ! class_exists('acf_admin_field_groups') ) :
class acf_admin_field_groups {
// vars
var $url = 'edit.php?post_type=acf-field-group',
$sync = array();
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action('current_screen', array($this, 'current_screen'));
add_action('trashed_post', array($this, 'trashed_post'));
add_action('untrashed_post', array($this, 'untrashed_post'));
add_action('deleted_post', array($this, 'deleted_post'));
}
/*
* current_screen
*
* This function is fired when loading the admin page before HTML has been rendered.
*
* @type action (current_screen)
* @date 21/07/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function current_screen() {
// validate screen
if( !acf_is_screen('edit-acf-field-group') ) {
return;
}
// customize post_status
global $wp_post_statuses;
// modify publish post status
$wp_post_statuses['publish']->label_count = _n_noop( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', 'acf' );
// reorder trash to end
$wp_post_statuses['trash'] = acf_extract_var( $wp_post_statuses, 'trash' );
// check stuff
$this->check_duplicate();
$this->check_sync();
// actions
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('admin_footer', array($this, 'admin_footer'));
// columns
add_filter('manage_edit-acf-field-group_columns', array($this, 'field_group_columns'), 10, 1);
add_action('manage_acf-field-group_posts_custom_column', array($this, 'field_group_columns_html'), 10, 2);
}
/*
* admin_enqueue_scripts
*
* This function will add the already registered css
*
* @type function
* @date 28/09/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_enqueue_scripts() {
wp_enqueue_script('acf-input');
}
/*
* check_duplicate
*
* This function will check for any $_GET data to duplicate
*
* @type function
* @date 17/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function check_duplicate() {
// message
if( $ids = acf_maybe_get_GET('acfduplicatecomplete') ) {
// explode
$ids = explode(',', $ids);
$total = count($ids);
if( $total == 1 ) {
acf_add_admin_notice( sprintf(__('Field group duplicated. %s', 'acf'), '<a href="' . get_edit_post_link($ids[0]) . '">' . get_the_title($ids[0]) . '</a>') );
} else {
acf_add_admin_notice( sprintf(_n( '%s field group duplicated.', '%s field groups duplicated.', $total, 'acf' ), $total) );
}
}
// vars
$ids = array();
// check single
if( $id = acf_maybe_get_GET('acfduplicate') ) {
$ids[] = $id;
// check multiple
} elseif( acf_maybe_get_GET('action2') === 'acfduplicate' ) {
$ids = acf_maybe_get_GET('post');
}
// sync
if( !empty($ids) ) {
// validate
check_admin_referer('bulk-posts');
// vars
$new_ids = array();
// loop
foreach( $ids as $id ) {
// duplicate
$field_group = acf_duplicate_field_group( $id );
// increase counter
$new_ids[] = $field_group['ID'];
}
// redirect
wp_redirect( admin_url( $this->url . '&acfduplicatecomplete=' . implode(',', $new_ids)) );
exit;
}
}
/*
* check_sync
*
* This function will check for any $_GET data to sync
*
* @type function
* @date 9/12/2014
* @since 5.1.5
*
* @param n/a
* @return n/a
*/
function check_sync() {
// message
if( $ids = acf_maybe_get_GET('acfsynccomplete') ) {
// explode
$ids = explode(',', $ids);
$total = count($ids);
if( $total == 1 ) {
acf_add_admin_notice( sprintf(__('Field group synchronised. %s', 'acf'), '<a href="' . get_edit_post_link($ids[0]) . '">' . get_the_title($ids[0]) . '</a>') );
} else {
acf_add_admin_notice( sprintf(_n( '%s field group synchronised.', '%s field groups synchronised.', $total, 'acf' ), $total) );
}
}
// vars
$groups = acf_get_field_groups();
// bail early if no field groups
if( empty($groups) ) return;
// find JSON field groups which have not yet been imported
foreach( $groups as $group ) {
// vars
$local = acf_maybe_get($group, 'local', false);
$modified = acf_maybe_get($group, 'modified', 0);
$private = acf_maybe_get($group, 'private', false);
// ignore DB / PHP / private field groups
if( $local !== 'json' || $private ) {
// do nothing
} elseif( !$group['ID'] ) {
$this->sync[ $group['key'] ] = $group;
} elseif( $modified && $modified > get_post_modified_time('U', true, $group['ID'], true) ) {
$this->sync[ $group['key'] ] = $group;
}
}
// bail if no sync needed
if( empty($this->sync) ) return;
// maybe sync
$sync_keys = array();
// check single
if( $key = acf_maybe_get_GET('acfsync') ) {
$sync_keys[] = $key;
// check multiple
} elseif( acf_maybe_get_GET('action2') === 'acfsync' ) {
$sync_keys = acf_maybe_get_GET('post');
}
// sync
if( !empty($sync_keys) ) {
// validate
check_admin_referer('bulk-posts');
// disable filters to ensure ACF loads raw data from DB
acf_disable_filters();
acf_enable_filter('local');
// disable JSON
// - this prevents a new JSON file being created and causing a 'change' to theme files - solves git anoyance
acf_update_setting('json', false);
// vars
$new_ids = array();
// loop
foreach( $sync_keys as $key ) {
// append fields
if( acf_have_local_fields($key) ) {
$this->sync[ $key ]['fields'] = acf_get_local_fields( $key );
}
// import
$field_group = acf_import_field_group( $this->sync[ $key ] );
// append
$new_ids[] = $field_group['ID'];
}
// redirect
wp_redirect( admin_url( $this->url . '&acfsynccomplete=' . implode(',', $new_ids)) );
exit;
}
// filters
add_filter('views_edit-acf-field-group', array($this, 'list_table_views'));
}
/*
* list_table_views
*
* This function will add an extra link for JSON in the field group list table
*
* @type function
* @date 3/12/2014
* @since 5.1.5
*
* @param $views (array)
* @return $views
*/
function list_table_views( $views ) {
// vars
$class = '';
$total = count($this->sync);
// active
if( acf_maybe_get_GET('post_status') === 'sync' ) {
// actions
add_action('admin_footer', array($this, 'sync_admin_footer'), 5);
// set active class
$class = ' class="current"';
// global
global $wp_list_table;
// update pagination
$wp_list_table->set_pagination_args( array(
'total_items' => $total,
'total_pages' => 1,
'per_page' => $total
));
}
// add view
$views['json'] = '<a' . $class . ' href="' . admin_url($this->url . '&post_status=sync') . '">' . __('Sync available', 'acf') . ' <span class="count">(' . $total . ')</span></a>';
// return
return $views;
}
/*
* trashed_post
*
* This function is run when a post object is sent to the trash
*
* @type action (trashed_post)
* @date 8/01/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return n/a
*/
function trashed_post( $post_id ) {
// validate post type
if( get_post_type($post_id) != 'acf-field-group' ) {
return;
}
// trash field group
acf_trash_field_group( $post_id );
}
/*
* untrashed_post
*
* This function is run when a post object is restored from the trash
*
* @type action (untrashed_post)
* @date 8/01/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return n/a
*/
function untrashed_post( $post_id ) {
// validate post type
if( get_post_type($post_id) != 'acf-field-group' ) {
return;
}
// trash field group
acf_untrash_field_group( $post_id );
}
/*
* deleted_post
*
* This function is run when a post object is deleted from the trash
*
* @type action (deleted_post)
* @date 8/01/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return n/a
*/
function deleted_post( $post_id ) {
// validate post type
if( get_post_type($post_id) != 'acf-field-group' ) {
return;
}
// trash field group
acf_delete_field_group( $post_id );
}
/*
* field_group_columns
*
* This function will customize the columns for the field group table
*
* @type filter (manage_edit-acf-field-group_columns)
* @date 28/09/13
* @since 5.0.0
*
* @param $columns (array)
* @return $columns (array)
*/
function field_group_columns( $columns ) {
return array(
'cb' => '<input type="checkbox" />',
'title' => __('Title', 'acf'),
'acf-fg-description' => __('Description', 'acf'),
'acf-fg-status' => '<i class="acf-icon -dot-3 small acf-js-tooltip" title="' . esc_attr__('Status', 'acf') . '"></i>',
'acf-fg-count' => __('Fields', 'acf'),
);
}
/*
* field_group_columns_html
*
* This function will render the HTML for each table cell
*
* @type action (manage_acf-field-group_posts_custom_column)
* @date 28/09/13
* @since 5.0.0
*
* @param $column (string)
* @param $post_id (int)
* @return n/a
*/
function field_group_columns_html( $column, $post_id ) {
// vars
$field_group = acf_get_field_group( $post_id );
// render
$this->render_column( $column, $field_group );
}
function render_column( $column, $field_group ) {
// description
if( $column == 'acf-fg-description' ) {
if( $field_group['description'] ) {
echo '<span class="acf-description">' . acf_esc_html($field_group['description']) . '</span>';
}
// status
} elseif( $column == 'acf-fg-status' ) {
if( isset($this->sync[ $field_group['key'] ]) ) {
echo '<i class="acf-icon -sync grey small acf-js-tooltip" title="' . esc_attr__('Sync available', 'acf') .'"></i> ';
}
if( $field_group['active'] ) {
//echo '<i class="acf-icon -check small acf-js-tooltip" title="' . esc_attr__('Active', 'acf') .'"></i> ';
} else {
echo '<i class="acf-icon -minus yellow small acf-js-tooltip" title="' . esc_attr__('Inactive', 'acf') . '"></i> ';
}
// fields
} elseif( $column == 'acf-fg-count' ) {
echo esc_html( acf_get_field_count( $field_group ) );
}
}
/*
* admin_footer
*
* This function will render extra HTML onto the page
*
* @type action (admin_footer)
* @date 23/06/12
* @since 3.1.8
*
* @param n/a
* @return n/a
*/
function admin_footer() {
// vars
$url_home = 'https://www.advancedcustomfields.com';
$url_support = 'https://support.advancedcustomfields.com';
$icon = '<i aria-hidden="true" class="dashicons dashicons-external"></i>';
?>
<script type="text/html" id="tmpl-acf-column-2">
<div class="acf-column-2">
<div class="acf-box">
<div class="inner">
<h2><?php echo acf_get_setting('name'); ?></h2>
<p><?php _e('Customise WordPress with powerful, professional and intuitive fields.','acf'); ?></p>
<h3><?php _e("Changelog",'acf'); ?></h3>
<p><?php
$acf_changelog = admin_url('edit.php?post_type=acf-field-group&page=acf-settings-info&tab=changelog');
$acf_version = acf_get_setting('version');
printf( __('See what\'s new in <a href="%s">version %s</a>.','acf'), esc_url($acf_changelog), $acf_version );
?></p>
<h3><?php _e("Resources",'acf'); ?></h3>
<ul>
<li><a href="<?php echo esc_url( $url_home ); ?>" target="_blank"><?php echo $icon; ?> <?php _e("Website",'acf'); ?></a></li>
<li><a href="<?php echo esc_url( $url_home . '/resources/' ); ?>" target="_blank"><?php echo $icon; ?> <?php _e("Documentation",'acf'); ?></a></li>
<li><a href="<?php echo esc_url( $url_support ); ?>" target="_blank"><?php echo $icon; ?> <?php _e("Support",'acf'); ?></a></li>
<?php if( !acf_get_setting('pro') ): ?>
<li><a href="<?php echo esc_url( $url_home . '/pro/' ); ?>" target="_blank"><?php echo $icon; ?> <?php _e("Pro",'acf'); ?></a></li>
<?php endif; ?>
</ul>
</div>
<div class="footer">
<p><?php printf( __('Thank you for creating with <a href="%s">ACF</a>.','acf'), esc_url($url_home) ); ?></p>
</div>
</div>
</div>
</script>
<script type="text/javascript">
(function($){
// wrap
$('#wpbody .wrap').attr('id', 'acf-field-group-wrap');
// wrap form
$('#posts-filter').wrap('<div class="acf-columns-2" />');
// add column main
$('#posts-filter').addClass('acf-column-1');
// add column side
$('#posts-filter').after( $('#tmpl-acf-column-2').html() );
// modify row actions
$('#the-list tr').each(function(){
// vars
var $tr = $(this),
id = $tr.attr('id'),
description = $tr.find('.column-acf-fg-description').html();
// replace Quick Edit with Duplicate (sync page has no id attribute)
if( id ) {
// vars
var post_id = id.replace('post-', '');
var url = '<?php echo esc_url( admin_url( $this->url . '&acfduplicate=__post_id__&_wpnonce=' . wp_create_nonce('bulk-posts') ) ); ?>';
var $span = $('<span class="acf-duplicate-field-group"><a title="<?php _e('Duplicate this item', 'acf'); ?>" href="' + url.replace('__post_id__', post_id) + '"><?php _e('Duplicate', 'acf'); ?></a> | </span>');
// replace
$tr.find('.column-title .row-actions .inline').replaceWith( $span );
}
// add description to title
$tr.find('.column-title .row-title').after( description );
});
// modify bulk actions
$('#bulk-action-selector-bottom option[value="edit"]').attr('value','acfduplicate').text('<?php _e( 'Duplicate', 'acf' ); ?>');
// clean up table
$('#adv-settings label[for="acf-fg-description-hide"]').remove();
// mobile compatibility
var status = $('.acf-icon.-dot-3').first().attr('title');
$('td.column-acf-fg-status').attr('data-colname', status);
// no field groups found
$('#the-list tr.no-items td').attr('colspan', 4);
// search
$('.subsubsub').append(' | <li><a href="#" class="acf-toggle-search"><?php _e('Search', 'acf'); ?></a></li>');
// events
$(document).on('click', '.acf-toggle-search', function( e ){
// prevent default
e.preventDefault();
// toggle
$('.search-box').slideToggle();
});
})(jQuery);
</script>
<?php
}
/*
* sync_admin_footer
*
* This function will render extra HTML onto the page
*
* @type action (admin_footer)
* @date 23/06/12
* @since 3.1.8
*
* @param n/a
* @return n/a
*/
function sync_admin_footer() {
// vars
$i = -1;
$columns = array(
'acf-fg-description',
'acf-fg-status',
'acf-fg-count'
);
$nonce = wp_create_nonce('bulk-posts');
?>
<script type="text/html" id="tmpl-acf-json-tbody">
<?php foreach( $this->sync as $field_group ):
// vars
$i++;
$key = $field_group['key'];
$title = $field_group['title'];
$url = admin_url( $this->url . '&post_status=sync&acfsync=' . $key . '&_wpnonce=' . $nonce );
?>
<tr <?php if($i%2 == 0): ?>class="alternate"<?php endif; ?>>
<th class="check-column" scope="row">
<label for="cb-select-<?php echo esc_attr($key); ?>" class="screen-reader-text"><?php echo esc_html(sprintf(__('Select %s', 'acf'), $title)); ?></label>
<input type="checkbox" value="<?php echo esc_attr($key); ?>" name="post[]" id="cb-select-<?php echo esc_attr($key); ?>">
</th>
<td class="post-title page-title column-title">
<strong>
<span class="row-title"><?php echo esc_html($title); ?></span><span class="acf-description"><?php echo esc_html($key); ?>.json</span>
</strong>
<div class="row-actions">
<span class="import"><a title="<?php echo esc_attr( __('Synchronise field group', 'acf') ); ?>" href="<?php echo esc_url($url); ?>"><?php _e( 'Sync', 'acf' ); ?></a></span>
</div>
</td>
<?php foreach( $columns as $column ): ?>
<td class="column-<?php echo esc_attr($column); ?>"><?php $this->render_column( $column, $field_group ); ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</script>
<script type="text/html" id="tmpl-acf-bulk-actions">
<?php // source: bulk_actions() wp-admin/includes/class-wp-list-table.php ?>
<select name="action2" id="bulk-action-selector-bottom"></select>
<?php submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction2" ) ); ?>
</script>
<script type="text/javascript">
(function($){
// update table HTML
$('#the-list').html( $('#tmpl-acf-json-tbody').html() );
// bulk may not exist if no field groups in DB
if( !$('#bulk-action-selector-bottom').exists() ) {
$('.tablenav.bottom .actions.alignleft').html( $('#tmpl-acf-bulk-actions').html() );
}
// set only options
$('#bulk-action-selector-bottom').html('<option value="-1"><?php _e('Bulk Actions'); ?></option><option value="acfsync"><?php _e('Sync', 'acf'); ?></option>');
})(jQuery);
</script>
<?php
}
}
new acf_admin_field_groups();
endif;
?>

View File

@@ -0,0 +1,354 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_admin_tools') ) :
class acf_admin_tools {
/** @var array Contains an array of admin tool instances */
var $tools = array();
/** @var string The active tool */
var $active = '';
/**
* __construct
*
* This function will setup the class functionality
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action('admin_menu', array($this, 'admin_menu'));
}
/**
* register_tool
*
* This function will store a tool tool class
*
* @date 10/10/17
* @since 5.6.3
*
* @param string $class
* @return n/a
*/
function register_tool( $class ) {
$instance = new $class();
$this->tools[ $instance->name ] = $instance;
}
/**
* get_tool
*
* This function will return a tool tool class
*
* @date 10/10/17
* @since 5.6.3
*
* @param string $name
* @return n/a
*/
function get_tool( $name ) {
return isset( $this->tools[$name] ) ? $this->tools[$name] : null;
}
/**
* get_tools
*
* This function will return an array of all tools
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return array
*/
function get_tools() {
return $this->tools;
}
/*
* admin_menu
*
* This function will add the ACF menu item to the WP admin
*
* @type action (admin_menu)
* @date 28/09/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_menu() {
// bail early if no show_admin
if( !acf_get_setting('show_admin') ) return;
// add page
$page = add_submenu_page('edit.php?post_type=acf-field-group', __('Tools','acf'), __('Tools','acf'), acf_get_setting('capability'), 'acf-tools', array($this, 'html'));
// actions
add_action('load-' . $page, array($this, 'load'));
}
/**
* load
*
* description
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function load() {
// disable filters (default to raw data)
acf_disable_filters();
// include tools
$this->include_tools();
// check submit
$this->check_submit();
// load acf scripts
acf_enqueue_scripts();
}
/**
* include_tools
*
* description
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function include_tools() {
// include
acf_include('includes/admin/tools/class-acf-admin-tool.php');
acf_include('includes/admin/tools/class-acf-admin-tool-export.php');
acf_include('includes/admin/tools/class-acf-admin-tool-import.php');
// action
do_action('acf/include_admin_tools');
}
/**
* check_submit
*
* description
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function check_submit() {
// loop
foreach( $this->get_tools() as $tool ) {
// load
$tool->load();
// submit
if( acf_verify_nonce($tool->name) ) {
$tool->submit();
}
}
}
/**
* html
*
* description
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function html() {
// vars
$screen = get_current_screen();
$active = acf_maybe_get_GET('tool');
// view
$view = array(
'screen_id' => $screen->id,
'active' => $active
);
// register metaboxes
foreach( $this->get_tools() as $tool ) {
// check active
if( $active && $active !== $tool->name ) continue;
// add metabox
add_meta_box( 'acf-admin-tool-' . $tool->name, $tool->title, array($this, 'metabox_html'), $screen->id, 'normal', 'default', array('tool' => $tool->name) );
}
// view
acf_get_view( 'html-admin-tools', $view );
}
/**
* meta_box_html
*
* description
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function metabox_html( $post, $metabox ) {
// vars
$tool = $this->get_tool($metabox['args']['tool']);
?>
<form method="post">
<?php $tool->html(); ?>
<?php acf_nonce_input( $tool->name ); ?>
</form>
<?php
}
}
// initialize
acf()->admin_tools = new acf_admin_tools();
endif; // class_exists check
/*
* acf_register_admin_tool
*
* alias of acf()->admin_tools->register_tool()
*
* @type function
* @date 31/5/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_register_admin_tool( $class ) {
return acf()->admin_tools->register_tool( $class );
}
/*
* acf_get_admin_tools_url
*
* This function will return the admin URL to the tools page
*
* @type function
* @date 31/5/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_get_admin_tools_url() {
return admin_url('edit.php?post_type=acf-field-group&page=acf-tools');
}
/*
* acf_get_admin_tool_url
*
* This function will return the admin URL to the tools page
*
* @type function
* @date 31/5/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_get_admin_tool_url( $tool = '' ) {
return acf_get_admin_tools_url() . '&tool='.$tool;
}
?>

View File

@@ -0,0 +1,235 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_admin') ) :
class acf_admin {
// vars
var $notices = array();
/*
* __construct
*
* Initialize filters, action, variables and includes
*
* @type function
* @date 23/06/12
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action('admin_menu', array($this, 'admin_menu'));
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 0);
add_action('admin_notices', array($this, 'admin_notices'));
}
/*
* add_notice
*
* This function will add the notice data to a setting in the acf object for the admin_notices action to use
*
* @type function
* @date 17/10/13
* @since 5.0.0
*
* @param $text (string)
* @param $class (string)
* @param wrap (string)
* @return n/a
*/
function add_notice( $text = '', $class = '', $wrap = 'p' ) {
// append
$this->notices[] = array(
'text' => $text,
'class' => 'updated ' . $class,
'wrap' => $wrap
);
}
/*
* get_notices
*
* This function will return an array of admin notices
*
* @type function
* @date 17/10/13
* @since 5.0.0
*
* @param n/a
* @return (array)
*/
function get_notices() {
// bail early if no notices
if( empty($this->notices) ) return false;
// return
return $this->notices;
}
/*
* admin_menu
*
* This function will add the ACF menu item to the WP admin
*
* @type action (admin_menu)
* @date 28/09/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_menu() {
// bail early if no show_admin
if( !acf_get_setting('show_admin') ) return;
// vars
$slug = 'edit.php?post_type=acf-field-group';
$cap = acf_get_setting('capability');
// add parent
add_menu_page(__("Custom Fields",'acf'), __("Custom Fields",'acf'), $cap, $slug, false, 'dashicons-welcome-widgets-menus', '80.025');
// add children
add_submenu_page($slug, __('Field Groups','acf'), __('Field Groups','acf'), $cap, $slug );
add_submenu_page($slug, __('Add New','acf'), __('Add New','acf'), $cap, 'post-new.php?post_type=acf-field-group' );
}
/*
* admin_enqueue_scripts
*
* This function will add the already registered css
*
* @type function
* @date 28/09/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_enqueue_scripts() {
wp_enqueue_style( 'acf-global' );
}
/*
* admin_notices
*
* This function will render any admin notices
*
* @type function
* @date 17/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_notices() {
// vars
$notices = $this->get_notices();
// bail early if no notices
if( !$notices ) return;
// loop
foreach( $notices as $notice ) {
$open = '';
$close = '';
if( $notice['wrap'] ) {
$open = "<{$notice['wrap']}>";
$close = "</{$notice['wrap']}>";
}
?>
<div class="notice is-dismissible <?php echo esc_attr($notice['class']); ?> acf-notice"><?php echo $open . $notice['text'] . $close; ?></div>
<?php
}
}
}
// initialize
acf()->admin = new acf_admin();
endif; // class_exists check
/*
* acf_add_admin_notice
*
* This function will add the notice data to a setting in the acf object for the admin_notices action to use
*
* @type function
* @date 17/10/13
* @since 5.0.0
*
* @param $text (string)
* @param $class (string)
* @return (int) message ID (array position)
*/
function acf_add_admin_notice( $text, $class = '', $wrap = 'p' ) {
return acf()->admin->add_notice($text, $class, $wrap);
}
/*
* acf_get_admin_notices
*
* This function will return an array containing any admin notices
*
* @type function
* @date 17/10/13
* @since 5.0.0
*
* @param n/a
* @return (array)
*/
function acf_get_admin_notices() {
return acf()->admin->get_notices();
}
?>

View File

@@ -0,0 +1,283 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_admin_install_network') ) :
class acf_admin_install_network {
/*
* __construct
*
* A good place to add actions / filters
*
* @type function
* @date 11/08/13
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action('network_admin_menu', array($this,'network_admin_menu'), 20);
}
/*
* network_admin_menu
*
* This function will chck for available updates and add actions if needed
*
* @type function
* @date 2/04/2015
* @since 5.1.5
*
* @param n/a
* @return n/a
*/
function network_admin_menu() {
// vars
$prompt = false;
// loop through sites and find updates
$sites = acf_get_sites();
if( $sites ) {
foreach( $sites as $site ) {
// switch blog
switch_to_blog( $site['blog_id'] );
// get site updates
$updates = acf_get_db_updates();
// restore
restore_current_blog();
if( $updates ) {
$prompt = true;
break;
}
}
}
// bail if no prompt
if( !$prompt ) return;
// actions
add_action('network_admin_notices', array($this, 'network_admin_notices'), 1);
// add page
$page = add_submenu_page('index.php', __('Upgrade Database','acf'), __('Upgrade Database','acf'), acf_get_setting('capability'), 'acf-upgrade-network', array($this,'network_html'));
// actions
add_action('load-' . $page, array($this,'network_load'));
}
/*
* load
*
* This function will look at the $_POST data and run any functions if needed
*
* @type function
* @date 7/01/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function network_load() {
// hide notice on this page
remove_action('network_admin_notices', array($this, 'network_admin_notices'), 1);
// load acf scripts
acf_enqueue_scripts();
}
/*
* network_admin_notices
*
* This function will render the update notice
*
* @type function
* @date 2/04/2015
* @since 5.1.5
*
* @param n/a
* @return n/a
*/
function network_admin_notices() {
// view
$view = array(
'button_text' => __("Review sites & upgrade", 'acf'),
'button_url' => network_admin_url('index.php?page=acf-upgrade-network'),
'confirm' => false
);
// load view
acf_get_view('install-notice', $view);
}
/*
* network_html
*
* This function will render the HTML for the network upgrade page
*
* @type function
* @date 19/02/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function network_html() {
// vars
$plugin_version = acf_get_setting('version');
// loop through sites and find updates
$sites = acf_get_sites();
if( $sites ) {
foreach( $sites as $i => $site ) {
// switch blog
switch_to_blog( $site['blog_id'] );
// extra info
$site['name'] = get_bloginfo('name');
$site['url'] = home_url();
// get site updates
$site['updates'] = acf_get_db_updates();
// get site version
$site['acf_version'] = get_option('acf_version');
// no value equals new instal
if( !$site['acf_version'] ) {
$site['acf_version'] = $plugin_version;
}
// update
$sites[ $i ] = $site;
// restore
restore_current_blog();
}
}
// view
$view = array(
'sites' => $sites,
'plugin_version' => $plugin_version
);
// load view
acf_get_view('install-network', $view);
}
}
// initialize
new acf_admin_install_network();
endif; // class_exists check
/*
* acf_get_sites
*
* This function will return an array of site data
*
* @type function
* @date 29/08/2016
* @since 5.4.0
*
* @param n/a
* @return (array)
*/
function acf_get_sites() {
// vars
$sites = array();
// WP >= 4.6
if( function_exists('get_sites') ) {
$_sites = get_sites(array(
'number' => 0
));
foreach( $_sites as $_site ) {
$_site = get_site( $_site );
$sites[] = $_site->to_array();
}
// WP < 4.6
} else {
$sites = wp_get_sites(array(
'limit' => 0
));
}
// return
return $sites;
}
?>

View File

@@ -0,0 +1,499 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/*
* acf_update_500
*
* These functions will update the DB for ACF v5.0.0
*
* @type function
* @date 10/09/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_update_500() {
// action for 3rd party
do_action('acf/update_500');
// field groups
acf_update_500_field_groups();
// version
acf_update_db_version('5.0.0');
}
function acf_update_500_field_groups() {
// vars
$ofgs = get_posts(array(
'numberposts' => -1,
'post_type' => 'acf',
'orderby' => 'menu_order title',
'order' => 'asc',
'suppress_filters' => true,
));
// check
if( !$ofgs ) return;
// loop
foreach( $ofgs as $ofg ){
acf_update_500_field_group( $ofg );
}
}
function acf_update_500_field_group( $ofg ) {
// global
global $wpdb;
// create new field group
$nfg = array(
'ID' => 0,
'title' => $ofg->post_title,
'menu_order' => $ofg->menu_order,
);
// location rules
$groups = array();
// get all rules
$rules = get_post_meta($ofg->ID, 'rule', false);
if( is_array($rules) ) {
$group_no = 0;
foreach( $rules as $rule ) {
// if field group was duplicated, it may now be a serialized string!
$rule = maybe_unserialize($rule);
// does this rule have a group?
// + groups were added in 4.0.4
if( !isset($rule['group_no']) ) {
$rule['group_no'] = $group_no;
// sperate groups?
if( get_post_meta($ofg->ID, 'allorany', true) == 'any' ) {
$group_no++;
}
}
// extract vars
$group = acf_extract_var( $rule, 'group_no' );
$order = acf_extract_var( $rule, 'order_no' );
// add to group
$groups[ $group ][ $order ] = $rule;
// sort rules
ksort( $groups[ $group ] );
}
// sort groups
ksort( $groups );
}
$nfg['location'] = $groups;
// settings
if( $position = get_post_meta($ofg->ID, 'position', true) ) {
$nfg['position'] = $position;
}
if( $layout = get_post_meta($ofg->ID, 'layout', true) ) {
$nfg['layout'] = $layout;
}
if( $hide_on_screen = get_post_meta($ofg->ID, 'hide_on_screen', true) ) {
$nfg['hide_on_screen'] = maybe_unserialize($hide_on_screen);
}
// Note: acf_update_field_group will call the acf_get_valid_field_group function and apply 'compatibility' changes
// save field group
$nfg = acf_update_field_group( $nfg );
// action for 3rd party
do_action('acf/update_500_field_group', $nfg, $ofg);
// trash?
if( $ofg->post_status == 'trash' ) {
acf_trash_field_group( $nfg['ID'] );
}
// get field from postmeta
$rows = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d AND meta_key LIKE %s", $ofg->ID, 'field_%'), ARRAY_A);
// check
if( $rows ) {
// loop
foreach( $rows as $row ) {
// bail early if key already migrated (potential duplicates in DB)
if( acf_has_done('update_500_field_group_' . $ofg->ID . '_' . $row['meta_key']) ) continue;
// vars
$field = $row['meta_value'];
$field = maybe_unserialize( $field );
$field = maybe_unserialize( $field ); // run again for WPML
// add parent
$field['parent'] = $nfg['ID'];
// migrate field
$field = acf_update_500_field( $field );
}
}
// return
return $nfg;
}
function acf_update_500_field( $field ) {
// orig
$orig = $field;
// order_no is now menu_order
$field['menu_order'] = acf_extract_var( $field, 'order_no' );
// correct very old field keys
if( substr($field['key'], 0, 6) !== 'field_' ) {
$field['key'] = 'field_' . str_replace('field', '', $field['key']);
}
// get valid field
$field = acf_get_valid_field( $field );
// save field
$field = acf_update_field( $field );
// sub fields
if( $field['type'] == 'repeater' ) {
// get sub fields
$sub_fields = acf_extract_var( $orig, 'sub_fields' );
// save sub fields
if( !empty($sub_fields) ) {
$keys = array_keys($sub_fields);
foreach( $keys as $key ) {
$sub_field = acf_extract_var($sub_fields, $key);
$sub_field['parent'] = $field['ID'];
acf_update_500_field( $sub_field );
}
}
} elseif( $field['type'] == 'flexible_content' ) {
// get layouts
$layouts = acf_extract_var( $orig, 'layouts' );
// update layouts
$field['layouts'] = array();
// save sub fields
if( !empty($layouts) ) {
foreach( $layouts as $layout ) {
// vars
$layout_key = uniqid();
// append layotu key
$layout['key'] = $layout_key;
// extract sub fields
$sub_fields = acf_extract_var($layout, 'sub_fields');
// save sub fields
if( !empty($sub_fields) ) {
$keys = array_keys($sub_fields);
foreach( $keys as $key ) {
$sub_field = acf_extract_var($sub_fields, $key);
$sub_field['parent'] = $field['ID'];
$sub_field['parent_layout'] = $layout_key;
acf_update_500_field( $sub_field );
}
// foreach
}
// if
// append layout
$field['layouts'][] = $layout;
}
// foreach
}
// if
// save field again with less sub field data
$field = acf_update_field( $field );
}
// action for 3rd party
do_action('acf/update_500_field', $field);
// return
return $field;
}
/*
* acf_update_550
*
* These functions will update the DB for ACF v5.5.0
*
* @type function
* @date 10/09/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_update_550() { //acf_log('acf_update_550');
// action for 3rd party
do_action('acf/update_550');
// termmeta
acf_update_550_termmeta();
// version
acf_update_db_version('5.5.0');
}
/*
* acf_update_550_termmeta
*
* This function will migrate all term meta
*
* @type function
* @date 3/09/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_update_550_termmeta() { //acf_log('acf_update_550_termmeta');
// bail early if no table
if( !acf_isset_termmeta() ) {
update_option('acf_update_550_termmeta', 1); // no longer used
//echo __('Term meta upgrade not possible (termmeta table does not exist)', 'acf');
return;
}
// vars
$taxonomies = get_taxonomies(false, 'objects');
// bail early if no taxonomies
if( !$taxonomies ) return;
// loop
foreach( $taxonomies as $taxonomy ) {
acf_update_550_taxonomy( $taxonomy->name );
}
// delete trigger
delete_option('acf_update_550_termmeta');
// action for 3rd party
do_action('acf/update_550_termmeta');
}
/*
* acf_update_550_taxonomy
*
* This function will migrate term meta for a specific taxonomy
*
* @type function
* @date 3/09/2016
* @since 5.4.0
*
* @param $taxonomy (string)
* @return n/a
*/
function acf_update_550_taxonomy( $taxonomy ) { //acf_log('acf_update_550_taxonomy', $taxonomy);
// global
global $wpdb;
// vars
$search = $taxonomy . '_%';
$_search = '_' . $search;
// escape '_'
// http://stackoverflow.com/questions/2300285/how-do-i-escape-in-sql-server
$search = str_replace('_', '\_', $search);
$_search = str_replace('_', '\_', $_search);
// search
// results show faster query times using 2 LIKE vs 2 wildcards
$rows = $wpdb->get_results($wpdb->prepare(
"SELECT *
FROM $wpdb->options
WHERE option_name LIKE %s
OR option_name LIKE %s",
$search,
$_search
), ARRAY_A);
// bail early if no rows
if( empty($rows) ) return;
// vars
$search = $taxonomy . '_';
$_search = '_' . $search;
// loop
foreach( $rows as $row ) {
// use regex to find (_)taxonomy_(term_id)_(field_name)
$matches = null;
$regexp = '/^(_?)' . $taxonomy . '_(\d+)_(.+)/';
// bail early if no match
if( !preg_match($regexp, $row['option_name'], $matches) ) continue;
/*
Array
(
[0] => category_3_color
[1] =>
[2] => 3
[3] => color
)
*/
// vars
$term_id = $matches[2];
$name = $matches[1] . $matches[3];
$value = $row['option_value'];
// update
update_metadata( 'term', $term_id, $name, $value );
}
// action for 3rd party
do_action('acf/update_550_taxonomy', $taxonomy);
}
?>

View File

@@ -0,0 +1,431 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_admin_install') ) :
class acf_admin_install {
// vars
var $db_updates = array(
'5.0.0' => 'acf_update_500',
'5.5.0' => 'acf_update_550'
);
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action('admin_menu', array($this,'admin_menu'), 20);
add_action('wp_upgrade', array($this,'wp_upgrade'), 10, 2);
// ajax
add_action('wp_ajax_acf/admin/db_update', array($this, 'ajax_db_update'));
}
/*
* admin_menu
*
* This function will chck for available updates and add actions if needed
*
* @type function
* @date 19/02/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_menu() {
// vars
$updates = acf_get_db_updates();
// bail early if no updates available
if( !$updates ) return;
// actions
add_action('admin_notices', array($this, 'admin_notices'), 1);
// add page
$page = add_submenu_page('index.php', __('Upgrade Database','acf'), __('Upgrade Database','acf'), acf_get_setting('capability'), 'acf-upgrade', array($this,'html') );
// actions
add_action('load-' . $page, array($this,'load'));
}
/*
* load
*
* This function will look at the $_POST data and run any functions if needed
*
* @type function
* @date 7/01/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function load() {
// hide upgrade
remove_action('admin_notices', array($this, 'admin_notices'), 1);
// load acf scripts
acf_enqueue_scripts();
}
/*
* admin_notices
*
* This function will render the DB Upgrade notice
*
* @type function
* @date 17/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_notices() {
// view
$view = array(
'button_text' => __("Upgrade Database", 'acf'),
'button_url' => admin_url('index.php?page=acf-upgrade'),
'confirm' => true
);
// load view
acf_get_view('install-notice', $view);
}
/*
* html
*
* description
*
* @type function
* @date 19/02/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function html() {
// view
$view = array(
'updates' => acf_get_db_updates(),
'plugin_version' => acf_get_setting('version')
);
// load view
acf_get_view('install', $view);
}
/*
* ajax_db_update
*
* description
*
* @type function
* @date 24/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function ajax_db_update() {
// options
$options = wp_parse_args( $_POST, array(
'nonce' => '',
'blog_id' => '',
));
// validate
if( !wp_verify_nonce($options['nonce'], 'acf_db_update') ) {
wp_send_json_error(array(
'message' => __('Error validating request', 'acf')
));
}
// switch blog
if( $options['blog_id'] ) {
switch_to_blog( $options['blog_id'] );
}
// vars
$updates = acf_get_db_updates();
$message = '';
// bail early if no updates
if( empty($updates) ) {
wp_send_json_error(array(
'message' => __('No updates available.', 'acf')
));
}
// install updates
foreach( $updates as $version => $callback ) {
$message .= $this->run_update( $callback );
}
// updates complete
acf_update_db_version();
// return
wp_send_json_success(array(
'message' => $message
));
}
/*
* run_db_update
*
* This function will perform a db upgrade
*
* @type function
* @date 10/09/2016
* @since 5.4.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function run_update( $callback = '' ) {
// include update functions
acf_include('includes/admin/install-updates.php');
// bail early if not found
if( !function_exists($callback) ) return false;
// load any errors / feedback from update
ob_start();
// include
call_user_func($callback);
// get feedback
$message = ob_get_clean();
// return
return $message;
}
/*
* wp_upgrade
*
* This function will run when the WP database is updated
*
* @type function
* @date 10/09/2016
* @since 5.4.0
*
* @param $wp_db_version (string) The new $wp_db_version
* @return $wp_current_db_version (string) The old (current) $wp_db_version
*/
function wp_upgrade( $wp_db_version, $wp_current_db_version ) {
// vars
$acf_db_version = acf_get_db_version();
// termmeta was added in WP 4.4 (34370)
// if website has already updated to ACF 5.5.0, termmeta will not have yet been migrated
if( $wp_db_version >= 34370 && $wp_current_db_version < 34370 && acf_version_compare($acf_db_version, '>=', '5.5.0') ) {
$this->run_update('acf_update_550_termmeta');
}
}
}
// initialize
acf()->admin->install = new acf_admin_install();
endif; // class_exists check
/*
* acf_get_db_version
*
* This function will return the current ACF DB version
*
* @type function
* @date 10/09/2016
* @since 5.4.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_get_db_version() {
return get_option('acf_version');
}
/*
* acf_update_db_version
*
* This function will update the current ACF DB version
*
* @type function
* @date 10/09/2016
* @since 5.4.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_update_db_version( $version = '' ) {
// default to latest
if( !$version ) {
$version = acf_get_setting('version');
}
// update
update_option('acf_version', $version );
}
/*
* acf_get_db_updates
*
* This function will return available db updates
*
* @type function
* @date 12/05/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_get_db_updates() {
// vars
$available = array();
$db_updates = acf()->admin->install->db_updates;
$acf_version = acf_get_setting('version');
$db_version = acf_get_db_version();
// bail early if is fresh install
if( !$db_version ) {
acf_update_db_version($acf_version);
return false;
}
// bail early if is up to date
if( acf_version_compare($db_version, '>=', $acf_version)) return false;
// loop
foreach( $db_updates as $version => $callback ) {
// ignore if update is for a future version (may exist for testing)
if( acf_version_compare( $version, '>', $acf_version ) ) continue;
// ignore if update has already been run
if( acf_version_compare( $version, '<=', $db_version ) ) continue;
// append
$available[ $version ] = $callback;
}
// bail early if no updates available
// - also update DB to current version
if( empty($available) ) {
acf_update_db_version($acf_version);
return false;
}
// return
return $available;
}
?>

View File

@@ -0,0 +1,123 @@
<?php
class acf_settings_addons {
var $view;
/*
* __construct
*
* Initialize filters, action, variables and includes
*
* @type function
* @date 23/06/12
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}
/*
* admin_menu
*
* This function will add the ACF menu item to the WP admin
*
* @type action (admin_menu)
* @date 28/09/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_menu() {
// bail early if no show_admin
if( !acf_get_setting('show_admin') )
{
return;
}
// add page
$page = add_submenu_page('edit.php?post_type=acf-field-group', __('Add-ons','acf'), __('Add-ons','acf'), acf_get_setting('capability'),'acf-settings-addons', array($this,'html') );
// actions
add_action('load-' . $page, array($this,'load'));
}
/*
* load
*
* description
*
* @type function
* @date 7/01/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function load() {
// vars
$this->view = array(
'json' => array(),
);
// load json
$request = wp_remote_post( 'https://assets.advancedcustomfields.com/add-ons/add-ons.json' );
// validate
if( is_wp_error($request) || wp_remote_retrieve_response_code($request) != 200)
{
acf_add_admin_notice(__('<b>Error</b>. Could not load add-ons list', 'acf'), 'error');
}
else
{
$this->view['json'] = json_decode( $request['body'], true );
}
}
/*
* html
*
* description
*
* @type function
* @date 7/01/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function html() {
// load view
acf_get_view('settings-addons', $this->view);
}
}
// initialize
new acf_settings_addons();
?>

View File

@@ -0,0 +1,102 @@
<?php
class acf_settings_info {
/*
* __construct
*
* Initialize filters, action, variables and includes
*
* @type function
* @date 23/06/12
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action('admin_menu', array($this, 'admin_menu'));
}
/*
* admin_menu
*
* This function will add the ACF menu item to the WP admin
*
* @type action (admin_menu)
* @date 28/09/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_menu() {
// bail early if no show_admin
if( !acf_get_setting('show_admin') ) {
return;
}
// add page
add_submenu_page('edit.php?post_type=acf-field-group', __('Info','acf'), __('Info','acf'), acf_get_setting('capability'),'acf-settings-info', array($this,'html'));
}
/*
* html
*
* description
*
* @type function
* @date 7/01/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function html() {
// vars
$view = array(
'version' => acf_get_setting('version'),
'have_pro' => acf_get_setting('pro'),
'tabs' => array(
'new' => __("What's New", 'acf'),
'changelog' => __("Changelog", 'acf')
),
'active' => 'new'
);
// set active tab
$tab = acf_maybe_get_GET('tab');
if( $tab && isset($view['tabs'][ $tab ]) ) {
$view['active'] = $tab;
}
// load view
acf_get_view('settings-info', $view);
}
}
// initialize
new acf_settings_info();
?>

View File

@@ -0,0 +1,592 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('ACF_Admin_Tool_Export') ) :
class ACF_Admin_Tool_Export extends ACF_Admin_Tool {
/** @var string View context */
var $view = '';
/** @var array Export data */
var $json = '';
/**
* initialize
*
* This function will initialize the admin tool
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'export';
$this->title = __("Export Field Groups", 'acf');
// active
if( $this->is_active() ) {
$this->title .= ' - ' . __('Generate PHP', 'acf');
}
}
/**
* submit
*
* This function will run when the tool's form has been submit
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function submit() {
// vars
$action = acf_maybe_get_POST('action');
// download
if( $action === 'download' ) {
$this->submit_download();
// generate
} elseif( $action === 'generate' ) {
$this->submit_generate();
}
}
/**
* submit_download
*
* description
*
* @date 17/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function submit_download() {
// vars
$json = $this->get_selected();
// validate
if( $json === false ) {
return acf_add_admin_notice( __("No field groups selected", 'acf') , 'error');
}
// headers
$file_name = 'acf-export-' . date('Y-m-d') . '.json';
header( "Content-Description: File Transfer" );
header( "Content-Disposition: attachment; filename={$file_name}" );
header( "Content-Type: application/json; charset=utf-8" );
// return
echo acf_json_encode( $json );
die;
}
/**
* submit_generate
*
* description
*
* @date 17/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function submit_generate() {
// vars
$keys = $this->get_selected_keys();
// validate
if( !$keys ) {
return acf_add_admin_notice( __("No field groups selected", 'acf') , 'error');
}
// url
$url = add_query_arg( 'keys', implode('+', $keys), $this->get_url() );
// redirect
wp_redirect( $url );
exit;
}
/**
* load
*
* description
*
* @date 21/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function load() {
// active
if( $this->is_active() ) {
// get selected keys
$selected = $this->get_selected_keys();
// add notice
if( $selected ) {
$count = count($selected);
$message = sprintf( _n( 'Exported 1 field group.', 'Exported %s field groups.', $count, 'acf' ), $count );
acf_add_admin_notice( $message );
}
}
}
/**
* html
*
* This function will output the metabox HTML
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function html() {
// single (generate PHP)
if( $this->is_active() ) {
$this->html_single();
// archive
} else {
$this->html_archive();
}
}
/**
* html_field_selection
*
* description
*
* @date 24/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function html_field_selection() {
// vars
$choices = array();
$selected = $this->get_selected_keys();
$field_groups = acf_get_field_groups();
// loop
if( $field_groups ) {
foreach( $field_groups as $field_group ) {
$choices[ $field_group['key'] ] = esc_html( $field_group['title'] );
}
}
// render
acf_render_field_wrap(array(
'label' => __('Select Field Groups', 'acf'),
'type' => 'checkbox',
'name' => 'keys',
'prefix' => false,
'value' => $selected,
'toggle' => true,
'choices' => $choices,
));
}
/**
* html_panel_selection
*
* description
*
* @date 21/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function html_panel_selection() {
?>
<div class="acf-panel acf-panel-selection">
<h3 class="acf-panel-title"><?php _e('Select Field Groups', 'acf') ?> <i class="dashicons dashicons-arrow-right"></i></h3>
<div class="acf-panel-inside">
<?php $this->html_field_selection(); ?>
</div>
</div>
<?php
}
/**
* html_panel_settings
*
* description
*
* @date 21/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function html_panel_settings() {
?>
<div class="acf-panel acf-panel-settings">
<h3 class="acf-panel-title"><?php _e('Settings', 'acf') ?> <i class="dashicons dashicons-arrow-right"></i></h3>
<div class="acf-panel-inside">
<?php
/*
acf_render_field_wrap(array(
'label' => __('Empty settings', 'acf'),
'type' => 'select',
'name' => 'minimal',
'prefix' => false,
'value' => '',
'choices' => array(
'all' => 'Include all settings',
'minimal' => 'Ignore empty settings'
)
));
*/
?>
</div>
</div>
<?php
}
/**
* html_archive
*
* description
*
* @date 20/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function html_archive() {
?>
<p><?php _e('Select the field groups you would like to export and then select your export method. Use the download button to export to a .json file which you can then import to another ACF installation. Use the generate button to export to PHP code which you can place in your theme.', 'acf'); ?></p>
<div class="acf-fields">
<?php $this->html_field_selection(); ?>
</div>
<p class="acf-submit">
<button type="submit" name="action" class="button button-primary" value="download"><?php _e('Export File', 'acf'); ?></button>
<button type="submit" name="action" class="button" value="generate"><?php _e('Generate PHP', 'acf'); ?></button>
</p>
<?php
}
/**
* html_single
*
* description
*
* @date 20/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function html_single() {
?>
<div class="acf-postbox-columns">
<div class="acf-postbox-main">
<?php $this->html_generate(); ?>
</div>
<div class="acf-postbox-side">
<?php $this->html_panel_selection(); ?>
<p class="acf-submit">
<button type="submit" name="action" class="button button-primary" value="generate"><?php _e('Generate PHP', 'acf'); ?></button>
</p>
</div>
</div>
<?php
}
/**
* html_generate
*
* description
*
* @date 17/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function html_generate() {
// prevent default translation and fake __() within string
acf_update_setting('l10n_var_export', true);
// vars
$json = $this->get_selected();
$str_replace = array(
" " => "\t",
"'!!__(!!\'" => "__('",
"!!\', !!\'" => "', '",
"!!\')!!'" => "')",
"array (" => "array("
);
$preg_replace = array(
'/([\t\r\n]+?)array/' => 'array',
'/[0-9]+ => array/' => 'array'
);
?>
<p><?php _e("The following code can be used to register a local version of the selected field group(s). A local field group can provide many benefits such as faster load times, version control & dynamic fields/settings. Simply copy and paste the following code to your theme's functions.php file or include it within an external file.", 'acf'); ?></p>
<textarea id="acf-export-textarea" readonly="true"><?php
echo "if( function_exists('acf_add_local_field_group') ):" . "\r\n" . "\r\n";
foreach( $json as $field_group ) {
// code
$code = var_export($field_group, true);
// change double spaces to tabs
$code = str_replace( array_keys($str_replace), array_values($str_replace), $code );
// correctly formats "=> array("
$code = preg_replace( array_keys($preg_replace), array_values($preg_replace), $code );
// esc_textarea
$code = esc_textarea( $code );
// echo
echo "acf_add_local_field_group({$code});" . "\r\n" . "\r\n";
}
echo "endif;";
?></textarea>
<p class="acf-submit">
<a class="button" id="acf-export-copy"><?php _e( 'Copy to clipboard', 'acf' ); ?></a>
</p>
<script type="text/javascript">
(function($){
// vars
var $a = $('#acf-export-copy');
var $textarea = $('#acf-export-textarea');
// remove $a if 'copy' is not supported
if( !document.queryCommandSupported('copy') ) {
return $a.remove();
}
// event
$a.on('click', function( e ){
// prevent default
e.preventDefault();
// select
$textarea.get(0).select();
// try
try {
// copy
var copy = document.execCommand('copy');
if( !copy ) return;
// tooltip
acf.tooltip.temp('Copied', $a);
} catch (err) {
// do nothing
}
});
})(jQuery);
</script>
<?php
}
/**
* get_selected_keys
*
* This function will return an array of field group keys that have been selected
*
* @date 20/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function get_selected_keys() {
// check $_POST
if( $keys = acf_maybe_get_POST('keys') ) {
return (array) $keys;
}
// check $_GET
if( $keys = acf_maybe_get_GET('keys') ) {
$keys = str_replace(' ', '+', $keys);
return explode('+', $keys);
}
// return
return false;
}
/**
* get_selected
*
* This function will return the JSON data for given $_POST args
*
* @date 17/10/17
* @since 5.6.3
*
* @param n/a
* @return array
*/
function get_selected() {
// vars
$selected = $this->get_selected_keys();
$json = array();
// bail early if no keys
if( !$selected ) return false;
// construct JSON
foreach( $selected as $key ) {
// load field group
$field_group = acf_get_field_group( $key );
// validate field group
if( empty($field_group) ) continue;
// load fields
$field_group['fields'] = acf_get_fields( $field_group );
// prepare for export
$field_group = acf_prepare_field_group_for_export( $field_group );
// add to json array
$json[] = $field_group;
}
// return
return $json;
}
}
// initialize
acf_register_admin_tool( 'acf_admin_tool_export' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,277 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('ACF_Admin_Tool_Import') ) :
class ACF_Admin_Tool_Import extends ACF_Admin_Tool {
/**
* initialize
*
* This function will initialize the admin tool
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'import';
$this->title = __("Import Field Groups", 'acf');
$this->icon = 'dashicons-upload';
}
/**
* html
*
* This function will output the metabox HTML
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function html() {
// vars
$choices = array();
$field_groups = acf_get_field_groups();
// loop
if( $field_groups ) {
foreach( $field_groups as $field_group ) {
$choices[ $field_group['key'] ] = esc_html( $field_group['title'] );
}
}
// html
?>
<p><?php _e('Select the Advanced Custom Fields JSON file you would like to import. When you click the import button below, ACF will import the field groups.', 'acf'); ?></p>
<div class="acf-fields">
<?php
acf_render_field_wrap(array(
'label' => __('Select File', 'acf'),
'type' => 'file',
'name' => 'acf_import_file',
'value' => false,
'uploader' => 'basic',
));
?>
</div>
<p class="acf-submit">
<input type="submit" class="button button-primary" value="<?php _e('Import File', 'acf'); ?>" />
</p>
<?php
}
/**
* submit
*
* This function will run when the tool's form has been submit
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function submit() {
// validate
if( empty($_FILES['acf_import_file']['size']) ) {
acf_add_admin_notice( __("No file selected", 'acf') , 'error');
return;
}
// vars
$file = $_FILES['acf_import_file'];
// validate error
if( $file['error'] ) {
acf_add_admin_notice(__('Error uploading file. Please try again', 'acf'), 'error');
return;
}
// validate type
if( pathinfo($file['name'], PATHINFO_EXTENSION) !== 'json' ) {
acf_add_admin_notice(__('Incorrect file type', 'acf'), 'error');
return;
}
// read file
$json = file_get_contents( $file['tmp_name'] );
// decode json
$json = json_decode($json, true);
// validate json
if( empty($json) ) {
acf_add_admin_notice(__('Import file empty', 'acf'), 'error');
return;
}
// if importing an auto-json, wrap field group in array
if( isset($json['key']) ) {
$json = array( $json );
}
// vars
$ids = array();
$keys = array();
$imported = array();
// populate keys
foreach( $json as $field_group ) {
// append key
$keys[] = $field_group['key'];
}
// look for existing ids
foreach( $keys as $key ) {
// attempt find ID
$field_group = _acf_get_field_group_by_key( $key );
// bail early if no field group
if( !$field_group ) continue;
// append
$ids[ $key ] = $field_group['ID'];
}
// enable local
acf_enable_local();
// reset local (JSON class has already included .json field groups which may conflict)
acf_reset_local();
// add local field groups
foreach( $json as $field_group ) {
// add field group
acf_add_local_field_group( $field_group );
}
// loop over keys
foreach( $keys as $key ) {
// vars
$field_group = acf_get_local_field_group( $key );
// attempt get id
$id = acf_maybe_get( $ids, $key );
if( $id ) {
$field_group['ID'] = $id;
}
// append fields
if( acf_have_local_fields($key) ) {
$field_group['fields'] = acf_get_local_fields( $key );
}
// import
$field_group = acf_import_field_group( $field_group );
// append message
$imported[] = array(
'ID' => $field_group['ID'],
'title' => $field_group['title'],
'updated' => $id ? 1 : 0
);
}
// messages
if( !empty($imported) ) {
// vars
$links = array();
$count = count($imported);
$message = sprintf(_n( 'Imported 1 field group', 'Imported %s field groups', $count, 'acf' ), $count) . '.';
// populate links
foreach( $imported as $import ) {
$links[] = '<a href="' . admin_url("post.php?post={$import['ID']}&action=edit") . '" target="_blank">' . $import['title'] . '</a>';
}
// append links
$message .= ' ' . implode(', ', $links);
// add notice
acf_add_admin_notice( $message );
}
}
}
// initialize
acf_register_admin_tool( 'acf_admin_tool_import' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,195 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('ACF_Admin_Tool') ) :
class ACF_Admin_Tool {
/** @var string Tool name */
var $name = '';
/** @var string Tool title */
var $title = '';
/** @var string Dashicon slug */
//var $icon = '';
/** @var boolean Redirect form to single */
//var $redirect = false;
/**
* get_name
*
* This function will return the Tool's name
*
* @date 19/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function get_name() {
return $this->name;
}
/**
* get_title
*
* This function will return the Tool's title
*
* @date 19/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function get_title() {
return $this->title;
}
/**
* get_url
*
* This function will return the Tool's title
*
* @date 19/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function get_url() {
return acf_get_admin_tool_url( $this->name );
}
/**
* is_active
*
* This function will return true if the tool is active
*
* @date 19/10/17
* @since 5.6.3
*
* @param n/a
* @return bool
*/
function is_active() {
return acf_maybe_get_GET('tool') === $this->name;
}
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 27/6/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// initialize
$this->initialize();
}
/**
* initialize
*
* This function will initialize the admin tool
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function initialize() {
/* do nothing */
}
/**
* load
*
* This function is called during the admin page load
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function load() {
/* do nothing */
}
/**
* html
*
* This function will output the metabox HTML
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function html() {
}
/**
* submit
*
* This function will run when the tool's form has been submit
*
* @date 10/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
function submit() {
}
}
endif; // class_exists check
?>

View File

@@ -0,0 +1,161 @@
<?php
// vars
$disabled = false;
// empty
if( empty($field['conditional_logic']) ) {
$disabled = true;
$field['conditional_logic'] = array(
// group 0
array(
// rule 0
array()
)
);
}
?>
<tr class="acf-field acf-field-true-false acf-field-setting-conditional_logic" data_type="true_false" data-name="conditional_logic">
<td class="acf-label">
<label><?php _e("Conditional Logic",'acf'); ?></label>
</td>
<td class="acf-input">
<?php
acf_render_field(array(
'type' => 'true_false',
'name' => 'conditional_logic',
'prefix' => $field['prefix'],
'value' => $disabled ? 0 : 1,
'ui' => 1,
'class' => 'conditional-toggle',
));
?>
<div class="rule-groups" <?php if($disabled): ?>style="display:none;"<?php endif; ?>>
<?php foreach( $field['conditional_logic'] as $group_id => $group ):
// validate
if( empty($group) ) continue;
// vars
// $group_id must be completely different to $rule_id to avoid JS issues
$group_id = "group_{$group_id}";
$h4 = ($group_id == "group_0") ? __("Show this field if",'acf') : __("or",'acf');
?>
<div class="rule-group" data-id="<?php echo $group_id; ?>">
<h4><?php echo $h4; ?></h4>
<table class="acf-table -clear">
<tbody>
<?php foreach( $group as $rule_id => $rule ):
// valid rule
$rule = wp_parse_args( $rule, array(
'field' => '',
'operator' => '==',
'value' => '',
));
// vars
// $group_id must be completely different to $rule_id to avoid JS issues
$rule_id = "rule_{$rule_id}";
$prefix = "{$field['prefix']}[conditional_logic][{$group_id}][{$rule_id}]";
?>
<tr class="rule" data-id="<?php echo $rule_id; ?>">
<td class="param">
<?php
$choices = array();
$choices[ $rule['field'] ] = $rule['field'];
// create field
acf_render_field(array(
'type' => 'select',
'prefix' => $prefix,
'name' => 'field',
'value' => $rule['field'],
'choices' => $choices,
'class' => 'conditional-rule-param',
'disabled' => $disabled,
));
?>
</td>
<td class="operator">
<?php
$choices = array(
'==' => __("is equal to",'acf'),
'!=' => __("is not equal to",'acf'),
);
// create field
acf_render_field(array(
'type' => 'select',
'prefix' => $prefix,
'name' => 'operator',
'value' => $rule['operator'],
'choices' => $choices,
'class' => 'conditional-rule-operator',
'disabled' => $disabled,
));
?>
</td>
<td class="value">
<?php
$choices = array();
$choices[ $rule['value'] ] = $rule['value'];
// create field
acf_render_field(array(
'type' => 'select',
'prefix' => $prefix,
'name' => 'value',
'value' => $rule['value'],
'choices' => $choices,
'class' => 'conditional-rule-value',
'disabled' => $disabled,
));
?>
</td>
<td class="add">
<a href="#" class="button add-conditional-rule"><?php _e("and",'acf'); ?></a>
</td>
<td class="remove">
<a href="#" class="acf-icon -minus remove-conditional-rule"></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endforeach; ?>
<h4><?php _e("or",'acf'); ?></h4>
<a href="#" class="button add-conditional-group"><?php _e("Add rule group",'acf'); ?></a>
</div>
</td>
</tr>

View File

@@ -0,0 +1,186 @@
<?php
// add prefix
$field['prefix'] = "acf_fields[{$field['ID']}]";
// vars
$atts = array(
'class' => "acf-field-object acf-field-object-{$field['type']}",
'data-id' => $field['ID'],
'data-key' => $field['key'],
'data-type' => $field['type'],
);
$meta = array(
'ID' => $field['ID'],
'key' => $field['key'],
'parent' => $field['parent'],
'menu_order' => $field['menu_order'],
'save' => '',
);
// class
$atts['class'] = str_replace('_', '-', $atts['class']);
?>
<div <?php echo acf_esc_attr( $atts ); ?>>
<div class="meta">
<?php foreach( $meta as $k => $v ):
acf_hidden_input(array( 'class' => "input-{$k}", 'name' => "{$field['prefix']}[{$k}]", 'value' => $v ));
endforeach; ?>
</div>
<div class="handle">
<ul class="acf-hl acf-tbody">
<li class="li-field-order">
<span class="acf-icon acf-sortable-handle" title="<?php _e('Drag to reorder','acf'); ?>"><?php echo ($i + 1); ?></span>
</li>
<li class="li-field-label">
<strong>
<a class="edit-field" title="<?php _e("Edit field",'acf'); ?>" href="#"><?php echo acf_get_field_label($field); ?></a>
</strong>
<div class="row-options">
<a class="edit-field" title="<?php _e("Edit field",'acf'); ?>" href="#"><?php _e("Edit",'acf'); ?></a>
<a class="duplicate-field" title="<?php _e("Duplicate field",'acf'); ?>" href="#"><?php _e("Duplicate",'acf'); ?></a>
<a class="move-field" title="<?php _e("Move field to another group",'acf'); ?>" href="#"><?php _e("Move",'acf'); ?></a>
<a class="delete-field" title="<?php _e("Delete field",'acf'); ?>" href="#"><?php _e("Delete",'acf'); ?></a>
</div>
</li>
<li class="li-field-name"><?php echo $field['name']; ?></li>
<li class="li-field-key"><?php echo $field['key']; ?></li>
<li class="li-field-type"><?php echo acf_get_field_type_label($field['type']); ?></li>
</ul>
</div>
<div class="settings">
<table class="acf-table">
<tbody>
<?php
// label
acf_render_field_setting($field, array(
'label' => __('Field Label','acf'),
'instructions' => __('This is the name which will appear on the EDIT page','acf'),
'name' => 'label',
'type' => 'text',
'class' => 'field-label'
), true);
// name
acf_render_field_setting($field, array(
'label' => __('Field Name','acf'),
'instructions' => __('Single word, no spaces. Underscores and dashes allowed','acf'),
'name' => 'name',
'type' => 'text',
'class' => 'field-name'
), true);
// type
acf_render_field_setting($field, array(
'label' => __('Field Type','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'type',
'choices' => acf_get_field_types(),
'class' => 'field-type'
), true);
// instructions
acf_render_field_setting($field, array(
'label' => __('Instructions','acf'),
'instructions' => __('Instructions for authors. Shown when submitting data','acf'),
'type' => 'textarea',
'name' => 'instructions',
'rows' => 5
), true);
// required
acf_render_field_setting($field, array(
'label' => __('Required?','acf'),
'instructions' => '',
'type' => 'true_false',
'name' => 'required',
'ui' => 1,
'class' => 'field-required'
), true);
// 3rd party settings
do_action('acf/render_field_settings', $field);
// type specific settings
do_action("acf/render_field_settings/type={$field['type']}", $field);
// conditional logic
acf_get_view('field-group-field-conditional-logic', array( 'field' => $field ));
// wrapper
acf_render_field_wrap(array(
'label' => __('Wrapper Attributes','acf'),
'instructions' => '',
'type' => 'number',
'name' => 'width',
'prefix' => $field['prefix'] . '[wrapper]',
'value' => $field['wrapper']['width'],
'prepend' => __('width', 'acf'),
'append' => '%',
'wrapper' => array(
'data-name' => 'wrapper',
'class' => 'acf-field-setting-wrapper'
)
), 'tr');
acf_render_field_wrap(array(
'label' => '',
'instructions' => '',
'type' => 'text',
'name' => 'class',
'prefix' => $field['prefix'] . '[wrapper]',
'value' => $field['wrapper']['class'],
'prepend' => __('class', 'acf'),
'wrapper' => array(
'data-append' => 'wrapper'
)
), 'tr');
acf_render_field_wrap(array(
'label' => '',
'instructions' => '',
'type' => 'text',
'name' => 'id',
'prefix' => $field['prefix'] . '[wrapper]',
'value' => $field['wrapper']['id'],
'prepend' => __('id', 'acf'),
'wrapper' => array(
'data-append' => 'wrapper'
)
), 'tr');
?>
<tr class="acf-field acf-field-save">
<td class="acf-label"></td>
<td class="acf-input">
<ul class="acf-hl">
<li>
<a class="button edit-field" title="<?php _e("Close Field",'acf'); ?>" href="#"><?php _e("Close Field",'acf'); ?></a>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
</div>

View File

@@ -0,0 +1,52 @@
<div class="acf-field-list-wrap">
<ul class="acf-hl acf-thead">
<li class="li-field-order"><?php _e('Order','acf'); ?></li>
<li class="li-field-label"><?php _e('Label','acf'); ?></li>
<li class="li-field-name"><?php _e('Name','acf'); ?></li>
<li class="li-field-key"><?php _e('Key','acf'); ?></li>
<li class="li-field-type"><?php _e('Type','acf'); ?></li>
</ul>
<div class="acf-field-list">
<div class="no-fields-message" <?php if( $fields ){ echo 'style="display:none;"'; } ?>>
<?php _e("No fields. Click the <strong>+ Add Field</strong> button to create your first field.",'acf'); ?>
</div>
<?php if( $fields ):
foreach( $fields as $i => $field ):
acf_get_view('field-group-field', array( 'field' => $field, 'i' => $i ));
endforeach;
endif; ?>
</div>
<ul class="acf-hl acf-tfoot">
<li class="acf-fr">
<a href="#" class="button button-primary button-large add-field"><?php _e('+ Add Field','acf'); ?></a>
</li>
</ul>
<?php if( !$parent ):
// get clone
$clone = acf_get_valid_field(array(
'ID' => 'acfcloneindex',
'key' => 'acfcloneindex',
'label' => __('New Field','acf'),
'name' => 'new_field',
'type' => 'text'
));
?>
<script type="text/html" id="tmpl-acf-field">
<?php acf_get_view('field-group-field', array( 'field' => $clone, 'i' => 0 )); ?>
</script>
<?php endif;?>
</div>

View File

@@ -0,0 +1,45 @@
<?php
// global
global $field_group;
?>
<div class="acf-field">
<div class="acf-label">
<label><?php _e("Rules",'acf'); ?></label>
<p class="description"><?php _e("Create a set of rules to determine which edit screens will use these advanced custom fields",'acf'); ?></p>
</div>
<div class="acf-input">
<div class="rule-groups">
<?php foreach( $field_group['location'] as $i => $group ):
// bail ealry if no group
if( empty($group) ) return;
// view
acf_get_view('html-location-group', array(
'group' => $group,
'group_id' => "group_{$i}"
));
endforeach; ?>
<h4><?php _e("or",'acf'); ?></h4>
<a href="#" class="button add-location-group"><?php _e("Add rule group",'acf'); ?></a>
</div>
</div>
</div>
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
acf.postbox.render({
'id': 'acf-field-group-locations',
'label': 'left'
});
}
</script>

View File

@@ -0,0 +1,150 @@
<?php
// global
global $field_group;
// active
acf_render_field_wrap(array(
'label' => __('Active','acf'),
'instructions' => '',
'type' => 'true_false',
'name' => 'active',
'prefix' => 'acf_field_group',
'value' => $field_group['active'],
'ui' => 1,
//'ui_on_text' => __('Active', 'acf'),
//'ui_off_text' => __('Inactive', 'acf'),
));
// style
acf_render_field_wrap(array(
'label' => __('Style','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'style',
'prefix' => 'acf_field_group',
'value' => $field_group['style'],
'choices' => array(
'default' => __("Standard (WP metabox)",'acf'),
'seamless' => __("Seamless (no metabox)",'acf'),
)
));
// position
acf_render_field_wrap(array(
'label' => __('Position','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'position',
'prefix' => 'acf_field_group',
'value' => $field_group['position'],
'choices' => array(
'acf_after_title' => __("High (after title)",'acf'),
'normal' => __("Normal (after content)",'acf'),
'side' => __("Side",'acf'),
),
'default_value' => 'normal'
));
// label_placement
acf_render_field_wrap(array(
'label' => __('Label placement','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'label_placement',
'prefix' => 'acf_field_group',
'value' => $field_group['label_placement'],
'choices' => array(
'top' => __("Top aligned",'acf'),
'left' => __("Left Aligned",'acf'),
)
));
// instruction_placement
acf_render_field_wrap(array(
'label' => __('Instruction placement','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'instruction_placement',
'prefix' => 'acf_field_group',
'value' => $field_group['instruction_placement'],
'choices' => array(
'label' => __("Below labels",'acf'),
'field' => __("Below fields",'acf'),
)
));
// menu_order
acf_render_field_wrap(array(
'label' => __('Order No.','acf'),
'instructions' => __('Field groups with a lower order will appear first','acf'),
'type' => 'number',
'name' => 'menu_order',
'prefix' => 'acf_field_group',
'value' => $field_group['menu_order'],
));
// description
acf_render_field_wrap(array(
'label' => __('Description','acf'),
'instructions' => __('Shown in field group list','acf'),
'type' => 'text',
'name' => 'description',
'prefix' => 'acf_field_group',
'value' => $field_group['description'],
));
// hide on screen
acf_render_field_wrap(array(
'label' => __('Hide on screen','acf'),
'instructions' => __('<b>Select</b> items to <b>hide</b> them from the edit screen.','acf') . '<br /><br />' . __("If multiple field groups appear on an edit screen, the first field group's options will be used (the one with the lowest order number)",'acf'),
'type' => 'checkbox',
'name' => 'hide_on_screen',
'prefix' => 'acf_field_group',
'value' => $field_group['hide_on_screen'],
'toggle' => true,
'choices' => array(
'permalink' => __("Permalink", 'acf'),
'the_content' => __("Content Editor",'acf'),
'excerpt' => __("Excerpt", 'acf'),
'custom_fields' => __("Custom Fields", 'acf'),
'discussion' => __("Discussion", 'acf'),
'comments' => __("Comments", 'acf'),
'revisions' => __("Revisions", 'acf'),
'slug' => __("Slug", 'acf'),
'author' => __("Author", 'acf'),
'format' => __("Format", 'acf'),
'page_attributes' => __("Page Attributes", 'acf'),
'featured_image' => __("Featured Image", 'acf'),
'categories' => __("Categories", 'acf'),
'tags' => __("Tags", 'acf'),
'send-trackbacks' => __("Send Trackbacks", 'acf'),
)
));
// 3rd party settings
do_action('acf/render_field_group_settings', $field_group);
?>
<div class="acf-hidden">
<input type="hidden" name="acf_field_group[key]" value="<?php echo $field_group['key']; ?>" />
</div>
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
acf.postbox.render({
'id': 'acf-field-group-options',
'label': 'left'
});
}
</script>

View File

@@ -0,0 +1,27 @@
<?php
/**
* html-admin-tools
*
* View to output admin tools for both archive and single
*
* @date 20/10/17
* @since 5.6.3
*
* @param string $screen_id The screen ID used to display metaboxes
* @param string $active The active Tool
* @return n/a
*/
$class = $active ? 'single' : 'grid';
?>
<div class="wrap" id="acf-admin-tools">
<h1><?php _e('Tools', 'acf'); ?> <?php if( $active ): ?><a class="page-title-action" href="<?php echo acf_get_admin_tools_url(); ?>">Back to all tools</a><?php endif; ?></h1>
<div class="acf-meta-box-wrap -<?php echo $class; ?>">
<?php do_meta_boxes( $screen_id, 'normal', '' ); ?>
</div>
</div>

View File

@@ -0,0 +1,27 @@
<div class="rule-group" data-id="<?php echo $group_id; ?>">
<h4><?php echo ($group_id == 'group_0') ? __("Show this field group if",'acf') : __("or",'acf'); ?></h4>
<table class="acf-table -clear">
<tbody>
<?php foreach( $group as $i => $rule ):
// append id
$rule['id'] = "rule_{$i}";
$rule['group'] = $group_id;
// valid rule
$rule = acf_get_valid_location_rule($rule);
// view
acf_get_view('html-location-rule', array(
'rule' => $rule
));
endforeach; ?>
</tbody>
</table>
</div>

View File

@@ -0,0 +1,85 @@
<tr data-id="<?php echo $rule['id']; ?>">
<td class="param">
<?php
// vars
$choices = acf_get_location_rule_types();
// array
if( is_array($choices) ) {
acf_render_field(array(
'type' => 'select',
'name' => 'param',
'prefix' => $rule['prefix'],
'value' => $rule['param'],
'choices' => $choices,
'class' => 'refresh-location-rule'
));
}
?>
</td>
<td class="operator">
<?php
// vars
$choices = acf_get_location_rule_operators( $rule );
// array
if( is_array($choices) ) {
acf_render_field(array(
'type' => 'select',
'name' => 'operator',
'prefix' => $rule['prefix'],
'value' => $rule['operator'],
'choices' => $choices
));
// custom
} else {
echo $choices;
}
?>
</td>
<td class="value">
<?php
// vars
$choices = acf_get_location_rule_values( $rule );
// array
if( is_array($choices) ) {
acf_render_field(array(
'type' => 'select',
'name' => 'value',
'prefix' => $rule['prefix'],
'value' => $rule['value'],
'choices' => $choices
));
// custom
} else {
echo $choices;
}
?>
</td>
<td class="add">
<a href="#" class="button add-location-rule"><?php _e("and",'acf'); ?></a>
</td>
<td class="remove">
<a href="#" class="acf-icon -minus remove-location-rule"></a>
</td>
</tr>

View File

@@ -0,0 +1,235 @@
<?php
// vars
$button = __('Upgrade Sites');
?>
<div id="acf-upgrade-wrap" class="wrap">
<h1><?php _e("Advanced Custom Fields Database Upgrade",'acf'); ?></h1>
<p><?php echo sprintf( __("The following sites require a DB upgrade. Check the ones you want to update and then click %s.", 'acf'), '"' . $button . '"'); ?></p>
<p><input type="submit" name="upgrade" value="<?php echo $button; ?>" class="button" id="upgrade-sites"></p>
<table class="wp-list-table widefat">
<thead>
<tr>
<td class="manage-column check-column" scope="col"><input type="checkbox" id="sites-select-all"></td>
<th class="manage-column" scope="col" style="width:33%;"><label for="sites-select-all"><?php _e("Site", 'acf'); ?></label></th>
<th><?php _e("Description", 'acf'); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<td class="manage-column check-column" scope="col"><input type="checkbox" id="sites-select-all-2"></td>
<th class="manage-column" scope="col"><label for="sites-select-all-2"><?php _e("Site", 'acf'); ?></label></th>
<th><?php _e("Description", 'acf'); ?></th>
</tr>
</tfoot>
<tbody id="the-list">
<?php foreach( $sites as $i => $site ): ?>
<tr<?php if( $i % 2 == 0 ): ?> class="alternate"<?php endif; ?>>
<th class="check-column" scope="row">
<?php if( $site['updates'] ): ?>
<input type="checkbox" value="<?php echo $site['blog_id']; ?>" name="checked[]">
<?php endif; ?>
</th>
<td>
<strong><?php echo $site['name']; ?></strong><br /><?php echo $site['url']; ?>
</td>
<td>
<?php if( $site['updates'] ): ?>
<span class="response"><?php printf(__('Site requires database upgrade from %s to %s', 'acf'), $site['acf_version'], $plugin_version); ?></span>
<?php else: ?>
<?php _e("Site is up to date", 'acf'); ?>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<p><input type="submit" name="upgrade" value="<?php echo $button; ?>" class="button" id="upgrade-sites-2"></p>
<p class="show-on-complete"><?php echo sprintf( __('Database Upgrade complete. <a href="%s">Return to network dashboard</a>', 'acf'), network_admin_url() ); ?></p>
<style type="text/css">
/* hide show */
.show-on-complete {
display: none;
}
</style>
<script type="text/javascript">
(function($) {
var upgrader = {
$buttons: null,
$inputs: null,
i: 0,
init : function(){
// reference
var self = this;
// vars
this.$buttons = $('#upgrade-sites, #upgrade-sites-2');
// events
this.$buttons.on('click', function( e ){
// prevent default
e.preventDefault();
// confirm
var answer = confirm("<?php _e('It is strongly recommended that you backup your database before proceeding. Are you sure you wish to run the updater now?', 'acf'); ?>");
// bail early if no confirm
if( !answer ) {
return;
}
// populate inputs
self.$inputs = $('#the-list input:checked');
// upgrade
self.upgrade();
});
// return
return this;
},
upgrade: function(){
// reference
var self = this;
// bail early if no sites
if( !this.$inputs.length ) {
return;
}
// complete
if( this.i >= this.$inputs.length ) {
this.complete();
return;
}
// disable buttons
this.$buttons.attr('disabled', 'disabled');
// vars
var $input = this.$inputs.eq( this.i ),
$tr = $input.closest('tr'),
text = '<?php _e('Upgrade complete', 'acf'); ?>';
// add loading
$tr.find('.response').html('<i class="acf-loading"></i></span> <?php printf(__('Upgrading data to version %s', 'acf'), $plugin_version); ?>');
// get results
var xhr = $.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
dataType: 'json',
type: 'post',
data: {
action: 'acf/admin/db_update',
nonce: '<?php echo wp_create_nonce('acf_db_update'); ?>',
blog_id: $input.val(),
},
success: function( json ){
// remove input
$input.prop('checked', false);
$input.remove();
// vars
var message = acf.get_ajax_message(json);
// bail early if no message text
if( !message.text ) {
return;
}
// update text
text = '<pre>' + message.text + '</pre>';
},
complete: function(){
$tr.find('.response').html( text );
// upgrade next site
self.next();
}
});
},
next: function(){
this.i++;
this.upgrade();
},
complete: function(){
// enable buttons
this.$buttons.removeAttr('disabled');
// show message
$('.show-on-complete').show();
}
}.init();
})(jQuery);
</script>
</div>

View File

@@ -0,0 +1,57 @@
<?php
// calculate add-ons (non pro only)
$plugins = array();
if( !acf_get_setting('pro') ) {
if( is_plugin_active('acf-repeater/acf-repeater.php') ) $plugins[] = __("Repeater",'acf');
if( is_plugin_active('acf-flexible-content/acf-flexible-content.php') ) $plugins[] = __("Flexible Content",'acf');
if( is_plugin_active('acf-gallery/acf-gallery.php') ) $plugins[] = __("Gallery",'acf');
if( is_plugin_active('acf-options-page/acf-options-page.php') ) $plugins[] = __("Options Page",'acf');
}
?>
<div id="acf-upgrade-notice">
<div class="inner">
<div class="acf-icon logo">
<i class="acf-sprite-logo"></i>
</div>
<div class="content">
<h2><?php _e("Database Upgrade Required",'acf'); ?></h2>
<p><?php printf(__("Thank you for updating to %s v%s!", 'acf'), acf_get_setting('name'), acf_get_setting('version') ); ?><br /><?php _e("Before you start using the new awesome features, please update your database to the newest version.", 'acf'); ?></p>
<?php if( !empty($plugins) ): ?>
<p><?php printf(__("Please also ensure any premium add-ons (%s) have first been updated to the latest version.", 'acf'), implode(', ', $plugins) ); ?></p>
<?php endif; ?>
<p><a id="acf-notice-action" href="<?php echo $button_url; ?>" class="button button-primary"><?php echo $button_text; ?></a></p>
<?php if( $confirm ): ?>
<script type="text/javascript">
(function($) {
$("#acf-notice-action").on("click", function(){
var answer = confirm("<?php _e( 'It is strongly recommended that you backup your database before proceeding. Are you sure you wish to run the updater now?', 'acf' ); ?>");
return answer;
});
})(jQuery);
</script>
<?php endif; ?>
</div>
<div class="clear"></div>
</div>
</div>

View File

@@ -0,0 +1,109 @@
<div id="acf-upgrade-wrap" class="wrap">
<h1><?php _e("Advanced Custom Fields Database Upgrade",'acf'); ?></h1>
<?php if( $updates ): ?>
<p><?php _e('Reading upgrade tasks...', 'acf'); ?></p>
<p class="show-on-ajax"><i class="acf-loading"></i> <?php printf(__('Upgrading data to version %s', 'acf'), $plugin_version); ?></p>
<p class="show-on-complete"><?php echo sprintf( __('Database Upgrade complete. <a href="%s">See what\'s new</a>', 'acf' ), admin_url('edit.php?post_type=acf-field-group&page=acf-settings-info') ); ?></p>
<style type="text/css">
/* hide show */
.show-on-ajax,
.show-on-complete {
display: none;
}
</style>
<script type="text/javascript">
(function($) {
var upgrader = {
init: function(){
// reference
var self = this;
// allow user to read message for 1 second
setTimeout(function(){
self.upgrade();
}, 1000);
// return
return this;
},
upgrade: function(){
// reference
var self = this;
// show message
$('.show-on-ajax').show();
// get results
var xhr = $.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
dataType: 'json',
type: 'post',
data: {
action: 'acf/admin/db_update',
nonce: '<?php echo wp_create_nonce('acf_db_update'); ?>'
},
success: function( json ){
// vars
var message = acf.get_ajax_message(json);
// bail early if no message text
if( !message.text ) {
return;
}
// show message
$('.show-on-ajax').html( message.text );
},
complete: function( json ){
// remove spinner
$('.acf-loading').hide();
// show complete
$('.show-on-complete').show();
}
});
}
}.init();
})(jQuery);
</script>
<?php else: ?>
<p><?php _e('No updates available.', 'acf'); ?></p>
<?php endif; ?>
</div>

View File

@@ -0,0 +1,54 @@
<div class="wrap acf-settings-wrap">
<h1><?php _e("Add-ons",'acf'); ?></h1>
<div class="add-ons-list">
<?php if( !empty($json) ): ?>
<?php foreach( $json as $addon ):
$addon = wp_parse_args($addon, array(
"title" => "",
"slug" => "",
"description" => "",
"thumbnail" => "",
"url" => "",
"btn" => __("Download & Install",'acf'),
"btn_color" => ""
));
?>
<div class="acf-box add-on add-on-<?php echo $addon['slug']; ?>">
<div class="thumbnail">
<a target="_blank" href="<?php echo $addon['url']; ?>">
<img src="<?php echo $addon['thumbnail']; ?>" />
</a>
</div>
<div class="inner">
<h3><a target="_blank" href="<?php echo $addon['url']; ?>"><?php echo $addon['title']; ?></a></h3>
<p><?php echo $addon['description']; ?></p>
</div>
<div class="footer">
<?php if( apply_filters("acf/is_add_on_active/slug={$addon['slug']}", false ) ): ?>
<a class="button" disabled="disabled"><?php _e("Installed",'acf'); ?></a>
<?php else: ?>
<a class="button <?php echo $addon['btn_color']; ?>" target="_blank" href="<?php echo $addon['url']; ?>" ><?php _e($addon['btn']); ?></a>
<?php endif; ?>
<?php if( !empty($addon['footer']) ): ?>
<p><?php echo $addon['footer']; ?></p>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>

View File

@@ -0,0 +1,183 @@
<div class="wrap about-wrap acf-wrap">
<h1><?php _e("Welcome to Advanced Custom Fields",'acf'); ?> <?php echo $version; ?></h1>
<div class="about-text"><?php printf(__("Thank you for updating! ACF %s is bigger and better than ever before. We hope you like it.", 'acf'), $version); ?></div>
<div class="acf-icon logo">
<i class="acf-sprite-logo"></i>
</div>
<h2 class="nav-tab-wrapper">
<?php foreach( $tabs as $tab_slug => $tab_title ): ?>
<a class="nav-tab<?php if( $active == $tab_slug ): ?> nav-tab-active<?php endif; ?>" href="<?php echo admin_url("edit.php?post_type=acf-field-group&page=acf-settings-info&tab={$tab_slug}"); ?>"><?php echo $tab_title; ?></a>
<?php endforeach; ?>
</h2>
<?php if( $active == 'new' ): ?>
<h2 class="about-headline-callout"><?php _e("A smoother custom field experience", 'acf'); ?></h2>
<div class="feature-section acf-three-col">
<div>
<img src="https://assets.advancedcustomfields.com/info/5.0.0/select2.png">
<h3><?php _e("Improved Usability", 'acf'); ?></h3>
<p><?php _e("Including the popular Select2 library has improved both usability and speed across a number of field types including post object, page link, taxonomy and select.", 'acf'); ?></p>
</div>
<div>
<img src="https://assets.advancedcustomfields.com/info/5.0.0/design.png">
<h3><?php _e("Improved Design", 'acf'); ?></h3>
<p><?php _e("Many fields have undergone a visual refresh to make ACF look better than ever! Noticeable changes are seen on the gallery, relationship and oEmbed (new) fields!", 'acf'); ?></p>
</div>
<div>
<img src="https://assets.advancedcustomfields.com/info/5.0.0/sub-fields.png">
<h3><?php _e("Improved Data", 'acf'); ?></h3>
<p><?php _e("Redesigning the data architecture has allowed sub fields to live independently from their parents. This allows you to drag and drop fields in and out of parent fields!", 'acf'); ?></p>
</div>
</div>
<hr />
<h2 class="about-headline-callout"><?php _e("Goodbye Add-ons. Hello PRO", 'acf'); ?></h2>
<div class="feature-section acf-three-col">
<div>
<h3><?php _e("Introducing ACF PRO", 'acf'); ?></h3>
<p><?php _e("We're changing the way premium functionality is delivered in an exciting way!", 'acf'); ?></p>
<p><?php printf(__('All 4 premium add-ons have been combined into a new <a href="%s">Pro version of ACF</a>. With both personal and developer licenses available, premium functionality is more affordable and accessible than ever before!', 'acf'), esc_url('https://www.advancedcustomfields.com/pro')); ?></p>
</div>
<div>
<h3><?php _e("Powerful Features", 'acf'); ?></h3>
<p><?php _e("ACF PRO contains powerful features such as repeatable data, flexible content layouts, a beautiful gallery field and the ability to create extra admin options pages!", 'acf'); ?></p>
<p><?php printf(__('Read more about <a href="%s">ACF PRO features</a>.', 'acf'), esc_url('https://www.advancedcustomfields.com/pro')); ?></p>
</div>
<div>
<h3><?php _e("Easy Upgrading", 'acf'); ?></h3>
<p><?php printf(__('To help make upgrading easy, <a href="%s">login to your store account</a> and claim a free copy of ACF PRO!', 'acf'), esc_url('https://www.advancedcustomfields.com/my-account/')); ?></p>
<p><?php printf(__('We also wrote an <a href="%s">upgrade guide</a> to answer any questions, but if you do have one, please contact our support team via the <a href="%s">help desk</a>', 'acf'), esc_url('https://www.advancedcustomfields.com/resources/updates/upgrading-v4-v5/'), esc_url('https://support.advancedcustomfields.com')); ?>
</div>
</div>
<hr />
<h2 class="about-headline-callout"><?php _e("Under the Hood", 'acf'); ?></h2>
<div class="feature-section acf-three-col">
<div>
<h4><?php _e("Smarter field settings", 'acf'); ?></h4>
<p><?php _e("ACF now saves its field settings as individual post objects", 'acf'); ?></p>
</div>
<div>
<h4><?php _e("More AJAX", 'acf'); ?></h4>
<p><?php _e("More fields use AJAX powered search to speed up page loading", 'acf'); ?></p>
</div>
<div>
<h4><?php _e("Local JSON", 'acf'); ?></h4>
<p><?php _e("New auto export to JSON feature improves speed", 'acf'); ?></p>
</div>
<br />
<div>
<h4><?php _e("Better version control", 'acf'); ?></h4>
<p><?php _e("New auto export to JSON feature allows field settings to be version controlled", 'acf'); ?></p>
</div>
<div>
<h4><?php _e("Swapped XML for JSON", 'acf'); ?></h4>
<p><?php _e("Import / Export now uses JSON in favour of XML", 'acf'); ?></p>
</div>
<div>
<h4><?php _e("New Forms", 'acf'); ?></h4>
<p><?php _e("Fields can now be mapped to comments, widgets and all user forms!", 'acf'); ?></p>
</div>
<br />
<div>
<h4><?php _e("New Field", 'acf'); ?></h4>
<p><?php _e("A new field for embedding content has been added", 'acf'); ?></p>
</div>
<div>
<h4><?php _e("New Gallery", 'acf'); ?></h4>
<p><?php _e("The gallery field has undergone a much needed facelift", 'acf'); ?></p>
</div>
<div>
<h4><?php _e("New Settings", 'acf'); ?></h4>
<p><?php _e("Field group settings have been added for label placement and instruction placement", 'acf'); ?></p>
</div>
<br />
<div>
<h4><?php _e("Better Front End Forms", 'acf'); ?></h4>
<p><?php _e("acf_form() can now create a new post on submission", 'acf'); ?></p>
</div>
<div>
<h4><?php _e("Better Validation", 'acf'); ?></h4>
<p><?php _e("Form validation is now done via PHP + AJAX in favour of only JS", 'acf'); ?></p>
</div>
<div>
<h4><?php _e("Relationship Field", 'acf'); ?></h4>
<p><?php _e("New Relationship field setting for 'Filters' (Search, Post Type, Taxonomy)", 'acf'); ?></p>
</div>
<br />
<div>
<h4><?php _e("Moving Fields", 'acf'); ?></h4>
<p><?php _e("New field group functionality allows you to move a field between groups & parents", 'acf'); ?></p>
</div>
<div>
<h4><?php _e("Page Link", 'acf'); ?></h4>
<p><?php _e("New archives group in page_link field selection", 'acf'); ?></p>
</div>
<div>
<h4><?php _e("Better Options Pages", 'acf'); ?></h4>
<p><?php _e("New functions for options page allow creation of both parent and child menu pages", 'acf'); ?></p>
</div>
</div>
<?php elseif( $active == 'changelog' ): ?>
<p class="about-description"><?php printf(__("We think you'll love the changes in %s.", 'acf'), $version); ?></p>
<?php
$items = file_get_contents( acf_get_path('readme.txt') );
$items = explode('= ' . $version . ' =', $items);
$items = end( $items );
$items = current( explode("\n\n", $items) );
$items = array_filter( array_map('trim', explode("*", $items)) );
?>
<ul class="changelog">
<?php foreach( $items as $item ):
$item = explode('http', $item);
?>
<li><?php echo $item[0]; ?><?php if( isset($item[1]) ): ?><a href="http<?php echo $item[1]; ?>" target="_blank">[...]</a><?php endif; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>

View File

@@ -0,0 +1,86 @@
<?php
/*
* ACF AJAX Class
*
* All the logic for misc AJAX functionality
*
* @class acf_ajax
* @package ACF
* @subpackage Core
*/
if( ! class_exists('acf_ajax') ) :
class acf_ajax {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// acf/update_user_setting
add_action( 'wp_ajax_acf/update_user_setting', array($this, 'update_user_setting') );
add_action( 'wp_ajax_nopriv_acf/update_user_setting', array($this, 'update_user_setting') );
}
/*
* update_user_setting
*
* This function will update a user setting
*
* @type function
* @date 15/07/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function update_user_setting() {
// options
$options = wp_parse_args( $_POST, array(
'name' => '',
'value' => '',
'nonce' => '',
));
// validate
if( ! wp_verify_nonce($options['nonce'], 'acf_nonce') || empty($options['name']) ) {
die('0');
}
// upadte setting
acf_update_user_setting( $options['name'], $options['value'] );
// return
die('1');
}
}
new acf_ajax();
endif;
?>

View File

@@ -0,0 +1,615 @@
<?php
/*
* acf_esc_html
*
* This function will encode <script> tags for safe output
*
* @type function
* @date 25/6/17
* @since 5.6.0
*
* @param string (string)
* @return (string)
*/
function acf_esc_html( $string = '' ) {
// cast
$string = (string) $string;
// replace
$string = str_replace('<script', htmlspecialchars('<script'), $string);
$string = str_replace('</script', htmlspecialchars('</script'), $string);
// return
return $string;
}
/**
* acf_clean_atts
*
* This function will remove empty attributes
*
* @date 3/10/17
* @since 5.6.3
*
* @param array $atts
* @return array
*/
function acf_clean_atts( $atts = array() ) {
// loop
foreach( $atts as $k => $v ) {
if( $v === '' ) unset( $atts[ $k ] );
}
// return
return $atts;
}
/**
* acf_get_atts
*
* This function will return an array of HTML attributes
*
* @date 2/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
/*
function acf_get_atts( $array, $keys ) {
// vars
$atts = array();
// append attributes
foreach( $keys as $k ) {
if( isset($array[ $k ]) ) $atts[ $k ] = $array[ $k ];
}
// modify special attributes
foreach( array('readonly', 'disabled', 'required') as $k ) {
$atts[ $k ] = $atts[ $k ] ? $k : '';
}
// clean up blank attributes
foreach( $atts as $k => $v ) {
if( $v === '' ) unset( $atts[ $k ] );
}
// return
return $atts;
}
*/
/*
* acf_esc_atts
*
* This function will escape an array of attributes and return as HTML
*
* @type function
* @date 27/6/17
* @since 5.6.0
*
* @param $atts (array)
* @return (string)
*/
function acf_esc_atts( $atts = array() ) {
// vars
$html = '';
// loop
foreach( $atts as $k => $v ) {
// string
if( is_string($v) ) {
// don't trim value
if( $k !== 'value') $v = trim($v);
// boolean
} elseif( is_bool($v) ) {
$v = $v ? 1 : 0;
// object
} elseif( is_array($v) || is_object($v) ) {
$v = json_encode($v);
}
// append
$html .= esc_attr( $k ) . '="' . esc_attr( $v ) . '" ';
}
// return
return trim( $html );
}
/*
* acf_esc_atts_e
*
* This function will echo acf_esc_atts
*
* @type function
* @date 27/6/17
* @since 5.6.0
*
* @param $atts (array)
* @return n/a
*/
function acf_esc_atts_e( $atts = array() ) {
echo acf_esc_atts( $atts );
}
/*
* acf_get_text_input
*
* This function will return HTML for a text input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_text_input( $atts = array() ) {
$atts['type'] = isset($atts['type']) ? $atts['type'] : 'text';
return '<input ' . acf_esc_atts( $atts ) . ' />';
}
/*
* acf_text_input
*
* This function will output HTML for a text input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_text_input( $atts = array() ) {
echo acf_get_text_input( $atts );
}
/*
* acf_get_hidden_input
*
* This function will return HTML for a hidden input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_hidden_input( $atts = array() ) {
$atts['type'] = 'hidden';
return acf_get_text_input( $atts );
}
/*
* acf_hidden_input
*
* This function will output HTML for a generic input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_hidden_input( $atts = array() ) {
echo acf_get_hidden_input( $atts ) . "\n";
}
/*
* acf_get_textarea_input
*
* This function will return HTML for a textarea input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_textarea_input( $atts = array() ) {
$value = acf_extract_var( $atts, 'value', '' );
return '<textarea ' . acf_esc_atts( $atts ) . '>' . esc_textarea( $value ) . '</textarea>';
}
/*
* acf_textarea_input
*
* This function will output HTML for a textarea input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_textarea_input( $atts = array() ) {
echo acf_get_textarea_input( $atts );
}
/*
* acf_get_checkbox_input
*
* This function will return HTML for a checkbox input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_checkbox_input( $atts = array() ) {
$label = acf_extract_var( $atts, 'label', '' );
$checked = acf_maybe_get( $atts, 'checked', '' );
$atts['type'] = acf_maybe_get( $atts, 'type', 'checkbox' );
return '<label' . ($checked ? ' class="selected"' : '') . '><input ' . acf_esc_attr( $atts ) . '/>' . acf_esc_html( $label ) . '</label>';
}
/*
* acf_checkbox_input
*
* This function will output HTML for a checkbox input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_checkbox_input( $atts = array() ) {
echo acf_get_checkbox_input( $atts );
}
/*
* acf_get_radio_input
*
* This function will return HTML for a radio input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_radio_input( $atts = array() ) {
$atts['type'] = 'radio';
return acf_get_checkbox_input( $atts );
}
/*
* acf_radio_input
*
* This function will output HTML for a radio input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_radio_input( $atts = array() ) {
echo acf_get_radio_input( $atts );
}
/*
* acf_get_select_input
*
* This function will return HTML for a select input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_select_input( $atts = array() ) {
// vars
$value = (array) acf_extract_var( $atts, 'value' );
$choices = (array) acf_extract_var( $atts, 'choices' );
// html
$html = '';
$html .= '<select ' . acf_esc_atts( $atts ) . '>' . "\n";
$html .= acf_walk_select_input( $choices, $value );
$html .= '</select>' . "\n";
// return
return $html;
}
/*
* acf_walk_select_input
*
* This function will return the HTML for a select input's choices
*
* @type function
* @date 27/6/17
* @since 5.6.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_walk_select_input( $choices = array(), $values = array(), $depth = 0 ) {
// bail ealry if no choices
if( empty($choices) ) return '';
// vars
$html = '';
// sanitize values for 'selected' matching
if( $depth == 0 ) {
$values = array_map('esc_attr', $values);
}
// loop
foreach( $choices as $value => $label ) {
// optgroup
if( is_array($label) ){
$html .= '<optgroup label="' . esc_attr($value) . '">' . "\n";
$html .= acf_walk_select_input( $label, $values, $depth+1 );
$html .= '</optgroup>';
// option
} else {
// vars
$atts = array( 'value' => $value );
$pos = array_search( esc_attr($value), $values );
// selected
if( $pos !== false ) {
$atts['selected'] = 'selected';
$atts['data-i'] = $pos;
}
// append
$html .= '<option ' . acf_esc_attr($atts) . '>' . esc_html($label) . '</option>' . "\n";
}
}
// return
return $html;
}
/*
* acf_select_input
*
* This function will output HTML for a select input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_select_input( $atts = array() ) {
echo acf_get_select_input( $atts );
}
/*
function acf_test_esc_html( $string = '' ) {
$s = '';
$time_start = microtime(true);
$s .= wp_kses_post( $string );
$s .= ' = ('. (microtime(true) - $time_start) .')';
$s .= '-----';
$time_start = microtime(true);
$s .= str_replace(array('<script', '</script'), array(htmlspecialchars('<script'), htmlspecialchars('</script')), $string);
$s .= ' = ('. (microtime(true) - $time_start) .')';
$time_start = microtime(true);
if( strpos($string, '<script') ) {
$s .= str_replace(array('<script', '</script'), array(htmlspecialchars('<script'), htmlspecialchars('</script')), $string);
}
$s .= ' = ('. (microtime(true) - $time_start) .')';
return $s;
}
*/
/*
* acf_get_file_input
*
* This function will return HTML for a file input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_file_input( $atts = array() ) {
$atts['type'] = 'file';
return acf_get_text_input( $atts );
}
/*
* acf_file_input
*
* This function will output HTML for a file input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_file_input( $atts = array() ) {
echo acf_get_file_input( $atts );
}
/*
* acf_esc_attr
*
* Deprecated since 5.6.0
*
* @type function
* @date 1/10/13
* @since 5.0.0
*
* @param $atts (array)
* @return n/a
*/
function acf_esc_attr( $atts ) {
return acf_esc_atts( $atts );
}
/*
* acf_esc_attr_e
*
* Deprecated since 5.6.0
*
* @type function
* @date 1/10/13
* @since 5.0.0
*
* @param $atts (array)
* @return n/a
*/
function acf_esc_attr_e( $atts ) {
acf_esc_atts_e( $atts );
}
?>

View File

@@ -0,0 +1,524 @@
<?php
/*
* acf_get_metadata
*
* This function will get a value from the DB
*
* @type function
* @date 16/10/2015
* @since 5.2.3
*
* @param $post_id (mixed)
* @param $name (string)
* @param $hidden (boolean)
* @return $return (mixed)
*/
function acf_get_metadata( $post_id = 0, $name = '', $hidden = false ) {
// vars
$value = null;
$prefix = $hidden ? '_' : '';
// get post_id info
$info = acf_get_post_id_info($post_id);
// bail early if no $post_id (acf_form - new_post)
if( !$info['id'] ) return $value;
// option
if( $info['type'] === 'option' ) {
$name = $prefix . $post_id . '_' . $name;
$value = get_option( $name, null );
// meta
} else {
$name = $prefix . $name;
$meta = get_metadata( $info['type'], $info['id'], $name, false );
if( isset($meta[0]) ) {
$value = $meta[0];
}
}
// return
return $value;
}
/*
* acf_update_metadata
*
* This function will update a value from the DB
*
* @type function
* @date 16/10/2015
* @since 5.2.3
*
* @param $post_id (mixed)
* @param $name (string)
* @param $value (mixed)
* @param $hidden (boolean)
* @return $return (boolean)
*/
function acf_update_metadata( $post_id = 0, $name = '', $value = '', $hidden = false ) {
// vars
$return = false;
$prefix = $hidden ? '_' : '';
// get post_id info
$info = acf_get_post_id_info($post_id);
// bail early if no $post_id (acf_form - new_post)
if( !$info['id'] ) return $return;
// option
if( $info['type'] === 'option' ) {
$name = $prefix . $post_id . '_' . $name;
$return = acf_update_option( $name, $value );
// meta
} else {
$name = $prefix . $name;
$return = update_metadata( $info['type'], $info['id'], $name, $value );
}
// return
return $return;
}
/*
* acf_delete_metadata
*
* This function will delete a value from the DB
*
* @type function
* @date 16/10/2015
* @since 5.2.3
*
* @param $post_id (mixed)
* @param $name (string)
* @param $hidden (boolean)
* @return $return (boolean)
*/
function acf_delete_metadata( $post_id = 0, $name = '', $hidden = false ) {
// vars
$return = false;
$prefix = $hidden ? '_' : '';
// get post_id info
$info = acf_get_post_id_info($post_id);
// bail early if no $post_id (acf_form - new_post)
if( !$info['id'] ) return $return;
// option
if( $info['type'] === 'option' ) {
$name = $prefix . $post_id . '_' . $name;
$return = delete_option( $name );
// meta
} else {
$name = $prefix . $name;
$return = delete_metadata( $info['type'], $info['id'], $name );
}
// return
return $return;
}
/*
* acf_update_option
*
* This function is a wrapper for the WP update_option but provides logic for a 'no' autoload
*
* @type function
* @date 4/01/2014
* @since 5.0.0
*
* @param $option (string)
* @param $value (mixed)
* @param autoload (mixed)
* @return (boolean)
*/
function acf_update_option( $option = '', $value = '', $autoload = null ) {
// vars
$deprecated = '';
$return = false;
// autoload
if( $autoload === null ){
$autoload = acf_get_setting('autoload') ? 'yes' : 'no';
}
// for some reason, update_option does not use stripslashes_deep.
// update_metadata -> https://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/meta.php#L82: line 101 (does use stripslashes_deep)
// update_option -> https://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/option.php#L0: line 215 (does not use stripslashes_deep)
$value = stripslashes_deep($value);
// add or update
if( get_option($option) !== false ) {
$return = update_option( $option, $value );
} else {
$return = add_option( $option, $value, $deprecated, $autoload );
}
// return
return $return;
}
/*
* acf_get_value
*
* This function will load in a field's value
*
* @type function
* @date 28/09/13
* @since 5.0.0
*
* @param $post_id (int)
* @param $field (array)
* @return (mixed)
*/
function acf_get_value( $post_id = 0, $field ) {
// allow filter to short-circuit load_value logic
//$value = apply_filters( "acf/pre_load_value", null, $post_id, $field );
//if( $value !== null ) {
// return $value;
//}
// vars
$cache_key = "get_value/post_id={$post_id}/name={$field['name']}";
// return early if cache is found
if( acf_isset_cache($cache_key) ) {
return acf_get_cache($cache_key);
}
// load value
$value = acf_get_metadata( $post_id, $field['name'] );
// if value was duplicated, it may now be a serialized string!
$value = maybe_unserialize( $value );
// no value? try default_value
if( $value === null && isset($field['default_value']) ) {
$value = $field['default_value'];
}
// filter for 3rd party customization
$value = apply_filters( "acf/load_value", $value, $post_id, $field );
$value = apply_filters( "acf/load_value/type={$field['type']}", $value, $post_id, $field );
$value = apply_filters( "acf/load_value/name={$field['_name']}", $value, $post_id, $field );
$value = apply_filters( "acf/load_value/key={$field['key']}", $value, $post_id, $field );
// update cache
acf_set_cache($cache_key, $value);
// return
return $value;
}
/*
* acf_format_value
*
* This function will format the value for front end use
*
* @type function
* @date 3/07/2014
* @since 5.0.0
*
* @param $value (mixed)
* @param $post_id (mixed)
* @param $field (array)
* @return $value
*/
function acf_format_value( $value, $post_id, $field ) {
// vars
$cache_key = "format_value/post_id={$post_id}/name={$field['name']}";
// return early if cache is found
if( acf_isset_cache($cache_key) ) {
return acf_get_cache($cache_key);
}
// apply filters
$value = apply_filters( "acf/format_value", $value, $post_id, $field );
$value = apply_filters( "acf/format_value/type={$field['type']}", $value, $post_id, $field );
$value = apply_filters( "acf/format_value/name={$field['_name']}", $value, $post_id, $field );
$value = apply_filters( "acf/format_value/key={$field['key']}", $value, $post_id, $field );
// update cache
acf_set_cache($cache_key, $value);
// return
return $value;
}
/*
* acf_update_value
*
* updates a value into the db
*
* @type action
* @date 23/01/13
*
* @param $value (mixed)
* @param $post_id (mixed)
* @param $field (array)
* @return (boolean)
*/
function acf_update_value( $value = null, $post_id = 0, $field ) {
// strip slashes
if( acf_get_setting('stripslashes') ) {
$value = stripslashes_deep($value);
}
// filter for 3rd party customization
$value = apply_filters( "acf/update_value", $value, $post_id, $field );
$value = apply_filters( "acf/update_value/type={$field['type']}", $value, $post_id, $field );
$value = apply_filters( "acf/update_value/name={$field['_name']}", $value, $post_id, $field );
$value = apply_filters( "acf/update_value/key={$field['key']}", $value, $post_id, $field );
// allow null to delete
if( $value === null ) {
return acf_delete_value( $post_id, $field );
}
// update value
$return = acf_update_metadata( $post_id, $field['name'], $value );
// update reference
acf_update_metadata( $post_id, $field['name'], $field['key'], true );
// clear cache
acf_delete_cache("get_value/post_id={$post_id}/name={$field['name']}");
acf_delete_cache("format_value/post_id={$post_id}/name={$field['name']}");
// return
return $return;
}
/*
* acf_delete_value
*
* This function will delete a value from the database
*
* @type function
* @date 28/09/13
* @since 5.0.0
*
* @param $post_id (mixed)
* @param $field (array)
* @return (boolean)
*/
function acf_delete_value( $post_id = 0, $field ) {
// action for 3rd party customization
do_action("acf/delete_value", $post_id, $field['name'], $field);
do_action("acf/delete_value/type={$field['type']}", $post_id, $field['name'], $field);
do_action("acf/delete_value/name={$field['_name']}", $post_id, $field['name'], $field);
do_action("acf/delete_value/key={$field['key']}", $post_id, $field['name'], $field);
// delete value
$return = acf_delete_metadata( $post_id, $field['name'] );
// delete reference
acf_delete_metadata( $post_id, $field['name'], true );
// clear cache
acf_delete_cache("get_value/post_id={$post_id}/name={$field['name']}");
acf_delete_cache("format_value/post_id={$post_id}/name={$field['name']}");
// return
return $return;
}
/*
* acf_copy_postmeta
*
* This function will copy postmeta from one post to another.
* Very useful for saving and restoring revisions
*
* @type function
* @date 25/06/2016
* @since 5.3.8
*
* @param $from_post_id (int)
* @param $to_post_id (int)
* @return n/a
*/
function acf_copy_postmeta( $from_post_id, $to_post_id ) {
// get all postmeta
$meta = get_post_meta( $from_post_id );
// bail early if no meta
if( !$meta ) return;
// loop
foreach( $meta as $name => $value ) {
// attempt to find key value
$key = acf_maybe_get( $meta, '_'.$name );
// bail ealry if no key
if( !$key ) continue;
// update vars
$value = $value[0];
$key = $key[0];
// bail early if $key is a not a field_key
if( !acf_is_field_key($key) ) continue;
// get_post_meta will return array before running maybe_unserialize
$value = maybe_unserialize( $value );
// add in slashes
// - update_post_meta will unslash the value, so we must first slash it to avoid losing backslashes
// - https://codex.wordpress.org/Function_Reference/update_post_meta#Character_Escaping
if( is_string($value) ) {
$value = wp_slash($value);
}
// update value
acf_update_metadata( $to_post_id, $name, $value );
acf_update_metadata( $to_post_id, $name, $key, true );
}
}
/*
* acf_preview_value
*
* This function will return a human freindly 'preview' for a given field value
*
* @type function
* @date 24/10/16
* @since 5.5.0
*
* @param $value (mixed)
* @param $post_id (mixed)
* @param $field (array)
* @return (string)
*/
function acf_preview_value( $value, $post_id, $field ) {
// apply filters
$value = apply_filters( "acf/preview_value", $value, $post_id, $field );
$value = apply_filters( "acf/preview_value/type={$field['type']}", $value, $post_id, $field );
$value = apply_filters( "acf/preview_value/name={$field['_name']}", $value, $post_id, $field );
$value = apply_filters( "acf/preview_value/key={$field['key']}", $value, $post_id, $field );
// return
return $value;
}
?>

View File

@@ -0,0 +1,445 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_cache') ) :
class acf_cache {
// vars
var $reference = array(),
$active = true;
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// prevent ACF from persistent cache
wp_cache_add_non_persistent_groups('acf');
}
/*
* is_active
*
* This function will return true if caching is enabled
*
* @type function
* @date 26/6/17
* @since 5.6.0
*
* @param n/a
* @return (bool)
*/
function is_active() {
return $this->active;
}
/*
* enable
*
* This function will enable ACF caching
*
* @type function
* @date 26/6/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function enable() {
$this->active = true;
}
/*
* disable
*
* This function will disable ACF caching
*
* @type function
* @date 26/6/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function disable() {
$this->active = false;
}
/*
* get_key
*
* This function will check for references and modify the key
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param $key (string)
* @return $key
*/
function get_key( $key = '' ) {
// check for reference
if( isset($this->reference[ $key ]) ) {
$key = $this->reference[ $key ];
}
// return
return $key;
}
/*
* isset_cache
*
* This function will return true if a cached data exists for the given key
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param $key (string)
* @return (boolean)
*/
function isset_cache( $key = '' ) {
// bail early if not active
if( !$this->is_active() ) return false;
// vars
$key = $this->get_key($key);
$found = false;
// get cache
$cache = wp_cache_get($key, 'acf', false, $found);
// return
return $found;
}
/*
* get_cache
*
* This function will return cached data for a given key
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param $key (string)
* @return (mixed)
*/
function get_cache( $key = '' ) {
// bail early if not active
if( !$this->is_active() ) return false;
// vars
$key = $this->get_key($key);
$found = false;
// get cache
$cache = wp_cache_get($key, 'acf', false, $found);
// return
return $cache;
}
/*
* set_cache
*
* This function will set cached data for a given key
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param $key (string)
* @param $data (mixed)
* @return n/a
*/
function set_cache( $key = '', $data = '' ) {
// bail early if not active
if( !$this->is_active() ) return false;
// set
wp_cache_set($key, $data, 'acf');
// return
return $key;
}
/*
* set_cache_reference
*
* This function will set a reference to cached data for a given key
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param $key (string)
* @param $reference (string)
* @return n/a
*/
function set_cache_reference( $key = '', $reference = '' ) {
// bail early if not active
if( !$this->is_active() ) return false;
// add
$this->reference[ $key ] = $reference;
// resturn
return $key;
}
/*
* delete_cache
*
* This function will delete cached data for a given key
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param $key (string)
* @return n/a
*/
function delete_cache( $key = '' ) {
// bail early if not active
if( !$this->is_active() ) return false;
// delete
return wp_cache_delete( $key, 'acf' );
}
}
// initialize
acf()->cache = new acf_cache();
endif; // class_exists check
/*
* acf_is_cache_active
*
* alias of acf()->cache->is_active()
*
* @type function
* @date 26/6/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_is_cache_active() {
return acf()->cache->is_active();
}
/*
* acf_disable_cache
*
* alias of acf()->cache->disable()
*
* @type function
* @date 26/6/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_disable_cache() {
return acf()->cache->disable();
}
/*
* acf_enable_cache
*
* alias of acf()->cache->enable()
*
* @type function
* @date 26/6/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_enable_cache() {
return acf()->cache->enable();
}
/*
* acf_isset_cache
*
* alias of acf()->cache->isset_cache()
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_isset_cache( $key = '' ) {
return acf()->cache->isset_cache( $key );
}
/*
* acf_get_cache
*
* alias of acf()->cache->get_cache()
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_get_cache( $key = '' ) {
return acf()->cache->get_cache( $key );
}
/*
* acf_set_cache
*
* alias of acf()->cache->set_cache()
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_set_cache( $key = '', $data ) {
return acf()->cache->set_cache( $key, $data );
}
/*
* acf_set_cache_reference
*
* alias of acf()->cache->set_cache_reference()
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_set_cache_reference( $key = '', $reference = '' ) {
return acf()->cache->set_cache_reference( $key, $reference );
}
/*
* acf_delete_cache
*
* alias of acf()->cache->delete_cache()
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_delete_cache( $key = '' ) {
return acf()->cache->delete_cache( $key );
}
?>

View File

@@ -0,0 +1,591 @@
<?php
class acf_compatibility {
/*
* __construct
*
* description
*
* @type function
* @date 30/04/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function __construct() {
// fields
add_filter('acf/validate_field', array($this, 'validate_field'), 20, 1);
add_filter('acf/validate_field/type=textarea', array($this, 'validate_textarea_field'), 20, 1);
add_filter('acf/validate_field/type=relationship', array($this, 'validate_relationship_field'), 20, 1);
add_filter('acf/validate_field/type=post_object', array($this, 'validate_relationship_field'), 20, 1);
add_filter('acf/validate_field/type=page_link', array($this, 'validate_relationship_field'), 20, 1);
add_filter('acf/validate_field/type=image', array($this, 'validate_image_field'), 20, 1);
add_filter('acf/validate_field/type=file', array($this, 'validate_image_field'), 20, 1);
add_filter('acf/validate_field/type=wysiwyg', array($this, 'validate_wysiwyg_field'), 20, 1);
add_filter('acf/validate_field/type=date_picker', array($this, 'validate_date_picker_field'), 20, 1);
add_filter('acf/validate_field/type=taxonomy', array($this, 'validate_taxonomy_field'), 20, 1);
add_filter('acf/validate_field/type=date_time_picker', array($this, 'validate_date_time_picker_field'), 20, 1);
add_filter('acf/validate_field/type=user', array($this, 'validate_user_field'), 20, 1);
// field groups
add_filter('acf/validate_field_group', array($this, 'validate_field_group'), 20, 1);
}
/*
* validate_field
*
* This function will provide compatibility with ACF4 fields
*
* @type function
* @date 23/04/2014
* @since 5.0.0
*
* @param $field (array)
* @return $field
*/
function validate_field( $field ) {
// conditional logic has changed
if( isset($field['conditional_logic']['status']) ) {
// extract logic
$logic = acf_extract_var( $field, 'conditional_logic' );
// disabled
if( !empty($logic['status']) ) {
// reset
$field['conditional_logic'] = array();
// vars
$group = 0;
$all_or_any = $logic['allorany'];
// loop over rules
if( !empty($logic['rules']) ) {
foreach( $logic['rules'] as $rule ) {
// sperate groups?
if( $all_or_any == 'any' ) {
$group++;
}
// add to group
$field['conditional_logic'][ $group ][] = $rule;
}
}
// reset keys
$field['conditional_logic'] = array_values($field['conditional_logic']);
} else {
$field['conditional_logic'] = 0;
}
}
// return
return $field;
}
/*
* validate_relationship_field
*
* This function will provide compatibility with ACF4 fields
*
* @type function
* @date 23/04/2014
* @since 5.0.0
*
* @param $field (array)
* @return $field
*/
function validate_relationship_field( $field ) {
// force array
$field['post_type'] = acf_get_array($field['post_type']);
$field['taxonomy'] = acf_get_array($field['taxonomy']);
// remove 'all' from post_type
if( acf_in_array('all', $field['post_type']) ) {
$field['post_type'] = array();
}
// remove 'all' from taxonomy
if( acf_in_array('all', $field['taxonomy']) ) {
$field['taxonomy'] = array();
}
// save_format is now return_format
if( !empty($field['result_elements']) ) {
$field['elements'] = acf_extract_var( $field, 'result_elements' );
}
// return
return $field;
}
/*
* validate_textarea_field
*
* This function will provide compatibility with ACF4 fields
*
* @type function
* @date 23/04/2014
* @since 5.0.0
*
* @param $field (array)
* @return $field
*/
function validate_textarea_field( $field ) {
// formatting has been removed
$formatting = acf_extract_var( $field, 'formatting' );
if( $formatting === 'br' ) {
$field['new_lines'] = 'br';
}
// return
return $field;
}
/*
* validate_image_field
*
* This function will provide compatibility with ACF4 fields
*
* @type function
* @date 23/04/2014
* @since 5.0.0
*
* @param $field (array)
* @return $field
*/
function validate_image_field( $field ) {
// save_format is now return_format
if( !empty($field['save_format']) ) {
$field['return_format'] = acf_extract_var( $field, 'save_format' );
}
// object is now array
if( $field['return_format'] == 'object' ) {
$field['return_format'] = 'array';
}
// return
return $field;
}
/*
* validate_wysiwyg_field
*
* This function will provide compatibility with ACF4 fields
*
* @type function
* @date 23/04/2014
* @since 5.0.0
*
* @param $field (array)
* @return $field
*/
function validate_wysiwyg_field( $field ) {
// media_upload is now numeric
if( $field['media_upload'] === 'yes' ) {
$field['media_upload'] = 1;
} elseif( $field['media_upload'] === 'no' ) {
$field['media_upload'] = 0;
}
// return
return $field;
}
/*
* validate_date_picker_field
*
* This function will provide compatibility with ACF4 fields
*
* @type function
* @date 23/04/2014
* @since 5.0.0
*
* @param $field (array)
* @return $field
*/
function validate_date_picker_field( $field ) {
// v4 used date_format
if( !empty($field['date_format']) ) {
// extract vars
$date_format = acf_extract_var( $field, 'date_format' );
$display_format = acf_extract_var( $field, 'display_format' );
// convert from js to php
//$date_format = acf_convert_date_to_php( $date_format );
$display_format = acf_convert_date_to_php( $display_format );
// bail early if already matches 'Ymd'
if( $date_format === 'yymmdd' ) return $field;
// append settings
$field['display_format'] = $display_format;
$field['save_format'] = $date_format;
}
// return
return $field;
}
/*
* validate_taxonomy_field
*
* This function will provide compatibility with ACF4 fields
*
* @type function
* @date 23/04/2014
* @since 5.0.0
*
* @param $field (array)
* @return $field
*/
function validate_taxonomy_field( $field ) {
// 5.2.7
if( isset($field['load_save_terms']) ) {
$field['save_terms'] = $field['load_save_terms'];
}
// return
return $field;
}
/*
* validate_date_time_picker_field
*
* This function will provide compatibility with existing 3rd party fields
*
* @type function
* @date 23/04/2014
* @since 5.0.0
*
* @param $field (array)
* @return $field
*/
function validate_date_time_picker_field( $field ) {
// 3rd party date time picker
// https://github.com/soderlind/acf-field-date-time-picker
if( !empty($field['time_format']) ) {
// extract vars
$time_format = acf_extract_var( $field, 'time_format' );
$date_format = acf_extract_var( $field, 'date_format' );
$get_as_timestamp = acf_extract_var( $field, 'get_as_timestamp' );
// convert from js to php
$time_format = acf_convert_time_to_php( $time_format );
$date_format = acf_convert_date_to_php( $date_format );
// append settings
$field['return_format'] = $date_format . ' ' . $time_format;
$field['display_format'] = $date_format . ' ' . $time_format;
// timestamp
if( $get_as_timestamp === 'true' ) {
$field['return_format'] = 'U';
}
}
// return
return $field;
}
/*
* validate_user_field
*
* This function will provide compatibility with ACF4 fields
*
* @type function
* @date 23/04/2014
* @since 5.0.0
*
* @param $field (array)
* @return $field
*/
function validate_user_field( $field ) {
// remove 'all' from roles
if( acf_in_array('all', $field['role']) ) {
$field['role'] = '';
}
// field_type removed in favour of multiple
if( !empty($field['field_type']) ) {
// extract vars
$field_type = acf_extract_var( $field, 'field_type' );
// multiple
if( $field_type === 'multi_select' ) {
$field['multiple'] = true;
}
}
// return
return $field;
}
/*
* validate_field_group
*
* This function will provide compatibility with ACF4 field groups
*
* @type function
* @date 23/04/2014
* @since 5.0.0
*
* @param $field_group (array)
* @return $field_group
*/
function validate_field_group( $field_group ) {
// vars
$version = 5;
// add missing 'key' (v5.0.0)
if( empty($field_group['key']) ) {
// update version
$version = 4;
// add missing key
$field_group['key'] = empty($field_group['id']) ? uniqid('group_') : 'group_' . $field_group['id'];
}
// extract options (v5.0.0)
if( !empty($field_group['options']) ) {
$options = acf_extract_var($field_group, 'options');
$field_group = array_merge($field_group, $options);
}
// location rules changed to groups (v5.0.0)
if( !empty($field_group['location']['rules']) ) {
// extract location
$location = acf_extract_var( $field_group, 'location' );
// reset location
$field_group['location'] = array();
// vars
$group = 0;
$all_or_any = $location['allorany'];
// loop over rules
if( !empty($location['rules']) ) {
foreach( $location['rules'] as $rule ) {
// sperate groups?
if( $all_or_any == 'any' ) $group++;
// add to group
$field_group['location'][ $group ][] = $rule;
}
}
// reset keys
$field_group['location'] = array_values($field_group['location']);
}
// some location rules have changed (v5.0.0)
if( !empty($field_group['location']) ) {
// param changes
$replace = array(
'taxonomy' => 'post_taxonomy',
'ef_media' => 'attachment',
'ef_taxonomy' => 'taxonomy',
'ef_user' => 'user_role',
'user_type' => 'current_user_role' // 5.2.0
);
// remove conflicting param
if( $version == 5 ) {
unset($replace['taxonomy']);
}
// loop over location groups
foreach( $field_group['location'] as $i => $group ) {
// bail early if group is empty
if( empty($group) ) continue;
// loop over group rules
foreach( $group as $ii => $rule ) {
// migrate param
if( isset($replace[ $rule['param'] ]) ) {
$rule['param'] = $replace[ $rule['param'] ];
}
// update
$group[ $ii ] = $rule;
}
// update
$field_group['location'][ $i ] = $group;
}
}
// change layout to style (v5.0.0)
if( !empty($field_group['layout']) ) {
$field_group['style'] = acf_extract_var($field_group, 'layout');
}
// change no_box to seamless (v5.0.0)
if( $field_group['style'] === 'no_box' ) {
$field_group['style'] = 'seamless';
}
//return
return $field_group;
}
}
new acf_compatibility();
?>

View File

@@ -0,0 +1,185 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_deprecated') ) :
class acf_deprecated {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 30/1/17
* @since 5.5.6
*
* @param n/a
* @return n/a
*/
function __construct() {
// settings
add_filter('acf/settings/show_admin', array($this, 'acf_settings_show_admin'), 5, 1); // 5.0.0
add_filter('acf/settings/l10n_textdomain', array($this, 'acf_settings_l10n_textdomain'), 5, 1); // 5.3.3
add_filter('acf/settings/l10n_field', array($this, 'acf_settings_l10n_field'), 5, 1); // 5.3.3
add_filter('acf/settings/l10n_field_group', array($this, 'acf_settings_l10n_field'), 5, 1); // 5.3.3
// filters
add_filter('acf/validate_field', array($this, 'acf_validate_field'), 10, 1); // 5.5.6
add_filter('acf/validate_field_group', array($this, 'acf_validate_field_group'), 10, 1); // 5.5.6
add_filter('acf/validate_post_id', array($this, 'acf_validate_post_id'), 10, 2); // 5.5.6
}
/*
* acf_settings_show_admin
*
* This function will add compatibility for previously named hooks
*
* @type function
* @date 19/05/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_settings_show_admin( $setting ) {
// 5.0.0 - removed ACF_LITE
return ( defined('ACF_LITE') && ACF_LITE ) ? false : $setting;
}
/*
* acf_settings_l10n_textdomain
*
* This function will add compatibility for previously named hooks
*
* @type function
* @date 19/05/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_settings_l10n_textdomain( $setting ) {
// 5.3.3 - changed filter name
return acf_get_setting( 'export_textdomain', $setting );
}
/*
* acf_settings_l10n_field
*
* This function will add compatibility for previously named hooks
*
* @type function
* @date 19/05/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_settings_l10n_field( $setting ) {
// 5.3.3 - changed filter name
return acf_get_setting( 'export_translate', $setting );
}
/*
* acf_validate_field
*
* This function will add compatibility for previously named hooks
*
* @type function
* @date 30/1/17
* @since 5.5.6
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_validate_field( $field ) {
// 5.5.6 - changed filter name
$field = apply_filters( "acf/get_valid_field", $field );
$field = apply_filters( "acf/get_valid_field/type={$field['type']}", $field );
// return
return $field;
}
/*
* acf_validate_field_group
*
* This function will add compatibility for previously named hooks
*
* @type function
* @date 30/1/17
* @since 5.5.6
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_validate_field_group( $field_group ) {
// 5.5.6 - changed filter name
$field_group = apply_filters('acf/get_valid_field_group', $field_group);
// return
return $field_group;
}
/*
* acf_validate_post_id
*
* This function will add compatibility for previously named hooks
*
* @type function
* @date 6/2/17
* @since 5.5.6
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_validate_post_id( $post_id, $_post_id ) {
// 5.5.6 - changed filter name
$post_id = apply_filters('acf/get_valid_post_id', $post_id, $_post_id);
// return
return $post_id;
}
}
// initialize
acf()->deprecated = new acf_deprecated();
endif; // class_exists check
?>

View File

@@ -0,0 +1,366 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_fields') ) :
class acf_fields {
/** @var array Contains an array of field type instances */
var $types = array();
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function __construct() {
/* do nothing */
}
/*
* register_field_type
*
* This function will store a field type class
*
* @type function
* @date 6/07/2016
* @since 5.4.0
*
* @param $class (string)
* @return n/a
*/
function register_field_type( $class ) {
if( $class instanceOf acf_field ) {
$this->types[ $class->name ] = $class;
} else {
$instance = new $class();
$this->types[ $instance->name ] = $instance;
}
}
/*
* get_field_type
*
* This function will return a field type class
*
* @type function
* @date 6/07/2016
* @since 5.4.0
*
* @param $name (string)
* @return (mixed)
*/
function get_field_type( $name ) {
return isset( $this->types[$name] ) ? $this->types[$name] : null;
}
/*
* is_field_type
*
* This function will return true if a field type exists
*
* @type function
* @date 6/07/2016
* @since 5.4.0
*
* @param $name (string)
* @return (mixed)
*/
function is_field_type( $name ) {
return isset( $this->types[$name] );
}
/*
* register_field_type_info
*
* This function will store a basic array of info about the field type
* to later be overriden by the avbove register_field_type function
*
* @type function
* @date 29/5/17
* @since 5.6.0
*
* @param $info (array)
* @return n/a
*/
function register_field_type_info( $info ) {
// convert to object
$instance = (object) $info;
$this->types[ $instance->name ] = $instance;
}
/*
* get_field_types
*
* This function will return an array of all field type infos
*
* @type function
* @date 6/07/2016
* @since 5.4.0
*
* @param $name (string)
* @return (mixed)
*/
function get_field_types() {
// vars
$groups = array();
$l10n = array(
'basic' => __('Basic', 'acf'),
'content' => __('Content', 'acf'),
'choice' => __('Choice', 'acf'),
'relational' => __('Relational', 'acf'),
'jquery' => __('jQuery', 'acf'),
'layout' => __('Layout', 'acf'),
);
// loop
foreach( $this->types as $type ) {
// bail ealry if not public
if( !$type->public ) continue;
// translate
$cat = $type->category;
$cat = isset( $l10n[$cat] ) ? $l10n[$cat] : $cat;
// append
$groups[ $cat ][ $type->name ] = $type->label;
}
// filter
$groups = apply_filters('acf/get_field_types', $groups);
// return
return $groups;
}
}
// initialize
acf()->fields = new acf_fields();
endif; // class_exists check
/*
* acf_register_field_type
*
* alias of acf()->fields->register_field_type()
*
* @type function
* @date 31/5/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_register_field_type( $class ) {
return acf()->fields->register_field_type( $class );
}
/*
* acf_get_field_type
*
* alias of acf()->fields->get_field_type()
*
* @type function
* @date 31/5/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_get_field_type( $name ) {
return acf()->fields->get_field_type( $name );
}
/*
* acf_register_field_type_info
*
* alias of acf()->fields->register_field_type_info()
*
* @type function
* @date 31/5/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_register_field_type_info( $info ) {
return acf()->fields->register_field_type_info( $info );
}
/*
* acf_get_field_types
*
* alias of acf()->fields->get_field_types()
*
* @type function
* @date 31/5/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_get_field_types() {
return acf()->fields->get_field_types();
}
/*
* acf_is_field_type
*
* alias of acf()->fields->is_field_type()
*
* @type function
* @date 31/5/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_is_field_type( $name = '' ) {
return acf()->fields->is_field_type( $name );
}
/*
* acf_get_field_type_prop
*
* This function will return a field type's property
*
* @type function
* @date 1/10/13
* @since 5.0.0
*
* @param n/a
* @return (array)
*/
function acf_get_field_type_prop( $name = '', $prop = '' ) {
$type = acf_get_field_type( $name );
return ($type && isset($type->$prop)) ? $type->$prop : null;
}
/*
* acf_get_field_type_label
*
* This function will return the label of a field type
*
* @type function
* @date 1/10/13
* @since 5.0.0
*
* @param n/a
* @return (array)
*/
function acf_get_field_type_label( $name = '' ) {
$type = acf_get_field_type( $name );
return $type ? $type->label : '<span class="acf-tooltip-js" title="'.__('Field type does not exist', 'acf').'">'.__('Unknown', 'acf').'</span>';
}
/*
* acf_field_type_exists (deprecated)
*
* deprecated in favour of acf_is_field_type()
*
* @type function
* @date 1/10/13
* @since 5.0.0
*
* @param $type (string)
* @return (boolean)
*/
function acf_field_type_exists( $type = '' ) {
return acf_is_field_type( $type );
}
/*
* acf_get_grouped_field_types (deprecated)
*
* deprecated in favour of acf_get_field_types()
*
* @type function
* @date 1/10/13
* @since 5.0.0
*
* @param n/a
* @return (array)
*/
function acf_get_grouped_field_types() {
return acf_get_field_types();
}
?>

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
?>

View File

@@ -0,0 +1,288 @@
<?php
/*
* ACF Attachment Form Class
*
* All the logic for adding fields to attachments
*
* @class acf_form_attachment
* @package ACF
* @subpackage Forms
*/
if( ! class_exists('acf_form_attachment') ) :
class acf_form_attachment {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
// render
add_filter('attachment_fields_to_edit', array($this, 'edit_attachment'), 10, 2);
// save
add_filter('attachment_fields_to_save', array($this, 'save_attachment'), 10, 2);
}
/*
* validate_page
*
* This function will check if the current page is for a post/page edit form
*
* @type function
* @date 23/06/12
* @since 3.1.8
*
* @param n/a
* @return (boolean)
*/
function validate_page() {
// global
global $pagenow, $typenow, $wp_version;
// validate page
if( $pagenow === 'post.php' && $typenow === 'attachment' ) {
return true;
}
// validate page
if( $pagenow === 'upload.php' && version_compare($wp_version, '4.0', '>=') ) {
add_action('admin_footer', array($this, 'admin_footer'), 0);
return true;
}
// return
return false;
}
/*
* admin_enqueue_scripts
*
* This action is run after post query but before any admin script / head actions.
* It is a good place to register all actions.
*
* @type action (admin_enqueue_scripts)
* @date 26/01/13
* @since 3.6.0
*
* @param N/A
* @return N/A
*/
function admin_enqueue_scripts() {
// bail early if not valid page
if( !$this->validate_page() ) {
return;
}
// load acf scripts
acf_enqueue_scripts();
}
/*
* admin_footer
*
* This function will add acf_form_data to the WP 4.0 attachment grid
*
* @type action (admin_footer)
* @date 11/09/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_footer() {
// render post data
acf_form_data(array(
'post_id' => 0,
'nonce' => 'attachment',
'ajax' => 1
));
?>
<script type="text/javascript">
// WP saves attachment on any input change, so unload is not needed
acf.unload.active = 0;
</script>
<?php
}
/*
* edit_attachment
*
* description
*
* @type function
* @date 8/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function edit_attachment( $form_fields, $post ) {
// vars
$is_page = $this->validate_page();
$post_id = $post->ID;
$el = 'tr';
$args = array(
'attachment' => $post_id
);
// get field groups
$field_groups = acf_get_field_groups( $args );
// render
if( !empty($field_groups) ) {
// get acf_form_data
ob_start();
acf_form_data(array(
'post_id' => $post_id,
'nonce' => 'attachment',
));
// open
echo '</td></tr>';
// loop
foreach( $field_groups as $field_group ) {
// load fields
$fields = acf_get_fields( $field_group );
// override instruction placement for modal
if( !$is_page ) {
$field_group['instruction_placement'] = 'field';
}
// render
acf_render_fields( $post_id, $fields, $el, $field_group['instruction_placement'] );
}
// close
echo '<tr class="compat-field-acf-blank"><td>';
$html = ob_get_contents();
ob_end_clean();
$form_fields[ 'acf-form-data' ] = array(
'label' => '',
'input' => 'html',
'html' => $html
);
}
// return
return $form_fields;
}
/*
* save_attachment
*
* description
*
* @type function
* @date 8/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function save_attachment( $post, $attachment ) {
// bail early if not valid nonce
if( ! acf_verify_nonce('attachment') ) {
return $post;
}
// validate and save
if( acf_validate_save_post(true) ) {
acf_save_post( $post['ID'] );
}
// return
return $post;
}
}
new acf_form_attachment();
endif;
?>

View File

@@ -0,0 +1,349 @@
<?php
/*
* ACF Comment Form Class
*
* All the logic for adding fields to comments
*
* @class acf_form_comment
* @package ACF
* @subpackage Forms
*/
if( ! class_exists('acf_form_comment') ) :
class acf_form_comment {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
// render
add_filter('comment_form_field_comment', array($this, 'comment_form_field_comment'), 999, 1);
//add_action( 'comment_form_logged_in_after', array( $this, 'add_comment') );
//add_action( 'comment_form', array( $this, 'add_comment') );
// save
add_action( 'edit_comment', array( $this, 'save_comment' ), 10, 1 );
add_action( 'comment_post', array( $this, 'save_comment' ), 10, 1 );
}
/*
* validate_page
*
* This function will check if the current page is for a post/page edit form
*
* @type function
* @date 23/06/12
* @since 3.1.8
*
* @param n/a
* @return (boolean)
*/
function validate_page() {
// global
global $pagenow;
// validate page
if( $pagenow == 'comment.php' ) {
return true;
}
// return
return false;
}
/*
* admin_enqueue_scripts
*
* This action is run after post query but before any admin script / head actions.
* It is a good place to register all actions.
*
* @type action (admin_enqueue_scripts)
* @date 26/01/13
* @since 3.6.0
*
* @param n/a
* @return n/a
*/
function admin_enqueue_scripts() {
// validate page
if( ! $this->validate_page() ) {
return;
}
// load acf scripts
acf_enqueue_scripts();
// actions
add_action('admin_footer', array($this, 'admin_footer'), 10, 1);
add_action('add_meta_boxes_comment', array($this, 'edit_comment'), 10, 1);
}
/*
* edit_comment
*
* This function is run on the admin comment.php page and will render the ACF fields within custom metaboxes to look native
*
* @type function
* @date 19/10/13
* @since 5.0.0
*
* @param $comment (object)
* @return n/a
*/
function edit_comment( $comment ) {
// vars
$post_id = "comment_{$comment->comment_ID}";
// get field groups
$field_groups = acf_get_field_groups(array(
'comment' => get_post_type( $comment->comment_post_ID )
));
// render
if( !empty($field_groups) ) {
// render post data
acf_form_data(array(
'post_id' => $post_id,
'nonce' => 'comment'
));
foreach( $field_groups as $field_group ) {
// load fields
$fields = acf_get_fields( $field_group );
// vars
$o = array(
'id' => 'acf-'.$field_group['ID'],
'key' => $field_group['key'],
//'style' => $field_group['style'],
'label' => $field_group['label_placement'],
'edit_url' => '',
'edit_title' => __('Edit field group', 'acf'),
//'visibility' => $visibility
);
// edit_url
if( $field_group['ID'] && acf_current_user_can_admin() ) {
$o['edit_url'] = admin_url('post.php?post=' . $field_group['ID'] . '&action=edit');
}
?>
<div id="acf-<?php echo $field_group['ID']; ?>" class="stuffbox">
<h3 class="hndle"><?php echo $field_group['title']; ?></h3>
<div class="inside">
<?php acf_render_fields( $post_id, $fields, 'div', $field_group['instruction_placement'] ); ?>
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
acf.postbox.render(<?php echo json_encode($o); ?>);
}
</script>
</div>
</div>
<?php
}
}
}
/*
* comment_form_field_comment
*
* description
*
* @type function
* @date 18/04/2016
* @since 5.3.8
*
* @param $post_id (int)
* @return $post_id (int)
*/
function comment_form_field_comment( $html ) {
// global
global $post;
// vars
$post_id = false;
// get field groups
$field_groups = acf_get_field_groups(array(
'comment' => $post->post_type
));
// bail early if no field groups
if( !$field_groups ) return $html;
// ob
ob_start();
// render post data
acf_form_data(array(
'post_id' => $post_id,
'nonce' => 'comment'
));
echo '<div class="acf-comment-fields acf-fields -clear">';
foreach( $field_groups as $field_group ) {
$fields = acf_get_fields( $field_group );
acf_render_fields( $post_id, $fields, 'p', $field_group['instruction_placement'] );
}
echo '</div>';
// append
$html .= ob_get_contents();
ob_end_clean();
// return
return $html;
}
/*
* save_comment
*
* This function will save the comment data
*
* @type function
* @date 19/10/13
* @since 5.0.0
*
* @param comment_id (int)
* @return n/a
*/
function save_comment( $comment_id ) {
// bail early if not valid nonce
if( !acf_verify_nonce('comment') ) {
return $comment_id;
}
// kses
if( isset($_POST['acf']) ) {
$_POST['acf'] = wp_kses_post_deep( $_POST['acf'] );
}
// validate and save
if( acf_validate_save_post(true) ) {
acf_save_post( "comment_{$comment_id}" );
}
}
/*
* admin_footer
*
* description
*
* @type function
* @date 27/03/2015
* @since 5.1.5
*
* @param $post_id (int)
* @return $post_id (int)
*/
function admin_footer() {
?>
<script type="text/javascript">
(function($) {
// vars
var $spinner = $('#publishing-action .spinner');
// create spinner if not exists (may exist in future WP versions)
if( !$spinner.exists() ) {
// create spinner
$spinner = $('<span class="spinner"></span>');
// append
$('#publishing-action').prepend( $spinner );
}
})(jQuery);
</script>
<?php
}
}
new acf_form_comment();
endif;
?>

View File

@@ -0,0 +1,471 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_form_customizer') ) :
class acf_form_customizer {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// vars
$this->preview_values = array();
$this->preview_fields = array();
$this->preview_errors = array();
// actions
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('customize_preview_init', array($this, 'customize_preview_init'), 1, 1);
add_action('customize_save', array($this, 'customize_save'), 1, 1);
// save
add_filter('widget_update_callback', array($this, 'save_widget'), 10, 4);
}
/*
* admin_enqueue_scripts
*
* This action is run after post query but before any admin script / head actions.
* It is a good place to register all actions.
*
* @type action (admin_enqueue_scripts)
* @date 26/01/13
* @since 3.6.0
*
* @param N/A
* @return N/A
*/
function admin_enqueue_scripts() {
// validate screen
if( !acf_is_screen('customize') ) return;
// load acf scripts
acf_enqueue_scripts();
// actions
add_action('acf/input/admin_footer', array($this, 'admin_footer'), 1);
}
/*
* save_widget
*
* This function will hook into the widget update filter and save ACF data
*
* @type function
* @date 27/05/2015
* @since 5.2.3
*
* @param $instance (array) widget settings
* @param $new_instance (array) widget settings
* @param $old_instance (array) widget settings
* @param $widget (object) widget info
* @return $instance
*/
function save_widget( $instance, $new_instance, $old_instance, $widget ) {
// bail ealry if not valid (customize + acf values + nonce)
if( !isset($_POST['wp_customize']) || !isset($new_instance['acf']) || !acf_verify_nonce('widget') ) return $instance;
// vars
$data = array(
'post_id' => "widget_{$widget->id}",
'values' => array(),
'fields' => array()
);
// append values
$data['values'] = $new_instance['acf'];
// append fields (name => key relationship) - used later in 'acf/get_field_reference' for customizer previews
foreach( $data['values'] as $k => $v ) {
// get field
$field = acf_get_field( $k );
// continue if no field
if( !$field ) continue;
// update
$data['fields'][ $field['name'] ] = $field['key'];
}
// append data to instance
$instance['acf'] = $data;
// return
return $instance;
}
/*
* settings
*
* This function will return an array of cutomizer settings that include ACF data
* similar to `$customizer->settings();`
*
* @type function
* @date 22/03/2016
* @since 5.3.2
*
* @param $customizer (object)
* @return $value (mixed)
*/
function settings( $customizer ) {
// vars
$data = array();
$settings = $customizer->settings();
// bail ealry if no settings
if( empty($settings) ) return false;
// loop over settings
foreach( $settings as $setting ) {
// vars
$id = $setting->id;
// verify settings type
if( substr($id, 0, 6) == 'widget' || substr($id, 0, 7) == 'nav_menu' ) {
// allow
} else {
continue;
}
// get value
$value = $setting->post_value();
// bail early if no acf
if( !is_array($value) || !isset($value['acf']) ) continue;
// set data
$setting->acf = $value['acf'];
// append
$data[] = $setting;
}
// bail ealry if no settings
if( empty($data) ) return false;
// return
return $data;
}
/*
* customize_preview_init
*
* This function is called when customizer preview is initialized
*
* @type function
* @date 22/03/2016
* @since 5.3.2
*
* @param $customizer (object)
* @return n/a
*/
function customize_preview_init( $customizer ) {
// get customizer settings (widgets)
$settings = $this->settings( $customizer );
// bail ealry if no settings
if( empty($settings) ) return;
// append values
foreach( $settings as $setting ) {
// get acf data
$data = $setting->acf;
// append acf_value to preview_values
$this->preview_values[ $data['post_id'] ] = $data['values'];
$this->preview_fields[ $data['post_id'] ] = $data['fields'];
}
// bail ealry if no preview_values
if( empty($this->preview_values) ) return;
// add filter
add_filter('acf/get_field_reference', array($this, 'get_field_reference'), 10, 3);
}
/*
* get_field_reference
*
* This function will return a field_key for a given field name + post_id
* Normally, ACF would lookup the DB fro this connection, but a new preview widget has not yet saved anything to the DB
*
* @type function
* @date 12/05/2016
* @since 5.3.8
*
* @param $field_key (string)
* @param $field_name (string)
* @param $post_id (mixed)
* @return $field_key
*/
function get_field_reference( $field_key, $field_name, $post_id ) {
// look for reference
if( isset($this->preview_fields[ $post_id ][ $field_name ]) ) {
// update key
$field_key = $this->preview_fields[ $post_id ][ $field_name ];
$field_value = $this->preview_values[ $post_id ][ $field_key ];
// cache value
acf_set_cache("get_value/post_id={$post_id}/name={$field_name}", $field_value);
}
// return
return $field_key;
}
/*
* customize_save
*
* This function is called when customizer saves a widget.
* Normally, the widget_update_callback filter would be used, but the customizer disables this and runs a custom action
* class-customizer-settings.php will save the widget data via the function set_root_value which uses update_option
*
* @type function
* @date 22/03/2016
* @since 5.3.2
*
* @param $customizer (object)
* @return n/a
*/
function customize_save( $customizer ) {
// get customizer settings (widgets)
$settings = $this->settings( $customizer );
// bail ealry if no settings
if( empty($settings) ) return;
// append values
foreach( $settings as $setting ) {
// get acf data
$data = $setting->acf;
// save acf data
acf_save_post( $data['post_id'], $data['values'] );
// remove [acf] data from saved widget array
$id_data = $setting->id_data();
add_filter('pre_update_option_' . $id_data['base'], array($this, 'pre_update_option'), 10, 3);
}
}
/*
* pre_update_option
*
* this function will remove the [acf] data from widget insance
*
* @type function
* @date 22/03/2016
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function pre_update_option( $value, $option, $old_value ) {
// bail ealry if no value
if( empty($value) ) return $value;
// loop over widgets
// WP saves all widgets (of the same type) as an array of widgets
foreach( $value as $i => $widget ) {
// bail ealry if no acf
if( !isset($widget['acf']) ) continue;
// remove widget
unset($value[ $i ]['acf']);
}
// return
return $value;
}
/*
* admin_footer
*
* This function will add some custom HTML to the footer of the edit page
*
* @type function
* @date 11/06/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_footer() {
?>
<script type="text/javascript">
(function($) {
// customizer saves widget on any input change, so unload is not needed
acf.unload.active = 0;
// hack customizer function to remove bug caused by WYSIWYG field using aunique ID
// customizer compares returned AJAX HTML with the HTML of the widget form.
// the _getInputsSignature() function is used to generate a string based of input name + id.
// because ACF generates a unique ID on the WYSIWYG field, this string will not match causing the preview function to bail.
// an attempt was made to remove the WYSIWYG unique ID, but this caused multiple issues in the wp-admin and altimately doesn't make sense with the tinymce rule that all editors must have a unique ID.
// source: wp-admin/js/customize-widgets.js
// vars
var WidgetControl = wp.customize.Widgets.WidgetControl.prototype;
// backup functions
WidgetControl.__getInputsSignature = WidgetControl._getInputsSignature;
WidgetControl.__setInputState = WidgetControl._setInputState;
// modify __getInputsSignature
WidgetControl._getInputsSignature = function( inputs ) {
// vars
var signature = this.__getInputsSignature( inputs );
safe = [];
// split
signature = signature.split(';');
// loop
for( var i in signature ) {
// vars
var bit = signature[i];
// bail ealry if acf is found
if( bit.indexOf('acf') !== -1 ) continue;
// append
safe.push( bit );
}
// update
signature = safe.join(';');
// return
return signature;
};
// modify _setInputState
// this function deosn't seem to run on widget title/content, only custom fields
// either way, this function is not needed and will break ACF fields
WidgetControl._setInputState = function( input, state ) {
return true;
};
})(jQuery);
</script>
<?php
}
}
new acf_form_customizer();
endif;
?>

View File

@@ -0,0 +1,707 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_form_front') ) :
class acf_form_front {
/** @var array An array of registered form settings */
private $forms = array();
/** @var array An array of default fields */
public $fields = array();
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// vars
$this->fields = array(
'_post_title' => array(
'prefix' => 'acf',
'name' => '_post_title',
'key' => '_post_title',
'label' => __('Title', 'acf'),
'type' => 'text',
'required' => true,
),
'_post_content' => array(
'prefix' => 'acf',
'name' => '_post_content',
'key' => '_post_content',
'label' => __('Content', 'acf'),
'type' => 'wysiwyg',
),
'_validate_email' => array(
'prefix' => 'acf',
'name' => '_validate_email',
'key' => '_validate_email',
'label' => __('Validate Email', 'acf'),
'type' => 'text',
'value' => '',
'wrapper' => array('style' => 'display:none !important;')
)
);
// actions
add_action('acf/validate_save_post', array($this, 'validate_save_post'), 1);
// filters
add_filter('acf/pre_save_post', array($this, 'pre_save_post'), 5, 2);
}
/*
* validate_form
*
* description
*
* @type function
* @date 28/2/17
* @since 5.5.8
*
* @param $post_id (int)
* @return $post_id (int)
*/
function validate_form( $args ) {
// defaults
$args = wp_parse_args( $args, array(
'id' => 'acf-form',
'post_id' => false,
'new_post' => false,
'field_groups' => false,
'fields' => false,
'post_title' => false,
'post_content' => false,
'form' => true,
'form_attributes' => array(),
'return' => add_query_arg( 'updated', 'true', acf_get_current_url() ),
'html_before_fields' => '',
'html_after_fields' => '',
'submit_value' => __("Update", 'acf'),
'updated_message' => __("Post updated", 'acf'),
'label_placement' => 'top',
'instruction_placement' => 'label',
'field_el' => 'div',
'uploader' => 'wp',
'honeypot' => true,
'html_updated_message' => '<div id="message" class="updated"><p>%s</p></div>', // 5.5.10
'html_submit_button' => '<input type="submit" class="acf-button button button-primary button-large" value="%s" />', // 5.5.10
'html_submit_spinner' => '<span class="acf-spinner"></span>', // 5.5.10
'kses' => true // 5.6.5
));
$args['form_attributes'] = wp_parse_args( $args['form_attributes'], array(
'id' => $args['id'],
'class' => 'acf-form',
'action' => '',
'method' => 'post',
));
// filter post_id
$args['post_id'] = acf_get_valid_post_id( $args['post_id'] );
// new post?
if( $args['post_id'] === 'new_post' ) {
$args['new_post'] = wp_parse_args( $args['new_post'], array(
'post_type' => 'post',
'post_status' => 'draft',
));
}
// filter
$args = apply_filters('acf/validate_form', $args);
// return
return $args;
}
/*
* add_form
*
* description
*
* @type function
* @date 28/2/17
* @since 5.5.8
*
* @param $post_id (int)
* @return $post_id (int)
*/
function add_form( $args = array() ) {
// validate
$args = $this->validate_form( $args );
// append
$this->forms[ $args['id'] ] = $args;
}
/*
* get_form
*
* description
*
* @type function
* @date 28/2/17
* @since 5.5.8
*
* @param $post_id (int)
* @return $post_id (int)
*/
function get_form( $id = '' ) {
// bail early if not set
if( !isset($this->forms[ $id ]) ) return false;
// return
return $this->forms[ $id ];
}
/*
* validate_save_post
*
* This function will validate fields from the above array
*
* @type function
* @date 7/09/2016
* @since 5.4.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function validate_save_post() {
// register field if isset in $_POST
foreach( $this->fields as $k => $field ) {
// bail early if no in $_POST
if( !isset($_POST['acf'][ $k ]) ) continue;
// register
acf_add_local_field($field);
}
// honeypot
if( !empty($_POST['acf']['_validate_email']) ) {
acf_add_validation_error( '', __('Spam Detected', 'acf') );
}
}
/*
* pre_save_post
*
* description
*
* @type function
* @date 7/09/2016
* @since 5.4.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function pre_save_post( $post_id, $form ) {
// vars
$save = array(
'ID' => 0
);
// determine save data
if( is_numeric($post_id) ) {
// update post
$save['ID'] = $post_id;
} elseif( $post_id == 'new_post' ) {
// merge in new post data
$save = array_merge($save, $form['new_post']);
} else {
// not post
return $post_id;
}
// save post_title
if( isset($_POST['acf']['_post_title']) ) {
$save['post_title'] = acf_extract_var($_POST['acf'], '_post_title');
}
// save post_content
if( isset($_POST['acf']['_post_content']) ) {
$save['post_content'] = acf_extract_var($_POST['acf'], '_post_content');
}
// honeypot
if( !empty($_POST['acf']['_validate_email']) ) return false;
// validate
if( count($save) == 1 ) {
return $post_id;
}
// save
if( $save['ID'] ) {
wp_update_post( $save );
} else {
$post_id = wp_insert_post( $save );
}
// return
return $post_id;
}
/*
* enqueue
*
* This function will enqueue a form
*
* @type function
* @date 7/09/2016
* @since 5.4.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function enqueue_form() {
// check
$this->check_submit_form();
// load acf scripts
acf_enqueue_scripts();
}
/*
* check_submit_form
*
* This function will maybe submit form data
*
* @type function
* @date 3/3/17
* @since 5.5.10
*
* @param n/a
* @return n/a
*/
function check_submit_form() {
// verify nonce
if( !acf_verify_nonce('acf_form') ) return;
// bail ealry if form not submit
if( empty($_POST['_acf_form']) ) return;
// load form
$form = json_decode( acf_decrypt($_POST['_acf_form']), true );
// bail ealry if form is corrupt
if( empty($form) ) return;
// kses
if( $form['kses'] && isset($_POST['acf']) ) {
$_POST['acf'] = wp_kses_post_deep( $_POST['acf'] );
}
// validate data
acf_validate_save_post(true);
// submit
$this->submit_form( $form );
}
/*
* submit_form
*
* This function will submit form data
*
* @type function
* @date 3/3/17
* @since 5.5.10
*
* @param n/a
* @return n/a
*/
function submit_form( $form ) {
// filter
$form = apply_filters('acf/pre_submit_form', $form);
// vars
$post_id = acf_maybe_get($form, 'post_id', 0);
// add global for backwards compatibility
$GLOBALS['acf_form'] = $form;
// allow for custom save
$post_id = apply_filters('acf/pre_save_post', $post_id, $form);
// save
acf_save_post( $post_id );
// restore form (potentially modified)
$form = $GLOBALS['acf_form'];
// action
do_action('acf/submit_form', $form, $post_id);
// vars
$return = acf_maybe_get($form, 'return', '');
// redirect
if( $return ) {
// update %placeholders%
$return = str_replace('%post_id%', $post_id, $return);
$return = str_replace('%post_url%', get_permalink($post_id), $return);
// redirect
wp_redirect( $return );
exit;
}
}
/*
* render
*
* description
*
* @type function
* @date 7/09/2016
* @since 5.4.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function render_form( $args = array() ) {
// array
if( is_array($args) ) {
$args = $this->validate_form( $args );
// id
} else {
$args = $this->get_form( $args );
}
// bail early if no args
if( !$args ) return false;
// load values from this post
$post_id = $args['post_id'];
// dont load values for 'new_post'
if( $post_id === 'new_post' ) $post_id = false;
// register local fields
foreach( $this->fields as $k => $field ) {
acf_add_local_field($field);
}
// vars
$field_groups = array();
$fields = array();
// post_title
if( $args['post_title'] ) {
// load local field
$_post_title = acf_get_field('_post_title');
$_post_title['value'] = $post_id ? get_post_field('post_title', $post_id) : '';
// append
$fields[] = $_post_title;
}
// post_content
if( $args['post_content'] ) {
// load local field
$_post_content = acf_get_field('_post_content');
$_post_content['value'] = $post_id ? get_post_field('post_content', $post_id) : '';
// append
$fields[] = $_post_content;
}
// specific fields
if( $args['fields'] ) {
foreach( $args['fields'] as $selector ) {
// append field ($strict = false to allow for better compatibility with field names)
$fields[] = acf_maybe_get_field( $selector, $post_id, false );
}
} elseif( $args['field_groups'] ) {
foreach( $args['field_groups'] as $selector ) {
$field_groups[] = acf_get_field_group( $selector );
}
} elseif( $args['post_id'] == 'new_post' ) {
$field_groups = acf_get_field_groups( $args['new_post'] );
} else {
$field_groups = acf_get_field_groups(array(
'post_id' => $args['post_id']
));
}
//load fields based on field groups
if( !empty($field_groups) ) {
foreach( $field_groups as $field_group ) {
$field_group_fields = acf_get_fields( $field_group );
if( !empty($field_group_fields) ) {
foreach( array_keys($field_group_fields) as $i ) {
$fields[] = acf_extract_var($field_group_fields, $i);
}
}
}
}
// honeypot
if( $args['honeypot'] ) {
$fields[] = acf_get_field('_validate_email');
}
// updated message
if( !empty($_GET['updated']) && $args['updated_message'] ) {
printf( $args['html_updated_message'], $args['updated_message'] );
}
// uploader (always set incase of multiple forms on the page)
acf_update_setting('uploader', $args['uploader']);
// display form
if( $args['form'] ): ?>
<form <?php acf_esc_attr_e( $args['form_attributes']); ?>>
<?php endif;
// render post data
acf_form_data(array(
'post_id' => $args['post_id'],
'nonce' => 'acf_form',
'form' => acf_encrypt(json_encode($args))
));
?>
<div class="acf-fields acf-form-fields -<?php echo $args['label_placement']; ?>">
<?php
// html before fields
echo $args['html_before_fields'];
// render
acf_render_fields( $post_id, $fields, $args['field_el'], $args['instruction_placement'] );
// html after fields
echo $args['html_after_fields'];
?>
</div>
<?php if( $args['form'] ): ?>
<div class="acf-form-submit">
<?php printf( $args['html_submit_button'], $args['submit_value'] ); ?>
<?php echo $args['html_submit_spinner']; ?>
</div>
</form>
<?php endif;
}
}
// initialize
acf()->form_front = new acf_form_front();
endif; // class_exists check
/*
* Functions
*
* alias of acf()->form->functions
*
* @type function
* @date 11/06/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_form_head() {
acf()->form_front->enqueue_form();
}
function acf_form( $args = array() ) {
acf()->form_front->render_form( $args );
}
function acf_get_form( $id = '' ) {
acf()->form_front->get_form( $id );
}
function acf_register_form( $args ) {
acf()->form_front->add_form( $args );
}
?>

View File

@@ -0,0 +1,323 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_form_nav_menu') ) :
class acf_form_nav_menu {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('wp_update_nav_menu', array($this, 'update_nav_menu'));
add_action('acf/validate_save_post', array($this, 'acf_validate_save_post'), 5);
// filters
add_filter('wp_edit_nav_menu_walker', array($this, 'wp_edit_nav_menu_walker'), 10, 2);
}
/*
* admin_enqueue_scripts
*
* This action is run after post query but before any admin script / head actions.
* It is a good place to register all actions.
*
* @type action (admin_enqueue_scripts)
* @date 26/01/13
* @since 3.6.0
*
* @param N/A
* @return N/A
*/
function admin_enqueue_scripts() {
// validate screen
if( !acf_is_screen('nav-menus') ) return;
// load acf scripts
acf_enqueue_scripts();
// actions
add_action('admin_footer', array($this, 'admin_footer'), 1);
}
/*
* update_nav_menu
*
* description
*
* @type function
* @date 26/5/17
* @since 5.6.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function update_nav_menu( $menu_id ) {
// vars
$post_id = acf_get_term_post_id( 'nav_menu', $menu_id );
// verify and remove nonce
if( !acf_verify_nonce('nav_menu') ) return $menu_id;
// validate and show errors
acf_validate_save_post( true );
// save
acf_save_post( $post_id );
// save nav menu items
$this->update_nav_menu_items( $menu_id );
}
/*
* update_nav_menu_items
*
* description
*
* @type function
* @date 26/5/17
* @since 5.6.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function update_nav_menu_items( $menu_id ) {
// bail ealry if not set
if( empty($_POST['menu-item-acf']) ) return;
// loop
foreach( $_POST['menu-item-acf'] as $post_id => $values ) {
acf_save_post( $post_id, $values );
}
}
/*
* wp_edit_nav_menu_walker
*
* description
*
* @type function
* @date 26/5/17
* @since 5.6.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function wp_edit_nav_menu_walker( $class, $menu_id = 0 ) {
// global
global $acf_menu;
// set var
$acf_menu = (int) $menu_id;
// include walker
if( class_exists('Walker_Nav_Menu_Edit') ) {
acf_include('includes/walkers/class-acf-walker-nav-menu-edit.php');
}
// return
return 'ACF_Walker_Nav_Menu_Edit';
}
/*
* acf_validate_save_post
*
* This function will loop over $_POST data and validate
*
* @type action 'acf/validate_save_post' 5
* @date 7/09/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_validate_save_post() {
// bail ealry if not set
if( empty($_POST['menu-item-acf']) ) return;
// loop
foreach( $_POST['menu-item-acf'] as $post_id => $values ) {
// vars
$prefix = 'menu-item-acf['.$post_id.']';
// validate
acf_validate_values( $values, $prefix );
}
}
/*
* admin_footer
*
* This function will add some custom HTML to the footer of the edit page
*
* @type function
* @date 11/06/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_footer() {
// global
global $acf_menu;
// vars
$post_id = acf_get_term_post_id( 'nav_menu', $acf_menu );
// get field groups
$field_groups = acf_get_field_groups(array(
'nav_menu' => $acf_menu
));
?>
<div id="tmpl-acf-menu-settings" style="display: none;">
<?php
// data (always needed to save nav menu items)
acf_form_data(array(
'post_id' => $post_id,
'nonce' => 'nav_menu',
));
// render
if( !empty($field_groups) ) {
// loop
foreach( $field_groups as $field_group ) {
$fields = acf_get_fields( $field_group );
echo '<div class="acf-menu-settings -'.$field_group['style'].'">';
echo '<h2>' . $field_group['title'] . '</h2>';
echo '<div class="acf-fields -left -clear">';
acf_render_fields( $post_id, $fields, 'div', $field_group['instruction_placement'] );
echo '</div>';
echo '</div>';
}
}
?>
</div>
<script type="text/javascript">
(function($) {
// append html
$('#post-body-content').append( $('#tmpl-acf-menu-settings').html() );
// avoid WP over-writing $_POST data
// - https://core.trac.wordpress.org/ticket/41502#ticket
$(document).on('submit', '#update-nav-menu', function() {
// vars
var $form = $(this);
var $input = $('input[name="nav-menu-data"]');
// decode json
var json = $form.serializeArray();
var json2 = [];
// loop
$.each( json, function( i, pair ) {
// avoid nesting (unlike WP)
if( pair.name === 'nav-menu-data' ) return;
// bail early if is 'acf[' input
if( pair.name.indexOf('acf[') > -1 ) return;
// append
json2.push( pair );
});
// update
$input.val( JSON.stringify(json2) );
});
})(jQuery);
</script>
<?php
}
}
new acf_form_nav_menu();
endif;
?>

View File

@@ -0,0 +1,632 @@
<?php
/*
* ACF Post Form Class
*
* All the logic for adding fields to posts
*
* @class acf_form_post
* @package ACF
* @subpackage Forms
*/
if( ! class_exists('acf_form_post') ) :
class acf_form_post {
var $post_id = 0,
$typenow = '',
$style = '';
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
// save
add_filter('wp_insert_post_empty_content', array($this, 'wp_insert_post_empty_content'), 10, 2);
add_action('save_post', array($this, 'save_post'), 10, 2);
// ajax
add_action('wp_ajax_acf/post/get_field_groups', array($this, 'get_field_groups'));
}
/*
* validate_page
*
* This function will check if the current page is for a post/page edit form
*
* @type function
* @date 23/06/12
* @since 3.1.8
*
* @param n/a
* @return (boolean)
*/
function validate_page() {
// global
global $post, $pagenow, $typenow;
// vars
$return = false;
// validate page
if( in_array($pagenow, array('post.php', 'post-new.php')) ) {
$return = true;
}
// update vars
if( !empty($post) ) {
$this->post_id = $post->ID;
$this->typenow = $typenow;
}
// validate post type
if( in_array($typenow, array('acf-field-group', 'attachment')) ) {
return false;
}
// validate page (Shopp)
if( $pagenow == "admin.php" && isset( $_GET['page'] ) && $_GET['page'] == "shopp-products" && isset( $_GET['id'] ) ) {
$return = true;
$this->post_id = absint( $_GET['id'] );
$this->typenow = 'shopp_product';
}
// return
return $return;
}
/*
* admin_enqueue_scripts
*
* This action is run after post query but before any admin script / head actions.
* It is a good place to register all actions.
*
* @type action (admin_enqueue_scripts)
* @date 26/01/13
* @since 3.6.0
*
* @param n/a
* @return n/a
*/
function admin_enqueue_scripts() {
// validate page
if( !$this->validate_page() ) return;
// load acf scripts
acf_enqueue_scripts();
// actions
add_action('acf/input/admin_head', array($this,'admin_head'));
add_action('acf/input/admin_footer', array($this,'admin_footer'));
}
/*
* admin_head
*
* This action will find and add field groups to the current edit page
*
* @type action (admin_head)
* @date 23/06/12
* @since 3.1.8
*
* @param n/a
* @return n/a
*/
function admin_head() {
// vars
$style_found = false;
// get field groups
$field_groups = acf_get_field_groups();
// add meta boxes
if( !empty($field_groups) ) {
foreach( $field_groups as $i => $field_group ) {
// vars
$id = "acf-{$field_group['key']}";
$title = $field_group['title'];
$context = $field_group['position'];
$priority = 'high';
$args = array(
'field_group' => $field_group,
'visibility' => false
);
// tweaks to vars
if( $context == 'side' ) {
$priority = 'core';
}
// filter for 3rd party customization
$priority = apply_filters('acf/input/meta_box_priority', $priority, $field_group);
// visibility
$args['visibility'] = acf_get_field_group_visibility( $field_group, array(
'post_id' => $this->post_id,
'post_type' => $this->typenow
));
// add meta box
add_meta_box( $id, $title, array($this, 'render_meta_box'), $this->typenow, $context, $priority, $args );
// update style
if( !$style_found && $args['visibility'] ) {
$style_found = true;
$this->style = acf_get_field_group_style( $field_group );
}
}
}
// Allow 'acf_after_title' metabox position
add_action('edit_form_after_title', array($this, 'edit_form_after_title'));
// remove postcustom metabox (removes expensive SQL query)
if( acf_get_setting('remove_wp_meta_box') ) {
remove_meta_box( 'postcustom', false, 'normal' );
}
// remove ACF values from meta postbox ()
add_filter('is_protected_meta', array($this, 'is_protected_meta'), 10, 3);
}
/*
* edit_form_after_title
*
* This action will allow ACF to render metaboxes after the title
*
* @type action
* @date 17/08/13
*
* @param n/a
* @return n/a
*/
function edit_form_after_title() {
// globals
global $post, $wp_meta_boxes;
// render post data
acf_form_data(array(
'post_id' => $this->post_id,
'nonce' => 'post',
'ajax' => 1
));
// render
do_meta_boxes( get_current_screen(), 'acf_after_title', $post);
// clean up
unset( $wp_meta_boxes['post']['acf_after_title'] );
}
/*
* render_meta_box
*
* description
*
* @type function
* @date 20/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function render_meta_box( $post, $args ) {
// extract args
extract( $args ); // all variables from the add_meta_box function
extract( $args ); // all variables from the args argument
// vars
$o = array(
'id' => $id,
'key' => $field_group['key'],
'style' => $field_group['style'],
'label' => $field_group['label_placement'],
'edit_url' => '',
'edit_title' => __('Edit field group', 'acf'),
'visibility' => $visibility
);
// edit_url
if( $field_group['ID'] && acf_current_user_can_admin() ) {
$o['edit_url'] = admin_url('post.php?post=' . $field_group['ID'] . '&action=edit');
}
// load and render fields
if( $visibility ) {
// load fields
$fields = acf_get_fields( $field_group );
// render
acf_render_fields( $this->post_id, $fields, 'div', $field_group['instruction_placement'] );
// render replace-me div
} else {
echo '<div class="acf-replace-with-fields"><div class="acf-loading"></div></div>';
}
?>
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
acf.postbox.render(<?php echo json_encode($o); ?>);
}
</script>
<?php
}
/*
* admin_footer
*
* description
*
* @type function
* @date 21/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function admin_footer(){
// get style of first field group
echo '<style type="text/css" id="acf-style">' . $this->style . '</style>';
}
/*
* get_field_groups
*
* This function will return all the JSON data needed to render new metaboxes
*
* @type function
* @date 21/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function get_field_groups() {
// options
$options = acf_parse_args($_POST, array(
'nonce' => '',
'post_id' => 0,
'ajax' => 1,
'exists' => array()
));
// vars
$json = array();
$exists = acf_extract_var( $options, 'exists' );
// verify nonce
if( !acf_verify_ajax() ) die();
// get field groups
$field_groups = acf_get_field_groups( $options );
// bail early if no field groups
if( empty($field_groups) ) {
wp_send_json_success( $json );
}
// loop through field groups
foreach( $field_groups as $i => $field_group ) {
// vars
$item = array(
//'ID' => $field_group['ID'], - JSON does not have ID (not used by JS anyway)
'key' => $field_group['key'],
'title' => $field_group['title'],
'html' => '',
'style' => ''
);
// style
if( $i == 0 ) {
$item['style'] = acf_get_field_group_style( $field_group );
}
// html
if( !in_array($field_group['key'], $exists) ) {
// load fields
$fields = acf_get_fields( $field_group );
// get field HTML
ob_start();
// render
acf_render_fields( $options['post_id'], $fields, 'div', $field_group['instruction_placement'] );
$item['html'] = ob_get_clean();
}
// append
$json[] = $item;
}
// return
wp_send_json_success( $json );
}
/*
* wp_insert_post_empty_content
*
* This function will allow WP to insert a new post without title / content if ACF data exists
*
* @type function
* @date 16/07/2014
* @since 5.0.1
*
* @param $maybe_empty (bool) whether the post should be considered "empty"
* @param $postarr (array) Array of post data
* @return $maybe_empty
*/
function wp_insert_post_empty_content( $maybe_empty, $postarr ) {
if( $maybe_empty && acf_maybe_get_POST('_acf_changed') ) {
$maybe_empty = false;
}
// return
return $maybe_empty;
}
/*
* allow_save_post
*
* This function will return true if the post is allowed to be saved
*
* @type function
* @date 26/06/2016
* @since 5.3.8
*
* @param $post_id (int)
* @return $post_id (int)
*/
function allow_save_post( $post ) {
// vars
$allow = true;
// disallow if is post type
$post_types = array( 'auto-draft', 'revision', 'acf-field', 'acf-field-group' );
if( in_array($post->post_type, $post_types) ) $allow = false;
// disallow if not the form post
$form_post_id = (int) acf_maybe_get_POST('post_ID');
if( $form_post_id && $form_post_id !== $post->ID ) $allow = false;
// revision (preview)
if( $post->post_type == 'revision' ) {
// allow if doing preview
if( acf_maybe_get_POST('wp-preview') == 'dopreview' ) $allow = true;
// disallow if not a revision of the form post
if( $form_post_id && $form_post_id !== $post->post_parent ) $allow = false;
}
// return
return $allow;
}
/*
* save_post
*
* This function will validate and save the $_POST data
*
* @type function
* @date 23/06/12
* @since 1.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function save_post( $post_id, $post ) {
// bail ealry if no allowed to save this post type
if( !$this->allow_save_post($post) ) return $post_id;
// verify nonce
if( !acf_verify_nonce('post') ) return $post_id;
// validate for published post (allow draft to save without validation)
if( $post->post_status == 'publish' ) {
// show errors
acf_validate_save_post( true );
}
// save
acf_save_post( $post_id );
// save revision
if( post_type_supports($post->post_type, 'revisions') ) {
acf_save_post_revision( $post_id );
}
// return
return $post_id;
}
/*
* is_protected_meta
*
* This function will remove any ACF meta from showing in the meta postbox
*
* @type function
* @date 12/04/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function is_protected_meta( $protected, $meta_key, $meta_type ) {
// if acf_get_field_reference returns a valid key, this is an acf value, so protect it!
if( !$protected ) {
$reference = acf_get_field_reference( $meta_key, $this->post_id );
if( acf_is_field_key($reference) ) {
$protected = true;
}
}
// return
return $protected;
}
}
new acf_form_post();
endif;
?>

View File

@@ -0,0 +1,462 @@
<?php
/*
* ACF Taxonomy Form Class
*
* All the logic for adding fields to taxonomy terms
*
* @class acf_form_taxonomy
* @package ACF
* @subpackage Forms
*/
if( ! class_exists('acf_form_taxonomy') ) :
class acf_form_taxonomy {
var $form = '#addtag';
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
// save
add_action('create_term', array($this, 'save_term'), 10, 3);
add_action('edit_term', array($this, 'save_term'), 10, 3);
// delete
add_action('delete_term', array($this, 'delete_term'), 10, 4);
}
/*
* validate_page
*
* This function will check if the current page is for a post/page edit form
*
* @type function
* @date 23/06/12
* @since 3.1.8
*
* @param n/a
* @return (boolean)
*/
function validate_page() {
// global
global $pagenow;
// validate page
if( $pagenow === 'edit-tags.php' || $pagenow === 'term.php' ) {
return true;
}
// return
return false;
}
/*
* admin_enqueue_scripts
*
* This action is run after post query but before any admin script / head actions.
* It is a good place to register all actions.
*
* @type action (admin_enqueue_scripts)
* @date 26/01/13
* @since 3.6.0
*
* @param N/A
* @return N/A
*/
function admin_enqueue_scripts() {
// validate page
if( !$this->validate_page() ) {
return;
}
// vars
$screen = get_current_screen();
$taxonomy = $screen->taxonomy;
// load acf scripts
acf_enqueue_scripts();
// actions
add_action('admin_footer', array($this, 'admin_footer'), 10, 1);
add_action("{$taxonomy}_add_form_fields", array($this, 'add_term'), 10, 1);
add_action("{$taxonomy}_edit_form", array($this, 'edit_term'), 10, 2);
}
/*
* add_term
*
* description
*
* @type function
* @date 8/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function add_term( $taxonomy ) {
// vars
$post_id = acf_get_term_post_id( $taxonomy, 0 );
// update vars
$this->form = '#addtag';
// get field groups
$field_groups = acf_get_field_groups(array(
'taxonomy' => $taxonomy
));
// render
if( !empty($field_groups) ) {
// data
acf_form_data(array(
'post_id' => $post_id,
'nonce' => 'taxonomy',
));
// wrap
echo '<div class="acf-addterm-fields acf-fields -clear">';
// loop
foreach( $field_groups as $field_group ) {
$fields = acf_get_fields( $field_group );
acf_render_fields( $post_id, $fields, 'div', 'field' );
}
// wrap
echo '</div>';
}
}
/*
* edit_term
*
* description
*
* @type function
* @date 8/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function edit_term( $term, $taxonomy ) {
// vars
$post_id = acf_get_term_post_id( $term->taxonomy, $term->term_id );
// update vars
$this->form = '#edittag';
// get field groups
$field_groups = acf_get_field_groups(array(
'taxonomy' => $taxonomy
));
// render
if( !empty($field_groups) ) {
acf_form_data(array(
'post_id' => $post_id,
'nonce' => 'taxonomy'
));
foreach( $field_groups as $field_group ) {
// title
if( $field_group['style'] == 'default' ) {
echo '<h2>' . $field_group['title'] . '</h2>';
}
// fields
echo '<table class="form-table">';
$fields = acf_get_fields( $field_group );
acf_render_fields( $post_id, $fields, 'tr', 'field' );
echo '</table>';
}
}
}
/*
* admin_footer
*
* description
*
* @type function
* @date 27/03/2015
* @since 5.1.5
*
* @param $post_id (int)
* @return $post_id (int)
*/
function admin_footer() {
?>
<script type="text/javascript">
(function($) {
// vars
var $spinner = $('<?php echo $this->form; ?> p.submit .spinner');
// create spinner if not exists (may exist in future WP versions)
if( !$spinner.exists() ) {
// create spinner
$spinner = $('<span class="spinner"></span>');
// append
$('<?php echo $this->form; ?> p.submit').append( $spinner );
}
// update acf validation class
acf.validation.error_class = 'form-invalid';
<?php if( $this->form == '#addtag' ): ?>
// store origional HTML
var $orig = $('#addtag').children('.acf-field').clone();
// events
$('#submit').on('click', function( e ){
// bail early if not active
if( !acf.validation.active ) {
return true;
}
// ignore validation (only ignore once)
if( acf.validation.ignore ) {
acf.validation.ignore = 0;
return true;
}
// bail early if this form does not contain ACF data
if( !$('#addtag').find('#acf-form-data').exists() ) {
return true;
}
// stop WP JS validation
e.stopImmediatePropagation();
// store submit trigger so it will be clicked if validation is passed
acf.validation.$trigger = $(this);
// run validation
acf.validation.fetch( $('#addtag') );
// stop all other click events on this input
return false;
});
$(document).ajaxComplete(function(event, xhr, settings) {
// bail early if is other ajax call
if( settings.data.indexOf('action=add-tag') == -1 ) {
return;
}
// unlock form
acf.validation.toggle( $('#addtag'), 'unlock' );
// bail early if response contains error
if( xhr.responseText.indexOf('wp_error') !== -1 ) {
return;
}
// action for 3rd party customization
acf.do_action('remove', $('#addtag'));
// remove old fields
$('#addtag').find('.acf-field').remove();
// add orig fields
$('#acf-form-data').after( $orig.clone() );
// reset unload
acf.unload.off();
// action for 3rd party customization
acf.do_action('append', $('#addtag'));
});
<?php endif; ?>
})(jQuery);
</script>
<?php
}
/*
* save_term
*
* description
*
* @type function
* @date 8/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function save_term( $term_id, $tt_id, $taxonomy ) {
// vars
$post_id = acf_get_term_post_id( $taxonomy, $term_id );
// verify and remove nonce
if( !acf_verify_nonce('taxonomy') ) return $term_id;
// valied and show errors
acf_validate_save_post( true );
// save
acf_save_post( $post_id );
}
/*
* delete_term
*
* description
*
* @type function
* @date 15/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function delete_term( $term, $tt_id, $taxonomy, $deleted_term ) {
// bail early if termmeta table exists
if( acf_isset_termmeta() ) return $term;
// globals
global $wpdb;
// vars
$search = $taxonomy . '_' . $term . '_%';
$_search = '_' . $search;
// escape '_'
// http://stackoverflow.com/questions/2300285/how-do-i-escape-in-sql-server
$search = str_replace('_', '\_', $search);
$_search = str_replace('_', '\_', $_search);
// delete
$result = $wpdb->query($wpdb->prepare(
"DELETE FROM $wpdb->options WHERE option_name LIKE %s OR option_name LIKE %s",
$search,
$_search
));
}
}
new acf_form_taxonomy();
endif;
?>

View File

@@ -0,0 +1,413 @@
<?php
/*
* ACF User Form Class
*
* All the logic for adding fields to users
*
* @class acf_form_user
* @package ACF
* @subpackage Forms
*/
if( ! class_exists('acf_form_user') ) :
class acf_form_user {
var $form = '#createuser';
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// actions
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('login_form_register', array($this, 'admin_enqueue_scripts'));
// render
add_action('show_user_profile', array($this, 'edit_user'));
add_action('edit_user_profile', array($this, 'edit_user'));
add_action('user_new_form', array($this, 'user_new_form'));
add_action('register_form', array($this, 'register_user'));
// save
//add_action('edit_user_profile_update', array($this, 'save_user'));
//add_action('personal_options_update', array($this, 'save_user'));
add_action('user_register', array($this, 'save_user'));
add_action('profile_update', array($this, 'save_user'));
}
/*
* validate_page
*
* This function will check if the current page is for a post/page edit form
*
* @type function
* @date 23/06/12
* @since 3.1.8
*
* @param N/A
* @return (boolean)
*/
function validate_page() {
// global
global $pagenow;
// validate page
if( in_array( $pagenow, array('profile.php', 'user-edit.php', 'user-new.php', 'wp-login.php') ) ) {
return true;
}
// return
return false;
}
/*
* admin_enqueue_scripts
*
* This action is run after post query but before any admin script / head actions.
* It is a good place to register all actions.
*
* @type action (admin_enqueue_scripts)
* @date 26/01/13
* @since 3.6.0
*
* @param N/A
* @return N/A
*/
function admin_enqueue_scripts() {
// validate page
if( ! $this->validate_page() ) {
return;
}
// load acf scripts
acf_enqueue_scripts();
// actions
add_action('acf/input/admin_footer', array($this, 'admin_footer'), 10, 1);
}
/*
* register_user
*
* description
*
* @type function
* @date 8/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function register_user() {
// update vars
$this->form = '#registerform';
// render
$this->render( 0, 'register', 'div' );
}
/*
* edit_user
*
* description
*
* @type function
* @date 8/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function edit_user( $user ) {
// update vars
$this->form = '#your-profile';
// render
$this->render( $user->ID, 'edit', 'tr' );
}
/*
* user_new_form
*
* description
*
* @type function
* @date 8/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function user_new_form() {
// update vars
$this->form = '#createuser';
// render
$this->render( 0, 'add', 'tr' );
}
/*
* render
*
* This function will render ACF fields for a given $post_id parameter
*
* @type function
* @date 7/10/13
* @since 5.0.0
*
* @param $user_id (int) this can be set to 0 for a new user
* @param $user_form (string) used for location rule matching. edit | add | register
* @param $el (string)
* @return n/a
*/
function render( $user_id, $user_form, $el = 'tr' ) {
// vars
$post_id = "user_{$user_id}";
$show_title = true;
// args
$args = array(
'user_id' => 'new',
'user_form' => $user_form
);
if( $user_id ) $args['user_id'] = $user_id;
// get field groups
$field_groups = acf_get_field_groups( $args );
// bail early if no field groups
if( empty($field_groups) ) return;
// form data
acf_form_data(array(
'post_id' => $post_id,
'nonce' => 'user'
));
// loop
foreach( $field_groups as $field_group ) {
// vars
$fields = acf_get_fields( $field_group );
// title
if( $show_title && $field_group['style'] === 'default' ) {
echo '<h2>' . $field_group['title'] . '</h2>';
}
// table start
if( $el == 'tr' ) {
echo '<table class="form-table"><tbody>';
} else {
echo '<div class="acf-user-register-fields acf-fields -clear">';
}
// render fields
acf_render_fields( $post_id, $fields, $el, $field_group['instruction_placement'] );
// table end
if( $el == 'tr' ) {
echo '</tbody></table>';
} else {
echo '</div>';
}
}
}
/*
* admin_footer
*
* description
*
* @type function
* @date 27/03/2015
* @since 5.1.5
*
* @param $post_id (int)
* @return $post_id (int)
*/
function admin_footer() {
?>
<style type="text/css">
<?php if( is_admin() ): ?>
/* override for user css */
.acf-field input[type="text"],
.acf-field input[type="password"],
.acf-field input[type="number"],
.acf-field input[type="search"],
.acf-field input[type="email"],
.acf-field input[type="url"],
.acf-field select {
max-width: 25em;
}
.acf-field textarea {
max-width: 500px;
}
/* allow sub fields to display correctly */
.acf-field .acf-field input[type="text"],
.acf-field .acf-field input[type="password"],
.acf-field .acf-field input[type="number"],
.acf-field .acf-field input[type="search"],
.acf-field .acf-field input[type="email"],
.acf-field .acf-field input[type="url"],
.acf-field .acf-field textarea,
.acf-field .acf-field select {
max-width: none;
}
<?php else: ?>
#registerform h2 {
margin: 1em 0;
}
#registerform .acf-field .acf-label {
margin-bottom: 0;
}
#registerform .acf-field .acf-label label {
font-weight: normal;
font-size: 14px;
}
#registerform p.submit {
text-align: right;
}
<?php endif; ?>
</style>
<script type="text/javascript">
(function($) {
// vars
var $spinner = $('<?php echo $this->form; ?> p.submit .spinner');
// create spinner if not exists (may exist in future WP versions)
if( !$spinner.exists() ) {
// create spinner (use .acf-spinner becuase .spinner CSS not included on register page)
$spinner = $('<span class="acf-spinner"></span>');
// append
$('<?php echo $this->form; ?> p.submit').append( $spinner );
}
})(jQuery);
</script>
<?php
}
/*
* save_user
*
* description
*
* @type function
* @date 8/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function save_user( $user_id ) {
// verify and remove nonce
if( ! acf_verify_nonce('user') ) {
return $user_id;
}
// save data
if( acf_validate_save_post(true) ) {
acf_save_post( "user_{$user_id}" );
}
}
}
new acf_form_user();
endif;
?>

View File

@@ -0,0 +1,384 @@
<?php
/*
* ACF Widget Form Class
*
* All the logic for adding fields to widgets
*
* @class acf_form_widget
* @package ACF
* @subpackage Forms
*/
if( ! class_exists('acf_form_widget') ) :
class acf_form_widget {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// vars
$this->preview_values = array();
$this->preview_reference = array();
$this->preview_errors = array();
// actions
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('in_widget_form', array($this, 'edit_widget'), 10, 3);
add_action('acf/validate_save_post', array($this, 'acf_validate_save_post'), 5);
// filters
add_filter('widget_update_callback', array($this, 'save_widget'), 10, 4);
}
/*
* admin_enqueue_scripts
*
* This action is run after post query but before any admin script / head actions.
* It is a good place to register all actions.
*
* @type action (admin_enqueue_scripts)
* @date 26/01/13
* @since 3.6.0
*
* @param N/A
* @return N/A
*/
function admin_enqueue_scripts() {
// validate screen
if( acf_is_screen('widgets') || acf_is_screen('customize') ) {
// valid
} else {
return;
}
// load acf scripts
acf_enqueue_scripts();
// actions
add_action('acf/input/admin_footer', array($this, 'admin_footer'), 1);
}
/*
* acf_validate_save_post
*
* This function will loop over $_POST data and validate
*
* @type action 'acf/validate_save_post' 5
* @date 7/09/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_validate_save_post() {
// bail ealry if not widget
if( !isset($_POST['_acf_widget_id']) ) return;
// vars
$id = $_POST['_acf_widget_id'];
$number = $_POST['_acf_widget_number'];
$prefix = $_POST['_acf_widget_prefix'];
// validate
acf_validate_values( $_POST[ $id ][ $number ]['acf'], $prefix );
}
/*
* edit_widget
*
* This function will render the fields for a widget form
*
* @type function
* @date 11/06/2014
* @since 5.0.0
*
* @param $widget (object)
* @param $return (null)
* @param $instance (object)
* @return $post_id (int)
*/
function edit_widget( $widget, $return, $instance ) {
// vars
$post_id = 0;
$prefix = 'widget-' . $widget->id_base . '[' . $widget->number . '][acf]';
// get id
if( $widget->number !== '__i__' ) {
$post_id = "widget_{$widget->id}";
}
// get field groups
$field_groups = acf_get_field_groups(array(
'widget' => $widget->id_base
));
// render
if( !empty($field_groups) ) {
// render post data
acf_form_data(array(
'post_id' => $post_id,
'nonce' => 'widget',
'widget_id' => 'widget-' . $widget->id_base,
'widget_number' => $widget->number,
'widget_prefix' => $prefix
));
// wrap
echo '<div class="acf-widget-fields acf-fields -clear">';
// loop
foreach( $field_groups as $field_group ) {
// load fields
$fields = acf_get_fields( $field_group );
// bail if not fields
if( empty($fields) ) continue;
// change prefix
acf_prefix_fields( $fields, $prefix );
// render
acf_render_fields( $post_id, $fields, 'div', $field_group['instruction_placement'] );
}
//wrap
echo '</div>';
// jQuery selector looks odd, but is necessary due to WP adding an incremental number into the ID
// - not possible to find number via PHP parameters
if( $widget->updated ): ?>
<script type="text/javascript">
(function($) {
acf.do_action('append', $('[id^="widget"][id$="<?php echo $widget->id; ?>"]') );
})(jQuery);
</script>
<?php endif;
}
}
/*
* save_widget
*
* This function will hook into the widget update filter and save ACF data
*
* @type function
* @date 27/05/2015
* @since 5.2.3
*
* @param $instance (array) widget settings
* @param $new_instance (array) widget settings
* @param $old_instance (array) widget settings
* @param $widget (object) widget info
* @return $instance
*/
function save_widget( $instance, $new_instance, $old_instance, $widget ) {
// bail ealry if not valid (!customize + acf values + nonce)
if( isset($_POST['wp_customize']) || !isset($new_instance['acf']) || !acf_verify_nonce('widget') ) return $instance;
// save
acf_save_post( "widget_{$widget->id}", $new_instance['acf'] );
// return
return $instance;
}
/*
* admin_footer
*
* This function will add some custom HTML to the footer of the edit page
*
* @type function
* @date 11/06/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function admin_footer() {
?>
<script type="text/javascript">
(function($) {
// vars
acf.update('post_id', 'widgets');
// restrict get fields
acf.add_filter('get_fields', function( $fields ){
// widgets
$fields = $fields.not('#available-widgets .acf-field');
// customizer
$fields = $fields.not('.widget-tpl .acf-field');
// return
return $fields;
});
$('#widgets-right').on('click', '.widget-control-save', function( e ){
// vars
var $form = $(this).closest('form');
// bail early if not active
if( !acf.validation.active ) {
return true;
}
// ignore validation (only ignore once)
if( acf.validation.ignore ) {
acf.validation.ignore = 0;
return true;
}
// bail early if this form does not contain ACF data
if( !$form.find('#acf-form-data').exists() ) {
return true;
}
// stop WP JS validation
e.stopImmediatePropagation();
// store submit trigger so it will be clicked if validation is passed
acf.validation.$trigger = $(this);
// run validation
acf.validation.fetch( $form );
// stop all other click events on this input
return false;
});
$(document).on('click', '.widget-top', function(){
var $el = $(this).parent().children('.widget-inside');
setTimeout(function(){
acf.get_fields('', $el).each(function(){
acf.do_action('show_field', $(this));
});
}, 250);
});
$(document).on('widget-added', function( e, $widget ){
// - use delay to avoid rendering issues with customizer (ensures div is visible)
setTimeout(function(){
acf.do_action('append', $widget );
}, 100);
});
$(document).on('widget-saved widget-updated', function( e, $widget ){
// unlock form
acf.validation.toggle( $widget, 'unlock' );
// submit
acf.do_action('submit', $widget );
});
})(jQuery);
</script>
<?php
}
}
new acf_form_widget();
endif;
?>

View File

@@ -0,0 +1,520 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_input') ) :
class acf_input {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// vars
$this->admin_enqueue_scripts = 'admin_enqueue_scripts';
$this->admin_head = 'admin_head';
$this->admin_footer = 'admin_footer';
$this->enqueued = false;
$this->data = array();
// actions
add_action('acf/save_post', array($this, 'save_post'), 10, 1);
}
/*
* get_data
*
* This function will return form data
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param $key (mixed)
* @return (mixed)
*/
function get_data( $key = false ) {
// vars
$data = $this->data;
// key
if( $key && isset($data[ $key ]) ) {
$data = $data[ $key ];
}
// return
return $data;
}
/*
* set_data
*
* This function will se the form data
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param $data (array)
* @return (array)
*/
function set_data( $data ) {
// defaults
$data = acf_parse_args($data, array(
'post_id' => 0, // ID of current post
'nonce' => 'post', // nonce used for $_POST validation
'validation' => 1, // runs AJAX validation
'ajax' => 0, // fetches new field groups via AJAX
'changed' => 0,
));
// update
$this->data = $data;
// enqueue uploader if page allows AJAX fields to appear
if( $data['ajax'] ) {
add_action($this->admin_footer, 'acf_enqueue_uploader', 1);
}
// return
return $data;
}
/*
* enqueue
*
* This function will determin the actions to use for different pages
*
* @type function
* @date 13/01/2016
* @since 5.3.2
*
* @param n/a
* @return n/a
*/
function enqueue() {
// bail ealry if already enqueued
if( $this->enqueued ) return;
// update setting
$this->enqueued = true;
// global
global $pagenow;
// determine action hooks
if( $pagenow == 'customize.php' ) {
$this->admin_head = 'customize_controls_print_scripts';
$this->admin_footer = 'customize_controls_print_footer_scripts';
} elseif( $pagenow == 'wp-login.php' ) {
$this->admin_enqueue_scripts = 'login_enqueue_scripts';
$this->admin_head = 'login_head';
$this->admin_footer = 'login_footer';
} elseif( !is_admin() ) {
$this->admin_enqueue_scripts = 'wp_enqueue_scripts';
$this->admin_head = 'wp_head';
$this->admin_footer = 'wp_footer';
}
// actions
acf_maybe_add_action($this->admin_enqueue_scripts, array($this, 'admin_enqueue_scripts'), 20 );
acf_maybe_add_action($this->admin_head, array($this, 'admin_head'), 20 );
acf_maybe_add_action($this->admin_footer, array($this, 'admin_footer'), 20 );
}
/*
* admin_enqueue_scripts
*
* The acf input screen admin_enqueue_scripts
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param n/a
* @return n/a
*/
function admin_enqueue_scripts() {
// scripts
wp_enqueue_script('acf-input');
// styles
wp_enqueue_style('acf-input');
// do action
do_action('acf/input/admin_enqueue_scripts');
}
/*
* admin_head
*
* The acf input screen admin_head
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param n/a
* @return n/a
*/
function admin_head() {
// do action
do_action('acf/input/admin_head');
}
/*
* admin_footer
*
* The acf input screen admin_footer
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param n/a
* @return n/a
*/
function admin_footer() {
// global
global $wp_version;
// options
$o = array(
'post_id' => acf_get_form_data('post_id'),
'nonce' => wp_create_nonce( 'acf_nonce' ),
'admin_url' => admin_url(),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'ajax' => acf_get_form_data('ajax'),
'validation' => acf_get_form_data('validation'),
'wp_version' => $wp_version,
'acf_version' => acf_get_setting('version'),
'browser' => acf_get_browser(),
'locale' => get_locale(),
'rtl' => is_rtl()
);
// l10n
$l10n = apply_filters( 'acf/input/admin_l10n', array(
'unload' => __('The changes you made will be lost if you navigate away from this page','acf'),
'expand_details' => __('Expand Details','acf'),
'collapse_details' => __('Collapse Details','acf'),
'validation_successful' => __('Validation successful', 'acf'),
'validation_failed' => __('Validation failed', 'acf'),
'validation_failed_1' => __('1 field requires attention', 'acf'),
'validation_failed_2' => __('%d fields require attention', 'acf'),
'restricted' => __('Restricted','acf'),
'are_you_sure' => __('Are you sure?','acf'),
'yes' => __('Yes','acf'),
'no' => __('No','acf'),
'remove' => __('Remove','acf'),
'cancel' => __('Cancel','acf')
));
?>
<script type="text/javascript">
var acf = acf || null;
if( acf ) {
acf.o = <?php echo json_encode($o); ?>;
acf.l10n = <?php echo json_encode($l10n); ?>;
<?php do_action('acf/input/admin_footer_js'); ?>
}
</script>
<?php
do_action('acf/input/admin_footer');
?>
<script type="text/javascript">
if( acf ) acf.do_action('prepare');
</script>
<?php
}
/*
* save_post
*
* This function will save the $_POST data
*
* @type function
* @date 24/10/2014
* @since 5.0.9
*
* @param $post_id (int)
* @return n/a
*/
function save_post( $post_id ) {
// bail early if empty
// - post data may have be modified
if( empty($_POST['acf']) ) return;
// loop
foreach( $_POST['acf'] as $k => $v ) {
// get field
$field = acf_get_field( $k );
// continue if no field
if( !$field ) continue;
// update
acf_update_value( $v, $post_id, $field );
}
}
}
// initialize
acf()->input = new acf_input();
endif; // class_exists check
/*
* acf_enqueue_scripts
*
* alias of acf()->form->enqueue()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_enqueue_scripts() {
return acf()->input->enqueue();
}
/*
* acf_get_form_data
*
* alias of acf()->form->get_data()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_get_form_data( $key = false ) {
return acf()->input->get_data( $key );
}
/*
* acf_set_form_data
*
* alias of acf()->form->set_data()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_set_form_data( $data = array() ) {
return acf()->input->set_data( $data );
}
/*
* acf_enqueue_uploader
*
* This function will render a WP WYSIWYG and enqueue media
*
* @type function
* @date 27/10/2014
* @since 5.0.9
*
* @param n/a
* @return n/a
*/
function acf_enqueue_uploader() {
// bail early if doing ajax
if( acf_is_ajax() ) return;
// bail ealry if already run
if( acf_has_done('enqueue_uploader') ) return;
// enqueue media if user can upload
if( current_user_can('upload_files') ) {
wp_enqueue_media();
}
// create dummy editor
?><div id="acf-hidden-wp-editor" class="acf-hidden"><?php wp_editor( '', 'acf_content' ); ?></div><?php
}
/*
* acf_form_data
*
* description
*
* @type function
* @date 15/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_form_data( $args = array() ) {
// make sure scripts and styles have been included
// case: front end bbPress edit user
acf_enqueue_scripts();
// set form data
$args = acf_set_form_data( $args );
// hidden inputs
$inputs = $args;
$inputs['nonce'] = wp_create_nonce($inputs['nonce']);
?>
<div id="acf-form-data" class="acf-hidden">
<?php foreach( $inputs as $k => $v ): ?>
<input type="hidden" id="_acf_<?php echo esc_attr($k); ?>" name="_acf_<?php echo esc_attr($k); ?>" value="<?php echo esc_attr($v); ?>" />
<?php endforeach; ?>
<?php do_action('acf/input/form_data', $args); ?>
</div>
<?php
}
/*
* acf_save_post
*
* description
*
* @type function
* @date 8/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_save_post( $post_id = 0, $values = null ) {
// override $_POST
if( $values !== null ) {
$_POST['acf'] = $values;
}
// bail early if no values
if( empty($_POST['acf']) ) return false;
// set form data
acf_set_form_data(array(
'post_id' => $post_id
));
// hook for 3rd party customization
do_action('acf/save_post', $post_id);
// return
return true;
}

View File

@@ -0,0 +1,279 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_json') ) :
class acf_json {
function __construct() {
// update setting
acf_update_setting('save_json', get_stylesheet_directory() . '/acf-json');
acf_append_setting('load_json', get_stylesheet_directory() . '/acf-json');
// actions
add_action('acf/update_field_group', array($this, 'update_field_group'), 10, 1);
add_action('acf/duplicate_field_group', array($this, 'update_field_group'), 10, 1);
add_action('acf/untrash_field_group', array($this, 'update_field_group'), 10, 1);
add_action('acf/trash_field_group', array($this, 'delete_field_group'), 10, 1);
add_action('acf/delete_field_group', array($this, 'delete_field_group'), 10, 1);
add_action('acf/include_fields', array($this, 'include_json_folders'), 10, 0);
}
/*
* update_field_group
*
* This function is hooked into the acf/update_field_group action and will save all field group data to a .json file
*
* @type function
* @date 10/03/2014
* @since 5.0.0
*
* @param $field_group (array)
* @return n/a
*/
function update_field_group( $field_group ) {
// validate
if( !acf_get_setting('json') ) return;
// get fields
$field_group['fields'] = acf_get_fields( $field_group );
// save file
acf_write_json_field_group( $field_group );
}
/*
* delete_field_group
*
* This function will remove the field group .json file
*
* @type function
* @date 10/03/2014
* @since 5.0.0
*
* @param $field_group (array)
* @return n/a
*/
function delete_field_group( $field_group ) {
// validate
if( !acf_get_setting('json') ) return;
// WP appends '__trashed' to end of 'key' (post_name)
$field_group['key'] = str_replace('__trashed', '', $field_group['key']);
// delete
acf_delete_json_field_group( $field_group['key'] );
}
/*
* include_json_folders
*
* This function will include all registered .json files
*
* @type function
* @date 10/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function include_json_folders() {
// validate
if( !acf_get_setting('json') ) return;
// vars
$paths = acf_get_setting('load_json');
// loop through and add to cache
foreach( $paths as $path ) {
$this->include_json_folder( $path );
}
}
/*
* include_json_folder
*
* This function will include all .json files within a folder
*
* @type function
* @date 1/5/17
* @since 5.5.13
*
* @param n/a
* @return n/a
*/
function include_json_folder( $path = '' ) {
// remove trailing slash
$path = untrailingslashit( $path );
// bail early if path does not exist
if( !is_dir($path) ) return false;
// open
$dir = opendir( $path );
// loop over files
while(false !== ( $file = readdir($dir)) ) {
// validate type
if( pathinfo($file, PATHINFO_EXTENSION) !== 'json' ) continue;
// read json
$json = file_get_contents("{$path}/{$file}");
// validate json
if( empty($json) ) continue;
// decode
$json = json_decode($json, true);
// add local
$json['local'] = 'json';
// add field group
acf_add_local_field_group( $json );
}
// return
return true;
}
}
// initialize
acf()->json = new acf_json();
endif; // class_exists check
/*
* acf_write_json_field_group
*
* This function will save a field group to a json file within the current theme
*
* @type function
* @date 5/12/2014
* @since 5.1.5
*
* @param $field_group (array)
* @return (boolean)
*/
function acf_write_json_field_group( $field_group ) {
// vars
$path = acf_get_setting('save_json');
$file = $field_group['key'] . '.json';
// remove trailing slash
$path = untrailingslashit( $path );
// bail early if dir does not exist
if( !is_writable($path) ) return false;
// prepare for export
$id = acf_extract_var( $field_group, 'ID' );
$field_group = acf_prepare_field_group_for_export( $field_group );
// add modified time
$field_group['modified'] = get_post_modified_time('U', true, $id, true);
// write file
$f = fopen("{$path}/{$file}", 'w');
fwrite($f, acf_json_encode( $field_group ));
fclose($f);
// return
return true;
}
/*
* acf_delete_json_field_group
*
* This function will delete a json field group file
*
* @type function
* @date 5/12/2014
* @since 5.1.5
*
* @param $key (string)
* @return (boolean)
*/
function acf_delete_json_field_group( $key ) {
// vars
$path = acf_get_setting('save_json');
$file = $key . '.json';
// remove trailing slash
$path = untrailingslashit( $path );
// bail early if file does not exist
if( !is_readable("{$path}/{$file}") ) {
return false;
}
// remove file
unlink("{$path}/{$file}");
// return
return true;
}
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,356 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_locations') ) :
class acf_locations {
/** @var array Contains an array of location rule instances */
var $locations = array();
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
/* do nothing */
}
/*
* register_location
*
* This function will store a location rule class
*
* @type function
* @date 6/07/2016
* @since 5.4.0
*
* @param $instance (object)
* @return n/a
*/
function register_location( $class ) {
$instance = new $class();
$this->locations[ $instance->name ] = $instance;
}
/*
* get_rule
*
* This function will return a location rule class
*
* @type function
* @date 6/07/2016
* @since 5.4.0
*
* @param $name (string)
* @return (mixed)
*/
function get_location( $name ) {
return isset( $this->locations[$name] ) ? $this->locations[$name] : null;
}
/*
* get_rules
*
* This function will return a grouped array of location rules (category => name => label)
*
* @type function
* @date 6/07/2016
* @since 5.4.0
*
* @param n/a
* @return (array)
*/
function get_locations() {
// vars
$groups = array();
$l10n = array(
'post' => __('Post', 'acf'),
'page' => __('Page', 'acf'),
'user' => __('User', 'acf'),
'forms' => __('Forms', 'acf'),
);
// loop
foreach( $this->locations as $location ) {
// bail ealry if not public
if( !$location->public ) continue;
// translate
$cat = $location->category;
$cat = isset( $l10n[$cat] ) ? $l10n[$cat] : $cat;
// append
$groups[ $cat ][ $location->name ] = $location->label;
}
// filter
$groups = apply_filters('acf/location/rule_types', $groups);
// return
return $groups;
}
}
// initialize
acf()->locations = new acf_locations();
endif; // class_exists check
/*
* acf_register_location_rule
*
* alias of acf()->locations->register_location()
*
* @type function
* @date 31/5/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_register_location_rule( $class ) {
return acf()->locations->register_location( $class );
}
/*
* acf_get_location_rule
*
* alias of acf()->locations->get_location()
*
* @type function
* @date 31/5/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_get_location_rule( $name ) {
return acf()->locations->get_location( $name );
}
/*
* acf_get_location_rule_types
*
* alias of acf()->locations->get_locations()
*
* @type function
* @date 31/5/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function acf_get_location_rule_types() {
return acf()->locations->get_locations();
}
/*
* acf_get_valid_location_rule
*
* This function will return a valid location rule array
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param $rule (array)
* @return (array)
*/
function acf_get_valid_location_rule( $rule ) {
// defaults
$rule = wp_parse_args( $rule, array(
'id' => '',
'group' => '',
'param' => '',
'operator' => '==',
'value' => '',
));
// prefix for inputs
$rule['prefix'] = 'acf_field_group[location]['.$rule['group'].']['.$rule['id'].']';
// return
return $rule;
}
/*
* acf_get_location_rule_operators
*
* This function will return the operators for a given rule
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param $rule (array)
* @return (array)
*/
function acf_get_location_rule_operators( $rule ) {
// vars
$operators = array(
'==' => __("is equal to",'acf'),
'!=' => __("is not equal to",'acf'),
);
// filter
$operators = apply_filters( "acf/location/rule_operators/{$rule['param']}", $operators, $rule );
$operators = apply_filters( "acf/location/rule_operators", $operators, $rule );
// return
return $operators;
}
/*
* acf_get_location_rule_values
*
* This function will return the values for a given rule
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param $rule (array)
* @return (array)
*/
function acf_get_location_rule_values( $rule ) {
// vars
$values = array();
// filter
$values = apply_filters( "acf/location/rule_values/{$rule['param']}", $values, $rule );
$values = apply_filters( "acf/location/rule_values", $values, $rule );
// return
return $values;
}
/*
* acf_match_location_rule
*
* This function will match a given rule to the $screen
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param $rule (array)
* @param $screen (array)
* @return (boolean)
*/
function acf_match_location_rule( $rule, $screen ) {
// vars
$result = false;
// filter
$result = apply_filters( "acf/location/rule_match/{$rule['param']}", $result, $rule, $screen );
$result = apply_filters( "acf/location/rule_match", $result, $rule, $screen );
// return
return $result;
}
/*
* acf_get_location_screen
*
* This function will return a valid location screen array
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param $screen (array)
* @param $field_group (array)
* @return (array)
*/
function acf_get_location_screen( $screen, $field_group ) {
// vars
$screen = wp_parse_args($screen, array(
'lang' => acf_get_setting('current_language'),
'ajax' => false
));
// filter for 3rd party customization
$screen = apply_filters('acf/location/screen', $screen, $field_group);
// return
return $screen;
}
?>

View File

@@ -0,0 +1,127 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_attachment') ) :
class acf_location_attachment extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'attachment';
$this->label = __("Attachment",'acf');
$this->category = 'forms';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$attachment = acf_maybe_get( $screen, 'attachment' );
// validate
if( !$attachment ) return false;
// get attachment mime type
$mime_type = get_post_mime_type( $attachment );
// no specific mime
if( !strpos($rule['value'], '/') ) {
// explode into [0] => type, [1] => mime
$bits = explode('/', $mime_type);
// if type matches, fake the $mime_type to match
if( $rule['value'] === $bits[0] ) {
$mime_type = $rule['value'];
}
}
// match
return $this->compare( $mime_type, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// vars
$mimes = get_allowed_mime_types();
$choices = array(
'all' => __('All', 'acf')
);
// loop
foreach( $mimes as $type => $mime ) {
$group = current( explode('/', $mime) );
$choices[ $group ][ $group ] = sprintf( __('All %s formats', 'acf'), $group);
$choices[ $group ][ $mime ] = "$type ($mime)";
}
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_attachment' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,95 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_comment') ) :
class acf_location_comment extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'comment';
$this->label = __("Comment",'acf');
$this->category = 'forms';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$comment = acf_maybe_get( $screen, 'comment' );
// bail early if not comment
if( !$comment ) return false;
// return
return $this->compare( $comment, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// vars
$choices = array( 'all' => __('All', 'acf') );
$choices = array_merge( $choices, acf_get_pretty_post_types() );
// change this to post types that support comments
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_comment' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,128 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_current_user_role') ) :
class acf_location_current_user_role extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'current_user_role';
$this->label = __("Current User Role",'acf');
$this->category = 'user';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// bail early if not logged in
if( !is_user_logged_in() ) return false;
// vars
$user = wp_get_current_user();
// super_admin
if( $rule['value'] == 'super_admin' ) {
$result = is_super_admin( $user->ID );
// role
} else {
$result = in_array( $rule['value'], $user->roles );
}
// reverse if 'not equal to'
if( $rule['operator'] == '!=' ) {
$result = !$result;
}
// return
return $result;
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// global
global $wp_roles;
// specific roles
$choices = $wp_roles->get_names();
// multi-site
if( is_multisite() ) {
$prepend = array( 'super_admin' => __('Super Admin', 'acf') );
$choices = array_merge( $prepend, $choices );
}
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_current_user_role' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,111 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_current_user') ) :
class acf_location_current_user extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'current_user';
$this->label = __("Current User",'acf');
$this->category = 'user';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// logged in
if( $rule['value'] == 'logged_in' ) {
$result = is_user_logged_in();
// viewing_front
} elseif( $rule['value'] == 'viewing_front' ) {
$result = !is_admin();
// viewing_back
} elseif( $rule['value'] == 'viewing_back' ) {
$result = is_admin();
}
// reverse if 'not equal to'
if( $rule['operator'] == '!=' ) {
$result = !$result;
}
// return
return $result;
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
return array(
'logged_in' => __('Logged in', 'acf'),
'viewing_front' => __('Viewing front end', 'acf'),
'viewing_back' => __('Viewing back end', 'acf')
);
}
}
// initialize
acf_register_location_rule( 'acf_location_current_user' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,106 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_nav_menu_item') ) :
class acf_location_nav_menu_item extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'nav_menu_item';
$this->label = __("Menu Item",'acf');
$this->category = 'forms';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$nav_menu_item = acf_maybe_get( $screen, 'nav_menu_item' );
// bail early if not nav_menu_item
if( !$nav_menu_item ) return false;
// global
global $acf_menu;
// append nav_menu data
$screen['nav_menu'] = $acf_menu;
// return
return acf_get_location_rule('nav_menu')->rule_match( $result, $rule, $screen );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// get menu choices
$choices = acf_get_location_rule('nav_menu')->rule_values( $choices, $rule );
// append item types?
// dificult to get these details
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_nav_menu_item' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,138 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_nav_menu') ) :
class acf_location_nav_menu extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'nav_menu';
$this->label = __("Menu",'acf');
$this->category = 'forms';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$nav_menu = acf_maybe_get( $screen, 'nav_menu' );
// bail early if not nav_menu
if( !$nav_menu ) return false;
// location
if( substr($rule['value'], 0, 9) === 'location/' ) {
// vars
$location = substr($rule['value'], 9);
$menu_locations = get_nav_menu_locations();
// bail ealry if no location
if( !isset($menu_locations[$location]) ) return false;
// if location matches, update value
if( $menu_locations[$location] == $nav_menu ) {
$nav_menu = $rule['value'];
}
}
// return
return $this->compare( $nav_menu, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// all
$choices = array(
'all' => __('All', 'acf'),
);
// locations
$nav_locations = get_registered_nav_menus();
if( !empty($nav_locations) ) {
$cat = __('Menu Locations', 'acf');
foreach( $nav_locations as $slug => $title ) {
$choices[ $cat ][ 'location/'.$slug ] = $title;
}
}
// specific menus
$nav_menus = wp_get_nav_menus();
if( !empty($nav_menus) ) {
$cat = __('Menus', 'acf');
foreach( $nav_menus as $nav_menu ) {
$choices[ $cat ][ $nav_menu->term_id ] = $nav_menu->name;
}
}
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_nav_menu' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,100 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_page_parent') ) :
class acf_location_page_parent extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'page_parent';
$this->label = __("Page Parent",'acf');
$this->category = 'page';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
$page_parent = acf_maybe_get( $screen, 'page_parent' );
// no page parent
if( $page_parent === null ) {
// bail early if no post id
if( !$post_id ) return false;
// get post parent
$post = get_post( $post_id );
$page_parent = $post->post_parent;
}
// compare
return $this->compare( $page_parent, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
return acf_get_location_rule('page')->rule_values( $choices, $rule );
}
}
// initialize
acf_register_location_rule( 'acf_location_page_parent' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,119 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_page_template') ) :
class acf_location_page_template extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'page_template';
$this->label = __("Page Template",'acf');
$this->category = 'page';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_type = acf_maybe_get( $screen, 'post_type' );
// lookup post_type
if( !$post_type ) {
$post_id = acf_maybe_get( $screen, 'post_id' );
if( !$post_id ) return false;
$post_type = get_post_type( $post_id );
}
// page template 'default' rule is only for 'page' post type
// prevents 'Default Template' field groups appearing on all post types that allow for post templates (WP 4.7)
if( $rule['value'] === 'default' ) {
// bail ealry if not page
if( $post_type !== 'page' ) return false;
}
// return
return acf_get_location_rule('post_template')->rule_match( $result, $rule, $screen );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// vars
$choices = array(
'default' => apply_filters( 'default_page_template_title', __('Default Template', 'acf') )
);
// get templates and merge them in
$templates = wp_get_theme()->get_page_templates();
$choices = array_merge($choices, $templates);
// return choices
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_page_template' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,161 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_page_type') ) :
class acf_location_page_type extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'page_type';
$this->label = __("Page Type",'acf');
$this->category = 'page';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
// bail early if no post id
if( !$post_id ) return false;
// get post
$post = get_post( $post_id );
// compare
if( $rule['value'] == 'front_page') {
// vars
$front_page = (int) get_option('page_on_front');
// compare
$result = ( $front_page === $post->ID );
} elseif( $rule['value'] == 'posts_page') {
// vars
$posts_page = (int) get_option('page_for_posts');
// compare
$result = ( $posts_page === $post->ID );
} elseif( $rule['value'] == 'top_level') {
// vars
$page_parent = acf_maybe_get( $screen, 'page_parent', $post->post_parent );
// compare
$result = ( $page_parent == 0 );
} elseif( $rule['value'] == 'parent' ) {
// get children
$children = get_posts(array(
'post_type' => $post->post_type,
'post_parent' => $post->ID,
'posts_per_page' => 1,
'fields' => 'ids',
));
// compare
$result = !empty( $children );
} elseif( $rule['value'] == 'child') {
// vars
$page_parent = acf_maybe_get( $screen, 'page_parent', $post->post_parent );
// compare
$result = ( $page_parent > 0 );
}
// reverse if 'not equal to'
if( $rule['operator'] == '!=' ) {
$result = !$result;
}
// return
return $result;
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
return array(
'front_page' => __("Front Page",'acf'),
'posts_page' => __("Posts Page",'acf'),
'top_level' => __("Top Level Page (no parent)",'acf'),
'parent' => __("Parent Page (has children)",'acf'),
'child' => __("Child Page (has parent)",'acf'),
);
}
}
// initialize
acf_register_location_rule( 'acf_location_page_type' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,99 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_page') ) :
class acf_location_page extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'page';
$this->label = __("Page",'acf');
$this->category = 'page';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
return acf_get_location_rule('post')->rule_match( $result, $rule, $screen );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// get posts grouped by post type
$groups = acf_get_grouped_posts(array(
'post_type' => 'page'
));
// pop
$choices = array_pop( $groups );
// convert posts to titles
foreach( $choices as &$item ) {
$item = acf_get_post_title( $item );
}
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_page' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,88 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post_category') ) :
class acf_location_post_category extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post_category';
$this->label = __("Post Category",'acf');
$this->category = 'post';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
return acf_get_location_rule('post_taxonomy')->rule_match( $result, $rule, $screen );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
$terms = acf_get_taxonomy_terms( 'category' );
if( !empty($terms) ) {
$choices = array_pop($terms);
}
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_post_category' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,143 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post_format') ) :
class acf_location_post_format extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post_format';
$this->label = __("Post Format",'acf');
$this->category = 'post';
}
/*
* get_post_type
*
* This function will return the current post_type
*
* @type function
* @date 25/11/16
* @since 5.5.0
*
* @param $options (int)
* @return (mixed)
*/
function get_post_type( $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
$post_type = acf_maybe_get( $screen, 'post_type' );
// post_type
if( $post_type ) return $post_type;
// $post_id
if( $post_id ) return get_post_type( $post_id );
// return
return false;
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_format = acf_maybe_get( $screen, 'post_format' );
// find post format
if( !$post_format ) {
// get post id
$post_id = acf_maybe_get( $screen, 'post_id' );
$post_type = $this->get_post_type( $screen );
// bail early if not a post
if( !$post_id || !$post_type ) return false;
// does post_type support 'post-format'
if( post_type_supports($post_type, 'post-formats') ) {
// update
$post_format = get_post_format($post_id);
$post_format = $post_format ? $post_format : 'standard';
}
}
// compare
return $this->compare( $post_format, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
return get_post_format_strings();
}
}
// initialize
acf_register_location_rule( 'acf_location_post_format' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,161 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post_status') ) :
class acf_location_post_status extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post_status';
$this->label = __("Post Status",'acf');
$this->category = 'post';
}
/*
* get_post_type
*
* This function will return the current post_type
*
* @type function
* @date 25/11/16
* @since 5.5.0
*
* @param $options (int)
* @return (mixed)
*/
function get_post_type( $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
$post_type = acf_maybe_get( $screen, 'post_type' );
// post_type
if( $post_type ) return $post_type;
// $post_id
if( $post_id ) return get_post_type( $post_id );
// return
return false;
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_status = acf_maybe_get( $screen, 'post_status' );
// find post format
if( !$post_status ) {
// get post id
$post_id = acf_maybe_get( $screen, 'post_id' );
// bail early if not a post
if( !$post_id ) return false;
// update
$post_status = get_post_status( $post_id );
}
// auto-draft = draft
if( $post_status == 'auto-draft' ) {
$post_status = 'draft';
}
// match
return $this->compare( $post_status, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// globals
global $wp_post_statuses;
// append
if( !empty($wp_post_statuses) ) {
foreach( $wp_post_statuses as $status ) {
$choices[ $status->name ] = $status->label;
}
}
// return choices
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_post_status' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,161 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post_taxonomy') ) :
class acf_location_post_taxonomy extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post_taxonomy';
$this->label = __("Post Taxonomy",'acf');
$this->category = 'post';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
$terms = acf_maybe_get( $screen, 'post_taxonomy' );
// bail early if not a post
if( !$post_id ) return false;
// get term data
$data = acf_decode_taxonomy_term( $rule['value'] );
$term = get_term_by( 'slug', $data['term'], $data['taxonomy'] );
// attempt get term via ID (ACF4 uses ID)
if( !$term && is_numeric($data['term']) ) {
$term = get_term_by( 'id', $data['term'], $data['taxonomy'] );
}
// bail early if no term
if( !$term ) return false;
// not ajax, load real post's terms
if( $terms === null ) {
$terms = wp_get_post_terms( $post_id, $term->taxonomy, array('fields' => 'ids') );
}
// If no terms, this is a new post and should be treated as if it has the "Uncategorized" (1) category ticked
if( empty($terms) ) {
// get post type
$post_type = get_post_type( $post_id );
// if is category
if( is_object_in_taxonomy($post_type, 'category') ) {
$terms = array( 1 );
}
}
// match
if( !empty($terms) ) {
$result = in_array( $term->term_id, $terms );
}
// reverse if 'not equal to'
if( $rule['operator'] === '!=' ) {
$result = !$result;
}
// return
return $result;
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// get
$choices = acf_get_taxonomy_terms();
// unset post_format
if( isset($choices['post_format']) ) {
unset( $choices['post_format']) ;
}
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_post_taxonomy' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,176 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post_template') ) :
class acf_location_post_template extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post_template';
$this->label = __("Post Template",'acf');
$this->category = 'post';
$this->public = acf_version_compare('wp', '>=', '4.7');
}
/*
* get_post_type
*
* This function will return the current post_type
*
* @type function
* @date 25/11/16
* @since 5.5.0
*
* @param $options (int)
* @return (mixed)
*/
function get_post_type( $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
$post_type = acf_maybe_get( $screen, 'post_type' );
// post_type
if( $post_type ) return $post_type;
// $post_id
if( $post_id ) return get_post_type( $post_id );
// return
return false;
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$templates = array();
$post_id = acf_maybe_get( $screen, 'post_id' );
$page_template = acf_maybe_get( $screen, 'page_template' );
$post_type = $this->get_post_type( $screen );
// bail early if no post_type found (not a post)
if( !$post_type ) return false;
// get templates (WP 4.7)
if( acf_version_compare('wp', '>=', '4.7') ) {
$templates = acf_get_post_templates();
}
// 'page' is always a valid pt even if no templates exist in the theme
// allows scenario where page_template = 'default' and no templates exist
if( !isset($templates['page']) ) {
$templates['page'] = array();
}
// bail early if this post type does not allow for templates
if( !isset($templates[ $post_type ]) ) return false;
// get page template
if( !$page_template ) {
$page_template = get_post_meta( $post_id, '_wp_page_template', true );
}
// new post - no page template
if( !$page_template ) $page_template = "default";
// match
return $this->compare( $page_template, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// vars
$choices = array(
'default' => apply_filters( 'default_page_template_title', __('Default Template', 'acf') )
);
// get templates (WP 4.7)
if( acf_version_compare('wp', '>=', '4.7') ) {
$templates = acf_get_post_templates();
$choices = array_merge($choices, $templates);
}
// return choices
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_post_template' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,132 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post_type') ) :
class acf_location_post_type extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post_type';
$this->label = __("Post Type",'acf');
$this->category = 'post';
}
/*
* get_post_type
*
* This function will return the current post_type
*
* @type function
* @date 25/11/16
* @since 5.5.0
*
* @param $options (int)
* @return (mixed)
*/
function get_post_type( $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
$post_type = acf_maybe_get( $screen, 'post_type' );
// post_type
if( $post_type ) return $post_type;
// $post_id
if( $post_id ) return get_post_type( $post_id );
// return
return false;
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_type = $this->get_post_type( $screen );
// bail early if no post_type found (not a post)
if( !$post_type ) return false;
// match
return $this->compare( $post_type, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// get post types
// - removed show_ui to allow 3rd party code to register a post type using a custom admin edit page
$post_types = acf_get_post_types(array(
//'show_ui' => 1,
'exclude' => array('attachment')
));
// return choices
return acf_get_pretty_post_types( $post_types );
}
}
// initialize
acf_register_location_rule( 'acf_location_post_type' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,127 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post') ) :
class acf_location_post extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post';
$this->label = __("Post",'acf');
$this->category = 'post';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
// bail early if not post
if( !$post_id ) return false;
// compare
return $this->compare( $post_id, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// get post types
$post_types = acf_get_post_types(array(
'exclude' => array('page', 'attachment')
));
// get posts grouped by post type
$groups = acf_get_grouped_posts(array(
'post_type' => $post_types
));
if( !empty($groups) ) {
foreach( array_keys($groups) as $group_title ) {
// vars
$posts = acf_extract_var( $groups, $group_title );
// override post data
foreach( array_keys($posts) as $post_id ) {
// update
$posts[ $post_id ] = acf_get_post_title( $posts[ $post_id ] );
};
// append to $choices
$choices[ $group_title ] = $posts;
}
}
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_post' );
endif; // class_exists check
?>

Some files were not shown because too many files have changed in this diff Show More