[wp-trac] [WordPress Trac] #35475: New functions: `current_widget` and `current_widget_id`

WordPress Trac noreply at wordpress.org
Mon Jan 18 18:37:48 UTC 2016


#35475: New functions: `current_widget` and `current_widget_id`
-------------------------------------+------------------------------
 Reporter:  sebastian.pisula         |       Owner:
     Type:  enhancement              |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Widgets                  |     Version:
 Severity:  normal                   |  Resolution:
 Keywords:  reporter-feedback close  |     Focuses:
-------------------------------------+------------------------------
Changes (by westonruter):

 * keywords:   => reporter-feedback close


Comment:

 I don't think this is the right approach, to add a new global function. I
 believe there is already a way to do what you want, for example this
 plugin code:

 {{{#!php
 <?php
 $is_recent_posts_widget = false;

 add_action( 'dynamic_sidebar', function( $widget ) use (
 &$is_recent_posts_widget ) {
     $is_recent_posts_widget = ( 0 === strpos( $widget['id'],
 'recent_posts-' ) );
 } );

 add_filter( 'widget_archives_args', function ( $args ) use (
 $is_recent_posts_widget ) {
     if ( $is_recent_posts_widget ) {
         $args['post_type'] = 'page';
     }
     return $args;
 } );
 }}}

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


More information about the wp-trac mailing list