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