| 3183 | /** |
| 3184 | * Retrieve revisions for a specific post. |
| 3185 | * |
| 3186 | * @since 3.5.0 |
| 3187 | * |
| 3188 | * The optional $fields parameter specifies what fields will be included |
| 3189 | * in the response array. |
| 3190 | * |
| 3191 | * @uses wp_get_post_revisions() |
| 3192 | * @see wp_getPost() for more on $fields |
| 3193 | * |
| 3194 | * @param array $args Method parameters. Contains: |
| 3195 | * - int $blog_id |
| 3196 | * - string $username |
| 3197 | * - string $password |
| 3198 | * - int $post_id |
| 3199 | * - array $fields |
| 3200 | * @return array contains a collection of posts. |
| 3201 | */ |
| 3202 | function wp_getRevisions( $args ) { |
| 3203 | if ( ! $this->minimum_args( $args, 4 ) ) |
| 3204 | return $this->error; |
| 3205 | $this->escape( $args ); |
| 3206 | |
| 3207 | $blog_id = (int) $args[0]; |
| 3208 | $username = $args[1]; |
| 3209 | $password = $args[2]; |
| 3210 | $post_id = (int) $args[3]; |
| 3211 | |
| 3212 | if ( isset( $args[4] ) ) |
| 3213 | $fields = $args[4]; |
| 3214 | else |
| 3215 | $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post' ), 'wp.getRevisions' ); |
| 3216 | |
| 3217 | if ( ! $user = $this->login( $username, $password ) ) |
| 3218 | return $this->error; |
| 3219 | |
| 3220 | do_action( 'xmlrpc_call', 'wp.getRevisions' ); |
| 3221 | |
| 3222 | $post_type = get_post_type_object( 'post' ); |
| 3223 | |
| 3224 | if ( ! current_user_can( $post_type->cap->edit_posts ) ) |
| 3225 | return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' )); |
| 3226 | |
| 3227 | $posts_list = wp_get_post_revisions( $post_id ); |
| 3228 | |
| 3229 | if ( ! $posts_list ) |
| 3230 | return array(); |
| 3231 | |
| 3232 | // holds all the posts data |
| 3233 | $struct = array(); |
| 3234 | |
| 3235 | foreach ( $posts_list as $post ) { |
| 3236 | $post_data = get_object_vars( $post ); |
| 3237 | $post_type = get_post_type_object( $post_data['post_type'] ); |
| 3238 | if ( ! current_user_can( $post_type->cap->edit_post, $post_data['ID'] ) ) |
| 3239 | continue; |
| 3240 | |
| 3241 | $struct[] = $this->_prepare_post( $post_data, $fields ); |
| 3242 | } |
| 3243 | |
| 3244 | return $struct; |
| 3245 | } |
| 3246 | |
| 3247 | /** |
| 3248 | * Restore a post revision |
| 3249 | * |
| 3250 | * @since 3.5.0 |
| 3251 | * |
| 3252 | * @uses wp_restore_post_revision() |
| 3253 | * |
| 3254 | * @param array $args Method parameters. Contains: |
| 3255 | * - int $blog_id |
| 3256 | * - string $username |
| 3257 | * - string $password |
| 3258 | * - int $post_id |
| 3259 | * @return bool false if there was an error restoring, true if success. |
| 3260 | */ |
| 3261 | function wp_restoreRevision( $args ) { |
| 3262 | if ( ! $this->minimum_args( $args, 3 ) ) |
| 3263 | return $this->error; |
| 3264 | |
| 3265 | $this->escape( $args ); |
| 3266 | |
| 3267 | $blog_id = (int) $args[0]; |
| 3268 | $username = $args[1]; |
| 3269 | $password = $args[2]; |
| 3270 | $post_id = (int) $args[3]; |
| 3271 | |
| 3272 | if ( ! $user = $this->login( $username, $password ) ) |
| 3273 | return $this->error; |
| 3274 | |
| 3275 | do_action( 'xmlrpc_call', 'wp.restoreRevision' ); |
| 3276 | |
| 3277 | $post = get_post( $post_id, ARRAY_A ); |
| 3278 | $post_type = get_post_type_object( $post['post_type'] ); |
| 3279 | |
| 3280 | if ( ! current_user_can( $post_type->cap->edit_posts ) ) |
| 3281 | return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' )); |
| 3282 | |
| 3283 | $post = wp_restore_post_revision( $post_id ); |
| 3284 | |
| 3285 | return (bool)$post; |
| 3286 | } |
| 3287 | |