function buddyforms_types_create_new_form_builder_form_element($form_fields, $form_slug, $field_type, $field_id)
{
    global $field_position;
    switch ($field_type) {
        case 'wp-types':
            //unset($form_fields);
            $boom = wpcf_admin_fields_get_fields_by_group(258);
            echo '<pre>';
            print_r($boom);
            echo '</pre>';
            $form_fields['general']['html'] = new Element_HTML('Hallo');
            break;
    }
    return $form_fields;
}
 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;
 }
Beispiel #3
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;
 }
Beispiel #4
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;
}
/**
 * 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;
}
Beispiel #6
0
/**
 * Generates form data.
 */
function wpcf_admin_usermeta_form()
{
    global $wpcf;
    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;
    // If it's update, get data
    $update = false;
    if (isset($_REQUEST['group_id'])) {
        $update = wpcf_admin_fields_get_group(intval($_REQUEST['group_id']), 'wp-types-user-group');
        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'], 'slug', false, true, false, 'wp-types-user-group', 'wpcf-usermeta');
            $update['show_for'] = wpcf_admin_get_groups_showfor_by_group($_REQUEST['group_id']);
            $update['admin_styles'] = wpcf_admin_get_groups_admin_styles_by_group($_REQUEST['group_id']);
        }
    }
    $form = array();
    $form['#form']['callback'] = array('wpcf_admin_save_usermeta_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/" target="_blank">' . __('Usermeta 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-usermeta') . '&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, false, 'wpcf-usermeta');
    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;page=wpcf-edit' . '&amp;wpcf_action=usermeta_insert_existing' . '&amp;field=' . $field['id']) . '&amp;_wpnonce=' . wp_create_nonce('usermeta_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_history2' . '&amp;field_id=' . $field['id']) . '&amp;_wpnonce=' . wp_create_nonce('remove_from_history2') . '&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']['data-label'] = addcslashes(__('Enter group title', 'wpcf'), '"');
        $form['title']['#attributes']['onfocus'] = 'if (jQuery(this).val() == jQuery(this).data(\'label\')) { jQuery(this).val(\'\'); }';
        $form['title']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(jQuery(this).data(\'label\')) }';
    }
    $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']['data-label'] = addcslashes(__('Enter a description for this group', 'wpcf'), '"');
        $form['description']['#attributes']['onfocus'] = 'if (jQuery(this).val() == jQuery(this).data(\'label\')) { jQuery(this).val(\'\'); }';
        $form['description']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(jQuery(this).data(\'label\')) }';
    }
    // Show Fields for
    global $wp_roles;
    $options = array();
    $users_currently_supported = array();
    $form_types = array();
    foreach ($wp_roles->role_names as $role => $name) {
        $options[$role]['#name'] = 'wpcf[group][supports][' . $role . ']';
        $options[$role]['#title'] = ucwords($role);
        $options[$role]['#default_value'] = $update && !empty($update['show_for']) && in_array($role, $update['show_for']) ? 1 : 0;
        $options[$role]['#value'] = $role;
        $options[$role]['#inline'] = TRUE;
        $options[$role]['#suffix'] = '<br />';
        $options[$role]['#id'] = 'wpcf-form-groups-show-for-' . $role;
        $options[$role]['#attributes'] = array('class' => 'wpcf-form-groups-support-post-type');
        if ($update && !empty($update['show_for']) && in_array($role, $update['show_for'])) {
            $users_currently_supported[] = ucwords($role);
        }
    }
    if (empty($users_currently_supported)) {
        $users_currently_supported[] = __('Displayed for all users roles', 'wpcf');
    }
    /*
     * Show for FILTER
     */
    $temp = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'wpcf[group][supports]', '#inline' => true);
    /*
     * 
     * Here we use unique function for all filters
     * Since Types 1.1.4
     */
    $form_users = _wpcf_filter_wrap('custom_post_types', __('Show For:', 'wpcf'), implode(', ', $users_currently_supported), __('Displayed for all users roles', 'wpcf'), $temp);
    /*
     * Now starting form
     */
    $access_notification = '';
    if (function_exists('wpcf_access_register_caps')) {
        $access_notification = '<div class="message custom wpcf-notif"><span class="wpcf-notif-congrats">' . __('This groups visibility is also controlled by the Access plugin.', 'wpcf') . '</span></div>';
    }
    $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 usermeta group can display different fields for user roles.', 'wpcf') . $access_notification . '</p>');
    /*
     * Join filter forms
     */
    // User Roles
    $form['p_wrap_1_' . wpcf_unique_id(serialize($form_users))] = array('#type' => 'markup', '#markup' => '<p class="wpcf-filter-wrap">');
    $form = $form + $form_users;
    $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';
        $user_id = wpcf_usermeta_get_user();
        $preview_profile = wpcf_usermeta_preview_profile($user_id, $update, 1);
        $group = $update;
        $group['fields'] = wpcf_admin_usermeta_process_fields($user_id, $group['fields'], true, false);
        $edit_profile = wpcf_admin_render_fields($group, $user_id, 1);
        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, '#value' => '', '#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>');
    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') . '\'');
    // 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') . '\'');
    return $form;
}
/**
 * Add User Fields to editor
 *
 * @author Gen gen.i@icanlocalize.com
 * @since Types 1.3
 */
function wpcf_admin_post_add_usermeta_to_editor_js($menu, $views_callback = false)
{
    global $wpcf;
    $post = apply_filters('wpcf_filter_wpcf_admin_get_current_edited_post', null);
    if (!$post) {
        $post = (object) array('ID' => -1);
    }
    $groups = wpcf_admin_fields_get_groups(TYPES_USER_META_FIELD_GROUP_CPT_NAME);
    $user_id = wpcf_usermeta_get_user();
    if (!empty($groups)) {
        $item_styles = array();
        foreach ($groups as $group_id => $group) {
            if (empty($group['is_active'])) {
                continue;
            }
            $group_name = sprintf(__('%s (Usermeta fields)', 'wpcf'), $group['name']);
            $fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta');
            if (!empty($fields)) {
                foreach ($fields as $field_id => $field) {
                    // Use field class
                    $wpcf->usermeta_field->set($user_id, $field);
                    // Get field data
                    $data = (array) $wpcf->usermeta_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'] . '\', \'usermeta\', ' . $post->ID . ')';
                    // Added for Views:users filter Vicon popup
                    if ($views_callback) {
                        $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'views-usermeta\', ' . $post->ID . ')';
                    }
                    $menu[$group_name][stripslashes($field['name'])] = array(stripslashes(wp_kses_post($field['name'])), trim(wpcf_usermeta_get_shortcode($field), '[]'), $group_name, $callback);
                }
                /*
                 * Since Types 1.2
                 * We use field class to enqueue JS and CSS
                 */
                $wpcf->usermeta_field->enqueue_script();
                $wpcf->usermeta_field->enqueue_style();
            }
        }
    }
    return $menu;
}
/**
 * Edit fields form.
 * 
 * @global type $wpdb
 * @param type $parent
 * @param type $child 
 */
function wpcf_pr_admin_edit_fields($parent, $child)
{
    global $wpdb;
    $post_type_parent = get_post_type_object($parent);
    $post_type_child = get_post_type_object($child);
    if (empty($post_type_parent) || empty($post_type_child)) {
        die(__('Wrong post types'));
    }
    $relationships = get_option('wpcf_post_relationship', array());
    if (!isset($relationships[$parent][$child])) {
        die(__('Relationship do not exist'));
    }
    $data = $relationships[$parent][$child];
    wp_enqueue_script('jquery');
    wpcf_admin_ajax_head('Edit fields', 'wpcf');
    // Process submit
    if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'pt_edit_fields')) {
        $relationships[$parent][$child]['fields_setting'] = $_POST['fields_setting'];
        $relationships[$parent][$child]['fields'] = isset($_POST['fields']) ? $_POST['fields'] : array();
        update_option('wpcf_post_relationship', $relationships);
        ?>
        <script type="text/javascript">
            window.parent.jQuery('#TB_closeWindowButton').trigger('click');
            window.parent.location.reload();
        </script>
        <?php 
        die;
    }
    $form = array();
    $form['select'] = array('#type' => 'radios', '#name' => 'fields_setting', '#options' => array(__('Title, all custom fields and parents', 'wpcf') => 'all_cf', __('All fields, including the standard post fields', 'wpcf') => 'all_cf_standard', __('Specific fields', 'wpcf') => 'specific'), '#default_value' => empty($data['fields_setting']) ? 'all_cf' : $data['fields_setting']);
    $options = array();
    $options['_wp_title'] = array('#title' => __('Post title', 'wpcf'), '#name' => 'fields[_wp_title]', '#default_value' => isset($data['fields']['_wp_title']) ? 1 : 0);
    $options['_wp_body'] = array('#title' => __('Post body', 'wpcf'), '#name' => 'fields[_wp_body]', '#default_value' => isset($data['fields']['_wp_body']) ? 1 : 0);
    //    $wpcf_fields = wpcf_admin_fields_get_fields(true);
    $groups = wpcf_admin_get_groups_by_post_type($child);
    foreach ($groups as $group) {
        $fields = wpcf_admin_fields_get_fields_by_group($group['id']);
        foreach ($fields as $key => $cf) {
            $options[WPCF_META_PREFIX . $key] = array();
            $options[WPCF_META_PREFIX . $key]['#title'] = $cf['name'];
            $options[WPCF_META_PREFIX . $key]['#name'] = 'fields[' . WPCF_META_PREFIX . $key . ']';
            $options[WPCF_META_PREFIX . $key]['#default_value'] = isset($data['fields'][WPCF_META_PREFIX . $key]) ? 1 : 0;
        }
    }
    $temp_belongs = wpcf_pr_admin_get_belongs($child);
    foreach ($temp_belongs as $temp_parent => $temp_data) {
        if ($temp_parent == $parent) {
            continue;
        }
        $temp_parent_type = get_post_type_object($temp_parent);
        $options[$temp_parent] = array();
        $options[$temp_parent]['#title'] = $temp_parent_type->label;
        $options[$temp_parent]['#name'] = 'fields[_wpcf_pr_parents][' . $temp_parent . ']';
        $options[$temp_parent]['#default_value'] = isset($data['fields']['_wpcf_pr_parents'][$temp_parent]) ? 1 : 0;
    }
    //    foreach ($wpcf_fields as $key => $cf) {
    //        $options[WPCF_META_PREFIX . $key] = array();
    //        $options[WPCF_META_PREFIX . $key]['#title'] = $cf['name'];
    //        $options[WPCF_META_PREFIX . $key]['#name'] = 'fields[' . WPCF_META_PREFIX . $key . ']';
    //        $options[WPCF_META_PREFIX . $key]['#default_value'] = isset($data['fields'][WPCF_META_PREFIX . $key]) ? 1 : 0;
    //    }
    //    $cf_all = $wpdb->get_results("
    //		SELECT meta_id, meta_key
    //		FROM $wpdb->postmeta
    //		GROUP BY meta_key
    //		HAVING meta_key NOT LIKE '\_%'
    //		ORDER BY meta_key");
    //    foreach ($cf_all as $key => $cf) {
    //        if (isset($options[$cf->meta_key])) {
    //            continue;
    //        }
    //        $options[$key] = array();
    //        $options[$key]['#title'] = $cf->meta_key;
    //        $options[$key]['#name'] = 'fields[' . $cf->meta_key . ']';
    //        $options[$key]['#default_value'] = isset($data['fields'][$cf->meta_key]) ? 1 : 0;
    //    }
    $form['specific'] = array('#type' => 'checkboxes', '#name' => 'fields', '#options' => $options, '#default_value' => isset($data['fields']), '#before' => '<div id="wpcf-specific" style="display:none;margin:10px 0 0 20px;">', '#after' => '</div>');
    $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Save'), '#attributes' => array('class' => 'button-primary'));
    echo '<form method="post" action="">';
    echo wpcf_form_simple($form);
    echo wp_nonce_field('pt_edit_fields');
    echo '</form>';
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function(){
            if (jQuery('input[name="fields_setting"]:checked').val() == 'specific') {
                jQuery('#wpcf-specific').show();
            }
            jQuery('input[name="fields_setting"]').change(function(){
                if (jQuery(this).val() == 'specific') {
                    jQuery('#wpcf-specific').slideDown();
                } else {
                    jQuery('#wpcf-specific').slideUp();
                }
            });
        });
    </script>
    <?php 
    wpcf_admin_ajax_footer();
}
Beispiel #9
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;
 }
/**
 * 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;
}
/**
 * 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;
}
Beispiel #12
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;
}
/**
 * Get allowed keys
 *
 * Function colect proper keys of all fields - built-in and CF's
 *
 * @since 1.9.0
 *
 * @param string $child post type slug
 * @return array array of allowed slugs
 */
function wpcf_post_relationship_get_specific_fields_keys($child)
{
    $options = array();
    $groups = wpcf_admin_get_groups_by_post_type($child);
    foreach ($groups as $group) {
        $fields = wpcf_admin_fields_get_fields_by_group($group['id']);
        foreach ($fields as $key => $cf) {
            $__key = wpcf_types_cf_under_control('check_outsider', $key) ? $key : WPCF_META_PREFIX . $key;
            $options[$__key] = 1;
        }
    }
    $supports = wpcf_post_relationship_get_supported_fields_by_post_type($child);
    foreach ($supports as $child_field_key => $child_field_data) {
        $options[$child_field_data['name']] = 1;
    }
    return $options;
}
 /**
  * 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);
     }
 }
Beispiel #15
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;
}
/**
 * Edit fields form.
 * 
 * @global type $wpdb
 * @param type $parent
 * @param type $child 
 */
