WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 11 months ago

Last modified 11 months ago

#20788 closed enhancement (fixed)

Add widget instance argument to widget_links_args filter

Reported by: ragulka Owned by: wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.3
Component: Widgets Keywords: dev-feedback has-patch commit
Focuses: Cc:

Description

Using the widget_links_args filter (used in the default Links Widget class) as it is right now is a bit useless because one does not have access to the widget instance that applies the filter.

Widget instance may contain custom variables set by custom fields that may have been added to the widget form by plugins or themes using other filters.

Being able to access widget instance from within the filter function gives developers lots of possibilities to customize the widget.

My suggestion is simple: add $instance argument to the widget_links_args filter, like this (wp-includes/default-widget.php line 113):

wp_list_bookmarks(apply_filters('widget_links_args', array(
	'title_before' => $before_title, 'title_after' => $after_title,
	'category_before' => $before_widget, 'category_after' => $after_widget,
	'show_images' => $show_images, 'show_description' => $show_description,
	'show_name' => $show_name, 'show_rating' => $show_rating,
	'category' => $category, 'class' => 'linkcat widget'
), $instance ));

Attachments (3)

20788.patch (965 bytes) - added by SergeyBiryukov 4 years ago.
20788.2.diff (1.0 KB) - added by MikeHansenMe 14 months ago.
Refresh + docs
20788.diff (1.9 KB) - added by DrewAPicture 11 months ago.
Refresh + cleanup

Download all attachments as: .zip

Change History (11)

#1 @SergeyBiryukov
4 years ago

  • Keywords has-patch added

@MikeHansenMe
14 months ago

Refresh + docs

#3 @chriscct7
11 months ago

  • Version changed from 3.3.2 to 3.3

@DrewAPicture
11 months ago

Refresh + cleanup

#4 @DrewAPicture
11 months ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 4.4

20788.diff refreshes the patch and simplifies the actual filter call by splitting out the args array to a separate variable. Adds the new parameter + docs

Moving for commit consideration.

#5 @chriscct7
11 months ago

  • Owner set to DrewAPicture
  • Status changed from new to assigned

#6 @DrewAPicture
11 months ago

  • Owner DrewAPicture deleted

#7 @wonderboymusic
11 months ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from assigned to closed

In 33971:

WP_Widget_Links: pass widget instance to widget_links_args filter

Props SergeyBiryukov, MikeHansenMe, DrewAPicture.
Fixes #20788.

#8 @DrewAPicture
11 months ago

In 33978:

Docs: Use the $widget_links_args parameter in the hook doc for the widget_links_args filter, introduced when the args array was split out to a variable in [33971].

See #20788.

Note: See TracTickets for help on using tickets.