WPCF7_ContactFormTemplate

The Contact Form 7 WPCF7 ContactFormTemplate class.

Defined (1)

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

/includes/contact-form-template.php  
  1. class WPCF7_ContactFormTemplate { 
  2.  
  3. public static function get_default( $prop = 'form' ) { 
  4. if ( 'form' == $prop ) { 
  5. $template = self::form(); 
  6. } elseif ( 'mail' == $prop ) { 
  7. $template = self::mail(); 
  8. } elseif ( 'mail_2' == $prop ) { 
  9. $template = self::mail_2(); 
  10. } elseif ( 'messages' == $prop ) { 
  11. $template = self::messages(); 
  12. } else { 
  13. $template = null; 
  14.  
  15. return apply_filters( 'wpcf7_default_template', $template, $prop ); 
  16.  
  17. public static function form() { 
  18. $template = sprintf( 
  19. <label> %2$s %1$s 
  20. [text* your-name] </label> 
  21.  
  22. <label> %3$s %1$s 
  23. [email* your-email] </label> 
  24.  
  25. <label> %4$s 
  26. [text your-subject] </label> 
  27.  
  28. <label> %5$s 
  29. [textarea your-message] </label> 
  30.  
  31. [submit "%6$s"]',  
  32. __( '(required)', 'contact-form-7' ),  
  33. __( 'Your Name', 'contact-form-7' ),  
  34. __( 'Your Email', 'contact-form-7' ),  
  35. __( 'Subject', 'contact-form-7' ),  
  36. __( 'Your Message', 'contact-form-7' ),  
  37. __( 'Send', 'contact-form-7' ) ); 
  38.  
  39. return trim( $template ); 
  40.  
  41. public static function mail() { 
  42. $template = array( 
  43. 'subject' => sprintf( 
  44. _x( '%1$s "%2$s"', 'mail subject', 'contact-form-7' ),  
  45. get_bloginfo( 'name' ), '[your-subject]' ),  
  46. 'sender' => sprintf( '[your-name] <%s>', self::from_email() ),  
  47. 'body' => 
  48. sprintf( __( 'From: %s', 'contact-form-7' ),  
  49. '[your-name] <[your-email]>' ) . "\n" 
  50. . sprintf( __( 'Subject: %s', 'contact-form-7' ),  
  51. '[your-subject]' ) . "\n\n" 
  52. . __( 'Message Body:', 'contact-form-7' ) 
  53. . "\n" . '[your-message]' . "\n\n" 
  54. . '-- ' . "\n" 
  55. . sprintf( __( 'This e-mail was sent from a contact form on %1$s (%2$s)',  
  56. 'contact-form-7' ), get_bloginfo( 'name' ), get_bloginfo( 'url' ) ),  
  57. 'recipient' => get_option( 'admin_email' ),  
  58. 'additional_headers' => 'Reply-To: [your-email]',  
  59. 'attachments' => '',  
  60. 'use_html' => 0,  
  61. 'exclude_blank' => 0,  
  62. ); 
  63.  
  64. return $template; 
  65.  
  66. public static function mail_2() { 
  67. $template = array( 
  68. 'active' => false,  
  69. 'subject' => sprintf( 
  70. _x( '%1$s "%2$s"', 'mail subject', 'contact-form-7' ),  
  71. get_bloginfo( 'name' ), '[your-subject]' ),  
  72. 'sender' => sprintf( '%s <%s>',  
  73. get_bloginfo( 'name' ), self::from_email() ),  
  74. 'body' => 
  75. __( 'Message Body:', 'contact-form-7' ) 
  76. . "\n" . '[your-message]' . "\n\n" 
  77. . '-- ' . "\n" 
  78. . sprintf( __( 'This e-mail was sent from a contact form on %1$s (%2$s)',  
  79. 'contact-form-7' ), get_bloginfo( 'name' ), get_bloginfo( 'url' ) ),  
  80. 'recipient' => '[your-email]',  
  81. 'additional_headers' => sprintf( 'Reply-To: %s',  
  82. get_option( 'admin_email' ) ),  
  83. 'attachments' => '',  
  84. 'use_html' => 0,  
  85. 'exclude_blank' => 0,  
  86. ); 
  87.  
  88. return $template; 
  89.  
  90. public static function from_email() { 
  91. $admin_email = get_option( 'admin_email' ); 
  92. $sitename = strtolower( $_SERVER['SERVER_NAME'] ); 
  93.  
  94. if ( wpcf7_is_localhost() ) { 
  95. return $admin_email; 
  96.  
  97. if ( substr( $sitename, 0, 4 ) == 'www.' ) { 
  98. $sitename = substr( $sitename, 4 ); 
  99.  
  100. if ( strpbrk( $admin_email, '@' ) == '@' . $sitename ) { 
  101. return $admin_email; 
  102.  
  103. return 'wordpress@' . $sitename; 
  104.  
  105. public static function messages() { 
  106. $messages = array(); 
  107.  
  108. foreach ( wpcf7_messages() as $key => $arr ) { 
  109. $messages[$key] = $arr['default']; 
  110.  
  111. return $messages;