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

Retrieves revisions for a specific 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. Fields to fetch.

Return

array|IXR_Error Array containing a collection of posts.

Source

 *
 * @param array $args {
 *     Method arguments. Note: arguments must be ordered as documented.
 *
 *     @type int    $0 Blog ID (unused).
 *     @type string $1 Username.
 *     @type string $2 Password.
 *     @type int    $3 Post ID.
 *     @type array  $4 Optional. Fields to fetch.
 * }
 * @return array|IXR_Error Array containing a collection of posts.
 */
public function wp_getRevisions( $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 revision query fields used by the given XML-RPC method.
		 *
		 * @since 3.5.0
		 *
		 * @param array  $field  An array of revision fields to retrieve. By default,
		 *                       contains 'post_date' and 'post_date_gmt'.
		 * @param string $method The method name.
		 */
		$fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' );
	}

	$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.getRevisions', $args, $this );

	$post = get_post( $post_id );
	if ( ! $post ) {
		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 posts.' ) );
	}

	// Check if revisions are enabled.
	if ( ! wp_revisions_enabled( $post ) ) {
		return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
	}

	$revisions = wp_get_post_revisions( $post_id );

	if ( ! $revisions ) {
		return array();
	}

	$struct = array();

	foreach ( $revisions as $revision ) {
		if ( ! current_user_can( 'read_post', $revision->ID ) ) {
			continue;

Changelog

VersionDescription
3.5.0Introduced.

User Contributed Notes

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