Skip to content

Commit

Permalink
Memberships: Add error messaging for connected accounts (#35564)
Browse files Browse the repository at this point in the history
* Return error when connected account can't be loaded.

* changelog
  • Loading branch information
chrisfromthelc authored Feb 13, 2024
1 parent 7d38061 commit eaddb2f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,31 @@ public function get_status( \WP_REST_Request $request ) {

if ( $this->is_wpcom() ) {
require_lib( 'memberships' );
$blog_id = get_current_blog_id();
return (array) get_memberships_settings_for_site( $blog_id, $product_type, $is_editable, $source );
$blog_id = get_current_blog_id();
$membership_settings = get_memberships_settings_for_site( $blog_id, $product_type, $is_editable, $source );

if ( is_wp_error( $membership_settings ) ) {
// Get error messages from the $membership_settings.
$error_codes = $membership_settings->get_error_codes();
$error_messages = array();

foreach ( $error_codes as $code ) {
$messages = $membership_settings->get_error_messages( $code );
foreach ( $messages as $message ) {
// Sanitize error message
$error_messages[] = esc_html( $message );
}
}

$error_messages_string = implode( ' ', $error_messages );
// translators: %s is a list of error messages.
$base_message = __( 'Could not get the membership settings due to the following error(s): %s', 'jetpack' );
$full_message = sprintf( $base_message, $error_messages_string );

return new WP_Error( 'membership_settings_error', $full_message, array( 'status' => 404 ) );
}

return (array) $membership_settings;
} else {
$payload = array(
'type' => $request['type'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Adds error messaging to endpoint when connected account for memberships cannot be loaeded.

0 comments on commit eaddb2f

Please sign in to comment.