'unknown', 'message' => __( 'This Connector Hub is too old to report which Google sign-in returns it accepts, so compatibility cannot be confirmed. If connecting Search Console, Analytics or Business Profile fails, an out-of-date Hub is the first thing to check.', 'ai-o-optimiser' ), 'missing' => array(), 'hub_version' => $hub_version, ); } $supported = array_map( 'strval', $response['oauth_actions'] ); $missing = array_values( array_diff( self::REQUIRED_ACTIONS, $supported ) ); if ( empty( $missing ) ) { return array( 'state' => 'ok', 'message' => __( 'The Connector Hub recognises this plugin\'s Google sign-in returns.', 'ai-o-optimiser' ), 'missing' => array(), 'hub_version' => $hub_version, ); } return array( 'state' => 'incompatible', 'message' => sprintf( /* translators: 1: comma-separated Google service names, 2: Hub version or "unknown". */ __( 'The Connector Hub does not accept this plugin\'s sign-in returns for %1$s, so connecting those services will fail until the Hub is updated. Hub version reported: %2$s.', 'ai-o-optimiser' ), implode( ', ', self::service_names( $missing ) ), '' !== $hub_version ? $hub_version : __( 'unknown', 'ai-o-optimiser' ) ), 'missing' => $missing, 'hub_version' => $hub_version, ); } /** * Name the affected services the way an administrator would recognise them. * * "ai_o_optimiser_local_gbp_oauth_return is missing" is true and useless to * the person who has to act on it. * * @param string[] $actions Missing action names. * @return string[] */ private static function service_names( $actions ) { $names = array( 'ai_o_optimiser_gsc_oauth_return' => __( 'Search Console', 'ai-o-optimiser' ), 'ai_o_optimiser_ga4_data_oauth_return' => __( 'Google Analytics', 'ai-o-optimiser' ), 'ai_o_optimiser_local_gbp_oauth_return' => __( 'Google Business Profile', 'ai-o-optimiser' ), ); $out = array(); foreach ( $actions as $action ) { $out[] = isset( $names[ $action ] ) ? $names[ $action ] : $action; } return $out; } /** Drop the cached verdict, so the next refresh asks again. */ public static function flush() { delete_transient( self::TRANSIENT ); } }