Skip to content

Architecture

Stacko Accessibility has a small PHP back end and a TypeScript front end. PHP handles permissions, signed scan requests, storage and the REST API. All checking happens in the browser.

Item Value
Plugin slug and text domain stacko-accessibility
PHP namespace Stacko\Accessibility
Constants STACKO_A11Y_VERSION, STACKO_A11Y_FILE, STACKO_A11Y_DIR, STACKO_A11Y_URL
Option, meta and hook prefix stacko_a11y_
Database tables {$wpdb->prefix}stacko_a11y_*
REST namespace stacko-a11y/v1
Requirements WordPress 6.9+, PHP 8.1+

The plugin boots on plugins_loaded. Database migrations run on admin_init when the stored schema version is behind.

The engine in src/engine/ is framework-free TypeScript. It wraps axe-core (4.14 at the time of writing) and adds Stacko’s own rules, written as axe rules and checks so they run in the same pass. axe-core is loaded with a dynamic import when the first scan starts, never up front.

A scan:

  1. Runs axe-core on the document, limited by tags for the chosen standard. The stacko tag is always included, and best-practice is added when that setting is on.
  2. Always excludes #wpadminbar, the inspector’s own UI and any element with a data-stacko-ignore attribute.
  3. Turns axe violations into must (critical or serious impact) or should (moderate or minor) issues, and axe’s incomplete results into review issues.
  4. Gives each issue a scope. Elements inside main, [role="main"], .wp-block-post-content or .entry-content are content. Other elements in headers, footers, navigation, sidebars and template parts are site.
  5. Gives each issue a 32-character fingerprint: a hash of the rule id, the selector and the HTML snippet, after numbers and long hex tokens are normalised and nonce, data-nonce, data-sa-path, srcset and sizes attributes are removed. The fingerprint stays the same across rescans, so ignores survive and site-wide issues can be de-duplicated across pages.
  6. Calculates a score from 0 to 100, weighted by impact.

Each scan records a rules_version so stored results show which version of the Stacko rules found them.

includes/Editor/EditorPanel.php loads the editor bundle on the post editor only (not the site editor or widgets screen), for post types chosen in settings, for users who may scan the post.

  • Live checks (src/editor/live-rules.ts) read the block tree from the core/block-editor store. They don’t render anything. They run on every change, debounced by 600 ms.
  • Full check (src/editor/full-scan.ts) loads a signed preview URL in two hidden iframes, 1280 px and 375 px wide. A small runner script in the iframe runs the engine and sends the result to the editor with postMessage (same origin only). Issues are merged, tagged by viewport, mapped back to blocks and saved through the REST API.
  • Fixes change block attributes through the block editor data store, so undo and revisions work as normal.

The sidebar is a Vue 3 app. A thin React shell registers the plugin with wp.plugins and PluginSidebar, then mounts the Vue app into the slot.

includes/Scan/ScanRequest.php handles preview requests that carry a stacko_a11y_scan query parameter. The value is a nonce for that post, and the user must be allowed to scan it. For a valid request, the plugin:

  • hides the admin bar so the page looks like it does for visitors,
  • adds data-sa-path="index:blockName" to the first element of each block in the post content. The index is the block’s position in a depth-first walk, the same order the editor uses. Blocks inside synced patterns are not numbered separately.
  • loads the runner script,
  • sends no-cache headers and a noindex robots directive.

Without a valid signature none of this happens, so visitors never see data-sa-path attributes.

includes/Frontend/Inspector.php adds an admin bar node and a small launcher script, only when the admin bar is showing and the user may scan the current page. The inspector app and axe-core load when the button is clicked. Adding ?stacko-a11y-inspect=1 to a URL opens the inspector on load.

The inspector UI is mounted in a Shadow DOM root, so theme CSS can’t affect it. It scans the live document at the current window width and saves the result with context: frontend.

The Site scan screen requests the queue from GET /queue. Each item includes a signed scan URL. The browser checks pages one at a time, each at both widths in hidden iframes, and posts every result to POST /scans. Progress is kept in localStorage (stacko-a11y-site-scan) so a paused or reloaded run can continue. The server does no scanning.

Nothing. Every script is enqueued only after a permission check for a logged-in user. The admin bar node, the inspector launcher and the runner all check permissions first. The runner also needs a valid nonce.

includes/Core/Permissions.php holds every capability check, so REST routes and the UI agree.

Check Rule
can_use_checker() Logged in, and either has manage_options or has a role from the Who sees the checker setting plus edit_posts
can_scan( $post_id ) can_use_checker(), plus edit_post for that post, or edit_posts when the post id is 0
can_ignore( $post_id, $scope ) can_use_checker(), plus edit_theme_options for site-wide issues, or edit_post for content issues

Settings and the site scan queue need manage_options.

Table Contents
stacko_a11y_scans One row per scan: object type (post or url), object id, URL and URL hash, context (editor, frontend or queue), score, must/should/review counts, rules version, user id and time
stacko_a11y_issues Issues of each scan: fingerprint, rule id, level, scope, viewport, selector, block path and HTML snippet
stacko_a11y_ignores Ignored issues: fingerprint, object id (0 for site-wide), rule id, reason, note, user id and time. Unique on fingerprint plus object id.

Only the last 5 scans of each post or URL are kept. Older scans and their issues are deleted when a new scan is saved. Selectors are stored up to 1,000 characters and snippets up to 300. Snippets are stored as plain text and escaped on output.

Ignores live in their own table, keyed by fingerprint, so they are not lost when issue rows are replaced by a new scan.

Key Type Contents
stacko_a11y_settings Option All settings, read and sanitised through Core\Settings
stacko_a11y_db_version Option Schema version used for migrations
stacko_a11y_onboarded Option First-run flag
stacko_a11y_summary Post meta Last score, counts and scan time of a post. Used by the list column, the admin bar badge and the queue, so they need no extra queries.
Key Type Default
post_types string[] ["post", "page"]
standard wcag21aa, wcag22aa or wcag22aaa wcag22aa
best_practices boolean true
include_site_parts boolean true
live_checks boolean true
checker_roles string[] ["administrator", "editor", "author"]
delete_on_uninstall boolean false

Unknown keys are dropped. Post types must have show_ui, and roles must exist.

Deactivation removes nothing. On uninstall, if delete_on_uninstall is true, the plugin drops its three tables and deletes its options and the stacko_a11y_summary post meta. Otherwise all data is kept.

The readable source of all JavaScript and CSS is in src/. Build it with:

Terminal window
npm install && npm run build

The front end uses Vue 3, TypeScript and Tailwind CSS, built with Vite. A PHP Assets class reads the Vite manifest to enqueue the right files. Script translations use @wordpress/i18n and wp_set_script_translations().