WP_Interactivity_API::data_wp_context_processor
Processes the data-wp-context directive.
It adds the context defined in the directive value to the stack so that it's available for the nested interactivity elements.
Method of the class: WP_Interactivity_API{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->data_wp_context_processor( $p, $mode );
- $p(WP_Interactivity_API_Directives_Processor) (required)
- The directives processor instance.
- $mode(string) (required)
- Whether the processing is entering or exiting the tag.
Changelog
| Since 6.5.0 | Introduced. |
WP_Interactivity_API::data_wp_context_processor() WP Interactivity API::data wp context processor code WP 7.0
private function data_wp_context_processor( WP_Interactivity_API_Directives_Processor $p, string $mode ) {
// When exiting tags, it removes the last context from the stack.
if ( 'exit' === $mode ) {
array_pop( $this->context_stack );
return;
}
$entries = $this->get_directive_entries( $p, 'context' );
$context = end( $this->context_stack ) !== false ? end( $this->context_stack ) : array();
foreach ( $entries as $entry ) {
if ( null !== $entry['suffix'] ) {
continue;
}
$context = array_replace_recursive(
$context,
array( $entry['namespace'] => is_array( $entry['value'] ) ? $entry['value'] : array() )
);
}
$this->context_stack[] = $context;
}