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 <pfefferle@users.noreply.github.com>
This commit is contained in:
Jeremy Herve 2023-09-15 10:38:47 +02:00 committed by GitHub
parent f7ebced624
commit fe07d5eb32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 1 deletions

View file

@ -107,6 +107,8 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
### Next ### ### Next ###
* Compatibility: allow deactivating blocks registered by the plugin.
* Compatibility: avoid Fatal Errors when using ClassicPress.
* Fixed: fix a typo in a hook name. * Fixed: fix a typo in a hook name.
### 1.0.0 ### ### 1.0.0 ###

View file

@ -15,6 +15,8 @@
namespace Activitypub; namespace Activitypub;
use function Activitypub\site_supports_blocks;
\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' ); \defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
/** /**
@ -52,10 +54,13 @@ function init() {
Admin::init(); Admin::init();
Hashtag::init(); Hashtag::init();
Shortcodes::init(); Shortcodes::init();
Blocks::init();
Mention::init(); Mention::init();
Health_Check::init(); Health_Check::init();
Scheduler::init(); Scheduler::init();
if ( site_supports_blocks() ) {
Blocks::init();
}
} }
\add_action( 'init', __NAMESPACE__ . '\init' ); \add_action( 'init', __NAMESPACE__ . '\init' );

View file

@ -457,3 +457,22 @@ if ( ! function_exists( 'get_self_link' ) ) {
return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . $path ) ) ); return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . $path ) ) );
} }
} }
/**
* Check if a site supports the block editor.
*
* @return boolean True if the site supports the block editor, false otherwise.
*/
function site_supports_blocks() {
if ( ! \function_exists( 'register_block_type_from_metadata' ) ) {
return false;
}
/**
* Allow plugins to disable block editor support,
* thus disabling blocks registered by the ActivityPub plugin.
*
* @param boolean $supports_blocks True if the site supports the block editor, false otherwise.
*/
return apply_filters( 'activitypub_site_supports_blocks', true );
}

View file

@ -107,6 +107,8 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
= Next = = Next =
* Compatibility: allow deactivating blocks registered by the plugin.
* Compatibility: avoid Fatal Errors when using ClassicPress.
* Fixed: fix a typo in a hook name. * Fixed: fix a typo in a hook name.
= 1.0.0 = = 1.0.0 =