Simple Membership - Version 3.5.4

Version Description

  • Added a check for PHP5.4 to detect if a server is using very old version of PHP and show an appropriate warning message. This will prevent an error on server's using old PHP version.
  • Added a new feature in the paypal button configuration so you can specify a custom checkout page header/logo.
Download this release

Release Info

Developer mra13
Plugin Icon 128x128 Simple Membership
Version 3.5.4
Comparing to
See all releases

Code changes from version 3.5.1 to 3.5.4

classes/class.swpm-init-time-tasks.php CHANGED
@@ -3,7 +3,7 @@
3
  class SwpmInitTimeTasks {
4
 
5
  public function __construct() {
6
-
7
  }
8
 
9
  public function do_init_tasks() {
@@ -30,7 +30,7 @@ class SwpmInitTimeTasks {
30
  $swpm_logout = filter_input(INPUT_GET, 'swpm-logout');
31
  if (!empty($swpm_logout)) {
32
  SwpmAuth::get_instance()->logout();
33
- $redirect_url = apply_filters('swpm_after_logout_redirect_url',SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL);
34
  wp_redirect(trailingslashit($redirect_url));
35
  exit(0);
36
  }
@@ -40,7 +40,7 @@ class SwpmInitTimeTasks {
40
  SwpmCommentFormRelated::check_and_restrict_comment_posting_to_members();
41
  } else {
42
  //Do admin side init time tasks
43
- if (current_user_can(SWPM_MANAGEMENT_PERMISSION)) {
44
  //Admin dashboard side stuff
45
  $this->admin_init();
46
  }
@@ -74,6 +74,11 @@ class SwpmInitTimeTasks {
74
  include_once('class.swpm-category-list.php');
75
  SwpmCategoryList::update_category_list();
76
  }
 
 
 
 
 
77
  }
78
 
79
  public function create_post_type() {
@@ -143,31 +148,38 @@ class SwpmInitTimeTasks {
143
  //TODO - allow an option to do a redirect if successful edit profile form submission?
144
  }
145
  }
146
-
147
  /* Payment Gateway IPN listener */
 
148
  public function swpm_ipn_listener() {
149
-
150
  //Listen and handle PayPal IPN
151
  $swpm_process_ipn = filter_input(INPUT_GET, 'swpm_process_ipn');
152
  if ($swpm_process_ipn == '1') {
153
  include(SIMPLE_WP_MEMBERSHIP_PATH . 'ipn/swpm_handle_pp_ipn.php');
154
  exit;
155
  }
156
-
157
  //Listen and handle Stripe Buy Now IPN
158
  $swpm_process_stripe_buy_now = filter_input(INPUT_GET, 'swpm_process_stripe_buy_now');
159
  if ($swpm_process_stripe_buy_now == '1') {
160
  include(SIMPLE_WP_MEMBERSHIP_PATH . 'ipn/swpm-stripe-buy-now-ipn.php');
161
  exit;
162
  }
163
-
 
 
 
 
 
 
 
164
  //Listen and handle Braintree Buy Now IPN
165
  $swpm_process_braintree_buy_now = filter_input(INPUT_GET, 'swpm_process_braintree_buy_now');
166
  if ($swpm_process_braintree_buy_now == '1') {
167
  include(SIMPLE_WP_MEMBERSHIP_PATH . 'ipn/swpm-braintree-buy-now-ipn.php');
168
  exit;
169
  }
170
-
171
  }
172
 
173
  }
3
  class SwpmInitTimeTasks {
4
 
5
  public function __construct() {
6
+
7
  }
8
 
9
  public function do_init_tasks() {
30
  $swpm_logout = filter_input(INPUT_GET, 'swpm-logout');
31
  if (!empty($swpm_logout)) {
32
  SwpmAuth::get_instance()->logout();
33
+ $redirect_url = apply_filters('swpm_after_logout_redirect_url', SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL);
34
  wp_redirect(trailingslashit($redirect_url));
35
  exit(0);
36
  }
40
  SwpmCommentFormRelated::check_and_restrict_comment_posting_to_members();
41
  } else {
42
  //Do admin side init time tasks
43
+ if (current_user_can(SWPM_MANAGEMENT_PERMISSION)) {
44
  //Admin dashboard side stuff
45
  $this->admin_init();
46
  }
74
  include_once('class.swpm-category-list.php');
75
  SwpmCategoryList::update_category_list();
76
  }
77
+ $update_post_list = filter_input(INPUT_POST, 'update_post_list');
78
+ if (!empty($update_post_list)) {
79
+ include_once('class.swpm-post-list.php');
80
+ SwpmPostList::update_post_list();
81
+ }
82
  }
83
 
84
  public function create_post_type() {
148
  //TODO - allow an option to do a redirect if successful edit profile form submission?
149
  }
150
  }
151
+
152
  /* Payment Gateway IPN listener */
153
+
154
  public function swpm_ipn_listener() {
155
+
156
  //Listen and handle PayPal IPN
157
  $swpm_process_ipn = filter_input(INPUT_GET, 'swpm_process_ipn');
158
  if ($swpm_process_ipn == '1') {
159
  include(SIMPLE_WP_MEMBERSHIP_PATH . 'ipn/swpm_handle_pp_ipn.php');
160
  exit;
161
  }
162
+
163
  //Listen and handle Stripe Buy Now IPN
164
  $swpm_process_stripe_buy_now = filter_input(INPUT_GET, 'swpm_process_stripe_buy_now');
165
  if ($swpm_process_stripe_buy_now == '1') {
166
  include(SIMPLE_WP_MEMBERSHIP_PATH . 'ipn/swpm-stripe-buy-now-ipn.php');
167
  exit;
168
  }
169
+
170
+ //Listen and handle Stripe Subscription IPN
171
+ $swpm_process_stripe_subscription = filter_input(INPUT_GET, 'swpm_process_stripe_subscription');
172
+ if ($swpm_process_stripe_subscription == '1') {
173
+ include(SIMPLE_WP_MEMBERSHIP_PATH . 'ipn/swpm-stripe-subscription-ipn.php');
174
+ exit;
175
+ }
176
+
177
  //Listen and handle Braintree Buy Now IPN
178
  $swpm_process_braintree_buy_now = filter_input(INPUT_GET, 'swpm_process_braintree_buy_now');
179
  if ($swpm_process_braintree_buy_now == '1') {
180
  include(SIMPLE_WP_MEMBERSHIP_PATH . 'ipn/swpm-braintree-buy-now-ipn.php');
181
  exit;
182
  }
 
183
  }
184
 
185
  }
classes/class.swpm-membership-levels.php CHANGED
@@ -238,6 +238,13 @@ class SwpmMembershipLevels extends WP_List_Table {
238
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_category_list.php');
239
  }
