本文整理汇总了PHP中wpcf_admin_message函数的典型用法代码示例。如果您正苦于以下问题:PHP wpcf_admin_message函数的具体用法?PHP wpcf_admin_message怎么用?PHP wpcf_admin_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpcf_admin_message函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: save
/**
* 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.
*/
private function save()
{
global $wpcf;
if (!isset($_POST['ct'])) {
return false;
}
$data = $_POST['ct'];
$update = false;
// Sanitize data
if (isset($data[$this->get_id])) {
$update = true;
$data[$this->get_id] = sanitize_title($data[$this->get_id]);
} else {
$data[$this->get_id] = null;
}
if (isset($data['slug'])) {
$data['slug'] = sanitize_title($data['slug']);
} elseif ($_GET['wpcf-post-type'] == 'post' || $_GET['wpcf-post-type'] == 'page' || $_GET['wpcf-post-type'] == 'attachment') {
$data['slug'] = $_GET['wpcf-post-type'];
} else {
$data['slug'] = null;
}
if (isset($data['rewrite']['slug'])) {
$data['rewrite']['slug'] = remove_accents($data['rewrite']['slug']);
$data['rewrite']['slug'] = strtolower($data['rewrite']['slug']);
$data['rewrite']['slug'] = trim($data['rewrite']['slug']);
}
$data['_builtin'] = false;
// Set post type name
$post_type = null;
if (!empty($data['slug'])) {
$post_type = $data['slug'];
} elseif (!empty($data[$this->get_id])) {
$post_type = $data[$this->get_id];
} elseif (!empty($data['labels']['singular_name'])) {
$post_type = sanitize_title($data['labels']['singular_name']);
}
if (empty($post_type)) {
wpcf_admin_message(__('Please set post type name', 'wpcf'), 'error');
return false;
}
$data['slug'] = $post_type;
$custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
$protected_data_check = array();
if (wpcf_is_builtin_post_types($data['slug'])) {
$data['_builtin'] = true;
$update = true;
} else {
// Check reserved name
$reserved = wpcf_is_reserved_name($post_type, 'post_type');
if (is_wp_error($reserved)) {
wpcf_admin_message($reserved->get_error_message(), 'error');
return false;
}
// Check overwriting
if ((!array_key_exists($this->get_id, $data) || $data[$this->get_id] != $post_type) && array_key_exists($post_type, $custom_types)) {
wpcf_admin_message(__('Post Type already exists', 'wpcf'), 'error');
return false;
}
/*
* Since Types 1.2
* We do not allow plural and singular names to be same.
*/
if ($wpcf->post_types->check_singular_plural_match($data)) {
wpcf_admin_message($wpcf->post_types->message('warning_singular_plural_match'), 'error');
return false;
}
// Check if renaming then rename all post entries and delete old type
if (!empty($data[$this->get_id]) && $data[$this->get_id] != $post_type) {
global $wpdb;
$wpdb->update($wpdb->posts, array('post_type' => $post_type), array('post_type' => $data[$this->get_id]), array('%s'), array('%s'));
/**
* update post meta "_wp_types_group_post_types"
*/
$sql = $wpdb->prepare(sprintf('select meta_id, meta_value from %s where meta_key = %%s', $wpdb->postmeta), '_wp_types_group_post_types');
$all_meta = $wpdb->get_results($sql, OBJECT_K);
$re = sprintf('/,%s,/', $data[$this->get_id]);
foreach ($all_meta as $meta) {
if (!preg_match($re, $meta->meta_value)) {
continue;
}
$wpdb->update($wpdb->postmeta, array('meta_value' => preg_replace($re, ',' . $post_type . ',', $meta->meta_value)), array('meta_id' => $meta->meta_id), array('%s'), array('%d'));
}
//.........这里部分代码省略.........
开发者ID:axeljohansson1988,项目名称:oddcv,代码行数:101,代码来源:class.types.admin.edit.post.type.php
示例2: wpcf_admin_usermeta_form
/**
* Generates form data.
*/
function wpcf_admin_usermeta_form()
{
global $wpcf;
wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\'');
wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\'');
$default = array();
global $wpcf_button_style;
global $wpcf_button_style30;
// If it's update, get data
$update = false;
if (isset($_REQUEST['group_id'])) {
$update = wpcf_admin_fields_get_group(intval($_REQUEST['group_id']), 'wp-types-user-group');
if (empty($update)) {
$update = false;
wpcf_admin_message(sprintf(__("Group with ID %d do not exist", 'wpcf'), intval($_REQUEST['group_id'])));
} else {
$update['fields'] = wpcf_admin_fields_get_fields_by_group($_REQUEST['group_id'], 'slug', false, true, false, 'wp-types-user-group', 'wpcf-usermeta');
$update['show_for'] = wpcf_admin_get_groups_showfor_by_group($_REQUEST['group_id']);
$update['admin_styles'] = wpcf_admin_get_groups_admin_styles_by_group($_REQUEST['group_id']);
}
}
$form = array();
$form['#form']['callback'] = array('wpcf_admin_save_usermeta_groups_submit');
// Form sidebars
$form['open-sidebar'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-fields-align-right">');
// Set help icon
$form['help-icon'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-admin-fields-help"><img src="' . WPCF_EMBEDDED_RELPATH . '/common/res/images/question.png" style="position:relative;top:2px;" /> <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">');
$form['title'] = array('#type' => 'textfield', '#name' => 'wpcf[group][name]', '#id' => 'wpcf-group-name', '#value' => $update ? $update['name'] : __('Enter group title', 'wpcf'), '#inline' => true, '#attributes' => array('style' => 'width:100%;margin-bottom:10px;'), '#validate' => array('required' => array('value' => true)));
if (!$update) {
$form['title']['#attributes']['data-label'] = addcslashes(__('Enter group title', 'wpcf'), '"');
$form['title']['#attributes']['onfocus'] = 'if (jQuery(this).val() == jQuery(this).data(\'label\')) { jQuery(this).val(\'\'); }';
$form['title']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(jQuery(this).data(\'label\')) }';
}
$form['description'] = array('#type' => 'textarea', '#id' => 'wpcf-group-description', '#name' => 'wpcf[group][description]', '#value' => $update ? $update['description'] : __('Enter a description for this group', 'wpcf'));
if (!$update) {
$form['description']['#attributes']['data-label'] = addcslashes(__('Enter a description for this group', 'wpcf'), '"');
$form['description']['#attributes']['onfocus'] = 'if (jQuery(this).val() == jQuery(this).data(\'label\')) { jQuery(this).val(\'\'); }';
$form['description']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(jQuery(this).data(\'label\')) }';
}
// Show Fields for
global $wp_roles;
$options = array();
$users_currently_supported = array();
$form_types = array();
foreach ($wp_roles->role_names as $role => $name) {
$options[$role]['#name'] = 'wpcf[group][supports][' . $role . ']';
$options[$role]['#title'] = ucwords($role);
//.........这里部分代码省略.........
开发者ID:sandum150,项目名称:cheltuieli,代码行数:101,代码来源:usermeta-form.php
示例3: save
/**
* 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.
*/
private function save()
{
if (!isset($_POST['ct'])) {
return false;
}
$data = $_POST['ct'];
$update = false;
// Sanitize data
if (isset($data[$this->get_id])) {
$update = true;
$data[$this->get_id] = sanitize_title($data[$this->get_id]);
}
if (isset($data['slug'])) {
$data['slug'] = sanitize_title($data['slug']);
}
if (isset($data['rewrite']['slug'])) {
$data['rewrite']['slug'] = remove_accents($data['rewrite']['slug']);
$data['rewrite']['slug'] = strtolower($data['rewrite']['slug']);
$data['rewrite']['slug'] = trim($data['rewrite']['slug']);
}
// Set tax name
$tax = '';
if (!empty($data['slug'])) {
$tax = $data['slug'];
} else {
if (!empty($data[$this->get_id])) {
$tax = $data[$this->get_id];
} else {
if (!empty($data['labels']['singular_name'])) {
$tax = sanitize_title($data['labels']['singular_name']);
}
}
}
if (empty($tax)) {
wpcf_admin_message(__('Please set taxonomy name', 'wpcf'), 'error');
return false;
}
if (empty($data['labels']['singular_name'])) {
$data['labels']['singular_name'] = $tax;
}
$data['slug'] = $tax;
$taxonomies = $this->taxonomies->get();
/**
* is built-in?
*/
$tax_is_built_in = wpcf_is_builtin_taxonomy($tax);
// Check reserved name
$reserved = wpcf_is_reserved_name($tax, 'taxonomy') && !$tax_is_built_in;
if (is_wp_error($reserved)) {
wpcf_admin_message($reserved->get_error_message(), 'error');
return false;
}
// Check if exists
if ($update && !array_key_exists($data[$this->get_id], $taxonomies)) {
wpcf_admin_message(__("Taxonomy do not exist", 'wpcf'), 'error');
return false;
}
// Check overwriting
if (!$update && array_key_exists($tax, $taxonomies)) {
/**
* set last edit author
*/
$data[WPCF_AUTHOR] = get_current_user_id();
wpcf_admin_message(__('Taxonomy already exists', 'wpcf'), 'error');
return false;
}
// Check if our tax overwrites some tax outside
$tax_exists = get_taxonomy($tax);
if (!$update && !empty($tax_exists)) {
wpcf_admin_message(__('Taxonomy already exists', 'wpcf'), 'error');
return false;
}
// Check if renaming
if (!$tax_is_built_in && $update && $data[$this->get_id] != $tax) {
global $wpdb;
$wpdb->update($wpdb->term_taxonomy, array('taxonomy' => esc_sql($tax)), array('taxonomy' => esc_sql($data[$this->get_id])), array('%s'), array('%s'));
// Sync action
do_action('wpcf_taxonomy_renamed', $tax, $data[$this->get_id]);
// Delete old type
unset($taxonomies[$data[$this->get_id]]);
}
// Check if active
if (isset($taxonomies[$tax]['disabled'])) {
//.........这里部分代码省略.........
开发者ID:phuocdungit,项目名称:fundy,代码行数:101,代码来源:class.types.admin.edit.taxonomy.php
示例4: wpcf_admin_fields_form
/**
* Generates form data.
*/
function wpcf_admin_fields_form()
{
wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\'');
wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\'');
$default = array();
// If it's update, get data
$update = false;
if (isset($_REQUEST['group_id'])) {
$update = wpcf_admin_fields_get_group(intval($_REQUEST['group_id']));
if (empty($update)) {
$update = false;
wpcf_admin_message(sprintf(__("Group with ID %d do not exist", 'wpcf'), intval($_REQUEST['group_id'])));
} else {
$update['fields'] = wpcf_admin_fields_get_fields_by_group($_REQUEST['group_id']);
$update['post_types'] = wpcf_admin_get_post_types_by_group($_REQUEST['group_id']);
$update['taxonomies'] = wpcf_admin_get_taxonomies_by_group($_REQUEST['group_id']);
$update['templates'] = wpcf_admin_get_templates_by_group($_REQUEST['group_id']);
}
}
$form = array();
$form['#form']['callback'] = array('wpcf_admin_save_fields_groups_submit');
// Form sidebars
$form['open-sidebar'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-fields-align-right">');
$form['submit2'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary'));
$form['fields'] = array('#type' => 'fieldset', '#title' => __('Available fields', 'wpcf'));
// Get field types
$fields_registered = wpcf_admin_fields_get_available_types();
// foreach (glob(WPCF_EMBEDDED_INC_ABSPATH . '/fields/*.php') as $filename) {
foreach ($fields_registered as $filename => $data) {
// require_once $filename;
// if (function_exists('wpcf_fields_' . basename($filename, '.php'))) {
// $data = call_user_func('wpcf_fields_' . basename($filename, '.php'));
// if (isset($data['wp_version']) && wpcf_compare_wp_version($data['wp_version'],
// '<')) {
// continue;
// }
$form['fields'][basename($filename, '.php')] = array('#type' => 'markup', '#markup' => '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax&wpcf_action=fields_insert' . '&field=' . basename($filename, '.php')) . '&_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' . '&field=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('fields_insert_existing') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary" onclick="jQuery(this).parent().fadeOut();">' . htmlspecialchars(stripslashes($field['name'])) . '</a>' . '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&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">');
$form['title'] = array('#type' => 'textfield', '#name' => 'wpcf[group][name]', '#id' => 'wpcf-group-name', '#value' => $update ? $update['name'] : __('Enter group title', 'wpcf'), '#inline' => true, '#attributes' => array('style' => 'width:100%;margin-bottom:10px;'), '#validate' => array('required' => array('value' => true)));
if (!$update) {
$form['title']['#attributes']['onfocus'] = 'if (jQuery(this).val() == \'' . __('Enter group title', 'wpcf') . '\') { jQuery(this).val(\'\'); }';
$form['title']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(\'' . __('Enter group title', 'wpcf') . '\') }';
}
$form['description'] = array('#type' => 'textarea', '#id' => 'wpcf-group-description', '#name' => 'wpcf[group][description]', '#value' => $update ? $update['description'] : __('Enter a description for this group', 'wpcf'));
if (!$update) {
$form['description']['#attributes']['onfocus'] = 'if (jQuery(this).val() == \'' . __('Enter a description for this group', 'wpcf') . '\') { jQuery(this).val(\'\'); }';
$form['description']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(\'' . __('Enter a description for this group', 'wpcf') . '\') }';
}
// Support post types and taxonomies
$post_types = get_post_types('', 'objects');
$options = array();
$post_types_currently_supported = array();
$form_types = array();
//.........这里部分代码省略.........
开发者ID:nuevomediagroup,项目名称:nmg-code,代码行数:101,代码来源:fields-form.php
示例5: wpcf_admin_fields_save_group
/**
* Update an existing field group or create new one.
*
* @param array $group
* @param string $post_type
* @return int Group ID.
*/
function wpcf_admin_fields_save_group($group, $post_type = TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, $which_fields = 'none')
{
if (!isset($group['name']) || empty($group['name'])) {
return false;
}
$post = array('post_status' => 'publish', 'post_type' => $post_type, 'post_title' => sanitize_text_field($group['name']), 'post_name' => sanitize_text_field($group['name']), 'post_content' => empty($group['description']) ? '' : $group['description']);
if (empty($post['post_title'])) {
wpcf_admin_message(__('Please set name', 'wpcf'), 'error');
return false;
}
$update = false;
if (isset($group['id']) && !empty($group['id'])) {
$update = true;
$post_to_update = get_post($group['id']);
if (empty($post_to_update) || $post_to_update->post_type != $post_type) {
return false;
}
$post['ID'] = $post_to_update->ID;
$post['post_status'] = $post_to_update->post_status;
}
if ($update) {
$group_id = wp_update_post($post);
if (!$group_id) {
return false;
}
update_post_meta($group_id, TOOLSET_EDIT_LAST, time());
} else {
$group_id = wp_insert_post($post, true);
if (is_wp_error($group_id)) {
return false;
}
}
if (isset($group['admin_styles'])) {
wpcf_admin_fields_save_group_admin_styles($group_id, $group['admin_styles']);
}
if (!empty($group['filters_association'])) {
update_post_meta($group_id, '_wp_types_group_filters_association', $group['filters_association']);
} else {
delete_post_meta($group_id, '_wp_types_group_filters_association');
}
// WPML register strings
if (function_exists('icl_register_string')) {
wpcf_translate_register_string('plugin Types', 'group ' . $group_id . ' name', $group['name']);
wpcf_translate_register_string('plugin Types', 'group ' . $group_id . ' description', $group['description']);
}
// admin message
wpcf_admin_fields_save_message($update, $which_fields);
return $group_id;
}
开发者ID:studiopengpeng,项目名称:ASCOMETAL,代码行数:56,代码来源:fields.php
示例6: wpcf_admin_custom_types_form_submit
/**
* Submit function
*/
function wpcf_admin_custom_types_form_submit($form)
{
global $wpcf;
if (!isset($_POST['ct'])) {
return false;
}
$data = $_POST['ct'];
$update = false;
// Sanitize data
if (isset($data['wpcf-post-type'])) {
$update = true;
$data['wpcf-post-type'] = sanitize_title($data['wpcf-post-type']);
} else {
$data['wpcf-post-type'] = null;
}
if (isset($data['slug'])) {
$data['slug'] = sanitize_title($data['slug']);
} else {
$data['slug'] = null;
}
if (isset($data['rewrite']['slug'])) {
$data['rewrite']['slug'] = remove_accents($data['rewrite']['slug']);
$data['rewrite']['slug'] = strtolower($data['rewrite']['slug']);
$data['rewrite']['slug'] = trim($data['rewrite']['slug']);
}
// Set post type name
$post_type = null;
if (!empty($data['slug'])) {
$post_type = $data['slug'];
} elseif (!empty($data['wpcf-post-type'])) {
$post_type = $data['wpcf-post-type'];
} elseif (!empty($data['labels']['singular_name'])) {
$post_type = sanitize_title($data['labels']['singular_name']);
}
if (empty($post_type)) {
wpcf_admin_message(__('Please set post type name', 'wpcf'), 'error');
return false;
}
$data['slug'] = $post_type;
$custom_types = get_option('wpcf-custom-types', array());
// Check reserved name
$reserved = wpcf_is_reserved_name($post_type, 'post_type');
if (is_wp_error($reserved)) {
wpcf_admin_message($reserved->get_error_message(), 'error');
return false;
}
// Check overwriting
if ((!array_key_exists('wpcf-post-type', $data) || $data['wpcf-post-type'] != $post_type) && array_key_exists($post_type, $custom_types)) {
wpcf_admin_message(__('Custom post type already exists', 'wpcf'), 'error');
return false;
}
/*
* Since Types 1.2
* We do not allow plural and singular names to be same.
*/
if ($wpcf->post_types->check_singular_plural_match($data)) {
wpcf_admin_message($wpcf->post_types->message('warning_singular_plural_match'), 'error');
return false;
}
// Check if renaming then rename all post entries and delete old type
if (!empty($data['wpcf-post-type']) && $data['wpcf-post-type'] != $post_type) {
global $wpdb;
$wpdb->update($wpdb->posts, array('post_type' => $post_type), array('post_type' => $data['wpcf-post-type']), array('%s'), array('%s'));
/**
* update post meta "_wp_types_group_post_types"
*/
$sql = sprintf('select meta_id, meta_value from %s where meta_key = \'%s\'', $wpdb->postmeta, '_wp_types_group_post_types');
$all_meta = $wpdb->get_results($sql, OBJECT_K);
$re = sprintf('/,%s,/', $data['wpcf-post-type']);
foreach ($all_meta as $meta) {
if (!preg_match($re, $meta->meta_value)) {
continue;
}
$wpdb->update($wpdb->postmeta, array('meta_value' => preg_replace($re, ',' . $post_type . ',', $meta->meta_value)), array('meta_id' => $meta->meta_id), array('%s'), array('%d'));
}
/**
* update _wpcf_belongs_{$data['wpcf-post-type']}_id
*/
$wpdb->update($wpdb->postmeta, array('meta_key' => sprintf('_wpcf_belongs_%s_id', $post_type)), array('meta_key' => sprintf('_wpcf_belongs_%s_id', $data['wpcf-post-type'])), array('%s'), array('%s'));
/**
* update options "wpv_options"
*/
$wpv_options = get_option('wpv_options', true);
if (is_array($wpv_options)) {
$re = sprintf('/(views_template_(archive_)?for_)%s/', $data['wpcf-post-type']);
foreach ($wpv_options as $key => $value) {
if (!preg_match($re, $key)) {
continue;
}
unset($wpv_options[$key]);
$key = preg_replace($re, "\$1" . $post_type, $key);
$wpv_options[$key] = $value;
}
update_option('wpv_options', $wpv_options);
}
/**
* update option "wpcf-custom-taxonomies"
//.........这里部分代码省略.........
开发者ID:sandum150,项目名称:cheltuieli,代码行数:101,代码来源:custom-types-form.php
示例7: save
/**
* 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 save()
{
if (!isset($_POST['wpcf']) || !isset($_POST['wpcf']['group']) || !isset($_POST['wpcf']['group']['name'])) {
return false;
}
$_POST['wpcf']['group'] = apply_filters('wpcf_group_pre_save', $_POST['wpcf']['group']);
$group_name = wp_kses_post($_POST['wpcf']['group']['name']);
require_once WPCF_EMBEDDED_ABSPATH . '/classes/forms.php';
$form = new Enlimbo_Forms_Wpcf();
if (empty($group_name)) {
$form->triggerError();
wpcf_admin_message(__('Group name can not be empty.', 'wpcf'), 'error');
return $form;
}
$new_group = false;
$group_slug = sanitize_title($group_name);
// Basic check
if (isset($_REQUEST[$this->get_id])) {
// Check if group exists
$post = get_post(intval($_REQUEST[$this->get_id]));
// Name changed
if (strtolower($group_name) != strtolower($post->post_title)) {
// Check if already exists
$exists = get_page_by_title($group_name, 'OBJECT', TYPES_USER_META_FIELD_GROUP_CPT_NAME);
if (!empty($exists)) {
$form->triggerError();
wpcf_admin_message(sprintf(__("A group by name <em>%s</em> already exists. Please use a different name and save again.", 'wpcf'), apply_filters('the_title', $exists->post_title)), 'error');
return $form;
}
}
if (empty($post) || $post->post_type != TYPES_USER_META_FIELD_GROUP_CPT_NAME) {
$form->triggerError();
wpcf_admin_message(sprintf(__("Wrong group ID %d", 'wpcf'), intval($_REQUEST[$this->get_id])), 'error');
return $form;
}
$group_id = $post->ID;
} else {
$new_group = true;
// Check if already exists
$exists = get_page_by_title($group_name, 'OBJECT', TYPES_USER_META_FIELD_GROUP_CPT_NAME);
if (!empty($exists)) {
$form->triggerError();
wpcf_admin_message(sprintf(__("A group by name <em>%s</em> already exists. Please use a different name and save again.", 'wpcf'), apply_filters('the_title', $exists->post_title)), 'error');
return $form;
}
}
// Save fields for future use
$fields = array();
if (!empty($_POST['wpcf']['fields'])) {
foreach ($_POST['wpcf']['fields'] as $key => $field) {
$field = wpcf_sanitize_field($field);
$field = apply_filters('wpcf_field_pre_save', $field);
if (!empty($field['is_new'])) {
// Check name and slug
if (wpcf_types_cf_under_control('check_exists', sanitize_title($field['name']), TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta')) {
$form->triggerError();
wpcf_admin_message(sprintf(__('Field with name "%s" already exists', 'wpcf'), $field['name']), 'error');
return $form;
}
if (isset($field['slug']) && wpcf_types_cf_under_control('check_exists', sanitize_title($field['slug']), TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta')) {
$form->triggerError();
wpcf_admin_message(sprintf(__('Field with slug "%s" already exists', 'wpcf'), $field['slug']), 'error');
return $form;
}
}
// Field ID and slug are same thing
$field_id = wpcf_admin_fields_save_field($field, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta');
if (!empty($field_id)) {
$fields[] = $field_id;
}
}
}
// Save group
$roles = isset($_POST['wpcf']['group']['supports']) ? $_POST['wpcf']['group']['supports'] : array();
/**
* Admin styles
*/
if (isset($_POST['wpcf']['group']['admin_styles'])) {
$admin_style = esc_html($_POST['wpcf']['group']['admin_styles']);
}
// Rename if needed
if (isset($_REQUEST[$this->get_id])) {
$_POST['wpcf']['group']['id'] = intval($_REQUEST[$this->get_id]);
//.........这里部分代码省略.........
开发者ID:phuocdungit,项目名称:fundy,代码行数:101,代码来源:class.types.admin.edit.meta.fields.group.php
示例8: wpcf_admin_custom_taxonomies_form_submit
/**
* Submit function
*/
function wpcf_admin_custom_taxonomies_form_submit($form)
{
if (!isset($_POST['ct'])) {
return false;
}
$data = $_POST['ct'];
$update = false;
// Sanitize data
if (isset($data['wpcf-tax'])) {
$update = true;
$data['wpcf-tax'] = sanitize_title($data['wpcf-tax']);
}
if (isset($data['slug'])) {
$data['slug'] = sanitize_title($data['slug']);
}
if (isset($data['rewrite']['slug'])) {
$data['rewrite']['slug'] = remove_accents($data['rewrite']['slug']);
$data['rewrite']['slug'] = strtolower($data['rewrite']['slug']);
$data['rewrite']['slug'] = trim($data['rewrite']['slug']);
}
// Set tax name
$tax = '';
if (!empty($data['slug'])) {
$tax = $data['slug'];
} else {
if (!empty($data['wpcf-tax'])) {
$tax = $data['wpcf-tax'];
} else {
if (!empty($data['labels']['singular_name'])) {
$tax = sanitize_title($data['labels']['singular_name']);
}
}
}
if (empty($tax)) {
wpcf_admin_message(__('Please set taxonomy name', 'wpcf'), 'error');
return false;
}
if (empty($data['labels']['singular_name'])) {
$data['labels']['singular_name'] = $tax;
}
$data['slug'] = $tax;
$custom_taxonomies = get_option('wpcf-custom-taxonomies', array());
// Check reserved name
if (wpcf_is_reserved_name($tax)) {
wpcf_admin_message(sprintf(__('The name %s is reserved in WordPress and cannot be used in custom taxonomies. Please use a different name.', 'wpcf'), $tax), 'error');
return false;
}
// Check if exists
if ($update && !array_key_exists($data['wpcf-tax'], $custom_taxonomies)) {
wpcf_admin_message(__("Custom taxonomy do not exist", 'wpcf'), 'error');
return false;
}
// Check overwriting
if (!$update && array_key_exists($tax, $custom_taxonomies)) {
wpcf_admin_message(__('Custom taxonomy already exists', 'wpcf'), 'error');
return false;
}
// Check if our tax overwrites some tax outside
$tax_exists = get_taxonomy($tax);
if (!$update && !empty($tax_exists)) {
wpcf_admin_message(__('Taxonomy already exists', 'wpcf'), 'error');
return false;
}
// Check if renaming
if ($update && $data['wpcf-tax'] != $tax) {
global $wpdb;
$wpdb->update($wpdb->term_taxonomy, array('taxonomy' => $tax), array('taxonomy' => $data['wpcf-tax']), array('%s'), array('%s'));
// Delete old type
unset($custom_taxonomies[$data['wpcf-tax']]);
}
// Check if active
if (isset($custom_taxonomies[$tax]['disabled'])) {
$data['disabled'] = $custom_taxonomies[$tax]['disabled'];
}
// Sync with post types
if (!empty($data['supports'])) {
$post_types = get_option('wpcf-custom-types', array());
foreach ($post_types as $id => $type) {
if (array_key_exists($id, $data['supports'])) {
$post_types[$id]['taxonomies'][$data['slug']] = 1;
} else {
unset($post_types[$id]['taxonomies'][$data['slug']]);
}
}
update_option('wpcf-custom-types', $post_types);
}
$custom_taxonomies[$tax] = $data;
update_option('wpcf-custom-taxonomies', $custom_taxonomies);
// WPML register strings
wpcf_custom_taxonimies_register_translation($tax, $data);
wpcf_admin_message_store(__('Custom taxonomy saved', 'wpcf'));
// Flush rewrite rules
flush_rewrite_rules();
// Redirect
wp_redirect(admin_url('admin.php?page=wpcf-edit-tax&wpcf-tax=' . $tax . '&wpcf-rewrite=1'));
die;
}
开发者ID:dewavi,项目名称:occupysandy.net,代码行数:100,代码来源:custom-taxonomies-form.php
示例9: wpcf_admin_fields_form
/**
* Generates form data.
*/
function wpcf_admin_fields_form()
{
wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\'');
wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\'');
$default = array();
global $wpcf_button_style;
global $wpcf_button_style30;
global $wpcf;
// If it's update, get data
$update = false;
if (isset($_REQUEST['group_id'])) {
$update = wpcf_admin_fields_get_group(intval($_REQUEST['group_id']));
if (empty($update)) {
$update = false;
wpcf_admin_message(sprintf(__("Group with ID %d do not exist", 'wpcf'), intval($_REQUEST['group_id'])));
} else {
$update['fields'] = wpcf_admin_fields_get_fields_by_group(sanitize_text_field($_REQUEST['group_id']), 'slug', false, true);
$update['post_types'] = wpcf_admin_get_post_types_by_group(sanitize_text_field($_REQUEST['group_id']));
$update['taxonomies'] = wpcf_admin_get_taxonomies_by_group(sanitize_text_field($_REQUEST['group_id']));
$update['templates'] = wpcf_admin_get_templates_by_group(sanitize_text_field($_REQUEST['group_id']));
$update['admin_styles'] = wpcf_admin_get_groups_admin_styles_by_group(sanitize_text_field($_REQUEST['group_id']));
}
}
$form = array();
$form['#form']['callback'] = array('wpcf_admin_save_fields_groups_submit');
// Form sidebars
$form['open-sidebar'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-fields-align-right">');
// Set help icon
$form['help-icon'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-admin-fields-help"><img src="' . WPCF_EMBEDDED_RELPATH . '/common/res/images/question.png" style="position:relative;top:2px;" /> <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">');
$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 . ']';
//.........这里部分代码省略.........
开发者ID:chrismathers,项目名称:premierplacement,代码行数:101,代码来源:fields-form.php
示例10: wpcf_admin_custom_types_form_submit
/**
* Submit function
*/
function wpcf_admin_custom_types_form_submit($form)
{
if (!isset($_POST['ct'])) {
return false;
}
$data = $_POST['ct'];
$update = false;
// Sanitize data
if (isset($data['wpcf-post-type'])) {
$update = true;
$data['wpcf-post-type'] = sanitize_title($data['wpcf-post-type']);
}
if (isset($data['slug'])) {
$data['slug'] = sanitize_title($data['slug']);
}
if (isset($data['rewrite']['slug'])) {
$data['rewrite']['slug'] = remove_accents($data['rewrite']['slug']);
$data['rewrite']['slug'] = strtolower($data['rewrite']['slug']);
$data['rewrite']['slug'] = trim($data['rewrite']['slug']);
}
// Set post type name
$post_type = '';
if (!empty($data['slug'])) {
$post_type = $data['slug'];
} else {
if (!empty($data['wpcf-post-type'])) {
$post_type = $data['wpcf-post-type'];
} else {
if (!empty($data['labels']['singular_name'])) {
$post_type = sanitize_title($data['labels']['singular_name']);
}
}
}
if (empty($post_type)) {
wpcf_admin_message(__('Please set post type name', 'wpcf'), 'error');
// $form->triggerError();
return false;
}
$data['slug'] = $post_type;
$custom_types = get_option('wpcf-custom-types', array());
// Check overwriting
if (!$update && array_key_exists($post_type, $custom_types)) {
wpcf_admin_message(__('Custom post type already exists', 'wpcf'), 'error');
// $form->triggerError();
return false;
}
// Check if renaming then rename all post entries and delete old type
if (!empty($data['wpcf-post-type']) && $data['wpcf-post-type'] != $post_type) {
global $wpdb;
$wpdb->update($wpdb->posts, array('post_type' => $post_type), array('post_type' => $data['wpcf-post-type']), array('%s'), array('%s'));
// Delete old type
unset($custom_types[$data['wpcf-post-type']]);
}
// Check if active
if (isset($custom_types[$post_type]['disabled'])) {
$data['disabled'] = $custom_types[$post_type]['disabled'];
}
// Sync taxes with custom taxes
if (!empty($data['taxonomies'])) {
$taxes = get_option('wpcf-custom-taxonomies', array());
foreach ($taxes as $id => $tax) {
if (array_key_exists($id, $data['taxonomies'])) {
$taxes[$id]['supports'][$data['slug']] = 1;
} else {
unset($taxes[$id]['supports'][$data['slug']]);
}
}
update_option('wpcf-custom-taxonomies', $taxes);
}
$custom_types[$post_type] = $data;
update_option('wpcf-custom-types', $custom_types);
wpcf_admin_message_store(__('Custom post type saved', 'wpcf'));
// Flush rewrite rules
flush_rewrite_rules();
// Redirect
wp_redirect(admin_url('admin.php?page=wpcf-edit-type&wpcf-post-type=' . $post_type
|
请发表评论