PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.2.2
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.2.2
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 4 years ago
Cookiebot_Recommendation_Notice.php
113 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
47 $notice = array(
48 'title' => __( 'Leave A Review?', 'cookiebot' ),
49 'msg' => __(
50 'We hope you enjoy using WordPress Cookiebot! Would you consider leaving us a review on WordPress.org?',
51 'cookiebot'
52 ),
53 'link_html' => get_view_html(
54 'admin/notices/cookiebot-recommendation-notice-links.php',
55 array(
56 'two_week_review_ignore' => $two_week_review_ignore,
57 'two_week_review_temp' => $two_week_review_temp,
58 )
59 ),
60 'later_link' => $two_week_review_temp,
61 'int' => 14,
62 );
63
64 include_view( 'admin/notices/cookiebot-recommendation-notice.php', array( 'notice' => $notice ) );
65
66 wp_enqueue_style(
67 'cookiebot-admin-notices',
68 asset_url( 'css/notice.css' ),
69 null,
70 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION
71 );
72 }
73
74 /**
75 * Validate if the last user action is valid for plugin recommendation
76 *
77 * @throws Exception
78 *
79 * @version 2.0.5
80 * @since 2.0.5
81 */
82 private function do_we_need_to_show_the_notice_message() {
83 $option = get_option( static::COOKIEBOT_RECOMMENDATION_OPTION_KEY );
84
85 if ( $option !== false ) {
86 //"Never show again" is clicked
87 if ( $option === 'hide' ) {
88 throw new Exception( 'Never show again is clicked' );
89 } elseif ( is_numeric( $option ) && strtotime( 'now' ) < $option ) {
90 throw new Exception( '"Show me after 2 weeks" is clicked and 2 weeks is not passed yet' );
91 }
92 }
93 }
94
95 /**
96 * Save the user action on cookiebot recommendation link
97 *
98 * @version 2.0.5
99 * @since 2.0.5
100 */
101 private function save_notice_link() {
102 if ( isset( $_GET['cookiebot_admin_notice'] ) && isset( $_GET['nonce'] ) ) {
103 if ( wp_verify_nonce( $_GET['nonce'], 'hide_recommendation' ) ) {
104 update_option( static::COOKIEBOT_RECOMMENDATION_OPTION_KEY, 'hide' );
105 }
106
107 if ( wp_verify_nonce( $_GET['nonce'], 'hide_recommendation_for_two_weeks' ) ) {
108 update_option( static::COOKIEBOT_RECOMMENDATION_OPTION_KEY, strtotime( '+2 weeks' ) );
109 }
110 }
111 }
112 }
113