| @@ -7,12 +7,17 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Extensions\Likes; |
| 9 | 9 | |
| 10 | 10 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 11 | +use Automattic\Jetpack\Modules; | |
| 11 | 12 | use Automattic\Jetpack\Status; |
| 12 | 13 | use Automattic\Jetpack\Status\Host; |
| 13 | 14 | use Jetpack_Gutenberg; |
| 14 | 15 | |
| 16 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 17 | + exit( 0 ); | |
| 18 | +} | |
| 19 | + | |
| 15 | 20 | /** |
| 16 | 21 | * Register Likes plugin. |
| 17 | 22 | * |
| 18 | 23 | * @return void |
| @@ -17,8 +22,18 @@ | ||
| 17 | 22 | * |
| 18 | 23 | * @return void |
| 19 | 24 | */ |
| 20 | 25 | function register_plugins() { |
| 26 | + /* | |
| 27 | + * The extension is available even when the module is not active, | |
| 28 | + * so we can display a nudge to activate the module instead of the block. | |
| 29 | + * We skip that nudge for non-admins, who cannot activate modules, and on block themes, | |
| 30 | + * where the answer is the Like block in a template rather than the legacy module. | |
| 31 | + */ | |
| 32 | + if ( ! ( new Modules() )->is_active( 'likes' ) && ( ! current_user_can( 'jetpack_activate_modules' ) || wp_is_block_theme() ) ) { | |
| 33 | + return; | |
| 34 | + } | |
| 35 | + | |
| 21 | 36 | // Register Likes. |
| 22 | 37 | if ( |
| 23 | 38 | ( new Host() )->is_wpcom_simple() |
| 24 | 39 | || ( ( new Connection_Manager( 'jetpack' ) )->has_connected_owner() && ! ( new Status() )->is_offline_mode() ) |
| @@ -34,9 +49,9 @@ | ||
| 34 | 49 | */ |
| 35 | 50 | add_action( |
| 36 | 51 | 'rest_api_init', |
| 37 | 52 | function () { |
| 38 | - if ( ! \Jetpack::is_module_active( 'likes' ) ) { | |
| 53 | + if ( ! ( new Modules() )->is_active( 'likes' ) ) { | |
| 39 | 54 | $post_types = get_post_types( array( 'public' => true ) ); |
| 40 | 55 | foreach ( $post_types as $post_type ) { |
| 41 | 56 | add_post_type_support( $post_type, 'jetpack-post-likes' ); |
| 42 | 57 | } |