240
 
 
 
 
 
 
 
 
241
  function handle_main_membership_level_admin_menu(){
242
 
243
  do_action( 'swpm_membership_level_menu_start' );
@@ -258,6 +265,7 @@ class SwpmMembershipLevels extends WP_List_Table {
258
  <a class="nav-tab <?php echo ($selected == "add") ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=add"><?php echo SwpmUtils::_('Add Level') ?></a>
259
  <a class="nav-tab <?php echo ($selected == "manage") ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=manage"><?php echo SwpmUtils::_('Manage Content Protection') ?></a>
260
  <a class="nav-tab <?php echo ($selected == "category_list") ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=category_list"><?php echo SwpmUtils::_('Category Protection') ?></a>
 
261
  <?php
262
 
263
  //Trigger hooks that allows an extension to add extra nav tabs in the membership levels menu.
@@ -302,6 +310,9 @@ class SwpmMembershipLevels extends WP_List_Table {
302
  case 'category_list':
303
  $this->manage_categroy();
304
  break;
 
 
 
305
  case 'delete':
306
  $this->delete_level();
307
  default:
238
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_category_list.php');
239
  }
240
 
241
+ function manage_post() {
242
+ $selected = "post_list";
243
+ include_once('class.swpm-post-list.php');
244
+ $post_list = new SwpmPostList();
245
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_post_list.php');
246
+ }
247
+
248
  function handle_main_membership_level_admin_menu(){
249
 
250
  do_action( 'swpm_membership_level_menu_start' );
265
  <a class="nav-tab <?php echo ($selected == "add") ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=add"><?php echo SwpmUtils::_('Add Level') ?></a>
266
  <a class="nav-tab <?php echo ($selected == "manage") ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=manage"><?php echo SwpmUtils::_('Manage Content Protection') ?></a>
267
  <a class="nav-tab <?php echo ($selected == "category_list") ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=category_list"><?php echo SwpmUtils::_('Category Protection') ?></a>
268
+ <a class="nav-tab <?php echo ($selected == "post_list") ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=post_list"><?php echo SwpmUtils::_('Post and Page Protection') ?></a>
269
  <?php
270
 
271
  //Trigger hooks that allows an extension to add extra nav tabs in the membership levels menu.
310
  case 'category_list':
311
  $this->manage_categroy();
312
  break;
313
+ case 'post_list':
314
+ $this->manage_post();
315
+ break;
316
  case 'delete':
317
  $this->delete_level();
318
  default:
classes/class.swpm-post-list.php ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * BCategoryList
5
+ *
6
+ * @author nur
7
+ */
8
+ if (!class_exists('WP_List_Table')) {
9
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
10
+ }
11
+
12
+ class SwpmPostList extends WP_List_Table {
13
+
14
+ public $selected_level_id = 1;
15
+ public $post;
16
+ public $type;
17
+
18
+ function __construct() {
19
+ parent::__construct(array(
20
+ 'singular' => SwpmUtils::_('Membership Level'),
21
+ 'plural' => SwpmUtils::_('Membership Levels'),
22
+ 'ajax' => false
23
+ ));
24
+ $selected = filter_input(INPUT_POST, 'membership_level_id');
25
+ $this->selected_level_id = empty($selected) ? 1 : $selected;
26
+ $this->post = ($this->selected_level_id == 1) ?
27
+ SwpmProtection::get_instance() :
28
+ SwpmPermission::get_instance($this->selected_level_id);
29
+ $this->type = filter_input(INPUT_GET, 'list_type');
30
+ if (is_null($this->type)) {
31
+ $this->type = filter_input(INPUT_POST, 'list_type');
32
+ }
33
+ if (is_null($this->type)) {
34
+ $this->type = 'post';
35
+ }
36
+ }
37
+
38
+ function get_columns() {
39
+ switch ($this->type) {
40
+ case 'page':
41
+ return array(
42
+ 'cb' => '<input type="checkbox" />'
43
+ , 'date' => SwpmUtils::_('Date')
44
+ , 'title' => SwpmUtils::_('Title')
45
+ , 'author' => SwpmUtils::_('Author')
46
+ , 'status' => SwpmUtils::_('Status')
47
+ );
48
+ break;
49
+ case 'post':
50
+ return array(
51
+ 'cb' => '<input type="checkbox" />'
52
+ , 'date' => SwpmUtils::_('Date')
53
+ , 'title' => SwpmUtils::_('Title')
54
+ , 'author' => SwpmUtils::_('Author')
55
+ , 'categories' => SwpmUtils::_('Categories')
56
+ , 'status' => SwpmUtils::_('Status')
57
+ );
58
+ break;
59
+ case 'custom_post':
60
+ return array(
61
+ 'cb' => '<input type="checkbox" />'
62
+ , 'date' => SwpmUtils::_('Date')
63
+ , 'title' => SwpmUtils::_('Title')
64
+ , 'author' => SwpmUtils::_('Author')
65
+ , 'type' => SwpmUtils::_('Type')
66
+ , 'status' => SwpmUtils::_('Status')
67
+ );
68
+ break;
69
+ }
70
+ }
71
+
72
+ function get_sortable_columns() {
73
+ return array();
74
+ }
75
+
76
+ function column_default($item, $column_name) {
77
+ return stripslashes($item[$column_name]);
78
+ }
79
+
80
+ function column_term_id($item) {
81
+ return $item->term_id;
82
+ }
83
+
84
+ function column_taxonomy($item) {
85
+ $taxonomy = $item->taxonomy;
86
+ if ($taxonomy == 'category') {
87
+ $taxonomy = 'Post Category';
88
+ } else {
89
+ $taxonomy = 'Custom Post Type (' . $taxonomy . ')';
90
+ }
91
+ return $taxonomy;
92
+ }
93
+
94
+ function column_cb($item) {
95
+ return sprintf(
96
+ '<input type="hidden" name="ids_in_page[]" value="%s">
97
+ <input type="checkbox" %s name="ids[]" value="%s" />', $item['ID'], $item['protected'], $item['ID']
98
+ );
99
+ }
100
+
101
+ public static function update_post_list() {
102
+ //Check we are on the admin end and user has management permission
103
+ SwpmMiscUtils::check_user_permission_and_is_admin('post protection update');
104
+
105
+ $type = filter_input(INPUT_POST, 'list_type');
106
+
107
+ $selected = filter_input(INPUT_POST, 'membership_level_id');
108
+ $selected_level_id = empty($selected) ? 1 : $selected;
109
+ $post = ($selected_level_id == 1) ?
110
+ SwpmProtection::get_instance() :
111
+ SwpmPermission::get_instance($selected_level_id);
112
+ $args = array('ids' => array(
113
+ 'filter' => FILTER_VALIDATE_INT,
114
+ 'flags' => FILTER_REQUIRE_ARRAY,
115
+ ));
116
+ $filtered = filter_input_array(INPUT_POST, $args);
117
+ $ids = $filtered['ids'];
118
+ $args = array('ids_in_page' => array(
119
+ 'filter' => FILTER_VALIDATE_INT,
120
+ 'flags' => FILTER_REQUIRE_ARRAY,
121
+ ));
122
+ $filtered = filter_input_array(INPUT_POST, $args);
123
+ $ids_in_page = $filtered['ids_in_page'];
124
+ $post->remove($ids_in_page, $type)->apply($ids, $type)->save();
125
+ $message = array('succeeded' => true, 'message' => '<p>' . SwpmUtils::_('Protection settings updated!') . '</p>');
126
+ SwpmTransfer::get_instance()->set('status', $message);
127
+ }
128
+
129
+ function prepare_items() {
130
+ global $wpdb;
131
+ switch ($this->type) {
132
+ case 'page':
133
+ $args = array(
134
+ 'child_of' => 0,
135
+ 'sort_order' => 'ASC',
136
+ 'sort_column' => 'post_title',
137
+ 'hierarchical' => 0,
138
+ 'parent' => -1,
139
+ );
140
+ $all_pages = get_pages($args);
141
+ $filtered_items = array();
142
+ foreach ($all_pages as $page) {
143
+ $page_summary = array();
144
+ $user_info = get_userdata($page->post_author);
145
+ $page_summary['protected'] = $this->post->in_pages($page->ID) ? " checked='checked'" : "";
146
+ $page_summary['ID'] = $page->ID;
147
+ $page_summary['date'] = $page->post_date;
148
+ $page_summary['title'] = '<a href="' . get_permalink($page->ID) . '" target="_blank">' . $page->post_title . '</a>';
149
+ $page_summary['author'] = $user_info->user_login;
150
+ $page_summary['status'] = $page->post_status;
151
+ $filtered_items[] = $page_summary;
152
+ }
153
+ break;
154
+ case 'post':
155
+ $sql = "SELECT ID,post_date,post_title,post_author, post_type, post_status FROM $wpdb->posts ";
156
+ $sql .= " WHERE post_type = 'post' AND post_status = 'publish'";
157
+ $all_posts = $wpdb->get_results($sql);
158
+ $filtered_items = array();
159
+ foreach ($all_posts as $post) {
160
+ //if($post->post_type=='page')continue;
161
+ $post_summary = array();
162
+ $user_info = get_userdata($post->post_author);
163
+ $categories = get_the_category($post->ID);
164
+ $cat = array();
165
+ foreach ($categories as $category)
166
+ $cat[] = $category->category_nicename;
167
+ $post_summary['protected'] = $this->post->in_posts($post->ID) ? " checked='checked'" : "";
168
+ $post_summary['ID'] = $post->ID;
169
+ $post_summary['date'] = $post->post_date;
170
+ $post_summary['title'] = '<a href="' . get_permalink($post->ID) . '" target="_blank">' . $post->post_title . '</a>';
171
+ $post_summary['author'] = $user_info->user_login;
172
+ $post_summary['categories'] = rawurldecode(implode(' ', $cat));
173
+ $post_summary['status'] = $post->post_status;
174
+ $filtered_items[] = $post_summary;
175
+ }
176
+ break;
177
+ case 'custom_post':
178
+ $filtered_items = array();
179
+ $args = array('public' => true, '_builtin' => false);
180
+ $post_types = get_post_types($args);
181
+ $arg = "'" . implode('\',\'', $post_types) . "'";
182
+ if (!empty($arg)) {
183
+ $sql = "SELECT ID,post_date,post_title,post_author, post_type, post_status FROM $wpdb->posts ";
184
+ $sql .= " WHERE post_type IN (" . $arg . ") AND (post_status='inherit' OR post_status='publish')";
185
+ $all_posts = $wpdb->get_results($sql);
186
+ foreach ($all_posts as $post) {
187
+ $post_summary = array();
188
+ $user_info = get_userdata($post->post_author);
189
+ $post_summary['protected'] = $this->post->in_custom_posts($post->ID) ? "checked='checked'" : "";
190
+ $post_summary['ID'] = $post->ID;
191
+ $post_summary['date'] = $post->post_date;
192
+ $post_summary['title'] = '<a href="' . get_permalink($post->ID) . '" target="_blank">' . $post->post_title . '</a>';
193
+ $post_summary['author'] = $user_info->user_login;
194
+ $post_summary['type'] = $post->post_type;
195
+ $post_summary['status'] = $post->post_status;
196
+ $filtered_items[] = $post_summary;
197
+ }
198
+ }
199
+ break;
200
+ }
201
+ $totalitems = count($filtered_items);
202
+ $perpage = 100;
203
+ $paged = !empty($_GET["paged"]) ? sanitize_text_field($_GET["paged"]) : '';
204
+ if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
205
+ $paged = 1;
206
+ }
207
+ $totalpages = ceil($totalitems / $perpage);
208
+ $offset = 0;
209
+ if (!empty($paged) && !empty($perpage)) {
210
+ $offset = ($paged - 1) * $perpage;
211
+ }
212
+ for ($i = $offset; $i < ((int) $offset + (int) $perpage) && !empty($filtered_items[$i]); $i++) {
213
+ $all_items[] = $filtered_items[$i];
214
+ }
215
+ $this->set_pagination_args(array(
216
+ "total_items" => $totalitems,
217
+ "total_pages" => $totalpages,
218
+ "per_page" => $perpage,
219
+ ));
220
+
221
+ $columns = $this->get_columns();
222
+ $hidden = array();
223
+ $sortable = $this->get_sortable_columns();
224
+
225
+ $this->_column_headers = array($columns, $hidden, $sortable);
226
+ $this->items = $all_items;
227
+ }
228
+
229
+ function no_items() {
230
+ SwpmUtils::e('No items found.');
231
+ }
232
+
233
+ }
classes/class.swpm-utils-member.php CHANGED
@@ -88,6 +88,14 @@ class SwpmMemberUtils {
88
  return $result;
89
  }
90
 
 
 
 
 
 
 
 
 
91
  public static function get_all_members_of_a_level($level_id) {
92
  //Retrieves all the SWPM user records for the given membership level
93
  global $wpdb;
88
  return $result;
89
  }
90
 
91
+ public static function get_wp_user_from_swpm_user_id($swpm_id) {
92
+ //Retrieves the WP user record for the given SWPM member ID.
93
+ $swpm_user_row = SwpmMemberUtils::get_user_by_id($swpm_id);
94
+ $username = $swpm_user_row->user_name;
95
+ $wp_user = get_user_by('login', $username);
96
+ return $wp_user;
97
+ }
98
+
99
  public static function get_all_members_of_a_level($level_id) {
100
  //Retrieves all the SWPM user records for the given membership level
101
  global $wpdb;
classes/class.swpm-utils-misc.php CHANGED
@@ -181,7 +181,7 @@ class SwpmMiscUtils {
181
  return $pageURL;
182
  }
183
 
184
- public static function replace_dynamic_tags($msg_body, $member_id, $additional_args='') {
185
  $settings = SwpmSettings::get_instance();
186
  $user_record = SwpmMemberUtils::get_user_by_id($member_id);
187
 
@@ -195,41 +195,42 @@ class SwpmMiscUtils {
195
 
196
  //Construct the primary address value
197
  $primary_address = "";
198
- if(!empty($user_record->address_street) && !empty($user_record->address_city)){
199
  //An address value is present.
200
  $primary_address .= $user_record->address_street;
201
  $primary_address .= "\n" . $user_record->address_city;
202
- if(!empty($user_record->address_state)){
203
  $primary_address .= " " . $user_record->address_state;
204
  }
205
- if(!empty($user_record->address_zipcode)){
206
  $primary_address .= " " . $user_record->address_zipcode;
207
  }
208
- if(!empty($user_record->country)){
209
  $primary_address .= "\n" . $user_record->country;
210
- }
211
  }
212
 
213
  //Format some field values
214
  $member_since_formatted = SwpmUtils::get_formatted_date_according_to_wp_settings($user_record->member_since);
215
  $subsc_starts_formatted = SwpmUtils::get_formatted_date_according_to_wp_settings($user_record->subscription_starts);
216
 
 
217
  //Define the replacable tags
218
  $tags = array("{member_id}", "{user_name}", "{first_name}", "{last_name}", "{membership_level}",
219
- "{account_state}", "{email}", "{phone}", "{member_since}", "{subscription_starts}", "{company_name}",
220
  "{password}", "{login_link}", "{reg_link}", "{primary_address}"
221
  );
222
-
223
  //Define the values
224
  $vals = array($member_id, $user_record->user_name, $user_record->first_name, $user_record->last_name, $user_record->membership_level,
225
  $user_record->account_state, $user_record->email, $user_record->phone, $member_since_formatted, $subsc_starts_formatted, $user_record->company_name,
226
  $password, $login_link, $reg_link, $primary_address
227
  );
228
-
229
  $msg_body = str_replace($tags, $vals, $msg_body);
230
  return $msg_body;
231
  }
232
-
233
  public static function get_login_link() {
234
  $login_url = SwpmSettings::get_instance()->get_value('login-page-url');
235
  $joinus_url = SwpmSettings::get_instance()->get_value('join-us-page-url');
@@ -237,13 +238,13 @@ class SwpmMiscUtils {
237
  return '<span style="color:red;">Simple Membership is not configured correctly. The login page or the join us page URL is missing in the settings configuration. '
238
  . 'Please contact <a href="mailto:' . get_option('admin_email') . '">Admin</a>';
239
  }
240
-
241
  //Create the login/protection message
242
- $filtered_login_url = apply_filters('swpm_get_login_link_url', $login_url);//Addons can override the login URL value using this filter.
243
  $login_msg = '';
244
  $login_msg .= SwpmUtils::_('Please') . ' <a class="swpm-login-link" href="' . $filtered_login_url . '">' . SwpmUtils::_('Login') . '</a>. ';
245
  $login_msg .= SwpmUtils::_('Not a Member?') . ' <a href="' . $joinus_url . '">' . SwpmUtils::_('Join Us') . '</a>';
246
-
247
  return $login_msg;
248
  }
249
 
@@ -255,66 +256,83 @@ class SwpmMiscUtils {
255
  }
256
  return SwpmUtils::_('Please') . ' <a class="swpm-renewal-link" href="' . $renewal . '">' . SwpmUtils::_('renew') . '</a> ' . SwpmUtils::_(' your account to gain access to this content.');
257
  }
258
-
259
- public static function compare_url($url1, $url2){
260
  $url1 = trailingslashit(strtolower($url1));
261
- $url2 = trailingslashit(strtolower($url2));
262
- if ($url1 == $url2) {return true;}
263
-
 
 
264
  $url1 = parse_url($url1);
265
- $url2 = parse_url($url2);
266
-
267
- $components = array('scheme','host','port','path');
268
-
269
- foreach ($components as $key=>$value){
270
- if (!isset($url1[$value])&& !isset($url2[$value])) {continue;}
271
-
272
- if (!isset($url2[$value])) {return false;}
273
- if (!isset($url1[$value])) {return false;}
274
-
275
- if ($url1[$value] != $url2[$value]) {return false;}
 
 
 
 
 
 
 
 
276
  }
277
 
278
- if (!isset($url1['query'])&& !isset($url2['query'])) {return true;}
 
 
 
 
 
 
 
 
 
279
 
280
- if (!isset($url2['query'])) {return false;}
281
- if (!isset($url1['query'])) {return false;}
282
-
283
- return strpos($url1['query'], $url2['query']) || strpos($url2['query'], $url1['query']);
284
  }
285
-
286
- public static function is_swpm_admin_page(){
287
  if (isset($_GET['page']) && (stripos($_GET['page'], 'simple_wp_membership') !== false)) {
288
  //This is an admin page of the SWPM plugin
289
  return true;
290
- }
291
  return false;
292
  }
293
-
294
- public static function check_user_permission_and_is_admin($action_name){
295
  //Check we are on the admin end
296
  if (!is_admin()) {
297
  //Error! This is not on the admin end. This can only be done from the admin side
298
- wp_die(SwpmUtils::_("Error! This action (".$action_name.") can only be done from admin end."));
299
  }
300
 
301
  //Check user has management permission
302
- if (!current_user_can(SWPM_MANAGEMENT_PERMISSION)) {
303
  //Error! Only management users can do this
304
- wp_die(SwpmUtils::_("Error! This action (".$action_name.") can only be done by an user with management permission."));
305
- }
306
  }
307
-
308
- public static function format_raw_content_for_front_end_display($raw_content){
309
- $formatted_content = wptexturize ($raw_content);
310
- $formatted_content = convert_smilies ($formatted_content);
311
- $formatted_content = convert_chars ($formatted_content);
312
- $formatted_content = wpautop ($formatted_content);
313
- $formatted_content = shortcode_unautop ($formatted_content);
314
- $formatted_content = prepend_attachment ($formatted_content);
315
- $formatted_content = capital_P_dangit ($formatted_content);
316
  $formatted_content = do_shortcode($formatted_content);
317
-
318
  return $formatted_content;
319
  }
320
- }
 
181
  return $pageURL;
182
  }
183
 
184
+ public static function replace_dynamic_tags($msg_body, $member_id, $additional_args = '') {
185
  $settings = SwpmSettings::get_instance();
186
  $user_record = SwpmMemberUtils::get_user_by_id($member_id);
187
 
195
 
196
  //Construct the primary address value
197
  $primary_address = "";
198
+ if (!empty($user_record->address_street) && !empty($user_record->address_city)) {
199
  //An address value is present.
200
  $primary_address .= $user_record->address_street;
201
  $primary_address .= "\n" . $user_record->address_city;
202
+ if (!empty($user_record->address_state)) {
203
  $primary_address .= " " . $user_record->address_state;
204
  }
205
+ if (!empty($user_record->address_zipcode)) {
206
  $primary_address .= " " . $user_record->address_zipcode;
207
  }
208
+ if (!empty($user_record->country)) {
209
  $primary_address .= "\n" . $user_record->country;
210
+ }
211
  }
212
 
213
  //Format some field values
214
  $member_since_formatted = SwpmUtils::get_formatted_date_according_to_wp_settings($user_record->member_since);
215
  $subsc_starts_formatted = SwpmUtils::get_formatted_date_according_to_wp_settings($user_record->subscription_starts);
216
 
217
+
218
  //Define the replacable tags
219
  $tags = array("{member_id}", "{user_name}", "{first_name}", "{last_name}", "{membership_level}",
220
+ "{account_state}", "{email}", "{phone}", "{member_since}", "{subscription_starts}", "{company_name}",
221
  "{password}", "{login_link}", "{reg_link}", "{primary_address}"
222
  );
223
+
224
  //Define the values
225
  $vals = array($member_id, $user_record->user_name, $user_record->first_name, $user_record->last_name, $user_record->membership_level,
226
  $user_record->account_state, $user_record->email, $user_record->phone, $member_since_formatted, $subsc_starts_formatted, $user_record->company_name,
227
  $password, $login_link, $reg_link, $primary_address
228
  );
229
+
230
  $msg_body = str_replace($tags, $vals, $msg_body);
231
  return $msg_body;
232
  }
233
+
234
  public static function get_login_link() {
235
  $login_url = SwpmSettings::get_instance()->get_value('login-page-url');
236
  $joinus_url = SwpmSettings::get_instance()->get_value('join-us-page-url');
238
  return '<span style="color:red;">Simple Membership is not configured correctly. The login page or the join us page URL is missing in the settings configuration. '
239
  . 'Please contact <a href="mailto:' . get_option('admin_email') . '">Admin</a>';
240
  }
241
+
242
  //Create the login/protection message
243
+ $filtered_login_url = apply_filters('swpm_get_login_link_url', $login_url); //Addons can override the login URL value using this filter.
244
  $login_msg = '';
245
  $login_msg .= SwpmUtils::_('Please') . ' <a class="swpm-login-link" href="' . $filtered_login_url . '">' . SwpmUtils::_('Login') . '</a>. ';
246
  $login_msg .= SwpmUtils::_('Not a Member?') . ' <a href="' . $joinus_url . '">' . SwpmUtils::_('Join Us') . '</a>';
247
+
248
  return $login_msg;
249
  }
250
 
256
  }
257
  return SwpmUtils::_('Please') . ' <a class="swpm-renewal-link" href="' . $renewal . '">' . SwpmUtils::_('renew') . '</a> ' . SwpmUtils::_(' your account to gain access to this content.');
258
  }
259
+
260
+ public static function compare_url($url1, $url2) {
261
  $url1 = trailingslashit(strtolower($url1));
262
+ $url2 = trailingslashit(strtolower($url2));
263
+ if ($url1 == $url2) {
264
+ return true;
265
+ }
266
+
267
  $url1 = parse_url($url1);
268
+ $url2 = parse_url($url2);
269
+
270
+ $components = array('scheme', 'host', 'port', 'path');
271
+
272
+ foreach ($components as $key => $value) {
273
+ if (!isset($url1[$value]) && !isset($url2[$value])) {
274
+ continue;
275
+ }
276
+
277
+ if (!isset($url2[$value])) {
278
+ return false;
279
+ }
280
+ if (!isset($url1[$value])) {
281
+ return false;
282
+ }
283
+
284
+ if ($url1[$value] != $url2[$value]) {
285
+ return false;
286
+ }
287
  }
288
 
289
+ if (!isset($url1['query']) && !isset($url2['query'])) {
290
+ return true;
291
+ }
292
+
293
+ if (!isset($url2['query'])) {
294
+ return false;
295
+ }
296
+ if (!isset($url1['query'])) {
297
+ return false;
298
+ }
299
 
300
+ return strpos($url1['query'], $url2['query']) || strpos($url2['query'], $url1['query']);
 
 
 
301
  }
302
+
303
+ public static function is_swpm_admin_page() {
304
  if (isset($_GET['page']) && (stripos($_GET['page'], 'simple_wp_membership') !== false)) {
305
  //This is an admin page of the SWPM plugin
306
  return true;
307
+ }
308
  return false;
309
  }
310
+
311
+ public static function check_user_permission_and_is_admin($action_name) {
312
  //Check we are on the admin end
313
  if (!is_admin()) {
314
  //Error! This is not on the admin end. This can only be done from the admin side
315
+ wp_die(SwpmUtils::_("Error! This action (" . $action_name . ") can only be done from admin end."));
316
  }
317
 
318
  //Check user has management permission
319
+ if (!current_user_can(SWPM_MANAGEMENT_PERMISSION)) {
320
  //Error! Only management users can do this
321
+ wp_die(SwpmUtils::_("Error! This action (" . $action_name . ") can only be done by an user with management permission."));
322
+ }
323
  }
324
+
325
+ public static function format_raw_content_for_front_end_display($raw_content) {
326
+ $formatted_content = wptexturize($raw_content);
327
+ $formatted_content = convert_smilies($formatted_content);
328
+ $formatted_content = convert_chars($formatted_content);
329
+ $formatted_content = wpautop($formatted_content);
330
+ $formatted_content = shortcode_unautop($formatted_content);
331
+ $formatted_content = prepend_attachment($formatted_content);
332
+ $formatted_content = capital_P_dangit($formatted_content);
333
  $formatted_content = do_shortcode($formatted_content);
334
+
335
  return $formatted_content;
336
  }
