Example #1
0
/**
 * Filters groups on post edit page.
 * 
 * @param type $groups
 * @param type $post
 * @return type 
 */
function wpcf_cred_post_groups_filter($groups, $post)
{
    if (isset($post->post_type) && $post->post_type == 'cred-form') {
        return wpcf_admin_fields_get_groups(TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, 'group_active', 'fields_active');
        return wpcf_admin_fields_get_groups();
    }
    return $groups;
}
Example #2
0
/**
 * Filters groups on post edit page.
 * 
 * @param type $groups
 * @param type $post
 * @return type 
 */
function wpcf_cred_post_groups_filter($groups, $post)
{
    if (isset($post->post_type) && $post->post_type == 'cred-form') {
        return wpcf_admin_fields_get_groups('wp-types-group', 'group_active', 'fields_active');
        return wpcf_admin_fields_get_groups();
    }
    return $groups;
}
Example #3
0
/**
 * Renders 'widefat' table.
 */
function wpcf_admin_fields_list()
{
    $groups = wpcf_admin_fields_get_groups();
    if (empty($groups)) {
        echo '<p>' . __("To use custom fields, please create a group to hold them.", 'wpcf') . '</p>';
        echo '<br /><a class="button-primary" href="' . admin_url('admin.php?page=wpcf-edit') . '">' . __('Add a custom fields group', 'wpcf') . '</a><br /><br />';
    } else {
        echo '<br /><a class="button-secondary" href="' . admin_url('admin.php?page=wpcf-edit') . '">' . __('Add a custom fields group', 'wpcf') . '</a><br /><br />';
        $rows = array();
        $header = array('group_name' => __('Group name', 'wpcf'), 'group_description' => __('Description', 'wpcf'), 'group_active' => __('Active', 'wpcf'), 'group_post_types' => __('Post types', 'wpcf'), 'group_taxonomies' => __('Taxonomies', 'wpcf'));
        foreach ($groups as $group) {
            // Set 'name' column
            $name = '';
            $name .= '<a href="' . admin_url('admin.php?page=wpcf-edit&amp;group_id=' . $group['id']) . '">' . $group['name'] . '</a>';
            $name .= '<br />';
            $name .= '<a href="' . admin_url('admin.php?page=wpcf-edit&amp;group_id=' . $group['id']) . '">' . __('Edit', 'wpcf') . '</a> | ';
            $name .= $group['is_active'] ? wpcf_admin_fields_get_ajax_deactivation_link($group['id']) . ' | ' : wpcf_admin_fields_get_ajax_activation_link($group['id']) . ' | ';
            $name .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&amp;' . 'wpcf_action=delete_group&amp;group_id=' . $group['id'] . '&amp;wpcf_ajax_update=wpcf_list_ajax_response_' . $group['id']) . '&amp;_wpnonce=' . wp_create_nonce('delete_group') . '&amp;wpcf_warning=' . __('Are you sure?', 'wpcf') . '" class="wpcf-ajax-link" ' . 'id="wpcf-list-delete-' . $group['id'] . '">' . __('Delete Permanently', 'wpcf') . '</a>';
            $name .= '<div id="wpcf_list_ajax_response_' . $group['id'] . '"></div>';
            $rows[$group['id']]['name'] = $name;
            $rows[$group['id']]['raw_name'] = $group['name'];
            $rows[$group['id']]['description'] = $group['description'];
            $rows[$group['id']]['active-' . $group['id']] = $group['is_active'] ? __('Yes', 'wpcf') : __('No', 'wpcf');
            $rows[$group['id']]['status'] = $group['is_active'] ? 'active' : 'inactive';
            // Set 'post_tpes' column
            $post_types = wpcf_admin_get_post_types_by_group($group['id']);
            $rows[$group['id']]['post_types'] = empty($post_types) ? __('All post types', 'wpcf') : implode(', ', $post_types);
            // Set 'taxonomies' column
            $taxonomies = wpcf_admin_get_taxonomies_by_group($group['id']);
            $output = '';
            if (empty($taxonomies)) {
                $output = __('None', 'wpcf');
            } else {
                foreach ($taxonomies as $taxonomy => $terms) {
                    $output .= '<em>' . $taxonomy . '</em>: ';
                    $terms_output = array();
                    foreach ($terms as $term_id => $term) {
                        $terms_output[] = $term['name'];
                    }
                    $output .= implode(', ', $terms_output) . '<br />';
                }
            }
            $rows[$group['id']]['tax'] = $output;
        }
        uasort($rows, 'wpcf_admin_fields_list_sort');
        // Render table
        wpcf_admin_widefat_table('wpcf_groups_list', $header, $rows);
    }
    do_action('wpcf_groups_list_table_after');
}
Example #4
0
/**
 * Renders 'widefat' table.
 */
function wpcf_admin_fields_list()
{
    $groups = wpcf_admin_fields_get_groups();
    if (empty($groups)) {
        echo '<p>' . __("Custom Fields (also known as post-meta) are information attached to WordPress posts. This data can then be queried and filtered in your database. With Types you can create Custom Field Groups which are then attached to any post type (including Posts, Pages and Custom Post Types) or taxonomy.", 'wpcf') . '<br /><br />' . __('You can read more about Custom Fields in this tutorial: <a href="http://wp-types.com/user-guides/using-custom-fields/" target="_blank">http://wp-types.com/user-guides/using-custom-fields/ &raquo;</a>.', 'wpcf') . '</p>';
    }
    echo '<br /><a class="button-secondary" href="' . admin_url('admin.php?page=wpcf-edit') . '">' . __('Add a custom fields group', 'wpcf') . '</a><br /><br />';
    if (!empty($groups)) {
        $rows = array();
        $header = array('group_name' => __('Group name', 'wpcf'), 'group_description' => __('Description', 'wpcf'), 'group_active' => __('Active', 'wpcf'), 'group_post_types' => __('Post types', 'wpcf'), 'group_taxonomies' => __('Taxonomies', 'wpcf'));
        foreach ($groups as $group) {
            // Set 'name' column
            $name = '';
            $name .= '<a href="' . admin_url('admin.php?page=wpcf-edit&amp;group_id=' . $group['id']) . '">' . $group['name'] . '</a>';
            $name .= '<br />';
            $name .= '<a href="' . admin_url('admin.php?page=wpcf-edit&amp;group_id=' . $group['id']) . '">' . __('Edit', 'wpcf') . '</a> | ';
            $name .= $group['is_active'] ? wpcf_admin_fields_get_ajax_deactivation_link($group['id']) . ' | ' : wpcf_admin_fields_get_ajax_activation_link($group['id']) . ' | ';
            $name .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&amp;' . 'wpcf_action=delete_group&amp;group_id=' . $group['id'] . '&amp;wpcf_ajax_update=wpcf_list_ajax_response_' . $group['id']) . '&amp;_wpnonce=' . wp_create_nonce('delete_group') . '&amp;wpcf_warning=' . __('Are you sure?', 'wpcf') . '" class="wpcf-ajax-link" ' . 'id="wpcf-list-delete-' . $group['id'] . '">' . __('Delete Permanently', 'wpcf') . '</a>';
            $name .= '<div id="wpcf_list_ajax_response_' . $group['id'] . '"></div>';
            $rows[$group['id']]['name'] = $name;
            $rows[$group['id']]['description'] = $group['description'];
            $rows[$group['id']]['active-' . $group['id']] = $group['is_active'] ? __('Yes', 'wpcf') : __('No', 'wpcf');
            // Set 'post_tpes' column
            $post_types = wpcf_admin_get_post_types_by_group($group['id']);
            $rows[$group['id']]['post_types'] = empty($post_types) ? __('None', 'wpcf') : implode(', ', $post_types);
            // Set 'taxonomies' column
            $taxonomies = wpcf_admin_get_taxonomies_by_group($group['id']);
            $output = '';
            if (empty($taxonomies)) {
                $output = __('None', 'wpcf');
            } else {
                foreach ($taxonomies as $taxonomy => $terms) {
                    $output .= '<em>' . $taxonomy . '</em>: ';
                    $terms_output = array();
                    foreach ($terms as $term_id => $term) {
                        $terms_output[] = $term['name'];
                    }
                    $output .= implode(', ', $terms_output) . '<br />';
                }
            }
            $rows[$group['id']]['tax'] = $output;
        }
        // Render table
        wpcf_admin_widefat_table('wpcf_groups_list', $header, $rows);
    }
    do_action('wpcf_groups_list_table_after');
}
 static function wpv_filters_add_filter_usermeta_field($filters)
 {
     $basic = array(array(__('First Name', 'wpv-views'), 'first_name', 'Basic', ''), array(__('Last Name', 'wpv-views'), 'last_name', 'Basic', ''), array(__('Nickname', 'wpv-views'), 'nickname', 'Basic', ''), array(__('Description', 'wpv-views'), 'description', 'Basic', ''), array(__('Yahoo IM', 'wpv-views'), 'yim', 'Basic', ''), array(__('Jabber', 'wpv-views'), 'jabber', 'Basic', ''), array(__('AIM', 'wpv-views'), 'aim', 'Basic', ''));
     foreach ($basic as $b_filter) {
         $filters['usermeta-field-basic-' . str_replace(' ', '_', $b_filter[1])] = array('name' => sprintf(__('User field - %s', 'wpv-views'), $b_filter[0]), 'present' => 'usermeta-field-' . $b_filter[1] . '_compare', 'callback' => array('WPV_Usermeta_Field_Filter', 'wpv_add_new_filter_usermeta_field_list_item'), 'args' => array('name' => 'usermeta-field-' . $b_filter[1]), 'group' => __('User data', 'wpv-views'));
     }
     // @todo review this for gods sake!!!!!!!!!!!!!!!!!!!!!!!!
     if (function_exists('wpcf_admin_fields_get_groups')) {
         $groups = wpcf_admin_fields_get_groups('wp-types-user-group');
         $user_id = wpcf_usermeta_get_user();
         $add = array();
         if (!empty($groups)) {
             foreach ($groups as $group_id => $group) {
                 if (empty($group['is_active'])) {
                     continue;
                 }
                 $fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true, 'wp-types-user-group', 'wpcf-usermeta');
                 if (!empty($fields)) {
                     foreach ($fields as $field_id => $field) {
                         $add[] = $field['meta_key'];
                         $filters['usermeta-field-' . str_replace(' ', '_', $field['meta_key'])] = array('name' => sprintf(__('User field - %s', 'wpv-views'), $field['name']), 'present' => 'usermeta-field-' . $field['meta_key'] . '_compare', 'callback' => array('WPV_Usermeta_Field_Filter', 'wpv_add_new_filter_usermeta_field_list_item'), 'args' => array('name' => 'usermeta-field-' . $field['meta_key']));
                     }
                 }
             }
         }
         $cf_types = wpcf_admin_fields_get_fields(true, true, false, 'wpcf-usermeta');
         foreach ($cf_types as $cf_id => $cf) {
             if (!in_array($cf['meta_key'], $add)) {
                 $filters['usermeta-field-' . str_replace(' ', '_', $cf['meta_key'])] = array('name' => sprintf(__('User field - %s', 'wpv-views'), $cf['name']), 'present' => 'usermeta-field-' . $cf['meta_key'] . '_compare', 'callback' => array('WPV_Usermeta_Field_Filter', 'wpv_add_new_filter_usermeta_field_list_item'), 'args' => array('name' => 'usermeta-field-' . $cf['meta_key']));
             }
         }
     }
     $meta_keys = get_user_meta_keys();
     foreach ($meta_keys as $key) {
         $key_nicename = '';
         if (stripos($key, 'wpcf-') === 0) {
             if (function_exists('wpcf_admin_fields_get_groups')) {
                 continue;
             }
         } else {
             $key_nicename = $key;
         }
         $filters['usermeta-field-' . str_replace(' ', '_', $key)] = array('name' => sprintf(__('User field - %s', 'wpv-views'), $key_nicename), 'present' => 'usermeta-field-' . $key . '_compare', 'callback' => array('WPV_Usermeta_Field_Filter', 'wpv_add_new_filter_usermeta_field_list_item'), 'args' => array('name' => 'usermeta-field-' . $key));
     }
     return $filters;
 }
Example #6
0
/**
 * Renders 'widefat' table.
 */
function wpcf_admin_usermeta_list()
{
    $post_type = 'wp-types-user-group';
    $groups = wpcf_admin_fields_get_groups('wp-types-user-group');
    if (empty($groups)) {
        echo '<p>' . __("User Fields, also known as user-meta, are additional fields that belong to user profiles.", 'wpcf') . '</p>';
    }
    echo '<br /><a class="button-secondary" href="' . admin_url('admin.php?page=wpcf-edit-usermeta') . '">' . __('Add a user meta group', 'wpcf') . '</a><br /><br />';
    if (!empty($groups)) {
        $rows = array();
        $header = array('group_name' => __('Group name', 'wpcf'), 'group_description' => __('Description', 'wpcf'), 'group_active' => __('Active', 'wpcf'), 'group_post_types' => __('Available for', 'wpcf'));
        foreach ($groups as $group) {
            // Set 'name' column
            $name = '';
            $name .= '<a href="' . admin_url('admin.php?page=wpcf-edit-usermeta&amp;group_id=' . $group['id']) . '">' . $group['name'] . '</a>';
            $name .= '<br />';
            $name .= '<a href="' . admin_url('admin.php?page=wpcf-edit-usermeta&amp;group_id=' . $group['id']) . '">' . __('Edit', 'wpcf') . '</a> | ';
            $name .= $group['is_active'] ? wpcf_admin_usermeta_get_ajax_deactivation_link($group['id']) . ' | ' : wpcf_admin_usermeta_get_ajax_activation_link($group['id']) . ' | ';
            $name .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&amp;' . 'wpcf_action=delete_usermeta_group&amp;group_id=' . $group['id'] . '&amp;wpcf_ajax_update=wpcf_list_ajax_response_' . $group['id']) . '&amp;_wpnonce=' . wp_create_nonce('delete_usermeta_group') . '&amp;wpcf_warning=' . __('Are you sure?', 'wpcf') . '" class="wpcf-ajax-link" ' . 'id="wpcf-list-delete-' . $group['id'] . '">' . __('Delete Permanently', 'wpcf') . '</a>';
            $name .= '<div id="wpcf_list_ajax_response_' . $group['id'] . '"></div>';
            $rows[$group['id']]['name'] = $name;
            $rows[$group['id']]['description'] = $group['description'];
            $rows[$group['id']]['active-' . $group['id']] = $group['is_active'] ? __('Yes', 'wpcf') : __('No', 'wpcf');
            $show_for = wpcf_admin_get_groups_showfor_by_group($group['id']);
            if (function_exists('wpcf_access_register_caps')) {
                $show_for = __('This groups visibility is also controlled by the Access plugin.', 'wpcf');
            } else {
                $show_for = count($show_for) == 0 ? __('Displayed for all users roles', 'wpcf') : ucwords(implode($show_for, ', '));
            }
            $rows[$group['id']]['group_post_types'] = $show_for;
        }
        // Render table
        wpcf_admin_widefat_table('wpcf_groups_list', $header, $rows);
    }
    do_action('wpcf_groups_list_table_after');
}
Example #7
0
/**
 * Gets all groups that contain specified field.
 * 
 * @static $cache
 * @param type $field_id 
 */
function wpcf_admin_fields_get_groups_by_field($field_id, $post_type = 'wp-types-group')
{
    static $cache = array();
    $groups = wpcf_admin_fields_get_groups($post_type);
    $meta_name = $post_type == 'wp-types-group' ? 'wpcf-fields' : 'wpcf-usermeta';
    $return = array();
    foreach ($groups as $group_id => $group) {
        if (isset($cache['groups'][$group_id])) {
            $fields = $cache['groups'][$group_id];
        } else {
            $fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', false, false, false, $post_type, $meta_name);
        }
        if (array_key_exists($field_id, $fields)) {
            $return[$group['id']] = $group;
        }
        $cache['groups'][$group_id] = $fields;
    }
    return $return;
}
Example #8
0
 /**
  * Adds items to view dropdown.
  * 
  * @param type $items
  * @return type 
  */
 public static function editorDropdownFilter($items)
 {
     $post = wpcf_admin_get_edited_post();
     if (empty($post)) {
         $post = (object) array('ID' => -1);
     }
     $groups = wpcf_admin_fields_get_groups('wp-types-group', 'group_active');
     $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();
         foreach ($groups as $group) {
             $fields = 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) {
                     $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'postmeta\', ' . $post->ID . ')';
                     $add[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback);
                     // TODO Remove - it's not post edit screen (meta box JS and CSS)
                     WPCF_Fields::enqueueScript($field['type']);
                     WPCF_Fields::enqueueStyle($field['type']);
                 }
             }
         }
     }
     $search_key = '';
     // Iterate all items to be displayed in the "V" menu
     foreach ($items as $key => $item) {
         if ($key == __('Basic', 'wpv-views')) {
             $search_key = 'found';
             continue;
         }
         if ($search_key == 'found') {
             $search_key = $key;
         }
         if ($key == __('Field', 'wpv-views') && isset($item[trim(wpcf_types_get_meta_prefix(), '-')])) {
             unset($items[$key][trim(wpcf_types_get_meta_prefix(), '-')]);
         }
     }
     if (empty($search_key) || $search_key == 'found') {
         $search_key = count($items);
     }
     $insert_position = array_search($search_key, array_keys($items));
     $part_one = array_slice($items, 0, $insert_position);
     $part_two = array_slice($items, $insert_position);
     $items = $part_one + $add + $part_two;
     // apply CSS styles to each item based on post types
     foreach ($items as $key => $value) {
         if (isset($item_styles[$key])) {
             $items[$key]['css'] = $item_styles[$key];
         } else {
             $items[$key]['css'] = $all_post_types;
         }
     }
     return $items;
 }
 function wpcf_register_modules_items_groups($items)
 {
     $groups = wpcf_admin_fields_get_groups();
     foreach ($groups as $group) {
         $_details = sprintf(__('Fields group: %s', 'wpcf'), $group['name']);
         $details = !empty($group['description']) ? $group['description'] : $_details;
         $items[] = array('id' => '12' . _GROUPS_MODULE_MANAGER_KEY_ . '21' . $group['id'], 'title' => $group['name'], 'details' => '<p style="padding:5px;">' . $details . '</p>', '__types_id' => $group['slug'], '__types_title' => $group['name']);
     }
     return $items;
 }
Example #10
0
/**
 * Bulk translation. 
 */
function wpcf_admin_bulk_string_translation()
{
    if (!function_exists('icl_register_string')) {
        return false;
    }
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/custom-types.php';
    require_once WPCF_INC_ABSPATH . '/custom-types-form.php';
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/custom-taxonomies.php';
    require_once WPCF_INC_ABSPATH . '/custom-taxonomies-form.php';
    // Register groups
    $groups = wpcf_admin_fields_get_groups();
    foreach ($groups as $group_id => $group) {
        wpcf_translate_register_string('plugin Types', 'group ' . $group_id . ' name', $group['name']);
        if (isset($group['description'])) {
            wpcf_translate_register_string('plugin Types', 'group ' . $group_id . ' description', $group['description']);
        }
    }
    // Register fields
    $fields = wpcf_admin_fields_get_fields();
    foreach ($fields as $field_id => $field) {
        wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' name', $field['name']);
        if (isset($field['description'])) {
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' description', $field['description']);
        }
        // For radios or select
        if (!empty($field['data']['options'])) {
            foreach ($field['data']['options'] as $name => $option) {
                if ($name == 'default') {
                    continue;
                }
                if (isset($option['title'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' title', $option['title']);
                }
                if (isset($option['value'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' value', $option['value']);
                }
                if (isset($option['display_value'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' display value', $option['display_value']);
                }
            }
        }
        if ($field['type'] == 'checkbox' && (isset($field['set_value']) && $field['set_value'] != '1')) {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value', $field['set_value']);
        }
        if ($field['type'] == 'checkbox' && !empty($field['display_value_selected'])) {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value selected', $field['display_value_selected']);
        }
        if ($field['type'] == 'checkbox' && !empty($field['display_value_not_selected'])) {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value not selected', $field['display_value_not_selected']);
        }
        // Validation message
        if (!empty($field['data']['validate'])) {
            foreach ($field['data']['validate'] as $method => $validation) {
                if (!empty($validation['message'])) {
                    // Skip if it's same as default
                    $default_message = wpcf_admin_validation_messages($method);
                    if ($validation['message'] != $default_message) {
                        wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' validation message ' . $method, $validation['message']);
                    }
                }
            }
        }
    }
    // Register types
    $custom_types = get_option('wpcf-custom-types', array());
    foreach ($custom_types as $post_type => $data) {
        wpcf_custom_types_register_translation($post_type, $data);
    }
    // Register taxonomies
    $custom_taxonomies = get_option('wpcf-custom-taxonomies', array());
    foreach ($custom_taxonomies as $taxonomy => $data) {
        wpcf_custom_taxonimies_register_translation($taxonomy, $data);
    }
}
Example #11
0
 public function __construct()
 {
     //Get list of groups
     self::$fields_groups = wpcf_admin_fields_get_groups();
     // setup custom capabilities
     //If access plugin installed
     if (function_exists('wpcf_access_register_caps')) {
         // integrate with Types Access
         if (!empty(self::$fields_groups)) {
             //Add Fields area
             add_filter('types-access-area', array('Post_Fields_Access', 'register_access_fields_area'), 10, 2);
             //Add Fields groups
             add_filter('types-access-group', array('Post_Fields_Access', 'register_access_fields_groups'), 10, 2);
             //Add Fields caps to groups
             add_filter('types-access-cap', array('Post_Fields_Access', 'register_access_fields_caps'), 10, 3);
             //}
         }
     }
 }
 /** ************************************************************************
  * REQUIRED! This is where you prepare your data for display. This method will
  * usually be used to query the database, sort and filter the data, and generally
  * get it ready to be displayed. At a minimum, we should set $this->items and
  * $this->set_pagination_args(), although the following properties and methods
  * are frequently interacted with here...
  *
  * @uses $this->_column_headers
  * @uses $this->items
  * @uses $this->get_columns()
  * @uses $this->get_sortable_columns()
  * @uses $this->get_pagenum()
  * @uses $this->set_pagination_args()
  **************************************************************************/
 function prepare_items()
 {
     /**
      * First, lets decide how many records per page to show
      */
     $per_page = $this->get_items_per_page('wpcf_uf_per_page', 10);
     /**
      * REQUIRED. Now we need to define our column headers. This includes a complete
      * array of columns to be displayed (slugs & titles), a list of columns
      * to keep hidden, and a list of columns that are sortable. Each of these
      * can be defined in another method (as we've done here) before being
      * used to build the value for our _column_headers property.
      */
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     /**
      * REQUIRED. Finally, we build an array to be used by the class for column
      * headers. The $this->_column_headers property takes an array which contains
      * 3 other arrays. One for all columns, one for hidden columns, and one
      * for sortable columns.
      */
     $this->_column_headers = array($columns, $hidden, $sortable);
     /**
      * Optional. You can handle your bulk actions however you see fit. In this
      * case, we'll handle them within our package just to keep things clean.
      */
     $this->process_bulk_action();
     /**
      * Instead of querying a database, we're going to fetch the example data
      * property we created for use in this plugin. This makes this example
      * package slightly different than one you might build on your own. In
      * this example, we'll be using array manipulation to sort and paginate
      * our data. In a real-world implementation, you will probably want to
      * use sort and pagination data to build a custom query instead, as you'll
      * be able to use your precisely-queried data immediately.
      */
     $s = isset($_POST['s']) ? mb_strtolower(trim($_POST['s'])) : false;
     $data = array();
     $groups = wpcf_admin_fields_get_groups(TYPES_USER_META_FIELD_GROUP_CPT_NAME);
     if (!empty($groups)) {
         foreach (array_values($groups) as $group) {
             $one = array('description' => $group['description'], 'id' => $group['id'], 'slug' => $group['slug'], 'status' => isset($group['is_active']) && $group['is_active'] ? 'active' : 'inactive', 'supports' => isset($group['supports']) ? $group['supports'] : array(), 'title' => wp_kses_post($group['name']), WPCF_AUTHOR => isset($group[WPCF_AUTHOR]) ? $group[WPCF_AUTHOR] : 0);
             $add_one = true;
             if ($s) {
                 $add_one = false;
                 foreach (array('description', 'id', 'slug', 'title') as $key) {
                     if ($add_one || empty($one[$key])) {
                         continue;
                     }
                     if (is_numeric(strpos(mb_strtolower($one[$key]), $s))) {
                         $add_one = true;
                     }
                 }
             }
             if ($add_one) {
                 $data[] = $one;
             }
         }
     }
     /**
      * This checks for sorting input and sorts the data in our array accordingly.
      */
     usort($data, 'wpcf_usort_reorder');
     /**
      * REQUIRED for pagination. Let's figure out what page the user is currently
      * looking at. We'll need this later, so you should always include it in
      * your own package classes.
      */
     $current_page = $this->get_pagenum();
     /**
      * REQUIRED for pagination. Let's check how many items are in our data array.
      * In real-world use, this would be the total number of items in your database,
      * without filtering. We'll need this later, so you should always include it
      * in your own package classes.
      */
     $total_items = count($data);
     /**
      * The WP_List_Table class does not handle pagination for us, so we need
      * to ensure that the data is trimmed to only the current page. We can use
      * array_slice() to
      */
     $data = array_slice($data, ($current_page - 1) * $per_page, $per_page);
     /**
      * REQUIRED. Now we can add our *sorted* data to the items property, where
      * it can be used by the rest of the class.
      */
     $this->items = $data;
     /**
      * REQUIRED. We also have to register our pagination options & calculations.
      */
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
Example #13
0
/**
 * Get active fields by post type
 *
 * Get active fields by post type chosing it from active groups and this 
 * groups which are connected to certain post type.
 *
 * @since: 1.7
 *
 * @param string $post_type post type
 *
 * @return array allowed meta keys
 */
function wpcf_admin_get_allowed_fields_by_post_type($post_type)
{
    $allowed_fields = $active_groups = array();
    $all_groups = wpcf_admin_get_groups_by_post_type($post_type);
    foreach ($all_groups as $group_id => $group_data) {
        $active_groups[] = $group_data['slug'];
    }
    $all_groups = wpcf_admin_fields_get_groups(TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, true, true);
    foreach ($all_groups as $group) {
        if (!in_array($group['slug'], $active_groups)) {
            continue;
        }
        foreach ($group['fields'] as $field_key => $field_data) {
            $allowed_fields[] = $field_data['meta_key'];
        }
    }
    return $allowed_fields;
}
 /**
  * @global object $wpdb
  */
 function prepare_items()
 {
     global $wpdb;
     $per_page = $this->get_items_per_page('wpcf_ufc_per_page', 10);
     // Get ours and enabled
     $cf_types = wpcf_admin_fields_get_fields(true, true, false, 'wpcf-usermeta');
     $__groups = wpcf_admin_fields_get_groups(TYPES_USER_META_FIELD_GROUP_CPT_NAME);
     foreach ($__groups as $__group_id => $__group) {
         $__groups[$__group_id]['fields'] = wpcf_admin_fields_get_fields_by_group($__group['id'], 'slug', false, true, false, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta');
     }
     foreach ($cf_types as $cf_id => $cf) {
         foreach ($__groups as $__group) {
             if (isset($__group['fields'][$cf_id])) {
                 $cf_types[$cf_id]['groups'][$__group['id']] = $__group['name'];
             }
         }
         $cf_types[$cf_id]['groups_txt'] = empty($cf_types[$cf_id]['groups']) ? __('None', 'wpcf') : implode(', ', $cf_types[$cf_id]['groups']);
     }
     $meta_key_not_like = array('\\_%', 'closedpostboxes%', 'meta-box-order%', 'metaboxhidden%');
     $having = '';
     foreach ($meta_key_not_like as $one) {
         if ($having) {
             $having .= ' AND ';
         }
         $having .= sprintf('meta_key NOT LIKE \'%s\'', $one);
     }
     if ($having) {
         $having = ' HAVING ' . $having;
     }
     $query = sprintf('SELECT umeta_id, meta_key FROM %s GROUP BY meta_key %s ORDER BY meta_key', $wpdb->usermeta, $having);
     // Get others (cache this result?)
     $cf_other = $wpdb->get_results($query);
     $output = '';
     // Clean from ours
     foreach ($cf_other as $type_id => $type_data) {
         if (strpos($type_data->meta_key, WPCF_META_PREFIX) !== false) {
             $field_temp = wpcf_admin_fields_get_field(str_replace(WPCF_META_PREFIX, '', $type_data->meta_key), false, false, 'wpcf-usermeta');
             if (!empty($field_temp)) {
                 if (!empty($field_temp['data']['disabled'])) {
                     $cf_types[$field_temp['id']] = array('id' => $field_temp['id'], 'slug' => $type_data->meta_key, 'name' => $type_data->meta_key, 'type' => 0, 'groups_txt' => __('None', 'wpcf'));
                 } else {
                     unset($cf_other[$type_id]);
                 }
             } else {
                 if (wpcf_types_cf_under_control('check_exists', $type_data->meta_key, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta')) {
                     unset($cf_other[$type_id]);
                 } else {
                     $cf_types[$type_data->meta_key] = array('id' => $type_data->meta_key, 'slug' => $type_data->meta_key, 'name' => $type_data->meta_key, 'type' => 0, 'groups_txt' => __('None', 'wpcf'));
                 }
             }
         } else {
             if (wpcf_types_cf_under_control('check_exists', $type_data->meta_key, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta')) {
                 unset($cf_other[$type_id]);
             } else {
                 $cf_types[$type_data->meta_key] = array('id' => $type_data->meta_key, 'slug' => $type_data->meta_key, 'name' => $type_data->meta_key, 'type' => 0, 'groups_txt' => __('None', 'wpcf'));
             }
         }
     }
     // Set some values
     foreach ($cf_types as $cf_id_temp => $cf_temp) {
         if (empty($cf_temp['type']) || !empty($cf_temp['data']['controlled'])) {
             $cf_types[$cf_id_temp]['slug'] = $cf_temp['name'];
         } else {
             $cf_types[$cf_id_temp]['slug'] = wpcf_types_get_meta_prefix($cf_temp) . $cf_temp['slug'];
         }
     }
     // Order
     $orderby = isset($_REQUEST['orderby']) && !empty($_REQUEST['orderby']) ? sanitize_text_field($_REQUEST['orderby']) : 'c';
     $order = isset($_REQUEST['order']) && !empty($_REQUEST['order']) ? sanitize_text_field($_REQUEST['order']) : 'asc';
     $sort_matches = array('c' => 'name', 'g' => 'groups_txt', 't' => 'slug', 'f' => 'type');
     $sorted_keys = array();
     $new_array = array();
     foreach ($cf_types as $cf_id_temp => $cf_temp) {
         if (isset($sort_matches[$orderby])) {
             $sorted_keys[$cf_temp['id']] = strtolower($cf_temp[$sort_matches[$orderby]]);
         } else {
             $sorted_keys[$cf_temp['id']] = strtolower($cf_temp[$sort_matches['c']]);
         }
     }
     asort($sorted_keys, SORT_STRING);
     if ('desc' == $order) {
         $sorted_keys = array_reverse($sorted_keys, true);
     }
     foreach ($sorted_keys as $cf_id_temp => $groups_txt) {
         $new_array[$cf_id_temp] = $cf_types[$cf_id_temp];
     }
     $cf_types = $new_array;
     // Search
     if (!empty($_REQUEST['s'])) {
         $search_results = array();
         foreach ($cf_types as $search_id => $search_field) {
             if (strpos(strval($search_field['name']), strval(trim(stripslashes($_REQUEST['s'])))) !== false) {
                 $search_results[$search_id] = $cf_types[$search_id];
             }
         }
         $cf_types = $search_results;
     }
     $total_items = count($cf_types);
     if ($total_items < $per_page) {
         $per_page = $total_items;
     }
     if ($this->get_pagenum() == 1) {
         $offset = 0;
     } else {
         $offset = ($this->get_pagenum() - 1) * $per_page;
     }
     // Display required number of entries on page
     $this->items = array_slice($cf_types, $offset, $per_page);
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page));
     $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
 }
 /**
  * Summary.
  *
  * Description.
  *
  * @since x.x.x
  * @access (for functions: only use if private)
  *
  * @see Function/method/class relied on
  * @link URL
  * @global type $varname Description.
  * @global type $varname Description.
  *
  * @param type $var Description.
  * @param type $var Optional. Description.
  * @return type Description.
  */
 public function ajax_metabox_custom_fields_get_content()
 {
     // check nonce
     if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], $this->get_nonce('custom-fields-box', $_REQUEST['type'], $_REQUEST['id']))) {
         $this->verification_failed_and_die();
     }
     // we need an array of all possible fields to check agains what is stored in the database,
     // otherwise stored db fields will always be shown until next cpt save
     $possible_fields = array();
     // current selected groups
     $current_selected_groups = isset($_REQUEST['current_groups']) && !empty($_REQUEST['current_groups']) ? $_REQUEST['current_groups'] : array();
     // current selected fields
     $current_selected_fields = isset($_REQUEST['current_fields']) && !empty($_REQUEST['current_fields']) ? $_REQUEST['current_fields'] : array();
     // get post type slug
     $post_type_slug = $this->get_type_from_request('id');
     // not saved yet
     if (empty($post_type_slug)) {
         $this->print_notice_and_die(__('Please save first, before you can edit the custom fields.', 'wpcf'));
     }
     // current post type
     require_once WPCF_INC_ABSPATH . '/classes/class.types.admin.post-type.php';
     $wpcf_post_type = new Types_Admin_Post_Type();
     $post_type = $wpcf_post_type->get_post_type($post_type_slug);
     // no groups selected
     if (empty($current_selected_groups)) {
         $this->print_notice_and_die(sprintf(__('You can include Post Fields in the <b>listing page for %s</b>. Add Post Fields to this Post Type and you will be able to select which ones will display in the listing page.', 'wpcf'), $post_type['labels']['name']));
     }
     // all custom field groups
     $custom_field_groups = wpcf_admin_fields_get_groups(TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, true, true);
     if (empty($custom_field_groups)) {
         echo wpautop(__('To use custom fields, please create a group to hold them.', 'wpcf'));
         die;
     }
     // form
     $form = $field_checkboxes = array();
     // add description to form
     $form['description'] = array('#type' => 'markup', '#markup' => sprintf('<p class="description">%s</p>', __('Check which fields should be shown on this Post Type list as a columns.', 'wpcf')));
     $form_add = array();
     // for all custom field groups
     foreach ($custom_field_groups as $custom_field_group) {
         // skip group if not selected
         if (!in_array($custom_field_group['id'], $current_selected_groups)) {
             continue;
         }
         $id = 'group-' . $custom_field_group['id'] . '-';
         // add fields to possible fields
         if (isset($custom_field_group['fields'])) {
             $possible_fields = array_merge($possible_fields, $custom_field_group['fields']);
         } else {
             $custom_field_group['fields'] = array();
         }
         // get field checkboxes
         $field_checkboxes = $this->build_options($post_type, $custom_field_group['fields'], 'custom-field-%s');
         // no fields
         if (empty($field_checkboxes)) {
             $form_add[$id] = array('#type' => 'markup', '#title' => $custom_field_group['name'], '#markup' => __('There are no available fields in this group.', 'wpcf'), '#inline' => true, '_builtin' => true, '#pattern' => '<div class="js-wpcf-custom-field-group wpcf-custom-field-group"><h4><TITLE></h4><ul><ELEMENT></ul></div>');
             continue;
         }
         // if not first time loading fields use the selected fields and not the database stored
         if ($_REQUEST['init'] == 0) {
             foreach ($field_checkboxes as $field_key => $field_values) {
                 // check if field is selected
                 $field_values['#default_value'] = in_array('wpcf-' . $field_key, $current_selected_fields) || in_array($field_key, $current_selected_fields) ? 1 : 0;
                 $field_checkboxes[$field_key] = $field_values;
             }
         }
         // add checkboxes to form
         $form_add[$id] = array('#type' => 'checkboxes', '#title' => $custom_field_group['name'], '#options' => $field_checkboxes, '#name' => 'wpcf[group][supports]', '#inline' => true, '_builtin' => true, '#pattern' => '<div class="js-wpcf-custom-field-group wpcf-custom-field-group"><h4><TITLE></h4><ul><ELEMENT></ul></div>');
     }
     // if form is still empty here the user didn't create any group
     if (empty($form_add)) {
         $form['no-fields'] = array('#type' => 'markup', '#markup' => sprintf('<p class="description">%s</p>', __('No custom field groups found.', 'wpcf')));
         $form = wpcf_form(__FUNCTION__, $form);
         echo $form->renderForm();
         die;
     }
     $form['groups-open'] = array('#type' => 'markup', '#markup' => '<div class="clearfix wpcf-custom-field-group-container js-wpcf-custom-field-group-container">');
     $form += $form_add;
     $form['groups-close'] = array('#type' => 'markup', '#markup' => '</div>');
     /**
      * Sortable Area
      */
     // on first load use db stored fields
     if ($_REQUEST['init'] == 1) {
         $fields_selected = wpcf_admin_fields_get_active_fields_by_post_type($post_type['slug']);
         // otherwise use unsaved selected fields
     } else {
         $fields_selected = array();
         foreach ($custom_field_groups as $custom_field_group) {
             if (isset($custom_field_group['fields'])) {
                 $fields_selected += $custom_field_group['fields'];
             }
         }
     }
     if (!empty($fields_selected)) {
         $field_checkboxes = $this->build_options($post_type, $fields_selected, 'ct[custom_fields][%s]');
         foreach ($field_checkboxes as $field_key => $field_values) {
             if ($_REQUEST['init'] == 0) {
                 $field_values['#default_value'] = in_array('wpcf-' . $field_key, $current_selected_fields) || in_array($field_key, $current_selected_fields) ? 1 : 0;
             }
             // remove if unchecked
             if (empty($field_values['#default_value'])) {
                 unset($field_checkboxes[$field_key]);
                 continue;
             }
             $field_checkboxes[$field_key]['#type'] = 'hidden';
             $field_checkboxes[$field_key]['#pattern'] = '<div class="wpcf-custom-field js-wpcf-custom-field"><ELEMENT><TITLE></div>';
         }
     }
     $form['wpcf-custom-field-order-open'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-custom-field-order">');
     $fields_in_sortable = array();
     // on first load use db data if not empty
     if ($_REQUEST['init'] == 1 && isset($post_type['custom_fields']) && !empty($post_type['custom_fields'])) {
         $fields_in_sortable = $post_type['custom_fields'];
         // otherwise currently selected fields
     } elseif (!empty($current_selected_fields)) {
         foreach ($current_selected_fields as $field) {
             $fields_in_sortable[$field] = 1;
         }
     }
     if (!empty($fields_in_sortable)) {
         $fields_to_add_to_sortable = array();
         foreach (array_keys($fields_in_sortable) as $key) {
             // remove "wpcf-" of id if field in sortable area is not part of checkboxes
             if (!isset($field_checkboxes[$key])) {
                 $key = preg_replace('/^wpcf-/', '', $key);
             }
             // abort if sortable field is still not part of checkboxes
             // OR if field isn't in possible fields
             if (!isset($field_checkboxes[$key]) || !array_key_exists($key, $possible_fields)) {
                 continue;
             }
             $fields_to_add_to_sortable['wpcf-custom-field-order-' . $key] = array('#type' => 'markup', '#markup' => sprintf('<li class="menu-item-handle" id="wpcf-custom-field-%s"><input type="hidden" name="%s" value="1" />%s</li>', esc_attr($field_checkboxes[$key]['#attributes']['data-wpcf-key']), esc_attr($field_checkboxes[$key]['#name']), $field_checkboxes[$key]['#title']));
         }
         // add fields to sortable area
         if (!empty($fields_to_add_to_sortable)) {
             $form['wpcf-custom-field-order-ul-open'] = $this->get_empty_ul();
             $form += $fields_to_add_to_sortable;
             $form['wpcf-custom-field-order-ul-close'] = array('#type' => 'markup', '#markup' => '</ul>');
         }
     }
     // if no fields selected add empty ul
     if (!isset($fields_to_add_to_sortable) || empty($fields_to_add_to_sortable)) {
         $form['wpcf-custom-field-order-ul'] = $this->get_empty_ul(true);
     }
     // close sortable container
     $form['wpcf-custom-field-order-close'] = array('#type' => 'markup', '#markup' => '</div>');
     $form = wpcf_form(__FUNCTION__, $form);
     echo $form->renderForm();
     die;
 }
Example #16
0
 /**
  * Adds items to view dropdown.
  * 
  * @param type $items
  * @return type 
  */
 public static function editorDropdownFilter($menu)
 {
     $post = wpcf_admin_get_edited_post();
     if (empty($post)) {
         $post = (object) array('ID' => -1);
     }
     $groups = wpcf_admin_fields_get_groups('wp-types-group', 'group_active');
     $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();
         foreach ($groups as $group) {
             $fields = 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) {
                     $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'postmeta\', ' . $post->ID . ')';
                     $menu[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback);
                     // TODO Remove - it's not post edit screen (meta box JS and CSS)
                     WPCF_Fields::enqueueScript($field['type']);
                     WPCF_Fields::enqueueStyle($field['type']);
                 }
             }
         }
     }
     return $menu;
 }
Example #17
0
/**
 * Gets all groups and fields for post.
 *
 * Core function. Works and stable. Do not move or change.
 * If required, add hooks only.
 *
 * @param type $post_ID
 * @return type
 */
function wpcf_admin_usermeta_get_groups_fields()
{
    $post = array();
    // Filter groups
    $groups = array();
    $groups_all = wpcf_admin_fields_get_groups('wp-types-user-group');
    foreach ($groups_all as $temp_key => $temp_group) {
        if (empty($temp_group['is_active'])) {
            unset($groups_all[$temp_key]);
            continue;
        }
        $passed = 1;
        if (!$passed) {
            unset($groups_all[$temp_key]);
        } else {
            $groups_all[$temp_key]['fields'] = wpcf_admin_fields_get_fields_by_group($temp_group['id'], 'slug', true, false, true, 'wp-types-user-group', 'wpcf-usermeta');
        }
    }
    $groups = $groups_all;
    return $groups;
}
Example #18
0
function wpcf_admin_metabox_custom_fields($ct)
{
    $form = array();
    $options = array();
    $option_to_key = array();
    $groups = wpcf_admin_fields_get_groups('wp-types-group', true, true);
    foreach ($groups as $group) {
        $post_types = wpcf_admin_get_post_types_by_group($group['id']);
        if (empty($post_types) || isset($ct['wpcf-post-type']) && in_array($ct['wpcf-post-type'], $post_types)) {
            if (!empty($group['fields'])) {
                foreach ($group['fields'] as $field => $data) {
                    if (isset($data['data']['repetitive']) && $data['data']['repetitive']) {
                        continue;
                    }
                    switch ($data['type']) {
                        case 'embed':
                        case 'checkboxes':
                        case 'audio':
                        case 'file':
                        case 'textarea':
                        case 'video':
                        case 'wysiwyg':
                            continue;
                        default:
                            $option_to_key[$data['meta_key']] = $field;
                            $options[$field] = array('#name' => sprintf('ct[custom_fields][%s]', esc_attr($data['meta_key'])), '#title' => sprintf('%s <small>(%s)</small>', $data['name'], $data['type']), '#value' => 1, '#inline' => true, '#before' => '<li>', '#after' => '</li>', '#default_value' => intval(isset($ct['custom_fields']) && isset($ct['custom_fields'][$data['meta_key']])));
                    }
                }
            }
        }
    }
    unset($groups);
    /**
     * get custom fields order
     */
    $options_to_add = array();
    if (isset($ct['custom_fields']) && is_array($ct['custom_fields']) && !empty($ct['custom_fields'])) {
        foreach ($ct['custom_fields'] as $key) {
            if (isset($option_to_key[$key]) && isset($options[$option_to_key[$key]])) {
                $options_to_add[$option_to_key[$key]] = $options[$option_to_key[$key]];
                unset($options[$option_to_key[$key]]);
            }
        }
    }
    $form['table-custom_fields-open'] = wpcf_admin_metabox_begin(__('Custom Fields', 'wpcf'), 'custom_fields', 'wpcf-types-form-visiblity-custom-fields-table', false);
    $form['table-custom_fields-description'] = array('#type' => 'checkboxes', '#options' => $options_to_add + $options, '#name' => 'wpcf[group][supports]', '#inline' => true, '#before' => wpautop(__('Check which fields should be shown on custom post list as a column.', 'wpcf')) . '<ul>', '#after' => '</ul>' . wpautop(__('Drag and drop ticked custom fields to reorder.', 'wpcf')));
    $form['table-custom_fields-close'] = wpcf_admin_metabox_end();
    return $form;
}
 /**
  * Summary.
  *
  * Description.
  *
  * @since x.x.x
  * @access (for functions: only use if private)
  *
  * @see Function/method/class relied on
  * @link URL
  * @global type $varname Description.
  * @global type $varname Description.
  *
  * @param type $var Description.
  * @param type $var Optional. Description.
  * @return type Description.
  */
 public function get_group_list($form = array(), $type = 'wpcf-fields')
 {
     $message = '';
     $groups = array();
     switch ($type) {
         case 'wpcf-fields':
             $groups = wpcf_admin_fields_get_groups();
             $message = __('There is no Post Field Group. Please define one first.', 'wpcf');
             break;
         case 'wpcf-usermeta':
             $groups = wpcf_admin_fields_get_groups(TYPES_USER_META_FIELD_GROUP_CPT_NAME);
             $message = __('There is no User Field Group. Please define one first.', 'wpcf');
             break;
         case WPCF_Field_Definition_Factory_Term::FIELD_DEFINITIONS_OPTION:
             $groups = wpcf_admin_fields_get_groups(Types_Field_Group_Term::POST_TYPE);
             $message = __('There is no Term Field Group. Please define one first.', 'wpcf');
             break;
     }
     if (empty($groups) && !empty($message)) {
         $form['message'] = array('#type' => 'notice', '#markup' => $message, '#attributes' => array('type' => 'warning'));
         return $form;
     }
     $form['groups-ul-open'] = array('#type' => 'markup', '#markup' => '<ul class="wpcf-list-of-items js-wpcf-list-of-items">');
     foreach ($groups as $group_id => $group) {
         $form[$group['id']] = array('#type' => 'checkbox', '#name' => 'groups', '#title' => $group['name'], '#id' => 'wpcf-group-' . $group['id'], '#value' => $group['id'], '#default_value' => false, '#before' => '<li>', '#after' => '</li>', '#inline' => true);
     }
     $form['groups-ul-close'] = array('#type' => 'markup', '#markup' => '</ul>');
     return $form;
 }
Example #20
0
/**
 * Deletes field.
 * Modified by Gen, 13.02.2013
 *
 * @global object $wpdb
 *
 * @param type $field_id
 */
