Official MailerLite Sign Up Forms - Version 1.4.2

Version Description

  • Fix - Styles on form description bug
  • Update - Added a Load more button for groups on the creation stage phase.
  • Update - Hidden api key
Download this release

Release Info

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

Code changes from version 1.4.1 to 1.4.2

include/mailerlite-admin.php CHANGED
@@ -35,7 +35,8 @@ class MailerLite_Admin {
35
  }
36
 
37
  if ( isset( $_POST['action'] )
38
- && $_POST['action'] == 'enter-mailerlite-key'
 
39
  ) {
40
  self::set_api_key();
41
  }
@@ -68,10 +69,14 @@ class MailerLite_Admin {
68
 
69
  $ML_Groups = new MailerLite_Forms_Groups( self::$api_key );
70
 
71
- $groups = $ML_Groups->getAllJson( [
 
72
  'limit' => 1000,
73
  'offset' => self::FIRST_GROUP_LOAD,
74
  ] );
 
 
 
75
 
76
  include( MAILERLITE_PLUGIN_DIR . 'include/templates/admin/ajax_groups.php' );
77
 
@@ -224,30 +229,45 @@ class MailerLite_Admin {
224
  $form->data = unserialize( $form->data );
225
 
226
  if ( $form->type == MailerLite_Form::TYPE_CUSTOM ) {
227
- add_filter(
228
- 'wp_default_editor',
229
- function () {
230
- return "tinymce";
231
- }
232
- );
233
 
234
  $ML_Groups = new MailerLite_Forms_Groups( $api_key );
235
 
236
- $groups = $ML_Groups->getAllJson( [
237
  'limit' => self::FIRST_GROUP_LOAD,
238
  'offset' => 0,
239
  ] );
240
 
241
- $can_load_more_groups = false;
242
- $can_load_more_groups_check = $ML_Groups->getAllJson( [
243
- 'limit' => 1,
244
- 'offset' => self::FIRST_GROUP_LOAD,
245
- ] );
246
-
247
- if ( count( $can_load_more_groups_check ) > 0 ) {
248
- $can_load_more_groups = true;
 
 
 
 
 
 
 
 
 
 
249
  }
250
 
 
 
 
 
 
 
 
251
  if ( $ML_Groups->hasCurlError() ) {
252
  $mailerlite_error = '<u>' . __( 'Send this error to info@mailerlite.com or our chat',
253
  'mailerlite' ) . '</u>: ' . $ML_Groups->getResponseBody();
@@ -263,7 +283,7 @@ class MailerLite_Admin {
263
  $form_title = self::issetWithDefault( 'form_title',
264
  __( 'Newsletter signup', 'mailerlite' ) );
265
  $form_description = self::issetWithDefault( 'form_description',
266
- __( 'Just simple MailerLite form!', 'mailerlite' ) );
267
  $success_message = self::issetWithDefault( 'success_message',
268
  '<span style="color: rgb(51, 153, 102);">' . __( 'Thank you for sign up!',
269
  'mailerlite' ) . '</span>', false );
@@ -286,6 +306,17 @@ class MailerLite_Admin {
286
 
287
  $form_lists = isset( $_POST['form_lists'] ) && is_array( $_POST['form_lists'] ) ? $_POST['form_lists'] : [];
288
 
 
 
 
 
 
 
 
 
 
 
 
289
  $prepared_fields = [];
290
 
291
  // Force to use email
@@ -306,6 +337,7 @@ class MailerLite_Admin {
306
  'language' => $language,
307
  'lists' => $form_lists,
308
  'fields' => $prepared_fields,
 
309
  ];
310
 
311
  $wpdb->update(
@@ -412,9 +444,9 @@ class MailerLite_Admin {
412
  global $mailerlite_error;
413
  self::mailerlite_api_key_require();
414
 
415
- $api_key = self::$api_key;
416
 
417
- $ML_Settings_Double_OptIn = new MailerLite_Forms_Settings_Double_OptIn( $api_key );
418
  $double_optin_enabled = $ML_Settings_Double_OptIn->status();
419
  $double_optin_enabled_local = ! get_option( 'mailerlite_double_optin_disabled' );
420
 
@@ -554,9 +586,22 @@ class MailerLite_Admin {
554
  if ( array_key_exists( 'create_signup_form_now', $_POST ) ) {
555
  $form_name = $_POST['form_name'];
556
  $form_data['lists'] = $_POST['form_lists'];
 
 
 
 
 
 
 
 
 
557
  } else {
558
  $ML_Groups = new MailerLite_Forms_Groups( self::$api_key );
559
- $groups = $ML_Groups->getAllJson();
 
 
 
 
560
 
561
  require_once( ABSPATH . 'wp-admin/admin-header.php' );
562
  include( MAILERLITE_PLUGIN_DIR . 'include/templates/admin/create_custom.php' );
@@ -598,4 +643,14 @@ class MailerLite_Admin {
598
 
599
  return $default;
600
  }
 
 
 
 
 
 
 
 
 
 
601
  }
35
  }
36
 
37
  if ( isset( $_POST['action'] )
38
+ && $_POST['action'] == 'enter-mailerlite-key'
39
+ && (ctype_alnum($_POST['mailerlite_key']) || empty($_POST['mailerlite_key']))
40
  ) {
41
  self::set_api_key();
42
  }
69
 
70
  $ML_Groups = new MailerLite_Forms_Groups( self::$api_key );
71
 
72
+ $lists = $form->data['lists'];
73
+ $groups_from_ml_extended = $ML_Groups->getAllJson( [
74
  'limit' => 1000,
75
  'offset' => self::FIRST_GROUP_LOAD,
76
  ] );
77
+ $groups = array_filter($groups_from_ml_extended, function($group) use ($lists) {
78
+ return ! in_array($group->id, $lists);
79
+ });
80
 
81
  include( MAILERLITE_PLUGIN_DIR . 'include/templates/admin/ajax_groups.php' );
82
 
229
  $form->data = unserialize( $form->data );
230
 
231
  if ( $form->type == MailerLite_Form::TYPE_CUSTOM ) {
232
+ add_filter(
233
+ 'wp_default_editor',
234
+ create_function( '', 'return "tinymce";' )
235
+ );
 
 
236
 
237
  $ML_Groups = new MailerLite_Forms_Groups( $api_key );
238
 
239
+ $groups_from_ml = $ML_Groups->getAllJson( [
240
  'limit' => self::FIRST_GROUP_LOAD,
241
  'offset' => 0,
242
  ] );
243
 
244
+ $lists = $form->data['lists'];
245
+ if (! isset($form->data['selected_groups'])) {
246
+ $groups_selected = array_filter($groups_from_ml, function($group) use ($lists) {
247
+ return in_array($group->id, $lists);
248
+ });
249
+
250
+ if (count($groups_selected) != count($lists)) {
251
+ $groups_from_ml_extended = $ML_Groups->getAllJson([
252
+ 'limit' => 1100,
253
+ 'offset' => 0,
254
+ ]);
255
+
256
+ $groups_selected = array_filter($groups_from_ml_extended, function($group) use ($lists) {
257
+ return in_array($group->id, $lists);
258
+ });
259
+ }
260
+ } else {
261
+ $groups_selected = $form->data['selected_groups'];
262
  }
263
 
264
+ $groups_not_selected = array_filter($groups_from_ml, function($group) use ($lists) {
265
+ return ! in_array($group->id, $lists);
266
+ });
267
+ $groups = array_merge($groups_selected, $groups_not_selected);
268
+
269
+ $can_load_more_groups = self::checkIfMoreGroups($ML_Groups);
270
+
271
  if ( $ML_Groups->hasCurlError() ) {
272
  $mailerlite_error = '<u>' . __( 'Send this error to info@mailerlite.com or our chat',
273
  'mailerlite' ) . '</u>: ' . $ML_Groups->getResponseBody();
283
  $form_title = self::issetWithDefault( 'form_title',
284
  __( 'Newsletter signup', 'mailerlite' ) );
285
  $form_description = self::issetWithDefault( 'form_description',
286
+ __( 'Just simple MailerLite form!', 'mailerlite' ), false );
287
  $success_message = self::issetWithDefault( 'success_message',
288
  '<span style="color: rgb(51, 153, 102);">' . __( 'Thank you for sign up!',
289
  'mailerlite' ) . '</span>', false );
306
 
307
  $form_lists = isset( $_POST['form_lists'] ) && is_array( $_POST['form_lists'] ) ? $_POST['form_lists'] : [];
308
 
309
+ $form_selected_groups =[];
310
+ $selected_groups = explode(';*',$_POST['selected_groups']);
311
+
312
+ foreach ($selected_groups as $group) {
313
+ $group = explode('::', $group);
314
+ $group_data = [];
315
+ $group_data['id'] = $group[0];
316
+ $group_data['name'] = $group[1];
317
+ $form_selected_groups[] = (object)$group_data;
318
+ }
319
+
320
  $prepared_fields = [];
321
 
322
  // Force to use email
337
  'language' => $language,
338
  'lists' => $form_lists,
339
  'fields' => $prepared_fields,
340
+ 'selected_groups' => $form_selected_groups
341
  ];
342
 
343
  $wpdb->update(
444
  global $mailerlite_error;
445
  self::mailerlite_api_key_require();
446
 
447
+ $api_key = "....".substr(self::$api_key, -4);
448
 
449
+ $ML_Settings_Double_OptIn = new MailerLite_Forms_Settings_Double_OptIn( self::$api_key );
450
  $double_optin_enabled = $ML_Settings_Double_OptIn->status();
451
  $double_optin_enabled_local = ! get_option( 'mailerlite_double_optin_disabled' );
452
 
586
  if ( array_key_exists( 'create_signup_form_now', $_POST ) ) {
587
  $form_name = $_POST['form_name'];
588
  $form_data['lists'] = $_POST['form_lists'];
589
+ $selected_groups = explode(';*',$_POST['selected_groups']);
590
+
591
+ foreach ($selected_groups as $group) {
592
+ $group = explode('::', $group);
593
+ $group_data = [];
594
+ $group_data['id'] = $group[0];
595
+ $group_data['name'] = $group[1];
596
+ $form_data['selected_groups'][] = (object)$group_data;
597
+ }
598
  } else {
599
  $ML_Groups = new MailerLite_Forms_Groups( self::$api_key );
600
+ $groups = $ML_Groups->getAllJson([
601
+ 'limit' => self::FIRST_GROUP_LOAD,
602
+ 'offset' => 0
603
+ ]);
604
+ $can_load_more_groups = self::checkIfMoreGroups($ML_Groups);
605
 
606
  require_once( ABSPATH . 'wp-admin/admin-header.php' );
607
  include( MAILERLITE_PLUGIN_DIR . 'include/templates/admin/create_custom.php' );
643
 
644
  return $default;
645
  }
646
+
647
+ private static function checkIfMoreGroups($ML_Groups)
648
+ {
649
+ $can_load_more_groups_check = $ML_Groups->getAllJson( [
650
+ 'limit' => 1,
651
+ 'offset' => self::FIRST_GROUP_LOAD,
652
+ ] );
653
+
654
+ return count( $can_load_more_groups_check ) > 0;
655
+ }
656
  }
include/templates/admin/create_custom.php CHANGED
@@ -37,6 +37,12 @@
37
  <?php endforeach; ?>
38
  </tbody>
39
  </table>
 
 
 
 
 
 
40
  <?php if ( count( $groups ) === 0 ) {
41
  ?>
42
  <div class="notice notice-error">
@@ -53,7 +59,7 @@
53
  'mailerlite' ); ?>
54
  </p>
55
  </div>
56
-
57
  <div class="submit">
58
  <input class="button-primary"
59
  value="<?php echo __( 'Create form', 'mailerlite' ); ?>" name="create_signup_form"
@@ -75,14 +81,39 @@
75
 
76
  jQuery(document).ready(function ($) {
77
  $('#create_custom').on('submit', function (e) {
78
- var checkedLists = $("[name='form_lists[]']:checked").length;
79
-
80
- if (checkedLists === 0) {
 
 
 
 
 
 
 
 
 
 
 
 
81
  $("#no-selections-error").show();
82
  e.preventDefault();
83
  return false;
84
  }
85
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  });
87
  })();
88
  </script>
37
  <?php endforeach; ?>
38
  </tbody>
39
  </table>
40
+ <table id="more-groups" class="form-table" style="display: none;"></table>
41
+ <?php if ( $can_load_more_groups ) { ?>
42
+ <button id="load-more-groups" class="button-primary" type="button">
43
+ Load more
44
+ </button>
45
+ <?php } ?>
46
  <?php if ( count( $groups ) === 0 ) {
47
  ?>
48
  <div class="notice notice-error">
59
  'mailerlite' ); ?>
60
  </p>
61
  </div>
62
+ <input type="hidden" id="selected_groups" name="selected_groups" />
63
  <div class="submit">
64
  <input class="button-primary"
65
  value="<?php echo __( 'Create form', 'mailerlite' ); ?>" name="create_signup_form"
81
 
82
  jQuery(document).ready(function ($) {
83
  $('#create_custom').on('submit', function (e) {
84
+ var checkedLists = $("[name='form_lists[]']:checked");
85
+
86
+ var selected_groups = '';
87
+ checkedLists.each(function() {
88
+ group = this.value +'::'+$("label[for='list_"+ this.value + "']").text();
89
+ if (selected_groups != '') {
90
+ selected_groups = selected_groups+';*'+group;
91
+ } else {
92
+ selected_groups = group;
93
+ }
94
+
95
+ });
96
+
97
+ $("[name=selected_groups]").val(selected_groups);
98
+ if (checkedLists.length === 0) {
99
  $("#no-selections-error").show();
100
  e.preventDefault();
101
  return false;
102
  }
103
  });
104
+
105
+ $('#load-more-groups').on('click', function () {
106
+ $('#load-more-groups').prop('disabled', true);
107
+
108
+ jQuery.ajax({
109
+ type: "POST",
110
+ url: ajaxurl,
111
+ data: {action: 'mailerlite_get_more_groups'}
112
+ }).done(function (html) {
113
+ $('#more-groups').show().html(html);
114
+ $('#load-more-groups').hide();
115
+ });
116
+ });
117
  });
118
  })();
119
  </script>
include/templates/admin/edit_custom.php CHANGED
@@ -229,7 +229,7 @@
229
  'mailerlite' ); ?>
230
  </p>
231
  </div>
232
-
233
  <div class="submit">
234
  <input class="button-primary"
235
  value="<?php _e( 'Save form', 'mailerlite' ); ?>"
@@ -278,9 +278,22 @@
278
 
279
  $(document).ready(function ($) {
280
  $('#edit_custom').on('submit', function (e) {
281
- var checkedLists = $("[name='form_lists[]']:checked").length;
282
-
283
- if (checkedLists === 0) {
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  $("#no-selections-error").show().addClass('notice');
285
  e.preventDefault();
286
  return false;
229
  'mailerlite' ); ?>
230
  </p>
231
  </div>
232
+ <input type="hidden" id="selected_groups" name="selected_groups" />
233
  <div class="submit">
234
  <input class="button-primary"
235
  value="<?php _e( 'Save form', 'mailerlite' ); ?>"
278
 
279
  $(document).ready(function ($) {
280
  $('#edit_custom').on('submit', function (e) {
281
+ var checkedLists = $("[name='form_lists[]']:checked");
282
+
283
+ var selected_groups = '';
284
+ checkedLists.each(function() {
285
+ group = this.value +'::'+$("label[for='list_"+ this.value + "']").text();
286
+ if (selected_groups != '') {
287
+ selected_groups = selected_groups+';*'+group;
288
+ } else {
289
+ selected_groups = group;
290
+ }
291
+
292
+ });
293
+
294
+ $("[name=selected_groups]").val(selected_groups);
295
+
296
+ if (checkedLists.length === 0) {
297
  $("#no-selections-error").show().addClass('notice');
298
  e.preventDefault();
299
  return false;
mailerlite.php CHANGED
@@ -3,7 +3,7 @@
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.4.1
7
  * Author: MailerGroup
8
  * Author URI: https://www.mailerlite.com
9
  * License: GPLv2 or later
@@ -29,7 +29,7 @@
29
  define( 'MAILERLITE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
30
  define( 'MAILERLITE_PLUGIN_URL', plugins_url( '', __FILE__ ) );
31
 
32
- define( 'MAILERLITE_VERSION', '1.4.1' );
33
 
34
  define( 'MAILERLITE_PHP_VERSION', '5.6.0' );
35
  define( 'MAILERLITE_WP_VERSION', '3.0.1' );
@@ -62,7 +62,7 @@ function mailerlite_install() {
62
 
63
  if ( $message ) {
64
  deactivate_plugins( basename( __FILE__ ) );
65
- wp_die( $message, 'Plugin Activation Error', array( 'response' => 200, 'back_link' => true ) );
66
  }
67
 
68
  $table_name = $wpdb->base_prefix . "mailerlite_forms";
@@ -98,7 +98,7 @@ register_activation_hook( __FILE__, 'mailerlite_install' );
98
  function register_mailerlite_styles() {
99
  wp_register_style(
100
  'mailerlite_forms.css',
101
- MAILERLITE_PLUGIN_URL . '/assets/css/mailerlite_forms.css', array(),
102
  MAILERLITE_VERSION
103
  );
104
  wp_enqueue_style( 'mailerlite_forms.css' );
@@ -159,7 +159,7 @@ function mailerlite_status_information() {
159
  $environment_group = __( 'Environment', 'mailerlite' );
160
  $plugin_group = __( 'Plugin', 'mailerlite' );
161
 
162
- $fields = array();
163
  $fields['WordPress']['Version'] = get_bloginfo( 'version' );
164
  $fields['WordPress']['Home URL'] = get_option( 'home' );
165
  $fields['WordPress']['Site URL'] = get_option( 'home' );
@@ -196,17 +196,17 @@ if ( in_array( 'official-mailerlite-sign-up-forms/mailerlite.php', get_option( '
196
  require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-admin.php' );
197
  require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-admin-status.php' );
198
 
199
- add_action( 'init', array( 'MailerLite_Admin', 'init' ) );
200
- add_action( 'init', array( 'MailerLite_Admin_Status', 'init' ) );
201
  }
202
 
203
  require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-widget.php' );
204
  require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-shortcode.php' );
205
  require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-gutenberg.php' );
206
 
207
- add_action( 'init', array( 'MailerLite_Shortcode', 'init' ) );
208
- add_action( 'init', array( 'MailerLite_Form', 'init' ) );
209
- add_action( 'init', array( 'MailerLite_Gutenberg', 'init' ) );
210
  } else {
211
  function mailerlite_old_php_notice() {
212
  $class = 'notice notice-error';
@@ -218,6 +218,6 @@ if ( in_array( 'official-mailerlite-sign-up-forms/mailerlite.php', get_option( '
218
  add_action( 'admin_notices', 'mailerlite_old_php_notice' );
219
 
220
  require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-admin-status.php' );
221
- add_action( 'init', array( 'MailerLite_Admin_Status', 'init' ) );
222
  }
223
  }
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.4.2
7
  * Author: MailerGroup
8
  * Author URI: https://www.mailerlite.com
9
  * License: GPLv2 or later
29
  define( 'MAILERLITE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
30
  define( 'MAILERLITE_PLUGIN_URL', plugins_url( '', __FILE__ ) );
31
 
32
+ define( 'MAILERLITE_VERSION', '1.4.2' );
33
 
34
  define( 'MAILERLITE_PHP_VERSION', '5.6.0' );
35
  define( 'MAILERLITE_WP_VERSION', '3.0.1' );
62
 
63
  if ( $message ) {
64
  deactivate_plugins( basename( __FILE__ ) );
65
+ wp_die( $message, 'Plugin Activation Error', [ 'response' => 200, 'back_link' => true ] );
66
  }
67
 
68
  $table_name = $wpdb->base_prefix . "mailerlite_forms";
98
  function register_mailerlite_styles() {
99
  wp_register_style(
100
  'mailerlite_forms.css',
101
+ MAILERLITE_PLUGIN_URL . '/assets/css/mailerlite_forms.css', [],
102
  MAILERLITE_VERSION
103
  );
104
  wp_enqueue_style( 'mailerlite_forms.css' );
159
  $environment_group = __( 'Environment', 'mailerlite' );
160
  $plugin_group = __( 'Plugin', 'mailerlite' );
161
 
162
+ $fields = [];
163
  $fields['WordPress']['Version'] = get_bloginfo( 'version' );
164
  $fields['WordPress']['Home URL'] = get_option( 'home' );
165
  $fields['WordPress']['Site URL'] = get_option( 'home' );
196
  require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-admin.php' );
197
  require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-admin-status.php' );
198
 
199
+ add_action( 'init', [ 'MailerLite_Admin', 'init' ] );
200
+ add_action( 'init', [ 'MailerLite_Admin_Status', 'init' ] );
201
  }
202
 
203
  require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-widget.php' );
204
  require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-shortcode.php' );
205
  require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-gutenberg.php' );
206
 
207
+ add_action( 'init', [ 'MailerLite_Shortcode', 'init' ] );
208
+ add_action( 'init', [ 'MailerLite_Form', 'init' ] );
209
+ add_action( 'init', [ 'MailerLite_Gutenberg', 'init' ] );
210
  } else {
211
  function mailerlite_old_php_notice() {
212
  $class = 'notice notice-error';
218
  add_action( 'admin_notices', 'mailerlite_old_php_notice' );
219
 
220
  require_once( MAILERLITE_PLUGIN_DIR . 'include/mailerlite-admin-status.php' );
221
+ add_action( 'init', [ 'MailerLite_Admin_Status', 'init' ] );
222
  }
223
  }
readme.txt CHANGED
@@ -3,9 +3,9 @@ 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: 5.2
7
  Requires PHP: 5.6.0
8
- Stable tag: 1.4.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -130,8 +130,10 @@ Add your custom CSS rules to the end of your theme stylesheet, /wp-content/theme
130
 
131
  == Changelog ==
132
 
133
- = 1.4.1 =
134
- * Tweak - WordPress 5.2 and PHP 7.2 support
 
 
135
 
136
  = 1.4 =
137
  * Tweak - Show more than 100 groups when creating a custom form
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: 5.3.2
7
  Requires PHP: 5.6.0
8
+ Stable tag: 1.4.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
130
 
131
  == Changelog ==
132
 
133
+ = 1.4.2 =
134
+ * Fix - Styles on form description bug
135
+ * Update - Added a Load more button for groups on the creation stage phase.
136
+ * Update - Hidden api key
137
 
138
  = 1.4 =
139
  * Tweak - Show more than 100 groups when creating a custom form