| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugin Name: Contact Form 7 Database Lite |
| 4 |
* Plugin URI: https://ninjateam.org/contact-form-7-database/ |
| 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.9 |
| 7 |
* Author: NinjaTeam |
| 8 |
* Author URI: http://ninjateam.org |
| 9 |
* Text Domain: cf7-database |
| 10 |
* Domain Path: /i18n/languages |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit( 'Direct\'s not allowed' ); |
| 15 |
} |
| 16 |
|
| 17 |
if ( function_exists( 'wpcf7db_plugin_init' ) ) { |
| 18 |
require_once plugin_dir_path( __FILE__ ) . 'admin/Fallback.php'; |
| 19 |
add_action( |
| 20 |
'admin_init', |
| 21 |
function() { |
| 22 |
deactivate_plugins( plugin_basename( __FILE__ ) ); |
| 23 |
} |
| 24 |
); |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
if ( ! defined( 'CF7D_VERSION' ) ) { |
| 29 |
define( 'CF7D_VERSION', '3.0.9' ); |
| 30 |
} |
| 31 |
|
| 32 |
if ( ! defined( 'CF7D_PREFIX' ) ) { |
| 33 |
define( 'CF7D_PREFIX', 'cf7-database' ); |
| 34 |
} |
| 35 |
if ( ! defined( 'CF7D_FILE' ) ) { |
| 36 |
define( 'CF7D_FILE', __FILE__ ); |
| 37 |
} |
| 38 |
if ( ! defined( 'CF7D_PLUGIN_DIR' ) ) { |
| 39 |
define( 'CF7D_PLUGIN_DIR', dirname( __FILE__ ) ); |
| 40 |
} |
| 41 |
if ( ! defined( 'CF7D_PLUGIN_URL' ) ) { |
| 42 |
define( 'CF7D_PLUGIN_URL', plugins_url( '', __FILE__ ) ); |
| 43 |
} |
| 44 |
if ( ! defined( 'CF7D_PLUGIN_PATH' ) ) { |
| 45 |
define( 'CF7D_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); |
| 46 |
} |
| 47 |
if ( ! defined( 'CF7D_PLUGIN_BASENAME' ) ) { |
| 48 |
define( 'CF7D_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 49 |
} |
| 50 |
|
| 51 |
if ( ! function_exists( 'wpcf7db_plugin_init' ) ) { |
| 52 |
function wpcf7db_plugin_init() { |
| 53 |
if ( ! class_exists( 'WPCF7' ) ) { |
| 54 |
add_action( 'admin_notices', function() { |
| 55 |
?> |
| 56 |
<div class="notice notice-error"> |
| 57 |
<p> |
| 58 |
<?php |
| 59 |
printf( |
| 60 |
/* translators: 1: Contact Form 7, 2: Contact Form 7 Database */ |
| 61 |
esc_html__( 'Please activate %1$s to use %2$s.', 'cf7-database' ), |
| 62 |
'<strong>Contact Form 7</strong>', |
| 63 |
'<strong>Contact Form 7 Database</strong>' |
| 64 |
); |
| 65 |
?> |
| 66 |
</p> |
| 67 |
</div> |
| 68 |
<?php |
| 69 |
} ); |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
require_once CF7D_PLUGIN_DIR . '/functions.php'; |
| 74 |
require_once CF7D_PLUGIN_DIR . '/frontend/init.php'; |
| 75 |
require_once CF7D_PLUGIN_DIR . '/frontend/save-files.php'; |
| 76 |
|
| 77 |
require_once CF7D_PLUGIN_DIR . '/admin/I18n.php'; |
| 78 |
require_once CF7D_PLUGIN_DIR . '/admin/init.php'; |
| 79 |
require_once CF7D_PLUGIN_DIR . '/admin/Helper.php'; |
| 80 |
require_once CF7D_PLUGIN_DIR . '/admin/Ajax.php'; |
| 81 |
require_once CF7D_PLUGIN_DIR . '/admin/unique-id.php'; |
| 82 |
} |
| 83 |
} |
| 84 |
add_action( 'plugins_loaded', 'wpcf7db_plugin_init' ); |
| 85 |
/* |
| 86 |
* Creating tables when plugin is actived |
| 87 |
*/ |
| 88 |
if ( ! function_exists( 'cf7d_table_func' ) ) { |
| 89 |
function cf7d_table_func() { |
| 90 |
global $wpdb; |
| 91 |
$charset_collate = $wpdb->get_charset_collate(); |
| 92 |
$cf7d_table = $wpdb->prefix . 'cf7_data'; |
| 93 |
if ( $wpdb->get_var( "show tables like '$cf7d_table'" ) != $cf7d_table ) { |
| 94 |
$sql = 'CREATE TABLE ' . $cf7d_table . ' ( |
| 95 |
`id` int(11) NOT NULL AUTO_INCREMENT, |
| 96 |
`created` timestamp NOT NULL, |
| 97 |
UNIQUE KEY id (id) |
| 98 |
) ' . $charset_collate . ';'; |
| 99 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 100 |
dbDelta( $sql ); |
| 101 |
} |
| 102 |
|
| 103 |
$cf7d_table_entry = $wpdb->prefix . 'cf7_data_entry'; |
| 104 |
if ( $wpdb->get_var( "show tables like '$cf7d_table_entry'" ) != $cf7d_table_entry ) { |
| 105 |
$sql = 'CREATE TABLE ' . $cf7d_table_entry . ' ( |
| 106 |
`id` int(11) NOT NULL AUTO_INCREMENT, |
| 107 |
`cf7_id` int(11) NOT NULL, |
| 108 |
`data_id` int(11) NOT NULL, |
| 109 |
`name` varchar(250), |
| 110 |
`value` text, |
| 111 |
UNIQUE KEY id (id) |
| 112 |
) ' . $charset_collate . ';'; |
| 113 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 114 |
dbDelta( $sql ); |
| 115 |
} else { |
| 116 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 117 |
|
| 118 |
maybe_convert_table_to_utf8mb4( $cf7d_table_entry ); |
| 119 |
$sql = 'ALTER TABLE ' . $cf7d_table_entry . ' change name name VARCHAR(250) character set utf8, change value value text character set utf8;'; |
| 120 |
$wpdb->query( $sql ); |
| 121 |
|
| 122 |
// remove fields cf7mls_step-1... in database for version old. |
| 123 |
// cf7mls_step-1, cf7mls_step-2... by plugin contact form 7 multi step pro. |
| 124 |
$wpdb->query( "DELETE FROM $cf7d_table_entry WHERE `name` LIKE 'cf7mls_step-%'" ); |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
register_activation_hook( CF7D_FILE, 'cf7d_table_func' ); |
| 129 |
|
| 130 |
|
| 131 |
|