WP_CLI
SynopsisValidator::query_spec
Filters a list of associative arrays, based on a set of key => value arguments.
Method of the class: SynopsisValidator{}
No Hooks.
Returns
Array.
Usage
// private - for code of main (parent) class only $result = $this->query_spec( $args, $operator );
- $args(array) (required)
- An array of key => value arguments to match against.
- $operator(string)
- .
Default:'AND'
SynopsisValidator::query_spec() SynopsisValidator::query spec code WP-CLI 2.13.0-alpha
private function query_spec( $args, $operator = 'AND' ) {
$operator = strtoupper( $operator );
$count = count( $args );
$filtered = [];
foreach ( $this->spec as $key => $to_match ) {
$matched = 0;
foreach ( $args as $m_key => $m_value ) {
if ( array_key_exists( $m_key, $to_match ) && $m_value === $to_match[ $m_key ] ) {
++$matched;
}
}
if ( ( 'AND' === $operator && $matched === $count )
|| ( 'OR' === $operator && $matched > 0 )
|| ( 'NOT' === $operator && 0 === $matched ) ) {
$filtered[ $key ] = $to_match;
}
}
return $filtered;
}