* Only load Interactivity API if enabled

* Use requires again inside wp-html

* Check if class exist instead of plugin

* Remove `wp-html.php` file
This commit is contained in:
David Arenas 2023-03-02 13:46:27 +01:00 committed by GitHub
parent 4b82793b33
commit 96c6b47cd6
3 changed files with 29 additions and 12 deletions

View File

@ -1,8 +0,0 @@
<?php
if ( ! class_exists( 'WP_HTML_Tag_Processor' ) ) {
include __DIR__ . '/../../../../gutenberg/lib/compat/wordpress-6.2/html-api/class-wp-html-attribute-token.php';
include __DIR__ . '/../../../../gutenberg/lib/compat/wordpress-6.2/html-api/class-wp-html-span.php';
include __DIR__ . '/../../../../gutenberg/lib/compat/wordpress-6.2/html-api/class-wp-html-text-replacement.php';
include __DIR__ . '/../../../../gutenberg/lib/compat/wordpress-6.2/html-api/class-wp-html-tag-processor.php';
}

View File

@ -1,6 +1,4 @@
<?php
require_once __DIR__ . '/directives/wp-html.php';
require_once __DIR__ . '/directives/class-woo-directive-context.php';
require_once __DIR__ . '/directives/class-woo-directive-store.php';
require_once __DIR__ . '/directives/woo-process-directives.php';

View File

@ -287,6 +287,33 @@ function woocommerce_blocks_plugin_outdated_notice() {
add_action( 'admin_notices', 'woocommerce_blocks_plugin_outdated_notice' );
// Include the Interactivity API.
require_once __DIR__ . '/src/Interactivity/woo-directives.php';
/**
* Disable the Interactivity API if the required `WP_HTML_Tag_Processor` class
* doesn't exist, regardless of whether it was enabled manually.
*
* @param bool $enabled Current filter value.
* @return bool True if _also_ the `WP_HTML_Tag_Processor` class was found.
*/
function woocommerce_blocks_has_wp_html_tag_processor( $enabled ) {
return $enabled && class_exists( 'WP_HTML_Tag_Processor' );
}
add_filter(
'woocommerce_blocks_enable_interactivity_api',
'woocommerce_blocks_has_wp_html_tag_processor',
999
);
/**
* Load and setup the Interactivity API if enabled.
*/
function woocommerce_blocks_interactivity_setup() {
$is_enabled = apply_filters(
'woocommerce_blocks_enable_interactivity_api',
false
);
if ( $is_enabled ) {
require_once __DIR__ . '/src/Interactivity/woo-directives.php';
}
}
add_action( 'plugins_loaded', 'woocommerce_blocks_interactivity_setup' );