WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 4 weeks ago

#37629 reviewing enhancement

is_sticky filter hook

Reported by: greenshady Owned by: SergeyBiryukov
Milestone: 5.3 Priority: normal
Severity: normal Version: 4.6
Component: Posts, Post Types Keywords: good-first-bug has-patch
Focuses: Cc:

Description

The is_sticky() function needs an accompanying filter hook.

This way, plugins that have custom post types with a custom sticky post implementation can simply filter this when necessary. This way, we don't have to roll a custom pluginslug_is_sticky() function every time.

Attachments (1)

37629.diff (783 bytes) - added by dehisok 4 weeks ago.
patch

Download all attachments as: .zip

Change History (6)

#1 follow-up: @tdmalone
22 months ago

How about the pre_option_sticky_posts filter?

There are other dynamic filters available in `get_option()` as well, which is_sticky() calls.

#2 in reply to: ↑ 1 @greenshady
22 months ago

Replying to tdmalone:

How about the pre_option_sticky_posts filter?

There are other dynamic filters available in `get_option()` as well, which is_sticky() calls.

By running a filter on that hook, you're filtering an option that's storing sticky posts of the post post type, not the result of the is_sticky() function. There's potential for some unintended consequences here when other code is calling get_option( 'sticky_posts' ).

While the option and the conditional are related by default, this is not necessarily true with custom sticky post implementations. Sticky posts can be stored in a variety of ways. A filter hook for the conditional function makes more sense in those scenarios.

#3 @johnbillion
7 weeks ago

  • Keywords needs-patch good-first-bug needs-docs added

@dehisok
4 weeks ago

patch

#4 @dehisok
4 weeks ago

  • Keywords has-patch added; needs-patch needs-docs removed

Changed conditions to prevent multiple apply_filters row. Made similar to the is_active_sidebar filter.
Enjoy :)
It's my the first contribution made at #WCEU

#5 @SergeyBiryukov
4 weeks ago

  • Milestone changed from Awaiting Review to 5.3
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing
Note: See TracTickets for help on using tickets.