[wp-trac] [WordPress Trac] #51660: Adding a filter to WP_List_Table::months_dropdown() to allow overriding the list of months displayed

WordPress Trac noreply at wordpress.org
Mon Feb 1 20:16:19 UTC 2021


#51660: Adding a filter to WP_List_Table::months_dropdown() to allow overriding the
list of months displayed
--------------------------------------+-----------------------------
 Reporter:  geoffguillain             |       Owner:  SergeyBiryukov
     Type:  enhancement               |      Status:  reviewing
 Priority:  normal                    |   Milestone:  5.7
Component:  Administration            |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch needs-dev-note  |     Focuses:  performance
--------------------------------------+-----------------------------

Comment (by hellofromTonya):

 **Testing information:**
 See the attached gif for before and after.

 Step 1: Log into your test site.

 Step 2: Go to the Posts.

 Step 3: Select the "All dates" dropdown.

 Step 4: Apply the PR by doing:
 {{{
 npm run grunt patch:https://github.com/WordPress/wordpress-
 develop/pull/967
 }}}

 Step 5: Add the following code to a must-use file or in the theme:

 {{{
 add_filter(
         'pre_months_dropdown_query',
         function( $months, $post_type ) {
                 if ( 'post' !== $post_type ) {
                         return $months;
                 }

                 return array(
                         (object) array( 'year' => 2020, 'month' => 10 ),
                         (object) array( 'year' => 2020, 'month' => 11 ),
                         (object) array( 'year' => 2020, 'month' => 12 ),
                         (object) array( 'year' => 2021, 'month' => 1 ),
                         (object) array( 'year' => 2021, 'month' => 2 ),
                 );
         },
         10,
         2
 );
 }}}

 Step 7: Refresh the Posts page.

 Step 8: Select the "All dates" dropdown. Notice the selections have
 changed.

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


More information about the wp-trac mailing list