getTemplate($template_name, $atts); if (empty($template)) { return null; } echo $template; } /** * Return the Content of the Template * * @param string $template_name The name of the template file * @param array $atts The parameter send to the template. * * @return string */ public function getTemplate($template_name, $atts = array()) { $template_path = plugin_dir_path(__FILE__) . '/templates/' . $template_name . '.php'; if (!file_exists($template_path)) { return ''; } extract($atts); ob_start(); require($template_path); $content = ob_get_contents(); ob_end_clean(); return $content; } /** * Return a list containing the array with all data stored within the contact form 7 form * * @param int $postID * * @return array */ public function getParameter($postID) { $data = array(); $data = apply_filters('f12_cf7_doubleoptin_get_parameter', $data); if (!$postID) { return $data; } $options = get_post_meta($postID, 'f12-cf7-doubleoptin', true); if (!$options) { return $data; } return array_merge($data, $options); } /** * CustomLinks constructor. */ private function __construct() { $UI = new UI(FORGE12_OPTIN_SLUG, 'Forge12 Double Opt-In', 'manage_options'); add_action('after_setup_theme', [$this, 'init']); add_action( 'init', [$this, 'load_text_domain'] ); $Compatibility = new Compatibility(FORGE12_OPTIN_SLUG); $CleanUp = new CleanUp(); // Pagination Pagination::getInstance(); // initialize filter CategoryOptions::getInstance(); OptInLimitFilter::getInstance(); OptInSearchFilter::getInstance(); // Support Support::getInstance(); } public function load_text_domain(){ load_plugin_textdomain( 'double-opt-in', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } /** * @private WordPress Hook */ public function init() { do_action('f12_cf7_doubleoptin_register_implementations'); } /** * @return string */ public function getIPAdress() { //whether ip is from share internet if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip_address = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']); } //whether ip is from proxy elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip_address = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); } //whether ip is from remote address else { $ip_address = sanitize_text_field($_SERVER['REMOTE_ADDR']); } return $ip_address; } public function sanitize_array($data){ if(!is_array($data)){ return []; } $sanitized_data = []; foreach($data as $key => $value){ if(is_array($value)){ $sanitized_data[sanitize_text_field($key)] = $this->sanitize_array($value); }else { $sanitized_data[sanitize_text_field($key)] = wp_kses_post($value); } } return $sanitized_data; } /** * Return all saved settings * * @param string $single The Key of the setting to return only the required setting * * @return array */ public function getSettings($single = '', $container = null) { $default = array(); $default = apply_filters('f12_cf7_doubleoptin_settings', $default); $settings = get_option('f12-doi-settings'); if (!is_array($settings)) { $settings = array(); } foreach ($default as $key => $data) { if (isset($settings[$key])) { if (is_array($default[$key])) { $default[$key] = array_merge($default[$key], $settings[$key]); } else { $default[$key] = $settings[$key]; } } } $settings = $default; if (!empty($single)) { if ($container != null) { if (isset($settings[$container]) && isset($settings[$container][$single])) { $settings = $settings[$container][$single]; } } } else { if (isset($settings[$single])) { $settings = $settings[$single]; } } return $settings; } } /** * Create the table to store the opt ins. * * @return void */ function createTableOptIn() { global $wpdb; $tableName = 'f12_cf7_doubleoptin'; $wpTableName = $wpdb->prefix . $tableName; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); $sql = "CREATE TABLE " . $wpTableName . " ( id int(11) NOT NULL auto_increment, cf_form_id int(11) NOT NULL, doubleoptin int(2), content text, files text, hash VARCHAR(255), ipaddr_register varchar(255) NOT NULL DEFAULT '', ipaddr_confirmation varchar(255) NOT NULL DEFAULT '', createtime varchar(255) DEFAULT '', updatetime varchar(255) DEFAULT '', category int(11), email varchar(255), form text, mail_optin text, PRIMARY KEY (id) )"; dbDelta($sql); } /** * Create the table for the categories * * @return void */ function createTableOptinCategories() { global $wpdb; $tableName = 'f12_cf7_doubleoptin_categories'; $wpTableName = $wpdb->prefix . $tableName; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); $sql = "CREATE TABLE " . $wpTableName . " ( id int(11) NOT NULL auto_increment, name varchar(255), createtime varchar(255) DEFAULT '', updatetime varchar(255) DEFAULT '', PRIMARY KEY (id) )"; dbDelta($sql); } /** * On Activation create the custom table to store the required information * for the double opt in system. */ function onActivation() { createTableOptin(); createTableOptinCategories(); // Add cron if (!wp_next_scheduled('dailyOptinClear')) { wp_schedule_event(time(), 'daily', 'dailyOptinClear'); } } register_activation_hook(__FILE__, 'forge12\contactform7\CF7DoubleOptIn\onActivation'); /** * On deactivation delete all tables */ function onDeactivation() { if (!defined('WP_UINSTALL_PLUGIN')) { return; } global $wpdb; // Backup Table $tableName = 'f12_cf7_doubleoptin'; $wpTableName = $wpdb->prefix . $tableName; $wpdb->query("DROP TABLE IF EXISTS " . $wpTableName); # clear cron wp_clear_scheduled_hook('dailyOptinClear'); } function onUpdate() { // Only run if the version installed not exist or the version is < 1.7 // this will add categories to already existing plugins if (version_compare(get_site_option(FORGE12_OPTIN_SLUG . '_version'), '1.7') < 0) { createTableOptinCategories(); createTableOptin(); update_option(FORGE12_OPTIN_SLUG . '_version', '1.7'); } // Only run if the version installed not exist or the version is < 2.0 // this will add categories to already existing plugins if (version_compare(get_site_option(FORGE12_OPTIN_SLUG . '_version'), '2.0') < 0) { createTableOptin(); update_option(FORGE12_OPTIN_SLUG . '_version', '2.0'); } } onUpdate(); register_deactivation_hook(__FILE__, 'forge12\contactform7\CF7DoubleOptIn\onDeactivation'); CF7DoubleOptIn::getInstance(); add_filter( 'safe_style_css', function( $styles ) { $styles[] = 'display'; return $styles; } ); }