Make WordPress Core

Opened 11 years ago

Closed 9 years ago

#24605 closed enhancement (fixed)

Pass widget ID as a third parameter to widget_text filter

Reported by: namarpi's profile namarpi Owned by: drewapicture's profile DrewAPicture
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.5.1
Component: Widgets Keywords: has-patch
Focuses: Cc:

Description

I would like to identify the current widget when using widget_text filter. If the widget ID will be returned by the filter, it would be very useful. A solution can be adding a third parameter in the wp-includes/default-widget.php near the line 401:

Original:

$text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' :
        $instance['text'], $instance );

Offered:

$text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : 
        $instance['text'], $instance, $this->id );

Attachments (2)

widget_text_filter.24605.diff (810 bytes) - added by mikejolley 10 years ago.
Patch for #24605
24605.diff (1.3 KB) - added by DrewAPicture 9 years ago.

Download all attachments as: .zip

Change History (13)

#1 @namarpi
11 years ago

  • Keywords needs-patch added; has-patch removed

#3 @SergeyBiryukov
11 years ago

  • Summary changed from Returning widget ID as third parameter of widget_text filter to Pass widget ID as a third parameter to widget_text filter
  • Type changed from feature request to enhancement

#4 @namarpi
11 years ago

Maybe it would be a better solution if the widget_text meta data in Options table will contain the widget ID. In this latter case there will be a possibility to find all the necessary widgets before (outside of) the loop.

#5 @namarpi
11 years ago

I would like to recant my Comment 4 because finally I have found the solution for getting widget IDs before the loop. In addition I would like to opiniate my original ticket.

#7 @mikejolley
10 years ago

  • Keywords has-patch added; needs-patch removed

I definitely see the benefit in being able to selectively filter text widgets.

ID is passed through via:

$args['widget_id']

I've attached a quick patch above.

#8 @wonderboymusic
9 years ago

  • Milestone changed from Awaiting Review to 4.4
  • Owner set to DrewAPicture
  • Status changed from new to assigned

#9 @DrewAPicture
9 years ago

  • Status changed from assigned to accepted

@DrewAPicture
9 years ago

#10 @DrewAPicture
9 years ago

Let's pass the entire WP_Widget_Text instance instead of just a part of it. Also, the type and description on the $instance parameter were incorrect. Both are done in 24605.diff.

#11 @DrewAPicture
9 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 34552:

Widgets: Pass $this to the widget_text filter to make targeting specific widget instances easier.

Also fixes docs errors in the type and description for the $instance parameter, introduced in [27697].

Fixes #24605.

Note: See TracTickets for help on using tickets.