settings.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. require_once WPCF7_PLUGIN_DIR . '/includes/functions.php';
  3. require_once WPCF7_PLUGIN_DIR . '/includes/l10n.php';
  4. require_once WPCF7_PLUGIN_DIR . '/includes/formatting.php';
  5. require_once WPCF7_PLUGIN_DIR . '/includes/pipe.php';
  6. require_once WPCF7_PLUGIN_DIR . '/includes/form-tag.php';
  7. require_once WPCF7_PLUGIN_DIR . '/includes/form-tags-manager.php';
  8. require_once WPCF7_PLUGIN_DIR . '/includes/shortcodes.php';
  9. require_once WPCF7_PLUGIN_DIR . '/includes/capabilities.php';
  10. require_once WPCF7_PLUGIN_DIR . '/includes/contact-form-template.php';
  11. require_once WPCF7_PLUGIN_DIR . '/includes/contact-form.php';
  12. require_once WPCF7_PLUGIN_DIR . '/includes/contact-form-functions.php';
  13. require_once WPCF7_PLUGIN_DIR . '/includes/mail.php';
  14. require_once WPCF7_PLUGIN_DIR . '/includes/special-mail-tags.php';
  15. require_once WPCF7_PLUGIN_DIR . '/includes/submission.php';
  16. require_once WPCF7_PLUGIN_DIR . '/includes/upgrade.php';
  17. require_once WPCF7_PLUGIN_DIR . '/includes/integration.php';
  18. require_once WPCF7_PLUGIN_DIR . '/includes/config-validator.php';
  19. require_once WPCF7_PLUGIN_DIR . '/includes/rest-api.php';
  20. if ( is_admin() ) {
  21. require_once WPCF7_PLUGIN_DIR . '/admin/admin.php';
  22. } else {
  23. require_once WPCF7_PLUGIN_DIR . '/includes/controller.php';
  24. }
  25. class WPCF7 {
  26. public static function load_modules() {
  27. self::load_module( 'acceptance' );
  28. self::load_module( 'akismet' );
  29. self::load_module( 'checkbox' );
  30. self::load_module( 'constant-contact' );
  31. self::load_module( 'count' );
  32. self::load_module( 'date' );
  33. self::load_module( 'file' );
  34. self::load_module( 'flamingo' );
  35. self::load_module( 'hidden' );
  36. self::load_module( 'listo' );
  37. self::load_module( 'number' );
  38. self::load_module( 'quiz' );
  39. self::load_module( 'really-simple-captcha' );
  40. self::load_module( 'recaptcha' );
  41. self::load_module( 'response' );
  42. self::load_module( 'select' );
  43. self::load_module( 'submit' );
  44. self::load_module( 'text' );
  45. self::load_module( 'textarea' );
  46. }
  47. protected static function load_module( $mod ) {
  48. $dir = WPCF7_PLUGIN_MODULES_DIR;
  49. if ( empty( $dir ) or ! is_dir( $dir ) ) {
  50. return false;
  51. }
  52. $file = path_join( $dir, $mod . '.php' );
  53. if ( file_exists( $file ) ) {
  54. include_once $file;
  55. }
  56. }
  57. public static function get_option( $name, $default = false ) {
  58. $option = get_option( 'wpcf7' );
  59. if ( false === $option ) {
  60. return $default;
  61. }
  62. if ( isset( $option[$name] ) ) {
  63. return $option[$name];
  64. } else {
  65. return $default;
  66. }
  67. }
  68. public static function update_option( $name, $value ) {
  69. $option = get_option( 'wpcf7' );
  70. $option = ( false === $option ) ? array() : (array) $option;
  71. $option = array_merge( $option, array( $name => $value ) );
  72. update_option( 'wpcf7', $option );
  73. }
  74. }
  75. add_action( 'plugins_loaded', 'wpcf7', 10, 0 );
  76. function wpcf7() {
  77. wpcf7_load_textdomain();
  78. WPCF7::load_modules();
  79. /* Shortcodes */
  80. add_shortcode( 'contact-form-7', 'wpcf7_contact_form_tag_func' );
  81. add_shortcode( 'contact-form', 'wpcf7_contact_form_tag_func' );
  82. }
  83. add_action( 'init', 'wpcf7_init', 10, 0 );
  84. function wpcf7_init() {
  85. wpcf7_get_request_uri();
  86. wpcf7_register_post_types();
  87. do_action( 'wpcf7_init' );
  88. }
  89. add_action( 'admin_init', 'wpcf7_upgrade', 10, 0 );
  90. function wpcf7_upgrade() {
  91. $old_ver = WPCF7::get_option( 'version', '0' );
  92. $new_ver = WPCF7_VERSION;
  93. if ( $old_ver == $new_ver ) {
  94. return;
  95. }
  96. do_action( 'wpcf7_upgrade', $new_ver, $old_ver );
  97. WPCF7::update_option( 'version', $new_ver );
  98. }
  99. /* Install and default settings */
  100. add_action( 'activate_' . WPCF7_PLUGIN_BASENAME, 'wpcf7_install', 10, 0 );
  101. function wpcf7_install() {
  102. if ( $opt = get_option( 'wpcf7' ) ) {
  103. return;
  104. }
  105. wpcf7_load_textdomain();
  106. wpcf7_register_post_types();
  107. wpcf7_upgrade();
  108. if ( get_posts( array( 'post_type' => 'wpcf7_contact_form' ) ) ) {
  109. return;
  110. }
  111. $contact_form = WPCF7_ContactForm::get_template(
  112. array(
  113. 'title' =>
  114. /* translators: title of your first contact form. %d: number fixed to '1' */
  115. sprintf( __( 'Contact form %d', 'contact-form-7' ), 1 ),
  116. )
  117. );
  118. $contact_form->save();
  119. WPCF7::update_option( 'bulk_validate',
  120. array(
  121. 'timestamp' => current_time( 'timestamp' ),
  122. 'version' => WPCF7_VERSION,
  123. 'count_valid' => 1,
  124. 'count_invalid' => 0,
  125. )
  126. );
  127. }