/** * Check if plugin dependencies are satisfied and add an admin notice if not * * @return bool */ public static function is_dependency_satisfied() { if (class_exists('acf') && version_compare(acf()->settings['version'], self::PLUGIN_MIN_VERSION, '>=')) { return true; } return false; }
/** * 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 acf_append_setting($name, $value) { // createa array if needed if (!isset(acf()->settings[$name])) { acf()->settings[$name] = array(); } // append to array acf()->settings[$name][] = $value; }
function __construct() { $this->acf_version = acf()->settings['version']; if (version_compare($this->acf_version, '4.0', '>=')) { add_filter('facetwp_facet_sources', array($this, 'facet_sources')); add_filter('facetwp_indexer_post_facet', array($this, 'indexer_post_facet'), 1, 2); add_filter('facetwp_acf_display_value', array($this, 'index_source_other'), 1, 2); } }
function acf_repeater_collapser_acf5_compat() { if (!class_exists('acf')) { return; } $acf_version = acf()->settings['version']; if (version_compare($acf_version, '5.0', '>=')) { add_filter('acf/compatibility/field_wrapper_class', '__return_true'); } }
function acf_check_404() { if (function_exists('acf')) { $acf = acf(); } // not set or < v5 of ACF if (!isset($acf) || version_compare($acf->settings['version'], '5.0', '<')) { add_action('admin_notices', 'acf_404'); add_action('network_admin_notices', 'acf_404'); } }
/** * Check if plugin dependencies are satisfied and add an admin notice if not * * @return bool */ public function is_dependency_satisfied() { if (class_exists('acf')) { //TODO: Should this be function_exists? $acf = \acf(); if (version_compare($acf->settings['version'], self::PLUGIN_MIN_VERSION, '>=')) { return true; } } return false; }
function acf_repeater_collapser_assets() { $acf_version = acf()->settings['version']; if (version_compare($acf_version, '4.0', '>=') && version_compare($acf_version, '5.0', '<')) { // version 4.X wp_enqueue_script('acf_repeater_collapser_admin_js', esc_url(plugins_url('js/acf4_repeater_collapser_admin.js', __FILE__)), array('jquery'), ACF_REPEATER_COLLAPSER_VERSION); wp_enqueue_style('acf_repeater_collapser_admin_css', esc_url(plugins_url('css/acf4_repeater_collapser_admin.css', __FILE__)), false, ACF_REPEATER_COLLAPSER_VERSION); } elseif (version_compare($acf_version, '5.0', '>=')) { // version 5.X wp_enqueue_script('acf_repeater_collapser_admin_js', esc_url(plugins_url('js/acf5_repeater_collapser_admin.js', __FILE__)), array('jquery'), ACF_REPEATER_COLLAPSER_VERSION); wp_enqueue_style('acf_repeater_collapser_admin_css', esc_url(plugins_url('css/acf5_repeater_collapser_admin.css', __FILE__)), false, ACF_REPEATER_COLLAPSER_VERSION); } }
function get_field_object($selector, $post_id = false, $format_value = true, $load_value = true) { // complete loading acf()->complete(); // compatibilty if (is_array($format_value)) { extract($format_value); } // vars $field_name = false; // get valid post_id $post_id = acf_get_valid_post_id($post_id); // load field reference if not a field_key if (!acf_is_field_key($selector)) { // save selector as field_name (could be sub field name) $field_name = $selector; // get reference $selector = acf_get_field_reference($selector, $post_id); // bail early if no reference for this field if (!$selector) { return false; } } // get field key $field = acf_get_field($selector); // bail early if no field found if (!$field) { return false; } // Override name - allows the $selector to be a sub field (images_0_image) if ($field_name) { $field['name'] = $field_name; } // load value if ($load_value) { $field['value'] = acf_get_value($post_id, $field); } // format value if ($format_value) { // get value for field $field['value'] = acf_format_value($field['value'], $post_id, $field); } // return return $field; }
function acf_set_form_data($data = array()) { return acf()->input->set_data($data); }
function acf_update_setting($name, $value) { return acf()->update_setting($name, $value); }
function get_field_object($selector, $post_id = false, $format_value = true, $load_value = true) { // complete loading acf()->complete(); // compatibilty if (is_array($format_value)) { $format_value = acf_parse_args($format_value, array('format_value' => true, 'load_value' => true)); extract($format_value); } // vars $override_name = false; // filter post_id $post_id = acf_get_valid_post_id($post_id); // load field reference if not a field_key if (!acf_is_field_key($selector)) { $override_name = $selector; $reference = acf_get_field_reference($selector, $post_id); if ($reference) { $selector = $reference; } } // get field key $field = acf_get_field($selector); // bail early if no field found if (!$field) { return false; } // override name? // This allows the $selector to be a sub field (images_0_image) if ($override_name) { $field['name'] = $override_name; } // load value if ($load_value) { $field['value'] = acf_get_value($post_id, $field); } // format value if ($format_value) { // get value for field $field['value'] = acf_format_value($field['value'], $post_id, $field); } // return return $field; }
function acf_local() { return acf()->local; }
function acf_remove_loop($i = 'active') { return acf()->loop->remove_loop($i); }
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; }
function acf_delete_cache($key = '') { return acf()->cache->delete_cache($key); }
function wp_restore_post_revision($post_id, $revision_id) { // copy postmeta from revision to post (restore from revision) acf_copy_postmeta($revision_id, $post_id); // Make sure the latest revision is also updated to match the new $post data // get latest revision $revision = acf_get_post_latest_revision($post_id); // save if ($revision) { // copy postmeta from revision to latest revision (potentialy may be the same, but most likely are different) acf_copy_postmeta($revision_id, $revision->ID); } } } // initialize acf()->revisions = new acf_revisions(); } // class_exists check /* * acf_save_post_revision * * This function will copy meta from a post to it's latest revision * * @type function * @date 26/09/2016 * @since 5.4.0 * * @param $post_id (int) * @return n/a */ function acf_save_post_revision($post_id = 0)
function acf_form($args = array()) { acf()->template_form->render_form($args); }
/** * Return the major version number for Advanced Custom Fields. * @return int */ public function acf_major_version() { return (int) acf()->settings['version'][0]; }
function acf_validate_value($value, $field, $input) { return acf()->validation->validate_value($value, $field, $input); }
{ // vars $message = ''; $info = acf_get_remote_plugin_info(); // check for upgrade notice if ($info['upgrade_notice']) { $message = '<div class="acf-plugin-upgrade-notice">' . $info['upgrade_notice'] . '</div>'; } // filter $message = apply_filters('acf/updates/plugin_update_message', $message, $plugin_data, $r); // return echo $message; } } // initialize acf()->updates = new acf_updates(); } // class_exists check /* * acf_get_remote_plugin_info * * This function will return an array of data from the plugin's readme.txt file (remote) * * @type function * @date 8/06/2016 * @since 5.3.9 * * @param n/a * @return (array) */ function acf_get_remote_plugin_info()
function get_field_object($field_key, $post_id = false, $options = array()) { // make sure add-ons are included acf()->include_3rd_party(); // filter post_id $post_id = apply_filters('acf/get_post_id', $post_id); $field = false; $orig_field_key = $field_key; // defaults for options $defaults = array('load_value' => true, 'format_value' => true); $options = array_merge($defaults, $options); // is $field_name a name? pre 3.4.0 if (substr($field_key, 0, 6) !== 'field_') { // get field key $field_key = get_field_reference($field_key, $post_id); } // get field if (substr($field_key, 0, 6) === 'field_') { $field = apply_filters('acf/load_field', false, $field_key); } // validate field if (!$field) { // treat as text field $field = array('type' => 'text', 'name' => $orig_field_key, 'key' => 'field_' . $orig_field_key); $field = apply_filters('acf/load_field', $field, $field['key']); } // load value if ($options['load_value']) { $field['value'] = apply_filters('acf/load_value', false, $post_id, $field); // format value if ($options['format_value']) { $field['value'] = apply_filters('acf/format_value_for_api', $field['value'], $post_id, $field); } } return $field; }
function acf_get_admin_notices() { return acf()->admin->get_notices(); }
return $where; } } /* * acf * * The main function responsible for returning the one true acf Instance to functions everywhere. * Use this function like you would a global variable, except without needing to declare the global. * * Example: <?php $acf = acf(); ?> * * @type function * @date 4/09/13 * @since 4.3.0 * * @param N/A * @return (object) */ function acf() { global $acf; if (!isset($acf)) { $acf = new acf(); $acf->initialize(); } return $acf; } // initialize acf(); } // class_exists check
function acf_refresh_plugin_updates_transient() { // vars $transient = get_site_transient('update_plugins'); // bail early if no transient if (empty($transient)) { return; } // update transient $transient = acf()->updates->modify_plugin_update($transient); // update set_site_transient('update_plugins', $transient); }
function acf_maybe_get_field($selector, $post_id = false, $strict = true) { // complete init // this function may be used in a theme file before the init action has been run acf()->init(); // vars $field_name = false; // get valid post_id $post_id = acf_get_valid_post_id($post_id); // load field reference if not a field_key if (!acf_is_field_key($selector)) { // save selector as field_name (could be sub field name) $field_name = $selector; // get reference $field_key = acf_get_field_reference($selector, $post_id); if ($field_key) { $selector = $field_key; } elseif ($strict) { return false; } } // get field key $field = acf_get_field($selector); // bail early if no field if (!$field) { return false; } // Override name - allows the $selector to be a sub field (images_0_image) if ($field_name) { $field['name'] = $field_name; } // return return $field; }
function acf_get_field_type($name) { return acf()->fields->get_field_type($name); }