WPCOM_JSON_API_Delete_Sharing_Button_Endpoint

The Jetpack by WordPress.com WPCOM JSON API Delete 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_Delete_Sharing_Button_Endpoint extends WPCOM_JSON_API_Sharing_Button_Endpoint { 
  2.  
  3. // POST /sites/%s/sharing-buttons/%s/delete -> $blog_id, $button_id 
  4. public function callback( $path = '', $blog_id = 0, $button_id = 0 ) { 
  5. // Validate request 
  6. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); 
  7. if ( is_wp_error( $blog_id ) ) { 
  8. return $blog_id; 
  9.  
  10. $continue = $this->setup(); 
  11. if ( is_wp_error( $continue ) ) { 
  12. return $continue; 
  13.  
  14. // Find existing button 
  15. $all_buttons = $this->sharing_service->get_all_services_blog(); 
  16. if ( ! array_key_exists( $button_id, $all_buttons ) ) { 
  17. // Button doesn't exist 
  18. return new WP_Error( 'not_found', 'The specified sharing button was not found', 404 ); 
  19.  
  20. // Verify button is custom 
  21. if ( ! is_a( $all_buttons[ $button_id ], 'Share_Custom' ) ) { 
  22. return new WP_error( 'invalid_request', 'Only custom sharing buttons can be deleted', 400 ); 
  23.  
  24. $success = $this->sharing_service->delete_service( $button_id ); 
  25. return array( 
  26. 'ID' => $button_id,  
  27. 'success' => $success 
  28. ); 
  29.