WPCOM_JSON_API_Update_Sharing_Button_Endpoint

The Jetpack by WordPress.com WPCOM JSON API Update Sharing Button Endpoint class.

Defined (1)

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

/json-endpoints/class.wpcom-json-api-sharing-buttons-endpoint.php  
  1. class WPCOM_JSON_API_Update_Sharing_Button_Endpoint extends WPCOM_JSON_API_Sharing_Button_Endpoint { 
  2.  
  3. // POST /sites/%s/sharing-buttons/new -> $blog_id 
  4. // POST /sites/%s/sharing-buttons/%s -> $blog_id, $button_id 
  5. public function callback( $path = '', $blog_id = 0, $button_id = 0 ) { 
  6. $new = $this->api->ends_with( $path, '/new' ); 
  7. $input = $this->input(); 
  8.  
  9. // Validate request 
  10. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); 
  11. if ( is_wp_error( $blog_id ) ) { 
  12. return $blog_id; 
  13.  
  14. $continue = $this->setup(); 
  15. if ( is_wp_error( $continue ) ) { 
  16. return $continue; 
  17.  
  18. $validation_error = $this->validate_button_input( $input, $new ); 
  19. if ( is_wp_error( $validation_error ) ) { 
  20. return $validation_error; 
  21.  
  22. // Update or create button 
  23. if ( $new ) { 
  24. $updated_service = $this->create_custom_button( $input ); 
  25. } else { 
  26. $updated_service = $this->update_button( $button_id, $input ); 
  27.  
  28. if ( false === $updated_service ) { 
  29. return new WP_Error( 'invalid_request', sprintf( 'The sharing button was not %s', $new ? 'created' : 'updated' ), 400 ); 
  30. } else if ( is_wp_error( $updated_service ) ) { 
  31. return $updated_service; 
  32. } else { 
  33. return $this->format_sharing_button( $updated_service ); 
  34.