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