Skip to content

Commit 7585417

Browse files
committed
Merge remote-tracking branch 'origin/development' into development
2 parents c5e8406 + d08e039 commit 7585417

File tree

5 files changed

+75
-35
lines changed

5 files changed

+75
-35
lines changed

assets/src/dashboard/parts/connected/settings/Compression.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,30 @@ const Compression = ({
3939
isSampleLoading,
4040
setIsSampleLoading
4141
}) => {
42+
const getQuality = value => {
43+
if ( 'number' === typeof value ) {
44+
return value;
45+
}
46+
47+
if ( 'auto' === value || 'mauto' === value ) {
48+
return 80;
49+
}
50+
51+
if ( 'high_c' === value ) {
52+
return 90;
53+
}
54+
55+
if ( 'medium_c' === value ) {
56+
return 75;
57+
}
58+
59+
if ( 'low_c' === value ) {
60+
return 55;
61+
}
62+
63+
return 80;
64+
};
65+
4266
const {
4367
sampleImages,
4468
isLoading
@@ -60,6 +84,7 @@ const Compression = ({
6084
const isBestFormatEnabled = 'disabled' !== settings[ 'best_format' ];
6185
const compressionMode = settings[ 'compression_mode' ];
6286
const isRetinaEnabled = 'disabled' !== settings[ 'retina_images' ];
87+
6388
const updateOption = ( option, value ) => {
6489
setCanSave( true );
6590
const data = { ...settings };
@@ -79,30 +104,6 @@ const Compression = ({
79104
);
80105
};
81106

82-
const getQuality = value => {
83-
if ( 'number' === typeof value ) {
84-
return value;
85-
}
86-
87-
if ( 'auto' === value ) {
88-
return 90;
89-
}
90-
91-
if ( 'high_c' === value ) {
92-
return 90;
93-
}
94-
95-
if ( 'medium_c' === value ) {
96-
return 75;
97-
}
98-
99-
if ( 'low_c' === value ) {
100-
return 55;
101-
}
102-
103-
return 90;
104-
};
105-
106107
const updateQuality = value => {
107108
setCanSave( true );
108109
const data = { ...settings };

inc/admin.php

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ public function add_notice_upgrade() {
652652
?>
653653
</p>
654654
<p style="margin: 1.5% 0;">
655-
<a href="<?php echo esc_url( tsdk_translate_link( 'https://optimole.com/pricing' ) ); ?>"
655+
<a href="<?php echo esc_url( tsdk_translate_link( self::get_upgrade_base_link() ) ); ?>"
656656
target="_blank"
657657
style="border-radius: 4px;padding: 9px 10px;border: 2px solid #FFF;color: white;text-decoration: none;"><?php _e( 'Check upgrade plans', 'optimole-wp' ); ?>
658658
</a>
@@ -704,6 +704,41 @@ public function should_show_upgrade() {
704704
return true;
705705
}
706706

707+
/**
708+
* Build upgrade URL with current user's encoded email.
709+
*
710+
* @return string Upgrade URL.
711+
*/
712+
public static function get_upgrade_base_link() {
713+
$base_url = 'https://optimole.com/upgrade';
714+
$email = self::get_account_email();
715+
716+
if ( ! empty( $email ) ) {
717+
$base_url = add_query_arg( 'email', base64_encode( $email ), $base_url );
718+
}
719+
720+
return $base_url;
721+
}
722+
723+
/**
724+
* Retrieve Optimole account email.
725+
*
726+
* @return string
727+
*/
728+
private static function get_account_email() {
729+
$settings = new Optml_Settings();
730+
$service_data = $settings->get( 'service_data' );
731+
732+
if ( isset( $service_data['user_email'] ) && is_string( $service_data['user_email'] ) ) {
733+
$email = sanitize_email( $service_data['user_email'] );
734+
if ( ! empty( $email ) ) {
735+
return $email;
736+
}
737+
}
738+
739+
return '';
740+
}
741+
707742
/**
708743
* CSS styles for Notice.
709744
*/
@@ -1520,7 +1555,7 @@ public function get_bf_notices() {
15201555
'<span class="border-b border-0 border-white border-dashed text-promo-orange">BFCM2425</span>',
15211556
'<span class="text-promo-orange uppercase">' . __( '25% off', 'optimole-wp' ) . '</span>'
15221557
),
1523-
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( 'https://optimole.com/pricing' ), 'bfcm24', 'sidebarnotice' ) ),
1558+
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm24', 'sidebarnotice' ) ),
15241559
],
15251560
];
15261561

@@ -1540,7 +1575,7 @@ public function get_bf_notices() {
15401575
'<span class="text-promo-orange">' . __( '25% discount', 'optimole-wp' ) . '</span>'
15411576
),
15421577
'cta_text' => __( 'Claim now', 'optimole-wp' ),
1543-
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( 'https://optimole.com/pricing' ), 'bfcm24', 'dismissiblenotice' ) ),
1578+
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm24', 'dismissiblenotice' ) ),
15441579
'dismiss_key' => self::BF_PROMO_DISMISS_KEY,
15451580
];
15461581

