Review.php
5.38 KB
1
2
3
4
5
6
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
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
182
183
<?php
namespace AC\Check;
use AC\Ajax;
use AC\Asset\Location\Absolute;
use AC\Asset\Script;
use AC\Capabilities;
use AC\Message;
use AC\Preferences;
use AC\Registerable;
use AC\Screen;
use AC\Type\Url\Documentation;
use AC\Type\Url\UtmTags;
class Review
implements Registerable
{
private $location;
public function __construct(Absolute $location)
{
$this->location = $location;
}
public function register(): void
{
add_action('ac/screen', [$this, 'display']);
$this->get_ajax_handler()->register();
}
public function display(Screen $screen): void
{
if ( ! $screen->has_screen()) {
return;
}
if ( ! current_user_can(Capabilities::MANAGE)) {
return;
}
if ( ! $screen->is_admin_screen() && ! $screen->is_list_screen()) {
return;
}
if ($this->get_preferences()->get('dismiss-review')) {
return;
}
if ( ! $this->first_login_compare()) {
return;
}
$script = new Script('ac-notice-review', $this->location->with_suffix('assets/js/message-review.js'), ['jquery']
);
$script->enqueue();
$notice = new Message\Notice\Dismissible($this->get_message(), $this->get_ajax_handler());
$notice
->set_id('review')
->register();
}
protected function get_ajax_handler(): Ajax\Handler
{
$handler = new Ajax\Handler();
$handler
->set_action('ac_check_review_dismiss_notice')
->set_callback([$this, 'ajax_dismiss_notice']);
return $handler;
}
protected function get_preferences(): Preferences\User
{
return new Preferences\User('check-review');
}
protected function first_login_compare(): bool
{
// Show after 30 days
return time() - (30 * DAY_IN_SECONDS) > $this->get_first_login();
}
/**
* Return the Unix timestamp of first login
*/
protected function get_first_login(): int
{
$timestamp = $this->get_preferences()->get('first-login-review');
if (empty($timestamp)) {
$timestamp = time();
$this->get_preferences()->set('first-login-review', $timestamp);
}
return $timestamp;
}
public function ajax_dismiss_notice(): void
{
$this->get_ajax_handler()->verify_request();
$this->get_preferences()->set('dismiss-review', true);
}
private function get_documentation_url(string $utm_medium): string
{
return (new UtmTags(new Documentation(), $utm_medium))->get_url();
}
protected function get_message(): string
{
$product = __('Admin Columns', 'codepress-admin-columns');
ob_start();
?>
<div class="info">
<p>
<?php
printf(
__(
"We don't mean to bug you, but you've been using %s for some time now, and we were wondering if you're happy with the plugin. If so, could you please leave a review at wordpress.org? If you're not happy with %s, please %s.",
'codepress-admin-columns'
),
'<strong>' . $product . '</strong>',
$product,
'<a class="hide-review-notice-soft" href="#">' . __(
'click here',
'codepress-admin-columns'
) . '</a>'
); ?>
</p>
<p class="buttons">
<a class="button button-primary" href="https://wordpress.org/support/view/plugin-reviews/codepress-admin-columns?rate=5#postform" target="_blank"><?php
_e('Leave a review!', 'codepress-admin-columns'); ?></a>
<a class="button button-secondary hide-review-notice" href='#' data-dismiss=""><?php
_e("Permanently hide notice", 'codepress-admin-columns'); ?></a>
</p>
</div>
<div class="help hidden">
<a href="#" class="hide-notice hide-review-notice"></a>
<p>
<?php
printf(
__(
"We're sorry to hear that; maybe we can help! If you're having problems properly setting up %s or if you would like help with some more advanced features, please visit our %s.",
'codepress-admin-columns'
),
$product,
'<a href="' . esc_url($this->get_documentation_url('review-notice')) . '" target="_blank">' . __(
'documentation page',
'codepress-admin-columns'
) . '</a>'
);
printf(
__('You can also find help on the %s, and %s.', 'codepress-admin-columns'),
'<a href="https://wordpress.org/support/plugin/codepress-admin-columns#postform" target="_blank">' . __(
'Admin Columns forum on WordPress.org',
'codepress-admin-columns'
) . '</a>',
'<a href="https://wordpress.org/plugins/codepress-admin-columns/#faq" target="_blank">' . __(
'find answers to frequently asked questions',
'codepress-admin-columns'
) . '</a>'
);
?>
</p>
</div>
<?php
return ob_get_clean();
}
}