Skip to content

Commit fe07d5e

Browse files
jehervepfefferle
andauthored
Blocks: short-circuit early on sites that do not support blocks (#431)
* Blocks: short-circuit early on sites that do not support blocks Fixes #430 This is typically only the case for sites using a custom version of WordPress, like ClassicPress. * let grunt build the markdown * Check for block support earlier and add filter One can now deactivate the blocks registered by ActivityPub like so: ``` add_filter( 'activitypub_site_supports_blocks', '__return_false' ); ``` * Fix readme (gotta remember to use grunt) * alias function --------- Co-authored-by: Matthias Pfefferle <[email protected]>
1 parent f7ebced commit fe07d5e

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
107107

108108
### Next ###
109109

110+
* Compatibility: allow deactivating blocks registered by the plugin.
111+
* Compatibility: avoid Fatal Errors when using ClassicPress.
110112
* Fixed: fix a typo in a hook name.
111113

112114
### 1.0.0 ###

activitypub.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
namespace Activitypub;
1717

18+
use function Activitypub\site_supports_blocks;
19+
1820
\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
1921

2022
/**
@@ -52,10 +54,13 @@ function init() {
5254
Admin::init();
5355
Hashtag::init();
5456
Shortcodes::init();
55-
Blocks::init();
5657
Mention::init();
5758
Health_Check::init();
5859
Scheduler::init();
60+
61+
if ( site_supports_blocks() ) {
62+
Blocks::init();
63+
}
5964
}
6065
\add_action( 'init', __NAMESPACE__ . '\init' );
6166

includes/functions.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,22 @@ function get_self_link() {
457457
return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . $path ) ) );
458458
}
459459
}
460+
461+
/**
462+
* Check if a site supports the block editor.
463+
*
464+
* @return boolean True if the site supports the block editor, false otherwise.
465+
*/
466+
function site_supports_blocks() {
467+
if ( ! \function_exists( 'register_block_type_from_metadata' ) ) {
468+
return false;
469+
}
470+
471+
/**
472+
* Allow plugins to disable block editor support,
473+
* thus disabling blocks registered by the ActivityPub plugin.
474+
*
475+
* @param boolean $supports_blocks True if the site supports the block editor, false otherwise.
476+
*/
477+
return apply_filters( 'activitypub_site_supports_blocks', true );
478+
}

readme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
107107

108108
= Next =
109109

110+
* Compatibility: allow deactivating blocks registered by the plugin.
111+
* Compatibility: avoid Fatal Errors when using ClassicPress.
110112
* Fixed: fix a typo in a hook name.
111113

112114
= 1.0.0 =

0 commit comments

Comments
 (0)