wpcf7_rest_delete_contact_form

The Contact Form 7 wpcf7 rest delete contact form function.

Description

wpcf7_rest_delete_contact_form( WP_REST_Request $request ); 

Parameters (1)

0. $request
The request.

Usage

  1. if ( !function_exists( 'wpcf7_rest_delete_contact_form' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7/includes/rest-api.php'; 
  3.  
  4. // The request. 
  5. $request = WP_REST_Request $request; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wpcf7_rest_delete_contact_form($request); 
  9.  

Defined (1)

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

/includes/rest-api.php  
  1. function wpcf7_rest_delete_contact_form( WP_REST_Request $request ) { 
  2. $id = (int) $request->get_param( 'id' ); 
  3. $item = wpcf7_contact_form( $id ); 
  4.  
  5. if ( ! $item ) { 
  6. return new WP_Error( 'wpcf7_not_found',  
  7. __( "The requested contact form was not found.", 'contact-form-7' ),  
  8. array( 'status' => 404 ) ); 
  9.  
  10. if ( ! current_user_can( 'wpcf7_delete_contact_form', $id ) ) { 
  11. return new WP_Error( 'wpcf7_forbidden',  
  12. __( "You are not allowed to access the requested contact form.", 'contact-form-7' ),  
  13. array( 'status' => 403 ) ); 
  14.  
  15. $result = $item->delete(); 
  16.  
  17. if ( ! $result ) { 
  18. return new WP_Error( 'wpcf7_cannot_delete',  
  19. __( "There was anerrordeleting the contact form.", 'contact-form-7' ),  
  20. array( 'status' => 500 ) ); 
  21.  
  22. $response = array( 'deleted' => true ); 
  23.  
  24. return rest_ensure_response( $response );