final class Meta_Schema

A class for validating input patterns and types for Meta stored in the database.

Properties

string $type
mixed $pattern
array $args

Methods

__construct(string $type, mixed $pattern = null, array $args = array())

Construct the Meta Schema with expressions, types, and defaults.

static bool
validate_pattern(string $pattern)

Validate whether or not a passed string is a valid RegExp.

WP_Error|true
validate(mixed $data, string[] $trace = array())

Validate the data based on this Schema.

mixed
generate_default()

Generate a default set of data based of of the Schema.

static string
create_error_message(WP_Error $Error)

Return an HTML list of validation errors.

Details

at line 53
final __construct(string $type, mixed $pattern = null, array $args = array())

Construct the Meta Schema with expressions, types, and defaults.

Parameters

string $type

The variable type that the Meta Schema should have.

mixed $pattern

The regular expression to validate the Meta value by. Only the 'string', type is required to have a pattern. Arrays types can accept a regular expressions, associative array, or Meta Schema class for the pattern.

array $args

Extra Arguments passed to the Schema. Can include a default value, extra information about the pattern, and allow NULL values.

at line 98
final static bool validate_pattern(string $pattern)

Validate whether or not a passed string is a valid RegExp.

Credit to https://stackoverflow.com/questions/10778318/test-if-a-string-is-regex

Parameters

string $pattern

The pattern to test for RegExp similarities.

Return Value

bool

Whether or not the pattern is a valid regular expression.

at line 110
final WP_Error|true validate(mixed $data, string[] $trace = array())

Validate the data based on this Schema.

Parameters

mixed $data

The data passed from the Meta (usually) to validate against this Schema.

string[] $trace

A list of $keys for providing recursive information.

Return Value

WP_Error|true

Return TRUE if the data passes validation, else return a WP Error with details.

at line 125
final mixed generate_default()

Generate a default set of data based of of the Schema.

Return Value

mixed

The default data to use.

at line 332
final static string create_error_message(WP_Error $Error)

Return an HTML list of validation errors.

Parameters

WP_Error $Error

The error to pull validation error messages from.

Return Value

string

An HTML list of validation errors.