PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.2.8
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.2.8
4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.5 3.6.6 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.2.0 4.2.1 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.10 4.3.11 4.3.12 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.7.1 4.3.8 4.3.9 4.3.9.1 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.7.0
cookiebot / src / admin_notices / Cookiebot_Recommendation_Notice.php
cookiebot / src / admin_notices Last commit date
Cookiebot_Recommendation_Notice.php 3 years ago
Cookiebot_Recommendation_Notice.php
121 lines
1 <?php
2
3 namespace cybot\cookiebot\admin_notices;
4
5 use Exception;
6 use cybot\cookiebot\lib\Cookiebot_WP;
7 use InvalidArgumentException;
8 use function cybot\cookiebot\lib\asset_url;
9 use function cybot\cookiebot\lib\get_view_html;
10 use function cybot\cookiebot\lib\include_view;
11
12 class Cookiebot_Recommendation_Notice {
13
14 const COOKIEBOT_RECOMMENDATION_OPTION_KEY = 'cookiebot_notice_recommend';
15
16 public function register_hooks() {
17 add_action( 'admin_notices', array( $this, 'show_notice_if_needed' ) );
18 }
19
20 public function show_notice_if_needed() {
21 /** Save actions when someone click on the notice message */
22 $this->save_notice_link();
23
24 try {
25 $this->do_we_need_to_show_the_notice_message();
26 $this->show_notice();
27 // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
28 } catch ( Exception $e ) {
29 }
30 }
31
32 /**
33 * @throws InvalidArgumentException
34 */
35 private function show_notice() {
36 $two_week_review_ignore = wp_nonce_url(
37 add_query_arg( array( 'cookiebot_admin_notice' => 'hide' ) ),
38 'hide_recommendation',
39 'nonce'
40 );
41 $two_week_review_temp = wp_nonce_url(
42 add_query_arg( array( 'cookiebot_admin_notice' => 'two_week' ) ),
43 'hide_recommendation_for_two_weeks',
44 'nonce'
45 );
46 $visit_review_temp = wp_nonce_url(
47 add_query_arg( array( 'cookiebot_admin_notice' => 'visit' ) ),
48 'hide_recommendation_next',
49 'nonce'
50 );
51
52 $notice = array(
53 'title' => __( 'Leave A Review? ', 'cookiebot' ),
54 'msg' => __(
55 'Hi, you have been using our Cookiebot CMP plugin to actively collect user consent - that is awesome. Could you please do us a BIG favor and give it a 5-star rating on WordPress? To help us spread the word and enable more WP websites to easily achieve compliance with GDPR and CCPA.',
56 'cookiebot'
57 ),
58 'link_html' => get_view_html(
59 'admin/notices/cookiebot-recommendation-notice-links.php',
60 array(
61 'two_week_review_ignore' => $two_week_review_ignore,
62 'two_week_review_temp' => $two_week_review_temp,
63 'visit_review_temp' => $visit_review_temp,
64 )
65 ),
66 'later_link' => $two_week_review_temp,
67 'int' => 14,
68 );
69
70 include_view( 'admin/notices/cookiebot-recommendation-notice.php', array( 'notice' => $notice ) );
71
72 wp_enqueue_style(
73 'cookiebot-admin-notices',
74 asset_url( 'css/notice.css' ),
75 null,
76 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION
77 );
78 }
79
80 /**
81 * Validate if the last user action is valid for plugin recommendation
82 *
83 * @throws Exception
84 *
85 * @version 2.0.5
86 * @since 2.0.5
87 */
88 private function do_we_need_to_show_the_notice_message() {
89 $option = get_option( static::COOKIEBOT_RECOMMENDATION_OPTION_KEY );
90
91 if ( $option !== false ) {
92 // "Never show again" is clicked
93 if ( $option === 'hide' ) {
94 throw new Exception( 'Never show again is clicked' );
95 } elseif ( $option === 'visit' ) {
96 throw new Exception( 'Show me after 1 day' );
97 } elseif ( is_numeric( $option ) && strtotime( 'now' ) < $option ) {
98 throw new Exception( 'Show me after 1 day' );
99 }
100 }
101 }
102
103 /**
104 * Save the user action on cookiebot recommendation link
105 *
106 * @version 2.0.5
107 * @since 2.0.5
108 */
109 private function save_notice_link() {
110 if ( isset( $_GET['cookiebot_admin_notice'] ) && isset( $_GET['nonce'] ) ) {
111 if ( wp_verify_nonce( $_GET['nonce'], 'hide_recommendation' ) ) {
112 update_option( static::COOKIEBOT_RECOMMENDATION_OPTION_KEY, 'hide' );
113 }
114
115 if ( wp_verify_nonce( $_GET['nonce'], 'hide_recommendation_next' ) ) {
116 update_option( static::COOKIEBOT_RECOMMENDATION_OPTION_KEY, strtotime( '+1 day' ) );
117 }
118 }
119 }
120 }
121