400 ) ); } $blocks = NewBlocks::prepare( $request['blocks'] ); if ( is_wp_error( $blocks ) ) { return $blocks; } $seo = ! empty( $request['seo'] ) ? Fields::sanitize( (array) $request['seo'] ) : array(); $store = Stores::current(); if ( $seo && null === $store ) { return new \WP_Error( 'searchsmith_seo_unsupported', __( 'The active SEO plugin is not supported yet.', 'searchsmith' ), array( 'status' => 422, 'seo_plugin' => Environment::seo_plugin(), ) ); } $post = array( 'post_type' => (string) $request['post_type'], 'post_status' => 'draft', 'post_title' => $title, // Separated by a blank line, as the editor writes them. 'post_content' => implode( "\n\n", array_map( 'serialize_block', $blocks ) ), 'post_author' => get_current_user_id(), ); if ( ! empty( $request['slug'] ) ) { $post['post_name'] = sanitize_title( (string) $request['slug'] ); } // wp_insert_post() unslashes its input, so slash it first. $post_id = wp_insert_post( wp_slash( $post ), true ); if ( is_wp_error( $post_id ) ) { return $post_id; } if ( $seo ) { $store->write( $post_id, $seo ); } $created = get_post( $post_id ); $result = array( 'id' => $created->ID, 'post_type' => $created->post_type, 'status' => $created->post_status, 'slug' => $created->post_name, 'modified_gmt' => ContentEditor::modified( $created ), 'op_key' => (string) $request['op_key'], 'seo' => $store ? $store->read( $created->ID ) : null, ); OpKeys::record( $request['op_key'], 'create', $created->ID, $created->ID, $result ); return $result; } }