WordPress.org

Make WordPress Core

Opened 10 months ago

Last modified 2 months ago

#24605 new enhancement

Pass widget ID as a third parameter to widget_text filter

Reported by: namarpi Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.5.1
Component: Widgets Keywords: needs-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 );

Change History (6)

comment:1 namarpi10 months ago

  • Keywords needs-patch added; has-patch removed

comment:3 SergeyBiryukov10 months 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

comment:4 namarpi10 months 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.

comment:5 namarpi9 months 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.

Note: See TracTickets for help on using tickets.