Add fictioneer_enable_menu_transients() helper
This was overdue anyway.
This commit is contained in:
parent
aa5ae7079e
commit
b1893c2df5
@ -1604,7 +1604,6 @@ define( 'CONSTANT_NAME', value );
|
||||
| FICTIONEER_API_STORYGRAPH_CHAPTERS | boolean | Whether to add chapters to the Storygraph `/stories` endpoint. Default `true`.
|
||||
| FICTIONEER_ENABLE_STICKY_CARDS | boolean | Whether to allow sticky cards. Expensive. Default `true`.
|
||||
| FICTIONEER_ENABLE_STORY_DATA_META_CACHE | boolean | Whether to "cache" story data in a meta field. Default `true`.
|
||||
| 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_DEFER_SCRIPTS | boolean | Whether to defer scripts or load them in the footer. Default `true`.
|
||||
|
@ -403,11 +403,6 @@ if ( ! defined( 'FICTIONEER_ENABLE_STORY_DATA_META_CACHE' ) ) {
|
||||
define( 'FICTIONEER_ENABLE_STORY_DATA_META_CACHE', true );
|
||||
}
|
||||
|
||||
// Boolean: Enable nav menu Transients
|
||||
if ( ! defined( 'FICTIONEER_ENABLE_MENU_TRANSIENTS' ) ) {
|
||||
define( 'FICTIONEER_ENABLE_MENU_TRANSIENTS', ! get_option( 'fictioneer_disable_menu_transients', false ) );
|
||||
}
|
||||
|
||||
// Boolean: Order stories by last updated chapter timestamp
|
||||
if ( ! defined( 'FICTIONEER_ORDER_STORIES_BY_LATEST_CHAPTER' ) ) {
|
||||
define( 'FICTIONEER_ORDER_STORIES_BY_LATEST_CHAPTER', false );
|
||||
|
@ -173,6 +173,29 @@ function fictioneer_enable_chapter_list_transients( $post_id ) {
|
||||
return apply_filters( 'fictioneer_filter_enable_chapter_list_transients', $bool, $post_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to enable Transients for menus
|
||||
*
|
||||
* @since 5.25.0
|
||||
*
|
||||
* @param string $location Location identifier of the menu. Possible locations are
|
||||
* 'nav_menu', 'mobile_nav_menu', and 'footer_menu'.
|
||||
*
|
||||
* @return boolean Either true or false.
|
||||
*/
|
||||
|
||||
function fictioneer_enable_menu_transients( $location ) {
|
||||
if ( is_customize_preview() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return apply_filters(
|
||||
'fictioneer_enable_menu_transients',
|
||||
! get_option( 'fictioneer_disable_menu_transients' ),
|
||||
$location
|
||||
);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// PURGE CACHES
|
||||
// =============================================================================
|
||||
|
@ -80,8 +80,9 @@ function fictioneer_footer_menu_row( $args ) {
|
||||
<div class="footer__menu"><?php
|
||||
if ( has_nav_menu( 'footer_menu' ) ) {
|
||||
$menu = null;
|
||||
$transient_enabled = fictioneer_enable_menu_transients( 'footer_menu' );
|
||||
|
||||
if ( FICTIONEER_ENABLE_MENU_TRANSIENTS ) {
|
||||
if ( $transient_enabled ) {
|
||||
$menu = get_transient( 'fictioneer_footer_menu_html' );
|
||||
}
|
||||
|
||||
@ -103,7 +104,7 @@ function fictioneer_footer_menu_row( $args ) {
|
||||
$menu = preg_replace( '/<\/li>\s*<li/', '</li><li', $menu );
|
||||
}
|
||||
|
||||
if ( FICTIONEER_ENABLE_MENU_TRANSIENTS ) {
|
||||
if ( $transient_enabled ) {
|
||||
set_transient( 'fictioneer_footer_menu_html', $menu );
|
||||
}
|
||||
}
|
||||
|
@ -263,8 +263,9 @@ function fictioneer_mobile_navigation_panel() {
|
||||
if ( ! function_exists( 'elementor_theme_do_location' ) || ! elementor_theme_do_location( 'mobile_nav_menu' ) ) {
|
||||
if ( has_nav_menu( 'nav_menu' ) ) {
|
||||
$menu = null;
|
||||
$transient_enabled = fictioneer_enable_menu_transients( 'mobile_nav_menu' );
|
||||
|
||||
if ( FICTIONEER_ENABLE_MENU_TRANSIENTS ) {
|
||||
if ( $transient_enabled ) {
|
||||
$menu = get_transient( 'fictioneer_mobile_nav_menu_html' );
|
||||
}
|
||||
|
||||
@ -284,7 +285,7 @@ function fictioneer_mobile_navigation_panel() {
|
||||
$menu = str_replace( ['current_page_item', 'current-menu-item', 'aria-current="page"'], '', $menu );
|
||||
}
|
||||
|
||||
if ( FICTIONEER_ENABLE_MENU_TRANSIENTS ) {
|
||||
if ( $transient_enabled ) {
|
||||
set_transient( 'fictioneer_mobile_nav_menu_html', $menu );
|
||||
}
|
||||
}
|
||||
|
@ -64,8 +64,9 @@ if ( $header_style === 'wide' ) {
|
||||
if ( ! function_exists( 'elementor_theme_do_location' ) || ! elementor_theme_do_location( 'nav_menu' ) ) {
|
||||
if ( has_nav_menu( 'nav_menu' ) ) {
|
||||
$menu = null;
|
||||
$transient_enabled = fictioneer_enable_menu_transients( 'nav_menu' );
|
||||
|
||||
if ( FICTIONEER_ENABLE_MENU_TRANSIENTS ) {
|
||||
if ( $transient_enabled ) {
|
||||
$menu = get_transient( 'fictioneer_main_nav_menu_html' );
|
||||
}
|
||||
|
||||
@ -85,7 +86,7 @@ if ( $header_style === 'wide' ) {
|
||||
$menu = str_replace( ['current_page_item', 'current-menu-item', 'aria-current="page"'], '', $menu );
|
||||
}
|
||||
|
||||
if ( FICTIONEER_ENABLE_MENU_TRANSIENTS ) {
|
||||
if ( $transient_enabled ) {
|
||||
set_transient( 'fictioneer_main_nav_menu_html', $menu );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user