PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.2.11
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.2.11
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
123 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 LogicException;
9 use function cybot\cookiebot\lib\asset_url;
10 use function cybot\cookiebot\lib\get_view_html;
11 use function cybot\cookiebot\lib\include_view;
12
13 class Cookiebot_Recommendation_Notice {
14
15 const COOKIEBOT_RECOMMENDATION_OPTION_KEY = 'cookiebot_notice_recommend';
16
17 public function register_hooks() {
18 add_action( 'admin_notices', array( $this, 'show_notice_if_needed' ) );
19 }
20
21 public function show_notice_if_needed() {
22 /** Save actions when someone click on the notice message */
23 $this->save_notice_link();
24
25 try {
26 $this->do_we_need_to_show_the_notice_message();
27 $this->show_notice();
28 // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
29 } catch ( Exception $e ) {
30 // If exception has been thrown, then we don't need to show the notice.
31 }
32 }
33
34 /**
35 * @throws InvalidArgumentException
36 */
37 private function show_notice() {
38 $two_week_review_ignore = wp_nonce_url(
39 add_query_arg( array( 'cookiebot_admin_notice' => 'hide' ) ),
40 'hide_recommendation',
41 'nonce'
42 );
43 $two_week_review_temp = wp_nonce_url(
44 add_query_arg( array( 'cookiebot_admin_notice' => 'two_week' ) ),
45 'hide_recommendation_for_two_weeks',
46 'nonce'
47 );
48 $visit_review_temp = wp_nonce_url(
49 add_query_arg( array( 'cookiebot_admin_notice' => 'visit' ) ),
50 'hide_recommendation_next',
51 'nonce'
52 );
53
54 $notice = array(
55 'title' => __( 'Leave A Review?', 'cookiebot' ),
56 'msg' => __(
57 '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.',
58 'cookiebot'
59 ),
60 'link_html' => get_view_html(
61 'admin/notices/cookiebot-recommendation-notice-links.php',
62 array(
63 'two_week_review_ignore' => $two_week_review_ignore,
64 'two_week_review_temp' => $two_week_review_temp,
65 'visit_review_temp' => $visit_review_temp,
66 )
67 ),
68 'later_link' => $visit_review_temp,
69 'int' => 14,
70 );
71
72 include_view( 'admin/notices/cookiebot-recommendation-notice.php', array( 'notice' => $notice ) );
73
74 wp_enqueue_style(
75 'cookiebot-admin-notices',
76 asset_url( 'css/notice.css' ),
77 null,
78 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION
79 );
80 }
81
82 /**
83 * Validate if the last user action is valid for plugin recommendation
84 *
85 * @throws Exception
86 *
87 * @version 2.0.5
88 * @since 2.0.5
89 */
90 private function do_we_need_to_show_the_notice_message() {
91 $option = get_option( static::COOKIEBOT_RECOMMENDATION_OPTION_KEY );
92
93 if ( $option !== false ) {
94 // "Never show again" is clicked
95 if ( $option === 'hide' ) {
96 throw new LogicException( 'Never show again is clicked' );
97 } elseif ( $option === 'visit' ) {
98 throw new LogicException( 'Show me after 1 day' );
99 } elseif ( is_numeric( $option ) && strtotime( 'now' ) < $option ) {
100 throw new LogicException( 'Show me after 1 day' );
101 }
102 }
103 }
104
105 /**
106 * Save the user action on cookiebot recommendation link
107 *
108 * @version 2.0.5
109 * @since 2.0.5
110 */
111 private function save_notice_link() {
112 if ( isset( $_GET['cookiebot_admin_notice'] ) && isset( $_GET['nonce'] ) ) {
113 if ( wp_verify_nonce( $_GET['nonce'], 'hide_recommendation' ) ) {
114 update_option( static::COOKIEBOT_RECOMMENDATION_OPTION_KEY, 'hide' );
115 }
116
117 if ( wp_verify_nonce( $_GET['nonce'], 'hide_recommendation_next' ) ) {
118 update_option( static::COOKIEBOT_RECOMMENDATION_OPTION_KEY, strtotime( '+1 day' ) );
119 }
120 }
121 }
122 }
123