class-controller.php
4.56 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
<?php
/**
* BLC admin notice for local screens when Cloud BLC is active.
*
* @link https://wordpress.org/plugins/broken-link-checker/
* @since 2.1
*
* @author WPMUDEV (https://wpmudev.com)
* @package WPMUDEV_BLC\App\Admin_Notices\Local
*
* @copyright (c) 2022, Incsub (http://incsub.com)
*/
namespace WPMUDEV_BLC\App\Admin_Notices\Local;
// Abort if called directly.
defined( 'WPINC' ) || die;
use WPMUDEV_BLC\App\Options\Settings\Model as Settings;
use WPMUDEV_BLC\Core\Controllers\Admin_Notice;
use WPMUDEV_BLC\Core\Utils\Utilities;
/**
* Class Controller
*
* @package WPMUDEV_BLC\App\Admin_Notices\Local
*/
class Controller extends Admin_Notice {
/**
* Admin Menu Callback.
*
* @return void The callback function of the Admin Menu Page.
* @since 2.1
*
*/
public function output() {
//View::instance()->render();
}
/**
* Returns true if module component should load, else returns false.
*
* @return void
* @since 2.1
*
*/
public function can_boot() {
/**
* Until multisites are officially supported, BLC v2 menus are disabled in subsites.
* Local menus are loaded instead. Local admin notification does not need to appear on subsites at this point.
*/
if ( Utilities::is_subsite() || Settings::instance()->get( 'use_legacy_blc_version' ) ) {
return;
}
/* We use the Utilities::$value_provider array variable.
This variable can hold values that can be used from different classes which should help avoid checking
same conditions multiple times.
In this case we are using `boot_admin_local_page` key which is also used in
WPMUDEV_BLC\App\Admin_Modals\Local\Controller class.
*/
if ( ! isset( Utilities::$value_provider[ 'boot_admin_local_page' ] ) ) {
Utilities::$value_provider['boot_admin_local_page'] = Utilities::is_admin_screen( $this->admin_pages );
}
return Utilities::$value_provider[ 'boot_admin_local_page' ];
}
public function admin_dash_page_classes( $classes ) {
return $classes . ' blc-show-local-notice';
}
/**
* Register scripts for the admin page.
*
* @since 2.1
* @return array Register scripts for the admin page.
*/
public function set_admin_scripts() {
$script_data = include WPMUDEV_BLC_DIR . 'assets/js/local-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;
$signup_url = add_query_arg(
array(
'utm_source' => 'blc',
'utm_medium' => 'plugin',
'utm_campaign' => 'blc_plugin_onboarding',
),
Utilities::signup_url()
);
return array(
'blc_local_notice' => array(
'src' => $this->scripts_dir . 'local-notice/main.js',
'deps' => $dependencies,
'ver' => $version,
'in_footer' => true,
'localize' => array(
'blc_local_notice' => array(
'data' => array(
'rest_url' => esc_url_raw( rest_url() ),
'settings_endpoint' => '/wpmudev_blc/v1/settings',
'nonce' => wp_create_nonce( 'wp_rest' ),
/*'legacy_active' => boolval( Settings::instance()->get( 'use_legacy_blc_version' ) ),
'local_blc_url' => admin_url( 'admin.php?page=blc_local' ),
'cloud_blc_url' => admin_url( 'admin.php?page=blc_dash' ),
'assets_url' => WPMUDEV_BLC_ASSETS_URL,
'site_connected' => (bool) self::site_connected(),
'expired_membership' => boolval( Utilities::membership_expired() ),
'hub_signup_url' => $signup_url,
'dash_installed' => boolval( Utilities::dash_plugin_installed() ),
'dash_active' => boolval( Utilities::dash_plugin_active() ),*/
),
'labels' => array(
'error_messages' => array(
'general' => __( 'Something went wrong here.', 'broken-link-checker' ),
),
),
),
),
'translate' => true,
),
// END OF blc_activation_popup.
);
}
protected function scripts_version() {
static $scripts_version = null;
if ( is_null( $scripts_version ) ) {
$script_data = include WPMUDEV_BLC_DIR . 'assets/js/local-notice/main.asset.php';
$scripts_version = $script_data['version'] ?? WPMUDEV_BLC_SCIPTS_VERSION;
}
return $scripts_version;
}
/**
* Prepares the properties of the Admin Page.
*
* @return void
* @since 2.1
*
*/
public function prepare_props() {
/*
* Se the admin pages the notice will be visible at.
*/
$this->admin_pages = array(
'view-broken-links',
'link-checker-settings',
'blc_local',
);
}
}