Official MailerLite Sign Up Forms - Version 1.0.8

Version Description

  • Fix shortcode popup
Download this release

Release Info

Developer mailerlite
Plugin Icon 128x128 Official MailerLite Sign Up Forms
Version 1.0.8
Comparing to
See all releases

Code changes from version 1.0.7 to 1.0.8

include/mailerlite-admin.php CHANGED
@@ -3,15 +3,17 @@
3
  require_once MAILERLITE_PLUGIN_DIR . "libs/mailerlite_rest/ML_Lists.php";
4
  require_once MAILERLITE_PLUGIN_DIR . "libs/mailerlite_rest/ML_Webforms.php";
5
 
6
- class MailerLite_Admin {
 
7
 
8
  private static $initiated = false;
9
- private static $api_key = false;
10
 
11
  /**
12
  * Initialization method
13
  */
14
- public static function init() {
 
15
 
16
  global $mailerlite_error;
17
 
@@ -19,11 +21,15 @@ class MailerLite_Admin {
19
 
20
  self::$api_key = get_option('mailerlite_api_key');
21
 
22
- if ( ! self::$initiated ) {
 
23
  self::init_hooks();
24
  }
25
 
26
- if ( isset( $_POST['action'] ) && $_POST['action'] == 'enter-mailerlite-key' ) {
 
 
 
27
  self::set_api_key();
28
  }
29
  }
@@ -31,41 +37,68 @@ class MailerLite_Admin {
31
  /**
32
  * Adds admin stuff
33
  */
34
- private static function init_hooks() {
 
35
 
36
  self::$initiated = true;
37
 
38
- add_action('admin_init', array('MailerLite_Admin', 'mailerlite_admin_init_setting'));
39
- add_action('admin_menu', array('MailerLite_Admin', 'mailerlite_admin_generate_menu_link'));
 
 
 
 
 
 
40
 
41
- wp_register_style( 'mailerlite.css', MAILERLITE_PLUGIN_URL . '/assets/css/mailerlite.css', array(), MAILERLITE_VERSION );
42
- wp_enqueue_style( 'mailerlite.css');
 
 
 
 
43
  }
44
 
45
  /**
46
  * Generates admin menu links
47
  */
48
- public static function mailerlite_admin_generate_menu_link() {
 
49
 
50
- add_menu_page('MailerLite', 'MailerLite', 'manage_options', 'mailerlite_main', null, MAILERLITE_PLUGIN_URL . '/assets/image/icon.png');
 
 
 
51
 
52
- add_submenu_page('mailerlite_main', __('Forms', 'mailerlite'), __('Signup forms', 'mailerlite'), 'manage_options', 'mailerlite_main', array('MailerLite_Admin', 'mailerlite_main'));
53
- add_submenu_page('mailerlite_main', __('Settings', 'mailerlite'), __('Settings', 'mailerlite'), 'manage_options', 'mailerlite_settings', array('MailerLite_Admin', 'mailerlite_settings'));
 
 
 
 
 
 
 
 
 
54
  }
55
 
56
- public static function mailerlite_admin_init_setting() {
 
57
 
58
  }
59
 
60
  /**
61
  * Checks if there is API key set
62
  */
63
- private static function mailerlite_api_key_require() {
 
64
  global $mailerlite_error;
65
 
66
- if ( self::$api_key == false )
67
  {
68
- include ( MAILERLITE_PLUGIN_DIR . 'include/templates/admin/api_key.php' );
 
69
  exit;
70
  }
71
 
@@ -74,103 +107,155 @@ class MailerLite_Admin {
74
  /**
75
  * Create, edit, list pages method
76
  */
77
- public static function mailerlite_main() {
 
78
  global $fields, $lists, $form, $forms_data, $webforms, $mailerlite_error, $result, $wpdb;
79
 
80
  //Check for api key
81
  self::mailerlite_api_key_require();
82
 
83
  $api_key = self::$api_key;
84
- $result = '';
85
 
86
  //Create new signup form view
87
- if( isset($_GET['view']) && $_GET['view'] == 'create' )
88
  {
89
- if( isset( $_POST['create_signup_form'] ) )
90
  {
91
  self::create_new_form($_POST);
92
- wp_redirect( 'admin.php?page=mailerlite_main&view=edit&id=' . $wpdb->insert_id );
 
 
 
93
  }
94
  else
95
  {
96
- if ( isset( $_GET['noheader'] ) ) {
 
97
  require_once(ABSPATH . 'wp-admin/admin-header.php');
98
  }
99
  }
100
 
101
  $ML_Webforms = new ML_Webforms($api_key);
102
- $webforms = $ML_Webforms->getAll();
103
- $webforms = json_decode($webforms);
104
 
105
- include ( MAILERLITE_PLUGIN_DIR . 'include/templates/admin/create.php' );
 
106
 
107
 
108
  }
109
  //Edit signup form view
110
- else if ( isset( $_GET['view'] ) && isset( $_GET['id'] ) && $_GET['view'] == 'edit' && absint( $_GET['id'] ) )
 
 
 
111
  {
112
  $form_id = absint($_GET['id']);
113
 
114
- $form = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "mailerlite_forms WHERE id = " . $form_id);
 
 
 
115
 
116
- if ( isset( $form->data ) )
117
  {
118
  $form->data = unserialize($form->data);
119
 
120
- if ( $form->type == 1 )
121
  {
122
- add_filter( 'wp_default_editor', create_function('', 'return "tinymce";') );
 
 
 
123
 
124
  $ML_Lists = new ML_Lists($api_key);
125
- $lists = $ML_Lists->getAll();
126
- $lists = json_decode($lists);
127
 
128
- $fields = $ML_Lists->setId($lists->Results[0]->id)->getFields();
 
129
  $fields = json_decode($fields);
130
 
131
- if ( isset( $_POST['save_custom_signup_form'] ) )
132
  {
133
- $form_name = isset($_POST['form_name']) && $_POST['form_name'] != '' ? sanitize_text_field($_POST['form_name']) : __('Subscribe for newsletter!', 'mailerlite');
134
- $form_title = isset($_POST['form_title']) && $_POST['form_title'] != '' ? sanitize_text_field($_POST['form_title']) : __('Newsletter signup', 'mailerlite');
135
- $form_description = isset($_POST['form_description']) && $_POST['form_description'] != '' ? $_POST['form_description'] : __('Just simple MailerLite form!', 'mailerlite');
136
- $button_name = isset($_POST['button_name']) && $_POST['button_name'] != '' ? sanitize_text_field($_POST['button_name']) : __('Subscribe', 'mailerlite');
137
-
138
- $selected_fields = isset($_POST['form_selected_field']) && is_array($_POST['form_selected_field']) ? $_POST['form_selected_field'] : array();
139
- $field_titles = isset($_POST['form_field']) && is_array($_POST['form_field']) ? $_POST['form_field'] : array();
140
-
141
- if ( !isset( $field_titles['email'] ) || $field_titles['email'] == '' )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  $field_titles['email'] = __('Email', 'mailerlite');
 
143
 
144
- $form_lists = isset($_POST['form_lists']) && is_array($_POST['form_lists']) ? $_POST['form_lists'] : array();
 
 
 
145
 
146
  $prepared_fields = array();
147
 
148
  //Force to use email
149
  $prepared_fields['email'] = $field_titles['email'];
150
 
151
- foreach($selected_fields as $field)
152
  {
153
  if (isset($field_titles[ $field ]))
154
- $prepared_fields[ $field ] = $field_titles[ $field ];
 
 
 
155
  }
156
 
157
  $form_data = array(
158
- 'title' => $form_title,
159
- 'description' => wpautop($form_description, true),
160
- 'button' => $button_name,
161
- 'lists' => $form_lists,
162
- 'fields' => $prepared_fields
163
  );
164
 
165
  $wpdb->update(
166
  $wpdb->prefix . 'mailerlite_forms',
167
  array(
168
- 'name' => $form_name,
169
- 'data' => serialize( $form_data )
170
  ),
171
- array( 'id' => $form_id ),
172
  array(),
173
- array( '%d' )
174
  );
175
 
176
  $form->data = $form_data;
@@ -178,25 +263,33 @@ class MailerLite_Admin {
178
  $result = 'success';
179
  }
180
 
181
- include ( MAILERLITE_PLUGIN_DIR . 'include/templates/admin/edit_custom.php' );
 
182
  }
183
- else if ( $form->type == 2 )
184
  {
185
  $ML_Webforms = new ML_Webforms($api_key);
186
- $webforms = $ML_Webforms->getAll();
187
- $webforms = json_decode($webforms);
188
 
189
  $parsed_webforms = array();
190
 
191
- foreach($webforms->Results as $webform)
192
  {
193
- $parsed_webforms[$webform->id] = $webform->code;
194
  }
195
 
196
- if ( isset($_POST['save_embedded_signup_form']) )
197
  {
198
- $form_name = isset($_POST['form_name']) && $_POST['form_name'] != '' ? sanitize_text_field($_POST['form_name']) : __('Embedded webform', 'mailerlite');
199
- $form_webform_id = isset($_POST['form_webform_id']) && isset($parsed_webforms[ $_POST['form_webform_id'] ]) ? $_POST['form_webform_id'] : 0;
 
 
 
 
 
 
 
200
 
201
  $form_data = array(
202
  'id' => $form_webform_id,
@@ -206,12 +299,12 @@ class MailerLite_Admin {
206
  $wpdb->update(
207
  $wpdb->prefix . 'mailerlite_forms',
208
  array(
209
- 'name' => $form_name,
210
- 'data' => serialize( $form_data )
211
  ),
212
- array( 'id' => $form_id ),
213
  array(),
214
- array( '%d' )
215
  );
216
 
217
  $form->data = $form_data;
@@ -219,60 +312,81 @@ class MailerLite_Admin {
219
  $result = 'success';
220
  }
221
 
222
- include ( MAILERLITE_PLUGIN_DIR . 'include/templates/admin/edit_embedded.php' );
 
223
  }
224
  }
225
  else
226
  {
227
- $forms_data = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . "mailerlite_forms ORDER BY time DESC" );
 
 
 
228
 
229
- include ( MAILERLITE_PLUGIN_DIR . 'include/templates/admin/main.php' );
 
230
  }
231
  }
232
  //Delete signup form view
233
- else if ( isset($_GET['view']) && isset($_GET['id']) && $_GET['view'] == 'delete' && absint($_GET['id']) )
 
 
 
234
  {
235
- $wpdb->delete( $wpdb->prefix . 'mailerlite_forms', array( 'id' => $_GET['id'] ) );
236
- wp_redirect( 'admin.php?page=mailerlite_main' );
 
 
237
  }
238
  //Signup forms list
239
  else
240
  {
241
- $forms_data = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . "mailerlite_forms ORDER BY time DESC" );
 
 
 
242
 
243
- include ( MAILERLITE_PLUGIN_DIR . 'include/templates/admin/main.php' );
244
  }
245
  }
246
 
247
  /**
248
  * Settings page method
249
  */
250
- public static function mailerlite_settings() {
 
251
  global $api_key, $mailerlite_error;
252
 
253
  self::mailerlite_api_key_require();
254
 
255
  $api_key = self::$api_key;
256
 
257
- include ( MAILERLITE_PLUGIN_DIR . 'include/templates/admin/settings.php' );
258
  }
259
 
260
  /**
261
  * Checks and sets API key
262
  */
263
- private static function set_api_key() {
 
264
  global $mailerlite_error;
265
 
266
- if ( function_exists('current_user_can') && !current_user_can('manage_options') )
 
 
 
 
 
267
  die(__('You not allowed to do that', 'mailerlite'));
 
268
 
269
- $key = preg_replace( '/[^a-z0-9]/i', '', $_POST['mailerlite_key'] );
270
 
271
  $ML_Lists = new ML_Lists($key);
272
  $ML_Lists->getAll();
273
  $response = $ML_Lists->getResponseInfo();
274
 
275
- if($response['http_code'] == 401)
276
  {
277
  $mailerlite_error = __('Wrong MailerLite API key', 'mailerlite');
278
  }
@@ -289,20 +403,24 @@ class MailerLite_Admin {
289
  *
290
  * @param $data
291
  */
292
- private static function create_new_form($data) {
 
293
  global $wpdb;
294
 
295
- $form_type = in_array( $data['form_type'], array(1, 2) ) ? $data['form_type'] : 1;
 
296
 
297
- if ( $form_type == 1 )
298
  {
299
  $form_name = __('New custom signup form', 'mailerlite');
300
  $form_data = array(
301
- 'title' => __('Newsletter signup', 'mailerlite'),
302
- 'description' => __('Just simple MailerLite form!', 'mailerlite'),
303
- 'button' => __('Subscribe', 'mailerlite'),
304
- 'lists' => array(),
305
- 'fields' => array('email' => __('Email', 'mailerlite'))
 
 
306
  );
307
  }
308
  else
@@ -317,10 +435,10 @@ class MailerLite_Admin {
317
  $wpdb->insert(
318
  $wpdb->prefix . 'mailerlite_forms',
319
  array(
320
- 'name' => $form_name,
321
- 'time' => date('Y-m-d h:i:s'),
322
- 'type' => $form_type,
323
- 'data' => serialize( $form_data )
324
  )
325
  );
326
  }
3
  require_once MAILERLITE_PLUGIN_DIR . "libs/mailerlite_rest/ML_Lists.php";
4
  require_once MAILERLITE_PLUGIN_DIR . "libs/mailerlite_rest/ML_Webforms.php";
5
 
6
+ class MailerLite_Admin
7
+ {
8
 
9
  private static $initiated = false;
10
+ private static $api_key = false;
11
 
12
  /**
13
  * Initialization method
14
  */
15
+ public static function init()
16
+ {
17
 
18
  global $mailerlite_error;
19
 
21
 
22
  self::$api_key = get_option('mailerlite_api_key');
23
 
24
+ if ( ! self::$initiated)
25
+ {
26
  self::init_hooks();
27
  }
28
 
29
+ if (isset($_POST['action'])
30
+ && $_POST['action'] == 'enter-mailerlite-key'
31
+ )
32
+ {
33
  self::set_api_key();
34
  }
35
  }
37
  /**
38
  * Adds admin stuff
39
  */
40
+ private static function init_hooks()
41
+ {
42
 
43
  self::$initiated = true;
44
 
45
+ add_action(
46
+ 'admin_init',
47
+ array('MailerLite_Admin', 'mailerlite_admin_init_setting')
48
+ );
49
+ add_action(
50
+ 'admin_menu', array('MailerLite_Admin',
51
+ 'mailerlite_admin_generate_menu_link')
52
+ );
53
 
54
+ wp_register_style(
55
+ 'mailerlite.css',
56
+ MAILERLITE_PLUGIN_URL . '/assets/css/mailerlite.css', array(),
57
+ MAILERLITE_VERSION
58
+ );
59
+ wp_enqueue_style('mailerlite.css');
60
  }
61
 
62
  /**
63
  * Generates admin menu links
64
  */
65
+ public static function mailerlite_admin_generate_menu_link()
66
+ {
67
 
68
+ add_menu_page(
69
+ 'MailerLite', 'MailerLite', 'manage_options', 'mailerlite_main',
70
+ null, MAILERLITE_PLUGIN_URL . '/assets/image/icon.png'
71
+ );
72
 
73
+ add_submenu_page(
74
+ 'mailerlite_main', __('Forms', 'mailerlite'),
75
+ __('Signup forms', 'mailerlite'), 'manage_options',
76
+ 'mailerlite_main', array('MailerLite_Admin', 'mailerlite_main')
77
+ );
78
+ add_submenu_page(
79
+ 'mailerlite_main', __('Settings', 'mailerlite'),
80
+ __('Settings', 'mailerlite'), 'manage_options',
81
+ 'mailerlite_settings',
82
+ array('MailerLite_Admin', 'mailerlite_settings')
83
+ );
84
  }
85
 
86
+ public static function mailerlite_admin_init_setting()
87
+ {
88
 
89
  }
90
 
91
  /**
92
  * Checks if there is API key set
93
  */
94
+ private static function mailerlite_api_key_require()
95
+ {
96
  global $mailerlite_error;
97
 
98
+ if (self::$api_key == false)
99
  {
100
+ include(MAILERLITE_PLUGIN_DIR
101
+ . 'include/templates/admin/api_key.php');
102
  exit;
103
  }
104
 
107
  /**
108
  * Create, edit, list pages method
109
  */
110
+ public static function mailerlite_main()
111
+ {
112
  global $fields, $lists, $form, $forms_data, $webforms, $mailerlite_error, $result, $wpdb;
113
 
114
  //Check for api key
115
  self::mailerlite_api_key_require();
116
 
117
  $api_key = self::$api_key;
118
+ $result = '';
119
 
120
  //Create new signup form view
121
+ if (isset($_GET['view']) && $_GET['view'] == 'create')
122
  {
123
+ if (isset($_POST['create_signup_form']))
124
  {
125
  self::create_new_form($_POST);
126
+ wp_redirect(
127
+ 'admin.php?page=mailerlite_main&view=edit&id='
128
+ . $wpdb->insert_id
129
+ );
130
  }
131
  else
132
  {
133
+ if (isset($_GET['noheader']))
134
+ {
135
  require_once(ABSPATH . 'wp-admin/admin-header.php');
136
  }
137
  }
138
 
139
  $ML_Webforms = new ML_Webforms($api_key);
140
+ $webforms = $ML_Webforms->getAll();
141
+ $webforms = json_decode($webforms);
142
 
143
+ include(MAILERLITE_PLUGIN_DIR
144
+ . 'include/templates/admin/create.php');
145
 
146
 
147
  }
148
  //Edit signup form view
149
+ else if (isset($_GET['view']) && isset($_GET['id'])
150
+ && $_GET['view'] == 'edit'
151
+ && absint($_GET['id'])
152
+ )
153
  {
154
  $form_id = absint($_GET['id']);
155
 
156
+ $form = $wpdb->get_row(
157
+ "SELECT * FROM " . $wpdb->prefix
158
+ . "mailerlite_forms WHERE id = " . $form_id
159
+ );
160
 
161
+ if (isset($form->data))
162
  {
163
  $form->data = unserialize($form->data);
164
 
165
+ if ($form->type == 1)
166
  {
167
+ add_filter(
168
+ 'wp_default_editor',
169
+ create_function('', 'return "tinymce";')
170
+ );
171
 
172
  $ML_Lists = new ML_Lists($api_key);
173
+ $lists = $ML_Lists->getAll();
174
+ $lists = json_decode($lists);
175
 
176
+ $fields = $ML_Lists->setId($lists->Results[0]->id)
177
+ ->getFields();
178
  $fields = json_decode($fields);
179
 
180
+ if (isset($_POST['save_custom_signup_form']))
181
  {
182
+ $form_name = isset($_POST['form_name'])
183
+ && $_POST['form_name'] != ''
184
+ ? sanitize_text_field($_POST['form_name'])
185
+ : __(
186
+ 'Subscribe for newsletter!', 'mailerlite'
187
+ );
188
+ $form_title = isset($_POST['form_title'])
189
+ && $_POST['form_title'] != ''
190
+ ? sanitize_text_field($_POST['form_title'])
191
+ : __(
192
+ 'Newsletter signup', 'mailerlite'
193
+ );
194
+ $form_description = isset($_POST['form_description'])
195
+ && $_POST['form_description'] != ''
196
+ ? $_POST['form_description']
197
+ : __(
198
+ 'Just simple MailerLite form!', 'mailerlite'
199
+ );
200
+ $button_name = isset($_POST['button_name'])
201
+ && $_POST['button_name'] != ''
202
+ ? sanitize_text_field($_POST['button_name'])
203
+ : __(
204
+ 'Subscribe', 'mailerlite'
205
+ );
206
+
207
+ $selected_fields = isset($_POST['form_selected_field'])
208
+ && is_array(
209
+ $_POST['form_selected_field']
210
+ ) ? $_POST['form_selected_field'] : array();
211
+ $field_titles = isset($_POST['form_field'])
212
+ && is_array(
213
+ $_POST['form_field']
214
+ ) ? $_POST['form_field'] : array();
215
+
216
+ if ( ! isset($field_titles['email'])
217
+ || $field_titles['email'] == ''
218
+ )
219
+ {
220
  $field_titles['email'] = __('Email', 'mailerlite');
221
+ }
222
 
223
+ $form_lists = isset($_POST['form_lists'])
224
+ && is_array(
225
+ $_POST['form_lists']
226
+ ) ? $_POST['form_lists'] : array();
227
 
228
  $prepared_fields = array();
229
 
230
  //Force to use email
231
  $prepared_fields['email'] = $field_titles['email'];
232
 
233
+ foreach ($selected_fields as $field)
234
  {
235
  if (isset($field_titles[ $field ]))
236
+ {
237
+ $prepared_fields[ $field ]
238
+ = $field_titles[ $field ];
239
+ }
240
  }
241
 
242
  $form_data = array(
243
+ 'title' => $form_title,
244
+ 'description' => wpautop($form_description, true),
245
+ 'button' => $button_name,
246
+ 'lists' => $form_lists,
247
+ 'fields' => $prepared_fields
248
  );
249
 
250
  $wpdb->update(
251
  $wpdb->prefix . 'mailerlite_forms',
252
  array(
253
+ 'name' => $form_name,
254
+ 'data' => serialize($form_data)
255
  ),
256
+ array('id' => $form_id),
257
  array(),
258
+ array('%d')
259
  );
260
 
261
  $form->data = $form_data;
263
  $result = 'success';
264
  }
265
 
266
+ include(MAILERLITE_PLUGIN_DIR
267
+ . 'include/templates/admin/edit_custom.php');
268
  }
269
+ else if ($form->type == 2)
270
  {
271
  $ML_Webforms = new ML_Webforms($api_key);
272
+ $webforms = $ML_Webforms->getAll();
273
+ $webforms = json_decode($webforms);
274
 
275
  $parsed_webforms = array();
276
 
277
+ foreach ($webforms->Results as $webform)
278
  {
279
+ $parsed_webforms[ $webform->id ] = $webform->code;
280
  }
281
 
282
+ if (isset($_POST['save_embedded_signup_form']))
283
  {
284
+ $form_name = isset($_POST['form_name'])
285
+ && $_POST['form_name'] != ''
286
+ ? sanitize_text_field($_POST['form_name'])
287
+ : __(
288
+ 'Embedded webform', 'mailerlite'
289
+ );
290
+ $form_webform_id = isset($_POST['form_webform_id'])
291
+ && isset($parsed_webforms[ $_POST['form_webform_id'] ])
292
+ ? $_POST['form_webform_id'] : 0;
293
 
294
  $form_data = array(
295
  'id' => $form_webform_id,
299
  $wpdb->update(
300
  $wpdb->prefix . 'mailerlite_forms',
301
  array(
302
+ 'name' => $form_name,
303
+ 'data' => serialize($form_data)
304
  ),
305
+ array('id' => $form_id),
306
  array(),
307
+ array('%d')
308
  );
309
 
310
  $form->data = $form_data;
312
  $result = 'success';
313
  }
314
 
315
+ include(MAILERLITE_PLUGIN_DIR
316
+ . 'include/templates/admin/edit_embedded.php');
317
  }
318
  }
319
  else
320
  {
321
+ $forms_data = $wpdb->get_results(
322
+ "SELECT * FROM " . $wpdb->prefix
323
+ . "mailerlite_forms ORDER BY time DESC"
324
+ );
325
 
326
+ include(MAILERLITE_PLUGIN_DIR
327
+ . 'include/templates/admin/main.php');
328
  }
329
  }
330
  //Delete signup form view
331
+ else if (isset($_GET['view']) && isset($_GET['id'])
332
+ && $_GET['view'] == 'delete'
333
+ && absint($_GET['id'])
334
+ )
335
  {
336
+ $wpdb->delete(
337
+ $wpdb->prefix . 'mailerlite_forms', array('id' => $_GET['id'])
338
+ );
339
+ wp_redirect('admin.php?page=mailerlite_main');
340
  }
341
  //Signup forms list
342
  else
343
  {
344
+ $forms_data = $wpdb->get_results(
345
+ "SELECT * FROM " . $wpdb->prefix
346
+ . "mailerlite_forms ORDER BY time DESC"
347
+ );
348
 
349
+ include(MAILERLITE_PLUGIN_DIR . 'include/templates/admin/main.php');
350
  }
351
  }
352
 
353
  /**
354
  * Settings page method
355
  */
356
+ public static function mailerlite_settings()
357
+ {
358
  global $api_key, $mailerlite_error;
359
 
360
  self::mailerlite_api_key_require();
361
 
362
  $api_key = self::$api_key;
363
 
364
+ include(MAILERLITE_PLUGIN_DIR . 'include/templates/admin/settings.php');
365
  }
366
 
367
  /**
368
  * Checks and sets API key
369
  */
370
+ private static function set_api_key()
371
+ {
372
  global $mailerlite_error;
373
 
374
+ if (function_exists('current_user_can')
375
+ && ! current_user_can(
376
+ 'manage_options'
377
+ )
378
+ )
379
+ {
380
  die(__('You not allowed to do that', 'mailerlite'));
381
+ }
382
 
383
+ $key = preg_replace('/[^a-z0-9]/i', '', $_POST['mailerlite_key']);
384
 
385
  $ML_Lists = new ML_Lists($key);
386
  $ML_Lists->getAll();
387
  $response = $ML_Lists->getResponseInfo();
388
 
389
+ if ($response['http_code'] == 401)
390
  {
391
  $mailerlite_error = __('Wrong MailerLite API key', 'mailerlite');
392
  }
403
  *
404
  * @param $data
405
  */
406
+ private static function create_new_form($data)
407
+ {
408
  global $wpdb;
409
 
410
+ $form_type = in_array($data['form_type'], array(1, 2))
411
+ ? $data['form_type'] : 1;
412
 
413
+ if ($form_type == 1)
414
  {
415
  $form_name = __('New custom signup form', 'mailerlite');
416
  $form_data = array(
417
+ 'title' => __('Newsletter signup', 'mailerlite'),
418
+ 'description' => __(
419
+ 'Just simple MailerLite form!', 'mailerlite'
420
+ ),
421
+ 'button' => __('Subscribe', 'mailerlite'),
422
+ 'lists' => array(),
423
+ 'fields' => array('email' => __('Email', 'mailerlite'))
424
  );
425
  }
426
  else
435
  $wpdb->insert(
436
  $wpdb->prefix . 'mailerlite_forms',
437
  array(
438
+ 'name' => $form_name,
439
+ 'time' => date('Y-m-d h:i:s'),
440
+ 'type' => $form_type,
441
+ 'data' => serialize($form_data)
442
  )
443
  );
444
  }
include/mailerlite-form.php CHANGED
@@ -2,7 +2,8 @@
2
 
3
  require_once MAILERLITE_PLUGIN_DIR . "libs/mailerlite_rest/ML_Subscribers.php";
4
 
5
- class MailerLite_Form {
 
6
  public $form_id;
7
  public $form_type;
8
  public $form_name;
@@ -12,76 +13,102 @@ class MailerLite_Form {
12
  *
13
  * Sets form data for class
14
  */
15
- public static function init() {
16
- add_action( 'wp_enqueue_scripts', array('MailerLite_Form', 'add_jquery_validation_libraries') );
 
 
 
 
17
  }
18
 
19
  /**
20
  * Generates form by type
21
  */
22
- public function generate_form($form_id, $form_type, $form_name, $form_data) {
 
23
 
24
- $this->form_id = $form_id;
25
  $this->form_type = $form_type;
26
  $this->form_name = $form_name;
27
  $this->form_data = $form_data;
28
 
29
- if ( $this->form_type == 1 )
 
30
  $this->generate_custom_form();
 
31
  else
 
32
  $this->generate_embedded_form();
 
33
  }
34
 
35
  /**
36
  * Saves form data
37
  */
38
- public static function save_form_data() {
 
39
  global $wpdb;
40
 
41
- $form_id = isset($_POST['form_id']) ? absint($_POST['form_id']) : 0;
42
- $form_fields = isset($_POST['form_fields']) ? $_POST['form_fields'] : array();
 
43
 
44
  $api_key = get_option('mailerlite_api_key');
45
 
46
- if ( $form_id > 0 && isset($form_fields['email']) ) {
47
- $form = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "mailerlite_forms WHERE id = " . $form_id);
 
 
 
 
48
 
49
- if ( isset( $form->data ) )
50
  {
51
 
52
  $form->data = unserialize($form->data);
53
 
54
- $ML_Subscribers = new ML_Subscribers( $api_key );
55
 
56
  $form_email = $form_fields['email'];
57
  unset($form_fields['email']);
58
 
59
  $fields = array();
60
 
61
- foreach ($form_fields as $field => $value) {
62
- $fields[] = array( 'name' => $field, 'value' => $value );
 
63
  }
64
 
65
  $subscriber = array(
66
- 'email' => $form_email,
67
  'fields' => $fields
68
  );
69
 
70
  foreach ($form->data['lists'] as $list)
71
  {
72
- $ML_Subscribers->setId( $list )->add( $subscriber, 1 );
73
  }
74
 
75
- echo json_encode(array('status' => 'success', 'message' => __('Subscriber successfully saved', 'mailerlite')));
 
 
 
 
76
  }
77
  else
78
  {
79
- echo json_encode(array('status' => 'error', 'message' => __('Form not found', 'mailerlite')));
 
 
 
80
  }
81
  }
82
  else
83
  {
84
- echo json_encode(array('status' => 'error', 'message' => __('Wrong data provided', 'mailerlite')));
 
 
 
85
  }
86
 
87
  exit;
@@ -90,45 +117,71 @@ class MailerLite_Form {
90
  /**
91
  * Method to generate custom form
92
  */
93
- private function generate_custom_form() {
 
94
  global $form_id, $form_name, $form_data;
95
 
96
  $form_id = $this->form_id;
97
  $form_name = $this->form_name;
98
  $form_data = $this->form_data;
99
 
100
- include ( MAILERLITE_PLUGIN_DIR . 'include/templates/forms/custom_form.php' );
 
101
 
102
  }
103
 
104
  /**
105
  * Method to generate embedded form
106
  */
107
- private function generate_embedded_form() {
 
108
  global $form_data;
109
 
110
  $form_data = $this->form_data;
111
 
112
- include ( MAILERLITE_PLUGIN_DIR . 'include/templates/forms/embedded_form.php' );
 
113
  }
114
 
115
  /**
116
  * Register jQuery validation library
117
  */
118
- public static function add_jquery_validation_libraries() {
 
119
 
120
- if ( !wp_script_is('jquery') && !wp_script_is('google-hosted-jquery') ) {
121
- wp_register_script('google-hosted-jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', false);
 
 
 
 
 
122
  wp_enqueue_script('google-hosted-jquery');
123
  }
124
 
125
- if ( !wp_script_is('jquery-validation-plugin') && wp_script_is('jquery') )
 
 
 
 
126
  {
127
- wp_register_script('jquery-validation-plugin', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.0/jquery.validate.min.js', array('jquery'));
 
 
 
 
128
  }
129
- else if ( !wp_script_is('jquery-validation-plugin') && wp_script_is('google-hosted-jquery') )
 
 
 
 
130
  {
131
- wp_register_script('jquery-validation-plugin', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.0/jquery.validate.min.js', array('google-hosted-jquery'));
 
 
 
 
132
  }
133
 
134
  wp_enqueue_script('jquery-validation-plugin');
@@ -136,8 +189,14 @@ class MailerLite_Form {
136
  }
137
  }
138
 
139
- add_action( 'wp_ajax_nopriv_mailerlite_subscribe_form', array('MailerLite_Form', 'save_form_data') );
140
- add_action( 'wp_ajax_mailerlite_subscribe_form', array('MailerLite_Form', 'save_form_data') );
 
 
 
 
 
 
141
 
142
 
143
  /**
@@ -145,16 +204,22 @@ add_action( 'wp_ajax_mailerlite_subscribe_form', array('MailerLite_Form', 'save_
145
  *
146
  * @param $form_id
147
  */
148
- function load_mailerlite_form($form_id) {
 
149
  global $wpdb;
150
 
151
- $form = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "mailerlite_forms WHERE id = " . $form_id);
 
 
 
152
 
153
- if ( isset( $form->data ) )
154
  {
155
  $form_data = unserialize($form->data);
156
 
157
  $MailerLite_form = new Mailerlite_Form();
158
- $MailerLite_form->generate_form($form_id, $form->type, $form->name, $form_data);
 
 
159
  }
160
  }
2
 
3
  require_once MAILERLITE_PLUGIN_DIR . "libs/mailerlite_rest/ML_Subscribers.php";
4
 
5
+ class MailerLite_Form
6
+ {
7
  public $form_id;
8
  public $form_type;
9
  public $form_name;
13
  *
14
  * Sets form data for class
15
  */
16
+ public static function init()
17
+ {
18
+ add_action(
19
+ 'wp_enqueue_scripts',
20
+ array('MailerLite_Form', 'add_jquery_validation_libraries')
21
+ );
22
  }
23
 
24
  /**
25
  * Generates form by type
26
  */
27
+ public function generate_form($form_id, $form_type, $form_name, $form_data)
28
+ {
29
 
30
+ $this->form_id = $form_id;
31
  $this->form_type = $form_type;
32
  $this->form_name = $form_name;
33
  $this->form_data = $form_data;
34
 
35
+ if ($this->form_type == 1)
36
+ {
37
  $this->generate_custom_form();
38
+ }
39
  else
40
+ {
41
  $this->generate_embedded_form();
42
+ }
43
  }
44
 
45
  /**
46
  * Saves form data
47
  */
48
+ public static function save_form_data()
49
+ {
50
  global $wpdb;
51
 
52
+ $form_id = isset($_POST['form_id']) ? absint($_POST['form_id']) : 0;
53
+ $form_fields = isset($_POST['form_fields']) ? $_POST['form_fields']
54
+ : array();
55
 
56
  $api_key = get_option('mailerlite_api_key');
57
 
58
+ if ($form_id > 0 && isset($form_fields['email']))
59
+ {
60
+ $form = $wpdb->get_row(
61
+ "SELECT * FROM " . $wpdb->prefix
62
+ . "mailerlite_forms WHERE id = " . $form_id
63
+ );
64
 
65
+ if (isset($form->data))
66
  {
67
 
68
  $form->data = unserialize($form->data);
69
 
70
+ $ML_Subscribers = new ML_Subscribers($api_key);
71
 
72
  $form_email = $form_fields['email'];
73
  unset($form_fields['email']);
74
 
75
  $fields = array();
76
 
77
+ foreach ($form_fields as $field => $value)
78
+ {
79
+ $fields[] = array('name' => $field, 'value' => $value);
80
  }
81
 
82
  $subscriber = array(
83
+ 'email' => $form_email,
84
  'fields' => $fields
85
  );
86
 
87
  foreach ($form->data['lists'] as $list)
88
  {
89
+ $ML_Subscribers->setId($list)->add($subscriber, 1);
90
  }
91
 
92
+ echo json_encode(
93
+ array('status' => 'success', 'message' => __(
94
+ 'Subscriber successfully saved', 'mailerlite'
95
+ ))
96
+ );
97
  }
98
  else
99
  {
100
+ echo json_encode(
101
+ array('status' => 'error',
102
+ 'message' => __('Form not found', 'mailerlite'))
103
+ );
104
  }
105
  }
106
  else
107
  {
108
+ echo json_encode(
109
+ array('status' => 'error',
110
+ 'message' => __('Wrong data provided', 'mailerlite'))
111
+ );
112
  }
113
 
114
  exit;
117
  /**
118
  * Method to generate custom form
119
  */
120
+ private function generate_custom_form()
121
+ {
122
  global $form_id, $form_name, $form_data;
123
 
124
  $form_id = $this->form_id;
125
  $form_name = $this->form_name;
126
  $form_data = $this->form_data;
127
 
128
+ include(MAILERLITE_PLUGIN_DIR
129
+ . 'include/templates/forms/custom_form.php');
130
 
131
  }
132
 
133
  /**
134
  * Method to generate embedded form
135
  */
136
+ private function generate_embedded_form()
137
+ {
138
  global $form_data;
139
 
140
  $form_data = $this->form_data;
141
 
142
+ include(MAILERLITE_PLUGIN_DIR
143
+ . 'include/templates/forms/embedded_form.php');
144
  }
145
 
146
  /**
147
  * Register jQuery validation library
148
  */
149
+ public static function add_jquery_validation_libraries()
150
+ {
151
 
152
+ if ( ! wp_script_is('jquery') && ! wp_script_is('google-hosted-jquery'))
153
+ {
154
+ wp_register_script(
155
+ 'google-hosted-jquery',
156
+ '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
157
+ false
158
+ );
159
  wp_enqueue_script('google-hosted-jquery');
160
  }
161
 
162
+ if ( ! wp_script_is('jquery-validation-plugin')
163
+ && wp_script_is(
164
+ 'jquery'
165
+ )
166
+ )
167
  {
168
+ wp_register_script(
169
+ 'jquery-validation-plugin',
170
+ 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.0/jquery.validate.min.js',
171
+ array('jquery')
172
+ );
173
  }
174
+ else if ( ! wp_script_is('jquery-validation-plugin')
175
+ && wp_script_is(
176
+ 'google-hosted-jquery'
177
+ )
178
+ )
179
  {
180
+ wp_register_script(
181
+ 'jquery-validation-plugin',
182
+ 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.0/jquery.validate.min.js',
183
+ array('google-hosted-jquery')
184
+ );
185
  }
186
 
187
  wp_enqueue_script('jquery-validation-plugin');
189
  }
190
  }
191
 
192
+ add_action(
193
+ 'wp_ajax_nopriv_mailerlite_subscribe_form',
194
+ array('MailerLite_Form', 'save_form_data')
195
+ );
196
+ add_action(
197
+ 'wp_ajax_mailerlite_subscribe_form',
198
+ array('MailerLite_Form', 'save_form_data')
199
+ );
200
 
201
 
202
  /**
204
  *
205
  * @param $form_id
206
  */
207
+ function load_mailerlite_form($form_id)
208
+ {
209
  global $wpdb;
210
 
211
+ $form = $wpdb->get_row(
212
+ "SELECT * FROM " . $wpdb->prefix . "mailerlite_forms WHERE id = "
213
+ . $form_id
214
+ );
215
 
216
+ if (isset($form->data))
217
  {
218
  $form_data = unserialize($form->data);
219
 
220
  $MailerLite_form = new Mailerlite_Form();
221
+ $MailerLite_form->generate_form(
222
+ $form_id, $form->type, $form->name, $form_data
223
+ );
224
  }
225
  }
include/mailerlite-shortcode.php CHANGED
@@ -1,20 +1,38 @@
1
  <?php
2
 
3
- class MailerLite_Shortcode {
 
4
 
5
  /**
6
  * WordPress' init() hook
7
  */
8
- public static function init() {
9
-
10
- add_shortcode( 'mailerlite_form', array('MailerLite_Shortcode', 'mailerlite_generate_shortcode') );
11
-
12
- add_action( 'wp_ajax_nopriv_mailerlite_tinymce_window', array('MailerLite_Shortcode', 'mailerlite_tinymce_window') );
13
- add_action( 'wp_ajax_mailerlite_tinymce_window', array('MailerLite_Shortcode', 'mailerlite_tinymce_window') );
14
-
15
- if ( get_user_option('rich_editing') ) {
16
- add_filter ( 'mce_buttons', array('MailerLite_Shortcode', 'mailerlite_register_button') );
17
- add_filter ( 'mce_external_plugins', array('MailerLite_Shortcode', 'mailerlite_add_tinymce_plugin') );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  }
19
 
20
  }
@@ -22,9 +40,11 @@ class MailerLite_Shortcode {
22
  /**
23
  * Add tinymce button to toolbar
24
  */
25
- public static function mailerlite_register_button($buttons) {
 
26
 
27
  array_push($buttons, "mailerlite_shortcode");
 
28
  return $buttons;
29
 
30
  }
@@ -32,22 +52,32 @@ class MailerLite_Shortcode {
32
  /**
33
  * Register tinymce plugin
34
  */
35
- public static function mailerlite_add_tinymce_plugin($plugin_array) {
36
- $plugin_array['mailerlite_shortcode'] = MAILERLITE_PLUGIN_URL.'/assets/js/mailerlite_shortcode.js';
 
 
 
37
  return $plugin_array;
38
  }
39
 
40
  /**
41
  * Returns selection of forms
42
  */
43
- public static function mailerlite_tinymce_window() {
 
44
  global $wpdb, $forms;
45
 
46
- if ( ! current_user_can( 'edit_posts' ) ) return;
 
 
 
47
 
48
- $forms = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "mailerlite_forms");
 
 
49
 
50
- include ( MAILERLITE_PLUGIN_DIR . 'include/templates/common/tiny_mce.php' );
 
51
 
52
  exit;
53
  }
@@ -57,12 +87,16 @@ class MailerLite_Shortcode {
57
  * Converts shortcode into html
58
  *
59
  * @param $attributes
 
60
  * @return string
61
  */
62
- public static function mailerlite_generate_shortcode( $attributes ) {
63
- $form_attributes = shortcode_atts( array(
64
- 'form_id' => '1'
65
- ), $attributes );
 
 
 
66
 
67
  ob_start();
68
  load_mailerlite_form($form_attributes['form_id']);
1
  <?php
2
 
3
+ class MailerLite_Shortcode
4
+ {
5
 
6
  /**
7
  * WordPress' init() hook
8
  */
9
+ public static function init()
10
+ {
11
+
12
+ add_shortcode(
13
+ 'mailerlite_form', array('MailerLite_Shortcode',
14
+ 'mailerlite_generate_shortcode')
15
+ );
16
+
17
+ add_action(
18
+ 'wp_ajax_nopriv_mailerlite_tinymce_window',
19
+ array('MailerLite_Shortcode', 'mailerlite_tinymce_window')
20
+ );
21
+ add_action(
22
+ 'wp_ajax_mailerlite_tinymce_window',
23
+ array('MailerLite_Shortcode', 'mailerlite_tinymce_window')
24
+ );
25
+
26
+ if (get_user_option('rich_editing'))
27
+ {
28
+ add_filter(
29
+ 'mce_buttons', array('MailerLite_Shortcode',
30
+ 'mailerlite_register_button')
31
+ );
32
+ add_filter(
33
+ 'mce_external_plugins', array('MailerLite_Shortcode',
34
+ 'mailerlite_add_tinymce_plugin')
35
+ );
36
  }
37
 
38
  }
40
  /**
41
  * Add tinymce button to toolbar
42
  */
43
+ public static function mailerlite_register_button($buttons)
44
+ {
45
 
46
  array_push($buttons, "mailerlite_shortcode");
47
+
48
  return $buttons;
49
 
50
  }
52
  /**
53
  * Register tinymce plugin
54
  */
55
+ public static function mailerlite_add_tinymce_plugin($plugin_array)
56
+ {
57
+ $plugin_array['mailerlite_shortcode']
58
+ = MAILERLITE_PLUGIN_URL . '/assets/js/mailerlite_shortcode.js';
59
+
60
  return $plugin_array;
61
  }
62
 
63
  /**
64
  * Returns selection of forms
65
  */
66
+ public static function mailerlite_tinymce_window()
67
+ {
68
  global $wpdb, $forms;
69
 
70
+ if ( ! current_user_can('edit_posts'))
71
+ {
72
+ return;
73
+ }
74
 
75
+ $forms = $wpdb->get_results(
76
+ "SELECT * FROM " . $wpdb->prefix . "mailerlite_forms"
77
+ );
78
 
79
+ include(MAILERLITE_PLUGIN_DIR
80
+ . 'include/templates/common/tiny_mce.php');
81
 
82
  exit;
83
  }
87
  * Converts shortcode into html
88
  *
89
  * @param $attributes
90
+ *
91
  * @return string
92
  */
93
+ public static function mailerlite_generate_shortcode($attributes)
94
+ {
95
+ $form_attributes = shortcode_atts(
96
+ array(
97
+ 'form_id' => '1'
98
+ ), $attributes
99
+ );
100
 
101
  ob_start();
102
  load_mailerlite_form($form_attributes['form_id']);
include/mailerlite-widget.php CHANGED
@@ -2,16 +2,20 @@
2
 
3
  require_once MAILERLITE_PLUGIN_DIR . "include/mailerlite-form.php";
4
 
5
- class MailerLite_Widget extends WP_Widget {
 
6
 
7
  /**
8
  * Sets up the widgets name etc
9
  */
10
- public function __construct() {
 
11
  parent::__construct(
12
  'mailerlite_widget', // Base ID
13
  __('Mailerlite sign up form', 'mailerlite'), // Name
14
- array( 'description' => __( 'MailerLite sign up form Widget', 'mailerlite' ), ) // Args
 
 
15
  );
16
  }
17
 
@@ -23,20 +27,29 @@ class MailerLite_Widget extends WP_Widget {
23
  * @param array $args Widget arguments.
24
  * @param array $instance Saved values from database.
25
  */
26
- public function widget( $args, $instance ) {
 
27
  global $wpdb;
28
 
29
- $form_id = isset($instance['mailerlite_form_id']) && intval($instance['mailerlite_form_id']) ? $instance['mailerlite_form_id'] : 0;
30
- $form = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "mailerlite_forms WHERE id = " . $form_id);
 
 
 
 
 
 
31
 
32
- if ( isset( $form->data ) )
33
  {
34
  $form_data = unserialize($form->data);
35
 
36
  echo $args['before_widget'];
37
 
38
  $MailerLite_form = new Mailerlite_Form();
39
- $MailerLite_form->generate_form($form_id, $form->type, $form->name, $form_data);
 
 
40
 
41
  echo $args['after_widget'];
42
  }
@@ -48,29 +61,44 @@ class MailerLite_Widget extends WP_Widget {
48
  * @see WP_Widget::form()
49
  *
50
  * @param array $instance Previously saved values from database.
 
51
  * @return void
52
  */
53
- public function form( $instance ) {
 
54
  global $wpdb;
55
 
56
- $forms_data = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . "mailerlite_forms ORDER BY time DESC" );
 
 
 
57
 
58
- if ( isset( $instance[ 'mailerlite_form_id' ] ) ) {
59
- $id = $instance[ 'mailerlite_form_id' ];
 
60
  }
61
- else {
 
62
  $id = 0;
63
  }
64
  ?>
65
  <p>
66
- <label for="<?php echo $this->get_field_id( 'mailerlite_form_id' ); ?>"><?php echo __( 'Select form:', 'mailerlite' ); ?></label>
67
- <select class="widefat" id="<?php echo $this->get_field_id( 'mailerlite_form_id' ); ?>" name="<?php echo $this->get_field_name( 'mailerlite_form_id' ); ?>">
 
 
 
 
 
 
68
  <?php foreach ($forms_data as $form): ?>
69
- <option value="<?php echo $form->id; ?>"<?php echo $form->id == $id ? ' selected="selected"' : ''; ?>><?php echo $form->name; ?></option>
 
 
70
  <?php endforeach; ?>
71
  </select>
72
  </p>
73
- <?php
74
  }
75
 
76
  /**
@@ -83,15 +111,20 @@ class MailerLite_Widget extends WP_Widget {
83
  *
84
  * @return array Updated safe values to be saved.
85
  */
86
- public function update( $new_instance, $old_instance ) {
 
87
  $instance = array();
88
- $instance['mailerlite_form_id'] = ( ! empty( $new_instance['mailerlite_form_id'] ) ) ? strip_tags( $new_instance['mailerlite_form_id'] ) : '';
 
 
89
 
90
  return $instance;
91
  }
92
  }
93
 
94
- function register_mailerlite_widget() {
95
- register_widget( 'Mailerlite_Widget' );
 
96
  }
97
- add_action( 'widgets_init', 'register_mailerlite_widget' );
 
2
 
3
  require_once MAILERLITE_PLUGIN_DIR . "include/mailerlite-form.php";
4
 
5
+ class MailerLite_Widget extends WP_Widget
6
+ {
7
 
8
  /**
9
  * Sets up the widgets name etc
10
  */
11
+ public function __construct()
12
+ {
13
  parent::__construct(
14
  'mailerlite_widget', // Base ID
15
  __('Mailerlite sign up form', 'mailerlite'), // Name
16
+ array('description' => __(
17
+ 'MailerLite sign up form Widget', 'mailerlite'
18
+ ),) // Args
19
  );
20
  }
21
 
27
  * @param array $args Widget arguments.
28
  * @param array $instance Saved values from database.
29
  */
30
+ public function widget($args, $instance)
31
+ {
32
  global $wpdb;
33
 
34
+ $form_id = isset($instance['mailerlite_form_id'])
35
+ && intval(
36
+ $instance['mailerlite_form_id']
37
+ ) ? $instance['mailerlite_form_id'] : 0;
38
+ $form = $wpdb->get_row(
39
+ "SELECT * FROM " . $wpdb->prefix . "mailerlite_forms WHERE id = "
40
+ . $form_id
41
+ );
42
 
43
+ if (isset($form->data))
44
  {
45
  $form_data = unserialize($form->data);
46
 
47
  echo $args['before_widget'];
48
 
49
  $MailerLite_form = new Mailerlite_Form();
50
+ $MailerLite_form->generate_form(
51
+ $form_id, $form->type, $form->name, $form_data
52
+ );
53
 
54
  echo $args['after_widget'];
55
  }
61
  * @see WP_Widget::form()
62
  *
63
  * @param array $instance Previously saved values from database.
64
+ *
65
  * @return void
66
  */
67
+ public function form($instance)
68
+ {
69
  global $wpdb;
70
 
71
+ $forms_data = $wpdb->get_results(
72
+ "SELECT * FROM " . $wpdb->prefix
73
+ . "mailerlite_forms ORDER BY time DESC"
74
+ );
75
 
76
+ if (isset($instance['mailerlite_form_id']))
77
+ {
78
+ $id = $instance['mailerlite_form_id'];
79
  }
80
+ else
81
+ {
82
  $id = 0;
83
  }
84
  ?>
85
  <p>
86
+ <label for="<?php echo $this->get_field_id(
87
+ 'mailerlite_form_id'
88
+ ); ?>"><?php echo __('Select form:', 'mailerlite'); ?></label>
89
+ <select class="widefat" id="<?php echo $this->get_field_id(
90
+ 'mailerlite_form_id'
91
+ ); ?>" name="<?php echo $this->get_field_name(
92
+ 'mailerlite_form_id'
93
+ ); ?>">
94
  <?php foreach ($forms_data as $form): ?>
95
+ <option value="<?php echo $form->id; ?>"<?php echo
96
+ $form->id == $id ? ' selected="selected"'
97
+ : ''; ?>><?php echo $form->name; ?></option>
98
  <?php endforeach; ?>
99
  </select>
100
  </p>
101
+ <?php
102
  }
103
 
104
  /**
111
  *
112
  * @return array Updated safe values to be saved.
113
  */
114
+ public function update($new_instance, $old_instance)
115
+ {
116
  $instance = array();
117
+ $instance['mailerlite_form_id']
118
+ = ( ! empty($new_instance['mailerlite_form_id']))
119
+ ? strip_tags($new_instance['mailerlite_form_id']) : '';
120
 
121
  return $instance;
122
  }
123
  }
124
 
125
+ function register_mailerlite_widget()
126
+ {
127
+ register_widget('Mailerlite_Widget');
128
  }
129
+
130
+ add_action('widgets_init', 'register_mailerlite_widget');
include/templates/common/tiny_mce.php CHANGED
@@ -1,7 +1,6 @@
1
  <html>
2
  <head>
3
- <?php wp_enqueue_script('jquery'); ?>
4
- <?php wp_head(); ?>
5
  <script type="text/javascript" src="<?php echo site_url().'/wp-includes/js/tinymce/tiny_mce_popup.js'; ?>"></script>
6
  </head>
7
 
1
  <html>
2
  <head>
3
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
 
4
  <script type="text/javascript" src="<?php echo site_url().'/wp-includes/js/tinymce/tiny_mce_popup.js'; ?>"></script>
5
  </head>
6
 
mailerlite.php CHANGED
@@ -2,46 +2,53 @@
2
 
3
  /**
4
  * Plugin Name: Official MailerLite Sign Up Forms
5
- * Description: Official MailerLite Sign Up Forms plugin for WordPress. Ability to embed MailerLite webforms and create custom ones just with few clicks.
6
- * Version: 1.0.7
 
7
  * Author: MailerGroup
8
  * Author URI: https://www.mailerlite.com
9
  * License: GPLv2 or later
10
-
11
- This program is free software; you can redistribute it and/or
12
- modify it under the terms of the GNU General Public License
13
- as published by the Free Software Foundation; either version 2
14
- of the License, or (at your option) any later version.
15
-
16
- This program is distributed in the hope that it will be useful,
17
- but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- GNU General Public License for more details.
20
-
21
- You should have received a copy of the GNU General Public License
22
- along with this program; if not, write to the Free Software
23
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
24
  */
25
 
26
- define( 'MAILERLITE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
27
- define( 'MAILERLITE_PLUGIN_URL', plugins_url( '', __FILE__ ) );
28
 
29
- define( 'MAILERLITE_VERSION', '1.0.7');
30
 
31
- function mailerlite_load_plugin_textdomain() {
 
32
 
33
  $domain = 'mailerlite';
34
- load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
 
 
35
 
36
  }
37
- add_action( 'init', 'mailerlite_load_plugin_textdomain' );
38
 
39
- function mailerlite_install() {
 
 
 
40
  global $wpdb;
41
 
42
  $table_name = $wpdb->prefix . "mailerlite_forms";
43
 
44
- $sql = "CREATE TABLE ".$table_name." (
45
  id mediumint(9) NOT NULL AUTO_INCREMENT,
46
  time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
47
  name tinytext NOT NULL,
@@ -50,28 +57,33 @@ function mailerlite_install() {
50
  PRIMARY KEY (id)
51
  );";
52
 
53
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
54
- dbDelta( $sql );
55
  }
56
 
57
- register_activation_hook( __FILE__, 'mailerlite_install' );
58
 
59
- function register_mailerlite_styles() {
60
- wp_register_style( 'mailerlite_forms.css', MAILERLITE_PLUGIN_URL . '/assets/css/mailerlite_forms.css', array(), MAILERLITE_VERSION );
61
- wp_enqueue_style( 'mailerlite_forms.css');
 
 
 
 
 
62
  }
63
 
64
- add_action( 'wp_enqueue_scripts', 'register_mailerlite_styles' );
65
 
66
- if ( is_admin() )
67
  {
68
- require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-admin.php' );
69
- add_action( 'init', array( 'MailerLite_Admin', 'init' ) );
70
  }
71
 
72
 
73
- require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-widget.php' );
74
- require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-shortcode.php' );
75
 
76
- add_action( 'init', array( 'MailerLite_Shortcode', 'init' ) );
77
- add_action( 'init', array( 'MailerLite_Form', 'init' ) );
2
 
3
  /**
4
  * Plugin Name: Official MailerLite Sign Up Forms
5
+ * Description: Official MailerLite Sign Up Forms plugin for WordPress. Ability
6
+ * to embed MailerLite webforms and create custom ones just with few clicks.
7
+ * Version: 1.0.8
8
  * Author: MailerGroup
9
  * Author URI: https://www.mailerlite.com
10
  * License: GPLv2 or later
11
+ *
12
+ * This program is free software; you can redistribute it and/or
13
+ * modify it under the terms of the GNU General Public License
14
+ * as published by the Free Software Foundation; either version 2
15
+ * of the License, or (at your option) any later version.
16
+ *
17
+ * This program is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ * GNU General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU General Public License
23
+ * along with this program; if not, write to the Free Software
24
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25
+ * USA.
26
  */
27
 
28
+ define('MAILERLITE_PLUGIN_DIR', plugin_dir_path(__FILE__));
29
+ define('MAILERLITE_PLUGIN_URL', plugins_url('', __FILE__));
30
 
31
+ define('MAILERLITE_VERSION', '1.0.8');
32
 
33
+ function mailerlite_load_plugin_textdomain()
34
+ {
35
 
36
  $domain = 'mailerlite';
37
+ load_plugin_textdomain(
38
+ $domain, false, basename(dirname(__FILE__)) . '/languages/'
39
+ );
40
 
41
  }
 
42
 
43
+ add_action('init', 'mailerlite_load_plugin_textdomain');
44
+
45
+ function mailerlite_install()
46
+ {
47
  global $wpdb;
48
 
49
  $table_name = $wpdb->prefix . "mailerlite_forms";
50
 
51
+ $sql = "CREATE TABLE " . $table_name . " (
52
  id mediumint(9) NOT NULL AUTO_INCREMENT,
53
  time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
54
  name tinytext NOT NULL,
57
  PRIMARY KEY (id)
58
  );";
59
 
60
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
61
+ dbDelta($sql);
62
  }
63
 
64
+ register_activation_hook(__FILE__, 'mailerlite_install');
65
 
66
+ function register_mailerlite_styles()
67
+ {
68
+ wp_register_style(
69
+ 'mailerlite_forms.css', MAILERLITE_PLUGIN_URL
70
+ . '/assets/css/mailerlite_forms.css', array(),
71
+ MAILERLITE_VERSION
72
+ );
73
+ wp_enqueue_style('mailerlite_forms.css');
74
  }
75
 
76
+ add_action('wp_enqueue_scripts', 'register_mailerlite_styles');
77
 
78
+ if (is_admin())
79
  {
80
+ require_once(MAILERLITE_PLUGIN_DIR . 'include/mailerlite-admin.php');
81
+ add_action('init', array('MailerLite_Admin', 'init'));
82
  }
83
 
84
 
85
+ require_once(MAILERLITE_PLUGIN_DIR . 'include/mailerlite-widget.php');
86
+ require_once(MAILERLITE_PLUGIN_DIR . 'include/mailerlite-shortcode.php');
87
 
88
+ add_action('init', array('MailerLite_Shortcode', 'init'));
89
+ add_action('init', array('MailerLite_Form', 'init'));
readme.txt CHANGED
@@ -3,12 +3,12 @@ Contributors: mailerlite
3
  Donate link: https://www.mailerlite.com/
4
  Tags: mailerlite, newsletter, subscribe, form, webform
5
  Requires at least: 3.0.1
6
- Tested up to: 4.0
7
- Stable tag: 1.0.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Add newsletter sign up forms to your WordPresss site. Subscribers will be saved directly to your MailerLite account. Super easy to set up!
12
 
13
  == Description ==
14
 
@@ -16,7 +16,7 @@ Add newsletter sign up forms to your WordPresss site. Subscribers will be saved
16
 
17
  The Official MailerLite Sign Up Form plugin makes it easy to grow your newsletter subscriber list. Use the plugin to add newsletter sign up form to your Wordpress blog or website and automatically integrate it with your MailerLite account.
18
 
19
- If you don't have MailerLite account yet, you can signup for a FREE trial here.
20
 
21
  Once you activate the plugin, you'll be able to select and add any of webforms you have in your MailerLite account or create a new webform. Place the webform in the sidebar using widget or put it enywhere in your post with a shortcode.
22
 
@@ -93,9 +93,8 @@ if( function_exists( 'load_mailerlite_form' ) ) {
93
  You can use CSS rules to style the sign-up form, use the following CSS selectors to target the various form elements.
94
 
95
  Every form can be different, because element ID of form is:
96
- `
97
- #mailerlite-form_(your_form_id)
98
- `
99
 
100
  Elements of form can be styled.
101
 
@@ -128,6 +127,8 @@ Add your custom CSS rules to the end of your theme stylesheet, /wp-content/theme
128
 
129
  == Changelog ==
130
 
 
 
131
  = 1.0.7 =
132
  * Fix shortcode
133
  = 1.0.6 =
@@ -147,6 +148,8 @@ Add your custom CSS rules to the end of your theme stylesheet, /wp-content/theme
147
 
148
  == Upgrade Notice ==
149
 
 
 
150
  = 1.0.7 =
151
  * Fix shortcode
152
  = 1.0.6 =
3
  Donate link: https://www.mailerlite.com/
4
  Tags: mailerlite, newsletter, subscribe, form, webform
5
  Requires at least: 3.0.1
6
+ Tested up to: 4.1
7
+ Stable tag: 1.0.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Add newsletter sign up forms to your WordPress site. Subscribers will be saved directly to your MailerLite account. Super easy to set up!
12
 
13
  == Description ==
14
 
16
 
17
  The Official MailerLite Sign Up Form plugin makes it easy to grow your newsletter subscriber list. Use the plugin to add newsletter sign up form to your Wordpress blog or website and automatically integrate it with your MailerLite account.
18
 
19
+ If you don't have MailerLite account yet, [you can signup for a FREE trial here](https://www.mailerlite.com/).
20
 
21
  Once you activate the plugin, you'll be able to select and add any of webforms you have in your MailerLite account or create a new webform. Place the webform in the sidebar using widget or put it enywhere in your post with a shortcode.
22
 
93
  You can use CSS rules to style the sign-up form, use the following CSS selectors to target the various form elements.
94
 
95
  Every form can be different, because element ID of form is:
96
+
97
+ `#mailerlite-form_(your_form_id)`
 
98
 
99
  Elements of form can be styled.
100
 
127
 
128
  == Changelog ==
129
 
130
+ = 1.0.8 =
131
+ * Fix shortcode popup
132
  = 1.0.7 =
133
  * Fix shortcode
134
  = 1.0.6 =
148
 
149
  == Upgrade Notice ==
150
 
151
+ = 1.0.8 =
152
+ * Fix shortcode popup
153
  = 1.0.7 =
154
  * Fix shortcode
155
  = 1.0.6 =