class-controller.php
4.01 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
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/**
* BLC welcome modal.
*
* @link https://wordpress.org/plugins/broken-link-checker/
* @since 2.2.0
*
* @author WPMUDEV (https://wpmudev.com)
* @package WPMUDEV_BLC\App\Admin_Notices\Welcome
*
* @copyright (c) 2022, Incsub (http://incsub.com)
*/
namespace WPMUDEV_BLC\App\Admin_Modals\Welcome;
// Abort if called directly.
defined( 'WPINC' ) || die;
use WPMUDEV_BLC\App\Options\Settings\Model as Settings;
use WPMUDEV_BLC\Core\Utils\Utilities;
use WPMUDEV_BLC\Core\Utils\Abstracts\Base;
use WPMUDEV_BLC\Core\Traits\Enqueue;
/**
* Class Controller
*
* @package WPMUDEV_BLC\App\Admin_Pages\Welcome
*/
class Controller extends Base {
/**
* Use the Enqueue Trait.
*
* @since 2.2.0
*/
use Enqueue;
/**
* The unique id that can be used by react.
*
* @var int $unique_id
*
* @since 2.2.0
*/
public $unique_id = null;
/**
* The admin pages the notice will be visible at.
*
* @var array $admin_pages
*
* @since 2.2.0
*/
protected $admin_pages = array();
/**
* Init function.
*
* @since 2.2.0
*/
public function init() {
Settings::instance()->init();
add_action( 'current_screen', array( $this, 'boot' ), 11 );
}
/**
* Boots modal parts.
*/
public function boot() {
if ( $this->can_boot() ) {
//add_filter( 'admin_body_class', array( $this, 'admin_body_classes' ), 999 );
add_action( 'admin_footer', array( $this, 'output' ) );
$this->unique_id = Utilities::get_unique_id();
$this->prepare_props();
$this->prepare_scripts();
}
}
/**
* Checks if admin page actions/scripts should load in current screen.
*
* @return boolean Checks if admin page actions/scripts should load. Useful for enqueuing scripts.
* @since 2.2.0
*/
public function can_boot() {
$admin_pages = array(
'toplevel_page_blc_dash',
//'link-checker_page_blc_local',
);
$version_highlights = Settings::instance()->get( 'version_highlights' );
$version_highlights_shown = ! empty( $version_highlights['2_2_0'] );
return Utilities::is_admin_screen( $admin_pages ) && ! $version_highlights_shown;
}
/**
* Prepares the properties of the Admin Page.
*
* @return void
* @since 2.2.0
*/
public function prepare_props() {
/*
* Set the admin pages the notice will be visible at.
*/
/*$this->admin_pages = array(
'blc_dash',
'link-checker_page_blc_local',
);*/
}
/**
* Admin Menu Callback.
*
* @return void The callback function of the Admin Menu Page.
* @since 2.2.0
*/
public function output() {
View::instance()->render( array( 'unique_id' => $this->unique_id ) );
}
/**
* Register scripts for the admin modal.
*
* @return array Register scripts for the admin modal.
* @since 2.2.0
*/
public function set_admin_scripts() {
$script_data = include WPMUDEV_BLC_DIR . 'assets/js/welcome-modal/main.asset.php';
$dependencies = $script_data['dependencies'] ?? array(
'react',
'wp-element',
'wp-i18n',
'wp-is-shallow-equal',
'wp-polyfill',
);
$version = $script_data['version'] ?? WPMUDEV_BLC_SCIPTS_VERSION;
return array(
'blc_welcome_modal' => array(
'src' => $this->scripts_dir . 'welcome-modal/main.js',
'deps' => $dependencies,
'ver' => $version,
'in_footer' => true,
'localize' => array(
'blc_welcome_modal' => array(
'data' => array(
'rest_url' => esc_url_raw( rest_url() ),
'settings_endpoint' => '/wpmudev_blc/v1/settings',
'unique_id' => $this->unique_id,
'nonce' => wp_create_nonce( 'wp_rest' ),
),
),
),
'translate' => true,
),
);
}
/**
* Register css files for admin modal.
*
* @return array
*/
public function set_admin_styles() {
return array(
'blc_sui' => array(
'src' => $this->styles_dir . 'shared-ui-' . BLC_SHARED_UI_VERSION_NUMBER . '.min.css',
'ver' => WPMUDEV_BLC_SCIPTS_VERSION,
),
'blc_welcome_modal' => array(
'src' => $this->styles_dir . 'welcome-modal.min.css',
'ver' => WPMUDEV_BLC_SCIPTS_VERSION,
),
);
}
}