1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Base class for all Metabox Pages. |
4
|
|
|
* |
5
|
|
|
* @since 5.5 |
6
|
|
|
* @author Sudar |
7
|
|
|
* @package BulkDelete\Base\Page |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Base class for Metabox Pages. |
14
|
|
|
* |
15
|
|
|
* @abstract |
16
|
|
|
* @since 5.5 |
17
|
|
|
*/ |
18
|
|
|
abstract class BD_Page extends BD_Base_Page { |
19
|
|
|
/** |
20
|
|
|
* @var string Item Type. Possible values 'posts', 'pages', 'users' etc. |
21
|
|
|
*/ |
22
|
|
|
protected $item_type; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Setup hooks. |
26
|
|
|
* |
27
|
|
|
* @since 5.5 |
28
|
|
|
*/ |
29
|
|
|
protected function setup_hooks() { |
30
|
|
|
parent::setup_hooks(); |
31
|
|
|
|
32
|
|
|
add_action( "bd_admin_footer_for_{$this->item_type}", array( $this, 'modify_admin_footer' ) ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Check for nonce before executing the action. |
37
|
|
|
* |
38
|
|
|
* @since 5.5 |
39
|
|
|
* @param bool $result The current result. |
40
|
|
|
* @param string $action Action name. |
41
|
|
|
*/ |
42
|
|
|
public function nonce_check( $result, $action ) { |
43
|
|
|
$action_prefix = "delete_{$this->item_type}_"; |
44
|
|
|
|
45
|
|
|
if ( $action_prefix === substr( $action, 0, strlen( $action_prefix ) ) |
46
|
|
|
&& check_admin_referer( "bd-{$this->page_slug}", "bd-{$this->page_slug}-nonce" ) ) { |
47
|
|
|
return true; |
48
|
|
|
} else { |
49
|
|
|
return $result; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Add menu. |
55
|
|
|
* |
56
|
|
|
* @since 5.5 |
57
|
|
|
*/ |
58
|
|
|
public function add_menu() { |
59
|
|
|
parent::add_menu(); |
60
|
|
|
|
61
|
|
|
add_action( "admin_print_scripts-{$this->screen}", array( $bd, 'add_script' ) ); |
|
|
|
|
62
|
|
|
|
63
|
|
|
add_action( "load-{$this->screen}", array( $this, 'add_settings_panel' ) ); |
64
|
|
|
add_action( "add_meta_boxes_{$this->screen}", array( $this, 'add_meta_boxes' ) ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Add settings Panel. |
69
|
|
|
* |
70
|
|
|
* @since 5.5 |
71
|
|
|
*/ |
72
|
|
|
public function add_settings_panel() { |
73
|
|
|
/** |
74
|
|
|
* Add contextual help for admin screens. |
75
|
|
|
* |
76
|
|
|
* @since 5.1 |
77
|
|
|
*/ |
78
|
|
|
do_action( 'bd_add_contextual_help', $this->screen ); |
79
|
|
|
|
80
|
|
|
// Trigger the add_meta_boxes hooks to allow meta boxes to be added |
81
|
|
|
do_action( 'add_meta_boxes_' . $this->screen, null ); |
82
|
|
|
|
83
|
|
|
// Enqueue WordPress' script for handling the meta boxes |
84
|
|
|
wp_enqueue_script( 'postbox' ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Register meta boxes. |
89
|
|
|
* |
90
|
|
|
* @since 5.5 |
91
|
|
|
*/ |
92
|
|
|
public function add_meta_boxes() { |
93
|
|
|
/** |
94
|
|
|
* Add meta box in delete users page. |
95
|
|
|
* This hook can be used for adding additional meta boxes in delete users page |
96
|
|
|
* |
97
|
|
|
* @since 5.3 |
98
|
|
|
*/ |
99
|
|
|
do_action( "bd_add_meta_box_for_{$this->item_type}", $this->screen, $this->page_slug ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Add additional nonce fields. |
104
|
|
|
* |
105
|
|
|
* @since 5.5.4 |
106
|
|
|
*/ |
107
|
|
|
protected function render_nonce_fields() { |
108
|
|
|
parent::render_nonce_fields(); |
109
|
|
|
|
110
|
|
|
// Used to save closed meta boxes and their order |
111
|
|
|
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); |
112
|
|
|
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Render meta boxes in body. |
117
|
|
|
* |
118
|
|
|
* @since 5.5.4 |
119
|
|
|
*/ |
120
|
|
|
protected function render_body() { |
121
|
|
|
do_meta_boxes( '', 'advanced', null ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Render footer. |
126
|
|
|
* |
127
|
|
|
* @since 5.5.4 |
128
|
|
|
*/ |
129
|
|
|
protected function render_footer() { |
130
|
|
|
parent::render_footer(); |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Runs just before displaying the footer text in the admin page. |
134
|
|
|
* |
135
|
|
|
* This action is primarily for adding extra content in the footer of admin page. |
136
|
|
|
* |
137
|
|
|
* @since 5.5.4 |
138
|
|
|
*/ |
139
|
|
|
do_action( "bd_admin_footer_for_{$this->item_type}" ); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
?> |
143
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.