-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdpr-comments.php
149 lines (127 loc) · 4.57 KB
/
gdpr-comments.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
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
<?php
/**
* Plugin Name: GDPR Comments
* Plugin URI: https://wordpress.org/plugins/gdpr-comments/
* Description: Assistance to meet GDPR compliance requirements for WordPress comments
* Version: 1.0.2
* Author: flowdee
* Author URI: https://kryptonitewp.com
* Text Domain: gdpr-comments
*
* @package GDPRComments
* @author flowdee
* @copyright Copyright (c) flowdee
*
* Copyright (c) 2018 - flowdee ( https://twitter.com/flowdee )
*/
// Exit if accessed directly
if( ! defined( 'ABSPATH' ) ) exit;
if( ! class_exists( 'GDPR_Comments' ) ) {
/**
* Main GDPR_Comments class
*
* @since 1.0.0
*/
class GDPR_Comments {
/**
* @var GDPR_Comments $instance The one true GDPR_Comments
* @since 1.0.0
*/
private static $instance;
/**
* Get active instance
*
* @access public
* @since 1.0.0
* @return object self::$instance The one true GDPR_Comments
*/
public static function instance() {
if( !self::$instance ) {
self::$instance = new GDPR_Comments();
self::$instance->setup_constants();
self::$instance->includes();
self::$instance->load_textdomain();
}
return self::$instance;
}
/**
* Setup plugin constants
*
* @access private
* @since 1.0.0
* @return void
*/
private function setup_constants() {
// Plugin name
define( 'GDPR_COMMENTS_NAME', 'GDPR Comments' );
// Plugin version
define( 'GDPR_COMMENTS_VER', '1.0.2' );
// Plugin path
define( 'GDPR_COMMENTS_DIR', plugin_dir_path( __FILE__ ) );
// Plugin URL
define( 'GDPR_COMMENTS_URL', plugin_dir_url( __FILE__ ) );
}
/**
* Include necessary files
*
* @access private
* @since 1.0.0
* @return void
*/
private function includes() {
// Basic
require_once GDPR_COMMENTS_DIR . 'includes/helper.php';
// Admin only
if ( is_admin() ) {
require_once GDPR_COMMENTS_DIR . 'includes/admin/plugins.php';
require_once GDPR_COMMENTS_DIR . 'includes/admin/class.settings.php';
require_once GDPR_COMMENTS_DIR . 'includes/admin/ajax.php';
}
// Anything else
require_once GDPR_COMMENTS_DIR . 'includes/functions.php';
require_once GDPR_COMMENTS_DIR . 'includes/scripts.php';
require_once GDPR_COMMENTS_DIR . 'includes/anonymize-ip.php';
require_once GDPR_COMMENTS_DIR . 'includes/comment-form.php';
}
/**
* Internationalization
*
* @access public
* @since 1.0.0
* @return void
*/
public function load_textdomain() {
// Set filter for language directory
$lang_dir = GDPR_COMMENTS_DIR . '/languages/';
$lang_dir = apply_filters( 'gdpr_comments_languages_directory', $lang_dir );
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), 'gdpr-comments' );
$mofile = sprintf( '%1$s-%2$s.mo', 'gdpr-comments', $locale );
// Setup paths to current locale file
$mofile_local = $lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/gdpr-comments/' . $mofile;
if( file_exists( $mofile_global ) ) {
// Look in global /wp-content/languages/gdpr-comments/ folder
load_textdomain( 'gdpr-comments', $mofile_global );
} elseif( file_exists( $mofile_local ) ) {
// Look in local /wp-content/plugins/gdpr-comments/languages/ folder
load_textdomain( 'gdpr-comments', $mofile_local );
} else {
// Load the default language files
load_plugin_textdomain( 'gdpr-comments', false, $lang_dir );
}
}
}
} // End if class_exists check
/**
* The main function responsible for returning the one true GDPR_Comments
* instance to functions everywhere
*
* @since 1.0.0
* @return \GDPR_Comments The one true GDPR_Comments
*
*/
function gdpr_cc_load() {
return GDPR_Comments::instance();
}
add_action( 'plugins_loaded', 'gdpr_cc_load' );