예제 #1
0
 function load()
 {
     // disable filters to ensure ACF loads raw data from DB
     acf_disable_filters();
     // run import / export
     if (acf_verify_nonce('import')) {
         $this->import();
     } elseif (acf_verify_nonce('export')) {
         if (isset($_POST['generate'])) {
             $this->generate();
         } else {
             $this->export();
         }
     }
     // load acf scripts
     acf_enqueue_scripts();
 }
예제 #2
0
function acf_untrash_field($selector = 0)
{
    // disable filters to ensure ACF loads raw data from DB
    acf_disable_filters();
    // load the origional field gorup
    $field = acf_get_field($selector);
    // bail early if field did not load correctly
    if (empty($field)) {
        return false;
    }
    // delete field
    wp_untrash_post($field['ID']);
    // action for 3rd party customisation
    do_action('acf/untrash_field', $field);
    // return
    return true;
}
예제 #3
0
 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'));
 }
예제 #4
0
function acf_import_field_group($field_group)
{
    // disable filters to ensure ACF loads raw data from DB
    acf_disable_filters();
    // vars
    $ref = array();
    $order = array();
    // extract fields
    $fields = acf_extract_var($field_group, 'fields');
    // format fields
    $fields = acf_prepare_fields_for_import($fields);
    // remove old fields
    if ($field_group['ID']) {
        // load fields
        $db_fields = acf_get_fields_by_id($field_group['ID']);
        $db_fields = acf_prepare_fields_for_import($db_fields);
        // get field keys
        $keys = array();
        foreach ($fields as $field) {
            $keys[] = $field['key'];
        }
        // loop over db fields
        foreach ($db_fields as $field) {
            // add to ref
            $ref[$field['key']] = $field['ID'];
            if (!in_array($field['key'], $keys)) {
                acf_delete_field($field['ID']);
            }
        }
    }
    // enable local filter for JSON to be created
    acf_enable_filter('local');
    // save field group
    $field_group = acf_update_field_group($field_group);
    // add to ref
    $ref[$field_group['key']] = $field_group['ID'];
    // add to order
    $order[$field_group['ID']] = 0;
    // add fields
    foreach ($fields as $field) {
        // add ID
        if (!$field['ID'] && isset($ref[$field['key']])) {
            $field['ID'] = $ref[$field['key']];
        }
        // add parent
        if (empty($field['parent'])) {
            $field['parent'] = $field_group['ID'];
        } elseif (isset($ref[$field['parent']])) {
            $field['parent'] = $ref[$field['parent']];
        }
        // add field menu_order
        if (!isset($order[$field['parent']])) {
            $order[$field['parent']] = 0;
        }
        $field['menu_order'] = $order[$field['parent']];
        $order[$field['parent']]++;
        // save field
        $field = acf_update_field($field);
        // add to ref
        $ref[$field['key']] = $field['ID'];
    }
    // return new field group
    return $field_group;
}
예제 #5
0
 function ajax_move_field()
 {
     // disable filters to ensure ACF loads raw data from DB
     acf_disable_filters();
     $args = acf_parse_args($_POST, array('nonce' => '', '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);
         $v1 = $field['label'];
         $v2 = '<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'), $v1, $v2) . '</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();
     if (!empty($field_groups)) {
         foreach ($field_groups as $field_group) {
             if ($field_group['ID']) {
                 $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;
 }