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
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Singleton. |
27
|
|
|
*/ |
28
|
|
|
public static function get_instance() { |
29
|
|
|
static $instance = false; |
30
|
|
|
|
31
|
|
|
if ( ! $instance ) { |
32
|
|
|
$instance = new self(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return $instance; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Premium_Blocks constructor. |
40
|
|
|
*/ |
41
|
|
|
private function __construct() { |
42
|
|
|
// Check if it's a Simple site. Bail if not. |
43
|
|
|
if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) { |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// Check if the class exists. Bail if not. |
48
|
|
|
if ( ! class_exists( 'Store_Product_List' ) ) { |
49
|
|
|
require WP_CONTENT_DIR . '/admin-plugins/wpcom-billing/store-product-list.php'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// Check if the method exists in the class. Bail if not. |
53
|
|
|
if ( ! method_exists( 'Store_Product_List', 'get_paid_blocks_list') ) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// Check if the are defined paid blocks |
58
|
|
|
$this->extensions = \Store_Product_List::get_paid_blocks_list(); |
59
|
|
|
if ( empty( $this->extensions ) ) { |
60
|
|
|
return; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// Populate the block-editor extensions available through Jetpack. |
64
|
|
|
add_filter( |
65
|
|
|
'jetpack_set_available_extensions', |
66
|
|
|
function ( $extensions ) { |
67
|
|
|
return array_merge( $extensions, $this->extensions ); |
68
|
|
|
} |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
// Set extensions availability depending on the plan site type and plan of the site. |
72
|
|
|
add_action( 'jetpack_register_gutenberg_extensions', array( $this, 'set_block_availability' ) ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Set the Jetpack Gutenberg extension availability. |
77
|
|
|
* It will check if the extension/block will require an upgrade |
78
|
|
|
* in order to make it completely available for the site. |
79
|
|
|
*/ |
80
|
|
|
public function set_block_availability() { |
81
|
|
|
foreach ( $this->extensions as $extension ) { |
82
|
|
|
\Jetpack_Gutenberg::set_availability_for_plan( $extension ); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|