Make WordPress Core

Opened 9 years ago

Closed 6 years ago

#37629 closed enhancement (fixed)

is_sticky filter hook

Reported by: greenshady's profile greenshady Owned by: sergeybiryukov's profile 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 6 years ago.
patch

Download all attachments as: .zip

Change History (7)

#1 follow-up: @tdmalone
8 years 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
8 years 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
6 years ago

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

@dehisok
6 years ago

patch

#4 @dehisok
6 years 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
6 years ago

  • Milestone changed from Awaiting Review to 5.3
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#6 @SergeyBiryukov
6 years ago

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

In 45671:

Posts, Post Types: Introduce is_sticky filter in is_sticky() to provide more flexibility for custom sticky post implementations.

Props dehisok, greenshady.
Fixes #37629.

Note: See TracTickets for help on using tickets.