/** ************************************************************************
  * Recommended. This method is called when the parent class can't find a method
  * specifically build for a given column. Generally, it's recommended to include
  * one method for each column you want to render, keeping your package class
  * neat and organized. For example, if the class needs to process a column
  * named 'title', it would first see if a method named $this->column_title()
  * exists - if it does, that method will be used. If it doesn't, this one will
  * be used. Generally, you should try to use custom column methods as much as
  * possible.
  *
  * Since we have defined a column_title() method later on, this method doesn't
  * need to concern itself with any column with a name of 'title'. Instead, it
  * needs to handle everything else.
  *
  * For more detailed insight into how columns are handled, take a look at
  * WP_List_Table::single_row_columns()
  *
  * @param array $item A singular item (one full row's worth of data)
  * @param array $column_name The name/slug of the column to be processed
  * @return string Text or HTML to be placed inside the column <td>
  **************************************************************************/
 function column_default($item, $column_name)
 {
     switch ($column_name) {
         case 'title':
         case 'description':
             return stripslashes($item[$column_name]);
         case 'post_types':
             $post_types = wpcf_admin_get_post_types_by_group($item['id']);
             return empty($post_types) ? __('All post types', 'wpcf') : implode(', ', $post_types);
             break;
         case 'taxonomies':
             $taxonomies = wpcf_admin_get_taxonomies_by_group($item['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 />';
                 }
             }
             return $output;
         case 'status':
             return 'active' == $item[$column_name] ? __('Yes', 'wpcf') : __('No', 'wpcf');
         default:
             return print_r($item, true);
             //Show the whole array for troubleshooting purposes
     }
 }
Ejemplo n.º 2
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');
}
Ejemplo n.º 3
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');
}
Ejemplo n.º 4
0
/**
 * Generates form data.
 */
