| @@ -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,19 @@ | ||
| 17 | 22 | * |
| 18 | 23 | * @return void |
| 19 | 24 | */ |
| 20 | 25 | function register_plugins() { |
| 26 | + $modules = new Modules(); | |
| 27 | + | |
| 28 | + // The panel's per-post switch applies to Like buttons and Comment Likes alike. | |
| 29 | + $shows_switch = $modules->is_active( 'likes' ) || $modules->is_active( 'comment-likes' ); | |
| 30 | + | |
| 31 | + // Without it, the panel can only nudge to activate Likes. Skip that for users who can't, | |
| 32 | + // and on block themes, where the Like block in a template replaces the legacy module. | |
| 33 | + if ( ! $shows_switch && ( ! current_user_can( 'jetpack_activate_modules' ) || wp_is_block_theme() ) ) { | |
| 34 | + return; | |
| 35 | + } | |
| 36 | + | |
| 21 | 37 | // Register Likes. |
| 22 | 38 | if ( |
| 23 | 39 | ( new Host() )->is_wpcom_simple() |
| 24 | 40 | || ( ( new Connection_Manager( 'jetpack' ) )->has_connected_owner() && ! ( new Status() )->is_offline_mode() ) |
| @@ -34,9 +50,9 @@ | ||
| 34 | 50 | */ |
| 35 | 51 | add_action( |
| 36 | 52 | 'rest_api_init', |
| 37 | 53 | function () { |
| 38 | - if ( ! \Jetpack::is_module_active( 'likes' ) ) { | |
| 54 | + if ( ! ( new Modules() )->is_active( 'likes' ) ) { | |
| 39 | 55 | $post_types = get_post_types( array( 'public' => true ) ); |
| 40 | 56 | foreach ( $post_types as $post_type ) { |
| 41 | 57 | add_post_type_support( $post_type, 'jetpack-post-likes' ); |
| 42 | 58 | } |