newsletter-subscription-form
Last commit date
languages
6 months ago
options
6 months ago
newsletter-subscription-form.php
6 months ago
readme.txt
6 months ago
newsletter-subscription-form.php
170 lines
| 1 | <?php |
| 2 | /* |
| 3 | * Plugin Name: Newsletter Subscription Form |
| 4 | * Description: Newsletter Subscription Form for WordPress is the ultimate lead generation, customer acquisition and email marketing plugin to grow and engage your mailing list and visitors. |
| 5 | * Version: 1.5.6 |
| 6 | * Author: Weblizar |
| 7 | * Text Domain: newsletter-subscription-form |
| 8 | * Domain Path: /options/languages |
| 9 | * Author URI: https://weblizar.com/ |
| 10 | * Plugin URI: https://weblizar.com/plugins/newsletter-subscription-form/ |
| 11 | * License: GPL-2.0+ |
| 12 | * License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 13 | * Copyright 2016-25 Weblizar (email : lizarweb@gmail.com, twitter : @weblizar) |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * Default Constants |
| 18 | */ |
| 19 | |
| 20 | define('NLS_TEXT_DOMAIN', 'newsletter-subscription-form'); // Your textdomain |
| 21 | define('NLS_PLUGIN_NAME', esc_html__('Newsletter Subscription Form', 'NLS_TEXT_DOMAIN')); // Plugin Name shows up on the admin settings screen. |
| 22 | |
| 23 | define("WEBLIZAR_NLS_PLUGIN_URL", plugin_dir_url(__FILE__)); |
| 24 | |
| 25 | // echo dirname(__FILE__) . '/options/option-panel.php'; |
| 26 | |
| 27 | if (file_exists(dirname(__FILE__) . '/options/option-panel.php')) { |
| 28 | include 'options/option-panel.php'; |
| 29 | } |
| 30 | if (file_exists(dirname(__FILE__) . '/options/default-options.php')) { |
| 31 | include 'options/default-options.php'; |
| 32 | } |
| 33 | |
| 34 | add_action('plugins_loaded', 'NLS_Language_Translater'); |
| 35 | function NLS_Language_Translater() { |
| 36 | load_plugin_textdomain('NLS_TEXT_DOMAIN', false, dirname(plugin_basename(__FILE__)) . '/languages'); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Function to create table for subscriber |
| 41 | */ |
| 42 | function nls_callback_plugin_subscriber() { |
| 43 | global $wpdb; |
| 44 | $table_name = $wpdb->prefix . 'nls_subscribers'; |
| 45 | $charset_collate = $wpdb->get_charset_collate(); |
| 46 | $sql= ''; |
| 47 | |
| 48 | $col2 = $wpdb->get_var("SHOW TABLES LIKE '$table_name'"); |
| 49 | if ($col2) { |
| 50 | /* Add deact_code column if not exists to nls_subscribers table */ |
| 51 | $row = $wpdb->get_results("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . DB_NAME . "' AND TABLE_NAME = '" . $table_name . "' AND COLUMN_NAME = 'deact_code'"); |
| 52 | if( !$row) { |
| 53 | $sql .= $wpdb->query("ALTER TABLE $table_name ADD deact_code VARCHAR(255) NOT NULL"); |
| 54 | } |
| 55 | |
| 56 | /* Add deact_code column if not exists to nls_subscribers table */ |
| 57 | $row = $wpdb->get_results("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . DB_NAME . "' AND TABLE_NAME = '" . $table_name . "' AND COLUMN_NAME = 'form_type'"); |
| 58 | if( !$row) { |
| 59 | $sql .= $wpdb->query("ALTER TABLE $table_name ADD form_type VARCHAR(255) NOT NULL"); |
| 60 | } |
| 61 | } else { |
| 62 | $sql = "CREATE TABLE IF NOT EXISTS $table_name ( |
| 63 | id int NOT NULL AUTO_INCREMENT, |
| 64 | f_name VARCHAR(255) NOT NULL, |
| 65 | l_name VARCHAR(255) NOT NULL, |
| 66 | terms VARCHAR(255) NOT NULL, |
| 67 | email VARCHAR(255) NOT NULL, |
| 68 | date timestamp, |
| 69 | act_code VARCHAR(255) NOT NULL, |
| 70 | deact_code VARCHAR(255) NOT NULL, |
| 71 | extra_detail text, |
| 72 | form_type VARCHAR(255) NOT NULL, |
| 73 | flag int, |
| 74 | UNIQUE KEY id (id) |
| 75 | )$charset_collate;"; |
| 76 | } |
| 77 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 78 | dbDelta($sql); |
| 79 | } |
| 80 | register_activation_hook(__FILE__, 'nls_callback_plugin_subscriber'); |
| 81 | |
| 82 | /** |
| 83 | * Function to redirect to maintenance mode page |
| 84 | */ |
| 85 | function nls_template_redirect_enqueue_script() { |
| 86 | wp_deregister_script('jQuery'); |
| 87 | wp_enqueue_script('wp-color-picker'); |
| 88 | wp_enqueue_style('wp-color-picker'); |
| 89 | wp_enqueue_style('form-style', plugin_dir_url(__FILE__) . 'options/css/form-style.css'); |
| 90 | wp_enqueue_script('form_js', plugin_dir_url(__FILE__) . 'options/js/form_js.js', array('jQuery', 'wp-color-picker')); |
| 91 | } |
| 92 | |
| 93 | add_action('wp_enqueue_scripts', 'nls_template_redirect_enqueue_script'); |
| 94 | function nls_maintenance_mode_template_redirect() { |
| 95 | if (isset($_GET['act_code'])) { |
| 96 | $act_code = $_GET['act_code']; |
| 97 | $email = $_GET['email']; |
| 98 | $wl_wnlsp_options = get_option('weblizar_wnlsp_options'); |
| 99 | //search & match the email & activation code |
| 100 | global $wpdb; |
| 101 | $table_name = $wpdb->prefix . 'nls_subscribers'; |
| 102 | $user_search_result = $wpdb->get_row("SELECT * FROM `$table_name` WHERE `email` LIKE '$email' AND `act_code` LIKE '$act_code'"); |
| 103 | if (count($user_search_result)) { |
| 104 | // check user is already subscribed |
| 105 | if ($user_search_result->flag == 1) { |
| 106 | get_header(); |
| 107 | echo '<div class="main_div1"><p class="subscribe-messages1">' . esc_html($wl_wnlsp_options['sub_form_subscribe_already_confirm_message']) . '<span class="close_message1">' . esc_html__('X', 'NLS_TEXT_DOMAIN') . '</span></p></div>'; |
| 108 | } else { |
| 109 | // update user subscription active |
| 110 | if ($wpdb->query("UPDATE `$table_name` SET `flag` = '1' WHERE `email` = '$email'")) { |
| 111 | get_header(); |
| 112 | echo '<div class="main_div1"><p class="subscribe-messages1">' . esc_html($wl_wnlsp_options['sub_form_subscribe_confirm_success_message']) . '<span class="close_message1">' . esc_html__('X', 'NLS_TEXT_DOMAIN') . '</span></p></div>'; |
| 113 | } |
| 114 | //require_once('wnlsp-options/themes/form-include/confirmation-mail-from.php'); |
| 115 | require_once('options/themes/form-include/confirmation-mail-from.php'); |
| 116 | } |
| 117 | } else { |
| 118 | get_header(); |
| 119 | echo '<div class="main_div1"><p class="subscribe-messages1">' . esc_html($wl_wnlsp_options['sub_form_invalid_confirmation_message']) . '<span class="close_message1">' . esc_html__('X', 'NLS_TEXT_DOMAIN') . '</span></p></div>'; |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | add_action('template_redirect', 'nls_maintenance_mode_template_redirect'); |
| 124 | |
| 125 | function weblizar_nls_activation() { |
| 126 | $weblizar_nls_default_settings = weblizar_nls_default_settings(); |
| 127 | $weblizar_nls_saved_theme_settings = get_option('weblizar_nls_options'); // get existing option data |
| 128 | if ($weblizar_nls_saved_theme_settings) { |
| 129 | $weblizar_nls_saved_theme_settings = array_merge($weblizar_nls_default_settings, $weblizar_nls_saved_theme_settings); |
| 130 | update_option('weblizar_nls_options', $weblizar_nls_saved_theme_settings); // Set existing and new option data |
| 131 | } else { |
| 132 | add_option('weblizar_nls_options', $weblizar_nls_default_settings); // set New option data |
| 133 | |
| 134 | /*mailchimp list display Settings data post function **/ |
| 135 | $weblizar_nls_mailchimp_allLists = ""; |
| 136 | add_option("weblizar_nls_mailchimp_key", serialize($weblizar_nls_mailchimp_allLists)); |
| 137 | |
| 138 | /*Madmimi display Settings data post function **/ |
| 139 | $weblizar_nls_madmimi = ""; |
| 140 | add_option("weblizar_nls_madmimi_list", serialize($weblizar_nls_madmimi)); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | register_activation_hook(__FILE__, 'weblizar_nls_activation'); |
| 145 | |
| 146 | // Do redirect when Plugin activate |
| 147 | function nls_nht_plugin_activate() { |
| 148 | add_option('nls_nht_plugin_do_activation_redirect', true); |
| 149 | } |
| 150 | function nls_nht_plugin_redirect() { |
| 151 | if (get_option('nls_nht_plugin_do_activation_redirect', false)) { |
| 152 | delete_option('nls_nht_plugin_do_activation_redirect'); |
| 153 | if (!isset($_GET['activate-multi'])) { |
| 154 | wp_redirect("admin.php?page=nls-weblizar"); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | register_activation_hook(__FILE__, 'nls_nht_plugin_activate'); |
| 159 | add_action('admin_init', 'nls_nht_plugin_redirect'); |
| 160 | |
| 161 | // Add settings link on plugin page |
| 162 | function nls_settings_link($links) { |
| 163 | $nls_settings_link = '<a href="admin.php?page=nls-weblizar">' . esc_html__('Settings', 'NLS_TEXT_DOMAIN') . '</a>'; |
| 164 | $nls_pro_link = '<a style="color: #ea5a21;font-weight: 700;" href="https://weblizar.com/plugins/newsletter-subscription-form-pro/" target="_blank">' . esc_html('Get Premium', 'NLS_TEXT_DOMAIN') . '</a>'; |
| 165 | array_unshift($links, $nls_pro_link, $nls_settings_link); |
| 166 | return $links; |
| 167 | } |
| 168 | $nls_plugin_name = plugin_basename(__FILE__); |
| 169 | add_filter("plugin_action_links_$nls_plugin_name", 'nls_settings_link'); |
| 170 |