Esempio n. 1
0
 function render_location_value($options)
 {
     // vars
     $options = wp_parse_args($options, array('group_id' => 0, 'rule_id' => 0, 'value' => null, 'param' => null));
     // vars
     $choices = array();
     // some case's have the same outcome
     if ($options['param'] == "page_parent") {
         $options['param'] = "page";
     }
     switch ($options['param']) {
         /*
          *  Basic
          */
         case "post_type":
             // all post types except attachment
             $exclude = array('attachment');
             $choices = acf_get_post_types($exclude);
             $choices = acf_get_pretty_post_types($choices);
             break;
         case "user_type":
             global $wp_roles;
             $choices = $wp_roles->get_names();
             if (is_multisite()) {
                 $choices['super_admin'] = __('Super Admin');
             }
             break;
             /*
              *  Post
              */
         /*
          *  Post
          */
         case "post":
             // get post types
             $exclude = array('page', 'attachment');
             $post_types = acf_get_post_types($exclude);
             // get posts grouped by post type
             $groups = acf_get_posts(array('post_type' => $post_types));
             if (!empty($groups)) {
                 foreach (array_keys($groups) as $group_title) {
                     // vars
                     $posts = acf_extract_var($groups, $group_title);
                     // override post data
                     foreach (array_keys($posts) as $post_id) {
                         // update
                         $posts[$post_id] = acf_get_post_title($posts[$post_id]);
                     }
                     // append to $choices
                     $choices[$group_title] = $posts;
                 }
             }
             break;
         case "post_category":
             $terms = acf_get_taxonomy_terms('category');
             if (!empty($terms)) {
                 $choices = array_pop($terms);
             }
             break;
         case "post_format":
             $choices = get_post_format_strings();
             break;
         case "post_status":
             $choices = array('publish' => __('Publish', 'acf'), 'pending' => __('Pending Review', 'acf'), 'draft' => __('Draft', 'acf'), 'future' => __('Future', 'acf'), 'private' => __('Private', 'acf'), 'inherit' => __('Revision', 'acf'), 'trash' => __('Trash', 'acf'));
             break;
         case "post_taxonomy":
             $choices = acf_get_taxonomy_terms();
             // unset post_format
             if (isset($choices['post_format'])) {
                 unset($choices['post_format']);
             }
             break;
             /*
              *  Page
              */
         /*
          *  Page
          */
         case "page":
             // get posts grouped by post type
             $groups = acf_get_posts(array('post_type' => 'page'));
             if (!empty($groups)) {
                 foreach (array_keys($groups) as $group_title) {
                     // vars
                     $posts = acf_extract_var($groups, $group_title);
                     // override post data
                     foreach (array_keys($posts) as $post_id) {
                         // update
                         $posts[$post_id] = acf_get_post_title($posts[$post_id]);
                     }
                     // append to $choices
                     $choices = $posts;
                 }
             }
             break;
         case "page_type":
             $choices = array('front_page' => __("Front Page", 'acf'), 'posts_page' => __("Posts Page", 'acf'), 'top_level' => __("Top Level Page (parent of 0)", 'acf'), 'parent' => __("Parent Page (has children)", 'acf'), 'child' => __("Child Page (has parent)", 'acf'));
             break;
         case "page_parent":
             // refer to "page"
             break;
         case "page_template":
             $choices = array('default' => __("Default Template", 'acf'));
             $templates = get_page_templates();
             foreach ($templates as $k => $v) {
                 $choices[$v] = $k;
             }
             break;
             /*
              *  User
              */
         /*
          *  User
          */
         case "user_role":
             global $wp_roles;
             $choices = array_merge(array('all' => __('All', 'acf')), $wp_roles->get_names());
             break;
         case "user_form":
             $choices = array('all' => __('All', 'acf'), 'edit' => __('Add / Edit', 'acf'), 'register' => __('Register', 'acf'));
             break;
             /*
              *  Forms
              */
         /*
          *  Forms
          */
         case "attachment":
             $choices = array('all' => __('All', 'acf'));
             break;
         case "taxonomy":
             $choices = array_merge(array('all' => __('All', 'acf')), acf_get_taxonomies());
             // unset post_format
             if (isset($choices['post_format'])) {
                 unset($choices['post_format']);
             }
             break;
         case "comment":
             $choices = array('all' => __('All', 'acf'));
             break;
         case "widget":
             global $wp_widget_factory;
             $choices = array('all' => __('All', 'acf'));
             if (!empty($wp_widget_factory->widgets)) {
                 foreach ($wp_widget_factory->widgets as $widget) {
                     $choices[$widget->id_base] = $widget->name;
                 }
             }
             break;
     }
     // allow custom location rules
     $choices = apply_filters('acf/location/rule_values/' . $options['param'], $choices);
     // create field
     acf_render_field(array('type' => 'select', 'prefix' => "acf_field_group[location][{$options['group_id']}][{$options['rule_id']}]", 'name' => 'value', 'value' => $options['value'], 'choices' => $choices));
 }
