Added dependency plugins
This commit is contained in:
@@ -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;
|
||||
|
||||
?>
|
||||
@@ -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;
|
||||
|
||||
?>
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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();
|
||||
|
||||
?>
|
||||
@@ -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();
|
||||
|
||||
?>
|
||||
@@ -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
|
||||
|
||||
?>
|
||||
@@ -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
|
||||
|
||||
?>
|
||||
@@ -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
|
||||
|
||||
?>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user