PHP handles the registration and configuration of your checks โ defining their metadata and exposing options to the block editor. The actual validation logic runs in JavaScript, ensuring the editing experience remains fast, responsive, and seamless.
Registering Checks
Use the ba11yc_ready action to register your custom checks once the Block Accessibility Checks plugin is fully initialized. Always confirm that the plugin is active by checking for the ba11yc_init_plugin function before registering your checks.
// Check if Block Accessibility Checks plugin is available
if ( function_exists( 'ba11yc_init_plugin' ) ) {
    add_action( 'ba11yc_ready', 'my_plugin_register_checks' );
}
function my_plugin_register_checks( $registry ) {
    $registry->register_check(
        'my-plugin/custom-block',
        'content_length',
        array(
            'error_msg'   => __( 'Content is too long for optimal readability', 'my-plugin' ),
            'warning_msg' => __( 'Content is long but still allowed (warning)', 'my-plugin' ),
            'description' => __( 'Long content can be difficult to read', 'my-plugin' ),
            'type'        => 'settings',
            'category'    => 'validation',
            'priority'    => 10,
        )
    );
}
Configuration
Each check includes a set of parameters that define how it behaves in both PHP and the block editor. Some are required, while others are optional for customizing appearance, severity, or order.
Best Practices
- Keep messages clear, concise, and actionable.
 - Always translate strings using 
__()or__e(). - Use consistent naming and categorize checks logically.
 - Reserve high priority (1โ5) for critical checks.
 
Parameters
error_msg (string)
The message displayed in the block editor when the check fails as an error.
It should be clear, actionable, and localized for translation.
'error_msg' => __( 'Image alt text is required for accessibility.', 'my-plugin' )
warning_msg (string)
Shown when the check fails as a warning.
Used only when type is set to 'settings' and configured as a warning.
'warning_msg' => __( 'Consider adding alt text to improve accessibility.', 'my-plugin' )
description (string)
A longer explanation displayed in the settings or admin UI.
Helps site admins understand what the check does and why it matters.
'description' => __( 'Alt text helps screen reader users understand image content.', 'my-plugin' )
type (string)
Controls how the check behaves in both the editor and settings interface.
'type' => 'settings' // Most flexible option
Options
'settings'โ Most flexible; lets site admins choose severity (default).'error'โ Always shown as an error, typically used for critical issues.'warning'โ Always shown as a warning, intended for recommendations.'none'โ Disabled, not yet active.
category (string)
Groups related checks for easier management and organization.
'category' => 'accessibility'
Options
'accessibility'โ WCAG and usability-related checks, use for issues affecting users with disabilities..'validation'โ Content structure and quality checks, use for general content quality..
priority (integer)
Controls the order in which checks are run.
Lower numbers run earlier. Default: 10.
'priority' => 5 // Runs before default priority checks
Guidelines
- 1โ5 โ Critical checks that should run first.
 - 10 โ Default for most checks.
 - 15โ20 โ Lower priority or expensive checks.
 
Settings Integration
Checks registered with 'type' => 'settings' automatically appear in the admin settings UI, allowing site admins to configure severity levels and enable/disable checks.
Admin Path: Settings โ Block Checks โ [Your Plugin Name]
Settings pages are created automatically based on your plugin information. No additional code required.
How It Works
- Register your check with 
'type' => 'settings' - The API automatically creates a settings page for your plugin
 - Site admins can configure each check as:
- Error โ Blocks publishing
 - Warning โ Shows but doesn’t block
 - Disabled โ Check doesn’t run
 
 
Example
// Check if Block Accessibility Checks plugin is available
if ( function_exists( 'ba11yc_init_plugin' ) ) {
    add_action( 'ba11yc_ready', 'my_plugin_register_checks' );
}
function my_plugin_register_checks( $registry ) {
    $registry->register_check(
        'my-plugin/custom-block',
        'my_check',
        array(
            'error_msg'   => __( 'This is required.', 'my-plugin' ),
            'warning_msg' => __( 'This is recommended.', 'my-plugin' ),
            'description' => __( 'Explanation for admins.', 'my-plugin' ),
            'type'        => 'settings', // โ Enables settings page
            'category'    => 'accessibility',
        )
    );
}
Multiple Checks for One Block
You can register multiple checks for a single block type. Each check is independent and can have different configuration.
// Check if Block Accessibility Checks plugin is available
if ( function_exists( 'ba11yc_init_plugin' ) ) {
    add_action( 'ba11yc_ready', 'my_plugin_register_checks' );
}
function my_plugin_register_checks( $registry ) {
    $block_type = 'my-plugin/card-block';
    
    // Required title check
    $registry->register_check( $block_type, 'title_required', [
        'error_msg' => __( 'Card title is required.', 'my-plugin' ),
        'type'      => 'error',
        'category'  => 'accessibility',
        'priority'  => 5, // High priority
    ] );
    
    // Image alt text check (configurable)
    $registry->register_check( $block_type, 'image_alt_required', [
        'error_msg'   => __( 'Card image requires alt text.', 'my-plugin' ),
        'warning_msg' => __( 'Consider adding alt text.', 'my-plugin' ),
        'type'        => 'settings',
        'category'    => 'accessibility',
        'priority'    => 10, // Default priority
    ] );
    
    // Description length warning
    $registry->register_check( $block_type, 'description_length', [
        'warning_msg' => __( 'Card description should be concise.', 'my-plugin' ),
        'description' => __( 'Keep descriptions under 200 characters.', 'my-plugin' ),
        'type'        => 'warning',
        'category'    => 'validation',
        'priority'    => 15, // Lower priority
    ] );
    
    // Link validation
    $registry->register_check( $block_type, 'valid_link_url', [
        'error_msg'  => __( 'Card link URL is invalid.', 'my-plugin' ),
        'type'       => 'error',
        'category'   => 'validation',
        'priority'   => 10,
    ] );
}
Best Practices for Multiple Checks
- Use meaningful names: 
'title_required'is better than'check1' - Set appropriate priorities: Critical checks should run first
 - Use consistent naming: Follow a pattern like 
'{field}_{validation_type}' - Group related checks: Use the same category for similar checks
 - Consider user experience: Don’t overwhelm users with too many checks