-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.php
More file actions
69 lines (52 loc) · 2.22 KB
/
plugin.php
File metadata and controls
69 lines (52 loc) · 2.22 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
<?php
/**
* Plugin name: Cookie Notice
* Description: "We use cookies" notice plugin for WordPress
* Author: Miika Arponen / Geniem Oy
* Author URI: http://www.geniem.com
* Text Domain: geniem-cookie-notice
* Version: 1.0.5
*/
namespace Geniem;
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
class CookieNotice {
private static $instance;
private static $lang;
private static $cookie_notice_text;
private static $ok_text;
private static $link_text;
private static $link_url;
private static $version;
protected function __construct() {}
public static function init() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
\load_textdomain( 'geniem-cookie-notice', dirname( __FILE__ ) . '/languages/' . get_locale() .'.mo' );
$plugin = \get_plugin_data( __FILE__ );
self::$version = array_key_exists( 'Version', $plugin ) ? $plugin['Version'] : '';
self::$lang = \get_bloginfo( 'language' );
self::$cookie_notice_text = __( 'We use cookies. By browsing our site you agree to our use of cookies.', 'geniem-cookie-notice' );
self::$ok_text = __( 'OK', 'geniem-cookie-notice' );
self::$link_text = __( 'See details.', 'geniem-cookie-notice' );
self::$link_url = '';
add_action( 'wp_enqueue_scripts', __CLASS__ .'::script' );
}
public static function script() {
wp_register_script( 'geniem_cookie_notice', plugin_dir_url( __FILE__ ) .'dist/plugin.js', [], self::$version, true );
$settings = [
'lang' => apply_filters( 'geniem/cookie_notice/lang', self::$lang ),
'cookie_notice_text' => apply_filters( 'geniem/cookie_notice/text', self::$cookie_notice_text ),
'ok_text' => apply_filters( 'geniem/cookie_notice/ok', self::$ok_text ),
'link_text' => apply_filters( 'geniem/cookie_notice/link', self::$link_text ),
'link_url' => apply_filters( 'geniem/cookie_notice/url', self::$link_url ),
'expires' => apply_filters( 'geniem/cookie_notice/expires', 365 )
];
wp_localize_script( 'geniem_cookie_notice', 'cookie_notice', $settings );
wp_enqueue_script( 'geniem_cookie_notice' );
wp_enqueue_style( 'geniem_cookie_notice', plugin_dir_url( __FILE__ ) .'dist/plugin.css', [], self::$version, null );
}
}
add_action( 'plugins_loaded', function() {
CookieNotice::init();
});