wpcf7_save_contact_form

The Contact Form 7 wpcf7 save contact form function.

Description

wpcf7_save_contact_form( (string) $args = '', (string) $context = 'save' ); 

Parameters (2)

0. $args — Optional. (string) => ''
The args.
1. $context — Optional. (string) => 'save'
The context.

Usage

  1. if ( !function_exists( 'wpcf7_save_contact_form' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7/includes/contact-form-functions.php'; 
  3.  
  4. // The args. 
  5. $args = ''; 
  6.  
  7. // The context. 
  8. $context = 'save'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wpcf7_save_contact_form($args, $context); 
  12.  

Defined (1)

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

/includes/contact-form-functions.php  
  1. function wpcf7_save_contact_form( $args = '', $context = 'save' ) { 
  2. $args = wp_parse_args( $args, array( 
  3. 'id' => -1,  
  4. 'title' => null,  
  5. 'locale' => null,  
  6. 'form' => null,  
  7. 'mail' => null,  
  8. 'mail_2' => null,  
  9. 'messages' => null,  
  10. 'additional_settings' => null,  
  11. ) ); 
  12.  
  13. $args['id'] = (int) $args['id']; 
  14.  
  15. if ( -1 == $args['id'] ) { 
  16. $contact_form = WPCF7_ContactForm::get_template(); 
  17. } else { 
  18. $contact_form = wpcf7_contact_form( $args['id'] ); 
  19.  
  20. if ( empty( $contact_form ) ) { 
  21. return false; 
  22.  
  23. if ( null !== $args['title'] ) { 
  24. $contact_form->set_title( $args['title'] ); 
  25.  
  26. if ( null !== $args['locale'] ) { 
  27. $contact_form->set_locale( $args['locale'] ); 
  28.  
  29. $properties = $contact_form->get_properties(); 
  30.  
  31. $properties['form'] = wpcf7_sanitize_form
  32. $args['form'], $properties['form'] ); 
  33.  
  34. $properties['mail'] = wpcf7_sanitize_mail
  35. $args['mail'], $properties['mail'] ); 
  36.  
  37. $properties['mail']['active'] = true; 
  38.  
  39. $properties['mail_2'] = wpcf7_sanitize_mail
  40. $args['mail_2'], $properties['mail_2'] ); 
  41.  
  42. $properties['messages'] = wpcf7_sanitize_messages
  43. $args['messages'], $properties['messages'] ); 
  44.  
  45. $properties['additional_settings'] = wpcf7_sanitize_additional_settings
  46. $args['additional_settings'], $properties['additional_settings'] ); 
  47.  
  48. $contact_form->set_properties( $properties ); 
  49.  
  50. do_action( 'wpcf7_save_contact_form', $contact_form, $args, $context ); 
  51.  
  52. if ( 'save' == $context ) { 
  53. $contact_form->save(); 
  54.  
  55. return $contact_form;