get( 'toolbar', true ) : true; } /** The article being viewed or edited, if Clusterlane analyses it. */ private static function current_article(): int { $id = 0; if ( is_admin() ) { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( $screen && $screen->base === 'post' && isset( $_GET['post'] ) ) $id = absint( $_GET['post'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only } elseif ( is_singular() ) { $id = (int) get_queried_object_id(); } if ( ! $id ) return 0; $post = get_post( $id ); if ( \Clusterlane\Core\Scope::excludes( $post ) ) return 0; return in_array( $post->post_type, \Clusterlane\Core\Scope::post_types(), true ) ? $id : 0; } public static function menu( \WP_Admin_Bar $bar ): void { if ( ! self::on() ) return; $url = static fn( string $page, array $args = [] ) => add_query_arg( array_merge( [ 'page' => $page ], $args ), admin_url( 'admin.php' ) ); $bar->add_node( [ 'id' => 'clusterlane', 'title' => '' . esc_html( \Clusterlane\Core\Brand::name() ) . '', 'href' => $url( 'clusterlane-dashboard' ), 'meta' => [ 'title' => \Clusterlane\Core\Brand::name() ], ] ); $article = self::current_article(); if ( $article ) { $bar->add_node( [ 'parent' => 'clusterlane', 'id' => 'clusterlane-inspect', 'title' => esc_html__( 'Inspect this article', 'clusterlane' ), 'href' => $url( 'clusterlane-article-inspector', [ 'post_id' => $article ] ), 'meta' => [ 'class' => 'clusterlane-ab-inspect' ], ] ); } $pages = [ 'clusterlane-dashboard' => __( 'Dashboard', 'clusterlane' ), 'clusterlane-cluster-inspector' => __( 'Cluster Inspector', 'clusterlane' ), 'clusterlane-article-inspector' => __( 'Article Inspector', 'clusterlane' ), 'clusterlane-seo-titles' => __( 'SEO Titles', 'clusterlane' ), 'clusterlane-report' => __( 'Report', 'clusterlane' ), ]; foreach ( $pages as $page => $title ) { $bar->add_node( [ 'parent' => 'clusterlane', 'id' => 'clusterlane-' . str_replace( 'clusterlane-', '', $page ) . '-ab', 'title' => esc_html( $title ), 'href' => $url( $page ) ] ); } } /** The mark as the item's icon, tinted like the toolbar's own icons. */ public static function css(): void { if ( ! self::on() ) return; $logo = \Clusterlane\Core\Brand::get()['logo_url']; // Our mark is a data: URI (esc_url() would drop it); a custom logo is a URL. $mask = $logo !== '' ? esc_url( $logo ) : esc_attr( \Clusterlane\Core\Brand::menu_icon() ); // Added to the toolbar's own stylesheet, so it loads wherever the toolbar does. wp_add_inline_style( 'admin-bar', '#wpadminbar .clusterlane-ab-icon{width:20px;height:20px;margin-top:6px !important;padding:0 !important}' . '#wpadminbar .clusterlane-ab-icon:before{content:"";display:block;width:20px;height:20px;background-color:currentColor;' . '-webkit-mask:url("' . $mask . '") center/18px no-repeat;mask:url("' . $mask . '") center/18px no-repeat;opacity:.6}' . '#wpadminbar #wp-admin-bar-clusterlane:hover .clusterlane-ab-icon:before{opacity:1}' . '#wpadminbar .clusterlane-ab-inspect > .ab-item{font-weight:600}' . '#wpadminbar .clusterlane-ab-inspect{border-bottom:1px solid rgba(255,255,255,.12);margin-bottom:4px !important;padding-bottom:4px !important}' . '@media screen and (max-width:782px){#wpadminbar #wp-admin-bar-clusterlane{display:block}#wpadminbar #wp-admin-bar-clusterlane .ab-label{display:none}#wpadminbar .clusterlane-ab-icon{width:52px;height:46px;margin:0 !important}#wpadminbar .clusterlane-ab-icon:before{width:52px;height:46px;-webkit-mask-size:30px;mask-size:30px;opacity:.75}}' ); } }