-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwpconsent.php
More file actions
382 lines (326 loc) · 10.9 KB
/
Copy pathwpconsent.php
File metadata and controls
382 lines (326 loc) · 10.9 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
/**
* Plugin Name: WPConsent
* Description: Improve your WordPress website privacy compliance. Custom cookie banner, website scanner, automatic script blocking, and easy cookie configuration.
* Version: 1.1.6
* Author: WPConsent
* Author URI: https://wpconsent.com
* License: GPL v2 or later
* Requires at least: 5.6
* Requires PHP: 7.0
* Tested up to: 6.9
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wpconsent-cookies-banner-privacy-suite
* Domain Path: /languages
*
* @package WPConsent
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Don't allow multiple versions to be active.
if ( function_exists( 'WPConsent' ) ) {
if ( ! function_exists( 'wpconsent_pro_just_activated' ) ) {
/**
* When we activate a Pro version, we need to do additional operations:
* 1) deactivate a Lite version;
* 2) register option which help to run all activation process for Pro version (custom tables creation, etc.).
*/
function wpconsent_pro_just_activated() {
wpconsent_deactivate();
add_option( 'wpconsent_install', 1 );
}
}
add_action( 'activate_wpconsent-premium/wpconsent-premium.php', 'wpconsent_pro_just_activated' );
if ( ! function_exists( 'wpconsent_lite_just_activated' ) ) {
/**
* Store temporarily that the Lite version of the plugin was activated.
* This is needed because WP does a redirect after activation and
* we need to preserve this state to know whether user activated Lite or not.
*/
function wpconsent_lite_just_activated() {
set_transient( 'wpconsent_lite_just_activated', true );
}
}
add_action( 'activate_wpconsent-cookies-banner-privacy-suite/wpconsent.php', 'wpconsent_lite_just_activated' );
if ( ! function_exists( 'wpconsent_lite_just_deactivated' ) ) {
/**
* Store temporarily that Lite plugin was deactivated.
* Convert temporary "activated" value to a global variable,
* so it is available through the request. Remove from the storage.
*/
function wpconsent_lite_just_deactivated() {
global $wpconsent_lite_just_activated, $wpconsent_lite_just_deactivated;
$wpconsent_lite_just_activated = (bool) get_transient( 'wpconsent_lite_just_activated' );
$wpconsent_lite_just_deactivated = true;
delete_transient( 'wpconsent_lite_just_activated' );
}
}
add_action( 'deactivate_wpconsent-cookies-banner-privacy-suite/wpconsent.php', 'wpconsent_lite_just_deactivated' );
if ( ! function_exists( 'wpconsent_deactivate' ) ) {
/**
* Deactivate Lite if WPConsent already activated.
*/
function wpconsent_deactivate() {
$plugin = 'wpconsent-cookies-banner-privacy-suite/wpconsent.php';
deactivate_plugins( $plugin );
do_action( 'wpconsent_plugin_deactivated', $plugin );
}
}
add_action( 'admin_init', 'wpconsent_deactivate' );
if ( ! function_exists( 'wpconsent_lite_notice' ) ) {
/**
* Display the notice after deactivation when Pro is still active
* and user wanted to activate the Lite version of the plugin.
*/
function wpconsent_lite_notice() {
global $wpconsent_lite_just_activated, $wpconsent_lite_just_deactivated;
if (
empty( $wpconsent_lite_just_activated ) ||
empty( $wpconsent_lite_just_deactivated )
) {
return;
}
// Currently tried to activate Lite with Pro still active, so display the message.
printf(
'<div class="notice notice-warning">
<p>%1$s</p>
<p>%2$s</p>
</div>',
esc_html__( 'Heads up!', 'wpconsent-cookies-banner-privacy-suite' ),
esc_html__( 'Your site already has WPConsent Pro activated. If you want to switch to WPConsent Lite, please first go to Plugins → Installed Plugins and deactivate WPConsent. Then, you can activate WPConsent Lite.', 'wpconsent-cookies-banner-privacy-suite' )
);
if ( isset( $_GET['activate'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
unset( $_GET['activate'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
}
unset( $wpconsent_lite_just_activated, $wpconsent_lite_just_deactivated );
}
}
add_action( 'admin_notices', 'wpconsent_lite_notice' );
// Do not process the plugin code further.
return;
}
/**
* Main plugin class.
*/
class WPConsent {
/**
* Holds the instance of the plugin.
*
* @since 1.0.0
*
* @var WPConsent The one true WPConsent
*/
private static $instance;
/**
* Plugin version.
*
* @since 2.0.0
*
* @var string
*/
public $version = '';
/**
* The admin page loader.
*
* @var WPConsent_Admin_Page_Loader
*/
public $admin_page_loader;
/**
* The settings instance.
*
* @var WPConsent_Settings
*/
public $settings;
/**
* The strings instance.
*
* @var WPConsent_Strings
*/
public $strings;
/**
* The banner instance.
*
* @var WPConsent_Banner
*/
public $banner;
/**
* The cookies instance.
*
* @var WPConsent_Cookies
*/
public $cookies;
/**
* The cookie blocking instance.
*
* @var WPConsent_Cookie_Blocking
*/
public $cookie_blocking;
/**
* Script blocker instance.
*
* @var WPConsent_Script_Blocker
*/
public $script_blocker;
/**
* The dashboard instance.
*
* @var WPConsent_Dashboard
*/
public $dashboard;
/**
* The recommended plugins instance.
*
* @var WPConsent_Recommended_Plugins
*/
public $recommended_plugins;
/**
* The inspector instance.
*
* @var WPConsent_Inspector
*/
public $inspector;
/**
* The scanner instance.
*
* @var WPConsent_Scanner
*/
public $scanner;
/**
* The services instance.
*
* @var WPConsent_Services
*/
public $services;
/**
* Admin notices instance.
*
* @var WPConsent_Notice
*/
public $notice;
/**
* The file cache class.
*
* @var WPConsent_File_Cache
*/
public $file_cache;
/**
* The admin notifications instance.
*
* @var WPConsent_Notifications
*/
public $notifications;
/**
* The privacy integration instance.
*
* @var WPConsent_Privacy_Integration
*/
public $privacy_integration;
/**
* Main instance of WPConsent.
*
* @return WPConsent
* @since 2.0.0
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WPConsent ) ) {
self::$instance = new WPConsent();
}
return self::$instance;
}
/**
* Constructor.
*/
private function __construct() {
$this->setup_constants();
$this->includes();
add_action( 'plugins_loaded', array( $this, 'load_components' ) );
}
/**
* Set up global constants.
*
* @return void
*/
private function setup_constants() {
define( 'WPCONSENT_FILE', __FILE__ );
$plugin_headers = get_file_data( WPCONSENT_FILE, array( 'version' => 'Version' ) );
define( 'WPCONSENT_VERSION', $plugin_headers['version'] );
define( 'WPCONSENT_PLUGIN_BASENAME', plugin_basename( WPCONSENT_FILE ) );
define( 'WPCONSENT_PLUGIN_URL', plugin_dir_url( WPCONSENT_FILE ) );
define( 'WPCONSENT_PLUGIN_PATH', plugin_dir_path( WPCONSENT_FILE ) );
// Declare WP Consent API support.
add_filter( 'wp_consent_api_registered_' . WPCONSENT_PLUGIN_BASENAME, '__return_true' );
$this->version = WPCONSENT_VERSION;
}
/**
* Require the files needed for the plugin.
*
* @return void
*/
private function includes() {
if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
require_once WPCONSENT_PLUGIN_PATH . 'includes/admin/class-wpconsent-admin-page-loader.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/admin/admin-scripts.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/admin/admin-ajax.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/admin/class-wpconsent-services.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/admin/onboarding.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/admin/class-wpconsent-admin-notice.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/admin/class-wpconsent-notifications.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/admin/class-wpconsent-reminders.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/admin/class-wpconsent-privacy-integration.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/admin/class-wpconsent-recommended-plugins.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/class-wpconsent-scanner.php';
}
require_once WPCONSENT_PLUGIN_PATH . 'includes/class-wpconsent-file-cache.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/class-wpconsent-install.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/icons.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/class-wpconsent-settings.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/class-wpconsent-strings.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/class-wpconsent-cookies.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/class-wpconsent-banner.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/class-wpconsent-content-placeholder.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/class-wpconsent-cookie-blocking.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/class-wpconsent-inspector.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/class-wpconsent-dashboard.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/frontend-scripts.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/class-wpconsent-script-blocker.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/cookie-policy-shortcode.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/preferences-button-shortcode.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/helpers.php';
require_once WPCONSENT_PLUGIN_PATH . 'includes/lite/loader.php';
// Load compatibility.
require_once WPCONSENT_PLUGIN_PATH . 'includes/compatibility/loader.php';
}
/**
* Load components in the main plugin instance.
*
* @return void
*/
public function load_components() {
if ( is_admin() || wp_doing_ajax() || defined( 'DOING_CRON' ) && DOING_CRON ) {
$this->admin_page_loader = new WPConsent_Admin_Page_Loader_Lite();
$this->services = WPConsent_Services::get_instance();
$this->scanner = WPConsent_Scanner::get_instance();
$this->notice = new WPConsent_Notice();
$this->notifications = new WPConsent_Notifications();
$this->privacy_integration = new WPConsent_Privacy_Integration();
// Load the reminders.
new WPConsent_Reminders();
new WPConsent_Usage_Tracking_Lite();
$this->recommended_plugins = new WPConsent_Recommended_Plugins();
}
$this->file_cache = new WPConsent_File_Cache();
$this->strings = new WPConsent_Strings();
$this->settings = new WPConsent_Settings();
$this->banner = new WPConsent_Banner();
$this->cookies = new WPConsent_Cookies();
$this->script_blocker = new WPConsent_Script_Blocker();
// Load the cookie blocking functionality.
$this->cookie_blocking = new WPConsent_Cookie_Blocking();
$this->inspector = new WPConsent_Inspector();
$this->dashboard = new WPConsent_Dashboard();
}
}
require_once __DIR__ . '/includes/wpconsent.php';
wpconsent();