| @@ 300-321 (lines=22) @@ | ||
| 297 | * |
|
| 298 | * @return array|WP_Error |
|
| 299 | */ |
|
| 300 | public function parse_site_info_response( $service_response ) { |
|
| 301 | ||
| 302 | /** |
|
| 303 | * If the service returned an error, we pass it on. |
|
| 304 | */ |
|
| 305 | if ( is_wp_error( $service_response ) ) { |
|
| 306 | return $service_response; |
|
| 307 | } |
|
| 308 | ||
| 309 | /** |
|
| 310 | * Check if the service returned proper site information. |
|
| 311 | */ |
|
| 312 | if ( ! isset( $service_response->ID ) ) { |
|
| 313 | return new WP_Error( |
|
| 314 | 'no_site_info', |
|
| 315 | __( 'Invalid site information returned from remote.', 'jetpack' ), |
|
| 316 | 'No site ID present in the response.' |
|
| 317 | ); |
|
| 318 | } |
|
| 319 | ||
| 320 | return $service_response; |
|
| 321 | } |
|
| 322 | ||
| 323 | /** |
|
| 324 | * Fetch list of posts from the WordPress public API. |
|
| @@ 361-386 (lines=26) @@ | ||
| 358 | * |
|
| 359 | * @return array|WP_Error |
|
| 360 | */ |
|
| 361 | public function parse_posts_response( $service_response ) { |
|
| 362 | ||
| 363 | /** |
|
| 364 | * If the service returned an error, we pass it on. |
|
| 365 | */ |
|
| 366 | if ( is_wp_error( $service_response ) ) { |
|
| 367 | return $service_response; |
|
| 368 | } |
|
| 369 | ||
| 370 | /** |
|
| 371 | * Check if the service returned proper posts array. |
|
| 372 | */ |
|
| 373 | if ( ! isset( $service_response->posts ) || ! is_array( $service_response->posts ) ) { |
|
| 374 | return new WP_Error( |
|
| 375 | 'no_posts', |
|
| 376 | __( 'No posts data returned by remote.', 'jetpack' ), |
|
| 377 | 'No posts information set in the returned data.' |
|
| 378 | ); |
|
| 379 | } |
|
| 380 | ||
| 381 | /** |
|
| 382 | * Format the posts to preserve storage space. |
|
| 383 | */ |
|
| 384 | ||
| 385 | return $this->format_posts_for_storage( $service_response ); |
|
| 386 | } |
|
| 387 | ||
| 388 | /** |
|
| 389 | * Format the posts for better storage. Drop all the data that is not used. |
|