PluginProbe ʕ •ᴥ•ʔ
CookieYes – Cookie Banner for Cookie Consent (Easy to setup GDPR/CCPA Compliant Cookie Notice) / 3.5.0
CookieYes – Cookie Banner for Cookie Consent (Easy to setup GDPR/CCPA Compliant Cookie Notice) v3.5.0
3.5.1 3.5.0 3.4.2 trunk 1.0.1 1.0.3 1.2 1.2.1 1.2.2 1.3 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.2.0 3.2.1 3.2.10 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.3.9.1 3.4.0 3.4.1
cookie-law-info / legacy / admin / class-cookie-law-info-admin.php
cookie-law-info / legacy / admin Last commit date
css 2 weeks ago images 2 weeks ago js 2 weeks ago modules 2 weeks ago partials 2 weeks ago videos 2 weeks ago views 2 weeks ago class-cookie-law-info-admin.php 2 weeks ago index.php 2 weeks ago
class-cookie-law-info-admin.php
543 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * The admin-specific functionality of the plugin.
9 *
10 * @link http://cookielawinfo.com/
11 * @since 1.6.6
12 *
13 * @package Cookie_Law_Info
14 * @subpackage Cookie_Law_Info/admin
15 */
16
17 /**
18 * The admin-specific functionality of the plugin.
19 *
20 * Defines the plugin name, version, and two examples hooks for how to
21 * enqueue the admin-specific stylesheet and JavaScript.
22 *
23 * @package Cookie_Law_Info
24 * @subpackage Cookie_Law_Info/admin
25 * @author WebToffee <info@webtoffee.com>
26 */
27 class Cookie_Law_Info_Admin {
28
29 /**
30 * The ID of this plugin.
31 *
32 * @since 1.6.6
33 * @access private
34 * @var string $plugin_name The ID of this plugin.
35 */
36 private $plugin_name;
37
38 /**
39 * The version of this plugin.
40 *
41 * @since 1.6.6
42 * @access private
43 * @var string $version The current version of this plugin.
44 */
45 private $version;
46
47 public $plugin_obj;
48
49 /*
50 * admin module list, Module folder and main file must be same as that of module name
51 * Please check the `admin_modules` method for more details
52 */
53 private $modules = array(
54 'cookies',
55 'cli-policy-generator',
56 'ccpa',
57 'cookie-scaner',
58 'uninstall-feedback',
59 );
60
61 public static $existing_modules = array();
62
63 /**
64 * Initialize the class and set its properties.
65 *
66 * @since 1.6.6
67 * @param string $plugin_name The name of this plugin.
68 * @param string $version The version of this plugin.
69 */
70 public function __construct( $plugin_name, $version, $plugin_obj ) {
71
72 $this->plugin_name = $plugin_name;
73 $this->version = $version;
74 $this->plugin_obj = $plugin_obj;
75 add_action( 'admin_init', array( $this, 'load_plugin' ) );
76 register_activation_hook( CLI_PLUGIN_FILENAME, array( $this, 'activator' ) );
77 // since 1.9.5 Initialize plugin settings
78 add_action( 'wt_cli_initialize_plugin', array( $this, 'initialize_plugin_settings' ) );
79 }
80
81 /**
82 * Store default data to the database if a first time user
83 *
84 * @since 2.3.1
85 * @access public
86 */
87 public function activator() {
88
89 if ( Cookie_Law_Info::maybe_first_time_install() === true ) {
90 add_option( 'wt_cli_first_time_activated_plugin', 'true' );
91 }
92 }
93
94 public function set_default_settings() {
95 $options = get_option( CLI_SETTINGS_FIELD );
96 if ( $options === false ) {
97 $default = Cookie_Law_Info::get_settings();
98 update_option( CLI_SETTINGS_FIELD, $default );
99 }
100 }
101 public function set_privacy_overview_options() {
102 $options = get_option( 'cookielawinfo_privacy_overview_content_settings' );
103 if ( $options === false ) {
104 $default = self::get_privacy_defaults();
105 update_option( 'cookielawinfo_privacy_overview_content_settings', $default );
106 }
107 }
108 public function initialize_plugin_settings() {
109 $this->set_default_settings();
110 $this->set_privacy_overview_options();
111 }
112 /**
113 * Register the stylesheets for the admin area.
114 *
115 * @since 1.6.6
116 */
117 public function enqueue_styles() {
118
119 /**
120 * This function is provided for demonstration purposes only.
121 *
122 * An instance of this class should be passed to the run() function
123 * defined in Cookie_Law_Info_Loader as all of the hooks are defined
124 * in that particular class.
125 *
126 * The Cookie_Law_Info_Loader will then create the relationship
127 * between the defined hooks and the functions defined in this
128 * class.
129 */
130 if ( $this->is_cookie_law_info_admin_screen() ) {
131 wp_enqueue_style( 'wp-color-picker' );
132 wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/cookie-law-info-admin.css', array(), $this->version, 'all' );
133 }
134 }
135
136 /**
137 * Register the JavaScript for the admin area.
138 *
139 * @since 1.6.6
140 */
141 public function enqueue_scripts() {
142
143 /**
144 * This function is provided for demonstration purposes only.
145 *
146 * An instance of this class should be passed to the run() function
147 * defined in Cookie_Law_Info_Loader as all of the hooks are defined
148 * in that particular class.
149 *
150 * The Cookie_Law_Info_Loader will then create the relationship
151 * between the defined hooks and the functions defined in this
152 * class.
153 */
154 if ( $this->is_cookie_law_info_admin_screen() ) {
155 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/cookie-law-info-admin.js', array( 'jquery', 'wp-color-picker' ), $this->version, false );
156 wp_localize_script(
157 $this->plugin_name,
158 'ckyConfigs',
159 array(
160 'redirectUrl' => esc_url( admin_url( 'admin.php?page=cookie-law-info' ) )
161 )
162 );
163 }
164
165 }
166
167 /**
168 Registers admin modules
169 */
170 public function admin_modules() {
171 foreach ( $this->modules as $module ) {
172 $module_file = plugin_dir_path( __FILE__ ) . "modules/$module/$module.php";
173 if ( file_exists( $module_file ) ) {
174 self::$existing_modules[] = $module; // this is for module_exits checking
175 require_once $module_file;
176 }
177 }
178 }
179
180 public static function module_exists( $module ) {
181 return in_array( $module, self::$existing_modules );
182 }
183
184 /**
185 Registers menu options
186 Hooked into admin_menu
187 */
188 public function admin_menu() {
189 global $submenu;
190 add_submenu_page(
191 'edit.php?post_type=' . CLI_POST_TYPE,
192 __( 'Settings', 'cookie-law-info' ),
193 __( 'Settings', 'cookie-law-info' ),
194 'manage_options',
195 'cookie-law-info',
196 array( $this, 'admin_settings_page' )
197 );
198 add_submenu_page(
199 'edit.php?post_type=' . CLI_POST_TYPE,
200 __( 'Privacy Overview', 'cookie-law-info' ),
201 __( 'Privacy Overview', 'cookie-law-info' ),
202 'manage_options',
203 'cookie-law-info-poverview',
204 array( $this, 'privacy_overview_page' )
205 );
206 // rearrange settings menu
207 if ( isset( $submenu ) && ! empty( $submenu ) && is_array( $submenu ) ) {
208 $out = array();
209 $back_up_settings_menu = array();
210 if ( isset( $submenu[ 'edit.php?post_type=' . CLI_POST_TYPE ] ) && is_array( $submenu[ 'edit.php?post_type=' . CLI_POST_TYPE ] ) ) {
211 foreach ( $submenu[ 'edit.php?post_type=' . CLI_POST_TYPE ] as $key => $value ) {
212 if ( $value[2] == 'cookie-law-info' ) {
213 $back_up_settings_menu = $value;
214 } else {
215 $out[ $key ] = $value;
216 }
217 }
218 array_unshift( $out, $back_up_settings_menu );
219 $submenu[ 'edit.php?post_type=' . CLI_POST_TYPE ] = $out;
220 }
221 }
222 }
223 /**
224 * Return the default privacy overview contents
225 *
226 * @since 1.9.2
227 * @return array
228 */
229 public static function get_privacy_defaults() {
230
231 $settings = array(
232 'privacy_overview_content' => 'This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.',
233 'privacy_overview_title' => 'Privacy Overview',
234 );
235 return $settings;
236 }
237 /*
238 * Privacy overview CMS page
239 * @since 1.7.7
240 */
241 public function privacy_overview_page() {
242 if ( ! current_user_can( 'manage_options' ) ) {
243 wp_die( esc_html__( 'You do not have sufficient permission to perform this operation', 'cookie-law-info' ) );
244 }
245
246 $stored_options = get_option( 'cookielawinfo_privacy_overview_content_settings' );
247 $stored_options = ( isset( $stored_options ) && is_array( $stored_options ) ) ? $stored_options : array();
248 $default_settings = self::get_privacy_defaults();
249
250 $privacy_title = isset( $stored_options['privacy_overview_title'] ) ? $stored_options['privacy_overview_title'] : $default_settings['privacy_overview_title'];
251 $privacy_content = isset( $stored_options['privacy_overview_content'] ) ? $stored_options['privacy_overview_content'] : $default_settings['privacy_overview_content'];
252
253 if ( isset( $_POST['update_privacy_overview_content_settings_form'] ) ) {
254
255 // Check nonce:
256 check_admin_referer( 'cookielawinfo-update-privacy-overview-content' );
257
258 $privacy_title = $stored_options['privacy_overview_title'] = sanitize_text_field( isset( $_POST['privacy_overview_title'] ) ? wp_unslash( $_POST['privacy_overview_title'] ) : '' );
259 $privacy_content = $stored_options['privacy_overview_content'] = wp_kses_post( isset( $_POST['privacy_overview_content'] ) && $_POST['privacy_overview_content'] !== '' ? wp_unslash( $_POST['privacy_overview_content'] ) : '' );
260
261 update_option( 'cookielawinfo_privacy_overview_content_settings', $stored_options );
262 echo '<div class="updated"><p><strong>' . esc_html__( 'Settings Updated.', 'cookie-law-info' ) . '</strong></p></div>';
263 }
264
265 require_once plugin_dir_path( __FILE__ ) . 'partials/cookie-law-info-privacy_overview.php';
266 }
267 public function plugin_action_links( $links ) {
268 $links[] = '<a href="' . get_admin_url( null, 'edit.php?post_type=' . CLI_POST_TYPE . '&page=cookie-law-info' ) . '">' . __( 'Settings', 'cookie-law-info' ) . '</a>';
269 $links[] = '<a href="https://www.cookieyes.com/support/" target="_blank">' . esc_html__( 'Support', 'cookie-law-info' ) . '</a>';
270 return $links;
271 }
272
273 /*
274 * admin settings page
275 */
276 public function admin_settings_page() {
277 // Lock out non-admins:
278 if ( ! current_user_can( 'manage_options' ) ) {
279 wp_die( esc_html__( 'You do not have sufficient permission to perform this operation', 'cookie-law-info' ) );
280 }
281 // Get options:
282 $the_options = Cookie_Law_Info::get_settings();
283 // Check if form has been set:
284 if ( isset( $_POST['update_admin_settings_form'] ) || // normal php submit
285 ( isset( $_POST['cli_settings_ajax_update'] ) && $_POST['cli_settings_ajax_update'] == 'update_admin_settings_form' ) ) {
286 // Check nonce:
287 check_admin_referer( 'cookielawinfo-update-' . CLI_SETTINGS_FIELD );
288
289 // module settings saving hook
290 do_action( 'cli_module_save_settings' );
291
292 foreach ( $the_options as $key => $value ) {
293 if ( isset( $_POST[ $key . '_field' ] ) ) {
294 // Store sanitised values only:
295 $the_options[ $key ] = Cookie_Law_Info::sanitise_settings( $key, wp_unslash( $_POST[ $key . '_field' ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
296 }
297 }
298 $the_options = apply_filters( 'wt_cli_before_save_settings', $the_options, $_POST );
299 update_option( CLI_SETTINGS_FIELD, $the_options );
300 do_action( 'wt_cli_ajax_settings_update', $_POST );
301 echo '<div class="updated"><p><strong>' . esc_html__( 'Settings Updated.', 'cookie-law-info' ) . '</strong></p></div>';
302 } elseif ( isset( $_POST['delete_all_settings'] ) || // normal php submit
303 ( isset( $_POST['cli_settings_ajax_update'] ) && $_POST['cli_settings_ajax_update'] == 'delete_all_settings' ) ) {
304 // Check nonce:
305 check_admin_referer( 'cookielawinfo-update-' . CLI_SETTINGS_FIELD );
306 $this->delete_settings();
307 // $the_options = Cookie_Law_Info::get_settings();
308 // exit();
309 }
310 if ( ! empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REQUESTED_WITH'] ) ) ) == 'xmlhttprequest' ) {
311 exit();
312 }
313 require_once plugin_dir_path( __FILE__ ) . 'partials/cookie-law-info-admin_settings.php';
314 }
315
316 /**
317 Add custom meta boxes to Cookie Audit custom post type.
318 - Cookie Type (e.g. session, permanent)
319 - Cookie Duration (e.g. 2 hours, days, years, etc)
320 */
321
322
323
324
325 /** Apply column names to the custom post type table */
326
327
328 function remove_cli_addnew_link() {
329 global $submenu;
330 if ( isset( $submenu ) && ! empty( $submenu ) && is_array( $submenu ) ) {
331 unset( $submenu[ 'edit.php?post_type=' . CLI_POST_TYPE ][10] );
332 }
333 }
334
335 /**
336 Delete the values in all fields
337 WARNING - this has a predictable result i.e. will delete saved settings! Once deleted,
338 the get_admin_options() function will not find saved settings so will return default values
339 */
340 public function delete_settings() {
341 if ( defined( 'CLI_ADMIN_OPTIONS_NAME' ) ) {
342 delete_option( CLI_ADMIN_OPTIONS_NAME );
343 }
344 if ( defined( 'CLI_SETTINGS_FIELD' ) ) {
345 delete_option( CLI_SETTINGS_FIELD );
346 }
347 }
348
349 /**
350 Prints a combobox based on options and selected=match value
351
352 Parameters:
353 $options = array of options (suggest using helper functions)
354 $selected = which of those options should be selected (allows just one; is case sensitive)
355
356 Outputs (based on array ( $key => $value ):
357 <option value=$value>$key</option>
358 <option value=$value selected="selected">$key</option>
359 */
360 public function print_combobox_options( $options, $selected ) {
361 foreach ( $options as $option ) {
362 echo '<option value="' . esc_attr( $option['value'] ) . '"';
363 if ( $option['value'] == $selected ) {
364 echo ' selected="selected"';
365 }
366 echo '>' . esc_html( $option['text'] ) . '</option>';
367 }
368 }
369
370 /**
371 Returns list of available jQuery actions
372 Used by buttons/links in header
373 */
374 public function get_js_actions() {
375 $js_actions = array(
376 'close_header' => array(
377 'text' => __( 'Close consent bar', 'cookie-law-info' ),
378 'value' => '#cookie_action_close_header',
379 ),
380 'open_url' => array(
381 'text' => __( 'Redirect to URL on click', 'cookie-law-info' ),
382 'value' => 'CONSTANT_OPEN_URL',
383 ), // Don't change this value, is used by jQuery
384 );
385 return $js_actions;
386 }
387
388 /**
389 Returns button sizes (dependent upon CSS implemented - careful if editing)
390 Used when printing admin form (for combo boxes)
391 */
392 public function get_button_sizes() {
393 $sizes = array(
394 'super' => array(
395 'text' => __( 'Extra Large', 'cookie-law-info' ),
396 'value' => 'super',
397 ),
398 'large' => array(
399 'text' => __( 'Large', 'cookie-law-info' ),
400 'value' => 'large',
401 ),
402 'medium' => array(
403 'text' => __( 'Medium', 'cookie-law-info' ),
404 'value' => 'medium',
405 ),
406 'small' => array(
407 'text' => __( 'Small', 'cookie-law-info' ),
408 'value' => 'small',
409 ),
410 );
411 return $sizes;
412 }
413
414 /**
415 Function returns list of supported fonts
416 Used when printing admin form (for combo box)
417 */
418 public function get_fonts() {
419 $fonts = array(
420 'default' => array(
421 'text' => __( 'Default theme font', 'cookie-law-info' ),
422 'value' => 'inherit',
423 ),
424 'sans_serif' => array(
425 'text' => __( 'Sans Serif', 'cookie-law-info' ),
426 'value' => 'Helvetica, Arial, sans-serif',
427 ),
428 'serif' => array(
429 'text' => __( 'Serif', 'cookie-law-info' ),
430 'value' => 'Georgia, Times New Roman, Times, serif',
431 ),
432 'arial' => array(
433 'text' => __( 'Arial', 'cookie-law-info' ),
434 'value' => 'Arial, Helvetica, sans-serif',
435 ),
436 'arial_black' => array(
437 'text' => __( 'Arial Black', 'cookie-law-info' ),
438 'value' => 'Arial Black,Gadget,sans-serif',
439 ),
440 'georgia' => array(
441 'text' => __( 'Georgia, serif', 'cookie-law-info' ),
442 'value' => 'Georgia, serif',
443 ),
444 'helvetica' => array(
445 'text' => __( 'Helvetica', 'cookie-law-info' ),
446 'value' => 'Helvetica, sans-serif',
447 ),
448 'lucida' => array(
449 'text' => __( 'Lucida', 'cookie-law-info' ),
450 'value' => 'Lucida Sans Unicode, Lucida Grande, sans-serif',
451 ),
452 'tahoma' => array(
453 'text' => __( 'Tahoma', 'cookie-law-info' ),
454 'value' => 'Tahoma, Geneva, sans-serif',
455 ),
456 'times_new_roman' => array(
457 'text' => __( 'Times New Roman', 'cookie-law-info' ),
458 'value' => 'Times New Roman, Times, serif',
459 ),
460 'trebuchet' => array(
461 'text' => __( 'Trebuchet', 'cookie-law-info' ),
462 'value' => 'Trebuchet MS, sans-serif',
463 ),
464 'verdana' => array(
465 'text' => __( 'Verdana', 'cookie-law-info' ),
466 'value' => 'Verdana, Geneva',
467 ),
468 );
469 return $fonts;
470 }
471
472 /**
473 * Set plugin default plugin on activation
474 *
475 * @since 1.9.5
476 * @access public
477 */
478
479 public function load_plugin() {
480
481 if ( is_admin() && get_option( 'wt_cli_first_time_activated_plugin' ) == 'true' ) {
482 do_action( 'wt_cli_initialize_plugin' );
483 delete_option( 'wt_cli_first_time_activated_plugin' );
484 }
485 $this->redirect_to_settings_page();
486 }
487 public static function wt_cli_admin_notice( $type = 'info', $message = '', $icon = false ) {
488 $icon_class = ( true === $icon ) ? 'wt-cli-callout-icon' : '';
489 $html = '<div class="wt-cli-callout wt-cli-callout-' . $type . ' ' . $icon_class . ' ">' . $message . '</div>';
490 return $html;
491 }
492 public function redirect_to_settings_page() {
493 if ( ! isset( $_GET['post_type'] ) && isset( $_GET['page'] ) && $_GET['page'] == 'cookie-law-info' ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
494 wp_safe_redirect( admin_url( 'edit.php?post_type=' . CLI_POST_TYPE . '&page=cookie-law-info' ) );
495 exit();
496 }
497 }
498
499 /**
500 * Output the update banner on all CY plugin admin pages.
501 *
502 * @return void
503 */
504 public function render_update_banner() {
505 if ( $this->is_cookie_law_info_admin_screen() ) {
506 include_once CLI_PLUGIN_PATH . 'admin/partials/wt-cli-update-banner.php';
507 }
508 }
509
510 /**
511 * Output the overlay and modals used by the update banner.
512 * Rendered via admin_footer so position:fixed elements don't sit inside
513 * the admin_notices flow and interfere with other notices.
514 *
515 * @return void
516 */
517 public function render_update_modals() {
518 if ( $this->is_cookie_law_info_admin_screen() ) {
519 include_once CLI_PLUGIN_PATH . 'admin/partials/wt-cli-update-modals.php';
520 }
521 }
522
523 /**
524 * Returns true when the current screen is a Cookie Law Info admin screen.
525 *
526 * Submenu page screen IDs are prefixed with the CPT label ('gdpr-cookie-consent_page_*'),
527 * not the post type slug, so post_type in the URL is the reliable cross-page signal.
528 *
529 * @return bool
530 */
531 private function is_cookie_law_info_admin_screen() {
532 $screen = get_current_screen();
533 if ( $screen && ( CLI_POST_TYPE === $screen->post_type || preg_match( '/cookielawinfo/', $screen->id ) ) ) {
534 return true;
535 }
536
537 $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
538 $post_type = isset( $_GET['post_type'] ) ? sanitize_text_field( wp_unslash( $_GET['post_type'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
539
540 return CLI_POST_TYPE === $post_type || 0 === strpos( $page, 'cookie-law-info' );
541 }
542 }
543