Official MailerLite Sign Up Forms - Version 1.0.10

Version Description

  • Some code refactor, array fixes for <5.4
Download this release

Release Info

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

Code changes from version 1.0.9 to 1.0.10

include/mailerlite-admin.php CHANGED
@@ -7,7 +7,7 @@ class MailerLite_Admin
7
  {
8
 
9
  private static $initiated = false;
10
- private static $api_key = false;
11
 
12
  /**
13
  * Initialization method
@@ -21,7 +21,7 @@ class MailerLite_Admin
21
 
22
  self::$api_key = get_option('mailerlite_api_key');
23
 
24
- if ( ! self::$initiated) {
25
  self::init_hooks();
26
  }
27
 
@@ -42,18 +42,18 @@ class MailerLite_Admin
42
 
43
  add_action(
44
  'admin_init',
45
- ['MailerLite_Admin', 'mailerlite_admin_init_setting']
46
  );
47
  add_action(
48
- 'admin_menu', [
49
  'MailerLite_Admin',
50
  'mailerlite_admin_generate_menu_link'
51
- ]
52
  );
53
 
54
  wp_register_style(
55
  'mailerlite.css',
56
- MAILERLITE_PLUGIN_URL . '/assets/css/mailerlite.css', [],
57
  MAILERLITE_VERSION
58
  );
59
  wp_enqueue_style('mailerlite.css');
@@ -73,13 +73,13 @@ class MailerLite_Admin
73
  add_submenu_page(
74
  'mailerlite_main', __('Forms', 'mailerlite'),
75
  __('Signup forms', 'mailerlite'), 'manage_options',
76
- 'mailerlite_main', ['MailerLite_Admin', 'mailerlite_main']
77
  );
78
  add_submenu_page(
79
  'mailerlite_main', __('Settings', 'mailerlite'),
80
  __('Settings', 'mailerlite'), 'manage_options',
81
  'mailerlite_settings',
82
- ['MailerLite_Admin', 'mailerlite_settings']
83
  );
84
  }
85
 
@@ -114,7 +114,7 @@ class MailerLite_Admin
114
  self::mailerlite_api_key_require();
115
 
116
  $api_key = self::$api_key;
117
- $result = '';
118
 
119
  //Create new signup form view
120
  if (isset($_GET['view']) && $_GET['view'] == 'create') {
@@ -131,8 +131,8 @@ class MailerLite_Admin
131
  }
132
 
133
  $ML_Webforms = new ML_Webforms($api_key);
134
- $webforms = $ML_Webforms->getAll();
135
- $webforms = json_decode($webforms);
136
 
137
  include(MAILERLITE_PLUGIN_DIR
138
  . 'include/templates/admin/create.php');
@@ -160,21 +160,21 @@ class MailerLite_Admin
160
  );
161
 
162
  $ML_Lists = new ML_Lists($api_key);
163
- $lists = $ML_Lists->getAll();
164
- $lists = json_decode($lists);
165
 
166
  $fields = $ML_Lists->setId($lists->Results[0]->id)
167
  ->getFields();
168
  $fields = json_decode($fields);
169
 
170
  if (isset($_POST['save_custom_signup_form'])) {
171
- $form_name = isset($_POST['form_name'])
172
  && $_POST['form_name'] != ''
173
  ? sanitize_text_field($_POST['form_name'])
174
  : __(
175
  'Subscribe for newsletter!', 'mailerlite'
176
  );
177
- $form_title = isset($_POST['form_title'])
178
  && $_POST['form_title'] != ''
179
  ? sanitize_text_field($_POST['form_title'])
180
  : __(
@@ -186,7 +186,7 @@ class MailerLite_Admin
186
  : __(
187
  'Just simple MailerLite form!', 'mailerlite'
188
  );
189
- $button_name = isset($_POST['button_name'])
190
  && $_POST['button_name'] != ''
191
  ? sanitize_text_field($_POST['button_name'])
192
  : __(
@@ -196,13 +196,13 @@ class MailerLite_Admin
196
  $selected_fields = isset($_POST['form_selected_field'])
197
  && is_array(
198
  $_POST['form_selected_field']
199
- ) ? $_POST['form_selected_field'] : [];
200
- $field_titles = isset($_POST['form_field'])
201
  && is_array(
202
  $_POST['form_field']
203
- ) ? $_POST['form_field'] : [];
204
 
205
- if ( ! isset($field_titles['email'])
206
  || $field_titles['email'] == ''
207
  ) {
208
  $field_titles['email'] = __('Email', 'mailerlite');
@@ -211,9 +211,9 @@ class MailerLite_Admin
211
  $form_lists = isset($_POST['form_lists'])
212
  && is_array(
213
  $_POST['form_lists']
214
- ) ? $_POST['form_lists'] : [];
215
 
216
- $prepared_fields = [];
217
 
218
  //Force to use email
219
  $prepared_fields['email'] = $field_titles['email'];
@@ -225,23 +225,23 @@ class MailerLite_Admin
225
  }
226
  }
227
 
228
- $form_data = [
229
- 'title' => $form_title,
230
  'description' => wpautop($form_description, true),
231
- 'button' => $button_name,
232
- 'lists' => $form_lists,
233
- 'fields' => $prepared_fields
234
- ];
235
 
236
  $wpdb->update(
237
  $wpdb->prefix . 'mailerlite_forms',
238
- [
239
  'name' => $form_name,
240
  'data' => serialize($form_data)
241
- ],
242
- ['id' => $form_id],
243
- [],
244
- ['%d']
245
  );
246
 
247
  $form->data = $form_data;
@@ -253,17 +253,17 @@ class MailerLite_Admin
253
  . 'include/templates/admin/edit_custom.php');
254
  } else if ($form->type == 2) {
255
  $ML_Webforms = new ML_Webforms($api_key);
256
- $webforms = $ML_Webforms->getAll();
257
- $webforms = json_decode($webforms);
258
 
259
- $parsed_webforms = [];
260
 
261
  foreach ($webforms->Results as $webform) {
262
  $parsed_webforms[$webform->id] = $webform->code;
263
  }
264
 
265
  if (isset($_POST['save_embedded_signup_form'])) {
266
- $form_name = isset($_POST['form_name'])
267
  && $_POST['form_name'] != ''
268
  ? sanitize_text_field($_POST['form_name'])
269
  : __(
@@ -273,20 +273,20 @@ class MailerLite_Admin
273
  && isset($parsed_webforms[$_POST['form_webform_id']])
274
  ? $_POST['form_webform_id'] : 0;
275
 
276
- $form_data = [
277
- 'id' => $form_webform_id,
278
  'code' => $parsed_webforms[$form_webform_id]
279
- ];
280
 
281
  $wpdb->update(
282
  $wpdb->prefix . 'mailerlite_forms',
283
- [
284
  'name' => $form_name,
285
  'data' => serialize($form_data)
286
- ],
287
- ['id' => $form_id],
288
- [],
289
- ['%d']
290
  );
291
 
292
  $form->data = $form_data;
@@ -312,7 +312,7 @@ class MailerLite_Admin
312
  && absint($_GET['id'])
313
  ) {
314
  $wpdb->delete(
315
- $wpdb->prefix . 'mailerlite_forms', ['id' => $_GET['id']]
316
  );
317
  wp_redirect('admin.php?page=mailerlite_main');
318
  } //Signup forms list
@@ -348,7 +348,7 @@ class MailerLite_Admin
348
  global $mailerlite_error;
349
 
350
  if (function_exists('current_user_can')
351
- && ! current_user_can(
352
  'manage_options'
353
  )
354
  ) {
@@ -379,36 +379,36 @@ class MailerLite_Admin
379
  {
380
  global $wpdb;
381
 
382
- $form_type = in_array($data['form_type'], [1, 2])
383
  ? $data['form_type'] : 1;
384
 
385
  if ($form_type == 1) {
386
  $form_name = __('New custom signup form', 'mailerlite');
387
- $form_data = [
388
- 'title' => __('Newsletter signup', 'mailerlite'),
389
  'description' => __(
390
  'Just simple MailerLite form!', 'mailerlite'
391
  ),
392
- 'button' => __('Subscribe', 'mailerlite'),
393
- 'lists' => [],
394
- 'fields' => ['email' => __('Email', 'mailerlite')]
395
- ];
396
  } else {
397
  $form_name = __('New embedded signup form', 'mailerlite');
398
- $form_data = [
399
- 'id' => 0,
400
  'code' => 0
401
- ];
402
  }
403
 
404
  $wpdb->insert(
405
  $wpdb->prefix . 'mailerlite_forms',
406
- [
407
  'name' => $form_name,
408
  'time' => date('Y-m-d h:i:s'),
409
  'type' => $form_type,
410
  'data' => serialize($form_data)
411
- ]
412
  );
413
  }
414
  }
7
  {
8
 
9
  private static $initiated = false;
10
+ private static $api_key = false;
11
 
12
  /**
13
  * Initialization method
21
 
22
  self::$api_key = get_option('mailerlite_api_key');
23
 
24
+ if (!self::$initiated) {
25
  self::init_hooks();
26
  }
27
 
42
 
43
  add_action(
44
  'admin_init',
45
+ array('MailerLite_Admin', 'mailerlite_admin_init_setting')
46
  );
47
  add_action(
48
+ 'admin_menu', array(
49
  'MailerLite_Admin',
50
  'mailerlite_admin_generate_menu_link'
51
+ )
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');
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
 
114
  self::mailerlite_api_key_require();
115
 
116
  $api_key = self::$api_key;
117
+ $result = '';
118
 
119
  //Create new signup form view
120
  if (isset($_GET['view']) && $_GET['view'] == 'create') {
131
  }
132
 
133
  $ML_Webforms = new ML_Webforms($api_key);
134
+ $webforms = $ML_Webforms->getAll();
135
+ $webforms = json_decode($webforms);
136
 
137
  include(MAILERLITE_PLUGIN_DIR
138
  . 'include/templates/admin/create.php');
160
  );
161
 
162
  $ML_Lists = new ML_Lists($api_key);
163
+ $lists = $ML_Lists->getAll();
164
+ $lists = json_decode($lists);
165
 
166
  $fields = $ML_Lists->setId($lists->Results[0]->id)
167
  ->getFields();
168
  $fields = json_decode($fields);
169
 
170
  if (isset($_POST['save_custom_signup_form'])) {
171
+ $form_name = isset($_POST['form_name'])
172
  && $_POST['form_name'] != ''
173
  ? sanitize_text_field($_POST['form_name'])
174
  : __(
175
  'Subscribe for newsletter!', 'mailerlite'
176
  );
177
+ $form_title = isset($_POST['form_title'])
178
  && $_POST['form_title'] != ''
179
  ? sanitize_text_field($_POST['form_title'])
180
  : __(
186
  : __(
187
  'Just simple MailerLite form!', 'mailerlite'
188
  );
189
+ $button_name = isset($_POST['button_name'])
190
  && $_POST['button_name'] != ''
191
  ? sanitize_text_field($_POST['button_name'])
192
  : __(
196
  $selected_fields = isset($_POST['form_selected_field'])
197
  && is_array(
198
  $_POST['form_selected_field']
199
+ ) ? $_POST['form_selected_field'] : array();
200
+ $field_titles = isset($_POST['form_field'])
201
  && is_array(
202
  $_POST['form_field']
203
+ ) ? $_POST['form_field'] : array();
204
 
205
+ if (!isset($field_titles['email'])
206
  || $field_titles['email'] == ''
207
  ) {
208
  $field_titles['email'] = __('Email', 'mailerlite');
211
  $form_lists = isset($_POST['form_lists'])
212
  && is_array(
213
  $_POST['form_lists']
214
+ ) ? $_POST['form_lists'] : array();
215
 
216
+ $prepared_fields = array();
217
 
218
  //Force to use email
219
  $prepared_fields['email'] = $field_titles['email'];
225
  }
226
  }
227
 
228
+ $form_data = array(
229
+ 'title' => $form_title,
230
  'description' => wpautop($form_description, true),
231
+ 'button' => $button_name,
232
+ 'lists' => $form_lists,
233
+ 'fields' => $prepared_fields
234
+ );
235
 
236
  $wpdb->update(
237
  $wpdb->prefix . 'mailerlite_forms',
238
+ array(
239
  'name' => $form_name,
240
  'data' => serialize($form_data)
241
+ ),
242
+ array('id' => $form_id),
243
+ array(),
244
+ array('%d')
245
  );
246
 
247
  $form->data = $form_data;
253
  . 'include/templates/admin/edit_custom.php');
254
  } else if ($form->type == 2) {
255
  $ML_Webforms = new ML_Webforms($api_key);
256
+ $webforms = $ML_Webforms->getAll();
257
+ $webforms = json_decode($webforms);
258
 
259
+ $parsed_webforms = array();
260
 
261
  foreach ($webforms->Results as $webform) {
262
  $parsed_webforms[$webform->id] = $webform->code;
263
  }
264
 
265
  if (isset($_POST['save_embedded_signup_form'])) {
266
+ $form_name = isset($_POST['form_name'])
267
  && $_POST['form_name'] != ''
268
  ? sanitize_text_field($_POST['form_name'])
269
  : __(
273
  && isset($parsed_webforms[$_POST['form_webform_id']])
274
  ? $_POST['form_webform_id'] : 0;
275
 
276
+ $form_data = array(
277
+ 'id' => $form_webform_id,
278
  'code' => $parsed_webforms[$form_webform_id]
279
+ );
280
 
281
  $wpdb->update(
282
  $wpdb->prefix . 'mailerlite_forms',
283
+ array(
284
  'name' => $form_name,
285
  'data' => serialize($form_data)
286
+ ),
287
+ array('id' => $form_id),
288
+ array(),
289
+ array('%d')
290
  );
291
 
292
  $form->data = $form_data;
312
  && absint($_GET['id'])
313
  ) {
314
  $wpdb->delete(
315
+ $wpdb->prefix . 'mailerlite_forms', array('id' => $_GET['id'])
316
  );
317
  wp_redirect('admin.php?page=mailerlite_main');
318
  } //Signup forms list
348
  global $mailerlite_error;
349
 
350
  if (function_exists('current_user_can')
351
+ && !current_user_can(
352
  'manage_options'
353
  )
354
  ) {
379
  {
380
  global $wpdb;
381
 
382
+ $form_type = in_array($data['form_type'], array(1, 2))
383
  ? $data['form_type'] : 1;
384
 
385
  if ($form_type == 1) {
386
  $form_name = __('New custom signup form', 'mailerlite');
387
+ $form_data = array(
388
+ 'title' => __('Newsletter signup', 'mailerlite'),
389
  'description' => __(
390
  'Just simple MailerLite form!', 'mailerlite'
391
  ),
392
+ 'button' => __('Subscribe', 'mailerlite'),
393
+ 'lists' => array(),
394
+ 'fields' => array('email' => __('Email', 'mailerlite'))
395
+ );
396
  } else {
397
  $form_name = __('New embedded signup form', 'mailerlite');
398
+ $form_data = array(
399
+ 'id' => 0,
400
  'code' => 0
401
+ );
402
  }
403
 
404
  $wpdb->insert(
405
  $wpdb->prefix . 'mailerlite_forms',
406
+ array(
407
  'name' => $form_name,
408
  'time' => date('Y-m-d h:i:s'),
409
  'type' => $form_type,
410
  'data' => serialize($form_data)
411
+ )
412
  );
413
  }
414
  }
include/mailerlite-form.php CHANGED
@@ -23,21 +23,23 @@ class MailerLite_Form
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
  }
@@ -49,21 +51,19 @@ class MailerLite_Form
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
 
@@ -74,18 +74,16 @@ class MailerLite_Form
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
 
@@ -94,20 +92,16 @@ class MailerLite_Form
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
 
@@ -121,12 +115,12 @@ class MailerLite_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
 
@@ -140,7 +134,7 @@ class MailerLite_Form
140
  $form_data = $this->form_data;
141
 
142
  include(MAILERLITE_PLUGIN_DIR
143
- . 'include/templates/forms/embedded_form.php');
144
  }
145
 
146
  /**
@@ -149,8 +143,7 @@ class MailerLite_Form
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',
@@ -159,24 +152,21 @@ class MailerLite_Form
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',
@@ -213,8 +203,7 @@ function load_mailerlite_form($form_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();
23
 
24
  /**
25
  * Generates form by type
26
+ *
27
+ * @param $form_id
28
+ * @param $form_type
29
+ * @param $form_name
30
+ * @param $form_data
31
  */
32
  public function generate_form($form_id, $form_type, $form_name, $form_data)
33
  {
34
 
35
+ $this->form_id = $form_id;
36
  $this->form_type = $form_type;
37
  $this->form_name = $form_name;
38
  $this->form_data = $form_data;
39
 
40
+ if ($this->form_type == 1) {
 
41
  $this->generate_custom_form();
42
+ } else {
 
 
43
  $this->generate_embedded_form();
44
  }
45
  }
51
  {
52
  global $wpdb;
53
 
54
+ $form_id = isset($_POST['form_id']) ? absint($_POST['form_id']) : 0;
55
  $form_fields = isset($_POST['form_fields']) ? $_POST['form_fields']
56
  : array();
57
 
58
  $api_key = get_option('mailerlite_api_key');
59
 
60
+ if ($form_id > 0 && isset($form_fields['email'])) {
 
61
  $form = $wpdb->get_row(
62
  "SELECT * FROM " . $wpdb->prefix
63
  . "mailerlite_forms WHERE id = " . $form_id
64
  );
65
 
66
+ if (isset($form->data)) {
 
67
 
68
  $form->data = unserialize($form->data);
69
 
74
 
75
  $fields = array();
76
 
77
+ foreach ($form_fields as $field => $value) {
 
78
  $fields[] = array('name' => $field, 'value' => $value);
79
  }
80
 
81
  $subscriber = array(
82
+ 'email' => $form_email,
83
  'fields' => $fields
84
  );
85
 
86
+ foreach ($form->data['lists'] as $list) {
 
87
  $ML_Subscribers->setId($list)->add($subscriber, 1);
88
  }
89
 
92
  'Subscriber successfully saved', 'mailerlite'
93
  ))
94
  );
95
+ } else {
 
 
96
  echo json_encode(
97
+ array('status' => 'error',
98
+ 'message' => __('Form not found', 'mailerlite'))
99
  );
100
  }
