wpcf7_rest_get_contact_form

The Contact Form 7 wpcf7 rest get contact form function.

Description

wpcf7_rest_get_contact_form( WP_REST_Request $request ); 

Parameters (1)

0. $request
The request.

Usage

  1. if ( !function_exists( 'wpcf7_rest_get_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_get_contact_form($request); 
  9.  

Defined (1)

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

/includes/rest-api.php  
  1. function wpcf7_rest_get_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_edit_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. $response = array( 
  16. 'id' => $item->id(),  
  17. 'slug' => $item->name(),  
  18. 'title' => $item->title(),  
  19. 'locale' => $item->locale(),  
  20. 'properties' => $item->get_properties(),  
  21. ); 
  22.  
  23. return rest_ensure_response( $response );