sovetit

Custom message from Contact Form 7 for acceptance

Oct 24th, 2020 (edited)
413
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###############################
  2. ### Paste in functions.php ###
  3. #############################
  4.  
  5. /**
  6.  * Custom message from Contact Form 7 for acceptance
  7.  * @link https://pastebin.com/4nsdh9Fk
  8.  * @see my_wpcf7_form_acceptance
  9.  * @param $replaced
  10.  * @param $submitted
  11.  * @param $html
  12.  * @param $mail_tag
  13.  * @return string
  14.  */
  15. function my_wpcf7_form_acceptance( $replaced, $submitted, $html, $mail_tag ) {
  16.  
  17.     $form_tag = $mail_tag->corresponding_form_tag();
  18.     if ( ! $form_tag ) {
  19.         return $replaced;
  20.     }
  21.  
  22.     /** My translation */
  23.     if ( ! empty( $submitted ) ) {
  24.         $replaced = 'Checked';
  25.     } else {
  26.         $replaced = 'Not checked';
  27.     }
  28.  
  29.     $content = empty( $form_tag->content )
  30.         ? (string) reset( $form_tag->values )
  31.         : $form_tag->content;
  32.  
  33.     if ( ! $html ) {
  34.         $content = wp_strip_all_tags( $content );
  35.     }
  36.  
  37.     $content = trim( $content );
  38.     if ( $content ) {
  39.         $replaced = sprintf( '%1$s: %2$s', $replaced, $content );
  40.     }
  41.  
  42.     return $replaced;
  43. }
  44. add_filter( 'wpcf7_mail_tag_replaced_acceptance', 'my_wpcf7_form_acceptance', 10, 4 );
RAW Paste Data