[wp-trac] [WordPress Trac] #57320: Revisions: add filter before deleting revisions

WordPress Trac noreply at wordpress.org
Mon Dec 12 17:07:16 UTC 2022


#57320: Revisions: add filter before deleting revisions
-------------------------+------------------------------
 Reporter:  jhned        |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Revisions    |     Version:  trunk
 Severity:  trivial      |  Resolution:
 Keywords:               |     Focuses:  administration
-------------------------+------------------------------

Comment (by costdev):

 Hi @jhned, thanks for creating this ticket!

 Would hooking the
 [https://developer.wordpress.org/reference/hooks/the_posts/ 'the_posts']
 filter suit your needs? The first parameter is the list of posts (or
 revisions in this case), and the second is the query object.

 I'm thinking something along the lines of this:
 {{{#!php
 <?php

 add_filter( 'the_posts', 'myprefix_skip_original_revision', 10, 2 );

 function myprefix_skip_original_revision( $revisions, $query ) {
     if ( 0 < $query->get( 'post_parent' ) && 'revision' === $query->get(
 'post_type' ) ) {
         array_shift( $revisions );
     }

     return $revisions;
 }

 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57320#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list