PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.3.2
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.3.2
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 / Helpers / ReviewNotice.php

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

149 lines 5.1 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\Helpers;
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/HelpPage/assets/images/darkify.gif'); ?>" alt="Darkify">
64 </div>
65 <div class="darkify-notice-text">
66 <h3>Enjoying <strong>Darkify</strong>?</h3>
67 <p>We hope you had a wonderful experience using <strong>Darkify</strong>. Please take a moment to leave a review on <a href="https://wordpress.org/support/plugin/darkify/reviews/?filter=5#new-post" target="_blank"><strong>WordPress.org</strong></a>.
68 Your positive review will help us improve. Thank you! 😊</p>
69
70 <p class="darkify-review-actions">
71 <a href="https://wordpress.org/support/plugin/darkify/reviews/?filter=5#new-post" target="_blank" class="button button-primary notice-dismissed rate-darkify">Ok, you deserve �
72
73
74
75
76 </a>
77 <a href="#" class="notice-dismissed remind-me-later"><span class="dashicons dashicons-clock"></span>Nope, maybe later
78 </a>
79 <a href="#" class="notice-dismissed never-show-again"><span class="dashicons dashicons-dismiss"></span>Never show again</a>
80 </p>
81 </div>
82 </div>
83
84 <script type='text/javascript'>
85 jQuery(document).ready(function($) {
86 $(document).on('click', '#darkify-review-notice.darkify-review-notice .notice-dismissed', function(event) {
87 if ($(this).hasClass('rate-darkify')) {
88 var notice_dismissed_value = "1";
89 }
90 if ($(this).hasClass('remind-me-later')) {
91 var notice_dismissed_value = "2";
92 event.preventDefault();
93 }
94 if ($(this).hasClass('never-show-again')) {
95 var notice_dismissed_value = "3";
96 event.preventDefault();
97 }
98
99 $.post(ajaxurl, {
100 action: 'darkify-review-notice',
101 notice_dismissed_data: notice_dismissed_value,
102 nonce: '<?php echo esc_attr(wp_create_nonce('darkify_review_notice')); ?>'
103 });
104
105 $('#darkify-review-notice.darkify-review-notice').hide();
106 });
107 });
108 </script>
109 <?php
110 }
111
112 /**
113 * Dismiss review notice
114 *
115 * @since 2.0.4
116 *
117 * @return void
118 **/
119 public function dismiss_review_notice()
120 {
121 $post_data = wp_unslash($_POST);
122 $review = get_option('darkify_review_notice_dismiss');
123
124 if (! isset($post_data['nonce']) || ! wp_verify_nonce(sanitize_key($post_data['nonce']), 'darkify_review_notice')) {
125 return;
126 }
127
128 if (! $review) {
129 $review = array();
130 }
131 switch (isset($post_data['notice_dismissed_data']) ? $post_data['notice_dismissed_data'] : '') {
132 case '1':
133 $review['time'] = time();
134 $review['dismissed'] = true;
135 break;
136 case '2':
137 $review['time'] = time();
138 $review['dismissed'] = false;
139 break;
140 case '3':
141 $review['time'] = time();
142 $review['dismissed'] = true;
143 break;
144 }
145 update_option('darkify_review_notice_dismiss', $review);
146 die;
147 }
148 }
149