Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #6152: Add license type to what is reported to Mixpanel #6189

Merged
merged 3 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions assets/css/wpr-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,15 @@ a:focus, button:focus {
text-decoration: underline;
}

/* ----------------------------------------------- *\

Rocket Analytics CTA

/* ----------------------------------------------- */
.wpr-rocket-analytics-cta.wpr-isHidden {
display: none;
}

/*-----------------------------------------------*\

Upgrade popin
Expand Down Expand Up @@ -2049,6 +2058,21 @@ div.wpr-upgrade-websites {
.wpr-addon .wpr-field-description {
font-style: normal;
}
.wpr-addon .wpr-field-helper {
font-size: 0.8125rem;
line-height: 1.5384615385;
color: #666666;
background-color: #E0E4E9;
padding: 8px;
margin: 8px 0;
}
.wpr-addon .wpr-field-helper span.wpr-helper-title {
font-weight: 600;
}
.wpr-addon .wpr-field-helper span.wpr-helper-title::after {
content: "\a";
white-space: pre;
}
.wpr-addon .wpr-addon-logo {
text-align: center;
flex: 0 0 160px;
Expand Down
2 changes: 1 addition & 1 deletion assets/css/wpr-admin.min.css

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions assets/js/wpr-admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/js/wpr-admin.js.min.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/wpr-admin.min.js

Large diffs are not rendered by default.

20 changes: 1 addition & 19 deletions inc/Engine/Admin/Settings/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,25 +260,7 @@ public function customer_data() {
'is_from_one_dot_com' => false,
];

if (
false === $user
||
! isset( $user->licence_account, $user->licence_expiration )
) {
return $data;
}

if (
1 <= $user->licence_account
&&
$user->licence_account < 3
) {
$data['license_type'] = 'Single';
} elseif ( -1 === (int) $user->licence_account ) {
$data['license_type'] = 'Infinite';
} else {
$data['license_type'] = 'Plus';
}
$data['license_type'] = rocket_get_license_type( $user );

$data['license_class'] = time() < $user->licence_expiration ? 'wpr-isValid' : 'wpr-isInvalid';
$data['license_expiration'] = date_i18n( get_option( 'date_format' ), (int) $user->licence_expiration );
Expand Down
6 changes: 6 additions & 0 deletions inc/admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ function rocket_analytics_data() {
$data['cdn_cnames'] = 0;
}

$customer_data = get_transient( 'wp_rocket_customer_data' );
$data['license_type'] = '';
if ( false !== $customer_data ) {
$data['license_type'] = rocket_get_license_type( $customer_data );
}

return $data;
}

Expand Down
47 changes: 41 additions & 6 deletions inc/functions/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function rocket_data_collection_preview_table() {
$html .= sprintf( '<strong>%s</strong>', __( 'Server type:', 'rocket' ) );
$html .= '</td>';
$html .= '<td>';
$html .= sprintf( '<code>%s</code>', $data['web_server'] );
$html .= sprintf( '<em>%s</em>', $data['web_server'] );
$html .= '</td>';
$html .= '</tr>';

Expand All @@ -370,7 +370,7 @@ function rocket_data_collection_preview_table() {
$html .= sprintf( '<strong>%s</strong>', __( 'PHP version number:', 'rocket' ) );
$html .= '</td>';
$html .= '<td>';
$html .= sprintf( '<code>%s</code>', $data['php_version'] );
$html .= sprintf( '<em>%s</em>', $data['php_version'] );
$html .= '</td>';
$html .= '</tr>';

Expand All @@ -379,7 +379,7 @@ function rocket_data_collection_preview_table() {
$html .= sprintf( '<strong>%s</strong>', __( 'WordPress version number:', 'rocket' ) );
$html .= '</td>';
$html .= '<td>';
$html .= sprintf( '<code>%s</code>', $data['wordpress_version'] );
$html .= sprintf( '<em>%s</em>', $data['wordpress_version'] );
$html .= '</td>';
$html .= '</tr>';

Expand All @@ -388,7 +388,7 @@ function rocket_data_collection_preview_table() {
$html .= sprintf( '<strong>%s</strong>', __( 'WordPress multisite:', 'rocket' ) );
$html .= '</td>';
$html .= '<td>';
$html .= sprintf( '<code>%s</code>', $data['multisite'] ? 'true' : 'false' );
$html .= sprintf( '<em>%s</em>', $data['multisite'] ? 'true' : 'false' );
$html .= '</td>';
$html .= '</tr>';

Expand All @@ -397,7 +397,7 @@ function rocket_data_collection_preview_table() {
$html .= sprintf( '<strong>%s</strong>', __( 'Current theme:', 'rocket' ) );
$html .= '</td>';
$html .= '<td>';
$html .= sprintf( '<code>%s</code>', $data['current_theme'] );
$html .= sprintf( '<em>%s</em>', $data['current_theme'] );
$html .= '</td>';
$html .= '</tr>';

Expand All @@ -406,7 +406,7 @@ function rocket_data_collection_preview_table() {
$html .= sprintf( '<strong>%s</strong>', __( 'Current site language:', 'rocket' ) );
$html .= '</td>';
$html .= '<td>';
$html .= sprintf( '<code>%s</code>', $data['locale'] );
$html .= sprintf( '<em>%s</em>', $data['locale'] );
$html .= '</td>';
$html .= '</tr>';

Expand All @@ -428,6 +428,15 @@ function rocket_data_collection_preview_table() {
$html .= '</td>';
$html .= '</tr>';

$html .= '<tr>';
$html .= '<td class="column-primary">';
$html .= sprintf( '<strong>%s</strong>', __( 'WP Rocket license type', 'rocket' ) );
$html .= '</td>';
$html .= '<td>';
$html .= sprintf( '<em>%s</em>', $data['license_type'] );
$html .= '</td>';
$html .= '</tr>';

$html .= '</tbody>';
$html .= '</table>';

Expand Down Expand Up @@ -526,3 +535,29 @@ function rocket_create_options_hash( $value ) {

return md5( wp_json_encode( $value_diff ) );
}

/**
* This function returns the license type for a customer.
*
* @param object $customer_data customer data as an object.
* @return string the type of the license the user has.
*/
function rocket_get_license_type( $customer_data ) {
if ( false === $customer_data
||
! isset( $customer_data->licence_account )
) {
return __( 'Unavailable', 'rocket' );
}

if ( 1 <= $customer_data->licence_account
&&
$customer_data->licence_account < 3
) {
return 'Single';
} elseif ( -1 === (int) $customer_data->licence_account ) {
return 'Infinite';
}

return 'Plus';
}
5 changes: 5 additions & 0 deletions src/js/global/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ $(document).ready(function(){
$('#analytics_enabled').trigger('change');
}

// Display CTA within the popin `What info will we collect?`
$('#analytics_enabled').on('change', function () {
$('.wpr-rocket-analytics-cta').toggleClass('wpr-isHidden');
});

/***
* Show popin upgrade
***/
Expand Down
13 changes: 13 additions & 0 deletions src/scss/layout/_Rocketanalytics.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// main: ../main.scss

/* ----------------------------------------------- *\

Rocket Analytics CTA

/* ----------------------------------------------- */

.wpr-rocket-analytics-cta {
&.wpr-isHidden{
display: none;
}
}
1 change: 1 addition & 0 deletions src/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ More informations here : https://suitcss.github.io/ or http://www.alsacreations.
@import "layout/_Page";
@import "layout/_Popin";
@import "layout/_Rocketcdn";
@import "layout/_Rocketanalytics";
@import "layout/_Upgrade";
@import "layout/_Promotion";
@import "layout/_Renewals";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
'config' => [
'role' => 'administrator',
'user_meta' => true,
'screen' => 'settings_page_wprocket',
],
'screen' => 'settings_page_wprocket'
],
],

'testShouldNotDisplayNoticeWhenActive' => [
Expand Down
28 changes: 28 additions & 0 deletions tests/Fixtures/inc/functions/admin/rocketGetLicenseType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

return [
'singleLicense' => [
'config' => [
'customer_data' => (object)['licence_account' => 1],
],
'expected' => 'Single',
],
'infiniteLicense' => [
'config' => [
'customer_data' => (object)['licence_account' => -1],
],
'expected' => 'Infinite',
],
'plusLicense' => [
'config' => [
'customer_data' => (object)['licence_account' => 3],
],
'expected' => 'Plus',
],
'unavailableLicense' => [
'config' => [
'customer_data' => null,
],
'expected' => 'Unavailable',
],
];
24 changes: 24 additions & 0 deletions tests/Unit/inc/functions/admin/rocketGetLicenseType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace WP_Rocket\Tests\Unit\inc\functions\admin;

use WP_Rocket\Tests\Unit\TestCase;

class Test_RocketGetLicenseType extends TestCase {

public function setUp(): void {
parent::setUp();
}

/**
* @dataProvider configTestData
*/
public function testReturnAsExpected($config, $expected) {
$this->stubTranslationFunctions();
// Extract 'customer_data' from the config
$customer_data = $config['customer_data'];
$result = rocket_get_license_type($customer_data);

$this->assertEquals($expected, $result);
}
}
3 changes: 2 additions & 1 deletion views/settings/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@
?>
</p>
<?php echo rocket_data_collection_preview_table(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view. ?>

<div class="wpr-Popin-flex">
<p><?php esc_html_e( 'WP Rocket will never transmit any domain names or email addresses (except for license validation), IP addresses, or third-party API keys.', 'rocket' ); ?></p>
<div>
<button class="wpr-button wpr-button--small wpr-button--icon wpr-icon-check wpr-button--blue"><?php esc_html_e( 'Activate Rocket analytics', 'rocket' ); ?></button>
<button class="wpr-button wpr-button--small wpr-button--icon wpr-icon-check wpr-button--blue wpr-rocket-analytics-cta<?php echo get_rocket_option( 'analytics_enabled' ) ? ' wpr-isHidden' : ''; ?>"><?php esc_html_e( 'Activate Rocket analytics', 'rocket' ); ?></button>
</div>
</div>
</div>
Expand Down
Loading