/**
  * FOLLOWING IS SIMPLY COPIED OUT OF TYPES
  * TODO make original source reusable and delete copied code
  */
 public function _filterTypesFieldsToViewsDialog($menu)
 {
     if (is_admin() || !defined('TYPES_RELPATH')) {
         return;
     }
     wp_enqueue_script('wpcf-js-embedded', TYPES_RELPATH . '/library/toolset/types/embedded/resources/js/basic.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-tabs', 'toolset_select2'), WPCF_VERSION);
     $this->types_js_settings();
     $post_type = 'wp-types-group';
     $only_active = false;
     $add_fields = false;
     $cache_group = 'types_cache_groups';
     $cache_key = md5('group::_get_group' . $post_type);
     $cached_object = wp_cache_get($cache_key, $cache_group);
     if (false === $cached_object) {
         $groups = get_posts('numberposts=-1&post_type=' . $post_type . '&post_status=null');
         wp_cache_add($cache_key, $groups, $cache_group);
     } else {
         $groups = $cached_object;
     }
     $_groups = array();
     if (!empty($groups)) {
         foreach ($groups as $k => $group) {
             $group = wpcf_admin_fields_adjust_group($group, $add_fields);
             if ($only_active && !$group['is_active']) {
                 continue;
             }
             $_groups[$k] = $group;
         }
     }
     $groups = $_groups;
     $all_post_types = implode(' ', get_post_types(array('public' => true)));
     $add = array();
     if (!empty($groups)) {
         // $group_id is blank therefore not equal to $group['id']
         // use array for item key and CSS class
         $item_styles = array();
         global $post;
         foreach ($groups as $group_id => $group) {
             $fields = $this->wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true);
             if (!empty($fields)) {
                 // code from Types used here without breaking the flow
                 // get post types list for every group or apply all
                 $post_types = get_post_meta($group['id'], '_wp_types_group_post_types', true);
                 if ($post_types == 'all') {
                     $post_types = $all_post_types;
                 }
                 $post_types = trim(str_replace(',', ' ', $post_types));
                 $item_styles[$group['name']] = $post_types;
                 foreach ($fields as $field_id => $field) {
                     $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'postmeta\', ' . $post->ID . ')';
                     $menu[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim($this->copy_fields_get_shortcode($field), '[]'), $group['name'], $callback);
                 }
             }
         }
     }
     return $menu;
 }
Beispiel #2
0
/**
 * Gets groups that have specific template.
 * 
 * @global type $wpdb
 * @param type $post_type
 * @param type $fetch_empty
 * @param type $only_active
 * @return type 
 */
function wpcf_admin_get_groups_by_template($templates = array('default'), $fetch_empty = true, $only_active = true)
{
    $args = array();
    $args['post_type'] = 'wp-types-group';
    $args['numberposts'] = -1;
    $meta_query = array();
    // Active
    if ($only_active) {
        $args['post_status'] = 'publish';
    }
    // Fetch empty
    if ($fetch_empty) {
        $args['meta_query'] = array('relation' => 'OR', array('key' => '_wp_types_group_templates', 'value' => 'all', 'compare' => '='));
    } else {
        $args['meta_query'] = array('relation' => 'OR');
    }
    foreach ($templates as $template) {
        $args['meta_query'][] = array('key' => '_wp_types_group_templates', 'value' => ',' . $template . ',', 'compare' => 'LIKE');
    }
    $results_by_template = array();
    // Get posts by template
    $groups = get_posts($args);
    if (!empty($groups)) {
        foreach ($groups as $key => $group) {
            $group = wpcf_admin_fields_adjust_group($group);
            $results_by_template[$group['id']] = $group;
        }
    }
    return $results_by_template;
}
/**
 * Gets group by ID.
 * 
 * @global type $wpdb
 * @param type $group_id
 * @return type 
 */
function wpcf_admin_fields_get_group($group_id)
{
    return wpcf_admin_fields_adjust_group(get_post($group_id));
}