class-admin.php
3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
* WP Admin resources.
*
* @package Block_Lab
* @copyright Copyright(c) 2020, Block Lab
* @license http://opensource.org/licenses/GPL-2.0 GNU General Public License, version 2 (GPL-2.0)
*/
namespace Block_Lab\Admin;
use Block_Lab\Component_Abstract;
use Block_Lab\Admin\Migration\Api;
use Block_Lab\Admin\Migration\Subscription_Api;
use Block_Lab\Admin\Migration\Notice;
use Block_Lab\Admin\Migration\Submenu;
/**
* Class Admin
*/
class Admin extends Component_Abstract {
/**
* JSON import.
*
* @var Import
*/
public $import;
/**
* Plugin license.
*
* @var License
*/
public $license;
/**
* User onboarding.
*
* @var Onboarding
*/
public $onboarding;
/**
* Plugin settings.
*
* @var Settings
*/
public $settings;
/**
* Plugin upgrade.
*
* @var Upgrade
*/
public $upgrade;
/**
* The migration API.
*
* @var Api
*/
private $api;
/**
* THe subscription API for the migration.
*
* @var Subscription_Api
*/
private $subscription_api;
/**
* The migration notice.
*
* @var Notice
*/
private $notice;
/**
* The migration submenu under the Block Lab menu item.
*
* @var Submenu
*/
private $submenu;
/**
* Initialise the Admin component.
*/
public function init() {
$this->settings = new Settings();
block_lab()->register_component( $this->settings );
$this->license = new License();
block_lab()->register_component( $this->license );
$this->onboarding = new Onboarding();
block_lab()->register_component( $this->onboarding );
$this->api = new Api();
block_lab()->register_component( $this->api );
$this->subscription_api = new Subscription_Api();
block_lab()->register_component( $this->subscription_api );
$this->notice = new Notice();
block_lab()->register_component( $this->notice );
$this->submenu = new Submenu();
block_lab()->register_component( $this->submenu );
$show_pro_nag = apply_filters( 'block_lab_show_pro_nag', false );
if ( $show_pro_nag && ! block_lab()->is_pro() ) {
$this->upgrade = new Upgrade();
block_lab()->register_component( $this->upgrade );
} else {
$this->maybe_settings_redirect();
}
if ( defined( 'WP_LOAD_IMPORTERS' ) && WP_LOAD_IMPORTERS ) {
$this->import = new Import();
block_lab()->register_component( $this->import );
}
}
/**
* Register any hooks that this component needs.
*/
public function register_hooks() {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
}
/**
* Enqueue scripts and styles used globally in the WP Admin.
*
* @return void
*/
public function enqueue_scripts() {
wp_enqueue_style(
'block-lab',
$this->plugin->get_url( 'css/admin.css' ),
[],
$this->plugin->get_version()
);
}
/**
* Redirect to the Settings screen if the license is being saved.
*/
public function maybe_settings_redirect() {
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
if ( 'block-lab-pro' === $page ) {
wp_safe_redirect(
add_query_arg(
[
'post_type' => 'block_lab',
'page' => 'block-lab-settings',
'tab' => 'license',
],
admin_url( 'edit.php' )
)
);
die();
}
}
}