Skip to content

Commit

Permalink
check if site supports blocks before loading them
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle committed Nov 14, 2024
1 parent d743ab0 commit e08d739
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
28 changes: 28 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
8 changes: 5 additions & 3 deletions webmention.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit e08d739

Please sign in to comment.