page = $page; } /** * Hook the menu. */ public function register(): void { add_action( 'admin_menu', array( $this, 'add_menu' ) ); } /** * The menu icon: the logo as a one-colour SVG data URI, which WordPress tints per admin colour scheme. * Falls back to a dashicon when the file cannot be read. */ private function icon(): string { $svg = file_get_contents( CONSENTFOLD_DIR . 'assets/images/logo.svg' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents,WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown -- Local plugin file. if ( false === $svg ) { return 'dashicons-privacy'; } // WordPress repaints `fill` attributes, so the brand colour is replaced by a neutral one it can swap. return 'data:image/svg+xml;base64,' . base64_encode( str_replace( '#6652f1', '#a7aaad', $svg ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Required for a data URI. } /** * Add the menu entry. */ public function add_menu(): void { $hook_suffix = add_menu_page( __( 'Consentfold', 'consentfold' ), __( 'Consentfold', 'consentfold' ), Capabilities::MANAGE, self::SLUG, array( $this->page, 'render' ), $this->icon(), 80 ); if ( is_string( $hook_suffix ) ) { $this->page->set_hook_suffix( $hook_suffix ); } } }