Validates template tag callback arguments against an arguments definition.
Description
See also
Parameters
- $tag_args
-
(array) (Required) Template tag callback arguments.
- $tag_args_definition
-
(array) (Required) Template tag callback arguments definition as an array of scalar $type values.
Return
(array) Validated template tag callback arguments.
Source
File: src/components/template-tag-handler.php
private function validate_tag_args( $tag_args, $tag_args_definition ) { if ( count( $tag_args ) !== count( $tag_args_definition ) ) { /* translators: %s: template tag handler slug */ throw new InvalidArgumentException( sprintf( __( 'Invalid template tag arguments passed to handler %s.', 'torro-forms' ), $this->slug ) ); } $valid = true; foreach ( $tag_args as $index => $tag_arg ) { switch ( $tag_args_definition[ $index ] ) { case 'string': case 'int': case 'float': case 'bool': if ( ! call_user_func( 'is_' . $tag_args_definition[ $index ], $tag_arg ) ) { $valid = false; } break; default: if ( ! is_a( $tag_arg, $tag_args_definition[ $index ] ) ) { $valid = false; } } } if ( ! $valid ) { /* translators: %s: template tag handler slug */ throw new InvalidArgumentException( sprintf( __( 'Invalid template tag arguments passed to handler %s.', 'torro-forms' ), $this->slug ) ); } return $tag_args; }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |