|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Displays the site type recommendations question as a banner. |
|
4
|
|
|
* |
|
5
|
|
|
* @package automattic/jetpack |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
use Automattic\Jetpack\Assets; |
|
9
|
|
|
use Automattic\Jetpack\Assets\Logo as Jetpack_Logo; |
|
10
|
|
|
use Automattic\Jetpack\Tracking; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Jetpack_Recommendations_Banner |
|
14
|
|
|
**/ |
|
15
|
|
|
class Jetpack_Recommendations_Banner { |
|
16
|
|
|
/** |
|
17
|
|
|
* Jetpack_Recommendations_Banner |
|
18
|
|
|
* |
|
19
|
|
|
* @var Jetpack_Recommendations_Banner |
|
20
|
|
|
**/ |
|
21
|
|
|
private static $instance = null; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Factory method |
|
25
|
|
|
*/ |
|
26
|
|
|
public static function init() { |
|
27
|
|
|
if ( is_null( self::$instance ) ) { |
|
28
|
|
|
self::$instance = new Jetpack_Recommendations_Banner(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
return self::$instance; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Jetpack_Recommendations_Banner constructor. |
|
36
|
|
|
*/ |
|
37
|
|
|
private function __construct() { |
|
38
|
|
|
add_action( 'current_screen', array( $this, 'maybe_initialize_hooks' ) ); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Initialize hooks to display the banner |
|
43
|
|
|
*/ |
|
44
|
|
|
public function maybe_initialize_hooks() { |
|
45
|
|
|
if ( ! $this->can_be_displayed() ) { |
|
46
|
|
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
add_action( 'admin_print_styles', array( $this, 'admin_banner_styles' ) ); |
|
50
|
|
|
add_action( 'admin_notices', array( $this, 'render_banner' ) ); |
|
51
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_banner_scripts' ) ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Determines if the banner can be displayed |
|
56
|
|
|
*/ |
|
57
|
|
|
private function can_be_displayed() { |
|
58
|
|
|
if ( ! Jetpack_Recommendations::is_banner_enabled() ) { |
|
59
|
|
|
return false; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
// Only the dashboard and plugins pages should see the banner. |
|
63
|
|
|
if ( ! in_array( get_current_screen()->id, array( 'dashboard', 'plugins' ), true ) ) { |
|
64
|
|
|
return false; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if ( ! current_user_can( 'jetpack_manage_modules' ) ) { |
|
68
|
|
|
return false; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
if ( Jetpack_Options::get_option( 'recommendations_banner_dismissed' ) ) { |
|
72
|
|
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
if ( ! in_array( |
|
76
|
|
|
Jetpack_Options::get_option( 'recommendations_step', 'not-started' ), |
|
77
|
|
|
array( |
|
78
|
|
|
'not-started', |
|
79
|
|
|
'site-type-question', |
|
80
|
|
|
), |
|
81
|
|
|
true |
|
82
|
|
|
) ) { |
|
83
|
|
|
return false; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return true; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Handles storing the user responses in the banner. |
|
91
|
|
|
*/ |
|
92
|
|
|
public static function ajax_callback() { |
|
93
|
|
|
check_ajax_referer( 'jp-recommendations-banner-nonce', 'nonce' ); |
|
94
|
|
|
|
|
95
|
|
|
if ( ! current_user_can( 'jetpack_manage_modules' ) ) { |
|
96
|
|
|
wp_die(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$tracking = new Tracking(); |
|
100
|
|
|
|
|
101
|
|
|
if ( isset( $_REQUEST['dismissBanner'] ) && 'true' === $_REQUEST['dismissBanner'] ) { |
|
102
|
|
|
Jetpack_Options::update_option( 'recommendations_banner_dismissed', 1 ); |
|
103
|
|
|
$tracking->record_user_event( 'recommendations_banner_dismissed' ); |
|
104
|
|
|
wp_send_json_success(); |
|
105
|
|
|
wp_die(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$data = Jetpack_Recommendations::get_recommendations_data(); |
|
109
|
|
|
|
|
110
|
|
|
$tracking_answers = array(); |
|
111
|
|
|
|
|
112
|
|
View Code Duplication |
if ( isset( $_REQUEST['personal'] ) && is_string( $_REQUEST['personal'] ) ) { |
|
113
|
|
|
$value = 'true' === $_REQUEST['personal'] ? true : false; |
|
114
|
|
|
$data['site-type-personal'] = $value; |
|
115
|
|
|
$tracking_answers['personal'] = $value; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
View Code Duplication |
if ( isset( $_REQUEST['business'] ) && is_string( $_REQUEST['business'] ) ) { |
|
119
|
|
|
$value = 'true' === $_REQUEST['business'] ? true : false; |
|
120
|
|
|
$data['site-type-business'] = $value; |
|
121
|
|
|
$tracking_answers['business'] = $value; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
View Code Duplication |
if ( isset( $_REQUEST['store'] ) && is_string( $_REQUEST['store'] ) ) { |
|
125
|
|
|
$value = 'true' === $_REQUEST['store'] ? true : false; |
|
126
|
|
|
$data['site-type-store'] = $value; |
|
127
|
|
|
$tracking_answers['store'] = $value; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
View Code Duplication |
if ( isset( $_REQUEST['other'] ) && is_string( $_REQUEST['other'] ) ) { |
|
131
|
|
|
$value = 'true' === $_REQUEST['other'] ? true : false; |
|
132
|
|
|
$data['site-type-other'] = $value; |
|
133
|
|
|
$tracking_answers['other'] = $value; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
Jetpack_Recommendations::update_recommendations_data( $data ); |
|
|
|
|
|
|
137
|
|
|
Jetpack_Options::update_option( 'recommendations_step', 'banner-completed' ); |
|
138
|
|
|
|
|
139
|
|
|
$tracking->record_user_event( 'recommendations_banner_answered', $tracking_answers ); |
|
140
|
|
|
|
|
141
|
|
|
wp_send_json_success(); |
|
142
|
|
|
wp_die(); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Enqueue JavaScript files. |
|
147
|
|
|
*/ |
|
148
|
|
View Code Duplication |
public function enqueue_banner_scripts() { |
|
149
|
|
|
wp_enqueue_script( |
|
150
|
|
|
'jetpack-recommendations-banner-js', |
|
151
|
|
|
Assets::get_file_url_for_environment( |
|
152
|
|
|
'_inc/build/jetpack-recommendations-banner.min.js', |
|
153
|
|
|
'_inc/jetpack-recommendations-banner.js' |
|
154
|
|
|
), |
|
155
|
|
|
array( 'jquery' ), |
|
156
|
|
|
JETPACK__VERSION, |
|
157
|
|
|
true |
|
158
|
|
|
); |
|
159
|
|
|
|
|
160
|
|
|
wp_localize_script( |
|
161
|
|
|
'jetpack-recommendations-banner-js', |
|
162
|
|
|
'jp_banner', |
|
163
|
|
|
array( |
|
164
|
|
|
'nonce' => wp_create_nonce( 'jp-recommendations-banner-nonce' ), |
|
165
|
|
|
'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
166
|
|
|
'recommendations_url' => admin_url( 'admin.php?page=jetpack#/recommendations' ), |
|
167
|
|
|
) |
|
168
|
|
|
); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Include the needed styles |
|
173
|
|
|
*/ |
|
174
|
|
|
public function admin_banner_styles() { |
|
175
|
|
|
wp_enqueue_style( |
|
176
|
|
|
'jetpack-recommendations-banner', |
|
177
|
|
|
Assets::get_file_url_for_environment( |
|
178
|
|
|
'css/jetpack-recommendations-banner.min.css', |
|
179
|
|
|
'css/jetpack-recommendations-banner.css' |
|
180
|
|
|
), |
|
181
|
|
|
array(), |
|
182
|
|
|
JETPACK__VERSION |
|
183
|
|
|
); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Renders the Recommendations Banner |
|
188
|
|
|
*/ |
|
189
|
|
|
public function render_banner() { |
|
190
|
|
|
$jetpack_logo = new Jetpack_Logo(); |
|
191
|
|
|
$site_name = get_bloginfo( 'name' ); |
|
192
|
|
|
?> |
|
193
|
|
|
<div id="jp-recommendations-banner-main" class="jp-recommendations-banner-main"> |
|
194
|
|
|
<div class="jp-recommendations-banner__content"> |
|
195
|
|
|
<div class="jp-recommendations-banner__logo"> |
|
196
|
|
|
<?php |
|
197
|
|
|
echo $jetpack_logo->get_jp_emblem_larger(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
198
|
|
|
?> |
|
199
|
|
|
</div> |
|
200
|
|
|
<h1 class="jp-recommendations-banner__question"> |
|
201
|
|
|
<?php |
|
202
|
|
|
/* translators: placeholder is the name of the website */ |
|
203
|
|
|
echo sprintf( esc_html__( 'What type of site is %s?', 'jetpack' ), esc_html( $site_name ) ); |
|
204
|
|
|
?> |
|
205
|
|
|
</h1> |
|
206
|
|
|
<p class="jp-recommendations-banner__description"> |
|
207
|
|
|
<?php esc_html_e( 'This assistant will help you get the most from Jetpack. Tell us more about your goals and we’ll recommend relevant features to help you succeed.', 'jetpack' ); ?> |
|
208
|
|
|
</p> |
|
209
|
|
|
<div class="jp-recommendations-banner__answer"> |
|
210
|
|
|
<form id="jp-recommendations-banner__form" class="jp-recommendations-banner__form"> |
|
211
|
|
|
<div class="jp-recommendations-banner__checkboxes"> |
|
212
|
|
|
<?php $this->render_checkbox( 'personal', __( 'Personal', 'jetpack' ) ); ?> |
|
213
|
|
|
<?php $this->render_checkbox( 'business', __( 'Business', 'jetpack' ) ); ?> |
|
214
|
|
|
<?php $this->render_checkbox( 'store', __( 'Store', 'jetpack' ) ); ?> |
|
215
|
|
|
<?php $this->render_checkbox( 'other', __( 'Other', 'jetpack' ) ); ?> |
|
216
|
|
|
</div> |
|
217
|
|
|
</form> |
|
218
|
|
|
<a id="jp-recommendations-banner__continue-button" class="jp-recommendations-banner__continue-button"> |
|
219
|
|
|
<?php esc_html_e( 'Continue', 'jetpack' ); ?> |
|
220
|
|
|
</a> |
|
221
|
|
|
<div class="jp-recommendations-banner__continue-description"> |
|
222
|
|
|
<?php esc_html_e( 'All of Jetpack’s great features await you and we’ll recommend some of our favorites.', 'jetpack' ); ?> |
|
223
|
|
|
</div> |
|
224
|
|
|
</div> |
|
225
|
|
|
</div> |
|
226
|
|
|
<div class="jp-recommendations-banner__illustration-container"> |
|
227
|
|
|
<img |
|
228
|
|
|
src="<?php echo esc_url( plugins_url( 'images/recommendations/background.svg', JETPACK__PLUGIN_FILE ), 'jetpack' ); ?>" |
|
229
|
|
|
class="jp-recommendations-banner__illustration-background" |
|
230
|
|
|
/> |
|
231
|
|
|
<img |
|
232
|
|
|
src="<?php echo esc_url( plugins_url( 'images/recommendations/site-type-illustration.jpg', JETPACK__PLUGIN_FILE ), 'jetpack' ); ?>" |
|
233
|
|
|
class="jp-recommendations-banner__illustration-foreground" |
|
234
|
|
|
/> |
|
235
|
|
|
</div> |
|
236
|
|
|
<span id="jp-recommendations-banner__notice-dismiss" class="notice-dismiss" title="<?php esc_attr_e( 'Dismiss this notice', 'jetpack' ); ?>"/> |
|
237
|
|
|
</div> |
|
238
|
|
|
<?php |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Renders a checkbox. |
|
243
|
|
|
* |
|
244
|
|
|
* @param string $name The name to give the form input. |
|
245
|
|
|
* @param string $title The title to put on the checkbox. |
|
246
|
|
|
*/ |
|
247
|
|
|
private function render_checkbox( $name, $title ) { |
|
248
|
|
|
?> |
|
249
|
|
|
<label for="<?php echo esc_html( $name ); ?>" class="jp-recommendations-answer__checkbox-label"> |
|
250
|
|
|
<input id="<?php echo esc_html( $name ); ?>" name="<?php echo esc_html( $name ); ?>" type="checkbox" tabindex="-1"/> |
|
251
|
|
|
<div class="jp-recommendations-answer__title"> |
|
252
|
|
|
<?php echo esc_html( $title ); ?> |
|
253
|
|
|
</div> |
|
254
|
|
|
</label> |
|
255
|
|
|
<?php |
|
256
|
|
|
} |
|
257
|
|
|
} |
|
258
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: