started ) { return; } $this->started = true; add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_public_assets' ) ); if ( is_admin() ) { $admin = new BitHub_Accessibility_Admin(); $admin->register_hooks(); } } /** * Loads the local loader and injects only the public configuration. * * @return void */ public function enqueue_public_assets() { $settings = self::get_settings(); if ( empty( $settings['enabled'] ) || empty( $settings['service_consent'] ) || empty( $settings['license_key'] ) ) { return; } $handle = 'bithub-accessibility'; wp_register_script( $handle, BITHUB_ACCESSIBILITY_URL . 'assets/js/bithub-accessibility-loader.js', array(), BITHUB_ACCESSIBILITY_VERSION, false ); $configuration = array( 'licenseKey' => $settings['license_key'], 'endpoint' => self::VERIFICATION_URL, 'widgetScriptUrl' => self::WIDGET_SCRIPT_URL, ); wp_add_inline_script( $handle, 'window.BH_CONFIG = ' . wp_json_encode( $configuration ) . ';', 'before' ); wp_enqueue_script( $handle ); } /** * Returns normalized plugin settings. * * @return array{license_key:string,enabled:int,service_consent:int} */ public static function get_settings() { $defaults = array( 'license_key' => '', 'enabled' => 0, 'service_consent' => 0, ); $settings = get_option( self::OPTION_NAME, array() ); return wp_parse_args( is_array( $settings ) ? $settings : array(), $defaults ); } /** * Returns the normalized host configured in WordPress. * * @return string */ public static function get_site_domain() { $host = wp_parse_url( home_url( '/' ), PHP_URL_HOST ); $host = is_string( $host ) ? strtolower( untrailingslashit( $host ) ) : ''; if ( 0 === strpos( $host, 'www.' ) ) { $host = substr( $host, 4 ); } return $host; } }