From 128597b69afce9cf5fa38d44e40f5fadcfce09ea Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 25 Jul 2019 01:35:52 +0000 Subject: [PATCH] Posts, Post Types: Introduce `is_sticky` filter in `is_sticky()` to provide more flexibility for custom sticky post implementations. Props dehisok, greenshady. Fixes #37629. git-svn-id: https://develop.svn.wordpress.org/trunk@45671 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 44411baa0d..499f800d67 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -2213,15 +2213,17 @@ function is_sticky( $post_id = 0 ) { $stickies = get_option( 'sticky_posts' ); - if ( ! is_array( $stickies ) ) { - return false; - } + $is_sticky = is_array( $stickies ) && in_array( $post_id, $stickies ); - if ( in_array( $post_id, $stickies ) ) { - return true; - } - - return false; + /** + * Filters whether a post is sticky. + * + * @since 5.3.0 + * + * @param bool $is_sticky Whether a post is sticky. + * @param int $post_id Post ID. + */ + return apply_filters( 'is_sticky', $is_sticky, $post_id ); } /**