From 11f3594cf4974abd8498699fc8dfd81d81772271 Mon Sep 17 00:00:00 2001 From: deepench Date: Mon, 28 Sep 2026 08:48:51 +0100 Subject: [PATCH 1/2] Fix content_width timing, remove dead code, add transient expiry 1. flash_content_width() ran on after_setup_theme priority 0 and called flash_get_layout(), which depends on is_page()/is_single()/$post - none of which are reliable before the main query is parsed. Verified live: a full-width page still got content_width=780 instead of 1200, because the layout lookup always saw the query in its unparsed pre-bootstrap state. Moved the hook to template_redirect, where those conditional tags are guaranteed to work. 2. Removed flash_plugin_version_compare() (inc/extras.php) and flash_is_woocommerce_pages() (inc/woocommerce.php) - confirmed zero call sites anywhere in this theme. flash_plugin_version_compare() IS used in Flash Pro's own inc/admin/tdi-notice.php, so left untouched there; flash_is_woocommerce_pages() doesn't exist in Pro at all. Two more confirmed-dead files couldn't be removed in this commit (sandboxed permission denial on file deletion in this session) - flagging for manual removal: inc/class-flash-site-library.php (zero references anywhere in the theme; fetches an external JSON URL and echoes title/homepage/array keys unescaped - a latent XSS if it were ever wired in, but it isn't loaded at all today) and inc/customizer/class-flash-upsell-custom-control.php (0 bytes). 3. set_transient('flash_categories', ...) had no expiry, so it never expired and effectively became a permanent autoloaded option. Added a 1-day expiry. Its flusher was also only hooked to edit_category and save_post - neither fires when a category is created or deleted, so the cached "how many categories" count went stale exactly when categories were added or removed. Verified live: creating a new category left the stale count in place before this fix; now create_category/delete_category flush it immediately. --- functions.php | 5 ++++- inc/extras.php | 22 ---------------------- inc/template-tags.php | 6 ++++-- inc/woocommerce.php | 13 ------------- 4 files changed, 8 insertions(+), 38 deletions(-) diff --git a/functions.php b/functions.php index 88d274a..2431b09 100644 --- a/functions.php +++ b/functions.php @@ -147,7 +147,10 @@ function flash_content_width() { $GLOBALS['content_width'] = apply_filters( 'flash_content_width', $content_width ); } - add_action( 'after_setup_theme', 'flash_content_width', 0 ); + // template_redirect, not after_setup_theme: flash_get_layout() relies on + // is_page()/is_single()/$post, which aren't reliable until the main query + // has been parsed. + add_action( 'template_redirect', 'flash_content_width' ); endif; /** diff --git a/inc/extras.php b/inc/extras.php index 0541d2a..1b444ad 100644 --- a/inc/extras.php +++ b/inc/extras.php @@ -646,25 +646,3 @@ function flash_change_logo_attr( $attr, $attachment, $size ) { endif; add_filter( 'wp_get_attachment_image_attributes', 'flash_change_logo_attr', 10, 3 ); - -/** - * Compare user's current version of plugin. - */ -if ( ! function_exists( 'flash_plugin_version_compare' ) ) { - function flash_plugin_version_compare( $plugin_slug, $version_to_compare ) { - if ( ! function_exists( 'get_plugins' ) ) { - require_once ABSPATH . 'wp-admin/includes/plugin.php'; - } - - $installed_plugins = get_plugins(); - - // Plugin not installed. - if ( ! isset( $installed_plugins[ $plugin_slug ] ) ) { - return false; - } - - $tdi_user_version = $installed_plugins[ $plugin_slug ]['Version']; - - return version_compare( $tdi_user_version, $version_to_compare, '<' ); - } -} diff --git a/inc/template-tags.php b/inc/template-tags.php index 346b6d8..7058fbc 100644 --- a/inc/template-tags.php +++ b/inc/template-tags.php @@ -101,7 +101,7 @@ function flash_categorized_blog() { // Count the number of categories that are attached to the posts. $all_the_cool_cats = count( $all_the_cool_cats ); - set_transient( 'flash_categories', $all_the_cool_cats ); + set_transient( 'flash_categories', $all_the_cool_cats, DAY_IN_SECONDS ); } if ( $all_the_cool_cats > 1 ) { @@ -124,4 +124,6 @@ function flash_category_transient_flusher() { delete_transient( 'flash_categories' ); } add_action( 'edit_category', 'flash_category_transient_flusher' ); -add_action( 'save_post', 'flash_category_transient_flusher' ); +add_action( 'save_post', 'flash_category_transient_flusher' ); +add_action( 'create_category', 'flash_category_transient_flusher' ); +add_action( 'delete_category', 'flash_category_transient_flusher' ); diff --git a/inc/woocommerce.php b/inc/woocommerce.php index 5a0f2ca..159e99a 100644 --- a/inc/woocommerce.php +++ b/inc/woocommerce.php @@ -51,16 +51,3 @@ function flash_woocommerce_header_add_to_cart_fragment( $fragments ) { $fragments['div.flash-cart-views'] = ob_get_clean(); return $fragments; } - -/** - * Check if the current viewed page is of WooCommerce - * - * @return void - */ -function flash_is_woocommerce_pages() { - if ( is_shop() || is_product() || is_product_category() || is_product_tag() ) { - return true; - } - - return false; -} \ No newline at end of file From 4943bc874aac71c99b3ec2e2620856fd74aa83f1 Mon Sep 17 00:00:00 2001 From: deepench Date: Tue, 29 Sep 2026 12:01:59 +0100 Subject: [PATCH 2/2] Restore content_width default for admin/REST, keep full-width override --- functions.php | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/functions.php b/functions.php index 2431b09..4c9e63a 100644 --- a/functions.php +++ b/functions.php @@ -137,20 +137,32 @@ function flash_block_editor_styles() { * @global int $content_width **/ function flash_content_width() { - $content_width = 780; + $GLOBALS['content_width'] = apply_filters( 'flash_content_width', 780 ); + } - $classes = flash_get_layout(); - if ( $classes == 'full-width' ) { - $content_width = 1200; - } + // Sets the theme's own default early, so wp-admin (image size caps, the block + // editor) and REST API requests -- which never reach template_redirect -- still + // get a value. + add_action( 'after_setup_theme', 'flash_content_width', 0 ); +endif; - $GLOBALS['content_width'] = apply_filters( 'flash_content_width', $content_width ); +if ( ! function_exists( 'flash_content_width_for_layout' ) ) : + /** + * Widen content_width for a full-width page's actual frontend render. + * + * Run on template_redirect, not after_setup_theme: flash_get_layout() relies + * on is_page()/is_single()/$post, which aren't reliable until the main query + * has been parsed. + * + * @global int $content_width + **/ + function flash_content_width_for_layout() { + if ( 'full-width' == flash_get_layout() ) { + $GLOBALS['content_width'] = apply_filters( 'flash_content_width', 1200 ); + } } - // template_redirect, not after_setup_theme: flash_get_layout() relies on - // is_page()/is_single()/$post, which aren't reliable until the main query - // has been parsed. - add_action( 'template_redirect', 'flash_content_width' ); + add_action( 'template_redirect', 'flash_content_width_for_layout' ); endif; /**