Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code review for 6.1.1 global stylesheet invalidation testing plugin #1

Merged
merged 11 commits into from
Dec 7, 2022
45 changes: 44 additions & 1 deletion wp-test-56970.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,50 @@
<?php
/**
* Plugin Name: Test for Trac 56970
* Description: Clears global stylesheet transient. See <a href="https://core.trac.wordpress.org/ticket/56970">Trac 56970</a>.
* Description: Clears the global stylesheet transient after upgrade to 6.1.1. See <a href="https://core.trac.wordpress.org/ticket/56970">Trac 56970</a>.
* Version: 0.1
*/

// Initialize plugin.
WP_Test_56970_Controller::init();

class WP_Test_56970_Controller {
public static function init() {
add_action( 'init', 'wp_test_56970_init' );
register_activation_hook( __FILE__, array( __CLASS__, 'activate' ) );
register_deactivation_hook( __FILE__, array( __CLASS__, 'deactivate' ) );
}
public static function activate() {
add_option( 'wp_test_56970_run', true );
register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall' ) );
}
public static function deactivate() {
delete_option( 'wp_test_56970_run' );
}
public static function uninstall() {
self::deactivate();
}
}

function wp_test_56970_init() {
global $wp_version;

if ( ! get_option( 'wp_test_56970_run' ) ) {
return;
}

// Issue described in Trac 56970 only affects upgrade from 5.9/6.0 to 6.1.1.
if ( '6.1.1' === $wp_version ) {
// Name of `global_styles_` stylesheet transient, e.g. 'global_styles_twentytwentyone'.
$transient_name = 'global_styles_' . get_stylesheet();
// Hook to invalidate the transient.
add_filter( "transient_$transient_name", 'wp_test_56970_transient_global_styles_stylesheet', 10, 2 );
}
}

function wp_test_56970_transient_global_styles_stylesheet( $value, $transient ) {
// Prevent hook from firing again.
update_option( 'wp_test_56970_run', false );

return false;
}