function wpcf_admin_fields_delete_field($field_id, $post_type = TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, $meta_name = 'wpcf-fields')
{
    global $wpdb;
    $fields = get_option($meta_name, array());
    if (isset($fields[$field_id])) {
        // Remove from groups
        $groups = wpcf_admin_fields_get_groups($post_type);
        foreach ($groups as $key => $group) {
            wpcf_admin_fields_remove_field_from_group($group['id'], $field_id);
        }
        // Remove from posts
        if (!wpcf_types_cf_under_control('check_outsider', $field_id, $post_type, $meta_name)) {
            $results = $wpdb->get_results($wpdb->prepare("SELECT post_id, meta_key FROM {$wpdb->postmeta} WHERE meta_key = %s", wpcf_types_get_meta_prefix($fields[$field_id]) . strval($field_id)));
            foreach ($results as $result) {
                delete_post_meta($result->post_id, $result->meta_key);
            }
        }
        unset($fields[$field_id]);
        wpcf_admin_fields_save_fields($fields, true, $meta_name);
        return true;
    } else {
        return false;
    }
}
Example #21
0
/**
 * Gets all groups that contain specified field.
 * 
 * @static $cache
 * @param type $field_id 
 */
function wpcf_admin_fields_get_groups_by_field($field_id)
{
    static $cache = array();
    $groups = wpcf_admin_fields_get_groups();
    $return = array();
    foreach ($groups as $group_id => $group) {
        if (isset($cache['groups'][$group_id])) {
            $fields = $cache['groups'][$group_id];
        } else {
            $fields = wpcf_admin_fields_get_fields_by_group($group['id']);
        }
        if (array_key_exists($field_id, $fields)) {
            $return[$group['id']] = $group;
        }
    }
    $cache['groups'][$group_id] = $fields;
    return $return;
}
 /**
  * Adding a "V" button to the menu (for user fields)
  * @param string $context
  * @param string $text_area
  * @param boolean $standard_v is this a standard V button
  */
 function add_users_form_button($context, $text_area = 'textarea#content', $codemirror_button = false)
 {
     global $wp_version, $sitepress, $wpdb, $WP_Views;
     $standard_v = true;
     // WP 3.3 changes ($context arg is actually a editor ID now)
     if (version_compare($wp_version, '3.1.4', '>') && !empty($context)) {
         $text_area = $context;
     }
     //print_r($this->items);exit;
     $this->items = array();
     $unused_field = array('comment_shortcuts', 'managenav-menuscolumnshidden', 'dismissed_wp_pointers', 'meta-box-order_dashboard', 'nav_menu_recently_edited', 'primary_blog', 'rich_editing', 'source_domain', 'use_ssl', 'user_level', 'user-settings-time', 'user-settings', 'dashboard_quick_press_last_post_id', 'capabilities', 'new_date', 'show_admin_bar_front', 'show_welcome_panel', 'show_highlight', 'admin_color', 'language_pairs', 'first_name', 'last_name', 'name', 'nickname', 'description', 'yim', 'jabber', 'aim');
     $exclude_these_hidden_var = '/(' . implode('|', $unused_field) . ')/';
     $this->items = array(array(__('User ID', 'wpv-views'), 'wpv-user field="ID"', __('Basic', 'wpv-views'), ''), array(__('User Email', 'wpv-views'), 'wpv-user field="user_email"', __('Basic', 'wpv-views'), ''), array(__('User Login', 'wpv-views'), 'wpv-user field="user_login"', __('Basic', 'wpv-views'), ''), array(__('First Name', 'wpv-views'), 'wpv-user field="user_firstname"', __('Basic', 'wpv-views'), ''), array(__('Last Name', 'wpv-views'), 'wpv-user field="user_lastname"', __('Basic', 'wpv-views'), ''), array(__('Nickname', 'wpv-views'), 'wpv-user field="nickname"', __('Basic', 'wpv-views'), ''), array(__('Display Name', 'wpv-views'), 'wpv-user field="display_name"', __('Basic', 'wpv-views'), ''), array(__('Description', 'wpv-views'), 'wpv-user field="description"', __('Basic', 'wpv-views'), ''), array(__('Yahoo IM', 'wpv-views'), 'wpv-user field="yim"', __('Basic', 'wpv-views'), ''), array(__('Jabber', 'wpv-views'), 'wpv-user field="jabber"', __('Basic', 'wpv-views'), ''), array(__('AIM', 'wpv-views'), 'wpv-user field="aim"', __('Basic', 'wpv-views'), ''), array(__('User Url', 'wpv-views'), 'wpv-user field="user_url"', __('Basic', 'wpv-views'), ''), array(__('Registration Date', 'wpv-views'), 'wpv-user field="user_registered"', __('Basic', 'wpv-views'), ''), array(__('User Status', 'wpv-views'), 'wpv-user field="user_status"', __('Basic', 'wpv-views'), ''), array(__('User Spam Status', 'wpv-views'), 'wpv-user field="spam"', __('Basic', 'wpv-views'), ''));
     if (isset($sitepress) && function_exists('wpml_string_shortcode')) {
         $this->items[] = array(__('Translatable string', 'wpv-views'), 'wpml-string', __('Basic', 'wpv-views'), 'wpv_insert_translatable_string_popup()');
     }
     $meta_keys = get_user_meta_keys();
     $all_types_fields = get_option('wpcf-fields', array());
     foreach ($meta_keys as $key) {
         $key_nicename = '';
         if (function_exists('wpcf_init')) {
             if (stripos($key, 'wpcf-') === 0) {
                 //
             } else {
                 if (preg_match($exclude_these_hidden_var, $key)) {
                     continue;
                 }
                 $this->items[] = array($key, 'wpv-user field="' . $key . '"', __('Users fields', 'wpv-views'), '');
             }
         } else {
             if (preg_match($exclude_these_hidden_var, $key)) {
                 continue;
             }
             $this->items[] = array($key, 'wpv-user field="' . $key . '"', __('User fields', 'wpv-views'), '');
         }
     }
     if (function_exists('wpcf_init')) {
         //Get types groups and fields
         $groups = wpcf_admin_fields_get_groups('wp-types-user-group');
         $user_id = wpcf_usermeta_get_user();
         $add = array();
         if (!empty($groups)) {
             foreach ($groups as $group_id => $group) {
                 if (empty($group['is_active'])) {
                     continue;
                 }
                 $fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true, 'wp-types-user-group', 'wpcf-usermeta');
                 if (!empty($fields)) {
                     foreach ($fields as $field_id => $field) {
                         $add[] = $field['meta_key'];
                         $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'views-usermeta\', -1)';
                         $this->items[] = array($field['name'], 'types usermeta="' . $field['meta_key'] . '"][/types', $group['name'], $callback);
                     }
                 }
             }
         }
         //Get unused types fields
         $cf_types = wpcf_admin_fields_get_fields(true, true, false, 'wpcf-usermeta');
         foreach ($cf_types as $cf_id => $cf) {
             if (!in_array($cf['meta_key'], $add)) {
                 $callback = 'wpcfFieldsEditorCallback(\'' . $cf['id'] . '\', \'views-usermeta\', -1)';
                 $this->items[] = array($cf['name'], 'types usermeta="' . $cf['meta_key'] . '"][/types', __('Types fields', 'wpv-views'), $callback);
             }
         }
     }
     $view_available = $wpdb->get_results("SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type='view' AND post_status in ('publish')");
     foreach ($view_available as $view) {
         $view_settings = get_post_meta($view->ID, '_wpv_settings', true);
         if (isset($view_settings['query_type'][0]) && $view_settings['query_type'][0] == 'posts' && !$WP_Views->is_archive_view($view->ID)) {
             $this->items[] = array($view->post_title, $view->post_title, __('Post View', 'wpv-views'), '');
         }
     }
     $out = array();
     $menus = array();
     $sub_menus = array();
     if ($this->items) {
         foreach ($this->items as $item) {
             $parts = explode('-!-', $item[2]);
             $menu_level =& $menus;
             foreach ($parts as $part) {
                 if ($part != '') {
                     if (!array_key_exists($part, $menu_level)) {
                         $menu_level[$part] = array();
                     }
                     $menu_level =& $menu_level[$part];
                 }
             }
             $menu_level[$item[0]] = $item;
         }
     }
     // Sort menus
     if (is_array($menus)) {
         $menus = $this->sort_menus_alphabetically($menus);
     }
     $this->_media_menu_direct_links = array();
     $menus_output = $this->_output_media_menu($menus, $text_area, $standard_v);
     $direct_links = implode(' ', $this->_media_menu_direct_links);
     $dropdown_class = 'js-editor_addon_dropdown-' . $this->name;
     $icon_class = 'js-wpv-shortcode-post-icon-' . $this->name;
     $addon_button = '<img src="' . $this->media_button_image . '" class="wpv-shortcode-post-icon ' . $icon_class . '" />';
     if (!$standard_v) {
         $addon_button = '<img src="' . $this->media_button_image . '" class="vicon wpv-shortcode-post-icon ' . $icon_class . '" />';
     }
     // Codemirrir (new layout) button
     if ($codemirror_button) {
         $addon_button = '<button class="js-code-editor-toolbar-button js-code-editor-toolbar-button-v-icon button-secondary">' . '<i class="icon-views"></i><span class="button-label">' . __('Fields', 'wpv-views') . '</span></button>';
     }
     // add search box
     $searchbar = $this->get_search_bar();
     // generate output content
     $out = '' . $addon_button . '
     <div class="editor_addon_dropdown ' . $dropdown_class . '" id="editor_addon_dropdown_' . md5(serialize(debug_backtrace())) . '">
         <h3 class="title">' . $this->button_text . '</h3>
         <div class="close">&nbsp;</div>
         <div class="editor_addon_dropdown_content">
                 ' . apply_filters('editor_addon_dropdown_top_message_' . $this->name, '') . '
                 <p class="direct-links-desc">' . __('Go to', 'wpv-views') . ': </p>
                 <ul class="direct-links">' . $direct_links . '</ul>
                 ' . $searchbar . '
                 ' . $menus_output . '
                 ' . apply_filters('editor_addon_dropdown_bottom_message' . $this->name, '') . '
         </div>
     </div>';
     // WP 3.3 changes
     if (version_compare($wp_version, '3.1.4', '>')) {
         echo apply_filters('wpv_add_media_buttons', $out);
     } else {
         return apply_filters('wpv_add_media_buttons', $context . $out);
     }
 }
 public function __construct()
 {
     //Get list of groups
     self::$fields_groups = wpcf_admin_fields_get_groups();
     // setup custom capabilities
     //If access plugin installed
     if (function_exists('wpcf_access_register_caps')) {
         // integrate with Types Access
         if (!empty(self::$fields_groups)) {
             $access_version = apply_filters('toolset_access_version_installed', '1.0');
             // Since 2.1 we can define a custom tab on Access >= 2.1
             if (version_compare($access_version, '2.0') > 0) {
                 // Add Types Fields tab
                 add_filter('types-access-tab', array('Post_Fields_Access', 'register_access_types_fields_tab'));
                 //Add Usermeta Fields area
                 add_filter('types-access-area-for-types-fields', array('Post_Fields_Access', 'register_access_fields_area'), 10, 2);
             } else {
                 //Add Usermeta Fields area
                 add_filter('types-access-area', array('Post_Fields_Access', 'register_access_fields_area'), 10, 2);
             }
             //Add Fields groups
             add_filter('types-access-group', array('Post_Fields_Access', 'register_access_fields_groups'), 10, 2);
             //Add Fields caps to groups
             add_filter('types-access-cap', array('Post_Fields_Access', 'register_access_fields_caps'), 10, 3);
             //}
         }
     }
 }
Example #24
0
/**
 * Adds items to view dropdown.
 * 
 * @param type $items
 * @return type 
 */
