Created
April 23, 2026 05:31
-
-
Save xlplugins/9157f8f0e94c0dcbdf2d6d25cb86f5b6 to your computer and use it in GitHub Desktop.
Wpb flush
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * DB connection sync (shutdown) | |
| * Description: Clears any pending MySQL result set on the default connection before other shutdown hooks run, reducing "Commands out of sync" errors from Action Scheduler, WooCommerce batch processing, Jetpack, and cron. | |
| * Version: 1.0.0 | |
| * | |
| * @package | |
| */ | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; | |
| } | |
| /** | |
| * When a previous query leaves results unconsumed, mysqli can throw "Commands out of sync" on the next query. | |
| * wpdb::flush() frees the last result and drains multi-query state (see wp-includes/class-wpdb.php). | |
| * Priority 0 runs before typical shutdown work (e.g. WooCommerce BatchProcessingController at default 10). | |
| */ | |
| add_action( | |
| 'shutdown', | |
| static function () { | |
| global $wpdb; | |
| if ( $wpdb && method_exists( $wpdb, 'flush' ) ) { | |
| $wpdb->flush(); | |
| } | |
| }, | |
| 0 | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment