wp_xmlrpc_server::wp_getPost( array $args ): array|IXR_Error

Retrieves a post.

Description

See also

Parameters

$argsarrayrequired
Method arguments. Note: arguments must be ordered as documented.
  • 0 int
    Blog ID (unused).
  • 1 string
    Username.
  • 2 string
    Password.
  • 3 int
    Post ID.
  • 4 array
    Optional. The subset of post type fields to return.

Return

array|IXR_Error Array contains (based on $fields parameter):
  • 'post_id'
  • 'post_title'
  • 'post_date'
  • 'post_date_gmt'
  • 'post_modified'
  • 'post_modified_gmt'
  • 'post_status'
  • 'post_type'
  • 'post_name'
  • 'post_author'
  • 'post_password'
  • 'post_excerpt'
  • 'post_content'
  • 'link'
  • 'comment_status'
  • 'ping_status'
  • 'sticky'
  • 'custom_fields'
  • 'terms'
  • 'categories'
  • 'tags'
  • 'enclosure'

Source

public function wp_getPost( $args ) {
	if ( ! $this->minimum_args( $args, 4 ) ) {
		return $this->error;
	}

	$this->escape( $args );

	$username = $args[1];
	$password = $args[2];
	$post_id  = (int) $args[3];

	if ( isset( $args[4] ) ) {
		$fields = $args[4];
	} else {
		/**
		 * Filters the default post query fields used by the given XML-RPC method.
		 *
		 * @since 3.4.0
		 *
		 * @param array  $fields An array of post fields to retrieve. By default,
		 *                       contains 'post', 'terms', and 'custom_fields'.
		 * @param string $method Method name.
		 */
		$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPost' );
	}

	$user = $this->login( $username, $password );
	if ( ! $user ) {
		return $this->error;
	}

	/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
	do_action( 'xmlrpc_call', 'wp.getPost', $args, $this );

	$post = get_post( $post_id, ARRAY_A );

	if ( empty( $post['ID'] ) ) {
		return new IXR_Error( 404, __( 'Invalid post ID.' ) );
	}

	if ( ! current_user_can( 'edit_post', $post_id ) ) {
		return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
	}

	return $this->_prepare_post( $post, $fields );
}

Hooks

do_action( ‘xmlrpc_call’, string $name, array|string $args, wp_xmlrpc_server $server )

Fires after the XML-RPC user has been authenticated but before the rest of the method logic begins.

apply_filters( ‘xmlrpc_default_post_fields’, array $fields, string $method )

Filters the default post query fields used by the given XML-RPC method.

Changelog

VersionDescription
3.4.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.