[wp-trac] [WordPress Trac] #57320: Revisions: add filter before deleting revisions
WordPress Trac
noreply at wordpress.org
Sun Jan 22 10:03:03 UTC 2023
#57320: Revisions: add filter before deleting revisions
--------------------------------------+-----------------------------
Reporter: jhned | Owner: audrasjb
Type: enhancement | Status: reviewing
Priority: normal | Milestone: 6.2
Component: Revisions | Version: trunk
Severity: trivial | Resolution:
Keywords: has-patch has-unit-tests | Focuses: administration
--------------------------------------+-----------------------------
Changes (by audrasjb):
* keywords: has-patch has-unit-tests needs-testing => has-patch has-unit-
tests
* owner: (none) => audrasjb
* status: new => reviewing
Comment:
I tested this filter using the following test snippet:
{{{#!php
<?php
add_filter(
'wp_save_post_revision_revisions_before_deletion',
function( $revisions, $post_id ) {
$original_revision = get_transient(
'original_revision_for_post_' . $post_id );
if ( $original_revision ) {
// Always remove the oldest revision for the array
of revisions to potentially delete.
unset( $revisions[ $original_revision ] );
} else {
// Set the oldest revision in a transient, so we
can verify that it is always ignored.
$original_revision = array_key_first( $revisions
);
set_transient( 'original_revision_for_post_' .
$post_id, $original_revision );
}
return $revisions;
},
10,
2
);
}}}
I also set `WP_POST_REVISIONS` constant to `3`.
Test report:
Works fine on my side: the oldest revision is never deleted ✅
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57320#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list