| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
/** |
| 8 |
* Dependencies |
| 9 |
*/ |
| 10 |
require_once('core/Messages.class.php'); |
| 11 |
require_once('core/Ajax.class.php'); |
| 12 |
require_once('core/Compatibility.class.php'); |
| 13 |
require_once('core/CleanUp.class.php'); |
| 14 |
require_once('core/HTMLSelect.class.php'); |
| 15 |
require_once('core/UI.class.php'); |
| 16 |
require_once('core/UIPage.class.php'); |
| 17 |
require_once('core/UIPageForm.class.php'); |
| 18 |
require_once('core/OptIn.class.php'); |
| 19 |
require_once('core/OptInLimitFilter.class.php'); |
| 20 |
require_once('core/OptInSearchFilter.class.php'); |
| 21 |
require_once('core/Category.class.php'); |
| 22 |
require_once('core/CategoryOptions.class.php'); |
| 23 |
require_once('core/Pagination.class.php'); |
| 24 |
require_once('core/Support.class.php'); |
| 25 |
|
| 26 |
/** |
| 27 |
* Plugin Name: Double Opt-In (Contact Form 7, Avada) - GDPR Ready |
| 28 |
* Plugin URI: https://www.forge12.com/blog/so-verwendest-du-das-double-opt-in-fuer-contact-form-7/ |
| 29 |
* Description: This plugin allows you to add a double OptIn System to your Contact Form 7 & Avada Forms. |
| 30 |
* Text Domain: double-opt-in |
| 31 |
* Domain Path: /languages |
| 32 |
* Version: 2.12 |
| 33 |
* Author: Forge12 Interactive GmbH |
| 34 |
* Author URI: https://www.forge12.com |
| 35 |
*/ |
| 36 |
define('FORGE12_OPTIN_VERSION', '2.12'); |
| 37 |
define('FORGE12_OPTIN_SLUG', 'f12-cf7-doubleoptin'); |
| 38 |
define('FORGE12_OPTIN_BASENAME', plugin_basename(__FILE__)); |
| 39 |
|
| 40 |
/** |
| 41 |
* Class CF7DoubleOptIn |
| 42 |
* Controller for the Custom Links. |
| 43 |
* |
| 44 |
* @package forge12\contactform7 |
| 45 |
*/ |
| 46 |
class CF7DoubleOptIn |
| 47 |
{ |
| 48 |
/** |
| 49 |
* @var CF7DoubleOptIn|Null |
| 50 |
*/ |
| 51 |
private static $_instance = null; |
| 52 |
|
| 53 |
/** |
| 54 |
* Get the instance of the custom links controller |
| 55 |
* |
| 56 |
* @return CF7DoubleOptIn |
| 57 |
*/ |
| 58 |
public static function getInstance() |
| 59 |
{ |
| 60 |
if (self::$_instance == null) { |
| 61 |
self::$_instance = new CF7DoubleOptIn(); |
| 62 |
} |
| 63 |
|
| 64 |
return self::$_instance; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* @param string $template_name The name of the template file |
| 69 |
* @param array $atts The parameter send to the template. |
| 70 |
* |
| 71 |
* @return void|null |
| 72 |
*/ |
| 73 |
public function renderTemplate($template_name, $atts = array()) |
| 74 |
{ |
| 75 |
$template = $this->getTemplate($template_name, $atts); |
| 76 |
|
| 77 |
if (empty($template)) { |
| 78 |
return null; |
| 79 |
} |
| 80 |
|
| 81 |
echo $template; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Return the Content of the Template |
| 86 |
* |
| 87 |
* @param string $template_name The name of the template file |
| 88 |
* @param array $atts The parameter send to the template. |
| 89 |
* |
| 90 |
* @return string |
| 91 |
*/ |
| 92 |
public function getTemplate($template_name, $atts = array()) |
| 93 |
{ |
| 94 |
$template_path = plugin_dir_path(__FILE__) . '/templates/' . $template_name . '.php'; |
| 95 |
|
| 96 |
if (!file_exists($template_path)) { |
| 97 |
return ''; |
| 98 |
} |
| 99 |
|
| 100 |
extract($atts); |
| 101 |
|
| 102 |
ob_start(); |
| 103 |
require($template_path); |
| 104 |
$content = ob_get_contents(); |
| 105 |
ob_end_clean(); |
| 106 |
|
| 107 |
return $content; |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Return a list containing the array with all data stored within the contact form 7 form |
| 112 |
* |
| 113 |
* @param int $postID |
| 114 |
* |
| 115 |
* @return array |
| 116 |
*/ |
| 117 |
public function getParameter($postID) |
| 118 |
{ |
| 119 |
$data = array(); |
| 120 |
|
| 121 |
$data = apply_filters('f12_cf7_doubleoptin_get_parameter', $data); |
| 122 |
|
| 123 |
if (!$postID) { |
| 124 |
return $data; |
| 125 |
} |
| 126 |
|
| 127 |
$options = get_post_meta($postID, 'f12-cf7-doubleoptin', true); |
| 128 |
|
| 129 |
if (!$options) { |
| 130 |
return $data; |
| 131 |
} |
| 132 |
|
| 133 |
return array_merge($data, $options); |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* CustomLinks constructor. |
| 138 |
*/ |
| 139 |
private function __construct() |
| 140 |
{ |
| 141 |
$UI = new UI(FORGE12_OPTIN_SLUG, 'Forge12 Double Opt-In', 'manage_options'); |
| 142 |
|
| 143 |
add_action('after_setup_theme', [$this, 'init']); |
| 144 |
add_action( 'init', [$this, 'load_text_domain'] ); |
| 145 |
|
| 146 |
$Compatibility = new Compatibility(FORGE12_OPTIN_SLUG); |
| 147 |
|
| 148 |
$CleanUp = new CleanUp(); |
| 149 |
|
| 150 |
// Pagination |
| 151 |
Pagination::getInstance(); |
| 152 |
|
| 153 |
// initialize filter |
| 154 |
CategoryOptions::getInstance(); |
| 155 |
OptInLimitFilter::getInstance(); |
| 156 |
OptInSearchFilter::getInstance(); |
| 157 |
|
| 158 |
// Support |
| 159 |
Support::getInstance(); |
| 160 |
} |
| 161 |
|
| 162 |
public function load_text_domain(){ |
| 163 |
load_plugin_textdomain( 'double-opt-in', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* @private WordPress Hook |
| 168 |
*/ |
| 169 |
public function init() |
| 170 |
{ |
| 171 |
do_action('f12_cf7_doubleoptin_register_implementations'); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* @return string |
| 176 |
*/ |
| 177 |
public function getIPAdress() |
| 178 |
{ |
| 179 |
//whether ip is from share internet |
| 180 |
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
| 181 |
$ip_address = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']); |
| 182 |
} //whether ip is from proxy |
| 183 |
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| 184 |
$ip_address = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); |
| 185 |
} //whether ip is from remote address |
| 186 |
else { |
| 187 |
$ip_address = sanitize_text_field($_SERVER['REMOTE_ADDR']); |
| 188 |
} |
| 189 |
|
| 190 |
return $ip_address; |
| 191 |
} |
| 192 |
|
| 193 |
public function sanitize_array($data){ |
| 194 |
if(!is_array($data)){ |
| 195 |
return []; |
| 196 |
} |
| 197 |
|
| 198 |
$sanitized_data = []; |
| 199 |
foreach($data as $key => $value){ |
| 200 |
if(is_array($value)){ |
| 201 |
$sanitized_data[sanitize_text_field($key)] = $this->sanitize_array($value); |
| 202 |
}else { |
| 203 |
$sanitized_data[sanitize_text_field($key)] = wp_kses_post($value); |
| 204 |
} |
| 205 |
} |
| 206 |
return $sanitized_data; |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Return all saved settings |
| 211 |
* |
| 212 |
* @param string $single The Key of the setting to return only the required setting |
| 213 |
* |
| 214 |
* @return array<mixed> |
| 215 |
*/ |
| 216 |
public function getSettings($single = '', $container = null) |
| 217 |
{ |
| 218 |
$default = array(); |
| 219 |
|
| 220 |
$default = apply_filters('f12_cf7_doubleoptin_settings', $default); |
| 221 |
|
| 222 |
$settings = get_option('f12-doi-settings'); |
| 223 |
|
| 224 |
if (!is_array($settings)) { |
| 225 |
$settings = array(); |
| 226 |
} |
| 227 |
|
| 228 |
foreach ($default as $key => $data) { |
| 229 |
if (isset($settings[$key])) { |
| 230 |
if (is_array($default[$key])) { |
| 231 |
$default[$key] = array_merge($default[$key], $settings[$key]); |
| 232 |
} else { |
| 233 |
$default[$key] = $settings[$key]; |
| 234 |
} |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
$settings = $default; |
| 239 |
|
| 240 |
if (!empty($single)) { |
| 241 |
if ($container != null) { |
| 242 |
if (isset($settings[$container]) && isset($settings[$container][$single])) { |
| 243 |
$settings = $settings[$container][$single]; |
| 244 |
} |
| 245 |
} |
| 246 |
} else { |
| 247 |
if (isset($settings[$single])) { |
| 248 |
$settings = $settings[$single]; |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
return $settings; |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Create the table to store the opt ins. |
| 258 |
* |
| 259 |
* @return void |
| 260 |
*/ |
| 261 |
function createTableOptIn() |
| 262 |
{ |
| 263 |
global $wpdb; |
| 264 |
|
| 265 |
$tableName = 'f12_cf7_doubleoptin'; |
| 266 |
$wpTableName = $wpdb->prefix . $tableName; |
| 267 |
|
| 268 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 269 |
|
| 270 |
$sql = "CREATE TABLE " . $wpTableName . " ( |
| 271 |
id int(11) NOT NULL auto_increment, |
| 272 |
cf_form_id int(11) NOT NULL, |
| 273 |
doubleoptin int(2), |
| 274 |
content text, |
| 275 |
files text, |
| 276 |
hash VARCHAR(255), |
| 277 |
ipaddr_register varchar(255) NOT NULL DEFAULT '', |
| 278 |
ipaddr_confirmation varchar(255) NOT NULL DEFAULT '', |
| 279 |
createtime varchar(255) DEFAULT '', |
| 280 |
updatetime varchar(255) DEFAULT '', |
| 281 |
category int(11), |
| 282 |
email varchar(255), |
| 283 |
form text, |
| 284 |
mail_optin text, |
| 285 |
PRIMARY KEY (id) |
| 286 |
)"; |
| 287 |
dbDelta($sql); |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* Create the table for the categories |
| 292 |
* |
| 293 |
* @return void |
| 294 |
*/ |
| 295 |
function createTableOptinCategories() |
| 296 |
{ |
| 297 |
global $wpdb; |
| 298 |
|
| 299 |
$tableName = 'f12_cf7_doubleoptin_categories'; |
| 300 |
$wpTableName = $wpdb->prefix . $tableName; |
| 301 |
|
| 302 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 303 |
|
| 304 |
$sql = "CREATE TABLE " . $wpTableName . " ( |
| 305 |
id int(11) NOT NULL auto_increment, |
| 306 |
name varchar(255), |
| 307 |
createtime varchar(255) DEFAULT '', |
| 308 |
updatetime varchar(255) DEFAULT '', |
| 309 |
PRIMARY KEY (id) |
| 310 |
)"; |
| 311 |
dbDelta($sql); |
| 312 |
} |
| 313 |
|
| 314 |
/** |
| 315 |
* On Activation create the custom table to store the required information |
| 316 |
* for the double opt in system. |
| 317 |
*/ |
| 318 |
function onActivation() |
| 319 |
{ |
| 320 |
createTableOptin(); |
| 321 |
createTableOptinCategories(); |
| 322 |
|
| 323 |
// Add cron |
| 324 |
if (!wp_next_scheduled('dailyOptinClear')) { |
| 325 |
wp_schedule_event(time(), 'daily', 'dailyOptinClear'); |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
register_activation_hook(__FILE__, 'forge12\contactform7\CF7DoubleOptIn\onActivation'); |
| 330 |
|
| 331 |
/** |
| 332 |
* On deactivation delete all tables |
| 333 |
*/ |
| 334 |
function onDeactivation() |
| 335 |
{ |
| 336 |
if (!defined('WP_UINSTALL_PLUGIN')) { |
| 337 |
return; |
| 338 |
} |
| 339 |
|
| 340 |
global $wpdb; |
| 341 |
|
| 342 |
// Backup Table |
| 343 |
$tableName = 'f12_cf7_doubleoptin'; |
| 344 |
$wpTableName = $wpdb->prefix . $tableName; |
| 345 |
|
| 346 |
$wpdb->query("DROP TABLE IF EXISTS " . $wpTableName); |
| 347 |
|
| 348 |
# clear cron |
| 349 |
wp_clear_scheduled_hook('dailyOptinClear'); |
| 350 |
} |
| 351 |
|
| 352 |
function onUpdate() |
| 353 |
{ |
| 354 |
// Only run if the version installed not exist or the version is < 1.7 |
| 355 |
// this will add categories to already existing plugins |
| 356 |
if (version_compare(get_site_option(FORGE12_OPTIN_SLUG . '_version'), '1.7') < 0) { |
| 357 |
createTableOptinCategories(); |
| 358 |
createTableOptin(); |
| 359 |
|
| 360 |
update_option(FORGE12_OPTIN_SLUG . '_version', '1.7'); |
| 361 |
} |
| 362 |
|
| 363 |
// Only run if the version installed not exist or the version is < 2.0 |
| 364 |
// this will add categories to already existing plugins |
| 365 |
if (version_compare(get_site_option(FORGE12_OPTIN_SLUG . '_version'), '2.0') < 0) { |
| 366 |
createTableOptin(); |
| 367 |
|
| 368 |
update_option(FORGE12_OPTIN_SLUG . '_version', '2.0'); |
| 369 |
} |
| 370 |
} |
| 371 |
|
| 372 |
onUpdate(); |
| 373 |
|
| 374 |
register_deactivation_hook(__FILE__, 'forge12\contactform7\CF7DoubleOptIn\onDeactivation'); |
| 375 |
|
| 376 |
CF7DoubleOptIn::getInstance(); |
| 377 |
|
| 378 |
add_filter( 'safe_style_css', function( $styles ) { |
| 379 |
$styles[] = 'display'; |
| 380 |
return $styles; |
| 381 |
} ); |
| 382 |
} |