本文整理汇总了PHP中WPCF_Roles::user_can_create方法的典型用法代码示例。如果您正苦于以下问题:PHP WPCF_Roles::user_can_create方法的具体用法?PHP WPCF_Roles::user_can_create怎么用?PHP WPCF_Roles::user_can_create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WPCF_Roles
的用法示例。
在下文中一共展示了WPCF_Roles::user_can_create方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wpcf_admin_menu_edit_user_fields
/**
* 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();
}
示例2: get_columns
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')));
}
示例3: wpcf_admin_menu_edit_user_fields
/**
* 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();
}
示例4: get_bulk_actions
function get_bulk_actions()
{
$actions = array();
if (WPCF_Roles::user_can_create('term-field')) {
$actions = array('activate' => __('Activate', 'wpcf'), 'deactivate' => __('Deactivate', 'wpcf'), 'delete' => __('Delete', 'wpcf'));
}
return $actions;
}
示例5: wpcf_add_admin_header
/**
* 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);
}
示例6: 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);
}
示例7: wpcf_admin_usermeta_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;
//.........这里部分代码省略.........
示例8: wpcf_admin_fields_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
*
//.........这里部分代码省略.........
示例9: 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);
}