101
+ } else {
 
 
102
  echo json_encode(
103
+ array('status' => 'error',
104
+ 'message' => __('Wrong data provided', 'mailerlite'))
105
  );
106
  }
107
 
115
  {
116
  global $form_id, $form_name, $form_data;
117
 
118
+ $form_id = $this->form_id;
119
  $form_name = $this->form_name;
120
  $form_data = $this->form_data;
121
 
122
  include(MAILERLITE_PLUGIN_DIR
123
+ . 'include/templates/forms/custom_form.php');
124
 
125
  }
126
 
134
  $form_data = $this->form_data;
135
 
136
  include(MAILERLITE_PLUGIN_DIR
137
+ . 'include/templates/forms/embedded_form.php');
138
  }
139
 
140
  /**
143
  public static function add_jquery_validation_libraries()
144
  {
145
 
146
+ if (!wp_script_is('jquery') && !wp_script_is('google-hosted-jquery')) {
 
147
  wp_register_script(
148
  'google-hosted-jquery',
149
  '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
152
  wp_enqueue_script('google-hosted-jquery');
153
  }
154
 
155
+ if (!wp_script_is('jquery-validation-plugin')
156
+ && wp_script_is(
157
  'jquery'
158
  )
159
+ ) {
 
160
  wp_register_script(
161
  'jquery-validation-plugin',
162
  'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.0/jquery.validate.min.js',
163
  array('jquery')
164
  );
165
+ } else if (!wp_script_is('jquery-validation-plugin')
166
+ && wp_script_is(
 
167
  'google-hosted-jquery'
168
  )
169
+ ) {
 
170
  wp_register_script(
171
  'jquery-validation-plugin',
172
  'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.0/jquery.validate.min.js',
203
  . $form_id
204
  );
205
 
206
+ if (isset($form->data)) {
 
207
  $form_data = unserialize($form->data);
208
 
209
  $MailerLite_form = new Mailerlite_Form();
include/mailerlite-shortcode.php CHANGED
@@ -11,7 +11,7 @@ class MailerLite_Shortcode
11
 
12
  add_shortcode(
13
  'mailerlite_form', array('MailerLite_Shortcode',
14
- 'mailerlite_generate_shortcode')
15
  );
16
 
17
  add_action(
@@ -23,15 +23,14 @@ class MailerLite_Shortcode
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
 
@@ -39,6 +38,9 @@ class MailerLite_Shortcode
39
 
40
  /**
41
  * Add tinymce button to toolbar
 
 
 
42
  */
43
  public static function mailerlite_register_button($buttons)
