Changeset 22037
- Timestamp:
- 09/27/2012 04:17:15 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-xmlrpc-server.php
r22034 r22037 83 83 'wp.getPostType' => 'this:wp_getPostType', 84 84 'wp.getPostTypes' => 'this:wp_getPostTypes', 85 'wp.getRevisions' => 'this:wp_getRevisions', 86 'wp.restoreRevision' => 'this:wp_restoreRevision', 85 87 86 88 // Blogger API … … 3490 3492 } 3491 3493 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 3517 $this->escape( $args ); 3518 3519 $blog_id = (int) $args[0]; 3520 $username = $args[1]; 3521 $password = $args[2]; 3522 $post_id = (int) $args[3]; 3523 3524 if ( isset( $args[4] ) ) 3525 $fields = $args[4]; 3526 else 3527 $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' ); 3528 3529 if ( ! $user = $this->login( $username, $password ) ) 3530 return $this->error; 3531 3532 do_action( 'xmlrpc_call', 'wp.getRevisions' ); 3533 3534 if ( ! $post = get_post( $post_id ) ) 3535 return new IXR_Error( 404, __( 'Invalid post ID' ) ); 3536 3537 if ( ! current_user_can( 'edit_post', $post_id ) ) 3538 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); 3539 3540 // Check if revisions are enabled. 3541 if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) ) 3542 return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); 3543 3544 $revisions = wp_get_post_revisions( $post_id ); 3545 3546 if ( ! $revisions ) 3547 return array(); 3548 3549 $struct = array(); 3550 3551 foreach ( $revisions as $revision ) { 3552 if ( ! current_user_can( 'read_post', $revision->ID ) ) 3553 continue; 3554 3555 // Skip autosaves 3556 if ( wp_is_post_autosave( $revision ) ) 3557 continue; 3558 3559 $struct[] = $this->_prepare_post( get_object_vars( $revision ), $fields ); 3560 } 3561 3562 return $struct; 3563 } 3564 3565 /** 3566 * Restore a post revision 3567 * 3568 * @since 3.5.0 3569 * 3570 * @uses wp_restore_post_revision() 3571 * 3572 * @param array $args Method parameters. Contains: 3573 * - int $blog_id 3574 * - string $username 3575 * - string $password 3576 * - int $post_id 3577 * @return bool false if there was an error restoring, true if success. 3578 */ 3579 function wp_restoreRevision( $args ) { 3580 if ( ! $this->minimum_args( $args, 3 ) ) 3581 return $this->error; 3582 3583 $this->escape( $args ); 3584 3585 $blog_id = (int) $args[0]; 3586 $username = $args[1]; 3587 $password = $args[2]; 3588 $revision_id = (int) $args[3]; 3589 3590 if ( ! $user = $this->login( $username, $password ) ) 3591 return $this->error; 3592 3593 do_action( 'xmlrpc_call', 'wp.restoreRevision' ); 3594 3595 if ( ! $revision = wp_get_post_revision( $revision_id ) ) 3596 return new IXR_Error( 404, __( 'Invalid post ID' ) ); 3597 3598 if ( wp_is_post_autosave( $revision ) ) 3599 return new IXR_Error( 404, __( 'Invalid post ID' ) ); 3600 3601 if ( ! $post = get_post( $revision->post_parent ) ) 3602 return new IXR_Error( 404, __( 'Invalid post ID' ) ); 3603 3604 if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) 3605 return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) ); 3606 3607 // Check if revisions are disabled. 3608 if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) ) 3609 return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); 3610 3611 $post = wp_restore_post_revision( $revision_id ); 3612 3613 return (bool) $post; 3614 } 3615 3492 3616 /* Blogger API functions. 3493 3617 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
Note: See TracChangeset
for help on using the changeset viewer.