PluginProbe
WPIDE – File Manager & Code Editor / 3.5.9
WPIDE – File Manager & Code Editor v3.5.9
3.5.9 3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 All 55 releases
← All changes | App/Classes/ReviewNotice.php +40 -46 3.23.5.9 View file →
@@ -15,48 +15,35 @@
15 15 class ReviewNotice {
16 16
17 17 /**
18 18 * Interval in days between reminder notice
19 - *
20 - * @since 1.0.0
21 - * @access public
22 - * @const int days_interval
23 19 */
24 20 public const days_interval = 7;
25 21
26 22 /**
27 23 * Max days before stopping the reminder notice
28 - *
29 - * @since 1.0.0
30 - * @access public
31 - * @const int max_days
32 24 */
33 25 public const max_days = 120;
34 26
35 27 /**
36 28 * Check if a notice is currently active
37 - *
38 - * @since 1.0.0
39 - * @access public
40 - * @var bool $active_notice
41 29 */
42 30 public static $active_notice = false;
43 31
44 32 /**
45 33 * Review url
46 - *
47 - * @since 1.0.0
48 - * @access public
49 - * @var string review_url
50 34 */
51 35 public static $review_url = '';
52 36
37 + /**
38 + * @throws \Exception
39 + */
53 40 public static function init() {
54 41
55 42 self::$review_url = 'https://wordpress.org/support/plugin/'. SLUG .'/reviews/?rate=5&filter=5/#new-post';
56 43
57 44 // Add Ajax Events
58 - add_action("wp_ajax_".SLUG."_plugin_rate_action", [__CLASS__, 'ajax_plugin_rate_action']);
45 + add_action("wp_ajax_".SLUG."_plugin_rate_action", [__CLASS__, 'ajaxPluginRateAction']);
59 46 add_action('admin_enqueue_scripts', [__CLASS__, 'enqueue_admin_assets'], 1);
60 47
61 48 if(!self::enabled()) {
62 49 return;
@@ -67,18 +54,21 @@
67 54 // Init Review Notice
68 55 add_action( 'admin_notices', [ __CLASS__, 'add_review_notice' ] );
69 56 }
70 57
58 + /**
59 + * @throws \Exception
60 + */
71 61 public static function enabled(): bool
72 62 {
73 63
74 - $min_days_trigger = self::get_min_days_trigger();
75 - $days_passed = self::get_days_passed();
64 + $min_days_trigger = self::getMinDaysTrigger();
65 + $days_passed = self::getDaysPassed();
76 66
77 67 return $min_days_trigger !== -1 && $days_passed >= $min_days_trigger && !self::$active_notice;
78 68 }
79 69
80 - public static function get_min_days_trigger(): int
70 + public static function getMinDaysTrigger(): int
81 71 {
82 72
83 73 $option_key = App::instance()->prefix('review_notice_min_days');
84 74 return intval(get_option($option_key, self::days_interval));
@@ -83,15 +73,16 @@
83 73 $option_key = App::instance()->prefix('review_notice_min_days');
84 74 return intval(get_option($option_key, self::days_interval));
85 75 }
86 76
87 - public static function set_min_days_trigger($value) {
77 + public static function setMinDaysTrigger($value): bool
78 + {
88 79
89 80 $option_key = App::instance()->prefix('review_notice_min_days');
90 81 return update_option($option_key, $value);
91 82 }
92 83
93 - public static function get_days_passed(): int
84 + public static function getDaysPassed(): int
94 85 {
95 86
96 87 $install_timestamp = Migrations::$installed_time;
97 88 $current_time = time();
@@ -100,9 +91,10 @@
100 91
101 92 return intval(round($date_diff / (60 * 60 * 24)));
102 93 }
103 94
104 - public static function get_readable_days_passed() {
95 + public static function getReadableDaysPassed(): string
96 + {
105 97
106 98 $install_timestamp = Migrations::$installed_time;
107 99 $current_time = time();
108 100
@@ -108,28 +100,28 @@
108 100
109 101 return human_time_diff($install_timestamp, $current_time);
110 102 }
111 103
112 - public static function ajax_plugin_rate_action() {
104 + public static function ajaxPluginRateAction() {
113 105
114 106 // Continue only if the nonce is correct
115 107 $nonce = sanitize_text_field($_REQUEST['_nonce']);
116 108
117 - if ( ! wp_verify_nonce( $nonce, App::instance()->prefix('wp_rate_action_nonce') ) ) {
109 + if ( ! wp_verify_nonce( $nonce, App::instance()->prefix('wp_notice_action_nonce') ) ) {
118 110 wp_send_json_error();
119 111 }
120 112
121 - $rate_action = sanitize_text_field($_POST['rate_action']);
113 + $notice_action = sanitize_text_field($_POST['notice_action']);
122 114
123 - self::rate_plugin($rate_action);
115 + self::ratePlugin($notice_action);
124 116
125 117 wp_send_json_success();
126 118 }
127 119
128 - public static function rate_plugin($rate_action, $days_interval = null) {
120 + public static function ratePlugin($notice_action, $days_interval = null) {
129 121
130 - $min_days_trigger = self::get_min_days_trigger();
131 - $days_passed = self::get_days_passed();
122 + $min_days_trigger = self::getMinDaysTrigger();
123 + $days_passed = self::getDaysPassed();
132 124 $days_interval = !empty($days_interval) ? $days_interval : self::days_interval;
133 125
134 126 if ( -1 === $min_days_trigger ) {
135 127 return;
@@ -134,9 +126,9 @@
134 126 if ( -1 === $min_days_trigger ) {
135 127 return;
136 128 }
137 129
138 - if ('done-rating' === $rate_action) {
130 + if ('done-rating' === $notice_action) {
139 131
140 132 $min_days_trigger = -1;
141 133
142 134 } else {
@@ -147,9 +139,9 @@
147 139 $min_days_trigger = $days_passed + $days_interval;
148 140 }
149 141 }
150 142
151 - self::set_min_days_trigger($min_days_trigger);
143 + self::setMinDaysTrigger($min_days_trigger);
152 144 }
153 145
154 146 public static function add_review_notice() {
155 147
@@ -155,23 +147,25 @@
155 147
156 148 $current_user = wp_get_current_user();
157 149 $first_name = ucfirst(strtolower(!empty($current_user->user_firstname) ? $current_user->user_firstname : $current_user->display_name));
158 150
159 - $time_passed = self::get_readable_days_passed();
151 + $time_passed = self::getReadableDaysPassed();
160 152 $action = SLUG."_plugin_rate_action";
161 153 ?>
162 - <div class="notice notice-info wpide-rating-notice" data-slug="<?php echo esc_attr(SLUG); ?>">
163 - <?php
164 - echo sprintf(esc_html__("Hey %s, I noticed you've been using %s for the past %s – that’s awesome!", "wpide"), $first_name, '<strong>' . NAME . '</strong>', '<strong>'.$time_passed.'</strong>');
165 - echo '&nbsp;';
166 - echo sprintf(esc_html__('Could you please do me a %1$sBIG favor%2$s and give it a %1$s5-star rating%2$s on WordPress? Just to %1$s help us%2$s spread the word and boost our motivation. Many thanks!', "wpide"), "<strong>", "</strong>");
167 - ?>
168 - <br><br><em>~ Georges H</em>
169 - <br><br>
170 - <ul class="wpide-wp-rate-notice" data-action="<?php echo esc_attr($action);?>" data-nonce="<?php echo wp_create_nonce( App::instance()->prefix('wp_rate_action_nonce') ) ?>">
154 + <div class="notice notice-info wpide-notice" data-slug="<?php echo esc_attr(SLUG); ?>">
155 + <p>
156 + <?php
157 + echo sprintf(esc_html__("Hey %s, I noticed you've been using %s for the past %s – that’s awesome!", "wpide"), $first_name, '<strong>' . NAME . '</strong>', '<strong>'.$time_passed.'</strong>');
158 + echo '&nbsp;';
159 + echo sprintf(esc_html__('Could you please do me a %1$sBIG favor%2$s and give it a %1$s5-star rating%2$s on WordPress? Just to %1$s help us%2$s spread the word and boost our motivation. Many thanks!', "wpide"), "<strong>", "</strong>");
160 + ?>
161 + <br><br>
162 + <em>~ Georges H</em>
163 + </p>
164 + <ul class="wpide-notice-action" data-action="<?php echo esc_attr($action);?>" data-nonce="<?php echo wp_create_nonce( App::instance()->prefix('wp_notice_action_nonce') ) ?>">
171 165 <li><span class="dashicons dashicons-thumbs-up"></span> <a target="_blank" href="<?php echo esc_url(self::$review_url);?>"><?php echo esc_html__( 'Ok, you deserve it', 'wpide' ) ?></a></li>
172 - <li><span class="dashicons dashicons-thumbs-down"></span> <a data-rate-action="not-enough" href="#"><?php echo esc_html__( 'Nope, maybe later', 'wpide' ) ?></a></li>
173 - <li><span class="dashicons dashicons-yes"></span> <a data-rate-action="done-rating" href="#"><?php echo esc_html__( 'I already did', 'wpide' ) ?></a></li>
166 + <li><span class="dashicons dashicons-thumbs-down"></span> <a data-action="not-enough" href="#"><?php echo esc_html__( 'Nope, maybe later', 'wpide' ) ?></a></li>
167 + <li><span class="dashicons dashicons-yes"></span> <a data-action="done-rating" href="#"><?php echo esc_html__( 'I already did', 'wpide' ) ?></a></li>
174 168 <li><span class="dashicons dashicons-sos"></span> <a target="_blank" href="https://xplodedthemes.com/support/"><?php echo esc_html__( 'Help me first', 'wpide' ) ?></a></li>
175 169 </ul>
176 170 </div>
177 171 <?php
@@ -179,9 +173,9 @@
179 173
180 174 public static function enqueue_admin_assets()
181 175 {
182 176
183 - wp_enqueue_script(SLUG.'-rating-notice', ASSETS_URL.'global/js/rating-notice-min.js', [], VERSION);
184 - wp_enqueue_style(SLUG.'-rating-notice', ASSETS_URL.'global/css/rating-notice.css', [], VERSION);
177 + wp_enqueue_script(SLUG.'-notice', ASSETS_URL.'global/js/notice-min.js', [], VERSION);
178 + wp_enqueue_style(SLUG.'-notice', ASSETS_URL.'global/css/notice.css', [], VERSION);
185 179 }
186 180
187 181 }