'; } public function enqueue_assets( string $hook_suffix ): void { if ( ! str_contains( $hook_suffix, self::SLUG ) ) { return; } $asset_file = WPAG_PLUGIN_DIR . 'assets/admin/build/index.asset.php'; if ( ! file_exists( $asset_file ) ) { // Built assets are missing. End users should never see this in production // (they install a pre-built ZIP). Show a developer-friendly notice only // when WP_DEBUG is enabled; otherwise stay silent so the admin UI is not // cluttered with technical jargon. if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { add_action( 'admin_notices', static function (): void { echo '

Instintia EAA Reports '; esc_html_e( '(developer notice): admin assets are missing. If you are running from source, execute `npm install && npm run build` inside the plugin directory. End users should install the pre-built ZIP from the official release.', 'accessibility-guard-eaa-toolkit' ); echo '

'; } ); } else { add_action( 'admin_notices', static function (): void { echo '

Instintia EAA Reports: '; esc_html_e( 'the plugin is incomplete. Please reinstall it using the official ZIP package from your provider.', 'accessibility-guard-eaa-toolkit' ); echo '

'; } ); } return; } $asset = include $asset_file; $script_file = WPAG_PLUGIN_DIR . 'assets/admin/build/index.js'; $version = file_exists( $script_file ) ? WPAG_VERSION . '-' . (string) filemtime( $script_file ) : WPAG_VERSION; wp_enqueue_script( 'wpag-admin', WPAG_PLUGIN_URL . 'assets/admin/build/index.js', $asset['dependencies'] ?? [], $version, true ); $style_relative = file_exists( WPAG_PLUGIN_DIR . 'assets/admin/build/style-index.css' ) ? 'assets/admin/build/style-index.css' : 'assets/admin/build/index.css'; if ( file_exists( WPAG_PLUGIN_DIR . $style_relative ) ) { wp_enqueue_style( 'wpag-admin', WPAG_PLUGIN_URL . $style_relative, [ 'wp-components' ], $version ); } wp_set_script_translations( 'wpag-admin', 'accessibility-guard-eaa-toolkit' ); wp_localize_script( 'wpag-admin', 'WPAG', [ 'restUrl' => esc_url_raw( rest_url( 'wpag/v1/' ) ), 'axeUrl' => esc_url_raw( WPAG_PLUGIN_URL . 'assets/admin/vendor/axe.min.js' ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'siteUrl' => esc_url_raw( home_url( '/' ) ), 'version' => WPAG_VERSION, 'pageSlug' => sanitize_text_field( wp_unslash( $_GET['page'] ?? self::SLUG ) ), // phpcs:ignore WordPress.Security.NonceVerification ] ); wp_add_inline_script( 'wpag-admin', 'window.wp&&window.wp.apiFetch&&window.wp.apiFetch.use(function(options,next){if(options&&options.path&&/^(dashboard|settings|scans|statement)(\/|\?|$)/.test(options.path)){options=Object.assign({},options,{url:' . wp_json_encode( esc_url_raw( rest_url( 'wpag/v1/' ) ) ) . '.replace(/\/$/,"")+"/"+String(options.path).replace(/^\//,"")});delete options.path;}return next(options);});', 'before' ); } }