Fix: cast $blog_id to int in wp_cache_clear_cache() to prevent crash on non-multisite installs#1042
Conversation
…ite function calls on single-site installs
donnchawp
left a comment
There was a problem hiding this comment.
This review was generated by AI.
The (int) $blog_id cast is correct and resolves #1019: (int) 'all' and (int) false both normalize to 0, routing to the single-site path. Normalizing the parameter to the type the function assumes is the right data-level fix. That one line should be the entire PR.
The other four changes (@fclose( $fr ) → if ( $fr ) { fclose( $fr ); }) are unrelated to #1019 and should be dropped:
-
Out of scope. The PR title, body, and linked issue describe only the cast. The
fcloseedits inwp_cache_get_ob()/wp_cache_shutdown_callback()are undocumented and touch a different code path. -
Two are dead code. At lines ~2511 and ~2965 the new
if ( $fr ) { fclose( $fr ); }sits inside an existingif ( $fr ) {block — the guard can never be false. Revert these to barefclose( $fr );. -
Inconsistent error handling. In the
! $gzbranch a guarded close now sits beside@fclose( $fr2 )and@unlink( ... ), so the error path is no longer uniform. Either leave the block's existing@style untouched, or change it consistently — not half.
Please resubmit with only the $blog_id cast.
Minor (no change required): global declarations conventionally precede statements, but order doesn't affect global semantics here.
For visibility: to unblock a release, the two genuinely-needed fixes in this PR have been split into focused PRs:
So this PR actually addressed two real issues. The remaining two changes here (the No action needed on your side — once #1053 and #1054 land, this PR can be closed as superseded. Thanks for surfacing both bugs. |
Problem
When a third-party theme or plugin calls
wp_cache_clear_cache('all', false)with a non-integer$blog_id, the function passes that value directly toget_supercache_dir(), which internally callsget_blog_option()— a multisite-only function. On non-multisite installs, this causes a fatal error.Fixes #1019
Fix
Cast
$blog_idtointat the top of the function. This ensures any non-integer value (e.g.'all',false) is normalized to0, which correctly triggers the single-site cache clearing path.Testing
wp_cache_clear_cache('all', false)