Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
CRAP | n/a |
0 / 0 |
|
| Automattic\Jetpack\Extensions\Likes\register_plugins | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Block Editor - Likes feature. |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Extensions\Likes; |
| 9 | |
| 10 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 11 | use Automattic\Jetpack\Modules; |
| 12 | use Automattic\Jetpack\Status; |
| 13 | use Automattic\Jetpack\Status\Host; |
| 14 | use Jetpack_Gutenberg; |
| 15 | |
| 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | exit( 0 ); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Register Likes plugin. |
| 22 | * |
| 23 | * @return void |
| 24 | */ |
| 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 | * However, since non-admins cannot activate modules, we do not display the empty block for them. |
| 30 | */ |
| 31 | if ( ! ( new Modules() )->is_active( 'likes' ) && ! current_user_can( 'jetpack_activate_modules' ) ) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | // Register Likes. |
| 36 | if ( |
| 37 | ( new Host() )->is_wpcom_simple() |
| 38 | || ( ( new Connection_Manager( 'jetpack' ) )->has_connected_owner() && ! ( new Status() )->is_offline_mode() ) |
| 39 | ) { |
| 40 | Jetpack_Gutenberg::set_extension_available( 'likes' ); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | add_action( 'jetpack_register_gutenberg_extensions', __NAMESPACE__ . '\register_plugins' ); |
| 45 | |
| 46 | /** |
| 47 | * Register post types |
| 48 | */ |
| 49 | add_action( |
| 50 | 'rest_api_init', |
| 51 | function () { |
| 52 | if ( ! ( new Modules() )->is_active( 'likes' ) ) { |
| 53 | $post_types = get_post_types( array( 'public' => true ) ); |
| 54 | foreach ( $post_types as $post_type ) { |
| 55 | add_post_type_support( $post_type, 'jetpack-post-likes' ); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | ); |