function wpcf_admin_post_editor_addon_menus_filter($items)
{
    $groups = wpcf_admin_fields_get_groups();
    $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();
        $all_post_types = implode(' ', get_post_types(array('public' => true)));
        foreach ($groups as $group_id => $group) {
            $fields = 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) {
                    // Get field data
                    $data = wpcf_fields_type_action($field['type']);
                    // Get inherited field
                    if (isset($data['inherited_field_type'])) {
                        $inherited_field_data = wpcf_fields_type_action($data['inherited_field_type']);
                    }
                    $callback = '';
                    if (isset($data['editor_callback'])) {
                        $callback = sprintf($data['editor_callback'], $field['id']);
                    } else {
                        // Set callback if function exists
                        $function = 'wpcf_fields_' . $field['type'] . '_editor_callback';
                        $callback = function_exists($function) ? 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\')' : '';
                    }
                    $add[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback);
                    // Process JS
                    if (!empty($data['meta_box_js'])) {
                        foreach ($data['meta_box_js'] as $handle => $data_script) {
                            if (isset($data_script['inline'])) {
                                add_action('admin_footer', $data_script['inline']);
                                continue;
                            }
                            $deps = !empty($data_script['deps']) ? $data_script['deps'] : array();
                            wp_enqueue_script($handle, $data_script['src'], $deps, WPCF_VERSION);
                        }
                    }
                    // Process CSS
                    if (!empty($data['meta_box_css'])) {
                        foreach ($data['meta_box_css'] as $handle => $data_script) {
                            $deps = !empty($data_script['deps']) ? $data_script['deps'] : array();
                            if (isset($data_script['inline'])) {
                                add_action('admin_header', $data_script['inline']);
                                continue;
                            }
                            wp_enqueue_style($handle, $data_script['src'], $deps, WPCF_VERSION);
                        }
                    }
                }
            }
        }
    }
    $search_key = '';
    // Iterate all items to be displayed in the "V" menu
    foreach ($items as $key => $item) {
        if ($key == __('Basic', 'wpv-views')) {
            $search_key = 'found';
            continue;
        }
        if ($search_key == 'found') {
            $search_key = $key;
        }
        if ($key == __('Field', 'wpv-views') && isset($item[trim(wpcf_types_get_meta_prefix(), '-')])) {
            unset($items[$key][trim(wpcf_types_get_meta_prefix(), '-')]);
        }
    }
    if (empty($search_key) || $search_key == 'found') {
        $search_key = count($items);
    }
    $insert_position = array_search($search_key, array_keys($items));
    $part_one = array_slice($items, 0, $insert_position);
    $part_two = array_slice($items, $insert_position);
    $items = $part_one + $add + $part_two;
    // apply CSS styles to each item based on post types
    foreach ($items as $key => $value) {
        if (isset($item_styles[$key])) {
            $items[$key]['css'] = $item_styles[$key];
        } else {
            $items[$key]['css'] = $all_post_types;
        }
    }
    return $items;
}
Example #25
0
/**
 * Gets all groups and fields for post.
 *
 * Core function. Works and stable. Do not move or change.
 * If required, add hooks only.
 *
 * @param type $post_ID
 * @return type
 */
function wpcf_admin_usermeta_get_groups_fields()
{
    wpcf_enqueue_scripts();
    $post = array();
    // Filter groups
    $groups = array();
    $groups_all = wpcf_admin_fields_get_groups(TYPES_USER_META_FIELD_GROUP_CPT_NAME);
    foreach ($groups_all as $temp_key => $temp_group) {
        if (empty($temp_group['is_active'])) {
            unset($groups_all[$temp_key]);
            continue;
        }
        $passed = 1;
        if (!$passed) {
            unset($groups_all[$temp_key]);
        } else {
            $groups_all[$temp_key]['fields'] = wpcf_admin_fields_get_fields_by_group($temp_group['id'], 'slug', true, false, true, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta');
        }
    }
    $groups = $groups_all;
    return $groups;
}
/**
 * Adds items to view dropdown.
 * 
 * @param type $items
 * @return type 
 */
function wpcf_admin_post_editor_addon_menus_filter($items)
{
    $groups = wpcf_admin_fields_get_groups();
    $add = array();
    if (!empty($groups)) {
        foreach ($groups as $group_id => $group) {
            $fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true);
            if (!empty($fields)) {
                foreach ($fields as $field_id => $field) {
                    // Get field data
                    $data = wpcf_fields_type_action($field['type']);
                    // Get inherited field
                    if (isset($data['inherited_field_type'])) {
                        $inherited_field_data = wpcf_fields_type_action($data['inherited_field_type']);
                    }
                    $callback = '';
                    if (isset($data['editor_callback'])) {
                        $callback = sprintf($data['editor_callback'], $field['id']);
                    } else {
                        // Set callback if function exists
                        $function = 'wpcf_fields_' . $field['type'] . '_editor_callback';
                        $callback = function_exists($function) ? 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\')' : '';
                    }
                    $add[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback);
                    // Process JS
                    if (!empty($data['meta_box_js'])) {
                        foreach ($data['meta_box_js'] as $handle => $data_script) {
                            if (isset($data_script['inline'])) {
                                add_action('admin_footer', $data_script['inline']);
                                continue;
                            }
                            $deps = !empty($data_script['deps']) ? $data_script['deps'] : array();
                            wp_enqueue_script($handle, $data_script['src'], $deps, WPCF_VERSION);
                        }
                    }
                    // Process CSS
                    if (!empty($data['meta_box_css'])) {
                        foreach ($data['meta_box_css'] as $handle => $data_script) {
                            $deps = !empty($data_script['deps']) ? $data_script['deps'] : array();
                            if (isset($data_script['inline'])) {
                                add_action('admin_header', $data_script['inline']);
                                continue;
                            }
                            wp_enqueue_style($handle, $data_script['src'], $deps, WPCF_VERSION);
                        }
                    }
                }
            }
        }
    }
    $search_key = '';
    foreach ($items as $key => $item) {
        if ($key == __('Basic', 'wpv-views')) {
            $search_key = 'found';
            continue;
        }
        if ($search_key == 'found') {
            $search_key = $key;
        }
        if ($key == __('Field', 'wpv-views') && isset($item[trim(wpcf_types_get_meta_prefix(), '-')])) {
            unset($items[$key][trim(wpcf_types_get_meta_prefix(), '-')]);
        }
    }
    if (empty($search_key) || $search_key == 'found') {
        $search_key = count($items);
    }
    $insert_position = array_search($search_key, array_keys($items));
    $part_one = array_slice($items, 0, $insert_position);
    $part_two = array_slice($items, $insert_position);
    $items = $part_one + $add + $part_two;
    return $items;
}
Example #27
0
/**
 * Adds items to view dropdown.
 *
 * Core function. Works and stable. Do not move or change.
 * If required, add hooks only.
 *
 * @todo Remove (to WPCF_WPViews)
 *
 * @param type $menu
 * @return type
 */
function wpcf_admin_post_editor_addon_menus_filter($menu)
{
    global $wpcf;
    $post = wpcf_admin_get_edited_post();
    if (empty($post)) {
        $post = (object) array('ID' => -1);
    }
    $groups = wpcf_admin_fields_get_groups('wp-types-group', 'group_active');
    $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();
        foreach ($groups as $group_id => $group) {
            $fields = 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) {
                    // Use field class
                    $wpcf->field->set($wpcf->post, $field);
                    // Get field data
                    $data = (array) $wpcf->field->config;
                    // Get inherited field
                    if (isset($data['inherited_field_type'])) {
                        $inherited_field_data = wpcf_fields_type_action($data['inherited_field_type']);
                    }
                    $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'postmeta\', ' . $post->ID . ')';
                    $menu[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback);
                    /*
                     * Since Types 1.2
                     * We use field class to enqueue JS and CSS
                     */
                    $wpcf->field->enqueue_script();
                    $wpcf->field->enqueue_style();
                }
            }
        }
    }
    /*
        $search_key = '';
    
        // Iterate all items to be displayed in the "V" menu
        foreach ( $items as $key => $item ) {
            if ( $key == __( 'Basic', 'wpv-views' ) ) {
                $search_key = 'found';
                continue;
            }
            if ( $search_key == 'found' ) {
                $search_key = $key;
            }
    
            if ( $key == __( 'Field', 'wpv-views' ) && isset( $item[trim( wpcf_types_get_meta_prefix(),
                                    '-' )] ) ) {
                unset( $items[$key][trim( wpcf_types_get_meta_prefix(), '-' )] );
            }
        }
        if ( empty( $search_key ) || $search_key == 'found' ) {
            $search_key = count( $items );
        }
    
        $insert_position = array_search( $search_key, array_keys( $items ) );
        $part_one = array_slice( $items, 0, $insert_position );
        $part_two = array_slice( $items, $insert_position );
        $items = $part_one + $add + $part_two;
    
        // apply CSS styles to each item based on post types
        foreach ( $items as $key => $value ) {
            if ( isset( $item_styles[$key] ) ) {
                $items[$key]['css'] = $item_styles[$key];
            } else {
                $items[$key]['css'] = $all_post_types;
            }
        }
    */
    return $menu;
}
/**
 * Adds items to view dropdown.
 *
 * Core function. Works and stable. Do not move or change.
 * If required, add hooks only.
 *
 * @todo Remove (to WPCF_WPViews)
 *
 * @param type $menu
 * @return type
 */
function wpcf_admin_post_editor_addon_menus_filter($menu)
{
    global $wpcf;
    $post = wpcf_admin_get_edited_post();
    if (empty($post)) {
        $post = (object) array('ID' => -1);
    }
    $groups = wpcf_admin_fields_get_groups(TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, 'group_active');
    $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();
        foreach ($groups as $group_id => $group) {
            $fields = 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) {
                    // Use field class
                    $wpcf->field->set($wpcf->post, $field);
                    // Get field data
                    $data = (array) $wpcf->field->config;
                    // Get inherited field
                    if (isset($data['inherited_field_type'])) {
                        $inherited_field_data = wpcf_fields_type_action($data['inherited_field_type']);
                    }
                    $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'postmeta\', ' . $post->ID . ')';
                    $menu[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback);
                    /*
                     * Since Types 1.2
                     * We use field class to enqueue JS and CSS
                     */
                    $wpcf->field->enqueue_script();
                    $wpcf->field->enqueue_style();
                }
            }
        }
    }
    return $menu;
}
Example #29
0
 /**
  *
  * @global object $wpdb
  *
  */
 function prepare_items()
 {
     global $wpdb;
     $wpcf_per_page = 15;
     // Get ours and enabled
     $cf_types = wpcf_admin_fields_get_fields(true, true);
     $__groups = wpcf_admin_fields_get_groups();
     foreach ($__groups as $__group_id => $__group) {
         $__groups[$__group_id]['fields'] = wpcf_admin_fields_get_fields_by_group($__group['id'], 'slug', false, true, false);
     }
     foreach ($cf_types as $cf_id => $cf) {
         foreach ($__groups as $__group) {
             if (isset($__group['fields'][$cf_id])) {
                 $cf_types[$cf_id]['groups'][$__group['id']] = $__group['name'];
             }
         }
         $cf_types[$cf_id]['groups_txt'] = empty($cf_types[$cf_id]['groups']) ? __('None', 'wpcf') : implode(', ', $cf_types[$cf_id]['groups']);
     }
     // Get others (cache this result?)
     $cf_other = $wpdb->get_results("\r\n\t\tSELECT meta_id, meta_key\r\n\t\tFROM {$wpdb->postmeta}\r\n\t\tGROUP BY meta_key\r\n\t\tHAVING meta_key NOT LIKE '\\_%'\r\n\t\tORDER BY meta_key");
     // Clean from ours
     foreach ($cf_other as $type_id => $type_data) {
         if (strpos($type_data->meta_key, WPCF_META_PREFIX) !== false) {
             $field_temp = wpcf_admin_fields_get_field(str_replace(WPCF_META_PREFIX, '', $type_data->meta_key));
             if (!empty($field_temp)) {
                 if (!empty($field_temp['data']['disabled'])) {
                     $cf_types[$field_temp['id']] = array('id' => $field_temp['id'], 'slug' => $type_data->meta_key, 'name' => $type_data->meta_key, 'type' => 0, 'groups_txt' => __('None', 'wpcf'));
                 } else {
                     unset($cf_other[$type_id]);
                 }
             } else {
                 if (wpcf_types_cf_under_control('check_exists', $type_data->meta_key)) {
                     unset($cf_other[$type_id]);
                 } else {
                     $cf_types[$type_data->meta_key] = array('id' => $type_data->meta_key, 'slug' => $type_data->meta_key, 'name' => $type_data->meta_key, 'type' => 0, 'groups_txt' => __('None', 'wpcf'));
                 }
             }
         } else {
             if (wpcf_types_cf_under_control('check_exists', $type_data->meta_key)) {
                 unset($cf_other[$type_id]);
             } else {
                 $cf_types[$type_data->meta_key] = array('id' => $type_data->meta_key, 'slug' => $type_data->meta_key, 'name' => $type_data->meta_key, 'type' => 0, 'groups_txt' => __('None', 'wpcf'));
             }
         }
     }
     // Set some values
     foreach ($cf_types as $cf_id_temp => $cf_temp) {
         if (empty($cf_temp['type']) || !empty($cf_temp['data']['controlled'])) {
             $cf_types[$cf_id_temp]['slug'] = $cf_temp['name'];
         } else {
             $cf_types[$cf_id_temp]['slug'] = wpcf_types_get_meta_prefix($cf_temp) . $cf_temp['slug'];
         }
     }
     // Order
     if (!empty($_REQUEST['orderby'])) {
         $sort_matches = array('c' => 'name', 'g' => 'groups_txt', 't' => 'slug', 'f' => 'type');
         $sorted_keys = array();
         $new_array = array();
         foreach ($cf_types as $cf_id_temp => $cf_temp) {
             if (isset($sort_matches[$_REQUEST['orderby']])) {
                 $sorted_keys[$cf_temp['id']] = strtolower($cf_temp[$sort_matches[$_REQUEST['orderby']]]);
             } else {
                 $sorted_keys[$cf_temp['id']] = strtolower($cf_temp[$sort_matches['c']]);
             }
         }
         asort($sorted_keys, SORT_STRING);
         if ('desc' == $_REQUEST['order']) {
             $sorted_keys = array_reverse($sorted_keys, true);
         }
         foreach ($sorted_keys as $cf_id_temp => $groups_txt) {
             $new_array[$cf_id_temp] = $cf_types[$cf_id_temp];
         }
         $cf_types = $new_array;
     }
     // Search
     if (!empty($_REQUEST['s'])) {
         $search_results = array();
         foreach ($cf_types as $search_id => $search_field) {
             if (strpos(strval($search_field['name']), strval(trim(stripslashes($_REQUEST['s'])))) !== false) {
                 $search_results[$search_id] = $cf_types[$search_id];
             }
         }
         $cf_types = $search_results;
     }
     if (empty($_GET['display_all'])) {
         $total_items = count($cf_types);
         if ($total_items < $wpcf_per_page) {
             $wpcf_per_page = $total_items;
         }
         if ($this->get_pagenum() == 1) {
             $offset = 0;
         } else {
             $offset = ($this->get_pagenum() - 1) * $wpcf_per_page;
         }
         // Display required number of entries on page
         $this->items = array_slice($cf_types, $offset, $wpcf_per_page);
         $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $wpcf_per_page));
     } else {
         $this->items = $cf_types;
     }
     $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
 }
