: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( empty( $post_data ) ) {
if ( isset( $post_data['post_type'] ) ) {
$ptype = get_post_type_object( $post_data['post_type'] );
$ptype = get_post_type_object( 'post' );
if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
if ( 'page' === $ptype->name ) {
wp_die( __( 'Sorry, you are not allowed to edit pages.' ) );
wp_die( __( 'Sorry, you are not allowed to edit posts.' ) );
if ( '-1' === $post_data['_status'] ) {
$post_data['post_status'] = null;
unset( $post_data['post_status'] );
$post_data['post_status'] = $post_data['_status'];
unset( $post_data['_status'] );
if ( ! empty( $post_data['post_status'] ) ) {
$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
if ( 'inherit' === $post_data['post_status'] ) {
unset( $post_data['post_status'] );
$post_ids = array_map( 'intval', (array) $post_data['post'] );
foreach ( $reset as $field ) {
if ( isset( $post_data[ $field ] ) && ( '' === $post_data[ $field ] || '-1' === $post_data[ $field ] ) ) {
unset( $post_data[ $field ] );
if ( isset( $post_data['post_category'] ) ) {
if ( is_array( $post_data['post_category'] ) && ! empty( $post_data['post_category'] ) ) {
$new_cats = array_map( 'absint', $post_data['post_category'] );
unset( $post_data['post_category'] );
if ( isset( $post_data['tax_input'] ) ) {
foreach ( $post_data['tax_input'] as $tax_name => $terms ) {
if ( is_taxonomy_hierarchical( $tax_name ) ) {
$tax_input[ $tax_name ] = array_map( 'absint', $terms );
$comma = _x( ',', 'tag delimiter' );
$terms = str_replace( $comma, ',', $terms );
$tax_input[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
if ( isset( $post_data['post_parent'] ) && (int) $post_data['post_parent'] ) {
$parent = (int) $post_data['post_parent'];
$pages = $wpdb->get_results( "SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'" );
for ( $i = 0; $i < 50 && $parent > 0; $i++ ) {
foreach ( $pages as $page ) {
if ( (int) $page->ID === $parent ) {
$parent = (int) $page->post_parent;
$shared_post_data = $post_data;
foreach ( $post_ids as $post_id ) {
// Start with fresh post data with each iteration.
$post_data = $shared_post_data;
$post_type_object = get_post_type_object( get_post_type( $post_id ) );
if ( ! isset( $post_type_object )
|| ( isset( $children ) && in_array( $post_id, $children, true ) )
|| ! current_user_can( 'edit_post', $post_id )
if ( wp_check_post_lock( $post_id ) ) {
$post = get_post( $post_id );
$tax_names = get_object_taxonomies( $post );
foreach ( $tax_names as $tax_name ) {
$taxonomy_obj = get_taxonomy( $tax_name );
if ( ! $taxonomy_obj->show_in_quick_edit ) {
if ( isset( $tax_input[ $tax_name ] ) && current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
$new_terms = $tax_input[ $tax_name ];
if ( $taxonomy_obj->hierarchical ) {
$current_terms = (array) wp_get_object_terms( $post_id, $tax_name, array( 'fields' => 'ids' ) );
$current_terms = (array) wp_get_object_terms( $post_id, $tax_name, array( 'fields' => 'names' ) );
$post_data['tax_input'][ $tax_name ] = array_merge( $current_terms, $new_terms );
if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) {
$cats = (array) wp_get_post_categories( $post_id );
isset( $post_data['indeterminate_post_category'] )
&& is_array( $post_data['indeterminate_post_category'] )
$indeterminate_post_category = $post_data['indeterminate_post_category'];
$indeterminate_post_category = array();
$indeterminate_cats = array_intersect( $cats, $indeterminate_post_category );
$determinate_cats = array_diff( $new_cats, $indeterminate_post_category );
$post_data['post_category'] = array_unique( array_merge( $indeterminate_cats, $determinate_cats ) );
unset( $post_data['tax_input']['category'] );
$post_data['post_ID'] = $post_id;
$post_data['post_type'] = $post->post_type;
$post_data['post_mime_type'] = $post->post_mime_type;
foreach ( array( 'comment_status', 'ping_status', 'post_author' ) as $field ) {
if ( ! isset( $post_data[ $field ] ) ) {
$post_data[ $field ] = $post->$field;
$post_data = _wp_translate_postdata( true, $post_data );
if ( is_wp_error( $post_data ) ) {
$post_data = _wp_get_allowed_postdata( $post_data );
if ( isset( $shared_post_data['post_format'] ) ) {
set_post_format( $post_id, $shared_post_data['post_format'] );
// Prevent wp_insert_post() from overwriting post format with the old data.
unset( $post_data['tax_input']['post_format'] );
// Reset post date of scheduled post to be published.
in_array( $post->post_status, array( 'future', 'draft' ), true ) &&
'publish' === $post_data['post_status']
$post_data['post_date'] = current_time( 'mysql' );
$post_data['post_date_gmt'] = '';
$post_id = wp_update_post( $post_data );
update_post_meta( $post_id, '_edit_last', get_current_user_id() );
if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
if ( 'sticky' === $post_data['sticky'] ) {
unstick_post( $post_id );
* Fires after processing the post data for bulk edit.
* @param int[] $updated An array of updated post IDs.
* @param array $shared_post_data Associative array containing the post data.
do_action( 'bulk_edit_posts', $updated, $shared_post_data );
* Returns default post information to use when populating the "Write Post" form.
* @param string $post_type Optional. A post type string. Default 'post'.
* @param bool $create_in_db Optional. Whether to insert the post into database. Default false.
* @return WP_Post Post object containing all the default post data as attributes
function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
if ( ! empty( $_REQUEST['post_title'] ) ) {
$post_title = esc_html( wp_unslash( $_REQUEST['post_title'] ) );
if ( ! empty( $_REQUEST['content'] ) ) {
$post_content = esc_html( wp_unslash( $_REQUEST['content'] ) );
if ( ! empty( $_REQUEST['excerpt'] ) ) {
$post_excerpt = esc_html( wp_unslash( $_REQUEST['excerpt'] ) );
$post_id = wp_insert_post(
'post_title' => __( 'Auto Draft' ),
'post_type' => $post_type,
'post_status' => 'auto-draft',
$post = get_post( $post_id );
if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) {
set_post_format( $post, get_option( 'default_post_format' ) );
wp_after_insert_post( $post, false, null );
// Schedule auto-draft cleanup.
if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) {
wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
$post->post_date_gmt = '';
$post->post_password = '';
$post->post_type = $post_type;
$post->post_status = 'draft';
$post->comment_status = get_default_comment_status( $post_type );
$post->ping_status = get_default_comment_status( $post_type, 'pingback' );
$post->post_pingback = get_option( 'default_pingback_flag' );
$post->post_category = get_option( 'default_category' );
$post->page_template = 'default';
$post = new WP_Post( $post );
* Filters the default post content initially used in the "Write Post" form.
* @param string $post_content Default post content.
* @param WP_Post $post Post object.
$post->post_content = (string) apply_filters( 'default_content', $post_content, $post );
* Filters the default post title initially used in the "Write Post" form.
* @param string $post_title Default post title.
* @param WP_Post $post Post object.
$post->post_title = (string) apply_filters( 'default_title', $post_title, $post );
* Filters the default post excerpt initially used in the "Write Post" form.
* @param string $post_excerpt Default post excerpt.
* @param WP_Post $post Post object.
$post->post_excerpt = (string) apply_filters( 'default_excerpt', $post_excerpt, $post );
* Determines if a post exists based on title, content, date and type.
* @since 5.2.0 Added the `$type` parameter.
* @since 5.8.0 Added the `$status` parameter.
* @global wpdb $wpdb WordPress database abstraction object.
* @param string $title Post title.
* @param string $content Optional. Post content.
* @param string $date Optional. Post date.
* @param string $type Optional. Post type.
* @param string $status Optional. Post status.
* @return int Post ID if post exists, 0 otherwise.
function post_exists( $title, $content = '', $date = '', $type = '', $status = '' ) {
$post_title = wp_unslash( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
$post_content = wp_unslash( sanitize_post_field( 'post_content', $content, 0, 'db' ) );
$post_date = wp_unslash( sanitize_post_field( 'post_date', $date, 0, 'db' ) );
$post_type = wp_unslash( sanitize_post_field( 'post_type', $type, 0, 'db' ) );
$post_status = wp_unslash( sanitize_post_field( 'post_status', $status, 0, 'db' ) );
$query = "SELECT ID FROM $wpdb->posts WHERE 1=1";
if ( ! empty( $date ) ) {
$query .= ' AND post_date = %s';
if ( ! empty( $title ) ) {
$query .= ' AND post_title = %s';
if ( ! empty( $content ) ) {
$query .= ' AND post_content = %s';
if ( ! empty( $type ) ) {
$query .= ' AND post_type = %s';
if ( ! empty( $status ) ) {
$query .= ' AND post_status = %s';
if ( ! empty( $args ) ) {
return (int) $wpdb->get_var( $wpdb->prepare( $query, $args ) );
* Creates a new post from the "Write Post" form using `$_POST` information.
* @global WP_User $current_user
* @return int|WP_Error Post ID on success, WP_Error on failure.
function wp_write_post() {
if ( isset( $_POST['post_type'] ) ) {
$ptype = get_post_type_object( $_POST['post_type'] );
$ptype = get_post_type_object( 'post' );
if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
if ( 'page' === $ptype->name ) {
return new WP_Error( 'edit_pages', __( 'Sorry, you are not allowed to create pages on this site.' ) );
return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to create posts or drafts on this site.' ) );
$_POST['post_mime_type'] = '';
// Clear out any data in internal vars.
unset( $_POST['filter'] );
// Edit, don't write, if we have a post ID.
if ( isset( $_POST['post_ID'] ) ) {
if ( isset( $_POST['visibility'] ) ) {
switch ( $_POST['visibility'] ) {
$_POST['post_password'] = '';
unset( $_POST['sticky'] );
$_POST['post_status'] = 'private';
$_POST['post_password'] = '';
unset( $_POST['sticky'] );
$translated = _wp_translate_postdata( false );
if ( is_wp_error( $translated ) ) {
$translated = _wp_get_allowed_postdata( $translated );
$post_id = wp_insert_post( $translated );
if ( is_wp_error( $post_id ) ) {
if ( empty( $post_id ) ) {
add_post_meta( $post_id, '_edit_last', $GLOBALS['current_user']->ID );
// Now that we have an ID we can fix any attachment anchor hrefs.
_fix_attachment_links( $post_id );
wp_set_post_lock( $post_id );
* Calls wp_write_post() and handles the errors.
* @return int|void Post ID on success, void on failure.
$result = wp_write_post();
if ( is_wp_error( $result ) ) {
wp_die( $result->get_error_message() );
* Adds post meta data defined in the `$_POST` superglobal for a post with given ID.
function add_meta( $post_id ) {
$post_id = (int) $post_id;