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