diff --git a/includes/functions.php b/includes/functions.php index 1a05d2c..2077fc4 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -685,3 +685,31 @@ function is_html( $string ) { // phpcs:ignore Universal.NamingConventions.NoRese return ( wp_strip_all_tags( $string ) !== $string ); } } + +/** + * Check if a site supports the block editor. + * + * @return boolean True if the site supports the block editor, false otherwise. + */ +function site_supports_blocks() { + $return = true; + + if ( \version_compare( \get_bloginfo( 'version' ), '5.9', '<' ) ) { + $return = false; + } elseif ( \function_exists( 'classicpress_version' ) ) { + $return = false; + } elseif ( + ! \function_exists( 'register_block_type_from_metadata' ) || + ! \function_exists( 'do_blocks' ) + ) { + $return = false; + } + + /** + * Allow plugins to disable block editor support, + * thus disabling blocks registered by the Webmentions plugin. + * + * @param boolean $supports_blocks True if the site supports the block editor, false otherwise. + */ + return apply_filters( 'webmention_site_supports_blocks', $return ); +} diff --git a/webmention.php b/webmention.php index af5ee65..3ff0a91 100755 --- a/webmention.php +++ b/webmention.php @@ -120,9 +120,11 @@ function init() { require_once __DIR__ . '/includes/class-discovery.php'; add_action( 'init', array( '\Webmention\Discovery', 'init' ) ); - // initialize Webmention Bloks. - require_once __DIR__ . '/includes/class-block.php'; - add_action( 'init', array( '\Webmention\Block', 'init' ) ); + if ( site_supports_blocks() ) { + // initialize Webmention Bloks. + require_once __DIR__ . '/includes/class-block.php'; + add_action( 'init', array( '\Webmention\Block', 'init' ) ); + } // load local avatar store. if ( WEBMENTION_LOCAL_AVATAR_STORE ) {