function wpv_layout_wizard_add_field()
{
    // TODO this might need localization TODO this is seriously broken
    if (!isset($_POST["wpnonce"]) || !wp_verify_nonce($_POST["wpnonce"], 'layout_wizard_nonce')) {
        die("Undefined Nonce.");
    }
    global $WP_Views, $wpdb;
    $settings = $WP_Views->get_view_settings($_POST["view_id"]);
    $WP_Views->editor_addon = new Editor_addon('wpv-views', __('Insert Views Shortcodes', 'wpv-views'), WPV_URL . '/res/js/views_editor_plugin.js', WPV_URL . '/res/img/bw_icon16.png');
    if ((string) $settings["query_type"][0] == 'posts') {
        add_short_codes_to_js(array('body-view-templates', 'post', 'taxonomy', 'post-view', 'taxonomy-view', 'user-view'), $WP_Views->editor_addon);
    } else {
        if ((string) $settings["query_type"][0] == 'taxonomy') {
            add_short_codes_to_js(array('post-view', 'taxonomy-view', 'user-view'), $WP_Views->editor_addon);
        } else {
            if ((string) $settings["query_type"][0] == 'users') {
            }
        }
    }
    $fields_list = $WP_Views->editor_addon->get_fields_list();
    if (empty($fields_list)) {
        $fields_list = array();
    }
    $fields_accos = array();
    // Show taxonomy fields only if we are in Taxonomy mode
    if ((string) $settings["query_type"][0] == 'taxonomy') {
        $tax_fields = array();
        $tax_fields[__('Taxonomy title', 'wpv-views')] = 'wpv-taxonomy-title';
        $tax_fields[__('Taxonomy title with a link', 'wpv-views')] = 'wpv-taxonomy-link';
        $tax_fields[__('Taxonomy URL', 'wpv-views')] = 'wpv-taxonomy-url';
        $tax_fields[__('Taxonomy slug', 'wpv-views')] = 'wpv-taxonomy-slug';
        $tax_fields[__('Taxonomy description', 'wpv-views')] = 'wpv-taxonomy-description';
        $tax_fields[__('Taxonomy post count', 'wpv-views')] = 'wpv-taxonomy-post-count';
        foreach ($tax_fields as $name => $value) {
            $fields_accos[__('Taxonomy fields', 'wpv-views')][] = array($name, $value);
        }
    }
    if ((string) $settings["query_type"][0] == 'users') {
        $user_fields = array();
        $user_fields[__('User ID', 'wpv-views')] = 'wpv-user field="ID"';
        $user_fields[__('User Email', 'wpv-views')] = 'wpv-user field="user_email"';
        $user_fields[__('User Login', 'wpv-views')] = 'wpv-user field="user_login"';
        $user_fields[__('First Name', 'wpv-views')] = 'wpv-user field="user_firstname"';
        $user_fields[__('Last Name', 'wpv-views')] = 'wpv-user field="user_lastname"';
        $user_fields[__('Nickname', 'wpv-views')] = 'wpv-user field="nickname"';
        $user_fields[__('Display Name', 'wpv-views')] = 'wpv-user field="display_name"';
        $user_fields[__('Description', 'wpv-views')] = 'wpv-user field="description"';
        $user_fields[__('Yahoo IM', 'wpv-views')] = 'wpv-user field="yim"';
        $user_fields[__('Jabber', 'wpv-views')] = 'wpv-user field="jabber"';
        $user_fields[__('AIM', 'wpv-views')] = 'wpv-user field="aim"';
        $user_fields[__('User Url', 'wpv-views')] = 'wpv-user field="user_url"';
        $user_fields[__('Registration Date', 'wpv-views')] = 'wpv-user field="user_registered"';
        $user_fields[__('User Status', 'wpv-views')] = 'wpv-user field="user_status"';
        $user_fields[__('User Spam Status', 'wpv-views')] = 'wpv-user field="spam"';
        foreach ($user_fields as $name => $value) {
            $fields_accos[__('Basic', 'wpv-views')][] = array($name, $value);
        }
        $unused_field = array('comment_shortcuts', 'managenav-menuscolumnshidden', 'dismissed_wp_pointers', 'meta-box-order_dashboard', 'nav_menu_recently_edited', 'primary_blog', 'rich_editing', 'source_domain', 'use_ssl', 'user_level', 'user-settings-time', 'user-settings', 'dashboard_quick_press_last_post_id', 'capabilities', 'new_date', 'show_admin_bar_front', 'show_welcome_panel', 'show_highlight', 'admin_color', 'language_pairs', 'first_name', 'last_name', 'name', 'nickname', 'description', 'yim', 'jabber', 'aim');
        $exclude_these_hidden_var = '/(' . implode('|', $unused_field) . ')/';
        $meta_keys = get_user_meta_keys();
        $all_types_fields = get_option('wpcf-fields', array());
        foreach ($meta_keys as $key) {
            $key_nicename = '';
            if (function_exists('wpcf_init')) {
                if (stripos($key, 'wpcf-') === 0) {
                    //
                } else {
                    if (preg_match($exclude_these_hidden_var, $key)) {
                        continue;
                    }
                    $fields_accos[__('Users fields', 'wpv-views')][] = array($key, 'wpv-user field="' . $key . '"');
                }
            } else {
                if (preg_match($exclude_these_hidden_var, $key)) {
                    continue;
                }
                $fields_accos[__('Users fields', 'wpv-views')][] = array($key, 'wpv-user field="' . $key . '"');
            }
        }
        if (function_exists('wpcf_init')) {
            // TODO do the same for wpcf-fields for posts
            //Get types groups and fields
            $groups = wpcf_admin_fields_get_groups('wp-types-user-group');
            $user_id = wpcf_usermeta_get_user();
            $add = array();
            if (!empty($groups)) {
                foreach ($groups as $group_id => $group) {
                    if (empty($group['is_active'])) {
                        continue;
                    }
                    $fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true, 'wp-types-user-group', 'wpcf-usermeta');
                    if (!empty($fields)) {
                        foreach ($fields as $field_id => $field) {
                            $add[] = $field['meta_key'];
                            $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'views-usermeta\', -1)';
                            /*$this->items[] = array($field['name'], 
                              'types usermeta="'.$field['meta_key'].'"][/types',
                              $group['name'],$callback);  */
                            $fields_accos[$group['name']][] = array($field['name'], 'types usermeta="' . $field['slug'] . '"][/types');
                        }
                    }
                }
            }
            //Get unused types fields
            $cf_types = wpcf_admin_fields_get_fields(true, true, false, 'wpcf-usermeta');
            foreach ($cf_types as $cf_id => $cf) {
                if (!in_array($cf['meta_key'], $add)) {
                    $callback = 'wpcfFieldsEditorCallback(\'' . $cf['id'] . '\', \'views-usermeta\', -1)';
                    /* $this->items[] = array($cf['name'], 
                       'types usermeta="'.$cf['meta_key'].'"][/types',
                       'Types fields',$callback); */
                    $fields_accos[__('Types fields', 'wpv-views')][] = array($cf['name'], 'types usermeta="' . $cf['slug'] . '"][/types');
                }
            }
        }
        $view_available = $wpdb->get_results("SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type='view' AND post_status in ('publish')");
        $fields_accos[__('Types fields', 'wpv-views')] = array();
        foreach ($view_available as $view) {
            $view_settings = get_post_meta($view->ID, '_wpv_settings', true);
            if (isset($view_settings['query_type'][0]) && $view_settings['query_type'][0] == 'posts' && !$WP_Views->is_archive_view($view->ID)) {
                $fields_accos[__('Post View', 'wpv-views')][] = array($view->post_title, 'wpv-view name="' . $view->post_title . '"');
            }
        }
    }
    $content_templates = array('Content template' => array(array('None', 'wpv-post-body view_template="None"')));
    if (function_exists('types_get_fields')) {
        $tmp = types_get_fields();
    } else {
        $tmp = array();
    }
    if (isset($tmp['fields'])) {
        $tmp = $tmp['fields'];
    }
    foreach ($fields_list as $items) {
        if (function_exists('wpcf_admin_fields_get_groups_by_field') && (preg_match('/-!-wpcf/', $items[2]) || preg_match('/-!-views/', $items[2]) || preg_match('/wpcf-/', $items[0]) || preg_match('/\\[types.*?field=\\"(.*?)\\"/', $items[0]))) {
            if (preg_match('/\\[types.*?field=\\"(.*?)\\"/', $items[0], $outp)) {
                $split = $outp[1];
            } else {
                $split = preg_replace('/wpcf-/', '', $items[0]);
            }
            //Field name, not a slug
            if (isset($tmp[$split]['name'])) {
                // if: fix PHP Notice in the AJAX response when showing hidden fields
                $items[0] = $tmp[$split]['name'];
                $group = wpcf_admin_fields_get_groups_by_field($tmp[$split]['id']);
                foreach ($group as $id => $params) {
                    $group = $params['name'];
                }
            }
        } else {
            if ($items[2] == 'Field' || strpos($items[2], 'Field') === 0) {
                $items[2] = 'Custom fields';
            }
            $group = $items[2];
        }
        if ($items[2] == __('Content template', 'wpv-views')) {
            //    global $wpdb;
            //  $items[0] = $wpdb->get_var("SELECT post_title  FROM {$wpdb->posts} WHERE post_title = '{$items[0]}'");
            $content_templates['Content template'][] = array($items[0], $items[1]);
        }
        if ($items[1] == 'wpml-string') {
            // Take out of the Layout Wizard the new wpml-string Translatable string shortcode added to V popups
            $group = '';
        }
        if (!empty($group)) {
            $fields_accos[$group][] = array($items[0], $items[1]);
        }
    }
    if ((string) $settings["query_type"][0] == 'posts') {
        // add taxonomies
        $assoc = array();
        $taxonomies = get_taxonomies(array(), 'objects');
        $exclude_tax_slugs = array();
        $exclude_tax_slugs = apply_filters('wpv_admin_exclude_tax_slugs', $exclude_tax_slugs);
        foreach ($taxonomies as $tname => $tax) {
            if (!in_array($tname, $exclude_tax_slugs) && $tax->show_ui) {
                $assoc['Taxonomies'][] = array($tax->label, 'wpv-post-taxonomy type="' . $tname . '" separator=", " format="link" show="name"');
            }
        }
        // add user meta fields
        if (function_exists('wpcf_admin_post_add_usermeta_to_editor_js')) {
            $usermeta_fields_list = wpcf_admin_post_add_usermeta_to_editor_js(array());
            foreach ($usermeta_fields_list as $group => $items) {
                foreach ($items as $field) {
                    $assoc[$group][] = array($field[0], $field[1]);
                }
            }
        }
        // Add after the Basic fields.
        $fields_accos = array_slice($fields_accos, 0, 1, true) + $assoc + array_slice($fields_accos, 1, count($fields_accos) - 1, true);
    }
    ob_start();
    ?>
