'gutenberg_interactivity_process_wp_bind', 'data-wp-context' => 'gutenberg_interactivity_process_wp_context', 'data-wp-class' => 'gutenberg_interactivity_process_wp_class', 'data-wp-style' => 'gutenberg_interactivity_process_wp_style', 'data-wp-text' => 'gutenberg_interactivity_process_wp_text', ); $tags = new WP_Directive_Processor( $block_content ); $tags = $tags->process_rendered_html( $tags, 'data-wp-', $directives ); return $tags->get_updated_html(); } return $block_content; } add_filter( 'render_block', 'gutenberg_process_directives_in_root_blocks', 10, 2 ); /** * Resolve the reference using the store and the context from the provided path. * * @param string $path Path. * @param array $context Context data. * @return mixed */ function gutenberg_interactivity_evaluate_reference( $path, array $context = array() ) { $store = array_merge( WP_Interactivity_Store::get_data(), array( 'context' => $context ) ); /* * Check first if the directive path is preceded by a negator operator (!), * indicating that the value obtained from the Interactivity Store (or the * passed context) using the subsequent path should be negated. */ $should_negate_value = '!' === $path[0]; $path = $should_negate_value ? substr( $path, 1 ) : $path; $path_segments = explode( '.', $path ); $current = $store; foreach ( $path_segments as $p ) { if ( isset( $current[ $p ] ) ) { $current = $current[ $p ]; } else { return null; } } /* * Check if $current is an anonymous function or an arrow function, and if * so, call it passing the store. Other types of callables are ignored on * purpose, as arbitrary strings or arrays could be wrongly evaluated as * "callables". * * E.g., "file" is an string and a "callable" (the "file" function exists). */ if ( $current instanceof Closure ) { $current = call_user_func( $current, $store ); } // Return the opposite if it has a negator operator (!). return $should_negate_value ? ! $current : $current; }