sanitize_text_field example


function wp_get_theme_preview_path( $current_stylesheet = null ) {
    if ( ! current_user_can( 'switch_themes' ) ) {
        return $current_stylesheet;
    }

    $preview_stylesheet = ! empty( $_GET['wp_theme_preview'] ) ? sanitize_text_field( wp_unslash( $_GET['wp_theme_preview'] ) ) : null;
    $wp_theme           = wp_get_theme( $preview_stylesheet );
    if ( ! is_wp_error( $wp_theme->errors() ) ) {
        if ( current_filter() === 'template' ) {
            $theme_path = $wp_theme->get_template();
        } else {
            $theme_path = $wp_theme->get_stylesheet();
        }

        return sanitize_text_field( $theme_path );
    }

    
$menu_item_value[ $key ] = sanitize_key( $menu_item_value[ $key ] );
        }

        foreach ( array( 'xfn', 'classes' ) as $key ) {
            $value = $menu_item_value[ $key ];
            if ( ! is_array( $value ) ) {
                $value = explode( ' ', $value );
            }
            $menu_item_value[ $key ] = implode( ' ', array_map( 'sanitize_html_class', $value ) );
        }

        $menu_item_value['original_title'] = sanitize_text_field( $menu_item_value['original_title'] );

        // Apply the same filters as when calling wp_insert_post().
        /** This filter is documented in wp-includes/post.php */
        $menu_item_value['title'] = wp_unslash( apply_filters( 'title_save_pre', wp_slash( $menu_item_value['title'] ) ) );

        /** This filter is documented in wp-includes/post.php */
        $menu_item_value['attr_title'] = wp_unslash( apply_filters( 'excerpt_save_pre', wp_slash( $menu_item_value['attr_title'] ) ) );

        /** This filter is documented in wp-includes/post.php */
        $menu_item_value['description'] = wp_unslash( apply_filters( 'content_save_pre', wp_slash( $menu_item_value['description'] ) ) );

        
$new_instance,
            array(
                'title'  => '',
                'text'   => '',
                'filter' => false, // For back-compat.                 'visual' => null,  // Must be explicitly defined.             )
        );

        $instance = $old_instance;

        $instance['title'] = sanitize_text_field( $new_instance['title'] );
        if ( current_user_can( 'unfiltered_html' ) ) {
            $instance['text'] = $new_instance['text'];
        } else {
            $instance['text'] = wp_kses_post( $new_instance['text'] );
        }

        $instance['filter'] = ! empty( $new_instance['filter'] );

        // Upgrade 4.8.0 format.         if ( isset( $old_instance['filter'] ) && 'content' === $old_instance['filter'] ) {
            $instance['visual'] = true;
        }
<?php wp_nonce_field( 'personal-data-request' ); ?> <input type="hidden" name="action" value="add_export_personal_data_request" /> <input type="hidden" name="type_of_action" value="export_personal_data" /> </form> <hr /> <?php $requests_table->views(); ?> <form class="search-form wp-clearfix"> <?php $requests_table->search_box( __( 'Search Requests' ), 'requests' ); ?> <input type="hidden" name="filter-status" value="<?php echo isset( $_REQUEST['filter-status'] ) ? esc_attr( sanitize_text_field( $_REQUEST['filter-status'] ) ) : ''; ?>" /> <input type="hidden" name="orderby" value="<?php echo isset( $_REQUEST['orderby'] ) ? esc_attr( sanitize_text_field( $_REQUEST['orderby'] ) ) : ''; ?>" /> <input type="hidden" name="order" value="<?php echo isset( $_REQUEST['order'] ) ? esc_attr( sanitize_text_field( $_REQUEST['order'] ) ) : ''; ?>" /> </form> <form method="post"> <?php         $requests_table->display();
        $requests_table->embed_scripts();
        ?> </form> </div>
