Skip to content

Fix content_width timing, remove dead code, add transient expiry - #112

Merged
iamprazol merged 2 commits into
developfrom
fix/content-width-jump-link-transient-hygiene
Sep 30, 2026
Merged

iamprazol merged 2 commits into
developfrom
fix/content-width-jump-link-transient-hygiene

Conversation

@deepench

Copy link
Copy Markdown
Contributor

Fixes #95

Changes proposed in this Pull Request:

Four independent hygiene items, all verified live rather than taken on the report's word:

  1. content_width ignoring per-page layout - 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 with a debug probe: a full-width page still got content_width=780 instead of 1200. Moved the hook to template_redirect, where those conditional tags actually work.

  2. Dead code - inc/class-flash-site-library.php and inc/customizer/class-flash-upsell-custom-control.php (0 bytes) have zero references anywhere in the theme, confirmed by grep. flash_plugin_version_compare() and flash_is_woocommerce_pages() are also unused here. Removed the two functions in this PR; the two files could not be deleted in this session (a local tooling restriction on file deletion, unrelated to the theme itself) and are flagged below for manual removal.

  3. Transient without expiry - set_transient('flash_categories', ...) had no expiry, so it never expired. Added one. Its flusher was also only hooked to edit_category/save_post - neither fires on category create or delete - so the cached category count went stale exactly when categories were added or removed. Verified live: creating a category used to leave the stale cached count in place; now create_category/delete_category flush it immediately.

Files still needing manual deletion (grep-confirmed zero references, listed in the commit message too):

  • inc/class-flash-site-library.php
  • inc/customizer/class-flash-upsell-custom-control.php

Note: item B from the issue (undefined $end in flash_remove_more_jump_link()) is Pro-only per the report - fixed over there: themegrill/flash-pro#124

How to test the changes in this Pull Request:

  1. Set a page's layout to Full Width and confirm content_width-dependent behavior (responsive image sizes) reflects 1200, not 780.
  2. Confirm the theme still activates and pages render normally after the dead-code removal.
  3. Create a new category and assign it to a post without editing anything else - the post's category list should reflect it immediately, not after some other save.

Types of changes:

  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (modification of the currently available functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Other information:

  • Have you added an explanation of what your changes do and why you would like us to include them?
  • Have you successfully ran tests with your changes locally?
  • Have you updated the documentation accordingly?

Changelog entry

Fix - content_width now reflects the actual page layout; added expiry and create/delete flushing to the category-count transient; removed unused code.

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.
@tg-autopilot
tg-autopilot requested a lite review from Copilot September 28, 2026 07:53
@github-actions

Copy link
Copy Markdown

QA suite — refused, no regression spec

This PR changes product source but adds no spec, so the suite was
refused before booting WordPress — running it just to report the same
thing at the end costs runner minutes for nothing. Run
/claudegrill:verify-fix locally and let write-spec add the guard
to this branch, then push again.

Source files changed with no matching spec
functions.php
inc/extras.php
inc/template-tags.php
inc/woocommerce.php

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

A moderate legacy-transient issue and cleanup/reference nits remain unresolved.

Review effort: Lite
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

This PR fixes layout-dependent content_width, improves category transient invalidation, and removes unused helpers.

Changes:

  • Defers content-width calculation until template_redirect.
  • Adds transient expiry and category create/delete flushing.
  • Removes unused helper code.
File Summary
inc/​woocommerce.php Removes an unused helper.
inc/​template-tags.php Adds transient expiry and invalidation; legacy transient migration remains needed (moderate).
inc/​extras.php Removes an unused helper; empty dead files still require removal (nit).
functions.php Updates content-width timing; tracking reference needs correction (nit).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread inc/template-tags.php
$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 );
Comment thread functions.php Outdated
Comment on lines +150 to +153
// 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' );
@deepench

Copy link
Copy Markdown
Contributor Author

Same regression a reviewer caught on the Pro sibling PR (flash-pro#124) exists here too, same code: moving the whole flash_content_width() to template_redirect means $content_width is never set at all in wp-admin/REST contexts (which never reach template_redirect), breaking the classic editor's image-size cap and REST media responses.

Fixed proactively in 4943bc8 the same way: flash_content_width() back on after_setup_theme priority 0 for the 780 default, plus a new flash_content_width_for_layout() on template_redirect that only widens to 1200 for an actual full-width frontend page. Verified live (debug probe): admin/CLI context now shows int(780), a full-width page shows 1200, a normal page shows 780.

@subin-shk subin-shk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏼

@iamprazol
iamprazol merged commit 82b37f9 into develop Sep 30, 2026
1 check failed
@iamprazol
iamprazol deleted the fix/content-width-jump-link-transient-hygiene branch September 30, 2026 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants