MailMunch – Grow your Email List - Version 1.4.3

Version Description

Download this release

Release Info

Developer mailmunch
Plugin Icon 128x128 MailMunch – Grow your Email List
Version 1.4.3
Comparing to
See all releases

Code changes from version 1.3.6 to 1.4.3

Files changed (9) hide show
  1. css/admin.css +40 -1
  2. img/close.png +0 -0
  3. inc/common.php +3 -3
  4. inc/mailmunchapi.php +27 -25
  5. inc/sidebar_widget.php +131 -0
  6. js/admin.js +56 -5
  7. mailmunch.php +126 -58
  8. readme.txt +6 -4
  9. uninstall.php +9 -0
css/admin.css CHANGED
@@ -1,3 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #sign-in-form, #sign-up-form {
2
  display: none;
3
  }
@@ -776,4 +815,4 @@ input[type="button"].btn-block {
776
  }
777
  .clearfix {
778
  clear: both;
779
- }
1
+ #signup-signin-box-overlay {
2
+ background-color: #000;
3
+ opacity: 0.8;
4
+ position: fixed;
5
+ left: 0px;
6
+ top: 0px;
7
+ height: 100%;
8
+ width: 100%;
9
+ z-index: 10000;
10
+ }
11
+
12
+ #signup-signin-close {
13
+ cursor: pointer;
14
+ position: absolute;
15
+ right: 0px;
16
+ top: 0px;
17
+ line-height: 0px;
18
+ }
19
+
20
+ #signup-signin-close img {
21
+ width: 20px;
22
+ height: 20px;
23
+ }
24
+
25
+ #signup-signin-box {
26
+ position: fixed;
27
+ background-color: #FFF;
28
+ z-index: 100000;
29
+ padding: 20px;
30
+ max-width: 600px;
31
+ }
32
+
33
+ #signup-signin-box h2.modal-header {
34
+ margin-top: 0px;
35
+ border-bottom: 1px solid #DEDEDE;
36
+ margin-bottom: 10px;
37
+ padding-bottom: 10px;
38
+ }
39
+
40
  #sign-in-form, #sign-up-form {
41
  display: none;
42
  }
815
  }
816
  .clearfix {
817
  clear: both;
818
+ }
img/close.png ADDED
Binary file
inc/common.php CHANGED
@@ -13,7 +13,7 @@ class MailmunchHelpers {
13
  }
14
 
15
  if (empty($mailmunch_password)) {
16
- update_option("mailmunch_user_password", uniqid());
17
  }
18
 
19
  $mailmunch_email = get_option("mailmunch_user_email");
@@ -30,7 +30,7 @@ class MailmunchHelpers {
30
  }
31
  }
32
 
33
- return $site;
34
  }
35
 
36
  function createAndGetSites($mm) {
@@ -70,4 +70,4 @@ class MailmunchHelpers {
70
  }
71
  }
72
  }
73
- ?>
13
  }
14
 
15
  if (empty($mailmunch_password)) {
16
+ update_option("mailmunch_user_password", base64_encode(uniqid()));
17
  }
18
 
19
  $mailmunch_email = get_option("mailmunch_user_email");
30
  }
31
  }
32
 
33
+ return (isset($site) ? $site : false);
34
  }
35
 
36
  function createAndGetSites($mm) {
70
  }
71
  }
72
  }
73
+ ?>
inc/mailmunchapi.php CHANGED
@@ -17,14 +17,18 @@
17
  return $this->ping('/sites');
18
  }
19
 
20
- function widgets($site_id) {
21
  $this->requestType = 'get';
22
- return $this->ping('/sites/'.$site_id.'/widgets');
 
 
 
 
23
  }
24
 
25
  function getWidgetsHtml($site_id) {
26
  $this->requestType = 'get';
27
- return $this->ping('/sites/'.$site_id.'/widgets/wordpress');
28
  }
29
 
30
  function deleteWidget($site_id, $widget_id) {
@@ -32,17 +36,6 @@
32
  return $this->ping('/sites/'.$site_id.'/widgets/'.$widget_id.'/delete');
33
  }
34
 
35
- function importWidgets($new_user_email, $new_user_password) {
36
- $this->requestType = 'post';
37
- return $this->ping('/wordpress/import_widgets', array(
38
- 'external_id' => get_option("mailmunch_wordpress_instance_id"),
39
- 'new_user_email' => $new_user_email,
40
- 'new_user_password' => $new_user_password,
41
- 'site_url' => home_url(),
42
- 'site_name' => get_bloginfo()
43
- ));
44
- }
45
-
46
  function hasSite() {
47
  $request = $this->sites();
48
  $sites = $request['body'];
@@ -97,11 +90,12 @@
97
  ), true);
98
  }
99
 
100
- function updateGuest($new_email) {
101
  $this->requestType = 'post';
102
  return $this->ping('/wordpress/update_guest', array(
103
  'user' => array(
104
  'email' => $new_email,
 
105
  'guest_user' => false
106
  )
107
  ), true);
@@ -113,15 +107,18 @@
113
  }
114
 
115
  function validPassword() {
116
- $this->requestType = 'get';
117
- $request = $this->ping('/sites');
118
-
119
- if ($request['response']['code'] == 200){
120
- return true;
121
- }
122
- else {
123
- return false;
124
- }
 
 
 
125
  }
126
 
127
  function isNewUser($email) {
@@ -152,7 +149,12 @@
152
  $args = array_merge($args, array('method' => 'POST', 'body' => $options));
153
  $request = wp_remote_post($url, $args);
154
  }
 
 
 
 
 
155
  return $request;
156
  }
157
  }
158
- ?>
17
  return $this->ping('/sites');
18
  }
19
 
20
+ function widgets($site_id, $widget_type_name) {
21
  $this->requestType = 'get';
22
+ if (!empty($widget_type_name)) {
23
+ return $this->ping('/sites/'.$site_id.'/widgets?widget_type_name='.$widget_type_name);
24
+ } else {
25
+ return $this->ping('/sites/'.$site_id.'/widgets');
26
+ }
27
  }
28
 
29
  function getWidgetsHtml($site_id) {
30
  $this->requestType = 'get';
31
+ return $this->ping('/sites/'.$site_id.'/widgets/wordpress?plugin=mailmunch');
32
  }
33
 
34
  function deleteWidget($site_id, $widget_id) {
36
  return $this->ping('/sites/'.$site_id.'/widgets/'.$widget_id.'/delete');
37
  }
38
 
 
 
 
 
 
 
 
 
 
 
 
39
  function hasSite() {
40
  $request = $this->sites();
41
  $sites = $request['body'];
90
  ), true);
91
  }
92
 
93
+ function updateGuest($new_email, $new_password) {
94
  $this->requestType = 'post';
95
  return $this->ping('/wordpress/update_guest', array(
96
  'user' => array(
97
  'email' => $new_email,
98
+ 'password' => $new_password,
99
  'guest_user' => false
100
  )
101
  ), true);
107
  }
108
 
109
  function validPassword() {
110
+ $this->requestType = 'get';
111
+ $request = $this->ping('/sites');
112
+ if( is_wp_error( $request ) ) {
113
+ return new WP_Error( 'broke', "Unable to connect to MailMunch. Please try again later." );
114
+ }
115
+
116
+ if ($request['response']['code'] == 200){
117
+ return true;
118
+ }
119
+ else {
120
+ return false;
121
+ }
122
  }
123
 
124
  function isNewUser($email) {
149
  $args = array_merge($args, array('method' => 'POST', 'body' => $options));
150
  $request = wp_remote_post($url, $args);
151
  }
152
+
153
+ if ( !is_wp_error( $request ) && ( $request['response']['code'] == 500 || $request['response']['code'] == 503 ) ) {
154
+ return new WP_Error( 'broke', "Internal Server Error" );
155
+ }
156
+
157
  return $request;
158
  }
159
  }
160
+ ?>
inc/sidebar_widget.php ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mailmunch_Sidebar_Widget extends WP_Widget {
3
+
4
+ /**
5
+ * Register widget with WordPress.
6
+ */
7
+ function __construct() {
8
+ parent::__construct(
9
+ 'mailmunch_widget', // Base ID
10
+ __('Sidebar MailMunch Form', 'text_domain'), // Name
11
+ array( 'description' => __( 'Displays a MailMunch optin form in Sidebar', 'text_domain' ), ) // Args
12
+ );
13
+ }
14
+
15
+ /**
16
+ * Front-end display of widget.
17
+ *
18
+ * @see WP_Widget::widget()
19
+ *
20
+ * @param array $args Widget arguments.
21
+ * @param array $instance Saved values from database.
22
+ */
23
+ public function widget( $args, $instance ) {
24
+ if ( isset( $instance[ 'form_id' ] ) ) {
25
+ $form_id = $instance[ 'form_id' ];
26
+ }
27
+
28
+ if (!empty($form_id)) {
29
+ echo $args['before_widget'];
30
+ if ( ! empty( $instance['title'] ) ) {
31
+ echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
32
+ }
33
+ echo "<div class='mailmunch-wordpress-widget mailmunch-wordpress-widget-".$form_id."' style='display: none !important;'></div>";
34
+ echo $args['after_widget'];
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Back-end widget form.
40
+ *
41
+ * @see WP_Widget::form()
42
+ *
43
+ * @param array $instance Previously saved values from database.
44
+ */
45
+ public function form( $instance ) {
46
+ if ( isset( $instance[ 'title' ] ) ) {
47
+ $title = $instance[ 'title' ];
48
+ }
49
+ else {
50
+ $title = __( 'Optin Form', 'text_domain' );
51
+ }
52
+
53
+ if ( isset( $instance[ 'form_id' ] ) ) {
54
+ $form_id = $instance[ 'form_id' ];
55
+ }
56
+
57
+ $mailmunch_data = unserialize(get_option("mailmunch_data"));
58
+ $mailmunch_user_email = get_option("mailmunch_user_email");
59
+ $mailmunch_user_password = get_option("mailmunch_user_password");
60
+ if (!empty($mailmunch_user_email) && !empty($mailmunch_user_password) && !empty($mailmunch_data["site_id"])) {
61
+ $mailmunch_site_id = $mailmunch_data["site_id"];
62
+ $mm = new MailmunchApi($mailmunch_user_email, $mailmunch_user_password, "http://".MAILMUNCH_URL);
63
+ $result = $mm->widgets($mailmunch_site_id, "Sidebar");
64
+ if ( !is_wp_error( $result ) ) {
65
+ $widgets = json_decode($result['body']);
66
+ }
67
+ } else {
68
+ ?>
69
+ <p>No MailMunch account found. <a href="<?php echo admin_url( 'admin.php?page='.MAILMUNCH_SLUG ); ?>">Go Here First</a></p>
70
+ <?php
71
+ return;
72
+ }
73
+ ?>
74
+ <script type="text/javascript">
75
+ window.onmessage = function (e) {
76
+ if (e.data === 'refresh') {
77
+ top.location.reload();
78
+ }
79
+ };
80
+ </script>
81
+ <?php
82
+ if (sizeof($widgets) > 0) {
83
+ ?>
84
+ <p>
85
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
86
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
87
+ </p>
88
+
89
+ <p>
90
+ <label for="<?php echo $this->get_field_id( 'form_id' ); ?>"><?php _e( 'Optin Form:' ); ?></label>
91
+ <select class="widefat" id="<?php echo $this->get_field_id( 'form_id' ); ?>" name="<?php echo $this->get_field_name( 'form_id' ); ?>">
92
+ <option value="">None</option>
93
+ <?php
94
+ foreach ($widgets as $widget) {
95
+ echo "<option value='".$widget->id."'";
96
+ if ($form_id == $widget->id) { echo " selected"; };
97
+ echo ">".$widget->name."</option>";
98
+ }
99
+ ?>
100
+ </select>
101
+ </p>
102
+
103
+ <p><a href="//<?php echo MAILMUNCH_URL ?>/sso?email=<?php echo urlencode($mailmunch_user_email) ?>&password=<?php echo urlencode($mailmunch_user_password) ?>&next_url=<?php echo urlencode("/sites/".$mailmunch_data["site_id"]."/widgets/new?wp_layout=1&widget_type=Sidebar") ?>" target="_blank">Create New Sidebar Form</a></p>
104
+ <?php
105
+ } else {
106
+ ?>
107
+ <p>No sidebar forms found. <a href="//<?php echo MAILMUNCH_URL ?>/sso?email=<?php echo urlencode($mailmunch_user_email) ?>&password=<?php echo urlencode($mailmunch_user_password) ?>&next_url=<?php echo urlencode("/sites/".$mailmunch_data["site_id"]."/widgets/new?wp_layout=1&widget_type=Sidebar") ?>" target="_blank">Create Your First One</a></p>
108
+ <?php
109
+ }
110
+
111
+ }
112
+
113
+ /**
114
+ * Sanitize widget form values as they are saved.
115
+ *
116
+ * @see WP_Widget::update()
117
+ *
118
+ * @param array $new_instance Values just sent to be saved.
119
+ * @param array $old_instance Previously saved values from database.
120
+ *
121
+ * @return array Updated safe values to be saved.
122
+ */
123
+ public function update( $new_instance, $old_instance ) {
124
+ $instance = array();
125
+ $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
126
+ $instance['form_id'] = ( ! empty( $new_instance['form_id'] ) ) ? strip_tags( $new_instance['form_id'] ) : '';
127
+
128
+ return $instance;
129
+ }
130
+
131
+ }
js/admin.js CHANGED
@@ -25,23 +25,74 @@ window.onmessage = function (e) {
25
  }
26
  };
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  function showSignInForm() {
29
  document.getElementById("sign-up-form").style.display = 'none';
30
  document.getElementById("sign-in-form").style.display = 'block';
 
 
31
  }
32
 
33
  function showSignUpForm() {
34
  document.getElementById("sign-in-form").style.display = 'none';
35
  document.getElementById("sign-up-form").style.display = 'block';
 
 
36
  }
37
 
38
- function showSignupBox() {
39
- document.getElementById('why-account').style.display = 'none';
40
- tb_show("Create Account","#TB_inline?width=550&height=450&inlineId=signup-signin-box",null);
 
 
41
  return false;
42
  }
43
 
 
 
 
 
 
44
  function showWhyAccount() {
45
  document.getElementById('why-account').style.display = 'block';
46
- tb_show("Create Account","#TB_inline?width=550&height=500&inlineId=signup-signin-box",null);
47
- }
25
  }
26
  };
27
 
28
+ function repositionSignupBox() {
29
+ divId = 'signup-signin-box';
30
+ var divWidth, divHeight;
31
+ var objDiv = document.getElementById(divId);
32
+
33
+ if (objDiv.clientWidth) {
34
+ divWidth = objDiv.clientWidth;
35
+ divHeight = objDiv.clientHeight;
36
+ }
37
+ else if (objDiv.offsetWidth)
38
+ {
39
+ divWidth = objDiv.offsetWidth;
40
+ divHeight = objDiv.offsetHeight;
41
+ }
42
+
43
+ // Get the x and y coordinates of the center in output browser's window
44
+ var centerX, centerY;
45
+ if (window.innerHeight)
46
+ {
47
+ centerX = window.innerWidth;
48
+ centerY = window.innerHeight;
49
+ }
50
+ else if (document.documentElement && document.documentElement.clientHeight)
51
+ {
52
+ centerX = document.documentElement.clientWidth;
53
+ centerY = document.documentElement.clientHeight;
54
+ }
55
+ else if (document.body)
56
+ {
57
+ centerX = document.body.clientWidth;
58
+ centerY = document.body.clientHeight;
59
+ }
60
+
61
+ var offsetLeft = (centerX - divWidth) / 2;
62
+ var offsetTop = (centerY - divHeight) / 2;
63
+
64
+ objDiv.style.top = offsetTop + 'px';
65
+ objDiv.style.left = offsetLeft + 'px';
66
+ }
67
+
68
  function showSignInForm() {
69
  document.getElementById("sign-up-form").style.display = 'none';
70
  document.getElementById("sign-in-form").style.display = 'block';
71
+ document.getElementById('why-account').style.display = 'none';
72
+ showSignupBox();
73
  }
74
 
75
  function showSignUpForm() {
76
  document.getElementById("sign-in-form").style.display = 'none';
77
  document.getElementById("sign-up-form").style.display = 'block';
78
+ document.getElementById('why-account').style.display = 'none';
79
+ showSignupBox();
80
  }
81
 
82
+ function showSignupBox(width, height) {
83
+ document.getElementById("signup-signin-box-overlay").style.display = 'block';
84
+ document.getElementById("signup-signin-box").style.display = 'block';
85
+ repositionSignupBox();
86
+
87
  return false;
88
  }
89
 
90
+ function hideSignupBox() {
91
+ document.getElementById("signup-signin-box-overlay").style.display = 'none';
92
+ document.getElementById("signup-signin-box").style.display = 'none';
93
+ }
94
+
95
  function showWhyAccount() {
96
  document.getElementById('why-account').style.display = 'block';
97
+ repositionSignupBox();
98
+ }
mailmunch.php CHANGED
@@ -1,9 +1,9 @@
1
  <?php
2
  /*
3
- Plugin Name: MailMunch
4
  Plugin URI: http://www.mailmunch.co
5
  Description: Collect email addresses from website visitors and grow your subscribers with our attention grabbing optin-forms, entry/exit intent technology, and other effective lead-generation forms.
6
- Version: 1.3.6
7
  Author: MailMunch
8
  Author URI: http://www.mailmunch.co
9
  License: GPL2
@@ -11,9 +11,10 @@
11
 
12
  require_once( plugin_dir_path( __FILE__ ) . 'inc/mailmunchapi.php' );
13
  require_once( plugin_dir_path( __FILE__ ) . 'inc/common.php' );
 
14
 
15
  define( 'MAILMUNCH_SLUG', "mailmunch");
16
- define( 'MAILMUNCH_VER', "1.3.6");
17
  define( 'MAILMUNCH_URL', "www.mailmunch.co");
18
 
19
  // Create unique WordPress instance ID
@@ -25,11 +26,21 @@
25
  add_action( 'admin_menu', 'mailmunch_register_page' );
26
 
27
  function mailmunch_register_page(){
28
- $menu_page = add_menu_page( 'MailMunch Settings', 'MailMunch', 'manage_options', MAILMUNCH_SLUG, 'mailmunch_setup', plugins_url( 'img/icon.png', __FILE__ ), 102.786 );
29
- // If successful, load admin assets only on that page.
30
- if ($menu_page) add_action('load-' . $menu_page, 'mailmunch_load_plugin_assets');
 
31
  }
32
 
 
 
 
 
 
 
 
 
 
33
  function mailmunch_load_plugin_assets() {
34
  add_action( 'admin_enqueue_scripts', 'mailmunch_enqueue_admin_styles' );
35
  add_action( 'admin_enqueue_scripts', 'mailmunch_enqueue_admin_scripts' );
@@ -75,14 +86,10 @@
75
  if (count($mailmunch_data) == 0) return;
76
 
77
  if (function_exists('wp_footer')) {
78
- if (!$_POST['mailmunch_data']) {
79
- add_action( 'wp_footer', 'mailmunch_load_asset_code' );
80
- }
81
  }
82
  elseif (function_exists('wp_head')) {
83
- if (!$_POST['mailmunch_data']) {
84
- add_action( 'wp_head', 'mailmunch_load_asset_code' );
85
- }
86
  }
87
  }
88
 
@@ -95,6 +102,11 @@
95
  return $content;
96
  }
97
 
 
 
 
 
 
98
  function mailmunch_insert_form_after_paragraph($insertion, $paragraph_id, $content) {
99
  $closing_p = '</p>';
100
  $paragraphs = explode($closing_p, $content);
@@ -131,7 +143,7 @@
131
 
132
  // This is a POST request. Let's save data first.
133
  if ($_POST) {
134
- $post_data = $_POST["mailmunch_data"];
135
  $post_action = $_POST["action"];
136
 
137
  if ($post_action == "save_settings") {
@@ -143,25 +155,15 @@
143
 
144
  $mm = new MailmunchApi($_POST["email"], $_POST["password"], "http://".MAILMUNCH_URL);
145
  if ($mm->validPassword()) {
146
- if (get_option("mailmunch_guest_user")) {
147
- // User exists and credentials are correct
148
- // Let's move optin forms from guest user to real user
149
- $account_info = $mm_helpers->getEmailPassword();
150
- $mailmunch_email = $account_info['email'];
151
- $mailmunch_password = $account_info['password'];
152
- $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
153
- $result = $mm->importWidgets($_POST["email"], $_POST["password"]);
154
- }
155
-
156
  update_option("mailmunch_user_email", $_POST["email"]);
157
- update_option("mailmunch_user_password", $_POST["password"]);
158
  delete_option("mailmunch_guest_user");
159
  }
160
 
161
  } else if ($post_action == "sign_up") {
162
 
163
- if (empty($_POST["email"])) {
164
- $invalid_email = true;
165
  } else {
166
  $account_info = $mm_helpers->getEmailPassword();
167
  $mailmunch_email = $account_info['email'];
@@ -169,11 +171,13 @@
169
 
170
  $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
171
  if ($mm->isNewUser($_POST['email'])) {
172
- $update_result = $mm->updateGuest($_POST['email']);
173
  $result = json_decode($update_result['body']);
174
  update_option("mailmunch_user_email", $result->email);
 
175
  if (!$result->guest_user) { delete_option("mailmunch_guest_user"); }
176
  $mailmunch_email = $result->email;
 
177
 
178
  // We have update the guest with real email address, let's create a site now
179
  $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
@@ -208,6 +212,21 @@
208
  $request = $mm->deleteWidget($_POST["site_id"], $_POST["widget_id"]);
209
  }
210
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  }
212
  }
213
 
@@ -218,7 +237,7 @@
218
  $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
219
  $mm->createGuestUser();
220
  update_option("mailmunch_user_email", $mailmunch_email);
221
- update_option("mailmunch_user_password", $mailmunch_password);
222
  update_option("mailmunch_guest_user", true);
223
  }
224
 
@@ -230,14 +249,21 @@
230
  $mailmunch_password = $account_info['password'];
231
 
232
  $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
233
- if (!$mm->validPassword()) {
 
 
 
 
 
 
 
234
  // Invalid user, create a GUEST user
235
  $mailmunch_email = "guest_".uniqid()."@mailmunch.co";
236
  $mailmunch_password = uniqid();
237
  $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
238
  $mm->createGuestUser();
239
  update_option("mailmunch_user_email", $mailmunch_email);
240
- update_option("mailmunch_user_password", $mailmunch_password);
241
  update_option("mailmunch_guest_user", true);
242
  }
243
  }
@@ -252,7 +278,7 @@
252
  $sites = $mm_helpers->createAndGetSites($mm);
253
  }
254
 
255
- if ($mailmunch_data["site_id"]) {
256
  // If there's a site already chosen, we need to get and save it's script_src in WordPress
257
  $site = $mm_helpers->getSite($sites, $mailmunch_data["site_id"]);
258
 
@@ -269,7 +295,7 @@
269
  }
270
  }
271
 
272
- if (!$mailmunch_data["site_id"]) {
273
  // If there's NO chosen site yet
274
 
275
  if (sizeof($sites) == 1 && ($sites[0]->name == get_bloginfo() || $sites[0]->name == "WordPress")) {
@@ -291,21 +317,51 @@
291
 
292
  <p>Choose the site that you would like to link with your WordPress.</p>
293
 
294
- <form action="" method="POST">
295
- <div class="form-group">
296
- <input type="hidden" name="action" value="save_settings" />
 
297
 
298
- <select name="mailmunch_data[site_id]">
299
- <?php foreach ($sites as $site) { ?>
300
- <option value="<?php echo $site->id ?>"><?php echo $site->name ?></option>
301
- <?php } ?>
302
- </select>
303
- </div>
304
 
305
- <div class="form-group">
306
- <input type="submit" value="Save Settings" />
307
- </div>
308
- </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  </div>
310
  <?php
311
  return;
@@ -322,27 +378,30 @@
322
  $current_user = wp_get_current_user();
323
  ?>
324
 
325
- <?php add_thickbox(); ?>
326
-
327
- <a id="signup-box-btn" href="#TB_inline?width=450&height=450&inlineId=signup-signin-box" title="Create Account" class="thickbox" style="display: none;">Sign Up</a>
328
 
329
  <div id="signup-signin-box" style="display:none;">
 
 
 
 
330
  <div id="sign-up-form" class="<?php if (!$_POST || ($_POST["action"] != "sign_in" && $_POST["action"] != "unlink_account")) { ?> active<?php } ?>">
331
  <div class="form-container">
332
- <p style="margin-bottom: 0px;">To activate your optin forms, we will now create your account on MailMunch (<a onclick="showWhyAccount();" id="why-account-btn">Why?</a>).</p>
 
333
 
334
  <div id="why-account" class="alert alert-warning" style="display: none;">
335
  <h4>Why do I need a MailMunch account?</h4>
336
 
337
  <p>
338
- MailMunch is a not just a WordPress plugin but a standalone service. An account is required to identify your WordPress and serve your optin forms.
339
  </p>
340
  </div>
341
 
342
- <?php if ($user_exists) { ?>
343
- <div id="invalid-alert" class="alert alert-danger" role="alert">Account with this email already exists. Please sign in using your password.</div>
344
- <?php } else if ($invalid_email) { ?>
345
- <div id="invalid-alert" class="alert alert-danger" role="alert">Invalid email. Please enter a valid email below.</div>
346
  <?php } ?>
347
 
348
  <form action="" method="POST">
@@ -363,6 +422,11 @@
363
  <input type="email" placeholder="Email Address" name="email" value="<?php echo $current_user->user_email ?>" class="form-control">
364
  </div>
365
 
 
 
 
 
 
366
  <div class="form-group">
367
  <input type="submit" value="Sign Up &raquo;" class="btn btn-success btn-lg" />
368
  </div>
@@ -373,10 +437,11 @@
373
  </div>
374
 
375
  <div id="sign-in-form" class="<?php if ($_POST && ($_POST["action"] == "sign_in" || $_POST["action"] == "unlink_account")) { ?> active<?php } ?>">
 
376
  <p>Sign in using your email and password below.</p>
377
 
378
  <?php if ($_POST && $_POST["action"] == "sign_in") { ?>
379
- <div id="invalid-alert" class="alert alert-danger" role="alert">Invalid Email or Password. Please try again.</div>
380
  <?php } ?>
381
 
382
  <div class="form-container">
@@ -385,7 +450,7 @@
385
 
386
  <div class="form-group">
387
  <label>Email Address</label>
388
- <input type="email" placeholder="Email Address" name="email" class="form-control" value="<?php echo $_POST["email"] ?>" />
389
  </div>
390
  <div class="form-group">
391
  <label>Password</label>
@@ -408,11 +473,14 @@
408
  ?>
409
  <script>
410
  jQuery(window).load(function() {
411
- showSignupBox();
 
 
 
 
412
  });
413
  </script>
414
  <?php
415
  }
416
  }
417
  }
418
- ?>
1
  <?php
2
  /*
3
+ Plugin Name: MailMunch - Increase your Email Subscribers by over 500%
4
  Plugin URI: http://www.mailmunch.co
5
  Description: Collect email addresses from website visitors and grow your subscribers with our attention grabbing optin-forms, entry/exit intent technology, and other effective lead-generation forms.
6
+ Version: 1.4.3
7
  Author: MailMunch
8
  Author URI: http://www.mailmunch.co
9
  License: GPL2
11
 
12
  require_once( plugin_dir_path( __FILE__ ) . 'inc/mailmunchapi.php' );
13
  require_once( plugin_dir_path( __FILE__ ) . 'inc/common.php' );
14
+ require_once( plugin_dir_path( __FILE__ ) . 'inc/sidebar_widget.php' );
15
 
16
  define( 'MAILMUNCH_SLUG', "mailmunch");
17
+ define( 'MAILMUNCH_VER', "1.4.3");
18
  define( 'MAILMUNCH_URL', "www.mailmunch.co");
19
 
20
  // Create unique WordPress instance ID
26
  add_action( 'admin_menu', 'mailmunch_register_page' );
27
 
28
  function mailmunch_register_page(){
29
+ add_options_page('MailMunch', 'MailMunch', 'manage_options', MAILMUNCH_SLUG, 'mailmunch_setup');
30
+ $menu_page = add_menu_page( 'MailMunch Settings', 'MailMunch', 'manage_options', MAILMUNCH_SLUG, 'mailmunch_setup', plugins_url( 'img/icon.png', __FILE__ ), 102.786 );
31
+ // If successful, load admin assets only on that page.
32
+ if ($menu_page) add_action('load-' . $menu_page, 'mailmunch_load_plugin_assets');
33
  }
34
 
35
+ function mailmunch_plugin_settings_link($links) {
36
+ $settings_link = '<a href="options-general.php?page='.MAILMUNCH_SLUG.'">Settings</a>';
37
+ array_unshift($links, $settings_link);
38
+ return $links;
39
+ }
40
+
41
+ $plugin = plugin_basename(__FILE__);
42
+ add_filter('plugin_action_links_'.$plugin, 'mailmunch_plugin_settings_link');
43
+
44
  function mailmunch_load_plugin_assets() {
45
  add_action( 'admin_enqueue_scripts', 'mailmunch_enqueue_admin_styles' );
46
  add_action( 'admin_enqueue_scripts', 'mailmunch_enqueue_admin_scripts' );
86
  if (count($mailmunch_data) == 0) return;
87
 
88
  if (function_exists('wp_footer')) {
89
+ add_action( 'wp_footer', 'mailmunch_load_asset_code' );
 
 
90
  }
91
  elseif (function_exists('wp_head')) {
92
+ add_action( 'wp_head', 'mailmunch_load_asset_code' );
 
 
93
  }
94
  }
95
 
102
  return $content;
103
  }
104
 
105
+ function mailmunch_register_sidebar_widget() {
106
+ register_widget( 'Mailmunch_Sidebar_Widget' );
107
+ }
108
+ add_action( 'widgets_init', 'mailmunch_register_sidebar_widget' );
109
+
110
  function mailmunch_insert_form_after_paragraph($insertion, $paragraph_id, $content) {
111
  $closing_p = '</p>';
112
  $paragraphs = explode($closing_p, $content);
143
 
144
  // This is a POST request. Let's save data first.
145
  if ($_POST) {
146
+ $post_data = (isset($_POST["mailmunch_data"]) ? $_POST["mailmunch_data"] : array());
147
  $post_action = $_POST["action"];
148
 
149
  if ($post_action == "save_settings") {
155
 
156
  $mm = new MailmunchApi($_POST["email"], $_POST["password"], "http://".MAILMUNCH_URL);
157
  if ($mm->validPassword()) {
 
 
 
 
 
 
 
 
 
 
158
  update_option("mailmunch_user_email", $_POST["email"]);
159
+ update_option("mailmunch_user_password", base64_encode($_POST["password"]));
160
  delete_option("mailmunch_guest_user");
161
  }
162
 
163
  } else if ($post_action == "sign_up") {
164
 
165
+ if (empty($_POST["email"]) || empty($_POST["password"])) {
166
+ $invalid_email_password = true;
167
  } else {
168
  $account_info = $mm_helpers->getEmailPassword();
169
  $mailmunch_email = $account_info['email'];
171
 
172
  $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
173
  if ($mm->isNewUser($_POST['email'])) {
174
+ $update_result = $mm->updateGuest($_POST['email'], $_POST['password']);
175
  $result = json_decode($update_result['body']);
176
  update_option("mailmunch_user_email", $result->email);
177
+ update_option("mailmunch_user_password", base64_encode($_POST['password']));
178
  if (!$result->guest_user) { delete_option("mailmunch_guest_user"); }
179
  $mailmunch_email = $result->email;
180
+ $mailmunch_password = $_POST['password'];
181
 
182
  // We have update the guest with real email address, let's create a site now
183
  $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
212
  $request = $mm->deleteWidget($_POST["site_id"], $_POST["widget_id"]);
213
  }
214
 
215
+ } else if ($post_action == "create_site") {
216
+ $site_url = (empty($_POST["site_url"]) ? get_bloginfo() : $_POST["site_url"]);
217
+ $site_name = (empty($_POST["site_name"]) ? home_url() : $_POST["site_name"]);
218
+
219
+ $account_info = $mm_helpers->getEmailPassword();
220
+ $mm = new MailmunchApi($account_info['email'], $account_info["password"], "http://".MAILMUNCH_URL);
221
+ $request = $mm->createSite($site_name, $site_url);
222
+ $site = json_decode($request['body']);
223
+
224
+ if (!empty($site->id)) {
225
+ $mailmunch_data = unserialize(get_option("mailmunch_data"));
226
+ $mailmunch_data["site_id"] = $site->id;
227
+ $mailmunch_data["script_src"] = $site->javascript_url;
228
+ update_option("mailmunch_data", serialize($mailmunch_data));
229
+ }
230
  }
231
  }
232
 
237
  $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
238
  $mm->createGuestUser();
239
  update_option("mailmunch_user_email", $mailmunch_email);
240
+ update_option("mailmunch_user_password", base64_encode($mailmunch_password));
241
  update_option("mailmunch_guest_user", true);
242
  }
243
 
249
  $mailmunch_password = $account_info['password'];
250
 
251
  $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
252
+ $pass_check = $mm->validPassword();
253
+
254
+ if( is_wp_error( $pass_check ) ) {
255
+ echo $pass_check->get_error_message();
256
+ return;
257
+ }
258
+
259
+ if (!$pass_check) {
260
  // Invalid user, create a GUEST user
261
  $mailmunch_email = "guest_".uniqid()."@mailmunch.co";
262
  $mailmunch_password = uniqid();
263
  $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
264
  $mm->createGuestUser();
265
  update_option("mailmunch_user_email", $mailmunch_email);
266
+ update_option("mailmunch_user_password", base64_encode($mailmunch_password));
267
  update_option("mailmunch_guest_user", true);
268
  }
269
  }
278
  $sites = $mm_helpers->createAndGetSites($mm);
279
  }
280
 
281
+ if (isset($mailmunch_data["site_id"])) {
282
  // If there's a site already chosen, we need to get and save it's script_src in WordPress
283
  $site = $mm_helpers->getSite($sites, $mailmunch_data["site_id"]);
284
 
295
  }
296
  }
297
 
298
+ if (!isset($mailmunch_data["site_id"])) {
299
  // If there's NO chosen site yet
300
 
301
  if (sizeof($sites) == 1 && ($sites[0]->name == get_bloginfo() || $sites[0]->name == "WordPress")) {
317
 
318
  <p>Choose the site that you would like to link with your WordPress.</p>
319
 
320
+ <div id="choose-site-form">
321
+ <form action="" method="POST">
322
+ <div class="form-group">
323
+ <input type="hidden" name="action" value="save_settings" />
324
 
325
+ <select name="mailmunch_data[site_id]">
326
+ <?php foreach ($sites as $site) { ?>
327
+ <option value="<?php echo $site->id ?>"><?php echo $site->name ?></option>
328
+ <?php } ?>
329
+ </select>
330
+ </div>
331
 
332
+ <div class="form-group">
333
+ <input type="submit" value="Save Settings" class="button-primary" />
334
+ </div>
335
+ </form>
336
+
337
+ <p>
338
+ Don't see this site above? <a href="" onclick="document.getElementById('create-site-form').style.display = 'block'; document.getElementById('choose-site-form').style.display = 'none'; return false;">Create New Site</a>
339
+ </p>
340
+ </div>
341
+
342
+ <div id="create-site-form" style="display: none;">
343
+ <form action="" method="POST">
344
+ <input type="hidden" name="action" value="create_site" />
345
+
346
+ <div class="form-group">
347
+ <label>Site Name</label>
348
+ <input type="text" name="site_name" value="<?php echo get_bloginfo() ?>" />
349
+ </div>
350
+
351
+ <div class="form-group">
352
+ <label>Site URL</label>
353
+ <input type="text" name="site_url" value="<?php echo home_url() ?>" />
354
+ </div>
355
+
356
+ <div class="form-group">
357
+ <input type="submit" value="Create Site" class="button-primary" />
358
+ </div>
359
+ </form>
360
+
361
+ <p>
362
+ Already have a site in your MailMunch account? <a href="" onclick="document.getElementById('create-site-form').style.display = 'none'; document.getElementById('choose-site-form').style.display = 'block'; return false;">Choose Site</a>
363
+ </p>
364
+ </div>
365
  </div>
366
  <?php
367
  return;
378
  $current_user = wp_get_current_user();
379
  ?>
380
 
381
+ <div id="signup-signin-box-overlay" onclick="hideSignupBox();" style="display: none;"></div>
 
 
382
 
383
  <div id="signup-signin-box" style="display:none;">
384
+ <a id="signup-signin-close" onclick="hideSignupBox();">
385
+ <img src="<?php echo plugins_url( 'img/close.png', __FILE__ ) ?>" />
386
+ </a>
387
+
388
  <div id="sign-up-form" class="<?php if (!$_POST || ($_POST["action"] != "sign_in" && $_POST["action"] != "unlink_account")) { ?> active<?php } ?>">
389
  <div class="form-container">
390
+ <h2 class="modal-header">Sign Up</h2>
391
+ <p>To activate your MailMunch forms, we will now create your account on MailMunch (<a onclick="showWhyAccount();" id="why-account-btn">Why?</a>).</p>
392
 
393
  <div id="why-account" class="alert alert-warning" style="display: none;">
394
  <h4>Why do I need a MailMunch account?</h4>
395
 
396
  <p>
397
+ MailMunch is a not just a WordPress plugin but a standalone service. An account is required to identify your WordPress and serve your MailMunch forms.
398
  </p>
399
  </div>
400
 
401
+ <?php if (isset($user_exists)) { ?>
402
+ <div id="invalid-alert" class="alert alert-danger signup-alert" role="alert">Account with this email already exists. Please sign in using your password.</div>
403
+ <?php } else if (isset($invalid_email_password)) { ?>
404
+ <div id="invalid-alert" class="alert alert-danger signup-alert" role="alert">Invalid email or password. Please enter a valid email and password below.</div>
405
  <?php } ?>
406
 
407
  <form action="" method="POST">
422
  <input type="email" placeholder="Email Address" name="email" value="<?php echo $current_user->user_email ?>" class="form-control">
423
  </div>
424
 
425
+ <div class="form-group">
426
+ <label>Password</label>
427
+ <input type="password" placeholder="Password" name="password" class="form-control" />
428
+ </div>
429
+
430
  <div class="form-group">
431
  <input type="submit" value="Sign Up &raquo;" class="btn btn-success btn-lg" />
432
  </div>
437
  </div>
438
 
439
  <div id="sign-in-form" class="<?php if ($_POST && ($_POST["action"] == "sign_in" || $_POST["action"] == "unlink_account")) { ?> active<?php } ?>">
440
+ <h2 class="modal-header">Sign In</h2>
441
  <p>Sign in using your email and password below.</p>
442
 
443
  <?php if ($_POST && $_POST["action"] == "sign_in") { ?>
444
+ <div id="invalid-alert" class="alert alert-danger signin-alert" role="alert">Invalid Email or Password. Please try again.</div>
445
  <?php } ?>
446
 
447
  <div class="form-container">
450
 
451
  <div class="form-group">
452
  <label>Email Address</label>
453
+ <input type="email" placeholder="Email Address" name="email" class="form-control" value="<?php if (isset($_POST["email"])) { echo $_POST["email"]; } ?>" />
454
  </div>
455
  <div class="form-group">
456
  <label>Password</label>
473
  ?>
474
  <script>
475
  jQuery(window).load(function() {
476
+ <?php if ($_POST && ($_POST["action"] == "sign_in" || $_POST["action"] == "unlink_account")) { ?>
477
+ showSignInForm();
478
+ <?php } else { ?>
479
+ showSignUpForm();
480
+ <?php } ?>
481
  });
482
  </script>
483
  <?php
484
  }
485
  }
486
  }
 
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
- === MailMunch - Increase your Email Subscribers by over 500% ===
2
  Contributors: mailmunch
3
  Tags: widget, MailChimp, newsletter, newsletters, MailChimp plugin, Aweber,subscribe, popup, exit popup, exit intent, growth, subscribers, subscription, hellobar, email, posts, sharing, links, popover, analytics , newsletter, automatic , mail, lightbox, analytics, newsletter, getresponse, collect email, optin, optin forms, double optin, popover, list builder, mailchimp
4
  Requires at least: 3.0.1
5
- Tested up to: 4.0
6
- Stable tag: 1.3.6
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -15,6 +15,8 @@ Collecting emails from your website visitors is the most important aspect of int
15
 
16
  MailMunch provides the tools you need to grow your email subscribers and convert them into customers. Now, people will find your blog, read your article, and subscribe via email to your newsletter. You can also sync your newsletter subscribers to MailChimp, GetResponse, Aweber, or others.
17
 
 
 
18
  = Features =
19
 
20
  * Easy integration with any WordPress theme
@@ -169,4 +171,4 @@ Why people use Aweber
169
  * Added powerful targeting for pages, posts, categories, authors and attachments
170
 
171
  = 1.0.1 =
172
- * Seamless integration with MailMunch designer
1
+ === MailMunch - Increase your Email Subscribers by over 500% ===
2
  Contributors: mailmunch
3
  Tags: widget, MailChimp, newsletter, newsletters, MailChimp plugin, Aweber,subscribe, popup, exit popup, exit intent, growth, subscribers, subscription, hellobar, email, posts, sharing, links, popover, analytics , newsletter, automatic , mail, lightbox, analytics, newsletter, getresponse, collect email, optin, optin forms, double optin, popover, list builder, mailchimp
4
  Requires at least: 3.0.1
5
+ Tested up to: 4.1
6
+ Stable tag: 1.4.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
15
 
16
  MailMunch provides the tools you need to grow your email subscribers and convert them into customers. Now, people will find your blog, read your article, and subscribe via email to your newsletter. You can also sync your newsletter subscribers to MailChimp, GetResponse, Aweber, or others.
17
 
18
+ [vimeo http://vimeo.com/117103275]
19
+
20
  = Features =
21
 
22
  * Easy integration with any WordPress theme
171
  * Added powerful targeting for pages, posts, categories, authors and attachments
172
 
173
  = 1.0.1 =
174
+ * Seamless integration with MailMunch designer
uninstall.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
3
+ exit();
4
+
5
+ delete_option("mailmunch_data");
6
+ delete_option("mailmunch_user_email");
7
+ delete_option("mailmunch_user_password");
8
+ delete_option("mailmunch_guest_user");
9
+ ?>