@@ -1687,7 +1722,7 @@ private function get_dashboard_strings() {
16871722
'notice_disabled_account' => sprintf(
16881723
/* translators: 1 anchor tag to pricing, 2 is the ending endin anchor tag, 3 is the bold tag start, 4 ending bold tag, 5 new line tag */
16891724
__( '%3$sYour account has been disabled due to exceeding quota.%4$s All images are being redirected to the original unoptimized URL. %5$sPlease %1$supgrade%2$s to re-activate the account.', 'optimole-wp' ),
1690-
'<b><a href="' . esc_url( tsdk_translate_link( 'https://optimole.com/pricing' ) ) . '">',
1725+
'<b><a href="' . esc_url( tsdk_translate_link( self::get_upgrade_base_link() ) ) . '">',
16911726
'</a></b>',
16921727
'<b>',
16931728
'</b>',

inc/config.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ public static function init( $service_settings = [] ) {
121121
self::$secret = trim( $service_settings['secret'] );
122122
}
123123
self::$service_url = sprintf( 'https://%s.%s', self::$key, self::$base_domain );
124-
if ( isset( $service_settings['domain'] ) && ! empty( $service_settings['domain'] ) ) {
125-
self::$service_url = sprintf( 'https://%s', $service_settings['domain'] );
126-
} elseif ( defined( 'OPTML_CUSTOM_DOMAIN' ) ) {
124+
if ( defined( 'OPTML_CUSTOM_DOMAIN' ) ) {
127125
self::$service_url = constant( 'OPTML_CUSTOM_DOMAIN' );
126+
} elseif ( isset( $service_settings['domain'] ) && ! empty( $service_settings['domain'] ) ) {
127+
self::$service_url = sprintf( 'https://%s', $service_settings['domain'] );
128128
}
129129

130130
$options = [ 'domain' => parse_url( self::$service_url, PHP_URL_HOST ) ];

inc/rest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ public function check_redirects( WP_REST_Request $request ) {
788788
$status_code = $response['response']['code'];
789789
if ( $status_code === 301 ) {
790790
$status = 'deactivated';
791-
$result = '<li>❌ ' . sprintf( /* translators: 1 is starting anchor tag, 2 is the ending anchor tag. */ __( 'Your account is currently disabled due to exceeding quota and Optimole is no longer able to optimize the images. In order to fix this you will need to %1$supgrade%2$s.', 'optimole-wp' ), '<a target="_blank" href="' . esc_url( tsdk_translate_link( 'https://optimole.com/pricing' ) ) . '">', '</a>' ) . '</li>';
791+
$result = '<li>❌ ' . sprintf( /* translators: 1 is starting anchor tag, 2 is the ending anchor tag. */ __( 'Your account is currently disabled due to exceeding quota and Optimole is no longer able to optimize the images. In order to fix this you will need to %1$supgrade%2$s.', 'optimole-wp' ), '<a target="_blank" href="' . esc_url( tsdk_translate_link( Optml_Admin::get_upgrade_base_link() ) ) . '">', '</a>' ) . '</li>';
792792
break;
793793
}
794794
if ( $status_code === 302 ) {

inc/settings.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Optml_Settings {
7575
'compression_mode' => 'custom',
7676
'cloud_sites' => [ 'all' => 'true' ],
7777
'watchers' => '',
78-
'quality' => 'auto',
78+
'quality' => 80,
7979
'wm_id' => - 1,
8080
'wm_opacity' => 1,
8181
'wm_position' => Position::SOUTH_EAST,
@@ -237,7 +237,9 @@ public function auto_connect() {
237237
* @return array
238238
*/
239239
public function parse_settings( $new_settings ) {
240-
$sanitized = [];
240+
$sanitized = [];
241+
$sanitized_value = '';
242+
241243
foreach ( $new_settings as $key => $value ) {
242244
switch ( $key ) {
243245
case 'admin_bar_item':
@@ -278,7 +280,9 @@ public function parse_settings( $new_settings ) {
278280
$sanitized_value = $this->to_bound_integer( $value, 100, 5000 );
279281
break;
280282
case 'quality':
281-
$sanitized_value = $this->to_bound_integer( $value, 1, 100 );
283+
if ( 'mauto' !== $value ) {
284+
$sanitized_value = $this->to_bound_integer( $value, 50, 100 );
285+
}
282286
break;
283287
case 'wm_id':
284288
$sanitized_value = intval( $value );

0 commit comments

Comments
 (0)