Version Description
Metform 1.3.0-beta1 is a major update. We have reconstructed the widgets with react and huge optimization for future proof. If you faced any issue please contact our support team from here https://help.wpmet.com/
Download this release
Release Info
Developer | ataurr |
Plugin | Metform Elementor Contact Form Builder – Flexible and Design-Friendly Contact Form builder plugin for WordPress |
Version | 1.3.11 |
Comparing to | |
See all releases |
Code changes from version 1.3.10 to 1.3.11
- metform.php +1 -1
- plugin.php +1 -1
- readme.txt +2 -2
- utils/banner/init.php +259 -259
- utils/notice/notice.php +482 -482
- utils/rating-notice.php +374 -359
- utils/rating.php +310 -311
metform.php
CHANGED
@@ -5,7 +5,7 @@ defined( 'ABSPATH' ) || exit;
|
|
5 |
* Plugin Name: MetForm
|
6 |
* Plugin URI: http://products.wpmet.com/metform/
|
7 |
* Description: Most flexible and design friendly form builder for Elementor
|
8 |
-
* Version: 1.3.
|
9 |
* Author: Wpmet
|
10 |
* Author URI: https://wpmet.com
|
11 |
* Text Domain: metform
|
5 |
* Plugin Name: MetForm
|
6 |
* Plugin URI: http://products.wpmet.com/metform/
|
7 |
* Description: Most flexible and design friendly form builder for Elementor
|
8 |
+
* Version: 1.3.11
|
9 |
* Author: Wpmet
|
10 |
* Author URI: https://wpmet.com
|
11 |
* Text Domain: metform
|
plugin.php
CHANGED
@@ -16,7 +16,7 @@ final class Plugin{
|
|
16 |
}
|
17 |
|
18 |
public function version(){
|
19 |
-
return '1.3.
|
20 |
}
|
21 |
|
22 |
public function package_type(){
|
16 |
}
|
17 |
|
18 |
public function version(){
|
19 |
+
return '1.3.11';
|
20 |
}
|
21 |
|
22 |
public function package_type(){
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: ataurr, wpmet, emranio, prappo_p, atiqsu, easin55474, enamulhoquem
|
|
3 |
Tags: Form builder, Elementor form builder, contact form, custom form, forms, drag & drop form builder
|
4 |
Requires at least: 4.8
|
5 |
Tested up to: 5.5.1
|
6 |
-
Stable tag: 1.3.
|
7 |
Requires PHP: 7.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
@@ -221,7 +221,7 @@ Connect with Gmail, Slack, Mailchimp, and many more.
|
|
221 |
|
222 |
|
223 |
== Changelog ==
|
224 |
-
Version 1.3.10
|
225 |
Fix : Minor bug fix
|
226 |
|
227 |
Version 1.3.9
|
3 |
Tags: Form builder, Elementor form builder, contact form, custom form, forms, drag & drop form builder
|
4 |
Requires at least: 4.8
|
5 |
Tested up to: 5.5.1
|
6 |
+
Stable tag: 1.3.11
|
7 |
Requires PHP: 7.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
221 |
|
222 |
|
223 |
== Changelog ==
|
224 |
+
Version 1.3.10 & 11
|
225 |
Fix : Minor bug fix
|
226 |
|
227 |
Version 1.3.9
|
utils/banner/init.php
CHANGED
@@ -1,259 +1,259 @@
|
|
1 |
-
<?php
|
2 |
-
namespace Wpmet\Libs\Banner;
|
3 |
-
|
4 |
-
defined( 'ABSPATH' ) || exit;
|
5 |
-
|
6 |
-
if(class_exists('\Wpmet\Libs\Banner\Init'))
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
protected $
|
13 |
-
|
14 |
-
protected $
|
15 |
-
protected $
|
16 |
-
protected $
|
17 |
-
|
18 |
-
protected $
|
19 |
-
|
20 |
-
protected $
|
21 |
-
|
22 |
-
protected $
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
//
|
42 |
-
$this->
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
$
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
$list
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
if($
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
$match
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
$
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
$match
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
$match_arr
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
$this
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
$this
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
$this
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
$this
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
$this->
|
174 |
-
|
175 |
-
|
176 |
-
$this->
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
)
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
$screen
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
->
|
224 |
-
->
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
1 |
+
<?php
|
2 |
+
namespace Wpmet\Libs\Banner;
|
3 |
+
|
4 |
+
defined( 'ABSPATH' ) || exit;
|
5 |
+
|
6 |
+
if(!class_exists('\Wpmet\Libs\Banner\Init')):
|
7 |
+
|
8 |
+
class Init {
|
9 |
+
|
10 |
+
protected $script_version = '1.0.5';
|
11 |
+
|
12 |
+
protected $key;
|
13 |
+
protected $api;
|
14 |
+
protected $data;
|
15 |
+
protected $last_check;
|
16 |
+
protected $check_interval;
|
17 |
+
|
18 |
+
protected $plugin_screens;
|
19 |
+
|
20 |
+
protected $text_domain;
|
21 |
+
protected $filter_string;
|
22 |
+
protected $api_url;
|
23 |
+
|
24 |
+
|
25 |
+
public function get_version(){
|
26 |
+
return $this->script_version;
|
27 |
+
}
|
28 |
+
|
29 |
+
public function get_script_location(){
|
30 |
+
return __FILE__;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function call(){
|
34 |
+
|
35 |
+
|
36 |
+
$this->key = 'wpmet_banner';
|
37 |
+
$this->api = $this->api_url . '?test=rrr&nocache='.time().'&plugin='. $this->text_domain.'&filter='. $this->filter_string;
|
38 |
+
|
39 |
+
// seconds
|
40 |
+
$this->check_interval = (3600 * 2);
|
41 |
+
// $this->check_interval = 1;
|
42 |
+
$this->get_banner();
|
43 |
+
|
44 |
+
if(!empty($this->data->error)) {
|
45 |
+
|
46 |
+
return;
|
47 |
+
}
|
48 |
+
|
49 |
+
if(empty($this->data)) {
|
50 |
+
|
51 |
+
return;
|
52 |
+
}
|
53 |
+
|
54 |
+
$list = [];
|
55 |
+
|
56 |
+
if(!empty($this->filter_string)) {
|
57 |
+
|
58 |
+
$list = explode(',', $this->filter_string);
|
59 |
+
|
60 |
+
foreach ($list as $idx => $item) {
|
61 |
+
$list[$idx] = trim($item);
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
foreach($this->data as $banner) {
|
66 |
+
|
67 |
+
if($banner->type != 'banner') continue;
|
68 |
+
|
69 |
+
if(!empty($list) && $this->in_blacklist($banner, $list)) {
|
70 |
+
|
71 |
+
continue;
|
72 |
+
}
|
73 |
+
|
74 |
+
$this->show($banner);
|
75 |
+
}
|
76 |
+
}
|
77 |
+
|
78 |
+
|
79 |
+
private function in_whitelist($conf, $list) {
|
80 |
+
|
81 |
+
$match = $conf->data->whitelist;
|
82 |
+
|
83 |
+
if(empty($match)) {
|
84 |
+
|
85 |
+
return true;
|
86 |
+
};
|
87 |
+
|
88 |
+
$match_arr = explode(',', $match);
|
89 |
+
|
90 |
+
foreach($list as $word) {
|
91 |
+
if(in_array($word, $match_arr)) {
|
92 |
+
|
93 |
+
return true;
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
return false;
|
98 |
+
}
|
99 |
+
|
100 |
+
|
101 |
+
private function in_blacklist($conf, $list) {
|
102 |
+
|
103 |
+
$match = $conf->data->blacklist;
|
104 |
+
|
105 |
+
if(empty($match)) {
|
106 |
+
|
107 |
+
return false;
|
108 |
+
};
|
109 |
+
|
110 |
+
$match_arr = explode(',', $match);
|
111 |
+
|
112 |
+
foreach($match_arr as $idx => $item) {
|
113 |
+
|
114 |
+
$match_arr[$idx] = trim($item);
|
115 |
+
}
|
116 |
+
|
117 |
+
foreach($list as $word) {
|
118 |
+
if(in_array($word, $match_arr)) {
|
119 |
+
|
120 |
+
return true;
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
return false;
|
125 |
+
}
|
126 |
+
|
127 |
+
|
128 |
+
public function is_test($is_test = false) {
|
129 |
+
|
130 |
+
if($is_test === true){
|
131 |
+
$this->check_interval = 1;
|
132 |
+
}
|
133 |
+
|
134 |
+
return $this;
|
135 |
+
}
|
136 |
+
|
137 |
+
|
138 |
+
public function set_text_domain($text_domain) {
|
139 |
+
|
140 |
+
$this->text_domain = $text_domain;
|
141 |
+
|
142 |
+
return $this;
|
143 |
+
}
|
144 |
+
|
145 |
+
|
146 |
+
public function set_filter($filter_string) {
|
147 |
+
|
148 |
+
$this->filter_string = $filter_string;
|
149 |
+
|
150 |
+
return $this;
|
151 |
+
}
|
152 |
+
|
153 |
+
|
154 |
+
public function set_api_url($url) {
|
155 |
+
|
156 |
+
$this->api_url = $url;
|
157 |
+
|
158 |
+
return $this;
|
159 |
+
}
|
160 |
+
|
161 |
+
public function set_plugin_screens($screen) {
|
162 |
+
|
163 |
+
$this->plugin_screens[] = $screen;
|
164 |
+
|
165 |
+
return $this;
|
166 |
+
}
|
167 |
+
|
168 |
+
|
169 |
+
private function get_banner() {
|
170 |
+
$this->data = get_option($this->text_domain . '__data');
|
171 |
+
$this->data = $this->data == '' ? [] : $this->data;
|
172 |
+
|
173 |
+
$this->last_check = get_option($this->text_domain . '__last_check');
|
174 |
+
$this->last_check = $this->last_check == '' ? 0 : $this->last_check;
|
175 |
+
|
176 |
+
if(($this->check_interval + $this->last_check) < time()){
|
177 |
+
$response = wp_remote_get( $this->api,
|
178 |
+
array(
|
179 |
+
'timeout' => 10,
|
180 |
+
'httpversion' => '1.1',
|
181 |
+
)
|
182 |
+
);
|
183 |
+
|
184 |
+
if(!is_wp_error($response) && isset($response['body']) && $response['body'] != ''){
|
185 |
+
|
186 |
+
$response = json_decode($response['body']);
|
187 |
+
|
188 |
+
if(!empty($response)) {
|
189 |
+
$this->data = $response;
|
190 |
+
}
|
191 |
+
|
192 |
+
update_option($this->text_domain . '__last_check', time());
|
193 |
+
update_option($this->text_domain . '__data', $this->data);
|
194 |
+
|
195 |
+
return;
|
196 |
+
}
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
|
201 |
+
public function show($banner) {
|
202 |
+
|
203 |
+
if($banner->start <= time() && time() <= $banner->end) {
|
204 |
+
|
205 |
+
$screen = get_current_screen();
|
206 |
+
|
207 |
+
if($this->is_correct_screen_to_show($banner->screen, $screen->id) && class_exists('\Oxaim\Libs\Notice')) {
|
208 |
+
|
209 |
+
// var_dump($banner); exit;
|
210 |
+
$inline_css = '';
|
211 |
+
$banner_unique_id = ((isset($banner->data->unique_key) && $banner->data->unique_key != '') ? $banner->data->unique_key : $banner->id );
|
212 |
+
|
213 |
+
if(!empty($banner->data->style_css)) {
|
214 |
+
|
215 |
+
$inline_css =' style="'.$banner->data->style_css.'"';
|
216 |
+
}
|
217 |
+
|
218 |
+
$contents = '<a target="_blank" '.$inline_css.' class="wpmet-jhanda-href" href="'.$banner->data->banner_link.'"><img style="display: block;margin: 0 auto;" src="'.$banner->data->banner_image.'" /></a>';
|
219 |
+
|
220 |
+
\Oxaim\Libs\Notice::instance('wpmet-jhanda', $banner_unique_id)
|
221 |
+
->set_dismiss('global', (3600 * 24 * 15))
|
222 |
+
->set_gutter(false)
|
223 |
+
->set_html($contents)
|
224 |
+
->call();
|
225 |
+
}
|
226 |
+
}
|
227 |
+
}
|
228 |
+
|
229 |
+
|
230 |
+
public function is_correct_screen_to_show($b_screen, $screen_id) {
|
231 |
+
|
232 |
+
if(in_array($b_screen, [$screen_id, 'all_page'])) {
|
233 |
+
|
234 |
+
return true;
|
235 |
+
}
|
236 |
+
|
237 |
+
|
238 |
+
if($b_screen == 'plugin_page') {
|
239 |
+
|
240 |
+
return in_array($screen_id, $this->plugin_screens);
|
241 |
+
}
|
242 |
+
|
243 |
+
return false;
|
244 |
+
}
|
245 |
+
|
246 |
+
|
247 |
+
private static $instance;
|
248 |
+
|
249 |
+
|
250 |
+
public static function instance() {
|
251 |
+
if(!self::$instance) {
|
252 |
+
self::$instance = new static();
|
253 |
+
}
|
254 |
+
|
255 |
+
return self::$instance;
|
256 |
+
}
|
257 |
+
}
|
258 |
+
|
259 |
+
endif;
|
utils/notice/notice.php
CHANGED
@@ -1,482 +1,482 @@
|
|
1 |
-
<?php
|
2 |
-
namespace Oxaim\Libs;
|
3 |
-
|
4 |
-
defined( 'ABSPATH' ) || exit;
|
5 |
-
|
6 |
-
if(class_exists('\Oxaim\Libs\Notice'))
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
*
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
*
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
*
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
*
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
*
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
*
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
*
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
*
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
*
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
*
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
*
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
*
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
*
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
*
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
protected $
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
*
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
*
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
*
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
*
|
151 |
-
*
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
$this->
|
157 |
-
|
158 |
-
$this->
|
159 |
-
|
160 |
-
$this->
|
161 |
-
|
162 |
-
$this->
|
163 |
-
|
164 |
-
$this->
|
165 |
-
|
166 |
-
$this->
|
167 |
-
|
168 |
-
$this->
|
169 |
-
|
170 |
-
$this->
|
171 |
-
|
172 |
-
$this->
|
173 |
-
|
174 |
-
$this->
|
175 |
-
|
176 |
-
$this->
|
177 |
-
|
178 |
-
$this->
|
179 |
-
|
180 |
-
$this->
|
181 |
-
|
182 |
-
|
183 |
-
'
|
184 |
-
'
|
185 |
-
'
|
186 |
-
|
187 |
-
|
188 |
-
];
|
189 |
-
|
190 |
-
$this
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
*
|
199 |
-
*
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
$this
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
$this
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
$this
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
$this
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
$this
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
$this
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
$this->
|
248 |
-
|
249 |
-
$this
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
$this
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
'
|
267 |
-
'
|
268 |
-
'
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
$expired =
|
285 |
-
|
286 |
-
|
287 |
-
}
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
$this
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
<?php
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
<?php
|
350 |
-
|
351 |
-
<?php
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
$
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
}
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
var
|
399 |
-
var
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
*
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
1 |
+
<?php
|
2 |
+
namespace Oxaim\Libs;
|
3 |
+
|
4 |
+
defined( 'ABSPATH' ) || exit;
|
5 |
+
|
6 |
+
if(!class_exists('\Oxaim\Libs\Notice')):
|
7 |
+
|
8 |
+
class Notice{
|
9 |
+
|
10 |
+
/**
|
11 |
+
* scripts version
|
12 |
+
*
|
13 |
+
* @var string
|
14 |
+
*/
|
15 |
+
protected $script_version = '2.0.2';
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Unique ID to identify each notice
|
19 |
+
*
|
20 |
+
* @var string
|
21 |
+
*/
|
22 |
+
protected $notice_id;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Plugin text-domain
|
26 |
+
*
|
27 |
+
* @var string
|
28 |
+
*/
|
29 |
+
protected $text_domain;
|
30 |
+
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Unique ID
|
34 |
+
*
|
35 |
+
* @var string
|
36 |
+
*/
|
37 |
+
protected $unique_id;
|
38 |
+
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Notice div container's class
|
42 |
+
*
|
43 |
+
* @var string
|
44 |
+
*/
|
45 |
+
protected $class;
|
46 |
+
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Single button's data
|
50 |
+
*
|
51 |
+
* @var array
|
52 |
+
*/
|
53 |
+
protected $button;
|
54 |
+
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Size class
|
58 |
+
*
|
59 |
+
* @var array
|
60 |
+
*/
|
61 |
+
protected $size;
|
62 |
+
|
63 |
+
|
64 |
+
/**
|
65 |
+
* List of all buttons with it's config data
|
66 |
+
*
|
67 |
+
* @var array
|
68 |
+
*/
|
69 |
+
protected $buttons;
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Notice title
|
73 |
+
*
|
74 |
+
* @var string
|
75 |
+
*/
|
76 |
+
protected $title;
|
77 |
+
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Notice message
|
81 |
+
*
|
82 |
+
* @var string
|
83 |
+
*/
|
84 |
+
protected $message;
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Left logo
|
88 |
+
*
|
89 |
+
* @var string
|
90 |
+
*/
|
91 |
+
protected $logo;
|
92 |
+
/**
|
93 |
+
* Container gutter
|
94 |
+
*
|
95 |
+
* @var string
|
96 |
+
*/
|
97 |
+
protected $gutter;
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Left logo style
|
101 |
+
*
|
102 |
+
* @var string
|
103 |
+
*/
|
104 |
+
protected $logo_style;
|
105 |
+
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Left logo style
|
109 |
+
*
|
110 |
+
* @var string
|
111 |
+
*/
|
112 |
+
protected $dismissible;
|
113 |
+
|
114 |
+
protected $expired_time;
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
+
/**
|
119 |
+
* html markup for notice
|
120 |
+
*
|
121 |
+
* @var string
|
122 |
+
*/
|
123 |
+
protected $html;
|
124 |
+
|
125 |
+
|
126 |
+
|
127 |
+
/**
|
128 |
+
* get_version
|
129 |
+
*
|
130 |
+
* @return string
|
131 |
+
*/
|
132 |
+
public function get_version(){
|
133 |
+
return $this->script_version;
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* get_script_location
|
138 |
+
*
|
139 |
+
* @return string
|
140 |
+
*/
|
141 |
+
public function get_script_location(){
|
142 |
+
return __FILE__;
|
143 |
+
}
|
144 |
+
|
145 |
+
// config
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Configures all setter variables
|
149 |
+
*
|
150 |
+
* @param string $prefix
|
151 |
+
* @return void
|
152 |
+
*/
|
153 |
+
public function config($text_domain = '', $unique_id = ''){
|
154 |
+
$this->text_domain = $text_domain;
|
155 |
+
|
156 |
+
$this->unique_id = $unique_id;
|
157 |
+
|
158 |
+
$this->notice_id = $text_domain . '-' . $unique_id;
|
159 |
+
|
160 |
+
$this->dismissible = false; // false, user, global
|
161 |
+
|
162 |
+
$this->expired_time = 1;
|
163 |
+
|
164 |
+
$this->html = '';
|
165 |
+
|
166 |
+
$this->title = '';
|
167 |
+
|
168 |
+
$this->message = '';
|
169 |
+
|
170 |
+
$this->class = '';
|
171 |
+
|
172 |
+
$this->gutter = true;
|
173 |
+
|
174 |
+
$this->logo = '';
|
175 |
+
|
176 |
+
$this->logo_style = '';
|
177 |
+
|
178 |
+
$this->size = [ ];
|
179 |
+
|
180 |
+
$this->button = [
|
181 |
+
'default_class' => 'button',
|
182 |
+
'class' => 'button-secondary ', // button-primary button-secondary button-small button-large button-link
|
183 |
+
'text' => 'Button',
|
184 |
+
'url' => '#',
|
185 |
+
'icon' => ''
|
186 |
+
];
|
187 |
+
|
188 |
+
$this->buttons = [];
|
189 |
+
|
190 |
+
return $this;
|
191 |
+
}
|
192 |
+
|
193 |
+
// setters begin
|
194 |
+
|
195 |
+
/**
|
196 |
+
* Adds classes to the container
|
197 |
+
*
|
198 |
+
* @param string $classname
|
199 |
+
* @return void
|
200 |
+
*/
|
201 |
+
public function set_class($classname = ''){
|
202 |
+
$this->class .= $classname;
|
203 |
+
|
204 |
+
return $this;
|
205 |
+
}
|
206 |
+
|
207 |
+
public function set_type($type = ''){
|
208 |
+
$this->class .= ' notice-' . $type;
|
209 |
+
|
210 |
+
return $this;
|
211 |
+
}
|
212 |
+
|
213 |
+
public function set_button($button = []){
|
214 |
+
$button = array_merge($this->button, $button);
|
215 |
+
$this->buttons[] = $button;
|
216 |
+
|
217 |
+
return $this;
|
218 |
+
}
|
219 |
+
|
220 |
+
public function set_id($id){
|
221 |
+
$this->notice_id = $id;
|
222 |
+
return $this;
|
223 |
+
}
|
224 |
+
|
225 |
+
public function set_title($title = ''){
|
226 |
+
$this->title .= $title;
|
227 |
+
|
228 |
+
return $this;
|
229 |
+
}
|
230 |
+
|
231 |
+
public function set_message($message = ''){
|
232 |
+
$this->message .= $message;
|
233 |
+
|
234 |
+
return $this;
|
235 |
+
}
|
236 |
+
|
237 |
+
public function set_gutter($gutter = true){
|
238 |
+
$this->gutter .= $gutter;
|
239 |
+
$this->class .= ($gutter === true ? '' : ' no-gutter');
|
240 |
+
|
241 |
+
return $this;
|
242 |
+
}
|
243 |
+
|
244 |
+
public function set_logo($logo = '', $logo_style = ""){
|
245 |
+
$this->logo = $logo;
|
246 |
+
|
247 |
+
$this->logo_style = $logo_style;
|
248 |
+
|
249 |
+
return $this;
|
250 |
+
}
|
251 |
+
|
252 |
+
public function set_html($html = ''){
|
253 |
+
$this->html .= $html;
|
254 |
+
|
255 |
+
return $this;
|
256 |
+
}
|
257 |
+
|
258 |
+
// setters ends
|
259 |
+
|
260 |
+
|
261 |
+
// group getter
|
262 |
+
public function get_data(){
|
263 |
+
return [
|
264 |
+
'message' => $this->message,
|
265 |
+
'title' => $this->title,
|
266 |
+
'buttons' => $this->buttons,
|
267 |
+
'class' => $this->class,
|
268 |
+
'html' => $this->html,
|
269 |
+
];
|
270 |
+
}
|
271 |
+
|
272 |
+
|
273 |
+
|
274 |
+
|
275 |
+
public function call(){
|
276 |
+
add_action( 'admin_notices', [$this, 'get_notice'] );
|
277 |
+
}
|
278 |
+
|
279 |
+
public function get_notice(){
|
280 |
+
// dismissible conditions
|
281 |
+
if ( 'user' === $this->dismissible) {
|
282 |
+
$expired = get_user_meta( get_current_user_id(), $this->notice_id, true );
|
283 |
+
} elseif ( 'global' === $this->dismissible ) {
|
284 |
+
$expired = get_transient( $this->notice_id );
|
285 |
+
}else{
|
286 |
+
$expired = '';
|
287 |
+
}
|
288 |
+
// echo $expired; exit;
|
289 |
+
|
290 |
+
global $oxaim_lib_notice_list;
|
291 |
+
|
292 |
+
if(!isset($oxaim_lib_notice_list[$this->notice_id])){
|
293 |
+
$oxaim_lib_notice_list[$this->notice_id] = __FILE__;
|
294 |
+
|
295 |
+
// is transient expired?
|
296 |
+
if ( false === $expired || empty( $expired ) ) {
|
297 |
+
$this->generate_html();
|
298 |
+
}
|
299 |
+
}
|
300 |
+
}
|
301 |
+
|
302 |
+
public function set_dismiss($scope, $time){
|
303 |
+
$this->dismissible = $scope;
|
304 |
+
$this->expired_time = $time;
|
305 |
+
|
306 |
+
return $this;
|
307 |
+
}
|
308 |
+
|
309 |
+
public function generate_html() {
|
310 |
+
|
311 |
+
?>
|
312 |
+
<div
|
313 |
+
id="<?php echo esc_attr($this->notice_id); ?>"
|
314 |
+
class="notice wpmet-notice notice-<?php echo esc_attr($this->notice_id . ' ' .$this->class); ?> <?php echo (false === $this->dismissible ? '' : 'is-dismissible') ;?>"
|
315 |
+
|
316 |
+
expired_time="<?php echo ($this->expired_time); ?>"
|
317 |
+
dismissible="<?php echo ($this->dismissible); ?>"
|
318 |
+
>
|
319 |
+
<?php if(!empty($this->logo)):?>
|
320 |
+
<div class="notice-left-container alignleft">
|
321 |
+
<p><img style="margin-right:15px; <?php echo esc_attr($this->logo_style); ?>" src="<?php echo esc_url($this->logo);?>" /></p>
|
322 |
+
</div>
|
323 |
+
<?php endif; ?>
|
324 |
+
|
325 |
+
<div class="notice-right-container">
|
326 |
+
|
327 |
+
<?php if(empty($this->html)): ?>
|
328 |
+
<div class="extension-message">
|
329 |
+
<?php echo (empty($this->title) ? '' : sprintf('<h3>%s</h3>', $this->title)); ?>
|
330 |
+
<?php echo ( $this->message );?>
|
331 |
+
</div>
|
332 |
+
|
333 |
+
<?php if(!empty($this->buttons)): ?>
|
334 |
+
<div class="submit">
|
335 |
+
<?php foreach($this->buttons as $button): ?>
|
336 |
+
<a id="<?php echo (!isset($button['id']) ? '' : $button['id']); ?>" href="<?php echo esc_url($button['url']); ?>" class="wpmet-notice-buttons <?php echo esc_attr($button['class']); ?>">
|
337 |
+
<?php if(!empty($button['icon'])) :?>
|
338 |
+
<i class="notice-icon <?php echo esc_attr($button['icon']); ?>"></i>
|
339 |
+
<?php endif; ?>
|
340 |
+
<?php echo esc_html($button['text']);?>
|
341 |
+
</a>
|
342 |
+
|
343 |
+
<?php endforeach; ?>
|
344 |
+
</div>
|
345 |
+
<?php endif;?>
|
346 |
+
|
347 |
+
<?php else:?>
|
348 |
+
<?php echo $this->html; ?>
|
349 |
+
<?php endif;?>
|
350 |
+
|
351 |
+
<?php if(false !== $this->dismissible): ?>
|
352 |
+
<button type="button" class="notice-dismiss">
|
353 |
+
<span class="screen-reader-text">x</span>
|
354 |
+
</button>
|
355 |
+
<?php endif;?>
|
356 |
+
|
357 |
+
</div>
|
358 |
+
|
359 |
+
<div style="clear:both"></div>
|
360 |
+
|
361 |
+
</div>
|
362 |
+
<?php
|
363 |
+
}
|
364 |
+
|
365 |
+
public static function init(){
|
366 |
+
add_action( 'wp_ajax_wpmet-notices', [ __CLASS__, 'dismiss_ajax_call' ] );
|
367 |
+
add_action( 'admin_head', [ __CLASS__, 'enqueue_scripts' ] );
|
368 |
+
}
|
369 |
+
|
370 |
+
public static function dismiss_ajax_call() {
|
371 |
+
$notice_id = ( isset( $_POST['notice_id'] ) ) ? $_POST['notice_id'] : '';
|
372 |
+
$dismissible = ( isset( $_POST['dismissible'] ) ) ? $_POST['dismissible'] : '';
|
373 |
+
$expired_time = ( isset( $_POST['expired_time'] ) ) ? $_POST['expired_time'] : '';
|
374 |
+
// print_r([$notice_id, $dismissible, $expired_time]);
|
375 |
+
|
376 |
+
if ( ! empty( $notice_id ) ) {
|
377 |
+
if ( 'user' === $dismissible ) {
|
378 |
+
update_user_meta( get_current_user_id(), $notice_id, true );
|
379 |
+
} else {
|
380 |
+
set_transient( $notice_id, true, $expired_time );
|
381 |
+
}
|
382 |
+
|
383 |
+
wp_send_json_success();
|
384 |
+
}
|
385 |
+
|
386 |
+
wp_send_json_error();
|
387 |
+
}
|
388 |
+
|
389 |
+
public static function enqueue_scripts() {
|
390 |
+
echo "
|
391 |
+
<script>
|
392 |
+
jQuery(document).ready(function ($) {
|
393 |
+
$( '.wpmet-notice.is-dismissible' ).on( 'click', '.notice-dismiss', function() {
|
394 |
+
|
395 |
+
_this = $( this ).parents('.wpmet-notice').eq(0);
|
396 |
+
var notice_id = _this.attr( 'id' ) || '';
|
397 |
+
var expired_time = _this.attr( 'expired_time' ) || '';
|
398 |
+
var dismissible = _this.attr( 'dismissible' ) || '';
|
399 |
+
var x = $( this ).attr('class');
|
400 |
+
|
401 |
+
console.log({
|
402 |
+
_this, x, notice_id, expired_time, dismissible
|
403 |
+
});
|
404 |
+
// return;
|
405 |
+
|
406 |
+
$.ajax({
|
407 |
+
url: ajaxurl,
|
408 |
+
type: 'POST',
|
409 |
+
data: {
|
410 |
+
action : 'wpmet-notices',
|
411 |
+
notice_id : notice_id,
|
412 |
+
dismissible : dismissible,
|
413 |
+
expired_time : expired_time,
|
414 |
+
},
|
415 |
+
});
|
416 |
+
});
|
417 |
+
});
|
418 |
+
</script>
|
419 |
+
<style>
|
420 |
+
.wpmet-notice .notice-icon{
|
421 |
+
display:inline-block;
|
422 |
+
}
|
423 |
+
|
424 |
+
.wpmet-notice .notice-icon:before{
|
425 |
+
vertical-align: middle!important;
|
426 |
+
margin-top: -1px;
|
427 |
+
}
|
428 |
+
|
429 |
+
.wpmet-notice-buttons {
|
430 |
+
text-decoration:none;
|
431 |
+
}
|
432 |
+
|
433 |
+
.wpmet-notice-buttons > i{
|
434 |
+
margin-right: 3px;
|
435 |
+
}
|
436 |
+
|
437 |
+
.wpmet-notice .notice-right-container{
|
438 |
+
padding-top: 10px;
|
439 |
+
}
|
440 |
+
.wpmet-notice .notice-right-container .submit {
|
441 |
+
padding-top: 8px
|
442 |
+
}
|
443 |
+
|
444 |
+
.wpmet-notice img{
|
445 |
+
max-width: 100%!important;
|
446 |
+
max-height: 100%!important;
|
447 |
+
}
|
448 |
+
|
449 |
+
.wpmet-notice.no-gutter{
|
450 |
+
padding: 0!important;
|
451 |
+
border: 0!important;
|
452 |
+
}
|
453 |
+
|
454 |
+
.wpmet-notice.no-gutter .notice-right-container{
|
455 |
+
padding: 0!important;
|
456 |
+
margin: 0!important;
|
457 |
+
}
|
458 |
+
|
459 |
+
</style>
|
460 |
+
";
|
461 |
+
}
|
462 |
+
|
463 |
+
|
464 |
+
private static $instance;
|
465 |
+
|
466 |
+
/**
|
467 |
+
* init
|
468 |
+
*
|
469 |
+
* @return void
|
470 |
+
*/
|
471 |
+
public static function instance($text_domain = null, $unique_id = null) {
|
472 |
+
if($text_domain == null){
|
473 |
+
return false;
|
474 |
+
}
|
475 |
+
|
476 |
+
self::$instance = new self();
|
477 |
+
|
478 |
+
return self::$instance->config($text_domain, (is_null($unique_id) ? uniqid() : $unique_id));
|
479 |
+
}
|
480 |
+
}
|
481 |
+
|
482 |
+
endif;
|
utils/rating-notice.php
CHANGED
@@ -1,432 +1,447 @@
|
|
1 |
<?php
|
2 |
-
namespace Wpmet\Notice;
|
3 |
|
4 |
-
|
5 |
-
if(class_exists('Wpmet\Notice\Notice')) { return; }
|
6 |
-
|
7 |
-
class Notice{
|
8 |
-
|
9 |
-
/**
|
10 |
-
* Unique ID to identify each notice
|
11 |
-
*
|
12 |
-
* @var string
|
13 |
-
*/
|
14 |
-
protected $notice_id;
|
15 |
-
|
16 |
-
/**
|
17 |
-
* Plugin text-domain
|
18 |
-
*
|
19 |
-
* @var string
|
20 |
-
*/
|
21 |
-
protected $text_domain;
|
22 |
-
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Unique ID
|
26 |
-
*
|
27 |
-
* @var string
|
28 |
-
*/
|
29 |
-
protected $unique_id;
|
30 |
-
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Notice div container's class
|
34 |
-
*
|
35 |
-
* @var string
|
36 |
-
*/
|
37 |
-
protected $class;
|
38 |
-
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Single button's data
|
42 |
-
*
|
43 |
-
* @var array
|
44 |
-
*/
|
45 |
-
protected $button;
|
46 |
-
|
47 |
-
|
48 |
-
/**
|
49 |
-
* Size class
|
50 |
-
*
|
51 |
-
* @var array
|
52 |
-
*/
|
53 |
-
protected $size;
|
54 |
-
|
55 |
-
|
56 |
-
/**
|
57 |
-
* List of all buttons with it's config data
|
58 |
-
*
|
59 |
-
* @var array
|
60 |
-
*/
|
61 |
-
protected $buttons;
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Notice title
|
65 |
-
*
|
66 |
-
* @var string
|
67 |
-
*/
|
68 |
-
protected $title;
|
69 |
-
|
70 |
-
|
71 |
-
/**
|
72 |
-
* Notice message
|
73 |
-
*
|
74 |
-
* @var string
|
75 |
-
*/
|
76 |
-
protected $message;
|
77 |
-
|
78 |
-
/**
|
79 |
-
* Left logo
|
80 |
-
*
|
81 |
-
* @var string
|
82 |
-
*/
|
83 |
-
protected $logo;
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Left logo style
|
87 |
-
*
|
88 |
-
* @var string
|
89 |
-
*/
|
90 |
-
protected $logo_style;
|
91 |
-
|
92 |
-
|
93 |
-
/**
|
94 |
-
* Left logo style
|
95 |
-
*
|
96 |
-
* @var string
|
97 |
-
*/
|
98 |
-
protected $dismissible;
|
99 |
-
|
100 |
-
protected $expired_time;
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
/**
|
105 |
-
* html markup for notice
|
106 |
-
*
|
107 |
-
* @var string
|
108 |
-
*/
|
109 |
-
protected $html;
|
110 |
-
|
111 |
-
|
112 |
-
/**
|
113 |
-
* Constractor
|
114 |
-
*
|
115 |
-
* @return void
|
116 |
-
*/
|
117 |
-
public function __construct(){
|
118 |
-
add_action( 'admin_footer', [ $this, 'enqueue_scripts' ], 9999);
|
119 |
-
}
|
120 |
|
|
|
121 |
|
122 |
-
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
132 |
|
133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
-
$this->notice_id = $text_domain . '-' . $unique_id;
|
136 |
|
137 |
-
|
138 |
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
|
141 |
-
|
142 |
|
143 |
-
|
144 |
|
145 |
-
|
146 |
|
147 |
-
|
148 |
|
149 |
-
|
150 |
|
151 |
-
|
152 |
|
153 |
-
|
154 |
|
155 |
-
|
156 |
-
'default_class' => 'button',
|
157 |
-
'class' => 'button-secondary', // button-primary button-secondary button-small button-large button-link
|
158 |
-
'text' => 'Button',
|
159 |
-
'url' => '#',
|
160 |
-
'icon' => ''
|
161 |
-
];
|
162 |
|
163 |
-
|
164 |
|
165 |
-
|
166 |
-
}
|
167 |
|
168 |
-
|
169 |
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
$this->class .= $classname;
|
178 |
|
179 |
-
|
180 |
-
}
|
181 |
|
182 |
-
|
183 |
-
|
184 |
|
185 |
-
|
186 |
-
}
|
187 |
|
188 |
-
|
189 |
-
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
-
|
193 |
-
|
194 |
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
}
|
199 |
|
200 |
-
|
201 |
-
|
202 |
|
203 |
-
|
204 |
-
|
|
|
|
|
205 |
|
206 |
-
|
207 |
-
|
208 |
|
209 |
-
|
210 |
-
|
|
|
|
|
|
|
211 |
|
212 |
-
|
213 |
-
|
|
|
214 |
|
215 |
-
|
|
|
216 |
|
217 |
-
|
218 |
-
|
|
|
219 |
|
220 |
-
|
221 |
-
|
222 |
|
223 |
-
|
224 |
-
|
|
|
225 |
|
226 |
-
|
227 |
|
|
|
|
|
228 |
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
'message' => $this->message,
|
233 |
-
'title' => $this->title,
|
234 |
-
'buttons' => $this->buttons,
|
235 |
-
'class' => $this->class,
|
236 |
-
'html' => $this->html,
|
237 |
-
];
|
238 |
-
}
|
239 |
|
|
|
|
|
240 |
|
|
|
241 |
|
242 |
|
243 |
-
|
244 |
-
|
245 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
}
|
247 |
-
add_action( 'admin_notices', [$this, 'get_notice'] );
|
248 |
-
add_action( 'wp_ajax_wp-advanced-notices', [ $this, 'dismiss_ajax_call' ] );
|
249 |
-
}
|
250 |
|
251 |
-
public function get_notice(){
|
252 |
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
|
|
|
|
260 |
}
|
261 |
|
262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
|
264 |
-
|
265 |
-
|
266 |
-
$this->generate_html();
|
267 |
-
}else{
|
268 |
-
// is transient expired?
|
269 |
-
if ( false === $expired || empty( $expired ) ) {
|
270 |
$this->generate_html();
|
|
|
|
|
|
|
|
|
|
|
271 |
}
|
272 |
}
|
273 |
|
274 |
-
|
|
|
|
|
|
|
275 |
|
276 |
-
|
277 |
-
|
278 |
-
$this->expired_time = $time;
|
279 |
|
280 |
-
|
281 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
|
283 |
-
|
284 |
-
|
285 |
-
$dismissible = ( isset( $_POST['dismissible'] ) ) ? $_POST['dismissible'] : '';
|
286 |
-
$expired_time = ( isset( $_POST['expired_time'] ) ) ? $_POST['expired_time'] : '';
|
287 |
-
print_r([$notice_id, $dismissible, $expired_time]);
|
288 |
-
|
289 |
-
if ( ! empty( $notice_id ) ) {
|
290 |
-
if ( 'user' === $dismissible ) {
|
291 |
-
update_user_meta( get_current_user_id(), $notice_id, true );
|
292 |
-
} else {
|
293 |
-
set_transient( $notice_id, true, $expired_time );
|
294 |
-
}
|
295 |
-
|
296 |
-
wp_send_json_success();
|
297 |
-
}
|
298 |
-
|
299 |
-
wp_send_json_error();
|
300 |
-
}
|
301 |
-
|
302 |
-
public function generate_html() {
|
303 |
-
|
304 |
-
?>
|
305 |
-
<div
|
306 |
-
id="<?php echo esc_attr($this->notice_id); ?>"
|
307 |
-
class="notice wp-advanced-notice notice-<?php echo esc_attr($this->notice_id . ' ' .$this->class); ?> <?php echo (false === $this->dismissible ? '' : 'is-dismissible') ;?>"
|
308 |
-
|
309 |
-
expired_time="<?php echo ($this->expired_time); ?>"
|
310 |
-
dismissible="<?php echo ($this->dismissible); ?>"
|
311 |
-
>
|
312 |
-
<?php if(!empty($this->logo)):?>
|
313 |
-
<div class="notice-left-container alignleft">
|
314 |
-
<p><img style="margin-right:15px; <?php echo esc_attr($this->logo_style); ?>" src="<?php echo esc_url($this->logo);?>" /></p>
|
315 |
-
</div>
|
316 |
-
<?php endif; ?>
|
317 |
|
318 |
-
|
|
|
319 |
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
|
|
|
|
|
|
|
|
324 |
</div>
|
|
|
|
|
|
|
325 |
|
326 |
-
<?php if(
|
327 |
-
<div class="
|
328 |
-
<?php
|
329 |
-
|
330 |
-
<?php if(!empty($button['icon'])) :?>
|
331 |
-
<i class="notice-icon <?php echo esc_attr($button['icon']); ?>"></i>
|
332 |
-
<?php endif; ?>
|
333 |
-
<?php echo esc_html($button['text']);?>
|
334 |
-
</a>
|
335 |
-
|
336 |
-
<?php endforeach; ?>
|
337 |
</div>
|
338 |
-
<?php endif;?>
|
339 |
|
340 |
-
|
341 |
-
|
342 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
343 |
|
344 |
-
|
345 |
-
|
346 |
-
<span class="screen-reader-text">x</span>
|
347 |
-
</button>
|
348 |
-
<?php endif;?>
|
349 |
|
350 |
</div>
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
},
|
381 |
});
|
382 |
});
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
|
401 |
-
.notice-right-container{
|
402 |
-
padding-top: 10px;
|
403 |
-
}
|
404 |
-
.notice-right-container .submit {
|
405 |
-
padding-top: 8px
|
406 |
|
407 |
-
|
408 |
-
|
409 |
-
</style>
|
410 |
-
";
|
411 |
-
}
|
412 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
413 |
|
414 |
-
|
|
|
|
|
415 |
|
416 |
-
|
417 |
-
* init
|
418 |
-
*
|
419 |
-
* @return void
|
420 |
-
*/
|
421 |
-
public static function instance($text_domain = null, $unique_id = null) {
|
422 |
-
if($text_domain == null){
|
423 |
-
return false;
|
424 |
}
|
425 |
-
|
426 |
-
|
427 |
-
self::$instance = new self();
|
428 |
-
}
|
429 |
-
|
430 |
-
return self::$instance->config($text_domain, (is_null($unique_id) ? uniqid() : $unique_id));
|
431 |
-
}
|
432 |
-
}
|
1 |
<?php
|
|
|
2 |
|
3 |
+
namespace Wpmet\Notice;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
defined('ABSPATH') || exit;
|
6 |
|
7 |
+
if (!class_exists('Wpmet\Notice\Notice')) {
|
8 |
|
9 |
+
class Notice
|
10 |
+
{
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Unique ID to identify each notice
|
14 |
+
*
|
15 |
+
* @var string
|
16 |
+
*/
|
17 |
+
protected $notice_id;
|
18 |
|
19 |
+
/**
|
20 |
+
* Plugin text-domain
|
21 |
+
*
|
22 |
+
* @var string
|
23 |
+
*/
|
24 |
+
protected $text_domain;
|
25 |
+
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Unique ID
|
29 |
+
*
|
30 |
+
* @var string
|
31 |
+
*/
|
32 |
+
protected $unique_id;
|
33 |
+
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Notice div container's class
|
37 |
+
*
|
38 |
+
* @var string
|
39 |
+
*/
|
40 |
+
protected $class;
|
41 |
+
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Single button's data
|
45 |
+
*
|
46 |
+
* @var array
|
47 |
+
*/
|
48 |
+
protected $button;
|
49 |
+
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Size class
|
53 |
+
*
|
54 |
+
* @var array
|
55 |
+
*/
|
56 |
+
protected $size;
|
57 |
+
|
58 |
+
|
59 |
+
/**
|
60 |
+
* List of all buttons with it's config data
|
61 |
+
*
|
62 |
+
* @var array
|
63 |
+
*/
|
64 |
+
protected $buttons;
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Notice title
|
68 |
+
*
|
69 |
+
* @var string
|
70 |
+
*/
|
71 |
+
protected $title;
|
72 |
+
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Notice message
|
76 |
+
*
|
77 |
+
* @var string
|
78 |
+
*/
|
79 |
+
protected $message;
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Left logo
|
83 |
+
*
|
84 |
+
* @var string
|
85 |
+
*/
|
86 |
+
protected $logo;
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Left logo style
|
90 |
+
*
|
91 |
+
* @var string
|
92 |
+
*/
|
93 |
+
protected $logo_style;
|
94 |
+
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Left logo style
|
98 |
+
*
|
99 |
+
* @var string
|
100 |
+
*/
|
101 |
+
protected $dismissible;
|
102 |
+
|
103 |
+
protected $expired_time;
|
104 |
+
|
105 |
+
|
106 |
+
|
107 |
+
/**
|
108 |
+
* html markup for notice
|
109 |
+
*
|
110 |
+
* @var string
|
111 |
+
*/
|
112 |
+
protected $html;
|
113 |
+
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Constractor
|
117 |
+
*
|
118 |
+
* @return void
|
119 |
+
*/
|
120 |
+
public function __construct()
|
121 |
+
{
|
122 |
+
add_action('admin_footer', [$this, 'enqueue_scripts'], 9999);
|
123 |
+
}
|
124 |
|
|
|
125 |
|
126 |
+
// config
|
127 |
|
128 |
+
/**
|
129 |
+
* Configures all setter variables
|
130 |
+
*
|
131 |
+
* @param string $prefix
|
132 |
+
* @return void
|
133 |
+
*/
|
134 |
+
public function config($text_domain = '', $unique_id = '')
|
135 |
+
{
|
136 |
+
$this->text_domain = $text_domain;
|
137 |
|
138 |
+
$this->unique_id = $unique_id;
|
139 |
|
140 |
+
$this->notice_id = $text_domain . '-' . $unique_id;
|
141 |
|
142 |
+
$this->dismissible = false; // false, user, global
|
143 |
|
144 |
+
$this->expired_time = 1;
|
145 |
|
146 |
+
$this->html = '';
|
147 |
|
148 |
+
$this->title = '';
|
149 |
|
150 |
+
$this->message = '';
|
151 |
|
152 |
+
$this->class = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
+
$this->logo = '';
|
155 |
|
156 |
+
$this->logo_style = '';
|
|
|
157 |
|
158 |
+
$this->size = [];
|
159 |
|
160 |
+
$this->button = [
|
161 |
+
'default_class' => 'button',
|
162 |
+
'class' => 'button-secondary', // button-primary button-secondary button-small button-large button-link
|
163 |
+
'text' => 'Button',
|
164 |
+
'url' => '#',
|
165 |
+
'icon' => ''
|
166 |
+
];
|
|
|
167 |
|
168 |
+
$this->buttons = [];
|
|
|
169 |
|
170 |
+
return $this;
|
171 |
+
}
|
172 |
|
173 |
+
// setters begin
|
|
|
174 |
|
175 |
+
/**
|
176 |
+
* Adds classes to the container
|
177 |
+
*
|
178 |
+
* @param string $classname
|
179 |
+
* @return void
|
180 |
+
*/
|
181 |
+
public function add_class($classname = '')
|
182 |
+
{
|
183 |
+
$this->class .= $classname;
|
184 |
|
185 |
+
return $this;
|
186 |
+
}
|
187 |
|
188 |
+
public function add_type($type = '')
|
189 |
+
{
|
190 |
+
$this->class .= 'notice-' . $type;
|
|
|
191 |
|
192 |
+
return $this;
|
193 |
+
}
|
194 |
|
195 |
+
public function add_button($button = [])
|
196 |
+
{
|
197 |
+
$button = array_merge($this->button, $button);
|
198 |
+
$this->buttons[] = $button;
|
199 |
|
200 |
+
return $this;
|
201 |
+
}
|
202 |
|
203 |
+
public function add_id($id)
|
204 |
+
{
|
205 |
+
$this->notice_id = $id;
|
206 |
+
return $this;
|
207 |
+
}
|
208 |
|
209 |
+
public function add_title($title = '')
|
210 |
+
{
|
211 |
+
$this->title .= $title;
|
212 |
|
213 |
+
return $this;
|
214 |
+
}
|
215 |
|
216 |
+
public function add_message($message = '')
|
217 |
+
{
|
218 |
+
$this->message .= $message;
|
219 |
|
220 |
+
return $this;
|
221 |
+
}
|
222 |
|
223 |
+
public function add_logo($logo = '', $logo_style = "")
|
224 |
+
{
|
225 |
+
$this->logo = $logo;
|
226 |
|
227 |
+
$this->logo_style = $logo_style;
|
228 |
|
229 |
+
return $this;
|
230 |
+
}
|
231 |
|
232 |
+
public function add_html($html = '')
|
233 |
+
{
|
234 |
+
$this->html .= $html;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
|
236 |
+
return $this;
|
237 |
+
}
|
238 |
|
239 |
+
// setters ends
|
240 |
|
241 |
|
242 |
+
// group getter
|
243 |
+
public function get_data()
|
244 |
+
{
|
245 |
+
return [
|
246 |
+
'message' => $this->message,
|
247 |
+
'title' => $this->title,
|
248 |
+
'buttons' => $this->buttons,
|
249 |
+
'class' => $this->class,
|
250 |
+
'html' => $this->html,
|
251 |
+
];
|
252 |
}
|
|
|
|
|
|
|
253 |
|
|
|
254 |
|
255 |
+
|
256 |
+
|
257 |
+
public function init()
|
258 |
+
{
|
259 |
+
if (!is_admin()) {
|
260 |
+
return;
|
261 |
+
}
|
262 |
+
add_action('admin_notices', [$this, 'get_notice']);
|
263 |
+
add_action('wp_ajax_wp-advanced-notices', [$this, 'dismiss_ajax_call']);
|
264 |
}
|
265 |
|
266 |
+
public function get_notice()
|
267 |
+
{
|
268 |
+
|
269 |
+
// dismissible conditions
|
270 |
+
if ('user' === $this->dismissible) {
|
271 |
+
$expired = get_user_meta(get_current_user_id(), $this->notice_id, true);
|
272 |
+
} elseif ('global' === $this->dismissible) {
|
273 |
+
$expired = get_transient($this->notice_id);
|
274 |
+
} else {
|
275 |
+
$expired = '';
|
276 |
+
}
|
277 |
+
|
278 |
+
// echo $expired; exit;
|
279 |
|
280 |
+
// notice visible after transient expire.
|
281 |
+
if (false === $this->notice_id) {
|
|
|
|
|
|
|
|
|
282 |
$this->generate_html();
|
283 |
+
} else {
|
284 |
+
// is transient expired?
|
285 |
+
if (false === $expired || empty($expired)) {
|
286 |
+
$this->generate_html();
|
287 |
+
}
|
288 |
}
|
289 |
}
|
290 |
|
291 |
+
public function dismissible($scope, $time)
|
292 |
+
{
|
293 |
+
$this->dismissible = $scope;
|
294 |
+
$this->expired_time = $time;
|
295 |
|
296 |
+
return $this;
|
297 |
+
}
|
|
|
298 |
|
299 |
+
public function dismiss_ajax_call()
|
300 |
+
{
|
301 |
+
$notice_id = (isset($_POST['notice_id'])) ? $_POST['notice_id'] : '';
|
302 |
+
$dismissible = (isset($_POST['dismissible'])) ? $_POST['dismissible'] : '';
|
303 |
+
$expired_time = (isset($_POST['expired_time'])) ? $_POST['expired_time'] : '';
|
304 |
+
print_r([$notice_id, $dismissible, $expired_time]);
|
305 |
+
|
306 |
+
if (!empty($notice_id)) {
|
307 |
+
if ('user' === $dismissible) {
|
308 |
+
update_user_meta(get_current_user_id(), $notice_id, true);
|
309 |
+
} else {
|
310 |
+
set_transient($notice_id, true, $expired_time);
|
311 |
+
}
|
312 |
|
313 |
+
wp_send_json_success();
|
314 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
|
316 |
+
wp_send_json_error();
|
317 |
+
}
|
318 |
|
319 |
+
public function generate_html()
|
320 |
+
{
|
321 |
+
|
322 |
+
?>
|
323 |
+
<div id="<?php echo esc_attr($this->notice_id); ?>" class="notice wp-advanced-notice notice-<?php echo esc_attr($this->notice_id . ' ' . $this->class); ?> <?php echo (false === $this->dismissible ? '' : 'is-dismissible'); ?>" expired_time="<?php echo ($this->expired_time); ?>" dismissible="<?php echo ($this->dismissible); ?>">
|
324 |
+
<?php if (!empty($this->logo)) : ?>
|
325 |
+
<div class="notice-left-container alignleft">
|
326 |
+
<p><img style="margin-right:15px; <?php echo esc_attr($this->logo_style); ?>" src="<?php echo esc_url($this->logo); ?>" /></p>
|
327 |
</div>
|
328 |
+
<?php endif; ?>
|
329 |
+
|
330 |
+
<div class="notice-right-container">
|
331 |
|
332 |
+
<?php if (empty($this->html)) : ?>
|
333 |
+
<div class="extension-message">
|
334 |
+
<?php echo (empty($this->title) ? '' : sprintf('<h3>%s</h3>', $this->title)); ?>
|
335 |
+
<?php echo ($this->message); ?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
</div>
|
|
|
337 |
|
338 |
+
<?php if (!empty($this->buttons)) : ?>
|
339 |
+
<div class="submit">
|
340 |
+
<?php foreach ($this->buttons as $button) : ?>
|
341 |
+
<a id="<?php echo $button['id']; ?>" href="<?php echo esc_url($button['url']); ?>" class="wpmet-notice-buttons <?php echo esc_attr($button['class']); ?>">
|
342 |
+
<?php if (!empty($button['icon'])) : ?>
|
343 |
+
<i class="notice-icon <?php echo esc_attr($button['icon']); ?>"></i>
|
344 |
+
<?php endif; ?>
|
345 |
+
<?php echo esc_html($button['text']); ?>
|
346 |
+
</a>
|
347 |
+
|
348 |
+
<?php endforeach; ?>
|
349 |
+
</div>
|
350 |
+
<?php endif; ?>
|
351 |
+
|
352 |
+
<?php else : ?>
|
353 |
+
<?php echo $this->html; ?>
|
354 |
+
<?php endif; ?>
|
355 |
+
|
356 |
+
<?php if (false !== $this->dismissible) : ?>
|
357 |
+
<button type="button" class="notice-dismiss">
|
358 |
+
<span class="screen-reader-text">x</span>
|
359 |
+
</button>
|
360 |
+
<?php endif; ?>
|
361 |
|
362 |
+
</div>
|
363 |
+
<div style="clear:both"></div>
|
|
|
|
|
|
|
364 |
|
365 |
</div>
|
366 |
+
<?php
|
367 |
+
}
|
368 |
+
|
369 |
+
public function enqueue_scripts()
|
370 |
+
{
|
371 |
+
echo "
|
372 |
+
<script>
|
373 |
+
jQuery(document).ready(function ($) {
|
374 |
+
$( '.wp-advanced-notice.is-dismissible' ).on( 'click', '.notice-dismiss', function() {
|
375 |
+
|
376 |
+
_this = $( this ).parents('.wp-advanced-notice').eq(0);
|
377 |
+
var notice_id = _this.attr( 'id' ) || '';
|
378 |
+
var expired_time = _this.attr( 'expired_time' ) || '';
|
379 |
+
var dismissible = _this.attr( 'dismissible' ) || '';
|
380 |
+
var x = $( this ).attr('class');
|
381 |
+
console.log({
|
382 |
+
_this, x, notice_id, expired_time, dismissible
|
383 |
+
});
|
384 |
+
// return;
|
385 |
+
$.ajax({
|
386 |
+
url: ajaxurl,
|
387 |
+
type: 'POST',
|
388 |
+
data: {
|
389 |
+
action : 'wp-advanced-notices',
|
390 |
+
notice_id : notice_id,
|
391 |
+
dismissible : dismissible,
|
392 |
+
expired_time : expired_time,
|
393 |
+
},
|
394 |
+
});
|
|
|
395 |
});
|
396 |
});
|
397 |
+
</script>
|
398 |
+
<style>
|
399 |
+
.notice .notice-icon{
|
400 |
+
display:inline-block;
|
401 |
+
}
|
402 |
+
.notice .notice-icon:before{
|
403 |
+
vertical-align: middle!important;
|
404 |
+
margin-top: -1px;
|
405 |
+
}
|
406 |
+
.wpmet-notice-buttons {
|
407 |
+
text-decoration:none;
|
408 |
+
}
|
409 |
+
.wpmet-notice-buttons > i{
|
410 |
+
margin-right: 3px;
|
411 |
+
|
412 |
+
}
|
413 |
+
|
414 |
+
.notice-right-container{
|
415 |
+
padding-top: 10px;
|
416 |
+
}
|
417 |
+
.notice-right-container .submit {
|
418 |
+
padding-top: 8px
|
419 |
+
|
420 |
+
}
|
421 |
+
|
422 |
+
</style>
|
423 |
+
";
|
424 |
+
}
|
425 |
|
|
|
|
|
|
|
|
|
|
|
426 |
|
427 |
+
private static $instance;
|
|
|
|
|
|
|
|
|
428 |
|
429 |
+
/**
|
430 |
+
* init
|
431 |
+
*
|
432 |
+
* @return void
|
433 |
+
*/
|
434 |
+
public static function instance($text_domain = null, $unique_id = null)
|
435 |
+
{
|
436 |
+
if ($text_domain == null) {
|
437 |
+
return false;
|
438 |
+
}
|
439 |
|
440 |
+
if (!self::$instance) {
|
441 |
+
self::$instance = new self();
|
442 |
+
}
|
443 |
|
444 |
+
return self::$instance->config($text_domain, (is_null($unique_id) ? uniqid() : $unique_id));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
445 |
}
|
446 |
+
}
|
447 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
utils/rating.php
CHANGED
@@ -2,379 +2,377 @@
|
|
2 |
|
3 |
namespace Wpmet\Rating;
|
4 |
|
5 |
-
defined(
|
6 |
-
|
7 |
-
if(class_exists('Wpmet\Rating\Rating')) return ;
|
8 |
|
9 |
use DateTime;
|
10 |
use Wpmet\Rating\Notice;
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
* Asking client for rating and
|
18 |
-
* other stuffs
|
19 |
-
* Class Rating
|
20 |
-
* @package MetForm\Utils
|
21 |
-
*/
|
22 |
-
class Rating
|
23 |
-
{
|
24 |
-
private $plugin_name;
|
25 |
-
private $days;
|
26 |
-
private $style;
|
27 |
-
private $rating_url;
|
28 |
-
private $version;
|
29 |
-
private $condition_status = true;
|
30 |
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
{
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
switch (gettype($result)) {
|
57 |
-
case 'boolean':
|
58 |
-
$this->condition_status = $result;
|
59 |
-
break;
|
60 |
-
case 'object':
|
61 |
-
$this->condition_status = $result();
|
62 |
-
break;
|
63 |
-
default:
|
64 |
-
$this->condition_status = false;
|
65 |
}
|
66 |
|
67 |
-
return $this;
|
68 |
-
}
|
69 |
|
|
|
|
|
70 |
|
71 |
-
|
72 |
-
|
|
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
77 |
|
78 |
-
if (current_user_can('update_plugins')) {
|
79 |
-
add_action('admin_footer', [$this, 'scripts'], 9999);
|
80 |
-
add_action("wp_ajax_never_show_message", [$this, "never_show_message"]);
|
81 |
-
add_action("wp_ajax_ask_me_later_message", [$this, "ask_me_later_message"]);
|
82 |
|
|
|
|
|
83 |
|
84 |
-
add_action('wp', [$this, 'cron_activation']);
|
85 |
-
add_action($this->plugin_name . '_cronjob', [$this, 'corn_job_func']);
|
86 |
|
|
|
87 |
|
88 |
-
|
|
|
|
|
89 |
|
90 |
-
|
91 |
-
$this->set_installation_date();
|
92 |
-
}
|
93 |
|
94 |
-
|
|
|
95 |
|
96 |
-
$this->
|
97 |
-
}
|
98 |
|
99 |
-
|
|
|
|
|
100 |
|
101 |
-
|
102 |
-
return;
|
103 |
}
|
104 |
-
|
105 |
-
$this->is_used_in($this->days);
|
106 |
}
|
107 |
}
|
108 |
-
|
109 |
}
|
110 |
-
return $this;
|
111 |
-
}
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
117 |
}
|
118 |
-
}
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
|
161 |
-
|
162 |
|
|
|
163 |
}
|
164 |
-
}
|
165 |
|
166 |
-
|
167 |
-
|
168 |
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
|
175 |
-
|
176 |
|
177 |
-
|
178 |
|
179 |
|
180 |
-
|
181 |
Could you please do us a <b>big favor</b> and give it a <b>5-star</b> rating on WordPress? This would boost our motivation and help other users make a comfortable decision while choosing the {$plugin_name}";
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
// Notice::push(
|
218 |
-
// [
|
219 |
-
// 'id' => $this->plugin_name . '_plugin_rating_msg_used_in_day',
|
220 |
-
// 'type' => 'info',
|
221 |
-
// 'dismissible' => false,
|
222 |
-
// 'btn' => $btn,
|
223 |
-
// 'style' => $this->style,
|
224 |
-
// 'message' => "Awesome, you've been using {$plugin_name} for more {$diff_interval} days. May we ask you to give a 5-star rating on wordpress?",
|
225 |
-
// ]
|
226 |
-
// );
|
|
|
227 |
}
|
228 |
-
}
|
229 |
|
230 |
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
|
240 |
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
|
249 |
-
|
250 |
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
|
257 |
-
|
258 |
|
259 |
-
|
260 |
|
261 |
|
262 |
-
|
263 |
Could you please do us a <b>big favor</b> and give it a <b>5-star</b> rating on WordPress? This would boost our motivation and help other users make a comfortable decision while choosing the {$plugin_name}";
|
264 |
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
}
|
300 |
-
}
|
301 |
|
302 |
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
|
311 |
|
312 |
-
|
313 |
-
|
314 |
|
315 |
-
|
316 |
|
317 |
-
|
318 |
-
|
319 |
|
320 |
-
|
|
|
321 |
}
|
322 |
-
}
|
323 |
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
|
330 |
-
|
331 |
-
|
332 |
|
333 |
-
|
334 |
-
|
335 |
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
|
343 |
|
344 |
-
|
345 |
-
|
346 |
|
347 |
-
|
348 |
-
|
349 |
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
|
356 |
-
|
357 |
-
|
358 |
|
359 |
-
|
360 |
|
361 |
-
|
362 |
-
|
363 |
|
364 |
-
|
|
|
365 |
}
|
366 |
-
}
|
367 |
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
<script>
|
379 |
jQuery(document).ready(function ($) {
|
380 |
$( '#btn_already_did' ).on( 'click', function() {
|
@@ -427,42 +425,43 @@ Could you please do us a <b>big favor</b> and give it a <b>5-star</b> rating on
|
|
427 |
});
|
428 |
</script>
|
429 |
";
|
430 |
-
|
431 |
-
|
432 |
-
/**
|
433 |
-
* Cron job activities. Where it will check basic
|
434 |
-
* functionality every day.
|
435 |
-
*
|
436 |
-
*/
|
437 |
-
|
438 |
-
public function corn_job_func()
|
439 |
-
{
|
440 |
|
441 |
-
|
|
|
|
|
|
|
|
|
442 |
|
443 |
-
|
444 |
-
|
445 |
|
446 |
-
|
447 |
-
if (get_option($this->plugin_name . '_ask_me_later') == 'yes' && get_option($this->plugin_name . '_never_show') != 'yes') {
|
448 |
|
449 |
-
$this->
|
450 |
}
|
451 |
|
452 |
-
if (
|
|
|
453 |
|
454 |
-
|
455 |
-
return;
|
456 |
}
|
457 |
|
458 |
-
if (
|
459 |
-
$this->set_installation_date();
|
460 |
-
}
|
461 |
-
$this->is_used_in($this->days);
|
462 |
|
463 |
-
|
464 |
-
|
465 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
466 |
}
|
467 |
}
|
468 |
}
|
2 |
|
3 |
namespace Wpmet\Rating;
|
4 |
|
5 |
+
defined('ABSPATH') || exit;
|
6 |
+
|
|
|
7 |
|
8 |
use DateTime;
|
9 |
use Wpmet\Rating\Notice;
|
10 |
|
11 |
+
require_once 'rating-notice.php';
|
|
|
|
|
12 |
|
13 |
+
if (!class_exists('Wpmet\Rating\Rating')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
/**
|
16 |
+
* Asking client for rating and
|
17 |
+
* other stuffs
|
18 |
+
* Class Rating
|
19 |
+
* @package MetForm\Utils
|
20 |
+
*/
|
21 |
+
class Rating
|
22 |
{
|
23 |
+
private $plugin_name;
|
24 |
+
private $days;
|
25 |
+
private $style;
|
26 |
+
private $rating_url;
|
27 |
+
private $version;
|
28 |
+
private $condition_status = true;
|
29 |
+
|
30 |
+
public function plugin_name($plugin_name)
|
31 |
+
{
|
32 |
+
$this->plugin_name = $plugin_name;
|
33 |
+
return $this;
|
34 |
+
}
|
35 |
|
36 |
+
public function first_appear_day($days = 7)
|
37 |
+
{
|
38 |
+
$this->days = $days;
|
39 |
+
return $this;
|
40 |
+
}
|
41 |
|
42 |
+
public function rating_url($url)
|
43 |
+
{
|
44 |
+
$this->rating_url = $url;
|
45 |
+
return $this;
|
46 |
+
}
|
47 |
|
48 |
+
public function add_message_style($style = '')
|
49 |
+
{
|
50 |
+
$this->style = $style;
|
51 |
+
return $this;
|
52 |
+
}
|
53 |
+
|
54 |
+
public function condition($result)
|
55 |
+
{
|
56 |
+
switch (gettype($result)) {
|
57 |
+
case 'boolean':
|
58 |
+
$this->condition_status = $result;
|
59 |
+
break;
|
60 |
+
case 'object':
|
61 |
+
$this->condition_status = $result();
|
62 |
+
break;
|
63 |
+
default:
|
64 |
+
$this->condition_status = false;
|
65 |
+
}
|
66 |
|
67 |
+
return $this;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
}
|
69 |
|
|
|
|
|
70 |
|
71 |
+
public function init()
|
72 |
+
{
|
73 |
|
74 |
+
if ($this->condition_status === false) {
|
75 |
+
return;
|
76 |
+
}
|
77 |
|
78 |
+
if (current_user_can('update_plugins')) {
|
79 |
+
add_action('admin_footer', [$this, 'scripts'], 9999);
|
80 |
+
add_action("wp_ajax_never_show_message", [$this, "never_show_message"]);
|
81 |
+
add_action("wp_ajax_ask_me_later_message", [$this, "ask_me_later_message"]);
|
82 |
|
|
|
|
|
|
|
|
|
83 |
|
84 |
+
add_action('wp', [$this, 'cron_activation']);
|
85 |
+
add_action($this->plugin_name . '_cronjob', [$this, 'corn_job_func']);
|
86 |
|
|
|
|
|
87 |
|
88 |
+
if ($this->action_on_fire()) {
|
89 |
|
90 |
+
if (!$this->is_installation_date_exists()) {
|
91 |
+
$this->set_installation_date();
|
92 |
+
}
|
93 |
|
94 |
+
if (get_option($this->plugin_name . '_ask_me_later') == 'yes' && get_option($this->plugin_name . '_never_show') != 'yes') {
|
|
|
|
|
95 |
|
96 |
+
$this->ask_me_later();
|
97 |
+
}
|
98 |
|
99 |
+
if (get_option($this->plugin_name . '_never_show') != 'yes') {
|
|
|
100 |
|
101 |
+
if (get_option($this->plugin_name . '_ask_me_later') == 'yes') {
|
102 |
+
return;
|
103 |
+
}
|
104 |
|
105 |
+
$this->is_used_in($this->days);
|
|
|
106 |
}
|
|
|
|
|
107 |
}
|
108 |
}
|
109 |
+
return $this;
|
110 |
}
|
|
|
|
|
111 |
|
112 |
+
public function cron_activation()
|
113 |
+
{
|
114 |
+
if (!wp_next_scheduled($this->plugin_name . '_cronjob')) {
|
115 |
+
wp_schedule_event(time(), 'daily', $this->plugin_name . '_cronjob');
|
116 |
+
}
|
117 |
}
|
|
|
118 |
|
119 |
+
private function action_on_fire()
|
120 |
+
{
|
121 |
+
return true;
|
122 |
+
}
|
123 |
|
124 |
|
125 |
+
public function set_installation_date()
|
126 |
+
{
|
127 |
+
add_option($this->plugin_name . '_installDate', date('Y-m-d h:i:s'));
|
128 |
+
}
|
129 |
|
130 |
+
public function is_installation_date_exists()
|
131 |
+
{
|
132 |
+
return (get_option($this->plugin_name . '_installDate') == false) ? false : true;
|
133 |
+
}
|
134 |
|
135 |
+
public function get_installation_date()
|
136 |
+
{
|
137 |
+
return get_option($this->plugin_name . '_installDate');
|
138 |
+
}
|
139 |
|
140 |
+
public function set_first_action_date()
|
141 |
+
{
|
142 |
+
add_option($this->plugin_name . '_first_action_Date', date('Y-m-d h:i:s'));
|
143 |
+
add_option($this->plugin_name . '_first_action', 'yes');
|
144 |
+
}
|
145 |
|
146 |
+
public function get_days($from_date, $to_date)
|
147 |
+
{
|
148 |
+
return round(($to_date->format('U') - $from_date->format('U')) / (60 * 60 * 24));
|
149 |
+
}
|
150 |
|
151 |
+
public function is_first_use($in_days)
|
152 |
+
{
|
153 |
+
$install_date = get_option($this->plugin_name . '_installDate');
|
154 |
+
$display_date = date('Y-m-d h:i:s');
|
155 |
+
$datetime1 = new DateTime($install_date);
|
156 |
+
$datetime2 = new DateTime($display_date);
|
157 |
+
$diff_interval = $this->get_days($datetime1, $datetime2);
|
158 |
+
if ($diff_interval >= $in_days && get_option($this->plugin_name . '_first_action_Date') == "yes") {
|
159 |
|
160 |
+
// action implementation here
|
161 |
|
162 |
+
}
|
163 |
}
|
|
|
164 |
|
165 |
+
public function is_used_in($days)
|
166 |
+
{
|
167 |
|
168 |
+
$install_date = get_option($this->plugin_name . '_installDate');
|
169 |
+
$display_date = date('Y-m-d h:i:s');
|
170 |
+
$datetime1 = new DateTime($install_date);
|
171 |
+
$datetime2 = new DateTime($display_date);
|
172 |
+
$diff_interval = $this->get_days($datetime1, $datetime2);
|
173 |
|
174 |
+
$plugin_name = $this->plugin_name;
|
175 |
|
176 |
+
if ($diff_interval >= $days) {
|
177 |
|
178 |
|
179 |
+
$message = "Hello! Seems like you have used {$plugin_name} to build this website — Thanks a lot! <br>
|
180 |
Could you please do us a <b>big favor</b> and give it a <b>5-star</b> rating on WordPress? This would boost our motivation and help other users make a comfortable decision while choosing the {$plugin_name}";
|
181 |
|
182 |
+
\Wpmet\Notice\Notice::instance('elementskit-lite', 'rating')
|
183 |
+
->dismissible('global', (60))
|
184 |
+
->add_id($this->plugin_name . '_plugin_rating_msg_used_in_day')
|
185 |
+
->add_message($message)
|
186 |
+
->add_logo('https://ps.w.org/metform/assets/icon-128x128.png', "max-height: 100px")
|
187 |
+
->add_button([
|
188 |
+
'url' => $this->rating_url,
|
189 |
+
'text' => 'Ok, you deserved it',
|
190 |
+
'class' => 'button-primary',
|
191 |
+
'id' => 'btn_deserved',
|
192 |
+
])
|
193 |
+
->add_button([
|
194 |
+
'url' => '#',
|
195 |
+
'text' => 'I already did',
|
196 |
+
'class' => 'button-default',
|
197 |
+
'id' => 'btn_already_did',
|
198 |
+
'icon' => 'dashicons-before dashicons-smiley'
|
199 |
+
])
|
200 |
+
->add_button([
|
201 |
+
'url' => 'https://help.wpmet.com/',
|
202 |
+
'text' => 'I need support',
|
203 |
+
'class' => 'button-default',
|
204 |
+
'id' => '#',
|
205 |
+
'icon' => 'dashicons-before dashicons-sos',
|
206 |
+
])
|
207 |
+
->add_button([
|
208 |
+
'url' => '#',
|
209 |
+
'text' => 'No, not good enough',
|
210 |
+
'class' => 'button-default',
|
211 |
+
'id' => 'btn_not_good',
|
212 |
+
'icon' => 'dashicons-before dashicons-thumbs-down',
|
213 |
+
])
|
214 |
+
->init();
|
215 |
+
|
216 |
+
// Notice::push(
|
217 |
+
// [
|
218 |
+
// 'id' => $this->plugin_name . '_plugin_rating_msg_used_in_day',
|
219 |
+
// 'type' => 'info',
|
220 |
+
// 'dismissible' => false,
|
221 |
+
// 'btn' => $btn,
|
222 |
+
// 'style' => $this->style,
|
223 |
+
// 'message' => "Awesome, you've been using {$plugin_name} for more {$diff_interval} days. May we ask you to give a 5-star rating on wordpress?",
|
224 |
+
// ]
|
225 |
+
// );
|
226 |
+
}
|
227 |
}
|
|
|
228 |
|
229 |
|
230 |
+
/**
|
231 |
+
* Change the status of Rating notification
|
232 |
+
* not to show the message again
|
233 |
+
*/
|
234 |
+
public function never_show_message()
|
235 |
+
{
|
236 |
+
add_option($this->plugin_name . '_never_show', 'yes');
|
237 |
+
}
|
238 |
|
239 |
|
240 |
+
/**
|
241 |
+
*
|
242 |
+
* Ask me later functionality
|
243 |
+
*
|
244 |
+
*/
|
245 |
+
public function ask_me_later()
|
246 |
+
{
|
247 |
|
248 |
+
$days = 30;
|
249 |
|
250 |
+
$install_date = get_option($this->plugin_name . '_installDate');
|
251 |
+
$display_date = date('Y-m-d h:i:s');
|
252 |
+
$datetime1 = new DateTime($install_date);
|
253 |
+
$datetime2 = new DateTime($display_date);
|
254 |
+
$diff_interval = $this->get_days($datetime1, $datetime2);
|
255 |
|
256 |
+
$plugin_name = $this->plugin_name;
|
257 |
|
258 |
+
if ($diff_interval >= $days) {
|
259 |
|
260 |
|
261 |
+
$message = "Hello! Seems like you have used {$plugin_name} to build this website — Thanks a lot! <br>
|
262 |
Could you please do us a <b>big favor</b> and give it a <b>5-star</b> rating on WordPress? This would boost our motivation and help other users make a comfortable decision while choosing the {$plugin_name}";
|
263 |
|
264 |
+
\Wpmet\Notice\Notice::instance('elementskit-lite', 'rating')
|
265 |
+
->dismissible('global', (60))
|
266 |
+
->add_id($this->plugin_name . '_plugin_rating_msg_used_in_day')
|
267 |
+
->add_message($message)
|
268 |
+
->add_logo('https://ps.w.org/metform/assets/icon-128x128.png', "max-height: 100px")
|
269 |
+
->add_button([
|
270 |
+
'url' => $this->rating_url,
|
271 |
+
'text' => 'Ok, you deserved it',
|
272 |
+
'class' => 'button-primary',
|
273 |
+
'id' => 'btn_deserved',
|
274 |
+
])
|
275 |
+
->add_button([
|
276 |
+
'url' => '#',
|
277 |
+
'text' => 'I already did',
|
278 |
+
'class' => 'button-default',
|
279 |
+
'id' => 'btn_already_did',
|
280 |
+
'icon' => 'dashicons-before dashicons-smiley'
|
281 |
+
])
|
282 |
+
->add_button([
|
283 |
+
'url' => 'https://help.wpmet.com/',
|
284 |
+
'text' => 'I need support',
|
285 |
+
'class' => 'button-default',
|
286 |
+
'id' => '#',
|
287 |
+
'icon' => 'dashicons-before dashicons-sos',
|
288 |
+
])
|
289 |
+
->add_button([
|
290 |
+
'url' => '#',
|
291 |
+
'text' => 'No, not good enough',
|
292 |
+
'class' => 'button-default',
|
293 |
+
'id' => 'btn_not_good',
|
294 |
+
'icon' => 'dashicons-before dashicons-thumbs-down',
|
295 |
+
])
|
296 |
+
->init();
|
297 |
+
}
|
298 |
}
|
|
|
299 |
|
300 |
|
301 |
+
/**
|
302 |
+
*
|
303 |
+
* When user will click @notGoodEnough button
|
304 |
+
* Then it will fire this function to change the status
|
305 |
+
* for next asking time
|
306 |
+
*
|
307 |
+
*/
|
308 |
|
309 |
|
310 |
+
public function ask_me_later_message()
|
311 |
+
{
|
312 |
|
313 |
+
if (get_option($this->plugin_name . '_ask_me_later') == false) {
|
314 |
|
315 |
+
add_option($this->plugin_name . '_ask_me_later', 'yes');
|
316 |
+
} else {
|
317 |
|
318 |
+
add_option($this->plugin_name . '_never_show', 'yes');
|
319 |
+
}
|
320 |
}
|
|
|
321 |
|
322 |
+
/**
|
323 |
+
*
|
324 |
+
* Get current version of the plugin
|
325 |
+
*
|
326 |
+
*/
|
327 |
|
328 |
+
public function get_current_version()
|
329 |
+
{
|
330 |
|
331 |
+
return $this->version;
|
332 |
+
}
|
333 |
|
334 |
+
/**
|
335 |
+
*
|
336 |
+
* Get previous version of the plugin
|
337 |
+
* that have been stored in database
|
338 |
+
*
|
339 |
+
*/
|
340 |
|
341 |
|
342 |
+
public function get_previous_version()
|
343 |
+
{
|
344 |
|
345 |
+
return get_option($this->plugin_name . '_version');
|
346 |
+
}
|
347 |
|
348 |
+
/**
|
349 |
+
*
|
350 |
+
* Set current version of the plugin
|
351 |
+
*
|
352 |
+
*/
|
353 |
|
354 |
+
public function set_version($version)
|
355 |
+
{
|
356 |
|
357 |
+
if (!get_option($this->plugin_name . '_version')) {
|
358 |
|
359 |
+
add_option($this->plugin_name . '_version');
|
360 |
+
} else {
|
361 |
|
362 |
+
update_option($this->plugin_name . '_version', $version);
|
363 |
+
}
|
364 |
}
|
|
|
365 |
|
366 |
+
/**
|
367 |
+
*
|
368 |
+
* JS Ajax script for updating
|
369 |
+
* rating status from users
|
370 |
+
*
|
371 |
+
*/
|
372 |
|
373 |
+
public function scripts()
|
374 |
+
{
|
375 |
+
echo "
|
376 |
<script>
|
377 |
jQuery(document).ready(function ($) {
|
378 |
$( '#btn_already_did' ).on( 'click', function() {
|
425 |
});
|
426 |
</script>
|
427 |
";
|
428 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
429 |
|
430 |
+
/**
|
431 |
+
* Cron job activities. Where it will check basic
|
432 |
+
* functionality every day.
|
433 |
+
*
|
434 |
+
*/
|
435 |
|
436 |
+
public function corn_job_func()
|
437 |
+
{
|
438 |
|
439 |
+
if ($this->get_current_version() != $this->get_previous_version()) {
|
|
|
440 |
|
441 |
+
$this->set_version($this->get_current_version());
|
442 |
}
|
443 |
|
444 |
+
if ($this->action_on_fire()) {
|
445 |
+
if (get_option($this->plugin_name . '_ask_me_later') == 'yes' && get_option($this->plugin_name . '_never_show') != 'yes') {
|
446 |
|
447 |
+
$this->ask_me_later();
|
|
|
448 |
}
|
449 |
|
450 |
+
if (get_option($this->plugin_name . '_never_show') != 'yes') {
|
|
|
|
|
|
|
451 |
|
452 |
+
if (get_option($this->plugin_name . '_ask_me_later') == 'yes') {
|
453 |
+
return;
|
454 |
+
}
|
455 |
+
|
456 |
+
if (!$this->is_installation_date_exists()) {
|
457 |
+
$this->set_installation_date();
|
458 |
+
}
|
459 |
+
$this->is_used_in($this->days);
|
460 |
+
|
461 |
+
add_action('admin_footer', [$this, 'scripts'], 9999);
|
462 |
+
add_action("wp_ajax_never_show_message", [$this, "never_show_message"]);
|
463 |
+
add_action("wp_ajax_ask_me_later_message", [$this, "ask_me_later_message"]);
|
464 |
+
}
|
465 |
}
|
466 |
}
|
467 |
}
|