function wpcf_admin_fields_form()
{
    wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\'');
    wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\'');
    $default = array();
    // If it's update, get data
    $update = false;
    if (isset($_REQUEST['group_id'])) {
        $update = wpcf_admin_fields_get_group(intval($_REQUEST['group_id']));
        if (empty($update)) {
            $update = false;
            wpcf_admin_message(sprintf(__("Group with ID %d do not exist", 'wpcf'), intval($_REQUEST['group_id'])));
        } else {
            $update['fields'] = wpcf_admin_fields_get_fields_by_group($_REQUEST['group_id']);
            $update['post_types'] = wpcf_admin_get_post_types_by_group($_REQUEST['group_id']);
            $update['taxonomies'] = wpcf_admin_get_taxonomies_by_group($_REQUEST['group_id']);
            $update['templates'] = wpcf_admin_get_templates_by_group($_REQUEST['group_id']);
        }
    }
    $form = array();
    $form['#form']['callback'] = array('wpcf_admin_save_fields_groups_submit');
    // Form sidebars
    $form['open-sidebar'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-fields-align-right">');
    $form['submit2'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary'));
    $form['fields'] = array('#type' => 'fieldset', '#title' => __('Available fields', 'wpcf'));
    // Get field types
    $fields_registered = wpcf_admin_fields_get_available_types();
    //    foreach (glob(WPCF_EMBEDDED_INC_ABSPATH . '/fields/*.php') as $filename) {
    foreach ($fields_registered as $filename => $data) {
        //        require_once $filename;
        //        if (function_exists('wpcf_fields_' . basename($filename, '.php'))) {
        //            $data = call_user_func('wpcf_fields_' . basename($filename, '.php'));
        //            if (isset($data['wp_version']) && wpcf_compare_wp_version($data['wp_version'],
        //                            '<')) {
        //                continue;
        //            }
        $form['fields'][basename($filename, '.php')] = array('#type' => 'markup', '#markup' => '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax&amp;wpcf_action=fields_insert' . '&amp;field=' . basename($filename, '.php')) . '&amp;_wpnonce=' . wp_create_nonce('fields_insert') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary">' . $data['title'] . '</a> ');
        // Process JS
        if (!empty($data['group_form_js'])) {
            foreach ($data['group_form_js'] as $handle => $script) {
                if (isset($script['inline'])) {
                    add_action('admin_footer', $script['inline']);
                    continue;
                }
                $deps = !empty($script['deps']) ? $script['deps'] : array();
                $in_footer = !empty($script['in_footer']) ? $script['in_footer'] : false;
                wp_register_script($handle, $script['src'], $deps, WPCF_VERSION, $in_footer);
                wp_enqueue_script($handle);
            }
        }
        // Process CSS
        if (!empty($data['group_form_css'])) {
            foreach ($data['group_form_css'] as $handle => $script) {
                if (isset($script['src'])) {
                    $deps = !empty($script['deps']) ? $script['deps'] : array();
                    wp_enqueue_style($handle, $script['src'], $deps, WPCF_VERSION);
                } else {
                    if (isset($script['inline'])) {
                        add_action('admin_head', $script['inline']);
                    }
                }
            }
        }
        //        }
    }
    // Get fields created by user
    $fields = wpcf_admin_fields_get_fields(true, true);
    if (!empty($fields)) {
        $form['fields-existing'] = array('#type' => 'fieldset', '#title' => __('User created fields', 'wpcf'), '#id' => 'wpcf-form-groups-user-fields');
        foreach ($fields as $key => $field) {
            if (isset($update['fields']) && array_key_exists($key, $update['fields'])) {
                continue;
            }
            if (!empty($field['data']['removed_from_history'])) {
                continue;
            }
            $form['fields-existing'][$key] = array('#type' => 'markup', '#markup' => '<div id="wpcf-user-created-fields-wrapper-' . $field['id'] . '" style="float:left; margin-right: 10px;"><a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&amp;wpcf_action=fields_insert_existing' . '&amp;field=' . $field['id']) . '&amp;_wpnonce=' . wp_create_nonce('fields_insert_existing') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary" onclick="jQuery(this).parent().fadeOut();">' . htmlspecialchars(stripslashes($field['name'])) . '</a>' . '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&amp;wpcf_action=remove_from_history' . '&amp;field_id=' . $field['id']) . '&amp;_wpnonce=' . wp_create_nonce('remove_from_history') . '&amp;wpcf_warning=' . sprintf(__('Are you sure that you want to remove field %s from history?', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '&amp;wpcf_ajax_update=wpcf-user-created-fields-wrapper-' . $field['id'] . '" title="' . sprintf(__('Remove field %s', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '" class="wpcf-ajax-link"><img src="' . WPCF_RES_RELPATH . '/images/delete-2.png" style="postion:absolute;margin-top:5px;margin-left:-4px;" /></a></div>');
        }
    }
    $form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>');
    // Group data
    $form['open-main'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-form-fields-main">');
    $form['title'] = array('#type' => 'textfield', '#name' => 'wpcf[group][name]', '#id' => 'wpcf-group-name', '#value' => $update ? $update['name'] : __('Enter group title', 'wpcf'), '#inline' => true, '#attributes' => array('style' => 'width:100%;margin-bottom:10px;'), '#validate' => array('required' => array('value' => true)));
    if (!$update) {
        $form['title']['#attributes']['onfocus'] = 'if (jQuery(this).val() == \'' . __('Enter group title', 'wpcf') . '\') { jQuery(this).val(\'\'); }';
        $form['title']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(\'' . __('Enter group title', 'wpcf') . '\') }';
    }
    $form['description'] = array('#type' => 'textarea', '#id' => 'wpcf-group-description', '#name' => 'wpcf[group][description]', '#value' => $update ? $update['description'] : __('Enter a description for this group', 'wpcf'));
    if (!$update) {
        $form['description']['#attributes']['onfocus'] = 'if (jQuery(this).val() == \'' . __('Enter a description for this group', 'wpcf') . '\') { jQuery(this).val(\'\'); }';
        $form['description']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(\'' . __('Enter a description for this group', 'wpcf') . '\') }';
    }
    // Support post types and taxonomies
    $post_types = get_post_types('', 'objects');
    $options = array();
    $post_types_currently_supported = array();
    $form_types = array();
    foreach ($post_types as $post_type_slug => $post_type) {
        if (in_array($post_type_slug, array('attachment', 'revision', 'nav_menu_item', 'view', 'view-template')) || !$post_type->show_ui) {
            continue;
        }
        $options[$post_type_slug]['#name'] = 'wpcf[group][supports][' . $post_type_slug . ']';
        $options[$post_type_slug]['#title'] = $post_type->label;
        $options[$post_type_slug]['#default_value'] = $update && !empty($update['post_types']) && in_array($post_type_slug, $update['post_types']) ? 1 : 0;
        $options[$post_type_slug]['#value'] = $post_type_slug;
        $options[$post_type_slug]['#inline'] = TRUE;
        $options[$post_type_slug]['#suffix'] = '<br />';
        $options[$post_type_slug]['#id'] = 'wpcf-form-groups-support-post-type-' . $post_type_slug;
        $options[$post_type_slug]['#attributes'] = array('class' => 'wpcf-form-groups-support-post-type');
        if ($update && !empty($update['post_types']) && in_array($post_type_slug, $update['post_types'])) {
            $post_types_currently_supported[] = $post_type->label;
        }
    }
    if (empty($post_types_currently_supported)) {
        $post_types_currently_supported[] = __('Displayed on all content types', 'wpcf');
    }
    $post_types_no_currently_supported_txt = __('Post Types:', 'wpcf') . ' ' . __('Displayed on all content types', 'wpcf');
    $form_types = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'wpcf[group][supports]', '#inline' => true, '#before' => '<span id="wpcf-group-form-update-types-ajax-response"' . ' style="font-style:italic;font-weight:bold;display:inline-block;">' . __('Post Types:', 'wpcf') . ' ' . implode(', ', $post_types_currently_supported) . '</span>' . '&nbsp;&nbsp;<a href="javascript:void(0);" style="line-height: 30px;"' . ' class="button-secondary" onclick="' . 'window.wpcfPostTypesText = new Array(); window.wpcfFormGroupsSupportPostTypesState = new Array(); ' . 'jQuery(this).next().slideToggle()' . '.find(\'.checkbox\').each(function(index){' . 'if (jQuery(this).is(\':checked\')) { ' . 'window.wpcfPostTypesText.push(jQuery(this).next().html()); ' . 'window.wpcfFormGroupsSupportPostTypesState.push(jQuery(this).attr(\'id\'));' . '}' . '});' . ' jQuery(this).css(\'visibility\', \'hidden\');">' . __('Edit', 'wpcf') . '</a>' . '<div class="hidden" id="wpcf-form-fields-post_types">', '#after' => '<a href="javascript:void(0);" style="line-height: 35px;" ' . 'class="button-primary wpcf-groups-form-ajax-update-post-types-ok"' . ' onclick="window.wpcfPostTypesText = new Array(); window.wpcfFormGroupsSupportPostTypesState = new Array(); ' . 'jQuery(this).parent().slideUp().find(\'.checkbox\').each(function(index){' . 'if (jQuery(this).is(\':checked\')) { ' . 'window.wpcfPostTypesText.push(jQuery(this).next().html()); ' . 'window.wpcfFormGroupsSupportPostTypesState.push(jQuery(this).attr(\'id\'));' . '}' . '});' . 'if (window.wpcfPostTypesText.length < 1) { ' . 'jQuery(\'#wpcf-group-form-update-types-ajax-response\').html(\'' . $post_types_no_currently_supported_txt . '\'); ' . '} else { jQuery(\'#wpcf-group-form-update-types-ajax-response\').html(\'' . __('Post Types:', 'wpcf') . ' \'+wpcfPostTypesText.join(\', \'));}' . ' jQuery(this).parent().parent().children(\'a\').css(\'visibility\', \'visible\');' . '">' . __('OK', 'wpcf') . '</a>&nbsp;' . '<a href="javascript:void(0);" style="line-height: 35px;" ' . 'class="button-secondary wpcf-groups-form-ajax-update-post-types-cancel"' . ' onclick="jQuery(this).parent().slideUp().find(\'input\').removeAttr(\'checked\');' . 'if (window.wpcfFormGroupsSupportPostTypesState.length > 0) { ' . 'for (var element in window.wpcfFormGroupsSupportPostTypesState) { ' . 'jQuery(\'#\'+window.wpcfFormGroupsSupportPostTypesState[element]).attr(\'checked\', \'checked\'); }}' . 'jQuery(\'#wpcf-group-form-update-types-ajax-response\').html(\'' . __('Post Types:', 'wpcf') . ' \'+window.wpcfPostTypesText.join(\', \'));' . ' jQuery(this).parent().parent().children(\'a\').css(\'visibility\', \'visible\');' . '">' . __('Cancel', 'wpcf') . '</a>' . '</div></div><br />');
    $taxonomies = get_taxonomies('', 'objects');
    $options = array();
    $tax_currently_supported = array();
    $form_tax = array();
    $form_tax_single = array();
    foreach ($taxonomies as $category_slug => $category) {
        if ($category_slug == 'nav_menu' || $category_slug == 'link_category' || $category_slug == 'post_format') {
            continue;
        }
        $terms = get_terms($category_slug, array('hide_empty' => false));
        if (!empty($terms)) {
            $options = array();
            $add_title = '<div class="taxonomy-title">' . $category->labels->name . '</div>';
            $title = '';
            foreach ($terms as $term) {
                $checked = 0;
                if ($update && !empty($update['taxonomies']) && array_key_exists($category_slug, $update['taxonomies'])) {
                    if (array_key_exists($term->term_id, $update['taxonomies'][$category_slug])) {
                        $checked = 1;
                        $tax_currently_supported[$term->term_id] = $title . $term->name;
                        $title = '';
                    }
                }
                $options[$term->term_id]['#name'] = 'wpcf[group][taxonomies][' . $category_slug . '][' . $term->term_id . ']';
                $options[$term->term_id]['#title'] = $term->name;
                $options[$term->term_id]['#default_value'] = $checked;
                $options[$term->term_id]['#value'] = $term->term_id;
                $options[$term->term_id]['#inline'] = true;
                $options[$term->term_id]['#prefix'] = $add_title;
                $options[$term->term_id]['#suffix'] = '<br />';
                $options[$term->term_id]['#id'] = 'wpcf-form-groups-support-tax-' . $term->term_id;
                $options[$term->term_id]['#attributes'] = array('class' => 'wpcf-form-groups-support-tax');
                $add_title = '';
            }
            $form_tax_single['taxonomies-' . $category_slug] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'wpcf[group][taxonomies][' . $category_slug . ']', '#suffix' => '<br />', '#inline' => true);
        }
    }
    if (empty($tax_currently_supported)) {
        $tax_currently_supported[] = __('Not Selected', 'wpcf');
    }
    $tax_no_currently_supported_txt = __('Terms:', 'wpcf') . ' ' . __('Not Selected', 'wpcf');
    $form_tax['taxonomies-open'] = array('#type' => 'markup', '#markup' => '<span id="wpcf-group-form-update-tax-ajax-response" ' . 'style="font-style:italic;font-weight:bold;display:inline-block;">' . __('Terms:', 'wpcf') . ' ' . implode(', ', $tax_currently_supported) . '</span>' . '&nbsp;&nbsp;<a href="javascript:void(0);" style="line-height: 30px;" ' . 'class="button-secondary" onclick="' . 'window.wpcfTaxText = new Array(); window.wpcfFormGroupsSupportTaxState = new Array(); ' . 'jQuery(this).next().slideToggle()' . '.find(\'.checkbox\').each(function(index){' . 'if (jQuery(this).is(\':checked\')) { ' . 'window.wpcfTaxText.push(jQuery(this).next().html()); ' . 'window.wpcfFormGroupsSupportTaxState.push(jQuery(this).attr(\'id\'));' . '}' . '});' . ' jQuery(this).css(\'visibility\', \'hidden\');">' . __('Edit', 'wpcf') . '</a>' . '<div class="hidden" id="wpcf-form-fields-taxonomies">');
    $form_tax = $form_tax + $form_tax_single;
    $form_tax['taxonomies-close'] = array('#type' => 'markup', '#markup' => '<a href="javascript:void(0);" style="line-height: 35px;" ' . 'class="button-primary wpcf-groups-form-ajax-update-tax-ok"' . ' onclick="window.wpcfTaxText = new Array(); window.wpcfFormGroupsSupportTaxState = new Array(); ' . 'jQuery(this).parent().slideUp().find(\'.checkbox\').each(function(index){' . 'if (jQuery(this).is(\':checked\')) { ' . 'window.wpcfTaxText.push(jQuery(this).next().html()); ' . 'window.wpcfFormGroupsSupportTaxState.push(jQuery(this).attr(\'id\'));' . '}' . '});' . 'if (window.wpcfTaxText.length < 1) { ' . 'jQuery(\'#wpcf-group-form-update-tax-ajax-response\').html(\'' . $tax_no_currently_supported_txt . '\'); ' . '} else { jQuery(\'#wpcf-group-form-update-tax-ajax-response\').html(\'' . __('Terms:', 'wpcf') . ' \'+wpcfTaxText.join(\', \'));' . '}' . ' jQuery(this).parent().parent().children(\'a\').css(\'visibility\', \'visible\');' . '">' . __('OK', 'wpcf') . '</a>&nbsp;' . '<a href="javascript:void(0);" style="line-height: 35px;" ' . 'class="button-secondary wpcf-groups-form-ajax-update-tax-cancel"' . ' onclick="jQuery(this).parent().slideUp().find(\'input\').removeAttr(\'checked\');' . 'if (window.wpcfFormGroupsSupportTaxState.length > 0) { ' . 'for (var element in window.wpcfFormGroupsSupportTaxState) { ' . 'jQuery(\'#\'+window.wpcfFormGroupsSupportTaxState[element]).attr(\'checked\', \'checked\'); }}' . 'jQuery(\'#wpcf-group-form-update-tax-ajax-response\').html(\'' . __('Terms:', 'wpcf') . ' \'+window.wpcfTaxText.join(\', \'));' . ' jQuery(this).parent().parent().children(\'a\').css(\'visibility\', \'visible\');' . '">' . __('Cancel', 'wpcf') . '</a>' . '</div><br />');
    $form['supports-table-open'] = array('#type' => 'markup', '#markup' => '<table class="widefat"><thead><tr><th>' . __('Where to display this group', 'wpcf') . '</th></tr></thead><tbody><tr><td>' . __('Each custom fields group can display on different content types or different taxonomy.', 'wpcf') . '<br />');
    $form['types'] = $form_types;
    $form = $form + $form_tax;
    // Choose templates
    $templates = get_page_templates();
    $templates_views = get_posts('post_type=view-template&numberposts=-1&status=publish');
    $options = array();
    $options['default-template'] = array('#title' => __('Default Template'), '#default_value' => !empty($update['templates']) && in_array('default', $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => 'default', '#inline' => true, '#after' => '<br />');
    foreach ($templates as $template_name => $template_filename) {
        $options[$template_filename] = array('#title' => $template_name, '#default_value' => !empty($update['templates']) && in_array($template_filename, $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => $template_filename, '#inline' => true, '#after' => '<br />');
    }
    foreach ($templates_views as $template_view) {
        $options[$template_view->post_name] = array('#title' => 'View Template ' . $template_view->post_title, '#default_value' => !empty($update['templates']) && in_array($template_view->ID, $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => $template_view->ID, '#inline' => true, '#after' => '<br />');
        $templates_view_list_text[$template_view->ID] = $template_view->post_title;
    }
    $text = '';
    $empty_txt = __('Not Selected', 'wpcf');
    if (!empty($update['templates'])) {
        $text = array();
        $templates = array_flip($templates);
        foreach ($update['templates'] as $template) {
            if ($template == 'default') {
                $template = __('Default Template');
            } else {
                if (strpos($template, '.php') !== false) {
                    $template = $templates[$template];
                } else {
                    $template = 'View Template ' . $templates_view_list_text[$template];
                }
            }
            $text[] = $template;
        }
        $text = implode(', ', $text);
    } else {
        $text = __('Not Selected', 'wpcf');
    }
    $form['templates'] = array('#type' => 'checkboxes', '#name' => 'wpcf[group][templates]', '#options' => $options, '#inline' => true);
    $form['templates'] = wpcf_admin_fields_form_nested_elements('templates', $form['templates'], __('Content templates:', 'wpcf'), $text, $empty_txt);
    $count = 0;
    $count += !empty($update['post_types']) ? 1 : 0;
    $count += !empty($update['taxonomies']) ? 1 : 0;
    $count += !empty($update['templates']) ? 1 : 0;
    $display = $count > 1 ? '' : ' style="display:none;"';
    $form['filters_association'] = array('#type' => 'radios', '#name' => 'wpcf[group][filters_association]', '#id' => 'wpcf-fields-form-filters-association', '#options' => array(__('Display this group when ANY of the above conditions is met', 'wpcf') => 'any', __('Display this group when ALL the above conditions is met', 'wpcf') => 'all'), '#default_value' => !empty($update['filters_association']) ? $update['filters_association'] : 'any', '#inline' => true, '#before' => '<div id="wpcf-fields-form-filters-association-form"' . $display . '>', '#after' => '<div id="wpcf-fields-form-filters-association-summary" style="margin-top:10px;font-style:italic;"></div></div>');
    wpcf_admin_add_js_settings('wpcf_filters_association_or', '\'' . __('This group will appear on %pt% edit pages where content belongs to taxonomy: %tx% or View Template is: %vt%', 'wpcf') . '\'');
    wpcf_admin_add_js_settings('wpcf_filters_association_and', '\'' . __('This group will appear on %pt% edit pages where content belongs to taxonomy: %tx% and View Template is: %vt%', 'wpcf') . '\'');
    wpcf_admin_add_js_settings('wpcf_filters_association_all_pages', '\'' . __('all', 'wpcf') . '\'');
    wpcf_admin_add_js_settings('wpcf_filters_association_all_taxonomies', '\'' . __('any', 'wpcf') . '\'');
    wpcf_admin_add_js_settings('wpcf_filters_association_all_templates', '\'' . __('any', 'wpcf') . '\'');
    $form['supports-table-close'] = array('#type' => 'markup', '#markup' => '</td></tr></tbody></table><br />');
    // Group fields
    $form['fields_title'] = array('#type' => 'markup', '#markup' => '<h2>' . __('Fields', 'wpcf') . '</h2>');
    $show_under_title = true;
    $form['ajax-response-open'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-fields-sortable" class="ui-sortable">');
    // If it's update, display existing fields
    $existing_fields = array();
    if ($update && isset($update['fields'])) {
        foreach ($update['fields'] as $slug => $field) {
            $field['submitted_key'] = $slug;
            $field['group_id'] = $update['id'];
            $form_field = wpcf_fields_get_field_form_data($field['type'], $field);
            if (is_array($form_field)) {
                $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">');
                $form = $form + $form_field;
                $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>');
            }
            $existing_fields[] = $slug;
            $show_under_title = false;
        }
    }
    // Any new fields submitted but failed? (Don't double it)
    if (!empty($_POST['wpcf']['fields'])) {
        foreach ($_POST['wpcf']['fields'] as $key => $field) {
            if (in_array($key, $existing_fields)) {
                continue;
            }
            $field['submitted_key'] = $key;
            $form_field = wpcf_fields_get_field_form_data($field['type'], $field);
            if (is_array($form_field)) {
                $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">');
                $form = $form + $form_field;
                $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>');
            }
        }
        $show_under_title = false;
    }
    $form['ajax-response-close'] = array('#type' => 'markup', '#markup' => '</div>' . '<div id="wpcf-ajax-response"></div>');
    if ($show_under_title) {
        $form['fields_title']['#markup'] = $form['fields_title']['#markup'] . '<div id="wpcf-fields-under-title">' . __('There are no fields in this group. To add a field, click on the field buttons at the right.', 'wpcf') . '</div>';
    }
    // If update, create ID field
    if ($update) {
        $form['group_id'] = array('#type' => 'hidden', '#name' => 'group_id', '#value' => $update['id'], '#forced_value' => true);
    }
    $form['submit'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary'));
    // Close main div
    $form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>');
    $form = apply_filters('wpcf_form_fields', $form);
    // Add JS settings
    wpcf_admin_add_js_settings('wpcfFormUniqueValuesCheckText', '\'' . __('Warning: same values selected', 'wpcf') . '\'');
    return $form;
}
Ejemplo n.º 5
0
/**
 * Generates form data.
 */
function wpcf_admin_fields_form()
{
    wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\'');
    wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\'');
    $default = array();
    global $wpcf_button_style;
    global $wpcf_button_style30;
    global $wpcf;
    // If it's update, get data
    $update = false;
    if (isset($_REQUEST['group_id'])) {
        $update = wpcf_admin_fields_get_group(intval($_REQUEST['group_id']));
        if (empty($update)) {
            $update = false;
            wpcf_admin_message(sprintf(__("Group with ID %d do not exist", 'wpcf'), intval($_REQUEST['group_id'])));
        } else {
            $update['fields'] = wpcf_admin_fields_get_fields_by_group(sanitize_text_field($_REQUEST['group_id']), 'slug', false, true);
            $update['post_types'] = wpcf_admin_get_post_types_by_group(sanitize_text_field($_REQUEST['group_id']));
            $update['taxonomies'] = wpcf_admin_get_taxonomies_by_group(sanitize_text_field($_REQUEST['group_id']));
            $update['templates'] = wpcf_admin_get_templates_by_group(sanitize_text_field($_REQUEST['group_id']));
            $update['admin_styles'] = wpcf_admin_get_groups_admin_styles_by_group(sanitize_text_field($_REQUEST['group_id']));
        }
    }
    $form = array();
    $form['#form']['callback'] = array('wpcf_admin_save_fields_groups_submit');
    // Form sidebars
    $form['open-sidebar'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-fields-align-right">');
    // Set help icon
    $form['help-icon'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-admin-fields-help"><img src="' . WPCF_EMBEDDED_RELPATH . '/common/res/images/question.png" style="position:relative;top:2px;" />&nbsp;<a href="http://wp-types.com/documentation/user-guides/using-custom-fields/?utm_source=typesplugin&utm_medium=help&utm_term=fields-help&utm_content=fields-editor&utm_campaign=types" target="_blank">' . __('Custom fields help', 'wpcf') . '</a></div>');
    $form['submit2'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit'));
    $form['fields'] = array('#type' => 'fieldset', '#title' => __('Available fields', 'wpcf'));
    // Get field types
    $fields_registered = wpcf_admin_fields_get_available_types();
    foreach ($fields_registered as $filename => $data) {
        $form['fields'][basename($filename, '.php')] = array('#type' => 'markup', '#markup' => '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax&amp;wpcf_action=fields_insert' . '&amp;field=' . basename($filename, '.php') . '&amp;page=wpcf-edit') . '&amp;_wpnonce=' . wp_create_nonce('fields_insert') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary">' . $data['title'] . '</a> ');
        // Process JS
        if (!empty($data['group_form_js'])) {
            foreach ($data['group_form_js'] as $handle => $script) {
                if (isset($script['inline'])) {
                    add_action('admin_footer', $script['inline']);
                    continue;
                }
                $deps = !empty($script['deps']) ? $script['deps'] : array();
                $in_footer = !empty($script['in_footer']) ? $script['in_footer'] : false;
                wp_register_script($handle, $script['src'], $deps, WPCF_VERSION, $in_footer);
                wp_enqueue_script($handle);
            }
        }
        // Process CSS
        if (!empty($data['group_form_css'])) {
            foreach ($data['group_form_css'] as $handle => $script) {
                if (isset($script['src'])) {
                    $deps = !empty($script['deps']) ? $script['deps'] : array();
                    wp_enqueue_style($handle, $script['src'], $deps, WPCF_VERSION);
                } else {
                    if (isset($script['inline'])) {
                        add_action('admin_head', $script['inline']);
                    }
                }
            }
        }
    }
    // Get fields created by user
    $fields = wpcf_admin_fields_get_fields(true, true);
    if (!empty($fields)) {
        $form['fields-existing'] = array('#type' => 'fieldset', '#title' => __('User created fields', 'wpcf'), '#id' => 'wpcf-form-groups-user-fields');
        foreach ($fields as $key => $field) {
            if (isset($update['fields']) && array_key_exists($key, $update['fields'])) {
                continue;
            }
            if (!empty($field['data']['removed_from_history'])) {
                continue;
            }
            $form['fields-existing'][$key] = array('#type' => 'markup', '#markup' => '<div id="wpcf-user-created-fields-wrapper-' . $field['id'] . '" style="float:left; margin-right: 10px;"><a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&amp;wpcf_action=fields_insert_existing' . '&amp;page=wpcf-edit' . '&amp;field=' . $field['id']) . '&amp;_wpnonce=' . wp_create_nonce('fields_insert_existing') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary" onclick="jQuery(this).parent().fadeOut();" ' . ' data-slug="' . $field['id'] . '">' . htmlspecialchars(stripslashes($field['name'])) . '</a>' . '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&amp;wpcf_action=remove_from_history' . '&amp;field_id=' . $field['id']) . '&amp;_wpnonce=' . wp_create_nonce('remove_from_history') . '&amp;wpcf_warning=' . sprintf(__('Are you sure that you want to remove field %s from history?', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '&amp;wpcf_ajax_update=wpcf-user-created-fields-wrapper-' . $field['id'] . '" title="' . sprintf(__('Remove field %s', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '" class="wpcf-ajax-link"><img src="' . WPCF_RES_RELPATH . '/images/delete-2.png" style="postion:absolute;margin-top:5px;margin-left:-4px;" /></a></div>');
        }
    }
    $form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>');
    // Group data
    $form['open-main'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-form-fields-main">');
    $form['title'] = array('#type' => 'textfield', '#name' => 'wpcf[group][name]', '#id' => 'wpcf-group-name', '#value' => $update ? $update['name'] : '', '#inline' => true, '#attributes' => array('style' => 'width:100%;margin-bottom:10px;', 'placeholder' => __('Enter group title', 'wpcf')), '#validate' => array('required' => array('value' => true)));
    $form['description'] = array('#type' => 'textarea', '#id' => 'wpcf-group-description', '#name' => 'wpcf[group][description]', '#value' => $update ? $update['description'] : '', '#attributes' => array('placeholder' => __('Enter a description for this group', 'wpcf')));
    /**
     *
     * FILTER BOX
     * Since Types 1.2 we moved JS to /embedded/resources/js/custom-fields-form-filter.js
     *
     */
    // Support post types and taxonomies
    $post_types = get_post_types('', 'objects');
    $options = array();
    $post_types_currently_supported = array();
    $form_types = array();
    foreach ($post_types as $post_type_slug => $post_type) {
        if (in_array($post_type_slug, $wpcf->excluded_post_types) || !$post_type->show_ui) {
            continue;
        }
        $options[$post_type_slug]['#name'] = 'wpcf[group][supports][' . $post_type_slug . ']';
        $options[$post_type_slug]['#title'] = $post_type->label;
        $options[$post_type_slug]['#default_value'] = $update && !empty($update['post_types']) && in_array($post_type_slug, $update['post_types']) ? 1 : 0;
        $options[$post_type_slug]['#value'] = $post_type_slug;
        $options[$post_type_slug]['#inline'] = TRUE;
        $options[$post_type_slug]['#suffix'] = '<br />';
        $options[$post_type_slug]['#id'] = 'wpcf-form-groups-support-post-type-' . $post_type_slug;
        $options[$post_type_slug]['#attributes'] = array('class' => 'wpcf-form-groups-support-post-type');
        if ($update && !empty($update['post_types']) && in_array($post_type_slug, $update['post_types'])) {
            $post_types_currently_supported[] = $post_type->label;
        }
    }
    if (empty($post_types_currently_supported)) {
        $post_types_currently_supported[] = __('Displayed on all content types', 'wpcf');
    }
    /**
     * POST TYPE FILTER
     */
    $temp = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'wpcf[group][supports]', '#inline' => true);
    /**
     * Here we use unique function for all filters
     * Since Types 1.2
     */
    $form_types = _wpcf_filter_wrap('custom_post_types', __('Post Types:', 'wpcf'), implode(',', $post_types_currently_supported), __('Displayed on all content types', 'wpcf'), $temp);
    /**
     * TAXONOMIES FILTER QUERY
     */
    $taxonomies = apply_filters('wpcf_group_form_filter_taxonomies', get_taxonomies('', 'objects'));
    $options = array();
    $tax_currently_supported = array();
    $form_tax = array();
    $form_tax_single = array();
    /**
     * Filter toxonomies
     */
    foreach ($taxonomies as $category_slug => $category) {
        if ($category_slug == 'nav_menu' || $category_slug == 'link_category' || $category_slug == 'post_format') {
            continue;
        }
        $terms = apply_filters('wpcf_group_form_filter_terms', get_terms($category_slug, array('hide_empty' => false)));
        if (!empty($terms)) {
            $options = array();
            $add_title = '<div class="taxonomy-title">' . $category->labels->name . '</div>';
            $title = '';
            foreach ($terms as $term) {
                $checked = 0;
                if ($update && !empty($update['taxonomies']) && array_key_exists($category_slug, $update['taxonomies'])) {
                    if (array_key_exists($term->term_taxonomy_id, $update['taxonomies'][$category_slug])) {
                        $checked = 1;
                        $tax_currently_supported[$term->term_taxonomy_id] = $term->name;
                        $title = '';
                    }
                }
                $options[$term->term_taxonomy_id]['#name'] = 'wpcf[group][taxonomies][' . $category_slug . '][' . $term->term_taxonomy_id . ']';
                $options[$term->term_taxonomy_id]['#title'] = $term->name;
                $options[$term->term_taxonomy_id]['#default_value'] = $checked;
                $options[$term->term_taxonomy_id]['#value'] = $term->term_taxonomy_id;
                $options[$term->term_taxonomy_id]['#inline'] = true;
                $options[$term->term_taxonomy_id]['#prefix'] = $add_title;
                $options[$term->term_taxonomy_id]['#suffix'] = '<br />';
                $options[$term->term_taxonomy_id]['#id'] = 'wpcf-form-groups-support-tax-' . $term->term_taxonomy_id;
                $options[$term->term_taxonomy_id]['#attributes'] = array('class' => 'wpcf-form-groups-support-tax');
                $add_title = '';
            }
            $form_tax_single['taxonomies-' . $category_slug] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'wpcf[group][taxonomies][' . $category_slug . ']', '#suffix' => '<br />', '#inline' => true);
        }
    }
    if (empty($tax_currently_supported)) {
        $tax_currently_supported[] = __('Not Selected', 'wpcf');
    }
    /**
     * Since Types 1.2 we use unique function
     */
    $form_tax = _wpcf_filter_wrap('custom_taxonomies', __('Terms:', 'wpcf'), implode(', ', array_values($tax_currently_supported)), __('Not Selected', 'wpcf'), $form_tax_single);
    /**
     * TEMPLATES
     */
    // Choose templates
    $templates = get_page_templates();
    $templates_views = get_posts('post_type=view-template&numberposts=-1&status=publish');
    $options = array();
    $options['default-template'] = array('#title' => __('Default Template'), '#default_value' => !empty($update['templates']) && in_array('default', $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => 'default', '#inline' => true, '#after' => '<br />');
    foreach ($templates as $template_name => $template_filename) {
        $options[$template_filename] = array('#title' => $template_name, '#default_value' => !empty($update['templates']) && in_array($template_filename, $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => $template_filename, '#inline' => true, '#after' => '<br />');
    }
    foreach ($templates_views as $template_view) {
        $options[$template_view->post_name] = array('#title' => 'View Template ' . $template_view->post_title, '#default_value' => !empty($update['templates']) && in_array($template_view->ID, $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => $template_view->ID, '#inline' => true, '#after' => '<br />');
        $templates_view_list_text[$template_view->ID] = $template_view->post_title;
    }
    $text = '';
    if (!empty($update['templates'])) {
        $text = array();
        $templates = array_flip($templates);
        foreach ($update['templates'] as $template) {
            if ($template == 'default') {
                $template = __('Default Template');
            } else {
                if (strpos($template, '.php') !== false) {
                    $template = $templates[$template];
                } else {
                    $template = 'View Template ' . $templates_view_list_text[$template];
                }
            }
            $text[] = $template;
        }
        $text = implode(', ', $text);
    } else {
        $text = __('Not Selected', 'wpcf');
    }
    // Add class
    foreach ($options as $_k => $_option) {
        $options[$_k]['#attributes'] = array('class' => 'wpcf-form-groups-support-templates');
    }
    $form_templates = array('#type' => 'checkboxes', '#name' => 'wpcf[group][templates]', '#options' => $options, '#inline' => true);
    /**
     * Since Types 1.2 we use unique function
     */
    $form_templates = _wpcf_filter_wrap('templates', __('Templates:', 'wpcf'), $text, __('Not Selected', 'wpcf'), $form_templates);
    /**
     * Now starting form
     */
    $form['supports-table-open'] = array('#type' => 'markup', '#markup' => '<table class="widefat"><thead><tr><th>' . __('Where to display this group', 'wpcf') . '</th></tr></thead><tbody><tr><td>' . '<p>' . __('Each custom fields group can display on different content types or different taxonomy.', 'wpcf') . '</p>');
    /**
     * Join filter forms
     */
    // Types
    $form['p_wrap_1_' . wpcf_unique_id(serialize($form_types))] = array('#type' => 'markup', '#markup' => '<p class="wpcf-filter-wrap">');
    $form = $form + $form_types;
    // Terms
    $form['p_wrap_2_' . wpcf_unique_id(serialize($form_tax))] = array('#type' => 'markup', '#markup' => '</p><p class="wpcf-filter-wrap">');
    $form = $form + $form_tax;
    // Templates
    $form['p_wrap_3_' . wpcf_unique_id(serialize($form_templates))] = array('#type' => 'markup', '#markup' => '</p><p class="wpcf-filter-wrap">');
    $form = $form + $form_templates;
    $form['p_wrap_4_' . wpcf_unique_id(serialize($form_templates))] = array('#type' => 'markup', '#markup' => '</p>');
    /**
     * TODO Code from now on should be revised
     */
    $count = 0;
    $count += !empty($update['post_types']) ? 1 : 0;
    $count += !empty($update['taxonomies']) ? 1 : 0;
    $count += !empty($update['templates']) ? 1 : 0;
    $display = $count > 1 ? '' : ' style="display:none;"';
    $form['filters_association'] = array('#type' => 'radios', '#name' => 'wpcf[group][filters_association]', '#id' => 'wpcf-fields-form-filters-association', '#options' => array(__('Display this group when ANY of the above conditions is met', 'wpcf') => 'any', __('Display this group when ALL the above conditions is met', 'wpcf') => 'all'), '#default_value' => !empty($update['filters_association']) ? $update['filters_association'] : 'any', '#inline' => true, '#before' => '<div id="wpcf-fields-form-filters-association-form"' . $display . '>', '#after' => '<div id="wpcf-fields-form-filters-association-summary" style="margin-top:10px;font-style:italic;margin-bottom:15px;"></div></div>');
    wpcf_admin_add_js_settings('wpcf_filters_association_or', '\'' . __('This group will appear on %pt% edit pages where content belongs to taxonomy: %tx% or View Template is: %vt%', 'wpcf') . '\'');
    wpcf_admin_add_js_settings('wpcf_filters_association_and', '\'' . __('This group will appear on %pt% edit pages where content belongs to taxonomy: %tx% and View Template is: %vt%', 'wpcf') . '\'');
    wpcf_admin_add_js_settings('wpcf_filters_association_all_pages', '\'' . __('all', 'wpcf') . '\'');
    wpcf_admin_add_js_settings('wpcf_filters_association_all_taxonomies', '\'' . __('any', 'wpcf') . '\'');
    wpcf_admin_add_js_settings('wpcf_filters_association_all_templates', '\'' . __('any', 'wpcf') . '\'');
    $additional_filters = apply_filters('wpcf_fields_form_additional_filters', array(), $update);
    $form = $form + $additional_filters;
    $form['supports-table-close'] = array('#type' => 'markup', '#markup' => '</td></tr></tbody></table><br />');
    /** Admin styles* */
    $form['adminstyles-table-open'] = array('#type' => 'markup', '#markup' => '<table class="widefat" id="wpcf-admin-styles-box"><thead><tr><th>' . __('Styling Editor', 'wpcf') . '</th></tr></thead><tbody><tr><td>' . '<p>' . __('Customize Fields for admin panel.', 'wpcf') . '</p>');
    $admin_styles_value = $preview_profile = $edit_profile = '';
    if (isset($update['admin_styles'])) {
        $admin_styles_value = $update['admin_styles'];
    }
    $temp = '';
    if ($update) {
        require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
        require_once WPCF_EMBEDDED_INC_ABSPATH . '/usermeta.php';
        require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php';
        require_once WPCF_EMBEDDED_INC_ABSPATH . '/usermeta-post.php';
        //Get sample post
        $post = query_posts('posts_per_page=1');
        if (!empty($post) && count($post) != '') {
            $post = $post[0];
        }
        $preview_profile = wpcf_admin_post_meta_box_preview($post, $update, 1);
        $group = $update;
        $group['fields'] = wpcf_admin_post_process_fields($post, $group['fields'], true, false);
        $edit_profile = wpcf_admin_post_meta_box($post, $group, 1, true);
        add_action('admin_enqueue_scripts', 'wpcf_admin_fields_form_fix_styles', PHP_INT_MAX);
    }
    $temp[] = array('#type' => 'radio', '#suffix' => '<br />', '#value' => 'edit_mode', '#title' => 'Edit mode', '#name' => 'wpcf[group][preview]', '#default_value' => '', '#before' => '<div class="wpcf-admin-css-preview-style-edit">', '#inline' => true, '#attributes' => array('onclick' => 'changePreviewHtml(\'editmode\')', 'checked' => 'checked'));
    $temp[] = array('#type' => 'radio', '#title' => 'Read Only', '#name' => 'wpcf[group][preview]', '#default_value' => '', '#after' => '</div>', '#inline' => true, '#attributes' => array('onclick' => 'changePreviewHtml(\'readonly\')'));
    $temp[] = array('#type' => 'textarea', '#name' => 'wpcf[group][admin_html_preview]', '#inline' => true, '#id' => 'wpcf-form-groups-admin-html-preview', '#before' => '<h3>Field group HTML</h3>');
    $temp[] = array('#type' => 'textarea', '#name' => 'wpcf[group][admin_styles]', '#inline' => true, '#value' => $admin_styles_value, '#default_value' => '', '#id' => 'wpcf-form-groups-css-fields-editor', '#after' => '
        <div class="wpcf-update-preview-btn"><input type="button" value="Update preview" onclick="wpcfPreviewHtml()" style="float:right;" class="button-secondary"></div>
        <h3>Field group preview</h3>
        <div id="wpcf-update-preview-div">Preview here</div>
        <script type="text/javascript">
var wpcfReadOnly = ' . json_encode($preview_profile) . ';
var wpcfEditMode = ' . json_encode($edit_profile) . ';
var wpcfDefaultCss = ' . json_encode($admin_styles_value) . ';
        </script>
        ', '#before' => '<h3>Your CSS</h3>');
    $admin_styles = _wpcf_filter_wrap('admin_styles', __('Admin styles for fields:', 'wpcf'), '', '', $temp, __('Open style editor', 'wpcf'));
    $form['p_wrap_1_' . wpcf_unique_id(serialize($admin_styles))] = array('#type' => 'markup', '#markup' => '<p class="wpcf-filter-wrap">');
    $form = $form + $admin_styles;
    $form['adminstyles-table-close'] = array('#type' => 'markup', '#markup' => '</td></tr></tbody></table><br />');
    /** End admin Styles * */
    // Group fields
    $form['fields_title'] = array('#type' => 'markup', '#markup' => '<h2>' . __('Fields', 'wpcf') . '</h2>');
    $show_under_title = true;
    $form['ajax-response-open'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-fields-sortable" class="ui-sortable">');
    // If it's update, display existing fields
    $existing_fields = array();
    if ($update && isset($update['fields'])) {
        foreach ($update['fields'] as $slug => $field) {
            $field['submitted_key'] = $slug;
            $field['group_id'] = $update['id'];
            $form_field = wpcf_fields_get_field_form_data($field['type'], $field);
            if (is_array($form_field)) {
                $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">');
                $form = $form + $form_field;
                $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>');
            }
            $existing_fields[] = $slug;
            $show_under_title = false;
        }
    }
    // Any new fields submitted but failed? (Don't double it)
    if (!empty($_POST['wpcf']['fields'])) {
        foreach ($_POST['wpcf']['fields'] as $key => $field) {
            if (in_array($key, $existing_fields)) {
                continue;
            }
            $field['submitted_key'] = $key;
            $form_field = wpcf_fields_get_field_form_data($field['type'], $field);
            if (is_array($form_field)) {
                $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">');
                $form = $form + $form_field;
                $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>');
            }
        }
        $show_under_title = false;
    }
    $form['ajax-response-close'] = array('#type' => 'markup', '#markup' => '</div>' . '<div id="wpcf-ajax-response"></div>');
    if ($show_under_title) {
        $form['fields_title']['#markup'] = $form['fields_title']['#markup'] . '<div id="wpcf-fields-under-title">' . __('There are no fields in this group. To add a field, click on the field buttons at the right.', 'wpcf') . '</div>';
    }
    // If update, create ID field
    if ($update) {
        $form['group_id'] = array('#type' => 'hidden', '#name' => 'group_id', '#value' => $update['id'], '#forced_value' => true);
    }
    $form['submit'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit'));
    // Close main div
    $form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>');
    $form = apply_filters('wpcf_form_fields', $form, $update);
    // Add JS settings
    wpcf_admin_add_js_settings('wpcfFormUniqueValuesCheckText', '\'' . __('Warning: same values selected', 'wpcf') . '\'');
    wpcf_admin_add_js_settings('wpcfFormUniqueNamesCheckText', '\'' . __('Warning: field name already used', 'wpcf') . '\'');
    wpcf_admin_add_js_settings('wpcfFormUniqueSlugsCheckText', '\'' . __('Warning: field slug already used', 'wpcf') . '\'');
    wpcf_admin_add_js_settings('wpcfFormAlertOnlyPreview', sprintf("'%s'", __('Sorry, but this is only preview!', 'wpcf')));
    return $form;
}
 /** ************************************************************************
  * Recommended. This method is called when the parent class can't find a method
  * specifically build for a given column. Generally, it's recommended to include
  * one method for each column you want to render, keeping your package class
  * neat and organized. For example, if the class needs to process a column
  * named 'title', it would first see if a method named $this->column_title()
  * exists - if it does, that method will be used. If it doesn't, this one will
  * be used. Generally, you should try to use custom column methods as much as
  * possible.
  *
  * Since we have defined a column_title() method later on, this method doesn't
  * need to concern itself with any column with a name of 'title'. Instead, it
  * needs to handle everything else.
  *
  * For more detailed insight into how columns are handled, take a look at
  * WP_List_Table::single_row_columns()
  *
  * @param array $item A singular item (one full row's worth of data)
  * @param array $column_name The name/slug of the column to be processed
  * @return string Text or HTML to be placed inside the column <td>
  **************************************************************************/
 function column_default($item, $column_name)
 {
     switch ($column_name) {
         case 'title':
         case 'description':
             return stripslashes($item[$column_name]);
         case 'post_types':
             global $wp_post_types;
             $post_types = wpcf_admin_get_post_types_by_group($item['id']);
             $supports = array();
             if (!empty($post_types)) {
                 foreach ($post_types as $key => $post_type_slug) {
                     if (isset($wp_post_types[$post_type_slug]->labels->singular_name)) {
                         $supports[] = $wp_post_types[$post_type_slug]->labels->singular_name;
                     } else {
                         $supports[] = $post_type_slug;
                     }
                 }
             }
             return empty($post_types) ? __('All post types', 'wpcf') : implode(', ', $supports);
             break;
         case 'taxonomies':
             global $wp_taxonomies;
             $taxonomies = wpcf_admin_get_taxonomies_by_group($item['id']);
             $output = '';
             if (empty($taxonomies)) {
                 $output = __('None', 'wpcf');
             } else {
                 foreach ($taxonomies as $taxonomy => $terms) {
                     $output .= isset($wp_taxonomies[$taxonomy]->labels->singular_name) ? '<em>' . $wp_taxonomies[$taxonomy]->labels->singular_name . '</em>: ' : '<em>' . $taxonomy . '</em>: ';
                     $terms_output = array();
                     foreach ($terms as $term_id => $term) {
                         $terms_output[] = $term['name'];
                     }
                     $output .= implode(', ', $terms_output) . '<br />';
                 }
             }
             return $output;
         case 'status':
             return 'active' == $item[$column_name] ? __('Yes', 'wpcf') : __('No', 'wpcf');
         default:
             return print_r($item, true);
             //Show the whole array for troubleshooting purposes
     }
 }
 /**
  * Summary.
  *
  * Description.
  *
  * @since x.x.x
  * @access (for functions: only use if private)
  *
  * @param $filter
  * @param $form
  */
 protected function form_add_filter_dialog($filter, &$form)
 {
     global $wpcf;
     switch ($filter) {
         /**
          * post types
          */
         case 'post-types':
             $form['post-types-description'] = array('#type' => 'markup', '#markup' => '<p class="description js-wpcf-description">' . __('Select specific Post Types that you want to use with this Field Group:', 'wpcf') . '</p>');
             $form['post-types-ul-open'] = array('#type' => 'markup', '#markup' => '<ul>');
             $currently_supported = wpcf_admin_get_post_types_by_group(sanitize_text_field($_REQUEST['id']));
             $post_types = get_post_types(array('show_ui' => true), 'objects');
             ksort($post_types);
             foreach ($post_types as $post_type_slug => $post_type) {
                 if (in_array($post_type_slug, $wpcf->excluded_post_types)) {
                     continue;
                 }
                 $form['option_' . $post_type_slug] = array('#name' => esc_attr($post_type_slug), '#type' => 'checkbox', '#value' => 1, '#default_value' => $this->ajax_filter_default_value($post_type_slug, $currently_supported, 'post-type'), '#inline' => true, '#before' => '<li>', '#after' => '</li>', '#title' => $post_type->label, '#attributes' => array('data-wpcf-value' => esc_attr($post_type_slug), 'data-wpcf-prefix' => 'post-type-'));
             }
             $form['post-types-ul-close'] = array('#type' => 'markup', '#markup' => '</ul><br class="clear" />');
             break;
             /**
              * taxonomies
              */
         /**
          * taxonomies
          */
         case 'taxonomies':
             $form['taxonomies-description'] = array('#type' => 'markup', '#markup' => '<p class="description js-wpcf-description">' . __('Select ' . 'specific Terms from Taxonomies below that you want to use with this Field Group:', 'wpcf') . '</p>');
             include_once WPCF_INC_ABSPATH . '/fields.php';
             $currently_supported = wpcf_admin_get_taxonomies_by_group($_REQUEST['id']);
             $taxonomies = apply_filters('wpcf_group_form_filter_taxonomies', get_taxonomies('', 'objects'));
             $taxonomies_settings = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array());
             $form['taxonomies-div-open'] = array('#type' => 'markup', '#markup' => '<div id="poststuff" class="meta-box-sortables">');
             foreach ($taxonomies as $category_slug => $category) {
                 if ($category_slug == 'nav_menu' || $category_slug == 'link_category' || $category_slug == 'post_format' || isset($taxonomies_settings[$category_slug]['disabled']) && $taxonomies_settings[$category_slug]['disabled'] == 1 || empty($category->labels->name)) {
                     continue;
                 }
                 $terms = apply_filters('wpcf_group_form_filter_terms', get_terms($category_slug, array('hide_empty' => false)));
                 if (empty($terms)) {
                     continue;
                 }
                 $form_tax = array();
                 $form_tax[$category_slug . '-search'] = array('#type' => 'textfield', '#name' => $category_slug . '-search', '#attributes' => array('class' => 'widefat js-wpcf-taxonomy-search', 'placeholder' => esc_attr__('Search', 'wpcf')));
                 foreach ($terms as $term) {
                     $form_tax[$term->term_taxonomy_id] = array('#type' => 'checkbox', '#name' => esc_attr(sprintf('tax-%d', $term->term_taxonomy_id)), '#value' => 1, '#inline' => true, '#before' => '<li>', '#after' => '</li>', '#title' => $term->name, '#default_value' => $this->ajax_filter_default_value($term->term_taxonomy_id, $currently_supported, 'taxonomy', $category_slug), '#attributes' => array('data-wpcf-value' => esc_attr($term->term_taxonomy_id), 'data-wpcf-slug' => esc_attr($term->slug), 'data-wpcf-name' => esc_attr($term->name), 'data-wpcf-taxonomy-slug' => esc_attr($category_slug), 'data-wpcf-prefix' => ''));
                 }
                 $form += $this->ajax_filter_add_box($category_slug, $category->labels->name, $form_tax);
             }
             $form['taxonomies-div-close'] = array('#type' => 'markup', '#markup' => '</div>');
             break;
             /**
              * templates
              */
         /**
          * templates
          */
         case 'templates':
             $form['templates-description'] = array('#type' => 'markup', '#markup' => '<p class="description js-wpcf-description">' . __('Select specific Template that you want to use with this Field Group:', 'wpcf') . '</p>');
             $form['templates-ul-open'] = array('#type' => 'markup', '#markup' => '<ul>');
             include_once WPCF_INC_ABSPATH . '/fields.php';
             $currently_supported = wpcf_admin_get_templates_by_group(sanitize_text_field($_REQUEST['id']));
             $templates = get_page_templates();
             $templates_views = get_posts(array('post_type' => 'view-template', 'numberposts' => -1, 'status' => 'publish'));
             $form['default-template'] = array('#type' => 'checkbox', '#default_value' => $this->ajax_filter_default_value('default', $currently_supported, 'template'), '#name' => 'default', '#value' => 1, '#inline' => true, '#title' => __('Default', 'wpcf'), '#before' => '<li>', '#after' => '</li>', '#attributes' => array('data-wpcf-value' => esc_attr('default'), 'data-wpcf-prefix' => 'templates-'));
             foreach ($templates as $template_name => $template_filename) {
                 $form[$template_filename] = array('#type' => 'checkbox', '#default_value' => $this->ajax_filter_default_value($template_filename, $currently_supported, 'template'), '#value' => 1, '#inline' => true, '#title' => $template_name, '#name' => sanitize_title_with_dashes($template_filename), '#before' => '<li>', '#after' => '</li>', '#attributes' => array('data-wpcf-value' => esc_attr($template_filename), 'data-wpcf-prefix' => 'templates-'));
             }
             foreach ($templates_views as $template_view) {
                 $form[$template_view->post_name] = array('#type' => 'checkbox', '#value' => 1, '#default_value' => $this->ajax_filter_default_value($template_view->ID, $currently_supported, 'template'), '#inline' => true, '#title' => apply_filters('the_title', $template_view->post_title), '#name' => $template_view->ID, '#before' => '<li>', '#after' => '</li>', '#attributes' => array('data-wpcf-value' => esc_attr($template_view->ID), 'data-wpcf-prefix' => 'templates-'));
             }
             $form['templates-ul-close'] = array('#type' => 'markup', '#markup' => '</ul><br class="clear" />');
             break;
             /**
              * data dependant
              */
         /**
          * data dependant
          */
         case 'data-dependant':
             require_once WPCF_INC_ABSPATH . '/classes/class.types.fields.conditional.php';
             $data_dependant = new Types_Fields_Conditional();
             $form += $data_dependant->group_condition_get(true);
             break;
     }
 }