Metform Elementor Contact Form Builder – Flexible and Design-Friendly Contact Form builder plugin for WordPress - Version 1.3.11

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 Icon 128x128 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

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