• The forum editor mangles the formatting of this report, so a properly formatted copy is here: https://gist.github.com/curtismchale/04070858f1cf20d9211d3ad89b3112cb β€” same text, readable code blocks.

    Fix Alt Text calls wp_suspend_cache_addition( true ) at the top of its save_post, attachment_updated, add_attachment, saved_term and delete_term handlers, and never calls wp_suspend_cache_addition( false ) afterward. A define() guard prevents the call from repeating, so the suspension is set once and stays set for the remainder of the PHP request.

    wp_suspend_cache_addition() gates wp_cache_add() and wp_cache_add_multiple(), which is exactly what core’s update_meta_cache() and _prime_post_caches() use to populate their caches. So from the first post save onward, cache priming silently no-ops and every subsequent get_post_meta() / metadata_exists() / post lookup goes back to the database.

    This is a performance and correctness bug, not a security issue. It is most visible on wp-admin/post-new.php (which always creates an auto-draft and therefore always fires save_post), and on any long-running request that saves posts and keeps working: importers, cron jobs, bulk edits, programmatic wp_insert_post() loops.

    AFFECTED VERSION

    Fix Alt Text 1.9.1 β€” Stable tag: 1.9.1 in readme.txt, define( 'FIXALTTEXT_VERSION', '1.9.1' ); in fix-alt-text.php. This is the current wordpress.org release as of 2026-08-19 (last updated 2025-05-05), so the behaviour is present in the shipping version.

    Verified against WordPress 7.0.4, PHP 8.x, with and without a persistent object cache drop-in (Redis Object Cache 2.8.0).

    WHERE IT HAPPENS

    Type: object cache state leak / unbalanced global flag (performance regression).

    • inc/Scan.php lines 36-39, 56-59, 62-65, 79-82, 85-88 β€” hook registration, all priority 999
    • inc/Scan.php line 193 (save_post_scan), line 111 (save_term_scan), line 138 (delete_term_scan)
    • library/_helpers-library/inc/Run_Library.php lines 342-371 (prevent_caching()), specifically line 367

    ROOT CAUSE

    inc/Scan.php, init() registers five hooks, all at priority 999:

    // Save Post
    add_action( 'save_post', [<br>self::class,<br>'save_post_scan',<br>], 999, 1 );</p>

    <p>Each of those handlers begins by suspending cache addition. <code>inc/Scan.php:191-197</code>:</p>

        Run::prevent_caching(true);
    
        $this_post = get_post( $post_id );

    The same first line appears in save_term_scan() (line 111) and delete_term_scan() (line 138).

    library/_helpers-library/inc/Run_Library.php:342-371:

    `<br>public final static function prevent_caching( bool $wp_cache = false ): void {</p></p> <pre class=”wp-block-code”><code></code></pre> <p><p><p>There is no matching <code>wp_suspend_cache_addition( false )</code> anywhere in the plugin:</p></p></p> <p><p><p><code>$ grep -rn “wp_suspend_cache_addition” /path/to/wp-content/plugins/fix-alt-text/ library/_helpers-library/inc/Run_Library.php:367: wp_suspend_cache_addition( true );</code></p></p></p> <p><p><p>Two properties make this bite harder than it looks.</p></p></p> <pre class=”wp-block-code”><code>if ( is_bool( $suspend ) ) { $_suspend = $suspend; } return $_suspend;</code></pre> <p><p><br></p></p> <p><p><p><code>public function add( $key, $data, $group = ‘default’, $expire = 0 ) { if ( wp_suspend_cache_addition() ) { return false; }</code></p></p></p> <p><p><p>and <code>add_multiple()</code> (line 235) is a loop over <code>add()</code>. Persistent drop-ins honour the same contract β€” Redis Object Cache 2.8.0, <code>includes/object-cache.php:1167</code>:</p></p></p> <p><p><p><code>public function add_multiple( array $data, $group = ‘default’, $expire = 0 ) { if ( function_exists( ‘wp_suspend_cache_addition’ ) && wp_suspend_cache_addition() ) { return array_combine( array_keys( $data ), array_fill( 0, count( $data ), false ) ); }</code></p></p></p> <p><p><p>Core’s cache priming paths use exactly those functions:</p></p></p> <ul> <li></li> <li></li> <li></li> <li></li> </ul> <p><p><p><code>wp_cache_set()</code> is not gated, so ordinary writes still succeed and the cache appears to be working. What stops working is priming: <code>update_meta_cache()</code> runs its SELECT, builds <code>$data</code>, hands it to <code>wp_cache_add_multiple()</code>, and the result is discarded. Every later <code>get_post_meta()</code> on those objects finds no cache entry and primes again, running the same query repeatedly within one request.</p></p></p> <p><p><p>PROOF OF CONCEPT</p></p></p> <p><p><p>Prerequisites: WordPress 6.x or 7.x (tested on 7.0.4), Fix Alt Text 1.9.1 active, WP-CLI. No configuration required β€” the effect occurs before any of the plugin’s own post-type/taxonomy filtering runs.</p></p></p> <p><p><p>Run a single <code>wp_insert_post()</code> and read the flag afterward:</p></p></p> <p><p><p><code>wp eval ‘var_dump( wp_suspend_cache_addition() ); wp_insert_post([“post_type”=>”page”,”post_title”=>”cache-flag-test”,”post_status”=>”draft”]); var_dump( wp_suspend_cache_addition() ); var_dump( defined(“FIXALTTEXT_HELPERSLIBRARY_DONOTCACHE_WP”) );'</code></p></p></p> <p><p><p>Expected result β€” the scan handler may suspend cache addition while it works, but the flag should be back to its prior value once the handler returns, so the rest of the request caches normally:</p></p></p> <p><p><p><code>bool(false) bool(false)</code></p></p></p> <p><p><p>Actual result with Fix Alt Text 1.9.1 active:</p></p></p> <p><p><p><code>bool(false) bool(true) bool(true)</code></p></p></p> <p><p><p>Cache addition remains suspended, and the guard constant is set so it will never be re-evaluated for the remainder of the request.</p></p></p> <p><p><p>Note that <code>save_post_scan()</code> calls <code>Run::prevent_caching( true )</code> before its post-type checks, so this reproduces even for post types the plugin is not configured to scan, and even when the handler immediately returns.</p></p></p> <p><p><p>To see the cost rather than just the flag, on any site with a meaningful amount of post meta:</p></p></p> <ol> <li></li> <li></li> <li></li> <li></li> </ol> <p><p><p>IMPACT</p></p></p> <p><p><p>Measured on a production-scale site (23 nav menus, 863 nav menu items), object cache flushed before each run:</p></p></p> <ul> <li><code>post.php?post=N&action=edit</code>, no <code>save_post</code> β€” 664 queries, 83.4% object cache hit rate, 5.5 s render</li> <li><code>post-new.php?post_type=page</code>, <code>save_post</code> fires β€” 24,968 queries, 25.2% object cache hit rate, 88-92 s render</li> </ul> <p><p><p>To be precise about attribution: the 24,968 queries are not generated by Fix Alt Text. That volume comes from an unrelated N+1 in another plugin’s meta box. What the cache suspension does is remove the mechanism that would otherwise absorb it β€” with cache addition intact, the same screen renders in 5-7 s. The plugin does not create the queries; it prevents them from ever being cached, so their cost scales linearly with the number of lookups instead of being paid once.</p></p></p> <p><p><p>The effect is not limited to that one screen. Any request that saves a post and then keeps doing work runs degraded from that point forward:</p></p></p> <ul> <li><code>wp-admin/post-new.php</code> for every post type, on every load</li> <li>Bulk edits (<code>edit.php</code> bulk actions), which save many posts in one request</li> <li>Importers such as WP All Import, which loop <code>wp_insert_post()</code> hundreds or thousands of times in a single request β€” the first save disables priming for all the rest</li> <li>Cron runs and any programmatic <code>wp_insert_post()</code> / <code>wp_update_post()</code> loop</li> <li>Term-heavy operations, via <code>saved_term</code> and <code>delete_term</code></li> </ul> <p><p><p>No user interaction beyond a normal save is required, and no specific role or configuration is needed. The suspension happens unconditionally at the top of the handler for any authenticated user or process capable of saving a post, attachment or term.</p></p></p> <p><p><p>There is no security consequence here: no data is exposed, modified or lost. The impact is CPU and database load, and on large sites, request timeouts.</p></p></p> <p><p><p>SUGGESTED FIX</p></p></p> <p><p><p>Suspending cache addition during the scan is defensible; leaving it suspended is not. The flag should be restored when the scan finishes.</p></p></p> <p><p><p>Because another plugin or core routine may legitimately have suspended cache addition already, the previous value should be captured and restored rather than unconditionally set to false. <code>wp_suspend_cache_addition()</code> returns the current value when called with no argument, which makes this straightforward.</p></p></p> <p><p><p>In <code>library/_helpers-library/inc/Run_Library.php</code>, add a companion method and record the prior state:</p></p></p> <p>`
    /**
    * Stores the object cache addition state that was in effect before we suspended it.
    *
    * @var bool|null
    */
    private static $previous_cache_addition = null;

    public final static function prevent_caching( bool $wp_cache = false ): void {
    
        // ... existing DONOTCACHE* handling unchanged ...
    
        if ( $wp_cache && ! defined( 'FIXALTTEXT_HELPERSLIBRARY_DONOTCACHE_WP' ) ) {
    
            // Flag to prevent this from running twice
            define( 'FIXALTTEXT_HELPERSLIBRARY_DONOTCACHE_WP', true );
    
            // Remember what the caller had set, so we can hand it back untouched.
            self::$previous_cache_addition = wp_suspend_cache_addition();
    
            // Prevent WP Caching objects in the global variables
            wp_suspend_cache_addition( true );
    
        }
    
    }
    
    /**
     * Restores object cache addition to whatever it was before prevent_caching() ran.
     */
    public final static function restore_caching(): void {
    
        if ( null !== self::$previous_cache_addition ) {
            wp_suspend_cache_addition( self::$previous_cache_addition );
            self::$previous_cache_addition = null;
        }
    
    }

    Then call Run::restore_caching() at the end of each handler in inc/Scan.php β€” save_post_scan(), save_term_scan(), delete_term_scan() β€” including on the early-return paths. A try { ... } finally { Run::restore_caching(); } around the body is the tidiest way to cover every exit.

    Note that the FIXALTTEXT_HELPERSLIBRARY_DONOTCACHE_WP constant would then need to stop doubling as the re-entry guard, since a second save in the same request should be able to suspend again. Replacing it with a static boolean property, or checking null === self::$previous_cache_addition, handles that.

    Two lighter alternatives if a wider refactor is unwelcome:

    • Shutdown hook: register add_action( 'shutdown', [ Run::class, 'restore_caching' ] ) when suspending. This bounds the suspension to the request but does not help long-running importers or cron, which do most of their work before shutdown. Better than nothing, but not the fix.
    • Restore immediately after the scan call: in save_post_scan(), move the suspension so it wraps only self::scan_post( $this_post ), and restore right after. This is the smallest change and matches the apparent intent β€” avoid caching the objects the scanner touches β€” without leaking state.

    The Scan_Process_Library.php:421 call in handle() is a different case: a background scan process generally owns its whole request, so an unrestored flag there is far less harmful. Restoring it consistently would still be an improvement.

    One unrelated note while in that function: the WP_REDIS_DISABLED define is inert. The Redis Object Cache drop-in reads that constant at load time in wp-content/object-cache.php, during wp-settings.php, long before save_post fires, so defining it inside a save_post handler cannot disable a drop-in that has already loaded. It is harmless, just ineffective β€” worth removing or documenting so it is not mistaken for the cause of the above.

    REFERENCES

    Plugin source (wordpress.org SVN, tag 1.9.1):

    WordPress core and documentation:

    • This topic was modified 2 months, 3 weeks ago by curtismchale.
    • This topic was modified 2 months, 3 weeks ago by curtismchale.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Steven Ayers

    (@stevenayers63)

    @curtismchale,

    First of all, thank you for being thorough! It is greatly appreciated.

    This is a known bug and is in the works of being fixed with the release of version 2.0. The added troubleshooting you have provided is very helpful. Great timing!

    I will leave this issue open until version 2.0 is released and this bug is fixed.

    -Steven

    P.S. Very cool retro website: https://curtismchale.ca/

    Thread Starter curtismchale

    (@curtismchale)

    @stevenayers63 I try to be complete if I’m going to report something. I’ll watch for version 2 and have the capacity to test if you need that. I run about 100 US city websites on our platform.

    Thanks, I like the site too.

    Plugin Author Steven Ayers

    (@stevenayers63)

    @curtismchale,

    This got me thinking… maybe a better solution would be to never scan in the moment. Scanning in the moment appears too risky. I cannot control what is simultaneously happening when I am calling that scan, which means I would be turning off cache for those other processes and bog everything down briefly while it scans. Most things are not running async so this is likely not a big issue. Scan in the moment is a blocking issue though.

    We have three options:

    1. Scan in the moment (currently) and turn off cache at the beginning and turn it back on at the end.
    2. We could just queue the resources to be scanned. The wp_cron checks every minute to see if there is something to be scanned and processes it. Of course, if wp_cron doesn’t run, nothing will ever be scanned. Also, if there is a scan in progress it could be blocking and delay the scan of that small resource.
    3. I could hit a rest end point as an async request and not expect a response. This triggers the start of the scan and isolates it so nothing is cache and not affecting anything else since it is a single process.

    So far, I’m liking #3, unless you see any conflicts with that.

    -Steven

    • This reply was modified 2 months, 3 weeks ago by Steven Ayers.
    Thread Starter curtismchale

    (@curtismchale)

    @stevenayers63 , #3 gets my vote.

    Three things I’d ask you to watch, all from running this pattern in our own hosting:

    Loopback reachability is the actual failure mode. A blocking => false request throws away the response, so when the loopback fails, it fails silently and scanning just stops with nothing in the logs. We have sites gated behind HTTP Basic Auth, and they answer their own loopback requests with a 401 β€” that broke this exact dispatch pattern for us in another plugin and took a while to find. Same thing happens behind IP allowlists, Cloudflare Access, staging passwords, and in containers where the public hostname doesn’t resolve internally. Two asks: make the cron fallback actually process the queue rather than only re-dispatching, and put up an admin notice if the queue has been non-empty and untouched for some number of minutes. Silent is worse than slow.

    Don’t authenticate the endpoint with cookies. get_post_args() currently sends ‘cookies’ => $_COOKIE, which only works when a logged-in admin triggered the save. It won’t work from WP-CLI, from cron, or from a front-end save. A per-batch token in a transient, checked in permission_callback, works everywhere.

    Please don’t ship permission_callback => ‘__return_true’. Without the token check that’s an unauthenticated endpoint anyone can hit to kick off scans.

    And regardless of which option you land on, I’d still wrap the scan in try/finally and restore the flag. It costs nothing, it’s correct if someone calls the scan directly, and it means sites like ours can drop the mu-plugin we’re currently running to clean up after it.

    Happy to test 2.0 on a real fleet when you have something β€” we’ve got sites across a range of configurations, including the auth-gated ones that will find the loopback problem fast.

    • This reply was modified 2 months, 3 weeks ago by curtismchale.
    Plugin Author Steven Ayers

    (@stevenayers63)

    @curtismchale,

    Thanks for the advice, I’ll let you know what I end up going with. It is possible I may roll out option #1 first for a more immediate fix, and then implement #3 soon after as it is much more involved.

    This logic affects another plugin WhereUsed, so I have to ensure it will work for both, thus more work.

    -Steven

    Plugin Author Steven Ayers

    (@stevenayers63)

    @curtismchale,

    I have implemented a fix that is coming in version 2.0 either today or tomorrow. It’s not option #3 as we discussed, but I will be looking to move to the option #3 in the future.

    -Steven

Viewing 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.