1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Old version of Bulk_Delete. |
4
|
|
|
* |
5
|
|
|
* This class is deprecated since 6.0.0. But included here for backward compatibility. |
6
|
|
|
* Don't depend on functionality from this class. |
7
|
|
|
*/ |
8
|
|
|
use BulkWP\BulkDelete\Core\BulkDelete; |
9
|
|
|
|
10
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Main Bulk_Delete class. |
14
|
|
|
* |
15
|
|
|
* @since 5.0 Singleton |
16
|
|
|
* @since 6.0.0 Deprecated. |
17
|
|
|
*/ |
18
|
|
|
final class Bulk_Delete { |
19
|
|
|
/** |
20
|
|
|
* The one true Bulk_Delete instance. |
21
|
|
|
* |
22
|
|
|
* @var Bulk_Delete |
23
|
|
|
* |
24
|
|
|
* @since 5.0 |
25
|
|
|
*/ |
26
|
|
|
private static $instance; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Path to the main plugin file. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $plugin_file; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Path where translations are stored. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
private $translations_path; |
|
|
|
|
41
|
|
|
|
42
|
|
|
// version |
43
|
|
|
const VERSION = '5.6.1'; |
44
|
|
|
|
45
|
|
|
// page slugs |
46
|
|
|
const POSTS_PAGE_SLUG = 'bulk-delete-posts'; |
47
|
|
|
const PAGES_PAGE_SLUG = 'bulk-delete-pages'; |
48
|
|
|
const CRON_PAGE_SLUG = 'bulk-delete-cron'; |
49
|
|
|
const ADDON_PAGE_SLUG = 'bulk-delete-addon'; |
50
|
|
|
|
51
|
|
|
// JS constants |
52
|
|
|
const JS_HANDLE = 'bulk-delete'; |
53
|
|
|
const CSS_HANDLE = 'bulk-delete'; |
54
|
|
|
|
55
|
|
|
// Cron hooks |
56
|
|
|
const CRON_HOOK_CATEGORY = 'do-bulk-delete-cat'; |
57
|
|
|
const CRON_HOOK_POST_STATUS = 'do-bulk-delete-post-status'; |
58
|
|
|
const CRON_HOOK_TAG = 'do-bulk-delete-tag'; |
59
|
|
|
const CRON_HOOK_TAXONOMY = 'do-bulk-delete-taxonomy'; |
60
|
|
|
const CRON_HOOK_POST_TYPE = 'do-bulk-delete-post-type'; |
61
|
|
|
const CRON_HOOK_CUSTOM_FIELD = 'do-bulk-delete-custom-field'; |
62
|
|
|
const CRON_HOOK_TITLE = 'do-bulk-delete-by-title'; |
63
|
|
|
const CRON_HOOK_DUPLICATE_TITLE = 'do-bulk-delete-by-duplicate-title'; |
64
|
|
|
const CRON_HOOK_POST_BY_ROLE = 'do-bulk-delete-posts-by-role'; |
65
|
|
|
|
66
|
|
|
const CRON_HOOK_PAGES_STATUS = 'do-bulk-delete-pages-by-status'; |
67
|
|
|
|
68
|
|
|
// meta boxes for delete posts |
69
|
|
|
const BOX_POST_STATUS = 'bd_by_post_status'; |
70
|
|
|
const BOX_CATEGORY = 'bd_by_category'; |
71
|
|
|
const BOX_TAG = 'bd_by_tag'; |
72
|
|
|
const BOX_TAX = 'bd_by_tax'; |
73
|
|
|
const BOX_POST_TYPE = 'bd_by_post_type'; |
74
|
|
|
const BOX_URL = 'bd_by_url'; |
75
|
|
|
const BOX_POST_REVISION = 'bd_by_post_revision'; |
76
|
|
|
const BOX_CUSTOM_FIELD = 'bd_by_custom_field'; |
77
|
|
|
const BOX_TITLE = 'bd_by_title'; |
78
|
|
|
const BOX_DUPLICATE_TITLE = 'bd_by_duplicate_title'; |
79
|
|
|
const BOX_POST_FROM_TRASH = 'bd_posts_from_trash'; |
80
|
|
|
const BOX_POST_BY_ROLE = 'bd_post_by_user_role'; |
81
|
|
|
|
82
|
|
|
// meta boxes for delete pages |
83
|
|
|
const BOX_PAGE_STATUS = 'bd_by_page_status'; |
84
|
|
|
const BOX_PAGE_FROM_TRASH = 'bd_pages_from_trash'; |
85
|
|
|
|
86
|
|
|
// Settings constants |
87
|
|
|
const SETTING_OPTION_GROUP = 'bd_settings'; |
88
|
|
|
const SETTING_OPTION_NAME = 'bd_licenses'; |
89
|
|
|
const SETTING_SECTION_ID = 'bd_license_section'; |
90
|
|
|
|
91
|
|
|
// Transient keys |
92
|
|
|
const LICENSE_CACHE_KEY_PREFIX = 'bd-license_'; |
93
|
|
|
|
94
|
|
|
const MAX_SELECT2_LIMIT = 50; |
95
|
|
|
|
96
|
|
|
// path variables |
97
|
|
|
// Ideally these should be constants, but because of PHP's limitations, these are static variables |
98
|
|
|
public static $PLUGIN_DIR; |
99
|
|
|
public static $PLUGIN_FILE; |
100
|
|
|
|
101
|
|
|
// Instance variables |
102
|
|
|
public $translations; |
103
|
|
|
public $posts_page; |
104
|
|
|
public $pages_page; |
105
|
|
|
public $cron_page; |
106
|
|
|
public $addon_page; |
107
|
|
|
public $settings_page; |
108
|
|
|
public $meta_page; |
109
|
|
|
public $misc_page; |
110
|
|
|
public $display_activate_license_form = false; |
111
|
|
|
|
112
|
|
|
// Deprecated. |
113
|
|
|
// Will be removed in v6.0 |
114
|
|
|
const CRON_HOOK_USER_ROLE = 'do-bulk-delete-users-by-role'; |
115
|
|
|
public $users_page; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Main Bulk_Delete Instance. |
119
|
|
|
* |
120
|
|
|
* Insures that only one instance of Bulk_Delete exists in memory at any one |
121
|
|
|
* time. Also prevents needing to define globals all over the place. |
122
|
|
|
* |
123
|
|
|
* @since 5.0 |
124
|
|
|
* @static |
125
|
|
|
* @staticvar array $instance |
126
|
|
|
* |
127
|
|
|
* @see BULK_DELETE() |
128
|
|
|
* |
129
|
|
|
* @return Bulk_Delete The one true instance of Bulk_Delete |
130
|
|
|
*/ |
131
|
|
|
public static function get_instance() { |
132
|
|
|
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Bulk_Delete ) ) { |
133
|
|
|
self::$instance = new Bulk_Delete(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return self::$instance; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Throw error on object clone. |
141
|
|
|
* |
142
|
|
|
* The whole idea of the singleton design pattern is that there is a single |
143
|
|
|
* object therefore, we don't want the object to be cloned. |
144
|
|
|
* |
145
|
|
|
* @since 5.0 |
146
|
|
|
* @access protected |
147
|
|
|
* |
148
|
|
|
* @return void |
149
|
|
|
*/ |
150
|
|
|
public function __clone() { |
151
|
|
|
// Cloning instances of the class is forbidden |
152
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bulk-delete' ), '5.0' ); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Disable unserializing of the class. |
157
|
|
|
* |
158
|
|
|
* @since 5.0 |
159
|
|
|
* @access protected |
160
|
|
|
* |
161
|
|
|
* @return void |
162
|
|
|
*/ |
163
|
|
|
public function __wakeup() { |
164
|
|
|
// Unserializing instances of the class is forbidden |
165
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bulk-delete' ), '5.0' ); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Set path to main plugin file. |
170
|
|
|
* |
171
|
|
|
* @param string $plugin_file Path to main plugin file. |
172
|
|
|
*/ |
173
|
|
|
public function set_plugin_file( $plugin_file ) { |
174
|
|
|
$this->plugin_file = $plugin_file; |
175
|
|
|
|
176
|
|
|
self::$PLUGIN_DIR = plugin_dir_path( $plugin_file ); |
177
|
|
|
self::$PLUGIN_FILE = $plugin_file; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Get path to main plugin file. |
182
|
|
|
* |
183
|
|
|
* @return string Plugin file. |
184
|
|
|
*/ |
185
|
|
|
public function get_plugin_file() { |
186
|
|
|
return $this->plugin_file; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Monkey patch the old `add_script` method. |
191
|
|
|
* |
192
|
|
|
* @since 6.0.0 |
193
|
|
|
*/ |
194
|
|
|
public function add_script() { |
195
|
|
|
$bd = BulkDelete::get_instance(); |
196
|
|
|
|
197
|
|
|
$primary_pages = $bd->get_primary_pages(); |
198
|
|
|
$post_page = $primary_pages[ self::POSTS_PAGE_SLUG ]; |
199
|
|
|
|
200
|
|
|
$post_page->enqueue_assets(); |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* The main function responsible for returning the one true Bulk_Delete |
206
|
|
|
* Instance to functions everywhere. |
207
|
|
|
* |
208
|
|
|
* Use this function like you would a global variable, except without needing |
209
|
|
|
* to declare the global. |
210
|
|
|
* |
211
|
|
|
* Example: `<?php $bulk_delete = BULK_DELETE(); ?>` |
212
|
|
|
* |
213
|
|
|
* @since 5.0 |
214
|
|
|
* |
215
|
|
|
* @return Bulk_Delete The one true Bulk_Delete Instance |
216
|
|
|
*/ |
217
|
|
|
function BULK_DELETE() { |
218
|
|
|
return Bulk_Delete::get_instance(); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
function bd_setup_backward_compatibility( $plugin_file ) { |
222
|
|
|
$bd = BULK_DELETE(); |
223
|
|
|
$bd->set_plugin_file( $plugin_file ); |
224
|
|
|
} |
225
|
|
|
add_action( 'bd_loaded', 'bd_setup_backward_compatibility' ); |
226
|
|
|
|