PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 12.2.3
Jetpack – WP Security, Backup, Speed, & Growth v12.2.3
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / stats / class-jetpack-stats-upgrade-nudges.php
jetpack / modules / stats Last commit date
class-jetpack-stats-upgrade-nudges.php 3 years ago
class-jetpack-stats-upgrade-nudges.php
584 lines
1 <?php
2 /**
3 * Adds a section with Upgrade nudges to the Status Report page
4 *
5 * @package jetpack
6 */
7
8 use Automattic\Jetpack\Connection\Manager;
9 use Automattic\Jetpack\Jetpack_CRM_Data;
10 use Automattic\Jetpack\Plugins_Installer;
11 use Automattic\Jetpack\Redirect;
12 use Automattic\Jetpack\Tracking;
13
14 /**
15 * Class that adds a new section to the Stats Report page
16 */
17 class Jetpack_Stats_Upgrade_Nudges {
18
19 /**
20 * Indicates whether the class initialized or not
21 *
22 * @var bool
23 */
24 private static $initialized = false;
25
26 /**
27 * Initialize the class by registering the action
28 *
29 * @return void
30 */
31 public static function init() {
32 if ( ! self::$initialized ) {
33 self::$initialized = true;
34 add_action( 'jetpack_admin_pages_wrap_ui_after_callback', array( __CLASS__, 'render' ) );
35 }
36 }
37
38 /**
39 * Unsets the collapse nudges setting.
40 */
41 public static function unset_nudges_setting() {
42 $stats_options = get_option( 'stats_options' );
43
44 if ( $stats_options ) {
45 unset( $stats_options['collapse_nudges'] );
46 update_option( 'stats_options', $stats_options );
47 }
48 }
49
50 /**
51 * Determines whether Backup is active
52 *
53 * @return boolean
54 */
55 private static function is_backup_active() {
56 $rewind_data = Jetpack_Core_Json_Api_Endpoints::rewind_data();
57 return is_object( $rewind_data ) && isset( $rewind_data->state ) && 'unavailable' !== $rewind_data->state;
58 }
59
60 /**
61 * Checks if a plugin is installed.
62 *
63 * @param string $plugin_file The plugin filename.
64 * @return boolean
65 */
66 private static function is_plugin_installed( $plugin_file ) {
67 $plugins = Plugins_Installer::get_plugins();
68 return isset( $plugins[ $plugin_file ] );
69 }
70
71 /**
72 * Checks if a plugin is active.
73 *
74 * @param string $plugin_file The plugin filename.
75 * @return boolean
76 */
77 private static function is_plugin_active( $plugin_file ) {
78 $plugins = Plugins_Installer::get_plugins();
79 return isset( $plugins[ $plugin_file ] ) && isset( $plugins[ $plugin_file ]['active'] ) && $plugins[ $plugin_file ]['active'];
80 }
81
82 /**
83 * Determines whether Scan is active
84 *
85 * @return boolean
86 */
87 private static function is_scan_active() {
88 $scan_data = Jetpack_Core_Json_Api_Endpoints::scan_state();
89 return is_object( $scan_data ) && isset( $scan_data->state ) && 'unavailable' !== $scan_data->state;
90 }
91
92 /**
93 * Determines whether Search module is active
94 *
95 * @return boolean
96 */
97 private static function is_search_active() {
98 return Jetpack::is_module_active( 'search' );
99 }
100
101 /**
102 * Determines whether the Site is on a Security Plan. It will also return true if site has backup, scan and akismet.
103 *
104 * @return boolean
105 */
106 private static function has_security_plan() {
107 $plan_data = Jetpack_Plan::get();
108 if ( is_array( $plan_data ) && isset( $plan_data['product_slug'] ) ) {
109 $has_plan = wp_startswith( $plan_data['product_slug'], 'jetpack_security' );
110 return (
111 $has_plan || (
112 self::is_backup_active() &&
113 self::is_scan_active() &&
114 self::is_akismet_active()
115 )
116 );
117 }
118 return false;
119 }
120
121 /**
122 * Determines whether the Site is on the Complete Plan.
123 *
124 * @return boolean
125 */
126 private static function has_complete_plan() {
127 $plan_data = Jetpack_Plan::get();
128 if ( is_array( $plan_data ) && isset( $plan_data['product_slug'] ) ) {
129 return wp_startswith( $plan_data['product_slug'], 'jetpack_complete' );
130 }
131 return false;
132 }
133
134 /**
135 * Determines whether the Site has a specific product.
136 *
137 * @param string $target_product_slug The product slug we are looking for.
138 *
139 * @return boolean
140 */
141 private static function has_product( $target_product_slug ) {
142 $site_products_slugs = array_column( Jetpack_Plan::get_products(), 'product_slug' );
143
144 foreach ( $site_products_slugs as $product_slug ) {
145 if ( wp_startswith( $product_slug, $target_product_slug ) ) {
146 return true;
147 }
148 }
149
150 return false;
151 }
152
153 /**
154 * Determines whether Akismet is active
155 *
156 * @return boolean
157 */
158 private static function is_akismet_active() {
159 return Jetpack::is_akismet_active();
160 }
161
162 /**
163 * Outputs the header of the Upgrade Secion
164 *
165 * @return void
166 */
167 private static function print_header() {
168 if ( self::has_security_plan() ) {
169 // translators: %s is the Site Name.
170 $title = __( 'Performance and growth tools for %s', 'jetpack' );
171 } else {
172 // translators: %s is the Site Name.
173 $title = __( 'Security, performance, and growth tools for %s', 'jetpack' );
174 }
175 $title = sprintf( $title, get_bloginfo( 'site_name' ) );
176
177 $aria_expanded = 'true';
178 $postbox_closed = '';
179
180 $stats_options = get_option( 'stats_options' );
181
182 if ( isset( $stats_options['collapse_nudges'] ) && $stats_options['collapse_nudges'] ) {
183 $aria_expanded = 'false';
184 $postbox_closed = ' closed';
185 }
186
187 ?>
188 <div id="jp-stats-report-upgrade-wrap">
189 <div class="meta-box-sortables">
190 <div class="postbox<?php echo esc_attr( $postbox_closed ); ?>">
191 <div class="dops-card dops-section-header is-compact jp-stats-report-upgrade-header">
192 <div class="dops-section-header__label">
193 <span class="dops-section-header__label-text">
194 <?php echo esc_html( $title ); ?>
195 </span>
196 </div>
197 <div class="dops-section-header__actions handle-actions hide-if-no-js">
198 <button type="button" id="stats_nudges_toggle" class="handlediv" aria-expanded="<?php echo esc_attr( $aria_expanded ); ?>">
199 <span class="screen-reader-text">Toggle Upgrade Nudges</span>
200 <span class="toggle-indicator" aria-hidden="true"></span>
201 </button>
202 </div>
203 </div>
204 <div class="inside">
205 <?php
206 }
207
208 /**
209 * Outputs the footer of the Upgrade Section
210 *
211 * @return void
212 */
213 private static function print_footer() {
214 ?>
215 </div>
216 </div>
217 </div>
218 </div>
219 <?php
220 }
221
222 /**
223 * Outputs the custom css rules of the Upgrade Section
224 *
225 * @return void
226 */
227 private static function print_styles() {
228 ?>
229 <style>
230 .dops-section-header.dops-card.jp-stats-report-upgrade-header {
231 font-weight: bold;
232 box-shadow: none;
233 flex-wrap: nowrap;
234 }
235 #jp-stats-report-upgrade-wrap .dops-section-header__label-text {
236 white-space: normal;
237 }
238 #stats_nudges_toggle {
239 height: 100%;
240 }
241 .dops-banner.dops-card.is-product.jp-stats-report-upgrade-item {
242 margin-bottom: 0px;
243 border-left: 0px;
244 box-shadow: none;
245 border-top: 1px solid #c3c4c7;
246 padding: 12px 24px;
247 }
248 .dops-banner.dops-card.jp-stats-report-upgrade-item.jp-stats-report-upgrade-subitem {
249 margin-left: 72px;
250 padding-left: 0px;
251 }
252 .jp-stats-report-upgrade-item .dops-banner__action {
253 margin-right: 0px;
254 }
255 #jp-stats-report-upgrade-wrap .dops-card::after {
256 content: "";
257 }
258 .jp-stats-report-upgrade-item .dops-banner__title p {
259 margin: 5px 0 0 0;
260 font-weight: normal;
261 }
262 #jp-stats-report-upgrade-wrap .postbox {
263 background-color: white;
264 border: 1px solid #c3c4c7;
265 margin-bottom: 0;
266 }
267 #jp-stats-report-upgrade-wrap .postbox .inside {
268 padding: 0;
269 }
270 </style>
271 <?php
272 }
273 /**
274 * Add a script which handles collapse/expansion of the nudge UI.
275 */
276 private static function print_script() {
277 ?>
278 <script>
279 (function(window, document, undefined){
280 window.onload = set_up_click_handler;
281
282 const stats_wrap = document.getElementById( 'jp-stats-wrap' );
283 stats_wrap.addEventListener( 'stats-loaded', function () {
284 const stat_chart = document.getElementById( 'statchart' );
285 if ( stat_chart === null ) {
286 document.getElementById( 'stats_nudges_toggle' ).style.display = 'none';
287 }
288 });
289
290 function set_up_click_handler(){
291 document.getElementById( 'stats_nudges_toggle' ).onclick = function () {
292 const collapseValue = 'true' === this.getAttribute( 'aria-expanded' );
293
294 fetch( '/wp-json/jetpack/v4/settings', {
295 method: 'post',
296 body: JSON.stringify( { collapse_nudges: collapseValue } ),
297 headers: {
298 'X-WP-Nonce': "<?php echo esc_js( wp_create_nonce( 'wp_rest' ) ); ?>",
299 'Content-type': 'application/json' }
300 } );
301 };
302 }
303 })(window, document, undefined);
304 </script>
305 <?php
306 }
307
308 /**
309 * Gets the upgrade Redirect link
310 *
311 * @param string $source The source of the redirect link.
312 * @return string
313 */
314 private static function get_upgrade_link( $source ) {
315 $args = array();
316 if ( ! ( new Manager( 'jetpack' ) )->has_connected_owner() ) {
317 $args['query'] = 'unlinked=1';
318 }
319 return Redirect::get_url( $source, $args );
320 }
321
322 /**
323 * Gets the product description link.
324 *
325 * @param string $product_key The product key of the product we wish to display.
326 * @return string
327 */
328 private static function get_product_description_link( $product_key ) {
329 return Jetpack::admin_url( array( 'page' => sprintf( 'jetpack#/product/%s', $product_key ) ) );
330 }
331
332 /**
333 * Tracks an event in Tracks
334 *
335 * @param string $event_name The event name.
336 * @return void
337 */
338 private static function track_event( $event_name ) {
339 $connection_manager = new Manager( 'jetpack' );
340 $tracking = new Tracking( 'jetpack', $connection_manager );
341 $tracking->record_user_event(
342 $event_name,
343 array(
344 'has_connected_owner' => $connection_manager->has_connected_owner(),
345 )
346 );
347 }
348
349 /**
350 * Outputs one Upgrade item
351 *
352 * @param string $title The title of the item.
353 * @param string $text The description of the item.
354 * @param string $icon The path of the icon, relative to Jetpack images folder.
355 * @param string $link The link of the button.
356 * @param string $tracks_id The id used to identify the tracks events. Automatically prefixed with "jetpack_stats_nudges_{view|click|learn_more}_".
357 * @param string $learn_more_link The target of the "Learn more" link.
358 * @param boolean $subitem Whether it is a subitem or not.
359 * @param string $button_label The button label.
360 * @return void
361 */
362 private static function print_item( $title, $text, $icon, $link, $tracks_id, $learn_more_link, $subitem = false, $button_label = null ) {
363 $additional_classes = $subitem ? 'jp-stats-report-upgrade-subitem' : '';
364 $button_class = $subitem ? 'is-secondary' : 'is-primary';
365 $icon_url = plugins_url( '', JETPACK__PLUGIN_FILE ) . '/images/products/' . $icon;
366 $button_label = $button_label === null ? _x( 'Upgrade', 'Call to action to buy a new plan', 'jetpack' ) : $button_label;
367 $view_event = "stats_nudges_view_$tracks_id";
368 $click_event = "stats_nudges_click_$tracks_id";
369 $learn_more_event = "stats_nudges_learn_more_$tracks_id";
370 self::track_event( $view_event );
371
372 ?>
373 <div class="dops-card dops-banner has-call-to-action is-product jp-stats-report-upgrade-item <?php echo esc_attr( $additional_classes ); ?>">
374 <div class="dops-banner__icon-plan">
375 <img src="<?php echo esc_attr( $icon_url ); ?>" alt="" width="32" height="32">
376 </div>
377 <div class="dops-banner__content">
378 <div class="dops-banner__info">
379 <div class="dops-banner__title">
380 <?php echo esc_html( $title ); ?>
381 <p>
382 <?php echo esc_html( $text ); ?>
383 <a href="<?php echo esc_attr( $learn_more_link ); ?>" class="jptracks" target="_blank" rel="noopener noreferrer" data-jptracks-name="<?php echo esc_attr( $learn_more_event ); ?>">
384 <?php esc_html_e( 'Learn more', 'jetpack' ); ?>
385 </a>
386 </p>
387 </div>
388 </div>
389 <div class="dops-banner__action">
390 <a href="<?php echo esc_attr( $link ); ?>" type="button" class="jptracks dops-button is-compact <?php echo esc_attr( $button_class ); ?>" data-jptracks-name="<?php echo esc_attr( $click_event ); ?>">
391 <?php echo esc_html( $button_label ); ?>
392 </a>
393 </div>
394 </div>
395 </div>
396 <?php
397 }
398
399 /**
400 * Prints the Security item
401 *
402 * @return void
403 */
404 private static function print_security() {
405 $link = self::get_product_description_link( 'security' );
406 $learn_link = self::get_upgrade_link( 'stats-nudges-security-learn' );
407 $text = __( 'Comprehensive protection for your site, including Backup, Scan, and Anti-spam.', 'jetpack' );
408 self::print_item( _x( 'Security', 'Jetpack product name', 'jetpack' ), $text, 'product-jetpack.svg', $link, 'security', $learn_link );
409 }
410
411 /**
412 * Prints the Backup item
413 *
414 * @return void
415 */
416 private static function print_backup() {
417 $link = self::get_product_description_link( 'backup' );
418 $learn_link = self::get_upgrade_link( 'stats-nudges-backup-learn' );
419 $text = __( 'Save every change and get back online quickly with one-click restores.', 'jetpack' );
420 self::print_item( __( 'VaultPress Backup', 'jetpack' ), $text, 'product-jetpack-backup.svg', $link, 'backup', $learn_link, true );
421 }
422
423 /**
424 * Prints the Scan item
425 *
426 * @since 10.1
427 * @since 10.3 The scan nudge has been removed, but leaving this here in case we reverse course.
428 *
429 * @todo Remove this function is not used ~6 months.
430 *
431 * @return void
432 */
433 private static function print_scan() {
434 $link = self::get_product_description_link( 'scan' );
435 $learn_link = self::get_upgrade_link( 'stats-nudges-scan-learn' );
436 $text = __( 'Stay ahead of security threats with automated scanning and one-click fixes.', 'jetpack' );
437 self::print_item( __( 'Scan', 'jetpack' ), $text, 'product-jetpack-scan.svg', $link, 'scan', $learn_link, true );
438 }
439
440 /**
441 * Prints the Akismet item
442 *
443 * @since 10.1
444 * @since 10.3 The anti-spam nudge has been removed, but leaving this here in case we reverse course.
445 *
446 * @todo Remove this function is not used ~6 months.
447 *
448 * @return void
449 */
450 private static function print_akismet() {
451 $link = self::get_product_description_link( 'akismet' );
452 $learn_link = self::get_upgrade_link( 'stats-nudges-akismet-learn' );
453 $text = __( 'Automatically clear spam from comments and forms.', 'jetpack' );
454 self::print_item( __( 'Akismet Anti-spam', 'jetpack' ), $text, 'product-jetpack-anti-spam.svg', $link, 'akismet', $learn_link, true );
455 }
456
457 /**
458 * Prints the Search item
459 *
460 * @return void
461 */
462 private static function print_search() {
463 $link = self::get_product_description_link( 'search' );
464 $learn_link = self::get_upgrade_link( 'stats-nudges-search-learn' );
465 $text = __( 'Help your site visitors instantly find what they\'re looking for so they read and buy more.', 'jetpack' );
466 self::print_item( __( 'Search', 'jetpack' ), $text, 'product-jetpack-search.svg', $link, 'search', $learn_link );
467 }
468
469 /**
470 * Prints the VideoPress item
471 *
472 * @return void
473 */
474 private static function print_videopress() {
475 $link = self::get_product_description_link( 'videopress' );
476 $learn_link = self::get_upgrade_link( 'stats-nudges-videopress-learn' );
477 $text = __( 'Engage your visitors with high-quality, ad-free videos built specifically for WordPress.', 'jetpack' );
478 self::print_item( __( 'VideoPress', 'jetpack' ), $text, 'product-jetpack-videopress.svg', $link, 'videopress', $learn_link );
479 }
480
481 /**
482 * Prints the Boost item
483 *
484 * @param bool $print Whether to print the item output or just check whether it would be printed or not.
485 *
486 * @return bool
487 */
488 private static function get_boost_output( $print = true ) {
489 $plugin_file = 'jetpack-boost/jetpack-boost.php';
490 $plugin_slug = 'jetpack-boost';
491 if ( self::is_plugin_active( $plugin_file ) ) {
492 return false;
493 } elseif ( self::is_plugin_installed( $plugin_file ) ) {
494 $label = __( 'Activate Boost', 'jetpack' );
495 $link = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . rawurlencode( $plugin_file ) . '&amp;plugin_status=all&amp;paged=1', 'activate-plugin_' . $plugin_file );
496 } else {
497 $label = __( 'Install Boost', 'jetpack' );
498 $link = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $plugin_slug ), 'install-plugin_' . $plugin_slug );
499 }
500 if ( $print ) {
501 $learn_link = self::get_upgrade_link( 'stats-nudges-boost-learn' );
502 $text = __( 'Improve your site\'s performance and SEO in a few clicks with the free Jetpack Boost plugin.', 'jetpack' );
503 self::print_item( __( 'Boost', 'jetpack' ), $text, 'product-jetpack-boost.svg', $link, 'boost', $learn_link, false, $label );
504 }
505 return true;
506 }
507
508 /**
509 * Prints the CRM item
510 *
511 * @param bool $print Whether to print the item output or just check whether it would be printed or not.
512 *
513 * @since 10.1
514 *
515 * @return bool
516 */
517 private static function get_crm_output( $print = true ) {
518 $plugin_file = Jetpack_CRM_Data::JETPACK_CRM_PLUGIN_SLUG;
519 $plugin_slug = substr( $plugin_file, 0, strpos( $plugin_file, '/' ) );
520 if ( self::is_plugin_active( $plugin_file ) ) {
521 return false;
522 } elseif ( self::is_plugin_installed( $plugin_file ) ) {
523 $link = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . rawurlencode( $plugin_file ) . '&amp;plugin_status=all&amp;paged=1', 'activate-plugin_' . $plugin_file );
524 $label = __( 'Activate CRM', 'jetpack' );
525 } else {
526 $link = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $plugin_slug ), 'install-plugin_' . $plugin_slug );
527 $label = __( 'Install CRM', 'jetpack' );
528 }
529 if ( $print ) {
530 $learn_link = self::get_upgrade_link( 'stats-nudges-crm-learn' );
531 $text = __( 'Sell more and get more leads with the free Jetpack CRM plugin built specifically for WordPress.', 'jetpack' );
532 self::print_item( __( 'CRM', 'jetpack' ), $text, 'product-jetpack-crm.svg', $link, 'crm', $learn_link, false, $label );
533 }
534 return true;
535 }
536
537 /**
538 * Outputs the section to the Stats Report page
539 *
540 * @param string $callback The callback passed to the jetpack admin page.
541 * @return void
542 */
543 public static function render( $callback ) {
544 /** This filter is documented in _inc/lib/admin-pages/class.jetpack-react-page.php */
545 if ( 'stats_reports_page' !== $callback || ! apply_filters( 'jetpack_show_promotions', true ) || ! current_user_can( 'manage_options' ) ) {
546 return;
547 }
548
549 if ( self::has_complete_plan() ) {
550 return;
551 }
552
553 if (
554 self::has_security_plan() &&
555 self::is_backup_active() &&
556 self::is_search_active() &&
557 ! self::get_boost_output( false ) &&
558 ! self::get_crm_output( false )
559 ) {
560 return;
561 }
562
563 self::print_styles();
564 self::print_script();
565 self::print_header();
566 if ( ! self::has_security_plan() ) {
567 self::print_security();
568 if ( ! self::is_backup_active() ) {
569 self::print_backup();
570 }
571 }
572 if ( ! self::is_search_active() ) {
573 self::print_search();
574 }
575 if ( ! self::has_product( 'jetpack_videopress' ) ) {
576 self::print_videopress();
577 }
578 self::get_boost_output();
579 self::get_crm_output();
580 self::print_footer();
581 }
582
583 }
584