Skip to content

Commit e08d739

Browse files
committed
check if site supports blocks before loading them
1 parent d743ab0 commit e08d739

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

includes/functions.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,3 +685,31 @@ function is_html( $string ) { // phpcs:ignore Universal.NamingConventions.NoRese
685685
return ( wp_strip_all_tags( $string ) !== $string );
686686
}
687687
}
688+
689+
/**
690+
* Check if a site supports the block editor.
691+
*
692+
* @return boolean True if the site supports the block editor, false otherwise.
693+
*/
694+
function site_supports_blocks() {
695+
$return = true;
696+
697+
if ( \version_compare( \get_bloginfo( 'version' ), '5.9', '<' ) ) {
698+
$return = false;
699+
} elseif ( \function_exists( 'classicpress_version' ) ) {
700+
$return = false;
701+
} elseif (
702+
! \function_exists( 'register_block_type_from_metadata' ) ||
703+
! \function_exists( 'do_blocks' )
704+
) {
705+
$return = false;
706+
}
707+
708+
/**
709+
* Allow plugins to disable block editor support,
710+
* thus disabling blocks registered by the Webmentions plugin.
711+
*
712+
* @param boolean $supports_blocks True if the site supports the block editor, false otherwise.
713+
*/
714+
return apply_filters( 'webmention_site_supports_blocks', $return );
715+
}

webmention.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,11 @@ function init() {
120120
require_once __DIR__ . '/includes/class-discovery.php';
121121
add_action( 'init', array( '\Webmention\Discovery', 'init' ) );
122122

123-
// initialize Webmention Bloks.
124-
require_once __DIR__ . '/includes/class-block.php';
125-
add_action( 'init', array( '\Webmention\Block', 'init' ) );
123+
if ( site_supports_blocks() ) {
124+
// initialize Webmention Bloks.
125+
require_once __DIR__ . '/includes/class-block.php';
126+
add_action( 'init', array( '\Webmention\Block', 'init' ) );
127+
}
126128

127129
// load local avatar store.
128130
if ( WEBMENTION_LOCAL_AVATAR_STORE ) {

0 commit comments

Comments
 (0)