id ) {
return;
}
remove_all_actions( 'admin_notices' );
remove_all_actions( 'all_admin_notices' );
remove_all_actions( 'network_admin_notices' );
remove_all_actions( 'user_admin_notices' );
}
/**
* Mark the plugin screen so popups rendered outside the app get the theme.
*
* @param string $classes Space-separated body classes.
*/
public static function body_class( $classes ): string {
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
return $screen && self::$hook === $screen->id ? $classes . ' psbench-screen' : (string) $classes;
}
/**
* Add Tools › Page Speed Benchmark.
*/
public static function menu(): void {
self::$hook = (string) add_management_page(
__( 'Page Speed Benchmark', 'mtx-psbench' ),
__( 'Page Speed Benchmark', 'mtx-psbench' ),
Ajax::CAPABILITY,
self::SLUG,
array( __CLASS__, 'render' )
);
}
/**
* Mount point for the app. The heading is for screen readers and for the
* moment before the script runs; the app draws its own header.
*/
public static function render(): void {
echo '
' . esc_html__( 'Page Speed Benchmark', 'mtx-psbench' ) . '
';
}
/**
* Load the app on its own screen only.
*
* @param string $hook Current screen hook.
*/
public static function enqueue( $hook ): void {
if ( $hook !== self::$hook ) {
return;
}
wp_enqueue_script( self::HANDLE, PSBENCH_URL . 'assets/js/admin.js', array( 'wp-i18n', 'heartbeat' ), self::asset_version( 'assets/js/admin.js' ), true );
wp_enqueue_style( self::HANDLE, PSBENCH_URL . 'assets/css/admin.css', array(), self::asset_version( 'assets/css/admin.css' ) );
wp_add_inline_style( self::HANDLE, '.psbench-screen #wpbody-content > :is(.notice, .updated, .error, .update-nag), .psbench-screen .psbench-wrap > :is(.notice, .updated, .error, .update-nag) { display: none !important; }' );
wp_set_script_translations( self::HANDLE, 'mtx-psbench' );
wp_add_inline_script(
self::HANDLE,
'window.psbenchData = ' . wp_json_encode(
array(
'version' => PSBENCH_VERSION,
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( Ajax::NONCE ),
'heartbeatKey' => Heartbeat::KEY,
'heartbeatInterval' => Heartbeat::INTERVAL,
'settings' => Settings::all(),
'limits' => Settings::LIMITS,
'queryTiming' => ! defined( 'SAVEQUERIES' ) || SAVEQUERIES,
)
) . ';',
'before'
);
}
/**
* The bundle is an ES module (Vite output).
*
* @param string $tag Script tag.
* @param string $handle Script handle.
*/
public static function module_type( $tag, $handle ): string {
if ( self::HANDLE === $handle && false === strpos( (string) $tag, 'type="module"' ) ) {
return (string) preg_replace( '/