context = $context; if ( ! $assets ) { $assets = new Assets( $this->context ); } $this->assets = $assets; } /** * Registers functionality through WordPress hooks. * * @since 1.0.0 */ public function register() { add_action( 'wp_dashboard_setup', function () { $this->add_widgets(); } ); $wp_dashboard_callback = function() { if ( 'dashboard' === get_current_screen()->id && current_user_can( Permissions::VIEW_DASHBOARD ) ) { // Enqueue fonts. $this->assets->enqueue_fonts(); // Enqueue styles. $this->assets->enqueue_asset( 'googlesitekit_wp_dashboard_css' ); // Enqueue scripts. $this->assets->enqueue_asset( 'googlesitekit_wp_dashboard' ); $this->assets->enqueue_asset( 'googlesitekit_modules' ); } }; add_action( 'admin_enqueue_scripts', $wp_dashboard_callback, 30 ); } /** * Add a Site Kit by Google widget to the WordPress admin dashboard. * * @since 1.0.0 */ private function add_widgets() { // Only show the Dashboard Widget if the current user has access. if ( ! current_user_can( Permissions::VIEW_DASHBOARD ) ) { return; } $logo = $this->assets->svg_sprite( 'logo-g', [ 'height' => '19', 'width' => '19', ] ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped. $logo_text = $this->assets->svg_sprite( 'logo-sitekit', [ 'height' => '17', 'width' => '78', ] ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped. wp_add_dashboard_widget( 'google_dashboard_widget', '' . $logo . $logo_text . '', function () { $this->render_googlesitekit_wp_dashboard(); } ); } /** * Render the Site Kit WordPress Dashboard widget. * * @since 1.0.0 */ private function render_googlesitekit_wp_dashboard() { do_action( 'googlesitekit_above_wp_dashboard_app' ); ?>