context = $context; $this->activation_flag = $activation_flag; $this->assets = $assets ?: new Assets( $this->context ); } /** * Registers functionality through WordPress hooks. * * @since 1.10.0 */ public function register() { add_filter( 'googlesitekit_admin_notices', function ( $notices ) { $notices[] = $this->get_activation_notice(); return $notices; } ); add_action( 'admin_enqueue_scripts', function ( $hook_suffix ) { if ( 'plugins.php' !== $hook_suffix || ! $this->activation_flag->get_activation_flag( is_network_admin() ) ) { return; } /** * Prevent the default WordPress "Plugin Activated" notice from rendering. * * @link https://github.com/WordPress/WordPress/blob/e1996633228749cdc2d92bc04cc535d45367bfa4/wp-admin/plugins.php#L569-L570 */ unset( $_GET['activate'] ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.VIP.SuperGlobalInputUsage $this->assets->enqueue_asset( 'googlesitekit-admin-css' ); $this->assets->enqueue_asset( 'googlesitekit-activation' ); } ); } /** * Gets the admin notice indicating that the plugin has just been activated. * * @since 1.10.0 * * @return Notice Admin notice instance. */ private function get_activation_notice() { return new Notice( 'activated', array( 'content' => function () { ob_start(); ?>