Esempio n. 1
0
/**
 * Add/Edit usermeta fields group
 *
 * @author Gen gen.i@icanlocalize.com
 * @since Types 1.3
 */
function wpcf_admin_menu_edit_user_fields()
{
    $title = __('View User Fields Group', 'wpcf');
    if (isset($_GET['group_id'])) {
        $item = wpcf_admin_get_user_field_group_by_id($_GET['group_id']);
        if (WPCF_Roles::user_can_edit('user-meta-field', $item)) {
            $title = __('Edit User Fields Group', 'wpcf');
        }
    } else {
        if (WPCF_Roles::user_can_create('user-meta-field')) {
            $title = __('Add New User Fields Group', 'wpcf');
        }
    }
    wpcf_add_admin_header($title);
    $form = wpcf_form('wpcf_form_fields');
    echo '<br /><form method="post" action="" class="wpcf-fields-form ' . 'wpcf-form-validate" onsubmit="';
    echo 'if (jQuery(\'#wpcf-group-name\').val() == \'' . __('Enter group title', 'wpcf') . '\') { jQuery(\'#wpcf-group-name\').val(\'\'); }';
    echo 'if (jQuery(\'#wpcf-group-description\').val() == \'' . __('Enter a description for this group', 'wpcf') . '\') { jQuery(\'#wpcf-group-description\').val(\'\'); }';
    echo 'jQuery(\'.wpcf-forms-set-legend\').each(function(){
        if (jQuery(this).val() == \'' . __('Enter field name', 'wpcf') . '\') {
            jQuery(this).val(\'\');
        }
        if (jQuery(this).next().val() == \'' . __('Enter field slug', 'wpcf') . '\') {
            jQuery(this).next().val(\'\');
        }
        if (jQuery(this).next().next().val() == \'' . __('Describe this field', 'wpcf') . '\') {
            jQuery(this).next().next().val(\'\');
        }
	});';
    echo '">';
    echo $form->renderForm();
    echo '</form>';
    wpcf_add_admin_footer();
}
 public static function getInstance()
 {
     if (!self::$instance) {
         self::$instance = new WPCF_Roles();
     }
     return self::$instance;
 }
Esempio n. 3
0
 function get_columns()
 {
     $columns = array();
     if (WPCF_Roles::user_can_create('term-field')) {
         $columns['cb'] = '<input type="checkbox" />';
     }
     return array_merge($columns, array('name' => __('Term Field Name', 'wpcf'), 'groups' => __('Field Groups', 'wpcf'), 'slug' => __('Slug', 'wpcf'), 'field_type' => __('Type', 'wpcf')));
 }
function wpcf_admin_common_metabox_save($ct, $button_text, $type = 'custom-post-type')
{
    $form = array();
    if (WPCF_Roles::user_can_edit($type, $ct)) {
        $form['submit-open'] = wpcf_admin_metabox_begin(__('Save', 'wpcf'), 'submitdiv', false, false, '_builtin');
        $form['submit-div-open'] = array('#type' => 'markup', '#markup' => '<div class="submitbox" id="submitpost"><div id="major-publishing-actions"><div id="publishing-action"><span class="spinner"></span>', '_builtin' => true);
        $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => $button_text, '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit'), '_builtin' => true);
        /**
         * add data attribute for _builtin post type
         */
        if (isset($ct['_builtin']) && $ct['_builtin']) {
            $form['submit']['#attributes']['data-post_type_is_builtin'] = '_builtin';
        }
        $form['submit-div-close'] = array('#type' => 'markup', '#markup' => '</div><div class="clear"></div></div></div>', '_builtin' => true);
        $form['submit-close'] = wpcf_admin_metabox_end(true, '_builtin');
    }
    return $form;
}
/**
 * Add/Edit usermeta fields group
 *
 * @author Gen gen.i@icanlocalize.com
 * @since Types 1.3
 */
