contact-form-template.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. class WPCF7_ContactFormTemplate {
  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. '
  20. <label> %2$s %1$s
  21. [text* your-name] </label>
  22. <label> %3$s %1$s
  23. [email* your-email] </label>
  24. <label> %4$s
  25. [text your-subject] </label>
  26. <label> %5$s
  27. [textarea your-message] </label>
  28. [submit "%6$s"]',
  29. __( '(required)', 'contact-form-7' ),
  30. __( 'Your Name', 'contact-form-7' ),
  31. __( 'Your Email', 'contact-form-7' ),
  32. __( 'Subject', 'contact-form-7' ),
  33. __( 'Your Message', 'contact-form-7' ),
  34. __( 'Send', 'contact-form-7' ) );
  35. return trim( $template );
  36. }
  37. public static function mail() {
  38. $template = array(
  39. 'subject' =>
  40. sprintf(
  41. /* translators: 1: blog name, 2: [your-subject] */
  42. _x( '%1$s "%2$s"', 'mail subject', 'contact-form-7' ),
  43. get_bloginfo( 'name' ),
  44. '[your-subject]'
  45. ),
  46. 'sender' => sprintf( '%s <%s>',
  47. get_bloginfo( 'name' ), self::from_email() ),
  48. 'body' =>
  49. /* translators: %s: [your-name] <[your-email]> */
  50. sprintf( __( 'From: %s', 'contact-form-7' ),
  51. '[your-name] <[your-email]>' ) . "\n"
  52. /* translators: %s: [your-subject] */
  53. . sprintf( __( 'Subject: %s', 'contact-form-7' ),
  54. '[your-subject]' ) . "\n\n"
  55. . __( 'Message Body:', 'contact-form-7' )
  56. . "\n" . '[your-message]' . "\n\n"
  57. . '-- ' . "\n"
  58. . sprintf(
  59. /* translators: 1: blog name, 2: blog URL */
  60. __( 'This e-mail was sent from a contact form on %1$s (%2$s)', 'contact-form-7' ),
  61. get_bloginfo( 'name' ),
  62. get_bloginfo( 'url' )
  63. ),
  64. 'recipient' => get_option( 'admin_email' ),
  65. 'additional_headers' => 'Reply-To: [your-email]',
  66. 'attachments' => '',
  67. 'use_html' => 0,
  68. 'exclude_blank' => 0,
  69. );
  70. return $template;
  71. }
  72. public static function mail_2() {
  73. $template = array(
  74. 'active' => false,
  75. 'subject' =>
  76. sprintf(
  77. /* translators: 1: blog name, 2: [your-subject] */
  78. _x( '%1$s "%2$s"', 'mail subject', 'contact-form-7' ),
  79. get_bloginfo( 'name' ),
  80. '[your-subject]'
  81. ),
  82. 'sender' => sprintf( '%s <%s>',
  83. get_bloginfo( 'name' ), self::from_email() ),
  84. 'body' =>
  85. __( 'Message Body:', 'contact-form-7' )
  86. . "\n" . '[your-message]' . "\n\n"
  87. . '-- ' . "\n"
  88. . sprintf(
  89. /* translators: 1: blog name, 2: blog URL */
  90. __( 'This e-mail was sent from a contact form on %1$s (%2$s)', 'contact-form-7' ),
  91. get_bloginfo( 'name' ),
  92. get_bloginfo( 'url' )
  93. ),
  94. 'recipient' => '[your-email]',
  95. 'additional_headers' => sprintf( 'Reply-To: %s',
  96. get_option( 'admin_email' ) ),
  97. 'attachments' => '',
  98. 'use_html' => 0,
  99. 'exclude_blank' => 0,
  100. );
  101. return $template;
  102. }
  103. public static function from_email() {
  104. $admin_email = get_option( 'admin_email' );
  105. $sitename = strtolower( $_SERVER['SERVER_NAME'] );
  106. if ( wpcf7_is_localhost() ) {
  107. return $admin_email;
  108. }
  109. if ( substr( $sitename, 0, 4 ) == 'www.' ) {
  110. $sitename = substr( $sitename, 4 );
  111. }
  112. if ( strpbrk( $admin_email, '@' ) == '@' . $sitename ) {
  113. return $admin_email;
  114. }
  115. return 'wordpress@' . $sitename;
  116. }
  117. public static function messages() {
  118. $messages = array();
  119. foreach ( wpcf7_messages() as $key => $arr ) {
  120. $messages[$key] = $arr['default'];
  121. }
  122. return $messages;
  123. }
  124. }
  125. function wpcf7_messages() {
  126. $messages = array(
  127. 'mail_sent_ok' => array(
  128. 'description'
  129. => __( "Sender's message was sent successfully", 'contact-form-7' ),
  130. 'default'
  131. => __( "Thank you for your message. It has been sent.", 'contact-form-7' ),
  132. ),
  133. 'mail_sent_ng' => array(
  134. 'description'
  135. => __( "Sender's message failed to send", 'contact-form-7' ),
  136. 'default'
  137. => __( "There was an error trying to send your message. Please try again later.", 'contact-form-7' ),
  138. ),
  139. 'validation_error' => array(
  140. 'description'
  141. => __( "Validation errors occurred", 'contact-form-7' ),
  142. 'default'
  143. => __( "One or more fields have an error. Please check and try again.", 'contact-form-7' ),
  144. ),
  145. 'spam' => array(
  146. 'description'
  147. => __( "Submission was referred to as spam", 'contact-form-7' ),
  148. 'default'
  149. => __( "There was an error trying to send your message. Please try again later.", 'contact-form-7' ),
  150. ),
  151. 'accept_terms' => array(
  152. 'description'
  153. => __( "There are terms that the sender must accept", 'contact-form-7' ),
  154. 'default'
  155. => __( "You must accept the terms and conditions before sending your message.", 'contact-form-7' ),
  156. ),
  157. 'invalid_required' => array(
  158. 'description'
  159. => __( "There is a field that the sender must fill in", 'contact-form-7' ),
  160. 'default'
  161. => __( "The field is required.", 'contact-form-7' ),
  162. ),
  163. 'invalid_too_long' => array(
  164. 'description'
  165. => __( "There is a field with input that is longer than the maximum allowed length", 'contact-form-7' ),
  166. 'default'
  167. => __( "The field is too long.", 'contact-form-7' ),
  168. ),
  169. 'invalid_too_short' => array(
  170. 'description'
  171. => __( "There is a field with input that is shorter than the minimum allowed length", 'contact-form-7' ),
  172. 'default'
  173. => __( "The field is too short.", 'contact-form-7' ),
  174. )
  175. );
  176. return apply_filters( 'wpcf7_messages', $messages );
  177. }