| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugin Name: Contact Form 7 Database Lite |
| 4 |
* Plugin URI: http://ninjateam.org |
| 5 |
* Description: Contact Form 7 Database is a plugin for WordPress allows you save all submitted from contact form 7 to database and display in Contact > Database menu |
| 6 |
* Version: 3.0.6 |
| 7 |
* Author: NinjaTeam |
| 8 |
* Author URI: http://ninjateam.org |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit( 'Direct\'s not allowed' ); |
| 13 |
} |
| 14 |
|
| 15 |
if ( function_exists( 'wpcf7db_plugin_init' ) ) { |
| 16 |
require_once plugin_dir_path( __FILE__ ) . 'admin/Fallback.php'; |
| 17 |
add_action( |
| 18 |
'admin_init', |
| 19 |
function() { |
| 20 |
deactivate_plugins( plugin_basename( __FILE__ ) ); |
| 21 |
} |
| 22 |
); |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
if ( ! defined( 'CF7D_PREFIX' ) ) { |
| 27 |
define( 'CF7D_PREFIX', 'cf7-database' ); |
| 28 |
} |
| 29 |
if ( ! defined( 'CF7D_FILE' ) ) { |
| 30 |
define( 'CF7D_FILE', __FILE__ ); |
| 31 |
} |
| 32 |
if ( ! defined( 'CF7D_PLUGIN_DIR' ) ) { |
| 33 |
define( 'CF7D_PLUGIN_DIR', dirname( __FILE__ ) ); |
| 34 |
} |
| 35 |
if ( ! defined( 'CF7D_PLUGIN_URL' ) ) { |
| 36 |
define( 'CF7D_PLUGIN_URL', plugins_url( '', __FILE__ ) ); |
| 37 |
} |
| 38 |
if ( ! defined( 'CF7D_PLUGIN_PATH' ) ) { |
| 39 |
define( 'CF7D_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); |
| 40 |
} |
| 41 |
if ( ! defined( 'CF7D_PLUGIN_BASENAME' ) ) { |
| 42 |
define( 'CF7D_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 43 |
} |
| 44 |
|
| 45 |
if ( ! function_exists( 'wpcf7db_plugin_init' ) ) { |
| 46 |
function wpcf7db_plugin_init() { |
| 47 |
require_once CF7D_PLUGIN_DIR . '/functions.php'; |
| 48 |
require_once CF7D_PLUGIN_DIR . '/frontend/init.php'; |
| 49 |
require_once CF7D_PLUGIN_DIR . '/frontend/save-files.php'; |
| 50 |
|
| 51 |
require_once CF7D_PLUGIN_DIR . '/admin/I18n.php'; |
| 52 |
require_once CF7D_PLUGIN_DIR . '/admin/init.php'; |
| 53 |
require_once CF7D_PLUGIN_DIR . '/admin/Helper.php'; |
| 54 |
require_once CF7D_PLUGIN_DIR . '/admin/Ajax.php'; |
| 55 |
require_once CF7D_PLUGIN_DIR . '/admin/unique-id.php'; |
| 56 |
} |
| 57 |
} |
| 58 |
add_action( 'plugins_loaded', 'wpcf7db_plugin_init' ); |
| 59 |
/* |
| 60 |
* Creating tables when plugin is actived |
| 61 |
*/ |
| 62 |
if ( ! function_exists( 'cf7d_table_func' ) ) { |
| 63 |
function cf7d_table_func() { |
| 64 |
global $wpdb; |
| 65 |
$charset_collate = $wpdb->get_charset_collate(); |
| 66 |
$cf7d_table = $wpdb->prefix . 'cf7_data'; |
| 67 |
if ( $wpdb->get_var( "show tables like '$cf7d_table'" ) != $cf7d_table ) { |
| 68 |
$sql = 'CREATE TABLE ' . $cf7d_table . ' ( |
| 69 |
`id` int(11) NOT NULL AUTO_INCREMENT, |
| 70 |
`created` timestamp NOT NULL, |
| 71 |
UNIQUE KEY id (id) |
| 72 |
) ' . $charset_collate . ';'; |
| 73 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 74 |
dbDelta( $sql ); |
| 75 |
} |
| 76 |
|
| 77 |
$cf7d_table_entry = $wpdb->prefix . 'cf7_data_entry'; |
| 78 |
if ( $wpdb->get_var( "show tables like '$cf7d_table_entry'" ) != $cf7d_table_entry ) { |
| 79 |
$sql = 'CREATE TABLE ' . $cf7d_table_entry . ' ( |
| 80 |
`id` int(11) NOT NULL AUTO_INCREMENT, |
| 81 |
`cf7_id` int(11) NOT NULL, |
| 82 |
`data_id` int(11) NOT NULL, |
| 83 |
`name` varchar(250), |
| 84 |
`value` text, |
| 85 |
UNIQUE KEY id (id) |
| 86 |
) ' . $charset_collate . ';'; |
| 87 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 88 |
dbDelta( $sql ); |
| 89 |
} else { |
| 90 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 91 |
|
| 92 |
maybe_convert_table_to_utf8mb4( $cf7d_table_entry ); |
| 93 |
$sql = 'ALTER TABLE ' . $cf7d_table_entry . ' change name name VARCHAR(250) character set utf8, change value value text character set utf8;'; |
| 94 |
$wpdb->query( $sql ); |
| 95 |
|
| 96 |
// remove fields cf7mls_step-1... in database for version old. |
| 97 |
// cf7mls_step-1, cf7mls_step-2... by plugin contact form 7 multi step pro. |
| 98 |
$wpdb->query( "DELETE FROM $cf7d_table_entry WHERE `name` LIKE 'cf7mls_step-%'" ); |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
register_activation_hook( CF7D_FILE, 'cf7d_table_func' ); |
| 103 |
|
| 104 |
|
| 105 |
|