Skip to content

Commit 20fd2f7

Browse files
authored
Notify limits (#484)
* Fix typo * Move get_tos_choice * Report API limits exceeded
1 parent 63beeb4 commit 20fd2f7

5 files changed

+51
-30
lines changed

Extension_ImageService_Plugin_Admin.js

+12
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,18 @@
435435
) {
436436
message = response.responseJSON.data.message;
437437
rebindBuyClick = true;
438+
439+
if ( 'accept' === w3tcData.tos_choice && w3tcData.track_usage ) {
440+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
441+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
442+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
443+
})(window,document,'script','https://api.w3-edge.com/v1/analytics','w3tc_ga');
444+
445+
if ( window.w3tc_ga ) {
446+
w3tc_ga( 'create', w3tcData.ga_profile, 'auto' );
447+
w3tc_ga( 'send', 'event', 'w3tc_error', 'imageservice', response.responseJSON.data.code );
448+
}
449+
}
438450
} else {
439451
message = w3tcData.lang.ajaxFail;
440452
}

Extension_ImageService_Plugin_Admin.php

+6
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ public function admin_menu() {
498498
* Runs on the "admin_enqueue_scripts" action.
499499
*
500500
* @since 2.2.0
501+
*
502+
* @see Util_Ui::admin_url()
503+
* @see Licensing_Core::get_tos_choice()
501504
*/
502505
public function admin_enqueue_scripts() {
503506
// Enqueue JavaScript for the Media Library (upload) and extension settings admin pages.
@@ -561,6 +564,9 @@ public function admin_enqueue_scripts() {
561564
'</a>'
562565
),
563566
),
567+
'tos_choice' => Licensing_Core::get_tos_choice(),
568+
'track_usage' => $this->config->get_boolean( 'common.track_usage' ),
569+
'ga_profile' => ( defined( 'W3TC_DEBUG' ) && W3TC_DEBUG ) ? 'UA-2264433-7' : 'UA-2264433-8',
564570
'settings' => $this->config->get_array( 'imageservice' ),
565571
'settingsUrl' => esc_url( Util_Ui::admin_url( 'upload.php?page=w3tc_extension_page_imageservice' ) ),
566572
)

Licensing_Core.php

+28
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,32 @@ static public function purchase_url( $data_src = '', $renew_key = '', $client_id
131131
( empty( $renew_key ) ? '' : '&renew_key=' . urlencode( $renew_key ) ) .
132132
( empty( $client_id ) ? '' : '&client_id=' . urlencode( $client_id ) );
133133
}
134+
135+
/**
136+
* Get the terms of service choice.
137+
*
138+
* @since X.X.X
139+
*
140+
* @static
141+
*
142+
* @see \W3TC\Util_Environment::is_w3tc_pro()
143+
* @see \W3TC\Dispatcher::config_state()
144+
* @see \W3TC\Dispatcher::config_state_master()
145+
* @see \W3TC\ConfigState::get_string()
146+
*
147+
* @return string
148+
*/
149+
public static function get_tos_choice() {
150+
$config = Dispatcher::config();
151+
152+
if ( Util_Environment::is_w3tc_pro( $config ) ) {
153+
$state = Dispatcher::config_state();
154+
$terms = $state->get_string( 'license.terms' );
155+
} else {
156+
$state_master = Dispatcher::config_state_master();
157+
$terms = $state_master->get_string( 'license.community_terms' );
158+
}
159+
160+
return $terms;
161+
}
134162
}

SetupGuide_Plugin_Admin.php

+4-29
Original file line numberDiff line numberDiff line change
@@ -813,39 +813,13 @@ public function config_lazyload() {
813813
}
814814
}
815815

816-
/**
817-
* Get the terms of service choice.
818-
*
819-
* @since 2.0.0
820-
*
821-
* @see \W3TC\Util_Environment::is_w3tc_pro()
822-
* @see \W3TC\Dispatcher::config_state()
823-
* @see \W3TC\Dispatcher::config_state_master()
824-
* @see \W3TC\ConfigState::get_string()
825-
*
826-
* @return string
827-
*/
828-
private function get_tos_choice() {
829-
$config = new Config();
830-
831-
if ( Util_Environment::is_w3tc_pro( $config ) ) {
832-
$state = Dispatcher::config_state();
833-
$terms = $state->get_string( 'license.terms' );
834-
} else {
835-
$state_master = Dispatcher::config_state_master();
836-
$terms = $state_master->get_string( 'license.community_terms' );
837-
}
838-
839-
return $terms;
840-
}
841-
842816
/**
843817
* Display the terms of service dialog if needed.
844818
*
845819
* @since 2.0.0
846820
* @access private
847821
*
848-
* @see self::get_tos_choice()
822+
* @see Licensing_Core::get_tos_choice()
849823
*
850824
* @return bool
851825
*/
@@ -854,7 +828,7 @@ private function maybe_ask_tos() {
854828
return false;
855829
}
856830

857-
$terms = $this->get_tos_choice();
831+
$terms = Licensing_Core::get_tos_choice();
858832

859833
return 'accept' !== $terms && 'decline' !== $terms && 'postpone' !== $terms;
860834
}
@@ -871,6 +845,7 @@ private function maybe_ask_tos() {
871845
* @see \W3TC\Config::get_boolean()
872846
* @see \W3TC\Util_Request::get_string()
873847
* @see \W3TC\Dispatcher::config_state()
848+
* @see \W3TC\Licensing_Core::get_tos_choice()
874849
* @see \W3TC\Util_Environment::home_url_host()
875850
* @see \W3TC\Util_Environment::w3tc_edition()
876851
* @see \W3TC\Util_Widget::list_widgets()
@@ -914,7 +889,7 @@ private function get_config() {
914889
'w3tc_edition' => esc_attr( Util_Environment::w3tc_edition( $config ) ),
915890
'list_widgets' => esc_attr( Util_Widget::list_widgets() ),
916891
'ga_profile' => ( defined( 'W3TC_DEBUG' ) && W3TC_DEBUG ) ? 'UA-2264433-7' : 'UA-2264433-8',
917-
'tos_choice' => $this->get_tos_choice(),
892+
'tos_choice' => Licensing_Core::get_tos_choice(),
918893
'track_usage' => $config->get_boolean( 'common.track_usage' ),
919894
'test_complete_msg' => __(
920895
'Testing complete. Click Next to advance to the section and see the results.',

inc/wizard/template.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public function enqueue_scripts() {
245245
'w3tc_wizard',
246246
'W3TC_Wizard',
247247
array(
248-
'beforeunloadText' => __( 'Are you sure that you want to leve this page?', 'w3-total-cache' ),
248+
'beforeunloadText' => __( 'Are you sure that you want to leave this page?', 'w3-total-cache' ),
249249
)
250250
);
251251

0 commit comments

Comments
 (0)