wp_xmlrpc_server::wp_restoreRevision()publicWP 3.5.0

Restores a post revision.

Метод класса: wp_xmlrpc_server{}

Хуки из метода

Возвращает

true|false|IXR_Error. false if there was an error restoring, true if success.

Использование

$wp_xmlrpc_server = new wp_xmlrpc_server();
$wp_xmlrpc_server->wp_restoreRevision( $args );
$args(массив) (обязательный)

Method arguments. Note: arguments must be ordered as documented.

  • 0(int)
    Blog ID (unused).

  • 1(строка)
    Username.

  • 2(строка)
    Password.

  • 3(int)
    Revision ID.

Список изменений

С версии 3.5.0 Введена.

Код wp_xmlrpc_server::wp_restoreRevision() WP 6.6.2

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

	$this->escape( $args );

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

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

	$revision = wp_get_post_revision( $revision_id );
	if ( ! $revision ) {
		return new IXR_Error( 404, __( 'Invalid post ID.' ) );
	}

	if ( wp_is_post_autosave( $revision ) ) {
		return new IXR_Error( 404, __( 'Invalid post ID.' ) );
	}

	$post = get_post( $revision->post_parent );
	if ( ! $post ) {
		return new IXR_Error( 404, __( 'Invalid post ID.' ) );
	}

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

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

	$post = wp_restore_post_revision( $revision_id );

	return (bool) $post;
}