_wp_get_allowed_postdata example

'filename' => esc_html( $_FILES['async-upload']['name'] ),
                    ),
                )
            );

            wp_die();
        }
    } else {
        $post_id = null;
    }

    $post_data = ! empty( $_REQUEST['post_data'] ) ? _wp_get_allowed_postdata( _wp_translate_postdata( false, (array) $_REQUEST['post_data'] ) ) : array();

    if ( is_wp_error( $post_data ) ) {
        wp_die( $post_data->get_error_message() );
    }

    // If the context is custom header or background, make sure the uploaded file is an image.     if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ), true ) ) {
        $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name']$_FILES['async-upload']['name'] );

        if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
            echo wp_json_encode(
                
$post_data['post_status']   = 'private';
                $post_data['post_password'] = '';
                unset( $post_data['sticky'] );
                break;
        }
    }

    $post_data = _wp_translate_postdata( true, $post_data );
    if ( is_wp_error( $post_data ) ) {
        wp_die( $post_data->get_error_message() );
    }
    $translated = _wp_get_allowed_postdata( $post_data );

    // Post formats.     if ( isset( $post_data['post_format'] ) ) {
        set_post_format( $post_id$post_data['post_format'] );
    }

    $format_meta_urls = array( 'url', 'link_url', 'quote_source_url' );
    foreach ( $format_meta_urls as $format_meta_url ) {
        $keyed = '_format_' . $format_meta_url;
        if ( isset( $post_data[ $keyed ] ) ) {
            update_post_meta( $post_id$keyedwp_slash( sanitize_url( wp_unslash( $post_data[ $keyed ] ) ) ) );
        }
Home | Imprint | This part of the site doesn't use cookies.