function wpcf_admin_menu_edit_user_fields()
{
    $add_new = false;
    $post_type = current_filter();
    $title = __('View User Field Group', 'wpcf');
    if (isset($_GET['group_id'])) {
        $item = wpcf_admin_get_user_field_group_by_id((int) $_GET['group_id']);
        if (WPCF_Roles::user_can_edit('user-meta-field', $item)) {
            $title = __('Edit User Field Group', 'wpcf');
            $add_new = array('page' => 'wpcf-edit-usermeta');
        }
    } else {
        if (WPCF_Roles::user_can_create('user-meta-field')) {
            $title = __('Add New User Field Group', 'wpcf');
        }
    }
    wpcf_add_admin_header($title, $add_new);
    $form = wpcf_form('wpcf_form_fields');
    echo '<form method="post" action="" class="wpcf-fields-form wpcf-form-validate js-types-show-modal">';
    wpcf_admin_screen($post_type, $form->renderForm());
    echo '</form>';
    wpcf_add_admin_footer();
    return;
    $form = wpcf_form('wpcf_form_fields');
    echo '<br /><form method="post" action="" class="wpcf-fields-form ' . 'wpcf-form-validate" onsubmit="';
    echo 'if (jQuery(\'#wpcf-group-name\').val() == \'' . __('Enter group title', 'wpcf') . '\') { jQuery(\'#wpcf-group-name\').val(\'\'); }';
    echo 'if (jQuery(\'#wpcf-group-description\').val() == \'' . __('Enter a description for this group', 'wpcf') . '\') { jQuery(\'#wpcf-group-description\').val(\'\'); }';
    echo 'jQuery(\'.wpcf-forms-set-legend\').each(function(){
        if (jQuery(this).val() == \'' . __('Enter field name', 'wpcf') . '\') {
            jQuery(this).val(\'\');
        }
        if (jQuery(this).next().val() == \'' . __('Enter field slug', 'wpcf') . '\') {
            jQuery(this).next().val(\'\');
        }
        if (jQuery(this).next().next().val() == \'' . __('Describe this field', 'wpcf') . '\') {
            jQuery(this).next().next().val(\'\');
        }
	});';
    echo '">';
    echo $form->renderForm();
    echo '</form>';
    wpcf_add_admin_footer();
}
Esempio n. 6
0
/**
 * Generates form data.
 */
function wpcf_admin_usermeta_form()
{
    /**
     * include common functions
     */
    include_once dirname(__FILE__) . '/common-functions.php';
    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();
    $current_user_can_edit = WPCF_Roles::user_can_create('user-meta-field');
    // If it's update, get data
    $update = false;
    if (isset($_REQUEST['group_id'])) {
        $update = wpcf_admin_fields_get_group(intval($_REQUEST['group_id']), TYPES_USER_META_FIELD_GROUP_CPT_NAME);
        $current_user_can_edit = WPCF_Roles::user_can_edit('user-meta-field', $update);
        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, false, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta');
            $update['show_for'] = wpcf_admin_get_groups_showfor_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_usermeta_groups_submit');
    $form['form-open'] = array('#type' => 'markup', '#markup' => sprintf('<div id="poststuff" class="%s">', $current_user_can_edit ? '' : 'wpcf-types-read-only'));
    // Form sidebars
    if ($current_user_can_edit) {
        $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_TOOLSET_RELPATH . '/toolset-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" class="wpcf-form-fields-main">');
    $form['title'] = array('#type' => 'textfield', '#name' => 'wpcf[group][name]', '#id' => 'wpcf-group-name', '#value' => $update ? wp_kses_post($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 ? wp_kses_post($update['description']) : '', '#attributes' => array('placeholder' => __('Enter a description for this group', 'wpcf')));
    // 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**/
    if (defined('TYPES_USE_STYLING_EDITOR') && TYPES_USE_STYLING_EDITOR && $current_user_can_edit) {
        $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 . '/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', 'wpcf') . '</h3>
            <div id="wpcf-update-preview-div">Preview here</div>
            <script type="text/javascript">
var wpcfReadOnly = ' . json_encode(base64_encode($preview_profile)) . ';
var wpcfEditMode = ' . json_encode(base64_encode($edit_profile)) . ';
var wpcfDefaultCss = ' . json_encode(base64_encode($admin_styles_value)) . ';
        </script>
        ', '#before' => sprintf('<h3>%s</h3>', __('Your CSS', 'wpcf')));
        $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 Content 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 Content 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') . '\'');
    /**
     * close form div
     */
    $form['form-close'] = array('#type' => 'markup', '#markup' => '</div>');
    /**
     * return form if current_user_can edit
     */
    if ($current_user_can_edit) {
        return $form;
    }
    return wpcf_admin_common_only_show($form);
}
 /**
  * Summary.
  *
  * Description.
  *
  * @since x.x.x
  * @access (for functions: only use if private)
  *
  * @see Function/method/class relied on
  * @link URL
  * @global type $varname Description.
  * @global type $varname Description.
  *
  * @param type $var Description.
  * @param type $var Optional. Description.
  * @return type Description.
  */
 public function form()
 {
     $this->save();
     global $wpcf;
     $id = false;
     $update = false;
     $taxonomies = array();
     if (isset($_GET[$this->get_id])) {
         $id = sanitize_text_field($_GET[$this->get_id]);
     } elseif (isset($_POST[$this->get_id])) {
         $id = sanitize_text_field($_POST[$this->get_id]);
     }
     if ($id) {
         $taxonomies = $this->taxonomies->get();
         if (isset($taxonomies[$id])) {
             $this->ct = $taxonomies[$id];
             $update = true;
         } else {
             wpcf_admin_message(__('Wrong Taxonomy specified.', 'wpcf'), 'error');
             return false;
         }
     } else {
         $this->ct = wpcf_custom_taxonomies_default();
     }
     $current_user_can_edit = WPCF_Roles::user_can_edit('custom-taxonomy', $this->ct);
     /**
      * sanitize _builtin
      */
     if (!isset($this->ct['_builtin'])) {
         $this->ct['_builtin'] = false;
     }
     $form = $this->prepare_screen();
     if ($current_user_can_edit && $update) {
         $form['id'] = array('#type' => 'hidden', '#value' => $id, '#name' => 'ct[wpcf-tax]');
     }
     /**
      * post icon field
      */
     $menu_icon = isset($this->ct['icon']) && !empty($this->ct['icon']) ? $this->ct['icon'] : 'admin-post';
     $form['icon'] = array('#type' => 'hidden', '#name' => 'ct[icon]', '#value' => $menu_icon, '#id' => 'wpcf-types-icon');
     $form['form-open'] = array('#type' => 'markup', '#markup' => sprintf('<div id="post-body-content" class="%s">', $current_user_can_edit ? '' : 'wpcf-types-read-only'), '_builtin' => true);
     $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">' . __('Taxonomy name and description', 'wpcf') . '</th></tr></thead><tbody>');
     $table_row = '<tr><td><LABEL></td><td><ERROR><BEFORE><ELEMENT><AFTER></td></tr>';
     $form['name'] = array('#type' => 'textfield', '#name' => 'ct[labels][name]', '#title' => __('Taxonomy name plural', 'wpcf') . ' (<strong>' . __('required', 'wpcf') . '</strong>)', '#description' => '<strong>' . __('Enter in plural!', 'wpcf') . '.', '#value' => isset($this->ct['labels']['name']) ? wp_kses_post($this->ct['labels']['name']) : '', '#validate' => array('required' => array('value' => true), 'maxlength' => array('value' => 30)), '#pattern' => $table_row, '#inline' => true, '#attributes' => array('placeholder' => __('Enter Taxonomy name plural', 'wpcf'), 'class' => 'widefat'));
     $form['name-singular'] = array('#type' => 'textfield', '#name' => 'ct[labels][singular_name]', '#title' => __('Taxonomy name singular', 'wpcf') . ' (<strong>' . __('required', 'wpcf') . '</strong>)', '#description' => '<strong>' . __('Enter in singular!', 'wpcf') . '</strong><br />' . '.', '#value' => isset($this->ct['labels']['singular_name']) ? wp_kses_post($this->ct['labels']['singular_name']) : '', '#validate' => array('required' => array('value' => true), 'maxlength' => array('value' => 30)), '#pattern' => $table_row, '#inline' => true, '#attributes' => array('placeholder' => __('Enter Taxonomy name singular', 'wpcf'), 'class' => 'widefat js-wpcf-slugize-source'));
     /*
      *
      * IF isset $_POST['slug'] it means form is not submitted
      */
     $attributes = array();
     if (!empty($_POST['ct']['slug'])) {
         $reserved = wpcf_is_reserved_name(sanitize_text_field($_POST['ct']['slug']), 'taxonomy');
         if (is_wp_error($reserved)) {
             $attributes = array('class' => 'wpcf-form-error', 'onclick' => 'jQuery(this).removeClass(\'wpcf-form-error\');');
         }
     }
     $form['slug'] = array('#type' => 'textfield', '#name' => 'ct[slug]', '#title' => __('Slug', 'wpcf') . ' (<strong>' . __('required', 'wpcf') . '</strong>)', '#description' => '<strong>' . __('Enter in singular!', 'wpcf') . '</strong><br />' . __('Machine readable name.', 'wpcf') . '<br />' . __('If not provided - will be created from singular name.', 'wpcf') . '<br />', '#value' => isset($this->ct['slug']) ? $this->ct['slug'] : '', '#pattern' => $table_row, '#inline' => true, '#validate' => array('required' => array('value' => true), 'nospecialchars' => array('value' => true), 'maxlength' => array('value' => 30)), '#attributes' => $attributes + array('maxlength' => '30', 'placeholder' => __('Enter Taxonomy slug', 'wpcf'), 'class' => 'widefat js-wpcf-slugize'));
     $form['description'] = array('#type' => 'textarea', '#name' => 'ct[description]', '#title' => __('Description', 'wpcf'), '#value' => isset($this->ct['description']) ? $this->ct['description'] : '', '#attributes' => array('rows' => 4, 'cols' => 60, 'placeholder' => __('Enter Taxonomy description', 'wpcf'), 'class' => 'hidden js-wpcf-description'), '#pattern' => $table_row, '#inline' => true, '#after' => $this->ct['_builtin'] ? __('This is built-in WordPress Taxonomy.', 'wpcf') : sprintf('<a class="js-wpcf-toggle-description hidden" href="#">%s</a>', __('Add description', 'wpcf')));
     $form['table-1-close'] = array('#type' => 'markup', '#markup' => '</tbody></table>');
     $form['box-1-close'] = array('#type' => 'markup', '#markup' => '</div>', '_builtin' => true);
     if ($this->ct['_builtin']) {
         $form['name']['#attributes']['disabled'] = 'disabled';
         $form['name-singular']['#attributes']['disabled'] = 'disabled';
         $form['slug']['#attributes']['disabled'] = 'disabled';
         $form['description']['#attributes']['disabled'] = 'disabled';
     }
     /**
      * return form if current_user_can edit
      */
     if ($current_user_can_edit) {
         return $form;
     }
     return wpcf_admin_common_only_show($form);
 }
/**
 * Adds typical header on admin pages.
 *
 * @param string $title
 * @param string $icon_id Custom icon
 * @return string
 */
function wpcf_add_admin_header($title, $add_new = false, $add_new_title = false)
{
    echo '<div class="wrap">';
    echo '<h2>', $title;
    if (!$add_new_title) {
        $add_new_title = __('Add New', 'wpcf');
    }
    if (is_array($add_new) && isset($add_new['page'])) {
        $add_button = false;
        /**
         * check user can?
         */
        switch ($add_new['page']) {
            case 'wpcf-edit-type':
                $add_button = WPCF_Roles::user_can_create('custom-post-type');
                break;
            case 'wpcf-edit-tax':
                $add_button = WPCF_Roles::user_can_create('custom-taxonomy');
                break;
            case 'wpcf-edit':
                $add_button = WPCF_Roles::user_can_create('custom-field');
                break;
            case 'wpcf-edit-usermeta':
                $add_button = WPCF_Roles::user_can_create('user-meta-field');
                break;
            case WPCF_Page_Edit_Termmeta::PAGE_NAME:
                $add_button = WPCF_Roles::user_can_create('term-field');
                break;
        }
        if ($add_button) {
            printf(' <a href="%s" class="add-new-h2">%s</a>', esc_url(add_query_arg($add_new, admin_url('admin.php'))), $add_new_title);
        }
    }
    echo '</h2>';
    $current_page = sanitize_text_field($_GET['page']);
    do_action('wpcf_admin_header');
    do_action('wpcf_admin_header_' . $current_page);
}
 /** ************************************************************************
  * Optional. You can handle your bulk actions anywhere or anyhow you prefer.
  * For this example package, we will handle it in the class to keep things
  * clean and organized.
  *
  * @see $this->prepare_items()
  **************************************************************************/
 function process_bulk_action()
 {
     $action = $this->current_action();
     /**
      * check nounce
      */
     if (!empty($action)) {
         $nonce = '';
         if (isset($_REQUEST['_wpnonce'])) {
             $nonce = $_REQUEST['_wpnonce'];
         }
         if (!wp_verify_nonce($nonce, 'bulk-customtaxonomies')) {
             die('Security check');
         }
     }
     //Detect when a bulk action is being triggered...
     if (!empty($this->custom_taxonomies) && isset($_POST[$this->bulk_action_field_name]) && !empty($_POST[$this->bulk_action_field_name])) {
         $slugs_to_delete = array();
         foreach ($_POST[$this->bulk_action_field_name] as $key) {
             /**
              * do not process if there is no entry
              */
             if (!isset($this->custom_taxonomies[$key])) {
                 continue;
             }
             /**
              * check capability
              */
             if (!WPCF_Roles::user_can_edit('custom-taxonomy', $this->custom_taxonomies[$key])) {
                 continue;
             }
             /**
              * do it!
              */
             switch ($action) {
                 case 'delete':
                     unset($this->custom_taxonomies[$key]);
                     $slugs_to_delete[] = $key;
                     break;
                 case 'deactivate':
                     $this->custom_taxonomies[$key]['disabled'] = 1;
                     break;
                 case 'activate':
                     if (isset($this->custom_taxonomies[$key]['disabled'])) {
                         unset($this->custom_taxonomies[$key]['disabled']);
                     }
                     break;
             }
         }
         /**
          * update custom taxonomies
          */
         update_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, $this->custom_taxonomies);
         /**
          * update custom post types
          */
         if (count($slugs_to_delete)) {
             $custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
             if (!empty($custom_types)) {
                 foreach ($slugs_to_delete as $slug) {
                     foreach ($custom_types as $custom_key => $data) {
                         if (!isset($data['taxonomies'])) {
                             continue;
                         }
                         if (isset($data['taxonomies'][$slug])) {
                             unset($custom_types[$custom_key]['taxonomies'][$slug]);
                         }
                     }
                 }
                 update_option(WPCF_OPTION_NAME_CUSTOM_TYPES, $custom_types);
             }
         }
     }
 }
Esempio n. 10
0
 /**
  * Initialize and render the form.
  *
  * Determine if existing field group is being edited or if we're creating a new one.
  * If we're reloading the edit page after clicking Save button, save changes to database.
  * Generate an array with form field definitions (setup the form).
  * Fill $this->update with field group data.
  *
  * @return array
  */
 public function form()
 {
     $this->save();
     $this->current_user_can_edit = WPCF_Roles::user_can_create('term-field');
     $field_group_id = (int) wpcf_getarr($_REQUEST, $this->get_id, 0);
     // If it's update, get data
     if (0 != $field_group_id) {
         $this->update = wpcf_admin_fields_get_group($field_group_id, WPCF_Field_Group_Term::POST_TYPE);
         if (null == $this->get_field_group()) {
             $this->update = false;
             wpcf_admin_message(sprintf(__("Group with ID %d do not exist", 'wpcf'), $field_group_id));
         } else {
             $this->current_user_can_edit = WPCF_Roles::user_can_edit('custom-field', $this->update);
             $this->update['fields'] = wpcf_admin_fields_get_fields_by_group($field_group_id, 'slug', false, true, false, WPCF_Field_Group_Term::POST_TYPE, WPCF_Field_Term_Definition_Factory::FIELD_DEFINITIONS_OPTION);
         }
     }
     // sanitize id
     $this->update['id'] = $this->get_field_group_id();
     // copy update to ct... dafuq is "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
     $nonce_name = $this->get_nonce_action($this->update['id']);
     $form['_wpnonce_' . $this->post_type] = array('#type' => 'markup', '#markup' => wp_nonce_field($nonce_name, '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 Field Group name', '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 Field Group description', '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>');
     $form += $this->fields();
     $form['form-close'] = array('#type' => 'markup', '#markup' => '</div>', '_builtin' => true);
     // setup common setting for forms
     $form = $this->common_form_setup($form);
     if ($this->current_user_can_edit) {
         return $form;
     }
     return wpcf_admin_common_only_show($form);
 }
Esempio n. 11
0
/**
 * All AJAX calls go here.
 *
 * @global object $wpdb
 *
 */
function wpcf_ajax()
{
    /**
     * check nounce
     */
    if (!(isset($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'], $_REQUEST['wpcf_action']))) {
        die;
    }
    require_once WPCF_INC_ABSPATH . '/classes/class.wpcf.roles.php';
    /**
     * check permissions
     */
    switch ($_REQUEST['wpcf_action']) {
        case 'deactivate_post_type':
        case 'activate_post_type':
        case 'delete_post_type':
        case 'duplicate_post_type':
            $post_type = wpcf_ajax_helper_get_post_type();
            if (empty($post_type)) {
                wpcf_ajax_helper_print_error_and_die();
            }
            if (!WPCF_Roles::user_can_edit_custom_post_by_slug($post_type)) {
                wpcf_ajax_helper_verification_failed_and_die();
            }
            break;
        case 'taxonomy_duplicate':
        case 'deactivate_taxonomy':
        case 'activate_taxonomy':
        case 'delete_taxonomy':
            $custom_taxonomy = wpcf_ajax_helper_get_taxonomy();
            if (empty($custom_taxonomy)) {
                wpcf_ajax_helper_print_error_and_die();
            }
            if (!WPCF_Roles::user_can_edit_custom_taxonomy_by_slug($custom_taxonomy)) {
                wpcf_ajax_helper_verification_failed_and_die();
            }
            break;
        case 'deactivate_group':
        case 'activate_group':
        case 'delete_group':
            if (!isset($_GET['group_id']) || empty($_GET['group_id'])) {
                wpcf_ajax_helper_print_error_and_die();
            }
            if (!WPCF_Roles::user_can_edit_custom_field_group_by_id($_GET['group_id'])) {
                wpcf_ajax_helper_verification_failed_and_die();
            }
            break;
        case 'deactivate_user_group':
        case 'activate_user_group':
        case 'delete_usermeta_group':
            if (!isset($_GET['group_id']) || empty($_GET['group_id'])) {
                wpcf_ajax_helper_print_error_and_die();
            }
            if (!WPCF_Roles::user_can_edit_usermeta_field_group_by_id($_GET['group_id'])) {
                wpcf_ajax_helper_verification_failed_and_die();
            }
            break;
        case 'deactivate_term_group':
        case 'activate_term_group':
        case 'delete_term_group':
            if (!isset($_GET['group_id']) || empty($_GET['group_id'])) {
                wpcf_ajax_helper_print_error_and_die();
            }
            if (!WPCF_Roles::user_can_edit_term_field_group_by_id($_GET['group_id'])) {
                wpcf_ajax_helper_verification_failed_and_die();
            }
            break;
        case 'usermeta_delete':
        case 'delete_usermeta':
        case 'remove_from_history2':
        case 'usermeta_insert_existing':
        case 'fields_insert':
        case 'fields_insert_existing':
        case 'remove_field_from_group':
        case 'add_radio_option':
        case 'add_select_option':
        case 'add_checkboxes_option':
        case 'group_form_collapsed':
        case 'form_fieldset_toggle':
        case 'fields_delete':
        case 'delete_field':
        case 'remove_from_history':
        case 'add_condition':
        case 'pt_edit_fields':
        case 'toggle':
        case 'cb_save_empty_migrate':
            if (!current_user_can('manage_options')) {
                wpcf_ajax_helper_verification_failed_and_die();
            }
            /**
             * do not check actions from other places
             */
            break;
        default:
            return;
    }
    /**
     * do actions
     */
    switch ($_REQUEST['wpcf_action']) {
        /* User meta actions*/
        case 'usermeta_delete':
        case 'delete_usermeta':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            if (isset($_GET['field_id'])) {
                $field_id = sanitize_text_field($_GET['field_id']);
                wpcf_admin_fields_delete_field($field_id, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta');
            }
            if (isset($_GET['field'])) {
                $field = sanitize_text_field($_GET['field']);
                wpcf_admin_fields_delete_field($field, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta');
            }
            echo json_encode(array('output' => ''));
            break;
        case 'remove_from_history2':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            $fields = wpcf_admin_fields_get_fields(true, true, false, 'wpcf-usermeta');
            if (isset($_GET['field_id']) && isset($fields[$_GET['field_id']])) {
                $fields[$_GET['field_id']]['data']['removed_from_history'] = 1;
                wpcf_admin_fields_save_fields($fields, true, 'wpcf-usermeta');
            }
            echo json_encode(array('output' => ''));
            break;
        case 'deactivate_user_group':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            require_once WPCF_INC_ABSPATH . '/usermeta.php';
            $success = wpcf_admin_fields_deactivate_group(intval($_GET['group_id']), TYPES_USER_META_FIELD_GROUP_CPT_NAME);
            if ($success) {
                echo json_encode(array('output' => __('Group deactivated', 'wpcf'), 'execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            } else {
                wpcf_ajax_helper_print_error_and_die();
                die;
            }
            break;
        case 'activate_user_group':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            require_once WPCF_INC_ABSPATH . '/usermeta.php';
            $success = wpcf_admin_fields_activate_group(intval($_GET['group_id']), TYPES_USER_META_FIELD_GROUP_CPT_NAME);
            if ($success) {
                echo json_encode(array('output' => __('Group activated', 'wpcf'), 'execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            } else {
                wpcf_ajax_helper_print_error_and_die();
                die;
            }
            break;
        case 'delete_usermeta_group':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            require_once WPCF_INC_ABSPATH . '/usermeta.php';
            $redirect = wpcf_ajax_group_delete_redirect();
            wpcf_admin_fields_delete_group(intval($_GET['group_id']), TYPES_USER_META_FIELD_GROUP_CPT_NAME);
            echo json_encode($redirect);
            break;
        case 'usermeta_insert_existing':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            require_once WPCF_INC_ABSPATH . '/fields-form.php';
            require_once WPCF_INC_ABSPATH . '/usermeta-form.php';
            wpcf_usermeta_insert_existing_ajax();
            wpcf_form_render_js_validation();
            break;
            /* End Usertmeta actions*/
        /* End Usertmeta actions*/
        case 'fields_insert':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            require_once WPCF_INC_ABSPATH . '/fields-form.php';
            wpcf_fields_insert_ajax();
            wpcf_form_render_js_validation();
            break;
        case 'fields_insert_existing':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            require_once WPCF_INC_ABSPATH . '/fields-form.php';
            wpcf_fields_insert_existing_ajax();
            wpcf_form_render_js_validation();
            break;
        case 'remove_field_from_group':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            if (isset($_GET['group_id']) && isset($_GET['field_id'])) {
                wpcf_admin_fields_remove_field_from_group(intval($_GET['group_id']), sanitize_text_field($_GET['field_id']));
            }
            break;
        case 'deactivate_group':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            $success = wpcf_admin_fields_deactivate_group(intval($_GET['group_id']));
            if ($success) {
                echo json_encode(array('output' => __('Group deactivated', 'wpcf'), 'execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            } else {
                wpcf_ajax_helper_print_error_and_die();
            }
            break;
        case 'activate_group':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            $success = wpcf_admin_fields_activate_group(intval($_GET['group_id']));
            if ($success) {
                echo json_encode(array('output' => __('Group activated', 'wpcf'), 'execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            } else {
                wpcf_ajax_helper_print_error_and_die();
            }
            break;
        case 'delete_group':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            $redirect = wpcf_ajax_group_delete_redirect();
            wpcf_admin_fields_delete_group(intval($_GET['group_id']));
            echo json_encode($redirect);
            break;
        case 'deactivate_term_group':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            $success = wpcf_admin_fields_deactivate_group(intval($_GET['group_id']), Types_Field_Group_Term::POST_TYPE);
            if ($success) {
                echo json_encode(array('output' => __('Group deactivated', 'wpcf'), 'execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            } else {
                wpcf_ajax_helper_print_error_and_die();
            }
            break;
        case 'activate_term_group':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            $success = wpcf_admin_fields_activate_group(intval($_GET['group_id']), Types_Field_Group_Term::POST_TYPE);
            if ($success) {
                echo json_encode(array('output' => __('Group activated', 'wpcf'), 'execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            } else {
                wpcf_ajax_helper_print_error_and_die();
            }
            break;
        case 'delete_term_group':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            $redirect = wpcf_ajax_group_delete_redirect();
            wpcf_admin_fields_delete_group(intval($_GET['group_id']), Types_Field_Group_Term::POST_TYPE);
            echo json_encode($redirect);
            break;
        case 'deactivate_post_type':
            $post_type = wpcf_ajax_helper_get_post_type();
            if (empty($post_type)) {
                wpcf_ajax_helper_print_error_and_die();
            }
            $custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
            $custom_types[$post_type]['disabled'] = 1;
            $custom_types[$post_type][TOOLSET_EDIT_LAST] = time();
            update_option(WPCF_OPTION_NAME_CUSTOM_TYPES, $custom_types);
            echo json_encode(array('output' => __('Post Type deactivated', 'wpcf'), 'execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            break;
        case 'activate_post_type':
            $post_type = wpcf_ajax_helper_get_post_type();
            if (empty($post_type)) {
                wpcf_ajax_helper_print_error_and_die();
            }
            $custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
            unset($custom_types[$post_type]['disabled']);
            $custom_types[$post_type][TOOLSET_EDIT_LAST] = time();
            update_option(WPCF_OPTION_NAME_CUSTOM_TYPES, $custom_types);
            echo json_encode(array('output' => __('Post Type activated', 'wpcf'), 'execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            break;
        case 'delete_post_type':
            $post_type = wpcf_ajax_helper_get_post_type();
            if (empty($post_type)) {
                wpcf_ajax_helper_print_error_and_die();
            }
            $post_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
            /**
             * Delete relation between custom posts types
             *
             * Filter allow to delete all custom fields used to make
             * a relation between posts.
             *
             * @since 1.6.4
             *
             * @param bool   $delete True or false flag to delete relationships.
             * @param string $var Currently deleted post type.
             */
            if (apply_filters('wpcf_delete_relation_meta', false, $post_type)) {
                global $wpdb;
                $wpdb->delete($wpdb->postmeta, array('meta_key' => sprintf('_wpcf_belongs_%s_id', $post_type)), array('%s'));
            }
            unset($post_types[$post_type]);
            /**
             * remove post relation
             */
            foreach (array_keys($post_types) as $post_type) {
                if (array_key_exists('post_relationship', $post_types[$post_type])) {
                    /**
                     * remove "has" relation
                     */
                    if (array_key_exists('has', $post_types[$post_type]['post_relationship']) && array_key_exists($post_type, $post_types[$post_type]['post_relationship']['has'])) {
                        unset($post_types[$post_type]['post_relationship']['has'][$post_type]);
                        $post_types[$post_type][TOOLSET_EDIT_LAST] = time();
                    }
                    /**
                     * remove "belongs" relation
                     */
                    if (array_key_exists('belongs', $post_types[$post_type]['post_relationship']) && array_key_exists($post_type, $post_types[$post_type]['post_relationship']['belongs'])) {
                        unset($post_types[$post_type]['post_relationship']['belongs'][$post_type]);
                        $post_types[$post_type][TOOLSET_EDIT_LAST] = time();
                    }
                }
            }
            update_option(WPCF_OPTION_NAME_CUSTOM_TYPES, $post_types);
            wpcf_admin_deactivate_content('post_type', $post_type);
            echo json_encode(array('output' => '', 'execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            break;
        case 'duplicate_post_type':
            $post_type = wpcf_ajax_helper_get_post_type();
            if (empty($post_type)) {
                wpcf_ajax_helper_print_error_and_die();
            }
            $post_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
            $i = 0;
            $key = false;
            do {
                $key = sprintf($post_type . '-%d', ++$i);
            } while (isset($post_types[$key]));
            if ($key) {
                /**
                 * duplicate post type
                 */
                $post_types[$key] = $post_types[$post_type];
                /**
                 * update some options
                 */
                $post_types[$key]['labels']['name'] .= sprintf(' (%d)', $i);
                $post_types[$key]['labels']['singular_name'] .= sprintf(' (%d)', $i);
                $post_types[$key]['slug'] = $key;
                $post_types[$key]['__types_id'] = $key;
                /**
                 * update post types
                 */
                update_option(WPCF_OPTION_NAME_CUSTOM_TYPES, $post_types);
                /**
                 * update custom taxonomies too
                 */
                $custom_taxonomies = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array());
                foreach ($custom_taxonomies as $taxonomy_key => $taxonomy_data) {
                    if (isset($taxonomy_data['supports']) && isset($taxonomy_data['supports'][$post_type])) {
                        $custom_taxonomies[$taxonomy_key]['supports'][$key] = 1;
                    }
                }
                update_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, $custom_taxonomies);
                echo json_encode(array('execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            }
            break;
        case 'taxonomy_duplicate':
            $custom_taxonomy = wpcf_ajax_helper_get_taxonomy();
            if (empty($custom_taxonomy)) {
                wpcf_ajax_helper_print_error_and_die();
            }
            $custom_taxonomies = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array());
            $i = 0;
            $key = false;
            do {
                $key = sprintf($custom_taxonomy . '-%d', ++$i);
            } while (isset($custom_taxonomies[$key]));
            if ($key) {
                /**
                 * duplicate custom taxonomies
                 */
                $custom_taxonomies[$key] = $custom_taxonomies[$custom_taxonomy];
                /**
                 * update some options
                 */
                $custom_taxonomies[$key]['labels']['name'] .= sprintf(' (%d)', $i);
                $custom_taxonomies[$key]['labels']['singular_name'] .= sprintf(' (%d)', $i);
                $custom_taxonomies[$key]['slug'] = $key;
                $custom_taxonomies[$key]['id'] = $key;
                $custom_taxonomies[$key]['__types_id'] = $key;
                /**
                 * update custom taxonomies
                 */
                update_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, $custom_taxonomies);
                /**
                 * update post types
                 */
                if (isset($custom_taxonomies[$key]['supports']) && is_array($custom_taxonomies[$key]['supports']) && !empty($custom_taxonomies[$key]['supports'])) {
                    $custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
                    foreach (array_keys($custom_taxonomies[$key]['supports']) as $custom_type) {
                        /**
                         * avoid to create fake CPT from old data
                         */
                        if (!isset($custom_types[$custom_type])) {
                            continue;
                        }
                        if (!isset($custom_types[$custom_type]['taxonomies'])) {
                            $custom_types[$custom_type]['taxonomies'] = array();
                        }
                        $custom_types[$custom_type]['taxonomies'][$key] = 1;
                    }
                    /**
                     * update post types
                     */
                    update_option(WPCF_OPTION_NAME_CUSTOM_TYPES, $custom_types);
                }
                echo json_encode(array('execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            }
            break;
        case 'deactivate_taxonomy':
            $custom_taxonomy = wpcf_ajax_helper_get_taxonomy();
            if (empty($custom_taxonomy)) {
                wpcf_ajax_helper_print_error_and_die();
            }
            $custom_taxonomies = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array());
            if (!isset($custom_taxonomies[$custom_taxonomy]) || !isset($custom_taxonomies[$custom_taxonomy]['supports'])) {
                $taxonomy = get_taxonomy($custom_taxonomy);
                $supports = array();
                if (is_object($taxonomy)) {
                    if (!empty($taxonomy->object_type)) {
                        foreach ($taxonomy->object_type as $support_post) {
                            $supports[$support_post] = 1;
                        }
                    }
                    $custom_taxonomies[$custom_taxonomy] = array('slug' => $taxonomy->name, 'labels' => array('singular_name' => $taxonomy->labels->singular_name, 'name' => $taxonomy->labels->name), 'supports' => $supports, 'type' => '_builtin', '_builtin' => true);
                } else {
                    wpcf_ajax_helper_print_error_and_die();
                }
            }
            if (wpcf_is_builtin_taxonomy($custom_taxonomy)) {
                $custom_taxonomies[$custom_taxonomy]['type'] = '_builtin';
                $custom_taxonomies[$custom_taxonomy]['_builtin'] = true;
            }
            $custom_taxonomies[$custom_taxonomy]['disabled'] = 1;
            $custom_taxonomies[$custom_taxonomy][TOOLSET_EDIT_LAST] = time();
            update_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, $custom_taxonomies);
            echo json_encode(array('output' => __('Taxonomy deactivated', 'wpcf'), 'execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            break;
        case 'activate_taxonomy':
            $custom_taxonomy = wpcf_ajax_helper_get_taxonomy();
            if (empty($custom_taxonomy)) {
                wpcf_ajax_helper_print_error_and_die();
            }
            $custom_taxonomies = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array());
            if (!isset($custom_taxonomies[$custom_taxonomy])) {
                $taxonomy = get_taxonomy($custom_taxonomy);
                if (is_object($taxonomy)) {
                    $custom_taxonomies[$custom_taxonomy] = array('slug' => $taxonomy->name, 'labels' => array('singular_name' => $taxonomy->labels->singular_name), 'type' => '_builtin', '_builtin' => true);
                } else {
                    wpcf_ajax_helper_print_error_and_die();
                }
            }
            if (wpcf_is_builtin_taxonomy($custom_taxonomy)) {
                $custom_taxonomies[$custom_taxonomy]['type'] = '_builtin';
                $custom_taxonomies[$custom_taxonomy]['_builtin'] = true;
            }
            $custom_taxonomies[$custom_taxonomy]['disabled'] = 0;
            $custom_taxonomies[$custom_taxonomy][TOOLSET_EDIT_LAST] = time();
            update_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, $custom_taxonomies);
            echo json_encode(array('output' => __('Taxonomy activated', 'wpcf'), 'execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            break;
        case 'delete_taxonomy':
            $custom_taxonomy = wpcf_ajax_helper_get_taxonomy();
            if (empty($custom_taxonomy)) {
                wpcf_ajax_helper_print_error_and_die();
            }
            $custom_taxonomies = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array());
            unset($custom_taxonomies[$custom_taxonomy]);
            update_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, $custom_taxonomies);
            wpcf_admin_deactivate_content('taxonomy', $custom_taxonomy);
            // on group edit page
            if (isset($_GET['wpcf_ref'])) {
                $redirect = $_GET['wpcf_ref'] == 'dashboard' ? admin_url('admin.php?page=toolset-dashboard') : admin_url('admin.php?page=wpcf-ctt');
                echo json_encode(array('output' => '', 'execute' => 'redirect', 'wpcf_redirect' => $redirect, 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
                // on listing page
            } else {
                echo json_encode(array('output' => '', 'execute' => 'reload', 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            }
            break;
        case 'add_radio_option':
            /**
             * check required data
             */
            if (!isset($_GET['parent_name']) || !isset($_GET['wpcf_ajax_update_add'])) {
                wpcf_ajax_helper_print_error_and_die();
            }
            require_once WPCF_INC_ABSPATH . '/fields/radio.php';
            $value = esc_html(urldecode($_GET['parent_name']));
            $element = wpcf_fields_radio_get_option($value);
            $id = array_shift($element);
            $element_txt = wpcf_fields_radio_get_option_alt_text($id, $value);
            echo json_encode(array('output' => wpcf_form_simple($element), 'execute' => 'append', 'append_target' => '#wpcf-form-groups-radio-ajax-response-' . esc_html(urldecode($_GET['wpcf_ajax_update_add'])), 'append_value' => trim(preg_replace('/[\\r\\n]+/', '', wpcf_form_simple($element_txt))), 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            break;
        case 'add_select_option':
            /**
             * check required data
             */
            if (!isset($_GET['parent_name'])) {
                wpcf_ajax_helper_print_error_and_die();
            }
            require_once WPCF_INC_ABSPATH . '/fields/select.php';
            $element = wpcf_fields_select_get_option(esc_html(urldecode($_GET['parent_name'])));
            echo json_encode(array('output' => wpcf_form_simple($element)));
            break;
        case 'add_checkboxes_option':
            /**
             * check required data
             */
            if (!isset($_GET['parent_name'])) {
                wpcf_ajax_helper_print_error_and_die();
            }
            require_once WPCF_INC_ABSPATH . '/fields/checkboxes.php';
            $value = esc_html(urldecode($_GET['parent_name']));
            $element = wpcf_fields_checkboxes_get_option($value);
            $id = array_shift($element);
            $element_txt = wpcf_fields_checkboxes_get_option_alt_text($id, $value);
            echo json_encode(array('output' => wpcf_form_simple($element), 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute')));
            break;
        case 'group_form_collapsed':
            require_once WPCF_INC_ABSPATH . '/fields-form.php';
            $group_id = sanitize_text_field($_GET['group_id']);
            $action = sanitize_text_field($_GET['toggle']);
            $fieldset = sanitize_text_field($_GET['id']);
            wpcf_admin_fields_form_save_open_fieldset($action, $fieldset, $group_id);
            break;
        case 'form_fieldset_toggle':
            $action = sanitize_text_field($_GET['toggle']);
            $fieldset = sanitize_text_field($_GET['id']);
            wpcf_admin_form_fieldset_save_toggle($action, $fieldset);
            break;
        case 'fields_delete':
        case 'delete_field':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            if (isset($_GET['field_id'])) {
                wpcf_admin_fields_delete_field(sanitize_text_field($_GET['field_id']));
            }
            if (isset($_GET['field'])) {
                wpcf_admin_fields_delete_field(sanitize_text_field($_GET['field']));
            }
            echo json_encode(array('output' => ''));
            break;
        case 'remove_from_history':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            $fields = wpcf_admin_fields_get_fields();
            if (isset($_GET['field_id']) && isset($fields[$_GET['field_id']])) {
                $fields[$_GET['field_id']]['data']['removed_from_history'] = 1;
                wpcf_admin_fields_save_fields($fields, true);
            }
            echo json_encode(array('output' => ''));
            break;
        case 'add_condition':
            require_once WPCF_INC_ABSPATH . '/fields.php';
            require_once WPCF_ABSPATH . '/includes/conditional-display.php';
            if (!empty($_GET['field']) || !empty($_GET['group'])) {
                $data = array();
                if (isset($_GET['group'])) {
                    $output = wpcf_form_simple(wpcf_cd_admin_form_single_filter(array(), array(), null, true));
                    echo json_encode(array('output' => $output));
                } else {
                    $data['id'] = str_replace('_conditional_display', '', sanitize_text_field($_GET['field']));
                    $output = wpcf_form_simple(wpcf_cd_admin_form_single_filter($data, array(), null, false));
                    if (!empty($data['id'])) {
                        echo json_encode(array('output' => $output));
                    } else {
                        wpcf_ajax_helper_print_error_and_die();
                    }
                }
            } else {
                wpcf_ajax_helper_print_error_and_die();
            }
            break;
        case 'pt_edit_fields':
            if (!empty($_GET['parent']) && !empty($_GET['child'])) {
                require_once WPCF_INC_ABSPATH . '/fields.php';
                require_once WPCF_INC_ABSPATH . '/post-relationship.php';
                wpcf_pr_admin_edit_fields(sanitize_text_field($_GET['parent']), sanitize_text_field($_GET['child']));
            }
            break;
        case 'toggle':
            $option = get_option('wpcf_toggle', array());
            $hidden = isset($_GET['hidden']) ? (bool) $_GET['hidden'] : 1;
            $div = esc_html(strval($_GET['div']));
            if (!$hidden) {
                unset($option[$div]);
            } else {
                $option[$div] = 1;
            }
            update_option('wpcf_toggle', $option);
            break;
        case 'cb_save_empty_migrate':
            $output = sprintf('<span style="color:red;">%s</div>', __('Migration process is not yet finished - please save group first, then change settings of this field.', 'wpcf'));
            if (isset($_GET['field']) && isset($_GET['subaction'])) {
                require_once WPCF_INC_ABSPATH . '/fields.php';
                $option = $_GET['meta_type'] == 'usermeta' ? 'wpcf-usermeta' : 'wpcf-fields';
                $meta_type = sanitize_text_field($_GET['meta_type']);
                $field = wpcf_admin_fields_get_field(sanitize_text_field($_GET['field']), false, false, false, $option);
                $_txt_updates = $meta_type == 'usermeta' ? __('%d users require update', 'wpcf') : __('%d posts require update', 'wpcf');
                $_txt_no_updates = $meta_type == 'usermeta' ? __('No users require update', 'wpcf') : __('No posts require update', 'wpcf');
                $_txt_updated = $meta_type == 'usermeta' ? __('Users updated', 'wpcf') : __('Posts updated', 'wpcf');
                if (!empty($field)) {
                    if ($_GET['subaction'] == 'save_check' || $_GET['subaction'] == 'do_not_save_check') {
                        if ($field['type'] == 'checkbox') {
                            $posts = wpcf_admin_fields_checkbox_migrate_empty_check($field, $_GET['subaction']);
                        } else {
                            if ($field['type'] == 'checkboxes') {
                                $posts = wpcf_admin_fields_checkboxes_migrate_empty_check($field, $_GET['subaction']);
                            }
                        }
                        if (!empty($posts)) {
                            $output = '<div class="message updated"><p>' . sprintf($_txt_updates, count($posts)) . '&nbsp;' . '<a href="javascript:void(0);" class="button-primary" onclick="' . 'wpcfCbSaveEmptyMigrate(jQuery(this).parent().parent().parent(), \'' . sanitize_text_field($_GET['field']) . '\', ' . count($posts) . ', \'' . wp_create_nonce('cb_save_empty_migrate') . '\', \'';
                            $output .= $_GET['subaction'] == 'save_check' ? 'save' : 'do_not_save';
                            $output .= '\', \'' . $meta_type . '\');' . '">' . __('Update', 'wpcf') . '</a>' . '</p></div>';
                        } else {
                            $output = '<div class="message updated"><p><em>' . $_txt_no_updates . '</em></p></div>';
                        }
                    } else {
                        if ($_GET['subaction'] == 'save' || $_GET['subaction'] == 'do_not_save') {
                            if ($field['type'] == 'checkbox') {
                                $posts = wpcf_admin_fields_checkbox_migrate_empty($field, $_GET['subaction']);
                            } else {
                                if ($field['type'] == 'checkboxes') {
                                    $posts = wpcf_admin_fields_checkboxes_migrate_empty($field, $_GET['subaction']);
                                }
                            }
                            if (isset($posts['offset'])) {
                                if (!isset($_GET['total'])) {
                                    $output = '<span style="color:red;">' . __('Error occured', 'wpcf') . '</div>';
                                } else {
                                    $output = '<script type="text/javascript">wpcfCbMigrateStep(' . intval($_GET['total']) . ',' . $posts['offset'] . ',' . '\'' . sanitize_text_field($_GET['field']) . '\',' . '\'' . wp_create_nonce('cb_save_empty_migrate') . '\', \'' . $meta_type . '\');</script>' . number_format($posts['offset']) . '/' . number_format(intval($_GET['total'])) . '<div class="wpcf-ajax-loading-small"></div>';
                                }
                            } else {
                                $output = sprintf('<div class="message updated"><p>%s</p></div>', $_txt_updated);
                            }
                        }
                    }
                }
            }
            echo json_encode(array('output' => $output));
            break;
        default:
            break;
    }
    die;
}
 /**
  * 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);
 }
/**
 * Add/edit form structure
 */
function wpcf_admin_custom_taxonomies_form()
{
    global $wpcf;
    include_once dirname(__FILE__) . '/common-functions.php';
    $ct = array();
    $id = false;
    $update = false;
    if (isset($_GET['wpcf-tax'])) {
        $id = sanitize_text_field($_GET['wpcf-tax']);
    } else {
        if (isset($_POST['wpcf-tax'])) {
            $id = sanitize_text_field($_POST['wpcf-tax']);
        }
    }
    if ($id) {
        $custom_taxonomies = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array());
        if (isset($custom_taxonomies[$id])) {
            $ct = $custom_taxonomies[$id];
            $update = true;
            // Set rewrite if needed
            if (isset($_GET['wpcf-rewrite'])) {
                flush_rewrite_rules();
            }
        } else {
            wpcf_admin_message(__('Wrong custom taxonomy specified', 'wpcf'), 'error');
            return false;
        }
    } else {
        $ct = wpcf_custom_taxonomies_default();
    }
    $current_user_can_edit = WPCF_Roles::user_can_edit('custom-taxonomy', $ct);
    $form = array();
    /**
     * postbox-controll
     */
    $markup = wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false, false);
    $markup .= wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false, false);
    $form['postbox-controll'] = array('#type' => 'markup', '#markup' => $markup);
    /**
     * form setup
     */
    $form['#form']['callback'] = 'wpcf_admin_custom_taxonomies_form_submit';
    $form['#form']['redirection'] = false;
    if ($current_user_can_edit && $update) {
        $form['id'] = array('#type' => 'hidden', '#value' => $id, '#name' => 'ct[wpcf-tax]');
    }
    /**
     * WP control for meta boxes
     */
    include_once ABSPATH . '/wp-admin/includes/meta-boxes.php';
    wp_enqueue_script('post');
    $form['form-open'] = array('#type' => 'markup', '#markup' => sprintf('<div id="poststuff" class="%s">', $current_user_can_edit ? '' : 'wpcf-types-read-only'));
    $form['form-metabox-holder-columns-2-open'] = array('#type' => 'markup', '#markup' => '<div id="post-body" class="metabox-holder columns-2">');
    $form['post-body-content-open'] = array('#type' => 'markup', '#markup' => '<div id="post-body-content">');
    $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">' . __('Name and description', 'wpcf') . '</th></tr></thead><tbody>');
    $table_row = '<tr><td><LABEL></td><td><ERROR><ELEMENT></td></tr>';
    $form['name'] = array('#type' => 'textfield', '#name' => 'ct[labels][name]', '#title' => __('Custom taxonomy name plural', 'wpcf') . ' (<strong>' . __('required', 'wpcf') . '</strong>)', '#description' => '<strong>' . __('Enter in plural!', 'wpcf') . '.', '#value' => isset($ct['labels']['name']) ? wp_kses_post($ct['labels']['name']) : '', '#validate' => array('required' => array('value' => true), 'maxlength' => array('value' => 30)), '#pattern' => $table_row, '#inline' => true, '#attributes' => array('placeholder' => __('Enter custom taxonomy name plural', 'wpcf')));
    $form['name-singular'] = array('#type' => 'textfield', '#name' => 'ct[labels][singular_name]', '#title' => __('Custom taxonomy name singular', 'wpcf') . ' (<strong>' . __('required', 'wpcf') . '</strong>)', '#description' => '<strong>' . __('Enter in singular!', 'wpcf') . '</strong><br />' . '.', '#value' => isset($ct['labels']['singular_name']) ? wp_kses_post($ct['labels']['singular_name']) : '', '#validate' => array('required' => array('value' => true), 'maxlength' => array('value' => 30)), '#pattern' => $table_row, '#inline' => true, '#attributes' => array('placeholder' => __('Enter custom taxonomy name singular', 'wpcf'), 'class' => 'js-wpcf-slugize-source'));
    /*
     *
     * IF isset $_POST['slug'] it means form is not submitted
     */
    $attributes = array();
    if (!empty($_POST['ct']['slug'])) {
        $reserved = wpcf_is_reserved_name(sanitize_text_field($_POST['ct']['slug']), 'taxonomy');
        if (is_wp_error($reserved)) {
            $attributes = array('class' => 'wpcf-form-error', 'onclick' => 'jQuery(this).removeClass(\'wpcf-form-error\');');
        }
    }
    $form['slug'] = array('#type' => 'textfield', '#name' => 'ct[slug]', '#title' => __('Slug', 'wpcf') . ' (<strong>' . __('required', 'wpcf') . '</strong>)', '#description' => '<strong>' . __('Enter in singular!', 'wpcf') . '</strong><br />' . __('Machine readable name.', 'wpcf') . '<br />' . __('If not provided - will be created from singular name.', 'wpcf') . '<br />', '#value' => isset($ct['slug']) ? $ct['slug'] : '', '#pattern' => $table_row, '#inline' => true, '#validate' => array('required' => array('value' => true), 'nospecialchars' => array('value' => true), 'maxlength' => array('value' => 30)), '#attributes' => $attributes + array('maxlength' => '30', 'placeholder' => __('Enter custom taxonomy slug', 'wpcf'), 'class' => 'js-wpcf-slugize'));
    $form['description'] = array('#type' => 'textarea', '#name' => 'ct[description]', '#title' => __('Description', 'wpcf'), '#value' => isset($ct['description']) ? $ct['description'] : '', '#attributes' => array('rows' => 4, 'cols' => 60, 'placeholder' => __('Enter custom taxonomy description', 'wpcf')), '#pattern' => $table_row, '#inline' => true);
    $form['table-1-close'] = array('#type' => 'markup', '#markup' => '</tbody></table>');
    $form['post-body-content-close'] = array('#type' => 'markup', '#markup' => '</div>');
    /**
     * get box order
     */
    $meta_box_order_defaults = apply_filters('wpcf_meta_box_order_defaults', array('side' => array('submitdiv', 'wpcf_visibility', 'post_types'), 'normal' => array('labels', 'options')), 'taxonomy');
    $screen = get_current_screen();
    if (false == ($meta_box_order = get_user_option('meta-box-order_' . $screen->id))) {
        $meta_box_order = $meta_box_order_defaults;
    } else {
        if (isset($meta_box_order[0]) && !isset($meta_box_order['normal'])) {
            $meta_box_order['normal'] = $meta_box_order[0];
        }
    }
    $meta_boxes = array();
    foreach ($meta_box_order_defaults as $key => $value) {
        foreach ($value as $meta_box_key) {
            $meta_boxes[$meta_box_key] = $ct;
        }
    }
    if (!$current_user_can_edit) {
        $meta_boxes['submitdiv'] = false;
    }
    foreach ($meta_box_order as $key => $value) {
        if (is_array($value)) {
            continue;
        }
        $meta_box_order[$key] = explode(',', $value);
    }
    /**
     * postbox-container-1
     */
    $form['postbox-container-1-open'] = array('#type' => 'markup', '#markup' => '<div id="postbox-container-1" class="postbox-container"><div class="meta-box-sortables ui-sortable" id="side-sortables">');
    foreach ($meta_box_order['side'] as $key) {
        $function = sprintf('wpcf_admin_metabox_%s', $key);
        if (is_callable($function) && isset($meta_boxes[$key])) {
            $form += $function($meta_boxes[$key], 'side');
            unset($meta_boxes[$key]);
        }
    }
    /* close side container */
    $form['postbox-container-1-close'] = array('#type' => 'markup', '#markup' => '</div></div>');
    /**
     * normal container
     */
    $form['postbox-container-2-open'] = array('#type' => 'markup', '#markup' => '<div id="postbox-container-2" class="postbox-container"><div class="meta-box-sortables ui-sortable" id="normal-sortables">');
    foreach ($meta_box_order['normal'] as $key) {
        $function = sprintf('wpcf_admin_metabox_%s', $key);
        if (is_callable($function) && isset($meta_boxes[$key])) {
            $form += $function($meta_boxes[$key]);
            unset($meta_boxes[$key]);
        }
    }
    /**
     * grab missing meta-boxes
     */
    foreach (array_keys($meta_boxes) as $key) {
        $function = sprintf('wpcf_admin_metabox_%s', $key);
        if (is_callable($function)) {
            $form += $function($meta_boxes[$key]);
        }
    }
    /**
     * filter wpcf_post_type_form
     */
    $form = $form + apply_filters('wpcf_post_type_form', array(), $ct);
    /**
     * container-2 close
     */
    $form['postbox-container-2-close'] = array('#type' => 'markup', '#markup' => '</div></div>');
    $form['form-close'] = array('#type' => 'markup', '#markup' => '</div></div>');
    /**
     * return form if current_user_can edit
     */
    if ($current_user_can_edit) {
        return $form;
    }
    return wpcf_admin_common_only_show($form);
}
 /**
  * Add/edit form
  */
 public function form()
 {
     $this->save();
     // Flush rewrite rules if we're asked to do so.
     //
     // This must be done after all post types and taxonomies are registered, and they can be registered properly
     // only on 'init'. So after making changes, we need to reload the page and THEN flush.
     if ('1' == wpcf_getget('flush', '0')) {
         flush_rewrite_rules();
     }
     global $wpcf;
     $id = false;
     $update = false;
     if (isset($_GET[$this->get_id])) {
         $id = sanitize_text_field($_GET[$this->get_id]);
     } elseif (isset($_POST[$this->get_id])) {
         $id = sanitize_text_field($_POST[$this->get_id]);
     }
     /**
      * get current post type
      */
     require_once WPCF_INC_ABSPATH . '/classes/class.types.admin.post-type.php';
     $wpcf_post_type = new Types_Admin_Post_Type();
     $custom_post_type = $wpcf_post_type->get_post_type($id);
     if (empty($custom_post_type)) {
         wpcf_admin_message(__('Please save new Post Type first.', 'wpcf'), 'error');
         die;
     }
     $this->ct = $custom_post_type;
     $current_user_can_edit = WPCF_Roles::user_can_edit('custom-post-type', $this->ct);
     /**
      * sanitize _builtin
      */
     if (!isset($this->ct['_builtin'])) {
         $this->ct['_builtin'] = false;
     }
     /**
      * fix taxonomies assigment for builitin post types
      */
     if ($this->ct['_builtin']) {
         $taxonomies = get_taxonomies('', 'objects');
         foreach ($taxonomies as $slug => $tax) {
             foreach ($tax->object_type as $post_slug) {
                 if ($this->ct['slug'] == $post_slug) {
                     $this->ct['taxonomies'][$slug] = 1;
                 }
             }
         }
     }
     $form = $this->prepare_screen();
     if ($current_user_can_edit && $this->ct['update']) {
         $form['id'] = array('#type' => 'hidden', '#value' => $id, '#name' => 'ct[wpcf-post-type]', '_builtin' => true);
         /**
          * update Taxonomy too
          */
         $custom_taxonomies = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array());
         foreach ($custom_taxonomies as $slug => $data) {
             if (!array_key_exists('supports', $data)) {
                 continue;
             }
             if (!array_key_exists($id, $data['supports'])) {
                 continue;
             }
             if (array_key_exists('taxonomies', $this->ct) && array_key_exists($slug, $this->ct['taxonomies'])) {
                 continue;
             }
             unset($custom_taxonomies[$slug]['supports'][$id]);
         }
         update_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, $custom_taxonomies);
     }
     /*
      * menu icon
      */
     switch ($this->ct['slug']) {
         case 'page':
             $menu_icon = 'admin-page';
             break;
         case 'attachment':
             $menu_icon = 'admin-media';
             break;
         default:
             $menu_icon = isset($this->ct['icon']) && !empty($this->ct['icon']) ? $this->ct['icon'] : 'admin-post';
             break;
     }
     /**
      * post icon field
      */
     $form['icon'] = array('#type' => 'hidden', '#name' => 'ct[icon]', '#value' => $menu_icon, '#id' => 'wpcf-types-icon');
     $form['form-open'] = array('#type' => 'markup', '#markup' => sprintf('<div id="post-body-content" class="%s">', $current_user_can_edit ? '' : 'wpcf-types-read-only'), '_builtin' => true);
     $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">' . __('Post Type name and description', 'wpcf') . '</th></tr></thead><tbody>', '_builtin' => true);
     $table_row = '<tr><td><LABEL></td><td><ERROR><BEFORE><ELEMENT><AFTER></td></tr>';
     $form['name'] = array('#type' => 'textfield', '#name' => 'ct[labels][name]', '#title' => __('Post Type name plural', 'wpcf') . ' (<strong>' . __('required', 'wpcf') . '</strong>)', '#description' => '<strong>' . __('Enter in plural!', 'wpcf') . '.', '#value' => isset($this->ct['labels']['name']) ? $this->ct['labels']['name'] : '', '#validate' => array('required' => array('value' => 'true')), '#pattern' => $table_row, '#inline' => true, '#id' => 'name-plural', '#attributes' => array('data-wpcf_warning_same_as_slug' => $wpcf->post_types->message('warning_singular_plural_match'), 'data-wpcf_warning_same_as_slug_ignore' => $wpcf->post_types->message('warning_singular_plural_match_ignore'), 'placeholder' => __('Enter Post Type name plural', 'wpcf'), 'class' => 'large-text'), '_builtin' => true);
     $form['name-singular'] = array('#type' => 'textfield', '#name' => 'ct[labels][singular_name]', '#title' => __('Post Type name singular', 'wpcf') . ' (<strong>' . __('required', 'wpcf') . '</strong>)', '#description' => '<strong>' . __('Enter in singular!', 'wpcf') . '</strong><br />' . '.', '#value' => isset($this->ct['labels']['singular_name']) ? $this->ct['labels']['singular_name'] : '', '#validate' => array('required' => array('value' => 'true')), '#pattern' => $table_row, '#inline' => true, '#id' => 'name-singular', '#attributes' => array('placeholder' => __('Enter Post Type name singular', 'wpcf'), 'class' => 'js-wpcf-slugize-source large-text'), '_builtin' => true);
     /**
      * IF isset $_POST['slug'] it means form is not submitted
      */
     $attributes = array();
     if (!empty($_POST['ct']['slug'])) {
         $reserved = wpcf_is_reserved_name(sanitize_text_field($_POST['ct']['slug']), 'post_type');
         if (is_wp_error($reserved)) {
             $attributes = array('class' => 'wpcf-form-error', 'onclick' => 'jQuery(this).removeClass(\'wpcf-form-error\');');
         }
     }
     $form['slug'] = array('#type' => 'textfield', '#name' => 'ct[slug]', '#title' => __('Slug', 'wpcf') . ' (<strong>' . __('required', 'wpcf') . '</strong>)', '#value' => isset($this->ct['slug']) ? $this->ct['slug'] : '', '#pattern' => $table_row, '#inline' => true, '#validate' => array('required' => array('value' => 'true'), 'nospecialchars' => array('value' => 'true'), 'maxlength' => array('value' => '20')), '#attributes' => $attributes + array('maxlength' => '20', 'placeholder' => __('Enter Post Type slug', 'wpcf'), 'class' => 'js-wpcf-slugize large-text'), '#id' => 'slug', '_builtin' => true);
     // disable for inbuilt
     if ($this->ct['_builtin']) {
         $form['slug']['#disable'] = 1;
         $form['slug']['#pattern'] = '<tr><td><LABEL></td><td><ERROR><BEFORE><ELEMENT><DESCRIPTION><AFTER></td></tr>';
         $form['slug']['#description'] = __('This option is not available for built-in post types.', 'wpcf');
     }
     $form['description'] = array('#type' => 'textarea', '#name' => 'ct[description]', '#title' => __('Description', 'wpcf'), '#value' => isset($this->ct['description']) ? $this->ct['description'] : '', '#attributes' => array('rows' => 4, 'cols' => 60, 'placeholder' => __('Enter Post Type description', 'wpcf'), 'class' => 'hidden js-wpcf-description'), '#pattern' => $table_row, '#inline' => true, '#after' => sprintf('<a class="js-wpcf-toggle-description hidden" href="#">%s</a>', __('Add description', 'wpcf')));
     /**
      * icons only for version 3.8 up
      */
     global $wp_version;
     if (version_compare('3.8', $wp_version) < 1) {
         $form['choose-icon'] = array('#name' => 'choose-icon', '#type' => 'button', '#value' => esc_attr__('Change icon', 'wpcf'), '#inline' => true, '#title' => __('Icon', 'wpcf'), '#pattern' => '<tr><td><LABEL></td><td><ERROR><BEFORE><ELEMENT><DESCRIPTION><AFTER></td></tr>', '#attributes' => array('data-wpcf-nonce' => wp_create_nonce('post-type-dashicons-list'), 'data-wpcf-post-type' => esc_attr($this->ct['slug']), 'data-wpcf-message-loading' => esc_attr__('Please Wait, Loading…', 'wpcf'), 'data-wpcf-title' => esc_attr__('Choose icon', 'wpcf'), 'data-wpcf-cancel' => esc_attr__('Cancel', 'wpcf'), 'data-wpcf-value' => esc_attr($menu_icon), 'class' => 'js-wpcf-choose-icon'), '#before' => sprintf('<div class="wpcf-types-menu-image dashicons-before dashicons-%s"><br></div>', esc_attr($menu_icon)));
         /**
          * clear ability to change for builitin post types
          */
         if ($this->ct['_builtin']) {
             $form['choose-icon']['#disable'] = 1;
             $form['choose-icon']['#description'] = __('This option is not available for built-in post types.', 'wpcf');
         }
     }
     $form['table-1-close'] = array('#type' => 'markup', '#markup' => '</tbody></table>', '_builtin' => true);
     $form['box-1-close'] = array('#type' => 'markup', '#markup' => '</div>', '_builtin' => true);
     /**
      * return form if current_user_can edit
      */
     if ($current_user_can_edit) {
         return $form;
     }
     return wpcf_admin_common_only_show($form);
 }
/**
 *
 * Use this to show filter item
 *
 * @since Types 1.2
 * @global type $wpcf_button_style
 * @global type $wpcf_button_style30
 * @param type $id
 * @param type $txt
 * @param type $txt_empty
 * @param type $e
 * @return string
 */
function _wpcf_filter_wrap($id, $title, $txt, $txt_empty, $e, $edit_button = '')
{
    global $wpcf_button_style;
    global $wpcf_button_style30;
    $form = array();
    $unique_id = wpcf_unique_id(serialize(func_get_args()));
    $query = 'jQuery(this), \'' . esc_js($id) . '\', \'' . esc_js($title) . '\', \'' . esc_js($txt) . '\', \'' . esc_js($txt_empty) . '\'';
    $group = array('id' => isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : 0);
    $current_user_can_edit = WPCF_Roles::user_can_edit('custom-field', $group);
    if (empty($edit_button)) {
        $edit = __('View', 'wpcf');
        if ($current_user_can_edit) {
            $edit = __('Edit', 'wpcf');
        }
    } else {
        $edit = $edit_button;
    }
    /*
     *
     * Title and Edit button
     */
    $form['filter_' . $unique_id . '_wrapper'] = array('#type' => 'markup', '#markup' => '<span class="wpcf-filter-ajax-response"' . ' style="font-style:italic;font-weight:bold;display:inline-block;">' . $title . ' ' . $txt . '</span>' . '&nbsp;&nbsp;<a href="javascript:void(0);" ' . $wpcf_button_style30 . ' ' . ' class="button-secondary wpcf-form-filter-edit" onclick="wpcfFilterEditClick(' . $query . ');">' . $edit . '</a><div class="hidden" id="wpcf-form-fields-' . $id . '">');
    /**
     * Form element as param
     * It may be single element or array of elements
     * Simply check if array has #type - indicates it is a form item
     */
    if (isset($e['#type'])) {
        $form['filter_' . $unique_id . '_items'] = $e;
    } else {
        /*
         * If array of elements just join
         */
        $form = $form + (array) $e;
    }
    /**
     * OK button
     */
    if ($current_user_can_edit) {
        $form['filter_' . $unique_id . '_ok'] = array('#type' => 'markup', '#markup' => '<a href="javascript:void(0);" ' . $wpcf_button_style . ' ' . 'class="button-primary  wpcf-form-filter-ok wpcf-groups-form-ajax-update-' . $id . '-ok"' . ' onclick="wpcfFilterOkClick(' . $query . ');">' . __('OK', 'wpcf') . '</a>&nbsp;');
    }
    /**
     * Cancel button
     */
    $button_cancel_text = __('Close', 'wpcf');
    if ($current_user_can_edit) {
        $button_cancel_text = __('Cancel', 'wpcf');
    }
    $form['filter_' . $unique_id . '_cancel'] = array('#type' => 'markup', '#markup' => sprintf('<a href="javascript:void(0);" %s class="button-secondary wpcf-form-filter-cancel wpcf-groups-form-ajax-update-%s-cancel" onclick="wpcfFilterCancelClick(%s);">%s</a>', $wpcf_button_style, $id, $query, $button_cancel_text));
    /**
     * Close wrapper
     */
    $form['filter_' . $unique_id . 'wrapper_close'] = array('#type' => 'markup', '#markup' => '</div>');
    return $form;
}
 /**
  * Summary.
  *
  * Description.
  *
  * @since x.x.x
  * @access (for functions: only use if private)
  *
  * @see Function/method/class relied on
  * @link URL
  * @global type $varname Description.
  * @global type $varname Description.
  *
  * @param type $var Description.
  * @param type $var Optional. Description.
  * @return type Description.
  */
 protected function submitdiv($button_text, $form = array(), $type = 'custom-post-type', $built_in = false)
 {
     if (WPCF_Roles::user_can_edit($type, $this->ct)) {
         $form['submit-div-open'] = array('#type' => 'markup', '#markup' => '<div class="submitbox" id="submitpost"><div id="major-publishing-actions">', '_builtin' => true);
         if ((isset($_GET['group_id']) || isset($_GET['wpcf-tax'])) && isset($_GET['page']) && !$built_in) {
             switch ($_GET['page']) {
                 case 'wpcf-edit':
                     // post fields
                     $action = 'delete_group';
                     break;
                 case 'wpcf-edit-usermeta':
                     // user fields
                     $action = 'delete_usermeta_group';
                     break;
                 case 'wpcf-termmeta-edit':
                     // term fields
                     $action = 'delete_term_group';
                     break;
                 case 'wpcf-edit-tax':
                     // taxonomy
                     $action = 'delete_taxonomy';
                     break;
             }
             if (isset($action)) {
                 $args = array('action' => 'wpcf_ajax', 'wpcf_action' => $action, '_wpnonce' => wp_create_nonce($action), 'wpcf_warning' => urlencode(__('Are you sure?', 'wpcf')));
                 if (isset($_GET['group_id'])) {
                     $args['group_id'] = sanitize_text_field($_GET['group_id']);
                     $args['wpcf_ajax_update'] = 'wpcf_list_ajax_response_' . sanitize_text_field($_GET['group_id']);
                     $delete_id_addition = sanitize_text_field($_GET['group_id']);
                 } else {
                     if (isset($_GET['wpcf-tax'])) {
                         $args['wpcf-tax'] = sanitize_text_field($_GET['wpcf-tax']);
                         $args['wpcf_ajax_update'] = 'wpcf_list_ajax_response_' . sanitize_text_field($_GET['wpcf-tax']);
                         $delete_id_addition = sanitize_text_field($_GET['wpcf-tax']);
                     }
                 }
                 $args['wpcf_ref'] = isset($_GET['ref']) ? $_GET['ref'] : 'list';
                 $form['delete'] = array('#type' => 'markup', '#markup' => sprintf('<div id="delete-action"><a href="%s" class="submitdelete wpcf-ajax-link wpcf-group-delete-link" id="wpcf-list-delete-%d"">%s</a></div>', esc_url(add_query_arg($args, admin_url('admin-ajax.php'))), $delete_id_addition, __('Delete', 'wpcf')));
             }
         }
         $form['submit-div-open-publish'] = array('#type' => 'markup', '#markup' => '<div id="publishing-action"><span class="spinner"></span>');
         $form['submit'] = array('#type' => 'submit', '#name' => 'wpcf-submit', '#value' => $button_text, '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit'), '_builtin' => true);
         /**
          * add data attribute for _builtin post type
          */
         if (isset($this->ct['_builtin']) && $this->ct['_builtin']) {
             $form['submit']['#attributes']['data-post_type_is_builtin'] = '_builtin';
         }
         $form['submit-div-close'] = array('#type' => 'markup', '#markup' => '</div><div class="clear"></div></div></div>', '_builtin' => true);
     }
     return $form;
 }
Esempio n. 17
0
 /**
  * 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.
  */
 protected function submitdiv($button_text, $form = array(), $type = 'custom-post-type')
 {
     if (WPCF_Roles::user_can_edit($type, $this->ct)) {
         $form['submit-div-open'] = array('#type' => 'markup', '#markup' => '<div class="submitbox" id="submitpost"><div id="major-publishing-actions"><div id="publishing-action"><span class="spinner"></span>', '_builtin' => true);
         $form['submit'] = array('#type' => 'submit', '#name' => 'wpcf-submit', '#value' => $button_text, '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit'), '_builtin' => true);
         /**
          * add data attribute for _builtin post type
          */
         if (isset($this->ct['_builtin']) && $this->ct['_builtin']) {
             $form['submit']['#attributes']['data-post_type_is_builtin'] = '_builtin';
         }
         $form['submit-div-close'] = array('#type' => 'markup', '#markup' => '</div><div class="clear"></div></div></div>', '_builtin' => true);
     }
     return $form;
 }
Esempio n. 18
0
 function process_bulk_action()
 {
     global $wpdb;
     $action = $this->current_action();
     if (empty($action)) {
         return;
     }
     $nonce = wpcf_getpost('_wpnonce', null);
     if (!wp_verify_nonce($nonce, WPCF_Page_Listing_Termmeta::BULK_ACTION_NONCE)) {
         die('Security check');
     }
     $selected_field_group_ids = wpcf_getpost(self::BULK_ACTION_FIELD_NAME, array());
     if (empty($selected_field_group_ids)) {
         return;
     }
     foreach ($selected_field_group_ids as $field_group_id) {
         if (!WPCF_Roles::user_can_edit('term-field', array('id' => $field_group_id))) {
             continue;
         }
         switch ($action) {
             case 'delete':
                 $wpdb->delete($wpdb->posts, array('ID' => $field_group_id, 'post_type' => WPCF_Field_Group_Term::POST_TYPE), array('%d', '%s'));
                 break;
             case 'deactivate':
                 $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('ID' => $field_group_id, 'post_type' => WPCF_Field_Group_Term::POST_TYPE), array('%s'), array('%d', '%s'));
                 break;
             case 'activate':
                 $wpdb->update($wpdb->posts, array('post_status' => 'publish'), array('ID' => $field_group_id), array('%s'), array('%d'));
                 break;
         }
     }
     wp_cache_delete(md5('group::_get_group' . WPCF_Field_Group_Term::POST_TYPE), 'types_cache_groups');
 }
 /** ************************************************************************
  * Optional. You can handle your bulk actions anywhere or anyhow you prefer.
  * For this example package, we will handle it in the class to keep things
  * clean and organized.
  *
  * @global object $wpdb
  *
  * @see $this->prepare_items()
  **************************************************************************/
 function process_bulk_action()
 {
     global $wpdb;
     $action = $this->current_action();
     /**
      * check nounce
      */
     if (!empty($action)) {
         $nonce = '';
         if (isset($_REQUEST['_wpnonce'])) {
             $nonce = $_REQUEST['_wpnonce'];
         }
         if (!wp_verify_nonce($nonce, 'bulk-userfieldgroups')) {
             die('Security check');
         }
     }
     //Detect when a bulk action is being triggered...
     if (true && isset($_POST[$this->bulk_action_field_name]) && !empty($_POST[$this->bulk_action_field_name])) {
         $items = array();
         $args = array('nopaging' => true, 'posts_per_page' => -1, 'post_type' => 'wp-types-user-group', 'post__in' => $_POST[$this->bulk_action_field_name], 'update_post_term_cache' => false);
         $query = new WP_Query($args);
         if ($query->have_posts()) {
             while ($query->have_posts()) {
                 $query->the_post();
                 $items[get_the_ID()] = array('id' => get_the_ID(), WPCF_AUTHOR => get_the_author_meta('ID'));
                 wp_reset_postdata();
             }
         }
         foreach ($_POST[$this->bulk_action_field_name] as $key) {
             /**
              * do not process if there is no entry
              */
             if (!isset($items[$key])) {
                 continue;
             }
             /**
              * check capability
              */
             if (!WPCF_Roles::user_can_edit('user-meta-field', $items[$key])) {
                 continue;
             }
             /**
              * do it!
              */
             switch ($action) {
                 case 'deactivate':
                     $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('ID' => $key, 'post_type' => TYPES_USER_META_FIELD_GROUP_CPT_NAME), array('%s'), array('%d', '%s'));
                     break;
                 case 'activate':
                     $wpdb->update($wpdb->posts, array('post_status' => 'publish'), array('ID' => $key), array('%s'), array('%d'));
                     break;
             }
         }
         wp_cache_delete(md5('group::_get_group' . TYPES_USER_META_FIELD_GROUP_CPT_NAME), 'types_cache_groups');
     }
 }
Esempio n. 20
0
 /**
  * Upgrade database to 2010000 (Types 2.1) 
  *
  * Batch fix types-768 for all non-superadmin users.
  */
 function upgrade_db_to_2010000()
 {
     $roles_manager = WPCF_Roles::getInstance();
     global $wpdb;
     // Will find users without the administrator roles but with one of the Types management roles.
     // A sign of the types-768 bug.
     $user_query = new WP_User_Query(array('meta_query' => array('relation' => 'AND', array('key' => $wpdb->prefix . 'capabilities', 'value' => '"administrator"', 'compare' => 'NOT LIKE'), array('key' => $wpdb->prefix . 'capabilities', 'value' => '"wpcf_custom_post_type_view"', 'compare' => 'LIKE'))));
     $users = $user_query->get_results();
     foreach ($users as $user) {
         $roles_manager->clean_the_mess_in_nonadmin_user_caps($user);
     }
 }
/**
 * Add/edit form
 */
function wpcf_admin_custom_types_form()
{
    global $wpcf;
    include_once dirname(__FILE__) . '/common-functions.php';
    include_once dirname(__FILE__) . '/fields.php';
    $ct = array();
    $id = false;
    $update = false;
    if (isset($_GET['wpcf-post-type'])) {
        $id = sanitize_text_field($_GET['wpcf-post-type']);
    } elseif (isset($_POST['wpcf-post-type'])) {
        $id = sanitize_text_field($_POST['wpcf-post-type']);
    }
    if ($id) {
        $custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
        if (isset($custom_types[$id])) {
            $ct = $custom_types[$id];
            $update = true;
            // Set rewrite if needed
            if (isset($_GET['wpcf-rewrite'])) {
                flush_rewrite_rules();
            }
        } else {
            $buildin_post_types = wpcf_get_builtin_in_post_types();
            if (isset($buildin_post_types[$id])) {
                $ct = get_object_vars(get_post_type_object($id));
                $ct['labels'] = get_object_vars($ct['labels']);
                $ct['slug'] = esc_attr($id);
                $ct['_builtin'] = true;
            } else {
                wpcf_admin_message(__('Wrong custom post type specified', 'wpcf'), 'error');
                return false;
            }
        }
    } else {
        $ct = wpcf_custom_types_default();
    }
    $current_user_can_edit = WPCF_Roles::user_can_edit('custom-post-type', $ct);
    /**
     * sanitize _builtin
     */
    if (!isset($ct['_builtin'])) {
        $ct['_builtin'] = false;
    }
    /**
     * fix taxonomies assigment for builitin post types
     */
    if ($ct['_builtin']) {
        $taxonomies = get_taxonomies('', 'objects');
        foreach ($taxonomies as $slug => $tax) {
            foreach ($tax->object_type as $post_slug) {
                if ($ct['slug'] == $post_slug) {
                    $ct['taxonomies'][$slug] = 1;
                }
            }
        }
    }
    $form = array();
    /**
     * postbox-controll
     */
    $markup = wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false, false);
    $markup .= wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false, false);
    $form['postbox-controll'] = array('#type' => 'markup', '#markup' => $markup, '_builtin' => true);
    /**
     * form setup
     */
    $form['#form']['callback'] = 'wpcf_admin_custom_types_form_submit';
    $form['#form']['redirection'] = false;
    if ($current_user_can_edit && $update) {
        $form['id'] = array('#type' => 'hidden', '#value' => $id, '#name' => 'ct[wpcf-post-type]', '_builtin' => true);
        /**
         * update taxonomy too
         */
        $custom_taxonomies = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array());
        foreach ($custom_taxonomies as $slug => $data) {
            if (!array_key_exists('supports', $data)) {
                continue;
            }
            if (!array_key_exists($id, $data['supports'])) {
                continue;
            }
            if (array_key_exists('taxonomies', $ct) && array_key_exists($slug, $ct['taxonomies'])) {
                continue;
            }
            unset($custom_taxonomies[$slug]['supports'][$id]);
        }
        update_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, $custom_taxonomies);
    }
    /**
     * WP control for meta boxes
     */
    include_once ABSPATH . '/wp-admin/includes/meta-boxes.php';
    wp_enqueue_script('post');
    $form['form-open'] = array('#type' => 'markup', '#markup' => sprintf('<div id="poststuff" class="%s">', $current_user_can_edit ? '' : 'wpcf-types-read-only'), '_builtin' => true);
    $form['form-metabox-holder-columns-2-open'] = array('#type' => 'markup', '#markup' => '<div id="post-body" class="metabox-holder columns-2">', '_builtin' => true);
    $form['post-body-content-open'] = array('#type' => 'markup', '#markup' => '<div id="post-body-content">', '_builtin' => true);
    $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">' . __('Name and description', 'wpcf') . '</th></tr></thead><tbody>', '_builtin' => true);
    $table_row = '<tr><td><LABEL></td><td><ERROR><ELEMENT></td></tr>';
    $form['name'] = array('#type' => 'textfield', '#name' => 'ct[labels][name]', '#title' => __('Custom post type name plural', 'wpcf') . ' (<strong>' . __('required', 'wpcf') . '</strong>)', '#description' => '<strong>' . __('Enter in plural!', 'wpcf') . '.', '#value' => isset($ct['labels']['name']) ? $ct['labels']['name'] : '', '#validate' => array('required' => array('value' => 'true')), '#pattern' => $table_row, '#inline' => true, '#id' => 'name-plural', '#attributes' => array('data-wpcf_warning_same_as_slug' => $wpcf->post_types->message('warning_singular_plural_match'), 'data-wpcf_warning_same_as_slug_ignore' => $wpcf->post_types->message('warning_singular_plural_match_ignore'), 'placeholder' => __('Enter post type name plural', 'wpcf')), '_builtin' => true);
    $form['name-singular'] = array('#type' => 'textfield', '#name' => 'ct[labels][singular_name]', '#title' => __('Custom post type name singular', 'wpcf') . ' (<strong>' . __('required', 'wpcf') . '</strong>)', '#description' => '<strong>' . __('Enter in singular!', 'wpcf') . '</strong><br />' . '.', '#value' => isset($ct['labels']['singular_name']) ? $ct['labels']['singular_name'] : '', '#validate' => array('required' => array('value' => 'true')), '#pattern' => $table_row, '#inline' => true, '#id' => 'name-singular', '#attributes' => array('placeholder' => __('Enter post type name singular', 'wpcf'), 'class' => 'js-wpcf-slugize-source'), '_builtin' => true);
    /**
     * IF isset $_POST['slug'] it means form is not submitted
     */
    $attributes = array();
    if (!empty($_POST['ct']['slug'])) {
        $reserved = wpcf_is_reserved_name(sanitize_text_field($_POST['ct']['slug']), 'post_type');
        if (is_wp_error($reserved)) {
            $attributes = array('class' => 'wpcf-form-error', 'onclick' => 'jQuery(this).removeClass(\'wpcf-form-error\');');
        }
    }
    $form['slug'] = array('#type' => 'textfield', '#name' => 'ct[slug]', '#title' => __('Slug', 'wpcf') . ' (<strong>' . __('required', 'wpcf') . '</strong>)', '#value' => isset($ct['slug']) ? $ct['slug'] : '', '#pattern' => $table_row, '#inline' => true, '#validate' => array('required' => array('value' => 'true'), 'nospecialchars' => array('value' => 'true'), 'maxlength' => array('value' => '20')), '#attributes' => $attributes + array('maxlength' => '20', 'placeholder' => __('Enter post type slug', 'wpcf'), 'class' => 'js-wpcf-slugize'), '#id' => 'slug', '_builtin' => true);
    $form['description'] = array('#type' => 'textarea', '#name' => 'ct[description]', '#title' => __('Description', 'wpcf'), '#value' => isset($ct['description']) ? $ct['description'] : '', '#attributes' => array('rows' => 4, 'cols' => 60, 'placeholder' => __('Enter post type description', 'wpcf')), '#pattern' => $table_row, '#inline' => true);
    /**
     * icons only for version 3.8 up
     */
    global $wp_version;
    if (version_compare('3.8', $wp_version) < 1) {
        $form['icon'] = array('#type' => 'select', '#name' => 'ct[icon]', '#title' => __('Icon', 'wpcf'), '#default_value' => isset($ct['icon']) ? $ct['icon'] : 'admin-post', '#pattern' => $table_row, '#inline' => true, '#id' => 'wpcf-types-icon', '#options' => array('admin appearance' => 'admin-appearance', 'admin collapse' => 'admin-collapse', 'admin comments' => 'admin-comments', 'admin generic' => 'admin-generic', 'admin home' => 'admin-home', 'admin links' => 'admin-links', 'admin media' => 'admin-media', 'admin network' => 'admin-network', 'admin page' => 'admin-page', 'admin plugins' => 'admin-plugins', 'admin post' => 'admin-post', 'admin settings' => 'admin-settings', 'admin site' => 'admin-site', 'admin tools' => 'admin-tools', 'admin users' => 'admin-users', 'album' => 'album', 'align center' => 'align-center', 'align left' => 'align-left', 'align none' => 'align-none', 'align right' => 'align-right', 'analytics' => 'analytics', 'archive' => 'archive', 'arrow down alt2' => 'arrow-down-alt2', 'arrow down alt' => 'arrow-down-alt', 'arrow down' => 'arrow-down', 'arrow left alt2' => 'arrow-left-alt2', 'arrow left alt' => 'arrow-left-alt', 'arrow left' => 'arrow-left', 'arrow right alt2' => 'arrow-right-alt2', 'arrow right alt' => 'arrow-right-alt', 'arrow right' => 'arrow-right', 'arrow up alt2' => 'arrow-up-alt2', 'arrow up alt' => 'arrow-up-alt', 'arrow up' => 'arrow-up', 'art' => 'art', 'awards' => 'awards', 'backup' => 'backup', 'book alt' => 'book-alt', 'book' => 'book', 'building' => 'building', 'businessman' => 'businessman', 'calendar alt' => 'calendar-alt', 'calendar' => 'calendar', 'camera' => 'camera', 'carrot' => 'carrot', 'cart' => 'cart', 'category' => 'category', 'chart area' => 'chart-area', 'chart bar' => 'chart-bar', 'chart line' => 'chart-line', 'chart pie' => 'chart-pie', 'clipboard' => 'clipboard', 'clock' => 'clock', 'cloud' => 'cloud', 'controls back' => 'controls-back', 'controls forward' => 'controls-forward', 'controls pause' => 'controls-pause', 'controls play' => 'controls-play', 'controls repeat' => 'controls-repeat', 'controls skipback' => 'controls-skipback', 'controls skipforward' => 'controls-skipforward', 'controls volumeoff' => 'controls-volumeoff', 'controls volumeon' => 'controls-volumeon', 'dashboard' => 'dashboard', 'desktop' => 'desktop', 'dismiss' => 'dismiss', 'download' => 'download', 'editor aligncenter' => 'editor-aligncenter', 'editor alignleft' => 'editor-alignleft', 'editor alignright' => 'editor-alignright', 'editor bold' => 'editor-bold', 'editor break' => 'editor-break', 'editor code' => 'editor-code', 'editor contract' => 'editor-contract', 'editor customchar' => 'editor-customchar', 'editor distractionfree' => 'editor-distractionfree', 'editor expand' => 'editor-expand', 'editor help' => 'editor-help', 'editor indent' => 'editor-indent', 'editor insertmore' => 'editor-insertmore', 'editor italic' => 'editor-italic', 'editor justify' => 'editor-justify', 'editor kitchensink' => 'editor-kitchensink', 'editor ol' => 'editor-ol', 'editor outdent' => 'editor-outdent', 'editor paragraph' => 'editor-paragraph', 'editor paste text' => 'editor-paste-text', 'editor paste word' => 'editor-paste-word', 'editor quote' => 'editor-quote', 'editor removeformatting' => 'editor-removeformatting', 'editor rtl' => 'editor-rtl', 'editor spellcheck' => 'editor-spellcheck', 'editor strikethrough' => 'editor-strikethrough', 'editor textcolor' => 'editor-textcolor', 'editor ul' => 'editor-ul', 'editor underline' => 'editor-underline', 'editor unlink' => 'editor-unlink', 'editor video' => 'editor-video', 'edit' => 'edit', 'email alt' => 'email-alt', 'email' => 'email', 'excerpt view' => 'excerpt-view', 'exerpt view' => 'exerpt-view', 'external' => 'external', 'facebook alt' => 'facebook-alt', 'facebook' => 'facebook', 'feedback' => 'feedback', 'flag' => 'flag', 'format aside' => 'format-aside', 'format audio' => 'format-audio', 'format chat' => 'format-chat', 'format gallery' => 'format-gallery', 'format image' => 'format-image', 'format links' => 'format-links', 'format quote' => 'format-quote', 'format standard' => 'format-standard', 'format status' => 'format-status', 'format video' => 'format-video', 'forms' => 'forms', 'googleplus' => 'googleplus', 'grid view' => 'grid-view', 'groups' => 'groups', 'hammer' => 'hammer', 'heart' => 'heart', 'id alt' => 'id-alt', 'id' => 'id', 'images alt2' => 'images-alt2', 'images alt' => 'images-alt', 'image crop' => 'image-crop', 'image flip horizontal' => 'image-flip-horizontal', 'image flip vertical' => 'image-flip-vertical', 'image rotate left' => 'image-rotate-left', 'image rotate right' => 'image-rotate-right', 'index card' => 'index-card', 'info' => 'info', 'leftright' => 'leftright', 'lightbulb' => 'lightbulb', 'list view' => 'list-view', 'location alt' => 'location-alt', 'location' => 'location', 'lock' => 'lock', 'marker' => 'marker', 'media archive' => 'media-archive', 'media audio' => 'media-audio', 'media code' => 'media-code', 'media default' => 'media-default', 'media document' => 'media-document', 'media interactive' => 'media-interactive', 'media spreadsheet' => 'media-spreadsheet', 'media text' => 'media-text', 'media video' => 'media-video', 'megaphone' => 'megaphone', 'menu' => 'menu', 'microphone' => 'microphone', 'migrate' => 'migrate', 'minus' => 'minus', 'money' => 'money', 'nametag' => 'nametag', 'networking' => 'networking', 'no alt' => 'no-alt', 'no' => 'no', 'palmtree' => 'palmtree', 'performance' => 'performance', 'phone' => 'phone', 'playlist audio' => 'playlist-audio', 'playlist video' => 'playlist-video', 'plus alt' => 'plus-alt', 'plus' => 'plus', 'portfolio' => 'portfolio', 'post status' => 'post-status', 'post trash' => 'post-trash', 'pressthis' => 'pressthis', 'products' => 'products', 'randomize' => 'randomize', 'redo' => 'redo', 'rss' => 'rss', 'schedule' => 'schedule', 'screenoptions' => 'screenoptions', 'search' => 'search', 'share1' => 'share1', 'share alt2' => 'share-alt2', 'share alt' => 'share-alt', 'share' => 'share', 'shield alt' => 'shield-alt', 'shield' => 'shield', 'slides' => 'slides', 'smartphone' => 'smartphone', 'smiley' => 'smiley', 'sort' => 'sort', 'sos' => 'sos', 'star empty' => 'star-empty', 'star filled' => 'star-filled', 'star half' => 'star-half', 'store' => 'store', 'tablet' => 'tablet', 'tagcloud' => 'tagcloud', 'tag' => 'tag', 'testimonial' => 'testimonial', 'text' => 'text', 'tickets alt' => 'tickets-alt', 'tickets' => 'tickets', 'translation' => 'translation', 'trash' => 'trash', 'twitter' => 'twitter', 'undo' => 'undo', 'universal access alt' => 'universal-access-alt', 'universal access' => 'universal-access', 'update' => 'update', 'upload' => 'upload', 'vault' => 'vault', 'video alt2' => 'video-alt2', 'video alt3' => 'video-alt3', 'video alt' => 'video-alt', 'visibility' => 'visibility', 'welcome add page' => 'welcome-add-page', 'welcome comments' => 'welcome-comments', 'welcome edit page' => 'welcome-edit-page', 'welcome learn more' => 'welcome-learn-more', 'welcome view site' => 'welcome-view-site', 'welcome widgets menus' => 'welcome-widgets-menus', 'welcome write blog' => 'welcome-write-blog', 'wordpress alt' => 'wordpress-alt', 'wordpress' => 'wordpress', 'yes' => 'yes'));
    }
    $form['table-1-close'] = array('#type' => 'markup', '#markup' => '</tbody></table>', '_builtin' => true);
    global $sitepress;
    if ($update && isset($sitepress) && defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '2.6.2', '>=') && function_exists('wpml_custom_post_translation_options')) {
        $form['table-sitepress'] = array('#type' => 'markup', '#markup' => wpml_custom_post_translation_options($ct['slug']), '_builtin' => true);
    }
    $form['post-body-content-close'] = array('#type' => 'markup', '#markup' => '</div>', '_builtin' => true);
    /**
     * get box order
     */
    $meta_box_order_defaults = apply_filters('wpcf_meta_box_order_defaults', array('side' => array('submitdiv', 'wpcf_visibility', 'taxonomies'), 'normal' => array('labels', 'display_sections', 'options')), 'post_type');
    $screen = get_current_screen();
    if (false == ($meta_box_order = get_user_option('meta-box-order_' . $screen->id))) {
        $meta_box_order = $meta_box_order_defaults;
    } else {
        if (isset($meta_box_order[0]) && !isset($meta_box_order['normal'])) {
            $meta_box_order['normal'] = $meta_box_order[0];
        }
    }
    $meta_boxes = array();
    foreach ($meta_box_order_defaults as $key => $value) {
        foreach ($value as $meta_box_key) {
            $meta_boxes[$meta_box_key] = $ct;
        }
    }
    if (!$current_user_can_edit) {
        $meta_boxes['submitdiv'] = false;
    }
    foreach ($meta_box_order as $key => $value) {
        if (is_array($value)) {
            continue;
        }
        $meta_box_order[$key] = explode(',', $value);
    }
    /**
     * postbox-container-1
     */
    $form['postbox-container-1-open'] = array('#type' => 'markup', '#markup' => '<div id="postbox-container-1" class="postbox-container"><div class="meta-box-sortables ui-sortable" id="side-sortables">', '_builtin' => true);
    foreach ($meta_box_order['side'] as $key) {
        $function = sprintf('wpcf_admin_metabox_%s', $key);
        if (is_callable($function) && isset($meta_boxes[$key])) {
            $form += $function($meta_boxes[$key]);
            unset($meta_boxes[$key]);
        }
    }
    /* close side container */
    $form['postbox-container-1-close'] = array('#type' => 'markup', '#markup' => '</div></div>', '_builtin' => true);
    /**
     * normal container
     */
    $form['postbox-container-2-open'] = array('#type' => 'markup', '#markup' => '<div id="postbox-container-2" class="postbox-container"><div class="meta-box-sortables ui-sortable">', '_builtin' => true);
    foreach ($meta_box_order['normal'] as $key) {
        $function = sprintf('wpcf_admin_metabox_%s', $key);
        if (is_callable($function) && isset($meta_boxes[$key])) {
            $form += $function($meta_boxes[$key]);
            unset($meta_boxes[$key]);
        }
    }
    /**
     * grab missing meta-boxes
     */
    foreach (array_keys($meta_boxes) as $key) {
        $function = sprintf('wpcf_admin_metabox_%s', $key);
        if (is_callable($function)) {
            $form += $function($meta_boxes[$key]);
        }
    }
    /**
     * filter wpcf_post_type_form
     */
    $form = $form + apply_filters('wpcf_post_type_form', array(), $ct);
    /**
     * container-2 close
     */
    $form['postbox-container-2-close'] = array('#type' => 'markup', '#markup' => '</div></div>', '_builtin' => true);
    $form['form-close'] = array('#type' => 'markup', '#markup' => '</div></div>', '_builtin' => true);
    /**
     * handle _builtin post types
     */
    if ($ct['_builtin']) {
        foreach ($form as $key => $data) {
            if (!isset($data['#type'])) {
                continue;
            }
            if (isset($data['_builtin'])) {
                switch ($data['#type']) {
                    case 'textfield':
                    case 'textarea':
                        $form[$key]['#attributes']['readonly'] = 'readonly';
                        break;
                    default:
                }
                continue;
            }
            unset($form[$key]);
        }
    }
    /**
     * return form if current_user_can edit
     */
    if ($current_user_can_edit) {
        return $form;
    }
    return wpcf_admin_common_only_show($form);
}