diff --git a/INSTALLATION.md b/INSTALLATION.md index a50949c9..f043b04a 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -1176,7 +1176,7 @@ Fictioneer loads the free version of [Font Awesome 6.4.2](https://fontawesome.co ### Constants -Some options are not available in the settings because tempering with them can break the theme or result in unexpected behavior. Those options are defined via constants in the **function.php**. If you want to change them, you need a [child theme](https://developer.wordpress.org/themes/advanced-topics/child-themes/). Just override them in the child theme’s own **function.php**, but only if you know what you are doing! +Some options are not available in the settings because tempering with them can break the theme or result in unexpected behavior. Those options are defined via constants in the **function.php**. If you want to change them, you need a [child theme](https://developer.wordpress.org/themes/advanced-topics/child-themes/) or access to your **wp-config.php**. Just override them in the child theme’s own **function.php**, but only if you know what you are doing! ```php define( 'CONSTANT_NAME', value ); @@ -1244,4 +1244,13 @@ define( 'CONSTANT_NAME', value ); | FICTIONEER_ENABLE_MENU_TRANSIENTS | boolean | Whether to cache nav menus as Transients. Default `true`. | FICTIONEER_ORDER_STORIES_BY_LATEST_CHAPTER | boolean | Whether to order updated stories based on the latest chapter added, excluding stories without chapters. Default `false`. | FICTIONEER_ENABLE_STORY_CHANGELOG | boolean | Whether changes to the story chapter list should be logged. Default `true`. +| FICTIONEER_ENABLE_BROWSER_NOTES | boolean | Whether to inform visitors of missing browser features. Default `true`. +| FICTIONEER_EXTEND_STORY_META_QUERY | boolean | Whether to use the extended meta query for stories. Default `true`. +| FICTIONEER_EXTEND_CHAPTER_META_QUERY | boolean | Whether to use the extended meta query for chapters. Default `true`. | FICTIONEER_EXAMPLE_CHAPTER_ICONS | array | Collection of example Font Awesome icon class strings. + +#### FICTIONEER_EXTEND_STORY_META_QUERY & FICTIONEER_EXTEND_CHAPTER_META_QUERY + +These two constants technically make querying **lists** of stories and chapters slower, in exchange for keeping your database smaller. This is a long-lasting grievance with WordPress queries, which exclude posts that lack requested meta fields even if they evaluate to false. Accounting for that is expensive, but saving those otherwise superfluous meta fields can add thousands of rows to your database, slowing down your site as well. This is a tradeoff and if you have proper caching, the impact is negligible. + +If you would rather have faster queries but store more rows in your database, you can set these constants to `false`. Once you have done this, head to **Fictioneer > Tools > Database Tools** and add the missing **[Story Hidden]** and **[Chapter Hidden]** fields, otherwise your lists will be empty. Also purge the theme caches. Anything else is taken care of by the theme, like allowing the fields to be stored in the future. diff --git a/chapters.php b/chapters.php index 81887e11..bf86ace9 100644 --- a/chapters.php +++ b/chapters.php @@ -33,8 +33,12 @@ $query_args = array( 'orderby' => $orderby, 'paged' => $page, 'posts_per_page' => get_option( 'posts_per_page', 8 ), - 'update_post_term_cache' => ! get_option( 'fictioneer_hide_taxonomies_on_chapter_cards' ), - 'meta_query' => array( + 'update_post_term_cache' => ! get_option( 'fictioneer_hide_taxonomies_on_chapter_cards' ) +); + +// Use extended meta query? +if ( FICTIONEER_EXTEND_CHAPTER_META_QUERY ) { + $query_args['meta_query'] = array( 'relation' => 'OR', array( 'key' => 'fictioneer_chapter_hidden', @@ -44,8 +48,15 @@ $query_args = array( 'key' => 'fictioneer_chapter_hidden', 'compare' => 'NOT EXISTS' ) - ) -); + ); +} else { + $query_args['meta_query'] = array( + array( + 'key' => 'fictioneer_chapter_hidden', + 'value' => '0' + ) + ); +} // Append date query (if any) $query_args = fictioneer_append_date_query( $query_args, $ago, $orderby ); diff --git a/functions.php b/functions.php index 59d6b4d5..628bcf39 100644 --- a/functions.php +++ b/functions.php @@ -376,11 +376,21 @@ if ( ! defined( 'FICTIONEER_ENABLE_STORY_CHANGELOG' ) ) { define( 'FICTIONEER_ENABLE_STORY_CHANGELOG', true ); } -// Boolean: Enable tracking of chapter changes in stories +// Boolean: Enable showing of outdated browsers' missing features if ( ! defined( 'FICTIONEER_ENABLE_BROWSER_NOTES' ) ) { define( 'FICTIONEER_ENABLE_BROWSER_NOTES', true ); } +// Boolean: Enable extended story meta query +if ( ! defined( 'FICTIONEER_EXTEND_STORY_META_QUERY' ) ) { + define( 'FICTIONEER_EXTEND_STORY_META_QUERY', true ); +} + +// Boolean: Enable extended chapter meta query +if ( ! defined( 'FICTIONEER_EXTEND_CHAPTER_META_QUERY' ) ) { + define( 'FICTIONEER_EXTEND_CHAPTER_META_QUERY', true ); +} + /* * Arrays */ diff --git a/includes/functions/_query_helpers.php b/includes/functions/_query_helpers.php index 8d27eba8..7f94d2d2 100644 --- a/includes/functions/_query_helpers.php +++ b/includes/functions/_query_helpers.php @@ -313,4 +313,46 @@ if ( FICTIONEER_ENABLE_STICKY_CARDS ) { add_filter( 'posts_clauses', 'fictioneer_clause_sticky_stories', 10, 2 ); } +// ============================================================================= +// LIST META QUERIES +// ============================================================================= + +/** + * Adds 'fictioneer_chapter_hidden' to be saved falsy + * + * @since 5.9.4 + * + * @param array $allowed Array of allowed falsy meta fields. + * + * @return array The updated array. + */ + +function fictioneer_allow_falsy_chapter_hidden( $allowed ) { + $allowed[] = 'fictioneer_chapter_hidden'; + return $allowed; +} + +if ( ! FICTIONEER_EXTEND_CHAPTER_META_QUERY ) { + add_filter( 'fictioneer_filter_falsy_meta_allow_list', 'fictioneer_allow_falsy_chapter_hidden' ); +} + +/** + * Adds 'fictioneer_story_hidden' to be saved falsy + * + * @since 5.9.4 + * + * @param array $allowed Array of allowed falsy meta fields. + * + * @return array The updated array. + */ + +function fictioneer_allow_falsy_story_hidden( $allowed ) { + $allowed[] = 'fictioneer_story_hidden'; + return $allowed; +} + +if ( ! FICTIONEER_EXTEND_STORY_META_QUERY ) { + add_filter( 'fictioneer_filter_falsy_meta_allow_list', 'fictioneer_allow_falsy_story_hidden' ); +} + ?> diff --git a/partials/_latest-chapters-compact.php b/partials/_latest-chapters-compact.php index 239dc471..5529975c 100644 --- a/partials/_latest-chapters-compact.php +++ b/partials/_latest-chapters-compact.php @@ -45,20 +45,30 @@ $query_args = array( 'orderby' => $args['orderby'], 'posts_per_page' => $args['count'] + 8, // Little buffer in case of unpublished parent story 'no_found_rows' => true, - 'update_post_term_cache' => false, - 'meta_query' => array( + 'update_post_term_cache' => false +); + +// Use extended meta query? +if ( FICTIONEER_EXTEND_CHAPTER_META_QUERY ) { + $query_args['meta_query'] = array( 'relation' => 'OR', array( 'key' => 'fictioneer_chapter_hidden', - 'compare' => 'NOT EXISTS' + 'value' => '0' ), array( 'key' => 'fictioneer_chapter_hidden', - 'value' => 0, - 'compare' => '=' + 'compare' => 'NOT EXISTS' ) - ) -); + ); +} else { + $query_args['meta_query'] = array( + array( + 'key' => 'fictioneer_chapter_hidden', + 'value' => '0' + ) + ); +} // Author? if ( ! empty( $args['author'] ) ) { diff --git a/partials/_latest-chapters.php b/partials/_latest-chapters.php index df693bdf..741f9020 100644 --- a/partials/_latest-chapters.php +++ b/partials/_latest-chapters.php @@ -46,20 +46,30 @@ $query_args = array( 'order' => $args['order'], 'posts_per_page' => $args['count'] + 8, // Little buffer in case of unpublished parent story 'no_found_rows' => true, - 'update_post_term_cache' => false, - 'meta_query' => array( + 'update_post_term_cache' => false +); + +// Use extended meta query? +if ( FICTIONEER_EXTEND_CHAPTER_META_QUERY ) { + $query_args['meta_query'] = array( 'relation' => 'OR', array( 'key' => 'fictioneer_chapter_hidden', - 'compare' => 'NOT EXISTS' + 'value' => '0' ), array( 'key' => 'fictioneer_chapter_hidden', - 'value' => 0, - 'compare' => '=' + 'compare' => 'NOT EXISTS' ) - ) -); + ); +} else { + $query_args['meta_query'] = array( + array( + 'key' => 'fictioneer_chapter_hidden', + 'value' => '0' + ) + ); +} // Author? if ( ! empty( $args['author'] ) ) { diff --git a/partials/_latest-stories-compact.php b/partials/_latest-stories-compact.php index 6b17aa9c..bcdc7d4b 100644 --- a/partials/_latest-stories-compact.php +++ b/partials/_latest-stories-compact.php @@ -43,7 +43,12 @@ $query_args = array( 'order' => $args['order'], 'orderby' => $args['orderby'], 'posts_per_page' => $args['count'], - 'meta_query' => array( + 'no_found_rows' => true +); + +// Use extended meta query? +if ( FICTIONEER_EXTEND_STORY_META_QUERY ) { + $query_args['meta_query'] = array( 'relation' => 'OR', array( 'key' => 'fictioneer_story_hidden', @@ -53,9 +58,15 @@ $query_args = array( 'key' => 'fictioneer_story_hidden', 'compare' => 'NOT EXISTS' ) - ), - 'no_found_rows' => true -); + ); +} else { + $query_args['meta_query'] = array( + array( + 'key' => 'fictioneer_story_hidden', + 'value' => '0' + ) + ); +} // Author? if ( ! empty( $args['author'] ) ) { diff --git a/partials/_latest-stories.php b/partials/_latest-stories.php index 04956789..ffb002a7 100644 --- a/partials/_latest-stories.php +++ b/partials/_latest-stories.php @@ -40,7 +40,12 @@ $query_args = array( 'order' => $args['order'], 'orderby' => $args['orderby'], 'posts_per_page' => $args['count'], - 'meta_query' => array( + 'no_found_rows' => true +); + +// Use extended meta query? +if ( FICTIONEER_EXTEND_STORY_META_QUERY ) { + $query_args['meta_query'] = array( 'relation' => 'OR', array( 'key' => 'fictioneer_story_hidden', @@ -50,9 +55,15 @@ $query_args = array( 'key' => 'fictioneer_story_hidden', 'compare' => 'NOT EXISTS' ) - ), - 'no_found_rows' => true -); + ); +} else { + $query_args['meta_query'] = array( + array( + 'key' => 'fictioneer_story_hidden', + 'value' => '0' + ) + ); +} // Author? if ( ! empty( $args['author'] ) ) { diff --git a/partials/_latest-updates-compact.php b/partials/_latest-updates-compact.php index 100443a3..01a0a485 100644 --- a/partials/_latest-updates-compact.php +++ b/partials/_latest-updates-compact.php @@ -45,7 +45,13 @@ $query_args = array( 'orderby' => 'meta_value', 'meta_key' => 'fictioneer_chapters_added', 'posts_per_page' => $args['count'] + 4, // Account for non-eligible posts! - 'meta_query' => array( + 'no_found_rows' => true, + 'update_post_term_cache' => false +); + +// Use extended meta query? +if ( FICTIONEER_EXTEND_STORY_META_QUERY ) { + $query_args['meta_query'] = array( 'relation' => 'OR', array( 'key' => 'fictioneer_story_hidden', @@ -54,11 +60,16 @@ $query_args = array( array( 'key' => 'fictioneer_story_hidden', 'compare' => 'NOT EXISTS' - ), - ), - 'no_found_rows' => true, - 'update_post_term_cache' => false -); + ) + ); +} else { + $query_args['meta_query'] = array( + array( + 'key' => 'fictioneer_story_hidden', + 'value' => '0' + ) + ); +} // Author? if ( ! empty( $args['author'] ) ) { diff --git a/partials/_latest-updates.php b/partials/_latest-updates.php index f350fcae..b17c1fa7 100644 --- a/partials/_latest-updates.php +++ b/partials/_latest-updates.php @@ -47,7 +47,12 @@ $query_args = array( 'orderby' => 'meta_value', 'meta_key' => 'fictioneer_chapters_added', 'posts_per_page' => $args['count'] + 4, // Account for non-eligible posts! - 'meta_query' => array( + 'no_found_rows' => true +); + +// Use extended meta query? +if ( FICTIONEER_EXTEND_STORY_META_QUERY ) { + $query_args['meta_query'] = array( 'relation' => 'OR', array( 'key' => 'fictioneer_story_hidden', @@ -56,10 +61,16 @@ $query_args = array( array( 'key' => 'fictioneer_story_hidden', 'compare' => 'NOT EXISTS' - ), - ), - 'no_found_rows' => true -); + ) + ); +} else { + $query_args['meta_query'] = array( + array( + 'key' => 'fictioneer_story_hidden', + 'value' => '0' + ) + ); +} // Author? if ( ! empty( $args['author'] ) ) { diff --git a/stories.php b/stories.php index 34d639d7..d2cb359b 100644 --- a/stories.php +++ b/stories.php @@ -34,8 +34,12 @@ $query_args = array ( 'orderby' => $orderby, 'paged' => $page, 'posts_per_page' => get_option( 'posts_per_page', 8 ), - 'update_post_term_cache' => ! get_option( 'fictioneer_hide_taxonomies_on_story_cards' ), - 'meta_query' => array( + 'update_post_term_cache' => ! get_option( 'fictioneer_hide_taxonomies_on_story_cards' ) +); + +// Use extended meta query? +if ( FICTIONEER_EXTEND_STORY_META_QUERY ) { + $query_args['meta_query'] = array( 'relation' => 'OR', array( 'key' => 'fictioneer_story_hidden', @@ -45,8 +49,15 @@ $query_args = array ( 'key' => 'fictioneer_story_hidden', 'compare' => 'NOT EXISTS' ) - ) -); + ); +} else { + $query_args['meta_query'] = array( + array( + 'key' => 'fictioneer_story_hidden', + 'value' => '0' + ) + ); +} // Order by latest chapter update timestamp? if ( FICTIONEER_ORDER_STORIES_BY_LATEST_CHAPTER && $orderby === 'modified' ) {