| 3171 | /** |
| 3172 | * Retrieves a post revision |
| 3173 | * |
| 3174 | * @since 3.5.0 |
| 3175 | * |
| 3176 | * @uses wp_get_post_revision() |
| 3177 | * @param array $args Method parameters. Contains: |
| 3178 | * - int $blog_id |
| 3179 | * - string $username |
| 3180 | * - string $password |
| 3181 | * - int $post_id |
| 3182 | * - array $fields |
| 3183 | * @return array |
| 3184 | */ |
| 3185 | function wp_getRevision( $args ) { |
| 3186 | if ( ! $this->minimum_args( $args, 4 ) ) |
| 3187 | return $this->error; |
| 3188 | |
| 3189 | $this->escape( $args ); |
| 3190 | |
| 3191 | $blog_id = (int) $args[0]; |
| 3192 | $username = $args[1]; |
| 3193 | $password = $args[2]; |
| 3194 | $post_id = (int) $args[3]; |
| 3195 | |
| 3196 | if ( isset( $args[4] ) ) |
| 3197 | $fields = $args[4]; |
| 3198 | else |
| 3199 | $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post' ), 'wp.getRevision' ); |
| 3200 | |
| 3201 | if ( ! $user = $this->login( $username, $password ) ) |
| 3202 | return $this->error; |
| 3203 | |
| 3204 | do_action( 'xmlrpc_call', 'wp.getRevision' ); |
| 3205 | |
| 3206 | $post = wp_get_post_revision( $post_id, ARRAY_A ); |
| 3207 | |
| 3208 | if ( empty( $post['ID'] ) ) |
| 3209 | return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
| 3210 | |
| 3211 | return $this->_prepare_post( $post, $fields ); |
| 3212 | } |
| 3213 | |
| 3214 | /** |
| 3215 | * Retrieve revisions. |
| 3216 | * |
| 3217 | * @since 3.5.0 |
| 3218 | * |
| 3219 | * The optional $filter parameter modifies the query used to retrieve posts. |
| 3220 | * Accepted keys are 'post_type', 'post_status', 'number', 'offset', |
| 3221 | * 'orderby', and 'order'. |
| 3222 | * |
| 3223 | * The optional $fields parameter specifies what fields will be included |
| 3224 | * in the response array. |
| 3225 | * |
| 3226 | * @uses wp_get_recent_posts() |
| 3227 | * @see wp_getPost() for more on $fields |
| 3228 | * @see get_posts() for more on $filter values |
| 3229 | * |
| 3230 | * @param array $args Method parameters. Contains: |
| 3231 | * - int $blog_id |
| 3232 | * - string $username |
| 3233 | * - string $password |
| 3234 | * - int $post_id |
| 3235 | * - array $fields |
| 3236 | * @return array contains a collection of posts. |
| 3237 | */ |
| 3238 | function wp_getRevisions( $args ) { |
| 3239 | if ( ! $this->minimum_args( $args, 4 ) ) |
| 3240 | return $this->error; |
| 3241 | $this->escape( $args ); |
| 3242 | |
| 3243 | $blog_id = (int) $args[0]; |
| 3244 | $username = $args[1]; |
| 3245 | $password = $args[2]; |
| 3246 | $post_id = (int) $args[3]; |
| 3247 | |
| 3248 | if ( isset( $args[4] ) ) |
| 3249 | $fields = $args[4]; |
| 3250 | else |
| 3251 | $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post' ), 'wp.getRevisions' ); |
| 3252 | |
| 3253 | if ( ! $user = $this->login( $username, $password ) ) |
| 3254 | return $this->error; |
| 3255 | |
| 3256 | do_action( 'xmlrpc_call', 'wp.getRevisions' ); |
| 3257 | |
| 3258 | $query = array(); |
| 3259 | |
| 3260 | $posts_list = wp_get_post_revisions( $post_id ); |
| 3261 | |
| 3262 | if ( ! $posts_list ) |
| 3263 | return array(); |
| 3264 | |
| 3265 | // holds all the posts data |
| 3266 | $struct = array(); |
| 3267 | |
| 3268 | foreach ( $posts_list as $post ) { |
| 3269 | $struct[] = $this->_prepare_post( $post, $fields ); |
| 3270 | } |
| 3271 | |
| 3272 | return $struct; |
| 3273 | } |
| 3274 | |
| 3275 | /** |
| 3276 | * Retrieve revisions. |
| 3277 | * |
| 3278 | * @since 3.5.0 |
| 3279 | * |
| 3280 | * The optional $filter parameter modifies the query used to retrieve posts. |
| 3281 | * Accepted keys are 'post_type', 'post_status', 'number', 'offset', |
| 3282 | * 'orderby', and 'order'. |
| 3283 | * |
| 3284 | * The optional $fields parameter specifies what fields will be included |
| 3285 | * in the response array. |
| 3286 | * |
| 3287 | * @uses wp_get_recent_posts() |
| 3288 | * @see wp_getPost() for more on $fields |
| 3289 | * @see get_posts() for more on $filter values |
| 3290 | * |
| 3291 | * @param array $args Method parameters. Contains: |
| 3292 | * - int $blog_id |
| 3293 | * - string $username |
| 3294 | * - string $password |
| 3295 | * - int $post_id |
| 3296 | * - array $fields |
| 3297 | * @return array contains a collection of posts. |
| 3298 | */ |
| 3299 | function wp_newRevision( $args ) { |
| 3300 | add_action( 'pre_post_update', 'wp_save_post_revision' ); |
| 3301 | return $this->wp_editPost( $args ); |
| 3302 | } |
| 3303 | |
| 3304 | /** |
| 3305 | * Retrieve revisions. |
| 3306 | * |
| 3307 | * @since 3.5.0 |
| 3308 | * |
| 3309 | * The optional $filter parameter modifies the query used to retrieve posts. |
| 3310 | * Accepted keys are 'post_type', 'post_status', 'number', 'offset', |
| 3311 | * 'orderby', and 'order'. |
| 3312 | * |
| 3313 | * The optional $fields parameter specifies what fields will be included |
| 3314 | * in the response array. |
| 3315 | * |
| 3316 | * @uses wp_get_recent_posts() |
| 3317 | * @see wp_getPost() for more on $fields |
| 3318 | * @see get_posts() for more on $filter values |
| 3319 | * |
| 3320 | * @param array $args Method parameters. Contains: |
| 3321 | * - int $blog_id |
| 3322 | * - string $username |
| 3323 | * - string $password |
| 3324 | * - int $post_id |
| 3325 | * - array $fields |
| 3326 | * @return array contains a collection of posts. |
| 3327 | */ |
| 3328 | function wp_restoreRevision( $args ) { |
| 3329 | if ( ! $this->minimum_args( $args, 3 ) ) |
| 3330 | return $this->error; |
| 3331 | |
| 3332 | $this->escape( $args ); |
| 3333 | |
| 3334 | $blog_id = (int) $args[0]; |
| 3335 | $username = $args[1]; |
| 3336 | $password = $args[2]; |
| 3337 | $post_id = (int) $args[3]; |
| 3338 | |
| 3339 | if ( isset( $args[4] ) ) |
| 3340 | $fields = $args[4]; |
| 3341 | else |
| 3342 | $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post' ), 'wp.restoreRevisions' ); |
| 3343 | |
| 3344 | if ( ! $user = $this->login( $username, $password ) ) |
| 3345 | return $this->error; |
| 3346 | |
| 3347 | do_action( 'xmlrpc_call', 'wp.restoreRevision' ); |
| 3348 | |
| 3349 | $post = wp_get_post_revision( $post_id, ARRAY_A ); |
| 3350 | |
| 3351 | return true; |
| 3352 | } |
| 3353 | |