Fix overzealous post__in filtering

I hate this.
This commit is contained in:
Tetrakern 2023-08-17 01:32:02 +02:00
parent bed9852de1
commit 299db867e8
18 changed files with 57 additions and 40 deletions

View File

@ -206,7 +206,7 @@ if ( ! defined( 'FICTIONEER_CHAPTER_FOLDING_THRESHOLD' ) ) {
// Integer: Expiration time for shortcode Transients (0 for infinite, -1 to disable)
if ( ! defined( 'FICTIONEER_SHORTCODE_TRANSIENT_EXPIRATION' ) ) {
define( 'FICTIONEER_SHORTCODE_TRANSIENT_EXPIRATION', 300 );
define( 'FICTIONEER_SHORTCODE_TRANSIENT_EXPIRATION', -1 );
}
// Integer: Timeout between refreshes of story comment counts (0 for always)

View File

@ -52,7 +52,7 @@ if ( ! function_exists( 'fictioneer_get_card_list' ) ) {
$the_card_args = array_merge( $the_card_args, $card_args );
// Query (but not if 'post__in' is set and empty)
if ( ! ( isset( $query_args['post__in'] ) && empty( $the_query_args['post__in'] ) ) ) {
if ( empty( $the_query_args['post__in'] ?? 0 ) ) {
$query = new WP_Query( $the_query_args );
// Prime author cache

View File

@ -934,7 +934,9 @@ function fictioneer_shortcode_chapter_list( $attr ) {
$empty = fictioneer_minify_html( ob_get_clean() );
// Abort if...
if ( empty( $attr['story_id'] ) && empty( $attr['chapter_ids'] ) ) return $empty;
if ( empty( $attr['story_id'] ) && empty( $attr['chapter_ids'] ) ) {
return $empty;
}
// Setup
$count = max( -1, intval( $attr['count'] ?? -1 ) );
@ -965,23 +967,30 @@ function fictioneer_shortcode_chapter_list( $attr ) {
}
// Extra classes
if ( $hide_icons ) $classes[] = '_no-icons';
if ( ! empty( $attr['class'] ) ) $classes[] = esc_attr( wp_strip_all_tags( $attr['class'] ) );
if ( $hide_icons ) {
$classes[] = '_no-icons';
}
// Apply offset
if ( ! $group ) $chapters = array_slice( $chapters, $offset );
if ( ! empty( $attr['class'] ) ) {
$classes[] = esc_attr( wp_strip_all_tags( $attr['class'] ) );
}
// Apply count
if ( ! $group ) $chapters = $count > 0 ? array_slice( $chapters, 0, $count ) : $chapters;
// Apply offset and count
if ( ! $group ) {
$chapters = array_slice( $chapters, $offset );
$chapters = $count > 0 ? array_slice( $chapters, 0, $count ) : $chapters;
}
// Check array for items
if ( empty( $chapters ) ) return $empty;
if ( empty( $chapters ) ) {
return $empty;
}
// Query chapters
$query_args = array(
'post_type' => 'fcn_chapter',
'post_status' => 'publish',
'post__in' => fictioneer_post__in( $chapters ),
'post__in' => $chapters, // Cannot be empty!
'ignore_sticky_posts' => true,
'orderby' => 'post__in', // Preserve order from meta box
'posts_per_page' => -1, // Get all chapters (this can be hundreds)
@ -1005,7 +1014,9 @@ function fictioneer_shortcode_chapter_list( $attr ) {
$chapter_query = fictioneer_shortcode_query( $query_args );
// Check query for items
if ( ! $chapter_query->have_posts() ) return $empty;
if ( ! $chapter_query->have_posts() ) {
return $empty;
}
// Buffer
ob_start();

View File

@ -43,13 +43,17 @@ function fictioneer_post_featured_list( $post_id ) {
global $post;
// Abort if...
if ( post_password_required() ) return;
if ( post_password_required() ) {
return;
}
// Setup
$featured = fictioneer_get_field( 'fictioneer_post_featured', $post_id );
// Abort if...
if ( empty( $featured ) ) return;
if ( empty( $featured ) ) {
return;
}
// Query
$query_args = array(
@ -64,7 +68,9 @@ function fictioneer_post_featured_list( $post_id ) {
$featured_query = new WP_Query( $query_args );
// Abort if...
if ( empty( $featured_query->posts ) ) return;
if ( empty( $featured_query->posts ) ) {
return;
}
// Prime author cache
if ( function_exists( 'update_post_author_caches' ) ) {

View File

@ -258,7 +258,7 @@ function fictioneer_ajax_get_finished_list() {
$list_items = fictioneer_get_card_list(
'story',
array(
'post__in' => fictioneer_post__in( $post_ids ),
'post__in' => $post_ids,
'paged' => $page,
'order' => $order
),

View File

@ -417,7 +417,7 @@ function fictioneer_ajax_get_follows_list() {
$list_items = fictioneer_get_card_list(
'story',
array(
'post__in' => fictioneer_post__in( $post_ids ),
'post__in' => $post_ids,
'paged' => $page,
'order' => $order
),

View File

@ -187,7 +187,7 @@ function fictioneer_ajax_get_reminders_list() {
$list_items = fictioneer_get_card_list(
'story',
array(
'post__in' => fictioneer_post__in( $post_ids ),
'post__in' => $post_ids,
'paged' => $page,
'order' => $order
),

View File

@ -29,7 +29,7 @@
$query_args = array(
'post_type' => 'fcn_chapter',
'post_status' => 'publish',
'post__in' => fictioneer_post__in( $args['post_ids'] ),
'post__in' => $args['post_ids'], // May be empty!
'order' => $args['order'] ?? 'desc',
'orderby' => $args['orderby'] ?? 'date',
'posts_per_page' => $args['count'],

View File

@ -30,7 +30,7 @@
$query_args = array(
'post_type' => 'fcn_chapter',
'post_status' => 'publish',
'post__in' => fictioneer_post__in( $args['post_ids'] ),
'post__in' => $args['post_ids'], // May be empty!
'orderby' => $args['orderby'] ?? 'date',
'order' => $args['order'] ?? 'desc',
'posts_per_page' => $args['count'],

View File

@ -25,7 +25,7 @@
$query_args = array(
'post_type' => 'post',
'post_status' => 'publish',
'post__in' => fictioneer_post__in( $args['post_ids'] ),
'post__in' => $args['post_ids'], // May be empty!
'has_password' => false,
'orderby' => 'date',
'order' => 'DESC',

View File

@ -29,7 +29,7 @@ $show_taxonomies = ! get_option( 'fictioneer_hide_taxonomies_on_recommendation_c
$query_args = array (
'post_type' => 'fcn_recommendation',
'post_status' => 'publish',
'post__in' => fictioneer_post__in( $args['post_ids'] ),
'post__in' => $args['post_ids'], // May be empty!
'orderby' => $args['orderby'] ?? 'date',
'order' => $args['order'] ?? 'desc',
'posts_per_page' => $args['count'],

View File

@ -30,7 +30,7 @@ $show_taxonomies = ! get_option( 'fictioneer_hide_taxonomies_on_recommendation_c
$query_args = array (
'post_type' => 'fcn_recommendation',
'post_status' => 'publish',
'post__in' => fictioneer_post__in( $args['post_ids'] ),
'post__in' => $args['post_ids'], // May be empty!
'orderby' => $args['orderby'] ?? 'date',
'order' => $args['order'] ?? 'desc',
'posts_per_page' => $args['count'],

View File

@ -30,7 +30,7 @@ $show_taxonomies = ! get_option( 'fictioneer_hide_taxonomies_on_story_cards' );
$query_args = array(
'post_type' => 'fcn_story',
'post_status' => 'publish',
'post__in' => fictioneer_post__in( $args['post_ids'] ),
'post__in' => $args['post_ids'], // May be empty!
'orderby' => $args['orderby'],
'order' => $args['order'] ?? 'desc',
'posts_per_page' => $args['count'],

View File

@ -27,7 +27,7 @@
$query_args = array(
'post_type' => 'fcn_story',
'post_status' => 'publish',
'post__in' => fictioneer_post__in( $args['post_ids'] ),
'post__in' => $args['post_ids'], // May be empty!
'orderby' => $args['orderby'],
'order' => $args['order'] ?? 'desc',
'posts_per_page' => $args['count'],

View File

@ -33,7 +33,7 @@ $card_counter = 0;
$query_args = array(
'post_type' => 'fcn_story',
'post_status' => 'publish',
'post__in' => fictioneer_post__in( $args['post_ids'] ),
'post__in' => $args['post_ids'], // May be empty!
'meta_key' => 'fictioneer_chapters_added',
'orderby' => 'meta_value',
'order' => $args['order'] ?? 'desc',

View File

@ -35,7 +35,7 @@ $card_counter = 0;
$query_args = array(
'post_type' => 'fcn_story',
'post_status' => 'publish',
'post__in' => fictioneer_post__in( $args['post_ids'] ),
'post__in' => $args['post_ids'], // May be empty!
'meta_key' => 'fictioneer_chapters_added',
'orderby' => 'meta_value',
'order' => $args['order'] ?? 'desc',

View File

@ -11,17 +11,17 @@
* @subpackage Fictioneer
* @since 4.0
*
* @internal $args['type'] Post type if the showcase.
* @internal $args['count'] Maximum number of items. Default 8.
* @internal $args['order'] Order direction. Default 'DESC'.
* @internal $args['orderby'] Order argument. Default 'date'.
* @internal $args['author'] Author provided by the shortcode.
* @internal $args['post_ids'] Array of post IDs. Default empty.
* @internal $args['excluded_cats'] Array of category IDs to exclude. Default empty.
* @internal $args['excluded_tags'] Array of tag IDs to exclude. Default empty.
* @internal $args['taxonomies'] Array of taxonomy arrays. Default empty.
* @internal $args['relation'] Relationship between taxonomies.
* @internal $args['classes'] Additional classes.
* @internal $args['type'] Post type if the showcase.
* @internal $args['count'] Maximum number of items. Default 8.
* @internal $args['order'] Order direction. Default 'DESC'.
* @internal $args['orderby'] Order argument. Default 'date'.
* @internal $args['author'] Author provided by the shortcode.
* @internal $args['post_ids'] Array of post IDs. Default empty.
* @internal $args['excluded_cats'] Array of category IDs to exclude. Default empty.
* @internal $args['excluded_tags'] Array of tag IDs to exclude. Default empty.
* @internal $args['taxonomies'] Array of taxonomy arrays. Default empty.
* @internal $args['relation'] Relationship between taxonomies.
* @internal $args['classes'] Additional classes.
*/
?>
@ -31,7 +31,7 @@
$query_args = array (
'post_type' => $args['type'],
'post_status' => 'publish',
'post__in' => fictioneer_post__in( $args['post_ids'] ),
'post__in' => $args['post_ids'], // May be empty!
'order' => $args['order'] ?? 'DESC',
'orderby' => $args['orderby'] ?? 'date',
'posts_per_page' => $args['count'] ?? 8,

View File

@ -164,7 +164,7 @@ $tabs[ $current_tab ]['classes'][] = '_current';
$list_items = fictioneer_get_card_list(
'story',
array(
'post__in' => fictioneer_post__in( $tabs[ $current_tab ]['post_ids'] ),
'post__in' => $tabs[ $current_tab ]['post_ids'],
'paged' => $current_page,
'order' => $order
),