<?php
if( !class_exists('acf') ):
class acf
{
var $settings;
function __construct()
{
add_filter('acf/helpers/get_path', array($this, 'helpers_get_path'), 1, 1);
add_filter('acf/helpers/get_dir', array($this, 'helpers_get_dir'), 1, 1);
$this->settings = array(
'path' => apply_filters('acf/helpers/get_path', __FILE__),
'dir' => apply_filters('acf/helpers/get_dir', __FILE__),
'hook' => basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ),
'version' => '4.4.9',
'upgrade_version' => '3.4.1',
'include_3rd_party' => false
);
load_textdomain('acf', $this->settings['path'] . 'lang/acf-' . get_locale() . '.mo');
add_action('init', array($this, 'init'), 1);
add_action('acf/pre_save_post', array($this, 'save_post_lock'), 0);
add_action('acf/pre_save_post', array($this, 'save_post_unlock'), 999);
add_action('acf/save_post', array($this, 'save_post_lock'), 0);
add_action('acf/save_post', array($this, 'save_post'), 10);
add_action('acf/save_post', array($this, 'save_post_unlock'), 999);
add_action('acf/create_fields', array($this, 'create_fields'), 1, 2);
add_filter('acf/get_info', array($this, 'get_info'), 1, 1);
add_filter('acf/parse_types', array($this, 'parse_types'), 1, 1);
add_filter('acf/get_post_types', array($this, 'get_post_types'), 1, 3);
add_filter('acf/get_taxonomies_for_select', array($this, 'get_taxonomies_for_select'), 1, 2);
add_filter('acf/get_image_sizes', array($this, 'get_image_sizes'), 1, 1);
add_filter('acf/get_post_id', array($this, 'get_post_id'), 1, 1);
$this->include_before_theme();
add_action('after_setup_theme', array($this, 'include_after_theme'), 1);
add_action('after_setup_theme', array($this, 'include_3rd_party'), 1);
}
function helpers_get_path( $file )
{
return trailingslashit(dirname($file));
}
function helpers_get_dir( $file )
{
$dir = trailingslashit(dirname($file));
$count = 0;
$dir = str_replace('\\' , '/', $dir);
$wp_plugin_dir = str_replace('\\' , '/', WP_PLUGIN_DIR);
$dir = str_replace($wp_plugin_dir, plugins_url(), $dir, $count);
if( $count < 1 )
{
$wp_content_dir = str_replace('\\' , '/', WP_CONTENT_DIR);
$dir = str_replace($wp_content_dir, content_url(), $dir, $count);
}
if( $count < 1 )
{
$wp_dir = str_replace('\\' , '/', ABSPATH);
$dir = str_replace($wp_dir, site_url('/'), $dir);
}
return $dir;
}
function get_post_id( $post_id ) {
if( !$post_id ) {
$post_id = (int) get_the_ID();
if( !$post_id ) {
$post_id = get_queried_object();
}
}
if( is_object($post_id) ) {
if( isset($post_id->roles, $post_id->ID) ) {
$post_id = 'user_' . $post_id->ID;
} elseif( isset($post_id->taxonomy, $post_id->term_id) ) {
$post_id = $post_id->taxonomy . '_' . $post_id->term_id;
} elseif( isset($post_id->comment_ID) ) {
$post_id = 'comment_' . $post_id->comment_ID;
} elseif( isset($post_id->ID) ) {
$post_id = $post_id->ID;
} else {
$post_id = 0;
}
}
if( $post_id === 'option' ) {
$post_id = 'options';
}
if( isset($_GET['preview_id']) ) {
$autosave = wp_get_post_autosave( $_GET['preview_id'] );
if( $autosave && $autosave->post_parent == $post_id ) {
$post_id = (int) $autosave->ID;
}
}
return $post_id;
}
function get_info( $i )
{
$return = false;
if( isset($this->settings[ $i ]) )
{
$return = $this->settings[ $i ];
}
if( $i == 'all' )
{
$return = $this->settings;
}
return $return;
}
function parse_types( $value )
{
$restricted = array(
'label',
'name',
'_name',
'value',
'instructions'
);
if( is_array($value) )
{
foreach( $value as $k => $v )
{
if( in_array($k, $restricted, true) )
{
continue;
}
$value[ $k ] = apply_filters( 'acf/parse_types', $v );
}
}
else
{
if( is_string($value) )
{
$value = trim( $value );
}
if( is_numeric($value) )
{
if( preg_match('/[^0-9]/', $value) )
{
}
else
{
$value = intval( $value );
}
}
}
return $value;
}
function include_before_theme()
{
include_once('core/api.php');
include_once('core/controllers/input.php');
include_once('core/controllers/location.php');
include_once('core/controllers/field_group.php');
if( is_admin() )
{
include_once('core/controllers/post.php');
include_once('core/controllers/revisions.php');
include_once('core/controllers/everything_fields.php');
include_once('core/controllers/field_groups.php');
}
include_once('core/fields/_functions.php');
include_once('core/fields/_base.php');
include_once('core/fields/text.php');
include_once('core/fields/textarea.php');
include_once('core/fields/number.php');
include_once('core/fields/email.php');
include_once('core/fields/password.php');
include_once('core/fields/wysiwyg.php');
include_once('core/fields/image.php');
include_once('core/fields/file.php');
include_once('core/fields/select.php');
include_once('core/fields/checkbox.php');
include_once('core/fields/radio.php');
include_once('core/fields/true_false.php');
include_once('core/fields/page_link.php');
include_once('core/fields/post_object.php');
include_once('core/fields/relationship.php');
include_once('core/fields/taxonomy.php');
include_once('core/fields/user.php');
include_once('core/fields/google-map.php');
include_once('core/fields/date_picker/date_picker.php');
include_once('core/fields/color_picker.php');
include_once('core/fields/message.php');
include_once('core/fields/tab.php');
}
function include_3rd_party() {
if( $this->settings['include_3rd_party'] )
{
return false;
}
$this->settings['include_3rd_party'] = true;
do_action('acf/register_fields');
}
function include_after_theme() {
if( defined('ACF_LITE') && ACF_LITE )
{
return;
}
if( is_admin() )
{
include_once('core/controllers/export.php');
include_once('core/controllers/addons.php');
include_once('core/controllers/third_party.php');
include_once('core/controllers/upgrade.php');
}
}
function init()
{
$labels = array(
'name' => __( 'Field Groups', 'acf' ),
'singular_name' => __( 'Advanced Custom Fields', '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'),
);
register_post_type('acf', array(
'labels' => $labels,
'public' => false,
'show_ui' => true,
'_builtin' => false,
'capability_type' => 'page',
'hierarchical' => true,
'rewrite' => false,
'query_var' => "acf",
'supports' => array(
'title',
),
'show_in_menu' => false,
));
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$scripts = array();
$scripts[] = array(
'handle' => 'acf-field-group',
'src' => $this->settings['dir'] . "js/field-group{$min}.js",
'deps' => array('jquery')
);
$scripts[] = array(
'handle' => 'acf-input',
'src' => $this->settings['dir'] . "js/input{$min}.js",
'deps' => array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker')
);
foreach( $scripts as $script )
{
wp_register_script( $script['handle'], $script['src'], $script['deps'], $this->settings['version'] );
}
$styles = array(
'acf' => $this->settings['dir'] . 'css/acf.css',
'acf-field-group' => $this->settings['dir'] . 'css/field-group.css',
'acf-global' => $this->settings['dir'] . 'css/global.css',
'acf-input' => $this->settings['dir'] . 'css/input.css',
'acf-datepicker' => $this->settings['dir'] . 'core/fields/date_picker/style.date_picker.css',
);
foreach( $styles as $k => $v )
{
wp_register_style( $k, $v, false, $this->settings['version'] );
}
if( defined('ACF_LITE') && ACF_LITE )
{
return;
}
if( is_admin() )
{
add_action('admin_menu', array($this, 'admin_menu'));
add_action('admin_head', array($this, 'admin_head'));
add_filter('post_updated_messages', array($this, 'post_updated_messages'));
}
}
function admin_menu()
{
add_menu_page(__("Custom Fields", 'acf'), __("Custom Fields", 'acf'), 'manage_options', 'edit.php?post_type=acf', false, false, '80.025');
}
function post_updated_messages( $messages )
{
global $post, $post_ID;
$messages['acf'] = array(
0 => '',
1 => __('Field group updated.', 'acf'),
2 => __('Custom field updated.', 'acf'),
3 => __('Custom field deleted.', 'acf'),
4 => __('Field group updated.', 'acf'),
5 => isset($_GET['revision']) ? sprintf( __('Field group restored to revision from %s', 'acf'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
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 $messages;
}
function admin_head()
{
?>
<style type="text/css">
#adminmenu #toplevel_page_edit-post_type-acf a[href="edit.php?post_type=acf&page=acf-upgrade"]{ display: none; }
#adminmenu #toplevel_page_edit-post_type-acf .wp-menu-image { background-position: 1px -33px; }
#adminmenu #toplevel_page_edit-post_type-acf:hover .wp-menu-image,
#adminmenu #toplevel_page_edit-post_type-acf.wp-menu-open .wp-menu-image { background-position: 1px -1px; }
</style>
<?php
}
function get_taxonomies_for_select( $choices, $simple_value = false )
{
$post_types = get_post_types();
if($post_types)
{
foreach($post_types as $post_type)
{
$post_type_object = get_post_type_object($post_type);
$taxonomies = get_object_taxonomies($post_type);
if($taxonomies)
{
foreach($taxonomies as $taxonomy)
{
if(!is_taxonomy_hierarchical($taxonomy)) continue;
$terms = get_terms($taxonomy, array('hide_empty' => false));
if($terms)
{
foreach($terms as $term)
{
$value = $taxonomy . ':' . $term->term_id;
if( $simple_value )
{
$value = $term->term_id;
}
$choices[$post_type_object->label . ': ' . $taxonomy][$value] = $term->name;
}
}
}
}
}
}
return $choices;
}
function get_post_types( $post_types, $exclude = array(), $include = array() )
{
$post_types = array_merge($post_types, get_post_types());
$acf_includes = array_merge( array(), $include );
$acf_excludes = array_merge( array( 'acf', 'revision', 'nav_menu_item' ), $exclude );
foreach( $acf_includes as $p )
{
if( post_type_exists($p) )
{
$post_types[ $p ] = $p;
}
}
foreach( $acf_excludes as $p )
{
unset( $post_types[ $p ] );
}
return $post_types;
}
function get_image_sizes( $sizes )
{
$all_sizes = get_intermediate_image_sizes();
$sizes = array_merge($sizes, array(
'thumbnail' => __("Thumbnail", 'acf'),
'medium' => __("Medium", 'acf'),
'large' => __("Large", 'acf'),
'full' => __("Full", 'acf')
));
foreach( $all_sizes as $size )
{
if( !isset($sizes[ $size ]) )
{
$sizes[ $size ] = ucwords( str_replace('-', ' ', $size) );
}
}
array
return $sizes;
}
function create_fields( $fields, $post_id )
{
if( is_array($fields) ) { foreach( $fields as $field ) {
if( !$field || !$field['type'] || $field['type'] == 'null' )
{
continue;
}
if( !isset($field['value']) )
{
$field['value'] = apply_filters('acf/load_value', false, $post_id, $field);
$field['value'] = apply_filters('acf/format_value', $field['value'], $post_id, $field);
}
$required_class = "";
$required_label = "";
if( $field['required'] )
{
$required_class = ' required';
$required_label = ' <span class="required">*</span>';
}
echo '<div id="acf-' . $field['name'] . '" class="field field_type-' . $field['type'] . ' field_key-' . $field['key'] . $required_class . '" data-field_name="' . $field['name'] . '" data-field_key="' . $field['key'] . '" data-field_type="' . $field['type'] . '">';
echo '<p class="label">';
echo '<label for="' . $field['id'] . '">' . $field['label'] . $required_label . '</label>';
echo $field['instructions'];
echo '</p>';
$field['name'] = 'fields[' . $field['key'] . ']';
do_action('acf/create_field', $field, $post_id);
echo '</div>';
}}
}
function save_post_lock( $post_id )
{
$GLOBALS['acf_save_lock'] = $post_id;
return $post_id;
}
function save_post_unlock( $post_id )
{
$GLOBALS['acf_save_lock'] = false;
return $post_id;
}
function save_post( $post_id )
{
if( !isset($_POST['fields']) )
{
return $post_id;
}
if( !empty($_POST['fields']) )
{
$_POST data
foreach( $_POST['fields'] as $k => $v )
{
$f = apply_filters('acf/load_field', false, $k );
do_action('acf/update_value', $v, $post_id, $f );
}
}
return $post_id;
}
}
function acf()
{
global $acf;
if( !isset($acf) )
{
$acf = new acf();
}
return $acf;
}
acf();
endif;
?>