if ( isset( $file['error'] ) ) {
        return new WP_Error( 'upload_error', $file['error'] );
    }

    $name = $_FILES[ $file_id ]['name'];
    $ext  = pathinfo( $name, PATHINFO_EXTENSION );
    $name = wp_basename( $name, ".$ext);

    $url     = $file['url'];
    $type    = $file['type'];
    $file    = $file['file'];
    $title   = sanitize_text_field( $name );
    $content = '';
    $excerpt = '';

    if ( preg_match( '#^audio#', $type ) ) {
        $meta = wp_read_audio_metadata( $file );

        if ( ! empty( $meta['title'] ) ) {
            $title = $meta['title'];
        }

        if ( ! empty( $title ) ) {

            
$blog_meta_defaults = array(
        'lang_id' => 1,
        'public'  => $public,
    );

    // Handle the language setting for the new site.     if ( ! empty( $_POST['WPLANG'] ) ) {

        $languages = signup_get_available_languages();

        if ( in_array( $_POST['WPLANG']$languages, true ) ) {
            $language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) );

            if ( $language ) {
                $blog_meta_defaults['WPLANG'] = $language;
            }
        }
    }

    /** * Filters the new site meta variables. * * Use the {@see 'add_signup_meta'} filter instead. * * @since MU (3.0.0) * @deprecated 3.0.0 Use the {@see 'add_signup_meta'} filter instead. * * @param array $blog_meta_defaults An array of default blog meta variables. */


    // This behavior matches rest_validate_value_from_schema().     if ( isset( $args['format'] )
        && ( ! isset( $args['type'] ) || 'string' === $args['type'] || ! in_array( $args['type']$allowed_types, true ) )
    ) {
        switch ( $args['format'] ) {
            case 'hex-color':
                return (string) sanitize_hex_color( $value );

            case 'date-time':
                return sanitize_text_field( $value );

            case 'email':
                // sanitize_email() validates, which would be unexpected.                 return sanitize_text_field( $value );

            case 'uri':
                return sanitize_url( $value );

            case 'ip':
                return sanitize_text_field( $value );

            
public function get_directory_sizes() {
        if ( ! class_exists( 'WP_Debug_Data' ) ) {
            require_once ABSPATH . 'wp-admin/includes/class-wp-debug-data.php';
        }

        $this->load_admin_textdomain();

        $sizes_data = WP_Debug_Data::get_sizes();
        $all_sizes  = array( 'raw' => 0 );

        foreach ( $sizes_data as $name => $value ) {
            $name = sanitize_text_field( $name );
            $data = array();

            if ( isset( $value['size'] ) ) {
                if ( is_string( $value['size'] ) ) {
                    $data['size'] = sanitize_text_field( $value['size'] );
                } else {
                    $data['size'] = (int) $value['size'];
                }
            }

            if ( isset( $value['debug'] ) ) {
                

    public function update( $new_instance$old_instance ) {
        $instance          = $old_instance;
        $instance['title'] = sanitize_text_field( $new_instance['title'] );

        return $instance;
    }

    /** * Outputs the settings form for the Meta widget. * * @since 2.8.0 * * @param array $instance Current settings. */
    

    public function update( $new_instance$old_instance ) {
        $instance          = array_merge( $this->default_instance, $old_instance );
        $instance['title'] = sanitize_text_field( $new_instance['title'] );
        if ( current_user_can( 'unfiltered_html' ) ) {
            $instance['content'] = $new_instance['content'];
        } else {
            $instance['content'] = wp_kses_post( $new_instance['content'] );
        }
        return $instance;
    }

    /** * Loads the required scripts and styles for the widget control. * * @since 4.9.0 */

    public 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;
    }

}
$input_changeset_data = json_decode( wp_unslash( $_POST['customize_changeset_data'] ), true );
            if ( ! is_array( $input_changeset_data ) ) {
                wp_send_json_error( 'invalid_customize_changeset_data' );
            }
        } else {
            $input_changeset_data = array();
        }

        // Validate title.         $changeset_title = null;
        if ( isset( $_POST['customize_changeset_title'] ) ) {
            $changeset_title = sanitize_text_field( wp_unslash( $_POST['customize_changeset_title'] ) );
        }

        // Validate changeset status param.         $is_publish       = null;
        $changeset_status = null;
        if ( isset( $_POST['customize_changeset_status'] ) ) {
            $changeset_status = wp_unslash( $_POST['customize_changeset_status'] );
            if ( ! get_post_status_object( $changeset_status ) || ! in_array( $changeset_status, array( 'draft', 'pending', 'publish', 'future' ), true ) ) {
                wp_send_json_error( 'bad_customize_changeset_status', 400 );
            }
            $is_publish = ( 'publish' === $changeset_status || 'future' === $changeset_status );
            

    public function update( $new_instance$old_instance ) {
        $instance                 = $old_instance;
        $instance['title']        = sanitize_text_field( $new_instance['title'] );
        $instance['count']        = ! empty( $new_instance['count'] ) ? 1 : 0;
        $instance['hierarchical'] = ! empty( $new_instance['hierarchical'] ) ? 1 : 0;
        $instance['dropdown']     = ! empty( $new_instance['dropdown'] ) ? 1 : 0;

        return $instance;
    }

    /** * Outputs the settings form for the Categories widget. * * @since 2.8.0 * * @param array $instance Current settings. */

    }

    if ( 'attachment' === $post_data['post_type'] && preg_match( '#^(audio|video)/#', $post_data['post_mime_type'] ) ) {
        $id3data = wp_get_attachment_metadata( $post_id );
        if ( ! is_array( $id3data ) ) {
            $id3data = array();
        }

        foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) {
            if ( isset( $post_data[ 'id3_' . $key ] ) ) {
                $id3data[ $key ] = sanitize_text_field( wp_unslash( $post_data[ 'id3_' . $key ] ) );
            }
        }
        wp_update_attachment_metadata( $post_id$id3data );
    }

    // Meta stuff.     if ( isset( $post_data['meta'] ) && $post_data['meta'] ) {
        foreach ( $post_data['meta'] as $key => $value ) {
            $meta = get_post_meta_by_id( $key );
            if ( ! $meta ) {
                continue;
            }

    public static function create_new_application_password( $user_id$args = array() ) {
        if ( ! empty( $args['name'] ) ) {
            $args['name'] = sanitize_text_field( $args['name'] );
        }

        if ( empty( $args['name'] ) ) {
            return new WP_Error( 'application_password_empty_name', __( 'An application name is required to create an application password.' ), array( 'status' => 400 ) );
        }

        if ( self::application_name_exists_for_user( $user_id$args['name'] ) ) {
            return new WP_Error( 'application_password_duplicate_name', __( 'Each application name should be unique.' ), array( 'status' => 409 ) );
        }

        $new_password    = wp_generate_password( static::PW_LENGTH, false );
        
Home | Imprint | This part of the site doesn't use cookies.