/** * 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); }
/** * 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); }
/** * 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;" /> <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&wpcf_action=fields_insert' . '&field=' . basename($filename, '.php') . '&page=wpcf-edit-usermeta') . '&_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' . '&page=wpcf-edit' . '&wpcf_action=usermeta_insert_existing' . '&field=' . $field['id']) . '&_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' . '&wpcf_action=remove_from_history2' . '&field_id=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('remove_from_history2') . '&wpcf_warning=' . sprintf(__('Are you sure that you want to remove field %s from history?', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '&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; $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); }
/** * Generates form data. * * @deprecated Possibly deprecated, no usage found in Types. Possibly identical code in Types_Admin_Edit_Fields::get_field_form_data() */ function wpcf_admin_fields_form() { /** * include common functions */ include_once dirname(__FILE__) . '/common-functions.php'; wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\''); wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\''); $default = array(); global $wpcf_button_style; global $wpcf_button_style30; global $wpcf; $form = array(); $form['#form']['callback'] = array('wpcf_admin_save_fields_groups_submit'); // 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;" /> <a href="' . Types_Helper_Url::get_url('using-post-fields', 'fields-editor', 'fields-help', Types_Helper_Url::UTM_MEDIUM_HELP) . '" target="_blank">' . __('Custom fields help', 'wpcf') . '</a></div>'); $form['submit2'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit')); $form['fields'] = array('#type' => 'fieldset', '#title' => __('Available fields', 'wpcf')); // Get field types $fields_registered = wpcf_admin_fields_get_available_types(); foreach ($fields_registered as $filename => $data) { $form['fields'][basename($filename, '.php')] = array('#type' => 'markup', '#markup' => '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax&wpcf_action=fields_insert' . '&field=' . basename($filename, '.php') . '&page=wpcf-edit') . '&_wpnonce=' . wp_create_nonce('fields_insert') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary">' . $data['title'] . '</a> '); // Process JS if (!empty($data['group_form_js'])) { foreach ($data['group_form_js'] as $handle => $script) { if (isset($script['inline'])) { add_action('admin_footer', $script['inline']); continue; } $deps = !empty($script['deps']) ? $script['deps'] : array(); $in_footer = !empty($script['in_footer']) ? $script['in_footer'] : false; wp_register_script($handle, $script['src'], $deps, WPCF_VERSION, $in_footer); wp_enqueue_script($handle); } } // Process CSS if (!empty($data['group_form_css'])) { foreach ($data['group_form_css'] as $handle => $script) { if (isset($script['src'])) { $deps = !empty($script['deps']) ? $script['deps'] : array(); wp_enqueue_style($handle, $script['src'], $deps, WPCF_VERSION); } else { if (isset($script['inline'])) { add_action('admin_head', $script['inline']); } } } } } // Get fields created by user $fields = wpcf_admin_fields_get_fields(true, true); if (!empty($fields)) { $form['fields-existing'] = array('#type' => 'fieldset', '#title' => __('User created fields', 'wpcf'), '#id' => 'wpcf-form-groups-user-fields'); foreach ($fields as $key => $field) { if (isset($update['fields']) && array_key_exists($key, $update['fields'])) { continue; } if (!empty($field['data']['removed_from_history'])) { continue; } $form['fields-existing'][$key] = array('#type' => 'markup', '#markup' => '<div id="wpcf-user-created-fields-wrapper-' . $field['id'] . '" style="float:left; margin-right: 10px;"><a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&wpcf_action=fields_insert_existing' . '&page=wpcf-edit' . '&field=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('fields_insert_existing') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary" onclick="jQuery(this).parent().fadeOut();" ' . ' data-slug="' . $field['id'] . '">' . htmlspecialchars(stripslashes($field['name'])) . '</a>' . '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&wpcf_action=remove_from_history' . '&field_id=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('remove_from_history') . '&wpcf_warning=' . sprintf(__('Are you sure that you want to remove field %s from history?', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '&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">'); /** * Now starting form */ /** End admin Styles * */ // Group fields $form['fields_title'] = array('#type' => 'markup', '#markup' => '<h2>' . __('Fields', 'wpcf') . '</h2>'); $show_under_title = true; $form['ajax-response-open'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-fields-sortable" class="ui-sortable">'); // If it's update, display existing fields $existing_fields = array(); if ($update && isset($update['fields'])) { foreach ($update['fields'] as $slug => $field) { $field['submitted_key'] = $slug; $field['group_id'] = $update['id']; $form_field = wpcf_fields_get_field_form_data($field['type'], $field); if (is_array($form_field)) { $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">'); $form = $form + $form_field; $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>'); } $existing_fields[] = $slug; $show_under_title = false; } } // Any new fields submitted but failed? (Don't double it) if (!empty($_POST['wpcf']['fields'])) { foreach ($_POST['wpcf']['fields'] as $key => $field) { if (in_array($key, $existing_fields)) { continue; } $field['submitted_key'] = $key; $form_field = wpcf_fields_get_field_form_data($field['type'], $field); if (is_array($form_field)) { $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">'); $form = $form + $form_field; $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>'); } } $show_under_title = false; } $form['ajax-response-close'] = array('#type' => 'markup', '#markup' => '</div>' . '<div id="wpcf-ajax-response"></div>'); if ($show_under_title) { $form['fields_title']['#markup'] = $form['fields_title']['#markup'] . '<div id="wpcf-fields-under-title">' . __('There are no fields in this group. To add a field, click on the field buttons at the right.', 'wpcf') . '</div>'; } // If update, create ID field if ($update) { $form['group_id'] = array('#type' => 'hidden', '#name' => 'group_id', '#value' => $update['id'], '#forced_value' => true); } $form['submit'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit')); // Close main div $form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>'); $form = apply_filters('wpcf_form_fields', $form, $update); // Add JS settings wpcf_admin_add_js_settings('wpcfFormUniqueValuesCheckText', '\'' . __('Warning: same values selected', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueNamesCheckText', '\'' . __('Warning: field name already used', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueSlugsCheckText', '\'' . __('Warning: field slug already used', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormAlertOnlyPreview', sprintf("'%s'", __('Sorry, but this is only preview!', 'wpcf'))); $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); }
/** * Generates form data. */ function wpcf_admin_fields_form() { /** * include common functions */ include_once dirname(__FILE__) . '/common-functions.php'; wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\''); wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\''); $default = array(); global $wpcf_button_style; global $wpcf_button_style30; global $wpcf; $current_user_can_edit = WPCF_Roles::user_can_create('custom-field'); // If it's update, get data $update = false; if (isset($_REQUEST['group_id'])) { $update = wpcf_admin_fields_get_group(intval($_REQUEST['group_id'])); $current_user_can_edit = WPCF_Roles::user_can_edit('custom-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); $update['post_types'] = wpcf_admin_get_post_types_by_group(sanitize_text_field($_REQUEST['group_id'])); $update['taxonomies'] = wpcf_admin_get_taxonomies_by_group(sanitize_text_field($_REQUEST['group_id'])); $update['templates'] = wpcf_admin_get_templates_by_group(sanitize_text_field($_REQUEST['group_id'])); if (defined('TYPES_USE_STYLING_EDITOR') && TYPES_USE_STYLING_EDITOR) { $update['admin_styles'] = wpcf_admin_get_groups_admin_styles_by_group(sanitize_text_field($_REQUEST['group_id'])); } } } $form = array(); $form['form-open'] = array('#type' => 'markup', '#markup' => sprintf('<div id="poststuff" class="%s">', $current_user_can_edit ? '' : 'wpcf-types-read-only')); $form['#form']['callback'] = array('wpcf_admin_save_fields_groups_submit'); // 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_RELPATH . '/common/res/images/question.png" style="position:relative;top:2px;" /> <a href="http://wp-types.com/documentation/user-guides/using-custom-fields/?utm_source=typesplugin&utm_medium=help&utm_term=fields-help&utm_content=fields-editor&utm_campaign=types" target="_blank">' . __('Custom fields help', 'wpcf') . '</a></div>'); $form['submit2'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit')); $form['fields'] = array('#type' => 'fieldset', '#title' => __('Available fields', 'wpcf')); // Get field types $fields_registered = wpcf_admin_fields_get_available_types(); foreach ($fields_registered as $filename => $data) { $form['fields'][basename($filename, '.php')] = array('#type' => 'markup', '#markup' => '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax&wpcf_action=fields_insert' . '&field=' . basename($filename, '.php') . '&page=wpcf-edit') . '&_wpnonce=' . wp_create_nonce('fields_insert') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary">' . $data['title'] . '</a> '); // Process JS if (!empty($data['group_form_js'])) { foreach ($data['group_form_js'] as $handle => $script) { if (isset($script['inline'])) { add_action('admin_footer', $script['inline']); continue; } $deps = !empty($script['deps']) ? $script['deps'] : array(); $in_footer = !empty($script['in_footer']) ? $script['in_footer'] : false; wp_register_script($handle, $script['src'], $deps, WPCF_VERSION, $in_footer); wp_enqueue_script($handle); } } // Process CSS if (!empty($data['group_form_css'])) { foreach ($data['group_form_css'] as $handle => $script) { if (isset($script['src'])) { $deps = !empty($script['deps']) ? $script['deps'] : array(); wp_enqueue_style($handle, $script['src'], $deps, WPCF_VERSION); } else { if (isset($script['inline'])) { add_action('admin_head', $script['inline']); } } } } } // Get fields created by user $fields = wpcf_admin_fields_get_fields(true, true); if (!empty($fields)) { $form['fields-existing'] = array('#type' => 'fieldset', '#title' => __('User created fields', 'wpcf'), '#id' => 'wpcf-form-groups-user-fields'); foreach ($fields as $key => $field) { if (isset($update['fields']) && array_key_exists($key, $update['fields'])) { continue; } if (!empty($field['data']['removed_from_history'])) { continue; } $form['fields-existing'][$key] = array('#type' => 'markup', '#markup' => '<div id="wpcf-user-created-fields-wrapper-' . $field['id'] . '" style="float:left; margin-right: 10px;"><a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&wpcf_action=fields_insert_existing' . '&page=wpcf-edit' . '&field=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('fields_insert_existing') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary" onclick="jQuery(this).parent().fadeOut();" ' . ' data-slug="' . $field['id'] . '">' . htmlspecialchars(stripslashes($field['name'])) . '</a>' . '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&wpcf_action=remove_from_history' . '&field_id=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('remove_from_history') . '&wpcf_warning=' . sprintf(__('Are you sure that you want to remove field %s from history?', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '&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 ? $update['name'] : '', '#inline' => true, '#attributes' => array('style' => 'width:100%;margin-bottom:10px;', 'placeholder' => __('Enter group title', 'wpcf')), '#validate' => array('required' => array('value' => true))); $form['description'] = array('#type' => 'textarea', '#id' => 'wpcf-group-description', '#name' => 'wpcf[group][description]', '#value' => $update ? $update['description'] : '', '#attributes' => array('placeholder' => __('Enter a description for this group', 'wpcf'))); /** * * FILTER BOX * Since Types 1.2 we moved JS to /embedded/resources/js/custom-fields-form-filter.js * */ // Support post types and taxonomies $post_types = get_post_types('', 'objects'); $options = array(); $post_types_currently_supported = array(); $form_types = array(); foreach ($post_types as $post_type_slug => $post_type) { if (in_array($post_type_slug, $wpcf->excluded_post_types) || !$post_type->show_ui) { continue; } $options[$post_type_slug]['#name'] = 'wpcf[group][supports][' . $post_type_slug . ']'; $options[$post_type_slug]['#title'] = $post_type->label; $options[$post_type_slug]['#default_value'] = $update && !empty($update['post_types']) && in_array($post_type_slug, $update['post_types']) ? 1 : 0; $options[$post_type_slug]['#value'] = $post_type_slug; $options[$post_type_slug]['#inline'] = TRUE; $options[$post_type_slug]['#suffix'] = '<br />'; $options[$post_type_slug]['#id'] = 'wpcf-form-groups-support-post-type-' . $post_type_slug; $options[$post_type_slug]['#attributes'] = array('class' => 'wpcf-form-groups-support-post-type'); if ($update && !empty($update['post_types']) && in_array($post_type_slug, $update['post_types'])) { $post_types_currently_supported[] = $post_type->label; } } if (empty($post_types_currently_supported)) { $post_types_currently_supported[] = __('Displayed on all content types', 'wpcf'); } /** * POST TYPE FILTER */ $temp = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'wpcf[group][supports]', '#inline' => true); /** * Here we use unique function for all filters * Since Types 1.2 */ $form_types = _wpcf_filter_wrap('custom_post_types', __('Post Types:', 'wpcf'), implode(',', $post_types_currently_supported), __('Displayed on all content types', 'wpcf'), $temp); /** * TAXONOMIES FILTER QUERY */ $taxonomies = apply_filters('wpcf_group_form_filter_taxonomies', get_taxonomies('', 'objects')); $options = array(); $tax_currently_supported = array(); $form_tax = array(); $form_tax_single = array(); /** * Filter toxonomies */ foreach ($taxonomies as $category_slug => $category) { if ($category_slug == 'nav_menu' || $category_slug == 'link_category' || $category_slug == 'post_format') { continue; } $terms = apply_filters('wpcf_group_form_filter_terms', get_terms($category_slug, array('hide_empty' => false))); if (!empty($terms)) { $options = array(); $add_title = '<div class="taxonomy-title">' . $category->labels->name . '</div>'; $title = ''; foreach ($terms as $term) { $checked = 0; if ($update && !empty($update['taxonomies']) && array_key_exists($category_slug, $update['taxonomies'])) { if (array_key_exists($term->term_taxonomy_id, $update['taxonomies'][$category_slug])) { $checked = 1; $tax_currently_supported[$term->term_taxonomy_id] = $term->name; $title = ''; } } $options[$term->term_taxonomy_id]['#name'] = 'wpcf[group][taxonomies][' . $category_slug . '][' . $term->term_taxonomy_id . ']'; $options[$term->term_taxonomy_id]['#title'] = $term->name; $options[$term->term_taxonomy_id]['#default_value'] = $checked; $options[$term->term_taxonomy_id]['#value'] = $term->term_taxonomy_id; $options[$term->term_taxonomy_id]['#inline'] = true; $options[$term->term_taxonomy_id]['#prefix'] = $add_title; $options[$term->term_taxonomy_id]['#suffix'] = '<br />'; $options[$term->term_taxonomy_id]['#id'] = 'wpcf-form-groups-support-tax-' . $term->term_taxonomy_id; $options[$term->term_taxonomy_id]['#attributes'] = array('class' => 'wpcf-form-groups-support-tax'); $add_title = ''; } $form_tax_single['taxonomies-' . $category_slug] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'wpcf[group][taxonomies][' . $category_slug . ']', '#suffix' => '<br />', '#inline' => true); } } if (empty($tax_currently_supported)) { $tax_currently_supported[] = __('Not Selected', 'wpcf'); } /** * Since Types 1.2 we use unique function */ $form_tax = _wpcf_filter_wrap('custom_taxonomies', __('Terms:', 'wpcf'), implode(', ', array_values($tax_currently_supported)), __('Not Selected', 'wpcf'), $form_tax_single); /** * TEMPLATES */ // Choose templates $templates = get_page_templates(); $templates_views = get_posts('post_type=view-template&numberposts=-1&status=publish'); $options = array(); $options['default-template'] = array('#title' => __('Default Template', 'wpcf'), '#default_value' => !empty($update['templates']) && in_array('default', $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => 'default', '#inline' => true, '#after' => '<br />'); foreach ($templates as $template_name => $template_filename) { $options[$template_filename] = array('#title' => $template_name, '#default_value' => !empty($update['templates']) && in_array($template_filename, $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => $template_filename, '#inline' => true, '#after' => '<br />'); } foreach ($templates_views as $template_view) { $options[$template_view->post_name] = array('#title' => 'Content Template ' . $template_view->post_title, '#default_value' => !empty($update['templates']) && in_array($template_view->ID, $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => $template_view->ID, '#inline' => true, '#after' => '<br />'); $templates_view_list_text[$template_view->ID] = $template_view->post_title; } $text = ''; if (!empty($update['templates'])) { $text = array(); $templates = array_flip($templates); foreach ($update['templates'] as $template) { if ($template == 'default') { $template = __('Default Template', 'wpcf'); } else { if (strpos($template, '.php') !== false) { $template = $templates[$template]; } else { $template = 'Content Template ' . $templates_view_list_text[$template]; } } $text[] = $template; } $text = implode(', ', $text); } else { $text = __('Not Selected', 'wpcf'); } // Add class foreach ($options as $_k => $_option) { $options[$_k]['#attributes'] = array('class' => 'wpcf-form-groups-support-templates'); } $form_templates = array('#type' => 'checkboxes', '#name' => 'wpcf[group][templates]', '#options' => $options, '#inline' => true); /** * Since Types 1.2 we use unique function */ $form_templates = _wpcf_filter_wrap('templates', __('Templates:', 'wpcf'), $text, __('Not Selected', 'wpcf'), $form_templates); /** * Now starting form */ $form['supports-table-open'] = array('#type' => 'markup', '#markup' => '<table class="widefat"><thead><tr><th>' . __('Where to display this group', 'wpcf') . '</th></tr></thead><tbody><tr><td>' . '<p>' . __('Each custom fields group can display on different content types or different taxonomy.', 'wpcf') . '</p>'); /** * Join filter forms */ // Types $form['p_wrap_1_' . wpcf_unique_id(serialize($form_types))] = array('#type' => 'markup', '#markup' => '<p class="wpcf-filter-wrap">'); $form = $form + $form_types; // Terms $form['p_wrap_2_' . wpcf_unique_id(serialize($form_tax))] = array('#type' => 'markup', '#markup' => '</p><p class="wpcf-filter-wrap">'); $form = $form + $form_tax; // Templates $form['p_wrap_3_' . wpcf_unique_id(serialize($form_templates))] = array('#type' => 'markup', '#markup' => '</p><p class="wpcf-filter-wrap">'); $form = $form + $form_templates; $form['p_wrap_4_' . wpcf_unique_id(serialize($form_templates))] = array('#type' => 'markup', '#markup' => '</p>'); /** * TODO Code from now on should be revised */ if ($current_user_can_edit) { $count = 0; $count += !empty($update['post_types']) ? 1 : 0; $count += !empty($update['taxonomies']) ? 1 : 0; $count += !empty($update['templates']) ? 1 : 0; $display = $count > 1 ? '' : ' style="display:none;"'; $form['filters_association'] = array('#type' => 'radios', '#name' => 'wpcf[group][filters_association]', '#id' => 'wpcf-fields-form-filters-association', '#options' => array(__('Display this group when ANY of the above conditions is met', 'wpcf') => 'any', __('Display this group when ALL the above conditions is met', 'wpcf') => 'all'), '#default_value' => !empty($update['filters_association']) ? $update['filters_association'] : 'any', '#inline' => true, '#before' => '<div id="wpcf-fields-form-filters-association-form"' . $display . '>', '#after' => '<div id="wpcf-fields-form-filters-association-summary" style="margin-top:10px;font-style:italic;margin-bottom:15px;"></div></div>'); wpcf_admin_add_js_settings('wpcf_filters_association_or', '\'' . __('This group will appear on %pt% edit pages where content belongs to taxonomy: %tx% or 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') . '\''); $additional_filters = apply_filters('wpcf_fields_form_additional_filters', array(), $update); $form = $form + $additional_filters; } $form['supports-table-close'] = array('#type' => 'markup', '#markup' => '</td></tr></tbody></table><br />'); /** Admin styles* */ 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 . '/usermeta.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/usermeta-post.php'; //Get sample post $post = query_posts('posts_per_page=1'); if (!empty($post) && count($post) != '') { $post = $post[0]; } $preview_profile = wpcf_admin_post_meta_box_preview($post, $update, 1); $group = $update; $group['fields'] = wpcf_admin_post_process_fields($post, $group['fields'], true, false); $edit_profile = wpcf_admin_post_meta_box($post, $group, 1, true); add_action('admin_enqueue_scripts', 'wpcf_admin_fields_form_fix_styles', PHP_INT_MAX); } $temp[] = array('#type' => 'radio', '#suffix' => '<br />', '#value' => 'edit_mode', '#title' => 'Edit mode', '#name' => 'wpcf[group][preview]', '#default_value' => '', '#before' => '<div class="wpcf-admin-css-preview-style-edit">', '#inline' => true, '#attributes' => array('onclick' => 'changePreviewHtml(\'editmode\')', 'checked' => 'checked')); $temp[] = array('#type' => 'radio', '#title' => 'Read Only', '#name' => 'wpcf[group][preview]', '#default_value' => '', '#after' => '</div>', '#inline' => true, '#attributes' => array('onclick' => 'changePreviewHtml(\'readonly\')')); $temp[] = array('#type' => 'textarea', '#name' => 'wpcf[group][admin_html_preview]', '#inline' => true, '#id' => 'wpcf-form-groups-admin-html-preview', '#before' => '<h3>Field group HTML</h3>'); $temp[] = array('#type' => 'textarea', '#name' => 'wpcf[group][admin_styles]', '#inline' => true, '#value' => $admin_styles_value, '#default_value' => '', '#id' => 'wpcf-form-groups-css-fields-editor', '#after' => ' <div class="wpcf-update-preview-btn"><input type="button" value="Update preview" onclick="wpcfPreviewHtml()" style="float:right;" class="button-secondary"></div> <h3>' . __('Field group preview', '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>'); $form = apply_filters('wpcf_form_fields', $form, $update); // Add JS settings wpcf_admin_add_js_settings('wpcfFormUniqueValuesCheckText', '\'' . __('Warning: same values selected', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueNamesCheckText', '\'' . __('Warning: field name already used', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueSlugsCheckText', '\'' . __('Warning: field slug already used', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormAlertOnlyPreview', sprintf("'%s'", __('Sorry, but this is only preview!', 'wpcf'))); $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); }
/** * 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); }
/** * 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); }
/** * 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); }