44
  {
@@ -51,6 +53,9 @@ class MailerLite_Shortcode
51
 
52
  /**
53
  * Register tinymce plugin
 
 
 
54
  */
55
  public static function mailerlite_add_tinymce_plugin($plugin_array)
56
  {
@@ -67,8 +72,7 @@ class MailerLite_Shortcode
67
  {
68
  global $wpdb, $forms;
69
 
70
- if ( ! current_user_can('edit_posts'))
71
- {
72
  return;
73
  }
74
 
@@ -77,7 +81,7 @@ class MailerLite_Shortcode
77
  );
78
 
79
  include(MAILERLITE_PLUGIN_DIR
80
- . 'include/templates/common/tiny_mce.php');
81
 
82
  exit;
83
  }
11
 
12
  add_shortcode(
13
  'mailerlite_form', array('MailerLite_Shortcode',
14
+ 'mailerlite_generate_shortcode')
15
  );
16
 
17
  add_action(
23
  array('MailerLite_Shortcode', 'mailerlite_tinymce_window')
24
  );
25
 
26
+ if (get_user_option('rich_editing')) {
 
27
  add_filter(
28
  'mce_buttons', array('MailerLite_Shortcode',
29
+ 'mailerlite_register_button')
30
  );
31
  add_filter(
32
  'mce_external_plugins', array('MailerLite_Shortcode',
33
+ 'mailerlite_add_tinymce_plugin')
34
  );
35
  }
36
 
38
 
39
  /**
40
  * Add tinymce button to toolbar
41
+ *
42
+ * @param $buttons
43
+ * @return mixed
44
  */
45
  public static function mailerlite_register_button($buttons)
46
  {
53
 
54
  /**
55
  * Register tinymce plugin
56
+ *
57
+ * @param $plugin_array
58
+ * @return mixed
59
  */
60
  public static function mailerlite_add_tinymce_plugin($plugin_array)
61
  {
72
  {
73
  global $wpdb, $forms;
74
 
75
+ if (!current_user_can('edit_posts')) {
 
76
  return;
77
  }
78
 
81
  );
82
 
83
  include(MAILERLITE_PLUGIN_DIR
84
+ . 'include/templates/common/tiny_mce.php');
85
 
86
  exit;
87
  }
include/mailerlite-widget.php CHANGED
@@ -24,7 +24,7 @@ class MailerLite_Widget extends WP_Widget
24
  *
25
  * @see WP_Widget::widget()
26
  *
27
- * @param array $args Widget arguments.
28
  * @param array $instance Saved values from database.
29
  */
30
  public function widget($args, $instance)
@@ -32,16 +32,15 @@ class MailerLite_Widget extends WP_Widget
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'];
@@ -73,12 +72,9 @@ class MailerLite_Widget extends WP_Widget
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
  ?>
@@ -115,7 +111,7 @@ class MailerLite_Widget extends WP_Widget
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;
24
  *
25
  * @see WP_Widget::widget()
26
  *
27
+ * @param array $args Widget arguments.
28
  * @param array $instance Saved values from database.
29
  */
30
  public function widget($args, $instance)
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
  $form_data = unserialize($form->data);
45
 
46
  echo $args['before_widget'];
72
  . "mailerlite_forms ORDER BY time DESC"
73
  );
74
 
75
+ if (isset($instance['mailerlite_form_id'])) {
 
76
  $id = $instance['mailerlite_form_id'];
77
+ } else {
 
 
78
  $id = 0;
79
  }
80
  ?>
111
  {
112
  $instance = array();
113
  $instance['mailerlite_form_id']
114
+ = (!empty($new_instance['mailerlite_form_id']))
115
  ? strip_tags($new_instance['mailerlite_form_id']) : '';
116
 
117
  return $instance;
include/templates/admin/api_key.php CHANGED
@@ -6,7 +6,7 @@
6
  <div id="post-body">
7
  <div id="post-body-content">
8
  <p><?php echo __('Hi there! You will be able to create awesome signup forms, but first we need your MailerLite API key!', 'mailerlite'); ?></p>
9
- <?php if($mailerlite_error): ?>
10
  <div class="error">
11
  <p><?php echo $mailerlite_error; ?></p>
12
  </div>
@@ -15,19 +15,24 @@
15
  <div class="mailerlite-activate">
16
  <div class="description-block">
17
  <p class="title"><?php echo __('Enter an API key', 'mailerlite'); ?></p>
18
- <p><?php echo __("Don't know where to find it?", 'mailerlite'); ?> <a href="http://mailerlite.helpscoutdocs.com/article/12-does-mailerlite-offer-an-api" target="_blank"><?php echo __('Check it here!', 'mailerlite'); ?></a></p>
 
 
 
19
  </div>
20
  <div class="input-block">
21
  <form action="" method="post" id="enter-mailerlite-key">
22
- <input type="text" name="mailerlite_key" class="regular-text" placeholder="API-key" />
23
- <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php echo __('Save this key', 'mailerlite'); ?>">
 
24
  <input type="hidden" name="action" value="enter-mailerlite-key">
25
  </form>
26
  </div>
27
  <div class="clear"></div>
28
  </div>
29
  <p><strong><?php echo __("Don't have an account?", 'mailerlite'); ?></strong></p>
30
- <a href="https://www.mailerlite.com/signup" target="_blank" class="button button-secondary"><?php echo __('Register!', 'mailerlite'); ?></a>
 
31
  </div>
32
  </div>
33
  </div>
6
  <div id="post-body">
7
  <div id="post-body-content">
8
  <p><?php echo __('Hi there! You will be able to create awesome signup forms, but first we need your MailerLite API key!', 'mailerlite'); ?></p>
9
+ <?php if ($mailerlite_error): ?>
10
  <div class="error">
11
  <p><?php echo $mailerlite_error; ?></p>
12
  </div>
15
  <div class="mailerlite-activate">
16
  <div class="description-block">
17
  <p class="title"><?php echo __('Enter an API key', 'mailerlite'); ?></p>
18
+
19
+ <p><?php echo __("Don't know where to find it?", 'mailerlite'); ?> <a
20
+ href="http://mailerlite.helpscoutdocs.com/article/12-does-mailerlite-offer-an-api"
21
+ target="_blank"><?php echo __('Check it here!', 'mailerlite'); ?></a></p>
22
  </div>
23
  <div class="input-block">
24
  <form action="" method="post" id="enter-mailerlite-key">
25
+ <input type="text" name="mailerlite_key" class="regular-text" placeholder="API-key"/>
26
+ <input type="submit" name="submit" id="submit" class="button button-primary"
27
+ value="<?php echo __('Save this key', 'mailerlite'); ?>">
28
  <input type="hidden" name="action" value="enter-mailerlite-key">
29
  </form>
30
  </div>
31
  <div class="clear"></div>
32
  </div>
33
  <p><strong><?php echo __("Don't have an account?", 'mailerlite'); ?></strong></p>
34
+ <a href="https://www.mailerlite.com/signup" target="_blank"
35
+ class="button button-secondary"><?php echo __('Register!', 'mailerlite'); ?></a>
36
  </div>
37
  </div>
38
  </div>
include/templates/admin/create.php CHANGED
@@ -1,32 +1,41 @@
1
  <?php defined('ABSPATH') or die("No direct access allowed!"); ?>
2
- <?php include_once ('header.php'); ?>
3
 
4
  <div class="wrap columns-2 dd-wrap">
5
  <h2><?php echo __('Create new signup form', 'mailerlite'); ?></h2>
 
6
  <div id="poststuff" class="metabox-holder has-right-sidebar">
7
  <?php include("sidebar.php"); ?>
8
  <div id="post-body">
9
  <div id="post-body-content">
10
  <div class="stuffbox">
11
  <h3><span><?php echo __('Form type', 'mailerlite'); ?></span></h3>
12
- <form action="<?php echo admin_url('admin.php?page=mailerlite_main&view=create&noheader=true'); ?>" method="post">
 
 
13
  <div class="inside">
14
  <p>
15
  <label for="form_type_custom" class="selectit">
16
- <input id="form_type_custom" type="radio" name="form_type" value="1" checked="checked">
 
17
  <?php echo __('Custom signup form', 'mailerlite'); ?>
18
  </label>
19
  </p>
 
20
  <p>
21
  <label for="form_type_webform" class="selectit">
22
- <input id="form_type_webform" type="radio" name="form_type" value="2"<?php echo $webforms->RecordsOnPage == 0 ? ' disabled="disabled"': ''; ?>>
 
23
  <?php echo __('Webforms created using MailerLite', 'mailerlite'); ?>
24
  </label>
25
  </p>
26
 
27
  <div class="submit">
28
- <input class="button-primary mailerlite-pull-right" value="<?php echo __('Create form', 'mailerlite'); ?>" name="create_signup_form" type="submit">
29
- <a class="button-secondary" href="<?php echo admin_url('admin.php?page=mailerlite_main'); ?>"><?php echo __('Back', 'mailerlite'); ?></a>
 
 
 
30
  </div>
31
  </div>
32
  </form>
1
  <?php defined('ABSPATH') or die("No direct access allowed!"); ?>
2
+ <?php include_once('header.php'); ?>
3
 
4
  <div class="wrap columns-2 dd-wrap">
5
  <h2><?php echo __('Create new signup form', 'mailerlite'); ?></h2>
6
+
7
  <div id="poststuff" class="metabox-holder has-right-sidebar">
8
  <?php include("sidebar.php"); ?>
9
  <div id="post-body">
10
  <div id="post-body-content">
11
  <div class="stuffbox">
12
  <h3><span><?php echo __('Form type', 'mailerlite'); ?></span></h3>
13
+
14
+ <form action="<?php echo admin_url('admin.php?page=mailerlite_main&view=create&noheader=true'); ?>"
15
+ method="post">
16
  <div class="inside">
17
  <p>
18
  <label for="form_type_custom" class="selectit">
19
+ <input id="form_type_custom" type="radio" name="form_type" value="1"
20
+ checked="checked">
21
  <?php echo __('Custom signup form', 'mailerlite'); ?>
22
  </label>
23
  </p>
24
+
25
  <p>
26
  <label for="form_type_webform" class="selectit">
27
+ <input id="form_type_webform" type="radio" name="form_type"
28
+ value="2"<?php echo $webforms->RecordsOnPage == 0 ? ' disabled="disabled"' : ''; ?>>
29
  <?php echo __('Webforms created using MailerLite', 'mailerlite'); ?>
30
  </label>
31
  </p>
32
 
33
  <div class="submit">
34
+ <input class="button-primary mailerlite-pull-right"
35
+ value="<?php echo __('Create form', 'mailerlite'); ?>" name="create_signup_form"
36
+ type="submit">
37
+ <a class="button-secondary"
38
+ href="<?php echo admin_url('admin.php?page=mailerlite_main'); ?>"><?php echo __('Back', 'mailerlite'); ?></a>
39
  </div>
40
  </div>
41
  </form>
include/templates/admin/edit_custom.php CHANGED
@@ -1,127 +1,164 @@
1
  <?php defined('ABSPATH') or die("No direct access allowed!"); ?>
2
- <?php include_once ('header.php'); ?>
3
 
4
- <div class="wrap columns-2 dd-wrap">
5
- <h2><?php _e('Edit custom signup form', 'mailerlite'); ?></h2>
6
- <?php if (isset($result) && $result == 'success'): ?>
7
- <div id="message" class="updated below-h2"><p><?php _e('Form saved.', 'mailerlite'); ?> <a href="<?php echo admin_url('admin.php?page=mailerlite_main'); ?>"><?php _e('Back to forms list', 'mailerlite'); ?></a></p></div>
8
- <?php endif; ?>
9
- <div id="poststuff" class="metabox-holder has-right-sidebar">
10
- <?php include("sidebar.php"); ?>
11
- <div id="post-body">
12
- <div id="post-body-content">
13
- <form action="<?php echo admin_url('admin.php?page=mailerlite_main&view=edit&id=' . (isset($_GET['id']) ? $_GET['id'] : 0) ); ?>" method="post">
14
- <div class="postbox">
15
- <h3><span><?php _e('Main information', 'mailerlite'); ?></span></h3>
16
- <div class="inside">
17
- <table class="form-table">
18
- <tbody>
 
 
 
 
 
19
  <tr>
20
  <th><label for="form_name"><?php _e('Form name', 'mailerlite'); ?></label></th>
21
- <td><input type="text" name="form_name" size="30" maxlength="255" value="<?php echo $form->name; ?>" id="form_name"> <span class="description"><strong><?php echo __('Tip:', 'mailerlite'); ?></strong> <?php echo __("This title won't be displayed in public!", 'mailerlite'); ?></span></td>
 
 
 
22
  </tr>
23
- </tbody>
24
- </table>
 
25
  </div>
26
- </div>
27
- <div class="postbox">
28
- <h3><span><?php _e('Form details', 'mailerlite'); ?></span></h3>
29
- <div class="inside">
30
- <table class="form-table">
31
- <tbody>
32
  <tr>
33
- <th><label for="form_title"><?php _e('Form title', 'mailerlite'); ?></label></th>
34
- <td><input type="text" name="form_title" size="30" maxlength="255" value="<?php echo $form->data['title']; ?>" id="form_title"> <span class="description"><strong><?php echo __('Example:', 'mailerlite'); ?></strong> <?php echo __("Newsletter signup!", 'mailerlite'); ?></span></td>
 
 
 
 
35
  </tr>
36
  <tr>
37
- <th><label for="form_description"><?php _e('Form description', 'mailerlite'); ?></label></th>
 
 
38
  <td>
39
  <?php
40
  $settings = array(
41
  'media_buttons' => false,
42
- 'textarea_rows' => 4 ,
43
  'tinymce' => array(
44
  'toolbar1' => 'bold,italic,underline,bullist,numlist,link,unlink,forecolor,alignleft,aligncenter,alignright,undo,redo',
45
  'toolbar2' => ''
46
  )
47
  );
48
 
49
- wp_editor( stripslashes($form->data['description']), 'form_description', $settings );
50
  ?>
51
  </td>
52
  </tr>
53
  <tr>
54
- <th><label for="button_name"><?php _e('Button title', 'mailerlite'); ?></label></th>
55
- <td><input type="text" name="button_name" size="30" maxlength="255" value="<?php echo $form->data['button']; ?>" id="button_name"> <span class="description"><strong><?php _e('Example:'); ?></strong> <?php _e('Subscribe'); ?></span></td>
 
 
 
 
56
  </tr>
57
- </tbody>
58
- </table>
 
59
  </div>
60
- </div>
61
- <div class="postbox">
62
- <h3><span><?php _e('Form fields and lists', 'mailerlite'); ?></span></h3>
63
- <div class="inside">
64
- <table class="form-table">
65
- <tr>
66
- <td style="vertical-align: top;">
67
- <h2><?php _e('Fields', 'mailerlite'); ?></h2>
68
- <table class="form-table">
69
- <tbody>
70
- <?php foreach($fields->Fields as $field): ?>
71
- <tr>
72
- <th style="width:1%;"><input type="checkbox" class="input_control" name="form_selected_field[]" value="<?php echo $field->field; ?>"<?php echo $field->field == 'email' || array_key_exists($field->field, $form->data['fields']) ? ' checked="checked"' : ''; echo $field->field == 'email' ? ' disabled="disabled"' : ''; ?>></th>
73
- <td><input type="text" id="field_<?php echo $field->field; ?>" name="form_field[<?php echo $field->field; ?>]" size="30" maxlength="255" value="<?php echo array_key_exists($field->field, $form->data['fields']) ? $form->data['fields'][ $field->field ] : $field->title; ?>"<?php echo $field->field == 'email' || array_key_exists($field->field, $form->data['fields']) ? '' : ' disabled="disabled"'; ?>></td>
74
- </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  <?php endforeach; ?>
76
- </tbody>
77
- </table>
78
- </td>
79
- <td style="vertical-align: top;">
80
- <h2><?php _e('Lists', 'mailerlite'); ?></h2>
81
- <table class="form-table">
82
- <tbody>
83
- <?php foreach($lists->Results as $list): ?>
84
- <tr>
85
- <th style="width:1%;"><input id="list_<?php echo $list->id; ?>" type="checkbox" class="input_control" name="form_lists[]" value="<?php echo $list->id; ?>"<?php echo in_array($list->id, $form->data['lists']) ? ' checked="checked"' : ''; ?>></th>
86
- <td><label for="list_<?php echo $list->id; ?>"><?php echo $list->name; ?></label></td>
87
- </tr>
88
- <?php endforeach; ?>
89
- </tbody>
90
- </table>
91
- </td>
92
- </tr>
93
- </table>
94
- <div class="submit">
95
- <input class="button-primary mailerlite-pull-right" value="<?php _e('Save form', 'mailerlite'); ?>" name="save_custom_signup_form" type="submit">
96
- <a class="button-secondary" href="<?php echo admin_url('admin.php?page=mailerlite_main'); ?>"><?php echo __('Back', 'mailerlite'); ?></a>
97
  </div>
98
  </div>
99
- </div>
100
- </form>
101
  </div>
102
  </div>
103
  </div>
104
- </div>
105
 
106
- <script type="text/javascript">
107
- jQuery(document).ready(function($) {
108
- $(".wp-editor-tabs").remove();
109
 
110
- var checkbox_class = $('.input_control');
111
 
112
- checkbox_class.click(function(){
113
- var input = $('input#field_'+ $(this).attr('value'));
114
 
115
- if($(this).prop('checked') == false)
116
- {
117
- input.attr('disabled', true);
118
- }
119
- else
120
- {
121
- input.attr('disabled', false);
122
- }
123
  });
124
- });
125
- </script>
126
 
127
  <?php /**/
1
  <?php defined('ABSPATH') or die("No direct access allowed!"); ?>
2
+ <?php include_once('header.php'); ?>
3
 
4
+ <div class="wrap columns-2 dd-wrap">
5
+ <h2><?php _e('Edit custom signup form', 'mailerlite'); ?></h2>
6
+ <?php if (isset($result) && $result == 'success'): ?>
7
+ <div id="message" class="updated below-h2"><p><?php _e('Form saved.', 'mailerlite'); ?> <a
8
+ href="<?php echo admin_url('admin.php?page=mailerlite_main'); ?>"><?php _e('Back to forms list', 'mailerlite'); ?></a>
9
+ </p></div>
10
+ <?php endif; ?>
11
+ <div id="poststuff" class="metabox-holder has-right-sidebar">
12
+ <?php include("sidebar.php"); ?>
13
+ <div id="post-body">
14
+ <div id="post-body-content">
15
+ <form
16
+ action="<?php echo admin_url('admin.php?page=mailerlite_main&view=edit&id=' . (isset($_GET['id']) ? $_GET['id'] : 0)); ?>"
17
+ method="post">
18
+ <div class="postbox">
19
+ <h3><span><?php _e('Main information', 'mailerlite'); ?></span></h3>
20
+
21
+ <div class="inside">
22
+ <table class="form-table">
23
+ <tbody>
24
  <tr>
25
  <th><label for="form_name"><?php _e('Form name', 'mailerlite'); ?></label></th>
26
+ <td><input type="text" name="form_name" size="30" maxlength="255"
27
+ value="<?php echo $form->name; ?>" id="form_name"> <span
28
+ class="description"><strong><?php echo __('Tip:', 'mailerlite'); ?></strong> <?php echo __("This title won't be displayed in public!", 'mailerlite'); ?></span>
29
+ </td>
30
  </tr>
31
+ </tbody>
32
+ </table>
33
+ </div>
34
  </div>
35
+ <div class="postbox">
36
+ <h3><span><?php _e('Form details', 'mailerlite'); ?></span></h3>
37
+
38
+ <div class="inside">
39
+ <table class="form-table">
40
+ <tbody>
41
  <tr>
42
+ <th><label for="form_title"><?php _e('Form title', 'mailerlite'); ?></label>
43
+ </th>
44
+ <td><input type="text" name="form_title" size="30" maxlength="255"
45
+ value="<?php echo $form->data['title']; ?>" id="form_title"> <span
46
+ class="description"><strong><?php echo __('Example:', 'mailerlite'); ?></strong> <?php echo __("Newsletter signup!", 'mailerlite'); ?></span>
47
+ </td>
48
  </tr>
49
  <tr>
50
+ <th><label
51
+ for="form_description"><?php _e('Form description', 'mailerlite'); ?></label>
52
+ </th>
53
  <td>
54
  <?php
55
  $settings = array(
56
  'media_buttons' => false,
57
+ 'textarea_rows' => 4,
58
  'tinymce' => array(
59
  'toolbar1' => 'bold,italic,underline,bullist,numlist,link,unlink,forecolor,alignleft,aligncenter,alignright,undo,redo',
60
  'toolbar2' => ''
61
  )
62
  );
63
 
64
+ wp_editor(stripslashes($form->data['description']), 'form_description', $settings);
65
  ?>
66
  </td>
67
  </tr>
68
  <tr>
69
+ <th><label for="button_name"><?php _e('Button title', 'mailerlite'); ?></label>
70
+ </th>
71
+ <td><input type="text" name="button_name" size="30" maxlength="255"
72
+ value="<?php echo $form->data['button']; ?>" id="button_name"> <span
73
+ class="description"><strong><?php _e('Example:'); ?></strong> <?php _e('Subscribe'); ?></span>
74
+ </td>
75
  </tr>
76
+ </tbody>
77
+ </table>
78
+ </div>
79
  </div>
80
+ <div class="postbox">
81
+ <h3><span><?php _e('Form fields and lists', 'mailerlite'); ?></span></h3>
82
+
83
+ <div class="inside">
84
+ <table class="form-table">
85
+ <tr>
86
+ <td style="vertical-align: top;">
87
+ <h2><?php _e('Fields', 'mailerlite'); ?></h2>
88
+ <table class="form-table">
89
+ <tbody>
90
+ <?php foreach ($fields->Fields as $field): ?>
91
+ <tr>
92
+ <th style="width:1%;"><input type="checkbox"
93
+ class="input_control"
94
+ name="form_selected_field[]"
95
+ value="<?php echo $field->field; ?>"<?php echo $field->field == 'email' || array_key_exists($field->field, $form->data['fields']) ? ' checked="checked"' : '';
96
+ echo $field->field == 'email' ? ' disabled="disabled"' : ''; ?>>
97
+ </th>
98
+ <td><input type="text" id="field_<?php echo $field->field; ?>"
99
+ name="form_field[<?php echo $field->field; ?>]"
100
+ size="30" maxlength="255"
101
+ value="<?php echo array_key_exists($field->field, $form->data['fields']) ? $form->data['fields'][$field->field] : $field->title; ?>"<?php echo $field->field == 'email' || array_key_exists($field->field, $form->data['fields']) ? '' : ' disabled="disabled"'; ?>>
102
+ </td>
103
+ </tr>
104
+ <?php endforeach; ?>
105
+ </tbody>
106
+ </table>
107
+ </td>
108
+ <td style="vertical-align: top;">
109
+ <h2><?php _e('Lists', 'mailerlite'); ?></h2>
110
+ <table class="form-table">
111
+ <tbody>
112
+ <?php foreach ($lists->Results as $list): ?>
113
+ <tr>
114
+ <th style="width:1%;"><input id="list_<?php echo $list->id; ?>"
115
+ type="checkbox"
116
+ class="input_control"
117
+ name="form_lists[]"
118
+ value="<?php echo $list->id; ?>"<?php echo in_array($list->id, $form->data['lists']) ? ' checked="checked"' : ''; ?>>
119
+ </th>
120
+ <td><label
121
+ for="list_<?php echo $list->id; ?>"><?php echo $list->name; ?></label>
122
+ </td>
123
+ </tr>
124
  <?php endforeach; ?>
125
+ </tbody>
126
+ </table>
127
+ </td>
128
+ </tr>
129
+ </table>
130
+ <div class="submit">
131
+ <input class="button-primary mailerlite-pull-right"
132
+ value="<?php _e('Save form', 'mailerlite'); ?>"
133
+ name="save_custom_signup_form" type="submit">
134
+ <a class="button-secondary"
135
+ href="<?php echo admin_url('admin.php?page=mailerlite_main'); ?>"><?php echo __('Back', 'mailerlite'); ?></a>
136
+ </div>
 
 
 
 
 
 
 
 
 
137
  </div>
138
  </div>
139
+ </form>
140
+ </div>
141
  </div>
142
  </div>
143
  </div>
 
144
 
145
+ <script type="text/javascript">
146
+ jQuery(document).ready(function ($) {
147
+ $(".wp-editor-tabs").remove();
148
 
149
+ var checkbox_class = $('.input_control');
150
 
151
+ checkbox_class.click(function () {
152
+ var input = $('input#field_' + $(this).attr('value'));
153
 
154
+ if ($(this).prop('checked') == false) {
155
+ input.attr('disabled', true);
156
+ }
157
+ else {
158
+ input.attr('disabled', false);
159
+ }
160
+ });
 
161
  });
162
+ </script>
 
163
 
164
  <?php /**/
include/templates/admin/edit_embedded.php CHANGED
@@ -1,45 +1,59 @@
1
  <?php defined('ABSPATH') or die("No direct access allowed!"); ?>
2
- <?php include_once ('header.php'); ?>
3
 
4
  <div class="wrap columns-2 dd-wrap">
5
  <h2><?php echo __('Edit webform', 'mailerlite'); ?></h2>
6
  <?php if (isset($result) && $result == 'success'): ?>
7
- <div id="message" class="updated below-h2"><p><?php _e('Form saved.', 'mailerlite'); ?> <a href="<?php echo admin_url('admin.php?page=mailerlite_main'); ?>"><?php _e('Back to forms list', 'mailerlite'); ?></a></p></div>
 
 
8
  <?php endif; ?>
9
  <div id="poststuff" class="metabox-holder has-right-sidebar">
10
  <?php include("sidebar.php"); ?>
11
  <div id="post-body">
12
  <div id="post-body-content">
13
- <form action="<?php echo admin_url('admin.php?page=mailerlite_main&view=edit&id=' . (isset($_GET['id']) ? $_GET['id'] : 0) ); ?>" method="post">
 
 
14
  <div class="postbox">
15
  <h3><span><?php echo __('Webform details', 'mailerlite'); ?></span></h3>
 
16
  <div class="inside">
17
  <table class="form-table">
18
  <tbody>
19
  <tr>
20
- <th><label for="form_name"><?php echo __('Form title', 'mailerlite'); ?></label></th>
21
- <td><input type="text" name="form_name" size="30" maxlength="255" value="<?php echo $form->name; ?>" id="form_name"> <span class="description"><strong><?php echo __('Tip:', 'mailerlite'); ?></strong> <?php echo __("This title won't be displayed in public!", 'mailerlite'); ?></span></td>
 
 
 
 
22
  </tr>
23
  <tr>
24
  <th><label for="form_webform_id"><?php _e('Webform', 'mailerlite'); ?></label></th>
25
  <td>
26
  <select id="form_webform_id" name="form_webform_id">
27
  <?php foreach ($webforms->Results as $webform): ?>
28
- <option data-code="<?php echo $webform->code; ?>" value="<?php echo $webform->id; ?>"<?php echo $webform->id == $form->data['id'] ? ' selected="selected"' : ''; ?>><?php echo $webform->name; ?></option>
 
29
  <?php endforeach; ?>
30
  </select>
31
  </td>
32
  </tr>
33
  <tr>
34
  <td colspan="2">
35
- <div id="webform_example">​</div>​​​​​​​
 
36
  </td>
37
  </tr>
38
  </tbody>
39
  </table>
40
  <div class="submit">
41
- <input class="button-primary mailerlite-pull-right" value="<?php _e('Save form', 'mailerlite'); ?>" name="save_embedded_signup_form" type="submit">
42
- <a class="button-secondary" href="<?php echo admin_url('admin.php?page=mailerlite_main'); ?>"><?php echo __('Back', 'mailerlite'); ?></a>
 
 
 
43
  </div>
44
  </div>
45
  </div>
@@ -50,15 +64,19 @@
50
  </div>
51
 
52
  <script type="text/javascript">
53
- jQuery(window).load(function() {
54
  var select = jQuery("#form_webform_id");
55
  loadIframe(select.children("option:selected").attr('data-code'));
56
- select.change(function() {
57
  loadIframe(jQuery("option:selected", this).attr('data-code'));
58
  });
59
  });
60
 
61
  function loadIframe(code) {
62
- jQuery('#webform_example').html(jQuery('<iframe></iframe>', { id: 'webform_example_iframe', src: "https://app.mailerlite.com/webforms/submit/"+code+"/", style: 'width:100%;height:350px;' }));
 
 
 
 
63
  }
64
  </script>
1
  <?php defined('ABSPATH') or die("No direct access allowed!"); ?>
2
+ <?php include_once('header.php'); ?>
3
 
4
  <div class="wrap columns-2 dd-wrap">
5
  <h2><?php echo __('Edit webform', 'mailerlite'); ?></h2>
6
  <?php if (isset($result) && $result == 'success'): ?>
7
+ <div id="message" class="updated below-h2"><p><?php _e('Form saved.', 'mailerlite'); ?> <a
8
+ href="<?php echo admin_url('admin.php?page=mailerlite_main'); ?>"><?php _e('Back to forms list', 'mailerlite'); ?></a>
9
+ </p></div>
10
  <?php endif; ?>
11
  <div id="poststuff" class="metabox-holder has-right-sidebar">
12
  <?php include("sidebar.php"); ?>
13
  <div id="post-body">
14
  <div id="post-body-content">
15
+ <form
16
+ action="<?php echo admin_url('admin.php?page=mailerlite_main&view=edit&id=' . (isset($_GET['id']) ? $_GET['id'] : 0)); ?>"
17
+ method="post">
18
  <div class="postbox">
19
  <h3><span><?php echo __('Webform details', 'mailerlite'); ?></span></h3>
20
+
21
  <div class="inside">
22
  <table class="form-table">
23
  <tbody>
24
  <tr>
25
+ <th><label for="form_name"><?php echo __('Form title', 'mailerlite'); ?></label>
26
+ </th>
27
+ <td><input type="text" name="form_name" size="30" maxlength="255"
28
+ value="<?php echo $form->name; ?>" id="form_name"> <span
29
+ class="description"><strong><?php echo __('Tip:', 'mailerlite'); ?></strong> <?php echo __("This title won't be displayed in public!", 'mailerlite'); ?></span>
30
+ </td>
31
  </tr>
32
  <tr>
33
  <th><label for="form_webform_id"><?php _e('Webform', 'mailerlite'); ?></label></th>
34
  <td>
35
  <select id="form_webform_id" name="form_webform_id">
36
  <?php foreach ($webforms->Results as $webform): ?>
37
+ <option data-code="<?php echo $webform->code; ?>"
38
+ value="<?php echo $webform->id; ?>"<?php echo $webform->id == $form->data['id'] ? ' selected="selected"' : ''; ?>><?php echo $webform->name; ?></option>
39
  <?php endforeach; ?>
40
  </select>
41
  </td>
42
  </tr>
43
  <tr>
44
  <td colspan="2">
45
+ <div id="webform_example">​</div>
46
+ ​​​​​​​
47
  </td>
48
  </tr>
49
  </tbody>
50
  </table>
51
  <div class="submit">
52
+ <input class="button-primary mailerlite-pull-right"
53
+ value="<?php _e('Save form', 'mailerlite'); ?>" name="save_embedded_signup_form"
54
+ type="submit">
55
+ <a class="button-secondary"
56
+ href="<?php echo admin_url('admin.php?page=mailerlite_main'); ?>"><?php echo __('Back', 'mailerlite'); ?></a>
57
  </div>
58
  </div>
59
  </div>
64
  </div>
65
 
66
  <script type="text/javascript">
67
+ jQuery(window).load(function () {
68
  var select = jQuery("#form_webform_id");
69
  loadIframe(select.children("option:selected").attr('data-code'));
70
+ select.change(function () {
71
  loadIframe(jQuery("option:selected", this).attr('data-code'));
72
  });
73
  });
74
 
75
  function loadIframe(code) {
76
+ jQuery('#webform_example').html(jQuery('<iframe></iframe>', {
77
+ id: 'webform_example_iframe',
78
+ src: "https://app.mailerlite.com/webforms/submit/" + code + "/",
79
+ style: 'width:100%;height:350px;'
80
+ }));
81
  }
82
  </script>
include/templates/admin/main.php CHANGED
@@ -1,45 +1,54 @@
1
  <?php defined('ABSPATH') or die("No direct access allowed!"); ?>
2
- <?php include_once ('header.php'); ?>
3
 
4
  <div class="wrap columns-2 dd-wrap">
5
- <h2><?php echo __('Signup forms', 'mailerlite'); ?> <a href="<?php echo admin_url( 'admin.php?page=mailerlite_main&view=create' ); ?>" class="add-new-h2"><?php _e('Add New', 'mailerlite'); ?></a></h2>
 
 
 
6
  <div id="poststuff" class="metabox-holder has-right-sidebar">
7
  <?php include("sidebar.php"); ?>
8
  <div id="post-body">
9
  <div id="post-body-content">
10
- <?php if ( !empty($forms_data) ): ?>
11
- <table class="wp-list-table widefat fixed forms">
12
- <thead>
13
  <tr>
14
  <th class="column-posts num"><?php _e('ID', 'mailerlite'); ?></th>
15
  <th><?php _e('Name', 'mailerlite'); ?></th>
16
  <th class="column-author"><?php _e('Type', 'mailerlite'); ?></th>
17
  <th class="column-date"><?php _e('Date', 'mailerlite'); ?></th>
18
  </tr>
19
- </thead>
20
- <tbody id="the-list">
21
  <?php $i = 1; ?>
22
- <?php foreach($forms_data as $form): ?>
23
- <?php $i++; ?>
24
- <tr<?php echo $i % 2 == 0 ? ' class="alternate"' : ''; ?>>
25
- <td class="column-posts num"><?php echo $form->id; ?></td>
26
- <td>
27
- <strong><a class="row-title" href="<?php echo admin_url( 'admin.php?page=mailerlite_main&view=edit&id=' . $form->id ); ?>"><?php echo $form->name; ?></a></strong>
28
- <div class="row-actions">
29
- <span class="edit"><a href="<?php echo admin_url( 'admin.php?page=mailerlite_main&view=edit&id=' . $form->id ); ?>"><?php _e('Edit', 'mailerlite'); ?></a> | </span>
30
- <span class="trash"><a onclick="return confirm('<?php _e("Are you sure you want to delete this form?", 'mailerlite'); ?>')" href="<?php echo admin_url( 'admin.php?page=mailerlite_main&view=delete&noheader=true&id=' . $form->id ); ?>"><?php _e('Delete', 'mailerlite'); ?></a></span>
31
- </div>
32
- </td>
33
- <td><?php echo $form->type == 1 ? __('Custom form', 'mailerlite') : __('Embedded form', 'mailerlite'); ?></td>
34
- <td><?php echo $form->time; ?></td>
35
- </tr>
 
 
 
 
 
36
  <?php endforeach; ?>
37
- </tbody>
38
- </table>
39
  <?php else: ?>
40
  <div class="postbox mailerlite-empty-list">
41
  <div class="inside mailerlite-text-center">
42
- <a href="<?php echo admin_url( 'admin.php?page=mailerlite_main&view=create' ); ?>" class="button-large button-primary"><?php _e('Add signup form', 'mailerlite'); ?></a>
 
43
  </div>
44
  </div>
45
  <?php endif; ?>
1
  <?php defined('ABSPATH') or die("No direct access allowed!"); ?>
2
+ <?php include_once('header.php'); ?>
3
 
4
  <div class="wrap columns-2 dd-wrap">
5
+ <h2><?php echo __('Signup forms', 'mailerlite'); ?> <a
6
+ href="<?php echo admin_url('admin.php?page=mailerlite_main&view=create'); ?>"
7
+ class="add-new-h2"><?php _e('Add New', 'mailerlite'); ?></a></h2>
8
+
9
  <div id="poststuff" class="metabox-holder has-right-sidebar">
10
  <?php include("sidebar.php"); ?>
11
  <div id="post-body">
12
  <div id="post-body-content">
13
+ <?php if (!empty($forms_data)): ?>
14
+ <table class="wp-list-table widefat fixed forms">
15
+ <thead>
16
  <tr>
17
  <th class="column-posts num"><?php _e('ID', 'mailerlite'); ?></th>
18
  <th><?php _e('Name', 'mailerlite'); ?></th>
19
  <th class="column-author"><?php _e('Type', 'mailerlite'); ?></th>
20
  <th class="column-date"><?php _e('Date', 'mailerlite'); ?></th>
21
  </tr>
22
+ </thead>
23
+ <tbody id="the-list">
24
  <?php $i = 1; ?>
25
+ <?php foreach ($forms_data as $form): ?>
26
+ <?php $i++; ?>
27
+ <tr<?php echo $i % 2 == 0 ? ' class="alternate"' : ''; ?>>
28
+ <td class="column-posts num"><?php echo $form->id; ?></td>
29
+ <td>
30
+ <strong><a class="row-title"
31
+ href="<?php echo admin_url('admin.php?page=mailerlite_main&view=edit&id=' . $form->id); ?>"><?php echo $form->name; ?></a></strong>
32
+
33
+ <div class="row-actions">
34
+ <span class="edit"><a
35
+ href="<?php echo admin_url('admin.php?page=mailerlite_main&view=edit&id=' . $form->id); ?>"><?php _e('Edit', 'mailerlite'); ?></a> | </span>
36
+ <span class="trash"><a
37
+ onclick="return confirm('<?php _e("Are you sure you want to delete this form?", 'mailerlite'); ?>')"
38
+ href="<?php echo admin_url('admin.php?page=mailerlite_main&view=delete&noheader=true&id=' . $form->id); ?>"><?php _e('Delete', 'mailerlite'); ?></a></span>
39
+ </div>
40
+ </td>
41
+ <td><?php echo $form->type == 1 ? __('Custom form', 'mailerlite') : __('Embedded form', 'mailerlite'); ?></td>
42
+ <td><?php echo $form->time; ?></td>
43
+ </tr>
44
  <?php endforeach; ?>
45
+ </tbody>
46
+ </table>
47
  <?php else: ?>
48
  <div class="postbox mailerlite-empty-list">
49
  <div class="inside mailerlite-text-center">
50
+ <a href="<?php echo admin_url('admin.php?page=mailerlite_main&view=create'); ?>"
51
+ class="button-large button-primary"><?php _e('Add signup form', 'mailerlite'); ?></a>
52
  </div>
53
  </div>
54
  <?php endif; ?>
include/templates/admin/settings.php CHANGED
@@ -1,14 +1,15 @@
1
  <?php defined('ABSPATH') or die("No direct access allowed!"); ?>
2
- <?php include_once ('header.php'); ?>
3
 
4
  <div class="wrap columns-2 dd-wrap">
5
  <h2><?php _e('Plugin settings', 'mailerlite'); ?></h2>
 
6
  <div id="poststuff" class="metabox-holder has-right-sidebar">
7
  <?php include("sidebar.php"); ?>
8
  <div id="post-body">
9
  <div id="post-body-content">
10
  <p><?php _e('Here you able to change your API key!', 'mailerlite'); ?></p>
11
- <?php if($mailerlite_error): ?>
12
  <div class="error">
13
  <p><?php echo $mailerlite_error; ?></p>
14
  </div>
@@ -17,19 +18,25 @@
17
  <div class="mailerlite-activate">
18
  <div class="description-block">
19
  <p class="title"><?php _e('Enter an API key', 'mailerlite'); ?></p>
20
- <p><?php _e("Don't know where to find it?", 'mailerlite'); ?> <a href="http://mailerlite.helpscoutdocs.com/article/12-does-mailerlite-offer-an-api" target="_blank"><?php _e("Check it here!", 'mailerlite'); ?></a></p>
 
 
 
21
  </div>
22
  <div class="input-block">
23
  <form action="" method="post" id="enter-mailerlite-key">
24
- <input type="text" name="mailerlite_key" class="regular-text" placeholder="API-key" value="<?php echo $api_key; ?>" />
25
- <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save this key', 'mailerlite'); ?>">
 
 
26
  <input type="hidden" name="action" value="enter-mailerlite-key">
27
  </form>
28
  </div>
29
  <div class="clear"></div>
30
  </div>
31
  <p><strong><?php _e("Don't have an account?", 'mailerlite'); ?></strong></p>
32
- <a href="https://www.mailerlite.com/signup" target="_blank" class="button button-secondary"><?php _e('Register!', 'mailerlite'); ?></a>
 
33
  </div>
34
  </div>
35
  </div>
1
  <?php defined('ABSPATH') or die("No direct access allowed!"); ?>
2
+ <?php include_once('header.php'); ?>
3
 
4
  <div class="wrap columns-2 dd-wrap">
5
  <h2><?php _e('Plugin settings', 'mailerlite'); ?></h2>
6
+
7
  <div id="poststuff" class="metabox-holder has-right-sidebar">
8
  <?php include("sidebar.php"); ?>
9
  <div id="post-body">
10
  <div id="post-body-content">
11
  <p><?php _e('Here you able to change your API key!', 'mailerlite'); ?></p>
12
+ <?php if ($mailerlite_error): ?>
13
  <div class="error">
14
  <p><?php echo $mailerlite_error; ?></p>
15
  </div>
18
  <div class="mailerlite-activate">
19
  <div class="description-block">
20
  <p class="title"><?php _e('Enter an API key', 'mailerlite'); ?></p>
21
+
22
+ <p><?php _e("Don't know where to find it?", 'mailerlite'); ?> <a
23
+ href="http://mailerlite.helpscoutdocs.com/article/12-does-mailerlite-offer-an-api"
24
+ target="_blank"><?php _e("Check it here!", 'mailerlite'); ?></a></p>
25
  </div>
26
  <div class="input-block">
27
  <form action="" method="post" id="enter-mailerlite-key">
28
+ <input type="text" name="mailerlite_key" class="regular-text" placeholder="API-key"
29
+ value="<?php echo $api_key; ?>"/>
30
+ <input type="submit" name="submit" id="submit" class="button button-primary"
31
+ value="<?php _e('Save this key', 'mailerlite'); ?>">
32
  <input type="hidden" name="action" value="enter-mailerlite-key">
33
  </form>
34
  </div>
35
  <div class="clear"></div>
36
  </div>
37
  <p><strong><?php _e("Don't have an account?", 'mailerlite'); ?></strong></p>
38
+ <a href="https://www.mailerlite.com/signup" target="_blank"
39
+ class="button button-secondary"><?php _e('Register!', 'mailerlite'); ?></a>
40
  </div>
41
  </div>
42
  </div>
include/templates/admin/sidebar.php CHANGED
@@ -2,8 +2,10 @@
2
 
3
  <div class="postbox">
4
  <h3><?php echo _e('Need help?', 'mailerlite'); ?></h3>
 
5
  <div class="inside">
6
  <p><?php echo _e('Have any questions? Stuck on something or found bug? Feel free to contact us!', 'mailerlite'); ?></p>
 
7
  <p><a href="mailto:info@mailerlite.com">info@mailerlite.com</a></p>
8
  </div>
9
  </div>
2
 
3
  <div class="postbox">
4
  <h3><?php echo _e('Need help?', 'mailerlite'); ?></h3>
5
+
6
  <div class="inside">
7
  <p><?php echo _e('Have any questions? Stuck on something or found bug? Feel free to contact us!', 'mailerlite'); ?></p>
8
+
9
  <p><a href="mailto:info@mailerlite.com">info@mailerlite.com</a></p>
10
  </div>
11
  </div>
include/templates/common/tiny_mce.php CHANGED
@@ -1,12 +1,14 @@
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
 
7
  <body>
8
 
9
  <h2>Add form</h2>
 
10
  <form id="mailerlite_tinymce_form" action="" method="post">
11
 
12
  <p><?php _e('Select form from list below, and hit "Add Shortcode" to add the shortcode to your post!', 'mailerlite'); ?></p>
@@ -15,7 +17,7 @@
15
  <label for="mailerlite_form_id">Form</label><br/>
16
  <select class="widefat" id="mailerlite_form_id" name="mailerlite_form_id">
17
  <?php foreach ($forms as $form): ?>
18
- <option value="<?php echo $form->id; ?>"><?php echo $form->name; ?></option>
19
  <?php endforeach; ?>
20
  </select>
21
  </p>
@@ -24,10 +26,10 @@
24
 
25
  </form>
26
  <script type="text/javascript">
27
- jQuery(document).ready(function() {
28
- jQuery('form#mailerlite_tinymce_form input:button').click(function() {
29
  var form_id = jQuery('form#mailerlite_tinymce_form #mailerlite_form_id').val();
30
- var shortcode = '[mailerlite_form form_id='+form_id+']';
31
  tinyMCEPopup.execCommand("mceInsertContent", false, shortcode);
32
  tinyMCEPopup.close();
33
  return false;
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"
5
+ src="<?php echo site_url() . '/wp-includes/js/tinymce/tiny_mce_popup.js'; ?>"></script>
6
  </head>
7
 
8
  <body>
9
 
10
  <h2>Add form</h2>
11
+
12
  <form id="mailerlite_tinymce_form" action="" method="post">
13
 
14
  <p><?php _e('Select form from list below, and hit "Add Shortcode" to add the shortcode to your post!', 'mailerlite'); ?></p>
17
  <label for="mailerlite_form_id">Form</label><br/>
18
  <select class="widefat" id="mailerlite_form_id" name="mailerlite_form_id">
19
  <?php foreach ($forms as $form): ?>
20
+ <option value="<?php echo $form->id; ?>"><?php echo $form->name; ?></option>
21
  <?php endforeach; ?>
22
  </select>
23
  </p>
26
 
27
  </form>
28
  <script type="text/javascript">
29
+ jQuery(document).ready(function () {
30
+ jQuery('form#mailerlite_tinymce_form input:button').click(function () {
31
  var form_id = jQuery('form#mailerlite_tinymce_form #mailerlite_form_id').val();
32
+ var shortcode = '[mailerlite_form form_id=' + form_id + ']';
33
  tinyMCEPopup.execCommand("mceInsertContent", false, shortcode);
34
  tinyMCEPopup.close();
35
  return false;
include/templates/forms/custom_form.php CHANGED
@@ -7,22 +7,26 @@
7
  <div class="mailerlite-form-description"><?php echo stripslashes($form_data['description']); ?></div>
8
  <div class="mailerlite-form-inputs">
9
  <?php foreach ($form_data['fields'] as $field => $title): ?>
10
- <?php if ($field == 'email') {
11
- $input_type = 'email';
12
- } else {
13
- $input_type = 'text';
14
- } ?>
15
- <div class="mailerlite-form-field">
16
- <label for="mailerlite-<?php echo $form_id; ?>-field-<?php echo $field; ?>"><?php echo $title; ?></label>
17
- <input id="mailerlite-<?php echo $form_id; ?>-field-<?php echo $field; ?>" type="<?php echo $input_type; ?>" required="required" name="form_fields[<?php echo $field; ?>]" />
18
- </div>
 
 
 
19
  <?php endforeach; ?>
20
  <div class="mailerlite-form-loader"><?php _e('Please wait...', 'mailerlite'); ?></div>
21
  <div class="mailerlite-subscribe-button-container">
22
- <input class="mailerlite-subscribe-submit" type="submit" value="<?php echo $form_data['button']; ?>" />
 
23
  </div>
24
- <input type="hidden" name="form_id" value="<?php echo $form_id; ?>" />
25
- <input type="hidden" name="action" value="mailerlite_subscribe_form" />
26
  </div>
27
  <div class="mailerlite-form-response">
28
  <h4><?php _e('Thank you for signup!', 'mailerlite'); ?></h4>
@@ -33,23 +37,23 @@
33
 
34
  <script type="text/javascript">
35
 
36
- jQuery(document).ready(function(){
37
  var form_container = jQuery("#mailerlite-form_<?php echo $form_id; ?>[data-temp-id=<?php echo $unique_id; ?>] form");
38
- form_container.submit(function(e) {
39
  e.preventDefault();
40
  }).validate({
41
- submitHandler: function(form) {
42
 
43
  jQuery(this.submitButton).prop('disabled', true);
44
 
45
- form_container.find('.mailerlite-subscribe-button-container').fadeOut(function() {
46
  form_container.find('.mailerlite-form-loader').fadeIn()
47
  });
48
 
49
  var data = jQuery(form).serialize();
50
 
51
- jQuery.post('<?php echo admin_url( 'admin-ajax.php' ); ?>', data, function(response) {
52
- form_container.find('.mailerlite-form-inputs').fadeOut(function() {
53
  form_container.find('.mailerlite-form-response').fadeIn()
54
  });
55
  });
7
  <div class="mailerlite-form-description"><?php echo stripslashes($form_data['description']); ?></div>
8
  <div class="mailerlite-form-inputs">
9
  <?php foreach ($form_data['fields'] as $field => $title): ?>
10
+ <?php if ($field == 'email') {
11
+ $input_type = 'email';
12
+ } else {
13
+ $input_type = 'text';
14
+ } ?>
15
+ <div class="mailerlite-form-field">
16
+ <label
17
+ for="mailerlite-<?php echo $form_id; ?>-field-<?php echo $field; ?>"><?php echo $title; ?></label>
18
+ <input id="mailerlite-<?php echo $form_id; ?>-field-<?php echo $field; ?>"
19
+ type="<?php echo $input_type; ?>" required="required"
20
+ name="form_fields[<?php echo $field; ?>]"/>
21
+ </div>
22
  <?php endforeach; ?>
23
  <div class="mailerlite-form-loader"><?php _e('Please wait...', 'mailerlite'); ?></div>
24
  <div class="mailerlite-subscribe-button-container">
25
+ <input class="mailerlite-subscribe-submit" type="submit"
26
+ value="<?php echo $form_data['button']; ?>"/>
27
  </div>
28
+ <input type="hidden" name="form_id" value="<?php echo $form_id; ?>"/>
29
+ <input type="hidden" name="action" value="mailerlite_subscribe_form"/>
30
  </div>
31
  <div class="mailerlite-form-response">
32
  <h4><?php _e('Thank you for signup!', 'mailerlite'); ?></h4>
37
 
38
  <script type="text/javascript">
39
 
40
+ jQuery(document).ready(function () {
41
  var form_container = jQuery("#mailerlite-form_<?php echo $form_id; ?>[data-temp-id=<?php echo $unique_id; ?>] form");
42
+ form_container.submit(function (e) {
43
  e.preventDefault();
44
  }).validate({
45
+ submitHandler: function (form) {
46
 
47
  jQuery(this.submitButton).prop('disabled', true);
48
 
49
+ form_container.find('.mailerlite-subscribe-button-container').fadeOut(function () {
50
  form_container.find('.mailerlite-form-loader').fadeIn()
51
  });
52
 
53
  var data = jQuery(form).serialize();
54
 
55
+ jQuery.post('<?php echo admin_url( 'admin-ajax.php' ); ?>', data, function (response) {
56
+ form_container.find('.mailerlite-form-inputs').fadeOut(function () {
57
  form_container.find('.mailerlite-form-response').fadeIn()
58
  });
59
  });
include/templates/forms/embedded_form.php CHANGED
@@ -1 +1,2 @@
1
- <script type="text/javascript" src="//app.mailerlite.com/data/webforms/<?php echo $form_data['id']; ?>/<?php echo $form_data['code']; ?>.js?v=<?php echo time(); ?>"></script>
 
1
+ <script type="text/javascript"
2
+ src="//app.mailerlite.com/data/webforms/<?php echo $form_data['id']; ?>/<?php echo $form_data['code']; ?>.js?v=<?php echo time(); ?>"></script>
libs/mailerlite_rest/ML_Campaigns.php CHANGED
@@ -1,57 +1,55 @@
1
  <?php
2
-
3
- require_once dirname(__FILE__).'/base/ML_Rest.php';
4
-
5
- class ML_Campaigns extends ML_Rest
6
- {
7
- function ML_Campaigns( $api_key )
8
- {
9
- $this->name = 'campaigns';
10
 
11
- parent::__construct($api_key);
12
- }
13
 
14
- function getRecipients( )
15
- {
16
- $this->path .= 'recipients/';
 
 
17
 
18
- return $this->execute( 'GET' );
19
- }
20
 
21
- function getOpens( )
22
- {
23
- $this->path .= 'opens/';
24
 
25
- return $this->execute( 'GET' );
26
- }
27
 
28
- function getClicks( )
29
- {
30
- $this->path .= 'clicks/';
31
 
32
- return $this->execute( 'GET' );
33
- }
34
 
35
- function getUnsubscribes( )
36
- {
37
- $this->path .= 'unsubscribes/';
38
 
39
- return $this->execute( 'GET' );
40
- }
41
 
42
- function getBounces( )
43
- {
44
- $this->path .= 'bounces/';
45
 
46
- return $this->execute( 'GET' );
47
- }
48
 
49
- function getJunk( )
50
- {
51
- $this->path .= 'junks/';
52
 
53
- return $this->execute( 'GET' );
54
- }
55
- }
56
 
57
- ?>
 
 
 
 
 
 
1
  <?php
 
 
 
 
 
 
 
 
2
 
3
+ require_once dirname(__FILE__) . '/base/ML_Rest.php';
 
4
 
5
+ class ML_Campaigns extends ML_Rest
6
+ {
7
+ function ML_Campaigns($api_key)
8
+ {
9
+ $this->name = 'campaigns';
10
 
11
+ parent::__construct($api_key);
12
+ }
13
 
14
+ function getRecipients()
15
+ {
16
+ $this->path .= 'recipients/';
17
 
18
+ return $this->execute('GET');
19
+ }
20
 
21
+ function getOpens()
22
+ {
23
+ $this->path .= 'opens/';
24
 
25
+ return $this->execute('GET');
26
+ }
27
 
28
+ function getClicks()
29
+ {
30
+ $this->path .= 'clicks/';
31
 
32
+ return $this->execute('GET');
33
+ }
34
 
35
+ function getUnsubscribes()
36
+ {
37
+ $this->path .= 'unsubscribes/';
38
 
39
+ return $this->execute('GET');
40
+ }
41
 
42
+ function getBounces()
43
+ {
44
+ $this->path .= 'bounces/';
45
 
46
+ return $this->execute('GET');
47
+ }
 
48
 
49
+ function getJunk()
50
+ {
51
+ $this->path .= 'junks/';
52
+
53
+ return $this->execute('GET');
54
+ }
55
+ }
libs/mailerlite_rest/ML_Lists.php CHANGED
@@ -1,42 +1,40 @@
1
  <?php
2
-
3
- require_once dirname(__FILE__).'/base/ML_Rest.php';
4
-
5
- class ML_Lists extends ML_Rest
6
- {
7
- function ML_Lists( $api_key )
8
- {
9
- $this->name = 'lists';
10
-
11
- parent::__construct($api_key);
12
- }
13
-
14
- function getActive( )
15
- {
16
- $this->path .= 'active/';
17
-
18
- return $this->execute( 'GET' );
19
- }
20
-
21
- function getUnsubscribed( )
22
- {
23
- $this->path .= 'unsubscribed/';
24
-
25
- return $this->execute( 'GET' );
26
- }
27
-
28
- function getBounced( )
29
- {
30
- $this->path .= 'bounced/';
31
-
32
- return $this->execute( 'GET' );
33
- }
34
-
35
- function getFields( )
36
- {
37
- $this->path .= 'fields/';
38
- return $this->execute( 'GET' );
39
- }
40
- }
41
-
42
- ?>
1
  <?php
2
+
3
+ require_once dirname(__FILE__) . '/base/ML_Rest.php';
4
+
5
+ class ML_Lists extends ML_Rest
6
+ {
7
+ function ML_Lists($api_key)
8
+ {
9
+ $this->name = 'lists';
10
+
11
+ parent::__construct($api_key);
12
+ }
13
+
14
+ function getActive()
15
+ {
16
+ $this->path .= 'active/';
17
+
18
+ return $this->execute('GET');
19
+ }
20
+
21
+ function getUnsubscribed()
22
+ {
23
+ $this->path .= 'unsubscribed/';
24
+
25
+ return $this->execute('GET');
26
+ }
27
+
28
+ function getBounced()
29
+ {
30
+ $this->path .= 'bounced/';
31
+
32
+ return $this->execute('GET');
33
+ }
34
+
35
+ function getFields()
36
+ {
37
+ $this->path .= 'fields/';
38
+ return $this->execute('GET');
39
+ }
40
+ }
 
 
libs/mailerlite_rest/ML_Subscribers.php CHANGED
@@ -1,59 +1,57 @@
1
  <?php
2
 
3
- require_once dirname(__FILE__).'/base/ML_Rest.php';
4
-
5
- class ML_Subscribers extends ML_Rest
6
- {
7
- public function ML_Subscribers( $api_key )
8
- {
9
- $this->name = 'subscribers';
10
 
11
- parent::__construct($api_key);
12
- }
 
 
 
13
 
14
- function add( $subscriber = null, $resubscribe = 0 )
15
- {
16
- $subscriber['resubscribe'] = $resubscribe;
17
 
18
- return $this->execute( 'POST', $subscriber );
19
- }
 
20
 
21
- function addAll( $subscribers, $resubscribe = 0 )
22
- {
23
- $data['resubscribe'] = $resubscribe;
24
 
25
- $data['subscribers'] = $subscribers;
 
 
26
 
27
- $this->path .= 'import/';
28
 
29
- return $this->execute( 'POST', $data );
30
- }
31
 
32
- function get( $email = null, $history = 0 )
33
- {
34
- $this->setId( null );
35
 
36
- $this->path .= '?email=' . urlencode( $email );
 
 
37
 
38
- if ( $history )
39
- $this->path .= '&history=1';
40
 
41
- return $this->execute( 'GET' );
42
- }
43
 
44
- function remove( $email = null )
45
- {
46
- $this->path .= '?email=' . urlencode( $email );
47
 
48
- return $this->execute( 'DELETE' );
49
- }
 
50
 
51
- function unsubscribe( $email )
52
- {
53
- $this->path .= 'unsubscribe/?email=' . urlencode( $email );
54
 
55
- return $this->execute( 'POST' );
56
- }
57
- }
58
 
59
- ?>
 
 
1
  <?php
2
 
3
+ require_once dirname(__FILE__) . '/base/ML_Rest.php';
 
 
 
 
 
 
4
 
5
+ class ML_Subscribers extends ML_Rest
6
+ {
7
+ public function ML_Subscribers($api_key)
8
+ {
9
+ $this->name = 'subscribers';
10
 
11
+ parent::__construct($api_key);
12
+ }
 
13
 
14
+ function add($subscriber = null, $resubscribe = 0)
15
+ {
16
+ $subscriber['resubscribe'] = $resubscribe;
17
 
18
+ return $this->execute('POST', $subscriber);
19
+ }
 
20
 
21
+ function addAll($subscribers, $resubscribe = 0)
22
+ {
23
+ $data['resubscribe'] = $resubscribe;
24
 
25
+ $data['subscribers'] = $subscribers;
26
 
27
+ $this->path .= 'import/';
 
28
 
29
+ return $this->execute('POST', $data);
30
+ }
 
31
 
32
+ function get($email = null, $history = 0)
33
+ {
34
+ $this->setId(null);
35
 
36
+ $this->path .= '?email=' . urlencode($email);
 
37
 
38
+ if ($history)
39
+ $this->path .= '&history=1';
40
 
41
+ return $this->execute('GET');
42
+ }
 
43
 
44
+ function remove($email = null)
45
+ {
46
+ $this->path .= '?email=' . urlencode($email);
47
 
48
+ return $this->execute('DELETE');
49
+ }
 
50
 
51
+ function unsubscribe($email)
52
+ {
53
+ $this->path .= 'unsubscribe/?email=' . urlencode($email);
54
 
55
+ return $this->execute('POST');
56
+ }
57
+ }
libs/mailerlite_rest/ML_Webforms.php CHANGED
@@ -1,15 +1,13 @@
1
  <?php
2
 
3
- require_once dirname(__FILE__).'/base/ML_Rest.php';
4
 
5
  class ML_Webforms extends ML_Rest
6
  {
7
- function ML_Webforms( $api_key )
8
  {
9
  $this->name = 'webforms';
10
 
11
  parent::__construct($api_key);
12
  }
13
- }
14
-
15
- ?>
1
  <?php
2
 
3
+ require_once dirname(__FILE__) . '/base/ML_Rest.php';
4
 
5
  class ML_Webforms extends ML_Rest
6
  {
7
+ function ML_Webforms($api_key)
8
  {
9
  $this->name = 'webforms';
10
 
11
  parent::__construct($api_key);
12
  }
13
+ }
 
 
libs/mailerlite_rest/base/ML_Rest.php CHANGED
@@ -1,61 +1,59 @@
1
  <?php
2
-
3
- require_once dirname(__FILE__) . '/ML_Rest_Base.php';
4
-
5
- class ML_Rest extends ML_Rest_Base
6
- {
7
- var $name = '';
8
-
9
- var $id = null;
10
-
11
- function __construct( $api_key )
12
- {
13
- parent::__construct();
14
-
15
- $this->apiKey = $api_key;
16
-
17
- $this->path = $this->url . $this->name . '/';
18
- }
19
-
20
- function setId( $id )
21
- {
22
- $this->id = $id;
23
-
24
- if ( $this->id )
25
- $this->path = $this->url . $this->name . '/' . $id . '/';
26
- else
27
- $this->path = $this->url . $this->name . '/';
28
-
29
- return $this;
30
- }
31
-
32
- function getAll( )
33
- {
34
- return $this->execute( 'GET' );
35
- }
36
-
37
- function get( $data = null )
38
- {
39
- if (!$this->id)
40
- throw new InvalidArgumentException('ID is not set.');
41
-
42
- return $this->execute( 'GET' );
43
- }
44
-
45
- function add( $data = null )
46
- {
47
- return $this->execute( 'POST', $data );
48
- }
49
-
50
- function put( $data = null)
51
- {
52
- return $this->execute( 'PUT', $data );
53
- }
54
-
55
- function remove( $data = null )
56
- {
57
- return $this->execute( 'DELETE' );
58
- }
59
- }
60
-
61
- ?>
1
  <?php
2
+
3
+ require_once dirname(__FILE__) . '/ML_Rest_Base.php';
4
+
5
+ class ML_Rest extends ML_Rest_Base
6
+ {
7
+ var $name = '';
8
+
9
+ var $id = null;
10
+
11
+ function __construct($api_key)
12
+ {
13
+ parent::__construct();
14
+
15
+ $this->apiKey = $api_key;
16
+
17
+ $this->path = $this->url . $this->name . '/';
18
+ }
19
+
20
+ function setId($id)
21
+ {
22
+ $this->id = $id;
23
+
24
+ if ($this->id)
25
+ $this->path = $this->url . $this->name . '/' . $id . '/';
26
+ else
27
+ $this->path = $this->url . $this->name . '/';
28
+
29
+ return $this;
30
+ }
31
+
32
+ function getAll()
33
+ {
34
+ return $this->execute('GET');
35
+ }
36
+
37
+ function get($data = null)
38
+ {
39
+ if (!$this->id)
40
+ throw new InvalidArgumentException('ID is not set.');
41
+
42
+ return $this->execute('GET');
43
+ }
44
+
45
+ function add($data = null)
46
+ {
47
+ return $this->execute('POST', $data);
48
+ }
49
+
50
+ function put($data = null)
51
+ {
52
+ return $this->execute('PUT', $data);
53
+ }
54
+
55
+ function remove($data = null)
56
+ {
57
+ return $this->execute('DELETE');
58
+ }
59
+ }
 
 
libs/mailerlite_rest/base/ML_Rest_Base.php CHANGED
@@ -2,233 +2,224 @@
2
 
3
  class ML_Rest_Base
4
  {
5
- protected $url;
6
- protected $verb;
7
- protected $requestBody;
8
- protected $requestLength;
9
- protected $username;
10
- protected $password;
11
- protected $acceptType;
12
- protected $responseBody;
13
- protected $responseInfo;
14
-
15
- protected $apiKey = '';
16
- protected $path = '';
17
-
18
- public function __construct ($url = 'https://app.mailerlite.com/api/v1/', $verb = 'GET')
19
- {
20
- $this->url = $url;
21
- $this->verb = $verb;
22
- $this->requestLength = 0;
23
- $this->username = null;
24
- $this->password = null;
25
- $this->acceptType = 'application/json';
26
- $this->responseBody = null;
27
- $this->responseInfo = null;
28
- }
29
-
30
- public function flush ()
31
- {
32
- $this->requestBody = null;
33
- $this->requestLength = 0;
34
- $this->verb = 'GET';
35
- $this->responseBody = null;
36
- $this->responseInfo = null;
37
- }
38
-
39
- public function execute ( $method = null, $data = null )
40
- {
41
- $ch = curl_init();
42
- $this->setAuth($ch);
43
-
44
- if ( $method )
45
- $this->verb = $method;
46
-
47
- $this->requestBody = $data;
48
-
49
- $this->buildPostBody();
50
-
51
- try
52
- {
53
- switch (strtoupper($this->verb))
54
- {
55
- case 'GET':
56
- $this->executeGet($ch);
57
- break;
58
- case 'POST':
59
- $this->executePost($ch);
60
- break;
61
- case 'PUT':
62
- $this->executePut($ch);
63
- break;
64
- case 'DELETE':
65
- $this->executeDelete($ch);
66
- break;
67
- default:
68
- throw new InvalidArgumentException('Current verb (' . $this->verb . ') is an invalid REST verb.');
69
- }
70
- }
71
- catch (InvalidArgumentException $e)
72
- {
73
- curl_close($ch);
74
- throw $e;
75
- }
76
- catch (Exception $e)
77
- {
78
- curl_close($ch);
79
- throw $e;
80
- }
81
-
82
- return $this->responseBody;
83
- }
84
-
85
- public function buildPostBody ()
86
- {
87
- $data = $this->requestBody;
88
-
89
- $data['apiKey'] = $this->apiKey;
90
-
91
- if (!is_array($data))
92
- {
93
- throw new InvalidArgumentException('Invalid data input for postBody. Array expected');
94
- }
95
-
96
- $data = http_build_query($data, '', '&');
97
- $this->requestBody = $data;
98
- }
99
-
100
- protected function executeGet ($ch)
101
- {
102
- $this->path .= ( strpos( $this->path, '?' ) === false ? '?' : '&' ) . $this->requestBody;
103
-
104
- $this->doExecute($ch);
105
- }
106
-
107
- protected function executePost ($ch)
108
- {
109
- curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody);
110
- curl_setopt($ch, CURLOPT_POST, 1);
111
-
112
- $this->doExecute($ch);
113
- }
114
-
115
- protected function executePut ($ch)
116
- {
117
- $this->requestLength = strlen($this->requestBody);
118
-
119
- $fh = fopen('php://memory', 'rw');
120
- fwrite($fh, $this->requestBody);
121
- rewind($fh);
122
-
123
- curl_setopt($ch, CURLOPT_INFILE, $fh);
124
- curl_setopt($ch, CURLOPT_INFILESIZE, $this->requestLength);
125
- curl_setopt($ch, CURLOPT_PUT, true);
126
-
127
- $this->doExecute($ch);
128
-
129
- fclose($fh);
130
- }
131
-
132
- protected function executeDelete ($ch)
133
- {
134
- $this->path .= ( strpos( $this->path, '?' ) === false ? '?' : '&' ) . $this->requestBody;
135
-
136
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
137
-
138
- $this->doExecute($ch);
139
- }
140
-
141
- protected function doExecute (&$curlHandle)
142
- {
143
- $this->setCurlOpts($curlHandle);
144
- $this->responseBody = curl_exec($curlHandle);
145
-
146
- $this->responseInfo = curl_getinfo($curlHandle);
147
-
148
- curl_close($curlHandle);
149
- }
150
-
151
- protected function setCurlOpts (&$curlHandle)
152
- {
153
- curl_setopt($curlHandle, CURLOPT_TIMEOUT, 10);
154
- curl_setopt($curlHandle, CURLOPT_URL, $this->path);
155
- curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
156
- curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array ('Accept: ' . $this->acceptType));
157
-
158
- curl_setopt($curlHandle, CURLOPT_SSL_VERIFYHOST, false );
159
- curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false );
160
- if (!ini_get('open_basedir') && !ini_get('safe_mode'))
161
- {
162
- url_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, true );
163
  }
164
- }
165
-
166
- protected function setAuth (&$curlHandle)
167
- {
168
- if ($this->username !== null && $this->password !== null)
169
- {
170
- curl_setopt($curlHandle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
171
- curl_setopt($curlHandle, CURLOPT_USERPWD, $this->username . ':' . $this->password);
172
- }
173
- }
174
-
175
- public function getAcceptType ()
176
- {
177
- return $this->acceptType;
178
- }
179
-
180
- public function setAcceptType ($acceptType)
181
- {
182
- $this->acceptType = $acceptType;
183
- }
184
-
185
- public function getPassword ()
186
- {
187
- return $this->password;
188
- }
189
-
190
- public function setPassword ($password)
191
- {
192
- $this->password = $password;
193
- }
194
-
195
- public function getResponseBody ()
196
- {
197
- return $this->responseBody;
198
- }
199
-
200
- public function getResponseInfo ()
201
- {
202
- return $this->responseInfo;
203
- }
204
-
205
- public function getUrl ()
206
- {
207
- return $this->url;
208
- }
209
-
210
- public function setUrl ($url)
211
- {
212
- $this->url = $url;
213
- }
214
-
215
- public function getUsername ()
216
- {
217
- return $this->username;
218
- }
219
-
220
- public function setUsername ($username)
221
- {
222
- $this->username = $username;
223
- }
224
-
225
- public function getVerb ()
226
- {
227
- return $this->verb;
228
- }
229
-
230
- public function setVerb ($verb)
231
- {
232
- $this->verb = $verb;
233
- }
234
- }
2
 
3
  class ML_Rest_Base
4
  {
5
+ protected $url;
6
+ protected $verb;
7
+ protected $requestBody;
8
+ protected $requestLength;
9
+ protected $username;
10
+ protected $password;
11
+ protected $acceptType;
12
+ protected $responseBody;
13
+ protected $responseInfo;
14
+
15
+ protected $apiKey = '';
16
+ protected $path = '';
17
+
18
+ public function __construct($url = 'https://app.mailerlite.com/api/v1/', $verb = 'GET')
19
+ {
20
+ $this->url = $url;
21
+ $this->verb = $verb;
22
+ $this->requestLength = 0;
23
+ $this->username = null;
24
+ $this->password = null;
25
+ $this->acceptType = 'application/json';
26
+ $this->responseBody = null;
27
+ $this->responseInfo = null;
28
+ }
29
+
30
+ public function flush()
31
+ {
32
+ $this->requestBody = null;
33
+ $this->requestLength = 0;
34
+ $this->verb = 'GET';
35
+ $this->responseBody = null;
36
+ $this->responseInfo = null;
37
+ }
38
+
39
+ public function execute($method = null, $data = null)
40
+ {
41
+ $ch = curl_init();
42
+ $this->setAuth($ch);
43
+
44
+ if ($method)
45
+ $this->verb = $method;
46
+
47
+ $this->requestBody = $data;
48
+
49
+ $this->buildPostBody();
50
+
51
+ try {
52
+ switch (strtoupper($this->verb)) {
53
+ case 'GET':
54
+ $this->executeGet($ch);
55
+ break;
56
+ case 'POST':
57
+ $this->executePost($ch);
58
+ break;
59
+ case 'PUT':
60
+ $this->executePut($ch);
61
+ break;
62
+ case 'DELETE':
63
+ $this->executeDelete($ch);
64
+ break;
65
+ default:
66
+ throw new InvalidArgumentException('Current verb (' . $this->verb . ') is an invalid REST verb.');
67
+ }
68
+ } catch (InvalidArgumentException $e) {
69
+ curl_close($ch);
70
+ throw $e;
71
+ } catch (Exception $e) {
72
+ curl_close($ch);
73
+ throw $e;
74
+ }
75
+
76
+ return $this->responseBody;
77
+ }
78
+
79
+ public function buildPostBody()
80
+ {
81
+ $data = $this->requestBody;
82
+
83
+ $data['apiKey'] = $this->apiKey;
84
+
85
+ if (!is_array($data)) {
86
+ throw new InvalidArgumentException('Invalid data input for postBody. Array expected');
87
+ }
88
+
89
+ $data = http_build_query($data, '', '&');
90
+ $this->requestBody = $data;
91
+ }
92
+
93
+ protected function executeGet($ch)
94
+ {
95
+ $this->path .= (strpos($this->path, '?') === false ? '?' : '&') . $this->requestBody;
96
+
97
+ $this->doExecute($ch);
98
+ }
99
+
100
+ protected function executePost($ch)
101
+ {
102
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody);
103
+ curl_setopt($ch, CURLOPT_POST, 1);
104
+
105
+ $this->doExecute($ch);
106
+ }
107
+
108
+ protected function executePut($ch)
109
+ {
110
+ $this->requestLength = strlen($this->requestBody);
111
+
112
+ $fh = fopen('php://memory', 'rw');
113
+ fwrite($fh, $this->requestBody);
114
+ rewind($fh);
115
+
116
+ curl_setopt($ch, CURLOPT_INFILE, $fh);
117
+ curl_setopt($ch, CURLOPT_INFILESIZE, $this->requestLength);
118
+ curl_setopt($ch, CURLOPT_PUT, true);
119
+
120
+ $this->doExecute($ch);
121
+
122
+ fclose($fh);
123
+ }
124
+
125
+ protected function executeDelete($ch)
126
+ {
127
+ $this->path .= (strpos($this->path, '?') === false ? '?' : '&') . $this->requestBody;
128
+
129
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
130
+
131
+ $this->doExecute($ch);
132
+ }
133
+
134
+ protected function doExecute(&$curlHandle)
135
+ {
136
+ $this->setCurlOpts($curlHandle);
137
+ $this->responseBody = curl_exec($curlHandle);
138
+
139
+ $this->responseInfo = curl_getinfo($curlHandle);
140
+
141
+ curl_close($curlHandle);
142
+ }
143
+
144
+ protected function setCurlOpts(&$curlHandle)
145
+ {
146
+ curl_setopt($curlHandle, CURLOPT_TIMEOUT, 10);
147
+ curl_setopt($curlHandle, CURLOPT_URL, $this->path);
148
+ curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
149
+ curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array('Accept: ' . $this->acceptType));
150
+
151
+ curl_setopt($curlHandle, CURLOPT_SSL_VERIFYHOST, false);
152
+ curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
153
+ if (!ini_get('open_basedir') && !ini_get('safe_mode')) {
154
+ url_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, true);
 
 
 
 
 
 
 
 
155
  }
156
+ }
157
+
158
+ protected function setAuth(&$curlHandle)
159
+ {
160
+ if ($this->username !== null && $this->password !== null) {
161
+ curl_setopt($curlHandle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
162
+ curl_setopt($curlHandle, CURLOPT_USERPWD, $this->username . ':' . $this->password);
163
+ }
164
+ }
165
+
166
+ public function getAcceptType()
167
+ {
168
+ return $this->acceptType;
169
+ }
170
+
171
+ public function setAcceptType($acceptType)
172
+ {
173
+ $this->acceptType = $acceptType;
174
+ }
175
+
176
+ public function getPassword()
177
+ {
178
+ return $this->password;
179
+ }
180
+
181
+ public function setPassword($password)
182
+ {
183
+ $this->password = $password;
184
+ }
185
+
186
+ public function getResponseBody()
187
+ {
188
+ return $this->responseBody;
189
+ }
190
+
191
+ public function getResponseInfo()
192
+ {
193
+ return $this->responseInfo;
194
+ }
195
+
196
+ public function getUrl()
197
+ {
198
+ return $this->url;
199
+ }
200
+
201
+ public function setUrl($url)
202
+ {
203
+ $this->url = $url;
204
+ }
205
+
206
+ public function getUsername()
207
+ {
208
+ return $this->username;
209
+ }
210
+
211
+ public function setUsername($username)
212
+ {
213
+ $this->username = $username;
214
+ }
215
+
216
+ public function getVerb()
217
+ {
218
+ return $this->verb;
219
+ }
220
+
221
+ public function setVerb($verb)
222
+ {
223
+ $this->verb = $verb;
224
+ }
225
+ }
 
mailerlite.php CHANGED
@@ -4,7 +4,7 @@
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.9
8
  * Author: MailerGroup
9
  * Author URI: https://www.mailerlite.com
10
  * License: GPLv2 or later
@@ -28,7 +28,7 @@
28
  define('MAILERLITE_PLUGIN_DIR', plugin_dir_path(__FILE__));
29
  define('MAILERLITE_PLUGIN_URL', plugins_url('', __FILE__));
30
 
31
- define('MAILERLITE_VERSION', '1.0.9');
32
 
33
  function mailerlite_load_plugin_textdomain()
34
  {
@@ -67,7 +67,7 @@ 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');
@@ -75,8 +75,7 @@ function register_mailerlite_styles()
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
  }
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.10
8
  * Author: MailerGroup
9
  * Author URI: https://www.mailerlite.com
10
  * License: GPLv2 or later
28
  define('MAILERLITE_PLUGIN_DIR', plugin_dir_path(__FILE__));
29
  define('MAILERLITE_PLUGIN_URL', plugins_url('', __FILE__));
30
 
31
+ define('MAILERLITE_VERSION', '1.0.10');
32
 
33
  function mailerlite_load_plugin_textdomain()
34
  {
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');
75
 
76
  add_action('wp_enqueue_scripts', 'register_mailerlite_styles');
77
 
78
+ if (is_admin()) {
 
79
  require_once(MAILERLITE_PLUGIN_DIR . 'include/mailerlite-admin.php');
80
  add_action('init', array('MailerLite_Admin', 'init'));
81
  }
readme.txt CHANGED
@@ -127,6 +127,8 @@ Add your custom CSS rules to the end of your theme stylesheet, /wp-content/theme
127
 
128
  == Changelog ==
129
 
 
 
130
  = 1.0.9 =
131
  * Curl safe mode fix
132
  = 1.0.8 =
@@ -150,6 +152,8 @@ Add your custom CSS rules to the end of your theme stylesheet, /wp-content/theme
150
 
151
  == Upgrade Notice ==
152
 
 
 
153
  = 1.0.9 =
154
  * Curl safe mode fix
155
  = 1.0.8 =
127
 
128
  == Changelog ==
129
 
130
+ = 1.0.10 =
131
+ * Some code refactor, array fixes for <5.4
132
  = 1.0.9 =
133
  * Curl safe mode fix
134
  = 1.0.8 =
152
 
153
  == Upgrade Notice ==
154
 
155
+ = 1.0.10 =
156
+ * Some code refactor, array fixes for <5.4
157
  = 1.0.9 =
158
  * Curl safe mode fix
159
  = 1.0.8 =