function admin_footer() { // vars $args = acf_get_setting('form_data'); // validate if (empty($args)) { return; } // global global $wp_version; // options $o = array('post_id' => $args['post_id'], 'nonce' => wp_create_nonce('acf_nonce'), 'admin_url' => admin_url(), 'ajaxurl' => admin_url('admin-ajax.php'), 'ajax' => $args['ajax'], 'wp_version' => $wp_version); // l10n $l10n = apply_filters('acf/input/admin_l10n', array('core' => array('expand_details' => __('Expand Details', 'acf'), 'collapse_details' => __('Collapse Details', 'acf'), 'save_alert' => __('The changes you made will be lost if you navigate away from this page.', 'acf')), 'validation' => array('error' => __("Validation Failed. One or more fields below are required.", 'acf')))); ?> <script type="text/javascript"> (function($) { acf.o = <?php echo json_encode($o); ?> ; acf.l10n = <?php echo json_encode($l10n); ?> ; })(jQuery); </script> <?php }
function inject_update($transient) { // bail early if not admin if (!is_admin()) { return $transient; } // bail early if no update available if (!acf_pro_is_update_available()) { return $transient; } // vars $info = acf_pro_get_remote_info(); $basename = acf_get_setting('basename'); $slug = acf_get_setting('slug'); // create new object for update $obj = new stdClass(); $obj->slug = $slug; $obj->new_version = $info['version']; $obj->url = $info['homepage']; $obj->package = ''; // license if (acf_pro_is_license_active()) { $obj->package = acf_pro_get_remote_url('download', array('k' => acf_pro_get_license())); } // add to transient $transient->response[$basename] = $obj; // return return $transient; }
function modify_plugin_update($transient) { // bail early if no response (dashboard showed an error) if (!isset($transient->response)) { return $transient; } // vars $basename = acf_get_setting('basename'); $show_updates = acf_get_setting('show_updates'); // bail early if not a plugin (included in theme) if (!acf_is_plugin_active()) { $show_updates = false; } // bail early if no show_updates if (!$show_updates) { // remove from transient unset($transient->response[$basename]); // return return $transient; } // get update $update = acf_maybe_get($transient->response, $basename); // filter $update = apply_filters('acf/updates/plugin_update', $update, $transient); // update if ($update) { $transient->response[$basename] = $update; } else { unset($transient->response[$basename]); } // return return $transient; }
function input_admin_enqueue_scripts() { // bail ealry if no enqueue if (!acf_get_setting('enqueue_select2')) { return; } // globals global $wp_scripts, $wp_styles; // vars $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; $major = acf_get_setting('select2_version'); $version = ''; $script = ''; $style = ''; // v4 if ($major == 4) { $version = '4.0'; $script = acf_get_dir("assets/inc/select2/4/select2.full{$min}.js"); $style = acf_get_dir("assets/inc/select2/4/select2{$min}.css"); // v3 } else { $version = '3.5.2'; $script = acf_get_dir("assets/inc/select2/3/select2{$min}.js"); $style = acf_get_dir("assets/inc/select2/3/select2.css"); } // enqueue wp_enqueue_script('select2', $script, array('jquery'), $version); wp_enqueue_style('select2', $style, '', $version); }
function admin_footer() { // vars $args = acf_get_setting('form_data'); // global global $wp_version; // options $o = array('post_id' => $args['post_id'], 'nonce' => wp_create_nonce('acf_nonce'), 'admin_url' => admin_url(), 'ajaxurl' => admin_url('admin-ajax.php'), 'ajax' => $args['ajax'], 'validation' => $args['validation'], 'wp_version' => $wp_version); // l10n $l10n = apply_filters('acf/input/admin_l10n', array('unload' => __('The changes you made will be lost if you navigate away from this page', 'acf'), 'expand_details' => __('Expand Details', 'acf'), 'collapse_details' => __('Collapse Details', 'acf'))); ?> <script type="text/javascript"> /* <![CDATA[ */ if( typeof acf !== 'undefined' ) { acf.o = <?php echo json_encode($o); ?> ; acf.l10n = <?php echo json_encode($l10n); ?> ; <?php do_action('acf/input/admin_footer_js'); ?> } /* ]]> */ </script> <?php }
/** * Check if the installed version of ACF is compatible with this version of Layotter * * @return bool */ public static function is_version_compatible() { if (self::is_pro_installed()) { return version_compare(acf_get_setting('version'), self::REQUIRED_PRO_VERSION) >= 0; } else { return version_compare(acf()->get_info('version'), self::REQUIRED_VERSION) >= 0; } }
function admin_menu() { // bail early if no show_admin if (!acf_get_setting('show_admin')) { return; } add_menu_page(__("Custom Fields", 'acf'), __("Custom Fields", 'acf'), 'manage_options', 'edit.php?post_type=acf-field-group', false, false, '80.025'); }
function wp_init() { // register acf scripts wp_register_script('acf-pro-input', acf_get_dir('pro/js/pro-input.js'), false, acf_get_setting('version')); wp_register_style('acf-pro-input', acf_get_dir('pro/css/pro-input.css'), false, acf_get_setting('version')); // register acf scripts wp_register_script('acf-pro-field-group', acf_get_dir('pro/js/pro-field-group.js'), false, acf_get_setting('version')); wp_register_style('acf-pro-field-group', acf_get_dir('pro/css/pro-field-group.css'), false, acf_get_setting('version')); }
function is_enabled() { // bail early if no local allowed if (!acf_get_setting('local')) { return false; } // return return acf_is_filter_enabled('local'); }
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', __('Import / Export', 'acf'), __('Import/Export', 'acf'), 'manage_options', 'acf-settings-export', array($this, 'html')); // actions add_action('load-' . $page, array($this, 'load')); }
function wp_init() { // min $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; // register scripts wp_register_script('acf-pro-input', acf_get_dir("pro/js/pro-input{$min}.js"), false, acf_get_setting('version')); wp_register_script('acf-pro-field-group', acf_get_dir("pro/js/pro-field-group{$min}.js"), false, acf_get_setting('version')); // register styles wp_register_style('acf-pro-input', acf_get_dir('pro/css/pro-input.css'), false, acf_get_setting('version')); wp_register_style('acf-pro-field-group', acf_get_dir('pro/css/pro-field-group.css'), false, acf_get_setting('version')); }
function acf_get_valid_field_group($field_group = false) { // parse in defaults $field_group = acf_parse_args($field_group, array('ID' => 0, 'key' => '', 'title' => '', 'fields' => array(), 'location' => array(), 'menu_order' => 0, 'position' => 'normal', 'style' => 'default', 'label_placement' => 'top', 'instruction_placement' => 'label', 'hide_on_screen' => array(), 'active' => 1, 'description' => '')); // translate $field_group = acf_translate_keys($field_group, acf_get_setting('l10n_field_group')); // filter $field_group = apply_filters('acf/get_valid_field_group', $field_group); // return return $field_group; }
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 if (!empty($_GET['tab']) && array_key_exists($_GET['tab'], $view['tabs'])) { $view['active'] = $_GET['tab']; } // load view acf_get_view('settings-info', $view); }
function admin_menu() { // bail early if no show_admin if (!acf_get_setting('show_admin')) { return; } // add parent menu page add_menu_page(__("Custom Fields", 'acf'), __("Custom Fields", 'acf'), acf_get_setting('capability'), 'edit.php?post_type=acf-field-group', false, false, '80.025'); // add child menu page add_submenu_page('edit.php?post_type=acf-field-group', __('Add New', 'acf'), __('Add New', 'acf'), acf_get_setting('capability'), 'post-new.php?post_type=acf-field-group'); }
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-settings-tools', array($this, 'html')); // actions add_action('load-' . $page, array($this, 'load')); }
function input_admin_enqueue_scripts() { // bail ealry if no enqueue if (!acf_get_setting('enqueue_datepicker')) { return; } // script wp_enqueue_script('jquery-ui-datepicker'); // style wp_enqueue_style('acf-datepicker', acf_get_dir('assets/inc/datepicker/jquery-ui.min.css'), '', '1.11.4'); }
function input_admin_enqueue_scripts() { // bail ealry if no enqueue if (!acf_get_setting('enqueue_datetimepicker')) { return; } // vars $version = '1.6.1'; // script wp_enqueue_script('acf-timepicker', acf_get_dir('assets/inc/timepicker/jquery-ui-timepicker-addon.min.js'), array('jquery-ui-datepicker'), $version); // style wp_enqueue_style('acf-timepicker', acf_get_dir('assets/inc/timepicker/jquery-ui-timepicker-addon.min.css'), '', $version); }
function acf_translate_field_group($field_group) { // vars $l10n = acf_get_setting('l10n'); $l10n_textdomain = acf_get_setting('l10n_textdomain'); // if if ($l10n && $l10n_textdomain) { // translate $field_group['title'] = acf_translate($field_group['title']); // filters $field_group = apply_filters("acf/translate_field_group", $field_group); } // return return $field_group; }
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'); }
public function after_setup_theme() { // check to see if acf5 is installed // if not then do not run anything else in this plugin // move all other actions to this function except text domain since this is too late if (!class_exists('acf') || !function_exists('acf_get_setting') || intval(acf_get_setting('version')) < 5 || !class_exists('acf_pro')) { $this->active = false; return; } add_action('init', array($this, 'init'), 0); add_action('admin_menu', array($this, 'build_admin_menu_list'), 999); add_filter('acf/load_field/name=_acfop_parent', array($this, 'acf_load_parent_menu_field')); add_filter('acf/load_field/name=_acfop_capability', array($this, 'acf_load_capabilities_field')); add_filter('manage_edit-' . $this->post_type . '_columns', array($this, 'admin_columns')); add_action('manage_' . $this->post_type . '_posts_custom_column', array($this, 'admin_columns_content'), 10, 2); add_action('acf/include_fields', array($this, 'acf_include_fields')); add_filter('acf_options_page/post_type', array($this, 'get_post_type')); add_filter('acf_options_page/text_domain', array($this, 'get_text_domain')); }
function include_fields() { // validate if (!acf_get_setting('json')) { return; } // vars $paths = acf_get_setting('load_json'); // loop through and add to cache foreach ($paths as $path) { // remove trailing slash $path = untrailingslashit($path); // check that path exists if (!file_exists($path)) { continue; } $dir = opendir($path); while (false !== ($file = readdir($dir))) { // only json files if (strpos($file, '.json') === false) { continue; } // read json $json = file_get_contents("{$path}/{$file}"); // validate json if (empty($json)) { continue; } // decode $json = json_decode($json, true); // add local $json['local'] = 'json'; // add field group acf_add_local_field_group($json); } } }
function modify_plugin_update($transient) { // bail early if no response (dashboard showed an error) if (empty($transient->response)) { return $transient; } // vars $basename = acf_get_setting('basename'); $show_updates = acf_get_setting('show_updates'); // ensure is_plugin_active() exists (not on frontend) if (!function_exists('is_plugin_active')) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; } // bail early if not a plugin (included in theme) if (!is_plugin_active($basename)) { $show_updates = false; } // bail early if no show_updates if (!$show_updates) { // remove from transient unset($transient->response[$basename]); // return return $transient; } // get update $update = acf_maybe_get($transient->response, $basename); // filter $update = apply_filters('acf/updates/plugin_update', $update, $transient); // update if ($update) { $transient->response[$basename] = $update; } else { unset($transient->response[$basename]); } // return return $transient; }
function inject_update($transient) { // vars $basename = acf_get_setting('basename'); // bail early if no show_updates if (!acf_get_setting('show_updates')) { return $transient; } // bail early if not a plugin (included in theme) if (!is_plugin_active($basename)) { return; } // bail early if no update available if (!acf_pro_is_update_available()) { return $transient; } // vars $info = acf_pro_get_remote_info(); $basename = acf_get_setting('basename'); $slug = acf_get_setting('slug'); // create new object for update $obj = new stdClass(); $obj->slug = $slug; $obj->plugin = $basename; $obj->new_version = $info['version']; $obj->url = $info['homepage']; $obj->package = ''; // license if (acf_pro_is_license_active()) { $obj->package = acf_pro_get_remote_url('download', array('k' => acf_pro_get_license(), 'wp_url' => home_url(), 'acf_version' => acf_get_setting('version'), 'wp_version' => get_bloginfo('version'))); } // add to transient $transient->response[$basename] = $obj; // return return $transient; }
function render_field($field) { // vars $uploader = acf_get_setting('uploader'); // enqueue if ($uploader == 'wp') { acf_enqueue_uploader(); } // vars $o = array('icon' => '', 'title' => '', 'url' => '', 'filesize' => '', 'filename' => ''); $div = array('class' => 'acf-file-uploader acf-cf', 'data-library' => $field['library'], 'data-mime_types' => $field['mime_types'], 'data-uploader' => $uploader); // has value? if ($field['value']) { $file = get_post($field['value']); if ($file) { $o['icon'] = wp_mime_type_icon($file->ID); $o['title'] = $file->post_title; $o['filesize'] = @size_format(filesize(get_attached_file($file->ID))); $o['url'] = wp_get_attachment_url($file->ID); $explode = explode('/', $o['url']); $o['filename'] = end($explode); } // url exists if ($o['url']) { $div['class'] .= ' has-value'; } } ?> <div <?php acf_esc_attr_e($div); ?> > <div class="acf-hidden"> <?php acf_hidden_input(array('name' => $field['name'], 'value' => $field['value'], 'data-name' => 'id')); ?> </div> <div class="show-if-value file-wrap acf-soh"> <div class="file-icon"> <img data-name="icon" src="<?php echo $o['icon']; ?> " alt=""/> </div> <div class="file-info"> <p> <strong data-name="title"><?php echo $o['title']; ?> </strong> </p> <p> <strong><?php _e('File name', 'acf'); ?> :</strong> <a data-name="filename" href="<?php echo $o['url']; ?> " target="_blank"><?php echo $o['filename']; ?> </a> </p> <p> <strong><?php _e('File size', 'acf'); ?> :</strong> <span data-name="filesize"><?php echo $o['filesize']; ?> </span> </p> <ul class="acf-hl acf-soh-target"> <?php if ($uploader != 'basic') { ?> <li><a class="acf-icon -pencil dark" data-name="edit" href="#"></a></li> <?php } ?> <li><a class="acf-icon -cancel dark" data-name="remove" href="#"></a></li> </ul> </div> </div> <div class="hide-if-value"> <?php if ($uploader == 'basic') { ?> <?php if ($field['value'] && !is_numeric($field['value'])) { ?> <div class="acf-error-message"><p><?php echo $field['value']; ?> </p></div> <?php } ?> <input type="file" name="<?php echo $field['name']; ?> " id="<?php echo $field['id']; ?> " /> <?php } else { ?> <p style="margin:0;"><?php _e('No file selected', 'acf'); ?> <a data-name="add" class="acf-button button" href="#"><?php _e('Add File', 'acf'); ?> </a></p> <?php } ?> </div> </div> <?php }
function get_term_title($term, $field, $post_id = 0) { // get post_id if (!$post_id) { $form_data = acf_get_setting('form_data'); if (!empty($form_data['post_id'])) { $post_id = $form_data['post_id']; } else { $post_id = get_the_ID(); } } // vars $title = ''; // ancestors $ancestors = get_ancestors($term->term_id, $field['taxonomy']); if (!empty($ancestors)) { $title .= str_repeat('- ', count($ancestors)); } // title $title .= $term->name; // filters $title = apply_filters('acf/fields/taxonomy/result', $title, $term, $field, $post_id); $title = apply_filters('acf/fields/taxonomy/result/name=' . $field['_name'], $title, $term, $field, $post_id); $title = apply_filters('acf/fields/taxonomy/result/key=' . $field['key'], $title, $term, $field, $post_id); // return return $title; }
function settings_export_translate($setting) { // 5.3.3 - changed filter name return acf_get_setting('export_translate', $setting); }
function get_result($user, $field, $post_id = 0) { // get post_id if (!$post_id) { $post_id = acf_get_setting('form_data/post_id', get_the_ID()); } // vars $result = $user->user_login; // append name if ($user->first_name) { $result .= ' (' . $user->first_name; if ($user->last_name) { $result .= ' ' . $user->last_name; } $result .= ')'; } // filters $result = apply_filters("acf/fields/user/result", $result, $user, $field, $post_id); $result = apply_filters("acf/fields/user/result/name={$field['_name']}", $result, $user, $field, $post_id); $result = apply_filters("acf/fields/user/result/key={$field['key']}", $result, $user, $field, $post_id); // return return $result; }
function acf_duplicate_field($selector = 0, $new_parent = 0) { // disable filters to ensure ACF loads raw data from DB acf_disable_filters(); // load the origional field $field = acf_get_field($selector); // bail early if field did not load correctly if (empty($field)) { return false; } // update ID $field['ID'] = false; // try duplicate keys $field['key'] = acf_get_setting('duplicate_key_' . $field['key']); // default key if (empty($field['key'])) { $field['key'] = uniqid('field_'); } // update parent if ($new_parent) { $field['parent'] = $new_parent; } // update conditional logic references (because field keys have changed) if (!empty($field['conditional_logic'])) { // extract groups $groups = acf_extract_var($field, 'conditional_logic'); // loop over groups foreach (array_keys($groups) as $g) { // extract group $group = acf_extract_var($groups, $g); // bail early if empty if (empty($group)) { continue; } // loop over rules foreach (array_keys($group) as $r) { // extract rule $rule = acf_extract_var($group, $r); // vars $new_key = acf_get_setting('duplicate_key_' . $rule['field']); // update rule with new key if ($new_key) { $rule['field'] = $new_key; } // append to group $group[$r] = $rule; } // append to groups $groups[$g] = $group; } // update conditional logic $field['conditional_logic'] = $groups; } // filter for 3rd party customization $field = apply_filters("acf/duplicate_field", $field); $field = apply_filters("acf/duplicate_field/type={$field['type']}", $field); // save return acf_update_field($field); }
function _acf_settings_slug($v) { $basename = acf_get_setting('basename'); $slug = explode('/', $basename); $slug = current($slug); return $slug; }
function wp_init() { // complete loading of ACF files $this->complete(); // vars $cap = acf_get_setting('capability'); // Create post type 'acf-field-group' register_post_type('acf-field-group', array('labels' => array('name' => __('Field Groups', 'acf'), 'singular_name' => __('Field Group', 'acf'), 'add_new' => __('Add New', 'acf'), 'add_new_item' => __('Add New Field Group', 'acf'), 'edit_item' => __('Edit Field Group', 'acf'), 'new_item' => __('New Field Group', 'acf'), 'view_item' => __('View Field Group', 'acf'), 'search_items' => __('Search Field Groups', 'acf'), 'not_found' => __('No Field Groups found', 'acf'), 'not_found_in_trash' => __('No Field Groups found in Trash', 'acf')), 'public' => false, 'show_ui' => true, '_builtin' => false, 'capability_type' => 'post', 'capabilities' => array('edit_post' => $cap, 'delete_post' => $cap, 'edit_posts' => $cap, 'delete_posts' => $cap), 'hierarchical' => true, 'rewrite' => false, 'query_var' => false, 'supports' => array('title'), 'show_in_menu' => false)); // Create post type 'acf-field' register_post_type('acf-field', array('labels' => array('name' => __('Fields', 'acf'), 'singular_name' => __('Field', 'acf'), 'add_new' => __('Add New', 'acf'), 'add_new_item' => __('Add New Field', 'acf'), 'edit_item' => __('Edit Field', 'acf'), 'new_item' => __('New Field', 'acf'), 'view_item' => __('View Field', 'acf'), 'search_items' => __('Search Fields', 'acf'), 'not_found' => __('No Fields found', 'acf'), 'not_found_in_trash' => __('No Fields found in Trash', 'acf')), 'public' => false, 'show_ui' => false, '_builtin' => false, 'capability_type' => 'post', 'capabilities' => array('edit_post' => $cap, 'delete_post' => $cap, 'edit_posts' => $cap, 'delete_posts' => $cap), 'hierarchical' => true, 'rewrite' => false, 'query_var' => false, 'supports' => array('title'), 'show_in_menu' => false)); // min $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; // register scripts $scripts = array(array('handle' => 'select2', 'src' => acf_get_dir("assets/inc/select2/select2{$min}.js"), 'deps' => array('jquery')), array('handle' => 'acf-input', 'src' => acf_get_dir("assets/js/acf-input{$min}.js"), 'deps' => array('jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-resizable', 'jquery-ui-datepicker', 'wp-color-picker', 'select2')), array('handle' => 'acf-field-group', 'src' => acf_get_dir("assets/js/acf-field-group{$min}.js"), 'deps' => array('acf-input'))); foreach ($scripts as $script) { wp_register_script($script['handle'], $script['src'], $script['deps'], acf_get_setting('version')); } // register styles $styles = array(array('handle' => 'select2', 'src' => acf_get_dir('assets/inc/select2/select2.css'), 'deps' => false), array('handle' => 'acf-datepicker', 'src' => acf_get_dir('assets/inc/datepicker/jquery-ui-1.10.4.custom.min.css'), 'deps' => false), array('handle' => 'acf-global', 'src' => acf_get_dir('assets/css/acf-global.css'), 'deps' => false), array('handle' => 'acf-input', 'src' => acf_get_dir('assets/css/acf-input.css'), 'deps' => array('acf-global', 'wp-color-picker', 'select2', 'acf-datepicker')), array('handle' => 'acf-field-group', 'src' => acf_get_dir('assets/css/acf-field-group.css'), 'deps' => array('acf-input'))); foreach ($styles as $style) { wp_register_style($style['handle'], $style['src'], $style['deps'], acf_get_setting('version')); } }