function wpcf_pr_admin_edit_fields($parent, $child)
{
    global $wpdb;
    $post_type_parent = get_post_type_object($parent);
    $post_type_child = get_post_type_object($child);
    if (empty($post_type_parent) || empty($post_type_child)) {
        die(__('Wrong post types'));
    }
    $relationships = get_option('wpcf_post_relationship', array());
    if (!isset($relationships[$parent][$child])) {
        die(__('Relationship do not exist'));
    }
    $data = $relationships[$parent][$child];
    wp_enqueue_script('jquery');
    wpcf_admin_ajax_head('Edit fields', 'wpcf');
    // Process submit
    if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'pt_edit_fields')) {
        $relationships[$parent][$child]['fields_setting'] = $_POST['fields_setting'];
        $relationships[$parent][$child]['fields'] = isset($_POST['fields']) ? $_POST['fields'] : array();
        update_option('wpcf_post_relationship', $relationships);
        ?>
        <script type="text/javascript">
            window.parent.jQuery('#TB_closeWindowButton').trigger('click');
            window.parent.location.reload();
        </script>
        <?php 
        die;
    }
    $groups = wpcf_admin_get_groups_by_post_type($child);
    $options_cf = array();
    $repetitive_warning = false;
    $repetitive_warning_markup = array();
    $repetitive_warning_txt = __('Repeating fields should not be used in child posts. Types will update all field values.', 'wpcf');
    foreach ($groups as $group) {
        $fields = wpcf_admin_fields_get_fields_by_group($group['id']);
        foreach ($fields as $key => $cf) {
            $options_cf[WPCF_META_PREFIX . $key] = array();
            $options_cf[WPCF_META_PREFIX . $key]['#title'] = $cf['name'];
            $options_cf[WPCF_META_PREFIX . $key]['#name'] = 'fields[' . WPCF_META_PREFIX . $key . ']';
            $options_cf[WPCF_META_PREFIX . $key]['#default_value'] = isset($data['fields'][WPCF_META_PREFIX . $key]) ? 1 : 0;
            // Repetitive warning
            if (wpcf_admin_is_repetitive($cf)) {
                if (!$repetitive_warning) {
                    $repetitive_warning_markup = array('#type' => 'markup', '#markup' => '<div class="message error" style="display:none;" id="wpcf-repetitive-warning"><p>' . $repetitive_warning_txt . '</p></div>');
                }
                $repetitive_warning = true;
                $options_cf[WPCF_META_PREFIX . $key]['#after'] = !isset($data['fields'][WPCF_META_PREFIX . $key]) ? '<div class="message error" style="display:none;"><p>' : '<div class="message error"><p>';
                $options_cf[WPCF_META_PREFIX . $key]['#after'] .= $repetitive_warning_txt;
                $options_cf[WPCF_META_PREFIX . $key]['#after'] .= '</p></div>';
                $options_cf[WPCF_META_PREFIX . $key]['#attributes'] = array('onclick' => 'jQuery(this).parent().find(\'.message\').toggle();');
            }
        }
    }
    $form = array();
    $form['repetitive_warning_markup'] = $repetitive_warning_markup;
    $form['select'] = array('#type' => 'radios', '#name' => 'fields_setting', '#options' => array(__('Title, all custom fields and parents', 'wpcf') => 'all_cf', __('All fields, including the standard post fields', 'wpcf') => 'all_cf_standard', __('Specific fields', 'wpcf') => 'specific'), '#default_value' => empty($data['fields_setting']) ? 'all_cf' : $data['fields_setting']);
    $options = array();
    $options['_wp_title'] = array('#title' => __('Post title', 'wpcf'), '#name' => 'fields[_wp_title]', '#default_value' => isset($data['fields']['_wp_title']) ? 1 : 0);
    $options['_wp_body'] = array('#title' => __('Post body', 'wpcf'), '#name' => 'fields[_wp_body]', '#default_value' => isset($data['fields']['_wp_body']) ? 1 : 0);
    $options = $options + $options_cf;
    $temp_belongs = wpcf_pr_admin_get_belongs($child);
    foreach ($temp_belongs as $temp_parent => $temp_data) {
        if ($temp_parent == $parent) {
            continue;
        }
        $temp_parent_type = get_post_type_object($temp_parent);
        $options[$temp_parent] = array();
        $options[$temp_parent]['#title'] = $temp_parent_type->label;
        $options[$temp_parent]['#name'] = 'fields[_wpcf_pr_parents][' . $temp_parent . ']';
        $options[$temp_parent]['#default_value'] = isset($data['fields']['_wpcf_pr_parents'][$temp_parent]) ? 1 : 0;
    }
    $form['specific'] = array('#type' => 'checkboxes', '#name' => 'fields', '#options' => $options, '#default_value' => isset($data['fields']), '#before' => '<div id="wpcf-specific" style="display:none;margin:10px 0 0 20px;">', '#after' => '</div>');
    $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary'));
    echo '<form method="post" action="">';
    echo wpcf_form_simple($form);
    echo wp_nonce_field('pt_edit_fields');
    echo '</form>';
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function(){
            if (jQuery('input[name="fields_setting"]:checked').val() == 'specific') {
                jQuery('#wpcf-specific').show();
            } else {
    <?php 
    if ($repetitive_warning) {
        ?>
                                    jQuery('#wpcf-repetitive-warning').show();
        <?php 
    }
    ?>
                            }
                            jQuery('input[name="fields_setting"]').change(function(){
                                if (jQuery(this).val() == 'specific') {
                                    jQuery('#wpcf-specific').slideDown();
                                } else {
                                    jQuery('#wpcf-specific').slideUp();
    <?php 
    if ($repetitive_warning) {
        ?>
                                        jQuery('#wpcf-repetitive-warning').show();
        <?php 
    }
    ?>
                                }
                            });
                        });
    </script>
    <?php 
    wpcf_admin_ajax_footer();
}
/**
 * Add User Fields to editor
 *
 * @author Gen gen.i@icanlocalize.com
 * @since Types 1.3
 */
function wpcf_admin_post_add_usermeta_to_editor_js($items, $views_callback = false)
{
    global $wpcf;
    $post = wpcf_admin_get_edited_post();
    if (empty($post)) {
        $post = (object) array('ID' => -1);
    }
    $groups = wpcf_admin_fields_get_groups('wp-types-user-group');
    $user_id = wpcf_usermeta_get_user();
    $add = array();
    if (!empty($groups)) {
        $item_styles = array();
        foreach ($groups as $group_id => $group) {
            if (empty($group['is_active'])) {
                continue;
            }
            $group['name'] .= ' (User meta fields)';
            $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) {
                    // Use field class
                    $wpcf->usermeta_field->set($user_id, $field);
                    // Get field data
                    $data = (array) $wpcf->usermeta_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'] . '\', \'usermeta\', ' . $post->ID . ')';
                    // Added for Views:users filter Vicon popup
                    if ($views_callback) {
                        $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'views-usermeta\', ' . $post->ID . ')';
                    }
                    $add[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_usermeta_get_shortcode($field), '[]'), $group['name'], $callback);
                }
                /*
                 * Since Types 1.2
                 * We use field class to enqueue JS and CSS
                 */
                $wpcf->usermeta_field->enqueue_script();
                $wpcf->usermeta_field->enqueue_style();
            }
        }
    }
    $items = $items + $add;
    return $items;
}
/**
 * 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;
}
/**
 * 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;
}
/**
 * Single condition form elements.
 * 
 * @param type $data
 * @param type $condition
 * @param type $key
 * @return string 
 */
function wpcf_cd_admin_form_single_filter($data, $condition, $key = null, $group = false, $force_multi = false)
{
    if ($group) {
        $name = 'wpcf[group][conditional_display]';
    } else {
        $name = 'wpcf[fields][' . $data['id'] . '][conditional_display]';
    }
    $group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : false;
    if ($group_id && !$group) {
        // Allow group to use other fields
        $fields = wpcf_admin_fields_get_fields_by_group($group_id);
    } else {
        $fields = wpcf_admin_fields_get_fields();
    }
    $options = array();
    foreach ($fields as $field_id => $field) {
        if (!$group && $data['id'] == $field_id) {
            continue;
        }
        if (wpcf_admin_is_repetitive($field)) {
            continue;
        }
        $options[$field_id] = array('#value' => $field_id, '#title' => $field['name'], '#attributes' => array('class' => 'wpcf-conditional-select-' . $field['type']));
    }
    if (!$group && empty($options)) {
        return array('cd' => array('#type' => 'markup', '#markup' => '<p>' . __('You will be able to set conditional field display when you save more fields.', 'wpcf') . '</p>'));
    }
    $id = !is_null($key) ? $key : strval('condition_' . mt_rand());
    $form = array();
    $before = '<div class="wpcf-cd-entry"><br />';
    $form['cd']['field_' . $id] = array('#type' => 'select', '#name' => $name . '[conditions][' . $id . '][field]', '#options' => $options, '#inline' => true, '#before' => $before, '#default_value' => isset($condition['field']) ? $condition['field'] : null, '#attributes' => array('class' => 'wpcf-cd-field'));
    $form['cd']['operation_' . $id] = array('#type' => 'select', '#name' => $name . '[conditions][' . $id . '][operation]', '#options' => array_flip(wpcf_cd_admin_operations()), '#inline' => true, '#default_value' => isset($condition['operation']) ? $condition['operation'] : null, '#attributes' => array('class' => 'wpcf-cd-operation'));
    $form['cd']['value_' . $id] = array('#type' => 'textfield', '#name' => $name . '[conditions][' . $id . '][value]', '#options' => wpcf_cd_admin_operations(), '#inline' => true, '#value' => isset($condition['value']) ? $condition['value'] : '', '#attributes' => array('class' => 'wpcf-cd-value'));
    $form['cd']['remove_' . $id] = array('#type' => 'button', '#name' => 'remove', '#value' => __('Remove condition', 'wpcf'), '#attributes' => array('onclick' => 'wpcfCdRemoveCondition(jQuery(this));', 'class' => 'wpcf-add-condition'), '#before' => '<br />', '#after' => '</div>');
    return $form['cd'];
}
 /**
  * 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 prepare_field_select_screen()
 {
     /**
      * check nonce
      */
     if (0 || !isset($_REQUEST['_wpnonce']) || !isset($_REQUEST['parent']) || !isset($_REQUEST['child']) || !wp_verify_nonce($_REQUEST['_wpnonce'], $this->get_nonce('child-post-fields', $_REQUEST['parent'], $_REQUEST['child']))) {
         $this->verification_failed_and_die();
     }
     $parent = $_REQUEST['parent'];
     $child = $_REQUEST['child'];
     $post_type_parent = get_post_type_object($parent);
     $post_type_child = get_post_type_object($child);
     if (empty($post_type_parent) || empty($post_type_child)) {
         die(__('Wrong post types', 'wpcf'));
     }
     $relationships = get_option('wpcf_post_relationship', array());
     if (!isset($relationships[$parent][$child])) {
         $this->print_notice_and_die(__('Please save Post Type first to edit these fields.', 'wpcf'));
     }
     $repetitive_warning_markup = array();
     $data = $relationships[$parent][$child];
     $form = array();
     $form['repetitive_warning_markup'] = $repetitive_warning_markup;
     $form['select'] = array('#type' => 'radios', '#name' => 'fields_setting', '#options' => array(__('Title, all custom fields and parents', 'wpcf') => 'all_cf', __('Do not show management options for this post type', 'wpcf') => 'only_list', __('All fields, including the standard post fields', 'wpcf') => 'all_cf_standard', __('Specific fields', 'wpcf') => 'specific'), '#attributes' => array('display' => 'ul'), '#default_value' => empty($data['fields_setting']) ? 'all_cf' : $data['fields_setting']);
     /**
      * check default, to avoid missing configuration
      */
     if (!in_array($form['select']['#default_value'], $form['select']['#options'])) {
         $form['select']['#default_value'] = 'all_cf';
     }
     /**
      * Specific options
      */
     $groups = wpcf_admin_get_groups_by_post_type($child);
     $options_cf = array();
     $repetitive_warning = false;
     $repetitive_warning_txt = __('Repeating fields should not be used in child posts. Types will update all field values.', 'wpcf');
     foreach ($groups as $group) {
         $fields = wpcf_admin_fields_get_fields_by_group($group['id']);
         foreach ($fields as $key => $cf) {
             $__key = wpcf_types_cf_under_control('check_outsider', $key) ? $key : WPCF_META_PREFIX . $key;
             $options_cf[$__key] = array('#title' => $cf['name'], '#name' => 'fields[' . $__key . ']', '#default_value' => isset($data['fields'][$__key]) ? 1 : 0, '#inline' => true, '#before' => '<li>', '#after' => '</li>');
             // Repetitive warning
             if (wpcf_admin_is_repetitive($cf)) {
                 if (!$repetitive_warning) {
                     $repetitive_warning_markup = array('#type' => 'markup', '#markup' => '<div class="message error" style="display:none;" id="wpcf-repetitive-warning"><p>' . $repetitive_warning_txt . '</p></div>');
                 }
                 $repetitive_warning = true;
                 $options_cf[$__key]['#after'] = !isset($data['fields'][$__key]) ? '<div class="message error" style="display:none;"><p>' : '<div class="message error"><p>';
                 $options_cf[$__key]['#after'] .= $repetitive_warning_txt;
                 $options_cf[$__key]['#after'] .= '</p></div></li>';
                 $options_cf[$__key]['#attributes'] = array('onclick' => 'jQuery(this).parent().find(\'.message\').toggle();', 'disabled' => 'disabled');
             }
         }
     }
     /**
      * build options for "Specific fields"
      */
     $options = array();
     /**
      * check and add built-in properites
      */
     require_once WPCF_INC_ABSPATH . '/post-relationship.php';
     $supports = wpcf_post_relationship_get_supported_fields_by_post_type($child);
     foreach ($supports as $child_field_key => $child_field_data) {
         $options[$child_field_data['name']] = array('#title' => $child_field_data['title'], '#name' => sprintf('fields[%s]', $child_field_data['name']), '#default_value' => isset($data['fields'][$child_field_data['name']]) ? 1 : 0, '#inline' => true, '#before' => '<li>', '#after' => '</li>');
     }
     /**
      * add custom fields
      */
     $options = $options + $options_cf;
     $temp_belongs = wpcf_pr_admin_get_belongs($child);
     foreach ($temp_belongs as $temp_parent => $temp_data) {
         if ($temp_parent == $parent) {
             continue;
         }
         $temp_parent_type = get_post_type_object($temp_parent);
         $options[$temp_parent] = array('#title' => $temp_parent_type->label, '#name' => 'fields[_wpcf_pr_parents][' . $temp_parent . ']', '#default_value' => isset($data['fields']['_wpcf_pr_parents'][$temp_parent]) ? 1 : 0, '#inline' => true, '#before' => '<li>', '#after' => '</li>');
     }
     /**
      * remove "Specific fields" if there is no fields
      */
     if (empty($options)) {
         unset($form['select']['#options'][__('Specific fields', 'wpcf')]);
         if ('specific' == $form['select']['#default_value']) {
             $form['select']['#default_value'] = 'all_cf';
         }
     }
     // Taxonomies
     $taxonomies = get_object_taxonomies($post_type_child->name, 'objects');
     if (!empty($taxonomies)) {
         foreach ($taxonomies as $tax_id => $taxonomy) {
             $options[$tax_id] = array('#title' => sprintf(__('Taxonomy - %s', 'wpcf'), $taxonomy->label), '#name' => 'fields[_wpcf_pr_taxonomies][' . $tax_id . ']', '#default_value' => isset($data['fields']['_wpcf_pr_taxonomies'][$tax_id]) ? 1 : 0, '#inline' => true, '#before' => '<li>', '#after' => '</li>');
         }
     }
     $form['specific'] = array('#type' => 'checkboxes', '#name' => 'fields', '#options' => $options, '#default_value' => isset($data['fields']), '#before' => sprintf('<ul id="wpcf-specific" class="%s">', 'specific' == $form['select']['#default_value'] ? '' : 'hidden'), '#after' => '</ul>');
     $form['nonce'] = array('#type' => 'hidden', '#value' => wp_create_nonce($this->get_nonce('child-post-fields-save', $parent, $child)), '#name' => 'wpcf-fields-save-nonce', '#id' => 'wpcf-fields-save-nonce');
     $form['parent'] = array('#type' => 'hidden', '#value' => esc_attr($parent), '#name' => 'wpcf-parent', '#id' => 'wpcf-parent');
     $form['child'] = array('#type' => 'hidden', '#value' => esc_attr($child), '#name' => 'wpcf-child', '#id' => 'wpcf-child');
     echo wpcf_form_simple($form);
     die;
 }
Beispiel #22
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;
}
Beispiel #23
0
/**
 * Get fields by group.
 * 
 * Returns array of fields and their values:
 * array( 'myfield' => 'some text' )
 * 
 * @global type $wpcf
 * @staticvar array $cache
 * @param type $group_id
 * @param type $active
 * @return array
 */
function types_get_fields_by_group($group, $only_active = 'only_active')
{
    static $cache = array();
    $cache_key = md5(serialize(func_get_args()));
    if (isset($cache[$cache_key])) {
        return $cache[$cache_key];
    }
    $results = array();
    $only_active = $only_active === 'only_active' || $only_active === true ? true : false;
    $group = wpcf_admin_fields_get_group($group);
    if (!empty($group['id'])) {
        if ($only_active && $group['is_active']) {
            $fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug');
            foreach ($fields as $field) {
                $results[$field['id']] = wpcf_api_field_meta_value($field);
            }
        }
    }
    $cache[$cache_key] = $results;
    return $cache[$cache_key];
}
Beispiel #24
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 = TYPES_CUSTOM_FIELD_GROUP_CPT_NAME)
{
    static $cache = array();
    $groups = wpcf_admin_fields_get_groups($post_type);
    switch ($post_type) {
        case TYPES_TERM_META_FIELD_GROUP_CPT_NAME:
            $meta_name = 'wpcf-termmeta';
            break;
        case TYPES_USER_META_FIELD_GROUP_CPT_NAME:
            $meta_name = 'wpcf-usermeta';
            break;
        case TYPES_CUSTOM_FIELD_GROUP_CPT_NAME:
        default:
            $meta_name = 'wpcf-fields';
            break;
    }
    $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;
}
/**
 * Custom Export function for Module Manager.
 *
 * Exports selected items (by ID) and of specified type (eg views, view-templates).
 * Returns xml string.
 *
 * @global type $iclTranslationManagement
 * @param array $items
 * @param type $_type
 * @param type $return mixed array|xml|download
 * @return string
 */
