wpcf7_rest_create_contact_form

The Contact Form 7 wpcf7 rest create contact form function.

Description

wpcf7_rest_create_contact_form( WP_REST_Request $request ); 

Parameters (1)

0. $request
The request.

Usage

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

Defined (1)

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

/includes/rest-api.php  
  1. function wpcf7_rest_create_contact_form( WP_REST_Request $request ) { 
  2. $id = (int) $request->get_param( 'id' ); 
  3.  
  4. if ( $id ) { 
  5. return new WP_Error( 'wpcf7_post_exists',  
  6. __( "Cannot create existing contact form.", 'contact-form-7' ),  
  7. array( 'status' => 400 ) ); 
  8.  
  9. if ( ! current_user_can( 'wpcf7_edit_contact_forms' ) ) { 
  10. return new WP_Error( 'wpcf7_forbidden',  
  11. __( "You are not allowed to create a contact form.", 'contact-form-7' ),  
  12. array( 'status' => 403 ) ); 
  13.  
  14. $args = $request->get_params(); 
  15. $args['id'] = -1; // Create 
  16. $context = $request->get_param( 'context' ); 
  17. $item = wpcf7_save_contact_form( $args, $context ); 
  18.  
  19. if ( ! $item ) { 
  20. return new WP_Error( 'wpcf7_cannot_save',  
  21. __( "There was anerrorsaving the contact form.", 'contact-form-7' ),  
  22. array( 'status' => 500 ) ); 
  23.  
  24. $response = array( 
  25. 'id' => $item->id(),  
  26. 'slug' => $item->name(),  
  27. 'title' => $item->title(),  
  28. 'locale' => $item->locale(),  
  29. 'properties' => $item->get_properties(),  
  30. 'config_errors' => array(),  
  31. ); 
  32.  
  33. $config_validator = new WPCF7_ConfigValidator( $item ); 
  34. $config_validator->validate(); 
  35.  
  36. $response['config_errors'] = $config_validator->collect_error_messages(); 
  37.  
  38. if ( 'save' == $context ) { 
  39. $config_validator->save(); 
  40.  
  41. return rest_ensure_response( $response );