Skip to content

Commit

Permalink
take jetpack_ai_enabled into consideration, don't waste cycles if use…
Browse files Browse the repository at this point in the history
…r has disabled it. Respond with default payload
  • Loading branch information
CGastrell committed Sep 30, 2024
1 parent a083a22 commit 921babd
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions projects/plugins/jetpack/_inc/lib/class-jetpack-ai-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ public static function get_ai_assistance_feature() {
return $cache;
}

if ( ! apply_filters( 'jetpack_ai_enabled', true ) ) {
// if user has disabled AI, don't waste request/computing cycles and return default payload.
return self::get_default_feature_payload();
}

if ( null !== static::$ai_assistant_failed_request ) {
return static::$ai_assistant_failed_request;
}
Expand Down Expand Up @@ -453,4 +458,27 @@ public static function get_ai_assistance_feature() {
return $error;
}
}

/**
* Get the default feature payload for when the feature is NOT available for a site.
* This is a default response for consistency.
*/
private static function get_default_feature_payload() {
return array(
'has-feature' => false,
'is-over-limit' => false,
'requests-count' => 0,
'requests-limit' => 20,
'usage-period' => array(),
'site-require-upgrade' => false,
'upgrade-type' => 'default',
'upgrade-url' => '',
'current-tier' => null,
'next-tier' => null,
'tier-plans' => array(),
'tier-plans-enabled' => false,
'costs' => array(),
'features-control' => array(),
);
}
}

0 comments on commit 921babd

Please sign in to comment.