From 329a067da04598dad75dd7f1a1de721ed82faf7a Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Fri, 20 Sep 2024 23:32:29 +0200 Subject: [PATCH] Replace fictioneer_exclude_protected_posts() --- DEVELOPMENT.md | 1 - includes/functions/_helpers-query.php | 22 -------------------- includes/functions/_setup-shortcodes.php | 5 +---- partials/_article-cards.php | 5 +---- partials/_latest-chapters-compact.php | 5 +---- partials/_latest-chapters-list.php | 5 +---- partials/_latest-chapters.php | 5 +---- partials/_latest-posts.php | 5 +---- partials/_latest-recommendations-compact.php | 5 +---- partials/_latest-recommendations.php | 5 +---- partials/_latest-stories-compact.php | 5 +---- partials/_latest-stories-list.php | 5 +---- partials/_latest-stories.php | 5 +---- partials/_latest-updates-compact.php | 5 +---- partials/_latest-updates-list.php | 5 +---- partials/_latest-updates.php | 5 +---- partials/_showcase.php | 5 +---- 17 files changed, 15 insertions(+), 83 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 44cb20d1..5567bbe8 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -359,7 +359,6 @@ Fictioneer customizes WordPress by using as many standard action and filter hook | `post_password_required` | `fictioneer_bypass_password`, `fictioneer_expire_post_password` | `post_stuck` | `fictioneer_prevent_post_sticky` | `postbox_classes_{$screen_id}_{$box_id}` | `fictioneer_append_metabox_classes` -| `posts_where` | `fictioneer_exclude_protected_posts` | `pre_comment_user_ip` | `__return_empty_string` | `pre_get_posts` | `fictioneer_extend_taxonomy_pages`, `fictioneer_edit_others_fictioneer_posts`, `fictioneer_add_sof_to_taxonomy_query` | `pre_insert_term` | `fictioneer_restrict_tag_creation` diff --git a/includes/functions/_helpers-query.php b/includes/functions/_helpers-query.php index d2fbe9a7..45600204 100644 --- a/includes/functions/_helpers-query.php +++ b/includes/functions/_helpers-query.php @@ -245,28 +245,6 @@ if ( ! function_exists( 'fictioneer_append_date_query' ) ) { } } -// ============================================================================= -// IGNORE PROTECTED POSTS FILTER -// ============================================================================= - -/** - * Filter to ignore protected posts - * - * Note: Filter is not added by default, only in certain places. - * - * @since 5.7.3 - * - * @param string $where WHERE statement. Default empty string. - * - * @return string The updated WHERE statement. - */ - -function fictioneer_exclude_protected_posts( $where = '' ) { - $where .= " AND post_password = ''"; - - return $where; -} - // ============================================================================= // STICKY STORIES // ============================================================================= diff --git a/includes/functions/_setup-shortcodes.php b/includes/functions/_setup-shortcodes.php index 95b6d021..047a2b17 100644 --- a/includes/functions/_setup-shortcodes.php +++ b/includes/functions/_setup-shortcodes.php @@ -1570,7 +1570,7 @@ function fictioneer_shortcode_blog( $attr ) { // Exclude protected if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -1590,9 +1590,6 @@ function fictioneer_shortcode_blog( $attr ) { // Query $blog_query = new WP_Query( $query_args ); - // Remove temporary filters - remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Prime author cache if ( function_exists( 'update_post_author_caches' ) ) { update_post_author_caches( $blog_query->posts ); diff --git a/partials/_article-cards.php b/partials/_article-cards.php index 30d3c205..cfe830ce 100644 --- a/partials/_article-cards.php +++ b/partials/_article-cards.php @@ -100,7 +100,7 @@ if ( ! $args['ignore_protected'] ) { $obfuscation = str_repeat( _x( '· ', 'Protected post content obfuscation character.', 'fictioneer' ), 256 ); $obfuscation = apply_filters( 'fictioneer_filter_obfuscation_string', $obfuscation, $post ); } else { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -109,9 +109,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_article_cards_query_ar // Query $query = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Unique ID $unique_id = wp_unique_id( 'article-block-' ); diff --git a/partials/_latest-chapters-compact.php b/partials/_latest-chapters-compact.php index 265202f0..71c9e27e 100644 --- a/partials/_latest-chapters-compact.php +++ b/partials/_latest-chapters-compact.php @@ -108,7 +108,7 @@ if ( ! empty( $args['excluded_authors'] ) ) { // Ignore protected? if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -117,9 +117,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_latest_chapters_query_ // Query chapters $entries = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Extra attributes $attributes = []; diff --git a/partials/_latest-chapters-list.php b/partials/_latest-chapters-list.php index 8498807d..df06d020 100644 --- a/partials/_latest-chapters-list.php +++ b/partials/_latest-chapters-list.php @@ -113,7 +113,7 @@ if ( ! empty( $args['excluded_authors'] ) ) { // Ignore protected? if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -122,9 +122,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_latest_chapters_query_ // Query chapters $entries = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Extra attributes $attributes = []; diff --git a/partials/_latest-chapters.php b/partials/_latest-chapters.php index 5989de10..c01dab33 100644 --- a/partials/_latest-chapters.php +++ b/partials/_latest-chapters.php @@ -113,7 +113,7 @@ if ( ! empty( $args['excluded_authors'] ) ) { // Ignore protected? if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -122,9 +122,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_latest_chapters_query_ // Query chapters $entries = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Extra attributes $attributes = []; diff --git a/partials/_latest-posts.php b/partials/_latest-posts.php index ffd9779c..8b4cd79a 100644 --- a/partials/_latest-posts.php +++ b/partials/_latest-posts.php @@ -72,7 +72,7 @@ if ( ! empty( $args['excluded_authors'] ) ) { // Ignore protected? if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -81,9 +81,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_latest_posts_query_arg // Query post $latest_entries = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - ?>
diff --git a/partials/_latest-recommendations-compact.php b/partials/_latest-recommendations-compact.php index a66658a4..d77977fa 100644 --- a/partials/_latest-recommendations-compact.php +++ b/partials/_latest-recommendations-compact.php @@ -87,7 +87,7 @@ if ( ! empty( $args['excluded_authors'] ) ) { // Ignore protected? if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -96,9 +96,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_latest_recommendations // Query chapters $entries = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Extra attributes $attributes = []; diff --git a/partials/_latest-recommendations.php b/partials/_latest-recommendations.php index debf7d36..419fae4a 100644 --- a/partials/_latest-recommendations.php +++ b/partials/_latest-recommendations.php @@ -84,7 +84,7 @@ if ( ! empty( $args['excluded_authors'] ) ) { // Ignore protected? if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -93,9 +93,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_latest_recommendations // Query recommendations $entries = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Extra attributes $attributes = []; diff --git a/partials/_latest-stories-compact.php b/partials/_latest-stories-compact.php index 219dd2c1..948e08b0 100644 --- a/partials/_latest-stories-compact.php +++ b/partials/_latest-stories-compact.php @@ -112,7 +112,7 @@ if ( ! empty( $args['excluded_authors'] ) ) { // Ignore protected? if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -121,9 +121,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_latest_stories_query_a // Query stories $entries = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Extra attributes $attributes = []; diff --git a/partials/_latest-stories-list.php b/partials/_latest-stories-list.php index a96867d4..1873844c 100644 --- a/partials/_latest-stories-list.php +++ b/partials/_latest-stories-list.php @@ -113,7 +113,7 @@ if ( ! empty( $args['excluded_authors'] ) ) { // Ignore protected? if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -122,9 +122,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_latest_stories_query_a // Query stories $entries = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Extra attributes $attributes = []; diff --git a/partials/_latest-stories.php b/partials/_latest-stories.php index fcb0aa67..780af963 100644 --- a/partials/_latest-stories.php +++ b/partials/_latest-stories.php @@ -113,7 +113,7 @@ if ( ! empty( $args['excluded_authors'] ) ) { // Ignore protected? if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -122,9 +122,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_latest_stories_query_a // Query stories $entries = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Extra attributes $attributes = []; diff --git a/partials/_latest-updates-compact.php b/partials/_latest-updates-compact.php index 768305b4..ead5913d 100644 --- a/partials/_latest-updates-compact.php +++ b/partials/_latest-updates-compact.php @@ -121,7 +121,7 @@ if ( ! empty( $args['excluded_authors'] ) ) { // Ignore protected? if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -130,9 +130,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_latest_updates_query_a // Query stories $entries = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Extra attributes $attributes = []; diff --git a/partials/_latest-updates-list.php b/partials/_latest-updates-list.php index 080d84d8..64b83e4a 100644 --- a/partials/_latest-updates-list.php +++ b/partials/_latest-updates-list.php @@ -124,7 +124,7 @@ if ( ! empty( $args['excluded_authors'] ) ) { // Ignore protected? if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -133,9 +133,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_latest_updates_query_a // Query stories $entries = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Extra attributes $attributes = []; diff --git a/partials/_latest-updates.php b/partials/_latest-updates.php index 3493a796..f3f09bca 100644 --- a/partials/_latest-updates.php +++ b/partials/_latest-updates.php @@ -127,7 +127,7 @@ if ( ! empty( $args['excluded_authors'] ) ) { // Ignore protected? if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -136,9 +136,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_latest_updates_query_a // Query stories $entries = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Extra attributes $attributes = []; diff --git a/partials/_showcase.php b/partials/_showcase.php index 26691596..f4354612 100644 --- a/partials/_showcase.php +++ b/partials/_showcase.php @@ -84,7 +84,7 @@ if ( ! empty( $args['excluded_authors'] ) ) { // Ignore protected? if ( $args['ignore_protected'] ) { - add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); + $query_args['has_password'] = false; } // Apply filters @@ -93,9 +93,6 @@ $query_args = apply_filters( 'fictioneer_filter_shortcode_showcase_query_args', // Query collections $query = fictioneer_shortcode_query( $query_args ); -// Remove temporary filters -remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); - // Extra attributes $attributes = [];