forked from felixarntz/wp-gdpr-cookie-notice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-gdpr-cookie-notice.php
86 lines (70 loc) · 2.75 KB
/
wp-gdpr-cookie-notice.php
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
<?php
/**
* Plugin initialization file
*
* @package WP_GDPR_Cookie_Notice
* @since 1.0.0
*
* @wordpress-plugin
* Plugin Name: WP GDPR Cookie Notice
* Plugin URI: https://wordpress.org/plugins/wp-gdpr-cookie-notice/
* Description: Simple performant cookie consent notice that supports AMP, granular cookie control and live preview customization.
* Version: 1.0.0-beta.2
* Author: Felix Arntz
* Author URI: https://felix-arntz.me
* License: GNU General Public License v2 (or later)
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-gdpr-cookie-notice
*/
/* This file must be parseable by PHP 5.2. */
defined( 'ABSPATH' ) || exit;
/**
* Checks whether the plugin requirements are met.
*
* @since 1.0.0
*
* @throws RuntimeException Thrown when the PHP or WordPress versions used are insufficient.
*/
function wp_gdpr_cookie_notice_check_requirements() {
$required_php_version = '7.0';
$required_wp_version = '4.9.6';
$php_version = phpversion();
$wp_version = str_replace( '-src', '', $GLOBALS['wp_version'] );
if ( version_compare( $php_version, $required_php_version, '<' ) ) {
/* translators: 1: required version, 2: active version */
throw new RuntimeException( sprintf( __( 'WP GDPR Cookie Notice requires at least PHP version %1$s, but you are only running version %2$s.', 'wp-gdpr-cookie-notice' ), $required_php_version, $php_version ) );
}
if ( version_compare( $wp_version, $required_wp_version, '<' ) ) {
/* translators: 1: required version, 2: active version */
throw new RuntimeException( sprintf( __( 'WP GDPR Cookie Notice requires at least WordPress version %1$s, but you are only running version %2$s.', 'wp-gdpr-cookie-notice' ), $required_wp_version, $wp_version ) );
}
}
/**
* Gets the plugin controller instance.
*
* Initializes the instance if it does not exist yet.
*
* @since 1.0.0
*
* @return Felix_Arntz\WP_GDPR_Cookie_Notice\Plugin Plugin controller instance.
*/
function wp_gdpr_cookie_notice() {
static $plugin = null;
if ( null !== $plugin ) {
return $plugin;
}
wp_gdpr_cookie_notice_check_requirements();
$namespace = 'Felix_Arntz\\WP_GDPR_Cookie_Notice';
$basedir = plugin_dir_path( __FILE__ ) . 'src';
require_once $basedir . '/class-autoloader.php';
$autoloader_class = $namespace . '\\Autoloader';
$autoloader = new $autoloader_class();
$autoloader->register_rule( $namespace, $basedir );
$autoloader->register_rule( $namespace . '\\Contracts', $basedir . '/contracts', constant( $namespace . '\\Autoloader::TYPE_INTERFACE' ) );
spl_autoload_register( array( $autoloader, 'load' ) );
$plugin_class = $namespace . '\\Plugin';
$plugin = new $plugin_class( __FILE__ );
$plugin->add_hooks();
return $plugin;
}
wp_gdpr_cookie_notice();