<li id="layout-wizard-style_<?php 
    echo isset($_POST['id']) ? $_POST['id'] : $count;
    ?>
">
    <i class="icon-move js-layout-wizard-move-field"></i>
    <select name="layout-wizard-style" class="js-select2 js-layout-wizard-item">
        <?php 
    $selected_value = '';
    $typename = '';
    $selected_body = '';
    $selected_body_template = '';
    $selected_found = false;
    $user_fields_with_head = array('user_email', 'display_name', 'user_login', 'user_url', 'user_registered', 'user_status', 'spam');
    if (!isset($_POST['selected'])) {
        $_POST['selected'] = '';
    }
    foreach ($fields_accos as $group_title => $group_items) {
        ?>
            <optgroup label="<?php 
        echo $group_title;
        ?>
">
                <?php 
        foreach ($group_items as $items) {
            $value = $items[1];
            $istype = false;
            $typename2 = '';
            $selected = mysql_real_escape_string($_POST['selected']) == '[' . mysql_real_escape_string($items[1]) . ']' ? "selected" : "";
            $selected_striped = substr(stripslashes($_POST['selected']), 1, -1);
            if ($selected_striped == stripslashes($value)) {
                // Dirty hack: sometimes the selected item was not being set for user shortcodes
                $selected = "selected";
                if (preg_match('/\\[types.*usermeta=\\"(.*?)\\"/', $_POST['selected'], $outp)) {
                    $typename = $outp[1];
                }
            }
            $_POST['selected'] = stripslashes($_POST['selected']);
            if (!$selected && preg_match('/wpv-post-taxonomy/', $items[1]) && trim($_POST['selected'], '[]') == $items[1]) {
                $selected = 'selected';
            }
            if (!$selected && preg_match('/wpv-view/', $items[1]) && trim($_POST['selected'], '[]') == $items[1]) {
                $selected = 'selected';
            }
            if (!$selected && preg_match('/\\[types.*?field=\\"(.*?)\\"/', $_POST['selected']) && preg_match('/"wpcf\\-.*?"/', $items[1])) {
                preg_match('/\\[types.*?field=\\"(.*?)\\"/', $_POST['selected'], $outp);
                $sel = $outp[1];
                preg_match('/"wpcf\\-(.*?)"/', $items[1], $outp);
                $cur = $outp[1];
                $items[1] = trim($_POST['selected'], '[]');
                $selected = $cur == $sel ? 'selected' : '';
                $typename = $sel;
            }
            if (!$selected && preg_match('/\\[types.*usermeta=\\"(.*?)\\"/', $_POST['selected']) && preg_match('/types.*usermeta=\\"(.*?)\\"/', $items[1])) {
                preg_match('/\\[types.*usermeta=\\"(.*?)\\"/', $_POST['selected'], $outp);
                $sel = $outp[1];
                preg_match('/types.*usermeta=\\"(.*?)\\"/', $items[1], $outp);
                $cur = $outp[1];
                $usermeta_field = $sel;
                $items[1] = trim($_POST['selected'], '[]');
                $selected = $cur == $sel ? 'selected' : '';
                if ($selected) {
                    $value = $items[1];
                }
                $typename = $sel;
                $typename2 = $cur;
                $istype = true;
            }
            if (!$selected && preg_match('/wpv-post-body/', $_POST['selected']) && preg_match('/Body/', $items[0])) {
                $selected_body = $items[0];
                preg_match('/view_template\\="(.*?)"/', $_POST['selected'], $out);
                $selected_body_template = $out[1];
                global $wpdb;
                $selected_body_template = $wpdb->get_var("SELECT post_title FROM {$wpdb->posts} WHERE post_name = '{$selected_body_template}'");
                //     $value = trim($_POST['selected'], '[]');
                //     if (!$selected_body_template) {
                //     $value = $items[1];
                //     }
                $selected = 'selected';
            }
            if ($selected == 'selected') {
                $selected_value = $items[1];
                $selected_found = true;
            }
            $s = preg_match('/"wpcf\\-(.*?)"/', $value, $outp);
            if ($s) {
                $saved_fields = array();
                $sets = get_post_meta($_POST["view_id"], '_wpv_layout_settings', true);
                if (isset($sets["real_fields"])) {
                    $saved_fields = $sets["real_fields"];
                }
                $typename2 = $outp[1];
                $value = isset($saved_fields[$_POST["id"]]) && preg_match('/types.*?field=\\"' . $outp[1] . '\\"/', $saved_fields[$_POST["id"]]) ? trim($saved_fields[$_POST["id"]], '[]') : 'types field="' . $outp[1] . '" id=""][/types';
                $istype = true;
                if (!function_exists('wpcf_init')) {
                    $istype = false;
                    if (strpos($items[1], 'wpv-user') === 0) {
                        $value = $items[1];
                    } else {
                        $value = 'wpv-post-field name="wpcf-' . $outp[1] . '"';
                    }
                }
            }
            $head = '';
            if (substr($value, 0, 17) === "wpv-post-taxonomy") {
                $head = 'wpv-post-taxonomy';
            } else {
                if (substr($value, 0, 14) === "wpv-post-field") {
                    $head = 'post-field-' . $items[0];
                    // if it is a new WooCommerce Views field
                    if (preg_match('/\\wpv-post-field.*?name=\\"views_woo(.*?)\\"/', $value, $woo_match)) {
                        $head = 'post-field-views_woo' . $woo_match[1];
                    }
                } else {
                    if (substr($value, 0, 8) === "wpv-post") {
                        $head = substr(current(explode(' ', $value)), 4);
                        if (substr($value, 0, 15) === "wpv-post-status" || substr($value, 0, 14) === "wpv-post-class") {
                            $head = '';
                        }
                    } else {
                        if (substr($value, 0, 8) === "wpv-view") {
                            $head = 'post-view';
                        } else {
                            if (substr($value, 0, 5) === "types") {
                                if (!isset($outp[1]) && isset($usermeta_field)) {
                                    $outp[1] = $usermeta_field;
                                } else {
                                    if (!isset($outp[1])) {
                                        $outp[1] = '';
                                    }
                                }
                                if (empty($typename2)) {
                                    $typename2 = $outp[1];
                                }
                                $head = 'types-field-' . $outp[1];
                                // Add a table column header only if it's a field for posts
                                if (empty($typename2) || empty($outp[1])) {
                                    preg_match("/(usermeta|field)=\"([^\"]+)\"/", $value, $new_match);
                                    $typename2 = $outp[1] = $new_match[2];
                                    $head = '';
                                    // If it's a usermeta field, do not add the table column header
                                }
                                if (!empty($typename2)) {
                                    $istype = true;
                                }
                            } else {
                                if (substr($value, 0, 12) === "wpv-taxonomy") {
                                    // heading table solumns for wpv-taxonomy-* shortcodes
                                    if (in_array($value, array('wpv-taxonomy-link', 'wpv-taxonomy-title'))) {
                                        $head = substr($value, 4);
                                    }
                                    if ($value == 'wpv-taxonomy-post-count') {
                                        $head = 'taxonomy-post_count';
                                    }
                                } else {
                                    if (substr($value, 0, 8) === "wpv-user") {
                                        // heaading table columns for wpv-user shortcodes
                                        preg_match('/\\wpv-user.*?field=\\"(.*?)\\"/', $value, $new_match);
                                        if (isset($new_match[1]) && in_array($new_match[1], $user_fields_with_head)) {
                                            $head = $new_match[1];
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            ?>
                    <option value="<?php 
            echo base64_encode('[' . $value . ']');
            ?>
"
                            data-fieldname="<?php 
            echo $items[0];
            ?>
"
                            data-headename="<?php 
            echo $head;
            ?>
"
                            <?php 
            if ($istype) {
                ?>
                            
                            data-istype="1"
                            data-typename="<?php 
                echo $typename2;
                ?>
"
                            <?php 
            }
            ?>
                            data-rowtitle="<?php 
            echo $items[0];
            ?>
" <?php 
            echo $selected;
            ?>
>
                        <?php 
            echo $items[0];
            ?>
                    </option>

                <?php 
        }
        ?>
            </optgroup>
        <?php 
    }
    ?>
    </select>
    <?php 
    //aditional combo for body-templates
    ?>

    <p class="layout-wizard-body-template-text js-layout-wizard-body-template-text <?php 
    if (!preg_match('/wpv-post-body/', $_POST['selected']) || !empty($selected_body_template)) {
        ?>
hidden<?php 
    }
    ?>
"><?php 
    echo __('Using Content Template', 'wpv-views');
    ?>
</p>
    <select name="layout-wizard-body-template" class="layout-wizard-body-template <?php 
    if (!preg_match('/wpv-post-body/', $_POST['selected']) || !empty($selected_body_template)) {
        ?>
hidden<?php 
    }
    ?>
">
        <?php 
    foreach ($content_templates['Content template'] as $items) {
        ?>
        	<option value="<?php 
        echo base64_encode('[' . $items[1] . ']');
        ?>
" data-rowtitle="<?php 
        echo $items[0];
        ?>
" <?php 
        if (trim($items[0]) == trim($selected_body_template)) {
            echo 'selected';
        }
        ?>
 > <?php 
        echo $items[0];
        ?>
</option>
        <?php 
    }
    ?>
    </select>
    <?php 
    if ((string) $settings["query_type"][0] == 'users') {
        $type_usermeta_addon = ' data-type="views-usermeta"';
    }
    ?>
    <button class="button-secondary js-custom-types-fields" 
    <?php 
    if (!preg_match('/types.*?field=|types.*?usermeta=/', $selected_value) || !function_exists('types_get_fields')) {
        ?>
 style="display: none" <?php 
    } else {
        ?>
  rel="<?php 
        echo $typename;
        ?>
" <?php 
    }
    ?>
        <?php 
    if (isset($type_usermeta_addon)) {
        echo $type_usermeta_addon;
    }
    ?>
>
    	<?php 
    echo __('Edit', 'wpv-views');
    ?>
    </button>
    <i class="icon-remove-sign js-layout-wizard-remove-field"></i>
</li>
<?php 
    $result = array('html' => ob_get_clean(), 'selected_found' => $selected_found);
    echo json_encode($result);
    die;
}