WPCOM_JSON_API_Get_Connections_Endpoint

The Jetpack by WordPress.com WPCOM JSON API Get Connections Endpoint class.

Defined (1)

The class is defined in the following location(s).

/json-endpoints/class.wpcom-json-api-publicize-endpoint.php  
  1. class WPCOM_JSON_API_Get_Connections_Endpoint extends WPCOM_JSON_API_Endpoint { 
  2. // /sites/%s/connections 
  3. function callback( $path = '', $blog_id = 0 ) { 
  4. // Verify required Publicize Jetpack module is active 
  5. if ( ! class_exists( 'Publicize' ) || ( method_exists( 'Jetpack', 'is_module_active' ) && ! Jetpack::is_module_active( 'publicize' ) ) ) { 
  6. return new WP_Error( 'missing_jetpack_module', 'The Publicize module must be activated in order to use this endpoint.', 400 ); 
  7.  
  8. // Authenticate user 
  9. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ), false ); 
  10. if ( is_wp_error( $blog_id ) ) { 
  11. return $blog_id; 
  12.  
  13. $current_user = wp_get_current_user(); 
  14. if ( ! $current_user->ID ) { 
  15. return new WP_Error( 'authorization_required', 'An active access token must be used to query information about the current user.', 403 ); 
  16.  
  17. // Parse query arguments to determine if filtering is requested 
  18. $args = $this->query_args(); 
  19. $service_filter = false; 
  20. if ( ! empty( $args['service'] ) ) { 
  21. $service_filter = $args['service']; 
  22.  
  23. // Iterate over connected services 
  24. $publicize = new Publicize(); 
  25. $connected_services = $publicize->get_services( 'connected' ); 
  26. $output = array(); 
  27. foreach( $connected_services as $service => $connections ) { 
  28. if ( false != $service_filter && $service_filter != $service ) { 
  29. continue; 
  30.  
  31. foreach ( $connections as $connection_id => $connection ) { 
  32. $output[] = WPCOM_JSON_API_Get_Connection_Endpoint::get_connection( $service, $connection ); 
  33.  
  34. return array( 'connections' => $output );