本文整理汇总了PHP中sanitize_text_field函数的典型用法代码示例。如果您正苦于以下问题:PHP sanitize_text_field函数的具体用法?PHP sanitize_text_field怎么用?PHP sanitize_text_field使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sanitize_text_field函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wppb_userdata_add_yim
function wppb_userdata_add_yim($userdata, $global_request)
{
if (isset($global_request['yim'])) {
$userdata['yim'] = sanitize_text_field(trim($global_request['yim']));
}
return $userdata;
}
示例2: wolf_columns_shortcode
/**
* Columns shortcode
*
* @param array $atts
* @param string $content
* @return string
*/
function wolf_columns_shortcode($atts, $content = null)
{
// if ( class_exists( 'Vc_Manager' ) && function_exists( 'vc_map_get_attributes' ) ) {
// $atts = vc_map_get_attributes( 'wolf_column', $atts );
// }
extract(shortcode_atts(array('col' => 'col-6', 'class' => '', 'first' => '', 'last' => '', 'inline_style' => ''), $atts));
$col = esc_attr($col);
$first = esc_attr($first);
$last = esc_attr($last);
$col = esc_attr($col);
$inline_style = sanitize_text_field($inline_style);
$output = '';
$style = '';
$class = $class ? "{$class} " : '';
// add space
if ($inline_style) {
$style .= $inline_style;
}
$style = $style ? " style='{$style}'" : '';
if ($first) {
$class = 'first';
} elseif ($last) {
$class = 'last';
}
if ($class == 'first') {
$output .= '<div class="clear"></div>';
}
$output .= '<div class="' . $col . ' ' . $class . '"' . $style . '>' . do_shortcode($content) . '</div>';
if ($class == 'last') {
$output .= '<div class="clear"></div>';
}
return $output;
}
示例3: ajax_register
function ajax_register()
{
// First check the nonce, if it fails the function will break
check_ajax_referer('ajax-register-nonce', 'security');
// Nonce is checked, get the POST data and sign user on
$info = array();
$info['user_nicename'] = $info['nickname'] = $info['display_name'] = $info['first_name'] = $info['user_login'] = sanitize_user($_POST['username']);
$info['user_pass'] = sanitize_text_field($_POST['password']);
$info['user_email'] = sanitize_email($_POST['email']);
// Register the user
$user_register = wp_insert_user($info);
if (is_wp_error($user_register)) {
$error = $user_register->get_error_codes();
if (in_array('empty_user_login', $error)) {
echo json_encode(array('loggedin' => false, 'message' => __('Xin lỗi, thông tin đăng nhập không hợp lệ.')));
} else {
if (in_array('existing_user_login', $error)) {
echo json_encode(array('loggedin' => false, 'message' => __('Xin lỗi, tên đăng nhập này đã tồn tại.')));
} else {
if (in_array('existing_user_email', $error)) {
echo json_encode(array('loggedin' => false, 'message' => __('Xin lỗi, thư điện tử này đã tồn tại.')));
}
}
}
// else echo json_encode(array('loggedin'=>false, 'message'=>__($user_register->get_error_messages($error))));
} else {
wp_insert_user($info);
echo json_encode(array('loggedin' => true, 'message' => __('Đăng ký thành công.')));
}
die;
}
示例4: ask_form_name_field
public function ask_form_name_field($args)
{
if (!is_user_logged_in() && ap_opt('allow_anonymous')) {
$args['fields'][] = array('name' => 'name', 'label' => __('Name', 'ap'), 'type' => 'text', 'placeholder' => __('Enter your name to display', 'ap'), 'value' => sanitize_text_field(@$_POST['name']), 'order' => 12);
}
return $args;
}
示例5: __construct
/**
* Construct
*/
function __construct($args = array(), $hook_prefs = NULL, $type = 'mycred_default')
{
if (!empty($args)) {
foreach ($args as $key => $value) {
$this->{$key} = $value;
}
}
// Grab myCRED Settings
$this->core = mycred($type);
if (!empty($type)) {
$this->core->cred_id = sanitize_text_field($type);
$this->mycred_type = $this->core->cred_id;
}
if ($this->mycred_type != 'mycred_default') {
$this->is_main_type = false;
}
// Grab settings
if ($hook_prefs !== NULL) {
// Assign prefs if set
if (isset($hook_prefs[$this->id])) {
$this->prefs = $hook_prefs[$this->id];
}
// Defaults must be set
if (!isset($this->defaults)) {
$this->defaults = array();
}
}
// Apply default settings if needed
if (!empty($this->defaults)) {
$this->prefs = mycred_apply_defaults($this->defaults, $this->prefs);
}
}
示例6: update
/**
* Update widget instance.
*
* @since 1.0.0
*
* @param array $new_instance New settings for this instance as input by the user via
* {@see WP_Widget::form()}.
* @param array $old_instance Old settings for this instance.
* @return array Settings to save or bool false to cancel saving.
*/
function update($new_instance, $old_instance)
{
$instance = $old_instance;
$new_instance = wp_parse_args((array) $new_instance, array('title' => ''));
$instance['title'] = sanitize_text_field($new_instance['title']);
return $instance;
}
示例7: update
function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = sanitize_text_field($new_instance['title']);
$instance['adsenseCode'] = wp_filter_post_kses(addslashes($new_instance['adsenseCode']));
return $instance;
}
示例8: wpuxss_eml_taxonomies_validate
function wpuxss_eml_taxonomies_validate($input)
{
if (!$input) {
$input = array();
}
foreach ($input as $taxonomy => $params) {
$sanitized_taxonomy = sanitize_key($taxonomy);
if ($sanitized_taxonomy !== $taxonomy) {
$input[$sanitized_taxonomy] = $input[$taxonomy];
unset($input[$taxonomy]);
$taxonomy = $sanitized_taxonomy;
}
$input[$taxonomy]['hierarchical'] = isset($params['hierarchical']) ? 1 : 0;
$input[$taxonomy]['sort'] = isset($params['sort']) ? 1 : 0;
$input[$taxonomy]['show_admin_column'] = isset($params['show_admin_column']) ? 1 : 0;
$input[$taxonomy]['show_in_nav_menus'] = isset($params['show_in_nav_menus']) ? 1 : 0;
$input[$taxonomy]['assigned'] = isset($params['assigned']) ? 1 : 0;
$input[$taxonomy]['admin_filter'] = isset($params['admin_filter']) ? 1 : 0;
$input[$taxonomy]['media_uploader_filter'] = isset($params['media_uploader_filter']) ? 1 : 0;
$input[$taxonomy]['media_popup_taxonomy_edit'] = isset($params['media_popup_taxonomy_edit']) ? 1 : 0;
$input[$taxonomy]['rewrite']['with_front'] = isset($params['rewrite']['with_front']) ? 1 : 0;
$input[$taxonomy]['rewrite']['slug'] = isset($params['rewrite']['slug']) ? wpuxss_eml_sanitize_slug($params['rewrite']['slug'], $taxonomy) : '';
if (isset($params['labels'])) {
$default_labels = array('menu_name' => $params['labels']['name'], 'all_items' => 'All ' . $params['labels']['name'], 'edit_item' => 'Edit ' . $params['labels']['singular_name'], 'view_item' => 'View ' . $params['labels']['singular_name'], 'update_item' => 'Update ' . $params['labels']['singular_name'], 'add_new_item' => 'Add New ' . $params['labels']['singular_name'], 'new_item_name' => 'New ' . $params['labels']['singular_name'] . ' Name', 'parent_item' => 'Parent ' . $params['labels']['singular_name'], 'search_items' => 'Search ' . $params['labels']['name']);
foreach ($params['labels'] as $label => $value) {
$input[$taxonomy]['labels'][$label] = sanitize_text_field($value);
if (empty($value) && isset($default_labels[$label])) {
$input[$taxonomy]['labels'][$label] = sanitize_text_field($default_labels[$label]);
}
}
}
}
return $input;
}
示例9: rcl_update_grouppost_meta
function rcl_update_grouppost_meta($post_id, $postdata, $action)
{
if ($postdata['post_type'] != 'post-group') {
return false;
}
if (isset($_POST['term_id'])) {
$term_id = intval(base64_decode($_POST['term_id']));
}
if (isset($term_id)) {
wp_set_object_terms($post_id, (int) $term_id, 'groups');
}
$gr_tag = sanitize_text_field($_POST['group-tag']);
if ($gr_tag) {
if (!$term_id) {
$groups = get_the_terms($post_id, 'groups');
foreach ($groups as $group) {
if ($group->parent != 0) {
continue;
}
$group_id = $group->term_id;
}
} else {
$group_id = $term_id;
}
$term = term_exists($gr_tag, 'groups', $group_id);
if (!$term) {
$term = wp_insert_term($gr_tag, 'groups', array('description' => '', 'slug' => '', 'parent' => $group_id));
}
wp_set_object_terms($post_id, array((int) $term['term_id'], (int) $group_id), 'groups');
}
}
示例10: process_network_settings
/**
* Process network options
*/
function process_network_settings()
{
if (current_user_can('manage_network')) {
$opts = array('recaptcha_publickey' => 'trim', 'recaptcha_privatekey' => 'trim', 'recaptcha_enable_comments' => 'intval', 'recaptcha_enable_signup' => 'intval', 'recaptcha_enable_login' => 'intval', 'recaptcha_enable_lostpw' => 'intval', 'recaptcha_enable_wc_order' => 'intval', 'recaptcha_disable_for_known_users' => 'intval', 'recaptcha_noscript' => 'intval', 'recaptcha_comment_use_42_filter' => 'intval');
if (array_intersect(array_keys($_POST), array_keys($opts))) {
check_admin_referer('recaptcha-network-settings');
}
$updated = false;
foreach ($opts as $option_name => $sanitize_cb) {
if (isset($_POST[$option_name])) {
$option_value = sanitize_text_field($_POST[$option_name]);
if (is_callable($sanitize_cb)) {
$option_value = call_user_func($sanitize_cb, $_POST[$option_name]);
}
update_site_option($option_name, $option_value);
$updated = true;
}
}
if ($updated) {
$redirect = $this->remove_new_apikey_url(add_query_arg(array('updated' => 'true')));
wp_redirect($redirect);
}
} else {
wp_die('Cheating, uh?');
}
// expecting api keys,
}
示例11: user_info
/**
*
* Process the infoz
* @since 1.0
*/
function user_info()
{
if (isset($_POST['action'])) {
// bail out if this user isnt logged in
if (!is_user_logged_in()) {
return;
}
if (!wp_verify_nonce($_POST['nonce'], 'process-user-info')) {
return;
}
$user_id = get_current_user_id();
if ($_POST['action'] == 'process_user_info') {
$gender = isset($_POST['gender']) ? sanitize_text_field($_POST['gender']) : false;
$age = isset($_POST['age']) ? sanitize_text_field($_POST['age']) : false;
$education = isset($_POST['education']) ? sanitize_text_field($_POST['education']) : false;
$employment = isset($_POST['employment']) ? sanitize_text_field($_POST['employment']) : false;
$data = array('gender' => $gender, 'age' => $age, 'education' => $education, 'employment' => $employment);
update_user_meta($user_id, 'user_info', $data);
update_user_meta($user_id, 'user_info_completed', 1);
do_action('user_info_updated', $user_id, $data);
wp_send_json_success();
} else {
wp_send_json_error();
}
} else {
wp_send_json_error();
}
}
示例12: fes_edd_save_meta_box_data
function fes_edd_save_meta_box_data($post_id)
{
/*
* We need to verify this came from our screen and with proper authorization,
* because the save_post action can be triggered at other times.
*/
// Check if our nonce is set.
if (!isset($_POST['fes_edd_meta_box_nonce'])) {
return;
}
// Verify that the nonce is valid.
if (!wp_verify_nonce($_POST['fes_edd_meta_box_nonce'], 'fes_edd_meta_box')) {
return;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
/* OK, it's safe for us to save the data now. */
// Make sure that it is set.
if (!isset($_POST['fes_edd_initial_message'])) {
return;
}
// Sanitize user input.
$my_data = sanitize_text_field($_POST['fes_edd_initial_message']);
// Update the meta field in the database.
update_post_meta($post_id, '_fes_edd_initial_message', $my_data);
}
示例13: submit
/**
* Check if ANY Newsletter Sign-Up form has been submitted.
*/
public function submit()
{
$opts = $this->options['form'];
$errors = array();
$email = isset($_POST['nsu_email']) ? sanitize_text_field($_POST['nsu_email']) : '';
$name = isset($_POST['nsu_name']) ? sanitize_text_field($_POST['nsu_name']) : '';
// has the honeypot been filled?
if (!empty($_POST['nsu_robocop'])) {
return false;
}
// if name is required, check it it was given
if ($this->options['mailinglist']['subscribe_with_name'] == 1 && $opts['name_required'] == 1 && empty($name)) {
$errors['name-field'] = $opts['text_empty_name'];
}
// validate email
if (empty($email)) {
$errors['email-field'] = $opts['text_empty_email'];
} elseif (!is_string($email) || !is_email($email)) {
$errors['email-field'] = $opts['text_invalid_email'];
}
// store errors as property
$this->validation_errors = $errors;
// send request to service if no errors occured
if (count($this->validation_errors) == 0) {
NSU::instance()->send_post_data($email, $name, 'form');
return true;
}
return false;
}
示例14: update
public function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = sanitize_text_field($new_instance['title']);
$instance['page_id'] = sanitize_text_field($new_instance['page_id']);
return $instance;
}
示例15: get_cart_item_data
/**
* Process this field after being posted
* @return array on success, WP_ERROR on failure
*/
public function get_cart_item_data()
{
$cart_item_data = array();
foreach ($this->addon['options'] as $key => $option) {
$option_key = empty($option['label']) ? $key : sanitize_title($option['label']);
$posted = isset($this->value[$option_key]) ? $this->value[$option_key] : '';
if ($posted === '') {
continue;
}
$label = $this->get_option_label($option);
$price = $this->get_option_price($option);
switch ($this->addon['type']) {
case "custom_price":
$price = floatval(sanitize_text_field($posted));
if ($price >= 0) {
$cart_item_data[] = array('name' => $label, 'value' => $price, 'price' => $price, 'display' => strip_tags(woocommerce_price($price)));
}
break;
case "input_multiplier":
$posted = absint($posted);
$cart_item_data[] = array('name' => $label, 'value' => $posted, 'price' => $posted * $price);
break;
default:
$cart_item_data[] = array('name' => $label, 'value' => wp_kses_post($posted), 'price' => $price);
break;
}
}
return $cart_item_data;
}