Skip to content

Commit b6edea6

Browse files
Add nearing quota warning
1 parent a83d28a commit b6edea6

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

assets/src/dashboard/parts/connected/dashboard/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ const ActivatedNotice = () => (
8181
</div>
8282
);
8383

84+
const ExceedPlanQuotaWarning = () => (
85+
<div className="flex gap-2 bg-warning text-danger border border-solid border-danger rounded relative px-6 py-5 mb-5">
86+
<Icon icon="warning" />
87+
88+
<p
89+
className="m-0"
90+
dangerouslySetInnerHTML={ { __html: optimoleDashboardApp.strings.exceed_plan_quota_notice } }
91+
/>
92+
</div>
93+
);
94+
8495
const Dashboard = () => {
8596
const {
8697
userData,
@@ -128,6 +139,7 @@ const Dashboard = () => {
128139
return (
129140
<div className="bg-white p-8 border-0 rounded-lg shadow-md">
130141
{ ( 0 < optimoleDashboardApp.strings.notice_just_activated.length && 'active' === userStatus ) && <ActivatedNotice/> }
142+
{ ( 0 < optimoleDashboardApp.strings.exceed_plan_quota_notice.length && 'active' === userStatus ) && <ExceedPlanQuotaWarning/> }
131143

132144
{ 'inactive' === userStatus && <InactiveWarning/> }
133145

inc/admin.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,14 @@ private function get_dashboard_strings() {
16241624
'</b>',
16251625
'<br>'
16261626
),
1627+
'exceed_plan_quota_notice' => $this->should_show_exceed_quota_warning() ?
1628+
sprintf(
1629+
/* translators: 1 starting bold tag, 2 is the ending bold tag */
1630+
__( '%1$sYour site has already reached over 50%% of your monthly visits limit within just two weeks.%2$s <br/> Based on this trend, you are likely to exceed your free quota before the month ends. To avoid any disruption in service, we strongly recommend upgrading your plan or waiting until your traffic stabilizes before offloading your images. Do you still wish to proceed?', 'optimole-wp' ),
1631+
'<strong>',
1632+
'</strong>'
1633+
)
1634+
: '',
16271635
'signup_terms' => sprintf(
16281636
/* translators: 1 is starting anchor tag to terms, 2 is starting anchor tag to privacy link and 3 is ending anchor tag. */
16291637
__( 'By signing up, you agree to our %1$sTerms of Service %3$s and %2$sPrivacy Policy %3$s.', 'optimole-wp' ),
@@ -2171,4 +2179,53 @@ public function survey_category( $value, $scale = 1 ) {
21712179

21722180
return 0;
21732181
}
2182+
2183+
/**
2184+
* Determines whether the exceed quota warning should be displayed to users.
2185+
*
2186+
* This function checks if the user's quota usage has exceeded a predefined limit
2187+
* and returns a boolean value indicating whether the warning should be shown.
2188+
*
2189+
* @return bool True if the exceed quota warning should be displayed, false otherwise.
2190+
*/
2191+
public function should_show_exceed_quota_warning() {
2192+
$current_screen = get_current_screen();
2193+
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ||
2194+
is_network_admin() ||
2195+
! current_user_can( 'manage_options' ) ||
2196+
! $this->settings->is_connected() ||
2197+
empty( $current_screen )
2198+
) {
2199+
return false;
2200+
}
2201+
if ( get_option( 'optml_notice_hide_upg', 'no' ) === 'yes' ) {
2202+
return false;
2203+
}
2204+
2205+
if ( ! str_contains( $current_screen->base, 'page_optimole' ) ) {
2206+
return false;
2207+
}
2208+
$service_data = $this->settings->get( 'service_data' );
2209+
2210+
if ( ! isset( $service_data['plan'] ) ) {
2211+
return false;
2212+
}
2213+
if ( $service_data['plan'] !== 'free' ) {
2214+
return false;
2215+
}
2216+
$service_data['days_since_registration'] = 15;
2217+
if ( $service_data['days_since_registration'] <= 14 ) {
2218+
return false;
2219+
}
2220+
$visitors_limit = isset( $service_data['visitors_limit'] ) ? (int) $service_data['visitors_limit'] : 0;
2221+
$visitors_left = isset( $service_data['visitors_left'] ) ? (int) $service_data['visitors_left'] : 0;
2222+
$used_quota = $visitors_limit - $visitors_left;
2223+
$is_50_percent_used = ( $used_quota / $visitors_limit ) >= 0.5;
2224+
2225+
if ( ! $is_50_percent_used ) {
2226+
return false;
2227+
}
2228+
2229+
return true;
2230+
}
21742231
}

0 commit comments

Comments
 (0)