337
+
338
+ }
ipn/swpm-stripe-subscription-ipn.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ include(SIMPLE_WP_MEMBERSHIP_PATH . 'ipn/swpm_handle_subsc_ipn.php');
4
+
5
+ class SwpmStripeSubscriptionIpnHandler {
6
+
7
+ public function __construct() {
8
+
9
+ $this->handle_stripe_ipn();
10
+ }
11
+
12
+ public function handle_stripe_ipn() {
13
+ if (isset($_GET['hook'])) {
14
+ //this is Webhook notify from Stripe
15
+ //TODO: add Webhook Signing Secret verification
16
+ //To do this, we need to get customer ID, retreive its details from Stripe, get button_id from metadata
17
+ //and see if the button has Signing Secret option set. If it is - we need to check signatures
18
+ //More details here: https://stripe.com/docs/webhooks#signatures
19
+
20
+ $input = @file_get_contents("php://input");
21
+ if (empty($input)) {
22
+ SwpmLog::log_simple_debug("Stripe Subscription Webhook sent empty data or page was accessed directly. Aborting.", false);
23
+ echo 'Empty Webhook data received.';
24
+ die;
25
+ }
26
+ //SwpmLog::log_simple_debug($input, true);
27
+ $event_json = json_decode($input);
28
+
29
+ $type = $event_json->type;
30
+
31
+ if ($type == 'customer.subscription.deleted' || $type == "charge.refunded") {
32
+ //Subscription expired or refunded event
33
+ SwpmLog::log_simple_debug("Stripe Subscription Webhook received. Processing request...", true);
34
+ //Let's form minimal ipn_data array for swpm_handle_subsc_cancel_stand_alone
35
+ $customer = $event_json->data->object->customer;
36
+ $ipn_data = array();
37
+ $ipn_data['subscr_id'] = $customer;
38
+ $ipn_data['parent_txn_id'] = $customer;
39
+
40
+ swpm_handle_subsc_cancel_stand_alone($ipn_data);
41
+ }
42
+ http_response_code(200); //tells Stripe we received this notify
43
+ return;
44
+ }
45
+
46
+ SwpmLog::log_simple_debug("Stripe Subscription IPN received. Processing request...", true);
47
+ //SwpmLog::log_simple_debug(print_r($_REQUEST, true), true);//Useful for debugging purpose
48
+ //Include the Stripe library.
49
+ include(SIMPLE_WP_MEMBERSHIP_PATH . 'lib/stripe-gateway/init.php');
50
+
51
+ //Read and sanitize the request parameters.
52
+ $button_id = sanitize_text_field($_REQUEST['item_number']);
53
+ $button_id = absint($button_id);
54
+ $button_title = sanitize_text_field($_REQUEST['item_name']);
55
+
56
+ $stripe_token = sanitize_text_field($_POST['stripeToken']);
57
+ $stripe_token_type = sanitize_text_field($_POST['stripeTokenType']);
58
+ $stripe_email = sanitize_email($_POST['stripeEmail']);
59
+
60
+ //Retrieve the CPT for this button
61
+ $button_cpt = get_post($button_id);
62
+ if (!$button_cpt) {
63
+ //Fatal error. Could not find this payment button post object.
64
+ SwpmLog::log_simple_debug("Fatal Error! Failed to retrieve the payment button post object for the given button ID: " . $button_id, false);
65
+ wp_die("Fatal Error! Payment button (ID: " . $button_id . ") does not exist. This request will fail.");
66
+ }
67
+
68
+ $plan_id = get_post_meta($button_id, 'stripe_plan_id', true);
69
+ $descr = 'Subscription to "' . $plan_id . '" plan';
70
+
71
+ $membership_level_id = get_post_meta($button_id, 'membership_level_id', true);
72
+
73
+ //Validate and verify some of the main values.
74
+ //Validation passed. Go ahead with the charge.
75
+ //Sandbox and other settings
76
+ $settings = SwpmSettings::get_instance();
77
+ $sandbox_enabled = $settings->get_value('enable-sandbox-testing');
78
+ if ($sandbox_enabled) {
79
+ SwpmLog::log_simple_debug("Sandbox payment mode is enabled. Using test API key details.", true);
80
+ $secret_key = get_post_meta($button_id, 'stripe_test_secret_key', true);
81
+ ; //Use sandbox API key
82
+ } else {
83
+ $secret_key = get_post_meta($button_id, 'stripe_live_secret_key', true);
84
+ ; //Use live API key
85
+ }
86
+
87
+ //Set secret API key in the Stripe library
88
+ \Stripe\Stripe::setApiKey($secret_key);
89
+
90
+ // Get the credit card details submitted by the form
91
+ $token = $stripe_token;
92
+
93
+ // Create the charge on Stripe's servers - this will charge the user's card
94
+ try {
95
+ $customer = \Stripe\Customer::create(array(
96
+ 'description' => $descr,
97
+ 'email' => $stripe_email,
98
+ 'source' => $token,
99
+ 'plan' => $plan_id,
100
+ ));
101
+ } catch (Exception $e) {
102
+ SwpmLog::log_simple_debug("Error occured during Stripe Subscribe. " . $e->getMessage(), false);
103
+ $body = $e->getJsonBody();
104
+ $error = $body['error'];
105
+ $error_string = print_r($error, true);
106
+ SwpmLog::log_simple_debug("Error details: " . $error_string, false);
107
+ wp_die("Stripe Subscription Error! " . $e->getMessage() . $error_string);
108
+ }
109
+
110
+ //Everything went ahead smoothly with the charge.
111
+ SwpmLog::log_simple_debug("Stripe Subscription successful.", true);
112
+
113
+ //let's add button_id to metadata
114
+ $customer->metadata = array('button_id' => $button_id);
115
+ try {
116
+ $customer->save();
117
+ } catch (Exception $e) {
118
+ SwpmLog::log_simple_debug("Error occured during Stripe customer metadata update. " . $e->getMessage(), false);
119
+ $body = $e->getJsonBody();
120
+ SwpmLog::log_simple_debug("Error details: " . $error_string, false);
121
+ }
122
+
123
+ //Grab the charge ID and set it as the transaction ID.
124
+ $txn_id = $customer->id; //$charge->balance_transaction;
125
+ //The charge ID can be used to
126
+ // retrieve the transaction details using hte following call.
127
+ //\Stripe\Charge::retrieve($charge->id);
128
+ $custom = sanitize_text_field($_REQUEST['custom']);
129
+ $custom_var = SwpmTransactions::parse_custom_var($custom);
130
+ $swpm_id = isset($custom_var['swpm_id']) ? $custom_var['swpm_id'] : '';
131
+
132
+ $payment_amount = $customer->subscriptions->data[0]->plan->amount / 100;
133
+
134
+ //Create the $ipn_data array.
135
+ $ipn_data = array();
136
+ $ipn_data['mc_gross'] = $payment_amount;
137
+ $ipn_data['first_name'] = '';
138
+ $ipn_data['last_name'] = '';
139
+ $ipn_data['payer_email'] = $stripe_email;
140
+ $ipn_data['membership_level'] = $membership_level_id;
141
+ $ipn_data['txn_id'] = $txn_id;
142
+ $ipn_data['subscr_id'] = $txn_id;
143
+ $ipn_data['swpm_id'] = $swpm_id;
144
+ $ipn_data['ip'] = $custom_var['user_ip'];
145
+ $ipn_data['custom'] = $custom;
146
+ $ipn_data['gateway'] = 'stripe';
147
+ $ipn_data['status'] = 'completed';
148
+
149
+ $ipn_data['address_street'] = '';
150
+ $ipn_data['address_city'] = '';
151
+ $ipn_data['address_state'] = '';
152
+ $ipn_data['address_zipcode'] = '';
153
+ $ipn_data['country'] = '';
154
+
155
+ //Handle the membership signup related tasks.
156
+ swpm_handle_subsc_signup_stand_alone($ipn_data, $membership_level_id, $txn_id, $swpm_id);
157
+
158
+ //Save the transaction record
159
+ SwpmTransactions::save_txn_record($ipn_data);
160
+ SwpmLog::log_simple_debug('Transaction data saved.', true);
161
+
162
+ //Trigger the stripe IPN processed action hook (so other plugins can can listen for this event).
163
+ do_action('swpm_stripe_ipn_processed', $ipn_data);
164
+
165
+ do_action('swpm_payment_ipn_processed', $ipn_data);
166
+
167
+ //Redirect the user to the return URL (or to the homepage if a return URL is not specified for this payment button).
168
+ $return_url = get_post_meta($button_id, 'return_url', true);
169
+ if (empty($return_url)) {
170
+ $return_url = SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL;
171
+ }
172
+ SwpmLog::log_simple_debug("Redirecting customer to: " . $return_url, true);
173
+ SwpmLog::log_simple_debug("End of Stripe Subscription IPN processing.", true, true);
174
+ SwpmMiscUtils::redirect_to_url($return_url);
175
+ }
176
+
177
+ }
178
+
179
+ $swpm_stripe_subscription_ipn = new SwpmStripeSubscriptionIpnHandler();
js/jquery.validationEngine.js CHANGED
@@ -1449,7 +1449,7 @@
1449
  }
1450
 
1451
  // If there is an error or if the the field is already validated, do not re-execute AJAX
1452
- if (!options.isError && !methods._checkAjaxFieldStatus(field.attr("id"), options)) {
1453
  $.ajax({
1454
  type: options.ajaxFormValidationMethod,
1455
  url: rule.url,
1449
  }
1450
 
1451
  // If there is an error or if the the field is already validated, do not re-execute AJAX
1452
+ if (!options.isError && !methods._checkAjaxFieldStatus(field.attr("id"), options) && options.eventTrigger!="submit") {
1453
  $.ajax({
1454
  type: options.ajaxFormValidationMethod,
1455
  url: rule.url,
lib/stripe-util-functions.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Misc Utility Functions for the Stripe Gateway */
4
+ class StripeUtilFunctions{
5
+
6
+ public static function get_stripe_plan_info($api_key, $plan_id) {
7
+ require_once(SIMPLE_WP_MEMBERSHIP_PATH . 'lib/stripe-gateway/init.php');
8
+
9
+ $stripe_err = '';
10
+
11
+ try {
12
+ \Stripe\Stripe::setApiKey($api_key);
13
+
14
+ $plan = \Stripe\Plan::retrieve($plan_id);
15
+ } catch (\Stripe\Error\Authentication $e) {
16
+ // Invalid secret key
17
+ $stripe_err = $e->getMessage();
18
+ } catch (Exception $e) {
19
+ //that's probably invalid plan ID or some other error
20
+ $stripe_err = $e->getMessage();
21
+ }
22
+ if (empty($stripe_err)) {
23
+ //we proceed with getting plan details only if no errors occured
24
+ $plan_data['name'] = $plan->name;
25
+ $plan_data['amount'] = $plan->amount;
26
+ $plan_data['currency'] = $plan->currency;
27
+ $plan_data['interval'] = $plan->interval;
28
+ $plan_data['interval_count'] = $plan->interval_count;
29
+ $plan_data['trial_period_days'] = $plan->trial_period_days;
30
+ return array('success' => true, 'plan_data' => $plan_data);
31
+ } else {
32
+ return array('success' => false, 'error_msg' => $stripe_err);
33
+ }
34
+ }
35
+
36
+ }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://simple-membership-plugin.com/
4
  Tags: member, members, members only, membership, memberships, register, WordPress membership plugin, content, content protection, paypal, restrict, restrict access, Restrict content, admin, access control, subscription, teaser, protection, profile, login, login page, bbpress, stripe, braintree
5
  Requires at least: 4.0
6
  Tested up to: 4.8
7
- Stable tag: 3.5.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -60,6 +60,7 @@ You can create a free forum user account and ask your questions.
60
  * There is an option to enable debug logging so you can troubleshoot membership payment related issues easily (if any).
61
  * Ability to customize the content protection message that gets shown to non-members.
62
  * Ability to partially protect post or page content.
 
63
  * Ability to use merge vars in the membership email notification.
64
  * Membership management side is handled by the plugin.
65
  * Ability to manually approve your members.
@@ -137,6 +138,21 @@ https://simple-membership-plugin.com/
137
 
138
  == Changelog ==
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  = 3.5.1 =
141
  - Added a new action hook (swpm_before_login_request_is_processed) that can be used to check stuff before the login request is processed by the plugin.
142
  - Stripe button: zero-decimal currencies (like JPY) are no longer multiplied by 100.
4
  Tags: member, members, members only, membership, memberships, register, WordPress membership plugin, content, content protection, paypal, restrict, restrict access, Restrict content, admin, access control, subscription, teaser, protection, profile, login, login page, bbpress, stripe, braintree
5
  Requires at least: 4.0
6
  Tested up to: 4.8
7
+ Stable tag: 3.5.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
60
  * There is an option to enable debug logging so you can troubleshoot membership payment related issues easily (if any).
61
  * Ability to customize the content protection message that gets shown to non-members.
62
  * Ability to partially protect post or page content.
63
+ * You can apply protection to posts and pages in bulk.
64
  * Ability to use merge vars in the membership email notification.
65
  * Membership management side is handled by the plugin.
66
  * Ability to manually approve your members.
138
 
139
  == Changelog ==
140
 
141
+ = 3.5.4 =
142
+ - Added a check for PHP5.4 to detect if a server is using very old version of PHP and show an appropriate warning message. This will prevent an error on server's using old PHP version.
143
+ - Added a new feature in the paypal button configuration so you can specify a custom checkout page header/logo.
144
+
145
+ = 3.5.3 =
146
+ - The login widget now shows a link to the edit profile page (for the logged in members).
147
+ - Applied a fix in the validation JS code that was preventing paid membership registration to be completed properly if the email field was skipped.
148
+ - Added Stripe subscription checkout option.
149
+
150
+ = 3.5.2 =
151
+ - There is a new feature to apply protection to posts and pages in bulk. The following documentation explains how to use this feature:
152
+ https://simple-membership-plugin.com/apply-protection-posts-pages-bulk/
153
+
154
+ - Added a new utility function in the SwpmMemberUtils class.
155
+
156
  = 3.5.1 =
157
  - Added a new action hook (swpm_before_login_request_is_processed) that can be used to check stuff before the login request is processed by the plugin.
158
  - Stripe button: zero-decimal currencies (like JPY) are no longer multiplied by 100.
simple-wp-membership.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: Simple WordPress Membership
4
- Version: 3.5.1
5
  Plugin URI: https://simple-membership-plugin.com/
6
  Author: smp7, wp.insider
7
  Author URI: https://simple-membership-plugin.com/
@@ -17,7 +17,7 @@ include_once('classes/class.simple-wp-membership.php');
17
  include_once('classes/class.swpm-cronjob.php');
18
  include_once('swpm-compat.php');
19
 
20
- define('SIMPLE_WP_MEMBERSHIP_VER', '3.5.1');
21
  define('SIMPLE_WP_MEMBERSHIP_DB_VER', '1.2');
22
  define('SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL', home_url());
23
  define('SIMPLE_WP_MEMBERSHIP_PATH', dirname(__FILE__) . '/');
1
  <?php
2
  /*
3
  Plugin Name: Simple WordPress Membership
4
+ Version: 3.5.4
5
  Plugin URI: https://simple-membership-plugin.com/
6
  Author: smp7, wp.insider
7
  Author URI: https://simple-membership-plugin.com/
17
  include_once('classes/class.swpm-cronjob.php');
18
  include_once('swpm-compat.php');
19
 
20
+ define('SIMPLE_WP_MEMBERSHIP_VER', '3.5.4');
21
  define('SIMPLE_WP_MEMBERSHIP_DB_VER', '1.2');
22
  define('SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL', home_url());
23
  define('SIMPLE_WP_MEMBERSHIP_PATH', dirname(__FILE__) . '/');
views/admin_post_list.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ <div class="swpm-yellow-box">
4
+ <p>
5
+ <?php echo SwpmUtils::_('First of all, globally protect posts and pages on your site by selecting "General Protection" from the drop-down box below and then select posts and pages that should be protected from non-logged in users.'); ?>
6
+ </p>
7
+ <p>
8
+ <?php echo SwpmUtils::_('Next, select an existing membership level from the drop-down box below and then select posts and pages you want to grant access to (for that particular membership level).'); ?>
9
+ </p>
10
+ <p>
11
+ Read the <a href="https://simple-membership-plugin.com/apply-protection-posts-pages-bulk/" target="_blank">bulk protect posts and pages documentation</a> to learn how to use it.
12
+ </p>
13
+ </div>
14
+ <style>
15
+ #swpm-list-type-nav .nav-tab {
16
+ padding: 1px 15px;
17
+ font-size: 12px;
18
+ }
19
+ </style>
20
+ <div id="swpm-list-type-nav" class="nav-tab-wrapper">
21
+ <a class="nav-tab<?php echo $post_list->type == 'post' ? ' nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=post_list&list_type=post"><?php SwpmUtils::e('Posts'); ?></a>
22
+ <a class="nav-tab<?php echo $post_list->type == 'page' ? ' nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=post_list&list_type=page"><?php SwpmUtils::e('Pages'); ?></a>
23
+ <a class="nav-tab<?php echo $post_list->type == 'custom_post' ? ' nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=post_list&list_type=custom_post"><?php SwpmUtils::e('Custom Posts'); ?></a>
24
+ </div>
25
+ <p><form id="post_list_form" method="post">
26
+ <p class="swpm-select-box-left">
27
+ <label for="membership_level_id"><?php SwpmUtils::e('Membership Level:'); ?></label>
28
+ <select id="membership_level_id" name="membership_level_id">
29
+ <option <?php echo $post_list->selected_level_id == 1 ? "selected" : "" ?> value="1">General Protection</option>
30
+ <?php echo SwpmUtils::membership_level_dropdown($post_list->selected_level_id); ?>
31
+ </select>
32
+ </p>
33
+ <p class="swpm-select-box-left"><input type="submit" class="button-primary" name="update_post_list" value="<?php SwpmUtils::e('Update'); ?>"></p>
34
+ <?php $post_list->prepare_items(); ?>
35
+ <?php $post_list->display(); ?>
36
+ <input type="hidden" name="list_type" value="<?php echo $post_list->type; ?>">
37
+ </form></p>
38
+
39
+ <script type="text/javascript">
40
+ jQuery(document).ready(function ($) {
41
+ $('#membership_level_id').change(function () {
42
+ $('#post_list_form').submit();
43
+ });
44
+ });
45
+ </script>
views/loggedin.php CHANGED
@@ -18,7 +18,16 @@ $auth = SwpmAuth::get_instance();
18
  <div class="swpm-logged-expiry-label swpm-logged-label"><?php echo SwpmUtils::_('Account Expiry') ?></div>
19
  <div class="swpm-logged-expiry-value swpm-logged-value"><?php echo $auth->get_expire_date(); ?></div>
20
  </div>
 
 
 
 
 
 
 
 
 
21
  <div class="swpm-logged-logout-link">
22
- <a href="?swpm-logout=true"><?php echo SwpmUtils::_('Logout') ?></a>
23
  </div>
24
  </div>
18
  <div class="swpm-logged-expiry-label swpm-logged-label"><?php echo SwpmUtils::_('Account Expiry') ?></div>
19
  <div class="swpm-logged-expiry-value swpm-logged-value"><?php echo $auth->get_expire_date(); ?></div>
20
  </div>
21
+ <?php
22
+ $edit_profile_page_url = SwpmSettings::get_instance()->get_value('profile-page-url');
23
+ if (!empty($edit_profile_page_url)) {
24
+ //Show the edit profile link
25
+ echo '<div class="swpm-edit-profile-link">';
26
+ echo '<a href="'.$edit_profile_page_url.'">'.SwpmUtils::_("Edit Profile").'</a>';
27
+ echo '</div>';
28
+ }
29
+ ?>
30
  <div class="swpm-logged-logout-link">
31
+ <a href="?swpm-logout=true"><?php echo SwpmUtils::_('Logout') ?></a>
32
  </div>
33
  </div>
views/payments/admin_create_payment_buttons.php CHANGED
@@ -5,6 +5,7 @@
5
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_paypal_buy_now_button.php');
6
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_paypal_subscription_button.php');
7
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_stripe_buy_now_button.php');
 
8
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_braintree_buy_now_button.php');
9
 
10
  do_action('swpm_create_new_button_process_submission');//Addons can use this hook to save the data after the form submit then redirect to the "edit" interface of that newly created button.
@@ -29,6 +30,8 @@ if (!isset($_REQUEST['swpm_button_type_selected'])) {
29
  <br />
30
  <input type="radio" name="button_type" value="stripe_buy_now"><?php SwpmUtils::e('Stripe Buy Now'); ?>
31
  <br />
 
 
32
  <input type="radio" name="button_type" value="braintree_buy_now"><?php SwpmUtils::e('Braintree Buy Now'); ?>
33
  <br />
34
  <?php
5
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_paypal_buy_now_button.php');
6
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_paypal_subscription_button.php');
7
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_stripe_buy_now_button.php');
8
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_stripe_subscription_button.php');
9
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_braintree_buy_now_button.php');
10
 
11
  do_action('swpm_create_new_button_process_submission');//Addons can use this hook to save the data after the form submit then redirect to the "edit" interface of that newly created button.
30
  <br />
31
  <input type="radio" name="button_type" value="stripe_buy_now"><?php SwpmUtils::e('Stripe Buy Now'); ?>
32
  <br />
33
+ <input type="radio" name="button_type" value="stripe_subscription"><?php SwpmUtils::e('Stripe Subscription'); ?>
34
+ <br />
35
  <input type="radio" name="button_type" value="braintree_buy_now"><?php SwpmUtils::e('Braintree Buy Now'); ?>
36
  <br />
37
  <?php
views/payments/admin_edit_payment_buttons.php CHANGED
@@ -4,6 +4,7 @@
4
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_paypal_buy_now_button.php');
5
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_paypal_subscription_button.php');
6
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_stripe_buy_now_button.php');
 
7
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_braintree_buy_now_button.php');
8
 
9
  do_action('swpm_edit_payment_button_process_submission'); //Addons can use this hook to save the data after the form submit.
4
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_paypal_buy_now_button.php');
5
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_paypal_subscription_button.php');
6
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_stripe_buy_now_button.php');
7
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_stripe_subscription_button.php');
8
  include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/admin_braintree_buy_now_button.php');
9
 
10
  do_action('swpm_edit_payment_button_process_submission'); //Addons can use this hook to save the data after the form submit.
views/payments/payment-gateway/admin_paypal_buy_now_button.php CHANGED
@@ -109,8 +109,16 @@ function swpm_create_new_pp_buy_now_button() {
109
  <input type="text" size="100" name="button_image_url" value="" />
110
  <p class="description">If you want to customize the look of the button using an image then enter the URL of the image.</p>
111
  </td>
112
- </tr>
113
 
 
 
 
 
 
 
 
 
114
  </table>
115
 
116
  <p class="submit">
@@ -152,6 +160,7 @@ function swpm_save_new_pp_buy_now_button_data() {
152
  add_post_meta($button_id, 'return_url', trim(sanitize_text_field($_REQUEST['return_url'])));
153
  add_post_meta($button_id, 'paypal_email', trim(sanitize_email($_REQUEST['paypal_email'])));
154
  add_post_meta($button_id, 'button_image_url', trim(sanitize_text_field($_REQUEST['button_image_url'])));
 
155
 
156
  //Redirect to the edit interface of this button with $button_id
157
  //$url = admin_url() . 'admin.php?page=simple_wp_membership_payments&tab=edit_button&button_id=' . $button_id . '&button_type=' . $button_type;
@@ -187,6 +196,8 @@ function swpm_edit_pp_buy_now_button() {
187
  $return_url = get_post_meta($button_id, 'return_url', true);
188
  $paypal_email = get_post_meta($button_id, 'paypal_email', true);
189
  $button_image_url = get_post_meta($button_id, 'button_image_url', true);
 
 
190
  ?>
191
  <div class="postbox">
192
  <h3 class="hndle"><label for="title"><?php echo SwpmUtils::_('PayPal Buy Now Button Configuration'); ?></label></h3>
@@ -294,6 +305,14 @@ function swpm_edit_pp_buy_now_button() {
294
  </td>
295
  </tr>
296
 
 
 
 
 
 
 
 
 
297
  </table>
298
 
299
  <p class="submit">
@@ -336,6 +355,7 @@ function swpm_edit_pp_buy_now_button_data() {
336
  update_post_meta($button_id, 'return_url', trim(sanitize_text_field($_REQUEST['return_url'])));
337
  update_post_meta($button_id, 'paypal_email', trim(sanitize_email($_REQUEST['paypal_email'])));
338
  update_post_meta($button_id, 'button_image_url', trim(sanitize_text_field($_REQUEST['button_image_url'])));
 
339
 
340
  echo '<div id="message" class="updated fade"><p>Payment button data successfully updated!</p></div>';
341
  }
109
  <input type="text" size="100" name="button_image_url" value="" />
110
  <p class="description">If you want to customize the look of the button using an image then enter the URL of the image.</p>
111
  </td>
112
+ </tr>
113
 
114
+ <tr valign="top">
115
+ <th scope="row"><?php echo SwpmUtils::_('Custom Checkout Page Logo Image'); ?></th>
116
+ <td>
117
+ <input type="text" size="100" name="checkout_logo_image_url" value="" />
118
+ <p class="description">Specify an image URL if you want to customize the paypal checkout page with a custom logo/image. The image URL must be a "https" URL.</p>
119
+ </td>
120
+ </tr>
121
+
122
  </table>
123
 
124
  <p class="submit">
160
  add_post_meta($button_id, 'return_url', trim(sanitize_text_field($_REQUEST['return_url'])));
161
  add_post_meta($button_id, 'paypal_email', trim(sanitize_email($_REQUEST['paypal_email'])));
162
  add_post_meta($button_id, 'button_image_url', trim(sanitize_text_field($_REQUEST['button_image_url'])));
163
+ add_post_meta($button_id, 'checkout_logo_image_url', trim(sanitize_text_field($_REQUEST['checkout_logo_image_url'])));
164
 
165
  //Redirect to the edit interface of this button with $button_id
166
  //$url = admin_url() . 'admin.php?page=simple_wp_membership_payments&tab=edit_button&button_id=' . $button_id . '&button_type=' . $button_type;
196
  $return_url = get_post_meta($button_id, 'return_url', true);
197
  $paypal_email = get_post_meta($button_id, 'paypal_email', true);
198
  $button_image_url = get_post_meta($button_id, 'button_image_url', true);
199
+ $checkout_logo_image_url = get_post_meta($button_id, 'checkout_logo_image_url', true);
200
+
201
  ?>
202
  <div class="postbox">
203
  <h3 class="hndle"><label for="title"><?php echo SwpmUtils::_('PayPal Buy Now Button Configuration'); ?></label></h3>
305
  </td>
306
  </tr>
307
 
308
+ <tr valign="top">
309
+ <th scope="row"><?php echo SwpmUtils::_('Custom Checkout Page Logo Image'); ?></th>
310
+ <td>
311
+ <input type="text" size="100" name="checkout_logo_image_url" value="<?php echo $checkout_logo_image_url; ?>" />
312
+ <p class="description">Specify an image URL if you want to customize the paypal checkout page with a custom logo/image. The image URL must be a "https" URL.</p>
313
+ </td>
314
+ </tr>
315
+
316
  </table>
317
 
318
  <p class="submit">
355
  update_post_meta($button_id, 'return_url', trim(sanitize_text_field($_REQUEST['return_url'])));
356
  update_post_meta($button_id, 'paypal_email', trim(sanitize_email($_REQUEST['paypal_email'])));
357
  update_post_meta($button_id, 'button_image_url', trim(sanitize_text_field($_REQUEST['button_image_url'])));
358
+ update_post_meta($button_id, 'checkout_logo_image_url', trim(sanitize_text_field($_REQUEST['checkout_logo_image_url'])));
359
 
360
  echo '<div id="message" class="updated fade"><p>Payment button data successfully updated!</p></div>';
361
  }
views/payments/payment-gateway/admin_paypal_subscription_button.php CHANGED
@@ -183,6 +183,14 @@ function swpm_create_new_pp_subscription_button() {
183
  </td>
184
  </tr>
185
 
 
 
 
 
 
 
 
 
186
  </table>
187
  </div>
188
  </div><!-- end of optional details box -->
@@ -221,6 +229,7 @@ function swpm_save_new_pp_subscription_button_data() {
221
  add_post_meta($button_id, 'return_url', trim(sanitize_text_field($_REQUEST['return_url'])));
222
  add_post_meta($button_id, 'paypal_email', trim(sanitize_email($_REQUEST['paypal_email'])));
223
  add_post_meta($button_id, 'button_image_url', trim(sanitize_text_field($_REQUEST['button_image_url'])));
 
224
 
225
  //Subscription billing details
226
  add_post_meta($button_id, 'billing_amount', sanitize_text_field($_REQUEST['billing_amount']));
@@ -265,7 +274,8 @@ function swpm_edit_pp_subscription_button() {
265
  $return_url = get_post_meta($button_id, 'return_url', true);
266
  $paypal_email = get_post_meta($button_id, 'paypal_email', true);
267
  $button_image_url = get_post_meta($button_id, 'button_image_url', true);
268
-
 
269
  //Subscription billing details
270
  $billing_amount = get_post_meta($button_id, 'billing_amount', true);
271
  $billing_cycle = get_post_meta($button_id, 'billing_cycle', true);
@@ -454,7 +464,15 @@ function swpm_edit_pp_subscription_button() {
454
  <p class="description">If you want to customize the look of the button using an image then enter the URL of the image.</p>
455
  </td>
456
  </tr>
457
-
 
 
 
 
 
 
 
 
458
  </table>
459
  </div>
460
  </div><!-- end of optional details box -->
@@ -496,6 +514,7 @@ function swpm_edit_pp_subscription_button_data() {
496
  update_post_meta($button_id, 'return_url', trim(sanitize_text_field($_REQUEST['return_url'])));
497
  update_post_meta($button_id, 'paypal_email', trim(sanitize_email($_REQUEST['paypal_email'])));
498
  update_post_meta($button_id, 'button_image_url', trim(sanitize_text_field($_REQUEST['button_image_url'])));
 
499
 
500
  //Subscription billing details
501
  update_post_meta($button_id, 'billing_amount', sanitize_text_field($_REQUEST['billing_amount']));
183
  </td>
184
  </tr>
185
 
186
+ <tr valign="top">
187
+ <th scope="row"><?php echo SwpmUtils::_('Custom Checkout Page Logo Image'); ?></th>
188
+ <td>
189
+ <input type="text" size="100" name="checkout_logo_image_url" value="" />
190
+ <p class="description">Specify an image URL if you want to customize the paypal checkout page with a custom logo/image. The image URL must be a "https" URL.</p>
191
+ </td>
192
+ </tr>
193
+
194
  </table>
195
  </div>
196
  </div><!-- end of optional details box -->
229
  add_post_meta($button_id, 'return_url', trim(sanitize_text_field($_REQUEST['return_url'])));
230
  add_post_meta($button_id, 'paypal_email', trim(sanitize_email($_REQUEST['paypal_email'])));
231
  add_post_meta($button_id, 'button_image_url', trim(sanitize_text_field($_REQUEST['button_image_url'])));
232
+ add_post_meta($button_id, 'checkout_logo_image_url', trim(sanitize_text_field($_REQUEST['checkout_logo_image_url'])));
233
 
234
  //Subscription billing details
235
  add_post_meta($button_id, 'billing_amount', sanitize_text_field($_REQUEST['billing_amount']));
274
  $return_url = get_post_meta($button_id, 'return_url', true);
275
  $paypal_email = get_post_meta($button_id, 'paypal_email', true);
276
  $button_image_url = get_post_meta($button_id, 'button_image_url', true);
277
+ $checkout_logo_image_url = get_post_meta($button_id, 'checkout_logo_image_url', true);
278
+
279
  //Subscription billing details
280
  $billing_amount = get_post_meta($button_id, 'billing_amount', true);
281
  $billing_cycle = get_post_meta($button_id, 'billing_cycle', true);
464
  <p class="description">If you want to customize the look of the button using an image then enter the URL of the image.</p>
465
  </td>
466
  </tr>
467
+
468
+ <tr valign="top">
469
+ <th scope="row"><?php echo SwpmUtils::_('Custom Checkout Page Logo Image'); ?></th>
470
+ <td>
471
+ <input type="text" size="100" name="checkout_logo_image_url" value="<?php echo $checkout_logo_image_url; ?>" />
472
+ <p class="description">Specify an image URL if you want to customize the paypal checkout page with a custom logo/image. The image URL must be a "https" URL.</p>
473
+ </td>
474
+ </tr>
475
+
476
  </table>
477
  </div>
478
  </div><!-- end of optional details box -->
514
  update_post_meta($button_id, 'return_url', trim(sanitize_text_field($_REQUEST['return_url'])));
515
  update_post_meta($button_id, 'paypal_email', trim(sanitize_email($_REQUEST['paypal_email'])));
516
  update_post_meta($button_id, 'button_image_url', trim(sanitize_text_field($_REQUEST['button_image_url'])));
517
+ update_post_meta($button_id, 'checkout_logo_image_url', trim(sanitize_text_field($_REQUEST['checkout_logo_image_url'])));
518
 
519
  //Subscription billing details
520
  update_post_meta($button_id, 'billing_amount', sanitize_text_field($_REQUEST['billing_amount']));
views/payments/payment-gateway/admin_stripe_subscription_button.php ADDED
@@ -0,0 +1,319 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* * ***************************************************************
3
+ * Render the new Stripe Subscription payment button creation interface
4
+ * ************************************************************** */
5
+
6
+ function swpm_render_new_edit_stripe_subscription_button_interface($opts, $edit = false) {
7
+
8
+ //Test for PHP v5.4.0 or show error and don't show the remaining interface.
9
+ if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
10
+ //The server is using at least PHP version 5.4.0
11
+ //Can use Braintree gateway library
12
+ } else {
13
+ //This server can't handle Braintree library
14
+ echo '<div class="swpm-red-box">';
15
+ echo '<p>The Stripe subscription gateway library requires at least PHP 5.4.0. Your server is using a very old version of PHP.</p>';
16
+ echo '<p>Request your hosting provider to upgrade your PHP to a more recent version then you will be able to use the Stripe subscription buttons.<p>';
17
+ echo '</div>';
18
+ return;
19
+ }
20
+
21
+ function swpm_stripe_subscr_gen_curr_opts($selected = false) {
22
+ $curr_arr = array(
23
+ "USD" => "US Dollars ($)",
24
+ "EUR" => "Euros (€)",
25
+ "GBP" => "Pounds Sterling (£)",
26
+ "AUD" => "Australian Dollars ($)",
27
+ "BRL" => "Brazilian Real (R$)",
28
+ "CAD" => "Canadian Dollars ($)",
29
+ "CNY" => "Chinese Yuan",
30
+ "CZK" => "Czech Koruna",
31
+ "DKK" => "Danish Krone",
32
+ "HKD" => "Hong Kong Dollar ($)",
33
+ "HUF" => "Hungarian Forint",
34
+ "INR" => "Indian Rupee",
35
+ "IDR" => "Indonesia Rupiah",
36
+ "ILS" => "Israeli Shekel",
37
+ "JPY" => "Japanese Yen (¥)",
38
+ "MYR" => "Malaysian Ringgits",
39
+ "MXN" => "Mexican Peso ($)",
40
+ "NZD" => "New Zealand Dollar ($)",
41
+ "NOK" => "Norwegian Krone",
42
+ "PHP" => "Philippine Pesos",
43
+ "PLN" => "Polish Zloty",
44
+ "SGD" => "Singapore Dollar ($)",
45
+ "ZAR" => "South African Rand (R)",
46
+ "KRW" => "South Korean Won",
47
+ "SEK" => "Swedish Krona",
48
+ "CHF" => "Swiss Franc",
49
+ "TWD" => "Taiwan New Dollars",
50
+ "THB" => "Thai Baht",
51
+ "TRY" => "Turkish Lira",
52
+ "VND" => "Vietnamese Dong",
53
+ );
54
+ $out = '';
55
+ foreach ($curr_arr as $key => $value) {
56
+ if ($selected !== false && $selected == $key) {
57
+ $sel = ' selected';
58
+ } else {
59
+ $sel = '';
60
+ }
61
+ $out .= '<option value="' . $key . '"' . $sel . '>' . $value . '</option>';
62
+ }
63
+ return $out;
64
+ }
65
+ ?>
66
+
67
+ <div class="swpm-orange-box">
68
+ View the <a target="_blank" href="https://simple-membership-plugin.com/create-stripe-subscription-button-membership-payment/">documentation</a>&nbsp;
69
+ to learn how to create a Stripe Subscription payment button and use it.
70
+ </div>
71
+
72
+ <form id="stripe_subsciption_button_config_form" method="post">
73
+
74
+ <div class="postbox">
75
+ <h3 class="hndle"><label for="title"><?php echo SwpmUtils::_('Stripe Subscription Button Configuration'); ?></label></h3>
76
+ <div class="inside">
77
+ <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
78
+ <?php if (!$edit) { ?>
79
+ <input type="hidden" name="button_type" value="<?php echo sanitize_text_field($_REQUEST['button_type']); ?>">
80
+ <input type="hidden" name="swpm_button_type_selected" value="1">
81
+ <?php } else { ?>
82
+ <tr valign="top">
83
+ <th scope="row"><?php echo SwpmUtils::_('Button ID'); ?></th>
84
+ <td>
85
+ <input type="text" size="10" name="button_id" value="<?php echo $opts['button_id']; ?>" readonly required />
86
+ <p class="description">This is the ID of this payment button. It is automatically generated for you and it cannot be changed.</p>
87
+ </td>
88
+ </tr>
89
+ <?php } ?>
90
+ <tr valign="top">
91
+ <th scope="row"><?php echo SwpmUtils::_('Button Title'); ?></th>
92
+ <td>
93
+ <input type="text" size="50" name="button_name" value="<?php echo ($edit ? $opts['button_title'] : ''); ?>" required />
94
+ <p class="description">Give this membership payment button a name. Example: Gold membership payment</p>
95
+ </td>
96
+ </tr>
97
+
98
+ <tr valign="top">
99
+ <th scope="row"><?php echo SwpmUtils::_('Membership Level'); ?></th>
100
+ <td>
101
+ <select id="membership_level_id" name="membership_level_id">
102
+ <?php echo ($edit ? SwpmUtils::membership_level_dropdown($opts['membership_level_id'][0]) : SwpmUtils::membership_level_dropdown()); ?>
103
+ </select>
104
+ <p class="description">Select the membership level this payment button is for.</p>
105
+ </td>
106
+ </tr>
107
+
108
+ <tr valign="top">
109
+ <th scope="row"><?php echo SwpmUtils::_('Stripe Plan ID'); ?></th>
110
+ <td>
111
+ <input type="text" name="stripe_plan_id" value="<?php echo ($edit ? $opts['stripe_plan_id'][0] : ''); ?>" required />
112
+ <p class="description">
113
+ ID of the plan that you want subscribers to be assigned to. You can get more details in the
114
+ <a href="https://simple-membership-plugin.com/create-stripe-subscription-button-membership-payment/" target="_blank">documentation</a>.
115
+ </p>
116
+ </td>
117
+ </tr>
118
+
119
+ </table>
120
+
121
+ </div>
122
+ </div><!-- end of main button configuration box -->
123
+
124
+ <div class="postbox">
125
+ <h3 class="hndle"><label for="title"><?php echo SwpmUtils::_('Stripe API Settings'); ?></label></h3>
126
+ <div class="inside">
127
+
128
+ <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
129
+
130
+ <tr valign="top">
131
+ <th scope="row"><?php echo SwpmUtils::_('Test Publishable Key'); ?></th>
132
+ <td>
133
+ <input type="text" size="100" name="stripe_test_publishable_key" value="<?php echo ($edit ? $opts['stripe_test_publishable_key'][0] : ''); ?>" />
134
+ <p class="description">Enter your Stripe test publishable key.</p>
135
+ </td>
136
+ </tr>
137
+
138
+ <tr valign="top">
139
+ <th scope="row"><?php echo SwpmUtils::_('Test Secret Key'); ?></th>
140
+ <td>
141
+ <input type="text" size="100" name="stripe_test_secret_key" value="<?php echo ($edit ? $opts['stripe_test_secret_key'][0] : ''); ?>" />
142
+ <p class="description">Enter your Stripe test secret key.</p>
143
+ </td>
144
+ </tr>
145
+
146
+ <tr valign="top">
147
+ <th scope="row"><?php echo SwpmUtils::_('Live Publishable Key'); ?></th>
148
+ <td>
149
+ <input type="text" size="100" name="stripe_live_publishable_key" value="<?php echo ($edit ? $opts['stripe_live_publishable_key'][0] : ''); ?>" />
150
+ <p class="description">Enter your Stripe live publishable key.</p>
151
+ </td>
152
+ </tr>
153
+
154
+ <tr valign="top">
155
+ <th scope="row"><?php echo SwpmUtils::_('Live Secret Key'); ?></th>
156
+ <td>
157
+ <input type="text" size="100" name="stripe_live_secret_key" value="<?php echo ($edit ? $opts['stripe_live_secret_key'][0] : ''); ?>" />
158
+ <p class="description">Enter your Stripe live secret key.</p>
159
+ </td>
160
+ </tr>
161
+
162
+ <tr valign="top">
163
+ <th scope="row"><?php echo SwpmUtils::_('Webook Endpoint URL'); ?></th>
164
+ <td>
165
+ <kbd><?php echo SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL . '/?swpm_process_stripe_subscription=1&hook=1'; ?></kbd>
166
+ <p class="description">You should create a new Webhook in your Stripe account and put this URL there if you want the plugin to handle subscription expiration automatically.<br />
167
+ You can get more info in the <a href="https://simple-membership-plugin.com/create-stripe-subscription-button-membership-payment/" target="_blank">documentation</a>.
168
+ </p>
169
+ </td>
170
+ </tr>
171
+
172
+ </table>
173
+ </div>
174
+ </div><!-- end of Stripe API Keys box -->
175
+
176
+ <div class="postbox">
177
+ <h3 class="hndle"><label for="title"><?php echo SwpmUtils::_('Optional Details'); ?></label></h3>
178
+ <div class="inside">
179
+
180
+ <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
181
+
182
+ <tr valign="top">
183
+ <th scope="row"><?php echo SwpmUtils::_('Return URL'); ?></th>
184
+ <td>
185
+ <input type="text" size="100" name="return_url" value="" />
186
+ <p class="description">This is the URL the user will be redirected to after a successful payment. Enter the URL of your Thank You page here.</p>
187
+ </td>
188
+ </tr>
189
+
190
+ <tr valign="top">
191
+ <th scope="row"><?php echo SwpmUtils::_('Button Image URL'); ?></th>
192
+ <td>
193
+ <input type="text" size="100" name="button_image_url" value="" />
194
+ <p class="description">If you want to customize the look of the button using an image then enter the URL of the image.</p>
195
+ </td>
196
+ </tr>
197
+
198
+ </table>
199
+ </div>
200
+ </div><!-- end of optional details box -->
201
+
202
+ <p class="submit">
203
+ <input type="submit" name="swpm_stripe_subscription_<?php echo ($edit ? 'edit' : 'save'); ?>_submit" class="button-primary" value="<?php echo SwpmUtils::_('Save Payment Data'); ?>" >
204
+ </p>
205
+
206
+ </form>
207
+
208
+ <?php
209
+ }
210
+
211
+ add_action('swpm_create_new_button_for_stripe_subscription', 'swpm_create_new_stripe_subscription_button');
212
+
213
+ function swpm_create_new_stripe_subscription_button() {
214
+ swpm_render_new_edit_stripe_subscription_button_interface('');
215
+ }
216
+
217
+ add_action('swpm_edit_payment_button_for_stripe_subscription', 'swpm_edit_stripe_subscription_button');
218
+
219
+ function swpm_edit_stripe_subscription_button() {
220
+ //Retrieve the payment button data and present it for editing.
221
+
222
+ $button_id = sanitize_text_field($_REQUEST['button_id']);
223
+ $button_id = absint($button_id);
224
+
225
+ $button = get_post($button_id); //Retrieve the CPT for this button
226
+
227
+ $post_meta = get_post_meta($button_id);
228
+ $post_meta['button_title'] = $button->post_title;
229
+ $post_meta['button_id'] = $button_id;
230
+
231
+ swpm_render_new_edit_stripe_subscription_button_interface($post_meta, true);
232
+ }
233
+
234
+ /*
235
+ * Process submission and save the new PayPal Subscription payment button data
236
+ */
237
+ add_action('swpm_create_new_button_process_submission', 'swpm_save_edit_stripe_subscription_button_data');
238
+ add_action('swpm_edit_payment_button_process_submission', 'swpm_save_edit_stripe_subscription_button_data');
239
+
240
+ function swpm_save_edit_stripe_subscription_button_data() {
241
+ if (isset($_REQUEST['swpm_stripe_subscription_save_submit'])) {
242
+ $edit = false;
243
+ }
244
+ if (isset($_REQUEST['swpm_stripe_subscription_edit_submit'])) {
245
+ $edit = true;
246
+ }
247
+ if (isset($edit)) {
248
+ //This is a Stripe subscription button save or edit event. Process the submission.
249
+ if ($edit) {
250
+ $button_id = sanitize_text_field($_REQUEST['button_id']);
251
+ $button_id = absint($button_id);
252
+ $button_type = sanitize_text_field($_REQUEST['button_type']);
253
+ $button_name = sanitize_text_field($_REQUEST['button_name']);
254
+
255
+ $button_post = array(
256
+ 'ID' => $button_id,
257
+ 'post_title' => $button_name,
258
+ 'post_type' => 'swpm_payment_button',
259
+ );
260
+ wp_update_post($button_post);
261
+ } else {
262
+ $button_id = wp_insert_post(
263
+ array(
264
+ 'post_title' => sanitize_text_field($_REQUEST['button_name']),
265
+ 'post_type' => 'swpm_payment_button',
266
+ 'post_content' => '',
267
+ 'post_status' => 'publish'
268
+ )
269
+ );
270
+ $button_type = sanitize_text_field($_REQUEST['button_type']);
271
+ }
272
+
273
+ update_post_meta($button_id, 'button_type', $button_type);
274
+ update_post_meta($button_id, 'membership_level_id', sanitize_text_field($_REQUEST['membership_level_id']));
275
+ update_post_meta($button_id, 'return_url', trim(sanitize_text_field($_REQUEST['return_url'])));
276
+ update_post_meta($button_id, 'button_image_url', trim(sanitize_text_field($_REQUEST['button_image_url'])));
277
+
278
+ if ($edit) {
279
+ // let's see if Stripe details (plan ID and Secret Key) are valid
280
+ $stripe_error_msg = '';
281
+ $settings = SwpmSettings::get_instance();
282
+ $sandbox_enabled = $settings->get_value('enable-sandbox-testing');
283
+ if ($sandbox_enabled) {
284
+ $secret_key = sanitize_text_field($_REQUEST['stripe_test_secret_key']);
285
+ } else {
286
+ $secret_key = sanitize_text_field($_REQUEST['stripe_live_secret_key']);
287
+ }
288
+
289
+ require_once(SIMPLE_WP_MEMBERSHIP_PATH . 'lib/stripe-util-functions.php');
290
+ $result = StripeUtilFunctions::get_stripe_plan_info($secret_key, sanitize_text_field($_REQUEST['stripe_plan_id']));
291
+ if ($result['success']) {
292
+ $plan_data = $result['plan_data'];
293
+ } else {
294
+ $stripe_error_msg = $result['error_msg'];
295
+ }
296
+ }
297
+ //API details
298
+ update_post_meta($button_id, 'stripe_test_secret_key', sanitize_text_field($_REQUEST['stripe_test_secret_key']));
299
+ update_post_meta($button_id, 'stripe_test_publishable_key', sanitize_text_field($_REQUEST['stripe_test_publishable_key']));
300
+ update_post_meta($button_id, 'stripe_live_secret_key', sanitize_text_field($_REQUEST['stripe_live_secret_key']));
301
+ update_post_meta($button_id, 'stripe_live_publishable_key', sanitize_text_field($_REQUEST['stripe_live_publishable_key']));
302
+
303
+ //Subscription billing details
304
+ update_post_meta($button_id, 'stripe_plan_id', sanitize_text_field($_REQUEST['stripe_plan_id']));
305
+ update_post_meta($button_id, 'stripe_plan_data', (isset($plan_data) ? $plan_data : false));
306
+
307
+ if ($edit) {
308
+ if (empty($stripe_error_msg)) {
309
+ echo '<div id="message" class="updated fade"><p>Payment button data successfully updated!</p></div>';
310
+ } else {
311
+ echo '<div id="message" class="error"><p>' . $stripe_error_msg . '</p></div>';
312
+ }
313
+ } else {
314
+ //Redirect to the edit interface of this button with $button_id
315
+ $url = admin_url() . 'admin.php?page=simple_wp_membership_payments&tab=edit_button&button_id=' . $button_id . '&button_type=' . $button_type;
316
+ SwpmMiscUtils::redirect_to_url($url);
317
+ }
318
+ }
319
+ }
views/payments/payment-gateway/paypal_button_shortcode_view.php CHANGED
@@ -78,6 +78,11 @@ function swpm_render_pp_buy_now_button_sc_output($button_code, $args) {
78
  $custom_field_value = urlencode($custom_field_value);//URL encode the custom field value so nothing gets lost when it is passed around.
79
  $output .= '<input type="hidden" name="custom" value="' . $custom_field_value . '" />';
80
 
 
 
 
 
 
81
  //Filter to add additional payment input fields to the form (example: langauge code or country code etc).
82
  $output .= apply_filters('swpm_pp_payment_form_additional_fields', '');
83
 
@@ -207,6 +212,11 @@ function swpm_render_pp_subscription_button_sc_output($button_code, $args) {
207
  $custom_field_value = urlencode($custom_field_value);//URL encode the custom field value so nothing gets lost when it is passed around.
208
  $output .= '<input type="hidden" name="custom" value="' . $custom_field_value . '" />';
209
 
 
 
 
 
 
210
  //Filter to add additional payment input fields to the form (example: langauge code or country code etc).
211
  $output .= apply_filters('swpm_pp_payment_form_additional_fields', '');
212
 
78
  $custom_field_value = urlencode($custom_field_value);//URL encode the custom field value so nothing gets lost when it is passed around.
79
  $output .= '<input type="hidden" name="custom" value="' . $custom_field_value . '" />';
80
 
81
+ $checkout_logo_image_url = get_post_meta($button_id, 'checkout_logo_image_url', true);
82
+ if (!empty($checkout_logo_image_url)) {
83
+ $output .= '<input type="hidden" name="image_url" value="' . $checkout_logo_image_url . '" />';
84
+ }
85
+
86
  //Filter to add additional payment input fields to the form (example: langauge code or country code etc).
87
  $output .= apply_filters('swpm_pp_payment_form_additional_fields', '');
88
 
212
  $custom_field_value = urlencode($custom_field_value);//URL encode the custom field value so nothing gets lost when it is passed around.
213
  $output .= '<input type="hidden" name="custom" value="' . $custom_field_value . '" />';
214
 
215
+ $checkout_logo_image_url = get_post_meta($button_id, 'checkout_logo_image_url', true);
216
+ if (!empty($checkout_logo_image_url)) {
217
+ $output .= '<input type="hidden" name="image_url" value="' . $checkout_logo_image_url . '" />';
218
+ }
219
+
220
  //Filter to add additional payment input fields to the form (example: langauge code or country code etc).
221
  $output .= apply_filters('swpm_pp_payment_form_additional_fields', '');
222
 
views/payments/payment-gateway/stripe_button_shortcode_view.php CHANGED
@@ -118,3 +118,154 @@ function swpm_render_stripe_buy_now_button_sc_output($button_code, $args) {
118
 
119
  return $output;
120
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  return $output;
120
  }
121
+
122
+ add_filter('swpm_payment_button_shortcode_for_stripe_subscription', 'swpm_render_stripe_subscription_button_sc_output', 10, 2);
123
+
124
+ function swpm_render_stripe_subscription_button_sc_output($button_code, $args) {
125
+
126
+ $button_id = isset($args['id']) ? $args['id'] : '';
127
+ if (empty($button_id)) {
128
+ return '<p class="swpm-red-box">Error! swpm_render_stripe_buy_now_button_sc_output() function requires the button ID value to be passed to it.</p>';
129
+ }
130
+
131
+ //Get class option for button styling, set Stripe's default if none specified
132
+ $class = isset($args['class']) ? $args['class'] : 'stripe-button-el';
133
+
134
+ //Check new_window parameter
135
+ $window_target = isset($args['new_window']) ? 'target="_blank"' : '';
136
+ $button_text = (isset($args['button_text'])) ? $args['button_text'] : SwpmUtils::_('Buy Now');
137
+ $billing_address = isset($args['billing_address']) ? '1' : '';
138
+ ; //By default don't show the billing address in the checkout form.
139
+ $item_logo = ''; //Can be used to show an item logo or thumbnail in the checkout form.
140
+
141
+ $settings = SwpmSettings::get_instance();
142
+ $button_cpt = get_post($button_id); //Retrieve the CPT for this button
143
+ $item_name = htmlspecialchars($button_cpt->post_title);
144
+
145
+ $membership_level_id = get_post_meta($button_id, 'membership_level_id', true);
146
+ //Verify that this membership level exists (to prevent user paying for a level that has been deleted)
147
+ if (!SwpmUtils::membership_level_id_exists($membership_level_id)) {
148
+ return '<p class="swpm-red-box">Error! The membership level specified in this button does not exist. You may have deleted this membership level. Edit the button and use the correct membership level.</p>';
149
+ }
150
+
151
+ //Return, cancel, notifiy URLs
152
+ $return_url = get_post_meta($button_id, 'return_url', true);
153
+ if (empty($return_url)) {
154
+ $return_url = SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL;
155
+ }
156
+ $notify_url = SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL . '/?swpm_process_stripe_subscription=1'; //We are going to use it to do post payment processing.
157
+ //$button_image_url = get_post_meta($button_id, 'button_image_url', true);//Stripe doesn't currenty support button image for their standard checkout.
158
+ //User's IP address
159
+ $user_ip = SwpmUtils::get_user_ip_address();
160
+ $_SESSION['swpm_payment_button_interaction'] = $user_ip;
161
+
162
+ //Custom field data
163
+ $custom_field_value = 'subsc_ref=' . $membership_level_id;
164
+ $custom_field_value .= '&user_ip=' . $user_ip;
165
+ if (SwpmMemberUtils::is_member_logged_in()) {
166
+ $custom_field_value .= '&swpm_id=' . SwpmMemberUtils::get_logged_in_members_id();
167
+ }
168
+ $custom_field_value = apply_filters('swpm_custom_field_value_filter', $custom_field_value);
169
+
170
+ //Sandbox settings
171
+ $sandbox_enabled = $settings->get_value('enable-sandbox-testing');
172
+
173
+ //API keys
174
+ $stripe_test_secret_key = get_post_meta($button_id, 'stripe_test_secret_key', true);
175
+ $stripe_test_publishable_key = get_post_meta($button_id, 'stripe_test_publishable_key', true);
176
+ $stripe_live_secret_key = get_post_meta($button_id, 'stripe_live_secret_key', true);
177
+ $stripe_live_publishable_key = get_post_meta($button_id, 'stripe_live_publishable_key', true);
178
+ if ($sandbox_enabled) {
179
+ $secret_key = $stripe_test_secret_key;
180
+ $publishable_key = $stripe_test_publishable_key; //Use sandbox API key
181
+ } else {
182
+ $secret_key = $stripe_live_secret_key;
183
+ $publishable_key = $stripe_live_publishable_key; //Use live API key
184
+ }
185
+
186
+ $plan_id = get_post_meta($button_id, 'stripe_plan_id', true);
187
+
188
+ $plan_data = get_post_meta($button_id, 'stripe_plan_data', true);
189
+
190
+ if (empty($plan_data)) {
191
+ //no plan data available, let's try to request one
192
+
193
+ if (version_compare(PHP_VERSION, '5.4.0', '<')) {
194
+ //This server's PHP version can't handle the library.
195
+ $error_msg = '<div class="swpm-red-box">';
196
+ $error_msg .= '<p>The Stripe Subscription payment gateway library requires at least PHP 5.4.0. Your server is using a very old version of PHP.</p>';
197
+ $error_msg .= '<p>Request your hosting provider to upgrade your PHP to a more recent version then you will be able to use the Stripe Subscription.<p>';
198
+ $error_msg .= '</div>';
199
+ return $error_msg;
200
+ }
201
+
202
+ require_once(SIMPLE_WP_MEMBERSHIP_PATH . 'lib/stripe-util-functions.php');
203
+ $result = StripeUtilFunctions::get_stripe_plan_info($secret_key, $plan_id);
204
+ if ($result['success'] === false) {
205
+ // some error occured, let's display it and stop processing the shortcode further
206
+ return '<p class="swpm-red-box">Stripe error occured: ' . $result['error_msg'] . '</p>';
207
+ } else {
208
+ // plan data has been successfully retreived
209
+ $plan_data = $result['plan_data'];
210
+ // Let's update post_meta in order to not re-request the data again on each button display
211
+ update_post_meta($button_id, 'stripe_plan_data', $plan_data);
212
+ }
213
+ }
214
+
215
+ //let's set some vars
216
+ $price_in_cents = $plan_data['amount'];
217
+ $payment_amount = $price_in_cents / 100;
218
+ $payment_currency = $plan_data['currency'];
219
+ $interval_count = $plan_data['interval_count'];
220
+ $interval = $plan_data['interval'];
221
+ $trial = $plan_data['trial_period_days'];
222
+ $plan_name = $plan_data['name'];
223
+ $description = $payment_amount . ' ' . strtoupper($payment_currency);
224
+ if ($interval_count == 1) {
225
+ $description .= ' / ' . $interval;
226
+ } else {
227
+ $description .= ' every ' . $plan_data['interval_count'] . ' ' . $plan_data['interval'] . 's';
228
+ }
229
+ // this should add info on trial period if available, but Stripe strips too long strings, so we leave it commented out for now.
230
+ // if ($trial != NULL) {
231
+ // $description .= '. '.$trial . ' days FREE trial.';
232
+ // }
233
+
234
+ /* === Stripe Buy Now Button Form === */
235
+ $output = '';
236
+ $output .= '<div class="swpm-button-wrapper swpm-stripe-buy-now-wrapper">';
237
+ $output .= "<form action='" . $notify_url . "' METHOD='POST'> ";
238
+ $output .= "<div style='display: none !important'>";
239
+ $output .= "<script src='https://checkout.stripe.com/checkout.js' class='stripe-button'
240
+ data-key='" . $publishable_key . "'
241
+ data-panel-label='Sign Me Up!'
242
+ data-name='{$item_name}'";
243
+ $output .= "data-description='{$description}'";
244
+ $output .= "data-label='{$button_text}'"; //Stripe doesn't currenty support button image for their standard checkout.
245
+ $output .= "data-currency='{$payment_currency}'";
246
+ if (!empty($item_logo)) {//Show item logo/thumbnail in the stripe payment window
247
+ $output .= "data-image='{$item_logo}'";
248
+ }
249
+ if (!empty($billing_address)) {//Show billing address in the stipe payment window
250
+ $output .= "data-billingAddress='true'";
251
+ }
252
+ $output .= apply_filters('swpm_stripe_additional_checkout_data_parameters', ''); //Filter to allow the addition of extra data parameters for stripe checkout.
253
+ $output .= "></script>";
254
+ $output .= '</div>';
255
+ $output .= "<button id='{$button_id}' type='submit' class='{$class}'><span>{$button_text}</span></button>";
256
+
257
+ $output .= wp_nonce_field('stripe_payments', '_wpnonce', true, false);
258
+ $output .= '<input type="hidden" name="item_number" value="' . $button_id . '" />';
259
+ $output .= "<input type='hidden' value='{$item_name}' name='item_name' />";
260
+ $output .= "<input type='hidden' value='{$payment_amount}' name='item_price' />";
261
+ $output .= "<input type='hidden' value='{$payment_currency}' name='currency_code' />";
262
+ $output .= "<input type='hidden' value='{$custom_field_value}' name='custom' />";
263
+
264
+ //Filter to add additional payment input fields to the form.
265
+ $output .= apply_filters('swpm_stripe_payment_form_additional_fields', '');
266
+
267
+ $output .= "</form>";
268
+ $output .= '</div>'; //End .swpm_button_wrapper
269
+
270
+ return $output;
271
+ }