wppaste
WordPress

wp_xmlrpc_server::_insert_post( WP_User $user, array|IXR_Error $content_struct ): IXR_Error|string

Since
3.4.0
Source
wp-includes/class-wp-xmlrpc-server.php:1430
Helper method for wp_newPost() and wp_editPost(), containing shared logic.

Parameters

$userWP_User
The post author if post_author isn't set in $content_struct.
$content_structarray|IXR_Error
Post data to insert.

Return

IXR_Error|string

Hooks fired · 1

One hook fires while wp_xmlrpc_server::_insert_post() runs, in this order:

  1. apply_filters( xmlrpc_wp_insert_post_data )filterline 1701 (+271 into the body)

    Filters post data array to be inserted via XML-RPC.

Uses · 28

Show all 28

Used by · 2

Source

	protected function _insert_post( $user, $content_struct ) {		$defaults = array(			'post_status'    => 'draft',			'post_type'      => 'post',			'post_author'    => 0,			'post_password'  => '',			'post_excerpt'   => '',			'post_content'   => '',			'post_title'     => '',			'post_date'      => '',			'post_date_gmt'  => '',			'post_format'    => null,			'post_name'      => null,			'post_thumbnail' => null,			'post_parent'    => 0,			'ping_status'    => '',			'comment_status' => '',			'custom_fields'  => null,			'terms_names'    => null,			'terms'          => null,			'sticky'         => null,			'enclosure'      => null,			'ID'             => null,		); 		$post_data = wp_parse_args( array_intersect_key( $content_struct, $defaults ), $defaults ); 		$post_type = get_post_type_object( $post_data['post_type'] );		if ( ! $post_type ) {			return new IXR_Error( 403, __( 'Invalid post type.' ) );		} 		$update = ! empty( $post_data['ID'] ); 		if ( $update ) {			if ( ! get_post( $post_data['ID'] ) ) {				return new IXR_Error( 401, __( 'Invalid post ID.' ) );			}			if ( ! current_user_can( 'edit_post', $post_data['ID'] ) ) {				return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );			}			if ( get_post_type( $post_data['ID'] ) !== $post_data['post_type'] ) {				return new IXR_Error( 401, __( 'The post type may not be changed.' ) );			}		} else {			if ( ! current_user_can( $post_type->cap->create_posts ) || ! current_user_can( $post_type->cap->edit_posts ) ) {				return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) );			}		} 		switch ( $post_data['post_status'] ) {			case 'draft':			case 'pending':				break;			case 'private':				if ( ! current_user_can( $post_type->cap->publish_posts ) ) {					return new IXR_Error( 401, __( 'Sorry, you are not allowed to create private posts in this post type.' ) );				}				break;			case 'publish':			case 'future':				if ( ! current_user_can( $post_type->cap->publish_posts ) ) {					return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type.' ) );				}				break;			default:				if ( ! get_post_status_object( $post_data['post_status'] ) ) {					$post_data['post_status'] = 'draft';				}				break;		} 		if ( ! empty( $post_data['post_password'] ) && ! current_user_can( $post_type->cap->publish_posts ) ) {			return new IXR_Error( 401, __( 'Sorry, you are not allowed to create password protected posts in this post type.' ) );		} 		$post_data['post_author'] = absint( $post_data['post_author'] );		if ( ! empty( $post_data['post_author'] ) && $post_data['post_author'] !== $user->ID ) {			if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {				return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) );

History

Introduced in 3.4.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/class-wp-xmlrpc-server.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.