Skip to content
Draft
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
32 changes: 32 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 @@ -206,6 +206,14 @@ public static function get_gpt_completion( $content, $post_id, $skip_cache = fal

$site_id = Manager::get_site_id();
if ( is_wp_error( $site_id ) ) {
// If the site is not connected, return a more helpful error message.
if ( 'unavailable_site_id' === $site_id->get_error_code() ) {
return new WP_Error(
'unavailable_site_id',
__( 'Your account must be connected to WordPress.com to generate AI content. Please connect your account from the Jetpack settings screen to proceed.', 'jetpack' ),
array( 'status' => 403 )
);
}
return $site_id;
}

Expand Down Expand Up @@ -271,6 +279,14 @@ function ( $msg ) {
);

if ( is_wp_error( $response ) ) {
// If the user is not connected, return a more helpful error message.
if ( 'missing_token' === $response->get_error_code() ) {
return new WP_Error(
'missing_token',
__( 'Your account must be connected to WordPress.com to use AI assistance. Please connect your account from the Jetpack settings screen to proceed.', 'jetpack' ),
array( 'status' => 403 )
);
}
return $response;
}

Expand Down Expand Up @@ -312,6 +328,14 @@ public static function get_dalle_generation( $prompt, $post_id ) {

$site_id = Manager::get_site_id();
if ( is_wp_error( $site_id ) ) {
// If the site is not connected, return a more helpful error message.
if ( 'unavailable_site_id' === $site_id->get_error_code() ) {
return new WP_Error(
'unavailable_site_id',
__( 'Your account must be connected to WordPress.com to generate AI images. Please connect your account from the Jetpack settings screen to proceed.', 'jetpack' ),
array( 'status' => 403 )
);
}
return $site_id;
}

Expand Down Expand Up @@ -346,6 +370,14 @@ public static function get_dalle_generation( $prompt, $post_id ) {
);

if ( is_wp_error( $response ) ) {
// If the user is not connected, return a more helpful error message.
if ( 'missing_token' === $response->get_error_code() ) {
return new WP_Error(
'missing_token',
__( 'Your account must be connected to WordPress.com to generate AI images. Please connect your account from the Jetpack settings screen to proceed.', 'jetpack' ),
array( 'status' => 403 )
);
}
return $response;
}

Expand Down