| 3494 | /** |
| 3495 | * Retrieve revisions for a specific post. |
| 3496 | * |
| 3497 | * @since 3.5.0 |
| 3498 | * |
| 3499 | * The optional $fields parameter specifies what fields will be included |
| 3500 | * in the response array. |
| 3501 | * |
| 3502 | * @uses wp_get_post_revisions() |
| 3503 | * @see wp_getPost() for more on $fields |
| 3504 | * |
| 3505 | * @param array $args Method parameters. Contains: |
| 3506 | * - int $blog_id |
| 3507 | * - string $username |
| 3508 | * - string $password |
| 3509 | * - int $post_id |
| 3510 | * - array $fields |
| 3511 | * @return array contains a collection of posts. |
| 3512 | */ |
| 3513 | function wp_getRevisions( $args ) { |
| 3514 | if ( ! $this->minimum_args( $args, 4 ) ) |
| 3515 | return $this->error; |
| 3516 | $this->escape( $args ); |
| 3517 | |
| 3518 | $blog_id = (int) $args[0]; |
| 3519 | $username = $args[1]; |
| 3520 | $password = $args[2]; |
| 3521 | $post_id = (int) $args[3]; |
| 3522 | |
| 3523 | if ( isset( $args[4] ) ) |
| 3524 | $fields = $args[4]; |
| 3525 | else |
| 3526 | $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' ); |
| 3527 | |
| 3528 | if ( ! $user = $this->login( $username, $password ) ) |
| 3529 | return $this->error; |
| 3530 | |
| 3531 | do_action( 'xmlrpc_call', 'wp.getRevisions' ); |
| 3532 | |
| 3533 | $post_type = get_post_type_object( 'post' ); |
| 3534 | |
| 3535 | if ( ! current_user_can( $post_type->cap->edit_posts ) ) |
| 3536 | return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' )); |
| 3537 | |
| 3538 | $posts_list = wp_get_post_revisions( $post_id ); |
| 3539 | |
| 3540 | if ( ! $posts_list ) |
| 3541 | return array(); |
| 3542 | |
| 3543 | // holds all the posts data |
| 3544 | $struct = array(); |
| 3545 | |
| 3546 | foreach ( $posts_list as $post ) { |
| 3547 | $post_data = get_object_vars( $post ); |
| 3548 | $post_type = get_post_type_object( $post_data['post_type'] ); |
| 3549 | if ( ! current_user_can( $post_type->cap->edit_post, $post_data['ID'] ) ) |
| 3550 | continue; |
| 3551 | |
| 3552 | $struct[] = $this->_prepare_post( $post_data, $fields ); |
| 3553 | } |
| 3554 | |
| 3555 | return $struct; |
| 3556 | } |
| 3557 | |
| 3558 | /** |
| 3559 | * Restore a post revision |
| 3560 | * |
| 3561 | * @since 3.5.0 |
| 3562 | * |
| 3563 | * @uses wp_restore_post_revision() |
| 3564 | * |
| 3565 | * @param array $args Method parameters. Contains: |
| 3566 | * - int $blog_id |
| 3567 | * - string $username |
| 3568 | * - string $password |
| 3569 | * - int $post_id |
| 3570 | * @return bool false if there was an error restoring, true if success. |
| 3571 | */ |
| 3572 | function wp_restoreRevision( $args ) { |
| 3573 | if ( ! $this->minimum_args( $args, 3 ) ) |
| 3574 | return $this->error; |
| 3575 | |
| 3576 | $this->escape( $args ); |
| 3577 | |
| 3578 | $blog_id = (int) $args[0]; |
| 3579 | $username = $args[1]; |
| 3580 | $password = $args[2]; |
| 3581 | $post_id = (int) $args[3]; |
| 3582 | |
| 3583 | if ( ! $user = $this->login( $username, $password ) ) |
| 3584 | return $this->error; |
| 3585 | |
| 3586 | do_action( 'xmlrpc_call', 'wp.restoreRevision' ); |
| 3587 | |
| 3588 | $post = get_post( $post_id, ARRAY_A ); |
| 3589 | $post_type = get_post_type_object( $post['post_type'] ); |
| 3590 | |
| 3591 | if ( ! current_user_can( $post_type->cap->edit_post( $post->ID ) ) ) |
| 3592 | return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' )); |
| 3593 | |
| 3594 | $post = wp_restore_post_revision( $post_id ); |
| 3595 | |
| 3596 | return (bool)$post; |
| 3597 | } |
| 3598 | |