class-admin-notice.php
3.06 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
<?php
/**
* Controller for admin notices.
*
* @link https://wordpress.org/plugins/broken-link-checker/
* @since 2.0.0
*
* @author WPMUDEV (https://wpmudev.com)
* @package WPMUDEV_BLC\Core\Controllers
*
* @copyright (c) 2022, Incsub (http://incsub.com)
*/
namespace WPMUDEV_BLC\Core\Controllers;
// Abort if called directly.
defined( 'WPINC' ) || die;
use WPMUDEV_BLC\Core\Utils\Abstracts\Base;
use WPMUDEV_BLC\Core\Traits\Enqueue;
use WPMUDEV_BLC\Core\Utils\Utilities;
use function get_current_screen;
/**
* Class Admin_Page
*
* @package WPMUDEV_BLC\Core\Controllers
*/
abstract class Admin_Notice extends Base {
/**
* Use the Enqueue Trait.
*
* @since 2.0.0
*/
use Enqueue;
/**
* The admin pages the notice will be visible at.
*
* @since 2.0.0
* @var array $admin_pages
*
*/
protected $admin_pages = array();
/**
* Init Admin Page
*
* @since 2.0.0
*
* @return void Initialize the Admin_Page.
*/
public function init() {
$this->prepare_props();
$this->actions();
}
/**
* Prepares the properties of the Admin Notice.
*
* @since 2.0.0
*
* @return void Prepares properties of the admin notice.
*/
abstract public function prepare_props();
/**
* Add Actions
*
* @since 2.0.0
*
* @return void Add the Actions.
*/
public function actions() {
add_action( 'admin_init', array( $this, 'boot' ) );
}
/**
* Admin init actions.
*
* @since 2.0.0
*
* @return void Admin init actions.
*/
public function boot() {
add_action( 'current_screen', array( $this, 'current_screen_actions' ) );
}
/**
* Current screen actions.
*
* @since 2.0.0
*
* @return void Current screen actions.
*/
public function current_screen_actions() {
if ( $this->can_boot() ) {
$this->prepare_scripts();
$this->notice_hooks();
add_filter( 'admin_body_class', array( $this, 'admin_body_classes' ), 999 );
add_action( 'admin_notices', array( $this, 'output' ) );
}
}
/**
* Checks if admin page actions/scripts should load in current screen.
*
* @since 2.0.0
*
* @return boolean Checks if admin page actions/scripts should load. Useful for enqueuing scripts.
*/
public abstract function can_boot();
/**
* Adds specific hooks per notice. Extends $this->actions.
*
* @since 2.0.0
*
* @return void
*/
public function notice_hooks() {
}
/**
* Adds SUI admin body class. It will be used in all admin pages.
*
* @param $classes
*
* @return string
*/
public function admin_body_classes( $classes ) {
$sui_classes = explode( ' ', $classes );
$sui_classes[] = BLC_SHARED_UI_VERSION;
if ( apply_filters( 'wpmudev_branding_hide_branding', false ) ) {
$sui_classes[] = 'wpmudev-hide-branding';
}
return join( ' ', $sui_classes );
}
/**
* Register scripts for the admin page.
*
* @since 2.0.0
*
* @return array Register scripts for the admin page.
*/
public function set_scripts() {
return array();
}
/**
* Admin Menu Output.
*
* @since 2.0.0
*
* @return void The output function of the Admin Menu Page.
*/
abstract public function output();
}