Esempio n. 2
0
 function render_field_settings($field)
 {
     // vars
     $field['min'] = empty($field['min']) ? '' : $field['min'];
     $field['max'] = empty($field['max']) ? '' : $field['max'];
     // post_type
     acf_render_field_setting($field, array('label' => __('Filter by Post Type', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'post_type', 'choices' => acf_get_pretty_post_types(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All post types", 'acf')));
     // taxonomy
     acf_render_field_setting($field, array('label' => __('Filter by Taxonomy', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'taxonomy', 'choices' => acf_get_taxonomy_terms(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All taxonomies", 'acf')));
     // filters
     acf_render_field_setting($field, array('label' => __('Filters', 'acf'), 'instructions' => '', 'type' => 'checkbox', 'name' => 'filters', 'choices' => array('search' => __("Search", 'acf'), 'post_type' => __("Post Type", 'acf'), 'taxonomy' => __("Taxonomy", 'acf'))));
     // filters
     acf_render_field_setting($field, array('label' => __('Elements', 'acf'), 'instructions' => __('Selected elements will be displayed in each result', 'acf'), 'type' => 'checkbox', 'name' => 'elements', 'choices' => array('featured_image' => __("Featured Image", 'acf'))));
     // min
     acf_render_field_setting($field, array('label' => __('Minimum posts', 'acf'), 'instructions' => '', 'type' => 'number', 'name' => 'min'));
     // max
     acf_render_field_setting($field, array('label' => __('Maximum posts', 'acf'), 'instructions' => '', 'type' => 'number', 'name' => 'max'));
     // return_format
     acf_render_field_setting($field, array('label' => __('Return Format', 'acf'), 'instructions' => '', 'type' => 'radio', 'name' => 'return_format', 'choices' => array('object' => __("Post Object", 'acf'), 'id' => __("Post ID", 'acf')), 'layout' => 'horizontal'));
 }
Esempio n. 3
0
function acf_get_grouped_posts($args)
{
    // vars
    $r = array();
    // defaults
    $args = acf_parse_args($args, array('posts_per_page' => -1, 'paged' => 0, 'post_type' => 'post', 'orderby' => 'menu_order title', 'order' => 'ASC', 'post_status' => 'any', 'suppress_filters' => false, 'update_post_meta_cache' => false));
    // find array of post_type
    $post_types = acf_force_type_array($args['post_type']);
    $post_types_labels = acf_get_pretty_post_types($post_types);
    // attachment doesn't work if it is the only item in an array
    if (count($post_types) == 1) {
        $args['post_type'] = current($post_types);
    }
    // add filter to orderby post type
    add_filter('posts_orderby', '_acf_orderby_post_type', 10, 2);
    // get posts
    $posts = get_posts($args);
    // loop
    foreach ($post_types as $post_type) {
        // vars
        $this_posts = array();
        $this_group = array();
        // populate $this_posts
        foreach (array_keys($posts) as $key) {
            if ($posts[$key]->post_type == $post_type) {
                $this_posts[] = acf_extract_var($posts, $key);
            }
        }
        // bail early if no posts for this post type
        if (empty($this_posts)) {
            continue;
        }
        // sort into hierachial order!
        // this will fail if a search has taken place because parents wont exist
        if (is_post_type_hierarchical($post_type) && empty($args['s'])) {
            // vars
            $match_id = $this_posts[0]->ID;
            $offset = 0;
            $length = count($this_posts);
            $parent = acf_maybe_get($args, 'post_parent', 0);
            // reset $this_posts
            $this_posts = array();
            // get all posts
            $all_args = array_merge($args, array('posts_per_page' => -1, 'paged' => 0, 'post_type' => $post_type));
            $all_posts = get_posts($all_args);
            // loop over posts and find $i
            foreach ($all_posts as $offset => $p) {
                if ($p->ID == $match_id) {
                    break;
                }
            }
            // order posts
            $all_posts = get_page_children($parent, $all_posts);
            for ($i = $offset; $i < $offset + $length; $i++) {
                $this_posts[] = acf_extract_var($all_posts, $i);
            }
        }
        // populate $this_posts
        foreach (array_keys($this_posts) as $key) {
            // extract post
            $post = acf_extract_var($this_posts, $key);
            // add to group
            $this_group[$post->ID] = $post;
        }
        // group by post type
        $post_type_name = $post_types_labels[$post_type];
        $r[$post_type_name] = $this_group;
    }
    // return
    return $r;
}
Esempio n. 4
0
 function render_field_settings($field)
 {
     // post_type
     acf_render_field_setting($field, array('label' => __('Filter by Post Type', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'post_type', 'choices' => acf_get_pretty_post_types(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All post types", 'acf')));
     // taxonomy
     acf_render_field_setting($field, array('label' => __('Filter by Taxonomy', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'taxonomy', 'choices' => acf_get_taxonomy_terms(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All taxonomies", 'acf')));
     // allow_null
     acf_render_field_setting($field, array('label' => __('Allow Null?', 'acf'), 'instructions' => '', 'type' => 'radio', 'name' => 'allow_null', 'choices' => array(1 => __("Yes", 'acf'), 0 => __("No", 'acf')), 'layout' => 'horizontal'));
     // multiple
     acf_render_field_setting($field, array('label' => __('Select multiple values?', 'acf'), 'instructions' => '', 'type' => 'radio', 'name' => 'multiple', 'choices' => array(1 => __("Yes", 'acf'), 0 => __("No", 'acf')), 'layout' => 'horizontal'));
 }
Esempio n. 5
0
 function render_field_settings($field)
 {
     // post_type
     acf_render_field_setting($field, array('label' => __('Filter by Post Type', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'post_type', 'choices' => acf_get_pretty_post_types(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All post types", 'acf')));
     // taxonomy
     acf_render_field_setting($field, array('label' => __('Filter by Taxonomy', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'taxonomy', 'choices' => acf_get_taxonomy_terms(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All taxonomies", 'acf')));
     // allow_null
     acf_render_field_setting($field, array('label' => __('Allow Null?', 'acf'), 'instructions' => '', 'name' => 'allow_null', 'type' => 'true_false', 'ui' => 1));
     // allow_archives
     acf_render_field_setting($field, array('label' => __('Allow Archives URLs', 'acf'), 'instructions' => '', 'name' => 'allow_archives', 'type' => 'true_false', 'ui' => 1));
     // multiple
     acf_render_field_setting($field, array('label' => __('Select multiple values?', 'acf'), 'instructions' => '', 'name' => 'multiple', 'type' => 'true_false', 'ui' => 1));
 }
Esempio n. 6
0
        $width['post_type'] = $width['post_type'] == 0 ? 0 : 50;
    }
    // search
    if ($width['post_type'] == 0 && $width['taxonomy'] == 0) {
        $width['search'] = $width['search'] == 0 ? 0 : 100;
    }
}
// post type filter
$post_types = array();
if ($width['post_type']) {
    if (!empty($field['post_type'])) {
        $post_types = $field['post_type'];
    } else {
        $post_types = acf_get_post_types();
    }
    $post_types = acf_get_pretty_post_types($post_types);
}
// taxonomy filter
$taxonomies = array();
$term_groups = array();
if ($width['taxonomy']) {
    // taxonomies
    if (!empty($field['taxonomy'])) {
        // get the field's terms
        $term_groups = acf_get_array($field['taxonomy']);
        $term_groups = acf_decode_taxonomy_terms($term_groups);
        // update taxonomies
        $taxonomies = array_keys($term_groups);
    } elseif (!empty($field['post_type'])) {
        // loop over post types and find connected taxonomies
        foreach ($field['post_type'] as $post_type) {
Esempio n. 7
0
 function render_location_value($options)
 {
     // vars
     $options = wp_parse_args($options, array('group_id' => 0, 'rule_id' => 0, 'value' => null, 'param' => null));
     // vars
     $choices = array();
     // some case's have the same outcome
     if ($options['param'] == "page_parent") {
         $options['param'] = "page";
     }
     switch ($options['param']) {
         /*
          *  Post
          */
         case "post_type":
             // get post types
             $post_types = acf_get_post_types(array('show_ui' => 1, 'exclude' => array('attachment')));
             // get choices
             $choices = acf_get_pretty_post_types($post_types);
             // end
             break;
         case "post":
             // get post types
             $post_types = acf_get_post_types(array('exclude' => array('page', 'attachment')));
             // get posts grouped by post type
             $groups = acf_get_grouped_posts(array('post_type' => $post_types));
             if (!empty($groups)) {
                 foreach (array_keys($groups) as $group_title) {
                     // vars
                     $posts = acf_extract_var($groups, $group_title);
                     // override post data
                     foreach (array_keys($posts) as $post_id) {
                         // update
                         $posts[$post_id] = acf_get_post_title($posts[$post_id]);
                     }
                     // append to $choices
                     $choices[$group_title] = $posts;
                 }
             }
             break;
         case "post_template":
             // vars
             $templates = wp_get_theme()->get_post_templates();
             $default = apply_filters('default_page_template_title', __('Default Template', 'acf'));
             // choices
             $choices = array('default' => $default);
             // templates
             if (!empty($templates)) {
                 foreach ($templates as $post_type => $post_type_templates) {
                     $choices = array_merge($choices, $post_type_templates);
                 }
             }
             // break
             break;
         case "post_category":
             $terms = acf_get_taxonomy_terms('category');
             if (!empty($terms)) {
                 $choices = array_pop($terms);
             }
             break;
         case "post_format":
             $choices = get_post_format_strings();
             break;
         case "post_status":
             global $wp_post_statuses;
             if (!empty($wp_post_statuses)) {
                 foreach ($wp_post_statuses as $status) {
                     $choices[$status->name] = $status->label;
                 }
             }
             break;
         case "post_taxonomy":
             $choices = acf_get_taxonomy_terms();
             // unset post_format
             if (isset($choices['post_format'])) {
                 unset($choices['post_format']);
             }
             break;
             /*
              *  Page
              */
         /*
          *  Page
          */
         case "page":
             // get posts grouped by post type
             $groups = acf_get_grouped_posts(array('post_type' => 'page'));
             if (!empty($groups)) {
                 foreach (array_keys($groups) as $group_title) {
                     // vars
                     $posts = acf_extract_var($groups, $group_title);
                     // override post data
                     foreach (array_keys($posts) as $post_id) {
                         // update
                         $posts[$post_id] = acf_get_post_title($posts[$post_id]);
                     }
                     // append to $choices
                     $choices = $posts;
                 }
             }
             break;
         case "page_type":
             $choices = array('front_page' => __("Front Page", 'acf'), 'posts_page' => __("Posts Page", 'acf'), 'top_level' => __("Top Level Page (no parent)", 'acf'), 'parent' => __("Parent Page (has children)", 'acf'), 'child' => __("Child Page (has parent)", 'acf'));
             break;
         case "page_parent":
             // refer to "page"
             break;
         case "page_template":
             // vars
             $templates = wp_get_theme()->get_page_templates();
             $default = apply_filters('default_page_template_title', __('Default Template', 'acf'));
             // merge
             $choices = array_merge(array('default' => $default), $templates);
             break;
             /*
              *  User
              */
         /*
          *  User
          */
         case "current_user":
             // viewing
             $choices = array('logged_in' => __('Logged in', 'acf'), 'viewing_front' => __('Viewing front end', 'acf'), 'viewing_back' => __('Viewing back end', 'acf'));
             break;
         case "current_user_role":
             // global
             global $wp_roles;
             // specific roles
             $choices = $wp_roles->get_names();
             // multi-site
             if (is_multisite()) {
                 $choices = array_merge(array('super_admin' => __('Super Admin', 'acf')), $choices);
             }
             break;
         case "user_role":
             global $wp_roles;
             $choices = array_merge(array('all' => __('All', 'acf')), $wp_roles->get_names());
             break;
         case "user_form":
             $choices = array('all' => __('All', 'acf'), 'edit' => __('Add / Edit', 'acf'), 'register' => __('Register', 'acf'));
             break;
             /*
              *  Forms
              */
         /*
          *  Forms
          */
         case "attachment":
             $choices = array('all' => __('All', 'acf'));
             break;
         case "taxonomy":
             $choices = array_merge(array('all' => __('All', 'acf')), acf_get_taxonomies());
             // unset post_format
             if (isset($choices['post_format'])) {
                 unset($choices['post_format']);
             }
             break;
         case "comment":
             // vars
             $choices = array('all' => __('All', 'acf'));
             // append post types
             $choices = array_merge($choices, acf_get_pretty_post_types());
             // end
             break;
         case "widget":
             global $wp_widget_factory;
             $choices = array('all' => __('All', 'acf'));
             if (!empty($wp_widget_factory->widgets)) {
                 foreach ($wp_widget_factory->widgets as $widget) {
                     $choices[$widget->id_base] = $widget->name;
                 }
             }
             break;
     }
     // allow custom location rules
     $choices = apply_filters('acf/location/rule_values/' . $options['param'], $choices);
     // create field
     acf_render_field(array('type' => 'select', 'prefix' => "acf_field_group[location][{$options['group_id']}][{$options['rule_id']}]", 'name' => 'value', 'value' => $options['value'], 'choices' => $choices));
 }
Esempio n. 8
0
 function render_field_settings($field)
 {
     // default_value
     acf_render_field_setting($field, array('label' => __('Filter by Post Type', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'post_type', 'choices' => acf_get_pretty_post_types(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All post types", 'acf')));
     // default_value
     acf_render_field_setting($field, array('label' => __('Filter by Taxonomy', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'taxonomy', 'choices' => acf_get_taxonomy_terms(), 'multiple' => 1, 'ui' => 1, 'allow_null' => 1, 'placeholder' => __("All taxonomies", 'acf')));
     // allow_null
     acf_render_field_setting($field, array('label' => __('Allow Null?', 'acf'), 'instructions' => '', 'name' => 'allow_null', 'type' => 'true_false', 'ui' => 1));
     // multiple
     acf_render_field_setting($field, array('label' => __('Select multiple values?', 'acf'), 'instructions' => '', 'name' => 'multiple', 'type' => 'true_false', 'ui' => 1));
     // return_format
     acf_render_field_setting($field, array('label' => __('Return Format', 'acf'), 'instructions' => '', 'type' => 'radio', 'name' => 'return_format', 'choices' => array('object' => __("Post Object", 'acf'), 'id' => __("Post ID", 'acf')), 'layout' => 'horizontal'));
 }