function wpcf_admin_export_selected_data(array $items, $_type = 'all', $return = 'download', $use_cache = false)
{
    global $wpcf;
    require_once WPCF_EMBEDDED_ABSPATH . '/common/array2xml.php';
    $xml = new ICL_Array2XML();
    $data = array();
    $data['settings'] = wpcf_get_settings();
    if ('user_groups' == $_type || 'all' == $_type) {
        // Get groups
        if (empty($items)) {
            $groups = get_posts('post_type=wp-types-user-group&post_status=null&numberposts=-1');
        } else {
            /*
             *
             * This fails
             * $items are in form of:
             * 0 => array('id' => 'pt', ...)
             */
            foreach ($items as $k => $item) {
                if (isset($item['id'])) {
                    $items[$k] = intval(wpcf_modman_get_submitted_id('groups', $item['id']));
                }
            }
            $args = array('post__in' => $items, 'post_type' => 'wp-types-user-group', 'post_status' => 'all', 'posts_per_page' => -1);
            $groups = get_posts($args);
        }
        if (!empty($groups)) {
            $data['user_groups'] = array('__key' => 'group');
            foreach ($groups as $key => $post) {
                $post = (array) $post;
                $post_data = array();
                $copy_data = array('ID', 'post_content', 'post_title', 'post_excerpt', 'post_type', 'post_status');
                foreach ($copy_data as $copy) {
                    if (isset($post[$copy])) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $_data = $post_data;
                $meta = get_post_custom($post['ID']);
                if (!empty($meta)) {
                    $_meta = array();
                    foreach ($meta as $meta_key => $meta_value) {
                        if (in_array($meta_key, array('_wp_types_group_showfor', '_wp_types_group_fields', '_wp_types_group_admin_styles'))) {
                            $_meta[$meta_key] = $meta_value[0];
                        }
                    }
                    if (!empty($_meta)) {
                        $_data['meta'] = $_meta;
                    }
                }
                $_data['checksum'] = $_data['hash'] = $wpcf->export->generate_checksum('group', $post['ID']);
                $_data['__types_id'] = $post['post_name'];
                $_data['__types_title'] = $post['post_title'];
                $data['user_groups']['group-' . $post['ID']] = $_data;
            }
        }
        if (!empty($items)) {
            // Get fields by group
            // TODO Document why we use by_group
            $fields = array();
            foreach ($groups as $key => $post) {
                $fields = array_merge($fields, wpcf_admin_fields_get_fields_by_group($post->ID, 'slug', false, false, false, 'wp-types-user-group', 'wpcf-usermeta', $use_cache));
            }
        } else {
            // Get fields
            $fields = wpcf_admin_fields_get_fields(false, false, false, 'wpcf-usermeta');
        }
        if (!empty($fields)) {
            // Add checksums before WPML
            foreach ($fields as $field_id => $field) {
                // TODO WPML and others should use hook
                $fields[$field_id] = apply_filters('wpcf_export_field', $fields[$field_id]);
                $fields[$field_id]['__types_id'] = $field_id;
                $fields[$field_id]['__types_title'] = $field['name'];
                $fields[$field_id]['checksum'] = $fields[$field_id]['hash'] = $wpcf->export->generate_checksum('field', $field_id);
            }
            // WPML
            global $iclTranslationManagement;
            if (!empty($iclTranslationManagement)) {
                foreach ($fields as $field_id => $field) {
                    // TODO Check this for all fields
                    if (isset($iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id])) {
                        $fields[$field_id]['wpml_action'] = $iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id];
                    }
                }
            }
            $data['user_fields'] = $fields;
            $data['user_fields']['__key'] = 'field';
        }
    }
    if ('groups' == $_type || 'all' == $_type) {
        // Get groups
        if (empty($items)) {
            $groups = get_posts('post_type=wp-types-group&post_status=null&numberposts=-1');
        } else {
            /*
             *
             * This fails
             * $items are in form of:
             * 0 => array('id' => 'pt', ...)
             */
            foreach ($items as $k => $item) {
                if (isset($item['id'])) {
                    $items[$k] = intval(wpcf_modman_get_submitted_id('groups', $item['id']));
                }
            }
            $args = array('post__in' => $items, 'post_type' => 'wp-types-group', 'post_status' => 'all', 'posts_per_page' => -1);
            $groups = get_posts($args);
        }
        if (!empty($groups)) {
            $data['groups'] = array('__key' => 'group');
            foreach ($groups as $key => $post) {
                $post = (array) $post;
                $post_data = array();
                $copy_data = array('ID', 'post_content', 'post_title', 'post_excerpt', 'post_type', 'post_status');
                foreach ($copy_data as $copy) {
                    if (isset($post[$copy])) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $_data = $post_data;
                $meta = get_post_custom($post['ID']);
                if (!empty($meta)) {
                    $_meta = array();
                    foreach ($meta as $meta_key => $meta_value) {
                        if (in_array($meta_key, array('_wp_types_group_terms', '_wp_types_group_post_types', '_wp_types_group_fields', '_wp_types_group_templates', '_wpcf_conditional_display', '_wp_types_group_filters_association', '_wp_types_group_admin_styles'))) {
                            $_meta[$meta_key] = $meta_value[0];
                            $_meta[$meta_key] = maybe_unserialize($_meta[$meta_key]);
                        }
                    }
                    if (!empty($_meta)) {
                        $_data['meta'] = $_meta;
                    }
                }
                $_data['checksum'] = $_data['hash'] = $wpcf->export->generate_checksum('group', $post['ID']);
                $_data['__types_id'] = $post['post_name'];
                $_data['__types_title'] = $post['post_title'];
                $data['groups']['group-' . $post['ID']] = $_data;
            }
        }
        if (!empty($items)) {
            // Get fields by group
            // TODO Document why we use by_group
            $fields = array();
            foreach ($groups as $key => $post) {
                $fields = array_merge($fields, wpcf_admin_fields_get_fields_by_group($post->ID, 'slug', false, false, false, 'wp-types-group', 'wpcf-fields', $use_cache));
            }
        } else {
            // Get fields
            $fields = wpcf_admin_fields_get_fields();
        }
        if (!empty($fields)) {
            // Add checksums before WPML
            foreach ($fields as $field_id => $field) {
                // TODO WPML and others should use hook
                $fields[$field_id] = apply_filters('wpcf_export_field', $fields[$field_id]);
                $fields[$field_id]['__types_id'] = $field_id;
                $fields[$field_id]['__types_title'] = $field['name'];
                $fields[$field_id]['checksum'] = $fields[$field_id]['hash'] = $wpcf->export->generate_checksum('field', $field_id);
            }
            // WPML
            global $iclTranslationManagement;
            if (!empty($iclTranslationManagement)) {
                foreach ($fields as $field_id => $field) {
                    // TODO Check this for all fields
                    if (isset($iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id])) {
                        $fields[$field_id]['wpml_action'] = $iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id];
                    }
                }
            }
            $data['fields'] = $fields;
            $data['fields']['__key'] = 'field';
        }
    }
    // Get custom types
    if ('types' == $_type || 'all' == $_type) {
        // Get custom types
        // TODO Document $items
        if (!empty($items)) {
            /*
             *
             * This fails
             * $items are in form of:
             * 0 => array('id' => 'pt', ...)
             */
            //            $custom_types = array_intersect_key( get_option( 'wpcf-custom-types',
            //                            array() ), array_flip( $items ) );
            $_items = array();
            foreach ($items as $k => $item) {
                if (is_array($item) && isset($item['id'])) {
                    $_items[$item['id']] = true;
                } else {
                    $_items[$item] = true;
                }
            }
            $custom_types = array_intersect_key(get_option('wpcf-custom-types', array()), $_items);
        } else {
            $custom_types = get_option('wpcf-custom-types', array());
        }
        // Get custom types
        if (!empty($custom_types)) {
            foreach ($custom_types as $key => $type) {
                $custom_types[$key]['id'] = $key;
                $custom_types[$key] = apply_filters('wpcf_export_custom_post_type', $custom_types[$key]);
                $custom_types[$key]['__types_id'] = $key;
                $custom_types[$key]['__types_title'] = $type['labels']['name'];
                $custom_types[$key]['checksum'] = $custom_types[$key]['hash'] = $wpcf->export->generate_checksum('custom_post_type', $key, $type);
            }
            $data['types'] = $custom_types;
            $data['types']['__key'] = 'type';
        }
        if (!empty($items)) {
            // Get post relationships only for items
            $relationships_all = get_option('wpcf_post_relationship', array());
            $relationships = array();
            foreach ($relationships_all as $parent => $children) {
                if (in_array($parent, $items)) {
                    foreach ($children as $child => $childdata) {
                        if (in_array($child, $items)) {
                            if (!isset($relationships[$parent])) {
                                $relationships[$parent] = array();
                            }
                            $relationships[$parent][$child] = $childdata;
                        }
                    }
                }
            }
        } else {
            // Get post relationships
            $relationships = get_option('wpcf_post_relationship', array());
        }
        if (!empty($relationships)) {
            $data['post_relationships']['data'] = json_encode($relationships);
        }
    }
    // Get custom tax
    if ('taxonomies' == $_type || 'all' == $_type) {
        if (!empty($items)) {
            /*
             *
             * This fails
             * $items are in form of:
             * 0 => array('id' => 'pt', ...)
             */
            //            $custom_taxonomies = array_intersect_key( get_option( 'wpcf-custom-taxonomies',
            //                            array() ), array_flip( $items ) );
            $_items = array();
            foreach ($items as $k => $item) {
                if (is_array($item) && isset($item['id'])) {
                    $_items[$item['id']] = true;
                } else {
                    $_items[$item] = true;
                }
            }
            $custom_taxonomies = array_intersect_key(get_option('wpcf-custom-taxonomies', array()), $_items);
        } else {
            // Get custom tax
            $custom_taxonomies = get_option('wpcf-custom-taxonomies', array());
        }
        if (!empty($custom_taxonomies)) {
            foreach ($custom_taxonomies as $key => $tax) {
                $custom_taxonomies[$key]['id'] = $key;
                $custom_taxonomies[$key] = apply_filters('wpcf_export_custom_post_type', $custom_taxonomies[$key]);
                $custom_taxonomies[$key]['__types_id'] = $key;
                $custom_taxonomies[$key]['__types_title'] = $tax['labels']['name'];
                $custom_taxonomies[$key]['checksum'] = $wpcf->export->generate_checksum('custom_taxonomy', $key, $tax);
            }
            $data['taxonomies'] = $custom_taxonomies;
            $data['taxonomies']['__key'] = 'taxonomy';
        }
    }
    /*
     *
     * Since Types 1.2
     */
    if ($return == 'array') {
        return $data;
    } else {
        if ($return == 'xml') {
            return $xml->array2xml($data, 'types');
        } else {
            if ($return == 'module_manager') {
                $items = array();
                // Re-arrange fields
                if (!empty($data['fields'])) {
                    foreach ($data['fields'] as $_data) {
                        if (is_array($_data) && isset($_data['__types_id']) && isset($_data['checksum'])) {
                            $_item = array();
                            $_item['hash'] = $_item['checksum'] = $_data['checksum'];
                            $_item['id'] = $_data['__types_id'];
                            $_item['title'] = $_data['__types_title'];
                            $items['__fields'][$_data['__types_id']] = $_item;
                        }
                    }
                }
                // Add checksums to items
                foreach ($data as $_t => $type) {
                    foreach ($type as $_data) {
                        // Skip fields
                        if ($_t == 'fields') {
                            continue;
                        }
                        if (is_array($_data) && isset($_data['__types_id']) && isset($_data['checksum'])) {
                            $_item = array();
                            $_item['hash'] = $_item['checksum'] = $_data['checksum'];
                            $_item['id'] = $_data['__types_id'];
                            $_item['title'] = $_data['__types_title'];
                            $items[$_data['__types_id']] = $_item;
                        }
                    }
                }
                return array('xml' => $xml->array2xml($data, 'types'), 'items' => $items);
            }
        }
    }
    // Offer for download
    $data = $xml->array2xml($data, 'types');
    $sitename = sanitize_title(get_bloginfo('name'));
    if (empty($sitename)) {
        $sitename = 'wp';
    }
    $sitename .= '.';
    $filename = $sitename . 'types.' . date('Y-m-d') . '.xml';
    $code = "<?php\r\n";
    $code .= '$timestamp = ' . time() . ';' . "\r\n";
    $code .= '$auto_import = ';
    $code .= isset($_POST['embedded-settings']) && $_POST['embedded-settings'] == 'ask' ? 0 : 1;
    $code .= ';' . "\r\n";
    $code .= "\r\n?" . ">";
    if (class_exists('ZipArchive')) {
        $zipname = $sitename . 'types.' . date('Y-m-d') . '.zip';
        $temp_dir = wpcf_get_temporary_directory();
        if (empty($temp_dir)) {
            die(__('There is a problem with temporary directory.'));
        }
        $file = tempnam($temp_dir, "zip");
        $zip = new ZipArchive();
        $zip->open($file, ZipArchive::OVERWRITE);
        /**
         * if sys_get_temp_dir fail in case of open_basedir restriction,
         * try use wp_upload_dir instead. if this fail too, send pure
         * xml file to user
         */
        if (empty($zip->filename)) {
            $temp_dir = wp_upload_dir();
            $temp_dir = $temp_dir['basedir'];
            $file = tempnam($temp_dir, "zip");
            $zip = new ZipArchive();
            $zip->open($file, ZipArchive::OVERWRITE);
        }
        /**
         * send a zip file
         */
        if (!empty($zip->filename)) {
            $zip->addFromString('settings.xml', $data);
            $zip->addFromString('settings.php', $code);
            $zip->close();
            $data = file_get_contents($file);
            header("Content-Description: File Transfer");
            header("Content-Disposition: attachment; filename=" . $zipname);
            header("Content-Type: application/zip");
            header("Content-length: " . strlen($data) . "\n\n");
            header("Content-Transfer-Encoding: binary");
            echo $data;
            unlink($file);
            die;
        }
    }
    /**
     * download the xml if fail downloading zip
     */
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=" . $filename);
    header("Content-Type: application/xml");
    header("Content-length: " . strlen($data) . "\n\n");
    echo $data;
    die;
}
/**
 * Single condition form elements.
 *
 * @param type $data
 * @param type $condition
 * @param type $key
 * @return string
 */
function wpcf_cd_admin_form_single_filter($data, $condition, $key = null, $group = false, $force_multi = false)
{
    global $wpcf;
    if ($group) {
        $name = 'wpcf[group][conditional_display]';
    } else {
        $name = 'wpcf[fields][' . $data['id'] . '][conditional_display]';
    }
    $group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : false;
    /*
     *
     *
     * TODO Review this allowing fields from same group as conditional (self loop)
     * I do not remember allowing fields from same group as conditional (self loop)
     * on Group Fields edit screen.
     */
    //    if ( $group_id && !$group ) {// Allow group to use other fields
    //        $fields = wpcf_admin_fields_get_fields_by_group( $group_id );
    //    } else {
    $fields = wpcf_admin_fields_get_fields(true, false, true);
    ksort($fields, SORT_STRING);
    //    }
    if ($group) {
        $_distinct = wpcf_admin_fields_get_fields_by_group($group_id);
        foreach ($_distinct as $_field_id => $_field) {
            if (isset($fields[$_field_id])) {
                unset($fields[$_field_id]);
            }
        }
    }
    $options = array();
    $ignore_field_type_array = array('audio', 'checkboxes', 'embed', 'file', 'image', 'video', 'wysiwyg');
    $flag_repetitive = false;
    foreach ($fields as $field_id => $field) {
        if (!$group && $data['id'] == $field_id) {
            continue;
        }
        // WE DO NOT ALLOW repetitive fields to be compared.
        if (wpcf_admin_is_repetitive($field)) {
            $flag_repetitive = true;
            continue;
        }
        /**
         * Skip some files
         */
        if (in_array($field['type'], $ignore_field_type_array)) {
            continue;
        }
        /**
         * build options
         */
        $options[$field_id] = array('#value' => $field_id, '#title' => stripslashes($field['name']), '#attributes' => array('class' => 'wpcf-conditional-select-' . $field['type']));
    }
    /*
     * Special case
     * https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/153565054/comments
     *
     * When field is new and only one diff field in list - that
     * means one field is saved but other not yet.
     */
    $is_new = isset($data['id']) && isset($fields[$data['id']]) ? false : true;
    $special_stop = false;
    if ($is_new) {
        if (count($options) == 1) {
            $special_stop = true;
        }
    }
    /*
     *
     * This means all fields are repetitive and no one left to compare with.
     * WE DO NOT ALLOW repetitive fields to be compared.
     */
    if (!$group && empty($options) && $flag_repetitive) {
        return array('cd' => array('#type' => 'markup', '#markup' => '<p class="wpcf-error">' . __('Conditional display is only working based on non-repeating fields. All fields in this group are repeating, so you cannot set their display based on other fields.', 'wpcf') . '</p>' . wpcf_conditional_disable_add_js($data['id'])));
    } else {
        if (!$group && (empty($options) || $special_stop)) {
            return array('cd' => array('#type' => 'markup', '#markup' => '<p>' . __('You will be able to set conditional field display when you save more fields.', 'wpcf') . '</p>'));
        }
    }
    $id = !is_null($key) ? $key : strval('condition_' . wpcf_unique_id(serialize($data) . serialize($condition) . $key . $group));
    $form = array();
    $before = '<div class="wpcf-cd-entry"><br />';
    $form['cd']['field_' . $id] = array('#type' => 'select', '#name' => $name . '[conditions][' . $id . '][field]', '#options' => $options, '#inline' => true, '#before' => $before, '#default_value' => isset($condition['field']) ? $condition['field'] : null, '#attributes' => array('class' => 'wpcf-cd-field'));
    $form['cd']['operation_' . $id] = array('#type' => 'select', '#name' => $name . '[conditions][' . $id . '][operation]', '#options' => array_flip(wpcf_cd_admin_operations()), '#inline' => true, '#default_value' => isset($condition['operation']) ? $condition['operation'] : null, '#attributes' => array('class' => 'wpcf-cd-operation'));
    $form['cd']['value_' . $id] = array('#type' => 'textfield', '#name' => $name . '[conditions][' . $id . '][value]', '#inline' => true, '#value' => isset($condition['value']) ? $condition['value'] : '', '#attributes' => array('class' => 'wpcf-cd-value'));
    /*
     *
     * Adjust for date
     */
    if (!empty($condition['value'])) {
        WPCF_Loader::loadInclude('fields/date/functions.php');
        $timestamp = wpcf_fields_date_convert_datepicker_to_timestamp($condition['value']);
        if ($timestamp !== false) {
            $date_value = adodb_date('d', $timestamp) . ',' . adodb_date('m', $timestamp) . ',' . adodb_date('Y', $timestamp);
            $date_function = 'date';
        } else {
            if (wpcf_fields_date_timestamp_is_valid($condition['value'])) {
                $date_value = adodb_date('d', $condition['value']) . ',' . adodb_date('m', $condition['value']) . ',' . adodb_date('Y', $condition['value']);
                $date_function = 'date';
            }
        }
    }
    if (empty($date_value)) {
        $date_value = '';
        $date_function = false;
    }
    $form['cd']['value_date_' . $id] = array('#type' => 'markup', '#markup' => '<br />' . wpcf_conditional_add_date_controls($date_function, $date_value, $name . '[conditions][' . $id . ']'), '#attributes' => array('class' => 'wpcf-cd-value-date'));
    $form['cd']['remove_' . $id] = array('#type' => 'button', '#name' => 'remove', '#value' => __('Remove condition', 'wpcf'), '#attributes' => array('onclick' => 'wpcfCdRemoveCondition(jQuery(this));', 'class' => 'wpcf-add-condition'), '#after' => '</div><br />');
    return $form['cd'];
}
/**
 * Edit fields form.
 *
 * @param type $parent
 * @param type $child
 */
