PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 2.1.0
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v2.1.0
2.1.3 2.1.2 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 trunk 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 All 57 releases
darkify / src / Admin / ReviewNotice / ReviewNotice.php

ReviewNotice.php in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 2.1.0, at src/Admin/ReviewNotice/ReviewNotice.php

153 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The public-facing functionality of the plugin.
5 *
6 * Defines the plugin name, version, and two examples hooks for how to
7 * enqueue the public-facing stylesheet and JavaScript.
8 *
9 * @link https://themeatelier.net
10 * @since 1.0.0
11 *
12 * @package darkify
13 * @subpackage darkify/src/Helpers
14 * @author ThemeAtelier<themeatelierbd@gmail.com>
15 */
16
17 namespace ThemeAtelier\Darkify\Admin\ReviewNotice;
18
19 /**
20 * The Helpers class to manage all public facing stuffs.
21 *
22 * @since 1.0.0
23 */
24 class ReviewNotice
25 {
26 public function __construct()
27 {
28 add_action('admin_notices', [$this, 'display_admin_notice']);
29 add_action('wp_ajax_darkify-never-show-review-notice', [$this, 'dismiss_review_notice']);
30 }
31 public function display_admin_notice()
32 {
33 // Show only to Admins.
34 if (! current_user_can('manage_options')) {
35 return;
36 }
37
38 // Variable default value.
39 $review = get_option('darkify_review_notice_dismiss');
40 $time = time();
41 $load = false;
42
43 if (! $review) {
44 $review = array(
45 'time' => $time,
46 'dismissed' => false,
47 );
48 add_option('darkify_review_notice_dismiss', $review);
49 } else {
50 // Check if it has been dismissed or not.
51 if ((isset($review['dismissed']) && ! $review['dismissed']) && (isset($review['time']) && (($review['time'] + (DAY_IN_SECONDS * 3)) <= $time))) {
52 $load = true;
53 }
54 }
55
56 // If we cannot load, return early.
57 if (! $load) {
58 return;
59 }
60 ?>
61 <div id="darkify-review-notice" class="darkify-review-notice">
62 <div class="darkify-plugin-icon">
63 <img src="<?php echo esc_url(DARKIFY_DIR_URL . 'src/Admin/assets/images/darkify-icon.svg'); ?>" alt="Darkify dark mode plugin">
64 </div>
65 <div class="darkify-notice-text">
66 <?php
67 $review = get_option('darkify_review_notice_dismiss');
68
69 ?>
70 <h3><?php echo esc_html__('Enjoying', 'darkify') ?> <strong><?php echo esc_html__('Darkify', 'darkify') ?></strong>?</h3>
71 <p><?php echo esc_html__('We hope you had a wonderful experience using', 'darkify') ?> <strong><?php echo esc_html__('Darkify', 'darkify') ?></strong>. <?php echo esc_html__('Please take a moment to leave a review on', 'darkify') ?> <a href="https://wordpress.org/support/plugin/darkify/reviews/#new-post" target="_blank"><strong><?php echo esc_html__('WordPress.org', 'darkify') ?></strong></a>.
72 <?php echo esc_html__('Your positive review will help us improve. Thank you!', 'darkify') ?> 😊</p>
73
74 <p class="darkify-review-actions">
75 <a href="https://wordpress.org/support/plugin/darkify/reviews/#new-post" target="_blank" class="button button-primary notice-dismissed rate-darkify"><?php echo esc_html__('Ok, you deserve', 'darkify') ?> �
76
77
78
79
80 </a>
81 <a href="#" class="notice-dismissed remind-me-later"><span class="dashicons dashicons-clock"></span><?php echo esc_html__('Nope, maybe later', 'darkify') ?>
82 </a>
83 <a href="#" class="notice-dismissed never-show-again"><span class="dashicons dashicons-dismiss"></span><?php echo esc_html__('Never show again', 'darkify') ?></a>
84 </p>
85 </div>
86 </div>
87
88 <script type='text/javascript'>
89 jQuery(document).ready(function($) {
90 $(document).on('click', '#darkify-review-notice.darkify-review-notice .notice-dismissed', function(event) {
91 if ($(this).hasClass('rate-darkify')) {
92 var notice_dismissed_value = "1";
93 }
94 if ($(this).hasClass('remind-me-later')) {
95 var notice_dismissed_value = "2";
96 event.preventDefault();
97 }
98 if ($(this).hasClass('never-show-again')) {
99 var notice_dismissed_value = "3";
100 event.preventDefault();
101 }
102
103 $.post(ajaxurl, {
104 action: 'darkify-never-show-review-notice',
105 notice_dismissed_data: notice_dismissed_value,
106 nonce: '<?php echo esc_attr(wp_create_nonce('darkify_review_notice')); ?>'
107 });
108
109 $('#darkify-review-notice.darkify-review-notice').hide();
110 });
111 });
112 </script>
113 <?php
114 }
115
116 /**
117 * Dismiss review notice
118 *
119 * @since 2.0.4
120 *
121 * @return void
122 **/
123 public function dismiss_review_notice()
124 {
125 $post_data = wp_unslash($_POST);
126 $review = get_option('darkify_review_notice_dismiss');
127
128 if (! isset($post_data['nonce']) || ! wp_verify_nonce(sanitize_key($post_data['nonce']), 'darkify_review_notice')) {
129 return;
130 }
131
132 if (! $review) {
133 $review = array();
134 }
135 switch (isset($post_data['notice_dismissed_data']) ? $post_data['notice_dismissed_data'] : '') {
136 case '1':
137 $review['time'] = time();
138 $review['dismissed'] = true;
139 break;
140 case '2':
141 $review['time'] = time();
142 $review['dismissed'] = false;
143 break;
144 case '3':
145 $review['time'] = time();
146 $review['dismissed'] = true;
147 break;
148 }
149 update_option('darkify_review_notice_dismiss', $review);
150 die;
151 }
152 }
153