Changeset 49125 for trunk/src/wp-includes/post.php
- Timestamp:
- 10/11/2020 01:37:04 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r49108 r49125 3234 3234 3235 3235 /** 3236 * Restore a post or pagefrom the Trash.3236 * Restores a post from the Trash. 3237 3237 * 3238 3238 * @since 2.9.0 3239 * 3240 * @param int $post_id Optional. Post ID. Default is ID of the global $post. 3239 * @since 5.6.0 An untrashed post is now returned to 'draft' status by default, except for 3240 * attachments which are returned to their original 'inherit' status. 3241 * 3242 * @param int $post_id Optional. Post ID. Default is ID of the global `$post`. 3241 3243 * @return WP_Post|false|null Post data on success, false or null on failure. 3242 3244 */ … … 3248 3250 } 3249 3251 3252 $post_id = $post->ID; 3253 3250 3254 if ( 'trash' !== $post->post_status ) { 3251 3255 return false; 3252 3256 } 3253 3257 3258 $previous_status = get_post_meta( $post_id, '_wp_trash_meta_status', true ); 3259 3254 3260 /** 3255 3261 * Filters whether a post untrashing should take place. 3256 3262 * 3257 3263 * @since 4.9.0 3258 * 3259 * @param bool|null $untrash Whether to go forward with untrashing. 3260 * @param WP_Post $post Post object. 3264 * @since 5.6.0 The `$previous_status` parameter was added. 3265 * 3266 * @param bool|null $untrash Whether to go forward with untrashing. 3267 * @param WP_Post $post Post object. 3268 * @param string $previous_status The status of the post at the point where it was trashed. 3261 3269 */ 3262 $check = apply_filters( 'pre_untrash_post', null, $post );3270 $check = apply_filters( 'pre_untrash_post', null, $post, $previous_status ); 3263 3271 if ( null !== $check ) { 3264 3272 return $check; … … 3269 3277 * 3270 3278 * @since 2.9.0 3271 * 3272 * @param int $post_id Post ID. 3279 * @since 5.6.0 The `$previous_status` parameter was added. 3280 * 3281 * @param int $post_id Post ID. 3282 * @param string $previous_status The status of the post at the point where it was trashed. 3273 3283 */ 3274 do_action( 'untrash_post', $post_id ); 3275 3276 $post_status = get_post_meta( $post_id, '_wp_trash_meta_status', true ); 3284 do_action( 'untrash_post', $post_id, $previous_status ); 3285 3286 $new_status = ( 'attachment' === $post->post_type ) ? 'inherit' : 'draft'; 3287 3288 /** 3289 * Filters the status that a post gets assigned when it is restored from the trash (untrashed). 3290 * 3291 * By default posts that are restored will be assigned a status of 'draft'. Return the value of `$previous_status` 3292 * in order to assign the status that the post had before it was trashed. The `wp_untrash_post_set_previous_status()` 3293 * function is available for this. 3294 * 3295 * Prior to WordPress 5.6.0, restored posts were always assigned their original status. 3296 * 3297 * @since 5.6.0 3298 * 3299 * @param string $new_status The new status of the post being restored. 3300 * @param int $post_id The ID of the post being restored. 3301 * @param string $previous_status The status of the post at the point where it was trashed. 3302 */ 3303 $post_status = apply_filters( 'wp_untrash_post_status', $new_status, $post_id, $previous_status ); 3277 3304 3278 3305 delete_post_meta( $post_id, '_wp_trash_meta_status' ); … … 3296 3323 * 3297 3324 * @since 2.9.0 3298 * 3299 * @param int $post_id Post ID. 3325 * @since 5.6.0 The `$previous_status` parameter was added. 3326 * 3327 * @param int $post_id Post ID. 3328 * @param string $previous_status The status of the post at the point where it was trashed. 3300 3329 */ 3301 do_action( 'untrashed_post', $post_id );3330 do_action( 'untrashed_post', $post_id, $previous_status ); 3302 3331 3303 3332 return $post; … … 7514 7543 return apply_filters( 'wp_get_original_image_url', $original_image_url, $attachment_id ); 7515 7544 } 7545 7546 /** 7547 * Filter callback which sets the status of an untrashed post to its previous status. 7548 * 7549 * This can be used as a callback on the `wp_untrash_post_status` filter. 7550 * 7551 * @since 5.6.0 7552 * 7553 * @param string $new_status The new status of the post being restored. 7554 * @param int $post_id The ID of the post being restored. 7555 * @param string $previous_status The status of the post at the point where it was trashed. 7556 * @return string The new status of the post. 7557 */ 7558 function wp_untrash_post_set_previous_status( $new_status, $post_id, $previous_status ) { 7559 return $previous_status; 7560 }
Note: See TracChangeset
for help on using the changeset viewer.