Version Description
Download this release
Release Info
Developer | Icegram |
Plugin | Email Subscribers & Newsletters |
Version | 4.3.3 |
Comparing to | |
See all releases |
Code changes from version 4.3.2 to 4.3.3
- email-subscribers.php +2 -2
- lite/includes/admin/class-es-actions.php +0 -294
- lite/includes/admin/class-es-admin-settings.php +0 -824
- lite/includes/admin/class-es-campaigns-table.php +0 -433
- lite/includes/admin/class-es-contacts-table.php +0 -1101
- lite/includes/admin/class-es-cron.php +0 -436
- lite/includes/admin/class-es-export-subscribers.php +0 -334
- lite/includes/admin/class-es-form-widget.php +0 -80
- lite/includes/admin/class-es-forms-table.php +0 -834
- lite/includes/admin/class-es-handle-post-notification.php +0 -262
- lite/includes/admin/class-es-handle-subscription.php +0 -416
- lite/includes/admin/class-es-handle-sync-wp-user.php +0 -201
- lite/includes/admin/class-es-import-subscribers.php +0 -314
- lite/includes/admin/class-es-info.php +0 -55
- lite/includes/admin/class-es-lists-table.php +0 -640
- lite/includes/admin/class-es-newsletters.php +0 -296
- lite/includes/admin/class-es-old-widget.php +0 -114
- lite/includes/admin/class-es-post-notifications.php +0 -393
- lite/includes/admin/class-es-queue.php +0 -693
- lite/includes/admin/class-es-reports-table.php +0 -525
- lite/includes/admin/class-es-subscription-throttaling.php +0 -56
- lite/includes/admin/class-es-templates-table.php +0 -323
- lite/includes/admin/class-es-tools.php +0 -92
- lite/includes/admin/class-es-tracking.php +0 -39
- lite/includes/admin/class-es-widget.php +0 -87
- lite/includes/class-es-common.php +2 -1
- lite/includes/class-es-mailer.php +0 -547
- lite/includes/classes/class-es-cron.php +87 -30
- lite/includes/classes/class-es-handle-post-notification.php +9 -6
- lite/includes/classes/class-es-handle-subscription.php +2 -1
- lite/includes/classes/class-es-mailer.php +24 -2
- lite/includes/classes/class-es-newsletters.php +81 -80
- lite/includes/classes/class-es-queue.php +31 -0
- lite/public/class-email-subscribers-public.php +0 -1
- lite/public/partials/class-es-shortcode.php +1 -1
- readme.txt +5 -1
email-subscribers.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Email Subscribers & Newsletters
|
4 |
* Plugin URI: https://www.icegram.com/
|
5 |
* Description: Add subscription forms on website, send HTML newsletters & automatically notify subscribers about new blog posts once it is published.
|
6 |
-
* Version: 4.3.
|
7 |
* Author: Icegram
|
8 |
* Author URI: https://www.icegram.com/
|
9 |
* Requires at least: 3.9
|
@@ -115,7 +115,7 @@ if ( $is_premium ) {
|
|
115 |
/* ***************************** Initial Compatibility Work (End) ******************* */
|
116 |
|
117 |
if ( ! defined( 'ES_PLUGIN_VERSION' ) ) {
|
118 |
-
define( 'ES_PLUGIN_VERSION', '4.3.
|
119 |
}
|
120 |
|
121 |
// Plugin Folder Path.
|
3 |
* Plugin Name: Email Subscribers & Newsletters
|
4 |
* Plugin URI: https://www.icegram.com/
|
5 |
* Description: Add subscription forms on website, send HTML newsletters & automatically notify subscribers about new blog posts once it is published.
|
6 |
+
* Version: 4.3.3
|
7 |
* Author: Icegram
|
8 |
* Author URI: https://www.icegram.com/
|
9 |
* Requires at least: 3.9
|
115 |
/* ***************************** Initial Compatibility Work (End) ******************* */
|
116 |
|
117 |
if ( ! defined( 'ES_PLUGIN_VERSION' ) ) {
|
118 |
+
define( 'ES_PLUGIN_VERSION', '4.3.3' );
|
119 |
}
|
120 |
|
121 |
// Plugin Folder Path.
|
lite/includes/admin/class-es-actions.php
DELETED
@@ -1,294 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
// Exit if accessed directly
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
4 |
-
exit;
|
5 |
-
}
|
6 |
-
|
7 |
-
if ( ! class_exists( 'ES_Actions' ) ) {
|
8 |
-
/**
|
9 |
-
* Class ES_Actions
|
10 |
-
*
|
11 |
-
* Track all actions
|
12 |
-
*
|
13 |
-
* IG_CONTACT_SUBSCRIBE => 1,
|
14 |
-
* IG_MESSAGE_SENT => 2,
|
15 |
-
* IG_MESSAGE_OPEN => 3,
|
16 |
-
* IG_LINK_CLICK => 4,
|
17 |
-
* IG_CONTACT_UNSUBSCRIBE => 5,
|
18 |
-
* IG_MESSAGE_SOFT_BOUNCE => 6,
|
19 |
-
* IG_MESSAGE_HARD_BOUNCE => 7,
|
20 |
-
* IG_MESSAGE_ERROR => 8
|
21 |
-
*
|
22 |
-
* @since 4.2.0
|
23 |
-
*/
|
24 |
-
class ES_Actions {
|
25 |
-
/**
|
26 |
-
* ES_DB_Actions object
|
27 |
-
*
|
28 |
-
* @since 4.2.1
|
29 |
-
* @var $db
|
30 |
-
*
|
31 |
-
*/
|
32 |
-
protected $db;
|
33 |
-
|
34 |
-
/**
|
35 |
-
* ES_Actions constructor.
|
36 |
-
*
|
37 |
-
* @since 4.2.0
|
38 |
-
*/
|
39 |
-
public function __construct() {
|
40 |
-
|
41 |
-
$this->db = new ES_DB_Actions();
|
42 |
-
|
43 |
-
add_action( 'init', array( &$this, 'init' ), 1 );
|
44 |
-
}
|
45 |
-
|
46 |
-
/**
|
47 |
-
* Init Actions
|
48 |
-
*/
|
49 |
-
public function init() {
|
50 |
-
/**
|
51 |
-
* @since 4.2.0
|
52 |
-
*/
|
53 |
-
add_action( 'ig_es_contact_subscribe', array( &$this, 'subscribe' ), 10, 2 );
|
54 |
-
add_action( 'ig_es_message_sent', array( &$this, 'sent' ), 10, 3 );
|
55 |
-
add_action( 'ig_es_message_open', array( &$this, 'open' ), 10, 3 );
|
56 |
-
add_action( 'ig_es_message_click', array( &$this, 'click' ), 10, 5 );
|
57 |
-
add_action( 'ig_es_contact_unsubscribe', array( &$this, 'unsubscribe' ), 10, 4 );
|
58 |
-
//add_action( 'ig_es_message_bounce', array( &$this, 'bounce' ), 10, 3 );
|
59 |
-
//add_action( 'ig_es_subscriber_error', array( &$this, 'error' ), 10, 3 );
|
60 |
-
//add_action( 'ig_es_contact_list_unsubscribe', array( &$this, 'list_unsubscribe' ), 10, 4 );
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Get action data
|
65 |
-
*
|
66 |
-
* @since 4.2.0
|
67 |
-
*/
|
68 |
-
public function get_fields( $fields = null, $where = null ) {
|
69 |
-
|
70 |
-
global $wpdb;
|
71 |
-
|
72 |
-
$fields = esc_sql( is_null( $fields ) ? '*' : ( is_array( $fields ) ? implode( ', ', $fields ) : $fields ) );
|
73 |
-
|
74 |
-
$sql = "SELECT $fields FROM {$wpdb->prefix}ig_actions WHERE 1=1";
|
75 |
-
if ( is_array( $where ) ) {
|
76 |
-
foreach ( $where as $key => $value ) {
|
77 |
-
$sql .= ', ' . esc_sql( $key ) . " = '" . esc_sql( $value ) . "'";
|
78 |
-
}
|
79 |
-
}
|
80 |
-
|
81 |
-
return $wpdb->get_results( $sql, ARRAY_A );
|
82 |
-
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Add action
|
87 |
-
*
|
88 |
-
* @param $args
|
89 |
-
* @param bool $explicit
|
90 |
-
*
|
91 |
-
* @return bool
|
92 |
-
*
|
93 |
-
* @since 4.2.0
|
94 |
-
*/
|
95 |
-
private function add( $args, $explicit = true ) {
|
96 |
-
|
97 |
-
$args = wp_parse_args( $args, array(
|
98 |
-
'created_at' => ig_es_get_current_gmt_timestamp(),
|
99 |
-
'updated_at' => ig_es_get_current_gmt_timestamp(),
|
100 |
-
'count' => 1,
|
101 |
-
) );
|
102 |
-
|
103 |
-
return $this->db->add( $args, $explicit );
|
104 |
-
|
105 |
-
}
|
106 |
-
|
107 |
-
/**
|
108 |
-
* Track Contact Action
|
109 |
-
*
|
110 |
-
* @param $args
|
111 |
-
* @param bool $explicit
|
112 |
-
*
|
113 |
-
* @since 4.2.4
|
114 |
-
*/
|
115 |
-
private function add_contact_action( $args, $explicit = true ) {
|
116 |
-
|
117 |
-
return $this->add( $args, $explicit );
|
118 |
-
}
|
119 |
-
|
120 |
-
/**
|
121 |
-
* Add action
|
122 |
-
*
|
123 |
-
* @param $args
|
124 |
-
* @param bool $explicit
|
125 |
-
*
|
126 |
-
* @return bool
|
127 |
-
*
|
128 |
-
* @since 4.2.0
|
129 |
-
*/
|
130 |
-
private function add_action( $args, $explicit = true ) {
|
131 |
-
return $this->add( $args, $explicit );
|
132 |
-
}
|
133 |
-
|
134 |
-
/**
|
135 |
-
* Track Subscribe Action
|
136 |
-
*
|
137 |
-
* @param $contact_id
|
138 |
-
* @param array $list_ids
|
139 |
-
*
|
140 |
-
* @since 4.2.0
|
141 |
-
*/
|
142 |
-
public function subscribe( $contact_id, $list_ids = array() ) {
|
143 |
-
if ( is_array( $list_ids ) && count( $list_ids ) > 0 ) {
|
144 |
-
foreach ( $list_ids as $list_id ) {
|
145 |
-
$this->add_action( array(
|
146 |
-
'contact_id' => $contact_id,
|
147 |
-
'list_id' => $list_id,
|
148 |
-
'type' => IG_CONTACT_SUBSCRIBE
|
149 |
-
) );
|
150 |
-
}
|
151 |
-
}
|
152 |
-
|
153 |
-
}
|
154 |
-
|
155 |
-
/**
|
156 |
-
* Track Send Action
|
157 |
-
*
|
158 |
-
* @param $contact_id
|
159 |
-
* @param $message_id
|
160 |
-
* @param $campaign_id
|
161 |
-
*
|
162 |
-
* @return bool
|
163 |
-
*
|
164 |
-
* @since 4.2.0
|
165 |
-
*/
|
166 |
-
public function sent( $contact_id, $campaign_id = 0, $message_id = 0 ) {
|
167 |
-
return $this->add_action( array(
|
168 |
-
'contact_id' => $contact_id,
|
169 |
-
'campaign_id' => $campaign_id,
|
170 |
-
'message_id' => $message_id,
|
171 |
-
'type' => IG_MESSAGE_SENT,
|
172 |
-
) );
|
173 |
-
}
|
174 |
-
|
175 |
-
/**
|
176 |
-
* Track Message Open Action
|
177 |
-
*
|
178 |
-
* @param $contact_id
|
179 |
-
* @param $message_id
|
180 |
-
* @param $campaign_id
|
181 |
-
*
|
182 |
-
* @return bool
|
183 |
-
*
|
184 |
-
* @since 4.2.0
|
185 |
-
*/
|
186 |
-
public function open( $contact_id, $message_id, $campaign_id, $explicit = true ) {
|
187 |
-
|
188 |
-
// Track only if campaign sent.
|
189 |
-
if ( $this->is_campaign_sent( $contact_id, $message_id, $campaign_id ) ) {
|
190 |
-
|
191 |
-
return $this->add_action( array(
|
192 |
-
'contact_id' => $contact_id,
|
193 |
-
'message_id' => $message_id,
|
194 |
-
'campaign_id' => $campaign_id,
|
195 |
-
'type' => IG_MESSAGE_OPEN,
|
196 |
-
), $explicit );
|
197 |
-
}
|
198 |
-
}
|
199 |
-
|
200 |
-
/**
|
201 |
-
* Track Link Click Action
|
202 |
-
*
|
203 |
-
* @param $contact_id
|
204 |
-
* @param $message_id
|
205 |
-
* @param $campaign_id
|
206 |
-
* @param $link_id
|
207 |
-
*
|
208 |
-
* @return bool
|
209 |
-
*
|
210 |
-
* @since 4.2.0
|
211 |
-
*/
|
212 |
-
public function click( $link_id, $contact_id, $message_id, $campaign_id, $explicit = true ) {
|
213 |
-
|
214 |
-
// When someone click on link which means they have opened that email
|
215 |
-
// Track Email Open
|
216 |
-
$this->open( $contact_id, $message_id, $campaign_id, false );
|
217 |
-
|
218 |
-
return $this->add_contact_action( array(
|
219 |
-
'contact_id' => $contact_id,
|
220 |
-
'campaign_id' => $campaign_id,
|
221 |
-
'message_id' => $message_id,
|
222 |
-
'link_id' => $link_id,
|
223 |
-
'type' => IG_LINK_CLICK,
|
224 |
-
), $explicit );
|
225 |
-
}
|
226 |
-
|
227 |
-
/**
|
228 |
-
* Track Contact Unsubscribe Action
|
229 |
-
*
|
230 |
-
* @param $contact_id
|
231 |
-
* @param $message_id
|
232 |
-
* @param $campaign_id
|
233 |
-
* @param array $list_ids
|
234 |
-
*
|
235 |
-
* @since 4.2.0
|
236 |
-
*/
|
237 |
-
public function unsubscribe( $contact_id, $message_id, $campaign_id, $list_ids = array() ) {
|
238 |
-
if ( is_array( $list_ids ) && count( $list_ids ) > 0 ) {
|
239 |
-
foreach ( $list_ids as $list_id ) {
|
240 |
-
|
241 |
-
$this->add_action( array(
|
242 |
-
'contact_id' => $contact_id,
|
243 |
-
'message_id' => $message_id,
|
244 |
-
'campaign_id' => $campaign_id,
|
245 |
-
'list_id' => $list_id,
|
246 |
-
'type' => IG_CONTACT_UNSUBSCRIBE,
|
247 |
-
) );
|
248 |
-
}
|
249 |
-
}
|
250 |
-
}
|
251 |
-
|
252 |
-
/**
|
253 |
-
* Track Message Bounce Action
|
254 |
-
*
|
255 |
-
* @param $contact_id
|
256 |
-
* @param $message_id
|
257 |
-
* @param $campaign_id
|
258 |
-
* @param bool $hard
|
259 |
-
*
|
260 |
-
* @since 4.2.0
|
261 |
-
*/
|
262 |
-
public function bounce( $contact_id, $campaign_id, $hard = false ) {
|
263 |
-
$this->add_action( array(
|
264 |
-
'contact_id' => $contact_id,
|
265 |
-
'campaign_id' => $campaign_id,
|
266 |
-
'type' => $hard ? IG_MESSAGE_HARD_BOUNCE : IG_MESSAGE_SOFT_BOUNCE,
|
267 |
-
) );
|
268 |
-
}
|
269 |
-
|
270 |
-
/**
|
271 |
-
* Check whether campaign is sent to specific contact
|
272 |
-
*
|
273 |
-
* @param $contact_id
|
274 |
-
* @param $message_id
|
275 |
-
* @param $campaign_id
|
276 |
-
*
|
277 |
-
* @return string|null
|
278 |
-
*
|
279 |
-
* @since 4.2.3
|
280 |
-
*/
|
281 |
-
public function is_campaign_sent( $contact_id, $message_id, $campaign_id ) {
|
282 |
-
|
283 |
-
global $wpdb;
|
284 |
-
|
285 |
-
$ig_actions_table = IG_ACTIONS_TABLE;
|
286 |
-
|
287 |
-
$sql = "SELECT count(*) FROM $ig_actions_table WHERE contact_id = %d AND message_id = %d AND campaign_id = %d AND type = %d";
|
288 |
-
|
289 |
-
return $wpdb->get_var( $wpdb->prepare( $sql, $contact_id, $message_id, $campaign_id, IG_MESSAGE_SENT ) );
|
290 |
-
}
|
291 |
-
}
|
292 |
-
}
|
293 |
-
|
294 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-admin-settings.php
DELETED
@@ -1,824 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
/**
|
9 |
-
* The admin-specific functionality of the plugin.
|
10 |
-
*
|
11 |
-
* Admin Settings
|
12 |
-
*
|
13 |
-
* @package Email_Subscribers
|
14 |
-
* @subpackage Email_Subscribers/admin
|
15 |
-
* @author Your Name <email@example.com>
|
16 |
-
*/
|
17 |
-
class ES_Admin_Settings {
|
18 |
-
|
19 |
-
static $instance;
|
20 |
-
|
21 |
-
public $subscribers_obj;
|
22 |
-
|
23 |
-
public function __construct() {
|
24 |
-
}
|
25 |
-
|
26 |
-
public static function set_screen( $status, $option, $value ) {
|
27 |
-
return $value;
|
28 |
-
}
|
29 |
-
|
30 |
-
public function es_settings_callback() {
|
31 |
-
|
32 |
-
$submitted = ig_es_get_request_data( 'submitted' );
|
33 |
-
$submit_action = ig_es_get_request_data( 'submit_action' );
|
34 |
-
|
35 |
-
if ( 'submitted' === $submitted && 'ig-es-save-admin-settings' === $submit_action ) {
|
36 |
-
|
37 |
-
$nonce = ig_es_get_request_data( 'update-settings' );
|
38 |
-
if ( ! wp_verify_nonce( $nonce, 'update-settings' ) ) {
|
39 |
-
$message = __( 'You do not have permission to update settings', 'email-subscribers' );
|
40 |
-
ES_Common::show_message( $message, 'error' );
|
41 |
-
} else {
|
42 |
-
|
43 |
-
$options = ig_es_get_post_data( '', '', false );
|
44 |
-
|
45 |
-
$options = apply_filters( 'ig_es_before_save_settings', $options );
|
46 |
-
|
47 |
-
$options['ig_es_disable_wp_cron'] = isset( $options['ig_es_disable_wp_cron'] ) ? $options['ig_es_disable_wp_cron'] : 'no';
|
48 |
-
$options['ig_es_track_email_opens'] = isset( $options['ig_es_track_email_opens'] ) ? $options['ig_es_track_email_opens'] : 'no';
|
49 |
-
|
50 |
-
$text_fields_to_sanitize = array(
|
51 |
-
'ig_es_from_name',
|
52 |
-
'ig_es_admin_emails',
|
53 |
-
'ig_es_email_type',
|
54 |
-
'ig_es_optin_type',
|
55 |
-
'ig_es_post_image_size',
|
56 |
-
'ig_es_track_email_opens',
|
57 |
-
'ig_es_enable_welcome_email',
|
58 |
-
'ig_es_welcome_email_subject',
|
59 |
-
'ig_es_confirmation_mail_subject',
|
60 |
-
'ig_es_notify_admin',
|
61 |
-
'ig_es_admin_new_contact_email_subject',
|
62 |
-
'ig_es_enable_cron_admin_email',
|
63 |
-
'ig_es_cron_admin_email_subject',
|
64 |
-
'ig_es_cronurl',
|
65 |
-
'ig_es_hourly_email_send_limit',
|
66 |
-
'ig_es_disable_wp_cron'
|
67 |
-
);
|
68 |
-
|
69 |
-
$texarea_fields_to_sanitize = array(
|
70 |
-
'ig_es_unsubscribe_link_content',
|
71 |
-
'ig_es_subscription_success_message',
|
72 |
-
'ig_es_subscription_error_messsage',
|
73 |
-
'ig_es_unsubscribe_success_message',
|
74 |
-
'ig_es_unsubscribe_error_message',
|
75 |
-
'ig_es_welcome_email_content',
|
76 |
-
'ig_es_confirmation_mail_content',
|
77 |
-
'ig_es_admin_new_contact_email_content',
|
78 |
-
'ig_es_cron_admin_email',
|
79 |
-
'ig_es_blocked_domains',
|
80 |
-
'ig_es_form_submission_success_message'
|
81 |
-
);
|
82 |
-
|
83 |
-
$email_fields_to_sanitize = array(
|
84 |
-
'ig_es_from_email'
|
85 |
-
);
|
86 |
-
|
87 |
-
foreach ( $options as $key => $value ) {
|
88 |
-
if ( substr( $key, 0, 6 ) === 'ig_es_' ) {
|
89 |
-
|
90 |
-
$value = stripslashes_deep( $value );
|
91 |
-
|
92 |
-
if ( in_array( $key, $text_fields_to_sanitize ) ) {
|
93 |
-
$value = sanitize_text_field( $value );
|
94 |
-
} elseif ( in_array( $key, $texarea_fields_to_sanitize ) ) {
|
95 |
-
$value = wp_kses_post( $value );
|
96 |
-
} elseif ( in_array( $key, $email_fields_to_sanitize ) ) {
|
97 |
-
$value = sanitize_email( $value );
|
98 |
-
}
|
99 |
-
|
100 |
-
update_option( $key, wp_unslash( $value ), false );
|
101 |
-
}
|
102 |
-
}
|
103 |
-
|
104 |
-
do_action( 'ig_es_after_settings_save', $options );
|
105 |
-
|
106 |
-
$message = __( 'Settings have been saved successfully!' );
|
107 |
-
$status = 'success';
|
108 |
-
ES_Common::show_message( $message, $status );
|
109 |
-
}
|
110 |
-
|
111 |
-
}
|
112 |
-
|
113 |
-
|
114 |
-
?>
|
115 |
-
|
116 |
-
<div class="wrap essettings">
|
117 |
-
<h1 class="wp-heading-inline">Settings</h1>
|
118 |
-
<form action="" method="post" id="email_tabs_form" class="ig-settings-form rcorners">
|
119 |
-
|
120 |
-
<?php settings_fields( 'email_subscribers_settings' );
|
121 |
-
$es_settings_tabs = array(
|
122 |
-
'general' => array( 'icon' => 'admin-generic', 'name' => __( 'General', 'email-subscribers' ) ),
|
123 |
-
'signup_confirmation' => array( 'icon' => 'groups', 'name' => __( 'Notifications', 'email-subscribers' ) ),
|
124 |
-
'email_sending' => array( 'icon' => 'schedule', 'name' => __( 'Email Sending', 'email-subscribers' ) ),
|
125 |
-
'security_settings' => array( 'icon' => 'lock', 'name' => __( 'Security', 'email-subscribers' ) ),
|
126 |
-
);
|
127 |
-
$es_settings_tabs = apply_filters( 'ig_es_settings_tabs', $es_settings_tabs );
|
128 |
-
?>
|
129 |
-
|
130 |
-
<div id="es-settings-tabs">
|
131 |
-
<div id="menu-tab-listing" class="">
|
132 |
-
<ul class="main-tab-nav">
|
133 |
-
<?php
|
134 |
-
foreach ( $es_settings_tabs as $key => $value ) {
|
135 |
-
?>
|
136 |
-
<li class="ig-menu-tab"><a href="#tabs-<?php echo $key ?>"><i class="dashicons dashicons-<?php echo $value['icon'] ?>"></i> <?php echo $value['name'] ?></a></li>
|
137 |
-
<?php
|
138 |
-
}
|
139 |
-
?>
|
140 |
-
</ul>
|
141 |
-
</div>
|
142 |
-
<div id="menu-tab-content">
|
143 |
-
<?php $settings = self::get_registered_settings();
|
144 |
-
foreach ( $settings as $key => $value ) {
|
145 |
-
?>
|
146 |
-
<div id="tabs-<?php echo $key ?>"><?php $this->render_settings_fields( $value ); ?></div>
|
147 |
-
<?php
|
148 |
-
}
|
149 |
-
?>
|
150 |
-
</div>
|
151 |
-
|
152 |
-
</div>
|
153 |
-
</form>
|
154 |
-
</div>
|
155 |
-
<?php
|
156 |
-
|
157 |
-
}
|
158 |
-
|
159 |
-
public function es_roles_sanitize_options( $input ) {
|
160 |
-
$input['option_display_mode'] = wp_filter_nohtml_kses( $input['option_display_mode'] );
|
161 |
-
$input['option_font_size'] = sanitize_text_field( absint( $input['option_font_size'] ) );
|
162 |
-
$input['option_font_color'] = sanitize_text_field( $input['option_font_color'] );
|
163 |
-
$input['option_custom_css'] = esc_textarea( $input['option_custom_css'] );
|
164 |
-
|
165 |
-
return $input;
|
166 |
-
}
|
167 |
-
|
168 |
-
public static function get_registered_settings() {
|
169 |
-
|
170 |
-
$general_settings = array(
|
171 |
-
|
172 |
-
'sender_information' => array(
|
173 |
-
'id' => 'sender_information',
|
174 |
-
'name' => __( 'Sender', 'email-subscribers' ),
|
175 |
-
'sub_fields' => array(
|
176 |
-
'from_name' => array(
|
177 |
-
'id' => 'ig_es_from_name',
|
178 |
-
'name' => __( 'Name', 'email-subscribers' ),
|
179 |
-
'desc' => __( 'Choose a FROM name for all the emails to be sent from this plugin.', 'email-subscribers' ),
|
180 |
-
'type' => 'text',
|
181 |
-
'placeholder' => __( 'Name', 'email-subscribers' ),
|
182 |
-
'default' => ''
|
183 |
-
),
|
184 |
-
|
185 |
-
'from_email' => array(
|
186 |
-
'id' => 'ig_es_from_email',
|
187 |
-
'name' => __( 'Email', 'email-subscribers' ),
|
188 |
-
'desc' => __( 'Choose a FROM email address for all the emails to be sent from this plugin', 'email-subscribers' ),
|
189 |
-
'type' => 'text',
|
190 |
-
'placeholder' => __( 'Email Address', 'email-subscribers' ),
|
191 |
-
'default' => ''
|
192 |
-
),
|
193 |
-
)
|
194 |
-
),
|
195 |
-
|
196 |
-
'admin_email' => array(
|
197 |
-
'id' => 'ig_es_admin_emails',
|
198 |
-
'name' => __( 'Email Addresses', 'email-subscribers' ),
|
199 |
-
'type' => 'text',
|
200 |
-
'desc' => __( 'Enter the admin email addresses that should receive notifications (separated by comma).', 'email-subscribers' ),
|
201 |
-
'default' => ''
|
202 |
-
),
|
203 |
-
|
204 |
-
// 'email_type' => array(
|
205 |
-
// 'id' => 'ig_es_email_type',
|
206 |
-
// 'name' => __( 'Email Type', 'email-subscribers' ),
|
207 |
-
// 'desc' => __( 'Select whether to send HTML or Plain Text email using WordPress or PHP mail(). We recommend to send email using WordPres', 'email-subscribers' ),
|
208 |
-
// 'type' => 'select',
|
209 |
-
// 'options' => ES_Common::get_email_sending_type(),
|
210 |
-
// 'default' => 'wp_html_mail'
|
211 |
-
// ),
|
212 |
-
|
213 |
-
'ig_es_optin_type' => array(
|
214 |
-
'id' => 'ig_es_optin_type',
|
215 |
-
'name' => __( 'Opt-in Type', 'email-subscribers' ),
|
216 |
-
'desc' => '',
|
217 |
-
'type' => 'select',
|
218 |
-
'options' => ES_Common::get_optin_types(),
|
219 |
-
'default' => ''
|
220 |
-
),
|
221 |
-
|
222 |
-
'ig_es_post_image_size' => array(
|
223 |
-
'id' => 'ig_es_post_image_size',
|
224 |
-
'name' => __( 'Image Size', 'email-subscribers' ),
|
225 |
-
'type' => 'select',
|
226 |
-
'options' => ES_Common::get_image_sizes(),
|
227 |
-
'desc' => __( '<p>Select image size for {{POSTIMAGE}} to be shown in the Post Notification Emails.</p>', 'email-subscribers' ),
|
228 |
-
'default' => 'full'
|
229 |
-
),
|
230 |
-
|
231 |
-
'ig_es_track_email_opens' => array(
|
232 |
-
'id' => 'ig_es_track_email_opens',
|
233 |
-
'name' => __( 'Track Opens', 'email-subscribers' ),
|
234 |
-
'type' => 'checkbox',
|
235 |
-
'desc' => __( 'Check this if you want to track email opening.', 'email-subscribers' ),
|
236 |
-
'default' => 'yes'
|
237 |
-
),
|
238 |
-
|
239 |
-
'ig_es_form_submission_success_message' => array(
|
240 |
-
'type' => 'textarea',
|
241 |
-
'options' => false,
|
242 |
-
'placeholder' => '',
|
243 |
-
'supplemental' => '',
|
244 |
-
'default' => '',
|
245 |
-
'id' => 'ig_es_form_submission_success_message',
|
246 |
-
'name' => __( 'Message to display after form submission', 'email-subscribers' ),
|
247 |
-
'desc' => '',
|
248 |
-
),
|
249 |
-
'ig_es_unsubscribe_link_content' => array(
|
250 |
-
'type' => 'textarea',
|
251 |
-
'options' => false,
|
252 |
-
'placeholder' => '',
|
253 |
-
'supplemental' => '',
|
254 |
-
'default' => '',
|
255 |
-
'id' => 'ig_es_unsubscribe_link_content',
|
256 |
-
'name' => __( 'Show Unsubscribe Message In Email Footer', 'email-subscribers' ),
|
257 |
-
'desc' => __( 'Add text which you want your contact to see in footer to unsubscribe. Use {{UNSUBSCRIBE-LINK}} keyword to add unsubscribe link.', 'email-subscribers' ),
|
258 |
-
),
|
259 |
-
|
260 |
-
//'ig_es_optin_link' => array( 'type' => 'text', 'options' => false, 'readonly' => 'readonly', 'placeholder' => '', 'supplemental' => '', 'default' => '', 'id' => 'ig_es_optin_link', 'name' => 'Double Opt-In Confirmation Link', 'desc' => '', ),
|
261 |
-
|
262 |
-
'subscription_messages' => array(
|
263 |
-
'id' => 'subscription_messages',
|
264 |
-
'name' => __( 'Subscription Success/ Error Messages', 'email-subscribers' ),
|
265 |
-
'sub_fields' => array(
|
266 |
-
'ig_es_subscription_success_message' => array(
|
267 |
-
'type' => 'textarea',
|
268 |
-
'options' => false,
|
269 |
-
'placeholder' => '',
|
270 |
-
'supplemental' => '',
|
271 |
-
'default' => __( 'You have been subscribed successfully!', 'email-subscribers' ),
|
272 |
-
'id' => 'ig_es_subscription_success_message',
|
273 |
-
'name' => __( 'Success Message', 'email-subscribers' ),
|
274 |
-
'desc' => __( 'Show this message if contact is successfully subscribed from Double Opt-In (Confirmation) Email', 'email-subscribers' )
|
275 |
-
),
|
276 |
-
|
277 |
-
'ig_es_subscription_error_messsage' => array(
|
278 |
-
'type' => 'textarea',
|
279 |
-
'options' => false,
|
280 |
-
'placeholder' => '',
|
281 |
-
'supplemental' => '',
|
282 |
-
'default' => __( 'Oops.. Your request couldn\'t be completed. This email address seems to be already subscribed / blocked.', 'email-subscribers' ),
|
283 |
-
'id' => 'ig_es_subscription_error_messsage',
|
284 |
-
'name' => __( 'Error Message', 'email-subscribers' ),
|
285 |
-
'desc' => __( 'Show this message if any error occured after clicking confirmation link from Double Opt-In (Confirmation) Email.', 'email-subscribers' )
|
286 |
-
),
|
287 |
-
|
288 |
-
)
|
289 |
-
),
|
290 |
-
|
291 |
-
'unsubscription_messages' => array(
|
292 |
-
'id' => 'unsubscription_messages',
|
293 |
-
'name' => __( 'Unsubscribe Success/ Error Messages', 'email-subscribers' ),
|
294 |
-
'sub_fields' => array(
|
295 |
-
|
296 |
-
'ig_es_unsubscribe_success_message' => array(
|
297 |
-
'type' => 'textarea',
|
298 |
-
'options' => false,
|
299 |
-
'placeholder' => '',
|
300 |
-
'supplemental' => '',
|
301 |
-
'default' => __( 'Thank You, You have been successfully unsubscribed. You will no longer hear from us.', 'email-subscribers' ),
|
302 |
-
'id' => 'ig_es_unsubscribe_success_message',
|
303 |
-
'name' => __( 'Success Message', 'email-subscribers' ),
|
304 |
-
'desc' => __( 'Once contact clicks on unsubscribe link, he/she will be redirected to a page where this message will be shown.', 'email-subscribers' )
|
305 |
-
),
|
306 |
-
|
307 |
-
|
308 |
-
'ig_es_unsubscribe_error_message' => array(
|
309 |
-
'type' => 'textarea',
|
310 |
-
'options' => false,
|
311 |
-
'placeholder' => '',
|
312 |
-
'supplemental' => '',
|
313 |
-
'default' => 'Oops.. There was some technical error. Please try again later or contact us.',
|
314 |
-
'id' => 'ig_es_unsubscribe_error_message',
|
315 |
-
'name' => __( 'Error Message', 'email-subscribers' ),
|
316 |
-
'desc' => __( 'Show this message if any error occured after clicking on unsubscribe link.', 'email-subscribers' )
|
317 |
-
)
|
318 |
-
)
|
319 |
-
),
|
320 |
-
|
321 |
-
|
322 |
-
/*
|
323 |
-
'sent_report_subject' => array(
|
324 |
-
'id' => 'ig_es_sent_report_subject',
|
325 |
-
'name' => __( 'Sent Report Subject', 'email-subscribers' ),
|
326 |
-
'type' => 'text',
|
327 |
-
'desc' => __( 'Subject for the email report which will be sent to admin.', 'email-subscribers' ),
|
328 |
-
'default' => 'Your email has been sent'
|
329 |
-
),
|
330 |
-
|
331 |
-
'sent_report_content' => array(
|
332 |
-
'id' => 'ig_es_sent_report_content',
|
333 |
-
'name' => __( 'Sent Report Content', 'email-subscribers' ),
|
334 |
-
'type' => 'textarea',
|
335 |
-
'desc' => __( 'Content for the email report which will be sent to admin.</p><p>Available Keywords: {{COUNT}}, {{UNIQUE}}, {{STARTTIME}}, {{ENDTIME}}', 'email-subscribers' ),
|
336 |
-
),
|
337 |
-
*/
|
338 |
-
);
|
339 |
-
|
340 |
-
$general_settings = apply_filters( 'ig_es_registered_general_settings', $general_settings );
|
341 |
-
|
342 |
-
$signup_confirmation_settings = array(
|
343 |
-
|
344 |
-
'welcome_emails' => array(
|
345 |
-
'id' => 'welcome_emails',
|
346 |
-
'name' => __( 'Welcome Email', 'email-subscribers' ),
|
347 |
-
'sub_fields' => array(
|
348 |
-
|
349 |
-
'ig_es_enable_welcome_email' => array(
|
350 |
-
'type' => 'select',
|
351 |
-
'options' => array( 'yes' => __( 'Yes', 'email-subscribers' ), 'no' => __( 'No', 'email-subscribers' ) ),
|
352 |
-
'placeholder' => '',
|
353 |
-
'supplemental' => '',
|
354 |
-
'default' => 'yes',
|
355 |
-
'id' => 'ig_es_enable_welcome_email',
|
356 |
-
'name' => __( 'Enable?', 'email-subscribers' ),
|
357 |
-
'desc' => __( 'Send welcome email to new contact after signup.', 'email-subscribers' ),
|
358 |
-
),
|
359 |
-
|
360 |
-
'ig_es_welcome_email_subject' => array(
|
361 |
-
'type' => 'text',
|
362 |
-
'options' => false,
|
363 |
-
'placeholder' => '',
|
364 |
-
'supplemental' => '',
|
365 |
-
'default' => '',
|
366 |
-
'id' => 'ig_es_welcome_email_subject',
|
367 |
-
'name' => __( 'Subject', 'email-subscribers' ),
|
368 |
-
'desc' => '',
|
369 |
-
),
|
370 |
-
'ig_es_welcome_email_content' => array(
|
371 |
-
'type' => 'textarea',
|
372 |
-
'options' => false,
|
373 |
-
'placeholder' => '',
|
374 |
-
'supplemental' => '',
|
375 |
-
'default' => '',
|
376 |
-
'id' => 'ig_es_welcome_email_content',
|
377 |
-
'name' => __( 'Content', 'email-subscribers' ),
|
378 |
-
'desc' => __( 'Available keywords. {{FIRSTNAME}}, {{LASTNAME}}, {{NAME}}, {{EMAIL}}, {{LIST}}, {{UNSUBSCRIBE-LINK}}', 'email-subscribers' ),
|
379 |
-
),
|
380 |
-
)
|
381 |
-
),
|
382 |
-
|
383 |
-
'confirmation_notifications' => array(
|
384 |
-
'id' => 'confirmation_notifications',
|
385 |
-
'name' => __( 'Confirmation Email', 'email-subscribers' ),
|
386 |
-
'sub_fields' => array(
|
387 |
-
|
388 |
-
'ig_es_confirmation_mail_subject' => array(
|
389 |
-
'type' => 'text',
|
390 |
-
'options' => false,
|
391 |
-
'placeholder' => '',
|
392 |
-
'supplemental' => '',
|
393 |
-
'default' => '',
|
394 |
-
'id' => 'ig_es_confirmation_mail_subject',
|
395 |
-
'name' => __( 'Subject', 'email-subscribers' ),
|
396 |
-
'desc' => '',
|
397 |
-
),
|
398 |
-
|
399 |
-
'ig_es_confirmation_mail_content' => array(
|
400 |
-
'type' => 'textarea',
|
401 |
-
'options' => false,
|
402 |
-
'placeholder' => '',
|
403 |
-
'supplemental' => '',
|
404 |
-
'default' => '',
|
405 |
-
'id' => 'ig_es_confirmation_mail_content',
|
406 |
-
'name' => __( 'Content', 'email-subscribers' ),
|
407 |
-
'desc' => __( 'If Double Optin is set, contact will receive confirmation email with above content. You can use {{FIRSTNAME}}, {{LASTNAME}}, {{NAME}}, {{EMAIL}}, {{SUBSCRIBE-LINK}} keywords', 'email-subscribers' ),
|
408 |
-
)
|
409 |
-
)
|
410 |
-
),
|
411 |
-
|
412 |
-
'admin_notifications' => array(
|
413 |
-
|
414 |
-
'id' => 'admin_notifications',
|
415 |
-
'name' => __( 'Admin Notification On New Subscription', 'email-subscribers' ),
|
416 |
-
'sub_fields' => array(
|
417 |
-
|
418 |
-
'notify_admin' => array(
|
419 |
-
'id' => 'ig_es_notify_admin',
|
420 |
-
'name' => __( 'Notify?', 'email-subscribers' ),
|
421 |
-
'type' => 'select',
|
422 |
-
'options' => array(
|
423 |
-
'yes' => __( 'Yes', 'email-subscribers' ),
|
424 |
-
'no' => __( 'No', 'email-subscribers' )
|
425 |
-
),
|
426 |
-
'desc' => __( 'Set this option to "Yes" to notify admin(s) for new contact signup.', 'email-subscribers' ),
|
427 |
-
'default' => 'yes'
|
428 |
-
),
|
429 |
-
|
430 |
-
|
431 |
-
'new_contact_email_subject' => array(
|
432 |
-
'id' => 'ig_es_admin_new_contact_email_subject',
|
433 |
-
'name' => __( 'Subject', 'email-subscribers' ),
|
434 |
-
'type' => 'text',
|
435 |
-
'desc' => __( 'Subject for the admin email whenever a new contact signs up and is confirmed', 'email-subscribers' ),
|
436 |
-
'default' => __( 'New email subscription', 'email-subscribers' )
|
437 |
-
),
|
438 |
-
|
439 |
-
'new_contact_email_content' => array(
|
440 |
-
'id' => 'ig_es_admin_new_contact_email_content',
|
441 |
-
'name' => __( 'Content', 'email-subscribers' ),
|
442 |
-
'type' => 'textarea',
|
443 |
-
'desc' => __( 'Content for the admin email whenever a new subscriber signs up and is confirmed. Available Keywords: {{NAME}}, {{EMAIL}}, {{LIST}}', 'email-subscribers' ),
|
444 |
-
'default' => '',
|
445 |
-
),
|
446 |
-
)
|
447 |
-
),
|
448 |
-
|
449 |
-
'ig_es_cron_report' => array(
|
450 |
-
'id' => 'ig_es_cron_report',
|
451 |
-
'name' => __( 'Admin Notification On Every Campaign Sent', 'email-subscribers' ),
|
452 |
-
'sub_fields' => array(
|
453 |
-
|
454 |
-
'ig_es_enable_cron_admin_email' => array(
|
455 |
-
'id' => 'ig_es_enable_cron_admin_email',
|
456 |
-
'name' => __( 'Notify?', 'email-subscribers' ),
|
457 |
-
'type' => 'select',
|
458 |
-
'options' => array(
|
459 |
-
'yes' => __( 'Yes', 'email-subscribers' ),
|
460 |
-
'no' => __( 'No', 'email-subscribers' )
|
461 |
-
),
|
462 |
-
'desc' => __( 'Set this option to "Yes" to notify admin(s) on every campaign sent.', 'email-subscribers' ),
|
463 |
-
'default' => 'yes'
|
464 |
-
),
|
465 |
-
'ig_es_cron_admin_email_subject' => array(
|
466 |
-
'type' => 'text',
|
467 |
-
'options' => false,
|
468 |
-
'placeholder' => '',
|
469 |
-
'supplemental' => '',
|
470 |
-
'default' => __( 'Campaign Sent!', 'email-subscribers' ),
|
471 |
-
'id' => 'ig_es_cron_admin_email_subject',
|
472 |
-
'name' => __( 'Subject', 'email-subscribers' ),
|
473 |
-
'desc' => '',
|
474 |
-
),
|
475 |
-
|
476 |
-
'ig_es_cron_admin_email' => array(
|
477 |
-
'type' => 'textarea',
|
478 |
-
'options' => false,
|
479 |
-
'placeholder' => '',
|
480 |
-
'supplemental' => '',
|
481 |
-
'default' => '',
|
482 |
-
'id' => 'ig_es_cron_admin_email',
|
483 |
-
'name' => __( 'Content', 'email-subscribers' ),
|
484 |
-
'desc' => __( 'Send report to admin(s) whenever campaign is successfully sent to all contacts. Available Keywords: {{DATE}}, {{SUBJECT}}, {{COUNT}}', 'email-subscribers' ),
|
485 |
-
)
|
486 |
-
|
487 |
-
)
|
488 |
-
)
|
489 |
-
);
|
490 |
-
|
491 |
-
$signup_confirmation_settings = apply_filters( 'ig_es_registered_signup_confirmation_settings', $signup_confirmation_settings );
|
492 |
-
|
493 |
-
$email_sending_settings = array(
|
494 |
-
'ig_es_cronurl' => array(
|
495 |
-
'type' => 'text',
|
496 |
-
'placeholder' => '',
|
497 |
-
'supplemental' => '',
|
498 |
-
'default' => '',
|
499 |
-
'readonly' => 'readonly',
|
500 |
-
'id' => 'ig_es_cronurl',
|
501 |
-
'name' => __( 'Cron URL', 'email-subscribers' ),
|
502 |
-
'desc' => __( sprintf( __( "You need to visit this URL to send email notifications. Know <a href='%s' target='_blank'>how to run this in background</a>", 'email-subscribers' ),
|
503 |
-
"https://www.icegram.com/documentation/es-how-to-schedule-cron-emails-in-cpanel/?utm_source=es&utm_medium=in_app&utm_campaign=view_docs_help_page" ) )
|
504 |
-
),
|
505 |
-
'ig_es_disable_wp_cron' => array(
|
506 |
-
'type' => 'checkbox',
|
507 |
-
'placeholder' => '',
|
508 |
-
'supplemental' => '',
|
509 |
-
'default' => 'no',
|
510 |
-
'id' => 'ig_es_disable_wp_cron',
|
511 |
-
'name' => __( 'Disable WordPress Cron', 'email-subscribers' ),
|
512 |
-
'desc' => __( 'Check this if you do not want Email Subscribers to use WP cron for sending emails', 'email-subscribers' )
|
513 |
-
),
|
514 |
-
|
515 |
-
'ig_es_hourly_email_send_limit' => array(
|
516 |
-
'type' => 'number',
|
517 |
-
'placeholder' => '',
|
518 |
-
'supplemental' => '',
|
519 |
-
'default' => 50,
|
520 |
-
'id' => 'ig_es_hourly_email_send_limit',
|
521 |
-
'name' => __( 'Maximum Emails To Send In An Hour', 'email-subscribers' ),
|
522 |
-
'desc' => __( 'Total emails your host can send in an hour.', 'email-subscribers' )
|
523 |
-
),
|
524 |
-
|
525 |
-
'ig_es_test_send_email' => array(
|
526 |
-
'type' => 'html',
|
527 |
-
'html' => '<input id="es-test-email" type="email"/><input type="submit" name="submit" id="es-send-test" class="button button-primary" value="Send Email"><span class="es_spinner_image_admin" id="spinner-image" style="display:none"><img src="' . ES_PLUGIN_URL . 'lite/public/images/spinner.gif' . '"/></span>',
|
528 |
-
'placeholder' => '',
|
529 |
-
'supplemental' => '',
|
530 |
-
'default' => '',
|
531 |
-
'id' => 'ig_es_test_send_email',
|
532 |
-
'name' => __( 'Send Test Email', 'email-subscribers' ),
|
533 |
-
'desc' => __( 'Enter email address to send test email.', 'email-subscribers' )
|
534 |
-
),
|
535 |
-
|
536 |
-
'ig_es_mailer_settings' => array(
|
537 |
-
'type' => 'html',
|
538 |
-
// 'html' => ES_Admin_Settings::mailers_html(),
|
539 |
-
'sub_fields' => array(
|
540 |
-
'mailer' => array(
|
541 |
-
'id' => 'ig_es_mailer_settings[mailer]',
|
542 |
-
'name' => __( 'Select Mailer', 'email-subscribers' ),
|
543 |
-
'type' => 'html',
|
544 |
-
'html' => ES_Admin_Settings::mailers_html(),
|
545 |
-
'desc' => '',
|
546 |
-
),
|
547 |
-
'ig_es_pepipost_api_key' => array(
|
548 |
-
'type' => 'password',
|
549 |
-
'options' => false,
|
550 |
-
'placeholder' => '',
|
551 |
-
'supplemental' => '',
|
552 |
-
'default' => '',
|
553 |
-
'id' => "ig_es_mailer_settings[pepipost][api_key]",
|
554 |
-
'name' => __( 'Pepipost API key', 'email-subscribers' ),
|
555 |
-
'desc' => '',
|
556 |
-
'class' => 'pepipost'
|
557 |
-
),
|
558 |
-
'ig_es_pepipost_docblock' => array(
|
559 |
-
'type' => 'html',
|
560 |
-
'html' => ES_Admin_Settings::pepipost_doc_block(),
|
561 |
-
'id' => 'ig_es_pepipost_docblock',
|
562 |
-
// 'class' => 'ig_es_docblock',
|
563 |
-
'name' => ''
|
564 |
-
)
|
565 |
-
|
566 |
-
),
|
567 |
-
'placeholder' => '',
|
568 |
-
'supplemental' => '',
|
569 |
-
'default' => '',
|
570 |
-
'id' => 'ig_es_mailer_settings',
|
571 |
-
'name' => __( 'Select a mailer to send mail', 'email-subscribers' ),
|
572 |
-
'desc' => ''
|
573 |
-
)
|
574 |
-
);
|
575 |
-
|
576 |
-
$email_sending_settings = apply_filters( 'ig_es_registered_email_sending_settings', $email_sending_settings );
|
577 |
-
|
578 |
-
$security_settings = array(
|
579 |
-
'blocked_domains' => array(
|
580 |
-
'id' => 'ig_es_blocked_domains',
|
581 |
-
'name' => __( 'Blocked Domain(s)', 'email-subscribers' ),
|
582 |
-
'type' => 'textarea',
|
583 |
-
'info' => __( 'Seeing spam signups from particular domains? Enter domains names (one per line) that you want to block here.', 'email-subscribers' ),
|
584 |
-
'default' => ''
|
585 |
-
),
|
586 |
-
|
587 |
-
);
|
588 |
-
|
589 |
-
$security_settings = apply_filters( 'ig_es_registered_security_settings', $security_settings );
|
590 |
-
|
591 |
-
$es_settings = array(
|
592 |
-
'general' => $general_settings,
|
593 |
-
'signup_confirmation' => $signup_confirmation_settings,
|
594 |
-
'email_sending' => $email_sending_settings,
|
595 |
-
'security_settings' => $security_settings
|
596 |
-
);
|
597 |
-
|
598 |
-
return apply_filters( 'ig_es_registered_settings', $es_settings );
|
599 |
-
}
|
600 |
-
|
601 |
-
public function field_callback( $arguments, $id_key = '' ) {
|
602 |
-
$field_html = '';
|
603 |
-
if ( 'ig_es_cronurl' === $arguments['id'] ) {
|
604 |
-
$value = ES()->cron->url();
|
605 |
-
} else {
|
606 |
-
if ( ! empty( $arguments['option_value'] ) ) {
|
607 |
-
preg_match( "(\[.*$)", $arguments['id'], $m );
|
608 |
-
$n = explode( '][', $m[0] );
|
609 |
-
$n = str_replace( '[', '', $n );
|
610 |
-
$n = str_replace( ']', '', $n );
|
611 |
-
$count = count( $n );
|
612 |
-
$id = '';
|
613 |
-
foreach ( $n as $key => $val ) {
|
614 |
-
if ( $id == '' ) {
|
615 |
-
$id = ! empty( $arguments['option_value'][ $val ] ) ? $arguments['option_value'][ $val ] : '';
|
616 |
-
} else {
|
617 |
-
$id = $id[ $val ];
|
618 |
-
}
|
619 |
-
}
|
620 |
-
$value = $id;
|
621 |
-
} else {
|
622 |
-
$value = get_option( $arguments['id'] ); // Get the current value, if there is one
|
623 |
-
}
|
624 |
-
}
|
625 |
-
|
626 |
-
if ( ! $value ) { // If no value exists
|
627 |
-
$value = ! empty( $arguments['default'] ) ? $arguments['default'] : ''; // Set to our default
|
628 |
-
}
|
629 |
-
|
630 |
-
$uid = ! empty( $arguments['id'] ) ? $arguments['id'] : '';
|
631 |
-
$type = ! empty( $arguments['type'] ) ? $arguments['type'] : '';
|
632 |
-
$placeholder = ! empty( $arguments['placeholder'] ) ? $arguments['placeholder'] : '';
|
633 |
-
$readonly = ! empty( $arguments['readonly'] ) ? $arguments['readonly'] : '';
|
634 |
-
$html = ! empty( $arguments['html'] ) ? $arguments['html'] : '';
|
635 |
-
$id_key = ! empty( $id_key ) ? $id_key : $uid;
|
636 |
-
$class = ! empty( $arguments['class'] ) ? $arguments['class'] : '';
|
637 |
-
// Check which type of field we want
|
638 |
-
switch ( $arguments['type'] ) {
|
639 |
-
case 'password':
|
640 |
-
case 'text': // If it is a text field
|
641 |
-
$field_html = sprintf( '<input name="%1$s" id="%2$s" type="%3$s" placeholder="%4$s" value="%5$s" %6$s class="%7$s"/>', $uid, $id_key, $type, $placeholder, $value, $readonly, $class );
|
642 |
-
break;
|
643 |
-
case 'number': // If it is a number field
|
644 |
-
$field_html = sprintf( '<input name="%1$s" id="%1$s" type="%2$s" placeholder="%3$s" value="%4$s" %5$s min="0"/>', $uid, $type, $placeholder, $value, $readonly );
|
645 |
-
case 'password': // If it is a text field
|
646 |
-
$field_html = sprintf( '<input name="%1$s" id="%2$s" type="%3$s" placeholder="%4$s" value="%5$s" %6$s class="%7$s" />', $uid, $id_key, $type, $placeholder, $value, $readonly, $class );
|
647 |
-
break;
|
648 |
-
|
649 |
-
case 'email':
|
650 |
-
$field_html = sprintf( '<input name="%1$s" id="%2$s" type="%3$s" placeholder="%4$s" value="%5$s" class="%6$s"/>', $uid, $id_key, $type, $placeholder, $value, $class );
|
651 |
-
break;
|
652 |
-
|
653 |
-
case 'textarea':
|
654 |
-
$field_html = sprintf( '<textarea name="%1$s" id="%2$s" placeholder="%3$s" size="100" rows="12" cols="58" class="%5$s">%4$s</textarea>',
|
655 |
-
$uid, $id_key, $placeholder, $value, $class );
|
656 |
-
break;
|
657 |
-
case 'file':
|
658 |
-
$field_html = '<input type="text" id="logo_url" name="' . $uid . '" value="' . $value . '" class="' . $class . '"/> <input id="upload_logo_button" type="button" class="button" value="Upload Logo" />';
|
659 |
-
break;
|
660 |
-
case 'checkbox' :
|
661 |
-
$field_html = '<input id="' . $id_key . '" type="checkbox" name="' . $uid . '" value="yes" ' . checked( $value, 'yes', false ) . ' class="' . $class . '" />' . $placeholder . '</input>';
|
662 |
-
break;
|
663 |
-
|
664 |
-
case 'select':
|
665 |
-
if ( ! empty ( $arguments['options'] ) && is_array( $arguments['options'] ) ) {
|
666 |
-
$options_markup = "";
|
667 |
-
foreach ( $arguments['options'] as $key => $label ) {
|
668 |
-
$options_markup .= sprintf( '<option value="%s" %s>%s</option>', $key,
|
669 |
-
selected( $value, $key, false ), $label );
|
670 |
-
}
|
671 |
-
$field_html = sprintf( '<select name="%1$s" id="%2$s" class="%4$s">%3$s</select>', $uid, $id_key, $options_markup, $class );
|
672 |
-
}
|
673 |
-
break;
|
674 |
-
case 'html' :
|
675 |
-
default:
|
676 |
-
$field_html = $html;
|
677 |
-
break;
|
678 |
-
}
|
679 |
-
|
680 |
-
$field_html .= '<br />';
|
681 |
-
|
682 |
-
//If there is help text
|
683 |
-
if ( ! empty( $arguments['desc'] ) ) {
|
684 |
-
$helper = $arguments['desc'];
|
685 |
-
$field_html .= sprintf( '<span class="helper"> %s</span>', $helper ); // Show it
|
686 |
-
}
|
687 |
-
|
688 |
-
return $field_html;
|
689 |
-
}
|
690 |
-
|
691 |
-
public static function get_instance() {
|
692 |
-
if ( ! isset( self::$instance ) ) {
|
693 |
-
self::$instance = new self();
|
694 |
-
}
|
695 |
-
|
696 |
-
return self::$instance;
|
697 |
-
}
|
698 |
-
|
699 |
-
public static function es_get_all_settings() {
|
700 |
-
|
701 |
-
global $wpdb;
|
702 |
-
|
703 |
-
$condition = 'ig_es';
|
704 |
-
$get_all_es_settings_from_options = $wpdb->prepare( "SELECT option_name, option_value
|
705 |
-
FROM {$wpdb->prefix}options
|
706 |
-
WHERE option_name LIKE %s", $wpdb->esc_like( $condition ) . '%' );
|
707 |
-
$result = $wpdb->get_results( $get_all_es_settings_from_options, ARRAY_A );
|
708 |
-
|
709 |
-
$settings = array();
|
710 |
-
|
711 |
-
if ( ! empty( $result ) ) {
|
712 |
-
foreach ( $result as $index => $data ) {
|
713 |
-
$settings[ $data['option_name'] ] = $data['option_value'];
|
714 |
-
}
|
715 |
-
}
|
716 |
-
|
717 |
-
return $settings;
|
718 |
-
}
|
719 |
-
|
720 |
-
function render_settings_fields( $fields ) {
|
721 |
-
|
722 |
-
$html = "<table class='form-table'>";
|
723 |
-
$html .= "<tbody>";
|
724 |
-
$button_html = '';
|
725 |
-
foreach ( $fields as $key => $field ) {
|
726 |
-
if ( ! empty( $field['name'] ) ) {
|
727 |
-
$html .= "<tr><th scope='row'>";
|
728 |
-
$html .= $field['name'];
|
729 |
-
|
730 |
-
//If there is help text
|
731 |
-
if ( ! empty( $field['info'] ) ) {
|
732 |
-
$helper = $field['info'];
|
733 |
-
$html .= "<br />" . sprintf( '<span class="helper">%s</span>', $helper ); // Show it
|
734 |
-
}
|
735 |
-
$button_html = "<tr><td></td>";
|
736 |
-
|
737 |
-
$html .= "</th>";
|
738 |
-
}
|
739 |
-
|
740 |
-
$html .= "<td>";
|
741 |
-
if ( ! empty( $field['sub_fields'] ) ) {
|
742 |
-
$option_key = '';
|
743 |
-
foreach ( $field['sub_fields'] as $key => $sub_field ) {
|
744 |
-
if ( strpos( $sub_field['id'], '[' ) ) {
|
745 |
-
$parts = explode( '[', $sub_field['id'] );
|
746 |
-
if ( $option_key !== $parts[0] ) {
|
747 |
-
$option_value = get_option( $parts[0] );
|
748 |
-
$option_key = $parts[0];
|
749 |
-
}
|
750 |
-
$sub_field['option_value'] = is_array( $option_value ) ? $option_value : '';
|
751 |
-
}
|
752 |
-
$class = ( ! empty( $sub_field['class'] ) ) ? $sub_field['class'] : "";
|
753 |
-
$html .= ( $sub_field !== reset( $field['sub_fields'] ) ) ? '<br/>' : '';
|
754 |
-
$html .= '<div class="es_sub_headline ' . $class . '" ><strong>' . $sub_field['name'] . '</strong></div>';
|
755 |
-
$html .= $this->field_callback( $sub_field, $key );
|
756 |
-
}
|
757 |
-
} else {
|
758 |
-
$html .= $this->field_callback( $field );
|
759 |
-
}
|
760 |
-
|
761 |
-
$html .= "</td></tr>";
|
762 |
-
}
|
763 |
-
|
764 |
-
$button_html = empty( $button_html ) ? "<tr>" : $button_html;
|
765 |
-
|
766 |
-
$nonce_field = wp_nonce_field( 'update-settings', 'update-settings', true, false );
|
767 |
-
|
768 |
-
$html .= $button_html . "<td class='es-settings-submit-btn'>";
|
769 |
-
$html .= '<input type="hidden" name="submitted" value="submitted"/>';
|
770 |
-
$html .= '<input type="hidden" name="submit_action" value="ig-es-save-admin-settings"/>';
|
771 |
-
//$html .= '<input type="hidden" name="update-settings" id="update-settings" value="' . $nonce . '"/>';
|
772 |
-
$html .= $nonce_field;
|
773 |
-
$html .= '<input type="submit" name="submit" id="submit" class="button button-primary" value="' . __( 'Save Settings', 'email-subscribers' ) . '">';
|
774 |
-
$html .= "</td></tr>";
|
775 |
-
$html .= "</tbody>";
|
776 |
-
$html .= "</table>";
|
777 |
-
echo $html;
|
778 |
-
|
779 |
-
}
|
780 |
-
|
781 |
-
public static function mailers_html() {
|
782 |
-
$html = '';
|
783 |
-
$es_email_type = get_option( 'ig_es_email_type' );
|
784 |
-
$selected_mailer_settings = get_option( 'ig_es_mailer_settings' );
|
785 |
-
$selected_mailer = $selected_mailer_settings['mailer'];
|
786 |
-
$default_mailer = ( $es_email_type === 'php_html_mail' || $es_email_type === 'php_plaintext_mail' || $selected_mailer === 'phpmail' ) ? 'phpmail' : $selected_mailer;
|
787 |
-
$pepipost_doc_block = '';
|
788 |
-
$mailers = array(
|
789 |
-
'wpmail' => array( 'name' => 'WP Mail', 'logo' => ES_PLUGIN_URL . 'lite/admin/images/wpmail.png' ),
|
790 |
-
'phpmail' => array( 'name' => 'PHP mail', 'logo' => ES_PLUGIN_URL . 'lite/admin/images/phpmail.png' ),
|
791 |
-
'pepipost' => array( 'name' => 'Pepipost', 'logo' => ES_PLUGIN_URL . 'lite/admin/images/pepipost.png', 'docblock' => $pepipost_doc_block ),
|
792 |
-
);
|
793 |
-
$mailers = apply_filters( 'ig_es_mailers', $mailers );
|
794 |
-
$default_mailer = ( array_key_exists( $default_mailer, $mailers ) ) ? $default_mailer : 'wpmail';
|
795 |
-
foreach ( $mailers as $key => $mailer ) {
|
796 |
-
$class = ( $key === 'pepipost' ) ? 'es_recommended' : '';
|
797 |
-
$html .= '<label><div class="es-mailer-logo ' . $class . '"><div class="es-logo-wrapper"><img src="' . $mailer['logo'] . '" alt="Default (none)"></div>';
|
798 |
-
$html .= '<input type="radio" class="es_mailer" name="ig_es_mailer_settings[mailer]" value="' . $key . '" ' . checked( $default_mailer, $key, false ) . '>' . $mailer['name'] . '</input></div></label>';
|
799 |
-
}
|
800 |
-
|
801 |
-
return $html;
|
802 |
-
|
803 |
-
}
|
804 |
-
|
805 |
-
public static function pepipost_doc_block() {
|
806 |
-
$html = '';
|
807 |
-
ob_start();
|
808 |
-
?>
|
809 |
-
<div class="es_sub_headline ig_es_docblock ig_es_pepipost_div_wrapper pepipost">
|
810 |
-
<ul>
|
811 |
-
<li><a class="" href="https://app.pepipost.com/index.php/signup/icegram?fpr=icegram" target="_blank"><?php _e( 'Signup for Pepipost', 'email-subscribers' ) ?></a></li>
|
812 |
-
<li><?php _e( 'How to find', 'email-subscribers' ) ?> <a href="https://developers.pepipost.com/api/getstarted/overview?utm_source=icegram&utm_medium=es_inapp&utm_campaign=pepipost" target="_blank"> <?php _e( 'Pepipost API key', 'email-subscribers' ) ?></a></li>
|
813 |
-
<li><a href="https://www.icegram.com/email-subscribers-integrates-with-pepipost?utm_source=es_inapp&utm_medium=es_upsale&utm_campaign=upsale" target="_blank"><?php _e( 'Why to choose Pepipost' ) ?></a></li>
|
814 |
-
</ul>
|
815 |
-
</div>
|
816 |
-
|
817 |
-
<?php
|
818 |
-
|
819 |
-
$html = ob_get_clean();
|
820 |
-
|
821 |
-
return $html;
|
822 |
-
}
|
823 |
-
|
824 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-campaigns-table.php
DELETED
@@ -1,433 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
if ( ! class_exists( 'WP_List_Table' ) ) {
|
9 |
-
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
10 |
-
}
|
11 |
-
|
12 |
-
class ES_Campaigns_Table extends WP_List_Table {
|
13 |
-
/**
|
14 |
-
* @since 4.2.1
|
15 |
-
* @var string
|
16 |
-
*
|
17 |
-
*/
|
18 |
-
public static $option_per_page = 'es_campaigns_per_page';
|
19 |
-
|
20 |
-
/**
|
21 |
-
* ES_Campaigns_Table constructor.
|
22 |
-
*
|
23 |
-
* @since 4.0
|
24 |
-
*/
|
25 |
-
public function __construct() {
|
26 |
-
|
27 |
-
parent::__construct( array(
|
28 |
-
'singular' => __( 'Campaign', 'email-subscribers' ), //singular name of the listed records
|
29 |
-
'plural' => __( 'Campaign', 'email-subscribers' ), //plural name of the listed records
|
30 |
-
'ajax' => false, //does this table support ajax?
|
31 |
-
'screen' => 'es_campaigns'
|
32 |
-
) );
|
33 |
-
}
|
34 |
-
|
35 |
-
/**
|
36 |
-
* Add Screen Option
|
37 |
-
*
|
38 |
-
* @since 4.2.1
|
39 |
-
*/
|
40 |
-
public static function screen_options() {
|
41 |
-
|
42 |
-
$option = 'per_page';
|
43 |
-
$args = array(
|
44 |
-
'label' => __( 'Number of campaigns per page', 'email-subscribers' ),
|
45 |
-
'default' => 20,
|
46 |
-
'option' => self::$option_per_page
|
47 |
-
);
|
48 |
-
|
49 |
-
add_screen_option( $option, $args );
|
50 |
-
|
51 |
-
}
|
52 |
-
|
53 |
-
/**
|
54 |
-
* Render Campaigns table
|
55 |
-
*
|
56 |
-
* @since 4.0
|
57 |
-
*/
|
58 |
-
public function render() {
|
59 |
-
$action = ig_es_get_request_data( 'action' );
|
60 |
-
|
61 |
-
?>
|
62 |
-
<div class="wrap">
|
63 |
-
<h1 class="wp-heading-inline"><?php _e( 'Campaigns', 'email-subscribers' ) ?>
|
64 |
-
<a href="admin.php?page=es_notifications&action=new" class="page-title-action"><?php _e( 'Create Post Notification', 'email-subscribers' ) ?></a>
|
65 |
-
<a href="admin.php?page=es_newsletters" class="page-title-action"><?php _e( 'Send Broadcast', 'email-subscribers' ) ?></a>
|
66 |
-
<?php do_action( 'ig_es_after_campaign_type_buttons' ) ?>
|
67 |
-
<a href="edit.php?post_type=es_template" class="page-title-action es-imp-button"><?php _e( 'Manage Templates', 'email-subscribers' ) ?></a>
|
68 |
-
</h1>
|
69 |
-
<?php Email_Subscribers_Admin::es_feedback(); ?>
|
70 |
-
<div id="poststuff">
|
71 |
-
<div id="post-body" class="metabox-holder column-1">
|
72 |
-
<div id="post-body-content">
|
73 |
-
<div class="meta-box-sortables ui-sortable">
|
74 |
-
<form method="post">
|
75 |
-
<?php
|
76 |
-
$this->prepare_items();
|
77 |
-
$this->display(); ?>
|
78 |
-
</form>
|
79 |
-
</div>
|
80 |
-
</div>
|
81 |
-
</div>
|
82 |
-
<br class="clear">
|
83 |
-
</div>
|
84 |
-
</div>
|
85 |
-
<?php
|
86 |
-
}
|
87 |
-
|
88 |
-
public function custom_admin_notice() {
|
89 |
-
$es_note_cat = ig_es_get_request_data( 'es_note_cat' );
|
90 |
-
|
91 |
-
if ( $es_note_cat ) {
|
92 |
-
echo '<div class="updated"><p>Notification Added Successfully!</p></div>';
|
93 |
-
}
|
94 |
-
}
|
95 |
-
|
96 |
-
/**
|
97 |
-
* Retrieve lists data from the database
|
98 |
-
*
|
99 |
-
* @param int $per_page
|
100 |
-
* @param int $page_number
|
101 |
-
*
|
102 |
-
* @return mixed
|
103 |
-
*/
|
104 |
-
public static function get_lists( $per_page = 5, $page_number = 1, $do_count_only = false ) {
|
105 |
-
|
106 |
-
global $wpdb;
|
107 |
-
|
108 |
-
$order_by = sanitize_sql_orderby( ig_es_get_request_data( 'orderby' ) );
|
109 |
-
$order = ig_es_get_request_data( 'order' );
|
110 |
-
$search = ig_es_get_request_data( 's' );
|
111 |
-
|
112 |
-
if ( $do_count_only ) {
|
113 |
-
$sql = "SELECT count(*) as total FROM " . IG_CAMPAIGNS_TABLE;
|
114 |
-
} else {
|
115 |
-
$sql = "SELECT * FROM " . IG_CAMPAIGNS_TABLE;
|
116 |
-
}
|
117 |
-
|
118 |
-
$args = $query = array();
|
119 |
-
$add_where_clause = true;
|
120 |
-
|
121 |
-
$query[] = "( deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00' )";
|
122 |
-
|
123 |
-
|
124 |
-
if ( ! empty( $search ) ) {
|
125 |
-
$query[] = " name LIKE %s ";
|
126 |
-
$args[] = "%" . $wpdb->esc_like( $search ) . "%";
|
127 |
-
}
|
128 |
-
|
129 |
-
$query = apply_filters( 'ig_es_campaign_list_where_caluse', $query );
|
130 |
-
|
131 |
-
if ( $add_where_clause ) {
|
132 |
-
$sql .= " WHERE ";
|
133 |
-
|
134 |
-
if ( count( $query ) > 0 ) {
|
135 |
-
$sql .= implode( " AND ", $query );
|
136 |
-
|
137 |
-
if ( count( $args ) > 0 ) {
|
138 |
-
$sql = $wpdb->prepare( $sql, $args );
|
139 |
-
}
|
140 |
-
}
|
141 |
-
}
|
142 |
-
|
143 |
-
if ( ! $do_count_only ) {
|
144 |
-
|
145 |
-
$order = ! empty( $order ) ? strtolower( $order ) : 'desc';
|
146 |
-
$expected_order_values = array( 'asc', 'desc' );
|
147 |
-
if ( ! in_array( $order, $expected_order_values ) ) {
|
148 |
-
$order = 'desc';
|
149 |
-
}
|
150 |
-
|
151 |
-
$default_order_by = esc_sql( 'created_at' );
|
152 |
-
|
153 |
-
$expected_order_by_values = array( 'base_template_id', 'type' );
|
154 |
-
if ( ! in_array( $order_by, $expected_order_by_values ) ) {
|
155 |
-
$order_by_clause = " ORDER BY {$default_order_by} DESC";
|
156 |
-
} else {
|
157 |
-
$order_by = esc_sql( $order_by );
|
158 |
-
$order_by_clause = " ORDER BY {$order_by} {$order}, {$default_order_by} DESC";
|
159 |
-
}
|
160 |
-
|
161 |
-
$sql .= $order_by_clause;
|
162 |
-
$sql .= " LIMIT $per_page";
|
163 |
-
$sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page;
|
164 |
-
|
165 |
-
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
|
166 |
-
} else {
|
167 |
-
$result = $wpdb->get_var( $sql );
|
168 |
-
}
|
169 |
-
|
170 |
-
return $result;
|
171 |
-
}
|
172 |
-
|
173 |
-
/**
|
174 |
-
* Text Display when no items available
|
175 |
-
*
|
176 |
-
* @since 4.0
|
177 |
-
*/
|
178 |
-
public function no_items() {
|
179 |
-
_e( 'No Campaigns Found.', 'email-subscribers' );
|
180 |
-
}
|
181 |
-
|
182 |
-
/**
|
183 |
-
* Render a column when no column specific method exist.
|
184 |
-
*
|
185 |
-
* @param array $item
|
186 |
-
* @param string $column_name
|
187 |
-
*
|
188 |
-
* @return mixed
|
189 |
-
*/
|
190 |
-
public function column_default( $item, $column_name ) {
|
191 |
-
switch ( $column_name ) {
|
192 |
-
|
193 |
-
case 'list_ids':
|
194 |
-
if ( ! empty( $item[ $column_name ] ) ) {
|
195 |
-
return ES()->lists_db->get_list_id_name_map( $item[ $column_name ] );
|
196 |
-
} else {
|
197 |
-
return '-';
|
198 |
-
}
|
199 |
-
break;
|
200 |
-
case 'status':
|
201 |
-
$status = ( $item[ $column_name ] == 1 ) ? __( 'Active', 'email-subscribers' ) : __( 'Inactive', 'email-subscribers' );
|
202 |
-
|
203 |
-
return $status;
|
204 |
-
|
205 |
-
break;
|
206 |
-
case 'type':
|
207 |
-
$type = ( $item[ $column_name ] === 'newsletter' ) ? __( 'Broadcast', 'email-subscribers' ) : $item[ $column_name ];
|
208 |
-
$type = ucwords( str_replace( '_', ' ', $type ) );
|
209 |
-
|
210 |
-
return $type;
|
211 |
-
break;
|
212 |
-
case 'categories':
|
213 |
-
if ( ! empty( $item[ $column_name ] ) ) {
|
214 |
-
$categories = ES_Common::convert_categories_string_to_array( $item[ $column_name ], false );
|
215 |
-
$categories = strpos( $item[ $column_name ], '{a}All{a}' ) ? __( 'All', 'email-subscribers' ) : trim( trim( implode( ', ', $categories ) ), ',' );
|
216 |
-
|
217 |
-
return $categories;
|
218 |
-
} else {
|
219 |
-
return '-';
|
220 |
-
}
|
221 |
-
break;
|
222 |
-
default:
|
223 |
-
return $item[ $column_name ];
|
224 |
-
}
|
225 |
-
}
|
226 |
-
|
227 |
-
/**
|
228 |
-
* Render the bulk edit checkbox
|
229 |
-
*
|
230 |
-
* @param array $item
|
231 |
-
*
|
232 |
-
* @return string
|
233 |
-
*/
|
234 |
-
function column_cb( $item ) {
|
235 |
-
return sprintf(
|
236 |
-
'<input type="checkbox" name="campaigns[]" value="%s" />', $item['id']
|
237 |
-
);
|
238 |
-
}
|
239 |
-
|
240 |
-
/**
|
241 |
-
* Method for name column
|
242 |
-
*
|
243 |
-
* @param array $item an array of DB data
|
244 |
-
*
|
245 |
-
* @return string
|
246 |
-
*/
|
247 |
-
function column_base_template_id( $item ) {
|
248 |
-
|
249 |
-
$type = $item['type'];
|
250 |
-
|
251 |
-
|
252 |
-
$nonce = wp_create_nonce( 'es_post_notification' );
|
253 |
-
|
254 |
-
if ( $type !== 'newsletter' ) {
|
255 |
-
|
256 |
-
$template = get_post( $item['base_template_id'] );
|
257 |
-
|
258 |
-
if ( $template instanceof WP_Post ) {
|
259 |
-
$title = '<strong>' . $template->post_title . '</strong>';
|
260 |
-
} else {
|
261 |
-
$title = ! empty( $item['name'] ) ? $item['name'] : '';
|
262 |
-
}
|
263 |
-
|
264 |
-
$slug = ( in_array( $item['type'], array( 'post_notification', 'post_digest' ) ) ) ? esc_attr( 'es_notifications' ) : 'es_' . $item['type'];
|
265 |
-
|
266 |
-
$actions ['edit'] = sprintf( __( '<a href="?page=%s&action=%s&list=%s&_wpnonce=%s">Edit</a>', 'email-subscribers' ), $slug, 'edit', absint( $item['id'] ), $nonce );
|
267 |
-
$actions['delete'] = sprintf( __( '<a href="?page=%s&action=%s&list=%s&_wpnonce=%s" onclick="return checkDelete()">Delete</a>', 'email-subscribers' ), esc_attr( 'es_campaigns' ), 'delete', absint( $item['id'] ), $nonce );
|
268 |
-
|
269 |
-
$title .= $this->row_actions( $actions );
|
270 |
-
} else {
|
271 |
-
$title = $item['name'];
|
272 |
-
}
|
273 |
-
|
274 |
-
return $title;
|
275 |
-
}
|
276 |
-
|
277 |
-
|
278 |
-
/**
|
279 |
-
* Associative array of columns
|
280 |
-
*
|
281 |
-
* @return array
|
282 |
-
*/
|
283 |
-
function get_columns() {
|
284 |
-
$columns = array(
|
285 |
-
'cb' => '<input type="checkbox" />',
|
286 |
-
'base_template_id' => __( 'Name', 'email-subscribers' ),
|
287 |
-
'type' => __( 'Type', 'email-subscribers' ),
|
288 |
-
'list_ids' => __( 'List', 'email-subscribers' ),
|
289 |
-
'categories' => __( 'Categories', 'email-subscribers' ),
|
290 |
-
'status' => __( 'Status', 'email-subscribers' )
|
291 |
-
);
|
292 |
-
|
293 |
-
return $columns;
|
294 |
-
}
|
295 |
-
|
296 |
-
|
297 |
-
/**
|
298 |
-
* Columns to make sortable.
|
299 |
-
*
|
300 |
-
* @return array
|
301 |
-
*/
|
302 |
-
public function get_sortable_columns() {
|
303 |
-
$sortable_columns = array(
|
304 |
-
//'base_template_id' => array( 'base_template_id', true ),
|
305 |
-
//'list_ids' => array( 'list_ids', true ),
|
306 |
-
//'status' => array( 'status', true )
|
307 |
-
'type' => array( 'type', true )
|
308 |
-
);
|
309 |
-
|
310 |
-
return $sortable_columns;
|
311 |
-
}
|
312 |
-
|
313 |
-
/**
|
314 |
-
* Returns an associative array containing the bulk action
|
315 |
-
*
|
316 |
-
* @return array
|
317 |
-
*/
|
318 |
-
public function get_bulk_actions() {
|
319 |
-
$actions = array(
|
320 |
-
'bulk_delete' => 'Delete'
|
321 |
-
);
|
322 |
-
|
323 |
-
return $actions;
|
324 |
-
}
|
325 |
-
|
326 |
-
public function search_box( $text, $input_id ) { ?>
|
327 |
-
<p class="search-box">
|
328 |
-
<label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
|
329 |
-
<input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>"/>
|
330 |
-
<?php submit_button( __( 'Search Campaigns', 'email-subscribers' ), 'button', false, false, array( 'id' => 'search-submit' ) ); ?>
|
331 |
-
</p>
|
332 |
-
<?php }
|
333 |
-
|
334 |
-
/**
|
335 |
-
* Handles data query and filter, sorting, and pagination.
|
336 |
-
*/
|
337 |
-
public function prepare_items() {
|
338 |
-
|
339 |
-
$this->_column_headers = $this->get_column_info();
|
340 |
-
|
341 |
-
/** Process bulk action */
|
342 |
-
$this->process_bulk_action();
|
343 |
-
|
344 |
-
// Note: Disable Search box for now.
|
345 |
-
$search = ig_es_get_request_data( 's' );
|
346 |
-
$this->search_box( $search, 'notification-search-input' );
|
347 |
-
|
348 |
-
$per_page = $this->get_items_per_page( self::$option_per_page, 25 );
|
349 |
-
|
350 |
-
$current_page = $this->get_pagenum();
|
351 |
-
$total_items = $this->get_lists( 0, 0, true );
|
352 |
-
|
353 |
-
$this->set_pagination_args( array(
|
354 |
-
'total_items' => $total_items, //We have to calculate the total number of items
|
355 |
-
'per_page' => $per_page //We have to determine how many items to show on a page
|
356 |
-
) );
|
357 |
-
|
358 |
-
$this->items = $this->get_lists( $per_page, $current_page );
|
359 |
-
}
|
360 |
-
|
361 |
-
public function process_bulk_action() {
|
362 |
-
|
363 |
-
if ( 'delete' === $this->current_action() ) {
|
364 |
-
|
365 |
-
// In our file that handles the request, verify the nonce.
|
366 |
-
$nonce = ig_es_get_request_data( '_wpnonce' );
|
367 |
-
|
368 |
-
if ( ! wp_verify_nonce( $nonce, 'es_post_notification' ) ) {
|
369 |
-
$message = __( 'You are not allowed to delete campaign.', 'email-subscribers' );
|
370 |
-
$status = 'error';
|
371 |
-
} else {
|
372 |
-
$list = ig_es_get_request_data( 'list' );
|
373 |
-
$this->delete_list( array( $list ) );
|
374 |
-
$message = __( 'Campaign has been deleted successfully!', 'email-subscribers' );
|
375 |
-
$status = 'success';
|
376 |
-
}
|
377 |
-
|
378 |
-
ES_Common::show_message( $message, $status );
|
379 |
-
}
|
380 |
-
|
381 |
-
$action = ig_es_get_request_data( 'action' );
|
382 |
-
$action2 = ig_es_get_request_data( 'action2' );
|
383 |
-
// If the delete bulk action is triggered
|
384 |
-
if ( ( 'bulk_delete' === $action ) || ( 'bulk_delete' === $action2 ) ) {
|
385 |
-
|
386 |
-
$ids = ig_es_get_request_data( 'campaigns' );
|
387 |
-
|
388 |
-
if ( is_array( $ids ) && count( $ids ) > 0 ) {
|
389 |
-
|
390 |
-
$deleted = $this->delete_list( $ids );
|
391 |
-
|
392 |
-
if ( $deleted ) {
|
393 |
-
$message = __( 'Campaign(s) have been deleted successfully!', 'email-subscribers' );
|
394 |
-
ES_Common::show_message( $message );
|
395 |
-
}
|
396 |
-
} else {
|
397 |
-
|
398 |
-
$message = __( 'Please check campaign(s) to delete.', 'email-subscribers' );
|
399 |
-
ES_Common::show_message( $message, 'error' );
|
400 |
-
}
|
401 |
-
|
402 |
-
|
403 |
-
}
|
404 |
-
}
|
405 |
-
|
406 |
-
/**
|
407 |
-
* Delete a list record.
|
408 |
-
*
|
409 |
-
* @param int $id list ID
|
410 |
-
*/
|
411 |
-
public function delete_list( $ids ) {
|
412 |
-
global $wpdb;
|
413 |
-
|
414 |
-
if ( is_array( $ids ) && count( $ids ) > 0 ) {
|
415 |
-
|
416 |
-
$campaigns_table = IG_CAMPAIGNS_TABLE;
|
417 |
-
|
418 |
-
$ids = implode( ',', array_map( 'absint', $ids ) );
|
419 |
-
|
420 |
-
$current_date = gmdate( 'Y-m-d G:i:s' );
|
421 |
-
$query = "UPDATE {$campaigns_table} SET deleted_at = %s WHERE id IN ($ids)";
|
422 |
-
$query = $wpdb->prepare( $query, array( $current_date ) );
|
423 |
-
$result = $wpdb->query( $query );
|
424 |
-
|
425 |
-
if ( $result ) {
|
426 |
-
return true;
|
427 |
-
}
|
428 |
-
}
|
429 |
-
|
430 |
-
return false;
|
431 |
-
}
|
432 |
-
|
433 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-contacts-table.php
DELETED
@@ -1,1101 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
if ( ! class_exists( 'WP_List_Table' ) ) {
|
9 |
-
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
10 |
-
}
|
11 |
-
|
12 |
-
class ES_Contacts_Table extends WP_List_Table {
|
13 |
-
/**
|
14 |
-
* @since 4.0.0
|
15 |
-
* @var array
|
16 |
-
*
|
17 |
-
*/
|
18 |
-
public $contact_lists_statuses = array();
|
19 |
-
|
20 |
-
/**
|
21 |
-
* @since 4.2.1
|
22 |
-
*
|
23 |
-
* @var string
|
24 |
-
*/
|
25 |
-
public static $option_per_page = 'es_contacts_per_page';
|
26 |
-
|
27 |
-
/**
|
28 |
-
* @since 4.0.0
|
29 |
-
* @var array
|
30 |
-
*
|
31 |
-
*/
|
32 |
-
public $list_ids = array();
|
33 |
-
|
34 |
-
/**
|
35 |
-
* @since 4.0.0
|
36 |
-
* @var array
|
37 |
-
*
|
38 |
-
*/
|
39 |
-
public $lists_id_name_map = array();
|
40 |
-
|
41 |
-
public function __construct() {
|
42 |
-
|
43 |
-
//set_error_handler(array( 'Email_General' , 'es_handle_error'));
|
44 |
-
parent::__construct( array(
|
45 |
-
'singular' => __( 'Contact', 'email-subscribers' ), //singular name of the listed records
|
46 |
-
'plural' => __( 'Contacts', 'email-subscribers' ), //plural name of the listed records
|
47 |
-
'ajax' => false,//does this table support ajax?
|
48 |
-
'screen' => 'es_subscribers'
|
49 |
-
) );
|
50 |
-
|
51 |
-
add_filter( 'ig_es_audience_tab_main_navigation', array( $this, 'get_audience_main_tabs' ), 10, 2 );
|
52 |
-
|
53 |
-
// @since 4.3.1
|
54 |
-
add_action( 'ig_es_list_deleted', array( $this, 'delete_contacts_from_list' ), 10, 1 );
|
55 |
-
add_action( 'ig_es_form_deleted', array( $this, 'set_default_form_id' ), 10, 1 );
|
56 |
-
}
|
57 |
-
|
58 |
-
/**
|
59 |
-
* Add Screen Option
|
60 |
-
*
|
61 |
-
* @since 4.2.1
|
62 |
-
*/
|
63 |
-
public static function screen_options() {
|
64 |
-
|
65 |
-
// Don't show screen option on Import/ Export subscribers page.
|
66 |
-
$action = ig_es_get_request_data( 'action' );
|
67 |
-
|
68 |
-
if ( '' === $action ) {
|
69 |
-
|
70 |
-
$option = 'per_page';
|
71 |
-
$args = array(
|
72 |
-
'label' => __( 'Number of contacts per page', 'email-subscribers' ),
|
73 |
-
'default' => 100,
|
74 |
-
'option' => self::$option_per_page
|
75 |
-
);
|
76 |
-
|
77 |
-
add_screen_option( $option, $args );
|
78 |
-
}
|
79 |
-
|
80 |
-
}
|
81 |
-
|
82 |
-
|
83 |
-
public function get_audience_main_tabs( $active_tab, $audience_main_tabs = array() ) {
|
84 |
-
|
85 |
-
$audience_tab_main_navigation = array(
|
86 |
-
'new_contact' => array(
|
87 |
-
'label' => __( 'Add New Contact', 'email-subscribers' ),
|
88 |
-
'indicator_option' => '',
|
89 |
-
'indicator_label' => '',
|
90 |
-
'indicator_type' => '',
|
91 |
-
'action' => 'new',
|
92 |
-
'url' => add_query_arg( 'action', 'new', 'admin.php?page=es_subscribers' )
|
93 |
-
),
|
94 |
-
|
95 |
-
'export' => array(
|
96 |
-
'label' => __( 'Export Contacts', 'email-subscribers' ),
|
97 |
-
'indicator_option' => '',
|
98 |
-
'indicator_label' => '',
|
99 |
-
'indicator_type' => '',
|
100 |
-
'action' => 'export',
|
101 |
-
'url' => add_query_arg( 'action', 'export', 'admin.php?page=es_subscribers' )
|
102 |
-
),
|
103 |
-
|
104 |
-
'import' => array(
|
105 |
-
'label' => __( 'Import Contacts', 'email-subscribers' ),
|
106 |
-
'indicator_option' => '',
|
107 |
-
'indicator_label' => '',
|
108 |
-
'indicator_type' => '',
|
109 |
-
'action' => 'import',
|
110 |
-
'url' => add_query_arg( 'action', 'import', 'admin.php?page=es_subscribers' )
|
111 |
-
),
|
112 |
-
|
113 |
-
'sync' => array(
|
114 |
-
'label' => __( 'Sync', 'email-subscribers' ),
|
115 |
-
'indicator_option' => 'ig_es_show_sync_tab',
|
116 |
-
'indicator_label' => __( 'New', 'email-subscribers' ),
|
117 |
-
'indicator_type' => 'new',
|
118 |
-
'action' => 'sync',
|
119 |
-
'url' => add_query_arg( 'action', 'sync', 'admin.php?page=es_subscribers' )
|
120 |
-
),
|
121 |
-
|
122 |
-
'manage_lists' => array(
|
123 |
-
'label' => __( 'Manage Lists', 'email-subscribers' ),
|
124 |
-
'indicator_option' => '',
|
125 |
-
'indicator_label' => '',
|
126 |
-
'indicator_type' => '',
|
127 |
-
'action' => 'manage-lists',
|
128 |
-
'is_imp' => true,
|
129 |
-
'url' => add_query_arg( 'action', 'manage-lists', 'admin.php?page=es_lists' )
|
130 |
-
)
|
131 |
-
);
|
132 |
-
|
133 |
-
$audience_main_tabs = $audience_main_tabs + $audience_tab_main_navigation;
|
134 |
-
|
135 |
-
if ( ! empty( $active_tab ) && isset( $audience_main_tabs[ $active_tab ] ) ) {
|
136 |
-
unset( $audience_main_tabs[ $active_tab ] );
|
137 |
-
}
|
138 |
-
|
139 |
-
return $audience_main_tabs;
|
140 |
-
}
|
141 |
-
|
142 |
-
/**
|
143 |
-
* Render Audience View
|
144 |
-
*
|
145 |
-
* @since 4.2.1
|
146 |
-
*/
|
147 |
-
public function render() {
|
148 |
-
|
149 |
-
?>
|
150 |
-
<div class="wrap">
|
151 |
-
|
152 |
-
<?php
|
153 |
-
|
154 |
-
$action = ig_es_get_request_data( 'action' );
|
155 |
-
if ( 'import' === $action ) {
|
156 |
-
$this->load_import();
|
157 |
-
} elseif ( 'export' === $action ) {
|
158 |
-
$this->load_export();
|
159 |
-
} elseif ( 'new' === $action || 'edit' === $action ) {
|
160 |
-
$contact_id = absint( ig_es_get_request_data( 'subscriber' ) );
|
161 |
-
$this->save_contact( $contact_id );
|
162 |
-
} elseif ( 'sync' === $action ) {
|
163 |
-
update_option( 'ig_es_show_sync_tab', 'no' ); // yes/no
|
164 |
-
$this->load_sync();
|
165 |
-
} else {
|
166 |
-
|
167 |
-
$audience_tab_main_navigation = array();
|
168 |
-
$active_tab = '';
|
169 |
-
$audience_tab_main_navigation = apply_filters( 'ig_es_audience_tab_main_navigation', $active_tab, $audience_tab_main_navigation );
|
170 |
-
|
171 |
-
?>
|
172 |
-
|
173 |
-
<h1 class="wp-heading-inline">
|
174 |
-
<?php
|
175 |
-
_e( 'Audience > Contacts', 'email-subscribers' );
|
176 |
-
ES_Common::prepare_main_header_navigation( $audience_tab_main_navigation );
|
177 |
-
?>
|
178 |
-
</h1>
|
179 |
-
|
180 |
-
<?php Email_Subscribers_Admin::es_feedback(); ?>
|
181 |
-
<div id="poststuff" class="es-audience-view">
|
182 |
-
<div id="post-body" class="metabox-holder column-1">
|
183 |
-
<div id="post-body-content">
|
184 |
-
<div class="meta-box-sortables ui-sortable">
|
185 |
-
<form method="post">
|
186 |
-
<?php
|
187 |
-
$this->prepare_items();
|
188 |
-
$this->display();
|
189 |
-
?>
|
190 |
-
</form>
|
191 |
-
</div>
|
192 |
-
</div>
|
193 |
-
</div>
|
194 |
-
<br class="clear">
|
195 |
-
</div>
|
196 |
-
</div>
|
197 |
-
<?php }
|
198 |
-
}
|
199 |
-
|
200 |
-
public function load_export() {
|
201 |
-
$export = new Export_Subscribers();
|
202 |
-
$export->export_subscribers_page();
|
203 |
-
}
|
204 |
-
|
205 |
-
public function load_import() {
|
206 |
-
$import = new ES_Import_Subscribers();
|
207 |
-
$import->import_subscribers_page();
|
208 |
-
}
|
209 |
-
|
210 |
-
public function load_sync() {
|
211 |
-
$sync = ES_Handle_Sync_Wp_User::get_instance();
|
212 |
-
$sync->prepare_sync_user();
|
213 |
-
}
|
214 |
-
|
215 |
-
public function save_contact( $id = 0 ) {
|
216 |
-
global $wpdb;
|
217 |
-
|
218 |
-
$first_name = $action = $last_name = $email = $guid = $created = '';
|
219 |
-
$list_ids = array();
|
220 |
-
$is_new = true;
|
221 |
-
|
222 |
-
if ( $id === 0 ) {
|
223 |
-
$title = __( 'Add New Contact', 'email-subscribers' );
|
224 |
-
$title_action = '<a href="admin.php?page=es_lists&action=manage-lists" class="page-title-action es-imp-button">' . __( 'Manage Lists', 'email-subscribers' ) . '</a>';
|
225 |
-
|
226 |
-
} else {
|
227 |
-
$is_new = false;
|
228 |
-
$title = __( 'Edit Contact', 'email-subscribers' );
|
229 |
-
$title_action = '<a href="admin.php?page=es_subscribers&action=new" class="page-title-action">' . __( 'Add New', 'email-subscribers' ) . '</a>';
|
230 |
-
|
231 |
-
$contacts_table = IG_CONTACTS_TABLE;
|
232 |
-
$query = "SELECT * FROM {$contacts_table} WHERE id = %d";
|
233 |
-
$contact = $wpdb->get_results( $wpdb->prepare( $query, $id ), ARRAY_A );
|
234 |
-
|
235 |
-
if ( ! empty( $contact[0] ) ) {
|
236 |
-
$contact = $contact[0];
|
237 |
-
|
238 |
-
$first_name = ! empty( $contact['first_name'] ) ? $contact['first_name'] : '';
|
239 |
-
$last_name = ! empty( $contact['last_name'] ) ? $contact['last_name'] : '';
|
240 |
-
$email = ! empty( $contact['email'] ) ? $contact['email'] : '';
|
241 |
-
$list_ids = ES_DB_Lists_Contacts::get_list_ids_by_contact( $id );
|
242 |
-
$guid = $contact['hash'];
|
243 |
-
$nonce = esc_attr( ig_es_get_request_data( '_wpnonce' ) );
|
244 |
-
}
|
245 |
-
}
|
246 |
-
|
247 |
-
$submitted = ig_es_get_request_data( 'submitted' );
|
248 |
-
if ( 'submitted' === $submitted ) {
|
249 |
-
|
250 |
-
$contact_data = ig_es_get_post_data( 'contact_data', array() );
|
251 |
-
$is_error = false;
|
252 |
-
if ( ! empty( $contact_data ) ) {
|
253 |
-
|
254 |
-
$email = ! empty( $contact_data['email'] ) ? sanitize_email( $contact_data['email'] ) : '';
|
255 |
-
|
256 |
-
if ( $email ) {
|
257 |
-
|
258 |
-
$list_ids = ! empty( $contact_data['lists'] ) ? $contact_data['lists'] : array();
|
259 |
-
|
260 |
-
if ( count( $list_ids ) > 0 ) {
|
261 |
-
$first_name = ! empty( $contact_data['first_name'] ) ? sanitize_text_field( $contact_data['first_name'] ) : '';
|
262 |
-
$last_name = ! empty( $contact_data['last_name'] ) ? sanitize_text_field( $contact_data['last_name'] ) : '';
|
263 |
-
|
264 |
-
if ( ! empty( $first_name ) ) {
|
265 |
-
|
266 |
-
$contact = array(
|
267 |
-
'first_name' => $first_name,
|
268 |
-
'last_name' => $last_name,
|
269 |
-
'email' => $email,
|
270 |
-
);
|
271 |
-
|
272 |
-
// Add contact
|
273 |
-
if ( $id ) {
|
274 |
-
$this->update_contact( $id, $contact );
|
275 |
-
} else {
|
276 |
-
$id = ES()->contacts_db->get_contact_id_by_email( $email );
|
277 |
-
if ( ! $id ) {
|
278 |
-
$contact['source'] = 'admin';
|
279 |
-
$contact['status'] = 'verified';
|
280 |
-
$contact['hash'] = ES_Common::generate_guid();
|
281 |
-
$contact['created_at'] = ig_get_current_date_time();
|
282 |
-
|
283 |
-
$id = ES()->contacts_db->insert( $contact );
|
284 |
-
|
285 |
-
} else {
|
286 |
-
$message = __( 'Contact already exist.', 'email-subscribers' );
|
287 |
-
ES_Common::show_message( $message, 'error' );
|
288 |
-
$is_error = true;
|
289 |
-
}
|
290 |
-
|
291 |
-
}
|
292 |
-
|
293 |
-
if ( ! $is_error ) {
|
294 |
-
|
295 |
-
$list_ids = ! empty( $list_ids ) ? $list_ids : array( 1 );
|
296 |
-
|
297 |
-
ES_DB_Lists_Contacts::update_list_contacts( $id, $list_ids );
|
298 |
-
|
299 |
-
if ( $id ) {
|
300 |
-
|
301 |
-
if ( $is_new ) {
|
302 |
-
|
303 |
-
if ( ! empty( $contact_data['send_welcome_email'] ) ) {
|
304 |
-
|
305 |
-
// Get comma(,) separated list name based on ids
|
306 |
-
$list_name = ES_Common::prepare_list_name_by_ids( $list_ids );
|
307 |
-
$name = ES_Common::prepare_name_from_first_name_last_name( $contact['first_name'], $contact['last_name'] );
|
308 |
-
|
309 |
-
$template_data = array(
|
310 |
-
'email' => $contact['email'],
|
311 |
-
'db_id' => $id,
|
312 |
-
'name' => $name,
|
313 |
-
'first_name' => $contact['first_name'],
|
314 |
-
'last_name' => $contact['last_name'],
|
315 |
-
'guid' => $contact['hash'],
|
316 |
-
'list_name' => $list_name
|
317 |
-
);
|
318 |
-
|
319 |
-
// Send Welcome Email
|
320 |
-
ES_Mailer::send_welcome_email( $contact['email'], $template_data );
|
321 |
-
}
|
322 |
-
|
323 |
-
$message = __( 'Contact has been added successfully!', 'email-subscribers' );
|
324 |
-
} else {
|
325 |
-
$message = __( 'Contact has been updated successfully!', 'email-subscribers' );
|
326 |
-
}
|
327 |
-
|
328 |
-
ES_Common::show_message( $message, 'success' );
|
329 |
-
}
|
330 |
-
}
|
331 |
-
} else {
|
332 |
-
$message = __( 'Please Enter First Name', 'email-subscribers' );
|
333 |
-
ES_Common::show_message( $message, 'error' );
|
334 |
-
}
|
335 |
-
|
336 |
-
} else {
|
337 |
-
$message = __( 'Please Select List', 'email-subscribers' );
|
338 |
-
ES_Common::show_message( $message, 'error' );
|
339 |
-
}
|
340 |
-
|
341 |
-
} else {
|
342 |
-
$message = __( 'Please Enter Valid Email Address', 'email-subscribers' );
|
343 |
-
ES_Common::show_message( $message, 'error' );
|
344 |
-
}
|
345 |
-
|
346 |
-
}
|
347 |
-
}
|
348 |
-
|
349 |
-
$data = array(
|
350 |
-
'id' => $id,
|
351 |
-
'first_name' => $first_name,
|
352 |
-
'last_name' => $last_name,
|
353 |
-
'email' => $email,
|
354 |
-
'selected_list_ids' => $list_ids,
|
355 |
-
'guid' => $guid
|
356 |
-
);
|
357 |
-
|
358 |
-
?>
|
359 |
-
|
360 |
-
<div class="wrap">
|
361 |
-
<h1 class="wp-heading-inline"><?php echo $title; ?><?php echo $title_action; ?></h1><?php Email_Subscribers_Admin::es_feedback(); ?>
|
362 |
-
<hr class="wp-header-end">
|
363 |
-
<div id="poststuff">
|
364 |
-
<div id="post-body" class="metabox-holder column-1">
|
365 |
-
<div id="post-body-content">
|
366 |
-
<div class="meta-box-sortables ui-sortable es-contact-form">
|
367 |
-
<?php echo $this->prepare_contact_form( $data, $is_new ); ?>
|
368 |
-
</div>
|
369 |
-
</div>
|
370 |
-
</div>
|
371 |
-
</div>
|
372 |
-
</div>
|
373 |
-
|
374 |
-
<?php
|
375 |
-
|
376 |
-
}
|
377 |
-
|
378 |
-
/**
|
379 |
-
* Retrieve subscribers data from the database
|
380 |
-
*
|
381 |
-
* @param int $per_page
|
382 |
-
* @param int $page_number
|
383 |
-
*
|
384 |
-
* @return mixed
|
385 |
-
*/
|
386 |
-
public function get_subscribers( $per_page = 5, $page_number = 1, $do_count_only = false ) {
|
387 |
-
global $wpdb;
|
388 |
-
|
389 |
-
$order_by = sanitize_sql_orderby( ig_es_get_request_data( 'orderby' ) );
|
390 |
-
$order = ig_es_get_request_data( 'order' );
|
391 |
-
$search = ig_es_get_request_data( 's' );
|
392 |
-
$filter_by_list_id = ig_es_get_request_data( 'filter_by_list_id' );
|
393 |
-
$filter_by_status = ig_es_get_request_data( 'filter_by_status' );
|
394 |
-
|
395 |
-
$contacts_table = IG_CONTACTS_TABLE;
|
396 |
-
$lists_contacts_table = IG_LISTS_CONTACTS_TABLE;
|
397 |
-
|
398 |
-
$add_where_clause = false;
|
399 |
-
|
400 |
-
$args = array();
|
401 |
-
$query = array();
|
402 |
-
|
403 |
-
if ( $do_count_only ) {
|
404 |
-
$sql = "SELECT count(*) FROM {$contacts_table}";
|
405 |
-
} else {
|
406 |
-
$sql = "SELECT * FROM {$contacts_table}";
|
407 |
-
}
|
408 |
-
|
409 |
-
// Prepare filter by list query
|
410 |
-
if ( ! empty( $filter_by_list_id ) || ! empty( $filter_by_status ) ) {
|
411 |
-
$add_where_clause = true;
|
412 |
-
|
413 |
-
$filter_sql = "SELECT contact_id FROM {$lists_contacts_table}";
|
414 |
-
|
415 |
-
$list_filter_sql = '';
|
416 |
-
$where_clause_added = false;
|
417 |
-
|
418 |
-
if ( ! empty( $filter_by_list_id ) ) {
|
419 |
-
$list_filter_sql = $wpdb->prepare( " WHERE list_id = %d", $filter_by_list_id );
|
420 |
-
$where_clause_added = true;
|
421 |
-
}
|
422 |
-
|
423 |
-
if ( ! empty( $filter_by_status ) ) {
|
424 |
-
if ( $where_clause_added ) {
|
425 |
-
$list_filter_sql .= $wpdb->prepare( " AND status = %s", $filter_by_status );
|
426 |
-
} else {
|
427 |
-
$list_filter_sql .= $wpdb->prepare( " WHERE status = %s", $filter_by_status );
|
428 |
-
}
|
429 |
-
|
430 |
-
}
|
431 |
-
|
432 |
-
$filter_sql .= $list_filter_sql;
|
433 |
-
$query[] = "id IN ( $filter_sql )";
|
434 |
-
}
|
435 |
-
|
436 |
-
// Prepare search query
|
437 |
-
if ( ! empty( $search ) ) {
|
438 |
-
$query[] = " ( first_name LIKE %s OR last_name LIKE %s OR email LIKE %s ) ";
|
439 |
-
$args[] = "%" . $wpdb->esc_like( $search ) . "%";
|
440 |
-
$args[] = "%" . $wpdb->esc_like( $search ) . "%";
|
441 |
-
$args[] = "%" . $wpdb->esc_like( $search ) . "%";
|
442 |
-
}
|
443 |
-
|
444 |
-
if ( $add_where_clause || count( $query ) > 0 ) {
|
445 |
-
$sql .= " WHERE ";
|
446 |
-
|
447 |
-
if ( count( $query ) > 0 ) {
|
448 |
-
$sql .= implode( " AND ", $query );
|
449 |
-
if ( ! empty( $args ) ) {
|
450 |
-
$sql = $wpdb->prepare( $sql, $args );
|
451 |
-
}
|
452 |
-
}
|
453 |
-
}
|
454 |
-
|
455 |
-
|
456 |
-
if ( ! $do_count_only ) {
|
457 |
-
|
458 |
-
// Prepare Order by clause
|
459 |
-
$order = ! empty( $order ) ? strtolower( $order ) : 'desc';
|
460 |
-
$expected_order_values = array( 'asc', 'desc' );
|
461 |
-
if ( ! in_array( $order, $expected_order_values ) ) {
|
462 |
-
$order = 'desc';
|
463 |
-
}
|
464 |
-
|
465 |
-
$offset = ( $page_number - 1 ) * $per_page;
|
466 |
-
|
467 |
-
$expected_order_by_values = array( 'name', 'email', 'created_at', 'first_name' );
|
468 |
-
if ( ! in_array( $order_by, $expected_order_by_values ) ) {
|
469 |
-
$order_by = 'created_at';
|
470 |
-
}
|
471 |
-
|
472 |
-
$order_by = esc_sql( $order_by );
|
473 |
-
|
474 |
-
$order_by_clause = " ORDER BY {$order_by} {$order}";
|
475 |
-
|
476 |
-
$sql .= $order_by_clause;
|
477 |
-
$sql .= " LIMIT {$offset}, {$per_page}";
|
478 |
-
|
479 |
-
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
|
480 |
-
} else {
|
481 |
-
$result = $wpdb->get_var( $sql );
|
482 |
-
}
|
483 |
-
|
484 |
-
return $result;
|
485 |
-
}
|
486 |
-
|
487 |
-
public function edit_list( $id ) {
|
488 |
-
global $wpdb;
|
489 |
-
|
490 |
-
$notificationid = $wpdb->get_results( "SELECT * FROM " . IG_CONTACTS_TABLE . " WHERE id = $id" );
|
491 |
-
|
492 |
-
$title = $notificationid[0]->first_name . ' ' . $notificationid[0]->last_name;
|
493 |
-
$email = $notificationid[0]->email;
|
494 |
-
$contact_lists = ES_DB_Lists_Contacts::get_list_ids_by_contact( $notificationid[0]->id );
|
495 |
-
|
496 |
-
$status = ig_es_get_request_data( 'status' );
|
497 |
-
if ( 'updated' === $status ) {
|
498 |
-
$email_address = sanitize_email( ig_es_get_request_data( 'email' ) );
|
499 |
-
|
500 |
-
if ( ! empty( $email_address ) ) {
|
501 |
-
$this->update_list( $id );
|
502 |
-
$title = ig_es_get_request_data( 'subscriber_name' );
|
503 |
-
$contact_lists = ig_es_get_request_data( 'lists' );
|
504 |
-
$email = $email_address;
|
505 |
-
}
|
506 |
-
}
|
507 |
-
|
508 |
-
$id = $notificationid[0]->id;
|
509 |
-
$guid = $notificationid[0]->hash;
|
510 |
-
$created = $notificationid[0]->created_at;
|
511 |
-
$nonce = esc_attr( ig_es_get_request_data( '_wpnonce' ) );
|
512 |
-
|
513 |
-
$data = array(
|
514 |
-
'id' => $id,
|
515 |
-
'action' => "admin.php?page=es_subscribers&action=edit&subscriber={$id}&_wpnonce={$nonce}&status=updated",
|
516 |
-
'name' => $title,
|
517 |
-
'email' => $email,
|
518 |
-
'created' => $created,
|
519 |
-
'guid' => $guid,
|
520 |
-
'selected_list_ids' => $contact_lists
|
521 |
-
);
|
522 |
-
|
523 |
-
$contact_name = ig_es_get_request_data( 'subscriber_name' );
|
524 |
-
if ( $contact_name ) {
|
525 |
-
$message = __( 'Contact updated successfully!', 'email-subscribers' );
|
526 |
-
ES_Common::show_message( $message, 'success' );
|
527 |
-
}
|
528 |
-
|
529 |
-
$editform = '<div class="wrap">
|
530 |
-
<h1 class="wp-heading-inline">' . __( 'Edit Contact', 'email-subscribers' ) . '<a href="admin.php?page=es_subscribers&action=new" class="page-title-action">Add New</a></h1>' . Email_Subscribers_Admin::es_feedback() . '
|
531 |
-
<hr class="wp-header-end">
|
532 |
-
<div id="poststuff">
|
533 |
-
<div id="post-body" class="metabox-holder column-1">
|
534 |
-
<div id="post-body-content">
|
535 |
-
<div class="meta-box-sortables ui-sortable es-contact-form">'
|
536 |
-
. $this->prepare_contact_form( $data, false ) .
|
537 |
-
'</div>
|
538 |
-
</div>
|
539 |
-
</div>
|
540 |
-
</div>
|
541 |
-
</div>';
|
542 |
-
|
543 |
-
return $editform;
|
544 |
-
}
|
545 |
-
|
546 |
-
public function prepare_contact_form( $data = array(), $is_new = false ) {
|
547 |
-
|
548 |
-
$id = ! empty( $data['id'] ) ? $data['id'] : '';
|
549 |
-
$created = ! empty( $data['created'] ) ? $data['created'] : '';
|
550 |
-
$guid = ! empty( $data['guid'] ) ? $data['guid'] : '';
|
551 |
-
$action = ! empty( $data['action'] ) ? $data['action'] : '#';
|
552 |
-
$first_name = ! empty( $data['first_name'] ) ? $data['first_name'] : '';
|
553 |
-
$last_name = ! empty( $data['last_name'] ) ? $data['last_name'] : '';
|
554 |
-
$email = ! empty( $data['email'] ) ? $data['email'] : '';
|
555 |
-
$selected_list_ids = ! empty( $data['selected_list_ids'] ) ? $data['selected_list_ids'] : array();
|
556 |
-
$send_welcome_email = ! empty( $data['send_welcome_email'] ) ? true : false;
|
557 |
-
|
558 |
-
$lists_id_name_map = ES()->lists_db->get_list_id_name_map();
|
559 |
-
|
560 |
-
if ( count( $lists_id_name_map ) ) {
|
561 |
-
$list_html = ES_Shortcode::prepare_lists_checkboxes( $lists_id_name_map, array_keys( $lists_id_name_map ), 4, $selected_list_ids, $id, 'contact_data[lists][]' );
|
562 |
-
} else {
|
563 |
-
$list_html = "<tr><td>" . __( 'No list found', 'email-subscribers' ) . "</td></tr>";
|
564 |
-
}
|
565 |
-
|
566 |
-
?>
|
567 |
-
<form method="post" action="<?php echo $action; ?>">
|
568 |
-
<table class="ig-es-form-table form-table">
|
569 |
-
<tbody>
|
570 |
-
<tr class="form-field">
|
571 |
-
<td><label><b><?php _e( 'First Name', 'email-subscribers' ); ?></b></label></td>
|
572 |
-
<td><input type="text" class="ig-es-contact-first-name" id="ig-es-contact-first-name" name="contact_data[first_name]" value="<?php echo $first_name; ?>"/></td>
|
573 |
-
</tr>
|
574 |
-
|
575 |
-
<tr class="form-field">
|
576 |
-
<td><label><b><?php _e( 'Last Name', 'email-subscribers' ); ?></b></label></td>
|
577 |
-
<td><input type="text" class="ig-es-contact-last-name" id="ig-es-contact-last-name" name="contact_data[last_name]" value="<?php echo $last_name; ?>"/></td>
|
578 |
-
</tr>
|
579 |
-
|
580 |
-
<tr class="form-field">
|
581 |
-
<td><label><b><?php _e( 'Email', 'email-subscribers' ); ?></b></label></td>
|
582 |
-
<td><input type="email" id="email" name="contact_data[email]" value="<?php echo $email; ?>"/></td>
|
583 |
-
</tr>
|
584 |
-
|
585 |
-
<?php if ( $is_new ) { ?>
|
586 |
-
<tr class="form-field">
|
587 |
-
<td><label><b><?php _e( 'Send Welcome Email?', 'email-subscribers' ); ?></b></label></td>
|
588 |
-
<td><input type="checkbox" id="ig-es-contact-welcome-email" name="contact_data[send_welcome_email]" <?php if ( $send_welcome_email ) {
|
589 |
-
echo "checked='checked'";
|
590 |
-
} ?> /></td>
|
591 |
-
</tr>
|
592 |
-
<?php } ?>
|
593 |
-
<tr class="form-field">
|
594 |
-
<td><label><b><?php _e( 'List(s)', 'email-subscribers' ); ?></b></label></td>
|
595 |
-
<td>
|
596 |
-
<table><?php echo $list_html; ?></table>
|
597 |
-
</td>
|
598 |
-
</tr>
|
599 |
-
<tr class="form-field">
|
600 |
-
<td></td>
|
601 |
-
<td>
|
602 |
-
<input type="hidden" name="contact_data[created_at]" value="<?php echo $created; ?>"/>
|
603 |
-
<input type="hidden" name="contact_data[guid]" value="<?php echo $guid; ?>"/>
|
604 |
-
<input type="hidden" name="submitted" value="submitted"/>
|
605 |
-
<input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'email-subscribers' ); ?>"/>
|
606 |
-
</td>
|
607 |
-
</tr>
|
608 |
-
</tbody>
|
609 |
-
</table>
|
610 |
-
</form>
|
611 |
-
<?php
|
612 |
-
}
|
613 |
-
|
614 |
-
public function update_contact( $contact_id = 0, $data = array() ) {
|
615 |
-
|
616 |
-
global $wpdb;
|
617 |
-
|
618 |
-
if ( ! empty( $contact_id ) ) {
|
619 |
-
|
620 |
-
$email = ! empty( $data['email'] ) ? sanitize_email( $data['email'] ) : '';
|
621 |
-
if ( ! empty( $email ) ) {
|
622 |
-
|
623 |
-
$first_name = ! empty( $data['first_name'] ) ? sanitize_text_field( $data['first_name'] ) : '';
|
624 |
-
$last_name = ! empty( $data['last_name'] ) ? sanitize_text_field( $data['last_name'] ) : '';
|
625 |
-
|
626 |
-
$data_to_update = array(
|
627 |
-
'first_name' => $first_name,
|
628 |
-
'last_name' => $last_name,
|
629 |
-
'email' => $email,
|
630 |
-
'updated_at' => ig_get_current_date_time()
|
631 |
-
);
|
632 |
-
|
633 |
-
$wpdb->update( IG_CONTACTS_TABLE, $data_to_update, array( 'id' => $contact_id ) );
|
634 |
-
}
|
635 |
-
}
|
636 |
-
|
637 |
-
}
|
638 |
-
|
639 |
-
|
640 |
-
/**
|
641 |
-
* Returns the count of records in the database.
|
642 |
-
*
|
643 |
-
* @return null|string
|
644 |
-
*/
|
645 |
-
public static function record_count() {
|
646 |
-
global $wpdb;
|
647 |
-
|
648 |
-
$sql = "SELECT COUNT(*) FROM " . IG_CONTACTS_TABLE;
|
649 |
-
|
650 |
-
return $wpdb->get_var( $sql );
|
651 |
-
}
|
652 |
-
|
653 |
-
|
654 |
-
/** Text displayed when no subscriber data is available */
|
655 |
-
|
656 |
-
|
657 |
-
/**
|
658 |
-
* Render a column when no column specific method exist.
|
659 |
-
*
|
660 |
-
* @param array $item
|
661 |
-
* @param string $column_name
|
662 |
-
*
|
663 |
-
* @return mixed
|
664 |
-
*/
|
665 |
-
public function column_default( $item, $column_name ) {
|
666 |
-
$item = apply_filters( 'es_subscribers_col_data', $item, $column_name );
|
667 |
-
switch ( $column_name ) {
|
668 |
-
case 'lists':
|
669 |
-
return $this->get_lists_to_show( $item['id'] );
|
670 |
-
case 'created_at':
|
671 |
-
return ig_es_format_date_time( $item[ $column_name ] );
|
672 |
-
case 'first_name':
|
673 |
-
case 'email':
|
674 |
-
default:
|
675 |
-
return $item[ $column_name ]; //Show the whole array for troubleshooting purposes
|
676 |
-
}
|
677 |
-
}
|
678 |
-
|
679 |
-
public function get_lists_to_show( $contact_id ) {
|
680 |
-
|
681 |
-
$list_str = '';
|
682 |
-
|
683 |
-
if ( isset( $this->contact_lists_statuses[ $contact_id ] ) ) {
|
684 |
-
|
685 |
-
$lists = $this->contact_lists_statuses[ $contact_id ];
|
686 |
-
|
687 |
-
if ( count( $lists ) > 0 ) {
|
688 |
-
// Show only 4 lists
|
689 |
-
//$contact_lists_to_display = array_slice( $lists, 0, 4 );
|
690 |
-
foreach ( $lists as $list_id => $status ) {
|
691 |
-
if ( ! empty( $this->lists_id_name_map[ $list_id ] ) ) {
|
692 |
-
$list_str .= '<span class="es_list_contact_status ' . strtolower( $status ) . '" title="' . ucwords( $status ) . '">' . $this->lists_id_name_map[ $list_id ] . '</span> ';
|
693 |
-
}
|
694 |
-
}
|
695 |
-
}
|
696 |
-
}
|
697 |
-
|
698 |
-
return $list_str;
|
699 |
-
}
|
700 |
-
|
701 |
-
public function status_label_map( $status ) {
|
702 |
-
|
703 |
-
$statuses = array(
|
704 |
-
// 'confirmed' => __( 'Confirmed', 'email-subscribers' ),
|
705 |
-
'subscribed' => __( 'Subscribed', 'email-subscribers' ),
|
706 |
-
'unconfirmed' => __( 'Unconfirmed', 'email-subscribers' ),
|
707 |
-
'unsubscribed' => __( 'Unsubscribed', 'email-subscribers' ),
|
708 |
-
// 'single_opt_in' => __( 'Single Opt In', 'email-subscribers' ),
|
709 |
-
// 'double_opt_in' => __( 'Double Opt In', 'email-subscribers' )
|
710 |
-
);
|
711 |
-
|
712 |
-
|
713 |
-
if ( ! in_array( $status, array_keys( $statuses ) ) ) {
|
714 |
-
return '';
|
715 |
-
}
|
716 |
-
|
717 |
-
return $statuses[ $status ];
|
718 |
-
}
|
719 |
-
|
720 |
-
/**
|
721 |
-
* Render the bulk edit checkbox
|
722 |
-
*
|
723 |
-
* @param array $item
|
724 |
-
*
|
725 |
-
* @return string
|
726 |
-
*/
|
727 |
-
function column_cb( $item ) {
|
728 |
-
return sprintf(
|
729 |
-
'<input type="checkbox" name="subscribers[]" value="%s"/>', $item['id']
|
730 |
-
);
|
731 |
-
}
|
732 |
-
|
733 |
-
|
734 |
-
/**
|
735 |
-
* Method for name column
|
736 |
-
*
|
737 |
-
* @param array $item an array of DB data
|
738 |
-
*
|
739 |
-
* @return string
|
740 |
-
*/
|
741 |
-
function column_name( $item ) {
|
742 |
-
$delete_nonce = wp_create_nonce( 'ig_es_delete_subscriber' );
|
743 |
-
|
744 |
-
$name = ES_Common::prepare_name_from_first_name_last_name( $item['first_name'], $item['last_name'] );
|
745 |
-
$title = '<strong>' . $name . '</strong>';
|
746 |
-
|
747 |
-
$page = ig_es_get_request_data( 'page' );
|
748 |
-
|
749 |
-
$actions = array(
|
750 |
-
'edit' => sprintf( __( '<a href="?page=%s&action=%s&subscriber=%s&_wpnonce=%s">Edit</a>', 'email-subscribers' ), esc_attr( $page ), 'edit', absint( $item['id'] ), $delete_nonce ),
|
751 |
-
'delete' => sprintf( __( '<a href="?page=%s&action=%s&subscriber=%s&_wpnonce=%s" onclick="return checkDelete()">Delete</a>', 'email-subscribers' ), esc_attr( $page ), 'delete', absint( $item['id'] ), $delete_nonce ),
|
752 |
-
);
|
753 |
-
|
754 |
-
$optin_type = get_option( 'ig_es_optin_type' );
|
755 |
-
|
756 |
-
//if ( in_array( $optin_type, array( 'double_optin', 'double_opt_in' ) ) ) {
|
757 |
-
$actions['resend'] = sprintf( __( '<a href="?page=%s&action=%s&subscriber=%s&_wpnonce=%s">Resend Confirmation<a>', 'email-subscribers' ), esc_attr( ig_es_get_request_data( 'page' ) ), 'resend', absint( $item['id'] ), $delete_nonce );
|
758 |
-
|
759 |
-
//}
|
760 |
-
|
761 |
-
return $title . $this->row_actions( $actions );
|
762 |
-
}
|
763 |
-
|
764 |
-
|
765 |
-
/**
|
766 |
-
* Associative array of columns
|
767 |
-
*
|
768 |
-
* @return array
|
769 |
-
*/
|
770 |
-
function get_columns() {
|
771 |
-
$columns = array(
|
772 |
-
'cb' => '<input type="checkbox"/>',
|
773 |
-
'name' => __( 'Name', 'email-subscribers' ),
|
774 |
-
'email' => __( 'Email', 'email-subscribers' ),
|
775 |
-
'lists' => __( 'List(s)', 'email-subscribers' ),
|
776 |
-
'created_at' => __( 'Created', 'email-subscribers' ),
|
777 |
-
);
|
778 |
-
|
779 |
-
return $columns;
|
780 |
-
}
|
781 |
-
|
782 |
-
/**
|
783 |
-
* Columns to make sortable.
|
784 |
-
*
|
785 |
-
* @return array
|
786 |
-
*/
|
787 |
-
public function get_sortable_columns() {
|
788 |
-
$sortable_columns = array(
|
789 |
-
'name' => array( 'first_name', true ),
|
790 |
-
'email' => array( 'email', false ),
|
791 |
-
// 'status' => array( 'status', false ),
|
792 |
-
'created_at' => array( 'created_at', false )
|
793 |
-
);
|
794 |
-
|
795 |
-
return $sortable_columns;
|
796 |
-
}
|
797 |
-
|
798 |
-
/**
|
799 |
-
* Returns an associative array containing the bulk action
|
800 |
-
*
|
801 |
-
* @return array
|
802 |
-
*/
|
803 |
-
public function get_bulk_actions() {
|
804 |
-
$actions = array(
|
805 |
-
'bulk_delete' => __( 'Delete', 'email-subscribers' ),
|
806 |
-
'bulk_list_update' => __( 'Move To List', 'email-subscribers' ),
|
807 |
-
'bulk_list_add' => __( 'Add To List', 'email-subscribers' ),
|
808 |
-
'bulk_status_update' => __( 'Change Status', 'email-subscribers' )
|
809 |
-
);
|
810 |
-
|
811 |
-
return $actions;
|
812 |
-
}
|
813 |
-
|
814 |
-
|
815 |
-
public function search_box( $text, $input_id ) {
|
816 |
-
|
817 |
-
?>
|
818 |
-
<p class="search-box box-ma10">
|
819 |
-
<label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
|
820 |
-
<input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>"/>
|
821 |
-
<?php submit_button( __( 'Search Contacts', 'email-subscribers' ), 'button', false, false, array( 'id' => 'search-submit' ) ); ?>
|
822 |
-
</p>
|
823 |
-
<p class="search-box search-group-box box-ma10">
|
824 |
-
<?php $filter_by_status = ig_es_get_request_data( 'filter_by_status' ); ?>
|
825 |
-
<select name="filter_by_status">
|
826 |
-
<?php echo ES_Common::prepare_statuses_dropdown_options( $filter_by_status, __( 'All Statuses', 'email-subscribers' ) ); ?>
|
827 |
-
</select>
|
828 |
-
</p>
|
829 |
-
<p class="search-box search-group-box box-ma10">
|
830 |
-
<?php $filter_by_list_id = ig_es_get_request_data( 'filter_by_list_id' ); ?>
|
831 |
-
<select name="filter_by_list_id">
|
832 |
-
<?php echo ES_Common::prepare_list_dropdown_options( $filter_by_list_id, __( 'All Lists', 'email-subscribers' ) ); ?>
|
833 |
-
</select>
|
834 |
-
</p>
|
835 |
-
|
836 |
-
<?php }
|
837 |
-
|
838 |
-
|
839 |
-
/**
|
840 |
-
* Handles data query and filter, sorting, and pagination.
|
841 |
-
*/
|
842 |
-
public function prepare_items() {
|
843 |
-
|
844 |
-
$this->_column_headers = $this->get_column_info();
|
845 |
-
|
846 |
-
/** Process bulk action */
|
847 |
-
$this->process_bulk_action();
|
848 |
-
$this->search_box( ig_es_get_request_data( 's' ), 'subscriber-search-input' );
|
849 |
-
$this->prepare_lists_dropdown();
|
850 |
-
$this->prepare_statuses_dropdown();
|
851 |
-
|
852 |
-
$per_page = $this->get_items_per_page( self::$option_per_page, 200 );
|
853 |
-
$current_page = $this->get_pagenum();
|
854 |
-
$total_items = $this->get_subscribers( 0, 0, true );
|
855 |
-
|
856 |
-
$this->set_pagination_args( array(
|
857 |
-
'total_items' => $total_items, //WE have to calculate the total number of items
|
858 |
-
'per_page' => $per_page //WE have to determine how many items to show on a page
|
859 |
-
) );
|
860 |
-
|
861 |
-
$contacts = $this->get_subscribers( $per_page, $current_page );
|
862 |
-
|
863 |
-
|
864 |
-
$this->items = $contacts;
|
865 |
-
|
866 |
-
if ( count( $contacts ) > 0 ) {
|
867 |
-
|
868 |
-
$contact_ids = array_map( array( $this, 'get_contact_id' ), $contacts );
|
869 |
-
|
870 |
-
$contact_lists_statuses = ES_DB_Lists_Contacts::get_list_status_by_contact_ids( $contact_ids );
|
871 |
-
|
872 |
-
$this->contact_lists_statuses = $contact_lists_statuses;
|
873 |
-
|
874 |
-
$lists_id_name_map = ES()->lists_db->get_list_id_name_map();
|
875 |
-
|
876 |
-
$this->lists_id_name_map = $lists_id_name_map;
|
877 |
-
|
878 |
-
}
|
879 |
-
}
|
880 |
-
|
881 |
-
public function get_contact_id(
|
882 |
-
$contact
|
883 |
-
) {
|
884 |
-
return $contact['id'];
|
885 |
-
}
|
886 |
-
|
887 |
-
public function prepare_lists_dropdown() {
|
888 |
-
$data = '<label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label><select name="list_id" id="list_id" class="groupsselect" style="display: none">';
|
889 |
-
$data .= ES_Common::prepare_list_dropdown_options();
|
890 |
-
$data .= '</select>';
|
891 |
-
|
892 |
-
echo $data;
|
893 |
-
}
|
894 |
-
|
895 |
-
/**
|
896 |
-
* Edit Status
|
897 |
-
*
|
898 |
-
* @since 4.0.0
|
899 |
-
*/
|
900 |
-
public function prepare_statuses_dropdown() {
|
901 |
-
$data = '<label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label><select name="status_select" id="status_select" class="statusesselect" style="display:none;">';
|
902 |
-
$data .= ES_Common::prepare_statuses_dropdown_options();
|
903 |
-
$data .= '</select>';
|
904 |
-
|
905 |
-
echo $data;
|
906 |
-
}
|
907 |
-
|
908 |
-
/**
|
909 |
-
* Process Bulk Action
|
910 |
-
*
|
911 |
-
* @since 4.0.0
|
912 |
-
*/
|
913 |
-
public function process_bulk_action() {
|
914 |
-
|
915 |
-
//Detect when a bulk action is being triggered...
|
916 |
-
if ( 'delete' === $this->current_action() ) {
|
917 |
-
|
918 |
-
// In our file that handles the request, verify the nonce.
|
919 |
-
$nonce = esc_attr( ig_es_get_request_data( '_wpnonce' ) );
|
920 |
-
|
921 |
-
if ( ! wp_verify_nonce( $nonce, 'ig_es_delete_subscriber' ) ) {
|
922 |
-
die( 'You do not have a permission to delete contact(s)' );
|
923 |
-
} else {
|
924 |
-
$subscriber_id = absint( ig_es_get_request_data( 'subscriber' ) );
|
925 |
-
$deleted = ES()->contacts_db->delete_contacts_by_ids( array( $subscriber_id ) );
|
926 |
-
if ( $deleted ) {
|
927 |
-
$message = __( 'Contact(s) have been deleted successfully!', 'email-subscribers' );
|
928 |
-
ES_Common::show_message( $message, 'success' );
|
929 |
-
}
|
930 |
-
|
931 |
-
return;
|
932 |
-
}
|
933 |
-
|
934 |
-
}
|
935 |
-
|
936 |
-
if ( 'resend' === $this->current_action() ) {
|
937 |
-
// In our file that handles the request, verify the nonce.
|
938 |
-
$nonce = esc_attr( ig_es_get_request_data( '_wpnonce' ) );
|
939 |
-
|
940 |
-
if ( ! wp_verify_nonce( $nonce, 'ig_es_delete_subscriber' ) ) {
|
941 |
-
die( 'You do not have a permission to resend email confirmation' );
|
942 |
-
} else {
|
943 |
-
$id = absint( ig_es_get_request_data( 'subscriber' ) );
|
944 |
-
$subscriber = ES()->contacts_db->get_by_id( $id );
|
945 |
-
$template_data = array(
|
946 |
-
'email' => $subscriber['email'],
|
947 |
-
'db_id' => $subscriber['id'],
|
948 |
-
'name' => $subscriber['first_name'],
|
949 |
-
'first_name' => $subscriber['first_name'],
|
950 |
-
'last_name' => $subscriber['last_name'],
|
951 |
-
'guid' => $subscriber['hash']
|
952 |
-
);
|
953 |
-
|
954 |
-
$subject = get_option( 'ig_es_confirmation_mail_subject', true );
|
955 |
-
$content = ES_Mailer::prepare_double_optin_email( $template_data );
|
956 |
-
$response = ES_Mailer::send( $subscriber['email'], $subject, $content );
|
957 |
-
|
958 |
-
if ( $response ) {
|
959 |
-
$message = __( 'Confirmation email has been sent successfully!', 'email-subscribers' );
|
960 |
-
ES_Common::show_message( $message, 'success' );
|
961 |
-
}
|
962 |
-
|
963 |
-
return;
|
964 |
-
|
965 |
-
}
|
966 |
-
|
967 |
-
}
|
968 |
-
|
969 |
-
$action = ig_es_get_request_data( 'action' );
|
970 |
-
$action2 = ig_es_get_request_data( 'action2' );
|
971 |
-
|
972 |
-
$actions = array( 'bulk_delete', 'bulk_status_update', 'bulk_list_update', 'bulk_list_add' );
|
973 |
-
if ( in_array( $action, $actions ) || in_array( $action2, $actions ) ) {
|
974 |
-
|
975 |
-
$subscriber_ids = ig_es_get_request_data( 'subscribers' );
|
976 |
-
if ( empty( $subscriber_ids ) ) {
|
977 |
-
$message = __( 'Please select subscribers to update.', 'email-subscribers' );
|
978 |
-
ES_Common::show_message( $message, 'error' );
|
979 |
-
|
980 |
-
return;
|
981 |
-
}
|
982 |
-
|
983 |
-
// If the delete bulk action is triggered
|
984 |
-
if ( ( 'bulk_delete' === $action ) || ( 'bulk_delete' === $action2 ) ) {
|
985 |
-
|
986 |
-
$deleted = ES()->contacts_db->delete_contacts_by_ids( $subscriber_ids );
|
987 |
-
|
988 |
-
if ( $deleted ) {
|
989 |
-
$message = __( 'Contact(s) have been deleted successfully!', 'email-subscribers' );
|
990 |
-
ES_Common::show_message( $message, 'success' );
|
991 |
-
}
|
992 |
-
|
993 |
-
return;
|
994 |
-
}
|
995 |
-
|
996 |
-
if ( ( 'bulk_status_update' === $action ) || ( 'bulk_status_update' === $action2 ) ) {
|
997 |
-
$status = ig_es_get_request_data( 'status_select' );
|
998 |
-
|
999 |
-
if ( empty( $status ) ) {
|
1000 |
-
$message = __( 'Please select status.', 'email-subscribers' );
|
1001 |
-
ES_Common::show_message( $message, 'error' );
|
1002 |
-
|
1003 |
-
return;
|
1004 |
-
}
|
1005 |
-
|
1006 |
-
// loop over the array of record IDs and delete them
|
1007 |
-
$edited = ES_DB_Lists_Contacts::edit_subscriber_status( $subscriber_ids, $status );
|
1008 |
-
|
1009 |
-
if ( $edited ) {
|
1010 |
-
$message = __( 'Status has been changed successfully!', 'email-subscribers' );
|
1011 |
-
ES_Common::show_message( $message, 'success' );
|
1012 |
-
}
|
1013 |
-
|
1014 |
-
return;
|
1015 |
-
}
|
1016 |
-
|
1017 |
-
if ( ( 'bulk_list_update' === $action ) || ( 'bulk_list_update' === $action2 ) ) {
|
1018 |
-
|
1019 |
-
$list_id = ig_es_get_request_data( 'list_id' );
|
1020 |
-
if ( empty( $list_id ) ) {
|
1021 |
-
$message = __( 'Please select list.', 'email-subscribers' );
|
1022 |
-
ES_Common::show_message( $message, 'error' );
|
1023 |
-
|
1024 |
-
return;
|
1025 |
-
}
|
1026 |
-
|
1027 |
-
$edited = ES()->contacts_db->update_contacts_list( $subscriber_ids, $list_id );
|
1028 |
-
|
1029 |
-
if ( $edited ) {
|
1030 |
-
$message = __( 'Contact(s) have been moved to list successfully!', 'email-subscribers' );
|
1031 |
-
ES_Common::show_message( $message, 'success' );
|
1032 |
-
}
|
1033 |
-
|
1034 |
-
return;
|
1035 |
-
}
|
1036 |
-
|
1037 |
-
if ( ( 'bulk_list_add' === $action ) || ( 'bulk_list_add' === $action2 ) ) {
|
1038 |
-
|
1039 |
-
$list_id = ig_es_get_request_data( 'list_id' );
|
1040 |
-
|
1041 |
-
if ( empty( $list_id ) ) {
|
1042 |
-
$message = __( 'Please select list.', 'email-subscribers' );
|
1043 |
-
ES_Common::show_message( $message, 'error' );
|
1044 |
-
|
1045 |
-
return;
|
1046 |
-
}
|
1047 |
-
|
1048 |
-
$edited = ES()->contacts_db->add_contacts_to_list( $subscriber_ids, $list_id );
|
1049 |
-
|
1050 |
-
if ( $edited ) {
|
1051 |
-
$message = __( 'Contact(s) have been added to list successfully!', 'email-subscribers' );
|
1052 |
-
ES_Common::show_message( $message, 'success' );
|
1053 |
-
}
|
1054 |
-
|
1055 |
-
return;
|
1056 |
-
}
|
1057 |
-
}
|
1058 |
-
}
|
1059 |
-
|
1060 |
-
/**
|
1061 |
-
* Remove contacts from list when list is deleted
|
1062 |
-
*
|
1063 |
-
* @param $list_ids
|
1064 |
-
*
|
1065 |
-
* @since 4.3.1
|
1066 |
-
*/
|
1067 |
-
public function delete_contacts_from_list( $list_id ) {
|
1068 |
-
global $wpdb;
|
1069 |
-
|
1070 |
-
$ig_lists_contacts_table = IG_LISTS_CONTACTS_TABLE;
|
1071 |
-
|
1072 |
-
$query = "DELETE FROM {$ig_lists_contacts_table} WHERE list_id = %d";
|
1073 |
-
|
1074 |
-
$wpdb->query( $wpdb->prepare( $query, $list_id ) );
|
1075 |
-
}
|
1076 |
-
|
1077 |
-
/**
|
1078 |
-
* Set form_id = 0 as Form is already deleted
|
1079 |
-
*
|
1080 |
-
* @param $form_id
|
1081 |
-
*
|
1082 |
-
* @since 4.3.1
|
1083 |
-
*/
|
1084 |
-
public function set_default_form_id($form_id) {
|
1085 |
-
|
1086 |
-
global $wpdb;
|
1087 |
-
|
1088 |
-
$ig_contacts_table = IG_CONTACTS_TABLE;
|
1089 |
-
|
1090 |
-
$query = "UPDATE $ig_contacts_table SET form_id = 0 WHERE form_id = %d";
|
1091 |
-
|
1092 |
-
$wpdb->query($wpdb->prepare($query, $form_id));
|
1093 |
-
|
1094 |
-
}
|
1095 |
-
|
1096 |
-
public function no_items() {
|
1097 |
-
_e( 'No contacts avaliable.', 'email-subscribers' );
|
1098 |
-
}
|
1099 |
-
|
1100 |
-
|
1101 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-cron.php
DELETED
@@ -1,436 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
class ES_Cron {
|
9 |
-
/**
|
10 |
-
* ES_Cron constructor.
|
11 |
-
*
|
12 |
-
* @since 4.0.0
|
13 |
-
*/
|
14 |
-
public function __construct() {
|
15 |
-
add_action( 'wp_loaded', array( &$this, 'init' ), 1 );
|
16 |
-
}
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Initialize Cron
|
20 |
-
*
|
21 |
-
* @since 4.3.1
|
22 |
-
*/
|
23 |
-
public function init() {
|
24 |
-
|
25 |
-
add_filter( 'cron_schedules', array( &$this, 'filter_cron_schedules' ) );
|
26 |
-
|
27 |
-
// Not using anymore...remain for backward compatibility to avoid PHP warnings.
|
28 |
-
add_action( 'ig_es_cron_fifteen_mins', array( &$this, 'ig_es_cron_fifteen_mins_callback' ), 10, 2 );
|
29 |
-
|
30 |
-
add_action( 'ig_es_cron', array( &$this, 'hourly' ) );
|
31 |
-
add_action( 'ig_es_cron_worker', array( &$this, 'handler' ), - 1 );
|
32 |
-
|
33 |
-
if ( ! wp_next_scheduled( 'ig_es_cron' ) ) {
|
34 |
-
$this->update( true );
|
35 |
-
}
|
36 |
-
|
37 |
-
$this->handle_cron_request();
|
38 |
-
}
|
39 |
-
|
40 |
-
public function ig_es_cron_fifteen_mins_callback( $es = '', $guid = '' ) {
|
41 |
-
/**
|
42 |
-
* We are not using ig_es_cron_fifteen_mins action anymore.
|
43 |
-
*
|
44 |
-
* This function was attached to ig_es_cron_fifteen_mins cron
|
45 |
-
*
|
46 |
-
* @since 4.3.1
|
47 |
-
*/
|
48 |
-
}
|
49 |
-
|
50 |
-
|
51 |
-
/**
|
52 |
-
* Schedule/ Clear Cronjob
|
53 |
-
*
|
54 |
-
* @param bool $hourly_only
|
55 |
-
*
|
56 |
-
* @return bool
|
57 |
-
*
|
58 |
-
* @since 4.3.1
|
59 |
-
*/
|
60 |
-
public function update( $hourly_only = false ) {
|
61 |
-
|
62 |
-
// Schedule Main Cron
|
63 |
-
if ( ! wp_next_scheduled( 'ig_es_cron' ) ) {
|
64 |
-
wp_schedule_event( strtotime( 'midnight' ) - 300, 'hourly', 'ig_es_cron' );
|
65 |
-
|
66 |
-
return true;
|
67 |
-
} elseif ( $hourly_only ) {
|
68 |
-
return false;
|
69 |
-
}
|
70 |
-
|
71 |
-
$ig_es_disable_wp_cron = get_option( 'ig_es_disable_wp_cron', 'no' );
|
72 |
-
|
73 |
-
// Don't want to use WP_CRON?
|
74 |
-
if ( 'yes' === $ig_es_disable_wp_cron ) {
|
75 |
-
$this->clear();
|
76 |
-
|
77 |
-
return true;
|
78 |
-
}
|
79 |
-
|
80 |
-
$this->schedule();
|
81 |
-
|
82 |
-
return false;
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Update Crons every hour
|
87 |
-
*
|
88 |
-
* @since 4.3.1
|
89 |
-
*/
|
90 |
-
public function hourly() {
|
91 |
-
$this->update();
|
92 |
-
}
|
93 |
-
|
94 |
-
/**
|
95 |
-
* Schedule Events if it's not already scheduled
|
96 |
-
*
|
97 |
-
* @since 4.3.1
|
98 |
-
*/
|
99 |
-
public function schedule() {
|
100 |
-
|
101 |
-
// Add worker only once
|
102 |
-
if ( ! wp_next_scheduled( 'ig_es_cron_auto_responder' ) ) {
|
103 |
-
wp_schedule_event( floor( time() / 300 ) * 300 - 30, 'ig_es_cron_interval', 'ig_es_cron_auto_responder' );
|
104 |
-
}
|
105 |
-
|
106 |
-
if ( ! wp_next_scheduled( 'ig_es_cron_worker' ) ) {
|
107 |
-
wp_schedule_event( floor( time() / 300 ) * 300, 'ig_es_cron_interval', 'ig_es_cron_worker' );
|
108 |
-
}
|
109 |
-
|
110 |
-
}
|
111 |
-
|
112 |
-
/**
|
113 |
-
* Clear all ES Cronjob
|
114 |
-
*
|
115 |
-
* @since 4.3.1
|
116 |
-
*/
|
117 |
-
public function clear() {
|
118 |
-
wp_clear_scheduled_hook( 'ig_es_cron' );
|
119 |
-
wp_clear_scheduled_hook( 'ig_es_cron_worker' );
|
120 |
-
wp_clear_scheduled_hook( 'ig_es_cron_auto_responder' );
|
121 |
-
|
122 |
-
$cron_url = $this->url();
|
123 |
-
if ( ! empty( $cron_url ) ) {
|
124 |
-
parse_str( $cron_url, $output );
|
125 |
-
$guid = $output['guid'];
|
126 |
-
wp_clear_scheduled_hook( 'ig_es_cron_fifteen_mins', array( 'cron', $guid ) );
|
127 |
-
}
|
128 |
-
}
|
129 |
-
|
130 |
-
/**
|
131 |
-
* Lock Cron to avoid multiple execution of a cron
|
132 |
-
*
|
133 |
-
* @param int $key
|
134 |
-
*
|
135 |
-
* @return bool
|
136 |
-
*
|
137 |
-
* @since 4.3.1
|
138 |
-
*/
|
139 |
-
public function lock( $key = 0 ) {
|
140 |
-
|
141 |
-
$process_id = get_option( 'ig_es_cron_lock_' . $key, false );
|
142 |
-
|
143 |
-
if ( $process_id && $this->is_locked( $key ) ) {
|
144 |
-
return $process_id;
|
145 |
-
}
|
146 |
-
|
147 |
-
$process_id = @getmypid();
|
148 |
-
|
149 |
-
update_option( 'ig_es_cron_lock_' . $key, $process_id, false );
|
150 |
-
|
151 |
-
return true;
|
152 |
-
}
|
153 |
-
|
154 |
-
/**
|
155 |
-
* Unlock Cron
|
156 |
-
*
|
157 |
-
* @param int $key
|
158 |
-
*
|
159 |
-
* @since 4.3.1
|
160 |
-
*/
|
161 |
-
public function unlock( $key = 0 ) {
|
162 |
-
update_option( 'ig_es_cron_lock_' . $key, false, false );
|
163 |
-
}
|
164 |
-
|
165 |
-
/**
|
166 |
-
* Check If Cron Locked
|
167 |
-
*
|
168 |
-
* @param $key
|
169 |
-
*
|
170 |
-
* @return bool
|
171 |
-
*
|
172 |
-
* @since 4.3.1
|
173 |
-
*/
|
174 |
-
public function is_locked( $key = 0 ) {
|
175 |
-
global $wpdb;
|
176 |
-
|
177 |
-
$sql = "SELECT COUNT(*) FROM {$wpdb->prefix}options WHERE option_name LIKE %s AND option_value != ''";
|
178 |
-
|
179 |
-
$res = $wpdb->get_var( $wpdb->prepare( $sql, 'ig_es_cron_lock_' . $key . '%' ) );
|
180 |
-
|
181 |
-
return ! ! $res;
|
182 |
-
}
|
183 |
-
|
184 |
-
/**
|
185 |
-
* Set interval for Email Subscribers Cronjob
|
186 |
-
*
|
187 |
-
* @return mixed
|
188 |
-
*
|
189 |
-
* @since 4.3.1
|
190 |
-
*/
|
191 |
-
public function filter_cron_schedules() {
|
192 |
-
|
193 |
-
$schedules['ig_es_cron_interval'] = array(
|
194 |
-
'interval' => 15 * MINUTE_IN_SECONDS,
|
195 |
-
'display' => esc_html__( 'Email Subscribers Cronjob Interval' ),
|
196 |
-
);
|
197 |
-
|
198 |
-
return $schedules;
|
199 |
-
}
|
200 |
-
|
201 |
-
/**
|
202 |
-
* Get Cron URL
|
203 |
-
*
|
204 |
-
* @param bool $self
|
205 |
-
* @param bool $pro
|
206 |
-
* @param string $campaign_hash
|
207 |
-
*
|
208 |
-
* @return mixed|string|void
|
209 |
-
*
|
210 |
-
* @since 4.3.1
|
211 |
-
*/
|
212 |
-
public function url( $self = false, $pro = false, $campaign_hash = '' ) {
|
213 |
-
|
214 |
-
$cron_url = get_option( 'ig_es_cronurl', '' );
|
215 |
-
|
216 |
-
$result = array();
|
217 |
-
if ( ! empty( $cron_url ) ) {
|
218 |
-
parse_str( $cron_url, $result );
|
219 |
-
}
|
220 |
-
|
221 |
-
$cron_url = add_query_arg( 'es', 'cron', site_url() );
|
222 |
-
if ( empty( $result['guid'] ) ) {
|
223 |
-
$guid = ES_Common::generate_guid();
|
224 |
-
} else {
|
225 |
-
$guid = $result['guid'];
|
226 |
-
}
|
227 |
-
|
228 |
-
$cron_url = add_query_arg( 'guid', $guid, $cron_url );
|
229 |
-
update_option( 'ig_es_cronurl', $cron_url );
|
230 |
-
|
231 |
-
if ( ! empty( $campaign_hash ) ) {
|
232 |
-
$cron_url = add_query_arg( 'campaign_hash', $campaign_hash, $cron_url );
|
233 |
-
}
|
234 |
-
|
235 |
-
if ( $self ) {
|
236 |
-
$cron_url = add_query_arg( 'self', true, $cron_url );
|
237 |
-
$nonce = wp_create_nonce( 'ig_es_self_cron' );
|
238 |
-
$cron_url = add_query_arg( '_wpnonce', $nonce, $cron_url );
|
239 |
-
}
|
240 |
-
|
241 |
-
if ( $pro ) {
|
242 |
-
$cron_url = add_query_arg( 'es_pro', true, $cron_url );
|
243 |
-
}
|
244 |
-
|
245 |
-
return $cron_url;
|
246 |
-
}
|
247 |
-
|
248 |
-
/**
|
249 |
-
* Handler
|
250 |
-
*
|
251 |
-
* @return bool
|
252 |
-
*
|
253 |
-
* @since 4.3.1
|
254 |
-
*/
|
255 |
-
public function handler() {
|
256 |
-
|
257 |
-
if ( defined( 'IG_ES_DOING_CRON' ) || defined( 'DOING_AJAX' ) || defined( 'DOING_AUTOSAVE' ) || defined( 'WP_INSTALLING' ) || defined( 'MAILSTER_DO_UPDATE' ) ) {
|
258 |
-
return false;
|
259 |
-
}
|
260 |
-
|
261 |
-
define( 'IG_ES_DOING_CRON', microtime( true ) );
|
262 |
-
|
263 |
-
register_shutdown_function( array( &$this, 'shutdown' ) );
|
264 |
-
}
|
265 |
-
|
266 |
-
/**
|
267 |
-
* Handle Shutdown event
|
268 |
-
*
|
269 |
-
* @since 4.3.1
|
270 |
-
*/
|
271 |
-
public function shutdown() {
|
272 |
-
|
273 |
-
if ( ! defined( 'IG_ES_DOING_CRON' ) ) {
|
274 |
-
return;
|
275 |
-
}
|
276 |
-
|
277 |
-
// Unlock Cron Lock
|
278 |
-
$this->unlock();
|
279 |
-
}
|
280 |
-
|
281 |
-
/**
|
282 |
-
* Handle Cron Request
|
283 |
-
*
|
284 |
-
* @since 4.0.0
|
285 |
-
*
|
286 |
-
* @modify 4.3.1
|
287 |
-
*/
|
288 |
-
public function handle_cron_request() {
|
289 |
-
|
290 |
-
$execution_start_time = microtime( true );
|
291 |
-
|
292 |
-
$es_request = ig_es_get_request_data( 'es' );
|
293 |
-
$guid = ig_es_get_request_data( 'guid' );
|
294 |
-
|
295 |
-
// It's not a cron request . Say Goodbye!
|
296 |
-
if ( 'cron' !== $es_request ) {
|
297 |
-
return;
|
298 |
-
}
|
299 |
-
|
300 |
-
$self = ig_es_get_request_data( 'self', 0 );
|
301 |
-
|
302 |
-
if ( ! $this->is_locked() && ( $self == 0 || ( $self == 1 && wp_verify_nonce( ig_es_get_request_data( '_wpnonce' ), 'ig_es_self_cron' ) ) ) ) {
|
303 |
-
|
304 |
-
if ( ! empty( $guid ) ) {
|
305 |
-
|
306 |
-
$response = array( 'status' => 'SUCCESS', 'es_remaining_email_count' => 100 );
|
307 |
-
|
308 |
-
$es_process_request = true;
|
309 |
-
|
310 |
-
// filter request
|
311 |
-
$es_process_request = apply_filters( 'ig_es_email_sending_limit', $es_process_request );
|
312 |
-
|
313 |
-
if ( true === $es_process_request ) {
|
314 |
-
$security1 = strlen( $guid );
|
315 |
-
$es_c_cronguid_noslash = str_replace( "-", "", $guid );
|
316 |
-
$security2 = strlen( $es_c_cronguid_noslash );
|
317 |
-
if ( $security1 == 34 && $security2 == 30 ) {
|
318 |
-
if ( ! preg_match( '/[^a-z]/', $es_c_cronguid_noslash ) ) {
|
319 |
-
$cron_url = ES()->cron->url();
|
320 |
-
|
321 |
-
parse_str( $cron_url, $output );
|
322 |
-
|
323 |
-
// Now, all check pass.
|
324 |
-
if ( $guid === $output['guid'] ) {
|
325 |
-
|
326 |
-
// Release WP_CRON if it should
|
327 |
-
if ( wp_next_scheduled( 'ig_es_cron' ) - $execution_start_time < 0 ) {
|
328 |
-
spawn_cron();
|
329 |
-
}
|
330 |
-
|
331 |
-
// Lock Cron to avoid duplicate
|
332 |
-
$this->lock();
|
333 |
-
|
334 |
-
// Queue Auto Responder
|
335 |
-
do_action( 'ig_es_cron_auto_responder' );
|
336 |
-
|
337 |
-
// Worker
|
338 |
-
do_action( 'ig_es_cron_worker' );
|
339 |
-
|
340 |
-
$response['total_emails_sent'] = get_transient('ig_es_total_emails_sent');
|
341 |
-
$response['es_remaining_email_count'] = get_transient('ig_es_remaining_email_count');
|
342 |
-
$response['message'] = 'EMAILS_SENT';
|
343 |
-
$response['status'] = 'SUCCESS';
|
344 |
-
|
345 |
-
// Unlock it.
|
346 |
-
$this->unlock();
|
347 |
-
|
348 |
-
} else {
|
349 |
-
$self = false;
|
350 |
-
$response['status'] = 'ERROR';
|
351 |
-
$response['message'] = 'CRON_GUID_DOES_NOT_MATCH';
|
352 |
-
}
|
353 |
-
} else {
|
354 |
-
$self = false;
|
355 |
-
$response['status'] = 'ERROR';
|
356 |
-
$response['message'] = 'CRON_GUID_PATTERN_DOES_NOT_MATCH';
|
357 |
-
}
|
358 |
-
} else {
|
359 |
-
$self = false;
|
360 |
-
$response['status'] = 'ERROR';
|
361 |
-
$response['message'] = 'INVALID_CRON_GUID';
|
362 |
-
}
|
363 |
-
} else {
|
364 |
-
$self = false;
|
365 |
-
$response['status'] = 'ERROR';
|
366 |
-
$response['message'] = 'DO_NOT_PROCESS_REQUEST';
|
367 |
-
}
|
368 |
-
} else {
|
369 |
-
$self = false;
|
370 |
-
$response['status'] = 'ERROR';
|
371 |
-
$response['message'] = 'EMPTY_CRON_GUID';
|
372 |
-
}
|
373 |
-
|
374 |
-
} else {
|
375 |
-
$response['es_remaining_email_count'] = 0;
|
376 |
-
$response['message'] = 'PLEASE_TRY_AGAIN_LATER';
|
377 |
-
$response['status'] = 'ERROR';
|
378 |
-
}
|
379 |
-
|
380 |
-
if ( $self ) {
|
381 |
-
|
382 |
-
$total_emails_sent = ! empty( $response['total_emails_sent'] ) ? $response['total_emails_sent'] : 0;
|
383 |
-
$status = ! empty( $response['status'] ) ? $response['status'] : 'ERROR';
|
384 |
-
$total_emails_to_be_sent = ! empty( $response['es_remaining_email_count'] ) ? $response['es_remaining_email_count'] : 0;
|
385 |
-
$cron_url = ES()->cron->url( true );
|
386 |
-
|
387 |
-
$send_now_text = __( sprintf( "<a href='%s'>Send Now</a>", $cron_url ), 'email-subscribers' );
|
388 |
-
|
389 |
-
if ( 'SUCCESS' === $status ) {
|
390 |
-
$message = __( sprintf( 'Email(s) have been sent successfully!' ), 'email-subscribers' );
|
391 |
-
} else {
|
392 |
-
$message = $this->get_status_messages( $response['message'] );
|
393 |
-
}
|
394 |
-
|
395 |
-
include ES_PLUGIN_DIR . 'lite/public/partials/cron-message.php';
|
396 |
-
die();
|
397 |
-
} else {
|
398 |
-
echo json_encode( $response );
|
399 |
-
die();
|
400 |
-
}
|
401 |
-
}
|
402 |
-
|
403 |
-
/**
|
404 |
-
* Get Status Message
|
405 |
-
*
|
406 |
-
* @param string $message
|
407 |
-
*
|
408 |
-
* @return mixed|string
|
409 |
-
*
|
410 |
-
* @since 4.0.0
|
411 |
-
*/
|
412 |
-
public function get_status_messages( $message = '' ) {
|
413 |
-
|
414 |
-
if ( empty( $message ) ) {
|
415 |
-
return '';
|
416 |
-
}
|
417 |
-
|
418 |
-
$status_messages = array(
|
419 |
-
'EMAILS_SENT' => __( 'Emails sent successfully!', 'email-subscribers' ),
|
420 |
-
'EMAILS_NOT_FOUND' => __( 'Emails not found.', 'email-subscribers' ),
|
421 |
-
'NOTIFICATION_NOT_FOUND' => __( 'No notifications found to send.', 'email-subscribers' ),
|
422 |
-
'CRON_GUID_DOES_NOT_MATCH' => __( 'Invalid GUID.', 'email-subscribers' ),
|
423 |
-
'CRON_GUID_PATTERN_DOES_NOT_MATCH' => __( 'Invalid GUID.', 'email-subscribers' ),
|
424 |
-
'INVALID_CRON_GUID' => __( 'Invalid GUID.', 'email-subscribers' ),
|
425 |
-
'DO_NOT_PROCESS_REQUEST' => __( 'Not allowed to process request.', 'email-subscribers' ),
|
426 |
-
'EMPTY_CRON_GUID' => __( 'GUID is empty.', 'email-subscribers' ),
|
427 |
-
'PLEASE_TRY_AGAIN_LATER' => __( 'Please try after sometime.', 'email-subscribers' ),
|
428 |
-
'EMAIL_SENDING_LIMIT_EXCEEDED' => __( 'You have hit your hourly email sending limit. Please try after sometime.', 'email-subscribers' ),
|
429 |
-
);
|
430 |
-
|
431 |
-
$message_text = ! empty( $status_messages[ $message ] ) ? $status_messages[ $message ] : '';
|
432 |
-
|
433 |
-
return $message_text;
|
434 |
-
}
|
435 |
-
|
436 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-export-subscribers.php
DELETED
@@ -1,334 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
/**
|
9 |
-
* CSV Exporter bootstrap file
|
10 |
-
*/
|
11 |
-
class Export_Subscribers {
|
12 |
-
|
13 |
-
/**
|
14 |
-
* Constructor
|
15 |
-
*/
|
16 |
-
public function __construct() {
|
17 |
-
|
18 |
-
$report = ig_es_get_request_data( 'report' );
|
19 |
-
$status = ig_es_get_request_data( 'status' );
|
20 |
-
|
21 |
-
$can_access = ES_Common::ig_es_can_access( 'audience' );
|
22 |
-
|
23 |
-
if ( $report && $status && $can_access ) {
|
24 |
-
|
25 |
-
$status = trim( $status );
|
26 |
-
|
27 |
-
$selected_list_id = 0;
|
28 |
-
|
29 |
-
if ( 'select_list' === $status ) {
|
30 |
-
$selected_list_id = ig_es_get_request_data( 'list_id', 0 );
|
31 |
-
|
32 |
-
if ( 0 === $selected_list_id ) {
|
33 |
-
$message = __( "Please Select List", "email-subscribers" );
|
34 |
-
ES_Common::show_message( $message, 'error' );
|
35 |
-
exit();
|
36 |
-
}
|
37 |
-
}
|
38 |
-
|
39 |
-
$csv = $this->generate_csv( $status, $selected_list_id );
|
40 |
-
|
41 |
-
$file_name = strtolower( $status ) . '-' . 'contacts.csv';
|
42 |
-
|
43 |
-
if ( empty( $csv ) ) {
|
44 |
-
$message = __( "No data available", 'email-subscribers' );
|
45 |
-
ES_Common::show_message( $message, 'error' );
|
46 |
-
exit();
|
47 |
-
} else {
|
48 |
-
header( "Pragma: public" );
|
49 |
-
header( "Expires: 0" );
|
50 |
-
header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
|
51 |
-
header( "Cache-Control: private", false );
|
52 |
-
header( "Content-Type: application/octet-stream" );
|
53 |
-
header( "Content-Disposition: attachment; filename={$file_name};" );
|
54 |
-
header( "Content-Transfer-Encoding: binary" );
|
55 |
-
|
56 |
-
echo $csv;
|
57 |
-
exit;
|
58 |
-
}
|
59 |
-
}
|
60 |
-
|
61 |
-
add_filter( 'query_vars', array( $this, 'query_vars' ) );
|
62 |
-
add_action( 'parse_request', array( $this, 'parse_request' ) );
|
63 |
-
add_action( 'admin_menu', array( $this, 'plugin_menu' ) );
|
64 |
-
}
|
65 |
-
|
66 |
-
public function plugin_menu() {
|
67 |
-
add_submenu_page( null, 'Export Contacts', __( 'Export Contacts', 'email-subscribers' ), 'edit_posts', 'es_export_subscribers', array( $this, 'export_subscribers_page' ) );
|
68 |
-
}
|
69 |
-
|
70 |
-
public function prepare_header_footer_row() {
|
71 |
-
|
72 |
-
?>
|
73 |
-
|
74 |
-
<tr>
|
75 |
-
<th scope="col"><?php _e( 'No.', 'email-subscribers' ); ?></th>
|
76 |
-
<th scope="col"><?php _e( 'Contacts', 'email-subscribers' ); ?></th>
|
77 |
-
<th scope="col"><?php _e( 'Total Contacts', 'email-subscribers' ); ?></th>
|
78 |
-
<th scope="col"><?php _e( 'Export', 'email-subscribers' ); ?></th>
|
79 |
-
</tr>
|
80 |
-
|
81 |
-
<?php
|
82 |
-
}
|
83 |
-
|
84 |
-
public function prepare_body() {
|
85 |
-
|
86 |
-
$list_dropdown_html = "<select name='list_id' id='ig_es_export_list_dropdown'>";
|
87 |
-
$list_dropdown_html .= ES_Common::prepare_list_dropdown_options();
|
88 |
-
$list_dropdown_html .= "</select>";
|
89 |
-
|
90 |
-
$export_lists = array(
|
91 |
-
|
92 |
-
'all' => __( 'All Contacts', 'email-subscribers' ),
|
93 |
-
'subscribed' => __( 'Subscribed Contacts', 'email-subscribers' ),
|
94 |
-
'unsubscribed' => __( 'Unsubscribed Contacts', 'email-subscribers' ),
|
95 |
-
//'confirmed' => __( 'Confirmed Contacts', 'email-subscribers' ),
|
96 |
-
'unconfirmed' => __( 'Unconfirmed Contacts', 'email-subscribers' ),
|
97 |
-
'select_list' => $list_dropdown_html
|
98 |
-
);
|
99 |
-
|
100 |
-
$i = 1;
|
101 |
-
foreach ( $export_lists as $key => $export_list ) {
|
102 |
-
$class = '';
|
103 |
-
if ( $i % 2 === 0 ) {
|
104 |
-
$class = 'alternate';
|
105 |
-
}
|
106 |
-
|
107 |
-
$url = "admin.php?page=download_report&report=users&status={$key}";
|
108 |
-
|
109 |
-
?>
|
110 |
-
|
111 |
-
<tr class="<?php echo $class; ?>" id="ig_es_export_<?php echo $key; ?>">
|
112 |
-
<td><?php echo $i; ?></td>
|
113 |
-
<td><?php _e( $export_list, 'email-subscribers' ); ?></td>
|
114 |
-
<td class="ig_es_total_contacts"><?php echo $this->count_subscribers( $key ); ?></td>
|
115 |
-
<td><a href="<?php echo $url; ?>" id="ig_es_export_link_<?php echo $key; ?>"><?php _e( 'Download', 'email-subscribers' ); ?></a></td>
|
116 |
-
</tr>
|
117 |
-
|
118 |
-
<?php
|
119 |
-
$i ++;
|
120 |
-
}
|
121 |
-
|
122 |
-
}
|
123 |
-
|
124 |
-
public function export_subscribers_page() {
|
125 |
-
|
126 |
-
$audience_tab_main_navigation = array();
|
127 |
-
$active_tab = 'export';
|
128 |
-
$audience_tab_main_navigation = apply_filters( 'ig_es_audience_tab_main_navigation', $active_tab, $audience_tab_main_navigation );
|
129 |
-
|
130 |
-
?>
|
131 |
-
<div class="wrap">
|
132 |
-
<h2 style="margin-bottom:1em;">
|
133 |
-
<?php _e( 'Audience > Export Contacts', 'email-subscribers' );
|
134 |
-
ES_Common::prepare_main_header_navigation( $audience_tab_main_navigation );
|
135 |
-
?>
|
136 |
-
</h2>
|
137 |
-
<div class="tool-box">
|
138 |
-
<form name="frm_es_subscriberexport" method="post">
|
139 |
-
<table width="100%" class="widefat" id="straymanage">
|
140 |
-
<thead>
|
141 |
-
<?php $this->prepare_header_footer_row(); ?>
|
142 |
-
</thead>
|
143 |
-
<tbody>
|
144 |
-
<?php $this->prepare_body(); ?>
|
145 |
-
</tbody>
|
146 |
-
<tfoot>
|
147 |
-
<?php $this->prepare_header_footer_row(); ?>
|
148 |
-
</tfoot>
|
149 |
-
</table>
|
150 |
-
</form>
|
151 |
-
</div>
|
152 |
-
</div>
|
153 |
-
<?php }
|
154 |
-
|
155 |
-
|
156 |
-
/**
|
157 |
-
* @param string $status
|
158 |
-
*
|
159 |
-
* @return string|null
|
160 |
-
*/
|
161 |
-
public function count_subscribers( $status = 'all' ) {
|
162 |
-
|
163 |
-
global $wpdb;
|
164 |
-
|
165 |
-
switch ( $status ) {
|
166 |
-
case 'all':
|
167 |
-
$sql = "SELECT COUNT(*) FROM " . IG_LISTS_CONTACTS_TABLE;
|
168 |
-
break;
|
169 |
-
|
170 |
-
case 'subscribed':
|
171 |
-
$sql = $wpdb->prepare( "SELECT COUNT(*) FROM " . IG_LISTS_CONTACTS_TABLE . " WHERE status = %s", 'subscribed' );
|
172 |
-
break;
|
173 |
-
|
174 |
-
case 'unsubscribed':
|
175 |
-
$sql = $wpdb->prepare( "SELECT COUNT(email) FROM " . IG_CONTACTS_TABLE . " WHERE status = %s", 'unsubscribed' );
|
176 |
-
break;
|
177 |
-
|
178 |
-
case 'confirmed':
|
179 |
-
$sql = $wpdb->prepare( "SELECT COUNT(*) FROM " . IG_LISTS_CONTACTS_TABLE . " WHERE status = %s AND optin_type = %d", 'subscribed', IG_DOUBLE_OPTIN );
|
180 |
-
break;
|
181 |
-
|
182 |
-
case 'unconfirmed':
|
183 |
-
$sql = $wpdb->prepare( "SELECT count(contact_id) FROM " . IG_LISTS_CONTACTS_TABLE . " WHERE status = %s", 'unconfirmed' );
|
184 |
-
break;
|
185 |
-
|
186 |
-
case 'select_list':
|
187 |
-
default:
|
188 |
-
return '-';
|
189 |
-
break;
|
190 |
-
}
|
191 |
-
|
192 |
-
return $wpdb->get_var( $sql );
|
193 |
-
}
|
194 |
-
|
195 |
-
|
196 |
-
/**
|
197 |
-
* Allow for custom query variables
|
198 |
-
*/
|
199 |
-
public function query_vars( $query_vars ) {
|
200 |
-
$query_vars[] = 'download_report';
|
201 |
-
|
202 |
-
return $query_vars;
|
203 |
-
}
|
204 |
-
|
205 |
-
/**
|
206 |
-
* Parse the request
|
207 |
-
*/
|
208 |
-
public function parse_request( &$wp ) {
|
209 |
-
if ( array_key_exists( 'download_report', $wp->query_vars ) ) {
|
210 |
-
$this->download_report();
|
211 |
-
exit;
|
212 |
-
}
|
213 |
-
}
|
214 |
-
|
215 |
-
/**
|
216 |
-
* Download report
|
217 |
-
*/
|
218 |
-
public function download_report() {
|
219 |
-
?>
|
220 |
-
|
221 |
-
<div class="wrap">
|
222 |
-
<div id="icon-tools" class="icon32"></div>
|
223 |
-
<h2>Download Report</h2>
|
224 |
-
<p>
|
225 |
-
<a href="?page=download_report&report=users"><?php _e( 'Export the Subscribers', 'email-subscribers' ); ?></a>
|
226 |
-
</p>
|
227 |
-
|
228 |
-
<?php
|
229 |
-
}
|
230 |
-
|
231 |
-
/**
|
232 |
-
* Generate CSV
|
233 |
-
* first_name, last_name, email, status, list, subscribed_at, unsubscribed_at
|
234 |
-
*
|
235 |
-
* @param string $status
|
236 |
-
* @param string $list_id
|
237 |
-
*
|
238 |
-
* @return string
|
239 |
-
*/
|
240 |
-
public function generate_csv( $status = 'all', $list_id = '' ) {
|
241 |
-
|
242 |
-
global $wpdb;
|
243 |
-
|
244 |
-
ini_set( 'memory_limit', IG_MAX_MEMORY_LIMIT );
|
245 |
-
set_time_limit( IG_SET_TIME_LIMIT );
|
246 |
-
|
247 |
-
$email_subscribe_table = IG_CONTACTS_TABLE;
|
248 |
-
$contact_lists_table = IG_LISTS_CONTACTS_TABLE;
|
249 |
-
|
250 |
-
if ( 'all' === $status ) {
|
251 |
-
$query = "SELECT * FROM " . IG_LISTS_CONTACTS_TABLE;
|
252 |
-
} elseif ( 'subscribed' === $status ) {
|
253 |
-
$query = $wpdb->prepare( "SELECT * FROM {$contact_lists_table} WHERE status = %s", 'subscribed' );
|
254 |
-
} elseif ( 'unsubscribed' === $status ) {
|
255 |
-
$query = $wpdb->prepare( "SELECT * FROM {$contact_lists_table} WHERE status = %s", 'unsubscribed' );
|
256 |
-
} elseif ( 'confirmed' === $status ) {
|
257 |
-
$query = $wpdb->prepare( "SELECT * FROM {$contact_lists_table} WHERE status = %s AND optin_type = %d ", 'subscribed', IG_DOUBLE_OPTIN );
|
258 |
-
} elseif ( 'unconfirmed' === $status ) {
|
259 |
-
$query = $wpdb->prepare( "SELECT * FROM {$contact_lists_table} WHERE status = %s", 'unconfirmed' );
|
260 |
-
} elseif ( 'select_list' === $status ) {
|
261 |
-
$query = $wpdb->prepare( "SELECT * FROM {$contact_lists_table} WHERE list_id = %d ", $list_id );
|
262 |
-
} else {
|
263 |
-
// If nothing comes, export only 10 contacts
|
264 |
-
$query = "SELECT * FROM " . IG_LISTS_CONTACTS_TABLE . " LIMIT 0, 10";
|
265 |
-
}
|
266 |
-
|
267 |
-
$subscribers = array();
|
268 |
-
$results = $wpdb->get_results( $query, ARRAY_A );
|
269 |
-
|
270 |
-
if ( count( $results ) > 0 ) {
|
271 |
-
$contact_list_map = array();
|
272 |
-
$contact_ids = array();
|
273 |
-
foreach ( $results as $result ) {
|
274 |
-
|
275 |
-
if ( ! in_array( $result['contact_id'], $contact_ids ) ) {
|
276 |
-
$contact_ids[] = $result['contact_id'];
|
277 |
-
}
|
278 |
-
|
279 |
-
$contact_list_map[ $result['contact_id'] ][] = array(
|
280 |
-
'status' => $result['status'],
|
281 |
-
'list_id' => $result['list_id'],
|
282 |
-
'optin_type' => $result['optin_type']
|
283 |
-
);
|
284 |
-
}
|
285 |
-
|
286 |
-
$contact_ids_str = "'" . implode( "' , '", $contact_ids ) . "' ";
|
287 |
-
|
288 |
-
$query = "SELECT `id`, `first_name`, `last_name`, `email`, `created_at` FROM {$email_subscribe_table} WHERE id IN ({$contact_ids_str})";
|
289 |
-
|
290 |
-
$subscribers = $wpdb->get_results( $query, ARRAY_A );
|
291 |
-
}
|
292 |
-
|
293 |
-
$csv_output = '';
|
294 |
-
if ( count( $subscribers ) > 0 ) {
|
295 |
-
|
296 |
-
$headers = array(
|
297 |
-
__( 'First Name', 'email-subscribers' ),
|
298 |
-
__( 'Last Name', 'email-subscribers' ),
|
299 |
-
__( 'Email', 'email-subscribers' ),
|
300 |
-
__( 'List', 'email-subscribers' ),
|
301 |
-
__( 'Status', 'email-subscribers' ),
|
302 |
-
__( 'Opt-In Type', 'email-subscribers' ),
|
303 |
-
__( 'Created On', 'email-subscribers' )
|
304 |
-
);
|
305 |
-
|
306 |
-
$lists_id_name_map = ES()->lists_db->get_list_id_name_map();
|
307 |
-
$csv_output .= '"' . implode( '", "', $headers ) . '"';
|
308 |
-
$csv_output .= "\n";
|
309 |
-
|
310 |
-
foreach ( $subscribers as $key => $subscriber ) {
|
311 |
-
|
312 |
-
$data['first_name'] = trim( str_replace( '"', ' ', $subscriber['first_name'] ) );
|
313 |
-
$data['last_name'] = trim( str_replace( '"', ' ', $subscriber['last_name'] ) );
|
314 |
-
$data['email'] = trim( str_replace( '"', ' ', $subscriber['email'] ) );
|
315 |
-
|
316 |
-
$contact_id = $subscriber['id'];
|
317 |
-
if ( ! empty( $contact_list_map[ $contact_id ] ) ) {
|
318 |
-
foreach ( $contact_list_map[ $contact_id ] as $list_details ) {
|
319 |
-
$data['list'] = $lists_id_name_map[ $list_details['list_id'] ];
|
320 |
-
$data['status'] = ucfirst( $list_details['status'] );
|
321 |
-
$data['optin_type'] = ( $list_details['optin_type'] == 1 ) ? 'Single Opt-In' : 'Double Opt-In';
|
322 |
-
$data['created_at'] = $subscriber['created_at'];
|
323 |
-
$csv_output .= '"' . implode( '", "', $data ) . '"';
|
324 |
-
$csv_output .= "\n";
|
325 |
-
}
|
326 |
-
}
|
327 |
-
}
|
328 |
-
}
|
329 |
-
|
330 |
-
return $csv_output;
|
331 |
-
}
|
332 |
-
|
333 |
-
}
|
334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-form-widget.php
DELETED
@@ -1,80 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
class ES_Form_Widget extends WP_Widget {
|
9 |
-
|
10 |
-
function __construct() {
|
11 |
-
parent::__construct( 'email-subscribers-form', __( 'Email Subscribers', 'email-subscribers' ), array( 'description' => __( 'Email Subscribers Form', 'email-subscribers' ) ) );
|
12 |
-
}
|
13 |
-
|
14 |
-
public function widget( $args, $instance ) {
|
15 |
-
|
16 |
-
$title = apply_filters( 'widget_title', $instance['title'] );
|
17 |
-
|
18 |
-
echo $args['before_widget'];
|
19 |
-
|
20 |
-
if ( ! empty( $title ) ) {
|
21 |
-
echo $args['before_title'] . $title . $args['after_title'];
|
22 |
-
}
|
23 |
-
|
24 |
-
$form_id = isset( $instance['form_id'] ) ? esc_attr( $instance['form_id'] ) : '';
|
25 |
-
|
26 |
-
$form_data = array();
|
27 |
-
if ( ! empty( $form_id ) ) {
|
28 |
-
|
29 |
-
$form = ES()->forms_db->get_form_by_id( $form_id );
|
30 |
-
|
31 |
-
$form_data = ES_Forms_Table::get_form_data_from_body( $form );
|
32 |
-
}
|
33 |
-
|
34 |
-
|
35 |
-
$data = array();
|
36 |
-
$data['form_id'] = 0;
|
37 |
-
$data['list'] = '';
|
38 |
-
$data['name_visible'] = ( ! empty( $form_data['name_visible'] ) && 'yes' === $form_data['name_visible'] ) ? 'yes' : '';
|
39 |
-
$data['name_required'] = ( ! empty( $form_data['name_required'] ) && 'yes' === $form_data['name_required'] ) ? 'yes' : '';
|
40 |
-
$data['list_visible'] = ( ! empty( $form_data['list_visible'] ) && 'yes' === $form_data['list_visible'] ) ? 'yes' : '';
|
41 |
-
$data['lists'] = ( ! empty( $form_data['lists'] ) ) ? $form_data['lists'] : array();
|
42 |
-
$data['desc'] = ( ! empty( $form_data['desc'] ) ) ? $form_data['desc'] : '';
|
43 |
-
$data['name_label'] = ( ! empty( $form_data['name_label'] ) ) ? $form_data['name_label'] : '';
|
44 |
-
$data['name_place_holder'] = ( ! empty( $form_data['name_place_holder'] ) ) ? $form_data['name_place_holder'] : '';
|
45 |
-
$data['email_label'] = ( ! empty( $form_data['email_label'] ) ) ? $form_data['email_label'] : '';
|
46 |
-
$data['email_place_holder'] = ( ! empty( $form_data['email_place_holder'] ) ) ? $form_data['email_place_holder'] : '';
|
47 |
-
$data['button_label'] = ( ! empty( $form_data['button_label'] ) ) ? $form_data['button_label'] : '';
|
48 |
-
$data['form_version'] = ( ! empty( $form_data['form_version'] ) ) ? $form_data['form_version'] : '';
|
49 |
-
|
50 |
-
ES_Shortcode::render_form( $data );
|
51 |
-
|
52 |
-
echo $args['after_widget'];
|
53 |
-
}
|
54 |
-
|
55 |
-
public function form( $instance ) {
|
56 |
-
$selected_form_id = isset( $instance['form_id'] ) ? esc_attr( $instance['form_id'] ) : '';
|
57 |
-
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
|
58 |
-
?>
|
59 |
-
|
60 |
-
<p>
|
61 |
-
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Widget Title:' ); ?></label>
|
62 |
-
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
|
63 |
-
</p>
|
64 |
-
<p>
|
65 |
-
<label for="widget-email-subscribers-2-es_group"><?php _e( 'Forms' ); ?></label>
|
66 |
-
<select id="<?php echo $this->get_field_id( 'form_id' ); ?>" name="<?php echo $this->get_field_name( 'form_id' ); ?>" class="widefat" style="width:100%;">
|
67 |
-
<?php echo ES_Common::prepare_form_dropdown_options( $selected_form_id, null ); ?>
|
68 |
-
</select>
|
69 |
-
</p>
|
70 |
-
<?php
|
71 |
-
}
|
72 |
-
|
73 |
-
public function update( $new_instance, $old_instance ) {
|
74 |
-
$instance = array();
|
75 |
-
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
|
76 |
-
$instance['form_id'] = ( ! empty( $new_instance['form_id'] ) ) ? strip_tags( $new_instance['form_id'] ) : '';
|
77 |
-
|
78 |
-
return $instance;
|
79 |
-
}
|
80 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-forms-table.php
DELETED
@@ -1,834 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
if ( ! class_exists( 'WP_List_Table' ) ) {
|
9 |
-
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
10 |
-
}
|
11 |
-
|
12 |
-
class ES_Forms_Table extends WP_List_Table {
|
13 |
-
|
14 |
-
/**
|
15 |
-
* @since 4.2.1
|
16 |
-
* @var string
|
17 |
-
*
|
18 |
-
*/
|
19 |
-
public static $option_per_page = 'es_forms_per_page';
|
20 |
-
|
21 |
-
/**
|
22 |
-
* ES_DB_Forms object
|
23 |
-
*
|
24 |
-
* @since 4.3.1
|
25 |
-
* @var $db
|
26 |
-
*
|
27 |
-
*/
|
28 |
-
protected $db;
|
29 |
-
|
30 |
-
/**
|
31 |
-
* ES_Forms_Table constructor.
|
32 |
-
*
|
33 |
-
* @since 4.0
|
34 |
-
*/
|
35 |
-
public function __construct() {
|
36 |
-
|
37 |
-
parent::__construct( array(
|
38 |
-
'singular' => __( 'Forms', 'email-subscribers' ), //singular name of the listed records
|
39 |
-
'plural' => __( 'Forms', 'email-subscribers' ), //plural name of the listed records
|
40 |
-
'ajax' => false, //does this table support ajax?,
|
41 |
-
'screen' => 'es_forms'
|
42 |
-
) );
|
43 |
-
|
44 |
-
$this->db = new ES_DB_Forms();
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Add Screen Option
|
49 |
-
*
|
50 |
-
* @since 4.2.1
|
51 |
-
*/
|
52 |
-
public static function screen_options() {
|
53 |
-
|
54 |
-
$option = 'per_page';
|
55 |
-
$args = array(
|
56 |
-
'label' => __( 'Number of forms per page', 'email-subscribers' ),
|
57 |
-
'default' => 20,
|
58 |
-
'option' => self::$option_per_page
|
59 |
-
);
|
60 |
-
|
61 |
-
add_screen_option( $option, $args );
|
62 |
-
}
|
63 |
-
|
64 |
-
|
65 |
-
/**
|
66 |
-
* Render Forms list view
|
67 |
-
*
|
68 |
-
* @since 4.0
|
69 |
-
*/
|
70 |
-
public function render() {
|
71 |
-
|
72 |
-
$action = ig_es_get_request_data( 'action' );
|
73 |
-
?>
|
74 |
-
<div class="wrap">
|
75 |
-
<?php if ( 'new' === $action ) {
|
76 |
-
$this->es_new_form_callback();
|
77 |
-
} elseif ( 'edit' === $action ) {
|
78 |
-
$form = ig_es_get_request_data( 'form' );
|
79 |
-
echo $this->edit_form( absint( $form ) );
|
80 |
-
} else { ?>
|
81 |
-
<h1 class="wp-heading-inline"><?php _e( 'Forms', 'email-subscribers' ) ?><a href="admin.php?page=es_forms&action=new" class="page-title-action"> <?php _e( 'Add New', 'email-subscribers' ) ?></a></h1>
|
82 |
-
<?php Email_Subscribers_Admin::es_feedback(); ?>
|
83 |
-
<div id="poststuff">
|
84 |
-
<div id="post-body" class="metabox-holder column-1">
|
85 |
-
<div id="post-body-content">
|
86 |
-
<div class="meta-box-sortables ui-sortable">
|
87 |
-
<form method="post">
|
88 |
-
<?php
|
89 |
-
$this->prepare_items();
|
90 |
-
$this->display(); ?>
|
91 |
-
</form>
|
92 |
-
</div>
|
93 |
-
|
94 |
-
</div>
|
95 |
-
</div>
|
96 |
-
<br class="clear">
|
97 |
-
</div>
|
98 |
-
</div>
|
99 |
-
<?php }
|
100 |
-
}
|
101 |
-
|
102 |
-
public function validate_data( $data ) {
|
103 |
-
|
104 |
-
$nonce = $data['nonce'];
|
105 |
-
$form_name = $data['name'];
|
106 |
-
$lists = $data['lists'];
|
107 |
-
|
108 |
-
$status = 'error';
|
109 |
-
$error = false;
|
110 |
-
$message = '';
|
111 |
-
if ( ! wp_verify_nonce( $nonce, 'es_form' ) ) {
|
112 |
-
$message = __( 'You do not have permission to edit this form.', 'email-subscribers' );
|
113 |
-
$error = true;
|
114 |
-
} elseif ( empty( $form_name ) ) {
|
115 |
-
$message = __( 'Please add form name.', 'email-subscribers' );
|
116 |
-
$error = true;
|
117 |
-
}
|
118 |
-
|
119 |
-
if ( empty( $lists ) ) {
|
120 |
-
$message = __( 'Please select list(s) in which contact will be subscribed.', 'email-subscribers' );
|
121 |
-
$error = true;
|
122 |
-
}
|
123 |
-
|
124 |
-
if ( ! $error ) {
|
125 |
-
$status = 'success';
|
126 |
-
}
|
127 |
-
|
128 |
-
$response = array(
|
129 |
-
'status' => $status,
|
130 |
-
'message' => $message
|
131 |
-
);
|
132 |
-
|
133 |
-
return $response;
|
134 |
-
|
135 |
-
}
|
136 |
-
|
137 |
-
public function es_new_form_callback() {
|
138 |
-
|
139 |
-
$submitted = ig_es_get_request_data( 'submitted' );
|
140 |
-
|
141 |
-
if ( 'submitted' === $submitted ) {
|
142 |
-
|
143 |
-
$nonce = ig_es_get_request_data( '_wpnonce' );
|
144 |
-
$form_data = ig_es_get_request_data( 'form_data' );
|
145 |
-
$lists = ig_es_get_request_data( 'lists' );
|
146 |
-
|
147 |
-
$form_data['lists'] = $lists;
|
148 |
-
|
149 |
-
$validate_data = array(
|
150 |
-
'nonce' => $nonce,
|
151 |
-
'name' => ! empty( $form_data['name'] ) ? sanitize_text_field( $form_data['name'] ) : '',
|
152 |
-
'lists' => ! empty( $form_data['lists'] ) ? $form_data['lists'] : array()
|
153 |
-
);
|
154 |
-
|
155 |
-
$response = $this->validate_data( $validate_data );
|
156 |
-
|
157 |
-
if ( 'error' === $response['status'] ) {
|
158 |
-
$message = $response['message'];
|
159 |
-
ES_Common::show_message( $message, 'error' );
|
160 |
-
$this->prepare_list_form( null, $form_data );
|
161 |
-
|
162 |
-
return;
|
163 |
-
}
|
164 |
-
|
165 |
-
$this->save_form( null, $form_data );
|
166 |
-
$message = __( 'Form has been added successfully!', 'email-subscribers' );
|
167 |
-
ES_Common::show_message( $message, 'success' );
|
168 |
-
}
|
169 |
-
|
170 |
-
$this->prepare_list_form();
|
171 |
-
}
|
172 |
-
|
173 |
-
|
174 |
-
public function edit_form( $id ) {
|
175 |
-
global $wpdb;
|
176 |
-
|
177 |
-
if ( $id ) {
|
178 |
-
$form_data = array();
|
179 |
-
|
180 |
-
$data = $wpdb->get_results( "SELECT * FROM " . IG_FORMS_TABLE . " WHERE id = $id", ARRAY_A );
|
181 |
-
|
182 |
-
if ( count( $data ) > 0 ) {
|
183 |
-
|
184 |
-
$submitted = ig_es_get_request_data( 'submitted' );
|
185 |
-
|
186 |
-
if ( 'submitted' === $submitted ) {
|
187 |
-
|
188 |
-
$nonce = ig_es_get_request_data( '_wpnonce' );
|
189 |
-
$form_data = ig_es_get_request_data( 'form_data' );
|
190 |
-
$lists = ig_es_get_request_data( 'lists' );
|
191 |
-
|
192 |
-
$form_data['lists'] = $lists;
|
193 |
-
|
194 |
-
$validate_data = array(
|
195 |
-
'nonce' => $nonce,
|
196 |
-
'name' => $form_data['name'],
|
197 |
-
'lists' => $form_data['lists']
|
198 |
-
);
|
199 |
-
|
200 |
-
$response = $this->validate_data( $validate_data );
|
201 |
-
|
202 |
-
if ( 'error' === $response['status'] ) {
|
203 |
-
$message = $response['message'];
|
204 |
-
ES_Common::show_message( $message, 'error' );
|
205 |
-
$this->prepare_list_form( $id, $form_data );
|
206 |
-
|
207 |
-
return;
|
208 |
-
}
|
209 |
-
|
210 |
-
$this->save_form( $id, $form_data );
|
211 |
-
$message = __( 'Form has been updated successfully!', 'email-subscribers' );
|
212 |
-
ES_Common::show_message( $message, 'success' );
|
213 |
-
} else {
|
214 |
-
|
215 |
-
$data = $data[0];
|
216 |
-
$id = $data['id'];
|
217 |
-
$form_data = self::get_form_data_from_body( $data );
|
218 |
-
}
|
219 |
-
} else {
|
220 |
-
$message = __( 'Sorry, form not found', 'email-subscribers' );
|
221 |
-
ES_Common::show_message( $message, 'error' );
|
222 |
-
}
|
223 |
-
|
224 |
-
$this->prepare_list_form( $id, $form_data );
|
225 |
-
}
|
226 |
-
}
|
227 |
-
|
228 |
-
public function prepare_list_form( $id = 0, $data = array() ) {
|
229 |
-
|
230 |
-
$is_new = empty( $id ) ? 1 : 0;
|
231 |
-
|
232 |
-
$action = 'new';
|
233 |
-
if ( ! $is_new ) {
|
234 |
-
$action = 'edit';
|
235 |
-
}
|
236 |
-
|
237 |
-
$form_data['name'] = ! empty( $data['name'] ) ? sanitize_text_field( $data['name'] ) : '';
|
238 |
-
$form_data['name_visible'] = ! empty( $data['name_visible'] ) ? sanitize_text_field( $data['name_visible'] ) : 'no';
|
239 |
-
$form_data['name_required'] = ! empty( $data['name_required'] ) ? sanitize_text_field( $data['name_required'] ) : 'no';
|
240 |
-
$form_data['name_label'] = ! empty( $data['name_label'] ) ? sanitize_text_field( $data['name_label'] ) : '';
|
241 |
-
$form_data['name_place_holder'] = ! empty( $data['name_place_holder'] ) ? sanitize_text_field( $data['name_place_holder'] ) : '';
|
242 |
-
$form_data['email_label'] = ! empty( $data['email_label'] ) ? sanitize_text_field( $data['email_label'] ) : '';
|
243 |
-
$form_data['email_place_holder'] = ! empty( $data['email_place_holder'] ) ? sanitize_text_field( $data['email_place_holder'] ) : '';
|
244 |
-
$form_data['button_label'] = ! empty( $data['button_label'] ) ? sanitize_text_field( $data['button_label'] ) : __( 'Subscribe', 'email-subscribers' );
|
245 |
-
$form_data['list_visible'] = ! empty( $data['list_visible'] ) ? $data['list_visible'] : 'no';
|
246 |
-
$form_data['lists'] = ! empty( $data['lists'] ) ? $data['lists'] : array();
|
247 |
-
$form_data['af_id'] = ! empty( $data['af_id'] ) ? $data['af_id'] : 0;
|
248 |
-
$form_data['desc'] = ! empty( $data['desc'] ) ? sanitize_text_field( $data['desc'] ) : '';
|
249 |
-
|
250 |
-
$lists = ES()->lists_db->get_list_id_name_map();
|
251 |
-
$nonce = wp_create_nonce( 'es_form' );
|
252 |
-
|
253 |
-
?>
|
254 |
-
|
255 |
-
<div class="wrap">
|
256 |
-
<h1 class="wp-heading-inline">
|
257 |
-
<?php
|
258 |
-
if ( $is_new ) {
|
259 |
-
_e( 'New Form', 'email-subscribers' );
|
260 |
-
} else {
|
261 |
-
_e( 'Edit Form', 'email-subscribers' );
|
262 |
-
}
|
263 |
-
|
264 |
-
?>
|
265 |
-
</h1>
|
266 |
-
|
267 |
-
<?php Email_Subscribers_Admin::es_feedback(); ?>
|
268 |
-
|
269 |
-
<div id="poststuff">
|
270 |
-
<div id="post-body" class="metabox-holder column-1">
|
271 |
-
<div id="post-body-content">
|
272 |
-
<div class="meta-box-sortables ui-sortable">
|
273 |
-
<form method="post" action="admin.php?page=es_forms&action=<?php echo $action; ?>&form=<?php echo $id; ?>&_wpnonce=<?php echo $nonce; ?>">
|
274 |
-
<table class="form-table">
|
275 |
-
<tbody>
|
276 |
-
<tr>
|
277 |
-
<th scope="row">
|
278 |
-
<label for="tag-link"><?php echo __( 'Form Name', 'email-subscribers' ); ?></label>
|
279 |
-
</th>
|
280 |
-
<td>
|
281 |
-
<input type="text" name="form_data[name]" id="ig_es_title" value="<?php echo stripslashes( $form_data['name'] ); ?>" size="30" maxlength="100"/>
|
282 |
-
</td>
|
283 |
-
</tr>
|
284 |
-
<tr>
|
285 |
-
<th scope="row">
|
286 |
-
<label for="tag-link"><?php echo __( 'Description', 'email-subscribers' ); ?></label>
|
287 |
-
</th>
|
288 |
-
<td>
|
289 |
-
<input type="text" name="form_data[desc]" id="ig_es_title" value="<?php echo stripslashes( $form_data['desc'] ); ?>" size="30" maxlength="100"/>
|
290 |
-
</td>
|
291 |
-
</tr>
|
292 |
-
<tr>
|
293 |
-
<th scope="row">
|
294 |
-
<label for="tag-link"><?php echo __( 'Form Fields', 'email-subscribers' ); ?></label>
|
295 |
-
</th>
|
296 |
-
<td>
|
297 |
-
<table class="">
|
298 |
-
<tr class="form-field">
|
299 |
-
<td><b><?php _e( 'Field', 'email-subscribers' ); ?></b></td>
|
300 |
-
<td><b><?php _e( 'Show?', 'email-subscribers' ); ?></b></td>
|
301 |
-
<td><b><?php _e( 'Required?', 'email-subscribers' ); ?></b></td>
|
302 |
-
<td><b><?php _e( 'Label', 'email-subscribers' ); ?></b></td>
|
303 |
-
<td><b><?php _e( 'Place Holder', 'email-subscribers' ); ?></b></td>
|
304 |
-
</tr>
|
305 |
-
<tr class="form-field">
|
306 |
-
<td><?php _e( 'Email', 'email-subscribers' ); ?></td>
|
307 |
-
<td><input type="checkbox" class="" name="form_data[email_visible]" value="yes" disabled="disabled" checked="checked"></td>
|
308 |
-
<td><input type="checkbox" class="" name="form_data[email_required]" value="yes" disabled="disabled" checked="checked"></td>
|
309 |
-
<td><input type="text" class="" name="form_data[email_label]" value="<?php echo $form_data['email_label']; ?>"></td>
|
310 |
-
<td><input type="text" class="" name="form_data[email_place_holder]" value="<?php echo $form_data['email_place_holder']; ?>"></td>
|
311 |
-
</tr>
|
312 |
-
<tr class="form-field">
|
313 |
-
<td><?php _e( 'Name', 'email-subscribers' ); ?></td>
|
314 |
-
<td><input type="checkbox" class="es_visible" name="form_data[name_visible]" value="yes" <?php if ( $form_data['name_visible'] === 'yes' ) {
|
315 |
-
echo 'checked="checked"';
|
316 |
-
} ?> /></td>
|
317 |
-
<td><input type="checkbox" class="es_required" name="form_data[name_required]" value="yes" <?php if ( $form_data['name_required'] === 'yes' ) {
|
318 |
-
echo 'checked=checked';
|
319 |
-
} ?>></td>
|
320 |
-
<td><input type="text" class="es_name_label" name="form_data[name_label]" value="<?php echo $form_data['name_label']; ?>" <?php if ( $form_data['name_required'] === 'yes' ) {
|
321 |
-
echo 'disabled=disabled';
|
322 |
-
} ?> ></td>
|
323 |
-
<td><input type="text" class="es_name_label" name="form_data[name_place_holder]" value="<?php echo $form_data['name_place_holder']; ?>" <?php if ( $form_data['name_required'] === 'yes' ) {
|
324 |
-
echo 'disabled=disabled';
|
325 |
-
} ?> ></td>
|
326 |
-
</tr>
|
327 |
-
<tr class="form-field">
|
328 |
-
<td><?php _e( 'Button', 'email-subscribers' ); ?></td>
|
329 |
-
<td><input type="checkbox" class="" name="form_data[button_visible]" value="yes" disabled="disabled" checked="checked"></td>
|
330 |
-
<td><input type="checkbox" class="" name="form_data[button_required]" value="yes" disabled="disabled" checked="checked"></td>
|
331 |
-
<td><input type="text" class="" name="form_data[button_label]" value="<?php echo $form_data['button_label']; ?>"></td>
|
332 |
-
</tr>
|
333 |
-
</table>
|
334 |
-
</td>
|
335 |
-
</tr>
|
336 |
-
|
337 |
-
<tr>
|
338 |
-
<th scope="row">
|
339 |
-
<label for="tag-link"><?php echo __( 'Lists', 'email-subscribers' ); ?></label>
|
340 |
-
<p class="helper"> <?php _e( 'Contacts will be added into selected list(s)', 'email-subscribers' ); ?></p>
|
341 |
-
</th>
|
342 |
-
<td>
|
343 |
-
<?php
|
344 |
-
|
345 |
-
if ( count( $lists ) > 0 ) {
|
346 |
-
|
347 |
-
echo ES_Shortcode::prepare_lists_checkboxes( $lists, array_keys( $lists ), 3, (array) $form_data['lists'] );
|
348 |
-
|
349 |
-
} else {
|
350 |
-
$create_list_link = admin_url( 'admin.php?page=es_lists&action=new' );
|
351 |
-
?>
|
352 |
-
<span><?php _e( sprintf( 'List not found. Please <a href="%s">create your first list</a>.', $create_list_link ) ); ?></span>
|
353 |
-
<?php } ?>
|
354 |
-
</td>
|
355 |
-
</tr>
|
356 |
-
<tr>
|
357 |
-
<th scope="row">
|
358 |
-
<label for="tag-link"><?php echo __( 'Allow contact to choose list(s)', 'email-subscribers' ); ?></label>
|
359 |
-
<p class="helper"> <?php _e( 'Allow contacts to choose list(s) in which they want to subscribe.', 'email-subscribers' ); ?></p>
|
360 |
-
</th>
|
361 |
-
<td>
|
362 |
-
<input type="radio" name="form_data[list_visible]" value="yes" <?php if ( $form_data['list_visible'] === 'yes' ) {
|
363 |
-
echo 'checked="checked"';
|
364 |
-
} ?> /><?php _e( 'Yes', 'email-subscribers' ); ?>
|
365 |
-
|
366 |
-
<input type="radio" name="form_data[list_visible]" value="no" <?php if ( $form_data['list_visible'] === 'no' ) {
|
367 |
-
echo 'checked="checked"';
|
368 |
-
} ?> /> <?php _e( 'No', 'email-subscribers' ); ?>
|
369 |
-
</td>
|
370 |
-
|
371 |
-
|
372 |
-
</tr>
|
373 |
-
|
374 |
-
</tbody>
|
375 |
-
</table>
|
376 |
-
<input type="hidden" name="form_data[af_id]" value="<?php echo $form_data['af_id']; ?>"/>
|
377 |
-
<input type="hidden" name="submitted" value="submitted"/>
|
378 |
-
<?php if ( count( $lists ) > 0 ) { ?>
|
379 |
-
<div class="row-blog"><?php submit_button(); ?></div>
|
380 |
-
<?php } else {
|
381 |
-
$lists_page_url = admin_url( 'admin.php?page=es_lists' );
|
382 |
-
$message = __( sprintf( 'List(s) not found. Please create a first list from <a href="%s">here</a>', $lists_page_url ), 'email-subscribers' );
|
383 |
-
$status = 'error';
|
384 |
-
ES_Common::show_message( $message, $status );
|
385 |
-
}
|
386 |
-
$url = 'https://www.icegram.com/email-subscribers-starter/?utm_source=in_app&utm_medium=es_form_captcha&utm_campaign=es_upsale';
|
387 |
-
?>
|
388 |
-
<div style=" background-image: linear-gradient(-100deg, rgba(250, 247, 133, 0.4), rgba(250, 247, 133, 0.8) 95%, rgba(250, 247, 133, 0.2)); padding: 10px; width: 35%; border-radius: 1em 0 1em 0; "><?php echo sprintf( __( 'Secure your form and avoid spam signups with Email Subscribers Starter Plan <a target="_blank" style="font-weight: bold; cursor:pointer; text-decoration:none" href="%s">Get started</a>',
|
389 |
-
'email-subscribers' ), $url ) ?></div>
|
390 |
-
</form>
|
391 |
-
</div>
|
392 |
-
</div>
|
393 |
-
</div>
|
394 |
-
<br class="clear">
|
395 |
-
</div>
|
396 |
-
</div>
|
397 |
-
|
398 |
-
<?php
|
399 |
-
|
400 |
-
}
|
401 |
-
|
402 |
-
public function save_form( $id, $data ) {
|
403 |
-
|
404 |
-
global $wpdb;
|
405 |
-
|
406 |
-
$form_data = self::prepare_form_data( $data );
|
407 |
-
|
408 |
-
if ( ! empty( $id ) ) {
|
409 |
-
$form_data['updated_at'] = ig_get_current_date_time();
|
410 |
-
|
411 |
-
// We don't want to change the created_at date for update
|
412 |
-
unset( $form_data['created_at'] );
|
413 |
-
$return = $wpdb->update( IG_FORMS_TABLE, $form_data, array( 'id' => $id ) );
|
414 |
-
} else {
|
415 |
-
$return = $wpdb->insert( IG_FORMS_TABLE, $form_data );
|
416 |
-
}
|
417 |
-
|
418 |
-
return $return;
|
419 |
-
}
|
420 |
-
|
421 |
-
public static function prepare_form_data( $data ) {
|
422 |
-
|
423 |
-
$form_data = array();
|
424 |
-
$name = ! empty( $data['name'] ) ? sanitize_text_field( $data['name'] ) : '';
|
425 |
-
$desc = ! empty( $data['desc'] ) ? sanitize_text_field( $data['desc'] ) : '';
|
426 |
-
$email_label = ! empty( $data['email_label'] ) ? sanitize_text_field( $data['email_label'] ) : '';
|
427 |
-
$email_place_holder = ! empty( $data['email_place_holder'] ) ? sanitize_text_field( $data['email_place_holder'] ) : '';
|
428 |
-
$name_label = ! empty( $data['name_label'] ) ? sanitize_text_field( $data['name_label'] ) : '';
|
429 |
-
$name_place_holder = ! empty( $data['name_place_holder'] ) ? sanitize_text_field( $data['name_place_holder'] ) : '';
|
430 |
-
$button_label = ! empty( $data['button_label'] ) ? sanitize_text_field( $data['button_label'] ) : '';
|
431 |
-
$name_visible = ( ! empty( $data['name_visible'] ) && $data['name_visible'] === 'yes' ) ? true : false;
|
432 |
-
$name_required = ( ! empty( $data['name_required'] ) && $data['name_required'] === 'yes' ) ? true : false;
|
433 |
-
$list_visible = ( ! empty( $data['list_visible'] ) && $data['list_visible'] === 'yes' ) ? true : false;
|
434 |
-
$list_requried = true;
|
435 |
-
$list_ids = ! empty( $data['lists'] ) ? $data['lists'] : array();
|
436 |
-
$af_id = ! empty( $data['af_id'] ) ? $data['af_id'] : 0;
|
437 |
-
|
438 |
-
$body = array(
|
439 |
-
array(
|
440 |
-
'type' => 'text',
|
441 |
-
'name' => 'Name',
|
442 |
-
'id' => 'name',
|
443 |
-
'params' => array(
|
444 |
-
'label' => $name_label,
|
445 |
-
'place_holder' => $name_place_holder,
|
446 |
-
'show' => $name_visible,
|
447 |
-
'required' => $name_required
|
448 |
-
),
|
449 |
-
|
450 |
-
'position' => 1
|
451 |
-
),
|
452 |
-
|
453 |
-
array(
|
454 |
-
'type' => 'text',
|
455 |
-
'name' => 'Email',
|
456 |
-
'id' => 'email',
|
457 |
-
'params' => array(
|
458 |
-
'label' => $email_label,
|
459 |
-
'place_holder' => $email_place_holder,
|
460 |
-
'show' => true,
|
461 |
-
'required' => true
|
462 |
-
),
|
463 |
-
|
464 |
-
'position' => 2
|
465 |
-
),
|
466 |
-
|
467 |
-
array(
|
468 |
-
'type' => 'checkbox',
|
469 |
-
'name' => 'Lists',
|
470 |
-
'id' => 'lists',
|
471 |
-
'params' => array(
|
472 |
-
'label' => 'Lists',
|
473 |
-
'show' => $list_visible,
|
474 |
-
'required' => $list_requried,
|
475 |
-
'values' => $list_ids
|
476 |
-
),
|
477 |
-
|
478 |
-
'position' => 3
|
479 |
-
),
|
480 |
-
|
481 |
-
array(
|
482 |
-
'type' => 'submit',
|
483 |
-
'name' => 'submit',
|
484 |
-
'id' => 'submit',
|
485 |
-
'params' => array(
|
486 |
-
'label' => $button_label,
|
487 |
-
'show' => true,
|
488 |
-
'required' => true
|
489 |
-
),
|
490 |
-
|
491 |
-
'position' => 4
|
492 |
-
),
|
493 |
-
|
494 |
-
);
|
495 |
-
|
496 |
-
$settings = array(
|
497 |
-
'lists' => $list_ids,
|
498 |
-
'desc' => $desc,
|
499 |
-
'form_version' => ES()->forms_db->version
|
500 |
-
);
|
501 |
-
|
502 |
-
$form_data['name'] = $name;
|
503 |
-
$form_data['body'] = maybe_serialize( $body );
|
504 |
-
$form_data['settings'] = maybe_serialize( $settings );
|
505 |
-
$form_data['styles'] = null;
|
506 |
-
$form_data['created_at'] = ig_get_current_date_time();
|
507 |
-
$form_data['updated_at'] = null;
|
508 |
-
$form_data['deleted_at'] = null;
|
509 |
-
$form_data['af_id'] = $af_id;
|
510 |
-
|
511 |
-
return $form_data;
|
512 |
-
}
|
513 |
-
|
514 |
-
public static function get_form_data_from_body( $data ) {
|
515 |
-
|
516 |
-
$name = ! empty( $data['name'] ) ? $data['name'] : '';
|
517 |
-
$id = ! empty( $data['id'] ) ? $data['id'] : '';
|
518 |
-
$af_id = ! empty( $data['af_id'] ) ? $data['af_id'] : '';
|
519 |
-
$body_data = maybe_unserialize( $data['body'] );
|
520 |
-
$settings_data = maybe_unserialize( $data['settings'] );
|
521 |
-
|
522 |
-
$desc = ! empty( $settings_data['desc'] ) ? $settings_data['desc'] : '';
|
523 |
-
$form_version = ! empty( $settings_data['form_version'] ) ? $settings_data['form_version'] : '0.1';
|
524 |
-
|
525 |
-
$form_data = array( 'form_id' => $id, 'name' => $name, 'af_id' => $af_id, 'desc' => $desc, 'form_version' => $form_version );
|
526 |
-
foreach ( $body_data as $d ) {
|
527 |
-
if ( $d['id'] === 'name' ) {
|
528 |
-
$form_data['name_visible'] = ( $d['params']['show'] === true ) ? 'yes' : '';
|
529 |
-
$form_data['name_required'] = ( $d['params']['required'] === true ) ? 'yes' : '';
|
530 |
-
$form_data['name_label'] = ! empty( $d['params']['label'] ) ? $d['params']['label'] : '';
|
531 |
-
$form_data['name_place_holder'] = ! empty( $d['params']['place_holder'] ) ? $d['params']['place_holder'] : '';
|
532 |
-
} elseif ( $d['id'] === 'lists' ) {
|
533 |
-
$form_data['list_visible'] = ( $d['params']['show'] === true ) ? 'yes' : '';
|
534 |
-
$form_data['list_required'] = ( $d['params']['required'] === true ) ? 'yes' : '';
|
535 |
-
$form_data['lists'] = ! empty( $d['params']['values'] ) ? $d['params']['values'] : array();
|
536 |
-
} elseif ( $d['id'] === 'email' ) {
|
537 |
-
$form_data['email_label'] = ! empty( $d['params']['label'] ) ? $d['params']['label'] : '';
|
538 |
-
$form_data['email_place_holder'] = ! empty( $d['params']['place_holder'] ) ? $d['params']['place_holder'] : '';
|
539 |
-
} elseif ( $d['id'] === 'submit' ) {
|
540 |
-
$form_data['button_label'] = ! empty( $d['params']['label'] ) ? $d['params']['label'] : '';
|
541 |
-
}
|
542 |
-
}
|
543 |
-
|
544 |
-
return $form_data;
|
545 |
-
}
|
546 |
-
|
547 |
-
/**
|
548 |
-
* Retrieve lists data from the database
|
549 |
-
*
|
550 |
-
* @param int $per_page
|
551 |
-
* @param int $page_number
|
552 |
-
*
|
553 |
-
* @return mixed
|
554 |
-
*/
|
555 |
-
public function get_lists( $per_page = 5, $page_number = 1, $do_count_only = false ) {
|
556 |
-
|
557 |
-
global $wpdb;
|
558 |
-
|
559 |
-
$order_by = sanitize_sql_orderby( ig_es_get_request_data( 'orderby' ) );
|
560 |
-
$order = ig_es_get_request_data( 'order' );
|
561 |
-
$search = ig_es_get_request_data( 's' );
|
562 |
-
|
563 |
-
$forms_table = IG_FORMS_TABLE;
|
564 |
-
if ( $do_count_only ) {
|
565 |
-
$sql = "SELECT count(*) as total FROM {$forms_table}";
|
566 |
-
} else {
|
567 |
-
$sql = "SELECT * FROM {$forms_table}";
|
568 |
-
}
|
569 |
-
|
570 |
-
$args = $query = array();
|
571 |
-
|
572 |
-
$add_where_clause = false;
|
573 |
-
|
574 |
-
if ( ! empty( $search ) ) {
|
575 |
-
$query[] = " name LIKE %s ";
|
576 |
-
$args[] = "%" . $wpdb->esc_like( $search ) . "%";
|
577 |
-
|
578 |
-
$add_where_clause = true;
|
579 |
-
}
|
580 |
-
|
581 |
-
if ( $add_where_clause ) {
|
582 |
-
$sql .= " WHERE ";
|
583 |
-
|
584 |
-
if ( count( $query ) > 0 ) {
|
585 |
-
$sql .= implode( " AND ", $query );
|
586 |
-
if ( count( $args ) > 0 ) {
|
587 |
-
$sql = $wpdb->prepare( $sql, $args );
|
588 |
-
}
|
589 |
-
}
|
590 |
-
}
|
591 |
-
|
592 |
-
if ( ! $do_count_only ) {
|
593 |
-
|
594 |
-
$order = ! empty( $order ) ? strtolower( $order ) : 'desc';
|
595 |
-
$expected_order_values = array( 'asc', 'desc' );
|
596 |
-
if ( ! in_array( $order, $expected_order_values ) ) {
|
597 |
-
$order = 'desc';
|
598 |
-
}
|
599 |
-
|
600 |
-
$default_order_by = esc_sql( 'created_at' );
|
601 |
-
|
602 |
-
$expected_order_by_values = array( 'name', 'created_at' );
|
603 |
-
|
604 |
-
if ( ! in_array( $order_by, $expected_order_by_values ) ) {
|
605 |
-
$order_by_clause = " ORDER BY {$default_order_by} DESC";
|
606 |
-
} else {
|
607 |
-
$order_by = esc_sql( $order_by );
|
608 |
-
$order_by_clause = " ORDER BY {$order_by} {$order}, {$default_order_by} DESC";
|
609 |
-
}
|
610 |
-
|
611 |
-
$sql .= $order_by_clause;
|
612 |
-
$sql .= " LIMIT $per_page";
|
613 |
-
$sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page;
|
614 |
-
|
615 |
-
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
|
616 |
-
} else {
|
617 |
-
$result = $wpdb->get_var( $sql );
|
618 |
-
}
|
619 |
-
|
620 |
-
return $result;
|
621 |
-
}
|
622 |
-
|
623 |
-
/**
|
624 |
-
* Returns the count of records in the database.
|
625 |
-
*
|
626 |
-
* @return null|string
|
627 |
-
*/
|
628 |
-
public function record_count() {
|
629 |
-
global $wpdb;
|
630 |
-
|
631 |
-
$sql = "SELECT COUNT(*) FROM " . IG_FORMS_TABLE;
|
632 |
-
|
633 |
-
return $wpdb->get_var( $sql );
|
634 |
-
}
|
635 |
-
|
636 |
-
/**
|
637 |
-
* Render a column when no column specific method exist.
|
638 |
-
*
|
639 |
-
* @param array $item
|
640 |
-
* @param string $column_name
|
641 |
-
*
|
642 |
-
* @return mixed
|
643 |
-
*/
|
644 |
-
public function column_default( $item, $column_name ) {
|
645 |
-
switch ( $column_name ) {
|
646 |
-
// case 'status':
|
647 |
-
// return $this->status_label_map( $item[ $column_name ] );
|
648 |
-
case 'created_at':
|
649 |
-
return ig_es_format_date_time( $item[ $column_name ] );
|
650 |
-
break;
|
651 |
-
case 'shortcode':
|
652 |
-
$shortcode = '[email-subscribers-form id="' . $item['id'] . '"]';
|
653 |
-
|
654 |
-
return '<code>' . $shortcode . '</code>';
|
655 |
-
break;
|
656 |
-
default:
|
657 |
-
return '';
|
658 |
-
}
|
659 |
-
}
|
660 |
-
|
661 |
-
/**
|
662 |
-
* Render the bulk edit checkbox
|
663 |
-
*
|
664 |
-
* @param array $item
|
665 |
-
*
|
666 |
-
* @return string
|
667 |
-
*/
|
668 |
-
function column_cb( $item ) {
|
669 |
-
return sprintf(
|
670 |
-
'<input type="checkbox" name="forms[]" value="%s" />', $item['id']
|
671 |
-
);
|
672 |
-
}
|
673 |
-
|
674 |
-
/**
|
675 |
-
* Method for name column
|
676 |
-
*
|
677 |
-
* @param array $item an array of DB data
|
678 |
-
*
|
679 |
-
* @return string
|
680 |
-
*/
|
681 |
-
function column_name( $item ) {
|
682 |
-
|
683 |
-
$list_nonce = wp_create_nonce( 'es_form' );
|
684 |
-
|
685 |
-
$title = '<strong>' . stripslashes( $item['name'] ) . '</strong>';
|
686 |
-
|
687 |
-
$page = ig_es_get_request_data( 'page' );
|
688 |
-
$actions = array(
|
689 |
-
'edit' => sprintf( __( '<a href="?page=%s&action=%s&form=%s&_wpnonce=%s">Edit</a>', 'email-subscribers' ), esc_attr( $page ), 'edit', absint( $item['id'] ), $list_nonce ),
|
690 |
-
'delete' => sprintf( __( '<a href="?page=%s&action=%s&form=%s&_wpnonce=%s" onclick="return checkDelete()">Delete</a>', 'email-subscribers' ), esc_attr( $page ), 'delete', absint( $item['id'] ), $list_nonce )
|
691 |
-
);
|
692 |
-
|
693 |
-
return $title . $this->row_actions( $actions );
|
694 |
-
}
|
695 |
-
|
696 |
-
|
697 |
-
/**
|
698 |
-
* Associative array of columns
|
699 |
-
*
|
700 |
-
* @return array
|
701 |
-
*/
|
702 |
-
function get_columns() {
|
703 |
-
$columns = array(
|
704 |
-
'cb' => '<input type="checkbox" />',
|
705 |
-
'name' => __( 'Name', 'email-subscribers' ),
|
706 |
-
'shortcode' => __( 'Shortcode', 'email-subscribers' ),
|
707 |
-
'created_at' => __( 'Created', 'email-subscribers' )
|
708 |
-
);
|
709 |
-
|
710 |
-
return $columns;
|
711 |
-
}
|
712 |
-
|
713 |
-
|
714 |
-
/**
|
715 |
-
* Columns to make sortable.
|
716 |
-
*
|
717 |
-
* @return array
|
718 |
-
*/
|
719 |
-
public function get_sortable_columns() {
|
720 |
-
$sortable_columns = array(
|
721 |
-
'name' => array( 'name', true ),
|
722 |
-
'created_at' => array( 'created_at', true ),
|
723 |
-
);
|
724 |
-
|
725 |
-
return $sortable_columns;
|
726 |
-
}
|
727 |
-
|
728 |
-
/**
|
729 |
-
* Returns an associative array containing the bulk action
|
730 |
-
*
|
731 |
-
* @return array
|
732 |
-
*/
|
733 |
-
public function get_bulk_actions() {
|
734 |
-
$actions = array(
|
735 |
-
'bulk_delete' => __( 'Delete', 'email-subscribers' )
|
736 |
-
);
|
737 |
-
|
738 |
-
return $actions;
|
739 |
-
}
|
740 |
-
|
741 |
-
public function search_box( $text, $input_id ) { ?>
|
742 |
-
<p class="search-box">
|
743 |
-
<label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
|
744 |
-
<input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>"/>
|
745 |
-
<?php submit_button( __( 'Search Forms', 'email-subscribers' ), 'button', false, false, array( 'id' => 'search-submit' ) ); ?>
|
746 |
-
</p>
|
747 |
-
<?php }
|
748 |
-
|
749 |
-
/**
|
750 |
-
* Handles data query and filter, sorting, and pagination.
|
751 |
-
*/
|
752 |
-
public function prepare_items() {
|
753 |
-
|
754 |
-
$this->_column_headers = $this->get_column_info();
|
755 |
-
|
756 |
-
|
757 |
-
/** Process bulk action */
|
758 |
-
$this->process_bulk_action();
|
759 |
-
|
760 |
-
$search_str = ig_es_get_request_data( 's' );
|
761 |
-
$this->search_box( $search_str, 'form-search-input' );
|
762 |
-
|
763 |
-
$per_page = $this->get_items_per_page( self::$option_per_page, 25 );
|
764 |
-
$current_page = $this->get_pagenum();
|
765 |
-
$total_items = $this->get_lists( 0, 0, true );
|
766 |
-
|
767 |
-
$this->set_pagination_args( array(
|
768 |
-
'total_items' => $total_items, //WE have to calculate the total number of items
|
769 |
-
'per_page' => $per_page //WE have to determine how many items to show on a page
|
770 |
-
) );
|
771 |
-
|
772 |
-
$this->items = $this->get_lists( $per_page, $current_page );
|
773 |
-
}
|
774 |
-
|
775 |
-
public function process_bulk_action() {
|
776 |
-
|
777 |
-
if ( 'delete' === $this->current_action() ) {
|
778 |
-
|
779 |
-
// In our file that handles the request, verify the nonce.
|
780 |
-
$nonce = ig_es_get_request_data( '_wpnonce' );
|
781 |
-
|
782 |
-
if ( ! wp_verify_nonce( $nonce, 'es_form' ) ) {
|
783 |
-
$message = __( 'You do not have permission to delete this form.', 'email-subscribers' );
|
784 |
-
ES_Common::show_message( $message, 'error' );
|
785 |
-
} else {
|
786 |
-
|
787 |
-
$form = ig_es_get_request_data( 'form' );
|
788 |
-
|
789 |
-
$this->db->delete_forms( array( $form ) );
|
790 |
-
$message = __( 'Form has been deleted successfully!', 'email-subscribers' );
|
791 |
-
ES_Common::show_message( $message, 'success' );
|
792 |
-
}
|
793 |
-
}
|
794 |
-
|
795 |
-
$action = ig_es_get_request_data( 'action' );
|
796 |
-
$action2 = ig_es_get_request_data( 'action2' );
|
797 |
-
// If the delete bulk action is triggered
|
798 |
-
if ( ( 'bulk_delete' === $action ) || ( 'bulk_delete' === $action2 ) ) {
|
799 |
-
|
800 |
-
$forms = ig_es_get_request_data( 'forms' );
|
801 |
-
|
802 |
-
if ( ! empty( $forms ) > 0 ) {
|
803 |
-
$this->db->delete_forms( $forms );
|
804 |
-
|
805 |
-
$message = __( 'Form(s) have been deleted successfully!', 'email-subscribers' );
|
806 |
-
ES_Common::show_message( $message, 'success' );
|
807 |
-
} else {
|
808 |
-
$message = __( 'Please select form(s) to delete.', 'email-subscribers' );
|
809 |
-
ES_Common::show_message( $message, 'error' );
|
810 |
-
|
811 |
-
return;
|
812 |
-
}
|
813 |
-
}
|
814 |
-
}
|
815 |
-
|
816 |
-
public function status_label_map( $status ) {
|
817 |
-
|
818 |
-
$statuses = array(
|
819 |
-
'enable' => __( 'Enable', 'email-subscribers' ),
|
820 |
-
'disable' => __( 'Disable', 'email-subscribers' )
|
821 |
-
);
|
822 |
-
|
823 |
-
if ( ! in_array( $status, array_keys( $statuses ) ) ) {
|
824 |
-
return '';
|
825 |
-
}
|
826 |
-
|
827 |
-
return $statuses[ $status ];
|
828 |
-
}
|
829 |
-
|
830 |
-
/** Text displayed when no list data is available */
|
831 |
-
public function no_items() {
|
832 |
-
_e( 'No Forms avaliable.', 'email-subscribers' );
|
833 |
-
}
|
834 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-handle-post-notification.php
DELETED
@@ -1,262 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class ES_Handle_Post_Notification {
|
4 |
-
|
5 |
-
public $is_wp_5 = false;
|
6 |
-
|
7 |
-
public $is_rest_request = false;
|
8 |
-
|
9 |
-
public $do_post_notification_via_wp_5_hook = false;
|
10 |
-
|
11 |
-
public $do_post_notification_for = 0;
|
12 |
-
|
13 |
-
public function __construct() {
|
14 |
-
global $wp_version;
|
15 |
-
|
16 |
-
// Action is available after WordPress 2.3.0+
|
17 |
-
add_action( 'transition_post_status', array( $this, 'es_post_publish_callback' ), 10, 3 );
|
18 |
-
|
19 |
-
// Action is available WordPress 5.0+
|
20 |
-
add_action( 'rest_after_insert_post', array( $this, 'handle_post_publish' ), 10, 3 );
|
21 |
-
|
22 |
-
// Filter is available after WordPress 4.7.0+
|
23 |
-
add_filter( 'rest_pre_insert_post', array( $this, 'prepare_post_data' ), 10, 2 );
|
24 |
-
|
25 |
-
if ( version_compare( $wp_version, '5.0.0', '>=' ) ) {
|
26 |
-
$this->is_wp_5 = true;
|
27 |
-
}
|
28 |
-
|
29 |
-
add_action( 'ig_es_refresh_post_notification_content', array( $this, 'refresh_post_content' ), 10, 2 );
|
30 |
-
}
|
31 |
-
|
32 |
-
public function prepare_post_data( $prepared_post, $request ) {
|
33 |
-
$this->is_rest_request = true;
|
34 |
-
|
35 |
-
return $prepared_post;
|
36 |
-
}
|
37 |
-
|
38 |
-
public function handle_post_publish( $post, $requst, $insert ) {
|
39 |
-
// If it's inserted for the first time????
|
40 |
-
// Not able to check whether it'a first time post or nth times
|
41 |
-
if ( is_object( $post ) && ( $post instanceof WP_Post ) ) { // Do it for the first time only
|
42 |
-
|
43 |
-
if ( $this->do_post_notification_via_wp_5_hook ) {
|
44 |
-
$post_id = $post->ID;
|
45 |
-
if ( $post_id == $this->do_post_notification_for ) {
|
46 |
-
$this->queue_post_notifications( $post_id );
|
47 |
-
}
|
48 |
-
}
|
49 |
-
}
|
50 |
-
|
51 |
-
}
|
52 |
-
|
53 |
-
public function es_post_publish_callback( $post_status, $original_post_status, $post ) {
|
54 |
-
|
55 |
-
if ( ( $post_status == 'publish' ) && ( $original_post_status != 'publish' ) ) {
|
56 |
-
|
57 |
-
if ( is_object( $post ) ) {
|
58 |
-
|
59 |
-
$post_id = $post->ID;
|
60 |
-
if ( ! empty( $post_id ) ) {
|
61 |
-
|
62 |
-
if ( $this->is_wp_5 && $this->is_rest_request ) {
|
63 |
-
$this->do_post_notification_via_wp_5_hook = true;
|
64 |
-
$this->do_post_notification_for = $post_id;
|
65 |
-
} else {
|
66 |
-
$this->queue_post_notifications( $post_id );
|
67 |
-
}
|
68 |
-
}
|
69 |
-
}
|
70 |
-
}
|
71 |
-
}
|
72 |
-
|
73 |
-
public function queue_post_notifications( $post_id ) {
|
74 |
-
|
75 |
-
if ( ! empty( $post_id ) ) {
|
76 |
-
|
77 |
-
$notifications = ES_DB_Notifications::get_notifications_by_post_id( $post_id );
|
78 |
-
if ( count( $notifications ) > 0 ) {
|
79 |
-
$existing_contacts = array();
|
80 |
-
foreach ( $notifications as $notification ) {
|
81 |
-
$template_id = $notification['base_template_id'];
|
82 |
-
$template = get_post( $template_id ); // to confirm if template exists in ES->Templates
|
83 |
-
if ( is_object( $template ) ) {
|
84 |
-
$list_id = $notification['list_ids'];
|
85 |
-
$subscribers = ES()->contacts_db->get_active_contacts_by_list_id( $list_id );
|
86 |
-
|
87 |
-
//schedule
|
88 |
-
if ( count( $subscribers ) > 0 ) {
|
89 |
-
/*
|
90 |
-
* Prepare Subject
|
91 |
-
* Prepare Body
|
92 |
-
* Add entry into sent_details table
|
93 |
-
* Add entry into deliverreport table
|
94 |
-
*/
|
95 |
-
|
96 |
-
foreach ( $subscribers as $key => $subscriber ) {
|
97 |
-
if ( in_array( $subscriber['id'], $existing_contacts ) ) {
|
98 |
-
unset( $subscribers[ $key ] );
|
99 |
-
} else {
|
100 |
-
$existing_contacts[] = $subscriber['id'];
|
101 |
-
}
|
102 |
-
}
|
103 |
-
/*check again for unique subscribers count
|
104 |
-
if unique count it 0 then skip this report
|
105 |
-
*/
|
106 |
-
if ( count( $subscribers ) <= 0 ) {
|
107 |
-
continue;
|
108 |
-
}
|
109 |
-
|
110 |
-
$post = get_post( $post_id );
|
111 |
-
|
112 |
-
if ( is_object( $post ) ) {
|
113 |
-
// Prepare subject
|
114 |
-
$post_subject = self::prepare_subject( $post, $template );
|
115 |
-
|
116 |
-
// Prepare body
|
117 |
-
$template_content = $template->post_content;
|
118 |
-
$post_content = self::prepare_body( $template_content, $post_id, $template_id );
|
119 |
-
|
120 |
-
$guid = ES_Common::generate_guid( 6 );
|
121 |
-
|
122 |
-
$data = array(
|
123 |
-
'hash' => $guid,
|
124 |
-
'campaign_id' => $notification['id'],
|
125 |
-
'subject' => $post_subject,
|
126 |
-
'body' => $post_content,
|
127 |
-
'count' => count( $subscribers ),
|
128 |
-
'status' => 'In Queue',
|
129 |
-
'start_at' => '',
|
130 |
-
'finish_at' => '',
|
131 |
-
'created_at' => ig_get_current_date_time(),
|
132 |
-
'updated_at' => ig_get_current_date_time(),
|
133 |
-
'meta' => maybe_serialize( array( 'post_id' => $post_id, 'type' => 'post_notification' ) )
|
134 |
-
);
|
135 |
-
|
136 |
-
// Add entry into mailing queue table
|
137 |
-
$insert = ES_DB_Mailing_Queue::add_notification( $data );
|
138 |
-
if ( $insert ) {
|
139 |
-
// Add entry into sending queue table
|
140 |
-
$delivery_data = array();
|
141 |
-
$delivery_data['hash'] = $guid;
|
142 |
-
$delivery_data['subscribers'] = $subscribers;
|
143 |
-
$delivery_data['campaign_id'] = $notification['id'];
|
144 |
-
$delivery_data['mailing_queue_id'] = $insert;
|
145 |
-
ES_DB_Sending_Queue::do_batch_insert( $delivery_data );
|
146 |
-
|
147 |
-
}
|
148 |
-
|
149 |
-
}
|
150 |
-
}
|
151 |
-
}
|
152 |
-
}
|
153 |
-
}
|
154 |
-
}
|
155 |
-
}
|
156 |
-
|
157 |
-
public static function prepare_subject( $post, $template ) {
|
158 |
-
//convert post subject here
|
159 |
-
|
160 |
-
$post_title = $post->post_title;
|
161 |
-
$template_title = $template->post_title;
|
162 |
-
|
163 |
-
$blog_charset = get_option( 'blog_charset' );
|
164 |
-
|
165 |
-
$post_title = html_entity_decode( $post_title, ENT_QUOTES, $blog_charset );
|
166 |
-
$post_subject = str_replace( '{{POSTTITLE}}', $post_title, $template_title );
|
167 |
-
|
168 |
-
$post_link = get_permalink( $post );
|
169 |
-
$post_subject = str_replace( '{{POSTLINK}}', $post_link, $post_subject );
|
170 |
-
|
171 |
-
return $post_subject;
|
172 |
-
|
173 |
-
}
|
174 |
-
|
175 |
-
public static function prepare_body( $es_templ_body, $post_id, $email_template_id ) {
|
176 |
-
$post = get_post( $post_id );
|
177 |
-
$post_date = $post->post_modified;
|
178 |
-
$es_templ_body = str_replace( '{{DATE}}', $post_date, $es_templ_body );
|
179 |
-
|
180 |
-
$post_title = get_the_title( $post );
|
181 |
-
$es_templ_body = str_replace( '{{POSTTITLE}}', $post_title, $es_templ_body );
|
182 |
-
$post_link = get_permalink( $post_id );
|
183 |
-
|
184 |
-
// Size of {{POSTIMAGE}}
|
185 |
-
$post_thumbnail = "";
|
186 |
-
$post_thumbnail_link = "";
|
187 |
-
if ( ( function_exists( 'has_post_thumbnail' ) ) && ( has_post_thumbnail( $post_id ) ) ) {
|
188 |
-
$es_post_image_size = get_option( 'ig_es_post_image_size', 'full' );
|
189 |
-
switch ( $es_post_image_size ) {
|
190 |
-
case 'full':
|
191 |
-
$post_thumbnail = get_the_post_thumbnail( $post_id, 'full' );
|
192 |
-
break;
|
193 |
-
case 'medium':
|
194 |
-
$post_thumbnail = get_the_post_thumbnail( $post_id, 'medium' );
|
195 |
-
break;
|
196 |
-
case 'thumbnail':
|
197 |
-
default:
|
198 |
-
$post_thumbnail = get_the_post_thumbnail( $post_id, 'thumbnail' );
|
199 |
-
break;
|
200 |
-
}
|
201 |
-
}
|
202 |
-
|
203 |
-
if ( $post_thumbnail != "" ) {
|
204 |
-
$post_thumbnail_link = "<a href='" . $post_link . "' target='_blank'>" . $post_thumbnail . "</a>";
|
205 |
-
}
|
206 |
-
$es_templ_body = str_replace( '{{POSTIMAGE}}', $post_thumbnail_link, $es_templ_body );
|
207 |
-
|
208 |
-
// Get post description
|
209 |
-
$post_description_length = 50;
|
210 |
-
$post_description = $post->post_content;
|
211 |
-
$post_description = strip_tags( strip_shortcodes( $post_description ) );
|
212 |
-
$words = explode( ' ', $post_description, $post_description_length + 1 );
|
213 |
-
if ( count( $words ) > $post_description_length ) {
|
214 |
-
array_pop( $words );
|
215 |
-
array_push( $words, '...' );
|
216 |
-
$post_description = implode( ' ', $words );
|
217 |
-
}
|
218 |
-
$es_templ_body = str_replace( '{{POSTDESC}}', $post_description, $es_templ_body );
|
219 |
-
|
220 |
-
// Get post excerpt
|
221 |
-
$post_excerpt = get_the_excerpt( $post );
|
222 |
-
$es_templ_body = str_replace( '{{POSTEXCERPT}}', $post_excerpt, $es_templ_body );
|
223 |
-
|
224 |
-
// get post author
|
225 |
-
$post_author_id = $post->post_author;
|
226 |
-
$post_author = get_the_author_meta( 'display_name', $post_author_id );
|
227 |
-
$es_templ_body = str_replace( '{{POSTAUTHOR}}', $post_author, $es_templ_body );
|
228 |
-
$es_templ_body = str_replace( '{{POSTLINK-ONLY}}', $post_link, $es_templ_body );
|
229 |
-
|
230 |
-
if ( $post_link != "" ) {
|
231 |
-
$post_link_with_title = "<a href='" . $post_link . "' target='_blank'>" . $post_title . "</a>";
|
232 |
-
$es_templ_body = str_replace( '{{POSTLINK-WITHTITLE}}', $post_link_with_title, $es_templ_body );
|
233 |
-
$post_link = "<a href='" . $post_link . "' target='_blank'>" . $post_link . "</a>";
|
234 |
-
}
|
235 |
-
$es_templ_body = str_replace( '{{POSTLINK}}', $post_link, $es_templ_body );
|
236 |
-
|
237 |
-
// Get full post
|
238 |
-
$post_full = $post->post_content;
|
239 |
-
$post_full = wpautop( $post_full );
|
240 |
-
$es_templ_body = str_replace( '{{POSTFULL}}', $post_full, $es_templ_body );
|
241 |
-
|
242 |
-
if($email_template_id > 0){
|
243 |
-
$es_templ_body = ES_Common::es_process_template_body( $es_templ_body, $email_template_id );
|
244 |
-
}
|
245 |
-
|
246 |
-
return $es_templ_body;
|
247 |
-
}
|
248 |
-
|
249 |
-
public static function refresh_post_content( $content, $args ) {
|
250 |
-
$campaign_id = $args['campaign_id'];
|
251 |
-
$post_id = $args['post_id'];
|
252 |
-
$post = get_post( $post_id );
|
253 |
-
$template_id = ES()->campaigns_db->get_template_id_by_campaign( $campaign_id );
|
254 |
-
$template = get_post( $template_id );
|
255 |
-
$template_content = $template->post_content;
|
256 |
-
$content['subject'] = self::prepare_subject( $post, $template );
|
257 |
-
$content['body'] = self::prepare_body( $template_content, $post_id, $template_id );
|
258 |
-
return $content;
|
259 |
-
}
|
260 |
-
|
261 |
-
}
|
262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-handle-subscription.php
DELETED
@@ -1,416 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
class ES_Handle_Subscription {
|
9 |
-
|
10 |
-
public $email;
|
11 |
-
|
12 |
-
public $name;
|
13 |
-
|
14 |
-
public $first_name;
|
15 |
-
|
16 |
-
public $last_name;
|
17 |
-
|
18 |
-
public $es_optin_type;
|
19 |
-
|
20 |
-
public $list_ids;
|
21 |
-
|
22 |
-
public $es_nonce;
|
23 |
-
|
24 |
-
public $status;
|
25 |
-
|
26 |
-
public $is_double_optin = false;
|
27 |
-
|
28 |
-
public $guid;
|
29 |
-
|
30 |
-
public $db_id;
|
31 |
-
|
32 |
-
public $form_id;
|
33 |
-
|
34 |
-
private $from_rainmaker = false;
|
35 |
-
|
36 |
-
|
37 |
-
public function __construct( $from_rainmaker = false ) {
|
38 |
-
if ( defined( 'DOING_AJAX' ) && ( true === DOING_AJAX ) ) {
|
39 |
-
add_action( 'wp_ajax_es_add_subscriber', array( $this, 'process_request' ), 10 );
|
40 |
-
add_action( 'wp_ajax_nopriv_es_add_subscriber', array( $this, 'process_request' ), 10 );
|
41 |
-
}
|
42 |
-
|
43 |
-
$this->from_rainmaker = $from_rainmaker;
|
44 |
-
}
|
45 |
-
|
46 |
-
public function process_request() {
|
47 |
-
|
48 |
-
$response = array( 'status' => 'ERROR', 'message' => '' );
|
49 |
-
|
50 |
-
$es = ig_es_get_post_data( 'es' );
|
51 |
-
$es_subscribe = ig_es_get_post_data( 'esfpx_es-subscribe' );
|
52 |
-
|
53 |
-
if ( 'subscribe' === $es && ! empty( $es_subscribe ) ) {
|
54 |
-
|
55 |
-
$form_data = ig_es_get_post_data();
|
56 |
-
$validate_response = $this->validate_data( $form_data );
|
57 |
-
if ( $validate_response['status'] === 'ERROR' ) {
|
58 |
-
|
59 |
-
// We want to pretend as "SUCCESS" for blocked emails.
|
60 |
-
// So, we are setting as "SUCCESS" even if this email is blocked
|
61 |
-
if ( $validate_response['message'] === 'es_email_address_blocked' ) {
|
62 |
-
$validate_response['status'] = 'SUCCESS';
|
63 |
-
$validate_response['message'] = 'es_optin_success_message';
|
64 |
-
}
|
65 |
-
|
66 |
-
$this->do_response( $validate_response );
|
67 |
-
exit;
|
68 |
-
}
|
69 |
-
|
70 |
-
$email = ! empty( $form_data['esfpx_email'] ) ? sanitize_email( $form_data['esfpx_email'] ) : '';
|
71 |
-
$name = ! empty( $form_data['esfpx_name'] ) ? sanitize_text_field( $form_data['esfpx_name'] ) : '';
|
72 |
-
|
73 |
-
$first_name = $last_name = '';
|
74 |
-
if ( ! empty( $name ) ) {
|
75 |
-
// Get First Name and Last Name from Name
|
76 |
-
$name_parts = ES_Common::prepare_first_name_last_name( $name );
|
77 |
-
$first_name = $name_parts['first_name'];
|
78 |
-
$last_name = $name_parts['last_name'];
|
79 |
-
} else {
|
80 |
-
$first_name = ES_Common::get_name_from_email( $email );
|
81 |
-
}
|
82 |
-
|
83 |
-
$this->name = $first_name;
|
84 |
-
$this->first_name = $first_name;
|
85 |
-
$this->last_name = $last_name;
|
86 |
-
$this->email = $email;
|
87 |
-
$this->list_ids = isset( $form_data['esfpx_lists'] ) ? $form_data['esfpx_lists'] : array();
|
88 |
-
$this->es_nonce = isset( $form_data['esfpx_es-subscribe'] ) ? trim( $form_data['esfpx_es-subscribe'] ) : '';
|
89 |
-
$this->form_id = isset( $form_data['esfpx_form_id'] ) ? trim( $form_data['esfpx_form_id'] ) : 0;
|
90 |
-
$this->es_optin_type = get_option( 'ig_es_optin_type' );
|
91 |
-
$this->guid = ES_Common::generate_guid();
|
92 |
-
|
93 |
-
if ( in_array( $this->es_optin_type, array( 'double_opt_in', 'double_optin' ) ) ) { // Backward Compatibility
|
94 |
-
$this->is_double_optin = true;
|
95 |
-
$this->status = "unconfirmed";
|
96 |
-
} else {
|
97 |
-
$this->status = "subscribed";
|
98 |
-
}
|
99 |
-
|
100 |
-
/**
|
101 |
-
* Check if subscribers exists?
|
102 |
-
* - If yes, get id and save lists into ig_lists_contacts table
|
103 |
-
* - If not, create contact and then save list
|
104 |
-
*/
|
105 |
-
|
106 |
-
$contact_id = ES()->contacts_db->get_contact_id_by_email( $this->email );
|
107 |
-
if ( ! $contact_id ) {
|
108 |
-
$data = array();
|
109 |
-
$data['first_name'] = $this->first_name;
|
110 |
-
$data['last_name'] = $this->last_name;
|
111 |
-
$data['source'] = 'form';
|
112 |
-
$data['form_id'] = $this->form_id;
|
113 |
-
$data['email'] = $this->email;
|
114 |
-
$data['hash'] = $this->guid;
|
115 |
-
$data['status'] = 'verified';
|
116 |
-
$data['hash'] = $this->guid;
|
117 |
-
$data['created_at'] = ig_get_current_date_time();
|
118 |
-
$data['updated_at'] = null;
|
119 |
-
$data['meta'] = null;
|
120 |
-
|
121 |
-
$data = apply_filters( 'ig_es_add_subscriber_data', $data );
|
122 |
-
if ( 'ERROR' === $data['status'] ) {
|
123 |
-
$this->do_response( $validate_response );
|
124 |
-
exit;
|
125 |
-
}
|
126 |
-
|
127 |
-
$contact_id = ES()->contacts_db->insert( $data );
|
128 |
-
|
129 |
-
//do_action( 'ig_es_contact_added', $data);
|
130 |
-
|
131 |
-
}
|
132 |
-
|
133 |
-
if ( count( $this->list_ids ) > 0 ) {
|
134 |
-
$contact_lists = ES_DB_Lists_Contacts::get_list_ids_by_contact( $contact_id, 'subscribed' );
|
135 |
-
if ( $contact_lists == $this->list_ids ) {
|
136 |
-
$response['message'] = 'es_email_exists_notice';
|
137 |
-
$this->do_response( $response );
|
138 |
-
exit;
|
139 |
-
}
|
140 |
-
$optin_type = $this->is_double_optin ? IG_DOUBLE_OPTIN : IG_SINGLE_OPTIN;
|
141 |
-
$list_contact_data = array(
|
142 |
-
'list_id' => $this->list_ids,
|
143 |
-
'contact_id' => $contact_id,
|
144 |
-
'status' => $this->status,
|
145 |
-
'subscribed_at' => ( $this->status === 'subscribed' ) ? ig_get_current_date_time() : '',
|
146 |
-
'optin_type' => $optin_type,
|
147 |
-
'subscribed_ip' => ig_es_get_ip()
|
148 |
-
);
|
149 |
-
ES_DB_Lists_Contacts::delete_list_contacts( $contact_id, $this->list_ids );
|
150 |
-
ES_DB_Lists_Contacts::add_lists_contacts( $list_contact_data );
|
151 |
-
|
152 |
-
if ( $contact_id ) {
|
153 |
-
|
154 |
-
do_action( 'ig_es_contact_subscribe', $contact_id, $this->list_ids );
|
155 |
-
|
156 |
-
$this->db_id = $contact_id;
|
157 |
-
if ( $this->is_double_optin ) {
|
158 |
-
$this->send_double_optin_notification();
|
159 |
-
$response['message'] = 'es_optin_success_message';
|
160 |
-
} else {
|
161 |
-
$enable_welcome_email = get_option( 'ig_es_enable_welcome_email', 'no' );
|
162 |
-
if ( 'yes' === $enable_welcome_email ) {
|
163 |
-
$this->send_welcome_notification();
|
164 |
-
}
|
165 |
-
|
166 |
-
$ig_es_notifyadmin = get_option( 'ig_es_notify_admin' );
|
167 |
-
if ( 'yes' === $ig_es_notifyadmin ) {
|
168 |
-
$this->send_admin_signup_notification();
|
169 |
-
}
|
170 |
-
|
171 |
-
$response['message'] = 'es_optin_success_message';
|
172 |
-
}
|
173 |
-
|
174 |
-
|
175 |
-
$response['status'] = 'SUCCESS';
|
176 |
-
|
177 |
-
} else {
|
178 |
-
$response['message'] = 'es_db_error_notice';
|
179 |
-
}
|
180 |
-
} else {
|
181 |
-
$response['message'] = 'es_no_list_selected';
|
182 |
-
$this->do_response( $response );
|
183 |
-
exit;
|
184 |
-
}
|
185 |
-
} else {
|
186 |
-
$response['message'] = 'es_permission_denied_notice';
|
187 |
-
}
|
188 |
-
|
189 |
-
$this->do_response( $response );
|
190 |
-
exit;
|
191 |
-
}
|
192 |
-
|
193 |
-
public function do_response( $response ) {
|
194 |
-
|
195 |
-
$message = isset( $response['message'] ) ? $response['message'] : '';
|
196 |
-
$response['message_text'] = '';
|
197 |
-
if ( ! empty( $message ) ) {
|
198 |
-
$response['message_text'] = $this->get_messages( $message );
|
199 |
-
}
|
200 |
-
|
201 |
-
echo json_encode( $response );
|
202 |
-
exit;
|
203 |
-
|
204 |
-
}
|
205 |
-
|
206 |
-
public function send_welcome_notification() {
|
207 |
-
|
208 |
-
// Get comma(,) separated lists name based on ids.
|
209 |
-
$list_name = ES_Common::prepare_list_name_by_ids( $this->list_ids );
|
210 |
-
|
211 |
-
$template_data = array(
|
212 |
-
'email' => $this->email,
|
213 |
-
'db_id' => $this->db_id,
|
214 |
-
'name' => $this->first_name,
|
215 |
-
'first_name' => $this->first_name,
|
216 |
-
'last_name' => $this->last_name,
|
217 |
-
'guid' => $this->guid,
|
218 |
-
'list_name' => $list_name
|
219 |
-
);
|
220 |
-
|
221 |
-
// Send Welcome Email
|
222 |
-
ES_Mailer::send_welcome_email( $this->email, $template_data );
|
223 |
-
}
|
224 |
-
|
225 |
-
public function send_double_optin_notification() {
|
226 |
-
|
227 |
-
$template_data = array(
|
228 |
-
'email' => $this->email,
|
229 |
-
'db_id' => $this->db_id,
|
230 |
-
'name' => $this->first_name,
|
231 |
-
'first_name' => $this->first_name,
|
232 |
-
'last_name' => $this->last_name,
|
233 |
-
'guid' => $this->guid
|
234 |
-
);
|
235 |
-
|
236 |
-
$subject = get_option( 'ig_es_confirmation_mail_subject', true );
|
237 |
-
$content = ES_Mailer::prepare_double_optin_email( $template_data );
|
238 |
-
|
239 |
-
$response = ES_Mailer::send( $this->email, $subject, $content );
|
240 |
-
|
241 |
-
if ( $response ) {
|
242 |
-
return true;
|
243 |
-
}
|
244 |
-
|
245 |
-
return false;
|
246 |
-
}
|
247 |
-
|
248 |
-
public function send_admin_signup_notification() {
|
249 |
-
|
250 |
-
$admin_email_addresses = get_option( 'ig_es_admin_emails', '' );
|
251 |
-
|
252 |
-
if ( ! empty( $admin_email_addresses ) ) {
|
253 |
-
|
254 |
-
$admin_emails = explode( ',', $admin_email_addresses );
|
255 |
-
|
256 |
-
$list_id_name_map = ES()->lists_db->get_list_id_name_map();
|
257 |
-
|
258 |
-
$list_name = '';
|
259 |
-
if ( count( $this->list_ids ) > 0 ) {
|
260 |
-
foreach ( $this->list_ids as $list_id ) {
|
261 |
-
$list_name .= $list_id_name_map[ $list_id ] . ',';
|
262 |
-
}
|
263 |
-
|
264 |
-
$list_name = rtrim( $list_name, ',' );
|
265 |
-
}
|
266 |
-
|
267 |
-
$template_data = array(
|
268 |
-
'name' => ES_Common::prepare_name_from_first_name_last_name( $this->first_name, $this->last_name ),
|
269 |
-
'first_name' => $this->first_name,
|
270 |
-
'last_name' => $this->last_name,
|
271 |
-
'email' => $this->email,
|
272 |
-
'list_name' => $list_name
|
273 |
-
);
|
274 |
-
|
275 |
-
if ( count( $admin_emails ) > 0 ) {
|
276 |
-
$send = ES_Common::send_signup_notification_to_admins( $template_data );
|
277 |
-
|
278 |
-
return $send;
|
279 |
-
}
|
280 |
-
}
|
281 |
-
|
282 |
-
return false;
|
283 |
-
|
284 |
-
}
|
285 |
-
|
286 |
-
public function validate_data( $data ) {
|
287 |
-
|
288 |
-
$es_response = array( 'status' => 'ERROR', 'message' => '' );
|
289 |
-
|
290 |
-
if ( ! $this->from_rainmaker ) {
|
291 |
-
|
292 |
-
// Honeypot validation
|
293 |
-
$hp_key = "esfpx_es_hp_" . wp_create_nonce( 'es_hp' );
|
294 |
-
if ( ! isset( $data[ $hp_key ] ) || ! empty( $data[ $hp_key ] ) ) {
|
295 |
-
$es_response['message'] = 'es_unexpected_error_notice';
|
296 |
-
|
297 |
-
return $es_response;
|
298 |
-
}
|
299 |
-
}
|
300 |
-
|
301 |
-
$name = isset( $data['esfpx_name'] ) ? $data['esfpx_name'] : '';
|
302 |
-
if ( strlen( $name ) > 50 ) {
|
303 |
-
$es_response['message'] = 'es_invalid_name_notice';
|
304 |
-
|
305 |
-
return $es_response;
|
306 |
-
}
|
307 |
-
|
308 |
-
$email = isset( $data['esfpx_email'] ) ? $data['esfpx_email'] : '';
|
309 |
-
|
310 |
-
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
311 |
-
$es_response['message'] = 'es_invalid_email_notice';
|
312 |
-
|
313 |
-
return $es_response;
|
314 |
-
}
|
315 |
-
|
316 |
-
$is_domain_blocked = $this->is_domain_blocked( $email );
|
317 |
-
|
318 |
-
// Store it blocked emails
|
319 |
-
if ( $is_domain_blocked ) {
|
320 |
-
$data = array(
|
321 |
-
'email' => $email,
|
322 |
-
'ip' => ig_es_get_ip()
|
323 |
-
);
|
324 |
-
|
325 |
-
ES()->blocked_emails_db->insert( $data );
|
326 |
-
|
327 |
-
$es_response['status'] = 'ERROR';
|
328 |
-
$es_response['message'] = 'es_email_address_blocked';
|
329 |
-
|
330 |
-
return $es_response;
|
331 |
-
}
|
332 |
-
|
333 |
-
$data = apply_filters( 'ig_es_validate_subscribers_data', $data );
|
334 |
-
|
335 |
-
if ( ! empty( $data['status'] ) && 'ERROR' === $data['status'] ) {
|
336 |
-
$es_response = $data;
|
337 |
-
|
338 |
-
return $es_response;
|
339 |
-
}
|
340 |
-
|
341 |
-
$timeout = ES_Subscription_Throttaling::throttle();
|
342 |
-
if ( $timeout > 0 ) {
|
343 |
-
$es_response['message'] = 'es_rate_limit_notice';
|
344 |
-
|
345 |
-
return $es_response;
|
346 |
-
}
|
347 |
-
|
348 |
-
$es_response['status'] = 'SUCCESS';
|
349 |
-
|
350 |
-
return $es_response;
|
351 |
-
}
|
352 |
-
|
353 |
-
/**
|
354 |
-
* @param $email
|
355 |
-
*
|
356 |
-
* @return bool
|
357 |
-
*/
|
358 |
-
public function is_domain_blocked( $email ) {
|
359 |
-
|
360 |
-
if ( empty( $email ) ) {
|
361 |
-
return true;
|
362 |
-
}
|
363 |
-
|
364 |
-
$domains = trim( get_option( 'ig_es_blocked_domains', '' ) );
|
365 |
-
|
366 |
-
// No domains to block? Return
|
367 |
-
if ( empty( $domains ) ) {
|
368 |
-
return false;
|
369 |
-
}
|
370 |
-
|
371 |
-
$domains = explode( PHP_EOL, $domains );
|
372 |
-
|
373 |
-
$domains = apply_filters( 'ig_es_blocked_domains', $domains );
|
374 |
-
|
375 |
-
if ( empty( $domains ) ) {
|
376 |
-
return false;
|
377 |
-
}
|
378 |
-
|
379 |
-
$rev_email = strrev( $email );
|
380 |
-
foreach ( $domains as $item ) {
|
381 |
-
$item = trim( $item );
|
382 |
-
if ( strpos( $rev_email, strrev( $item ) ) === 0 ) {
|
383 |
-
return true;
|
384 |
-
}
|
385 |
-
}
|
386 |
-
|
387 |
-
return false;
|
388 |
-
}
|
389 |
-
|
390 |
-
public function get_messages( $message ) {
|
391 |
-
$ig_es_form_submission_success_message = get_option( 'ig_es_form_submission_success_message' );
|
392 |
-
$messages = array(
|
393 |
-
'es_empty_email_notice' => __( 'Please enter email address', 'email-subscribers' ),
|
394 |
-
'es_rate_limit_notice' => __( 'You need to wait for sometime before subscribing again', 'email-subscribers' ),
|
395 |
-
'es_optin_success_message' => ! empty( $ig_es_form_submission_success_message ) ? $ig_es_form_submission_success_message : __( 'Successfully Subscribed.', 'email-subscribers' ),
|
396 |
-
'es_email_exists_notice' => __( 'Email Address already exists!', 'email-subscribers' ),
|
397 |
-
'es_unexpected_error_notice' => __( 'Oops.. Unexpected error occurred.', 'email-subscribers' ),
|
398 |
-
'es_invalid_email_notice' => __( 'Invalid email address', 'email-subscribers' ),
|
399 |
-
'es_invalid_name_notice' => __( 'Invalid name', 'email-subscribers' ),
|
400 |
-
'es_try_later_notice' => __( 'Please try after some time', 'email-subscribers' ),
|
401 |
-
'es_db_error_notice' => __( 'Oops...unable to add subscriber', 'email-subscribers' ),
|
402 |
-
'es_permission_denied_notice' => __( 'You do not have permission to add subscriber', 'email-subscribers' ),
|
403 |
-
'es_no_list_selected' => __( 'Please select the list', 'email-subscribers' ),
|
404 |
-
'es_invalid_captcha' => __( 'Invalid Captcha', 'email-subscribers' )
|
405 |
-
);
|
406 |
-
|
407 |
-
$messages = apply_filters( 'ig_es_subscription_messages', $messages );
|
408 |
-
|
409 |
-
if ( ! empty( $messages ) ) {
|
410 |
-
return isset( $messages[ $message ] ) ? $messages[ $message ] : '';
|
411 |
-
}
|
412 |
-
|
413 |
-
return $messages;
|
414 |
-
}
|
415 |
-
|
416 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-handle-sync-wp-user.php
DELETED
@@ -1,201 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class ES_Handle_Sync_Wp_User {
|
4 |
-
|
5 |
-
public static $instance;
|
6 |
-
|
7 |
-
public function __construct() {
|
8 |
-
// Sync upcoming WordPress users
|
9 |
-
add_action( 'user_register', array( $this, 'sync_registered_wp_user' ) );
|
10 |
-
add_action( 'ig_es_sync_users_tabs_wordpress', array( $this, 'sync_wordpress_users_settings' ) );
|
11 |
-
}
|
12 |
-
|
13 |
-
public function sync_wordpress_users_settings( $wordpress_tab ) {
|
14 |
-
|
15 |
-
if ( ! empty( $wordpress_tab['indicator_option'] ) ) {
|
16 |
-
update_option( $wordpress_tab['indicator_option'], 'no' );
|
17 |
-
}
|
18 |
-
|
19 |
-
$submitted = ig_es_get_post_data( 'submitted' );
|
20 |
-
if ( 'submitted' === $submitted ) {
|
21 |
-
|
22 |
-
$form_data = ig_es_get_post_data( 'form_data' );
|
23 |
-
|
24 |
-
$error = false;
|
25 |
-
if ( ! empty( $form_data['es_registered'] ) && 'YES' === $form_data['es_registered'] ) {
|
26 |
-
$list_id = ! empty( $form_data['es_registered_group'] ) ? $form_data['es_registered_group'] : 0;
|
27 |
-
if ( $list_id === 0 ) {
|
28 |
-
$message = __( 'Please select list', 'email-subscribers' );
|
29 |
-
ES_Common::show_message( $message, 'error' );
|
30 |
-
$error = true;
|
31 |
-
}
|
32 |
-
}
|
33 |
-
|
34 |
-
if ( ! $error ) {
|
35 |
-
update_option( 'ig_es_sync_wp_users', $form_data );
|
36 |
-
$message = __( 'Settings have been saved successfully!', 'email-subscribers' );
|
37 |
-
ES_Common::show_message( $message, 'success' );
|
38 |
-
}
|
39 |
-
}
|
40 |
-
|
41 |
-
$default_form_data = array(
|
42 |
-
'es_registered' => 'NO',
|
43 |
-
'es_registered_group' => 0,
|
44 |
-
);
|
45 |
-
|
46 |
-
$form_data = get_option( 'ig_es_sync_wp_users', array() );
|
47 |
-
$form_data = wp_parse_args( $form_data, $default_form_data );
|
48 |
-
|
49 |
-
?>
|
50 |
-
|
51 |
-
<table class="form-table">
|
52 |
-
<tbody>
|
53 |
-
<tr>
|
54 |
-
<th scope="row">
|
55 |
-
<label for="tag-image">
|
56 |
-
<?php echo __( 'Sync WordPress Users?', 'email-subscribers' ); ?>
|
57 |
-
</label>
|
58 |
-
<p class="description"><?php _e( "Whenever someone signup, it will automatically be added into selected list", 'email-subscribers' ); ?></p>
|
59 |
-
</th>
|
60 |
-
<td>
|
61 |
-
<select name="form_data[es_registered]" id="es_email_status">
|
62 |
-
<option value='NO' <?php if ( $form_data['es_registered'] == 'NO' ) {
|
63 |
-
echo "selected='selected'";
|
64 |
-
} ?>><?php echo __( 'No', 'email-subscribers' ); ?></option>
|
65 |
-
<option value='YES' <?php if ( $form_data['es_registered'] == 'YES' ) {
|
66 |
-
echo "selected='selected'";
|
67 |
-
} ?>><?php echo __( 'Yes', 'email-subscribers' ); ?></option>
|
68 |
-
</select>
|
69 |
-
</td>
|
70 |
-
</tr>
|
71 |
-
<tr>
|
72 |
-
<th>
|
73 |
-
<label for="tag-display-status">
|
74 |
-
<?php echo __( 'Select List', 'email-subscribers' ); ?>
|
75 |
-
</label>
|
76 |
-
<p class="description"><?php _e( "Select the list in which newly registered user will be subscribed to", 'email-subscribers' ); ?></p>
|
77 |
-
</th>
|
78 |
-
<td>
|
79 |
-
<select name="form_data[es_registered_group]">
|
80 |
-
<?php echo ES_Common::prepare_list_dropdown_options( $form_data['es_registered_group'], 'Select List' ); ?>
|
81 |
-
</select>
|
82 |
-
</td>
|
83 |
-
</tr>
|
84 |
-
</tbody>
|
85 |
-
</table>
|
86 |
-
<input type="hidden" name="submitted" value="submitted"/>
|
87 |
-
<p style="padding-top:5px;">
|
88 |
-
<input type="submit" class="button-primary" value="<?php echo __( 'Save Settings', 'email-subscribers' ); ?>"/>
|
89 |
-
</p>
|
90 |
-
|
91 |
-
<?php
|
92 |
-
}
|
93 |
-
|
94 |
-
public function sync_registered_wp_user( $user_id ) {
|
95 |
-
//get option
|
96 |
-
$ig_es_sync_wp_users = get_option( 'ig_es_sync_wp_users', 'norecord' );
|
97 |
-
$ig_es_sync_unserialized_data = maybe_unserialize( $ig_es_sync_wp_users );
|
98 |
-
$ig_es_registered = ( $ig_es_sync_unserialized_data != 'norecord' ) ? $ig_es_sync_unserialized_data['es_registered'] : 'NO';
|
99 |
-
if ( $ig_es_sync_wp_users != 'norecord' && 'YES' === $ig_es_registered ) {
|
100 |
-
$list_id = $ig_es_sync_unserialized_data['es_registered_group'];
|
101 |
-
//get user info
|
102 |
-
$user_info = get_userdata( $user_id );
|
103 |
-
if ( ! ( $user_info instanceof WP_User ) ) {
|
104 |
-
return false;
|
105 |
-
}
|
106 |
-
$user_firstname = $user_info->display_name;
|
107 |
-
|
108 |
-
|
109 |
-
$email = $user_info->user_email;
|
110 |
-
if ( empty( $user_firstname ) ) {
|
111 |
-
$user_firstname = ES_Common::get_name_from_email( $email );
|
112 |
-
}
|
113 |
-
//prepare data
|
114 |
-
$data = array(
|
115 |
-
'first_name' => $user_firstname,
|
116 |
-
'email' => $email,
|
117 |
-
'source' => 'wp',
|
118 |
-
'status' => 'verified',
|
119 |
-
'hash' => ES_Common::generate_guid(),
|
120 |
-
'created_at' => ig_get_current_date_time(),
|
121 |
-
'wp_user_id' => $user_id
|
122 |
-
);
|
123 |
-
|
124 |
-
do_action( 'ig_es_add_contact', $data, $list_id );
|
125 |
-
}
|
126 |
-
|
127 |
-
return true;
|
128 |
-
|
129 |
-
}
|
130 |
-
|
131 |
-
public function prepare_sync_user() {
|
132 |
-
|
133 |
-
$audience_tab_main_navigation = array();
|
134 |
-
$active_tab = 'sync';
|
135 |
-
$audience_tab_main_navigation = apply_filters( 'ig_es_audience_tab_main_navigation', $active_tab, $audience_tab_main_navigation );
|
136 |
-
|
137 |
-
?>
|
138 |
-
<div class="wrap">
|
139 |
-
<h2> <?php _e( 'Audience > Sync Contacts', 'email-subscribers' );
|
140 |
-
ES_Common::prepare_main_header_navigation( $audience_tab_main_navigation );
|
141 |
-
?>
|
142 |
-
</h2>
|
143 |
-
<?php $this->sync_users_callback(); ?>
|
144 |
-
</div>
|
145 |
-
|
146 |
-
<?php
|
147 |
-
}
|
148 |
-
|
149 |
-
public function sync_users_callback() {
|
150 |
-
|
151 |
-
$logger = get_ig_logger();
|
152 |
-
$logger->trace( 'Sync Users' );
|
153 |
-
$active_tab = ig_es_get_request_data( 'tab', 'wordpress' );
|
154 |
-
|
155 |
-
$tabs = array(
|
156 |
-
'wordpress' => array(
|
157 |
-
'name' => __( 'WordPress', 'email-subscribers' ),
|
158 |
-
'url' => admin_url( 'admin.php?page=es_subscribers&action=sync&tab=wordpress' )
|
159 |
-
)
|
160 |
-
);
|
161 |
-
|
162 |
-
$tabs = apply_filters( 'ig_es_sync_users_tabs', $tabs );
|
163 |
-
?>
|
164 |
-
<h2 class="nav-tab-wrapper">
|
165 |
-
<?php foreach ( $tabs as $key => $tab ) {
|
166 |
-
$tab_url = admin_url( 'admin.php?page=es_subscribers&action=sync' );
|
167 |
-
$tab_url = add_query_arg( 'tab', $key, $tab_url );
|
168 |
-
|
169 |
-
$indicator_option = ! empty( $tab['indicator_option'] ) ? $tab['indicator_option'] : '';
|
170 |
-
$indicator_label = '';
|
171 |
-
$indicator_class = '';
|
172 |
-
if ( ! empty( $indicator_option ) && ( get_option( $indicator_option, 'yes' ) == 'yes' ) ) {
|
173 |
-
$indicator_label = ! empty( $tab['indicator_label'] ) ? $tab['indicator_label'] : '';
|
174 |
-
$indicator_class = ! empty( $tab['indicator_type'] ) ? 'ig-es-indicator-' . $tab['indicator_type'] : 'ig-es-indicator-new';
|
175 |
-
}
|
176 |
-
?>
|
177 |
-
<a class="nav-tab <?php echo $key === $active_tab ? 'nav-tab-active' : ''; ?>" href="<?php echo esc_url( $tab_url ); ?>"><?php echo esc_html__( $tab['name'] ); ?>
|
178 |
-
<?php if ( ! empty( $indicator_label ) ) { ?>
|
179 |
-
<span class="ig-es-indicator<?php echo " " . $indicator_class; ?>"><?php echo $indicator_label; ?></span>
|
180 |
-
<?php } ?>
|
181 |
-
</a>
|
182 |
-
<?php } ?>
|
183 |
-
</h2>
|
184 |
-
<form name="form_sync" id="form_sync" method="post" action="#">
|
185 |
-
<?php
|
186 |
-
$from = ! empty( $tabs[ $active_tab ]['from'] ) ? $tabs[ $active_tab ]['from'] . '_' : '';
|
187 |
-
do_action( $from . 'ig_es_sync_users_tabs_' . $active_tab, $tabs[ $active_tab ] ); ?>
|
188 |
-
</form>
|
189 |
-
|
190 |
-
<?php
|
191 |
-
}
|
192 |
-
|
193 |
-
public static function get_instance() {
|
194 |
-
if ( ! isset( self::$instance ) ) {
|
195 |
-
self::$instance = new self();
|
196 |
-
}
|
197 |
-
|
198 |
-
return self::$instance;
|
199 |
-
}
|
200 |
-
|
201 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-import-subscribers.php
DELETED
@@ -1,314 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
class ES_Import_Subscribers {
|
9 |
-
/**
|
10 |
-
* ES_Import_Subscribers constructor.
|
11 |
-
*
|
12 |
-
* @since 4.0.0
|
13 |
-
*/
|
14 |
-
public function __construct() {
|
15 |
-
}
|
16 |
-
|
17 |
-
/**
|
18 |
-
* Import Contacts
|
19 |
-
*
|
20 |
-
* @since 4.0,0
|
21 |
-
*
|
22 |
-
* @modify 4.3.1
|
23 |
-
*/
|
24 |
-
public function import_callback() {
|
25 |
-
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
26 |
-
|
27 |
-
$submit = ig_es_get_post_data( 'submit' );
|
28 |
-
if ( $submit ) {
|
29 |
-
$import_contacts_nonce = ig_es_get_post_data( 'import_contacts' );
|
30 |
-
if ( ! isset( $_POST['import_contacts'] ) || ! wp_verify_nonce( sanitize_key( $import_contacts_nonce ), 'import-contacts' ) ) {
|
31 |
-
$message = __( "Sorry, you do not have permission to import contacts.", 'email-subscribers' );
|
32 |
-
ES_Common::show_message( $message, 'error' );
|
33 |
-
}
|
34 |
-
|
35 |
-
if ( isset( $_FILES["file"] ) ) {
|
36 |
-
|
37 |
-
if ( is_uploaded_file( $_FILES["file"]["tmp_name"] ) ) {
|
38 |
-
|
39 |
-
$ext = substr( $_FILES['file']['name'], strrpos( $_FILES['file']['name'], "." ), ( strlen( $_FILES['file']['name'] ) - strrpos( $_FILES['file']['name'], "." ) ) );
|
40 |
-
|
41 |
-
if ( $ext == ".csv" ) {
|
42 |
-
|
43 |
-
$statuses = ES_Common::get_statuses_key_name_map();
|
44 |
-
$es_email_status = ig_es_get_post_data( 'es_email_status' );
|
45 |
-
|
46 |
-
$status = '';
|
47 |
-
if ( in_array( $es_email_status, array_keys( $statuses ) ) ) {
|
48 |
-
$status = $es_email_status;
|
49 |
-
}
|
50 |
-
|
51 |
-
if ( ! empty( $status ) ) {
|
52 |
-
|
53 |
-
$lists = ES()->lists_db->get_id_name_map();
|
54 |
-
|
55 |
-
$list_id = ig_es_get_post_data( 'list_id' );
|
56 |
-
|
57 |
-
if ( ! in_array( $list_id, array_keys( $lists ) ) ) {
|
58 |
-
$list_id = '';
|
59 |
-
}
|
60 |
-
|
61 |
-
if ( ! empty( $list_id ) ) {
|
62 |
-
|
63 |
-
$delimiter = $this->get_delimiter($_FILES["file"]["tmp_name"]);
|
64 |
-
|
65 |
-
$handle = fopen( $_FILES["file"]["tmp_name"], 'r' );
|
66 |
-
|
67 |
-
// Get Headers
|
68 |
-
$headers = array_map( 'trim', fgetcsv( $handle, 0, $delimiter ) );
|
69 |
-
|
70 |
-
$existing_contacts_email_id_map = ES()->contacts_db->get_email_id_map();
|
71 |
-
|
72 |
-
$existing_contacts = array();
|
73 |
-
if ( count( $existing_contacts_email_id_map ) > 0 ) {
|
74 |
-
$existing_contacts = array_keys( $existing_contacts_email_id_map );
|
75 |
-
}
|
76 |
-
|
77 |
-
$invalid_emails_count = $imported_subscribers_count = $existing_contacts_count = 0;
|
78 |
-
$emails = array();
|
79 |
-
|
80 |
-
$values = $place_holders = $contacts_data = array();
|
81 |
-
$current_date_time = ig_get_current_date_time();
|
82 |
-
|
83 |
-
$i = 0;
|
84 |
-
while ( ( $data = fgetcsv( $handle, 0, $delimiter) ) !== false ) {
|
85 |
-
|
86 |
-
$data = array_map( 'trim', $data );
|
87 |
-
|
88 |
-
$data = array_combine( $headers, $data );
|
89 |
-
|
90 |
-
$email = isset( $data['Email'] ) ? sanitize_email( trim( $data['Email'] ) ) : '';
|
91 |
-
|
92 |
-
if ( empty( $email ) ) {
|
93 |
-
$invalid_emails_count ++;
|
94 |
-
continue;
|
95 |
-
}
|
96 |
-
|
97 |
-
if ( ! in_array( $email, $existing_contacts ) ) {
|
98 |
-
|
99 |
-
$name = isset( $data['Name'] ) ? trim( $data['Name'] ) : '';
|
100 |
-
$first_name = isset( $data['First Name'] ) ? sanitize_text_field( trim( $data['First Name'] ) ) : '';
|
101 |
-
$last_name = isset( $data['Last Name'] ) ? sanitize_text_field( trim( $data['Last Name'] ) ) : '';
|
102 |
-
|
103 |
-
// If we don't get the first_name & last_name, consider Name field.
|
104 |
-
// If name empty, get the name from Email
|
105 |
-
if ( empty( $first_name ) && empty( $last_name ) ) {
|
106 |
-
|
107 |
-
if ( empty( $name ) ) {
|
108 |
-
$name = ES_Common::get_name_from_email( $email );
|
109 |
-
}
|
110 |
-
|
111 |
-
$names = ES_Common::prepare_first_name_last_name( $name );
|
112 |
-
$first_name = sanitize_text_field( $names['first_name'] );
|
113 |
-
$last_name = sanitize_text_field( $names['last_name'] );
|
114 |
-
}
|
115 |
-
|
116 |
-
$guid = ES_Common::generate_guid();
|
117 |
-
|
118 |
-
$contacts_data[ $imported_subscribers_count ]['first_name'] = $first_name;
|
119 |
-
$contacts_data[ $imported_subscribers_count ]['last_name'] = $last_name;
|
120 |
-
$contacts_data[ $imported_subscribers_count ]['email'] = $email;
|
121 |
-
$contacts_data[ $imported_subscribers_count ]['source'] = 'import';
|
122 |
-
$contacts_data[ $imported_subscribers_count ]['status'] = 'verified';
|
123 |
-
$contacts_data[ $imported_subscribers_count ]['hash'] = $guid;
|
124 |
-
$contacts_data[ $imported_subscribers_count ]['created_at'] = $current_date_time;
|
125 |
-
|
126 |
-
$existing_contacts[] = $email;
|
127 |
-
} else {
|
128 |
-
$existing_contacts_count ++;
|
129 |
-
}
|
130 |
-
|
131 |
-
$emails[] = $email;
|
132 |
-
$imported_subscribers_count ++;
|
133 |
-
}
|
134 |
-
|
135 |
-
if ( count( $emails ) > 0 ) {
|
136 |
-
|
137 |
-
ES()->contacts_db->do_batch_insert( $contacts_data );
|
138 |
-
|
139 |
-
$contact_ids = ES()->contacts_db->get_contact_ids_by_emails( $emails );
|
140 |
-
if ( count( $contact_ids ) > 0 ) {
|
141 |
-
ES_DB_Lists_Contacts::delete_contacts_from_list( $list_id, $contact_ids );
|
142 |
-
ES_DB_Lists_Contacts::do_import_contacts_into_list( $list_id, $contact_ids, $status, 1, $current_date_time );
|
143 |
-
}
|
144 |
-
|
145 |
-
$message = sprintf( __( 'Total %d contacts have been imported successfully!', 'email-subscribers' ), $imported_subscribers_count );
|
146 |
-
$status = 'success';
|
147 |
-
} else {
|
148 |
-
|
149 |
-
$message = sprintf( __( 'Total %d contacts have been imported successfully!', 'email-subscribers' ), $imported_subscribers_count );
|
150 |
-
|
151 |
-
if ( $existing_contacts_count > 0 ) {
|
152 |
-
$message .= " ";
|
153 |
-
$message .= sprintf( __( '%d contacts are already exists.', 'email-subscribers' ), $existing_contacts );
|
154 |
-
}
|
155 |
-
|
156 |
-
if ( $invalid_emails_count > 0 ) {
|
157 |
-
$message .= " ";
|
158 |
-
$message .= sprintf( __( '%d contacts are invalid.', 'email-subscribers' ), $invalid_emails_count );
|
159 |
-
}
|
160 |
-
|
161 |
-
$status = 'error';
|
162 |
-
}
|
163 |
-
|
164 |
-
fclose( $handle );
|
165 |
-
ES_Common::show_message( $message, $status );
|
166 |
-
|
167 |
-
} else {
|
168 |
-
$message = __( "Error: Please Select List", 'email-subscribers' );
|
169 |
-
ES_Common::show_message( $message, 'error' );
|
170 |
-
}
|
171 |
-
} else {
|
172 |
-
$message = __( "Error: Please select status", 'email-subscribers' );
|
173 |
-
ES_Common::show_message( $message, 'error' );
|
174 |
-
}
|
175 |
-
} else {
|
176 |
-
$message = __( "Error: Please Upload only CSV File", 'email-subscribers' );
|
177 |
-
ES_Common::show_message( $message, 'error' );
|
178 |
-
}
|
179 |
-
} else {
|
180 |
-
$message = __( "Error: Please Upload File", 'email-subscribers' );
|
181 |
-
ES_Common::show_message( $message, 'error' );
|
182 |
-
}
|
183 |
-
} else {
|
184 |
-
$message = __( "Error: Please Upload File", 'email-subscribers' );
|
185 |
-
ES_Common::show_message( $message, 'error' );
|
186 |
-
}
|
187 |
-
}
|
188 |
-
|
189 |
-
$this->prepare_import_subscriber_form();
|
190 |
-
|
191 |
-
}
|
192 |
-
|
193 |
-
public function prepare_import_subscriber_form() {
|
194 |
-
|
195 |
-
?>
|
196 |
-
|
197 |
-
<div class="tool-box">
|
198 |
-
<form name="form_addemail" id="form_addemail" method="post" action="#" enctype="multipart/form-data">
|
199 |
-
<table class="form-table">
|
200 |
-
<tbody>
|
201 |
-
<tr>
|
202 |
-
<th scope="row">
|
203 |
-
<label for="tag-image"><?php _e( 'Select CSV file', 'email-subscribers' ); ?>
|
204 |
-
<p class="description">
|
205 |
-
<?php _e( 'Check CSV structure', 'email-subscribers' ); ?>
|
206 |
-
<a target="_blank" href="<?php echo plugin_dir_url( __FILE__ ) . '../../admin/partials/sample.csv'; ?>"><?php _e( 'from here', 'email-subscribers' ); ?></a>
|
207 |
-
</p>
|
208 |
-
</label>
|
209 |
-
</th>
|
210 |
-
<td>
|
211 |
-
<input type="file" name="file" id="file"/>
|
212 |
-
</td>
|
213 |
-
</tr>
|
214 |
-
<tr>
|
215 |
-
<th scope="row">
|
216 |
-
<label for="tag-email-status">
|
217 |
-
<?php _e( 'Select status', 'email-subscribers' ); ?> <p></p>
|
218 |
-
</label>
|
219 |
-
</th>
|
220 |
-
<td>
|
221 |
-
<select name="es_email_status" id="es_email_status">
|
222 |
-
<?php echo ES_Common::prepare_statuses_dropdown_options(); ?>
|
223 |
-
</select>
|
224 |
-
</td>
|
225 |
-
</tr>
|
226 |
-
<tr>
|
227 |
-
<th>
|
228 |
-
<label for="tag-email-group">
|
229 |
-
<?php _e( 'Select list', 'email-subscribers' ); ?>
|
230 |
-
</label>
|
231 |
-
</th>
|
232 |
-
<td>
|
233 |
-
<select name="list_id" id="list_id">
|
234 |
-
<?php echo ES_Common::prepare_list_dropdown_options(); ?>
|
235 |
-
</select>
|
236 |
-
</td>
|
237 |
-
</tr>
|
238 |
-
</tbody>
|
239 |
-
</table>
|
240 |
-
<p style="padding-top:10px;">
|
241 |
-
<?php wp_nonce_field( 'import-contacts', 'import_contacts' ); ?>
|
242 |
-
<input type="submit" name="submit" class="button-primary" value=<?php _e( "Import", 'email-subscribers' ); ?>>
|
243 |
-
</p>
|
244 |
-
</form>
|
245 |
-
</div>
|
246 |
-
|
247 |
-
<?php
|
248 |
-
}
|
249 |
-
|
250 |
-
/**
|
251 |
-
* Show import contacts
|
252 |
-
*
|
253 |
-
* @since 4.0.0
|
254 |
-
*/
|
255 |
-
public function import_subscribers_page() {
|
256 |
-
|
257 |
-
$audience_tab_main_navigation = array();
|
258 |
-
$active_tab = 'import';
|
259 |
-
$audience_tab_main_navigation = apply_filters( 'ig_es_audience_tab_main_navigation', $active_tab, $audience_tab_main_navigation );
|
260 |
-
|
261 |
-
?>
|
262 |
-
|
263 |
-
<div class="wrap">
|
264 |
-
<h2> <?php _e( 'Audience > Import Contacts', 'email-subscribers' );
|
265 |
-
|
266 |
-
ES_Common::prepare_main_header_navigation( $audience_tab_main_navigation );
|
267 |
-
?>
|
268 |
-
|
269 |
-
</h2>
|
270 |
-
<?php $this->import_callback(); ?>
|
271 |
-
</div>
|
272 |
-
|
273 |
-
<?php
|
274 |
-
}
|
275 |
-
|
276 |
-
/**
|
277 |
-
* Get CSV file delimiter
|
278 |
-
*
|
279 |
-
* @param $file
|
280 |
-
* @param int $check_lines
|
281 |
-
*
|
282 |
-
* @return mixed
|
283 |
-
*
|
284 |
-
* @since 4.3.1
|
285 |
-
*/
|
286 |
-
function get_delimiter( $file, $check_lines = 2 ) {
|
287 |
-
|
288 |
-
$file = new SplFileObject( $file );
|
289 |
-
|
290 |
-
$delimiters = array(',','\t',';','|',':');
|
291 |
-
$results = array();
|
292 |
-
$i = 0;
|
293 |
-
while ( $file->valid() && $i <= $check_lines ) {
|
294 |
-
$line = $file->fgets();
|
295 |
-
foreach ( $delimiters as $delimiter ) {
|
296 |
-
$regExp = '/[' . $delimiter . ']/';
|
297 |
-
$fields = preg_split( $regExp, $line );
|
298 |
-
if ( count( $fields ) > 1 ) {
|
299 |
-
if ( ! empty( $results[ $delimiter ] ) ) {
|
300 |
-
$results[ $delimiter ] ++;
|
301 |
-
} else {
|
302 |
-
$results[ $delimiter ] = 1;
|
303 |
-
}
|
304 |
-
}
|
305 |
-
}
|
306 |
-
$i ++;
|
307 |
-
}
|
308 |
-
$results = array_keys( $results, max( $results ) );
|
309 |
-
|
310 |
-
return $results[0];
|
311 |
-
}
|
312 |
-
|
313 |
-
}
|
314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-info.php
DELETED
@@ -1,55 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
class ES_Info {
|
9 |
-
|
10 |
-
static $instance;
|
11 |
-
|
12 |
-
public function __construct() {
|
13 |
-
add_action( 'admin_menu', array( $this, 'plugin_menu' ) );
|
14 |
-
}
|
15 |
-
|
16 |
-
public function plugin_menu() {
|
17 |
-
$help_title = __( 'Help & Info', 'email-subscribers' );
|
18 |
-
add_submenu_page( 'es_dashboard', $help_title, $help_title, 'edit_posts', 'es_general_information', array( $this, 'es_information_callback' ) );
|
19 |
-
|
20 |
-
$pro_title = __( '<span class="es-fire-sale"> 🔥 </span> Go Pro', 'email-subscribers' );
|
21 |
-
if( ! ES()->is_pro() ){
|
22 |
-
add_submenu_page( 'es_dashboard', $pro_title, $pro_title, 'edit_posts', 'es_pricing', array( $this, 'es_pricing_callback' ) );
|
23 |
-
}
|
24 |
-
}
|
25 |
-
|
26 |
-
public function es_information_callback() {
|
27 |
-
|
28 |
-
$is_option_exists = get_option( 'current_sa_email_subscribers_db_version', false );
|
29 |
-
$enable_manual_update = false;
|
30 |
-
if ( $is_option_exists ) {
|
31 |
-
$enable_manual_update = true;
|
32 |
-
}
|
33 |
-
|
34 |
-
$update_url = add_query_arg( 'do_update_ig_es', 'true', admin_url( 'admin.php?page=es_general_information' ) );
|
35 |
-
$update_url = add_query_arg( 'from_db_version', '3.5.18', $update_url );
|
36 |
-
$update_url = wp_nonce_url( $update_url, 'ig_es_db_update', 'ig_es_db_update_nonce' );
|
37 |
-
|
38 |
-
include_once( ES_PLUGIN_DIR . '/lite/admin/partials/help.php' );
|
39 |
-
}
|
40 |
-
|
41 |
-
public static function es_pricing_callback() {
|
42 |
-
//remove because of warning
|
43 |
-
// $url = 'https://www.icegram.com/email-subscribers-pricing/';
|
44 |
-
// header('Location: ' . $url );
|
45 |
-
}
|
46 |
-
|
47 |
-
public static function get_instance() {
|
48 |
-
if ( ! isset( self::$instance ) ) {
|
49 |
-
self::$instance = new self();
|
50 |
-
}
|
51 |
-
|
52 |
-
return self::$instance;
|
53 |
-
}
|
54 |
-
|
55 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-lists-table.php
DELETED
@@ -1,640 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
if ( ! class_exists( 'WP_List_Table' ) ) {
|
9 |
-
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
10 |
-
}
|
11 |
-
|
12 |
-
class ES_Lists_Table extends WP_List_Table {
|
13 |
-
/**
|
14 |
-
* ES_DB_Lists object
|
15 |
-
*
|
16 |
-
* @since 4.2.1
|
17 |
-
* @var $db
|
18 |
-
*
|
19 |
-
*/
|
20 |
-
protected $db;
|
21 |
-
/**
|
22 |
-
* @since 4.2.1
|
23 |
-
* @var string
|
24 |
-
*
|
25 |
-
*/
|
26 |
-
public static $option_per_page = 'es_lists_per_page';
|
27 |
-
|
28 |
-
/**
|
29 |
-
* ES_Lists_Table constructor.
|
30 |
-
*
|
31 |
-
* @since 4.0
|
32 |
-
*/
|
33 |
-
public function __construct() {
|
34 |
-
|
35 |
-
parent::__construct( array(
|
36 |
-
'singular' => __( 'List', 'email-subscribers' ), //singular name of the listed records
|
37 |
-
'plural' => __( 'Lists', 'email-subscribers' ), //plural name of the listed records
|
38 |
-
'ajax' => false, //does this table support ajax?,
|
39 |
-
'screen' => 'es_lists'
|
40 |
-
) );
|
41 |
-
|
42 |
-
$this->db = new ES_DB_Lists();
|
43 |
-
}
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Add Screen Option
|
47 |
-
*
|
48 |
-
* @since 4.2.1
|
49 |
-
*/
|
50 |
-
public static function screen_options() {
|
51 |
-
|
52 |
-
$option = 'per_page';
|
53 |
-
$args = array(
|
54 |
-
'label' => __( 'Number of lists per page', 'email-subscribers' ),
|
55 |
-
'default' => 20,
|
56 |
-
'option' => self::$option_per_page
|
57 |
-
);
|
58 |
-
|
59 |
-
add_screen_option( $option, $args );
|
60 |
-
|
61 |
-
}
|
62 |
-
|
63 |
-
public function render() {
|
64 |
-
|
65 |
-
$action = ig_es_get_request_data( 'action' );
|
66 |
-
|
67 |
-
?>
|
68 |
-
<div class="wrap">
|
69 |
-
<?php if ( 'new' === $action ) {
|
70 |
-
$this->es_new_lists_callback();
|
71 |
-
} elseif ( 'edit' === $action ) {
|
72 |
-
$list = ig_es_get_request_data( 'list' );
|
73 |
-
echo $this->edit_list( absint( $list ) );
|
74 |
-
} else { ?>
|
75 |
-
<h1 class="wp-heading-inline"><?php _e( 'Audience > Lists', 'email-subscribers' ); ?> <a href="admin.php?page=es_lists&action=new" class="page-title-action">Add New</a></h1>
|
76 |
-
<?php Email_Subscribers_Admin::es_feedback(); ?>
|
77 |
-
<div id="poststuff">
|
78 |
-
<div id="post-body" class="metabox-holder column-1">
|
79 |
-
<div id="post-body-content">
|
80 |
-
<div class="meta-box-sortables ui-sortable">
|
81 |
-
<form method="post">
|
82 |
-
<?php
|
83 |
-
$this->prepare_items();
|
84 |
-
$this->display(); ?>
|
85 |
-
</form>
|
86 |
-
</div>
|
87 |
-
</div>
|
88 |
-
</div>
|
89 |
-
<br class="clear">
|
90 |
-
</div>
|
91 |
-
</div>
|
92 |
-
<?php }
|
93 |
-
}
|
94 |
-
|
95 |
-
/**
|
96 |
-
* Validate data
|
97 |
-
*
|
98 |
-
* @param $data
|
99 |
-
*
|
100 |
-
* @return array
|
101 |
-
*/
|
102 |
-
public function validate_data( $data ) {
|
103 |
-
|
104 |
-
$nonce = $data['nonce'];
|
105 |
-
$list_name = $data['list_name'];
|
106 |
-
|
107 |
-
$status = 'error';
|
108 |
-
$message = '';
|
109 |
-
if ( ! wp_verify_nonce( $nonce, 'es_list' ) ) {
|
110 |
-
$message = __( 'You do not have permission to edit list', 'email-subscribers' );
|
111 |
-
} elseif ( empty( $list_name ) ) {
|
112 |
-
$message = __( 'Please add list name', 'email-subscribers' );
|
113 |
-
} elseif ( $this->db->is_list_exists( $list_name ) ) {
|
114 |
-
$message = __( 'List already exists. Please choose different name', 'email-subscribers' );
|
115 |
-
} else {
|
116 |
-
$status = 'success';
|
117 |
-
}
|
118 |
-
|
119 |
-
$response = array(
|
120 |
-
'status' => $status,
|
121 |
-
'message' => $message
|
122 |
-
);
|
123 |
-
|
124 |
-
return $response;
|
125 |
-
|
126 |
-
}
|
127 |
-
|
128 |
-
public function es_new_lists_callback() {
|
129 |
-
|
130 |
-
$submitted = ig_es_get_request_data( 'submitted' );
|
131 |
-
|
132 |
-
if ( 'submitted' === $submitted ) {
|
133 |
-
|
134 |
-
$nonce = ig_es_get_request_data( '_wpnonce' );
|
135 |
-
$list_name = ig_es_get_request_data( 'list_name' );
|
136 |
-
|
137 |
-
$validate_data = array(
|
138 |
-
'nonce' => $nonce,
|
139 |
-
'list_name' => $list_name,
|
140 |
-
);
|
141 |
-
|
142 |
-
$response = $this->validate_data( $validate_data );
|
143 |
-
|
144 |
-
if ( 'error' === $response['status'] ) {
|
145 |
-
$message = $response['message'];
|
146 |
-
ES_Common::show_message( $message, 'error' );
|
147 |
-
$this->prepare_list_form( null, $validate_data );
|
148 |
-
|
149 |
-
return;
|
150 |
-
}
|
151 |
-
|
152 |
-
$data = array(
|
153 |
-
'list_name' => $list_name,
|
154 |
-
);
|
155 |
-
|
156 |
-
$save = $this->save_list( null, $data );
|
157 |
-
|
158 |
-
if ( $save ) {
|
159 |
-
$message = __( 'List has been added successfully!', 'email-subscribers' );
|
160 |
-
ES_Common::show_message( $message, 'success' );
|
161 |
-
} else {
|
162 |
-
|
163 |
-
}
|
164 |
-
}
|
165 |
-
|
166 |
-
$this->prepare_list_form();
|
167 |
-
}
|
168 |
-
|
169 |
-
/**
|
170 |
-
* Edit List
|
171 |
-
*
|
172 |
-
* @param $id
|
173 |
-
*
|
174 |
-
* @since 4.0.0
|
175 |
-
*/
|
176 |
-
public function edit_list( $id ) {
|
177 |
-
|
178 |
-
$list = $this->db->get( $id );
|
179 |
-
|
180 |
-
$submitted = ig_es_get_request_data( 'submitted' );
|
181 |
-
|
182 |
-
if ( 'submitted' === $submitted ) {
|
183 |
-
|
184 |
-
$nonce = ig_es_get_request_data( '_wpnonce' );
|
185 |
-
$list_name = ig_es_get_request_data( 'list_name' );
|
186 |
-
|
187 |
-
$validate_data = array(
|
188 |
-
'nonce' => $nonce,
|
189 |
-
'list_name' => $list_name,
|
190 |
-
);
|
191 |
-
|
192 |
-
$response = $this->validate_data( $validate_data );
|
193 |
-
|
194 |
-
if ( 'error' === $response['status'] ) {
|
195 |
-
$message = $response['message'];
|
196 |
-
ES_Common::show_message( $message, 'error' );
|
197 |
-
$this->prepare_list_form( $id, $validate_data );
|
198 |
-
|
199 |
-
return;
|
200 |
-
}
|
201 |
-
|
202 |
-
$data = array(
|
203 |
-
'list_name' => $list_name,
|
204 |
-
);
|
205 |
-
|
206 |
-
$save = $this->save_list( $id, $data );
|
207 |
-
if ( $save ) {
|
208 |
-
$message = __( 'List has been updated successfully!', 'email-subscribers' );
|
209 |
-
ES_Common::show_message( $message, 'success' );
|
210 |
-
} else {
|
211 |
-
|
212 |
-
}
|
213 |
-
} else {
|
214 |
-
|
215 |
-
$id = $list['id'];
|
216 |
-
|
217 |
-
$data = array(
|
218 |
-
'list_name' => $list['name'],
|
219 |
-
);
|
220 |
-
|
221 |
-
}
|
222 |
-
|
223 |
-
$this->prepare_list_form( $id, $data );
|
224 |
-
|
225 |
-
?>
|
226 |
-
|
227 |
-
<?php
|
228 |
-
}
|
229 |
-
|
230 |
-
public function prepare_list_form( $id = 0, $data = array() ) {
|
231 |
-
|
232 |
-
$is_new = empty( $id ) ? 1 : 0;
|
233 |
-
|
234 |
-
$action = 'new';
|
235 |
-
if ( ! $is_new ) {
|
236 |
-
$action = 'edit';
|
237 |
-
}
|
238 |
-
|
239 |
-
$list_name = isset( $data['list_name'] ) ? $data['list_name'] : '';
|
240 |
-
|
241 |
-
$nonce = wp_create_nonce( 'es_list' );
|
242 |
-
|
243 |
-
?>
|
244 |
-
|
245 |
-
<div class="wrap">
|
246 |
-
<h1 class="wp-heading-inline">
|
247 |
-
<?php
|
248 |
-
if ( $is_new ) {
|
249 |
-
_e( 'Add New', 'email-subscribers' );
|
250 |
-
} else {
|
251 |
-
_e( 'Edit List', 'email-subscribers' );
|
252 |
-
}
|
253 |
-
|
254 |
-
?>
|
255 |
-
<a href="admin.php?page=es_lists&action=manage-lists" class="page-title-action es-imp-button"><?php _e( 'Manage Lists', 'email-subscribers' ); ?></a>
|
256 |
-
</h1>
|
257 |
-
|
258 |
-
<?php Email_Subscribers_Admin::es_feedback(); ?>
|
259 |
-
|
260 |
-
<div id="poststuff">
|
261 |
-
<div id="post-body" class="metabox-holder column-1">
|
262 |
-
<div id="post-body-content">
|
263 |
-
<div class="meta-box-sortables ui-sortable">
|
264 |
-
<form method="post" action="admin.php?page=es_lists&action=<?php echo $action; ?>&list=<?php echo $id; ?>&_wpnonce=<?php echo $nonce; ?>">
|
265 |
-
<div class="row-blog">
|
266 |
-
<label><?php _e( 'Name', 'email-subscribers' ); ?>: </label>
|
267 |
-
<input type="text" id="name" name="list_name" value="<?php echo $list_name; ?>"/>
|
268 |
-
</div>
|
269 |
-
<input type="hidden" name="submitted" value="submitted"/>
|
270 |
-
<div class="row-blog"><?php submit_button(); ?></div>
|
271 |
-
</form>
|
272 |
-
</div>
|
273 |
-
</div>
|
274 |
-
</div>
|
275 |
-
<br class="clear">
|
276 |
-
</div>
|
277 |
-
</div>
|
278 |
-
|
279 |
-
<?php
|
280 |
-
|
281 |
-
}
|
282 |
-
|
283 |
-
/**
|
284 |
-
* Save list
|
285 |
-
*
|
286 |
-
* @param $id
|
287 |
-
* @param $data
|
288 |
-
*
|
289 |
-
* @return bool|int|void
|
290 |
-
*
|
291 |
-
* @since 4.0.0
|
292 |
-
*/
|
293 |
-
public function save_list( $id, $data ) {
|
294 |
-
$name = sanitize_text_field( $data['list_name'] );
|
295 |
-
|
296 |
-
if ( ! empty( $id ) ) {
|
297 |
-
$return = $this->db->update_list( $id, $name );
|
298 |
-
} else {
|
299 |
-
$return = $this->db->add_list( $name );
|
300 |
-
}
|
301 |
-
|
302 |
-
/*
|
303 |
-
$list_data['name'] = sanitize_text_field( $data['list_name'] );
|
304 |
-
$list_data['slug'] = sanitize_title( $list_data['name'] );
|
305 |
-
$list_data['created_at'] = ig_get_current_date_time();
|
306 |
-
|
307 |
-
if ( ! empty( $id ) ) {
|
308 |
-
$return = $wpdb->update( IG_LISTS_TABLE, $list_data, array( 'id' => $id ) );
|
309 |
-
} else {
|
310 |
-
$return = $wpdb->insert( IG_LISTS_TABLE, $list_data );
|
311 |
-
}
|
312 |
-
*/
|
313 |
-
|
314 |
-
return $return;
|
315 |
-
}
|
316 |
-
|
317 |
-
/**
|
318 |
-
* Retrieve lists data from the database
|
319 |
-
*
|
320 |
-
* @param int $per_page
|
321 |
-
* @param int $page_number
|
322 |
-
*
|
323 |
-
* @return mixed
|
324 |
-
*/
|
325 |
-
public function get_lists( $per_page = 5, $page_number = 1, $do_count_only = false ) {
|
326 |
-
|
327 |
-
global $wpdb;
|
328 |
-
|
329 |
-
$order_by = sanitize_sql_orderby( ig_es_get_request_data( 'orderby' ) );
|
330 |
-
$order = ig_es_get_request_data( 'order' );
|
331 |
-
$search = ig_es_get_request_data( 's' );
|
332 |
-
|
333 |
-
if ( $do_count_only ) {
|
334 |
-
$sql = "SELECT count(*) as total FROM " . IG_LISTS_TABLE;
|
335 |
-
} else {
|
336 |
-
$sql = "SELECT * FROM " . IG_LISTS_TABLE;
|
337 |
-
}
|
338 |
-
|
339 |
-
$args = $query = array();
|
340 |
-
|
341 |
-
$add_where_clause = false;
|
342 |
-
|
343 |
-
if ( ! empty( $search ) ) {
|
344 |
-
$query[] = " name LIKE %s ";
|
345 |
-
$args[] = "%" . $wpdb->esc_like( $search ) . "%";
|
346 |
-
|
347 |
-
$add_where_clause = true;
|
348 |
-
}
|
349 |
-
|
350 |
-
if ( $add_where_clause ) {
|
351 |
-
$sql .= " WHERE ";
|
352 |
-
|
353 |
-
if ( count( $query ) > 0 ) {
|
354 |
-
$sql .= implode( " AND ", $query );
|
355 |
-
if ( count( $args ) > 0 ) {
|
356 |
-
$sql = $wpdb->prepare( $sql, $args );
|
357 |
-
}
|
358 |
-
}
|
359 |
-
}
|
360 |
-
|
361 |
-
if ( ! $do_count_only ) {
|
362 |
-
|
363 |
-
// Prepare Order by clause
|
364 |
-
$order = ! empty( $order ) ? strtolower( $order ) : 'desc';
|
365 |
-
$expected_order_values = array( 'asc', 'desc' );
|
366 |
-
if ( ! in_array( $order, $expected_order_values ) ) {
|
367 |
-
$order = 'desc';
|
368 |
-
}
|
369 |
-
|
370 |
-
$default_order_by = esc_sql( 'created_at' );
|
371 |
-
|
372 |
-
$expected_order_by_values = array( 'name', 'created_at' );
|
373 |
-
|
374 |
-
if ( ! in_array( $order_by, $expected_order_by_values ) ) {
|
375 |
-
$order_by_clause = " ORDER BY {$default_order_by} DESC";
|
376 |
-
} else {
|
377 |
-
$order_by = esc_sql( $order_by );
|
378 |
-
$order_by_clause = " ORDER BY {$order_by} {$order}, {$default_order_by} DESC";
|
379 |
-
}
|
380 |
-
|
381 |
-
$sql .= $order_by_clause;
|
382 |
-
$sql .= " LIMIT $per_page";
|
383 |
-
$sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page;
|
384 |
-
|
385 |
-
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
|
386 |
-
|
387 |
-
} else {
|
388 |
-
$result = $wpdb->get_var( $sql );
|
389 |
-
}
|
390 |
-
|
391 |
-
return $result;
|
392 |
-
}
|
393 |
-
|
394 |
-
|
395 |
-
/**
|
396 |
-
* Returns the count of records in the database.
|
397 |
-
*
|
398 |
-
* @return null|string
|
399 |
-
*/
|
400 |
-
public function record_count() {
|
401 |
-
global $wpdb;
|
402 |
-
|
403 |
-
$sql = "SELECT COUNT(*) FROM " . IG_LISTS_TABLE;
|
404 |
-
|
405 |
-
return $wpdb->get_var( $sql );
|
406 |
-
}
|
407 |
-
|
408 |
-
/**
|
409 |
-
* Render a column when no column specific method exist.
|
410 |
-
*
|
411 |
-
* @param array $item
|
412 |
-
* @param string $column_name
|
413 |
-
*
|
414 |
-
* @return mixed
|
415 |
-
*/
|
416 |
-
public function column_default( $item, $column_name ) {
|
417 |
-
|
418 |
-
switch ( $column_name ) {
|
419 |
-
case 'active_contacts':
|
420 |
-
$count = ES_DB_Lists_Contacts::get_total_count_by_list( $item['id'], 'subscribed' );
|
421 |
-
if ( $count > 0 ) {
|
422 |
-
$url = admin_url( 'admin.php?page=es_subscribers&filter_by_status=subscribed&filter_by_list_id=' . $item['id'] );
|
423 |
-
$count = sprintf( __( '<a href="%s" target="_blank">%d</a>', 'email-subscribers' ), $url, $count );
|
424 |
-
}
|
425 |
-
|
426 |
-
return $count;
|
427 |
-
break;
|
428 |
-
case 'all_contacts':
|
429 |
-
$count = ES_DB_Lists_Contacts::get_total_count_by_list( $item['id'], 'all' );
|
430 |
-
if ( $count > 0 ) {
|
431 |
-
$url = admin_url( 'admin.php?page=es_subscribers&filter_by_list_id=' . $item['id'] );
|
432 |
-
$count = sprintf( __( '<a href="%s" target="_blank">%d</a>', 'email-subscribers' ), $url, $count );
|
433 |
-
}
|
434 |
-
|
435 |
-
return $count;
|
436 |
-
break;
|
437 |
-
case 'created_at':
|
438 |
-
return ig_es_format_date_time( $item[ $column_name ] );
|
439 |
-
break;
|
440 |
-
|
441 |
-
case 'export':
|
442 |
-
return "<a href='admin.php?page=download_report&report=users&status=select_list&list_id={$item['id']}'>" . __( 'Download', 'email-subscribers' ) . '</a>';
|
443 |
-
default:
|
444 |
-
return '';
|
445 |
-
}
|
446 |
-
}
|
447 |
-
|
448 |
-
/**
|
449 |
-
* Render the bulk edit checkbox
|
450 |
-
*
|
451 |
-
* @param array $item
|
452 |
-
*
|
453 |
-
* @return string
|
454 |
-
*/
|
455 |
-
function column_cb( $item ) {
|
456 |
-
return sprintf(
|
457 |
-
'<input type="checkbox" name="lists[]" value="%s" />', $item['id']
|
458 |
-
);
|
459 |
-
}
|
460 |
-
|
461 |
-
/**
|
462 |
-
* Method for name column
|
463 |
-
*
|
464 |
-
* @param array $item an array of DB data
|
465 |
-
*
|
466 |
-
* @return string
|
467 |
-
*/
|
468 |
-
function column_name( $item ) {
|
469 |
-
|
470 |
-
$list_nonce = wp_create_nonce( 'es_list' );
|
471 |
-
|
472 |
-
$title = '<strong>' . $item['name'] . '</strong>';
|
473 |
-
$actions = array();
|
474 |
-
if ( $item['id'] != 1 ) {
|
475 |
-
$page = ig_es_get_request_data( 'page' );
|
476 |
-
$actions = array(
|
477 |
-
'edit' => sprintf( __( '<a href="?page=%s&action=%s&list=%s&_wpnonce=%s">Edit</a>', 'email-subscribers' ), esc_attr( $page ), 'edit', absint( $item['id'] ), $list_nonce ),
|
478 |
-
'delete' => sprintf( __( '<a href="?page=%s&action=%s&list=%s&_wpnonce=%s" onclick="return checkDelete()">Delete</a>', 'email-subscribers' ), esc_attr( $page ), 'delete', absint( $item['id'] ), $list_nonce )
|
479 |
-
);
|
480 |
-
}
|
481 |
-
|
482 |
-
return $title . $this->row_actions( $actions );
|
483 |
-
}
|
484 |
-
|
485 |
-
|
486 |
-
/**
|
487 |
-
* Associative array of columns
|
488 |
-
*
|
489 |
-
* @return array
|
490 |
-
*/
|
491 |
-
function get_columns() {
|
492 |
-
$columns = array(
|
493 |
-
'cb' => '<input type="checkbox" />',
|
494 |
-
'name' => __( 'Name', 'email-subscribers' ),
|
495 |
-
'active_contacts' => __( 'Active Contacts', 'email-subscribers' ),
|
496 |
-
'all_contacts' => __( 'All Contacts', 'email-subscribers' ),
|
497 |
-
'created_at' => __( 'Created', 'email-subscribers' ),
|
498 |
-
'export' => __( 'Export', 'email-subscribers' )
|
499 |
-
);
|
500 |
-
|
501 |
-
return $columns;
|
502 |
-
}
|
503 |
-
|
504 |
-
|
505 |
-
/**
|
506 |
-
* Columns to make sortable.
|
507 |
-
*
|
508 |
-
* @return array
|
509 |
-
*/
|
510 |
-
public function get_sortable_columns() {
|
511 |
-
$sortable_columns = array(
|
512 |
-
'name' => array( 'name', true ),
|
513 |
-
'created_at' => array( 'created_at', true ),
|
514 |
-
);
|
515 |
-
|
516 |
-
return $sortable_columns;
|
517 |
-
}
|
518 |
-
|
519 |
-
/**
|
520 |
-
* Returns an associative array containing the bulk action
|
521 |
-
*
|
522 |
-
* @return array
|
523 |
-
*/
|
524 |
-
public function get_bulk_actions() {
|
525 |
-
$actions = array(
|
526 |
-
'bulk_delete' => __( 'Delete', 'email-subscribers' )
|
527 |
-
);
|
528 |
-
|
529 |
-
return $actions;
|
530 |
-
}
|
531 |
-
|
532 |
-
public function search_box( $text, $input_id ) { ?>
|
533 |
-
<p class="search-box">
|
534 |
-
<label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
|
535 |
-
<input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>"/>
|
536 |
-
<?php submit_button( __( 'Search Lists', 'email-subscribers' ), 'button', false, false, array( 'id' => 'search-submit' ) ); ?>
|
537 |
-
</p>
|
538 |
-
<?php }
|
539 |
-
|
540 |
-
/**
|
541 |
-
* Handles data query and filter, sorting, and pagination.
|
542 |
-
*/
|
543 |
-
public function prepare_items() {
|
544 |
-
|
545 |
-
$this->_column_headers = $this->get_column_info();
|
546 |
-
|
547 |
-
/** Process bulk action */
|
548 |
-
$this->process_bulk_action();
|
549 |
-
$this->search_box( ig_es_get_request_data( 's' ), 'list-search-input' );
|
550 |
-
|
551 |
-
$per_page = $this->get_items_per_page( self::$option_per_page, 10 );
|
552 |
-
$current_page = $this->get_pagenum();
|
553 |
-
$total_items = $this->get_lists( 0, 0, true );
|
554 |
-
|
555 |
-
$this->set_pagination_args( array(
|
556 |
-
'total_items' => $total_items, //WE have to calculate the total number of items
|
557 |
-
'per_page' => $per_page //WE have to determine how many items to show on a page
|
558 |
-
) );
|
559 |
-
|
560 |
-
$this->items = $this->get_lists( $per_page, $current_page );
|
561 |
-
}
|
562 |
-
|
563 |
-
public function process_bulk_action() {
|
564 |
-
|
565 |
-
//Detect when a bulk action is being triggered...
|
566 |
-
if ( 'edit' === $this->current_action() ) {
|
567 |
-
|
568 |
-
// In our file that handles the request, verify the nonce.
|
569 |
-
$nonce = esc_attr( ig_es_get_request_data( '_wpnonce' ) );
|
570 |
-
|
571 |
-
if ( ! wp_verify_nonce( $nonce, 'es_list' ) ) {
|
572 |
-
$message = __( 'You do not have permission to edit list', 'email-subscribers' );
|
573 |
-
ES_Common::show_message( $message, 'error' );
|
574 |
-
} else {
|
575 |
-
$this->edit_list( absint( ig_es_get_request_data( 'list' ) ) );
|
576 |
-
$message = __( 'List has been updated successfully!', 'email-subscribers' );
|
577 |
-
ES_Common::show_message( $message, 'success' );
|
578 |
-
}
|
579 |
-
|
580 |
-
}
|
581 |
-
|
582 |
-
if ( 'delete' === $this->current_action() ) {
|
583 |
-
|
584 |
-
// In our file that handles the request, verify the nonce.
|
585 |
-
$nonce = esc_attr( ig_es_get_request_data( '_wpnonce' ) );
|
586 |
-
|
587 |
-
if ( ! wp_verify_nonce( $nonce, 'es_list' ) ) {
|
588 |
-
$message = __( 'You do not have permission to delete list', 'email-subscribers' );
|
589 |
-
ES_Common::show_message( $message, 'error' );
|
590 |
-
} else {
|
591 |
-
$list = ig_es_get_request_data( 'list' );
|
592 |
-
if ( $list != 1 ) {
|
593 |
-
$list = ig_es_get_request_data( 'list' );
|
594 |
-
$this->db->delete_lists( array( $list ) );
|
595 |
-
$message = __( 'List has been deleted successfully!', 'email-subscribers' );
|
596 |
-
ES_Common::show_message( $message, 'success' );
|
597 |
-
}
|
598 |
-
}
|
599 |
-
}
|
600 |
-
|
601 |
-
$action = ig_es_get_request_data( 'action' );
|
602 |
-
$action2 = ig_es_get_request_data( 'action2' );
|
603 |
-
// If the delete bulk action is triggered
|
604 |
-
if ( ( 'bulk_delete' === $action ) || ( 'bulk_delete' === $action2 ) ) {
|
605 |
-
|
606 |
-
$lists = ig_es_get_request_data( 'lists' );
|
607 |
-
|
608 |
-
if ( ! empty( $lists ) > 0 ) {
|
609 |
-
$this->db->delete_lists( $lists );
|
610 |
-
$message = __( 'List(s) have been deleted successfully', 'email-subscribers' );
|
611 |
-
ES_Common::show_message( $message, 'success' );
|
612 |
-
} else {
|
613 |
-
$message = __( 'Please select list', 'email-subscribers' );
|
614 |
-
ES_Common::show_message( $message, 'error' );
|
615 |
-
|
616 |
-
return;
|
617 |
-
}
|
618 |
-
}
|
619 |
-
}
|
620 |
-
|
621 |
-
public function status_label_map( $status ) {
|
622 |
-
|
623 |
-
$statuses = array(
|
624 |
-
'enable' => __( 'Enable', 'email-subscribers' ),
|
625 |
-
'disable' => __( 'Disable', 'email-subscribers' )
|
626 |
-
);
|
627 |
-
|
628 |
-
if ( ! in_array( $status, array_keys( $statuses ) ) ) {
|
629 |
-
return '';
|
630 |
-
}
|
631 |
-
|
632 |
-
return $statuses[ $status ];
|
633 |
-
}
|
634 |
-
|
635 |
-
/** Text displayed when no list data is available */
|
636 |
-
public function no_items() {
|
637 |
-
_e( 'No lists avaliable.', 'email-subscribers' );
|
638 |
-
}
|
639 |
-
|
640 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-newsletters.php
DELETED
@@ -1,296 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
/**
|
9 |
-
* The admin-specific functionality of the plugin.
|
10 |
-
*
|
11 |
-
* Admin Settings
|
12 |
-
*
|
13 |
-
* @package Email_Subscribers
|
14 |
-
* @subpackage Email_Subscribers/admin
|
15 |
-
* @author Your Name <email@example.com>
|
16 |
-
*/
|
17 |
-
class ES_Newsletters {
|
18 |
-
|
19 |
-
// class instance
|
20 |
-
static $instance;
|
21 |
-
|
22 |
-
// class constructor
|
23 |
-
public function __construct() {
|
24 |
-
add_filter( 'ig_es_refresh_newsletter_content', array( $this, 'refresh_newsletter_content' ), 10, 2 );
|
25 |
-
}
|
26 |
-
|
27 |
-
public static function set_screen( $status, $option, $value ) {
|
28 |
-
return $value;
|
29 |
-
}
|
30 |
-
|
31 |
-
public function es_newsletters_settings_callback() {
|
32 |
-
|
33 |
-
|
34 |
-
$submitted = ig_es_get_request_data( 'submitted' );
|
35 |
-
$preview = ig_es_get_request_data( 'es_broadcast_preview' );
|
36 |
-
$broadcast_data = ig_es_get_request_data( 'broadcast_data', array(), false );
|
37 |
-
if( 'preview' !== $preview ){
|
38 |
-
if ( 'submitted' === $submitted ) {
|
39 |
-
|
40 |
-
// $email_sent_type = __('Active', 'email-subscribers');
|
41 |
-
$list_id = !empty($broadcast_data['list_ids']) ? $broadcast_data['list_ids'] : '' ;
|
42 |
-
$template_id = !empty($broadcast_data['template_id']) ? $broadcast_data['template_id'] : '' ;
|
43 |
-
$subject = !empty($broadcast_data['subject']) ? $broadcast_data['subject'] : '' ;
|
44 |
-
// $template_id = ig_es_get_request_data( 'ig_es_broadcast_base_template_id' );
|
45 |
-
if ( empty( $broadcast_data['body']) ) {
|
46 |
-
// if ( empty( $template_id) ) {
|
47 |
-
$message = __( 'Please add message body or select template', 'email-subscribers' );
|
48 |
-
ES_Common::show_message( $message, 'error' );
|
49 |
-
} elseif ( empty( $list_id ) ) {
|
50 |
-
$message = __( 'Please select list.', 'email-subscribers' );
|
51 |
-
ES_Common::show_message( $message, 'error' );
|
52 |
-
} elseif ( empty( $subject ) ) {
|
53 |
-
$message = __( 'Please add the subject', 'email-subscribers' );
|
54 |
-
ES_Common::show_message( $message, 'error' );
|
55 |
-
}else {
|
56 |
-
$broadcast_data['base_template_id'] = $template_id;
|
57 |
-
$broadcast_data['list_ids'] = $list_id;
|
58 |
-
$broadcast_data['status'] = 1;
|
59 |
-
// $meta = !empty($broadcast_data['meta']) ? $broadcast_data['meta'] : array();
|
60 |
-
// $meta['pre_header'] = $broadcast_data['pre_header'];
|
61 |
-
// $broadcast_data['meta'] = maybe_serialize($meta);
|
62 |
-
self::es_send_email_callback( $broadcast_data );
|
63 |
-
|
64 |
-
$reports_url = admin_url( 'admin.php?page=es_reports' );
|
65 |
-
$message = __( sprintf( 'A new broadcast has been created successfully! Contacts from selected list will be notified within an hour. Want to notify now? <a href="%s" target="_blank">Click here</a>', $reports_url ), 'email-subscribers' );
|
66 |
-
|
67 |
-
ES_Common::show_message( $message, 'success' );
|
68 |
-
|
69 |
-
do_action( 'ig_es_broadcast_created' );
|
70 |
-
$broadcast_data = array();
|
71 |
-
}
|
72 |
-
|
73 |
-
}
|
74 |
-
|
75 |
-
$this->prepare_newsletter_settings_form();
|
76 |
-
}else if('preview' === $preview ){
|
77 |
-
// $broadcast_data = ig_es_get_request_data( 'broadcast_data', array(), false );
|
78 |
-
if ( empty( $broadcast_data['body'] ) ) {
|
79 |
-
$message = __( 'Please add message content', 'email-subscribers' );
|
80 |
-
ES_Common::show_message( $message, 'error' );
|
81 |
-
$this->prepare_newsletter_settings_form();
|
82 |
-
} else{
|
83 |
-
//content validation
|
84 |
-
$template_data['content'] = !empty($broadcast_data['body']) ? $broadcast_data['body'] : '';
|
85 |
-
$template_data['template_id'] = !empty($broadcast_data['template_id']) ? $broadcast_data['template_id'] : '';
|
86 |
-
$this->es_broadcast_preview_callback( $template_data );
|
87 |
-
|
88 |
-
}
|
89 |
-
|
90 |
-
}
|
91 |
-
}
|
92 |
-
|
93 |
-
public function prepare_newsletter_settings_form() {
|
94 |
-
$newsletter_data = array();
|
95 |
-
$templates = ES_Common::prepare_templates_dropdown_options( 'newsletter' );
|
96 |
-
$lists = ES_Common::prepare_list_dropdown_options();
|
97 |
-
$from_email = ES_Common::get_ig_option( 'from_email' );
|
98 |
-
|
99 |
-
?>
|
100 |
-
|
101 |
-
<div class="wrap">
|
102 |
-
<h2 class="wp-heading-inline"><?php _e( 'Campaigns > Broadcast', 'email-subscribers' ); ?>
|
103 |
-
<a href="admin.php?page=es_campaigns" class="page-title-action"><?php _e( 'Campaigns', 'email-subscribers' ) ?></a>
|
104 |
-
<a href="edit.php?post_type=es_template" class="page-title-action es-imp-button"><?php _e( 'Manage Templates', 'email-subscribers' ) ?></a>
|
105 |
-
</h2>
|
106 |
-
<div class="es-form" style="width: 100%;">
|
107 |
-
<form method="post" action="#">
|
108 |
-
<div class="es_newsletters_settings_wrapper">
|
109 |
-
<div class="es_campaign_name_wrapper ">
|
110 |
-
<input placeholder="Add Broadcast name" type="text" class="es_newsletter_name" name="broadcast_data[name]" value="">
|
111 |
-
<input id="ig_es_campaign_submit_button" class="es_primary_btn" type="submit" name="submit" value="Send Broadcast">
|
112 |
-
<input type="hidden" name="submitted" value="submitted">
|
113 |
-
</div>
|
114 |
-
<div class="es_settings_left_pan">
|
115 |
-
<div class="es_settings_field">
|
116 |
-
<label><?php _e('From Email', 'email-subscribers')?><br/><input type="email" name="broadcast_data[from_email]" value="<?php echo $from_email; ?>"/></label>
|
117 |
-
</div>
|
118 |
-
<div class="es_settings_field">
|
119 |
-
<label><?php _e('Design template', 'email-subscribers')?><br/><select name="broadcast_data[template_id]" id="base_template_id"><?php echo $templates ?></select></label>
|
120 |
-
</div>
|
121 |
-
<div class="es_settings_field"><label><?php _e('Subject', 'email-subscribers')?><br/><input type="text" id="ig_es_broadcast_subject" name="broadcast_data[subject]" placeholder="<?php _e('New Broadcast', 'email-subscribers')?>"/></label></div>
|
122 |
-
<!-- <div class="es_settings_field"><label><?php _e('Pre Header', 'email-subscribers')?><br/><input type="text" name="broadcast_data[pre_header]"/></label></div> -->
|
123 |
-
<div class="es_settings_field">
|
124 |
-
<label><?php _e('Body', 'email-subscribers'); ?></label>
|
125 |
-
<?php
|
126 |
-
$body = !empty($broadcast_data['body']) ? $broadcast_data['body'] : '';
|
127 |
-
$editor_args = array(
|
128 |
-
'textarea_name' => 'broadcast_data[body]',
|
129 |
-
'textarea_rows' => 40,
|
130 |
-
'editor_class' => 'wp-editor-content',
|
131 |
-
'media_buttons' => true,
|
132 |
-
'tinymce' => true,
|
133 |
-
'quicktags'=> true,
|
134 |
-
'editor_class' => 'wp-editor-boradcast'
|
135 |
-
);
|
136 |
-
wp_editor( $body, 'edit-es-boradcast-body', $editor_args ); ?>
|
137 |
-
</div>
|
138 |
-
<?php do_action( 'ig_es_after_broadcast_left_pan_settings'); ?>
|
139 |
-
</div>
|
140 |
-
<div class="es_settings_right_pan">
|
141 |
-
<div class="es_settings_field">
|
142 |
-
<label><?php _e('Recipients', 'email-subscribers')?><br/><select name="broadcast_data[list_ids]" id="ig_es_broadcast_list_ids"><?php echo $lists ?></select></label>
|
143 |
-
</div>
|
144 |
-
<hr>
|
145 |
-
<div class="es_settings_field">
|
146 |
-
<label>
|
147 |
-
<input class="es_secondary_btn" type="submit" id="ig_es_preview_broadcast" value="<?php _e('Preview this email in browser', 'email-subscribers')?>">
|
148 |
-
<input type="hidden" name="es_broadcast_preview" id="es_broadcast_preview">
|
149 |
-
</label>
|
150 |
-
</div>
|
151 |
-
<?php do_action( 'ig_es_after_broadcast_right_pan_settings'); ?>
|
152 |
-
</div>
|
153 |
-
|
154 |
-
</div>
|
155 |
-
</form>
|
156 |
-
</div>
|
157 |
-
<div clas="es-preview" style="float: right;width: 19%;">
|
158 |
-
<div class="es-templ-img"></div>
|
159 |
-
</div>
|
160 |
-
</div>
|
161 |
-
|
162 |
-
<?php
|
163 |
-
|
164 |
-
|
165 |
-
}
|
166 |
-
|
167 |
-
public static function es_send_email_callback( $data ) {
|
168 |
-
|
169 |
-
$list_id = ! empty( $data['list_ids'] ) ? $data['list_ids'] : '';
|
170 |
-
|
171 |
-
$title = get_the_title( $data['base_template_id'] );
|
172 |
-
|
173 |
-
$data['type'] = 'newsletter';
|
174 |
-
$data['name'] = !empty( $data['name'] ) ? $data['name'] : $data['subject'] ;
|
175 |
-
$data['slug'] = sanitize_title( sanitize_text_field( $data['name'] ) );
|
176 |
-
|
177 |
-
$data = apply_filters( 'ig_es_broadcast_data', $data );
|
178 |
-
|
179 |
-
if ( ! empty( $data['body'] ) ) {
|
180 |
-
|
181 |
-
$campaign_id = ES()->campaigns_db->save_campaign( $data );
|
182 |
-
|
183 |
-
$data['body'] = ES_Common::es_process_template_body( $data['body'], $data['base_template_id'], $campaign_id );
|
184 |
-
|
185 |
-
$subscribers = ES()->contacts_db->get_active_contacts_by_list_id( $list_id );
|
186 |
-
|
187 |
-
if ( ! empty( $subscribers ) && count( $subscribers ) > 0 ) {
|
188 |
-
$guid = ES_Common::generate_guid( 6 );
|
189 |
-
$data = array(
|
190 |
-
'hash' => $guid,
|
191 |
-
'campaign_id' => $campaign_id,
|
192 |
-
'subject' => $data['subject'],
|
193 |
-
'body' => $data['body'],
|
194 |
-
'count' => count( $subscribers ),
|
195 |
-
'status' => 'In Queue',
|
196 |
-
'start_at' => ! empty( $data['start_at'] ) ? $data['start_at'] : '',
|
197 |
-
'finish_at' => '',
|
198 |
-
'created_at' => ig_get_current_date_time(),
|
199 |
-
'updated_at' => ig_get_current_date_time(),
|
200 |
-
'meta' => maybe_serialize( array( 'type' => 'newsletter' ) )
|
201 |
-
);
|
202 |
-
|
203 |
-
$last_report_id = ES_DB_Mailing_Queue::add_notification( $data );
|
204 |
-
|
205 |
-
$delivery_data = array();
|
206 |
-
$delivery_data['hash'] = $guid;
|
207 |
-
$delivery_data['subscribers'] = $subscribers;
|
208 |
-
$delivery_data['campaign_id'] = $campaign_id;
|
209 |
-
$delivery_data['mailing_queue_id'] = $last_report_id;
|
210 |
-
ES_DB_Sending_Queue::do_batch_insert( $delivery_data );
|
211 |
-
}
|
212 |
-
}
|
213 |
-
|
214 |
-
return;
|
215 |
-
|
216 |
-
}
|
217 |
-
|
218 |
-
public static function refresh_newsletter_content( $content, $args) {
|
219 |
-
$campaign_id = $args['campaign_id'];
|
220 |
-
$template_id = ES()->campaigns_db->get_template_id_by_campaign( $campaign_id );
|
221 |
-
$content['subject'] = ES()->campaigns_db->get_column( 'subject', $campaign_id );
|
222 |
-
$content['body'] = ES()->campaigns_db->get_column( 'body', $campaign_id );
|
223 |
-
$content['body'] = ES_Common::es_process_template_body( $content['body'], $template_id, $campaign_id );
|
224 |
-
return $content;
|
225 |
-
}
|
226 |
-
|
227 |
-
public static function get_instance() {
|
228 |
-
if ( ! isset( self::$instance ) ) {
|
229 |
-
self::$instance = new self();
|
230 |
-
}
|
231 |
-
|
232 |
-
return self::$instance;
|
233 |
-
}
|
234 |
-
|
235 |
-
public function es_broadcast_preview_callback( $template_data ) {
|
236 |
-
|
237 |
-
$template_id = $template_data['template_id'];
|
238 |
-
if ( !empty($template_data['content'] )) {
|
239 |
-
$current_user = wp_get_current_user();
|
240 |
-
$username = $current_user->user_login;
|
241 |
-
$useremail = $current_user->user_email;
|
242 |
-
|
243 |
-
$es_template_body = $template_data['content'] ;
|
244 |
-
|
245 |
-
$es_template_body = ES_Common::es_process_template_body( $es_template_body , $template_id );
|
246 |
-
$es_template_body = str_replace( '{{NAME}}', $username, $es_template_body );
|
247 |
-
$es_template_body = str_replace( '{{EMAIL}}', $useremail, $es_template_body );
|
248 |
-
|
249 |
-
if ( has_post_thumbnail( $template_id ) ) {
|
250 |
-
$image_array = wp_get_attachment_image_src( get_post_thumbnail_id( $template_id ), 'full' );
|
251 |
-
$image = '<img src="' . $image_array[0] . '" class="img-responsive" alt="Image for Post ' . $template_id . '" />';
|
252 |
-
} else {
|
253 |
-
$image = '';
|
254 |
-
}
|
255 |
-
|
256 |
-
$html = '';
|
257 |
-
$html .= '<style type="text/css">
|
258 |
-
.es-sidebar {
|
259 |
-
width: 23%;
|
260 |
-
background-color: rgb(230, 230, 230);
|
261 |
-
padding:15px;
|
262 |
-
border-right: 1px solid #bdbdbd;
|
263 |
-
}
|
264 |
-
.es-preview {
|
265 |
-
float: left;
|
266 |
-
padding:15px;
|
267 |
-
width: 70%;
|
268 |
-
background-color:#FFF;
|
269 |
-
font-size:16px;
|
270 |
-
}
|
271 |
-
</style>
|
272 |
-
<div class="wrap">
|
273 |
-
<div class="tool-box">
|
274 |
-
<div class="es-main" style="display:flex;">
|
275 |
-
<div class="es-sidebar">
|
276 |
-
<h2 style="margin-bottom:1em;">
|
277 |
-
Template Preview <a class="add-new-h2" target="_blank" href="' . admin_url() . 'admin.php?page=es-general-information">Help</a>
|
278 |
-
</h2>
|
279 |
-
<p>
|
280 |
-
This is how your email may look.<br><br>Note: Different email services (like gmail, yahoo etc) display email content differently. So there could be a slight variation on how your customer will view the email content. </p>
|
281 |
-
</div>
|
282 |
-
<div class="es-preview">' . $es_template_body . '</div>
|
283 |
-
<div style="clear:both;"></div>
|
284 |
-
</div>
|
285 |
-
<div style="clear:both;"></div>
|
286 |
-
</div>
|
287 |
-
</div>';
|
288 |
-
echo apply_filters( 'the_content', $html );
|
289 |
-
} else {
|
290 |
-
echo 'Please publish it or save it as a draft';
|
291 |
-
}
|
292 |
-
|
293 |
-
}
|
294 |
-
|
295 |
-
|
296 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-old-widget.php
DELETED
@@ -1,114 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
class ES_Old_Widget extends WP_Widget {
|
9 |
-
|
10 |
-
function __construct() {
|
11 |
-
$widget_ops = array( 'classname' => 'widget_text elp-widget', 'description' => __( 'Email Subscribers', 'email-subscribers' ) );
|
12 |
-
parent::__construct( 'email-subscribers', __( 'Email Subscribers', 'email-subscribers' ), $widget_ops );
|
13 |
-
}
|
14 |
-
|
15 |
-
function widget( $args, $instance ) {
|
16 |
-
|
17 |
-
$title = apply_filters( 'widget_title', $instance['es_title'] );
|
18 |
-
|
19 |
-
echo $args['before_widget'];
|
20 |
-
|
21 |
-
if ( ! empty( $title ) ) {
|
22 |
-
echo $args['before_title'] . $title . $args['after_title'];
|
23 |
-
}
|
24 |
-
|
25 |
-
$display_name = isset( $instance['es_name'] ) ? esc_attr( $instance['es_name'] ) : '';
|
26 |
-
$subscribers_group = isset( $instance['es_group'] ) ? esc_attr( $instance['es_group'] ) : '';
|
27 |
-
$desc = isset( $instance['es_desc'] ) ? esc_attr( $instance['es_desc'] ) : '';
|
28 |
-
|
29 |
-
$name = strtolower( $display_name ) != 'no' ? 'yes' : '';
|
30 |
-
|
31 |
-
$list = ES()->lists_db->get_list_by_name($subscribers_group);
|
32 |
-
if(!empty($list)) {
|
33 |
-
$list_id = $list['id'];
|
34 |
-
}
|
35 |
-
|
36 |
-
$data['name_visible'] = $name;
|
37 |
-
$data['list_visible'] = 'no';
|
38 |
-
$data['lists'] = array();
|
39 |
-
$data['form_id'] = 0;
|
40 |
-
$data['list'] = $list_id;
|
41 |
-
$data['desc'] = $desc;
|
42 |
-
|
43 |
-
ES_Shortcode::render_form( $data );
|
44 |
-
|
45 |
-
echo $args['after_widget'];
|
46 |
-
}
|
47 |
-
|
48 |
-
function update( $new_instance, $old_instance ) {
|
49 |
-
$instance = $old_instance;
|
50 |
-
$instance['es_title'] = ( ! empty( $new_instance['es_title'] ) ) ? strip_tags( $new_instance['es_title'] ) : '';
|
51 |
-
$instance['es_desc'] = ( ! empty( $new_instance['es_desc'] ) ) ? strip_tags( $new_instance['es_desc'] ) : '';
|
52 |
-
$instance['es_name'] = ( ! empty( $new_instance['es_name'] ) ) ? strip_tags( $new_instance['es_name'] ) : '';
|
53 |
-
$instance['es_group'] = ( ! empty( $new_instance['es_group'] ) ) ? strip_tags( $new_instance['es_group'] ) : '';
|
54 |
-
|
55 |
-
return $instance;
|
56 |
-
}
|
57 |
-
|
58 |
-
function form( $instance ) {
|
59 |
-
$defaults = array(
|
60 |
-
'es_title' => '',
|
61 |
-
'es_desc' => '',
|
62 |
-
'es_name' => '',
|
63 |
-
'es_group' => ''
|
64 |
-
);
|
65 |
-
$instance = wp_parse_args( (array) $instance, $defaults );
|
66 |
-
$es_title = $instance['es_title'];
|
67 |
-
$es_desc = $instance['es_desc'];
|
68 |
-
$es_name = $instance['es_name'];
|
69 |
-
$es_group = $instance['es_group'];
|
70 |
-
?>
|
71 |
-
<p>
|
72 |
-
<label for="<?php echo $this->get_field_id( 'es_title' ); ?>"><?php echo __( 'Widget Title', 'email-subscribers' ); ?></label>
|
73 |
-
<input class="widefat" id="<?php echo $this->get_field_id( 'es_title' ); ?>" name="<?php echo $this->get_field_name( 'es_title' ); ?>" type="text" value="<?php echo $es_title; ?>"/>
|
74 |
-
</p>
|
75 |
-
<p>
|
76 |
-
<label for="<?php echo $this->get_field_id( 'es_desc' ); ?>"><?php echo __( 'Short description about subscription form', 'email-subscribers' ); ?></label>
|
77 |
-
<input class="widefat" id="<?php echo $this->get_field_id( 'es_desc' ); ?>" name="<?php echo $this->get_field_name( 'es_desc' ); ?>" type="text" value="<?php echo $es_desc; ?>"/>
|
78 |
-
</p>
|
79 |
-
<p>
|
80 |
-
<label for="<?php echo $this->get_field_id( 'es_name' ); ?>"><?php echo __( 'Display Name Field', 'email-subscribers' ); ?></label>
|
81 |
-
<select class="widefat" id="<?php echo $this->get_field_id( 'es_name' ); ?>" name="<?php echo $this->get_field_name( 'es_name' ); ?>">
|
82 |
-
<option value="YES" <?php $this->es_selected( $es_name == 'YES' ); ?>><?php echo __( 'YES', 'email-subscribers' ); ?></option>
|
83 |
-
<option value="NO" <?php $this->es_selected( $es_name == 'NO' ); ?>><?php echo __( 'NO', 'email-subscribers' ); ?></option>
|
84 |
-
</select>
|
85 |
-
</p>
|
86 |
-
<p>
|
87 |
-
<label for="<?php echo $this->get_field_id( 'es_group' ); ?>"><?php echo __( 'Subscriber Group', 'email-subscribers' ); ?></label>
|
88 |
-
<select class="widefat" name="<?php echo $this->get_field_name( 'es_group' ); ?>" id="<?php echo $this->get_field_id( 'es_group' ); ?>">
|
89 |
-
<?php
|
90 |
-
$groups = ES()->lists_db->get_list_id_name_map();
|
91 |
-
if ( count( $groups ) > 0 ) {
|
92 |
-
$i = 1;
|
93 |
-
foreach ( $groups as $group ) {
|
94 |
-
?>
|
95 |
-
<option value="<?php echo esc_html( stripslashes( $group ) ); ?>" <?php if ( stripslashes( $es_group ) == $group ) {
|
96 |
-
echo 'selected="selected"';
|
97 |
-
} ?>>
|
98 |
-
<?php echo stripslashes( $group ); ?>
|
99 |
-
</option>
|
100 |
-
<?php
|
101 |
-
}
|
102 |
-
}
|
103 |
-
?>
|
104 |
-
</select>
|
105 |
-
</p>
|
106 |
-
<?php
|
107 |
-
}
|
108 |
-
|
109 |
-
function es_selected( $var ) {
|
110 |
-
if ( $var == 1 || $var == true ) {
|
111 |
-
echo 'selected="selected"';
|
112 |
-
}
|
113 |
-
}
|
114 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-post-notifications.php
DELETED
@@ -1,393 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
class ES_Post_Notifications_Table {
|
9 |
-
|
10 |
-
static $instance;
|
11 |
-
|
12 |
-
public function __construct() {
|
13 |
-
|
14 |
-
}
|
15 |
-
|
16 |
-
public function es_notifications_callback() {
|
17 |
-
|
18 |
-
$action = ig_es_get_request_data( 'action' );
|
19 |
-
|
20 |
-
?>
|
21 |
-
<div class="wrap">
|
22 |
-
<?php if ( 'new' === $action ) {
|
23 |
-
$this->es_newnotification_callback();
|
24 |
-
} elseif ( 'edit' === $action ) {
|
25 |
-
$list = ig_es_get_request_data( 'list' );
|
26 |
-
$this->edit_list( absint( $list ) );
|
27 |
-
}
|
28 |
-
?>
|
29 |
-
</div>
|
30 |
-
<?php
|
31 |
-
}
|
32 |
-
|
33 |
-
public function es_newnotification_callback() {
|
34 |
-
|
35 |
-
$submitted = ig_es_get_request_data( 'submitted' );
|
36 |
-
if ( 'submitted' === $submitted ) {
|
37 |
-
|
38 |
-
$list_id = ig_es_get_request_data( 'list_id' );
|
39 |
-
$template_id = ig_es_get_request_data( 'template_id' );
|
40 |
-
$cat = ig_es_get_request_data( 'es_note_cat' );
|
41 |
-
$es_note_cat_parent = ig_es_get_request_data( 'es_note_cat_parent' );
|
42 |
-
$cat = (!empty($es_note_cat_parent) && $es_note_cat_parent == '{a}All{a}') ? array($es_note_cat_parent) : $cat;
|
43 |
-
|
44 |
-
if ( empty( $list_id ) ) {
|
45 |
-
$message = __( 'Please select list.', 'email-subscribers' );
|
46 |
-
ES_Common::show_message( $message, 'error' );
|
47 |
-
$this->prepare_post_notification_form();
|
48 |
-
|
49 |
-
return;
|
50 |
-
}
|
51 |
-
|
52 |
-
if ( empty( $cat ) ) {
|
53 |
-
$message = __( 'Please select categories.', 'email-subscribers' );
|
54 |
-
ES_Common::show_message( $message, 'error' );
|
55 |
-
$this->prepare_post_notification_form();
|
56 |
-
|
57 |
-
return;
|
58 |
-
}
|
59 |
-
|
60 |
-
$type = 'post_notification';
|
61 |
-
$title = get_the_title( $template_id );
|
62 |
-
|
63 |
-
$data = array(
|
64 |
-
'categories' => ES_Common::convert_categories_array_to_string( $cat ),
|
65 |
-
'list_ids' => $list_id,
|
66 |
-
'base_template_id' => $template_id,
|
67 |
-
'status' => 1,
|
68 |
-
'type' => $type,
|
69 |
-
'name' => $title,
|
70 |
-
'slug' => sanitize_title( $title )
|
71 |
-
);
|
72 |
-
$data = apply_filters( 'ig_es_post_notification_data', $data );
|
73 |
-
if ( empty( $data['base_template_id'] ) ) {
|
74 |
-
$message = __( 'Please select template.', 'email-subscribers' );
|
75 |
-
ES_Common::show_message( $message, 'error' );
|
76 |
-
$this->prepare_post_notification_form();
|
77 |
-
|
78 |
-
return;
|
79 |
-
}
|
80 |
-
$this->save_list( $data );
|
81 |
-
$type = ucwords(str_replace('_', ' ', $data['type']));
|
82 |
-
$message = __( "$type has been added successfully!", 'email-subscribers' );
|
83 |
-
ES_Common::show_message( $message, 'success' );
|
84 |
-
}
|
85 |
-
|
86 |
-
$this->prepare_post_notification_form();
|
87 |
-
|
88 |
-
}
|
89 |
-
|
90 |
-
public function custom_admin_notice() {
|
91 |
-
$es_note_cate = ig_es_get_request_data( 'es_note_cate' );
|
92 |
-
|
93 |
-
if ( $es_note_cate ) {
|
94 |
-
echo '<div class="updated"><p>Notification Added Successfully!</p></div>';
|
95 |
-
}
|
96 |
-
}
|
97 |
-
|
98 |
-
public function update_list( $id ) {
|
99 |
-
|
100 |
-
global $wpdb;
|
101 |
-
$cat = ig_es_get_request_data( 'es_note_cat' );
|
102 |
-
$data = array(
|
103 |
-
'categories' => ES_Common::convert_categories_array_to_string( $cat ),
|
104 |
-
'list_ids' => ig_es_get_request_data( 'list_id' ),
|
105 |
-
'base_template_id' => ig_es_get_request_data( 'template_id' ),
|
106 |
-
'status' => 'active'
|
107 |
-
);
|
108 |
-
$wpdb->update( IG_CAMPAIGNS_TABLE, $data, array( 'id' => $id ) );
|
109 |
-
|
110 |
-
}
|
111 |
-
|
112 |
-
public function save_list( $data, $id = null ) {
|
113 |
-
return ES()->campaigns_db->save_campaign( $data, $id );
|
114 |
-
}
|
115 |
-
|
116 |
-
/**
|
117 |
-
* Retrieve lists data from the database
|
118 |
-
*
|
119 |
-
* @param int $per_page
|
120 |
-
* @param int $page_number
|
121 |
-
*
|
122 |
-
* @return mixed
|
123 |
-
*/
|
124 |
-
public static function get_lists( $per_page = 5, $page_number = 1 ) {
|
125 |
-
|
126 |
-
global $wpdb;
|
127 |
-
|
128 |
-
$order_by = sanitize_sql_orderby( ig_es_get_request_data( 'orderby' ) );
|
129 |
-
$order = ig_es_get_request_data( 'order' );
|
130 |
-
$search = ig_es_get_request_data( 's' );
|
131 |
-
|
132 |
-
$add_where_clause = false;
|
133 |
-
$sql = "SELECT * FROM " . IG_CAMPAIGNS_TABLE;
|
134 |
-
$args = array();
|
135 |
-
$query = array();
|
136 |
-
|
137 |
-
if ( ! empty( $search ) ) {
|
138 |
-
$add_where_clause = true;
|
139 |
-
$query[] = " name LIKE %s ";
|
140 |
-
$args[] = "%" . $wpdb->esc_like( $search ) . "%";
|
141 |
-
}
|
142 |
-
|
143 |
-
if ( $add_where_clause ) {
|
144 |
-
$sql .= " WHERE ";
|
145 |
-
|
146 |
-
if ( count( $query ) > 0 ) {
|
147 |
-
$sql .= implode( " AND ", $query );
|
148 |
-
$sql = $wpdb->prepare( $sql, $args );
|
149 |
-
}
|
150 |
-
}
|
151 |
-
|
152 |
-
// Prepare Order by clause
|
153 |
-
$order_by_clause = '';
|
154 |
-
if ( ! empty( $order_by ) ) {
|
155 |
-
$order_by_clause = ' ORDER BY ' . esc_sql( $order_by );
|
156 |
-
$order_by_clause .= ! empty( $order ) ? ' ' . esc_sql( $order ) : ' ASC';
|
157 |
-
}
|
158 |
-
|
159 |
-
$sql .= $order_by_clause;
|
160 |
-
$sql .= " LIMIT $per_page";
|
161 |
-
$sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page;
|
162 |
-
|
163 |
-
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
|
164 |
-
|
165 |
-
return $result;
|
166 |
-
|
167 |
-
}
|
168 |
-
|
169 |
-
public function edit_list( $id ) {
|
170 |
-
|
171 |
-
global $wpdb;
|
172 |
-
|
173 |
-
$notifications = $wpdb->get_results( "SELECT * FROM " . IG_CAMPAIGNS_TABLE . " WHERE id = $id LIMIT 0, 1", ARRAY_A );
|
174 |
-
|
175 |
-
$submitted = ig_es_get_request_data( 'submitted' );
|
176 |
-
if ( 'submitted' === $submitted ) {
|
177 |
-
$categories = ig_es_get_request_data( 'es_note_cat', array() );
|
178 |
-
|
179 |
-
//all categories selected
|
180 |
-
$parent_category_option = ig_es_get_request_data( 'es_note_cat_parent' );
|
181 |
-
if ( $parent_category_option === '{a}All{a}' ) {
|
182 |
-
array_unshift( $categories, $parent_category_option );
|
183 |
-
}
|
184 |
-
|
185 |
-
$data = array(
|
186 |
-
'categories' => ES_Common::convert_categories_array_to_string( $categories ),
|
187 |
-
'list_ids' => ig_es_get_request_data( 'list_id' ),
|
188 |
-
'base_template_id' => ig_es_get_request_data( 'template_id' ),
|
189 |
-
'status' => ig_es_get_request_data( 'status' )
|
190 |
-
);
|
191 |
-
|
192 |
-
$title = '';
|
193 |
-
if ( ! empty( $data['base_template_id'] ) ) {
|
194 |
-
$title = get_the_title( $data['base_template_id'] );
|
195 |
-
}
|
196 |
-
$data['name'] = $title;
|
197 |
-
|
198 |
-
$data = apply_filters( 'ig_es_post_notification_data', $data );
|
199 |
-
$data['type'] = !empty($data['type']) ? $data['type'] : 'post_notification';
|
200 |
-
//check tempalte id
|
201 |
-
if ( empty( $data['base_template_id'] ) ) {
|
202 |
-
$message = __( 'Please select template.', 'email-subscribers' );
|
203 |
-
ES_Common::show_message( $message, 'error' );
|
204 |
-
$this->prepare_post_notification_form( $id, $data );
|
205 |
-
return;
|
206 |
-
}
|
207 |
-
//check categories
|
208 |
-
if ( empty( $categories ) ) {
|
209 |
-
$message = __( 'Please select Categories.', 'email-subscribers' );
|
210 |
-
ES_Common::show_message( $message, 'error' );
|
211 |
-
$this->prepare_post_notification_form( $id, $data );
|
212 |
-
return;
|
213 |
-
}
|
214 |
-
$this->save_list( $data, $id );
|
215 |
-
|
216 |
-
$data['categories'] = ES_Common::convert_categories_string_to_array( $data['categories'], true );
|
217 |
-
$type = ucwords(str_replace('_', ' ', $data['type']));
|
218 |
-
$message = __( "$type has been updated successfully!", 'email-subscribers' );
|
219 |
-
ES_Common::show_message( $message, 'success' );
|
220 |
-
} else {
|
221 |
-
|
222 |
-
$notification = array_shift( $notifications );
|
223 |
-
$id = $notification['id'];
|
224 |
-
|
225 |
-
$categories_str = ! empty( $notification['categories'] ) ? $notification['categories'] : '';
|
226 |
-
$categories = ES_Common::convert_categories_string_to_array( $categories_str, true );
|
227 |
-
$data = array(
|
228 |
-
'categories' => $categories,
|
229 |
-
'list_ids' => $notification['list_ids'],
|
230 |
-
'base_template_id' => $notification['base_template_id'],
|
231 |
-
'status' => $notification['status']
|
232 |
-
);
|
233 |
-
}
|
234 |
-
|
235 |
-
$this->prepare_post_notification_form( $id, $data );
|
236 |
-
|
237 |
-
}
|
238 |
-
|
239 |
-
public static function prepare_post_notification_form( $id = '', $data = array() ) {
|
240 |
-
|
241 |
-
$is_new = empty( $id ) ? 1 : 0;
|
242 |
-
|
243 |
-
$action = 'new';
|
244 |
-
$heading = __( 'Campaigns > New Post Notification', 'email-subscribers' );
|
245 |
-
if ( ! $is_new ) {
|
246 |
-
$action = 'edit';
|
247 |
-
$heading = __( 'Campaigns > Edit Post Notification', 'email-subscribers' );
|
248 |
-
}
|
249 |
-
$cat = isset( $data['categories'] ) ? $data['categories'] : '';
|
250 |
-
$list_id = isset( $data['list_ids'] ) ? $data['list_ids'] : '';
|
251 |
-
$template_id = isset( $data['base_template_id'] ) ? $data['base_template_id'] : '';
|
252 |
-
$status = isset( $data['status'] ) ? $data['status'] : '';
|
253 |
-
$nonce = wp_create_nonce( 'es_post_notification' );
|
254 |
-
?>
|
255 |
-
|
256 |
-
<div class="wrap">
|
257 |
-
<h2 class="wp-heading-inline"><?php echo $heading; ?>
|
258 |
-
<a href="admin.php?page=es_campaigns" class="page-title-action"><?php _e( 'Campaigns', 'email-subscribers' ) ?></a>
|
259 |
-
<?php if ( $action === 'edit' ) { ?>
|
260 |
-
<a href="admin.php?page=es_notifications&action=new" class="page-title-action"><?php _e( 'Add New', 'email-subscribers' ) ?></a>
|
261 |
-
<?php } ?>
|
262 |
-
<a href="edit.php?post_type=es_template" class="page-title-action es-imp-button"><?php _e( 'Manage Templates', 'email-subscribers' ) ?></a>
|
263 |
-
</h2>
|
264 |
-
<hr class="wp-header-end">
|
265 |
-
<div class="meta-box-sortables ui-sortable" style="width: 80%;display:inline;float:left">
|
266 |
-
<form method="post" action="admin.php?page=es_notifications&action=<?php echo $action; ?>&list=<?php echo $id; ?>&_wpnonce=<?php echo $nonce; ?>">
|
267 |
-
<table class="form-table">
|
268 |
-
<tbody>
|
269 |
-
<?php do_action('es_before_post_notification_settings', $id ); ?>
|
270 |
-
<tr>
|
271 |
-
<th scope="row">
|
272 |
-
<label for="tag-link"><?php _e( 'Select List', 'email-subscribers' ); ?></label>
|
273 |
-
<p class="helper"><?php _e( 'Contacts from the selected list will be notified about new post notification.', 'email-subscribers' ); ?></p>
|
274 |
-
</th>
|
275 |
-
<td>
|
276 |
-
<select name="list_id" id="ig_es_post_notification_list_ids">
|
277 |
-
<?php echo ES_Common::prepare_list_dropdown_options( $list_id ); ?>
|
278 |
-
</select>
|
279 |
-
</td>
|
280 |
-
</tr>
|
281 |
-
<tr>
|
282 |
-
<th scope="row">
|
283 |
-
<label for="tag-link">
|
284 |
-
<?php _e( 'Select template', 'email-subscribers' ); ?>
|
285 |
-
<p class="helper"><?php _e( 'Content of the selected template will be sent out as post notification.', 'email-subscribers' ); ?></p>
|
286 |
-
</label>
|
287 |
-
</th>
|
288 |
-
<td>
|
289 |
-
<select name="template_id" id="base_template_id">
|
290 |
-
<?php echo ES_Common::prepare_templates_dropdown_options( 'post_notification', $template_id ); ?>
|
291 |
-
</select>
|
292 |
-
</td>
|
293 |
-
</tr>
|
294 |
-
<?php do_action('es_after_post_notification_template', $id ); ?>
|
295 |
-
<?php if ( ! $is_new ) { ?>
|
296 |
-
<tr>
|
297 |
-
<th scope="row">
|
298 |
-
<label for="tag-link">
|
299 |
-
<?php _e( 'Select Status', 'email-subscribers' ); ?>
|
300 |
-
</label>
|
301 |
-
</th>
|
302 |
-
<td>
|
303 |
-
<select name="status" id="status">
|
304 |
-
<?php echo ES_Common::prepare_status_dropdown_options( $status ); ?>
|
305 |
-
</select>
|
306 |
-
</td>
|
307 |
-
</tr>
|
308 |
-
<?php } ?>
|
309 |
-
<tr>
|
310 |
-
<th scope="row">
|
311 |
-
<label for="tag-link"><?php _e( 'Select Post Category', 'email-subscribers' ); ?></label>
|
312 |
-
<p class="helper"><?php _e( 'Notification will be sent out when any post from selected categories will be published.', 'email-subscribers' ); ?></p>
|
313 |
-
</th>
|
314 |
-
<td style="vertical-align: top;">
|
315 |
-
<table border="0" cellspacing="0">
|
316 |
-
<tbody>
|
317 |
-
<?php echo ES_Common::prepare_categories_html( $cat ); ?>
|
318 |
-
</tbody>
|
319 |
-
</table>
|
320 |
-
</td>
|
321 |
-
</tr>
|
322 |
-
<tr>
|
323 |
-
<th scope="row">
|
324 |
-
<label for="tag-link">
|
325 |
-
<?php _e( 'Select custom post type(s)', 'email-subscribers' ); ?>
|
326 |
-
<p class="helper"><?php _e( '(Optional) Select custom post type for which you want to send notification.', 'email-subscribers' ); ?></p>
|
327 |
-
</label>
|
328 |
-
</th>
|
329 |
-
<td>
|
330 |
-
<table border="0" cellspacing="0">
|
331 |
-
<tbody>
|
332 |
-
<?php $custom_post_type = '';
|
333 |
-
echo ES_Common::prepare_custom_post_type_checkbox( $cat ); ?>
|
334 |
-
</tbody>
|
335 |
-
</table>
|
336 |
-
</td>
|
337 |
-
</tr>
|
338 |
-
<?php do_action('es_after_post_notification_settings', $id ); ?>
|
339 |
-
<tr>
|
340 |
-
<td><input type="hidden" name="submitted" value="submitted"></td>
|
341 |
-
</tr>
|
342 |
-
</tbody>
|
343 |
-
</table>
|
344 |
-
<div class="row-blog">
|
345 |
-
<div class="leftside">
|
346 |
-
<p class="submit"><input type="submit" name="submit" id="ig_es_campaign_post_notification_submit_button" class="button button-primary button-large" value="Save Changes"></p>
|
347 |
-
</div>
|
348 |
-
</div>
|
349 |
-
</form>
|
350 |
-
</div>
|
351 |
-
<div clas="es-preview" style="float: right;width: 19%;">
|
352 |
-
<div class="es-templ-img"></div>
|
353 |
-
</div>
|
354 |
-
</div>
|
355 |
-
|
356 |
-
<?php
|
357 |
-
|
358 |
-
}
|
359 |
-
|
360 |
-
|
361 |
-
/**
|
362 |
-
* Returns an associative array containing the bulk action
|
363 |
-
*
|
364 |
-
* @return array
|
365 |
-
*/
|
366 |
-
public function get_bulk_actions() {
|
367 |
-
$actions = array(
|
368 |
-
'bulk_delete' => 'Delete'
|
369 |
-
);
|
370 |
-
|
371 |
-
return $actions;
|
372 |
-
}
|
373 |
-
|
374 |
-
public function search_box( $text, $input_id ) { ?>
|
375 |
-
<p class="search-box">
|
376 |
-
<label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
|
377 |
-
<input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>"/>
|
378 |
-
<?php submit_button( 'Search Notifications', 'button', false, false, array( 'id' => 'search-submit' ) ); ?>
|
379 |
-
</p>
|
380 |
-
<?php
|
381 |
-
}
|
382 |
-
|
383 |
-
public static function get_instance() {
|
384 |
-
if ( ! isset( self::$instance ) ) {
|
385 |
-
self::$instance = new self();
|
386 |
-
}
|
387 |
-
|
388 |
-
return self::$instance;
|
389 |
-
}
|
390 |
-
|
391 |
-
}
|
392 |
-
|
393 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-queue.php
DELETED
@@ -1,693 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
// Exit if accessed directly
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
4 |
-
exit;
|
5 |
-
}
|
6 |
-
|
7 |
-
if ( ! class_exists( 'ES_Queue' ) ) {
|
8 |
-
/**
|
9 |
-
* Class ES_Queue
|
10 |
-
*
|
11 |
-
* Manage Mailing Queue
|
12 |
-
*
|
13 |
-
* Actions
|
14 |
-
* ig_es_time_based_campaign - Immediately, Daily, Weekly, Monthly
|
15 |
-
* ig_es_contact_insert - Time after contact subscribe
|
16 |
-
* ig_es_campaign_open - Time after specific campaign open
|
17 |
-
*
|
18 |
-
* @since 4.2.0
|
19 |
-
*/
|
20 |
-
class ES_Queue {
|
21 |
-
/**
|
22 |
-
* ES_DB_Queue object
|
23 |
-
*
|
24 |
-
* @since 4.2.1
|
25 |
-
* @var $db
|
26 |
-
*
|
27 |
-
*/
|
28 |
-
protected $db;
|
29 |
-
|
30 |
-
/**
|
31 |
-
* ES_Queue constructor.
|
32 |
-
*
|
33 |
-
* @since 4.2.0
|
34 |
-
*/
|
35 |
-
public function __construct() {
|
36 |
-
|
37 |
-
$this->db = new ES_DB_Queue();
|
38 |
-
|
39 |
-
add_action( 'plugins_loaded', array( &$this, 'init' ), 1 );
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Initialize Queue
|
44 |
-
*
|
45 |
-
* @since 4.2.0
|
46 |
-
*/
|
47 |
-
public function init() {
|
48 |
-
add_action( 'ig_es_cron_auto_responder', array( &$this, 'queue_time_based_campaigns' ), 30 );
|
49 |
-
add_action( 'ig_es_cron_auto_responder', array( &$this, 'queue_sequences' ), 30 );
|
50 |
-
|
51 |
-
add_action( 'ig_es_cron_worker', array( &$this, 'process_campaigns' ), 10 );
|
52 |
-
add_action( 'ig_es_cron_worker', array( &$this, 'process_queue' ), 30 );
|
53 |
-
}
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Queue valid time based campaigns
|
57 |
-
*
|
58 |
-
* @since 4.2.0
|
59 |
-
*/
|
60 |
-
public function queue_time_based_campaigns( $campaign_id = 0, $force = false ) {
|
61 |
-
/**
|
62 |
-
* Steps
|
63 |
-
* 1. Fetch all active campaigns
|
64 |
-
* 2. Loop over through and based on matched condition put campaign into mailing_queue table
|
65 |
-
* 3. And also insert subscribers for respective campaign into sending_queue_table
|
66 |
-
* 4. Call es cron to send emails from queue
|
67 |
-
*/
|
68 |
-
static $campaigns_to_process;
|
69 |
-
|
70 |
-
if ( ! isset( $campaigns_to_process ) ) {
|
71 |
-
$campaigns_to_process = array();
|
72 |
-
}
|
73 |
-
|
74 |
-
if ( $campaign_id ) {
|
75 |
-
$campaign = ES()->campaigns_db->get_campaign_by_id( $campaign_id );
|
76 |
-
$campaigns = array( $campaign );
|
77 |
-
} else {
|
78 |
-
$campaigns = ES()->campaigns_db->get_active_campaigns( IG_CAMPAIGN_TYPE_POST_DIGEST );
|
79 |
-
}
|
80 |
-
|
81 |
-
if ( empty( $campaigns ) ) {
|
82 |
-
return;
|
83 |
-
}
|
84 |
-
|
85 |
-
$now = time();
|
86 |
-
|
87 |
-
foreach ( $campaigns as $campaign ) {
|
88 |
-
|
89 |
-
if ( in_array( $campaign['id'], $campaigns_to_process ) && ! $force ) {
|
90 |
-
continue;
|
91 |
-
}
|
92 |
-
|
93 |
-
$campaign_id = $campaign['id'];
|
94 |
-
|
95 |
-
$campaigns_to_process[] = $campaign_id;
|
96 |
-
|
97 |
-
$meta = maybe_unserialize( $campaign['meta'] );
|
98 |
-
|
99 |
-
$rules = ! empty( $meta['rules'] ) ? $meta['rules'] : array();
|
100 |
-
|
101 |
-
if ( ! empty( $rules ) ) {
|
102 |
-
|
103 |
-
$action = ! empty( $rules['action'] ) ? $rules['action'] : '';
|
104 |
-
|
105 |
-
if ( 'ig_es_time_based_campaign' != $action ) {
|
106 |
-
continue;
|
107 |
-
}
|
108 |
-
|
109 |
-
$start_time = ! empty( $meta['next_run'] ) ? $meta['next_run'] : 0;
|
110 |
-
|
111 |
-
if ( ! empty( $start_time ) ) {
|
112 |
-
|
113 |
-
$scheduled = ! empty( $meta['scheduled'] ) ? $meta['scheduled'] : 0;
|
114 |
-
|
115 |
-
$delay = $start_time - $now;
|
116 |
-
|
117 |
-
// seconds the campaign should created before the actual send time.
|
118 |
-
$time_created_before = 3600;
|
119 |
-
|
120 |
-
// Is it a good time to do now?
|
121 |
-
$do_it = $delay <= $time_created_before;
|
122 |
-
|
123 |
-
// By default do not schedule
|
124 |
-
if ( $do_it && ! $scheduled ) {
|
125 |
-
|
126 |
-
$campaign['start_at'] = date( 'Y-m-d H:i:s', $start_time );
|
127 |
-
|
128 |
-
$list_id = $campaign['list_ids'];
|
129 |
-
|
130 |
-
// Do we have active subscribers?
|
131 |
-
$contacts = ES()->contacts_db->get_active_contacts_by_list_id( $list_id );
|
132 |
-
$total_contacts = count( $contacts );
|
133 |
-
|
134 |
-
if ( $total_contacts > 0 ) {
|
135 |
-
// Create a new mailing queue using this campaign
|
136 |
-
$result = $this->add_campaign_to_queue( $campaign, $total_contacts );
|
137 |
-
|
138 |
-
if ( is_array( $result ) ) {
|
139 |
-
$queue_id = $result['id'];
|
140 |
-
$hash = $result['hash'];
|
141 |
-
|
142 |
-
$this->add_contacts_to_queue( $campaign_id, $hash, $queue_id, $contacts );
|
143 |
-
}
|
144 |
-
|
145 |
-
}
|
146 |
-
}
|
147 |
-
|
148 |
-
$time_frame = ! empty( $rules['time_frame'] ) ? $rules['time_frame'] : '';
|
149 |
-
|
150 |
-
if ( 'immediately' !== $time_frame ) {
|
151 |
-
|
152 |
-
$data = array(
|
153 |
-
'utc_start' => $start_time,
|
154 |
-
'interval' => $rules['interval'],
|
155 |
-
'time_frame' => $time_frame,
|
156 |
-
'time_of_day' => $rules['time_of_day'],
|
157 |
-
'weekdays' => $rules['weekdays'],
|
158 |
-
'force' => true
|
159 |
-
);
|
160 |
-
|
161 |
-
// Get the next run time.
|
162 |
-
$next_run = ig_es_get_next_future_schedule_date( $data );
|
163 |
-
|
164 |
-
$meta_data['next_run'] = $next_run;
|
165 |
-
if ( $next_run == $start_time ) {
|
166 |
-
$meta_data['scheduled'] = 1;
|
167 |
-
} else {
|
168 |
-
$meta_data['scheduled'] = 0;
|
169 |
-
}
|
170 |
-
|
171 |
-
} else {
|
172 |
-
$meta_data['scheduled'] = 1;
|
173 |
-
}
|
174 |
-
|
175 |
-
ES()->campaigns_db->update_campaign_meta( $campaign_id, $meta_data );
|
176 |
-
}
|
177 |
-
}
|
178 |
-
}
|
179 |
-
|
180 |
-
}
|
181 |
-
|
182 |
-
/**
|
183 |
-
* Queue Valid Sequence messages
|
184 |
-
*
|
185 |
-
* @since 4.2.1
|
186 |
-
*/
|
187 |
-
public function queue_sequences( $campaign_id = 0, $force = false ) {
|
188 |
-
global $wpdb;
|
189 |
-
/**
|
190 |
-
* Steps
|
191 |
-
* 1. Fetch all active Sequence Message
|
192 |
-
* 2. Loop over through and based on matched condition put campaign into mailing_queue table if not already exists
|
193 |
-
* 3. And also insert subscribers for respective campaign into snding_queue_table
|
194 |
-
*/
|
195 |
-
static $campaigns_to_process;
|
196 |
-
|
197 |
-
if ( ! isset( $campaigns_to_process ) ) {
|
198 |
-
$campaigns_to_process = array();
|
199 |
-
}
|
200 |
-
|
201 |
-
if ( $campaign_id ) {
|
202 |
-
$campaign = ES()->campaigns_db->get_campaign_by_id( $campaign_id );
|
203 |
-
$campaigns = array( $campaign );
|
204 |
-
} else {
|
205 |
-
$campaigns = ES()->campaigns_db->get_active_campaigns( IG_CAMPAIGN_TYPE_SEQUENCE_MESSAGE );
|
206 |
-
}
|
207 |
-
|
208 |
-
if ( empty( $campaigns ) ) {
|
209 |
-
return;
|
210 |
-
}
|
211 |
-
|
212 |
-
$now = time();
|
213 |
-
|
214 |
-
foreach ( $campaigns as $campaign ) {
|
215 |
-
|
216 |
-
if ( in_array( $campaign['id'], $campaigns_to_process ) && ! $force ) {
|
217 |
-
continue;
|
218 |
-
}
|
219 |
-
|
220 |
-
$campaign_id = $campaign['id'];
|
221 |
-
|
222 |
-
$campaigns_to_process[] = $campaign_id;
|
223 |
-
|
224 |
-
$meta = maybe_unserialize( $campaign['meta'] );
|
225 |
-
|
226 |
-
$rules = ! empty( $meta['rules'] ) ? $meta['rules'] : array();
|
227 |
-
|
228 |
-
//ES()->logger->info( 'Rules: ' . print_r( $rules, true ) );
|
229 |
-
|
230 |
-
if ( ! empty( $rules ) ) {
|
231 |
-
|
232 |
-
$action = ! empty( $rules['action'] ) ? $rules['action'] : '';
|
233 |
-
|
234 |
-
if ( 'ig_es_contact_insert' != $action ) {
|
235 |
-
continue;
|
236 |
-
}
|
237 |
-
|
238 |
-
// We are considering contacts for sequences which are last added in a week.
|
239 |
-
$grace_period = 1 * DAY_IN_SECONDS;
|
240 |
-
$queue_upfront = 3600;
|
241 |
-
|
242 |
-
$offset = (int) $rules['amount'] . ' ' . strtoupper( $rules['unit'] );
|
243 |
-
|
244 |
-
$list_ids = $campaign['list_ids'];
|
245 |
-
|
246 |
-
$ig_actions_table = IG_ACTIONS_TABLE;
|
247 |
-
$ig_lists_contacts_table = IG_LISTS_CONTACTS_TABLE;
|
248 |
-
$ig_queue_table = IG_QUEUE_TABLE;
|
249 |
-
$ig_campaign_sent = IG_MESSAGE_SENT;
|
250 |
-
|
251 |
-
$query_args = array(
|
252 |
-
"select" => "SELECT lists_contacts.contact_id, UNIX_TIMESTAMP ( lists_contacts.subscribed_at + INTERVAL $offset ) AS timestamp",
|
253 |
-
"from" => "FROM $ig_lists_contacts_table AS lists_contacts",
|
254 |
-
'join1' => "LEFT JOIN $ig_actions_table AS actions_sent_message ON lists_contacts.contact_id = actions_sent_message.contact_id AND actions_sent_message.type = $ig_campaign_sent AND actions_sent_message.campaign_id IN ($campaign_id)",
|
255 |
-
'join2' => "LEFT JOIN $ig_queue_table AS queue ON lists_contacts.contact_id = queue.contact_id AND queue.campaign_id IN ($campaign_id)",
|
256 |
-
'where' => "WHERE 1=1 AND lists_contacts.list_id IN ($list_ids) AND lists_contacts.status = 'subscribed' AND actions_sent_message.contact_id IS NULL AND queue.contact_id IS NULL",
|
257 |
-
'group_by' => "GROUP BY lists_contacts.contact_id",
|
258 |
-
'having' => "HAVING timestamp <= " . ( $now + $queue_upfront ) . " AND timestamp >= " . ( $now - $grace_period ),
|
259 |
-
'order_by' => 'ORDER BY timestamp ASC',
|
260 |
-
);
|
261 |
-
|
262 |
-
$query = implode( ' ', $query_args );
|
263 |
-
|
264 |
-
//ES()->logger->info( '----------------------------Query Args (ig_es_contact_insert) ----------------------------' );
|
265 |
-
//ES()->logger->info( $query );
|
266 |
-
//ES()->logger->info( '----------------------------Query Args Complete (ig_es_contact_insert) ----------------------------' );
|
267 |
-
|
268 |
-
$results = $wpdb->get_results( $query, ARRAY_A );
|
269 |
-
|
270 |
-
//ES()->logger->info( 'Results: ' . print_r( $results, true ) );
|
271 |
-
|
272 |
-
if ( ! empty( $results ) ) {
|
273 |
-
|
274 |
-
$contact_ids = wp_list_pluck( $results, 'contact_id' );
|
275 |
-
$timestamps = wp_list_pluck( $results, 'timestamp' );
|
276 |
-
|
277 |
-
/**
|
278 |
-
* Check whether campaign is already exists in mailing_queue table with $campaign_id
|
279 |
-
* If Exists, Get the mailing_queue_id & hash
|
280 |
-
* If Not, create new and get the mailing_queue_id & hash
|
281 |
-
*/
|
282 |
-
$total_contacts = count( $contact_ids );
|
283 |
-
if ( $total_contacts > 0 ) {
|
284 |
-
|
285 |
-
$this->bulk_add( $campaign_id, $contact_ids, $timestamps, 15 );
|
286 |
-
|
287 |
-
$timestamp = min( $timestamps );
|
288 |
-
|
289 |
-
// handle instant delivery
|
290 |
-
if ( $timestamp - time() <= 0 ) {
|
291 |
-
wp_schedule_single_event( $timestamp, 'ig_es_cron_worker', array( $campaign_id ) );
|
292 |
-
}
|
293 |
-
|
294 |
-
}
|
295 |
-
}
|
296 |
-
|
297 |
-
}
|
298 |
-
}
|
299 |
-
|
300 |
-
|
301 |
-
}
|
302 |
-
|
303 |
-
/**
|
304 |
-
* Add campaign to queue
|
305 |
-
*
|
306 |
-
* @param $campaign
|
307 |
-
*
|
308 |
-
* @return int | array
|
309 |
-
*
|
310 |
-
* @since 4.2.0
|
311 |
-
*/
|
312 |
-
public function add_campaign_to_queue( $campaign, $total_contacts ) {
|
313 |
-
|
314 |
-
$campaign_id = $campaign['id'];
|
315 |
-
$template_id = $campaign['base_template_id'];
|
316 |
-
$template = get_post( $template_id );
|
317 |
-
$queue_id = 0;
|
318 |
-
if ( $template instanceof WP_Post && $total_contacts > 0 ) {
|
319 |
-
|
320 |
-
$subject = ! empty( $template->post_title ) ? $template->post_title : '';
|
321 |
-
$content = ! empty( $template->post_content ) ? $template->post_content : '';
|
322 |
-
$content = ES_Common::es_process_template_body( $content, $template_id );
|
323 |
-
|
324 |
-
$guid = ES_Common::generate_guid( 6 );
|
325 |
-
|
326 |
-
$data = array(
|
327 |
-
'hash' => $guid,
|
328 |
-
'campaign_id' => $campaign_id,
|
329 |
-
'subject' => $subject,
|
330 |
-
'body' => $content,
|
331 |
-
'count' => $total_contacts,
|
332 |
-
'status' => 'In Queue',
|
333 |
-
'start_at' => ! empty( $campaign['start_at'] ) ? $campaign['start_at'] : '',
|
334 |
-
'finish_at' => '',
|
335 |
-
'created_at' => ig_get_current_date_time(),
|
336 |
-
'updated_at' => ig_get_current_date_time(),
|
337 |
-
'meta' => maybe_serialize( array( 'type' => $campaign['type'] ) )
|
338 |
-
);
|
339 |
-
|
340 |
-
$queue_id = ES_DB_Mailing_Queue::add_notification( $data );
|
341 |
-
|
342 |
-
return array(
|
343 |
-
'hash' => $guid,
|
344 |
-
'id' => $queue_id
|
345 |
-
);
|
346 |
-
|
347 |
-
}
|
348 |
-
|
349 |
-
return $queue_id;
|
350 |
-
}
|
351 |
-
|
352 |
-
/**
|
353 |
-
* Add contacts into sending_queue_table
|
354 |
-
*
|
355 |
-
* @param $campaign_id
|
356 |
-
* @param $guid
|
357 |
-
* @param $queue_id
|
358 |
-
* @param $contacts
|
359 |
-
*
|
360 |
-
* @since 4.2.1
|
361 |
-
*/
|
362 |
-
public function add_contacts_to_queue( $campaign_id, $guid, $queue_id, $contacts ) {
|
363 |
-
|
364 |
-
$delivery_data = array();
|
365 |
-
$delivery_data['hash'] = $guid;
|
366 |
-
$delivery_data['subscribers'] = $contacts;
|
367 |
-
$delivery_data['campaign_id'] = $campaign_id;
|
368 |
-
$delivery_data['mailing_queue_id'] = $queue_id;
|
369 |
-
|
370 |
-
ES_DB_Sending_Queue::do_batch_insert( $delivery_data );
|
371 |
-
}
|
372 |
-
|
373 |
-
/**
|
374 |
-
* Bulk Add contacts into queue
|
375 |
-
*
|
376 |
-
* @param $campaign_id
|
377 |
-
* @param $subscribers
|
378 |
-
* @param null $timestamp
|
379 |
-
* @param int $priority
|
380 |
-
* @param bool $clear
|
381 |
-
* @param bool $ignore_status
|
382 |
-
* @param bool $reset
|
383 |
-
* @param bool $options
|
384 |
-
* @param bool $tags
|
385 |
-
*
|
386 |
-
* @return bool|void
|
387 |
-
*
|
388 |
-
* @since 4.2.1
|
389 |
-
*/
|
390 |
-
public function bulk_add( $campaign_id, $subscribers, $timestamp = null, $priority = 10, $clear = false, $ignore_status = false, $reset = false, $options = false, $tags = false ) {
|
391 |
-
|
392 |
-
global $wpdb;
|
393 |
-
|
394 |
-
if ( $clear ) {
|
395 |
-
$this->clear( $campaign_id, $subscribers );
|
396 |
-
}
|
397 |
-
|
398 |
-
if ( empty( $subscribers ) ) {
|
399 |
-
return;
|
400 |
-
}
|
401 |
-
|
402 |
-
if ( is_null( $timestamp ) ) {
|
403 |
-
$timestamp = time();
|
404 |
-
}
|
405 |
-
|
406 |
-
$timestamps = ! is_array( $timestamp )
|
407 |
-
? array_fill( 0, count( $subscribers ), $timestamp )
|
408 |
-
: $timestamp;
|
409 |
-
|
410 |
-
$now = time();
|
411 |
-
|
412 |
-
$campaign_id = (int) $campaign_id;
|
413 |
-
$subscribers = array_filter( $subscribers, 'is_numeric' );
|
414 |
-
|
415 |
-
if ( $tags ) {
|
416 |
-
$tags = maybe_serialize( $tags );
|
417 |
-
}
|
418 |
-
if ( $options ) {
|
419 |
-
$options = maybe_serialize( $options );
|
420 |
-
}
|
421 |
-
|
422 |
-
if ( empty( $subscribers ) ) {
|
423 |
-
return true;
|
424 |
-
}
|
425 |
-
|
426 |
-
$inserts = array();
|
427 |
-
|
428 |
-
foreach ( $subscribers as $i => $subscriber_id ) {
|
429 |
-
$inserts[] = "($subscriber_id,$campaign_id,$now," . $timestamps[ $i ] . ",$priority,1,'$ignore_status','$options','$tags')";
|
430 |
-
}
|
431 |
-
|
432 |
-
$chunks = array_chunk( $inserts, 1000 );
|
433 |
-
|
434 |
-
$success = true;
|
435 |
-
|
436 |
-
foreach ( $chunks as $insert ) {
|
437 |
-
|
438 |
-
$sql = "INSERT INTO {$wpdb->prefix}ig_queue (contact_id, campaign_id, added, timestamp, priority, count, ignore_status, options, tags) VALUES";
|
439 |
-
|
440 |
-
$sql .= ' ' . implode( ',', $insert );
|
441 |
-
|
442 |
-
$sql .= ' ON DUPLICATE KEY UPDATE timestamp = values(timestamp), ignore_status = values(ignore_status)';
|
443 |
-
if ( $reset ) {
|
444 |
-
$sql .= ', sent = 0';
|
445 |
-
}
|
446 |
-
if ( $options ) {
|
447 |
-
$sql .= sprintf( ", options = '%s'", $options );
|
448 |
-
}
|
449 |
-
if ( $tags ) {
|
450 |
-
$sql .= sprintf( ", tags = '%s'", $tags );
|
451 |
-
}
|
452 |
-
|
453 |
-
//ES()->logger->info( 'Adding Bulk SQL: ' . $sql );
|
454 |
-
|
455 |
-
$success = $success && false !== $wpdb->query( $sql );
|
456 |
-
|
457 |
-
}
|
458 |
-
|
459 |
-
return $success;
|
460 |
-
|
461 |
-
}
|
462 |
-
|
463 |
-
/**
|
464 |
-
* Clear queue which are not assigned to any campaign
|
465 |
-
*
|
466 |
-
* @param null $campaign_id
|
467 |
-
* @param array $subscribers
|
468 |
-
*
|
469 |
-
* @return bool
|
470 |
-
*
|
471 |
-
* @since 4.2.1
|
472 |
-
*/
|
473 |
-
public function clear( $campaign_id = null, $subscribers = array() ) {
|
474 |
-
|
475 |
-
global $wpdb;
|
476 |
-
|
477 |
-
$campaign_id = (int) $campaign_id;
|
478 |
-
$subscribers = array_filter( $subscribers, 'is_numeric' );
|
479 |
-
|
480 |
-
if ( empty( $subscribers ) ) {
|
481 |
-
$subscribers = array( - 1 );
|
482 |
-
}
|
483 |
-
|
484 |
-
$sql = "DELETE queue FROM {$wpdb->prefix}ig_queue AS queue WHERE queue.sent = 0 AND queue.contact_id NOT IN (" . implode( ',', $subscribers ) . ')';
|
485 |
-
if ( ! is_null( $campaign_id ) ) {
|
486 |
-
$sql .= $wpdb->prepare( ' AND queue.campaign_id = %d', $campaign_id );
|
487 |
-
}
|
488 |
-
|
489 |
-
return false !== $wpdb->query( $sql );
|
490 |
-
|
491 |
-
}
|
492 |
-
|
493 |
-
/**
|
494 |
-
* Process Queue
|
495 |
-
*
|
496 |
-
* @since 4.2.1
|
497 |
-
*/
|
498 |
-
public function process_queue() {
|
499 |
-
global $wpdb;
|
500 |
-
|
501 |
-
$micro_time = microtime( true );
|
502 |
-
|
503 |
-
$ig_queue_table = IG_QUEUE_TABLE;
|
504 |
-
$ig_campaigns_table = IG_CAMPAIGNS_TABLE;
|
505 |
-
|
506 |
-
$sql = 'SELECT queue.campaign_id, queue.contact_id, queue.count AS _count, queue.requeued AS _requeued, queue.options AS _options, queue.tags AS _tags, queue.priority AS _priority';
|
507 |
-
$sql .= " FROM $ig_queue_table AS queue";
|
508 |
-
$sql .= " LEFT JOIN $ig_campaigns_table AS campaigns ON campaigns.id = queue.campaign_id";
|
509 |
-
$sql .= ' WHERE queue.timestamp <= ' . (int) $micro_time . " AND queue.sent_at = 0";
|
510 |
-
$sql .= " AND (campaigns.status = 1)";
|
511 |
-
$sql .= ' ORDER BY queue.priority DESC';
|
512 |
-
|
513 |
-
//ES()->logger->info( 'Process Queue:' );
|
514 |
-
//ES()->logger->info( 'SQL: ' . $sql );
|
515 |
-
|
516 |
-
$notifications = $wpdb->get_results( $sql, ARRAY_A );
|
517 |
-
|
518 |
-
if ( is_array( $notifications ) && count( $notifications ) > 0 ) {
|
519 |
-
$campaigns_notifications = $contact_ids = array();
|
520 |
-
foreach ( $notifications as $notification ) {
|
521 |
-
$campaigns_notifications[ $notification['campaign_id'] ][] = $notification;
|
522 |
-
|
523 |
-
$contact_ids[] = $notification['contact_id'];
|
524 |
-
}
|
525 |
-
|
526 |
-
// We need unique ids
|
527 |
-
$contact_ids = array_unique( $contact_ids );
|
528 |
-
|
529 |
-
$contacts = ES()->contacts_db->get_details_by_ids( $contact_ids );
|
530 |
-
|
531 |
-
foreach ( $campaigns_notifications as $campaign_id => $notifications ) {
|
532 |
-
|
533 |
-
$campaign = ES()->campaigns_db->get( $campaign_id );
|
534 |
-
|
535 |
-
if ( ! empty( $campaign ) ) {
|
536 |
-
|
537 |
-
$content = $campaign['body'];
|
538 |
-
$subject = $campaign['subject'];
|
539 |
-
|
540 |
-
foreach ( $notifications as $notification ) {
|
541 |
-
|
542 |
-
$contact_id = $notification['contact_id'];
|
543 |
-
|
544 |
-
if ( ! empty( $contacts[ $contact_id ] ) ) {
|
545 |
-
|
546 |
-
$first_name = $contacts[ $contact_id ]['first_name'];
|
547 |
-
$last_name = $contacts[ $contact_id ]['last_name'];
|
548 |
-
$hash = $contacts[ $contact_id ]['hash'];
|
549 |
-
$email = $contacts[ $contact_id ]['email'];
|
550 |
-
$name = ES_Common::prepare_name_from_first_name_last_name( $first_name, $last_name );
|
551 |
-
|
552 |
-
$keywords = array(
|
553 |
-
'name' => $name,
|
554 |
-
'first_name' => $first_name,
|
555 |
-
'last_name' => $last_name,
|
556 |
-
'email' => $email,
|
557 |
-
'guid' => $hash,
|
558 |
-
'dbid' => $contact_id,
|
559 |
-
'message_id' => 0,
|
560 |
-
'campaign_id' => $campaign_id
|
561 |
-
);
|
562 |
-
|
563 |
-
// Preparing email body
|
564 |
-
$body = ES_Mailer::prepare_email_template( $content, $keywords );
|
565 |
-
|
566 |
-
$result = ES_Mailer::send( $email, $subject, $body );
|
567 |
-
|
568 |
-
do_action( 'ig_es_message_sent', $contact_id, $campaign_id, 0 );
|
569 |
-
|
570 |
-
// Email Sent now delete from queue now.
|
571 |
-
$this->db->delete_from_queue( $campaign_id, $contact_id );
|
572 |
-
}
|
573 |
-
}
|
574 |
-
}
|
575 |
-
|
576 |
-
}
|
577 |
-
|
578 |
-
}
|
579 |
-
|
580 |
-
|
581 |
-
}
|
582 |
-
|
583 |
-
/**
|
584 |
-
* Process Campaigns and send notifications
|
585 |
-
*
|
586 |
-
* @since 4.3.1
|
587 |
-
*/
|
588 |
-
public function process_campaigns() {
|
589 |
-
/**
|
590 |
-
* - Get GUID from ig_es_mailing_queue table which are in queue
|
591 |
-
* - Get contacts from the ig_es_sending_queue table based on fetched guid
|
592 |
-
* - Prepare email content
|
593 |
-
* - Send emails based on fetched contacts
|
594 |
-
* - Update status in ig_es_mailing_queue table
|
595 |
-
* - Update status in ig_es_sending_queue table
|
596 |
-
*/
|
597 |
-
$es_c_croncount = ES_Common::total_emails_to_be_sent();
|
598 |
-
|
599 |
-
if ( $es_c_croncount > 0 ) {
|
600 |
-
|
601 |
-
// Get GUID from sentdetails report which are in queue
|
602 |
-
$campaign_hash = ig_es_get_request_data( 'campaign_hash' );
|
603 |
-
|
604 |
-
$notification = ES_DB_Mailing_Queue::get_notification_to_be_sent( $campaign_hash );
|
605 |
-
$notification_guid = isset( $notification['hash'] ) ? $notification['hash'] : null;
|
606 |
-
|
607 |
-
if ( ! is_null( $notification_guid ) ) {
|
608 |
-
ES_DB_Mailing_Queue::update_sent_status( $notification_guid, 'Sending' );
|
609 |
-
|
610 |
-
// Get subscribers from the sending_queue table based on fetched guid
|
611 |
-
$emails = ES_DB_Sending_Queue::get_emails_to_be_sent_by_hash( $notification_guid, $es_c_croncount );
|
612 |
-
$total_emails = count( $emails );
|
613 |
-
// Found Subscribers to send notification?
|
614 |
-
if ( $total_emails > 0 ) {
|
615 |
-
$ids = array();
|
616 |
-
foreach ( $emails as $email ) {
|
617 |
-
$ids[] = $email['id'];
|
618 |
-
}
|
619 |
-
|
620 |
-
$updated = ES_DB_Sending_Queue::update_sent_status( $ids, 'Sending' );
|
621 |
-
|
622 |
-
// Send out emails
|
623 |
-
if ( $updated ) {
|
624 |
-
ES_Mailer::prepare_and_send_email( $emails, $notification );
|
625 |
-
ES_DB_Sending_Queue::update_sent_status( $ids, 'Sent' );
|
626 |
-
}
|
627 |
-
|
628 |
-
$total_remaining_emails = ES_DB_Sending_Queue::get_total_emails_to_be_sent_by_hash( $notification_guid );
|
629 |
-
$remaining_emails_to_be_sent = ES_DB_Sending_Queue::get_total_emails_to_be_sent();
|
630 |
-
|
631 |
-
// No emails left for the $notification_guid??? Send admin notification for the
|
632 |
-
// Completion of a job
|
633 |
-
if ( $total_remaining_emails == 0 ) {
|
634 |
-
ES_DB_Mailing_Queue::update_sent_status( $notification_guid, 'Sent' );
|
635 |
-
|
636 |
-
$notify_admin = get_option( 'ig_es_enable_cron_admin_email', 'yes' );
|
637 |
-
|
638 |
-
if ( 'yes' === $notify_admin ) {
|
639 |
-
|
640 |
-
$admin_email_addresses = get_option( 'ig_es_admin_emails' );
|
641 |
-
if ( ! empty( $admin_email_addresses ) ) {
|
642 |
-
$template = ES_Mailer::prepare_es_cron_admin_email( $notification_guid );
|
643 |
-
|
644 |
-
if ( ! empty( $template ) ) {
|
645 |
-
$subject = get_option( 'ig_es_cron_admin_email_subject', __( 'Campaign Sent!', 'email-subscribers' ) );
|
646 |
-
$notification = ES_DB_Mailing_Queue::get_notification_by_hash( $notification_guid );
|
647 |
-
if ( isset( $notification['subject'] ) ) {
|
648 |
-
$subject = str_replace( '{{SUBJECT}}', $notification['subject'], $subject );
|
649 |
-
}
|
650 |
-
|
651 |
-
$admin_emails = explode( ',', $admin_email_addresses );
|
652 |
-
foreach ( $admin_emails as $admin_email ) {
|
653 |
-
$admin_email = trim( $admin_email );
|
654 |
-
ES_Mailer::send( $admin_email, $subject, $template );
|
655 |
-
}
|
656 |
-
}
|
657 |
-
}
|
658 |
-
}
|
659 |
-
}
|
660 |
-
|
661 |
-
//TODO: Implement better solution
|
662 |
-
set_transient('ig_es_total_emails_sent', $total_emails, MINUTE_IN_SECONDS);
|
663 |
-
set_transient('ig_es_remaining_email_count', $remaining_emails_to_be_sent, MINUTE_IN_SECONDS);
|
664 |
-
|
665 |
-
$response['total_emails_sent'] = $total_emails;
|
666 |
-
$response['es_remaining_email_count'] = $remaining_emails_to_be_sent;
|
667 |
-
$response['message'] = 'EMAILS_SENT';
|
668 |
-
$response['status'] = 'SUCCESS';
|
669 |
-
// update last cron run time
|
670 |
-
update_option( 'ig_es_last_cron_run', time() );
|
671 |
-
} else {
|
672 |
-
$response['es_remaining_email_count'] = 0;
|
673 |
-
$response['message'] = 'EMAILS_NOT_FOUND';
|
674 |
-
$response['status'] = 'SUCCESS';
|
675 |
-
ES_DB_Mailing_Queue::update_sent_status( $notification_guid, 'Sent' );
|
676 |
-
}
|
677 |
-
} else {
|
678 |
-
$response['es_remaining_email_count'] = 0;
|
679 |
-
$response['message'] = 'NOTIFICATION_NOT_FOUND';
|
680 |
-
$response['status'] = 'SUCCESS';
|
681 |
-
}
|
682 |
-
} else {
|
683 |
-
$self = false;
|
684 |
-
$response['status'] = 'ERROR';
|
685 |
-
$response['message'] = 'EMAIL_SENDING_LIMIT_EXCEEDED';
|
686 |
-
}
|
687 |
-
}
|
688 |
-
|
689 |
-
}
|
690 |
-
}
|
691 |
-
|
692 |
-
|
693 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-reports-table.php
DELETED
@@ -1,525 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
if ( ! class_exists( 'WP_List_Table' ) ) {
|
9 |
-
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
10 |
-
}
|
11 |
-
|
12 |
-
class ES_Reports_Table extends WP_List_Table {
|
13 |
-
|
14 |
-
static $instance;
|
15 |
-
|
16 |
-
public function __construct() {
|
17 |
-
|
18 |
-
parent::__construct( array(
|
19 |
-
'singular' => __( 'Report', 'email-subscribers' ), //singular name of the listed records
|
20 |
-
'plural' => __( 'Reports', 'email-subscribers' ), //plural name of the listed records
|
21 |
-
'ajax' => false, //does this table support ajax?,
|
22 |
-
'screen' => 'es_reports'
|
23 |
-
) );
|
24 |
-
|
25 |
-
//add_filter( 'set-screen-option', array( $this, 'set_screen' ), 10, 3 );
|
26 |
-
}
|
27 |
-
|
28 |
-
|
29 |
-
public static function set_screen( $status, $option, $value ) {
|
30 |
-
return $value;
|
31 |
-
}
|
32 |
-
|
33 |
-
public function es_reports_callback() {
|
34 |
-
|
35 |
-
$action = ig_es_get_request_data( 'action' );
|
36 |
-
if ( 'view' === $action ) {
|
37 |
-
$list = ig_es_get_request_data( 'list' );
|
38 |
-
$this->view_list( $list );
|
39 |
-
} else {
|
40 |
-
?>
|
41 |
-
|
42 |
-
<div class="wrap">
|
43 |
-
<h1 class="wp-heading-inline"><?php _e( 'Reports', 'email-subscribers' ); ?></h1>
|
44 |
-
<?php
|
45 |
-
$emails_to_be_sent = ES_DB_Sending_Queue::get_total_emails_to_be_sent();
|
46 |
-
if ( $emails_to_be_sent > 0 ) {
|
47 |
-
$cron_url = ES()->cron->url( true );
|
48 |
-
$content = sprintf( __( "<a href='%s' target='_blank' class='page-title-action es-imp-button'>Send Queued Emails Now</a>", 'email-subscribers' ), $cron_url );
|
49 |
-
} else {
|
50 |
-
$content = sprintf( __( "<span class='page-title-action button-disabled'>Send Queued Emails Now</span>", 'email-subscribers' ) );
|
51 |
-
$content .= sprintf( __( "<br /><span class='es-helper'>No emails found in queue</span>", 'email-subscribers' ) );
|
52 |
-
}
|
53 |
-
?>
|
54 |
-
|
55 |
-
<span class="ig-es-process-queue"><?php echo $content; ?></span>
|
56 |
-
|
57 |
-
|
58 |
-
<div id="poststuff">
|
59 |
-
<div id="post-body" class="metabox-holder column-1">
|
60 |
-
<div id="post-body-content">
|
61 |
-
<div class="meta-box-sortables ui-sortable">
|
62 |
-
<form method="post">
|
63 |
-
<?php
|
64 |
-
$this->prepare_items();
|
65 |
-
$this->display(); ?>
|
66 |
-
</form>
|
67 |
-
</div>
|
68 |
-
</div>
|
69 |
-
</div>
|
70 |
-
<br class="clear">
|
71 |
-
</div>
|
72 |
-
</div>
|
73 |
-
|
74 |
-
<?php
|
75 |
-
}
|
76 |
-
}
|
77 |
-
|
78 |
-
public function screen_option() {
|
79 |
-
|
80 |
-
$option = 'per_page';
|
81 |
-
$args = array(
|
82 |
-
'label' => __( 'Reports', 'email-subscribers' ),
|
83 |
-
'default' => 10,
|
84 |
-
'option' => 'reports_per_page'
|
85 |
-
);
|
86 |
-
|
87 |
-
add_screen_option( $option, $args );
|
88 |
-
|
89 |
-
}
|
90 |
-
|
91 |
-
public function prepare_header_footer_row() {
|
92 |
-
|
93 |
-
?>
|
94 |
-
|
95 |
-
<tr>
|
96 |
-
<th width="6%" scope="col"><?php _e( 'Sr No', 'email-subscribers' ); ?></th>
|
97 |
-
<th scope="col"><?php _e( 'Email', 'email-subscribers' ); ?></th>
|
98 |
-
<th scope="col"><?php _e( 'Status', 'email-subscribers' ); ?></th>
|
99 |
-
<th scope="col"><?php _e( 'Sent Date', 'email-subscribers' ); ?></th>
|
100 |
-
<th scope="col"><?php _e( 'Viewed Status', 'email-subscribers' ); ?></th>
|
101 |
-
<th scope="col"><?php _e( 'Viewed Date', 'email-subscribers' ); ?></th>
|
102 |
-
</tr>
|
103 |
-
|
104 |
-
<?php
|
105 |
-
}
|
106 |
-
|
107 |
-
public function view_list( $id ) {
|
108 |
-
global $wpdb;
|
109 |
-
|
110 |
-
$emails = ES_DB_Sending_Queue::get_emails_by_hash( $id );
|
111 |
-
$email_viewed_count = ES_DB_Sending_Queue::get_viewed_count_by_hash( $id );
|
112 |
-
$total_email_sent = ES_DB_Sending_Queue::get_total_email_count_by_hash( $id );
|
113 |
-
|
114 |
-
?>
|
115 |
-
<div class="wrap">
|
116 |
-
<div class="tool-box">
|
117 |
-
<div class="tablenav">
|
118 |
-
<div class="alignleft" style="padding-bottom:10px;"><?php echo 'Viewed ' . $email_viewed_count . '/' . $total_email_sent; ?></div>
|
119 |
-
</div>
|
120 |
-
<form name="frm_es_display" method="post">
|
121 |
-
<table width="100%" class="widefat" id="straymanage">
|
122 |
-
<thead>
|
123 |
-
<?php echo $this->prepare_header_footer_row(); ?>
|
124 |
-
</thead>
|
125 |
-
<tbody>
|
126 |
-
<?php echo $this->prepare_body( $emails ); ?>
|
127 |
-
</tbody>
|
128 |
-
<tfoot>
|
129 |
-
<?php echo $this->prepare_header_footer_row(); ?>
|
130 |
-
</tfoot>
|
131 |
-
</table>
|
132 |
-
</form>
|
133 |
-
</div>
|
134 |
-
</div>
|
135 |
-
|
136 |
-
<?php
|
137 |
-
|
138 |
-
//$wpdb->update( EMAIL_SUBSCRIBERS_STATS_TABLE, array( 'viewdate' => date( 'Y-m-d H:i:s' ) ), array( 'viewdate' => $id ) );
|
139 |
-
|
140 |
-
}
|
141 |
-
|
142 |
-
|
143 |
-
public function prepare_body( $emails ) {
|
144 |
-
|
145 |
-
$i = 1;
|
146 |
-
foreach ( $emails as $key => $email ) {
|
147 |
-
$class = '';
|
148 |
-
if ( $i % 2 === 0 ) {
|
149 |
-
$class = 'alternate';
|
150 |
-
}
|
151 |
-
|
152 |
-
$email_id = ! empty( $email['email'] ) ? $email['email'] : ( ! empty( $email['es_deliver_emailmail'] ) ? $email['es_deliver_emailmail'] : '' );
|
153 |
-
$status = ! empty( $email['status'] ) ? $email['status'] : ( ! empty( $email['es_deliver_sentstatus'] ) ? $email['es_deliver_sentstatus'] : '' );
|
154 |
-
$sent_at = ! empty( $email['sent_at'] ) ? $email['sent_at'] : ( ! empty( $email['es_deliver_sentdate'] ) ? $email['es_deliver_sentdate'] : '' );
|
155 |
-
$opened = ! empty( $email['opened'] ) ? $email['opened'] : ( ! empty( $email['es_deliver_status'] ) && $email['es_deliver_status'] === 'Viewed' ? 1 : 0 );
|
156 |
-
$opened_at = ! empty( $email['opened_at'] ) ? $email['opened_at'] : ( ! empty( $email['es_deliver_viewdate'] ) ? $email['es_deliver_viewdate'] : '' );
|
157 |
-
|
158 |
-
?>
|
159 |
-
|
160 |
-
<tr class="<?php echo $class; ?>">
|
161 |
-
<td align="left"><?php echo $i; ?></td>
|
162 |
-
<td><?php echo $email_id; ?></td>
|
163 |
-
<td><span style="color:#03a025;font-weight:bold;"><?php echo $status; ?></span></td>
|
164 |
-
<td><?php echo ig_es_format_date_time( $sent_at ); ?></td>
|
165 |
-
<td><span><?php echo ( ! empty( $opened ) && $opened == 1 ) ? _e( 'Viewed', 'email-subscribers' ) : '<i title="' . __( 'Not yet viewed', 'email-subscribers' ) . '" class="dashicons dashicons-es dashicons-minus">' ?></span></td>
|
166 |
-
<td><?php echo ig_es_format_date_time( $opened_at ); ?></td>
|
167 |
-
</tr>
|
168 |
-
|
169 |
-
<?php
|
170 |
-
$i ++;
|
171 |
-
}
|
172 |
-
|
173 |
-
}
|
174 |
-
|
175 |
-
|
176 |
-
/** Text displayed when no list data is available */
|
177 |
-
public function no_items() {
|
178 |
-
_e( 'No Reports avaliable.', 'email-subscribers' );
|
179 |
-
}
|
180 |
-
|
181 |
-
/**
|
182 |
-
* Render a column when no column specific method exist.
|
183 |
-
*
|
184 |
-
* @param array $item
|
185 |
-
* @param string $column_name
|
186 |
-
*
|
187 |
-
* @return mixed
|
188 |
-
*/
|
189 |
-
public function column_default( $item, $column_name ) {
|
190 |
-
global $wpdb;
|
191 |
-
|
192 |
-
switch ( $column_name ) {
|
193 |
-
case 'start_at':
|
194 |
-
case 'finish_at':
|
195 |
-
return ig_es_format_date_time( $item[ $column_name ] );
|
196 |
-
case 'type':
|
197 |
-
if ( empty( $item['campaign_id'] ) ) {
|
198 |
-
$type = __( 'Post Notification', 'email-subscribers' );
|
199 |
-
} else {
|
200 |
-
$type = ES()->campaigns_db->get_campaign_type_by_id( $item['campaign_id'] );
|
201 |
-
$type = strtolower( $type );
|
202 |
-
$type = ( 'newsletter' === $type ) ? __( 'Broadcast', 'email-subscribers' ) : $type;
|
203 |
-
}
|
204 |
-
|
205 |
-
$type = ucwords( str_replace( '_', ' ', $type ) );
|
206 |
-
|
207 |
-
return $type;
|
208 |
-
case 'subject':
|
209 |
-
// case 'type':
|
210 |
-
// return ucwords($item[ $column_name ]);
|
211 |
-
case 'count':
|
212 |
-
return $item[ $column_name ];
|
213 |
-
default:
|
214 |
-
return print_r( $item, true ); //Show the whole array for troubleshooting purposes
|
215 |
-
}
|
216 |
-
}
|
217 |
-
|
218 |
-
function column_status( $item ) {
|
219 |
-
if ( $item['status'] == 'Sent' ) {
|
220 |
-
return __( 'Completed', 'email-subscribers' );
|
221 |
-
} else {
|
222 |
-
|
223 |
-
$actions = array(
|
224 |
-
'send_now' => $this->prepare_send_now_url( $item )
|
225 |
-
);
|
226 |
-
|
227 |
-
return $item['status'] . $this->row_actions( $actions, true );
|
228 |
-
}
|
229 |
-
}
|
230 |
-
|
231 |
-
/**
|
232 |
-
* Render the bulk edit checkbox
|
233 |
-
*
|
234 |
-
* @param array $item
|
235 |
-
*
|
236 |
-
* @return string
|
237 |
-
*/
|
238 |
-
function column_cb( $item ) {
|
239 |
-
return sprintf(
|
240 |
-
'<input type="checkbox" name="bulk_delete[]" value="%s" />', $item['id']
|
241 |
-
);
|
242 |
-
}
|
243 |
-
|
244 |
-
|
245 |
-
/**
|
246 |
-
* Method for name column
|
247 |
-
*
|
248 |
-
* @param array $item an array of DB data
|
249 |
-
*
|
250 |
-
* @return string
|
251 |
-
*/
|
252 |
-
function column_subject( $item ) {
|
253 |
-
|
254 |
-
$es_nonce = wp_create_nonce( 'es_notification' );
|
255 |
-
$page = ig_es_get_request_data( 'page' );
|
256 |
-
|
257 |
-
$title = '<strong>' . $item['subject'] . '</strong>';
|
258 |
-
|
259 |
-
$actions = array(
|
260 |
-
'view' => sprintf( '<a href="?page=%s&action=%s&list=%s&_wpnonce=%s">%s</a>', esc_attr( $page ), 'view', $item['hash'], $es_nonce, __( 'View', 'email-subscribers' ) ),
|
261 |
-
'delete' => sprintf( '<a href="?page=%s&action=%s&list=%s&_wpnonce=%s">%s</a>', esc_attr( $page ), 'delete', absint( $item['id'] ), $es_nonce, __( 'Delete', 'email-subscribers' ) ),
|
262 |
-
'preview_email' => sprintf( '<a target="_blank" href="?page=%s&action=%s&list=%s&_wpnonce=%s">%s</a>', esc_attr( $page ), 'preview', absint( $item['id'] ), $es_nonce, __( 'Preview', 'email-subscribers' ) )
|
263 |
-
);
|
264 |
-
|
265 |
-
return $title . $this->row_actions( $actions );
|
266 |
-
}
|
267 |
-
|
268 |
-
|
269 |
-
/**
|
270 |
-
* Associative array of columns
|
271 |
-
*
|
272 |
-
* @return array
|
273 |
-
*/
|
274 |
-
function get_columns() {
|
275 |
-
$columns = array(
|
276 |
-
'cb' => '<input type="checkbox" />',
|
277 |
-
'subject' => __( 'Subject', 'email-subscribers' ),
|
278 |
-
'type' => __( 'Type', 'email-subscribers' ),
|
279 |
-
'status' => __( 'Status', 'email-subscribers' ),
|
280 |
-
'start_at' => __( 'Start Date', 'email-subscribers' ),
|
281 |
-
'finish_at' => __( 'End Date', 'email-subscribers' ),
|
282 |
-
'count' => __( 'Total Contacts', 'email-subscribers' ),
|
283 |
-
);
|
284 |
-
|
285 |
-
return $columns;
|
286 |
-
}
|
287 |
-
|
288 |
-
function column_count( $item ) {
|
289 |
-
|
290 |
-
$campaign_hash = $item['hash'];
|
291 |
-
|
292 |
-
$total_emails_sent = $total_emails_to_be_sent = $item['count'];
|
293 |
-
// if ( ! empty( $campaign_hash ) ) {
|
294 |
-
// $total_emails_sent = ES_DB_Sending_Queue::get_total_emails_sent_by_hash( $campaign_hash );
|
295 |
-
// }
|
296 |
-
|
297 |
-
// $content = $total_emails_sent . "/" . $total_emails_to_be_sent;
|
298 |
-
|
299 |
-
return $total_emails_to_be_sent;
|
300 |
-
|
301 |
-
}
|
302 |
-
|
303 |
-
function prepare_send_now_url( $item ) {
|
304 |
-
$campaign_hash = $item['hash'];
|
305 |
-
|
306 |
-
$cron_url = '';
|
307 |
-
if ( ! empty( $campaign_hash ) ) {
|
308 |
-
$cron_url = ES()->cron->url( true, false, $campaign_hash );
|
309 |
-
}
|
310 |
-
|
311 |
-
|
312 |
-
$content = '';
|
313 |
-
if ( ! empty( $cron_url ) ) {
|
314 |
-
$content = __( sprintf( "<a href='%s' target='_blank'>Send</a>", $cron_url ), 'email-subscribers' );
|
315 |
-
}
|
316 |
-
|
317 |
-
return $content;
|
318 |
-
}
|
319 |
-
|
320 |
-
/**
|
321 |
-
* Columns to make sortable.
|
322 |
-
*
|
323 |
-
* @return array
|
324 |
-
*/
|
325 |
-
public function get_sortable_columns() {
|
326 |
-
$sortable_columns = array(
|
327 |
-
'subject' => array( 'subject', true ),
|
328 |
-
'status' => array( 'status', true ),
|
329 |
-
'start_at' => array( 'start_at', true ),
|
330 |
-
'finish_at' => array( 'finish_at', true ),
|
331 |
-
'count' => array( 'count', true )
|
332 |
-
);
|
333 |
-
|
334 |
-
return $sortable_columns;
|
335 |
-
}
|
336 |
-
|
337 |
-
/**
|
338 |
-
* Returns an associative array containing the bulk action
|
339 |
-
*
|
340 |
-
* @return array
|
341 |
-
*/
|
342 |
-
public function get_bulk_actions() {
|
343 |
-
$actions = array(
|
344 |
-
'bulk_delete' => __( 'Delete', 'email-subscribers' )
|
345 |
-
);
|
346 |
-
|
347 |
-
return $actions;
|
348 |
-
}
|
349 |
-
|
350 |
-
|
351 |
-
/**
|
352 |
-
* Handles data query and filter, sorting, and pagination.
|
353 |
-
*/
|
354 |
-
public function prepare_items() {
|
355 |
-
|
356 |
-
$this->_column_headers = $this->get_column_info();
|
357 |
-
|
358 |
-
/** Process bulk action */
|
359 |
-
$this->process_bulk_action();
|
360 |
-
|
361 |
-
$per_page = $this->get_items_per_page( 'reports_per_page', 20 );
|
362 |
-
$current_page = $this->get_pagenum();
|
363 |
-
$total_items = $this->get_notifications( 0, 0, true );
|
364 |
-
|
365 |
-
$this->set_pagination_args( array(
|
366 |
-
'total_items' => $total_items, //WE have to calculate the total number of items
|
367 |
-
'per_page' => $per_page //WE have to determine how many items to show on a page
|
368 |
-
) );
|
369 |
-
|
370 |
-
$this->items = $this->get_notifications( $per_page, $current_page, false );
|
371 |
-
}
|
372 |
-
|
373 |
-
public function get_notifications( $per_page = 5, $page_number = 1, $do_count_only = false ) {
|
374 |
-
global $wpdb;
|
375 |
-
|
376 |
-
$order_by = sanitize_sql_orderby( ig_es_get_request_data( 'orderby' ) );
|
377 |
-
$order = ig_es_get_request_data( 'order' );
|
378 |
-
|
379 |
-
$ig_mailing_queue_table = IG_MAILING_QUEUE_TABLE;
|
380 |
-
|
381 |
-
if ( $do_count_only ) {
|
382 |
-
$sql = "SELECT count(*) as total FROM {$ig_mailing_queue_table}";
|
383 |
-
} else {
|
384 |
-
$sql = "SELECT * FROM {$ig_mailing_queue_table}";
|
385 |
-
}
|
386 |
-
|
387 |
-
if ( ! $do_count_only ) {
|
388 |
-
|
389 |
-
// Prepare Order by clause
|
390 |
-
$order = ! empty( $order ) ? strtolower( $order ) : 'desc';
|
391 |
-
|
392 |
-
$expected_order_values = array( 'asc', 'desc' );
|
393 |
-
if ( ! in_array( $order, $expected_order_values ) ) {
|
394 |
-
$order = 'desc';
|
395 |
-
}
|
396 |
-
|
397 |
-
$default_order_by = esc_sql( 'created_at' );
|
398 |
-
|
399 |
-
$expected_order_by_values = array( 'subject', 'type', 'status', 'start_at', 'count', 'created_at' );
|
400 |
-
|
401 |
-
if ( ! in_array( $order_by, $expected_order_by_values ) ) {
|
402 |
-
$order_by_clause = " ORDER BY {$default_order_by} DESC";
|
403 |
-
} else {
|
404 |
-
$order_by = esc_sql( $order_by );
|
405 |
-
$order_by_clause = " ORDER BY {$order_by} {$order}, {$default_order_by} DESC";
|
406 |
-
}
|
407 |
-
|
408 |
-
$sql .= $order_by_clause;
|
409 |
-
$sql .= " LIMIT $per_page";
|
410 |
-
$sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page;
|
411 |
-
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
|
412 |
-
|
413 |
-
} else {
|
414 |
-
$result = $wpdb->get_var( $sql );
|
415 |
-
}
|
416 |
-
|
417 |
-
return $result;
|
418 |
-
}
|
419 |
-
|
420 |
-
public function process_bulk_action() {
|
421 |
-
|
422 |
-
//Detect when a bulk action is being triggered...
|
423 |
-
if ( 'view' === $this->current_action() ) {
|
424 |
-
|
425 |
-
// In our file that handles the request, verify the nonce.
|
426 |
-
$nonce = ig_es_get_request_data( '_wpnonce' );
|
427 |
-
|
428 |
-
if ( ! wp_verify_nonce( $nonce, 'es_notification' ) ) {
|
429 |
-
$message = __( 'You do not have permission to view notification', 'email-subscribers' );
|
430 |
-
ES_Common::show_message( $message, 'error' );
|
431 |
-
} else {
|
432 |
-
$this->view_list( ig_es_get_request_data( 'list' ) );
|
433 |
-
}
|
434 |
-
|
435 |
-
} elseif ( 'delete' === $this->current_action() ) {
|
436 |
-
|
437 |
-
// In our file that handles the request, verify the nonce.
|
438 |
-
$nonce = ig_es_get_request_data( '_wpnonce' );
|
439 |
-
|
440 |
-
if ( ! wp_verify_nonce( $nonce, 'es_notification' ) ) {
|
441 |
-
$message = __( 'You do not have permission to delete notification', 'email-subscribers' );
|
442 |
-
ES_Common::show_message( $message, 'error' );
|
443 |
-
} else {
|
444 |
-
$notification_ids = absint( ig_es_get_request_data( 'list' ) );
|
445 |
-
ES_DB_Mailing_Queue::delete_notifications( array( $notification_ids ) );
|
446 |
-
ES_DB_Sending_Queue::delete_sending_queue_by_mailing_id( array( $notification_ids ) );
|
447 |
-
$message = __( 'Report has been deleted successfully!', 'email-subscribers' );
|
448 |
-
ES_Common::show_message( $message, 'success' );
|
449 |
-
}
|
450 |
-
|
451 |
-
} elseif ( 'preview' === $this->current_action() ) {
|
452 |
-
// In our file that handles the request, verify the nonce.
|
453 |
-
$nonce = ig_es_get_request_data( '_wpnonce' );
|
454 |
-
|
455 |
-
if ( ! wp_verify_nonce( $nonce, 'es_notification' ) ) {
|
456 |
-
$message = __( 'You do not have permission to preview notification', 'email-subscribers' );
|
457 |
-
ES_Common::show_message( $message, 'error' );
|
458 |
-
} else {
|
459 |
-
$report_id = ig_es_get_request_data( 'list' );
|
460 |
-
echo $this->preview_email( $report_id );
|
461 |
-
die();
|
462 |
-
}
|
463 |
-
}
|
464 |
-
|
465 |
-
$action = ig_es_get_request_data( 'action' );
|
466 |
-
$action2 = ig_es_get_request_data( 'action2' );
|
467 |
-
// If the delete bulk action is triggered
|
468 |
-
if ( ( 'bulk_delete' === $action ) || ( 'bulk_delete' === $action2 ) ) {
|
469 |
-
$notification_ids = ig_es_get_request_data( 'bulk_delete' );
|
470 |
-
|
471 |
-
if ( count( $notification_ids ) > 0 ) {
|
472 |
-
ES_DB_Mailing_Queue::delete_notifications( $notification_ids );
|
473 |
-
ES_DB_Sending_Queue::delete_sending_queue_by_mailing_id( $notification_ids );
|
474 |
-
$message = __( 'Reports have been deleted successfully!', 'email-subscribers' );
|
475 |
-
ES_Common::show_message( $message, 'success' );
|
476 |
-
}
|
477 |
-
|
478 |
-
}
|
479 |
-
}
|
480 |
-
|
481 |
-
public function preview_email( $report_id ) {
|
482 |
-
ob_start();
|
483 |
-
?>
|
484 |
-
<div class="wrap">
|
485 |
-
<h2 style="margin-bottom:1em;">
|
486 |
-
<?php echo __( 'Preview Email', 'email-subscribers' ); ?>
|
487 |
-
</h2>
|
488 |
-
<p>
|
489 |
-
<?php echo __( 'This is how the email you sent may look. <br>Note: Different email services (like gmail, yahoo etc) display email content differently. So there could be a slight variation on how your customer will view the email content.', 'email-subscribers' ); ?>
|
490 |
-
</p>
|
491 |
-
<div class="tool-box">
|
492 |
-
<div style="padding:15px;background-color:#FFFFFF;">
|
493 |
-
<?php
|
494 |
-
$preview = array();
|
495 |
-
$preview = ES_DB_Mailing_Queue::get_email_by_id( $report_id );
|
496 |
-
|
497 |
-
$es_email_type = get_option( 'ig_es_email_type' ); // Not the ideal way. Email type can differ while previewing sent email.
|
498 |
-
|
499 |
-
if ( $es_email_type == "WP HTML MAIL" || $es_email_type == "PHP HTML MAIL" ) {
|
500 |
-
$preview['body'] = ES_Common::es_process_template_body( $preview['body'], $report_id );
|
501 |
-
} else {
|
502 |
-
$preview['body'] = str_replace( "<br />", "\r\n", $preview['body'] );
|
503 |
-
$preview['body'] = str_replace( "<br>", "\r\n", $preview['body'] );
|
504 |
-
}
|
505 |
-
|
506 |
-
echo stripslashes( $preview['body'] );
|
507 |
-
?>
|
508 |
-
</div>
|
509 |
-
</div>
|
510 |
-
</div>
|
511 |
-
<?php
|
512 |
-
$html = ob_get_clean();
|
513 |
-
|
514 |
-
return $html;
|
515 |
-
|
516 |
-
}
|
517 |
-
|
518 |
-
public static function get_instance() {
|
519 |
-
if ( ! isset( self::$instance ) ) {
|
520 |
-
self::$instance = new self();
|
521 |
-
}
|
522 |
-
|
523 |
-
return self::$instance;
|
524 |
-
}
|
525 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-subscription-throttaling.php
DELETED
@@ -1,56 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
class ES_Subscription_Throttaling {
|
9 |
-
|
10 |
-
static function throttle() {
|
11 |
-
|
12 |
-
global $wpdb;
|
13 |
-
|
14 |
-
if ( ! ( is_user_logged_in() && is_super_admin() ) ) {
|
15 |
-
$subscriber_ip = ig_es_get_ip();
|
16 |
-
|
17 |
-
$whitelist_ips = array();
|
18 |
-
$whitelist_ips = apply_filters( 'ig_es_whitelist_ips', $whitelist_ips );
|
19 |
-
|
20 |
-
$blacklist_ips = array();
|
21 |
-
$blacklist_ips = apply_filters( 'ig_es_blacklist_ips', $blacklist_ips );
|
22 |
-
|
23 |
-
if ( ! ( empty( $subscriber_ip ) || ( is_array( $whitelist_ips ) && count( $whitelist_ips ) > 0 && in_array( $subscriber_ip, $whitelist_ips ) ) ) ) {
|
24 |
-
|
25 |
-
if ( is_array( $blacklist_ips ) && count( $blacklist_ips ) > 0 && in_array( $subscriber_ip, $blacklist_ips ) ) {
|
26 |
-
return MINUTE_IN_SECONDS * 10;
|
27 |
-
}
|
28 |
-
|
29 |
-
$query = "SELECT count(*) as count from " . IG_CONTACTS_IPS_TABLE . " WHERE ip = %s AND ( `created_on` >= NOW() - INTERVAL %s SECOND )";
|
30 |
-
$subscribers = $wpdb->get_var( $wpdb->prepare( $query, $subscriber_ip, DAY_IN_SECONDS ) );
|
31 |
-
|
32 |
-
if ( $subscribers > 0 ) {
|
33 |
-
$timeout = MINUTE_IN_SECONDS * pow( 2, $subscribers - 1 );
|
34 |
-
|
35 |
-
$query = "SELECT count(*) as count from " . IG_CONTACTS_IPS_TABLE . " WHERE ip = %s AND ( `created_on` >= NOW() - INTERVAL %s SECOND ) LIMIT 1";
|
36 |
-
$subscribers = $wpdb->get_var( $wpdb->prepare( $query, $subscriber_ip, $timeout ) );
|
37 |
-
|
38 |
-
if ( $subscribers > 0 ) {
|
39 |
-
return $timeout;
|
40 |
-
}
|
41 |
-
}
|
42 |
-
|
43 |
-
// Add IP Address.
|
44 |
-
$query = "INSERT INTO " . IG_CONTACTS_IPS_TABLE . " (`ip`) VALUES ( %s )";
|
45 |
-
$wpdb->query( $wpdb->prepare( $query, $subscriber_ip ) );
|
46 |
-
|
47 |
-
// Delete older entries
|
48 |
-
$query = "DELETE FROM " . IG_CONTACTS_IPS_TABLE . " WHERE (`created_on` < NOW() - INTERVAL %s SECOND )";
|
49 |
-
$wpdb->query( $wpdb->prepare( $query, DAY_IN_SECONDS ) );
|
50 |
-
}
|
51 |
-
}
|
52 |
-
|
53 |
-
return false;
|
54 |
-
}
|
55 |
-
|
56 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-templates-table.php
DELETED
@@ -1,323 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
class ES_Templates_Table {
|
9 |
-
|
10 |
-
static $instance;
|
11 |
-
|
12 |
-
public function __construct() {
|
13 |
-
add_action( 'add_meta_boxes', array( $this, 'es_template_meta_box_add' ) );
|
14 |
-
add_action( 'save_post', array( $this, 'es_template_meta_save' ), 10, 2 );
|
15 |
-
add_action( 'post_submitbox_misc_actions', array( $this, 'preview_button' ) );
|
16 |
-
add_filter( 'manage_edit-es_template_columns', array( $this, 'add_new_columns' ), 10, 1 );
|
17 |
-
add_action( 'manage_posts_custom_column', array( $this, 'custom_columns' ) );
|
18 |
-
add_action( 'admin_footer', array( $this, 'add_custom_button' ) );
|
19 |
-
add_action( 'edit_form_after_title', array( $this, 'add_template_type' ) );
|
20 |
-
//duplicate template
|
21 |
-
add_filter( 'post_row_actions', array( &$this, 'add_message_action' ), 10, 2 );
|
22 |
-
add_action( 'admin_init', array( &$this, 'duplicate_message' ), 10, 1 );
|
23 |
-
}
|
24 |
-
|
25 |
-
public function add_template_type() {
|
26 |
-
global $post;
|
27 |
-
if ( ! ( is_object( $post ) && 'es_template' === $post->post_type ) ) {
|
28 |
-
return;
|
29 |
-
}
|
30 |
-
$values = get_post_custom( $post->ID );
|
31 |
-
|
32 |
-
$selected = isset( $values['es_template_type'] ) ? esc_attr( $values['es_template_type'][0] ) : '';
|
33 |
-
$template_type = array(
|
34 |
-
'newsletter' => __( 'Broadcast', 'email-subscribers' ),
|
35 |
-
'post_notification' => __( 'Post Notification', 'email-subscribers' )
|
36 |
-
);
|
37 |
-
$template_type = apply_filters( 'es_template_type', $template_type );
|
38 |
-
?>
|
39 |
-
<p>
|
40 |
-
<label for="es_template_type"><strong><?php _e( 'Select your Email Template Type', 'email-subscirbers' ); ?></strong></label></br>
|
41 |
-
<select name="es_template_type" id="es_template_type">
|
42 |
-
<?php
|
43 |
-
if ( ! empty( $template_type ) ) {
|
44 |
-
foreach ( $template_type as $key => $value ) {
|
45 |
-
echo "<option value=" . $key . " " . selected( $selected, $key, false ) . ">" . $value . "</option>";
|
46 |
-
}
|
47 |
-
}
|
48 |
-
?>
|
49 |
-
|
50 |
-
</select>
|
51 |
-
</p>
|
52 |
-
<?php
|
53 |
-
}
|
54 |
-
|
55 |
-
public function es_template_meta_box_add() {
|
56 |
-
add_meta_box( 'es_template_meta_box', 'Available Keywords', array( $this, 'es_template_type_meta_box' ), 'es_template', 'normal', 'high' );
|
57 |
-
}
|
58 |
-
|
59 |
-
public function es_template_type_meta_box( $post ) {
|
60 |
-
|
61 |
-
if ( ! ( is_object( $post ) && 'es_template' === $post->post_type ) ) {
|
62 |
-
return;
|
63 |
-
}
|
64 |
-
?>
|
65 |
-
<p id="post_notification">
|
66 |
-
<a href="https://www.icegram.com/documentation/es-what-are-the-available-keywords-in-the-post-notifications/?utm_source=es&utm_medium=in_app&utm_campaign=view_docs_help_page" target="_blank"><?php _e( 'Available Keywords', 'email-subscribers' ); ?></a> <?php _e( 'for Post Notification: ', 'email-subsribers' ); ?> {{FIRSTNAME}},
|
67 |
-
{{LASTNAME}}, {{NAME}}, {{EMAIL}},
|
68 |
-
{{DATE}}, {{POSTTITLE}}, {{POSTIMAGE}}, {{POSTEXCERPT}}, {{POSTDESC}},
|
69 |
-
{{POSTAUTHOR}}, {{POSTLINK}}, {{POSTLINK-WITHTITLE}}, {{POSTLINK-ONLY}}, {{POSTFULL}} </p>
|
70 |
-
<p id="newsletter">
|
71 |
-
<a href="https://www.icegram.com/documentation/es-what-are-the-available-keywords-in-the-newsletters/?utm_source=es&utm_medium=in_app&utm_campaign=view_docs_help_page" target="_blank"><?php _e( 'Available Keywords', 'email-subscribers' ); ?></a> <?php _e( 'for Broadcast:', 'email-subscribers' ); ?> {{FIRSTNAME}}, {{LASTNAME}}, {{NAME}},
|
72 |
-
{{EMAIL}} </p>
|
73 |
-
<div id="post_digest">
|
74 |
-
<span style="font-size: 0.8em; margin-left: 0.3em; padding: 2px; background: #e66060; color: #fff; border-radius: 2px; ">Pro</span>
|
75 |
-
<a href="https://www.icegram.com/send-post-digest-using-email-subscribers-plugin/?utm_source=es&utm_medium=in_app&utm_campaign=view_post_digest_post" target="_blank"><?php _e( 'Available Keywords', 'email-subscribers' ); ?></a> <?php _e( 'for Post Digest:', 'email-subscribers' ); ?>
|
76 |
-
{{FIRSTNAME}}, {{LASTNAME}}, {{NAME}}<div class="post_digest_block"> {{POSTDIGEST}} <br/><?php _e( 'Any keywords related Post Notification', 'email-subscribers' ); ?> <br/>{{/POSTDIGEST}} </div>
|
77 |
-
</div>
|
78 |
-
<?php
|
79 |
-
}
|
80 |
-
|
81 |
-
public function es_template_meta_save( $post_id, $post ) {
|
82 |
-
if ( empty( $post_id ) || empty( $post ) || empty( $_POST ) ) {
|
83 |
-
return;
|
84 |
-
}
|
85 |
-
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
86 |
-
return;
|
87 |
-
}
|
88 |
-
if ( is_int( wp_is_post_revision( $post ) ) ) {
|
89 |
-
return;
|
90 |
-
}
|
91 |
-
if ( is_int( wp_is_post_autosave( $post ) ) ) {
|
92 |
-
return;
|
93 |
-
}
|
94 |
-
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
95 |
-
return;
|
96 |
-
}
|
97 |
-
if ( $post->post_type != 'es_template' ) {
|
98 |
-
return;
|
99 |
-
}
|
100 |
-
|
101 |
-
|
102 |
-
if ( isset( $_POST['es_template_type'] ) ) {
|
103 |
-
$es_template_type = ig_es_get_post_data('es_template_type');
|
104 |
-
update_post_meta( $post_id, 'es_template_type', esc_attr( $es_template_type ) );
|
105 |
-
}
|
106 |
-
}
|
107 |
-
|
108 |
-
|
109 |
-
public function preview_button( $post ) {
|
110 |
-
if ( is_object( $post ) && 'es_template' === $post->post_type ) {
|
111 |
-
$post_id = $post->ID;
|
112 |
-
?>
|
113 |
-
|
114 |
-
<div class="misc-pub-section">
|
115 |
-
<div id="" class="es_preview_button" style="display: block;">
|
116 |
-
<a href="<?php echo admin_url(); ?>admin.php?page=es_template_preview&post=<?php echo $post_id; ?>&preview=true&preview_id=<?php echo $post_id ?>" target="_blank" class="button button-primary es_preview"><?php _e( 'Preview Template', 'email-subscribers' ); ?></a>
|
117 |
-
<div class="clear"></div>
|
118 |
-
</div>
|
119 |
-
</div>
|
120 |
-
|
121 |
-
<?php
|
122 |
-
}
|
123 |
-
}
|
124 |
-
|
125 |
-
public function add_custom_button() {
|
126 |
-
$screen = get_current_screen();
|
127 |
-
if ( $screen->post_type == 'es_template' ) {
|
128 |
-
?>
|
129 |
-
<script type="text/javascript">
|
130 |
-
jQuery('<a href="admin.php?page=es_campaigns" class="page-title-action">Campaigns</a>').insertBefore(".wp-header-end");
|
131 |
-
</script>
|
132 |
-
<?php
|
133 |
-
}
|
134 |
-
}
|
135 |
-
|
136 |
-
public function es_template_preview_callback() {
|
137 |
-
|
138 |
-
$template_id = ig_es_get_request_data('post');
|
139 |
-
|
140 |
-
$template = get_post( $template_id, ARRAY_A );
|
141 |
-
|
142 |
-
if ( $template ) {
|
143 |
-
$current_user = wp_get_current_user();
|
144 |
-
$username = $current_user->user_login;
|
145 |
-
$useremail = $current_user->user_email;
|
146 |
-
|
147 |
-
$es_template_body = $template['post_content'];
|
148 |
-
|
149 |
-
$es_template_type = get_post_meta( $template_id, 'es_template_type', true );
|
150 |
-
|
151 |
-
|
152 |
-
if ( 'post_notification' === $es_template_type ) {
|
153 |
-
$args = array( 'numberposts' => '1', 'order' => 'DESC', 'post_status' => 'publish' );
|
154 |
-
$recent_posts = wp_get_recent_posts( $args );
|
155 |
-
|
156 |
-
if ( count( $recent_posts ) > 0 ) {
|
157 |
-
$recent_post = array_shift( $recent_posts );
|
158 |
-
|
159 |
-
$post_id = $recent_post['ID'];
|
160 |
-
$es_template_body = ES_Handle_Post_Notification::prepare_body( $es_template_body, $post_id, $template_id );
|
161 |
-
}
|
162 |
-
} else {
|
163 |
-
$es_template_body = ES_Common::es_process_template_body( $es_template_body, $template_id );
|
164 |
-
}
|
165 |
-
|
166 |
-
$es_template_body = str_replace( '{{NAME}}', $username, $es_template_body );
|
167 |
-
$es_template_body = str_replace( '{{EMAIL}}', $useremail, $es_template_body );
|
168 |
-
|
169 |
-
if ( has_post_thumbnail( $template_id ) ) {
|
170 |
-
$image_array = wp_get_attachment_image_src( get_post_thumbnail_id( $template_id ), 'full' );
|
171 |
-
$image = '<img src="' . $image_array[0] . '" class="img-responsive" alt="Image for Post ' . $template_id . '" />';
|
172 |
-
} else {
|
173 |
-
$image = '';
|
174 |
-
}
|
175 |
-
$html = '';
|
176 |
-
$html .= '<style type="text/css">
|
177 |
-
.es-sidebar {
|
178 |
-
width: 23%;
|
179 |
-
background-color: rgb(230, 230, 230);
|
180 |
-
padding:15px;
|
181 |
-
border-right: 1px solid #bdbdbd;
|
182 |
-
}
|
183 |
-
.es-preview {
|
184 |
-
float: left;
|
185 |
-
padding:15px;
|
186 |
-
width: 70%;
|
187 |
-
background-color:#FFF;
|
188 |
-
font-size:16px;
|
189 |
-
}
|
190 |
-
</style>
|
191 |
-
<div class="wrap">
|
192 |
-
<div class="tool-box">
|
193 |
-
<div class="es-main" style="display:flex;">
|
194 |
-
<div class="es-sidebar">
|
195 |
-
<h2 style="margin-bottom:1em;">
|
196 |
-
Template Preview <a class="add-new-h2" href="' . admin_url() . 'admin.php?page=es-general-information">Help</a>
|
197 |
-
</h2>' . Email_Subscribers_Admin::es_feedback() . '
|
198 |
-
<p>
|
199 |
-
<a class="button-primary" href="' . admin_url() . 'post.php?post=' . $template_id . '&action=edit">Edit</a>
|
200 |
-
</p>
|
201 |
-
<p>
|
202 |
-
This is how your email may look.<br><br>Note: Different email services (like gmail, yahoo etc) display email content differently. So there could be a slight variation on how your customer will view the email content. </p>
|
203 |
-
</div>
|
204 |
-
<div class="es-preview">' . $es_template_body . '</div>
|
205 |
-
<div style="clear:both;"></div>
|
206 |
-
</div>
|
207 |
-
<div style="clear:both;"></div>
|
208 |
-
</div>
|
209 |
-
</div>';
|
210 |
-
echo apply_filters( 'the_content', $html );
|
211 |
-
} else {
|
212 |
-
echo 'Please publish it or save it as a draft';
|
213 |
-
}
|
214 |
-
|
215 |
-
}
|
216 |
-
|
217 |
-
public function add_new_columns( $existing_columns ) {
|
218 |
-
|
219 |
-
$date = $existing_columns['date'];
|
220 |
-
unset( $existing_columns['date'] );
|
221 |
-
|
222 |
-
$existing_columns['es_template_type'] = __( 'Template Type', 'email-subscribers' );
|
223 |
-
$existing_columns['es_template_thumbnail'] = __( 'Thumbnail', 'email-subscribers' );
|
224 |
-
$existing_columns['date'] = $date;
|
225 |
-
|
226 |
-
return $existing_columns;
|
227 |
-
|
228 |
-
}
|
229 |
-
|
230 |
-
public function custom_columns( $column ) {
|
231 |
-
|
232 |
-
global $post;
|
233 |
-
|
234 |
-
$es_template_thumbnail = get_the_post_thumbnail( $post->ID, array( '200', '200' ) );
|
235 |
-
$default_template_thumbnail = '<img src="' . ES_PLUGIN_URL . 'lite/admin/images/envelope.png" />';
|
236 |
-
$es_template_thumbnail = apply_filters( 'ig_es_template_thumbnail', $es_template_thumbnail );
|
237 |
-
$es_template_thumbnail = ( ! empty( $es_template_thumbnail ) ) ? $es_template_thumbnail : $default_template_thumbnail;
|
238 |
-
switch ( $column ) {
|
239 |
-
case 'es_template_type':
|
240 |
-
$type = get_post_meta( $post->ID, 'es_template_type', true );
|
241 |
-
$type = sanitize_text_field(strtolower( $type ));
|
242 |
-
$type = ( 'newsletter' === $type ) ? __( 'Broadcast', 'email-subscribers' ) : $type;
|
243 |
-
echo $type = ucwords( str_replace( '_', ' ', $type ) );
|
244 |
-
break;
|
245 |
-
case 'es_template_thumbnail' :
|
246 |
-
echo $es_template_thumbnail;
|
247 |
-
break;
|
248 |
-
default:
|
249 |
-
break;
|
250 |
-
}
|
251 |
-
|
252 |
-
return $column;
|
253 |
-
}
|
254 |
-
|
255 |
-
function add_message_action( $actions, $post ) {
|
256 |
-
if ( $post->post_type != 'es_template' ) {
|
257 |
-
return $actions;
|
258 |
-
}
|
259 |
-
$actions['duplicate_template'] = '<a class="es-duplicate-template" href="post.php?template_id=' . $post->ID . '&action=duplicate-template" >' . __( 'Duplicate', 'email-subscribers' ) . '</a>';
|
260 |
-
|
261 |
-
return $actions;
|
262 |
-
}
|
263 |
-
|
264 |
-
function duplicate_message() {
|
265 |
-
$action = ig_es_get_request_data( 'action' );
|
266 |
-
$template_id = ig_es_get_request_data( 'template_id' );
|
267 |
-
if ( ! empty( $template_id ) && 'duplicate-template' === $action ) {
|
268 |
-
//duplicate tempalte
|
269 |
-
$this->duplicate_in_db( $template_id );
|
270 |
-
// $location = admin_url( 'post.php?post='.$duplicate_template_id.'&action=edit');
|
271 |
-
$location = admin_url( 'edit.php?post_type=es_template' );
|
272 |
-
wp_safe_redirect( $location );
|
273 |
-
exit;
|
274 |
-
}
|
275 |
-
}
|
276 |
-
|
277 |
-
function duplicate_in_db( $original_id ) {
|
278 |
-
// Get access to the database
|
279 |
-
global $wpdb;
|
280 |
-
// Get the post as an array
|
281 |
-
$duplicate = get_post( $original_id, 'ARRAY_A' );
|
282 |
-
// Modify some of the elements
|
283 |
-
$duplicate['post_title'] = $duplicate['post_title'] . ' ' . __( 'Copy', 'icegram' );
|
284 |
-
$duplicate['post_status'] = 'draft';
|
285 |
-
// Set the post date
|
286 |
-
$timestamp = current_time( 'timestamp', 0 );
|
287 |
-
|
288 |
-
$duplicate['post_date'] = date( 'Y-m-d H:i:s', $timestamp );
|
289 |
-
|
290 |
-
// Remove some of the keys
|
291 |
-
unset( $duplicate['ID'] );
|
292 |
-
unset( $duplicate['guid'] );
|
293 |
-
unset( $duplicate['comment_count'] );
|
294 |
-
|
295 |
-
// Insert the post into the database
|
296 |
-
$duplicate_id = wp_insert_post( $duplicate );
|
297 |
-
|
298 |
-
// Duplicate all taxonomies/terms
|
299 |
-
$taxonomies = get_object_taxonomies( $duplicate['post_type'] );
|
300 |
-
|
301 |
-
foreach ( $taxonomies as $taxonomy ) {
|
302 |
-
$terms = wp_get_post_terms( $original_id, $taxonomy, array( 'fields' => 'names' ) );
|
303 |
-
wp_set_object_terms( $duplicate_id, $terms, $taxonomy );
|
304 |
-
}
|
305 |
-
|
306 |
-
// Duplicate all custom fields
|
307 |
-
$custom_fields = get_post_custom( $original_id );
|
308 |
-
foreach ( $custom_fields as $key => $value ) {
|
309 |
-
add_post_meta( $duplicate_id, $key, maybe_unserialize( $value[0] ) );
|
310 |
-
}
|
311 |
-
|
312 |
-
return $duplicate_id;
|
313 |
-
}
|
314 |
-
|
315 |
-
public static function get_instance() {
|
316 |
-
if ( ! isset( self::$instance ) ) {
|
317 |
-
self::$instance = new self();
|
318 |
-
}
|
319 |
-
|
320 |
-
return self::$instance;
|
321 |
-
}
|
322 |
-
|
323 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-tools.php
DELETED
@@ -1,92 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
/**
|
9 |
-
* The admin-specific functionality of the plugin.
|
10 |
-
*
|
11 |
-
* Admin Settings
|
12 |
-
*
|
13 |
-
* @package Email_Subscribers
|
14 |
-
* @subpackage Email_Subscribers/admin
|
15 |
-
* @author Your Name <email@example.com>
|
16 |
-
*/
|
17 |
-
class ES_Tools {
|
18 |
-
// class instance
|
19 |
-
static $instance;
|
20 |
-
|
21 |
-
public function __construct() {
|
22 |
-
|
23 |
-
// Allow only to send test email to user who have Settings & Campaigns permission
|
24 |
-
$accessible_sub_menus = ES_Common::ig_es_get_accessible_sub_menus();
|
25 |
-
if ( in_array( 'settings', $accessible_sub_menus ) || in_array( 'campaigns', $accessible_sub_menus ) ) {
|
26 |
-
add_action( 'wp_ajax_es_send_test_email', array( $this, 'es_send_test_email_callback' ) );
|
27 |
-
}
|
28 |
-
}
|
29 |
-
|
30 |
-
public static function es_send_test_email_callback() {
|
31 |
-
|
32 |
-
$email = sanitize_email( ig_es_get_request_data( 'es_test_email' ) );
|
33 |
-
|
34 |
-
$email_response = '';
|
35 |
-
$response = array();
|
36 |
-
|
37 |
-
if ( ! empty( $email ) ) {
|
38 |
-
$subject = 'Email Subscribers: ' . sprintf( esc_html__( 'Test email to %s', 'email-subscribers' ), $email );
|
39 |
-
$content = self::get_email_message();
|
40 |
-
$response = ES_Mailer::send( $email, $subject, $content );
|
41 |
-
if ( $response['status'] === 'SUCCESS' ) {
|
42 |
-
$response['message'] = __( 'Email has been sent. Please check your inbox', 'email-subscribers' );
|
43 |
-
}
|
44 |
-
// if ( $email_response ) {
|
45 |
-
// $response['status'] = 'success';
|
46 |
-
// } else {
|
47 |
-
// $response['message'] = __( 'Something went wrong', 'email-subscribers' );
|
48 |
-
// $response['status'] = 'error';
|
49 |
-
// }
|
50 |
-
}
|
51 |
-
|
52 |
-
echo json_encode( $response );
|
53 |
-
exit;
|
54 |
-
}
|
55 |
-
|
56 |
-
|
57 |
-
public static function get_instance() {
|
58 |
-
if ( ! isset( self::$instance ) ) {
|
59 |
-
self::$instance = new self();
|
60 |
-
}
|
61 |
-
|
62 |
-
return self::$instance;
|
63 |
-
}
|
64 |
-
|
65 |
-
public static function get_email_message() {
|
66 |
-
ob_start();
|
67 |
-
?>
|
68 |
-
|
69 |
-
<html>
|
70 |
-
<head></head>
|
71 |
-
<body>
|
72 |
-
<p>Congrats, test email was sent successfully!</p>
|
73 |
-
|
74 |
-
<p>Thank you for trying out Email Subscribers. We are on a mission to make the best Email Marketing Automation plugin for WordPress.</p>
|
75 |
-
|
76 |
-
<p>If you find this plugin useful, please consider giving us <a href="https://wordpress.org/support/plugin/email-subscribers/reviews/?filter=5">5 stars review</a> on WordPress!</p>
|
77 |
-
|
78 |
-
<p>Nirav Mehta</p>
|
79 |
-
<p>Founder, <a href="https://www.icegram.com/">Icegram</a></p>
|
80 |
-
</body>
|
81 |
-
</html>
|
82 |
-
|
83 |
-
<?php
|
84 |
-
$message = ob_get_clean();
|
85 |
-
|
86 |
-
return $message;
|
87 |
-
|
88 |
-
}
|
89 |
-
}
|
90 |
-
|
91 |
-
|
92 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-tracking.php
DELETED
@@ -1,39 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
// Exit if accessed directly
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
4 |
-
exit;
|
5 |
-
}
|
6 |
-
|
7 |
-
if ( ! class_exists( 'ES_Tracking' ) ) {
|
8 |
-
/**
|
9 |
-
* Class ES_Tracking
|
10 |
-
*
|
11 |
-
* Track Activities like Subscribe, Open, Click, Unsubscribe
|
12 |
-
*
|
13 |
-
* @since 4.2.0
|
14 |
-
*/
|
15 |
-
class ES_Tracking {
|
16 |
-
/**
|
17 |
-
* ES_Actions constructor.
|
18 |
-
*
|
19 |
-
* @since 4.2.0
|
20 |
-
*/
|
21 |
-
public function __construct() {
|
22 |
-
add_action( 'init', array( $this, 'init' ), 1 );
|
23 |
-
}
|
24 |
-
|
25 |
-
/**
|
26 |
-
* Track user interaction
|
27 |
-
*
|
28 |
-
* @since 4.2.0
|
29 |
-
*/
|
30 |
-
public function init() {
|
31 |
-
|
32 |
-
}
|
33 |
-
|
34 |
-
}
|
35 |
-
}
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/admin/class-es-widget.php
DELETED
@@ -1,87 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
class ES_Widget extends WP_Widget {
|
9 |
-
|
10 |
-
function __construct() {
|
11 |
-
parent::__construct( 'email_subscriber_widget', __( 'Email Subscribers Widget', 'email-subscribers' ), array( 'description' => __( 'Email Subscribers', 'email-subscribers' ) ) );
|
12 |
-
}
|
13 |
-
|
14 |
-
public function widget( $args, $instance ) {
|
15 |
-
|
16 |
-
$title = apply_filters( 'widget_title', $instance['title'] );
|
17 |
-
|
18 |
-
echo $args['before_widget'];
|
19 |
-
|
20 |
-
if ( ! empty( $title ) ) {
|
21 |
-
echo $args['before_title'] . $title . $args['after_title'];
|
22 |
-
}
|
23 |
-
|
24 |
-
$display_name = isset( $instance['display_name'] ) ? esc_attr( $instance['display_name'] ) : '';
|
25 |
-
$subscribers_group = isset( $instance['subscribers_group'] ) ? esc_attr( $instance['subscribers_group'] ) : '';
|
26 |
-
$desc = isset( $instance['short_desc'] ) ? esc_attr( $instance['short_desc'] ) : '';
|
27 |
-
|
28 |
-
$name = strtolower( $display_name ) != 'no' ? 'yes' : '';
|
29 |
-
|
30 |
-
$data['name_visible'] = $name;
|
31 |
-
$data['list_visible'] = 'no';
|
32 |
-
$data['lists'] = array();
|
33 |
-
$data['form_id'] = 0;
|
34 |
-
$data['list'] = $subscribers_group;
|
35 |
-
$data['desc'] = $desc;
|
36 |
-
|
37 |
-
ES_Shortcode::render_form( $data );
|
38 |
-
|
39 |
-
echo $args['after_widget'];
|
40 |
-
}
|
41 |
-
|
42 |
-
public function form( $instance ) {
|
43 |
-
|
44 |
-
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
|
45 |
-
$short_desc = isset( $instance['short_desc'] ) ? esc_attr( $instance['short_desc'] ) : '';
|
46 |
-
$display_name = isset( $instance['display_name'] ) ? esc_attr( $instance['display_name'] ) : '';
|
47 |
-
$subscribers_group = isset( $instance['subscribers_group'] ) ? esc_attr( $instance['subscribers_group'] ) : '';
|
48 |
-
|
49 |
-
$display_names = array( 'yes' => __( 'Yes', 'email-subscribers' ), 'no' => __( 'No', 'email-subscribers' ) );
|
50 |
-
|
51 |
-
?>
|
52 |
-
|
53 |
-
<p>
|
54 |
-
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Widget Title:' ); ?></label>
|
55 |
-
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
|
56 |
-
</p>
|
57 |
-
<p>
|
58 |
-
<label for="<?php echo $this->get_field_id( 'short_desc' ); ?>"><?php _e( 'Short description' ); ?></label>
|
59 |
-
<input class="widefat" id="<?php echo $this->get_field_id( 'short_desc' ); ?>" name="<?php echo $this->get_field_name( 'short_desc' ); ?>" type="text" value="<?php echo esc_attr( $short_desc ); ?>">
|
60 |
-
</p>
|
61 |
-
<p>
|
62 |
-
<label for="widget-email-subscribers-2-es_name"><?php _e( 'Display Name Field' ); ?></label>
|
63 |
-
<select id="<?php echo $this->get_field_id( 'display_name' ); ?>" name="<?php echo $this->get_field_name( 'display_name' ); ?>" class="widefat" style="width:100%;">
|
64 |
-
<?php foreach ( $display_names as $name ) { ?>
|
65 |
-
<option <?php selected( $display_name, $name ); ?> value="<?php echo $name; ?>"><?php echo $name; ?></option>
|
66 |
-
<?php } ?>
|
67 |
-
</select>
|
68 |
-
</p>
|
69 |
-
<p>
|
70 |
-
<label for="widget-email-subscribers-2-es_group"><?php _e( 'Subscriber List' ); ?></label>
|
71 |
-
<select id="<?php echo $this->get_field_id( 'subscribers_group' ); ?>" name="<?php echo $this->get_field_name( 'subscribers_group' ); ?>" class="widefat" style="width:100%;">
|
72 |
-
<?php echo ES_Common::prepare_list_dropdown_options( $subscribers_group ); ?>
|
73 |
-
</select>
|
74 |
-
</p>
|
75 |
-
<?php
|
76 |
-
}
|
77 |
-
|
78 |
-
public function update( $new_instance, $old_instance ) {
|
79 |
-
$instance = array();
|
80 |
-
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
|
81 |
-
$instance['short_desc'] = ( ! empty( $new_instance['short_desc'] ) ) ? strip_tags( $new_instance['short_desc'] ) : '';
|
82 |
-
$instance['display_name'] = ( ! empty( $new_instance['display_name'] ) ) ? strip_tags( $new_instance['display_name'] ) : '';
|
83 |
-
$instance['subscribers_group'] = ( ! empty( $new_instance['subscribers_group'] ) ) ? strip_tags( $new_instance['subscribers_group'] ) : '';
|
84 |
-
|
85 |
-
return $instance;
|
86 |
-
}
|
87 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/class-es-common.php
CHANGED
@@ -66,8 +66,9 @@ Class ES_Common {
|
|
66 |
$meta = ES()->campaigns_db->get_campaign_meta_by_id( $campaign_id );
|
67 |
|
68 |
$meta['pre_header'] = !empty($meta['pre_header']) ? $meta['pre_header'] : '';
|
|
|
69 |
if( !empty( $meta['pre_header'] )){
|
70 |
-
|
71 |
}
|
72 |
|
73 |
return $content;
|
66 |
$meta = ES()->campaigns_db->get_campaign_meta_by_id( $campaign_id );
|
67 |
|
68 |
$meta['pre_header'] = !empty($meta['pre_header']) ? $meta['pre_header'] : '';
|
69 |
+
|
70 |
if( !empty( $meta['pre_header'] )){
|
71 |
+
//$content = '<span class="es_preheader" style="display: none !important; visibility: hidden; opacity: 0; color: transparent; height: 0; width: 0;">'.$meta['pre_header'].'</span>'.$content;
|
72 |
}
|
73 |
|
74 |
return $content;
|
lite/includes/class-es-mailer.php
DELETED
@@ -1,547 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
class ES_Mailer {
|
9 |
-
|
10 |
-
public function __construct() {
|
11 |
-
|
12 |
-
}
|
13 |
-
|
14 |
-
/* prepare cron email*/
|
15 |
-
public static function prepare_and_send_email( $mails, $notification ) {
|
16 |
-
|
17 |
-
if ( count( $mails ) <= 0 ) {
|
18 |
-
return;
|
19 |
-
}
|
20 |
-
|
21 |
-
// $source = $notification['source'];
|
22 |
-
$content = $notification['body'];
|
23 |
-
$subject = $notification['subject'];
|
24 |
-
$guid = $notification['hash'];
|
25 |
-
$template_id = ES()->campaigns_db->get_template_id_by_campaign( $notification['id'] );
|
26 |
-
function temp_fun( $mail ) {
|
27 |
-
return $mail['email'];
|
28 |
-
}
|
29 |
-
|
30 |
-
$emails = array_map( "temp_fun", $mails );
|
31 |
-
|
32 |
-
$emails_name_map = ES()->contacts_db->get_contacts_email_name_map( $emails );
|
33 |
-
|
34 |
-
foreach ( $mails as $mail ) {
|
35 |
-
$email = $mail['email'];
|
36 |
-
$id = $mail['contact_id'];
|
37 |
-
$guid = $mail['mailing_queue_hash'];
|
38 |
-
$campaign_id = $mail['campaign_id'];
|
39 |
-
$message_id = $mail['mailing_queue_id'];
|
40 |
-
$email_name = ! empty( $emails_name_map[ $email ] ) ? $emails_name_map[ $email ]['name'] : '';
|
41 |
-
$first_name = ! empty( $emails_name_map[ $email ] ) ? $emails_name_map[ $email ]['first_name'] : '';
|
42 |
-
$last_name = ! empty( $emails_name_map[ $email ] ) ? $emails_name_map[ $email ]['last_name'] : '';
|
43 |
-
|
44 |
-
$keywords = array(
|
45 |
-
'name' => $email_name,
|
46 |
-
'first_name' => $first_name,
|
47 |
-
'last_name' => $last_name,
|
48 |
-
'email' => $email,
|
49 |
-
'hash' => $guid,
|
50 |
-
'dbid' => $id,
|
51 |
-
'message_id' => $notification['id'],
|
52 |
-
'campaign_id' => $notification['campaign_id']
|
53 |
-
);
|
54 |
-
|
55 |
-
|
56 |
-
// Preparing email body
|
57 |
-
$body = self::prepare_email_template( $content, $keywords );
|
58 |
-
|
59 |
-
$send = self::send( $email, $subject, $body );
|
60 |
-
|
61 |
-
ES_DB_Sending_Queue::update_sent_status( $mail['id'], 'Sent' );
|
62 |
-
ES_Common::update_total_email_sent_count();
|
63 |
-
|
64 |
-
// Track Message Sent
|
65 |
-
do_action( 'ig_es_message_sent', $id, $campaign_id, $message_id );
|
66 |
-
}
|
67 |
-
|
68 |
-
}
|
69 |
-
|
70 |
-
public static function prepare_email( $content = '', $data = array() ) {
|
71 |
-
|
72 |
-
$blog_name = get_option( 'blogname' );
|
73 |
-
$site_url = home_url( '/' );
|
74 |
-
|
75 |
-
$name = isset( $data['name'] ) ? $data['name'] : '';
|
76 |
-
$first_name = isset( $data['first_name'] ) ? $data['first_name'] : '';
|
77 |
-
$last_name = isset( $data['last_name'] ) ? $data['last_name'] : '';
|
78 |
-
$email = isset( $data['email'] ) ? $data['email'] : '';
|
79 |
-
$list_name = isset( $data['list_name'] ) ? $data['list_name'] : '';
|
80 |
-
|
81 |
-
$content = str_replace( "{{NAME}}", $name, $content );
|
82 |
-
$content = str_replace( "{{FIRSTNAME}}", $first_name, $content );
|
83 |
-
$content = str_replace( "{{LASTNAME}}", $last_name, $content );
|
84 |
-
$content = str_replace( "{{EMAIL}}", $email, $content );
|
85 |
-
$content = str_replace( "{{GROUP}}", $list_name, $content );
|
86 |
-
$content = str_replace( "{{LIST}}", $list_name, $content );
|
87 |
-
$content = str_replace( "{{SITENAME}}", $blog_name, $content );
|
88 |
-
$content = str_replace( "{{SITEURL}}", $site_url, $content );
|
89 |
-
|
90 |
-
|
91 |
-
$content = nl2br( $content );
|
92 |
-
|
93 |
-
return $content;
|
94 |
-
}
|
95 |
-
|
96 |
-
public static function prepare_admin_signup_subject( $data ) {
|
97 |
-
|
98 |
-
$content = get_option( 'ig_es_admin_new_contact_email_subject' );
|
99 |
-
|
100 |
-
$result = self::prepare_email( $content, $data );
|
101 |
-
|
102 |
-
return $result;
|
103 |
-
}
|
104 |
-
|
105 |
-
public static function prepare_admin_signup_email( $data ) {
|
106 |
-
|
107 |
-
$content = get_option( 'ig_es_admin_new_contact_email_content' );
|
108 |
-
|
109 |
-
$result = self::prepare_email( $content, $data );
|
110 |
-
|
111 |
-
return $result;
|
112 |
-
}
|
113 |
-
|
114 |
-
public static function prepare_welcome_email_subject( $data = array() ) {
|
115 |
-
|
116 |
-
$content = stripslashes( get_option( 'ig_es_welcome_email_subject', __( 'Welcome !', 'email-subscribers' ) ) );
|
117 |
-
|
118 |
-
$result = self::prepare_email( $content, $data );
|
119 |
-
|
120 |
-
return $result;
|
121 |
-
}
|
122 |
-
|
123 |
-
public static function prepare_welcome_email( $data ) {
|
124 |
-
|
125 |
-
$blog_name = get_option( 'blogname' );
|
126 |
-
$total_contacts = ES()->contacts_db->count_active_contacts_by_list_id();
|
127 |
-
$content = stripslashes( get_option( 'ig_es_welcome_email_content', '' ) );
|
128 |
-
|
129 |
-
$name = isset( $data['name'] ) ? $data['name'] : '';
|
130 |
-
$first_name = isset( $data['first_name'] ) ? $data['first_name'] : '';
|
131 |
-
$last_name = isset( $data['last_name'] ) ? $data['last_name'] : '';
|
132 |
-
$email = isset( $data['email'] ) ? $data['email'] : '';
|
133 |
-
$list_name = isset( $data['list_name'] ) ? $data['list_name'] : '';
|
134 |
-
$db_id = isset( $data['db_id'] ) ? $data['db_id'] : '';
|
135 |
-
$guid = ES()->contacts_db->get_contact_hash_by_id( $db_id );
|
136 |
-
// $guid = isset( $data['guid'] ) ? $data['guid'] : '';
|
137 |
-
$guid = ! empty( $guid ) ? $guid : '';
|
138 |
-
|
139 |
-
$link_data = array(
|
140 |
-
'action' => 'unsubscribe',
|
141 |
-
'contact_id' => $db_id,
|
142 |
-
'email' => $email,
|
143 |
-
'guid' => $guid
|
144 |
-
);
|
145 |
-
|
146 |
-
$unsubscribe_link = self::prepare_link( $link_data );
|
147 |
-
|
148 |
-
$content = str_replace( "{{NAME}}", $name, $content );
|
149 |
-
$content = str_replace( "{{FIRSTNAME}}", $first_name, $content );
|
150 |
-
$content = str_replace( "{{LASTNAME}}", $last_name, $content );
|
151 |
-
$content = str_replace( "{{EMAIL}}", $email, $content );
|
152 |
-
$content = str_replace( "{{SITENAME}}", $blog_name, $content );
|
153 |
-
$content = str_replace( "{{GROUP}}", $list_name, $content );
|
154 |
-
$content = str_replace( "{{LIST}}", $list_name, $content );
|
155 |
-
$content = str_replace( "{{UNSUBSCRIBE-LINK}}", $unsubscribe_link, $content );
|
156 |
-
$content = str_replace( "{{LINK}}", $unsubscribe_link, $content );
|
157 |
-
$content = str_replace( "{{TOTAL-CONTACTS}}", $total_contacts, $content );
|
158 |
-
|
159 |
-
$content = nl2br( $content );
|
160 |
-
|
161 |
-
return $content;
|
162 |
-
|
163 |
-
}
|
164 |
-
|
165 |
-
public static function prepare_double_optin_email( $data ) {
|
166 |
-
|
167 |
-
$blog_name = get_option( 'blogname' );
|
168 |
-
$total_contacts = ES()->contacts_db->count_active_contacts_by_list_id();
|
169 |
-
$content = stripslashes( get_option( 'ig_es_confirmation_mail_content', '' ) );
|
170 |
-
|
171 |
-
|
172 |
-
$db_id = isset( $data['db_id'] ) ? $data['db_id'] : '';
|
173 |
-
$guid = ES()->contacts_db->get_contact_hash_by_id( $db_id );
|
174 |
-
// $guid = isset( $data['guid'] ) ? $data['guid'] : '';
|
175 |
-
$guid = ! empty( $guid ) ? $guid : '';
|
176 |
-
$email = isset( $data['email'] ) ? $data['email'] : '';
|
177 |
-
$name = isset( $data['name'] ) ? $data['name'] : '';
|
178 |
-
$first_name = isset( $data['first_name'] ) ? $data['first_name'] : '';
|
179 |
-
$last_name = isset( $data['last_name'] ) ? $data['last_name'] : '';
|
180 |
-
|
181 |
-
$link_data = array(
|
182 |
-
'action' => 'subscribe',
|
183 |
-
'contact_id' => $db_id,
|
184 |
-
'email' => $email,
|
185 |
-
'guid' => $guid
|
186 |
-
);
|
187 |
-
$subscribe_link = self::prepare_link( $link_data );
|
188 |
-
|
189 |
-
$content = str_replace( "{{NAME}}", $name, $content );
|
190 |
-
$content = str_replace( "{{FIRSTNAME}}", $first_name, $content );
|
191 |
-
$content = str_replace( "{{LASTNAME}}", $last_name, $content );
|
192 |
-
$content = str_replace( "{{EMAIL}}", $email, $content );
|
193 |
-
$content = str_replace( "{{LINK}}", $subscribe_link, $content );
|
194 |
-
$content = str_replace( "{{SITENAME}}", $blog_name, $content );
|
195 |
-
$content = str_replace( "{{SUBSCRIBE-LINK}}", $subscribe_link, $content );
|
196 |
-
$content = str_replace( "{{TOTAL-CONTACTS}}", $total_contacts, $content );
|
197 |
-
|
198 |
-
$content = nl2br( $content );
|
199 |
-
|
200 |
-
return $content;
|
201 |
-
|
202 |
-
}
|
203 |
-
|
204 |
-
public static function prepare_email_template( $template_content, $keywords, $template_id = 0 ) {
|
205 |
-
|
206 |
-
$name = isset( $keywords['name'] ) ? $keywords['name'] : '';
|
207 |
-
$email = isset( $keywords['email'] ) ? $keywords['email'] : '';
|
208 |
-
$first_name = isset( $keywords['first_name'] ) ? $keywords['first_name'] : '';
|
209 |
-
$last_name = isset( $keywords['last_name'] ) ? $keywords['last_name'] : '';
|
210 |
-
$contact_id = isset( $keywords['dbid'] ) ? $keywords['dbid'] : '';
|
211 |
-
$hash = isset( $keywords['hash'] ) ? $keywords['hash'] : '';
|
212 |
-
|
213 |
-
if ( empty( $hash ) ) {
|
214 |
-
$hash = ES()->contacts_db->get_contact_hash_by_id( $contact_id );
|
215 |
-
}
|
216 |
-
|
217 |
-
$template_content = str_replace( "{{NAME}}", $name, $template_content );
|
218 |
-
$template_content = str_replace( "{{FIRSTNAME}}", $first_name, $template_content );
|
219 |
-
$template_content = str_replace( "{{LASTNAME}}", $last_name, $template_content );
|
220 |
-
$template_content = str_replace( "{{EMAIL}}", $email, $template_content );
|
221 |
-
|
222 |
-
$template_content = convert_chars( convert_smilies( wptexturize( $template_content ) ) );
|
223 |
-
if ( isset( $GLOBALS['wp_embed'] ) ) {
|
224 |
-
$template_content = $GLOBALS['wp_embed']->autoembed( $template_content );
|
225 |
-
}
|
226 |
-
$template_content = wpautop( $template_content );
|
227 |
-
|
228 |
-
$template_content = do_shortcode( shortcode_unautop( $template_content ) );
|
229 |
-
|
230 |
-
$campaign_id = ! empty( $keywords['campaign_id'] ) ? $keywords['campaign_id'] : 0;
|
231 |
-
$message_id = ! empty( $keywords['message_id'] ) ? $keywords['message_id'] : 0;
|
232 |
-
|
233 |
-
|
234 |
-
$data['content'] = $template_content;
|
235 |
-
$data['tmpl_id'] = $template_id;
|
236 |
-
$data = apply_filters( 'es_after_process_template_body', $data );
|
237 |
-
$template_content = $data['content'];
|
238 |
-
|
239 |
-
$link_data = array(
|
240 |
-
'message_id' => $message_id,
|
241 |
-
'campaign_id' => $campaign_id,
|
242 |
-
'contact_id' => $contact_id,
|
243 |
-
'email' => $email,
|
244 |
-
'guid' => $hash
|
245 |
-
);
|
246 |
-
|
247 |
-
$is_track_clicks = false;
|
248 |
-
$is_track_clicks = apply_filters( 'ig_es_track_clicks', $is_track_clicks, $contact_id, $campaign_id );
|
249 |
-
if ( $is_track_clicks ) {
|
250 |
-
$link_data['action'] = 'click';
|
251 |
-
$template_content = self::replace_links( $template_content, $link_data );
|
252 |
-
}
|
253 |
-
|
254 |
-
|
255 |
-
$link_data['action'] = 'unsubscribe';
|
256 |
-
$unsubscribe_link = self::prepare_link( $link_data );
|
257 |
-
$unsubtext = self::get_unsubscribe_text( $unsubscribe_link );
|
258 |
-
|
259 |
-
$is_track_email_opens = get_option( 'ig_es_track_email_opens', 'yes' );
|
260 |
-
|
261 |
-
$email_tracking_image = '';
|
262 |
-
if ( 'yes' === $is_track_email_opens ) {
|
263 |
-
$data = array(
|
264 |
-
'message_id' => $keywords['message_id'],
|
265 |
-
'campaign_id' => $keywords['campaign_id'],
|
266 |
-
'contact_id' => $contact_id,
|
267 |
-
'email' => $email,
|
268 |
-
'guid' => $hash
|
269 |
-
);
|
270 |
-
|
271 |
-
$email_tracking_image = self::get_tracking_pixel( $data );
|
272 |
-
}
|
273 |
-
|
274 |
-
$template_content = $template_content . $unsubtext . $email_tracking_image;
|
275 |
-
|
276 |
-
return $template_content;
|
277 |
-
}
|
278 |
-
|
279 |
-
/**
|
280 |
-
* Get link
|
281 |
-
*
|
282 |
-
* @param array $data
|
283 |
-
*
|
284 |
-
* @return string
|
285 |
-
*
|
286 |
-
* Modified @since 4.2.0
|
287 |
-
*/
|
288 |
-
public static function prepare_link( $data = array() ) {
|
289 |
-
/**
|
290 |
-
* We are getting different data like action, message_id, campaign_id, contact_id, guid, email etc in $data
|
291 |
-
*/
|
292 |
-
$action = ! empty( $data['action'] ) ? $data['action'] : '';
|
293 |
-
|
294 |
-
if ( 'subscribe' === $action ) {
|
295 |
-
$action = 'optin';
|
296 |
-
}
|
297 |
-
|
298 |
-
$link = add_query_arg( 'es', $action, site_url( '/' ) );
|
299 |
-
|
300 |
-
$data = ig_es_encode_request_data( $data );
|
301 |
-
|
302 |
-
$link = add_query_arg( 'hash', $data, $link );
|
303 |
-
|
304 |
-
return $link;
|
305 |
-
}
|
306 |
-
|
307 |
-
public static function get_unsubscribe_text( $unsublink ) {
|
308 |
-
|
309 |
-
$unsubtext = get_option( 'ig_es_unsubscribe_link_content', '' );
|
310 |
-
$unsubtext = stripslashes( $unsubtext );
|
311 |
-
$unsubtext = str_replace( "{{LINK}}", $unsublink, $unsubtext );
|
312 |
-
$unsubtext = str_replace( "{{UNSUBSCRIBE-LINK}}", $unsublink, $unsubtext );
|
313 |
-
|
314 |
-
return $unsubtext;
|
315 |
-
}
|
316 |
-
|
317 |
-
/**
|
318 |
-
* Get Tracking pixel
|
319 |
-
*
|
320 |
-
* @param array $data
|
321 |
-
*
|
322 |
-
* @return string
|
323 |
-
*
|
324 |
-
* @since 4.2.0
|
325 |
-
*/
|
326 |
-
public static function get_tracking_pixel( $data = array() ) {
|
327 |
-
|
328 |
-
$data['action'] = 'open';
|
329 |
-
|
330 |
-
$url = self::prepare_link( $data );
|
331 |
-
|
332 |
-
$tracking_image = "<img src='{$url}' width='1' height='1' alt=''/>";
|
333 |
-
|
334 |
-
return $tracking_image;
|
335 |
-
|
336 |
-
}
|
337 |
-
|
338 |
-
public static function prepare_unsubscribe_email() {
|
339 |
-
$content = get_option( 'ig_es_unsubscribe_success_message' );
|
340 |
-
|
341 |
-
return $content;
|
342 |
-
}
|
343 |
-
|
344 |
-
public static function prepare_subscribe_email() {
|
345 |
-
$content = get_option( 'ig_es_subscription_success_message' );
|
346 |
-
|
347 |
-
return $content;
|
348 |
-
}
|
349 |
-
|
350 |
-
public static function prepare_es_cron_admin_email( $notification_guid ) {
|
351 |
-
|
352 |
-
$notification = ES_DB_Mailing_Queue::get_notification_by_hash( $notification_guid );
|
353 |
-
|
354 |
-
$template = '';
|
355 |
-
|
356 |
-
if ( isset( $notification['subject'] ) ) {
|
357 |
-
$email_count = $notification['count'];
|
358 |
-
$post_subject = $notification['subject'];
|
359 |
-
$cron_date = date( 'Y-m-d h:i:s' );
|
360 |
-
|
361 |
-
$template = get_option( 'ig_es_cron_admin_email' );
|
362 |
-
|
363 |
-
$template = str_replace( '{{DATE}}', $cron_date, $template );
|
364 |
-
$template = str_replace( '{{COUNT}}', $email_count, $template );
|
365 |
-
$template = str_replace( '{{SUBJECT}}', $post_subject, $template );
|
366 |
-
|
367 |
-
$template = nl2br( $template );
|
368 |
-
}
|
369 |
-
|
370 |
-
return $template;
|
371 |
-
}
|
372 |
-
|
373 |
-
/**
|
374 |
-
* Send Welcome email after subscription
|
375 |
-
*
|
376 |
-
* @param $email
|
377 |
-
* @param $data
|
378 |
-
*
|
379 |
-
* @since 4.1.13
|
380 |
-
*/
|
381 |
-
public static function send_welcome_email( $email, $data ) {
|
382 |
-
|
383 |
-
// Enable Welcome Email?
|
384 |
-
$enable_welcome_email = get_option( 'ig_es_enable_welcome_email', 'no' );
|
385 |
-
|
386 |
-
if ( $enable_welcome_email === 'yes' ) {
|
387 |
-
|
388 |
-
// Prepare Welcome Email Subject
|
389 |
-
$subject = ES_Mailer::prepare_welcome_email_subject( $data );
|
390 |
-
|
391 |
-
// Prepare Welcome Email Content
|
392 |
-
$content = ES_Mailer::prepare_welcome_email( $data );
|
393 |
-
|
394 |
-
// Send Email
|
395 |
-
ES_Mailer::send( $email, $subject, $content );
|
396 |
-
}
|
397 |
-
|
398 |
-
}
|
399 |
-
|
400 |
-
public static function send( $to_email, $subject, $email_template ) {
|
401 |
-
|
402 |
-
$response = array( 'status' => 'ERROR' );
|
403 |
-
$subject = html_entity_decode( $subject, ENT_QUOTES, get_bloginfo( 'charset' ) );
|
404 |
-
$get_email_type = get_option( 'ig_es_email_type', true );
|
405 |
-
$site_title = get_bloginfo();
|
406 |
-
$admin_email = get_option( 'admin_email' );
|
407 |
-
//adding missing header
|
408 |
-
$from_name = get_option( 'ig_es_from_name', true );
|
409 |
-
$from_email = get_option( 'ig_es_from_email', true );
|
410 |
-
|
411 |
-
|
412 |
-
$sender_email = ! empty( $from_email ) ? $from_email : $admin_email;
|
413 |
-
$sender_name = ! empty( $from_name ) ? $from_name : $site_title;
|
414 |
-
|
415 |
-
$headers = array(
|
416 |
-
"From: \"$sender_name\" <$sender_email>",
|
417 |
-
"Return-Path: <" . $sender_email . ">",
|
418 |
-
"Reply-To: \"" . $sender_name . "\" <" . $sender_email . ">"
|
419 |
-
);
|
420 |
-
|
421 |
-
if ( in_array( $get_email_type, array( 'php_html_mail', 'php_plaintext_mail' ) ) ) {
|
422 |
-
$headers[] = "MIME-Version: 1.0";
|
423 |
-
$headers[] = "X-Mailer: PHP" . phpversion();
|
424 |
-
}
|
425 |
-
|
426 |
-
$plain_text_template = self::convert_to_text( $email_template );
|
427 |
-
$headers[] = "Content-Type: text/html; charset=\"" . get_bloginfo( 'charset' ) . "\"";
|
428 |
-
$headers = implode( "\n", $headers );
|
429 |
-
$ig_es_mailer_settings = get_option( 'ig_es_mailer_settings' );
|
430 |
-
if ( ! empty( $ig_es_mailer_settings['mailer'] ) && 'phpmail' !== $ig_es_mailer_settings['mailer'] ) {
|
431 |
-
$data = array(
|
432 |
-
'to_email' => $to_email,
|
433 |
-
'subject' => $subject,
|
434 |
-
'email_template' => $email_template,
|
435 |
-
'plain_text_template' => $plain_text_template,
|
436 |
-
'headers' => $headers,
|
437 |
-
'sender_email' => $sender_email,
|
438 |
-
'sender_name' => $sender_name,
|
439 |
-
'email_type' => $get_email_type
|
440 |
-
);
|
441 |
-
|
442 |
-
$response = apply_filters( 'ig_es_lite_do_send', $response, $data );
|
443 |
-
|
444 |
-
} else {
|
445 |
-
$result = mail( $to_email, $subject, $email_template, $headers );
|
446 |
-
if ( $result ) {
|
447 |
-
$response['status'] = 'SUCCESS';
|
448 |
-
}
|
449 |
-
}
|
450 |
-
|
451 |
-
return $response;
|
452 |
-
|
453 |
-
}
|
454 |
-
|
455 |
-
public static function convert_to_text( $html, $links_only = false ) {
|
456 |
-
|
457 |
-
if ( $links_only ) {
|
458 |
-
$links = '/< *a[^>]*href *= *"([^#]*)"[^>]*>(.*)< *\/ *a *>/Uis';
|
459 |
-
$text = preg_replace( $links, '${2} [${1}]', $html );
|
460 |
-
$text = str_replace( array( ' ', ' ' ), ' ', strip_tags( $text ) );
|
461 |
-
$text = @html_entity_decode( $text, ENT_QUOTES, 'UTF-8' );
|
462 |
-
|
463 |
-
return trim( $text );
|
464 |
-
|
465 |
-
} else {
|
466 |
-
require_once ES_PLUGIN_DIR . 'lite/includes/libraries/class-es-html2text.php';
|
467 |
-
$htmlconverter = new ES_Html2Text( $html, array( 'width' => 200, 'do_links' => 'table' ) );
|
468 |
-
|
469 |
-
$text = trim( $htmlconverter->get_text() );
|
470 |
-
$text = preg_replace( '/\s*$^\s*/mu', "\n\n", $text );
|
471 |
-
$text = preg_replace( '/[ \t]+/u', ' ', $text );
|
472 |
-
|
473 |
-
return $text;
|
474 |
-
|
475 |
-
}
|
476 |
-
|
477 |
-
}
|
478 |
-
|
479 |
-
/**
|
480 |
-
* Replace links with tracking link
|
481 |
-
*
|
482 |
-
* @param $content
|
483 |
-
* @param $data
|
484 |
-
*
|
485 |
-
* @return string|string[]|null
|
486 |
-
*
|
487 |
-
* @since 4.2.4
|
488 |
-
*/
|
489 |
-
public static function replace_links( $content, $data ) {
|
490 |
-
|
491 |
-
// get all links from the basecontent
|
492 |
-
preg_match_all( '# href=(\'|")?(https?[^\'"]+)(\'|")?#', $content, $links );
|
493 |
-
$links = $links[2];
|
494 |
-
|
495 |
-
if ( empty( $links ) ) {
|
496 |
-
return $content;
|
497 |
-
}
|
498 |
-
|
499 |
-
$inserted_links = array();
|
500 |
-
|
501 |
-
$campaign_id = ! empty( $data['campaign_id'] ) ? $data['campaign_id'] : 0;
|
502 |
-
$message_id = ! empty( $data['message_id'] ) ? $data['message_id'] : 0;
|
503 |
-
|
504 |
-
foreach ( $links as $link ) {
|
505 |
-
|
506 |
-
if ( ! isset( $inserted_links[ $link ] ) ) {
|
507 |
-
$index = 0;
|
508 |
-
} else {
|
509 |
-
$index = $inserted_links[ $link ] + 1;
|
510 |
-
}
|
511 |
-
|
512 |
-
$inserted_links[ $link ] = $index;
|
513 |
-
$result = ES()->links_db->get_link_by_campaign_id( $link, $campaign_id, $message_id, $index );
|
514 |
-
|
515 |
-
if ( is_array( $result ) && count( $result ) > 0 ) {
|
516 |
-
$hash = $result[0]['hash'];
|
517 |
-
} else {
|
518 |
-
|
519 |
-
$hash = ES_Common::generate_hash( 12 );
|
520 |
-
|
521 |
-
$link_data = array(
|
522 |
-
'link' => $link,
|
523 |
-
'message_id' => $message_id,
|
524 |
-
'campaign_id' => $campaign_id,
|
525 |
-
'hash' => $hash,
|
526 |
-
'i' => $index
|
527 |
-
);
|
528 |
-
|
529 |
-
$insert = ES()->links_db->insert( $link_data );
|
530 |
-
}
|
531 |
-
|
532 |
-
$data['link_hash'] = $hash;
|
533 |
-
|
534 |
-
$new_link = self::prepare_link( $data );
|
535 |
-
|
536 |
-
$link = ' href="' . $link . '"';
|
537 |
-
$new_link = ' href="' . $new_link . '"';
|
538 |
-
|
539 |
-
if ( ( $pos = strpos( $content, $link ) ) !== false ) {
|
540 |
-
$content = preg_replace( '/' . preg_quote( $link, '/' ) . '/', $new_link, $content, 1 );
|
541 |
-
}
|
542 |
-
}
|
543 |
-
|
544 |
-
return $content;
|
545 |
-
}
|
546 |
-
|
547 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lite/includes/classes/class-es-cron.php
CHANGED
@@ -25,9 +25,6 @@ class ES_Cron {
|
|
25 |
|
26 |
add_filter( 'cron_schedules', array( &$this, 'cron_schedules' ) );
|
27 |
|
28 |
-
// Not using anymore...remain for backward compatibility to avoid PHP warnings.
|
29 |
-
add_action( 'ig_es_cron_fifteen_mins', array( &$this, 'ig_es_cron_fifteen_mins_callback' ), 10, 2 );
|
30 |
-
|
31 |
add_action( 'ig_es_cron', array( &$this, 'hourly' ) );
|
32 |
add_action( 'ig_es_cron_worker', array( &$this, 'handler' ), - 1 );
|
33 |
|
@@ -38,17 +35,6 @@ class ES_Cron {
|
|
38 |
$this->handle_cron_request();
|
39 |
}
|
40 |
|
41 |
-
public function ig_es_cron_fifteen_mins_callback( $es = '', $guid = '' ) {
|
42 |
-
/**
|
43 |
-
* We are not using ig_es_cron_fifteen_mins action anymore.
|
44 |
-
*
|
45 |
-
* This function was attached to ig_es_cron_fifteen_mins cron
|
46 |
-
*
|
47 |
-
* @since 4.3.1
|
48 |
-
*/
|
49 |
-
}
|
50 |
-
|
51 |
-
|
52 |
/**
|
53 |
* Schedule/ Clear Cronjob
|
54 |
*
|
@@ -163,6 +149,30 @@ class ES_Cron {
|
|
163 |
update_option( 'ig_es_cron_lock_' . $key, false, false );
|
164 |
}
|
165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
/**
|
167 |
* Check If Cron Locked
|
168 |
*
|
@@ -247,6 +257,33 @@ class ES_Cron {
|
|
247 |
return $cron_url;
|
248 |
}
|
249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
/**
|
251 |
* Handler
|
252 |
*
|
@@ -301,7 +338,12 @@ class ES_Cron {
|
|
301 |
|
302 |
$self = ig_es_get_request_data( 'self', 0 );
|
303 |
|
304 |
-
|
|
|
|
|
|
|
|
|
|
|
305 |
|
306 |
if ( ! empty( $guid ) ) {
|
307 |
|
@@ -325,27 +367,41 @@ class ES_Cron {
|
|
325 |
// Now, all check pass.
|
326 |
if ( $guid === $output['guid'] ) {
|
327 |
|
328 |
-
//
|
329 |
-
if (
|
330 |
-
|
331 |
}
|
332 |
|
333 |
-
|
334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
|
336 |
-
|
337 |
-
|
338 |
|
339 |
-
|
340 |
-
|
341 |
|
342 |
-
|
343 |
-
|
344 |
-
$response['message'] = 'EMAILS_SENT';
|
345 |
-
$response['status'] = 'SUCCESS';
|
346 |
|
347 |
-
|
348 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
|
350 |
} else {
|
351 |
$self = false;
|
@@ -428,6 +484,7 @@ class ES_Cron {
|
|
428 |
'EMPTY_CRON_GUID' => __( 'GUID is empty.', 'email-subscribers' ),
|
429 |
'PLEASE_TRY_AGAIN_LATER' => __( 'Please try after sometime.', 'email-subscribers' ),
|
430 |
'EMAIL_SENDING_LIMIT_EXCEEDED' => __( 'You have hit your hourly email sending limit. Please try after sometime.', 'email-subscribers' ),
|
|
|
431 |
);
|
432 |
|
433 |
$message_text = ! empty( $status_messages[ $message ] ) ? $status_messages[ $message ] : '';
|
25 |
|
26 |
add_filter( 'cron_schedules', array( &$this, 'cron_schedules' ) );
|
27 |
|
|
|
|
|
|
|
28 |
add_action( 'ig_es_cron', array( &$this, 'hourly' ) );
|
29 |
add_action( 'ig_es_cron_worker', array( &$this, 'handler' ), - 1 );
|
30 |
|
35 |
$this->handle_cron_request();
|
36 |
}
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
/**
|
39 |
* Schedule/ Clear Cronjob
|
40 |
*
|
149 |
update_option( 'ig_es_cron_lock_' . $key, false, false );
|
150 |
}
|
151 |
|
152 |
+
/**
|
153 |
+
* Should Unlock Cron?
|
154 |
+
*
|
155 |
+
* @param bool $force
|
156 |
+
*
|
157 |
+
* @return bool
|
158 |
+
*
|
159 |
+
* @since 4.3.3
|
160 |
+
*/
|
161 |
+
public function should_unlock( $force = false ) {
|
162 |
+
|
163 |
+
if ( $force ) {
|
164 |
+
return true;
|
165 |
+
}
|
166 |
+
|
167 |
+
$cron_last_hit = $this->get_last_hit();
|
168 |
+
|
169 |
+
// Initially we don't have timetamp data. So, set as 900 to unlock cron lock
|
170 |
+
$time_lapsed = isset( $cron_last_hit['timestamp'] ) ? ( round( time() - $cron_last_hit['timestamp'] ) ) : 900;
|
171 |
+
|
172 |
+
return $time_lapsed > ( 10 * MINUTE_IN_SECONDS );
|
173 |
+
}
|
174 |
+
|
175 |
+
|
176 |
/**
|
177 |
* Check If Cron Locked
|
178 |
*
|
257 |
return $cron_url;
|
258 |
}
|
259 |
|
260 |
+
/**
|
261 |
+
* Set Cron Last Hit data
|
262 |
+
*
|
263 |
+
* @return bool
|
264 |
+
*
|
265 |
+
* @since 4.3.3
|
266 |
+
*/
|
267 |
+
public function set_last_hit() {
|
268 |
+
|
269 |
+
$last_hit = array();
|
270 |
+
|
271 |
+
$last_hit['timestamp'] = time();
|
272 |
+
|
273 |
+
return update_option( 'ig_es_cron_last_hit', $last_hit );
|
274 |
+
}
|
275 |
+
|
276 |
+
/**
|
277 |
+
* Get Cron Last Hit data
|
278 |
+
*
|
279 |
+
* @return mixed|void
|
280 |
+
*
|
281 |
+
* @since 4.3.3
|
282 |
+
*/
|
283 |
+
public function get_last_hit() {
|
284 |
+
return get_option( 'ig_es_cron_last_hit', array() );
|
285 |
+
}
|
286 |
+
|
287 |
/**
|
288 |
* Handler
|
289 |
*
|
338 |
|
339 |
$self = ig_es_get_request_data( 'self', 0 );
|
340 |
|
341 |
+
$verified_self = false;
|
342 |
+
if ( $self == 1 && wp_verify_nonce( ig_es_get_request_data( '_wpnonce' ), 'ig_es_self_cron' ) ) {
|
343 |
+
$verified_self = true;
|
344 |
+
}
|
345 |
+
|
346 |
+
if ( 0 == $self || $verified_self ) {
|
347 |
|
348 |
if ( ! empty( $guid ) ) {
|
349 |
|
367 |
// Now, all check pass.
|
368 |
if ( $guid === $output['guid'] ) {
|
369 |
|
370 |
+
// Should I unlock cron?
|
371 |
+
if ( $this->should_unlock( $verified_self ) ) {
|
372 |
+
$this->unlock();
|
373 |
}
|
374 |
|
375 |
+
if ( ! $this->is_locked() ) {
|
376 |
+
|
377 |
+
// Set Last Hit time.
|
378 |
+
$this->set_last_hit();
|
379 |
+
|
380 |
+
// Release WP_CRON if it should
|
381 |
+
if ( wp_next_scheduled( 'ig_es_cron' ) - $execution_start_time < 0 ) {
|
382 |
+
spawn_cron();
|
383 |
+
}
|
384 |
|
385 |
+
// Lock Cron to avoid duplicate
|
386 |
+
$this->lock();
|
387 |
|
388 |
+
// Queue Auto Responder
|
389 |
+
do_action( 'ig_es_cron_auto_responder' );
|
390 |
|
391 |
+
// Worker
|
392 |
+
do_action( 'ig_es_cron_worker' );
|
|
|
|
|
393 |
|
394 |
+
$response['total_emails_sent'] = get_transient( 'ig_es_total_emails_sent' );
|
395 |
+
$response['es_remaining_email_count'] = get_transient( 'ig_es_remaining_email_count' );
|
396 |
+
$response['message'] = 'EMAILS_SENT';
|
397 |
+
$response['status'] = 'SUCCESS';
|
398 |
+
|
399 |
+
// Unlock it.
|
400 |
+
$this->unlock();
|
401 |
+
} else {
|
402 |
+
$response['status'] = 'ERROR';
|
403 |
+
$response['message'] = 'CRON_LOCK_ENABLED';
|
404 |
+
}
|
405 |
|
406 |
} else {
|
407 |
$self = false;
|
484 |
'EMPTY_CRON_GUID' => __( 'GUID is empty.', 'email-subscribers' ),
|
485 |
'PLEASE_TRY_AGAIN_LATER' => __( 'Please try after sometime.', 'email-subscribers' ),
|
486 |
'EMAIL_SENDING_LIMIT_EXCEEDED' => __( 'You have hit your hourly email sending limit. Please try after sometime.', 'email-subscribers' ),
|
487 |
+
'CRON_LOCK_ENABLED' => __( 'Cron lock enabled. Please try after sometime.', 'email-subscribers' ),
|
488 |
);
|
489 |
|
490 |
$message_text = ! empty( $status_messages[ $message ] ) ? $status_messages[ $message ] : '';
|
lite/includes/classes/class-es-handle-post-notification.php
CHANGED
@@ -179,7 +179,7 @@ class ES_Handle_Post_Notification {
|
|
179 |
|
180 |
$post_title = get_the_title( $post );
|
181 |
$es_templ_body = str_replace( '{{POSTTITLE}}', $post_title, $es_templ_body );
|
182 |
-
$post_link
|
183 |
|
184 |
// Size of {{POSTIMAGE}}
|
185 |
$post_thumbnail = "";
|
@@ -238,11 +238,13 @@ class ES_Handle_Post_Notification {
|
|
238 |
$post_full = $post->post_content;
|
239 |
$post_full = wpautop( $post_full );
|
240 |
$es_templ_body = str_replace( '{{POSTFULL}}', $post_full, $es_templ_body );
|
|
|
241 |
// add pre header as post excerpt
|
242 |
-
if( !empty($post_excerpt) ){
|
243 |
-
|
244 |
}
|
245 |
-
|
|
|
246 |
$es_templ_body = ES_Common::es_process_template_body( $es_templ_body, $email_template_id );
|
247 |
}
|
248 |
|
@@ -250,14 +252,15 @@ class ES_Handle_Post_Notification {
|
|
250 |
}
|
251 |
|
252 |
public static function refresh_post_content( $content, $args ) {
|
253 |
-
|
254 |
-
|
255 |
$post = get_post( $post_id );
|
256 |
$template_id = ES()->campaigns_db->get_template_id_by_campaign( $campaign_id );
|
257 |
$template = get_post( $template_id );
|
258 |
$template_content = $template->post_content;
|
259 |
$content['subject'] = self::prepare_subject( $post, $template );
|
260 |
$content['body'] = self::prepare_body( $template_content, $post_id, $template_id );
|
|
|
261 |
return $content;
|
262 |
}
|
263 |
|
179 |
|
180 |
$post_title = get_the_title( $post );
|
181 |
$es_templ_body = str_replace( '{{POSTTITLE}}', $post_title, $es_templ_body );
|
182 |
+
$post_link = get_permalink( $post_id );
|
183 |
|
184 |
// Size of {{POSTIMAGE}}
|
185 |
$post_thumbnail = "";
|
238 |
$post_full = $post->post_content;
|
239 |
$post_full = wpautop( $post_full );
|
240 |
$es_templ_body = str_replace( '{{POSTFULL}}', $post_full, $es_templ_body );
|
241 |
+
|
242 |
// add pre header as post excerpt
|
243 |
+
if ( ! empty( $post_excerpt ) ) {
|
244 |
+
//$es_templ_body = '<span class="es_preheader" style="display: none !important; visibility: hidden; opacity: 0; color: transparent; height: 0; width: 0;">' . $post_excerpt . '</span>' . $es_templ_body;
|
245 |
}
|
246 |
+
|
247 |
+
if ( $email_template_id > 0 ) {
|
248 |
$es_templ_body = ES_Common::es_process_template_body( $es_templ_body, $email_template_id );
|
249 |
}
|
250 |
|
252 |
}
|
253 |
|
254 |
public static function refresh_post_content( $content, $args ) {
|
255 |
+
$campaign_id = $args['campaign_id'];
|
256 |
+
$post_id = $args['post_id'];
|
257 |
$post = get_post( $post_id );
|
258 |
$template_id = ES()->campaigns_db->get_template_id_by_campaign( $campaign_id );
|
259 |
$template = get_post( $template_id );
|
260 |
$template_content = $template->post_content;
|
261 |
$content['subject'] = self::prepare_subject( $post, $template );
|
262 |
$content['body'] = self::prepare_body( $template_content, $post_id, $template_id );
|
263 |
+
|
264 |
return $content;
|
265 |
}
|
266 |
|
lite/includes/classes/class-es-handle-subscription.php
CHANGED
@@ -306,7 +306,8 @@ if ( ! class_exists( 'ES_Handle_Subscription' ) ) {
|
|
306 |
if ( ! $this->from_rainmaker ) {
|
307 |
|
308 |
// Honeypot validation
|
309 |
-
|
|
|
310 |
if ( ! isset( $data[ $hp_key ] ) || ! empty( $data[ $hp_key ] ) ) {
|
311 |
$es_response['message'] = 'es_unexpected_error_notice';
|
312 |
|
306 |
if ( ! $this->from_rainmaker ) {
|
307 |
|
308 |
// Honeypot validation
|
309 |
+
//$hp_key = "esfpx_es_hp" . wp_create_nonce( 'es_hp' );
|
310 |
+
$hp_key = "esfpx_es_hp_email";
|
311 |
if ( ! isset( $data[ $hp_key ] ) || ! empty( $data[ $hp_key ] ) ) {
|
312 |
$es_response['message'] = 'es_unexpected_error_notice';
|
313 |
|
lite/includes/classes/class-es-mailer.php
CHANGED
@@ -181,9 +181,19 @@ if ( ! class_exists( 'ES_Mailer' ) ) {
|
|
181 |
|
182 |
if ( ! empty( $admin_emails ) && is_array( $admin_emails ) && count( $admin_emails ) > 0 ) {
|
183 |
|
|
|
|
|
|
|
|
|
184 |
$subject = $this->get_admin_new_contact_email_subject();
|
|
|
185 |
$content = $this->get_admin_new_contact_email_content();
|
186 |
|
|
|
|
|
|
|
|
|
|
|
187 |
$this->add_unsubscribe_link = false;
|
188 |
$this->add_tracking_pixel = false;
|
189 |
$this->send( $subject, $content, $admin_emails, $data );
|
@@ -585,6 +595,8 @@ if ( ! class_exists( 'ES_Mailer' ) ) {
|
|
585 |
$response['status'] = 'ERROR';
|
586 |
$response['message'] = $send_response->get_error_messages();
|
587 |
|
|
|
|
|
588 |
//TODO: Log somewhere
|
589 |
} else {
|
590 |
// Successfully Sent Email
|
@@ -665,10 +677,11 @@ if ( ! class_exists( 'ES_Mailer' ) ) {
|
|
665 |
|
666 |
$message->body_text = $this->convert_to_text( $message->body );
|
667 |
|
|
|
|
|
668 |
$campaign_id = ! empty( $merge_tags['campaign_id'] ) ? $merge_tags['campaign_id'] : 0;
|
669 |
-
|
670 |
$message->body = $this->set_pre_header_text( $message->body, $campaign_id );
|
671 |
-
|
672 |
return $message;
|
673 |
}
|
674 |
|
@@ -747,6 +760,15 @@ if ( ! class_exists( 'ES_Mailer' ) ) {
|
|
747 |
return $content;
|
748 |
}
|
749 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
750 |
public function get_contact_merge_tags( $contact_id = 0 ) {
|
751 |
$merge_tags = array();
|
752 |
|
181 |
|
182 |
if ( ! empty( $admin_emails ) && is_array( $admin_emails ) && count( $admin_emails ) > 0 ) {
|
183 |
|
184 |
+
$name = ! empty( $data['name'] ) ? $data['name'] : '';
|
185 |
+
$email = ! empty( $data['email'] ) ? $data['email'] : '';
|
186 |
+
$list = ! empty( $data['list_name'] ) ? $data['list_name'] : '';
|
187 |
+
|
188 |
$subject = $this->get_admin_new_contact_email_subject();
|
189 |
+
|
190 |
$content = $this->get_admin_new_contact_email_content();
|
191 |
|
192 |
+
$content = str_replace( '{{NAME}}', $name, $content );
|
193 |
+
$content = str_replace( '{{EMAIL}}', $email, $content );
|
194 |
+
$content = str_replace( '{{GROUP}}', '{{LIST}}', $content );
|
195 |
+
$content = str_replace( '{{LIST}}', $list, $content );
|
196 |
+
|
197 |
$this->add_unsubscribe_link = false;
|
198 |
$this->add_tracking_pixel = false;
|
199 |
$this->send( $subject, $content, $admin_emails, $data );
|
595 |
$response['status'] = 'ERROR';
|
596 |
$response['message'] = $send_response->get_error_messages();
|
597 |
|
598 |
+
do_action( 'ig_es_email_sending_error', $contact_id, $campaign_id, $message_id, $response );
|
599 |
+
|
600 |
//TODO: Log somewhere
|
601 |
} else {
|
602 |
// Successfully Sent Email
|
677 |
|
678 |
$message->body_text = $this->convert_to_text( $message->body );
|
679 |
|
680 |
+
/*
|
681 |
+
* TODO: Enable after Fixing preheader issue.
|
682 |
$campaign_id = ! empty( $merge_tags['campaign_id'] ) ? $merge_tags['campaign_id'] : 0;
|
|
|
683 |
$message->body = $this->set_pre_header_text( $message->body, $campaign_id );
|
684 |
+
*/
|
685 |
return $message;
|
686 |
}
|
687 |
|
760 |
return $content;
|
761 |
}
|
762 |
|
763 |
+
/**
|
764 |
+
* Get contact merge tags
|
765 |
+
*
|
766 |
+
* @param int $contact_id
|
767 |
+
*
|
768 |
+
* @return array
|
769 |
+
*
|
770 |
+
* @since 4.3.2
|
771 |
+
*/
|
772 |
public function get_contact_merge_tags( $contact_id = 0 ) {
|
773 |
$merge_tags = array();
|
774 |
|
lite/includes/classes/class-es-newsletters.php
CHANGED
@@ -30,35 +30,35 @@ class ES_Newsletters {
|
|
30 |
|
31 |
public function es_newsletters_settings_callback() {
|
32 |
|
33 |
-
|
34 |
-
$submitted
|
35 |
-
$preview
|
36 |
$broadcast_data = ig_es_get_request_data( 'broadcast_data', array(), false );
|
37 |
-
if( 'preview' !== $preview ){
|
38 |
if ( 'submitted' === $submitted ) {
|
39 |
|
40 |
// $email_sent_type = __('Active', 'email-subscribers');
|
41 |
-
$list_id = !empty($broadcast_data['list_ids']) ? $broadcast_data['list_ids'] : ''
|
42 |
-
$template_id
|
43 |
-
$subject
|
44 |
// $template_id = ig_es_get_request_data( 'ig_es_broadcast_base_template_id' );
|
45 |
-
if ( empty( $broadcast_data['body']) ) {
|
46 |
-
|
47 |
$message = __( 'Please add message body or select template', 'email-subscribers' );
|
48 |
ES_Common::show_message( $message, 'error' );
|
49 |
} elseif ( empty( $list_id ) ) {
|
50 |
$message = __( 'Please select list.', 'email-subscribers' );
|
51 |
ES_Common::show_message( $message, 'error' );
|
52 |
-
}
|
53 |
$message = __( 'Please add the subject', 'email-subscribers' );
|
54 |
ES_Common::show_message( $message, 'error' );
|
55 |
-
}else {
|
56 |
$broadcast_data['base_template_id'] = $template_id;
|
57 |
-
$broadcast_data['list_ids']
|
58 |
-
$broadcast_data['status']
|
59 |
-
$meta
|
60 |
-
$meta['pre_header']
|
61 |
-
$broadcast_data['meta']
|
62 |
self::es_send_email_callback( $broadcast_data );
|
63 |
|
64 |
$reports_url = admin_url( 'admin.php?page=es_reports' );
|
@@ -73,16 +73,16 @@ class ES_Newsletters {
|
|
73 |
}
|
74 |
|
75 |
$this->prepare_newsletter_settings_form();
|
76 |
-
}
|
77 |
// $broadcast_data = ig_es_get_request_data( 'broadcast_data', array(), false );
|
78 |
if ( empty( $broadcast_data['body'] ) ) {
|
79 |
$message = __( 'Please add message content', 'email-subscribers' );
|
80 |
ES_Common::show_message( $message, 'error' );
|
81 |
$this->prepare_newsletter_settings_form();
|
82 |
-
} else{
|
83 |
//content validation
|
84 |
-
$template_data['content']
|
85 |
-
$template_data['template_id'] = !empty($broadcast_data['template_id']) ? $broadcast_data['template_id'] : '';
|
86 |
$this->es_broadcast_preview_callback( $template_data );
|
87 |
|
88 |
}
|
@@ -92,9 +92,9 @@ class ES_Newsletters {
|
|
92 |
|
93 |
public function prepare_newsletter_settings_form() {
|
94 |
$newsletter_data = array();
|
95 |
-
$templates
|
96 |
-
$lists
|
97 |
-
$from_email
|
98 |
|
99 |
?>
|
100 |
|
@@ -105,53 +105,53 @@ class ES_Newsletters {
|
|
105 |
</h2>
|
106 |
<div class="es-form" style="width: 100%;">
|
107 |
<form method="post" action="#">
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
<?php
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
wp_editor( $body, 'edit-es-boradcast-body', $editor_args ); ?>
|
137 |
-
|
138 |
-
<?php do_action( 'ig_es_after_broadcast_left_pan_settings'); ?>
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
<?php do_action( 'ig_es_after_broadcast_right_pan_settings'); ?>
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
</form>
|
156 |
</div>
|
157 |
<div clas="es-preview" style="float: right;width: 19%;">
|
@@ -166,13 +166,13 @@ class ES_Newsletters {
|
|
166 |
|
167 |
public static function es_send_email_callback( $data ) {
|
168 |
|
169 |
-
|
170 |
|
171 |
$title = get_the_title( $data['base_template_id'] );
|
172 |
|
173 |
-
$data['type']
|
174 |
-
$data['name']
|
175 |
-
$data['slug']
|
176 |
|
177 |
$data = apply_filters( 'ig_es_broadcast_data', $data );
|
178 |
|
@@ -215,12 +215,13 @@ class ES_Newsletters {
|
|
215 |
|
216 |
}
|
217 |
|
218 |
-
public static function refresh_newsletter_content( $content, $args) {
|
219 |
-
$campaign_id
|
220 |
$template_id = ES()->campaigns_db->get_template_id_by_campaign( $campaign_id );
|
221 |
$content['subject'] = ES()->campaigns_db->get_column( 'subject', $campaign_id );
|
222 |
-
$content['body']
|
223 |
$content['body'] = ES_Common::es_process_template_body( $content['body'], $template_id, $campaign_id );
|
|
|
224 |
return $content;
|
225 |
}
|
226 |
|
@@ -232,17 +233,17 @@ class ES_Newsletters {
|
|
232 |
return self::$instance;
|
233 |
}
|
234 |
|
235 |
-
|
236 |
|
237 |
$template_id = $template_data['template_id'];
|
238 |
-
if ( !empty($template_data['content'] )) {
|
239 |
$current_user = wp_get_current_user();
|
240 |
$username = $current_user->user_login;
|
241 |
$useremail = $current_user->user_email;
|
242 |
|
243 |
-
$es_template_body = $template_data['content']
|
244 |
|
245 |
-
$es_template_body = ES_Common::es_process_template_body( $es_template_body
|
246 |
$es_template_body = str_replace( '{{NAME}}', $username, $es_template_body );
|
247 |
$es_template_body = str_replace( '{{EMAIL}}', $useremail, $es_template_body );
|
248 |
|
30 |
|
31 |
public function es_newsletters_settings_callback() {
|
32 |
|
33 |
+
|
34 |
+
$submitted = ig_es_get_request_data( 'submitted' );
|
35 |
+
$preview = ig_es_get_request_data( 'es_broadcast_preview' );
|
36 |
$broadcast_data = ig_es_get_request_data( 'broadcast_data', array(), false );
|
37 |
+
if ( 'preview' !== $preview ) {
|
38 |
if ( 'submitted' === $submitted ) {
|
39 |
|
40 |
// $email_sent_type = __('Active', 'email-subscribers');
|
41 |
+
$list_id = ! empty( $broadcast_data['list_ids'] ) ? $broadcast_data['list_ids'] : '';
|
42 |
+
$template_id = ! empty( $broadcast_data['template_id'] ) ? $broadcast_data['template_id'] : '';
|
43 |
+
$subject = ! empty( $broadcast_data['subject'] ) ? $broadcast_data['subject'] : '';
|
44 |
// $template_id = ig_es_get_request_data( 'ig_es_broadcast_base_template_id' );
|
45 |
+
if ( empty( $broadcast_data['body'] ) ) {
|
46 |
+
// if ( empty( $template_id) ) {
|
47 |
$message = __( 'Please add message body or select template', 'email-subscribers' );
|
48 |
ES_Common::show_message( $message, 'error' );
|
49 |
} elseif ( empty( $list_id ) ) {
|
50 |
$message = __( 'Please select list.', 'email-subscribers' );
|
51 |
ES_Common::show_message( $message, 'error' );
|
52 |
+
} elseif ( empty( $subject ) ) {
|
53 |
$message = __( 'Please add the subject', 'email-subscribers' );
|
54 |
ES_Common::show_message( $message, 'error' );
|
55 |
+
} else {
|
56 |
$broadcast_data['base_template_id'] = $template_id;
|
57 |
+
$broadcast_data['list_ids'] = $list_id;
|
58 |
+
$broadcast_data['status'] = 1;
|
59 |
+
$meta = ! empty( $broadcast_data['meta'] ) ? $broadcast_data['meta'] : array();
|
60 |
+
$meta['pre_header'] = $broadcast_data['pre_header'];
|
61 |
+
$broadcast_data['meta'] = maybe_serialize( $meta );
|
62 |
self::es_send_email_callback( $broadcast_data );
|
63 |
|
64 |
$reports_url = admin_url( 'admin.php?page=es_reports' );
|
73 |
}
|
74 |
|
75 |
$this->prepare_newsletter_settings_form();
|
76 |
+
} elseif ( 'preview' === $preview ) {
|
77 |
// $broadcast_data = ig_es_get_request_data( 'broadcast_data', array(), false );
|
78 |
if ( empty( $broadcast_data['body'] ) ) {
|
79 |
$message = __( 'Please add message content', 'email-subscribers' );
|
80 |
ES_Common::show_message( $message, 'error' );
|
81 |
$this->prepare_newsletter_settings_form();
|
82 |
+
} else {
|
83 |
//content validation
|
84 |
+
$template_data['content'] = ! empty( $broadcast_data['body'] ) ? $broadcast_data['body'] : '';
|
85 |
+
$template_data['template_id'] = ! empty( $broadcast_data['template_id'] ) ? $broadcast_data['template_id'] : '';
|
86 |
$this->es_broadcast_preview_callback( $template_data );
|
87 |
|
88 |
}
|
92 |
|
93 |
public function prepare_newsletter_settings_form() {
|
94 |
$newsletter_data = array();
|
95 |
+
$templates = ES_Common::prepare_templates_dropdown_options( 'newsletter' );
|
96 |
+
$lists = ES_Common::prepare_list_dropdown_options();
|
97 |
+
$from_email = ES_Common::get_ig_option( 'from_email' );
|
98 |
|
99 |
?>
|
100 |
|
105 |
</h2>
|
106 |
<div class="es-form" style="width: 100%;">
|
107 |
<form method="post" action="#">
|
108 |
+
<div class="es_newsletters_settings_wrapper">
|
109 |
+
<div class="es_campaign_name_wrapper ">
|
110 |
+
<input placeholder="Add Broadcast name" type="text" class="es_newsletter_name" name="broadcast_data[name]" value="">
|
111 |
+
<input id="ig_es_campaign_submit_button" class="es_primary_btn" type="submit" name="submit" value="Send Broadcast">
|
112 |
+
<input type="hidden" name="submitted" value="submitted">
|
113 |
+
</div>
|
114 |
+
<div class="es_settings_left_pan">
|
115 |
+
<div class="es_settings_field">
|
116 |
+
<label><?php _e( 'From Email', 'email-subscribers' ) ?><br/><input type="email" name="broadcast_data[from_email]" value="<?php echo $from_email; ?>"/></label>
|
117 |
+
</div>
|
118 |
+
<div class="es_settings_field">
|
119 |
+
<label><?php _e( 'Design template', 'email-subscribers' ) ?><br/><select name="broadcast_data[template_id]" id="base_template_id"><?php echo $templates ?></select></label>
|
120 |
+
</div>
|
121 |
+
<div class="es_settings_field"><label><?php _e( 'Subject', 'email-subscribers' ) ?><br/><input type="text" id="ig_es_broadcast_subject" name="broadcast_data[subject]" placeholder="<?php _e( 'New Broadcast', 'email-subscribers' ) ?>"/></label></div>
|
122 |
+
<div class="es_settings_field"><label><?php _e( 'Pre Header', 'email-subscribers' ) ?><br/><input placeholder="<?php _e( 'Add Pre header', 'email-subscribers' ); ?>" type="text" name="broadcast_data[pre_header]"/></label></div>
|
123 |
+
<div class="es_settings_field">
|
124 |
+
<label><?php _e( 'Body', 'email-subscribers' ); ?></label>
|
125 |
+
<?php
|
126 |
+
$body = ! empty( $broadcast_data['body'] ) ? $broadcast_data['body'] : '';
|
127 |
+
$editor_args = array(
|
128 |
+
'textarea_name' => 'broadcast_data[body]',
|
129 |
+
'textarea_rows' => 40,
|
130 |
+
'editor_class' => 'wp-editor-content',
|
131 |
+
'media_buttons' => true,
|
132 |
+
'tinymce' => true,
|
133 |
+
'quicktags' => true,
|
134 |
+
'editor_class' => 'wp-editor-boradcast'
|
135 |
+
);
|
136 |
wp_editor( $body, 'edit-es-boradcast-body', $editor_args ); ?>
|
137 |
+
</div>
|
138 |
+
<?php do_action( 'ig_es_after_broadcast_left_pan_settings' ); ?>
|
139 |
+
</div>
|
140 |
+
<div class="es_settings_right_pan">
|
141 |
+
<div class="es_settings_field">
|
142 |
+
<label><?php _e( 'Recipients', 'email-subscribers' ) ?><br/><select name="broadcast_data[list_ids]" id="ig_es_broadcast_list_ids"><?php echo $lists ?></select></label>
|
143 |
+
</div>
|
144 |
+
<hr>
|
145 |
+
<div class="es_settings_field">
|
146 |
+
<label>
|
147 |
+
<input class="es_secondary_btn" type="submit" id="ig_es_preview_broadcast" value="<?php _e( 'Preview this email in browser', 'email-subscribers' ) ?>">
|
148 |
+
<input type="hidden" name="es_broadcast_preview" id="es_broadcast_preview">
|
149 |
+
</label>
|
150 |
+
</div>
|
151 |
+
<?php do_action( 'ig_es_after_broadcast_right_pan_settings' ); ?>
|
152 |
+
</div>
|
153 |
+
|
154 |
+
</div>
|
155 |
</form>
|
156 |
</div>
|
157 |
<div clas="es-preview" style="float: right;width: 19%;">
|
166 |
|
167 |
public static function es_send_email_callback( $data ) {
|
168 |
|
169 |
+
$list_id = ! empty( $data['list_ids'] ) ? $data['list_ids'] : '';
|
170 |
|
171 |
$title = get_the_title( $data['base_template_id'] );
|
172 |
|
173 |
+
$data['type'] = 'newsletter';
|
174 |
+
$data['name'] = ! empty( $data['name'] ) ? $data['name'] : $data['subject'];
|
175 |
+
$data['slug'] = sanitize_title( sanitize_text_field( $data['name'] ) );
|
176 |
|
177 |
$data = apply_filters( 'ig_es_broadcast_data', $data );
|
178 |
|
215 |
|
216 |
}
|
217 |
|
218 |
+
public static function refresh_newsletter_content( $content, $args ) {
|
219 |
+
$campaign_id = $args['campaign_id'];
|
220 |
$template_id = ES()->campaigns_db->get_template_id_by_campaign( $campaign_id );
|
221 |
$content['subject'] = ES()->campaigns_db->get_column( 'subject', $campaign_id );
|
222 |
+
$content['body'] = ES()->campaigns_db->get_column( 'body', $campaign_id );
|
223 |
$content['body'] = ES_Common::es_process_template_body( $content['body'], $template_id, $campaign_id );
|
224 |
+
|
225 |
return $content;
|
226 |
}
|
227 |
|
233 |
return self::$instance;
|
234 |
}
|
235 |
|
236 |
+
public function es_broadcast_preview_callback( $template_data ) {
|
237 |
|
238 |
$template_id = $template_data['template_id'];
|
239 |
+
if ( ! empty( $template_data['content'] ) ) {
|
240 |
$current_user = wp_get_current_user();
|
241 |
$username = $current_user->user_login;
|
242 |
$useremail = $current_user->user_email;
|
243 |
|
244 |
+
$es_template_body = $template_data['content'];
|
245 |
|
246 |
+
$es_template_body = ES_Common::es_process_template_body( $es_template_body, $template_id );
|
247 |
$es_template_body = str_replace( '{{NAME}}', $username, $es_template_body );
|
248 |
$es_template_body = str_replace( '{{EMAIL}}', $useremail, $es_template_body );
|
249 |
|
lite/includes/classes/class-es-queue.php
CHANGED
@@ -39,6 +39,7 @@ if ( ! class_exists( 'ES_Queue' ) ) {
|
|
39 |
add_action( 'plugins_loaded', array( &$this, 'init' ), 1 );
|
40 |
|
41 |
add_action( 'ig_es_before_message_send', array( &$this, 'set_sending_status' ), 10, 3 );
|
|
|
42 |
add_action( 'ig_es_message_sent', array( &$this, 'set_sent_status' ), 10, 3 );
|
43 |
add_action( 'ig_es_message_sent', array( &$this, 'update_email_sent_count' ), 10, 3 );
|
44 |
}
|
@@ -502,6 +503,12 @@ if ( ! class_exists( 'ES_Queue' ) ) {
|
|
502 |
public function process_queue() {
|
503 |
global $wpdb;
|
504 |
|
|
|
|
|
|
|
|
|
|
|
|
|
505 |
$micro_time = microtime( true );
|
506 |
|
507 |
$ig_queue_table = IG_QUEUE_TABLE;
|
@@ -587,6 +594,13 @@ if ( ! class_exists( 'ES_Queue' ) ) {
|
|
587 |
* @since 4.3.1
|
588 |
*/
|
589 |
public function process_campaigns() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
590 |
/**
|
591 |
* - Get GUID from ig_es_mailing_queue table which are in queue
|
592 |
* - Get contacts from the ig_es_sending_queue table based on fetched guid
|
@@ -730,6 +744,23 @@ if ( ! class_exists( 'ES_Queue' ) ) {
|
|
730 |
}
|
731 |
}
|
732 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
733 |
}
|
734 |
}
|
735 |
|
39 |
add_action( 'plugins_loaded', array( &$this, 'init' ), 1 );
|
40 |
|
41 |
add_action( 'ig_es_before_message_send', array( &$this, 'set_sending_status' ), 10, 3 );
|
42 |
+
add_action( 'ig_es_email_sending_error', array( &$this, 'set_status_in_queue' ), 10, 4 );
|
43 |
add_action( 'ig_es_message_sent', array( &$this, 'set_sent_status' ), 10, 3 );
|
44 |
add_action( 'ig_es_message_sent', array( &$this, 'update_email_sent_count' ), 10, 3 );
|
45 |
}
|
503 |
public function process_queue() {
|
504 |
global $wpdb;
|
505 |
|
506 |
+
if ( ES()->cron->should_unlock() ) {
|
507 |
+
ES()->cron->unlock();
|
508 |
+
}
|
509 |
+
|
510 |
+
ES()->cron->set_last_hit();
|
511 |
+
|
512 |
$micro_time = microtime( true );
|
513 |
|
514 |
$ig_queue_table = IG_QUEUE_TABLE;
|
594 |
* @since 4.3.1
|
595 |
*/
|
596 |
public function process_campaigns() {
|
597 |
+
|
598 |
+
if ( ES()->cron->should_unlock() ) {
|
599 |
+
ES()->cron->unlock();
|
600 |
+
}
|
601 |
+
|
602 |
+
ES()->cron->set_last_hit();
|
603 |
+
|
604 |
/**
|
605 |
* - Get GUID from ig_es_mailing_queue table which are in queue
|
606 |
* - Get contacts from the ig_es_sending_queue table based on fetched guid
|
744 |
}
|
745 |
}
|
746 |
|
747 |
+
/**
|
748 |
+
* Set status in queue
|
749 |
+
*
|
750 |
+
* @param int $contact_id
|
751 |
+
* @param int $campaign_id
|
752 |
+
* @param int $message_id
|
753 |
+
* @param array $response
|
754 |
+
*
|
755 |
+
* @since 4.3.3
|
756 |
+
*/
|
757 |
+
public function set_status_in_queue( $contact_id = 0, $campaign_id = 0, $message_id = 0, $response = array() ) {
|
758 |
+
|
759 |
+
if ( 0 != $contact_id && 0 != $message_id ) {
|
760 |
+
$this->update_email_sent_status( $contact_id, $campaign_id, $message_id, 'In Queue' );
|
761 |
+
}
|
762 |
+
}
|
763 |
+
|
764 |
}
|
765 |
}
|
766 |
|
lite/public/class-email-subscribers-public.php
CHANGED
@@ -139,7 +139,6 @@ class Email_Subscribers_Public {
|
|
139 |
if ( ! empty( $hash ) ) {
|
140 |
|
141 |
$data = ig_es_decode_request_data( $hash );
|
142 |
-
|
143 |
$db_id = ! empty( $data['contact_id'] ) ? (int) $data['contact_id'] : 0;
|
144 |
$email = ! empty( $data['email'] ) ? $data['email'] : '';
|
145 |
$guid = ! empty( $data['guid'] ) ? $data['guid'] : '';
|
139 |
if ( ! empty( $hash ) ) {
|
140 |
|
141 |
$data = ig_es_decode_request_data( $hash );
|
|
|
142 |
$db_id = ! empty( $data['contact_id'] ) ? (int) $data['contact_id'] : 0;
|
143 |
$email = ! empty( $data['email'] ) ? $data['email'] : '';
|
144 |
$guid = ! empty( $data['guid'] ) ? $data['guid'] : '';
|
lite/public/partials/class-es-shortcode.php
CHANGED
@@ -222,7 +222,7 @@ class ES_Shortcode {
|
|
222 |
<input type="hidden" name="es_email_page_url" value="<?php echo $current_page_url; ?>"/>
|
223 |
<input type="hidden" name="status" value="Unconfirmed"/>
|
224 |
<input type="hidden" name="es-subscribe" id="es-subscribe" value="<?php echo $nonce; ?>"/>
|
225 |
-
<label style="<?php echo $hp_style; ?>"><input type="
|
226 |
<?php do_action( 'ig_es_after_form_fields' ) ?>
|
227 |
<?php if ( ( in_array( 'gdpr/gdpr.php', $active_plugins ) || array_key_exists( 'gdpr/gdpr.php', $active_plugins ) ) ) {
|
228 |
echo GDPR::consent_checkboxes();
|
222 |
<input type="hidden" name="es_email_page_url" value="<?php echo $current_page_url; ?>"/>
|
223 |
<input type="hidden" name="status" value="Unconfirmed"/>
|
224 |
<input type="hidden" name="es-subscribe" id="es-subscribe" value="<?php echo $nonce; ?>"/>
|
225 |
+
<label style="<?php echo $hp_style; ?>"><input type="email" name="es_hp_email" class="es_required_field" tabindex="-1" autocomplete="-1" value="" /></label>
|
226 |
<?php do_action( 'ig_es_after_form_fields' ) ?>
|
227 |
<?php if ( ( in_array( 'gdpr/gdpr.php', $active_plugins ) || array_key_exists( 'gdpr/gdpr.php', $active_plugins ) ) ) {
|
228 |
echo GDPR::consent_checkboxes();
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Author URI: https://www.icegram.com/
|
|
5 |
Tags: subscription, newsletter, email marketing, post notification, email newsletter form, email signup, email widget, newsletter signup, subscribe, subscription form, bulk emails, signup form, list builder, lead generation, welcome email, contacts
|
6 |
Requires at least: 3.9
|
7 |
Tested up to: 5.3
|
8 |
-
Stable tag: 4.3.
|
9 |
License: GPLv3
|
10 |
License URI: http://www.gnu.org/licenses
|
11 |
|
@@ -300,6 +300,10 @@ Refer [here](https://www.icegram.com/documentation/es-faq/).
|
|
300 |
|
301 |
== Changelog ==
|
302 |
|
|
|
|
|
|
|
|
|
303 |
**4.3.2 (20.11.2019)**
|
304 |
|
305 |
* New: Added basic reporting like total subscribed, unsubscribed, open in last 60 days in audience dashboard
|
5 |
Tags: subscription, newsletter, email marketing, post notification, email newsletter form, email signup, email widget, newsletter signup, subscribe, subscription form, bulk emails, signup form, list builder, lead generation, welcome email, contacts
|
6 |
Requires at least: 3.9
|
7 |
Tested up to: 5.3
|
8 |
+
Stable tag: 4.3.3
|
9 |
License: GPLv3
|
10 |
License URI: http://www.gnu.org/licenses
|
11 |
|
300 |
|
301 |
== Changelog ==
|
302 |
|
303 |
+
**4.3.3 (25.11.2019)**
|
304 |
+
* Fix: Cron Lock issue
|
305 |
+
* Fix: Honeypot issue with caching plugin
|
306 |
+
|
307 |
**4.3.2 (20.11.2019)**
|
308 |
|
309 |
* New: Added basic reporting like total subscribed, unsubscribed, open in last 60 days in audience dashboard
|