Parse the HTML element and get all the valid directives with the given prefix.
Parameters
$pWP_Interactivity_API_Directives_Processorrequired- The directives processor instance.
$prefixstringrequired- The directive prefix to filter by.
Source
private function get_directive_entries( WP_Interactivity_API_Directives_Processor $p, string $prefix ) {
$directive_attributes = $p->get_attribute_names_with_prefix( 'data-wp-' . $prefix );
$entries = array();
foreach ( $directive_attributes as $attribute_name ) {
[ 'prefix' => $attr_prefix, 'suffix' => $suffix, 'unique_id' => $unique_id] = $this->parse_directive_name( $attribute_name );
// Ensure it is the desired directive.
if ( $prefix !== $attr_prefix ) {
continue;
}
list( $namespace, $value ) = $this->extract_directive_value( $p->get_attribute( $attribute_name ), end( $this->namespace_stack ) );
$entries[] = array(
'namespace' => $namespace,
'value' => $value,
'suffix' => $suffix,
'unique_id' => $unique_id,
);
}
// Sort directive entries to ensure stable ordering with the client.
// Put nulls first, then sort by suffix and finally by uniqueIds.
usort(
$entries,
function ( $a, $b ) {
$a_suffix = $a['suffix'] ?? '';
$b_suffix = $b['suffix'] ?? '';
if ( $a_suffix !== $b_suffix ) {
return $a_suffix < $b_suffix ? -1 : 1;
}
$a_id = $a['unique_id'] ?? '';
$b_id = $b['unique_id'] ?? '';
if ( $a_id === $b_id ) {
return 0;
}
return $a_id > $b_id ? 1 : -1;
}
);
return $entries;
}
Changelog
| Version | Description |
|---|---|
| 6.9.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.