equal
deleted
inserted
replaced
445 * Deletes the row from the posts table corresponding to the specified revision. |
445 * Deletes the row from the posts table corresponding to the specified revision. |
446 * |
446 * |
447 * @since 2.6.0 |
447 * @since 2.6.0 |
448 * |
448 * |
449 * @param int|WP_Post $revision_id Revision ID or revision object. |
449 * @param int|WP_Post $revision_id Revision ID or revision object. |
450 * @return array|false|WP_Post|WP_Error|null Null or WP_Error if error, deleted post if success. |
450 * @return WP_Post|false|null Null or false if error, deleted post object if success. |
451 */ |
451 */ |
452 function wp_delete_post_revision( $revision_id ) { |
452 function wp_delete_post_revision( $revision_id ) { |
453 $revision = wp_get_post_revision( $revision_id ); |
453 $revision = wp_get_post_revision( $revision_id ); |
454 if ( ! $revision ) { |
454 if ( ! $revision ) { |
455 return $revision; |
455 return $revision; |
515 |
515 |
516 return $revisions; |
516 return $revisions; |
517 } |
517 } |
518 |
518 |
519 /** |
519 /** |
|
520 * Returns the url for viewing and potentially restoring revisions of a given post. |
|
521 * |
|
522 * @since 5.9.0 |
|
523 * |
|
524 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`. |
|
525 * @return null|string The URL for editing revisions on the given post, otherwise null. |
|
526 */ |
|
527 function wp_get_post_revisions_url( $post_id = 0 ) { |
|
528 $post = get_post( $post_id ); |
|
529 |
|
530 if ( ! $post instanceof WP_Post ) { |
|
531 return null; |
|
532 } |
|
533 |
|
534 // If the post is a revision, return early. |
|
535 if ( 'revision' === $post->post_type ) { |
|
536 return get_edit_post_link( $post ); |
|
537 } |
|
538 |
|
539 if ( ! wp_revisions_enabled( $post ) ) { |
|
540 return null; |
|
541 } |
|
542 |
|
543 $revisions = wp_get_post_revisions( $post->ID, array( 'posts_per_page' => 1 ) ); |
|
544 |
|
545 if ( 0 === count( $revisions ) ) { |
|
546 return null; |
|
547 } |
|
548 |
|
549 $revision = reset( $revisions ); |
|
550 return get_edit_post_link( $revision ); |
|
551 } |
|
552 |
|
553 /** |
520 * Determine if revisions are enabled for a given post. |
554 * Determine if revisions are enabled for a given post. |
521 * |
555 * |
522 * @since 3.6.0 |
556 * @since 3.6.0 |
523 * |
557 * |
524 * @param WP_Post $post The post object. |
558 * @param WP_Post $post The post object. |
572 * Overrides both the value of WP_POST_REVISIONS and the {@see 'wp_revisions_to_keep'} filter. |
606 * Overrides both the value of WP_POST_REVISIONS and the {@see 'wp_revisions_to_keep'} filter. |
573 * |
607 * |
574 * The dynamic portion of the hook name, `$post->post_type`, refers to |
608 * The dynamic portion of the hook name, `$post->post_type`, refers to |
575 * the post type slug. |
609 * the post type slug. |
576 * |
610 * |
|
611 * Possible hook names include: |
|
612 * |
|
613 * - `wp_post_revisions_to_keep` |
|
614 * - `wp_page_revisions_to_keep` |
|
615 * |
577 * @since 5.8.0 |
616 * @since 5.8.0 |
578 * |
617 * |
579 * @param int $num Number of revisions to store. |
618 * @param int $num Number of revisions to store. |
580 * @param WP_Post $post Post object. |
619 * @param WP_Post $post Post object. |
581 */ |
620 */ |
597 if ( ! is_object( $post ) ) { |
636 if ( ! is_object( $post ) ) { |
598 return $post; |
637 return $post; |
599 } |
638 } |
600 |
639 |
601 $preview = wp_get_post_autosave( $post->ID ); |
640 $preview = wp_get_post_autosave( $post->ID ); |
602 if ( ! is_object( $preview ) ) { |
641 |
603 return $post; |
642 if ( is_object( $preview ) ) { |
604 } |
643 $preview = sanitize_post( $preview ); |
605 |
644 |
606 $preview = sanitize_post( $preview ); |
645 $post->post_content = $preview->post_content; |
607 |
646 $post->post_title = $preview->post_title; |
608 $post->post_content = $preview->post_content; |
647 $post->post_excerpt = $preview->post_excerpt; |
609 $post->post_title = $preview->post_title; |
648 } |
610 $post->post_excerpt = $preview->post_excerpt; |
|
611 |
649 |
612 add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); |
650 add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); |
613 add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 3 ); |
651 add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 3 ); |
614 |
652 |
615 return $post; |
653 return $post; |