/wp-content/plugins/contact-form-7/settings.php

https://bitbucket.org/rossberenson/michael-karas · PHP · 207 lines · 140 code · 62 blank · 5 comment · 22 complexity · aaaa78c2ff882864deed17f3969e1081 MD5 · raw file

  1. <?php
  2. require_once WPCF7_PLUGIN_DIR . '/includes/functions.php';
  3. require_once WPCF7_PLUGIN_DIR . '/includes/deprecated.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/shortcodes.php';
  7. require_once WPCF7_PLUGIN_DIR . '/includes/capabilities.php';
  8. require_once WPCF7_PLUGIN_DIR . '/includes/classes.php';
  9. if ( is_admin() )
  10. require_once WPCF7_PLUGIN_DIR . '/admin/admin.php';
  11. else
  12. require_once WPCF7_PLUGIN_DIR . '/includes/controller.php';
  13. add_action( 'plugins_loaded', 'wpcf7_init_shortcode_manager', 1 );
  14. function wpcf7_init_shortcode_manager() {
  15. global $wpcf7_shortcode_manager;
  16. $wpcf7_shortcode_manager = new WPCF7_ShortcodeManager();
  17. }
  18. /* Loading modules */
  19. add_action( 'plugins_loaded', 'wpcf7_load_modules', 1 );
  20. function wpcf7_load_modules() {
  21. $dir = WPCF7_PLUGIN_MODULES_DIR;
  22. if ( ! ( is_dir( $dir ) && $dh = opendir( $dir ) ) )
  23. return false;
  24. while ( ( $module = readdir( $dh ) ) !== false ) {
  25. if ( substr( $module, -4 ) == '.php' && substr( $module, 0, 1 ) != '.' )
  26. include_once $dir . '/' . $module;
  27. }
  28. }
  29. add_action( 'plugins_loaded', 'wpcf7_set_request_uri', 9 );
  30. function wpcf7_set_request_uri() {
  31. global $wpcf7_request_uri;
  32. $wpcf7_request_uri = add_query_arg( array() );
  33. }
  34. function wpcf7_get_request_uri() {
  35. global $wpcf7_request_uri;
  36. return (string) $wpcf7_request_uri;
  37. }
  38. add_action( 'init', 'wpcf7_init' );
  39. function wpcf7_init() {
  40. wpcf7();
  41. // L10N
  42. wpcf7_load_plugin_textdomain();
  43. // Custom Post Type
  44. wpcf7_register_post_types();
  45. do_action( 'wpcf7_init' );
  46. }
  47. function wpcf7() {
  48. global $wpcf7;
  49. if ( is_object( $wpcf7 ) )
  50. return;
  51. $wpcf7 = (object) array(
  52. 'processing_within' => '',
  53. 'widget_count' => 0,
  54. 'unit_count' => 0,
  55. 'global_unit_count' => 0,
  56. 'result' => array() );
  57. }
  58. function wpcf7_load_plugin_textdomain() {
  59. load_plugin_textdomain( 'wpcf7', false, 'contact-form-7/languages' );
  60. }
  61. function wpcf7_register_post_types() {
  62. WPCF7_ContactForm::register_post_type();
  63. }
  64. /* Upgrading */
  65. add_action( 'admin_init', 'wpcf7_upgrade' );
  66. function wpcf7_upgrade() {
  67. $opt = get_option( 'wpcf7' );
  68. if ( ! is_array( $opt ) )
  69. $opt = array();
  70. $old_ver = isset( $opt['version'] ) ? (string) $opt['version'] : '0';
  71. $new_ver = WPCF7_VERSION;
  72. if ( $old_ver == $new_ver )
  73. return;
  74. do_action( 'wpcf7_upgrade', $new_ver, $old_ver );
  75. $opt['version'] = $new_ver;
  76. update_option( 'wpcf7', $opt );
  77. }
  78. add_action( 'wpcf7_upgrade', 'wpcf7_convert_to_cpt', 10, 2 );
  79. function wpcf7_convert_to_cpt( $new_ver, $old_ver ) {
  80. global $wpdb;
  81. if ( ! version_compare( $old_ver, '3.0-dev', '<' ) )
  82. return;
  83. $old_rows = array();
  84. $table_name = $wpdb->prefix . "contact_form_7";
  85. if ( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) ) {
  86. $old_rows = $wpdb->get_results( "SELECT * FROM $table_name" );
  87. } elseif ( ( $opt = get_option( 'wpcf7' ) ) && ! empty( $opt['contact_forms'] ) ) {
  88. foreach ( (array) $opt['contact_forms'] as $key => $value ) {
  89. $old_rows[] = (object) array_merge( $value, array( 'cf7_unit_id' => $key ) );
  90. }
  91. }
  92. foreach ( (array) $old_rows as $row ) {
  93. $q = "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_old_cf7_unit_id'"
  94. . $wpdb->prepare( " AND meta_value = %d", $row->cf7_unit_id );
  95. if ( $wpdb->get_var( $q ) )
  96. continue;
  97. $postarr = array(
  98. 'post_type' => 'wpcf7_contact_form',
  99. 'post_status' => 'publish',
  100. 'post_title' => maybe_unserialize( $row->title ) );
  101. $post_id = wp_insert_post( $postarr );
  102. if ( $post_id ) {
  103. update_post_meta( $post_id, '_old_cf7_unit_id', $row->cf7_unit_id );
  104. $metas = array( 'form', 'mail', 'mail_2', 'messages', 'additional_settings' );
  105. foreach ( $metas as $meta ) {
  106. update_post_meta( $post_id, '_' . $meta,
  107. wpcf7_normalize_newline_deep( maybe_unserialize( $row->{$meta} ) ) );
  108. }
  109. }
  110. }
  111. }
  112. add_action( 'wpcf7_upgrade', 'wpcf7_prepend_underscore', 10, 2 );
  113. function wpcf7_prepend_underscore( $new_ver, $old_ver ) {
  114. if ( version_compare( $old_ver, '3.0-dev', '<' ) )
  115. return;
  116. if ( ! version_compare( $old_ver, '3.3-dev', '<' ) )
  117. return;
  118. $posts = WPCF7_ContactForm::find( array(
  119. 'post_status' => 'any',
  120. 'posts_per_page' => -1 ) );
  121. foreach ( $posts as $post ) {
  122. $props = $post->get_properties();
  123. foreach ( $props as $prop => $value ) {
  124. if ( metadata_exists( 'post', $post->id, '_' . $prop ) )
  125. continue;
  126. update_post_meta( $post->id, '_' . $prop, $value );
  127. delete_post_meta( $post->id, $prop );
  128. }
  129. }
  130. }
  131. /* Install and default settings */
  132. add_action( 'activate_' . WPCF7_PLUGIN_BASENAME, 'wpcf7_install' );
  133. function wpcf7_install() {
  134. if ( $opt = get_option( 'wpcf7' ) )
  135. return;
  136. wpcf7_load_plugin_textdomain();
  137. wpcf7_register_post_types();
  138. wpcf7_upgrade();
  139. if ( get_posts( array( 'post_type' => 'wpcf7_contact_form' ) ) )
  140. return;
  141. $contact_form = wpcf7_get_contact_form_default_pack(
  142. array( 'title' => sprintf( __( 'Contact form %d', 'wpcf7' ), 1 ) ) );
  143. $contact_form->save();
  144. }
  145. ?>