diff --git a/includes/functions/_service-caching.php b/includes/functions/_service-caching.php index 72dc4ecf..16995058 100644 --- a/includes/functions/_service-caching.php +++ b/includes/functions/_service-caching.php @@ -126,11 +126,11 @@ if ( ! defined( 'FICTIONEER_ENABLE_QUERY_RESULT_CACHING' ) ) { } // ============================================================================= -// ENABLE SHORTCODE TRANSIENTS? +// ENABLE TRANSIENTS? // ============================================================================= /** - * Return whether shortcode Transients should be enabled + * Whether to enable Transients for shortcodes * * @since 5.6.3 * @since 5.23.1 - Do not turn off with cache plugin @@ -139,19 +139,38 @@ if ( ! defined( 'FICTIONEER_ENABLE_QUERY_RESULT_CACHING' ) ) { */ function fictioneer_enable_shortcode_transients() { - // Disable in Customizer if ( is_customize_preview() ) { return false; } - // Check constant $bool = FICTIONEER_SHORTCODE_TRANSIENT_EXPIRATION > -1; - // Filter - $bool = apply_filters( 'fictioneer_filter_enable_shortcode_transients', $bool ); + return apply_filters( 'fictioneer_filter_enable_shortcode_transients', $bool ); +} - // Return - return $bool; +/** + * Whether to enable Transients for story chapter lists + * + * Note: By default true unless there is a known cache plugin + * active or the Transients are turned off by option. They are + * always disabled in the Customizer preview. + * + * @since 5.25.0 + * + * @param int $post_id Post ID of the story. + * + * @return boolean Either true or false. + */ + +function fictioneer_enable_chapter_list_transients( $post_id ) { + if ( is_customize_preview() ) { + return false; + } + + $bool = ! fictioneer_caching_active( 'story_chapter_list' ) && + ! get_option( 'fictioneer_disable_chapter_list_transients' ); + + return apply_filters( 'fictioneer_filter_enable_chapter_list_transients', $bool, $post_id ); } // ============================================================================= diff --git a/includes/functions/hooks/_story_hooks.php b/includes/functions/hooks/_story_hooks.php index fab26566..b8e24a10 100644 --- a/includes/functions/hooks/_story_hooks.php +++ b/includes/functions/hooks/_story_hooks.php @@ -493,9 +493,7 @@ function fictioneer_story_chapters( $args ) { return; } - $enable_transients = FICTIONEER_CHAPTER_LIST_TRANSIENTS && - ! fictioneer_caching_active( 'story_chapter_list' ) && - ! is_customize_preview(); + $enable_transients = fictioneer_enable_chapter_list_transients( $args['story_id'] ); // Check for cached chapters output if ( $enable_transients ) { diff --git a/includes/functions/settings/_register_settings.php b/includes/functions/settings/_register_settings.php index ea56a874..045b058e 100644 --- a/includes/functions/settings/_register_settings.php +++ b/includes/functions/settings/_register_settings.php @@ -725,6 +725,12 @@ define( 'FICTIONEER_OPTIONS', array( 'group' => 'fictioneer-settings-general-group', 'sanitize_callback' => 'fictioneer_sanitize_checkbox', 'default' => 0 + ), + 'fictioneer_disable_chapter_list_transients' => array( + 'name' => 'fictioneer_disable_chapter_list_transients', + 'group' => 'fictioneer-settings-general-group', + 'sanitize_callback' => 'fictioneer_sanitize_checkbox', + 'default' => 0 ) ), 'integers' => array( @@ -1197,6 +1203,7 @@ function fictioneer_get_option_label( $option ) { 'fictioneer_disable_menu_transients' => __( 'Disable menu Transient caching', 'fictioneer' ), 'fictioneer_enable_line_break_fix' => __( 'Enable fixing of chapter paragraphs', 'fictioneer' ), 'fictioneer_show_story_modified_date' => __( 'Show the modified date on story pages', 'fictioneer' ), + 'fictioneer_disable_chapter_list_transients' => __( 'Disable chapter list Transient caching', 'fictioneer' ), ); } diff --git a/includes/functions/settings/_settings_page_general.php b/includes/functions/settings/_settings_page_general.php index 341928a6..e0c4e15a 100644 --- a/includes/functions/settings/_settings_page_general.php +++ b/includes/functions/settings/_settings_page_general.php @@ -1377,6 +1377,16 @@ $images = get_template_directory_uri() . '/img/documentation/'; ?> +
+ +
+