Completed
Push — update/premium-blocks-module ( 762cc5...f394fd )
by
unknown
197:09 queued 180:40
created

Premium_Blocks::check_extension_availability()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 1
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/**
3
 * Block Editor class for Premium Blocks.
4
 * Sets blocks as premium depending on the site site plan and site type.
5
 *
6
 * @package Automattic\Jetpack\Extensions
7
 */
8
9
namespace Automattic\Jetpack\Extensions;
10
11
/**
12
 * Class Premium_Blocks.
13
 *
14
 * @package Automattic\Jetpack\Extensions
15
 */
16
class Premium_Blocks {
17
18
	/**
19
	 * List of premium blocks.
20
	 *
21
	 * @var array
22
	 */
23
	public $extensions = array(
24
		'core/audio',
25
		'core/cover',
26
		'core/video',
27
		'premium-content/container',
28
	);
29
30
	/**
31
	 * Plan level required to access premium blocks.
32
	 *
33
	 * @var string
34
	 */
35
	public $required_plan = 'jetpack_premium';
36
37
	/**
38
	 * Whether the current site is on WP.com.
39
	 *
40
	 * @var bool
41
	 */
42
	public $is_simple_site = false;
43
44
	/**
45
	 * Singleton.
46
	 */
47
	public static function get_instance() {
48
		static $instance = false;
49
50
		if ( ! $instance ) {
51
			$instance = new self();
52
		}
53
54
		return $instance;
55
	}
56
57
	/**
58
	 * Premium_Blocks constructor.
59
	 */
60
	private function __construct() {
61
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
62
			$this->is_simple_site = true;
63
			$this->required_plan  = 'value_bundle';
64
		}
65
66
		// Populate the block-editor extensions available through Jetpack.
67
		add_filter(
68
			'jetpack_set_available_extensions',
69
			function ( $extensions ) {
70
				return array_merge( $extensions, $this->extensions );
71
			}
72
		);
73
74
		// Set extensions availability depending on the plan site type and plan of the site.
75
		add_action( 'jetpack_register_gutenberg_extensions', array( $this, 'set_extension_availability' ) );
76
	}
77
78
	/**
79
	 * Set the Jetpack Gutenberg extension availability.
80
	 * It will check if the extension/block will require an upgrade
81
	 * in order to make it available for the site.
82
	 */
83
	public function set_extension_availability() {
84
		foreach ( $this->extensions as $extension ) {
85
			\Jetpack_Gutenberg::set_availability_for_plan( $extension );
86
		}
87
	}
88
}
89