Created
May 24, 2023 21:48
-
-
Save mcaskill/3812b96b7795c3d31c36ad542f454ce9 to your computer and use it in GitHub Desktop.
Revisions
-
mcaskill created this gist
May 24, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ <?php /** * Ensure ACF fields can be previewed when post revisions are disabled * (`WP_POST_REVISIONS`). * * @listens action:wp_revisions_to_keep * Filters the number of revisions to save for the given post. */ add_filter( 'wp_revisions_to_keep', function ( int $num, WP_Post $post ) : int { // Bail early if post revisions enabled. if ( WP_POST_REVISIONS ) { return $num; } // Bail early if the post type is not supported. if ( ! post_type_supports( $post->post_type, 'revisions' ) ) { return $num; } // Bail early if not previewing post. if ( ! is_preview() || empty( $_GET['preview_id'] ) ) { return $num; } $preview_id = (int) $_GET['preview_id']; // Bail early if not previewing this post. if ( $preview_id !== $post->ID ) { return $num; } // Bail early if not currently filtering the post ID // for ACF to fetch from its latest revision. if ( ! doing_filter( 'wp_revisions_to_keep' ) || ! doing_filter( 'acf/validate_post_id' ) ) { return $num; } return 1; }, 10, 2 );