function wpcf_pr_admin_edit_fields($parent, $child)
{
    $post_type_parent = get_post_type_object($parent);
    $post_type_child = get_post_type_object($child);
    if (empty($post_type_parent) || empty($post_type_child)) {
        die(__('Wrong post types', 'wpcf'));
    }
    $relationships = get_option('wpcf_post_relationship', array());
    if (!isset($relationships[$parent][$child])) {
        die(__('Relationship do not exist', 'wpcf'));
    }
    $data = $relationships[$parent][$child];
    wp_enqueue_script('jquery');
    wp_enqueue_style('types');
    wpcf_admin_ajax_head('Edit fields', 'wpcf');
    // Process submit
    if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'pt_edit_fields')) {
        $relationships[$parent][$child]['fields_setting'] = sanitize_text_field($_POST['fields_setting']);
        // @todo Maybe sanitization here
        $relationships[$parent][$child]['fields'] = isset($_POST['fields']) ? $_POST['fields'] : array();
        update_option('wpcf_post_relationship', $relationships);
        ?>
        <script type="text/javascript">
            window.parent.jQuery('#TB_closeWindowButton').trigger('click');
            window.parent.location.reload();
        </script>
        <?php 
        die;
    }
    $groups = wpcf_admin_get_groups_by_post_type($child);
    $options_cf = array();
    $repetitive_warning = false;
    $repetitive_warning_markup = array();
    $repetitive_warning_txt = __('Repeating fields should not be used in child posts. Types will update all field values.', 'wpcf');
    foreach ($groups as $group) {
        $fields = wpcf_admin_fields_get_fields_by_group($group['id']);
        foreach ($fields as $key => $cf) {
            $__key = wpcf_types_cf_under_control('check_outsider', $key) ? $key : WPCF_META_PREFIX . $key;
            $options_cf[$__key] = array();
            $options_cf[$__key]['#title'] = $cf['name'];
            $options_cf[$__key]['#name'] = 'fields[' . $__key . ']';
            $options_cf[$__key]['#default_value'] = isset($data['fields'][$__key]) ? 1 : 0;
            // Repetitive warning
            if (wpcf_admin_is_repetitive($cf)) {
                if (!$repetitive_warning) {
                    $repetitive_warning_markup = array('#type' => 'markup', '#markup' => '<div class="message error" style="display:none;" id="wpcf-repetitive-warning"><p>' . $repetitive_warning_txt . '</p></div>');
                }
                $repetitive_warning = true;
                $options_cf[$__key]['#after'] = !isset($data['fields'][$__key]) ? '<div class="message error" style="display:none;"><p>' : '<div class="message error"><p>';
                $options_cf[$__key]['#after'] .= $repetitive_warning_txt;
                $options_cf[$__key]['#after'] .= '</p></div>';
                $options_cf[$__key]['#attributes'] = array('onclick' => 'jQuery(this).parent().find(\'.message\').toggle();', 'disabled' => 'disabled');
            }
        }
    }
    $form = array();
    $form['repetitive_warning_markup'] = $repetitive_warning_markup;
    $form['select'] = array('#type' => 'radios', '#name' => 'fields_setting', '#options' => array(__('Title, all custom fields and parents', 'wpcf') => 'all_cf', __('Do not show management options for this post type', 'wpcf') => 'only_list', __('All fields, including the standard post fields', 'wpcf') => 'all_cf_standard', __('Specific fields', 'wpcf') => 'specific'), '#default_value' => empty($data['fields_setting']) ? 'all_cf' : $data['fields_setting']);
    /**
     * check default, to avoid missing configuration
     */
    if (!in_array($form['select']['#default_value'], $form['select']['#options'])) {
        $form['select']['#default_value'] = 'all_cf';
    }
    /**
     * build options for "Specific fields"
     */
    $options = array();
    /**
     * check and add build-in properites
     */
    $check_support = array('title' => array('name' => '_wp_title', 'title' => __('Post title', 'wpcf')), 'editor' => array('name' => '_wp_body', 'title' => __('Post body', 'wpcf')), 'excerpt' => array('name' => '_wp_excerpt', 'title' => __('Post excerpt', 'wpcf')), 'thumbnail' => array('name' => '_wp_featured_image', 'title' => __('Post featured image', 'wpcf')));
    foreach ($check_support as $child_field_key => $child_field_data) {
        if (!post_type_supports($child, $child_field_key)) {
            continue;
        }
        $options[$child_field_data['name']] = array('#title' => $child_field_data['title'], '#name' => sprintf('fields[%s]', $child_field_data['name']), '#default_value' => isset($data['fields'][$child_field_data['name']]) ? 1 : 0);
    }
    /**
     * add custom fields
     */
    $options = $options + $options_cf;
    $temp_belongs = wpcf_pr_admin_get_belongs($child);
    foreach ($temp_belongs as $temp_parent => $temp_data) {
        if ($temp_parent == $parent) {
            continue;
        }
        $temp_parent_type = get_post_type_object($temp_parent);
        $options[$temp_parent] = array();
        $options[$temp_parent]['#title'] = $temp_parent_type->label;
        $options[$temp_parent]['#name'] = 'fields[_wpcf_pr_parents][' . $temp_parent . ']';
        $options[$temp_parent]['#default_value'] = isset($data['fields']['_wpcf_pr_parents'][$temp_parent]) ? 1 : 0;
    }
    /**
     * remove "Specific fields" if there is no fields
     */
    if (empty($options)) {
        unset($form['select']['#options'][__('Specific fields', 'wpcf')]);
        if ('specific' == $form['select']['#default_value']) {
            $form['select']['#default_value'] = 'all_cf';
        }
    }
    // Taxonomies
    $taxonomies = get_object_taxonomies($post_type_child->name, 'objects');
    if (!empty($taxonomies)) {
        foreach ($taxonomies as $tax_id => $taxonomy) {
            $options[$tax_id] = array();
            $options[$tax_id]['#title'] = sprintf(__('Taxonomy - %s', 'wpcf'), $taxonomy->label);
            $options[$tax_id]['#name'] = 'fields[_wpcf_pr_taxonomies][' . $tax_id . ']';
            $options[$tax_id]['#default_value'] = isset($data['fields']['_wpcf_pr_taxonomies'][$tax_id]) ? 1 : 0;
        }
    }
    $form['specific'] = array('#type' => 'checkboxes', '#name' => 'fields', '#options' => $options, '#default_value' => isset($data['fields']), '#before' => '<div id="wpcf-specific" style="display:none;margin:10px 0 0 20px;">', '#after' => '</div>');
    $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary'));
    echo '<form method="post" action="" class="types-select-child-fields">';
    echo wpcf_form_simple($form);
    echo wp_nonce_field('pt_edit_fields');
    echo '</form>';
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function(){
            if (jQuery('input[name="fields_setting"]:checked').val() == 'specific') {
                jQuery('#wpcf-specific').show();
            } else {
    <?php 
    if ($repetitive_warning && 'only_list' != $form['select']['#default_value']) {
        ?>
                    jQuery('#wpcf-repetitive-warning').show();
        <?php 
    }
    ?>
            }
            jQuery('input[name="fields_setting"]').change(function(){
                if (jQuery(this).val() == 'specific') {
                    jQuery('#wpcf-specific').slideDown();
                } else {
                    jQuery('#wpcf-specific').slideUp();
    <?php 
    if ($repetitive_warning) {
        ?>
                    if ( 'only_list' != jQuery('input[name="fields_setting"]:checked').val()) {
                        jQuery('#wpcf-repetitive-warning').show();
                    }
        <?php 
    }
    ?>
                }
            });
        });
    </script>
    <?php 
    wpcf_admin_ajax_footer();
}
 /**
  * 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 form()
 {
     $this->save();
     global $wpcf;
     $this->current_user_can_edit = WPCF_Roles::user_can_create('user-meta-field');
     // If it's update, get data
     $this->update = false;
     if (isset($_REQUEST[$this->get_id])) {
         $this->update = wpcf_admin_fields_get_group(intval($_REQUEST[$this->get_id]), TYPES_USER_META_FIELD_GROUP_CPT_NAME);
         $this->current_user_can_edit = WPCF_Roles::user_can_edit('user-meta-field', $this->update);
         if (empty($this->update)) {
             $this->update = false;
             wpcf_admin_message(sprintf(__("Group with ID %d do not exist", 'wpcf'), intval($_REQUEST[$this->get_id])));
         } else {
             $this->update['fields'] = wpcf_admin_fields_get_fields_by_group(sanitize_text_field($_REQUEST[$this->get_id]), 'slug', false, true, false, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta');
             $this->update['show_for'] = wpcf_admin_get_groups_showfor_by_group(sanitize_text_field($_REQUEST[$this->get_id]));
             if (defined('TYPES_USE_STYLING_EDITOR') && TYPES_USE_STYLING_EDITOR) {
                 $this->update['admin_styles'] = wpcf_admin_get_groups_admin_styles_by_group(sanitize_text_field($_REQUEST[$this->get_id]));
             }
         }
     }
     /**
      * sanitize id
      */
     if (!isset($this->update['id'])) {
         $this->update['id'] = 0;
     }
     /**
      * setup meta type
      */
     $this->update['meta_type'] = 'custom_fields_group';
     /**
      * copy update to ct
      */
     $this->ct = $this->update;
     $form = $this->prepare_screen();
     $form['_wpnonce_wpcf'] = array('#type' => 'markup', '#markup' => wp_nonce_field('wpcf_form_fields', '_wpnonce_wpcf', true, false));
     /**
      * nonce depend on group id
      */
     $form['_wpnonce_' . $this->post_type] = array('#type' => 'markup', '#markup' => wp_nonce_field($this->get_nonce_action($this->update['id']), 'wpcf_save_group_nonce', true, false));
     $form['form-open'] = array('#type' => 'markup', '#markup' => sprintf('<div id="post-body-content" class="%s">', $this->current_user_can_edit ? '' : 'wpcf-types-read-only'));
     $form[$this->get_id] = array('#type' => 'hidden', '#name' => 'wpcf[group][id]', '#value' => $this->update['id']);
     $form['table-1-open'] = array('#type' => 'markup', '#markup' => '<table id="wpcf-types-form-name-table" class="wpcf-types-form-table widefat js-wpcf-slugize-container"><thead><tr><th colspan="2">' . __('Field Group name and description', 'wpcf') . '</th></tr></thead><tbody>');
     $table_row = '<tr><td><LABEL></td><td><ERROR><BEFORE><ELEMENT><AFTER></td></tr>';
     $form['title'] = array('#title' => sprintf('%s <b>(%s)</b>', __('Field Group name', 'wpcf'), __('required', 'wpcf')), '#type' => 'textfield', '#name' => 'wpcf[group][name]', '#id' => 'wpcf-group-name', '#value' => $this->update['id'] ? $this->update['name'] : '', '#inline' => true, '#attributes' => array('class' => 'large-text', 'placeholder' => __('Enter group title', 'wpcf')), '#validate' => array('required' => array('value' => true)), '#pattern' => $table_row);
     $form['description'] = array('#title' => __('Description', 'wpcf'), '#type' => 'textarea', '#id' => 'wpcf-group-description', '#name' => 'wpcf[group][description]', '#value' => $this->update['id'] ? $this->update['description'] : '', '#attributes' => array('placeholder' => __('Enter a description for this group', 'wpcf'), 'class' => 'hidden js-wpcf-description'), '#pattern' => $table_row, '#after' => sprintf('<a class="js-wpcf-toggle-description hidden" href="#">%s</a>', __('Add description', 'wpcf')), '#inline' => true);
     $form['table-1-close'] = array('#type' => 'markup', '#markup' => '</tbody></table>');
     /**
      * fields
      */
     $form += $this->fields();
     $form['form-close'] = array('#type' => 'markup', '#markup' => '</div>', '_builtin' => true);
     /**
      * setup common setting for forms
      */
     $form = $this->common_form_setup($form);
     /**
      * return form if current_user_can edit
      */
     if ($this->current_user_can_edit) {
         return $form;
     }
     return wpcf_admin_common_only_show($form);
 }
Beispiel #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());
 }
Beispiel #30
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;
}