Skip to content

Latest commit

 

History

History
165 lines (122 loc) · 4.97 KB

File metadata and controls

165 lines (122 loc) · 4.97 KB

API Reference

All public registration functions, registry methods, and contracts.

Global Functions

validation_api_register_block_check()

Register a validation check for a block type.

validation_api_register_block_check( string $block_type, array $args ): void
Parameter Type Description
$block_type string Block type name (e.g., 'core/image').
$args array Check configuration (see Check Arguments). Must include 'namespace'.

validation_api_register_meta_check()

Register a validation check for a post meta field.

validation_api_register_meta_check( string $post_type, array $args ): void
Parameter Type Description
$post_type string Post type (e.g., 'post', 'page').
$args array Check configuration. Must include 'namespace' and 'meta_key'. See Check Arguments.

validation_api_register_editor_check()

Register a validation check for the editor (document-level).

validation_api_register_editor_check( string $post_type, array $args ): void
Parameter Type Description
$post_type string Post type (e.g., 'post', 'page').
$args array Check configuration (see Check Arguments). Must include 'namespace'.

validation_api_init_plugin()

Initialize the Validation API plugin. Called internally on init. Not intended for external use.

validation_api_init_plugin(): void

Check Arguments

All registration functions accept an $args array with the following keys:

Key Type Required Default Description
namespace string Yes Identifier for the plugin registering this check
name string Yes Unique identifier for this check within its scope
error_msg string Yes Message shown when the check fails at error level
warning_msg string No Same as error_msg Message shown at warning level
level string No 'error' Severity: 'error', 'warning', or 'none'
description string No '' Human-readable description (shown in REST API, companion settings)
priority int No 10 Execution order (lower runs first)
enabled bool No true Whether the check is active

Meta checks only:

Key Type Required Description
meta_key string Yes The post meta key to validate

Registry Classes

These are the internal registry singletons. Most integrations should use the global functions above. Registry methods are documented here for contributors and advanced use cases.

ValidationAPI\Block\Registry

Singleton. Access via BlockRegistry::get_instance().

register_check( string $block_type, string $check_name, array $check_args ): bool
get_checks( string $block_type ): array
get_all_checks(): array
is_check_registered( string $block_type, string $check_name ): bool
get_check_config( string $block_type, string $check_name ): ?array
get_registered_block_types(): array
get_effective_check_level( string $block_type, string $check_name ): string

ValidationAPI\Editor\Registry

Singleton. Access via EditorRegistry::get_instance().

register_editor_check( string $post_type, string $check_name, array $check_args ): bool
get_editor_checks( string $post_type ): array
get_all_editor_checks(): array
get_editor_check_config( string $post_type, string $check_name ): ?array
get_effective_editor_check_level( string $post_type, string $check_name ): string

ValidationAPI\Meta\Registry

Singleton. Access via MetaRegistry::get_instance().

register_meta_check( string $post_type, string $meta_key, string $check_name, array $check_args ): bool
get_meta_checks( string $post_type ): array
get_all_meta_checks(): array
get_meta_check_config( string $post_type, string $meta_key, string $check_name ): ?array
get_effective_meta_check_level( string $post_type, string $meta_key, string $check_name ): string

REST API

GET /wp-validation/v1/checks

Returns all registered checks across all three scopes.

Permission: manage_options

Response:

{
    "block": {
        "core/image": {
            "alt_text": {
                "level": "error",
                "description": "Images must have alt text",
                "error_msg": "This image is missing alt text.",
                "warning_msg": "Consider adding alt text.",
                "priority": 10,
                "enabled": true,
                "_namespace": "my-rules"
            }
        }
    },
    "meta": {
        "post": {
            "seo_description": {
                "required": { ... }
            }
        }
    },
    "editor": {
        "post": {
            "heading_hierarchy": { ... }
        }
    }
}

Constants

VALIDATION_API_VERSION

define( 'VALIDATION_API_VERSION', '1.0.0' );

The current plugin version.