File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -117,11 +117,38 @@ public function add_menu_page() {
117117 'manage_options ' ,
118118 self ::SLUG ,
119119 array ( $ this , 'render_settings_page ' ),
120- ' dashicons-analytics ' ,
120+ $ this -> get_menu_icon () ,
121121 null
122122 );
123123 }
124124
125+ /**
126+ * Get the monochrome Basicrum mark for the WordPress admin menu.
127+ *
128+ * WordPress recolors base64-encoded SVG menu icons to match the active admin
129+ * color scheme. Fall back to the analytics Dashicon if the packaged SVG
130+ * cannot be read.
131+ *
132+ * @return string SVG data URI or Dashicon class.
133+ */
134+ private function get_menu_icon () {
135+ $ icon_path = Helpers::get_asset_path ( 'images/basicrum-menu-icon.svg ' );
136+
137+ if ( ! is_readable ( $ icon_path ) ) {
138+ return 'dashicons-analytics ' ;
139+ }
140+
141+ // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Reading a trusted packaged SVG.
142+ $ svg = file_get_contents ( $ icon_path );
143+
144+ if ( false === $ svg || '' === trim ( $ svg ) ) {
145+ return 'dashicons-analytics ' ;
146+ }
147+
148+ // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Required for a WordPress SVG menu icon data URI.
149+ return 'data:image/svg+xml;base64, ' . base64_encode ( $ svg );
150+ }
151+
125152 /**
126153 * Register all settings, sections, and fields.
127154 *
Original file line number Diff line number Diff line change @@ -76,6 +76,34 @@ function( $path ) {
7676 $ this ->assertStringContainsString ( 'height="48" ' , $ html );
7777 }
7878
79+ /**
80+ * Test the top-level menu uses the packaged monochrome Basicrum mark.
81+ */
82+ public function test_admin_menu_uses_packaged_brand_icon () {
83+ $ menu_arguments = null ;
84+
85+ Functions \when ( 'add_menu_page ' )->alias (
86+ function () use ( &$ menu_arguments ) {
87+ $ menu_arguments = func_get_args ();
88+ }
89+ );
90+
91+ $ page = new Page ();
92+ $ page ->add_menu_page ();
93+
94+ $ this ->assertIsArray ( $ menu_arguments );
95+ $ this ->assertArrayHasKey ( 5 , $ menu_arguments );
96+ $ this ->assertStringStartsWith ( 'data:image/svg+xml;base64, ' , $ menu_arguments [5 ] );
97+
98+ $ encoded_svg = substr ( $ menu_arguments [5 ], strlen ( 'data:image/svg+xml;base64, ' ) );
99+ $ svg = base64_decode ( $ encoded_svg , true );
100+
101+ $ this ->assertIsString ( $ svg );
102+ $ this ->assertStringContainsString ( 'viewBox="0 0 24 24" ' , $ svg );
103+ $ this ->assertStringContainsString ( 'style="fill:#a7aaad" ' , $ svg );
104+ $ this ->assertStringContainsString ( 'M0 4h4v16H0z ' , $ svg );
105+ }
106+
79107 /**
80108 * Set up WordPress function stubs.
81109 */
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ require_entry 'basicrum/assets/js/integrations/cookieyes.js'
5252require_entry ' basicrum/assets/js/integrations/generic-opt-in.js'
5353require_entry ' basicrum/assets/js/integrations/generic-opt-out.js'
5454require_entry ' basicrum/assets/images/basicrum-logo.png'
55+ require_entry ' basicrum/assets/images/basicrum-menu-icon.svg'
5556require_entry ' basicrum/languages/basicrum.pot'
5657
5758if printf ' %s\n' " $ARCHIVE_ENTRIES " | grep -Fqx ' basicrum/assets/js/loaders/consent-api.js' ; then
You can’t perform that action at this time.
0 commit comments