function acf_pro_get_remote_response($action = '', $post = array()) { // vars $url = acf_pro_get_remote_url($action); // connect $request = wp_remote_post($url, array('body' => $post)); // error if (is_wp_error($request)) { // loop foreach ($request->errors as $k => $v) { // bail early if no error if (empty($v[0])) { continue; } // save acf_update_setting('remote_response_error', $k . ': ' . $v[0]); // only run once break; } // success } elseif (wp_remote_retrieve_response_code($request) === 200) { return $request['body']; } // return return 0; }
function __construct() { // global global $sitepress; // vars $this->lang = ICL_LANGUAGE_CODE; // update settings acf_update_setting('default_language', $sitepress->get_default_language()); acf_update_setting('current_language', $this->lang); // actions add_action('acf/verify_ajax', array($this, 'verify_ajax')); add_action('acf/field_group/admin_head', array($this, 'admin_head')); add_action('acf/input/admin_head', array($this, 'admin_head')); // bail early if not transaltable if (!$this->is_translatable()) { return; } // actions add_action('acf/upgrade_start/5.0.0', array($this, 'upgrade_start_5')); add_action('acf/upgrade_finish/5.0.0', array($this, 'upgrade_finish_5')); add_action('acf/update_field_group', array($this, 'update_field_group'), 2, 1); add_action('icl_make_duplicate', array($this, 'icl_make_duplicate'), 10, 4); // filters add_filter('acf/settings/save_json', array($this, 'settings_save_json')); add_filter('acf/settings/load_json', array($this, 'settings_load_json')); }
/** * Action: Set Language * * @param string $lang_slug * @param object $current_lang Current language */ public function set_language($lang_slug, $current_lang) { $this->default_lang = pll_default_language(); $this->current_lang = pll_current_language(); acf_update_setting('default_language', $this->default_lang); acf_update_setting('current_language', $this->current_lang); }
function init() { // ACF_LITE if (defined('ACF_LITE') && ACF_LITE) { acf_update_setting('show_admin', false); } }
function __construct() { // update setting acf_update_setting('pro', true); acf_update_setting('name', __('Advanced Custom Fields PRO', 'acf')); // api acf_include('pro/api/api-pro.php'); acf_include('pro/api/api-options-page.php'); // updates acf_include('pro/core/updates.php'); // admin if (is_admin()) { // options page acf_include('pro/admin/options-page.php'); // settings acf_include('pro/admin/settings-updates.php'); } // fields acf_include('pro/fields/repeater.php'); acf_include('pro/fields/flexible-content.php'); acf_include('pro/fields/gallery.php'); // actions add_action('init', array($this, 'wp_init')); add_action('acf/input/admin_enqueue_scripts', array($this, 'input_admin_enqueue_scripts')); add_action('acf/field_group/admin_enqueue_scripts', array($this, 'field_group_admin_enqueue_scripts')); add_action('acf/field_group/admin_l10n', array($this, 'field_group_admin_l10n')); // filters add_filter('acf/get_valid_field', array($this, 'get_valid_field'), 11, 1); add_filter('acf/update_field', array($this, 'update_field'), 1, 1); add_filter('acf/prepare_field_for_export', array($this, 'prepare_field_for_export')); add_filter('acf/prepare_field_for_import', array($this, 'prepare_field_for_import')); }
function __construct() { // update setting acf_update_setting('save_json', get_stylesheet_directory() . '/acf-json'); acf_append_setting('load_json', get_stylesheet_directory() . '/acf-json'); // actions add_action('acf/update_field_group', array($this, 'update_field_group'), 10, 5); add_action('acf/duplicate_field_group', array($this, 'update_field_group'), 10, 5); add_action('acf/untrash_field_group', array($this, 'update_field_group'), 10, 5); add_action('acf/trash_field_group', array($this, 'delete_field_group'), 10, 5); add_action('acf/delete_field_group', array($this, 'delete_field_group'), 10, 5); add_action('acf/include_fields', array($this, 'include_fields'), 10, 5); }
function __construct() { // global global $sitepress; // vars $this->lang = ICL_LANGUAGE_CODE; // update settings acf_update_setting('default_language', $sitepress->get_default_language()); acf_update_setting('current_language', $this->lang); // actions add_action('acf/update_field_group', array($this, 'update_field_group'), 1, 1); add_action('icl_make_duplicate', array($this, 'icl_make_duplicate'), 10, 4); add_action('acf/field_group/admin_head', array($this, 'admin_head')); add_action('acf/input/admin_head', array($this, 'admin_head')); // filters add_filter('acf/settings/save_json', array($this, 'settings_save_json')); add_filter('acf/settings/load_json', array($this, 'settings_load_json')); }
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; } // import field group if ($key = acf_maybe_get($_GET, 'acfsync')) { // 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); // validate check_admin_referer('bulk-posts'); // 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]); // redirect wp_redirect(admin_url($this->url . '&acfsynccomplete=' . $field_group['ID'])); exit; } elseif (acf_maybe_get($_GET, 'action2') === 'acfsync') { // validate check_admin_referer('bulk-posts'); // get ids $keys = acf_maybe_get($_GET, 'post'); if (!empty($keys)) { // 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(); foreach ($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')); }
function acf_form($args = array()) { // vars $url = acf_get_current_url(); // defaults $args = wp_parse_args($args, array('id' => 'acf-form', 'post_id' => false, 'new_post' => false, 'field_groups' => false, 'fields' => false, 'post_title' => false, 'post_content' => false, 'form' => true, 'form_attributes' => array(), 'return' => add_query_arg('updated', 'true', $url), 'html_before_fields' => '', 'html_after_fields' => '', 'submit_value' => __("Update", 'acf'), 'updated_message' => __("Post updated", 'acf'), 'label_placement' => 'top', 'instruction_placement' => 'label', 'field_el' => 'div', 'uploader' => 'wp')); $args['form_attributes'] = wp_parse_args($args['form_attributes'], array('id' => 'post', 'class' => '', 'action' => '', 'method' => 'post')); // filter post_id $args['post_id'] = acf_get_valid_post_id($args['post_id']); // load values from this post $post_id = $args['post_id']; // new post? if ($post_id == 'new_post') { // dont load values $post_id = false; // new post defaults $args['new_post'] = acf_parse_args($args['new_post'], array('post_type' => 'post', 'post_status' => 'draft')); } // attributes $args['form_attributes']['class'] .= ' acf-form'; // vars $field_groups = array(); $fields = array(); // post_title if ($args['post_title']) { $fields[] = acf_get_valid_field(array('name' => '_post_title', 'label' => 'Title', 'type' => 'text', 'value' => $post_id ? get_post_field('post_title', $post_id) : '', 'required' => true)); } // post_content if ($args['post_content']) { $fields[] = acf_get_valid_field(array('name' => '_post_content', 'label' => 'Content', 'type' => 'wysiwyg', 'value' => $post_id ? get_post_field('post_content', $post_id) : '')); } // specific fields if ($args['fields']) { foreach ($args['fields'] as $selector) { // append field ($strict = false to allow for better compatibility with field names) $fields[] = acf_maybe_get_field($selector, $post_id, false); } } elseif ($args['field_groups']) { foreach ($args['field_groups'] as $selector) { $field_groups[] = acf_get_field_group($selector); } } elseif ($args['post_id'] == 'new_post') { $field_groups = acf_get_field_groups(array('post_type' => $args['new_post']['post_type'])); } else { $field_groups = acf_get_field_groups(array('post_id' => $args['post_id'])); } //load fields based on field groups if (!empty($field_groups)) { foreach ($field_groups as $field_group) { $field_group_fields = acf_get_fields($field_group); if (!empty($field_group_fields)) { foreach (array_keys($field_group_fields) as $i) { $fields[] = acf_extract_var($field_group_fields, $i); } } } } // updated message if (!empty($_GET['updated']) && $args['updated_message']) { echo '<div id="message" class="updated"><p>' . $args['updated_message'] . '</p></div>'; } // uploader (always set incase of multiple forms on the page) acf_update_setting('uploader', $args['uploader']); // display form if ($args['form']) { ?> <form <?php acf_esc_attr_e($args['form_attributes']); ?> > <?php } // render post data acf_form_data(array('post_id' => $args['post_id'], 'nonce' => 'acf_form')); ?> <div class="acf-hidden"> <?php acf_hidden_input(array('name' => '_acf_form', 'value' => base64_encode(json_encode($args)))); ?> </div> <div class="acf-fields acf-form-fields -<?php echo $args['label_placement']; ?> "> <?php // html before fields echo $args['html_before_fields']; // render acf_render_fields($post_id, $fields, $args['field_el'], $args['instruction_placement']); // html after fields echo $args['html_after_fields']; ?> </div><!-- acf-form-fields --> <?php if ($args['form']) { ?> <!-- Submit --> <div class="acf-form-submit"> <input type="submit" class="button button-primary button-large" value="<?php echo $args['submit_value']; ?> " /> <span class="acf-spinner"></span> </div> <!-- / Submit --> </form> <?php } }
function admin_load() { // globals global $plugin_page; // vars $this->page = acf_get_options_page($plugin_page); // verify and remove nonce if (acf_verify_nonce('options')) { // save data if (acf_validate_save_post(true)) { // get post_id (allow lang modification) $post_id = acf_get_valid_post_id($this->page['post_id']); // set autoload acf_update_setting('autoload', $this->page['autoload']); // save acf_save_post($post_id); // redirect wp_redirect(add_query_arg(array('message' => '1'))); exit; } } // load acf 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 columns support add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); }
function acf_duplicate_fields($fields, $new_parent = 0) { // bail early if no fields if (empty($fields)) { return; } // create new field keys (for conditional logic fixes) foreach ($fields as $field) { // ensure a delay for unique ID usleep(1); acf_update_setting('duplicate_key_' . $field['key'], uniqid('field_')); } // duplicate fields foreach ($fields as $field) { // duplicate acf_duplicate_field($field['ID'], $new_parent); } }
function admin_load() { // globals global $plugin_page; // vars $this->page = acf_get_options_page($plugin_page); // verify and remove nonce if (acf_verify_nonce('options')) { // save data if (acf_validate_save_post(true)) { // get post_id (allow lang modification) $post_id = acf_get_valid_post_id($this->page['post_id']); // set autoload acf_update_setting('autoload', $this->page['autoload']); // save acf_save_post($post_id); // redirect wp_redirect(admin_url("admin.php?page={$plugin_page}&message=1")); exit; } } // actions add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); }
function generate() { // translate if (acf_get_setting('l10n_textdomain')) { // prevent default translation acf_update_setting('l10n_var_export', true); // filters add_filter('acf/prepare_field_group_for_export', array($this, '_translate_field_group')); add_filter('acf/prepare_field_for_export', array($this, '_translate_field')); } // vars $json = $this->get_json(); // validate if ($json === false) { acf_add_admin_notice(__("No field groups selected", 'acf'), 'error'); return; } // update view $this->view = 'settings-tools-export'; $this->data['field_groups'] = $json; }
function copernico_acf_init() { global $copernico_opt; acf_update_setting('google_api_key', $copernico_opt['acf_google_map_api']); }
function complete() { // bail early if actions have not passed 'plugins_loaded' // this allows all plugins / theme to hook in if (!did_action('plugins_loaded')) { return; } // once run once if (acf_get_setting('complete')) { return; } // update setting acf_update_setting('complete', true); // wpml if (defined('ICL_SITEPRESS_VERSION')) { acf_include('core/wpml.php'); } // include field types do_action('acf/include_field_types', 5); // include local fields do_action('acf/include_fields', 5); // final action do_action('acf/init'); }
function complete() { // bail early if actions have not passed 'plugins_loaded' if (!did_action('plugins_loaded')) { return; } // once run once if (acf_get_setting('complete')) { return; } // update setting acf_update_setting('complete', true); // wpml if (defined('ICL_SITEPRESS_VERSION')) { acf_include('core/wpml.php'); } // action for 3rd party customization do_action('acf/include_field_types', 5); do_action('acf/include_fields', 5); }
function generate() { // prevent default translation and fake __() within string acf_update_setting('l10n_var_export', true); // vars $json = $this->get_json(); // validate if ($json === false) { acf_add_admin_notice(__("No field groups selected", 'acf'), 'error'); return; } // update view $this->view = 'settings-tools-export'; $this->data['field_groups'] = $json; }
function acf_debug_start() { acf_update_setting('debug_start', memory_get_usage()); }
function acf_disable_filters() { // get filters $filters = acf_get_setting('_filters', array()); // loop foreach (array_keys($filters) as $k) { $filters[$k] = false; } // update acf_update_setting('_filters', $filters); }
function after_setup_theme() { if (defined('ACF_LITE') && ACF_LITE) { acf_update_setting('show_admin', false); } }
function init() { // bail early if a plugin called get_field early if (!did_action('plugins_loaded')) { return; } // bail early if already init if (acf_get_setting('init')) { return; } // only run once acf_update_setting('init', true); // vars $major = intval(acf_get_setting('version')); // redeclare dir // - allow another plugin to modify dir (maybe force SSL) acf_update_setting('dir', plugin_dir_url(__FILE__)); // set text domain load_textdomain('acf', acf_get_path('lang/acf-' . get_locale() . '.mo')); // include wpml support if (defined('ICL_SITEPRESS_VERSION')) { acf_include('core/wpml.php'); } // field types acf_include('fields/text.php'); acf_include('fields/textarea.php'); acf_include('fields/number.php'); acf_include('fields/email.php'); acf_include('fields/url.php'); acf_include('fields/password.php'); acf_include('fields/wysiwyg.php'); acf_include('fields/oembed.php'); acf_include('fields/image.php'); acf_include('fields/file.php'); acf_include('fields/select.php'); acf_include('fields/checkbox.php'); acf_include('fields/radio.php'); acf_include('fields/true_false.php'); acf_include('fields/post_object.php'); acf_include('fields/page_link.php'); acf_include('fields/relationship.php'); acf_include('fields/taxonomy.php'); acf_include('fields/user.php'); acf_include('fields/google-map.php'); acf_include('fields/date_picker.php'); acf_include('fields/date_time_picker.php'); acf_include('fields/time_picker.php'); acf_include('fields/color_picker.php'); acf_include('fields/message.php'); acf_include('fields/tab.php'); // 3rd party field types do_action('acf/include_field_types', $major); // local fields do_action('acf/include_fields', $major); // action for 3rd party do_action('acf/init'); }
function acf_form_data($args = array()) { // make sure scripts and styles have been included // case: front end bbPress edit user acf_enqueue_scripts(); // defaults $args = acf_parse_args($args, array('post_id' => 0, 'nonce' => 'post', 'validation' => 1, 'ajax' => 0)); // save form_data for later actions acf_update_setting('form_data', $args); // enqueue uploader if page allows AJAX fields to appear if ($args['ajax']) { add_action('admin_footer', 'acf_enqueue_uploader', 1); //acf_enqueue_uploader(); } ?> <div id="acf-form-data" class="acf-hidden"> <input type="hidden" name="_acfnonce" value="<?php echo wp_create_nonce($args['nonce']); ?> " /> <input type="hidden" name="_acfchanged" value="0" /> <?php do_action('acf/input/form_data', $args); ?> </div> <?php }
function wpc_acf_init() { acf_update_setting('google_api_key', GOOGLE_MAP_API_KEY); }