Version Description
- Commented out call to date_default_timezone_set() function for WP5.3.
- Updated some comments in the SwpmAjax class.
- Added an extra content protection check for post preview URL.
Download this release
Release Info
Developer | mra13 |
Plugin | Simple Membership |
Version | 3.9.4 |
Comparing to | |
See all releases |
Code changes from version 3.9.2 to 3.9.4
- classes/class.simple-wp-membership.php +5 -2
- classes/class.swpm-admin-registration.php +170 -145
- classes/class.swpm-ajax.php +4 -3
- classes/class.swpm-auth.php +393 -430
- classes/class.swpm-front-registration.php +500 -449
- classes/class.swpm-init-time-tasks.php +212 -209
- classes/class.swpm-members.php +761 -669
- classes/class.swpm-registration.php +110 -103
- classes/class.swpm-settings.php +1147 -605
- classes/class.swpm-transactions.php +82 -74
- classes/class.swpm-utils-misc.php +735 -508
- classes/class.swpm-utils.php +518 -511
- classes/class.swpm-wp-loaded-tasks.php +1 -0
- classes/shortcode-related/class.swpm-shortcodes-handler.php +50 -0
- ipn/swpm-stripe-sca-subscription-ipn.php +8 -2
- ipn/swpm-stripe-subscription-ipn.php +41 -10
- ipn/swpm_handle_subsc_ipn.php +36 -31
- lib/braintree/lib/Braintree/WebhookTestingGateway.php +4 -4
- readme.txt +11 -1
- simple-wp-membership.php +2 -2
classes/class.simple-wp-membership.php
CHANGED
@@ -612,8 +612,11 @@ class SimpleWpMembership {
|
|
612 |
|
613 |
public function filter_content($content) {
|
614 |
if (is_preview() || is_admin()) {
|
615 |
-
//
|
616 |
-
|
|
|
|
|
|
|
617 |
}
|
618 |
$acl = SwpmAccessControl::get_instance();
|
619 |
global $post;
|
612 |
|
613 |
public function filter_content($content) {
|
614 |
if (is_preview() || is_admin()) {
|
615 |
+
//If the user is logged-in as an admin user then do not apply filtering for admin side viewing or preview page viewing.
|
616 |
+
if ( current_user_can('administrator') ){
|
617 |
+
//The user is logged in as admin in this browser.
|
618 |
+
return $content;
|
619 |
+
}
|
620 |
}
|
621 |
$acl = SwpmAccessControl::get_instance();
|
622 |
global $post;
|
classes/class.swpm-admin-registration.php
CHANGED
@@ -6,150 +6,175 @@
|
|
6 |
*/
|
7 |
class SwpmAdminRegistration extends SwpmRegistration {
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
}
|
6 |
*/
|
7 |
class SwpmAdminRegistration extends SwpmRegistration {
|
8 |
|
9 |
+
public static function get_instance() {
|
10 |
+
self::$_intance = empty( self::$_intance ) ? new SwpmAdminRegistration() : self::$_intance;
|
11 |
+
return self::$_intance;
|
12 |
+
}
|
13 |
+
|
14 |
+
public function show_form() {
|
15 |
+
|
16 |
+
}
|
17 |
+
|
18 |
+
public function register_admin_end() {
|
19 |
+
//Check we are on the admin end and user has management permission
|
20 |
+
SwpmMiscUtils::check_user_permission_and_is_admin( 'member creation by admin' );
|
21 |
+
|
22 |
+
//Check nonce
|
23 |
+
if ( ! isset( $_POST['_wpnonce_create_swpmuser_admin_end'] ) || ! wp_verify_nonce( $_POST['_wpnonce_create_swpmuser_admin_end'], 'create_swpmuser_admin_end' ) ) {
|
24 |
+
//Nonce check failed.
|
25 |
+
wp_die( SwpmUtils::_( 'Error! Nonce verification failed for user registration from admin end.' ) );
|
26 |
+
}
|
27 |
+
|
28 |
+
global $wpdb;
|
29 |
+
$member = SwpmTransfer::$default_fields;
|
30 |
+
$form = new SwpmForm( $member );
|
31 |
+
if ( $form->is_valid() ) {
|
32 |
+
$member_info = $form->get_sanitized_member_form_data();
|
33 |
+
$account_status = SwpmSettings::get_instance()->get_value( 'default-account-status', 'active' );
|
34 |
+
$member_info['account_state'] = $account_status;
|
35 |
+
$plain_password = $member_info['plain_password'];
|
36 |
+
unset( $member_info['plain_password'] );
|
37 |
+
$wpdb->insert( $wpdb->prefix . 'swpm_members_tbl', $member_info );
|
38 |
+
|
39 |
+
//Register to WordPress
|
40 |
+
$query = $wpdb->prepare( 'SELECT role FROM ' . $wpdb->prefix . 'swpm_membership_tbl WHERE id = %d', $member_info['membership_level'] );
|
41 |
+
$wp_user_info = array();
|
42 |
+
$wp_user_info['user_nicename'] = implode( '-', explode( ' ', $member_info['user_name'] ) );
|
43 |
+
$wp_user_info['display_name'] = $member_info['user_name'];
|
44 |
+
$wp_user_info['user_email'] = $member_info['email'];
|
45 |
+
$wp_user_info['nickname'] = $member_info['user_name'];
|
46 |
+
if ( isset( $member_info['first_name'] ) ) {
|
47 |
+
$wp_user_info['first_name'] = $member_info['first_name'];
|
48 |
+
}
|
49 |
+
if ( isset( $member_info['last_name'] ) ) {
|
50 |
+
$wp_user_info['last_name'] = $member_info['last_name'];
|
51 |
+
}
|
52 |
+
$wp_user_info['user_login'] = $member_info['user_name'];
|
53 |
+
$wp_user_info['password'] = $plain_password;
|
54 |
+
$wp_user_info['role'] = $wpdb->get_var( $query );
|
55 |
+
$wp_user_info['user_registered'] = date( 'Y-m-d H:i:s' );
|
56 |
+
SwpmUtils::create_wp_user( $wp_user_info );
|
57 |
+
//End register to WordPress
|
58 |
+
|
59 |
+
//Send notification
|
60 |
+
$send_notification = SwpmSettings::get_instance()->get_value( 'enable-notification-after-manual-user-add' );
|
61 |
+
$member_info['plain_password'] = $plain_password;
|
62 |
+
$this->member_info = $member_info;
|
63 |
+
if ( ! empty( $send_notification ) ) {
|
64 |
+
$this->send_reg_email();
|
65 |
+
}
|
66 |
+
|
67 |
+
//Trigger action hook
|
68 |
+
do_action( 'swpm_admin_end_registration_complete_user_data', $member_info );
|
69 |
+
|
70 |
+
//Save success message
|
71 |
+
$message = array(
|
72 |
+
'succeeded' => true,
|
73 |
+
'message' => '<p>' . SwpmUtils::_( 'Member record added successfully.' ) . '</p>',
|
74 |
+
);
|
75 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
76 |
+
wp_redirect( 'admin.php?page=simple_wp_membership' );
|
77 |
+
exit( 0 );
|
78 |
+
}
|
79 |
+
$message = array(
|
80 |
+
'succeeded' => false,
|
81 |
+
'message' => SwpmUtils::_( 'Please correct the following:' ),
|
82 |
+
'extra' => $form->get_errors(),
|
83 |
+
);
|
84 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
85 |
+
}
|
86 |
+
|
87 |
+
public function edit_admin_end( $id ) {
|
88 |
+
//Check we are on the admin end and user has management permission
|
89 |
+
SwpmMiscUtils::check_user_permission_and_is_admin( 'member edit by admin' );
|
90 |
+
|
91 |
+
//Check nonce
|
92 |
+
if ( ! isset( $_POST['_wpnonce_edit_swpmuser_admin_end'] ) || ! wp_verify_nonce( $_POST['_wpnonce_edit_swpmuser_admin_end'], 'edit_swpmuser_admin_end' ) ) {
|
93 |
+
//Nonce check failed.
|
94 |
+
wp_die( SwpmUtils::_( 'Error! Nonce verification failed for user edit from admin end.' ) );
|
95 |
+
}
|
96 |
+
|
97 |
+
global $wpdb;
|
98 |
+
$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'swpm_members_tbl WHERE member_id = %d', $id );
|
99 |
+
$member = $wpdb->get_row( $query, ARRAY_A );
|
100 |
+
// let's get previous membership level
|
101 |
+
$prev_level = false;
|
102 |
+
if ( $member ) {
|
103 |
+
$prev_level = $member['membership_level'];
|
104 |
+
}
|
105 |
+
$email_address = $member['email'];
|
106 |
+
$user_name = $member['user_name'];
|
107 |
+
unset( $member['member_id'] );
|
108 |
+
unset( $member['user_name'] );
|
109 |
+
$form = new SwpmForm( $member );
|
110 |
+
if ( $form->is_valid() ) {
|
111 |
+
$member = $form->get_sanitized_member_form_data();
|
112 |
+
$plain_password = isset( $member['plain_password'] ) ? $member['plain_password'] : '';
|
113 |
+
SwpmUtils::update_wp_user( $user_name, $member );
|
114 |
+
unset( $member['plain_password'] );
|
115 |
+
$wpdb->update( $wpdb->prefix . 'swpm_members_tbl', $member, array( 'member_id' => $id ) );
|
116 |
+
// set previous membership level
|
117 |
+
$member['prev_membership_level'] = $prev_level;
|
118 |
+
$member['member_id'] = $id;
|
119 |
+
|
120 |
+
//Trigger action hook
|
121 |
+
do_action( 'swpm_admin_end_edit_complete_user_data', $member );
|
122 |
+
|
123 |
+
if ( $member['prev_membership_level'] != $member['membership_level'] ) {
|
124 |
+
do_action(
|
125 |
+
'swpm_membership_level_changed',
|
126 |
+
array(
|
127 |
+
'member_id' => $id,
|
128 |
+
'from_level' => $member['prev_membership_level'],
|
129 |
+
'to_level' => $member['membership_level'],
|
130 |
+
)
|
131 |
+
);
|
132 |
+
}
|
133 |
+
|
134 |
+
//Set messages
|
135 |
+
$message = array(
|
136 |
+
'succeeded' => true,
|
137 |
+
'message' => '<p>Member profile updated successfully.</p>',
|
138 |
+
);
|
139 |
+
$error = apply_filters( 'swpm_admin_edit_custom_fields', array(), $member + array( 'member_id' => $id ) );
|
140 |
+
if ( ! empty( $error ) ) {
|
141 |
+
$message = array(
|
142 |
+
'succeeded' => false,
|
143 |
+
'message' => SwpmUtils::_( 'Please correct the following:' ),
|
144 |
+
'extra' => $error,
|
145 |
+
);
|
146 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
147 |
+
return;
|
148 |
+
}
|
149 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
150 |
+
$send_notification = filter_input( INPUT_POST, 'account_status_change' );
|
151 |
+
if ( ! empty( $send_notification ) ) {
|
152 |
+
$settings = SwpmSettings::get_instance();
|
153 |
+
$from_address = $settings->get_value( 'email-from' );
|
154 |
+
$headers = 'From: ' . $from_address . "\r\n";
|
155 |
+
$subject = filter_input( INPUT_POST, 'notificationmailhead' );
|
156 |
+
$body = filter_input( INPUT_POST, 'notificationmailbody' );
|
157 |
+
$settings->set_value( 'account-change-email-body', $body )->set_value( 'account-change-email-subject', $subject )->save();
|
158 |
+
$member['login_link'] = $settings->get_value( 'login-page-url' );
|
159 |
+
$member['user_name'] = $user_name;
|
160 |
+
$member['password'] = empty( $plain_password ) ? SwpmUtils::_( 'Your current password' ) : $plain_password;
|
161 |
+
$values = array_values( $member );
|
162 |
+
$keys = array_map( 'swpm_enclose_var', array_keys( $member ) );
|
163 |
+
$body = html_entity_decode( str_replace( $keys, $values, $body ) );
|
164 |
+
$subject = apply_filters( 'swpm_email_account_status_change_subject', $subject );
|
165 |
+
$body = apply_filters( 'swpm_email_account_status_change_body', $body );
|
166 |
+
SwpmMiscUtils::mail( $email_address, $subject, $body, $headers );
|
167 |
+
SwpmLog::log_simple_debug( 'Notify email sent (after profile edit from admin side). Email sent to: ' . $email_address, true );
|
168 |
+
}
|
169 |
+
wp_redirect( 'admin.php?page=simple_wp_membership' );
|
170 |
+
exit( 0 );
|
171 |
+
}
|
172 |
+
$message = array(
|
173 |
+
'succeeded' => false,
|
174 |
+
'message' => SwpmUtils::_( 'Please correct the following:' ),
|
175 |
+
'extra' => $form->get_errors(),
|
176 |
+
);
|
177 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
178 |
+
}
|
179 |
|
180 |
}
|
classes/class.swpm-ajax.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
*
|
4 |
-
*
|
5 |
-
* @author nur
|
6 |
*/
|
|
|
7 |
class SwpmAjax {
|
|
|
8 |
public static function validate_email_ajax() {
|
9 |
global $wpdb;
|
10 |
$field_value = filter_input(INPUT_GET, 'fieldValue');
|
@@ -45,4 +45,5 @@ class SwpmAjax {
|
|
45 |
'",true,"√ '.SwpmUtils::_('Available'). '"]');
|
46 |
exit;
|
47 |
}
|
|
|
48 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Handles various AJAX calls
|
|
|
|
|
4 |
*/
|
5 |
+
|
6 |
class SwpmAjax {
|
7 |
+
|
8 |
public static function validate_email_ajax() {
|
9 |
global $wpdb;
|
10 |
$field_value = filter_input(INPUT_GET, 'fieldValue');
|
45 |
'",true,"√ '.SwpmUtils::_('Available'). '"]');
|
46 |
exit;
|
47 |
}
|
48 |
+
|
49 |
}
|
classes/class.swpm-auth.php
CHANGED
@@ -2,435 +2,398 @@
|
|
2 |
|
3 |
class SwpmAuth {
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
$error = $body['error'];
|
399 |
-
$error_string = print_r($error, true);
|
400 |
-
SwpmLog::log_simple_debug("Error details: " . $error_string, false);
|
401 |
-
}
|
402 |
-
if (!isset($error)) {
|
403 |
-
SwpmLog::log_simple_debug("Stripe Subscription has been cancelled.", true);
|
404 |
-
}
|
405 |
-
}
|
406 |
-
}
|
407 |
-
}
|
408 |
-
|
409 |
-
wp_clear_auth_cookie();
|
410 |
-
$this->logout();
|
411 |
-
SwpmMembers::delete_swpm_user_by_id($user_id);
|
412 |
-
SwpmMembers::delete_wp_user($user_name);
|
413 |
-
}
|
414 |
-
|
415 |
-
public function reload_user_data() {
|
416 |
-
if (!$this->is_logged_in()) {
|
417 |
-
return;
|
418 |
-
}
|
419 |
-
global $wpdb;
|
420 |
-
$query = "SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE member_id = %d";
|
421 |
-
$this->userData = $wpdb->get_row($wpdb->prepare($query, $this->userData->member_id));
|
422 |
-
}
|
423 |
-
|
424 |
-
public function is_expired_account() {
|
425 |
-
if (!$this->is_logged_in()) {
|
426 |
-
return null;
|
427 |
-
}
|
428 |
-
$account_status = $this->get('account_state');
|
429 |
-
if ($account_status == 'expired' || $account_status == 'inactive') {
|
430 |
-
//Expired or Inactive accounts are both considered to be expired.
|
431 |
-
return true;
|
432 |
-
}
|
433 |
-
return false;
|
434 |
-
}
|
435 |
|
436 |
}
|
2 |
|
3 |
class SwpmAuth {
|
4 |
|
5 |
+
public $protected;
|
6 |
+
public $permitted;
|
7 |
+
private $isLoggedIn;
|
8 |
+
private $lastStatusMsg;
|
9 |
+
private static $_this;
|
10 |
+
public $userData;
|
11 |
+
|
12 |
+
private function __construct() {
|
13 |
+
//check if we need to display custom message on the login form
|
14 |
+
$custom_msg = filter_input( INPUT_COOKIE, 'swpm-login-form-custom-msg', FILTER_SANITIZE_STRING );
|
15 |
+
if ( ! empty( $custom_msg ) ) {
|
16 |
+
$this->lastStatusMsg = $custom_msg;
|
17 |
+
//let's 'unset' the cookie
|
18 |
+
setcookie( 'swpm-login-form-custom-msg', '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN );
|
19 |
+
}
|
20 |
+
$this->isLoggedIn = false;
|
21 |
+
$this->userData = null;
|
22 |
+
$this->protected = SwpmProtection::get_instance();
|
23 |
+
}
|
24 |
+
|
25 |
+
private function init() {
|
26 |
+
$valid = $this->validate();
|
27 |
+
//SwpmLog::log_auth_debug("init:". ($valid? "valid": "invalid"), true);
|
28 |
+
if ( ! $valid ) {
|
29 |
+
$this->authenticate();
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
public static function get_instance() {
|
34 |
+
if ( empty( self::$_this ) ) {
|
35 |
+
self::$_this = new SwpmAuth();
|
36 |
+
self::$_this->init();
|
37 |
+
}
|
38 |
+
return self::$_this;
|
39 |
+
}
|
40 |
+
|
41 |
+
private function authenticate( $user = null, $pass = null ) {
|
42 |
+
global $wpdb;
|
43 |
+
$swpm_password = empty( $pass ) ? filter_input( INPUT_POST, 'swpm_password' ) : $pass;
|
44 |
+
$swpm_user_name = empty( $user ) ? apply_filters( 'swpm_user_name', filter_input( INPUT_POST, 'swpm_user_name' ) ) : $user;
|
45 |
+
|
46 |
+
if ( ! empty( $swpm_user_name ) && ! empty( $swpm_password ) ) {
|
47 |
+
//SWPM member login request.
|
48 |
+
//Trigger action hook that can be used to check stuff before the login request is processed by the plugin.
|
49 |
+
$args = array(
|
50 |
+
'username' => $swpm_user_name,
|
51 |
+
'password' => $swpm_password,
|
52 |
+
);
|
53 |
+
do_action( 'swpm_before_login_request_is_processed', $args );
|
54 |
+
|
55 |
+
//First, lets make sure this user is not already logged into the site as an "Admin" user. We don't want to override that admin login session.
|
56 |
+
if ( current_user_can( 'administrator' ) ) {
|
57 |
+
//This user is logged in as ADMIN then trying to do another login as a member. Stop the login request processing (we don't want to override your admin login session).
|
58 |
+
$wp_profile_page = SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL . '/wp-admin/profile.php';
|
59 |
+
$error_msg = '';
|
60 |
+
$error_msg .= '<p>' . SwpmUtils::_( 'Warning! Simple Membership plugin cannot process this login request to prevent you from getting logged out of WP Admin accidentally.' ) . '</p>';
|
61 |
+
$error_msg .= '<p><a href="' . $wp_profile_page . '" target="_blank">' . SwpmUtils::_( 'Click here' ) . '</a>' . SwpmUtils::_( ' to see the profile you are currently logged into in this browser.' ) . '</p>';
|
62 |
+
$error_msg .= '<p>' . SwpmUtils::_( 'You are logged into the site as an ADMIN user in this browser. First, logout from WP Admin then you will be able to log in as a normal member.' ) . '</p>';
|
63 |
+
$error_msg .= '<p>' . SwpmUtils::_( 'Alternatively, you can use a different browser (where you are not logged-in as ADMIN) to test the membership login.' ) . '</p>';
|
64 |
+
$error_msg .= '<p>' . SwpmUtils::_( 'Your normal visitors or members will never see this message. This message is ONLY for ADMIN user.' ) . '</p>';
|
65 |
+
wp_die( $error_msg );
|
66 |
+
}
|
67 |
+
|
68 |
+
//If captcha is present and validation failed, it returns an error string. If validation succeeds, it returns an empty string.
|
69 |
+
$captcha_validation_output = apply_filters( 'swpm_validate_login_form_submission', '' );
|
70 |
+
if ( ! empty( $captcha_validation_output ) ) {
|
71 |
+
$this->lastStatusMsg = SwpmUtils::_( 'Captcha validation failed on login form.' );
|
72 |
+
return;
|
73 |
+
}
|
74 |
+
|
75 |
+
if ( is_email( $swpm_user_name ) ) {//User is trying to log-in using an email address
|
76 |
+
$email = sanitize_email( $swpm_user_name );
|
77 |
+
$query = $wpdb->prepare( 'SELECT user_name FROM ' . $wpdb->prefix . 'swpm_members_tbl WHERE email = %s', $email );
|
78 |
+
$username = $wpdb->get_var( $query );
|
79 |
+
if ( $username ) {//Found a user record
|
80 |
+
$swpm_user_name = $username; //Grab the usrename value so it can be used in the authentication process.
|
81 |
+
SwpmLog::log_auth_debug( 'Authentication request using email address: ' . $email . ', Found a user record with username: ' . $swpm_user_name, true );
|
82 |
+
}
|
83 |
+
}
|
84 |
+
|
85 |
+
//Lets process the request. Check username and password
|
86 |
+
$user = sanitize_user( $swpm_user_name );
|
87 |
+
$pass = trim( $swpm_password );
|
88 |
+
SwpmLog::log_auth_debug( 'Authentication request - Username: ' . $swpm_user_name, true );
|
89 |
+
|
90 |
+
$query = 'SELECT * FROM ' . $wpdb->prefix . 'swpm_members_tbl WHERE user_name = %s';
|
91 |
+
$userData = $wpdb->get_row( $wpdb->prepare( $query, $user ) );
|
92 |
+
$this->userData = $userData;
|
93 |
+
if ( ! $userData ) {
|
94 |
+
$this->isLoggedIn = false;
|
95 |
+
$this->userData = null;
|
96 |
+
$this->lastStatusMsg = SwpmUtils::_( 'User Not Found.' );
|
97 |
+
return false;
|
98 |
+
}
|
99 |
+
$check = $this->check_password( $pass, $userData->password );
|
100 |
+
if ( ! $check ) {
|
101 |
+
$this->isLoggedIn = false;
|
102 |
+
$this->userData = null;
|
103 |
+
$this->lastStatusMsg = SwpmUtils::_( 'Password Empty or Invalid.' );
|
104 |
+
return false;
|
105 |
+
}
|
106 |
+
if ( $this->check_constraints() ) {
|
107 |
+
$rememberme = filter_input( INPUT_POST, 'rememberme' );
|
108 |
+
$remember = empty( $rememberme ) ? false : true;
|
109 |
+
$this->set_cookie( $remember );
|
110 |
+
$this->isLoggedIn = true;
|
111 |
+
$this->lastStatusMsg = 'Logged In.';
|
112 |
+
SwpmLog::log_auth_debug( 'Authentication successful for username: ' . $user . '. Executing swpm_login action hook.', true );
|
113 |
+
do_action( 'swpm_login', $user, $pass, $remember );
|
114 |
+
return true;
|
115 |
+
}
|
116 |
+
}
|
117 |
+
return false;
|
118 |
+
}
|
119 |
+
|
120 |
+
private function check_constraints() {
|
121 |
+
if ( empty( $this->userData ) ) {
|
122 |
+
return false;
|
123 |
+
}
|
124 |
+
global $wpdb;
|
125 |
+
$enable_expired_login = SwpmSettings::get_instance()->get_value( 'enable-expired-account-login', '' );
|
126 |
+
|
127 |
+
//Update the last accessed date and IP address for this login attempt. $wpdb->update(table, data, where, format, where format)
|
128 |
+
$last_accessed_date = current_time( 'mysql' );
|
129 |
+
$last_accessed_ip = SwpmUtils::get_user_ip_address();
|
130 |
+
$wpdb->update(
|
131 |
+
$wpdb->prefix . 'swpm_members_tbl',
|
132 |
+
array(
|
133 |
+
'last_accessed' => $last_accessed_date,
|
134 |
+
'last_accessed_from_ip' => $last_accessed_ip,
|
135 |
+
),
|
136 |
+
array( 'member_id' => $this->userData->member_id ),
|
137 |
+
array( '%s', '%s' ),
|
138 |
+
array( '%d' )
|
139 |
+
);
|
140 |
+
|
141 |
+
//Check the member's account status.
|
142 |
+
$can_login = true;
|
143 |
+
if ( $this->userData->account_state == 'inactive' && empty( $enable_expired_login ) ) {
|
144 |
+
$this->lastStatusMsg = SwpmUtils::_( 'Account is inactive.' );
|
145 |
+
$can_login = false;
|
146 |
+
} elseif ( ( $this->userData->account_state == 'expired' ) && empty( $enable_expired_login ) ) {
|
147 |
+
$this->lastStatusMsg = SwpmUtils::_( 'Account has expired.' );
|
148 |
+
$can_login = false;
|
149 |
+
} elseif ( $this->userData->account_state == 'pending' ) {
|
150 |
+
$this->lastStatusMsg = SwpmUtils::_( 'Account is pending.' );
|
151 |
+
$can_login = false;
|
152 |
+
} elseif ( $this->userData->account_state == 'activation_required' ) {
|
153 |
+
$resend_email_url = add_query_arg(
|
154 |
+
array(
|
155 |
+
'swpm_resend_activation_email' => '1',
|
156 |
+
'swpm_member_id' => $this->userData->member_id,
|
157 |
+
),
|
158 |
+
get_home_url()
|
159 |
+
);
|
160 |
+
$msg = sprintf( SwpmUtils::_( 'You need to activate your account. If you didn\'t receive an email then %s to resend the activation email.' ), '<a href="' . $resend_email_url . '">' . SwpmUtils::_( 'click here' ) . '</a>' );
|
161 |
+
$this->lastStatusMsg = $msg;
|
162 |
+
$can_login = false;
|
163 |
+
}
|
164 |
+
|
165 |
+
if ( ! $can_login ) {
|
166 |
+
$this->isLoggedIn = false;
|
167 |
+
$this->userData = null;
|
168 |
+
return false;
|
169 |
+
}
|
170 |
+
|
171 |
+
if ( SwpmUtils::is_subscription_expired( $this->userData ) ) {
|
172 |
+
if ( $this->userData->account_state == 'active' ) {
|
173 |
+
$wpdb->update( $wpdb->prefix . 'swpm_members_tbl', array( 'account_state' => 'expired' ), array( 'member_id' => $this->userData->member_id ), array( '%s' ), array( '%d' ) );
|
174 |
+
}
|
175 |
+
if ( empty( $enable_expired_login ) ) {
|
176 |
+
$this->lastStatusMsg = SwpmUtils::_( 'Account has expired.' );
|
177 |
+
$this->isLoggedIn = false;
|
178 |
+
$this->userData = null;
|
179 |
+
return false;
|
180 |
+
}
|
181 |
+
}
|
182 |
+
|
183 |
+
$this->permitted = SwpmPermission::get_instance( $this->userData->membership_level );
|
184 |
+
$this->lastStatusMsg = SwpmUtils::_( 'You are logged in as:' ) . $this->userData->user_name;
|
185 |
+
$this->isLoggedIn = true;
|
186 |
+
return true;
|
187 |
+
}
|
188 |
+
|
189 |
+
private function check_password( $plain_password, $hashed_pw ) {
|
190 |
+
global $wp_hasher;
|
191 |
+
if ( empty( $plain_password ) ) {
|
192 |
+
return false;
|
193 |
+
}
|
194 |
+
if ( empty( $wp_hasher ) ) {
|
195 |
+
require_once ABSPATH . 'wp-includes/class-phpass.php';
|
196 |
+
$wp_hasher = new PasswordHash( 8, true );
|
197 |
+
}
|
198 |
+
return $wp_hasher->CheckPassword( $plain_password, $hashed_pw );
|
199 |
+
}
|
200 |
+
|
201 |
+
public function match_password( $password ) {
|
202 |
+
if ( ! $this->is_logged_in() ) {
|
203 |
+
return false;
|
204 |
+
}
|
205 |
+
return $this->check_password( $password, $this->get( 'password' ) );
|
206 |
+
}
|
207 |
+
|
208 |
+
public function login_to_swpm_using_wp_user( $user ) {
|
209 |
+
if ( $this->isLoggedIn ) {
|
210 |
+
return false;
|
211 |
+
}
|
212 |
+
$email = $user->user_email;
|
213 |
+
$member = SwpmMemberUtils::get_user_by_email( $email );
|
214 |
+
if ( empty( $member ) ) {
|
215 |
+
//There is no swpm profile with this email.
|
216 |
+
return false;
|
217 |
+
}
|
218 |
+
$this->userData = $member;
|
219 |
+
$this->isLoggedIn = true;
|
220 |
+
$this->set_cookie();
|
221 |
+
SwpmLog::log_auth_debug( 'Member has been logged in using WP User object.', true );
|
222 |
+
$this->check_constraints();
|
223 |
+
return true;
|
224 |
+
}
|
225 |
+
|
226 |
+
public function login( $user, $pass, $remember = '', $secure = '' ) {
|
227 |
+
SwpmLog::log_auth_debug( 'SwpmAuth::login()', true );
|
228 |
+
if ( $this->isLoggedIn ) {
|
229 |
+
return;
|
230 |
+
}
|
231 |
+
if ( $this->authenticate( $user, $pass ) && $this->validate() ) {
|
232 |
+
$this->set_cookie( $remember, $secure );
|
233 |
+
} else {
|
234 |
+
$this->isLoggedIn = false;
|
235 |
+
$this->userData = null;
|
236 |
+
}
|
237 |
+
return $this->lastStatusMsg;
|
238 |
+
}
|
239 |
+
|
240 |
+
public function logout() {
|
241 |
+
if ( ! $this->isLoggedIn ) {
|
242 |
+
return;
|
243 |
+
}
|
244 |
+
setcookie( SIMPLE_WP_MEMBERSHIP_AUTH, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
|
245 |
+
setcookie( SIMPLE_WP_MEMBERSHIP_SEC_AUTH, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
|
246 |
+
$this->userData = null;
|
247 |
+
$this->isLoggedIn = false;
|
248 |
+
$this->lastStatusMsg = SwpmUtils::_( 'Logged Out Successfully.' );
|
249 |
+
do_action( 'swpm_logout' );
|
250 |
+
}
|
251 |
+
|
252 |
+
private function set_cookie( $remember = '', $secure = '' ) {
|
253 |
+
if ( $remember ) {
|
254 |
+
$expiration = time() + 1209600; //14 days
|
255 |
+
$expire = $expiration + 43200; //12 hours grace period
|
256 |
+
} else {
|
257 |
+
$expiration = time() + 259200; //3 days.
|
258 |
+
$expire = $expiration; //The minimum cookie expiration should be at least a few days.
|
259 |
+
}
|
260 |
+
|
261 |
+
$expire = apply_filters( 'swpm_auth_cookie_expiry_value', $expire );
|
262 |
+
|
263 |
+
setcookie( 'swpm_in_use', 'swpm_in_use', $expire, COOKIEPATH, COOKIE_DOMAIN );
|
264 |
+
|
265 |
+
$expiration_timestamp = SwpmUtils::get_expiration_timestamp( $this->userData );
|
266 |
+
$enable_expired_login = SwpmSettings::get_instance()->get_value( 'enable-expired-account-login', '' );
|
267 |
+
// make sure cookie doesn't live beyond account expiration date.
|
268 |
+
// but if expired account login is enabled then ignore if account is expired
|
269 |
+
$expiration = empty( $enable_expired_login ) ? min( $expiration, $expiration_timestamp ) : $expiration;
|
270 |
+
$pass_frag = substr( $this->userData->password, 8, 4 );
|
271 |
+
$scheme = 'auth';
|
272 |
+
if ( ! $secure ) {
|
273 |
+
$secure = is_ssl();
|
274 |
+
}
|
275 |
+
$key = self::b_hash( $this->userData->user_name . $pass_frag . '|' . $expiration, $scheme );
|
276 |
+
$hash = hash_hmac( 'md5', $this->userData->user_name . '|' . $expiration, $key );
|
277 |
+
$auth_cookie = $this->userData->user_name . '|' . $expiration . '|' . $hash;
|
278 |
+
$auth_cookie_name = $secure ? SIMPLE_WP_MEMBERSHIP_SEC_AUTH : SIMPLE_WP_MEMBERSHIP_AUTH;
|
279 |
+
setcookie( $auth_cookie_name, $auth_cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure, true );
|
280 |
+
}
|
281 |
+
|
282 |
+
private function validate() {
|
283 |
+
$auth_cookie_name = is_ssl() ? SIMPLE_WP_MEMBERSHIP_SEC_AUTH : SIMPLE_WP_MEMBERSHIP_AUTH;
|
284 |
+
if ( ! isset( $_COOKIE[ $auth_cookie_name ] ) || empty( $_COOKIE[ $auth_cookie_name ] ) ) {
|
285 |
+
return false;
|
286 |
+
}
|
287 |
+
$cookie_elements = explode( '|', $_COOKIE[ $auth_cookie_name ] );
|
288 |
+
if ( count( $cookie_elements ) != 3 ) {
|
289 |
+
return false;
|
290 |
+
}
|
291 |
+
|
292 |
+
//SwpmLog::log_auth_debug("validate() - " . $_COOKIE[$auth_cookie_name], true);
|
293 |
+
list($username, $expiration, $hmac) = $cookie_elements;
|
294 |
+
$expired = $expiration;
|
295 |
+
// Allow a grace period for POST and AJAX requests
|
296 |
+
if ( defined( 'DOING_AJAX' ) || 'POST' == $_SERVER['REQUEST_METHOD'] ) {
|
297 |
+
$expired += HOUR_IN_SECONDS;
|
298 |
+
}
|
299 |
+
// Quick check to see if an honest cookie has expired
|
300 |
+
if ( $expired < time() ) {
|
301 |
+
$this->lastStatusMsg = SwpmUtils::_( 'Session Expired.' ); //do_action('auth_cookie_expired', $cookie_elements);
|
302 |
+
SwpmLog::log_auth_debug( 'validate() - Session Expired', true );
|
303 |
+
return false;
|
304 |
+
}
|
305 |
+
|
306 |
+
global $wpdb;
|
307 |
+
$query = ' SELECT * FROM ' . $wpdb->prefix . 'swpm_members_tbl WHERE user_name = %s';
|
308 |
+
$user = $wpdb->get_row( $wpdb->prepare( $query, $username ) );
|
309 |
+
if ( empty( $user ) ) {
|
310 |
+
$this->lastStatusMsg = SwpmUtils::_( 'Invalid Username' );
|
311 |
+
return false;
|
312 |
+
}
|
313 |
+
|
314 |
+
$pass_frag = substr( $user->password, 8, 4 );
|
315 |
+
$key = self::b_hash( $username . $pass_frag . '|' . $expiration );
|
316 |
+
$hash = hash_hmac( 'md5', $username . '|' . $expiration, $key );
|
317 |
+
if ( $hmac != $hash ) {
|
318 |
+
$this->lastStatusMsg = SwpmUtils::_( 'Please login again.' );
|
319 |
+
SwpmLog::log_auth_debug( 'validate() - Bad Hash', true );
|
320 |
+
wp_logout(); //Force logout of WP user session to clear the bad hash.
|
321 |
+
return false;
|
322 |
+
}
|
323 |
+
|
324 |
+
if ( $expiration < time() ) {
|
325 |
+
$GLOBALS['login_grace_period'] = 1;
|
326 |
+
}
|
327 |
+
$this->userData = $user;
|
328 |
+
return $this->check_constraints();
|
329 |
+
}
|
330 |
+
|
331 |
+
public static function b_hash( $data, $scheme = 'auth' ) {
|
332 |
+
$salt = wp_salt( $scheme ) . 'j4H!B3TA,J4nIn4.';
|
333 |
+
return hash_hmac( 'md5', $data, $salt );
|
334 |
+
}
|
335 |
+
|
336 |
+
public function is_logged_in() {
|
337 |
+
return $this->isLoggedIn;
|
338 |
+
}
|
339 |
+
|
340 |
+
public function get( $key, $default = '' ) {
|
341 |
+
if ( isset( $this->userData->$key ) ) {
|
342 |
+
return $this->userData->$key;
|
343 |
+
}
|
344 |
+
if ( isset( $this->permitted->$key ) ) {
|
345 |
+
return $this->permitted->$key;
|
346 |
+
}
|
347 |
+
if ( ! empty( $this->permitted ) ) {
|
348 |
+
return $this->permitted->get( $key, $default );
|
349 |
+
}
|
350 |
+
return $default;
|
351 |
+
}
|
352 |
+
|
353 |
+
public function get_message() {
|
354 |
+
return $this->lastStatusMsg;
|
355 |
+
}
|
356 |
+
|
357 |
+
public function get_expire_date() {
|
358 |
+
if ( $this->isLoggedIn ) {
|
359 |
+
return SwpmUtils::get_formatted_expiry_date( $this->get( 'subscription_starts' ), $this->get( 'subscription_period' ), $this->get( 'subscription_duration_type' ) );
|
360 |
+
}
|
361 |
+
return '';
|
362 |
+
}
|
363 |
+
|
364 |
+
public function delete() {
|
365 |
+
if ( ! $this->is_logged_in() ) {
|
366 |
+
return;
|
367 |
+
}
|
368 |
+
$user_name = $this->get( 'user_name' );
|
369 |
+
$user_id = $this->get( 'member_id' );
|
370 |
+
$subscr_id = $this->get( 'subscr_id' );
|
371 |
+
$email = $this->get( 'email' );
|
372 |
+
wp_clear_auth_cookie();
|
373 |
+
$this->logout();
|
374 |
+
SwpmMembers::delete_swpm_user_by_id( $user_id );
|
375 |
+
SwpmMembers::delete_wp_user( $user_name );
|
376 |
+
}
|
377 |
+
|
378 |
+
public function reload_user_data() {
|
379 |
+
if ( ! $this->is_logged_in() ) {
|
380 |
+
return;
|
381 |
+
}
|
382 |
+
global $wpdb;
|
383 |
+
$query = 'SELECT * FROM ' . $wpdb->prefix . 'swpm_members_tbl WHERE member_id = %d';
|
384 |
+
$this->userData = $wpdb->get_row( $wpdb->prepare( $query, $this->userData->member_id ) );
|
385 |
+
}
|
386 |
+
|
387 |
+
public function is_expired_account() {
|
388 |
+
if ( ! $this->is_logged_in() ) {
|
389 |
+
return null;
|
390 |
+
}
|
391 |
+
$account_status = $this->get( 'account_state' );
|
392 |
+
if ( $account_status == 'expired' || $account_status == 'inactive' ) {
|
393 |
+
//Expired or Inactive accounts are both considered to be expired.
|
394 |
+
return true;
|
395 |
+
}
|
396 |
+
return false;
|
397 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
398 |
|
399 |
}
|
classes/class.swpm-front-registration.php
CHANGED
@@ -7,454 +7,505 @@
|
|
7 |
*/
|
8 |
class SwpmFrontRegistration extends SwpmRegistration {
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
|
460 |
}
|
7 |
*/
|
8 |
class SwpmFrontRegistration extends SwpmRegistration {
|
9 |
|
10 |
+
public static function get_instance() {
|
11 |
+
self::$_intance = empty( self::$_intance ) ? new SwpmFrontRegistration() : self::$_intance;
|
12 |
+
return self::$_intance;
|
13 |
+
}
|
14 |
+
|
15 |
+
public function regigstration_ui( $level ) {
|
16 |
+
|
17 |
+
//Trigger the filter to override the registration form (the form builder addon uses this filter)
|
18 |
+
$form = apply_filters( 'swpm_registration_form_override', '', $level ); //The $level value could be empty also so the code handling the filter need to check for it.
|
19 |
+
if ( ! empty( $form ) ) {
|
20 |
+
//An addon has overridden the registration form. So use that one.
|
21 |
+
return $form;
|
22 |
+
}
|
23 |
+
|
24 |
+
$settings_configs = SwpmSettings::get_instance();
|
25 |
+
$joinuspage_url = $settings_configs->get_value( 'join-us-page-url' );
|
26 |
+
$membership_level = '';
|
27 |
+
global $wpdb;
|
28 |
+
|
29 |
+
if ( SwpmUtils::is_paid_registration() ) {
|
30 |
+
//Lets check if this is a registration for paid membership
|
31 |
+
$member = SwpmUtils::get_paid_member_info();
|
32 |
+
if ( empty( $member ) ) {
|
33 |
+
SwpmUtils::e( 'Error! Invalid Request. Could not find a match for the given security code and the user ID.' );
|
34 |
+
} else {
|
35 |
+
$membership_level = $member->membership_level;
|
36 |
+
}
|
37 |
+
} elseif ( ! empty( $level ) ) {
|
38 |
+
//Membership level is specified in the shortcode (level specific registration form).
|
39 |
+
$member = SwpmTransfer::$default_fields;
|
40 |
+
$membership_level = absint( $level );
|
41 |
+
}
|
42 |
+
|
43 |
+
//Check if free membership registration is disalbed on the site
|
44 |
+
if ( empty( $membership_level ) ) {
|
45 |
+
$joinuspage_link = '<a href="' . $joinuspage_url . '">' . SwpmUtils::_( 'Join Us' ) . '</a>';
|
46 |
+
$free_rego_disabled_msg = '<p>';
|
47 |
+
$free_rego_disabled_msg .= SwpmUtils::_( 'Free membership is disabled on this site. Please make a payment from the ' );
|
48 |
+
$free_rego_disabled_msg .= SwpmUtils::_( $joinuspage_link );
|
49 |
+
$free_rego_disabled_msg .= SwpmUtils::_( ' page to pay for a premium membership.' );
|
50 |
+
$free_rego_disabled_msg .= '</p><p>';
|
51 |
+
$free_rego_disabled_msg .= SwpmUtils::_( 'You will receive a unique link via email after the payment. You will be able to use that link to complete the premium membership registration.' );
|
52 |
+
$free_rego_disabled_msg .= '</p>';
|
53 |
+
return $free_rego_disabled_msg;
|
54 |
+
}
|
55 |
+
|
56 |
+
//Handle the registration form in core plugin
|
57 |
+
$mebership_info = SwpmPermission::get_instance( $membership_level );
|
58 |
+
$membership_level = $mebership_info->get( 'id' );
|
59 |
+
if ( empty( $membership_level ) ) {
|
60 |
+
return 'Error! Failed to retrieve membership level ID from the membership info object.';
|
61 |
+
}
|
62 |
+
$level_identifier = md5( $membership_level );
|
63 |
+
$membership_level_alias = $mebership_info->get( 'alias' );
|
64 |
+
$swpm_registration_submit = filter_input( INPUT_POST, 'swpm_registration_submit' );
|
65 |
+
if ( ! empty( $swpm_registration_submit ) ) {
|
66 |
+
$member = array_map( 'sanitize_text_field', $_POST );
|
67 |
+
}
|
68 |
+
ob_start();
|
69 |
+
extract( (array) $member, EXTR_SKIP );
|
70 |
+
include SIMPLE_WP_MEMBERSHIP_PATH . 'views/add.php';
|
71 |
+
return ob_get_clean();
|
72 |
+
}
|
73 |
+
|
74 |
+
public function register_front_end() {
|
75 |
+
|
76 |
+
//If captcha is present and validation failed, it returns an error string. If validation succeeds, it returns an empty string.
|
77 |
+
$captcha_validation_output = apply_filters( 'swpm_validate_registration_form_submission', '' );
|
78 |
+
if ( ! empty( $captcha_validation_output ) ) {
|
79 |
+
$message = array(
|
80 |
+
'succeeded' => false,
|
81 |
+
'message' => SwpmUtils::_( 'Security check: captcha validation failed.' ),
|
82 |
+
);
|
83 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
84 |
+
return;
|
85 |
+
}
|
86 |
+
|
87 |
+
//Check if Terms and Conditions enabled
|
88 |
+
$terms_enabled = SwpmSettings::get_instance()->get_value( 'enable-terms-and-conditions' );
|
89 |
+
if ( ! empty( $terms_enabled ) ) {
|
90 |
+
//check if user checked "I accept terms" checkbox
|
91 |
+
if ( empty( $_POST['accept_terms'] ) ) {
|
92 |
+
$message = array(
|
93 |
+
'succeeded' => false,
|
94 |
+
'message' => SwpmUtils::_( 'You must accept the terms and conditions.' ),
|
95 |
+
);
|
96 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
97 |
+
return;
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
//Check if Privacy Policy enabled
|
102 |
+
$pp_enabled = SwpmSettings::get_instance()->get_value( 'enable-privacy-policy' );
|
103 |
+
if ( ! empty( $pp_enabled ) ) {
|
104 |
+
//check if user checked "I agree with Privacy Policy" checkbox
|
105 |
+
if ( empty( $_POST['accept_pp'] ) ) {
|
106 |
+
$message = array(
|
107 |
+
'succeeded' => false,
|
108 |
+
'message' => SwpmUtils::_( 'You must agree to the privacy policy.' ),
|
109 |
+
);
|
110 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
111 |
+
return;
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
//Validate swpm level hash data.
|
116 |
+
$hash_val_posted = sanitize_text_field( $_POST['swpm_level_hash'] );
|
117 |
+
$level_value = sanitize_text_field( $_POST['membership_level'] );
|
118 |
+
$swpm_p_key = get_option( 'swpm_private_key_one' );
|
119 |
+
$hash_val = md5( $swpm_p_key . '|' . $level_value );
|
120 |
+
if ( $hash_val != $hash_val_posted ) {//Level hash validation failed.
|
121 |
+
$msg = '<p>Error! Security check failed for membership level validation.</p>';
|
122 |
+
$msg .= '<p>The submitted membership level data does not seem to be authentic.</p>';
|
123 |
+
$msg .= '<p>If you are using caching please empty the cache data and try again.</p>';
|
124 |
+
wp_die( $msg );
|
125 |
+
}
|
126 |
+
|
127 |
+
$this->email_activation = get_option( 'swpm_email_activation_lvl_' . $level_value );
|
128 |
+
|
129 |
+
//Crete the member profile and send notification
|
130 |
+
if ( $this->create_swpm_user() && $this->prepare_and_create_wp_user_front_end() && $this->send_reg_email() ) {
|
131 |
+
do_action( 'swpm_front_end_registration_complete' ); //Keep this action hook for people who are using it (so their implementation doesn't break).
|
132 |
+
do_action( 'swpm_front_end_registration_complete_user_data', $this->member_info );
|
133 |
+
|
134 |
+
//Check if there is after registration redirect
|
135 |
+
if ( ! $this->email_activation ) {
|
136 |
+
$after_rego_url = SwpmSettings::get_instance()->get_value( 'after-rego-redirect-page-url' );
|
137 |
+
$after_rego_url = apply_filters( 'swpm_after_registration_redirect_url', $after_rego_url );
|
138 |
+
if ( ! empty( $after_rego_url ) ) {
|
139 |
+
//Yes. Need to redirect to this after registration page
|
140 |
+
SwpmLog::log_simple_debug( 'After registration redirect is configured in settings. Redirecting user to: ' . $after_rego_url, true );
|
141 |
+
wp_redirect( $after_rego_url );
|
142 |
+
exit( 0 );
|
143 |
+
}
|
144 |
+
}
|
145 |
+
|
146 |
+
//Set the registration complete message
|
147 |
+
if ( $this->email_activation ) {
|
148 |
+
$email_act_msg = '<div class="swpm-registration-success-msg">';
|
149 |
+
$email_act_msg .= SwpmUtils::_( 'You need to confirm your email address. Please check your email and follow instructions to complete your registration.' );
|
150 |
+
$email_act_msg .= '</div>';
|
151 |
+
$message = array(
|
152 |
+
'succeeded' => true,
|
153 |
+
'message' => $email_act_msg,
|
154 |
+
);
|
155 |
+
} else {
|
156 |
+
$login_page_url = SwpmSettings::get_instance()->get_value( 'login-page-url' );
|
157 |
+
$after_rego_msg = '<div class="swpm-registration-success-msg">' . SwpmUtils::_( 'Registration Successful. ' ) . SwpmUtils::_( 'Please' ) . ' <a href="' . $login_page_url . '">' . SwpmUtils::_( 'Login' ) . '</a></div>';
|
158 |
+
$after_rego_msg = apply_filters( 'swpm_registration_success_msg', $after_rego_msg );
|
159 |
+
$message = array(
|
160 |
+
'succeeded' => true,
|
161 |
+
'message' => $after_rego_msg,
|
162 |
+
);
|
163 |
+
}
|
164 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
165 |
+
return;
|
166 |
+
}
|
167 |
+
}
|
168 |
+
|
169 |
+
private function create_swpm_user() {
|
170 |
+
global $wpdb;
|
171 |
+
$member = SwpmTransfer::$default_fields;
|
172 |
+
$form = new SwpmFrontForm( $member );
|
173 |
+
if ( ! $form->is_valid() ) {
|
174 |
+
$message = array(
|
175 |
+
'succeeded' => false,
|
176 |
+
'message' => SwpmUtils::_( 'Please correct the following' ),
|
177 |
+
'extra' => $form->get_errors(),
|
178 |
+
);
|
179 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
180 |
+
return false;
|
181 |
+
}
|
182 |
+
|
183 |
+
$member_info = $form->get_sanitized_member_form_data();
|
184 |
+
|
185 |
+
//Check if the email belongs to an existing wp user account with admin role.
|
186 |
+
$wp_user_id = email_exists( $member_info['email'] );
|
187 |
+
if ( $wp_user_id ) {
|
188 |
+
//A wp user account exist with this email.
|
189 |
+
//Check if the user has admin role.
|
190 |
+
$admin_user = SwpmMemberUtils::wp_user_has_admin_role( $wp_user_id );
|
191 |
+
if ( $admin_user ) {
|
192 |
+
//This email belongs to an admin user. Update is not allowed on admin users. Show error message then exit.
|
193 |
+
$error_msg = '<p>This email address (' . $member_info['email'] . ') belongs to an admin user. This email cannot be used to register a new account on this site.</p>';
|
194 |
+
wp_die( $error_msg );
|
195 |
+
}
|
196 |
+
}
|
197 |
+
|
198 |
+
//Go ahead and create the SWPM user record.
|
199 |
+
$free_level = SwpmUtils::get_free_level();
|
200 |
+
$account_status = SwpmSettings::get_instance()->get_value( 'default-account-status', 'active' );
|
201 |
+
$member_info['last_accessed_from_ip'] = SwpmUtils::get_user_ip_address();
|
202 |
+
$member_info['member_since'] = date( 'Y-m-d' );
|
203 |
+
$member_info['subscription_starts'] = date( 'Y-m-d' );
|
204 |
+
$member_info['account_state'] = $account_status;
|
205 |
+
if ( $this->email_activation ) {
|
206 |
+
$member_info['account_state'] = 'activation_required';
|
207 |
+
}
|
208 |
+
$plain_password = $member_info['plain_password'];
|
209 |
+
unset( $member_info['plain_password'] );
|
210 |
+
|
211 |
+
if ( SwpmUtils::is_paid_registration() ) {
|
212 |
+
$member_info['reg_code'] = '';
|
213 |
+
$member_id = filter_input( INPUT_GET, 'member_id', FILTER_SANITIZE_NUMBER_INT );
|
214 |
+
$code = filter_input( INPUT_GET, 'code', FILTER_SANITIZE_STRING );
|
215 |
+
$wpdb->update(
|
216 |
+
$wpdb->prefix . 'swpm_members_tbl',
|
217 |
+
$member_info,
|
218 |
+
array(
|
219 |
+
'member_id' => $member_id,
|
220 |
+
'reg_code' => $code,
|
221 |
+
)
|
222 |
+
);
|
223 |
+
|
224 |
+
$query = $wpdb->prepare( 'SELECT membership_level FROM ' . $wpdb->prefix . 'swpm_members_tbl WHERE member_id=%d', $member_id );
|
225 |
+
$member_info['membership_level'] = $wpdb->get_var( $query );
|
226 |
+
$last_insert_id = $member_id;
|
227 |
+
} elseif ( ! empty( $free_level ) ) {
|
228 |
+
$member_info['membership_level'] = $free_level;
|
229 |
+
$wpdb->insert( $wpdb->prefix . 'swpm_members_tbl', $member_info );
|
230 |
+
$last_insert_id = $wpdb->insert_id;
|
231 |
+
} else {
|
232 |
+
$message = array(
|
233 |
+
'succeeded' => false,
|
234 |
+
'message' => SwpmUtils::_( 'Membership Level Couldn\'t be found.' ),
|
235 |
+
);
|
236 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
237 |
+
return false;
|
238 |
+
}
|
239 |
+
$member_info['plain_password'] = $plain_password;
|
240 |
+
$this->member_info = $member_info;
|
241 |
+
return true;
|
242 |
+
}
|
243 |
+
|
244 |
+
private function prepare_and_create_wp_user_front_end() {
|
245 |
+
global $wpdb;
|
246 |
+
$member_info = $this->member_info;
|
247 |
+
|
248 |
+
//Retrieve the user role assigned for this level
|
249 |
+
$query = $wpdb->prepare( 'SELECT role FROM ' . $wpdb->prefix . 'swpm_membership_tbl WHERE id = %d', $member_info['membership_level'] );
|
250 |
+
$user_role = $wpdb->get_var( $query );
|
251 |
+
//Check to make sure that the user role of this level is not admin.
|
252 |
+
if ( $user_role == 'administrator' ) {
|
253 |
+
//For security reasons we don't allow users with administrator role to be creted from the front-end. That can only be done from the admin dashboard side.
|
254 |
+
$error_msg = '<p>Error! The user role for this membership level (level ID: ' . $member_info['membership_level'] . ') is set to "Administrator".</p>';
|
255 |
+
$error_msg .= '<p>For security reasons, member registration to this level is not permitted from the front end.</p>';
|
256 |
+
$error_msg .= '<p>An administrator of the site can manually create a member record with this access level from the admin dashboard side.</p>';
|
257 |
+
wp_die( $error_msg );
|
258 |
+
}
|
259 |
+
|
260 |
+
$wp_user_info = array();
|
261 |
+
$wp_user_info['user_nicename'] = implode( '-', explode( ' ', $member_info['user_name'] ) );
|
262 |
+
$wp_user_info['display_name'] = $member_info['user_name'];
|
263 |
+
$wp_user_info['user_email'] = $member_info['email'];
|
264 |
+
$wp_user_info['nickname'] = $member_info['user_name'];
|
265 |
+
$wp_user_info['first_name'] = $member_info['first_name'];
|
266 |
+
$wp_user_info['last_name'] = $member_info['last_name'];
|
267 |
+
$wp_user_info['user_login'] = $member_info['user_name'];
|
268 |
+
$wp_user_info['password'] = $member_info['plain_password'];
|
269 |
+
$wp_user_info['role'] = $user_role;
|
270 |
+
$wp_user_info['user_registered'] = date( 'Y-m-d H:i:s' );
|
271 |
+
SwpmUtils::create_wp_user( $wp_user_info );
|
272 |
+
return true;
|
273 |
+
}
|
274 |
+
|
275 |
+
public function edit_profile_front_end() {
|
276 |
+
global $wpdb;
|
277 |
+
//Check that the member is logged in
|
278 |
+
$auth = SwpmAuth::get_instance();
|
279 |
+
if ( ! $auth->is_logged_in() ) {
|
280 |
+
return;
|
281 |
+
}
|
282 |
+
|
283 |
+
//Check nonce
|
284 |
+
if ( ! isset( $_POST['swpm_profile_edit_nonce_val'] ) || ! wp_verify_nonce( $_POST['swpm_profile_edit_nonce_val'], 'swpm_profile_edit_nonce_action' ) ) {
|
285 |
+
//Nonce check failed.
|
286 |
+
wp_die( SwpmUtils::_( 'Error! Nonce verification failed for front end profile edit.' ) );
|
287 |
+
}
|
288 |
+
|
289 |
+
$user_data = (array) $auth->userData;
|
290 |
+
unset( $user_data['permitted'] );
|
291 |
+
$form = new SwpmForm( $user_data );
|
292 |
+
if ( $form->is_valid() ) {
|
293 |
+
global $wpdb;
|
294 |
+
$msg_str = '<div class="swpm-profile-update-success">' . SwpmUtils::_( 'Profile updated successfully.' ) . '</div>';
|
295 |
+
$message = array(
|
296 |
+
'succeeded' => true,
|
297 |
+
'message' => $msg_str,
|
298 |
+
);
|
299 |
+
|
300 |
+
$member_info = $form->get_sanitized_member_form_data();
|
301 |
+
SwpmUtils::update_wp_user( $auth->get( 'user_name' ), $member_info ); //Update corresponding wp user record.
|
302 |
+
|
303 |
+
//Lets check if password was also changed.
|
304 |
+
$password_also_changed = false;
|
305 |
+
if ( isset( $member_info['plain_password'] ) ) {
|
306 |
+
//Password was also changed.
|
307 |
+
$msg_str = '<div class="swpm-profile-update-success">' . SwpmUtils::_( 'Profile updated successfully. You will need to re-login since you changed your password.' ) . '</div>';
|
308 |
+
$message = array(
|
309 |
+
'succeeded' => true,
|
310 |
+
'message' => $msg_str,
|
311 |
+
);
|
312 |
+
unset( $member_info['plain_password'] );
|
313 |
+
//Set the password chagned flag.
|
314 |
+
$password_also_changed = true;
|
315 |
+
}
|
316 |
+
|
317 |
+
//Update the data in the swpm database.
|
318 |
+
$swpm_id = $auth->get( 'member_id' );
|
319 |
+
//SwpmLog::log_simple_debug("Updating member profile data with SWPM ID: " . $swpm_id, true);
|
320 |
+
$member_info = array_filter( $member_info );//Remove any null values.
|
321 |
+
$wpdb->update( $wpdb->prefix . 'swpm_members_tbl', $member_info, array( 'member_id' => $swpm_id ) );
|
322 |
+
$auth->reload_user_data();//Reload user data after update so the profile page reflects the new data.
|
323 |
+
|
324 |
+
if ( $password_also_changed ) {
|
325 |
+
//Password was also changed. Logout the user's current session.
|
326 |
+
wp_logout(); //Log the user out from the WP user session also.
|
327 |
+
SwpmLog::log_simple_debug( 'Member has updated the password from profile edit page. Logging the user out so he can re-login using the new password.', true );
|
328 |
+
}
|
329 |
+
|
330 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
331 |
+
|
332 |
+
do_action( 'swpm_front_end_profile_edited', $member_info );
|
333 |
+
return true; //Successful form submission.
|
334 |
+
} else {
|
335 |
+
$msg_str = '<div class="swpm-profile-update-error">' . SwpmUtils::_( 'Please correct the following.' ) . '</div>';
|
336 |
+
$message = array(
|
337 |
+
'succeeded' => false,
|
338 |
+
'message' => $msg_str,
|
339 |
+
'extra' => $form->get_errors(),
|
340 |
+
);
|
341 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
342 |
+
return false; //Error in the form submission.
|
343 |
+
}
|
344 |
+
}
|
345 |
+
|
346 |
+
public function reset_password( $email ) {
|
347 |
+
|
348 |
+
//If captcha is present and validation failed, it returns an error string. If validation succeeds, it returns an empty string.
|
349 |
+
$captcha_validation_output = apply_filters( 'swpm_validate_pass_reset_form_submission', '' );
|
350 |
+
if ( ! empty( $captcha_validation_output ) ) {
|
351 |
+
$message = '<div class="swpm-reset-pw-error">' . SwpmUtils::_( 'Captcha validation failed.' ) . '</div>';
|
352 |
+
$message = array(
|
353 |
+
'succeeded' => false,
|
354 |
+
'message' => $message,
|
355 |
+
);
|
356 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
357 |
+
return;
|
358 |
+
}
|
359 |
+
|
360 |
+
$email = sanitize_email( $email );
|
361 |
+
if ( ! is_email( $email ) ) {
|
362 |
+
$message = '<div class="swpm-reset-pw-error">' . SwpmUtils::_( 'Email address not valid.' ) . '</div>';
|
363 |
+
$message = array(
|
364 |
+
'succeeded' => false,
|
365 |
+
'message' => $message,
|
366 |
+
);
|
367 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
368 |
+
return;
|
369 |
+
}
|
370 |
+
global $wpdb;
|
371 |
+
$query = 'SELECT member_id,user_name,first_name, last_name FROM ' .
|
372 |
+
$wpdb->prefix . 'swpm_members_tbl ' .
|
373 |
+
' WHERE email = %s';
|
374 |
+
$user = $wpdb->get_row( $wpdb->prepare( $query, $email ) );
|
375 |
+
if ( empty( $user ) ) {
|
376 |
+
$message = '<div class="swpm-reset-pw-error">' . SwpmUtils::_( 'No user found with that email address.' ) . '</div>';
|
377 |
+
$message .= '<div class="swpm-reset-pw-error-email">' . SwpmUtils::_( 'Email Address: ' ) . $email . '</div>';
|
378 |
+
$message = array(
|
379 |
+
'succeeded' => false,
|
380 |
+
'message' => $message,
|
381 |
+
);
|
382 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
383 |
+
return;
|
384 |
+
}
|
385 |
+
$settings = SwpmSettings::get_instance();
|
386 |
+
$password = wp_generate_password();
|
387 |
+
|
388 |
+
$password_hash = SwpmUtils::encrypt_password( trim( $password ) ); //should use $saned??;
|
389 |
+
$wpdb->update( $wpdb->prefix . 'swpm_members_tbl', array( 'password' => $password_hash ), array( 'member_id' => $user->member_id ) );
|
390 |
+
|
391 |
+
//Update wp user password
|
392 |
+
add_filter( 'send_password_change_email', array( &$this, 'dont_send_password_change_email' ), 1, 3 ); //Stop WordPress from sending a reset password email to admin.
|
393 |
+
SwpmUtils::update_wp_user( $user->user_name, array( 'plain_password' => $password ) );
|
394 |
+
|
395 |
+
$body = $settings->get_value( 'reset-mail-body' );
|
396 |
+
$subject = $settings->get_value( 'reset-mail-subject' );
|
397 |
+
$body = html_entity_decode( $body );
|
398 |
+
$additional_args = array( 'password' => $password );
|
399 |
+
$body = SwpmMiscUtils::replace_dynamic_tags( $body, $user->member_id, $additional_args );
|
400 |
+
$from = $settings->get_value( 'email-from' );
|
401 |
+
$headers = 'From: ' . $from . "\r\n";
|
402 |
+
$subject = apply_filters( 'swpm_email_password_reset_subject', $subject );
|
403 |
+
$body = apply_filters( 'swpm_email_password_reset_body', $body );
|
404 |
+
SwpmMiscUtils::mail( $email, $subject, $body, $headers );
|
405 |
+
SwpmLog::log_simple_debug( 'Member password has been reset. Password reset email sent to: ' . $email, true );
|
406 |
+
|
407 |
+
$message = '<div class="swpm-reset-pw-success-box">';
|
408 |
+
$message .= '<div class="swpm-reset-pw-success">' . SwpmUtils::_( 'New password has been sent to your email address.' ) . '</div>';
|
409 |
+
$message .= '<div class="swpm-reset-pw-success-email">' . SwpmUtils::_( 'Email Address: ' ) . $email . '</div>';
|
410 |
+
$message .= '</div>';
|
411 |
+
|
412 |
+
$message = array(
|
413 |
+
'succeeded' => false,
|
414 |
+
'message' => $message,
|
415 |
+
'pass_reset_sent' => true,
|
416 |
+
);
|
417 |
+
SwpmTransfer::get_instance()->set( 'status', $message );
|
418 |
+
}
|
419 |
+
|
420 |
+
function dont_send_password_change_email( $send = false, $user = '', $userdata = '' ) {
|
421 |
+
//Stop the WordPress's default password change email notification to site admin
|
422 |
+
//Only the simple membership plugin's password reset email will be sent.
|
423 |
+
return false;
|
424 |
+
}
|
425 |
+
|
426 |
+
public function email_activation() {
|
427 |
+
$login_page_url = SwpmSettings::get_instance()->get_value( 'login-page-url' );
|
428 |
+
|
429 |
+
$member_id = FILTER_INPUT( INPUT_GET, 'swpm_member_id', FILTER_SANITIZE_NUMBER_INT );
|
430 |
+
|
431 |
+
$member = SwpmMemberUtils::get_user_by_id( $member_id );
|
432 |
+
if ( empty( $member ) ) {
|
433 |
+
//can't find member
|
434 |
+
echo SwpmUtils::_( "Can't find member account." );
|
435 |
+
wp_die();
|
436 |
+
}
|
437 |
+
if ( $member->account_state !== 'activation_required' ) {
|
438 |
+
//account already active
|
439 |
+
echo SwpmUtils::_( 'Account already active. ' ) . '<a href="' . $login_page_url . '">' . SwpmUtils::_( 'click here' ) . '</a>' . SwpmUtils::_( ' to login.' );
|
440 |
+
wp_die();
|
441 |
+
}
|
442 |
+
$code = FILTER_INPUT( INPUT_GET, 'swpm_token', FILTER_SANITIZE_STRING );
|
443 |
+
$act_data = get_option( 'swpm_email_activation_data_usr_' . $member_id );
|
444 |
+
if ( empty( $code ) || empty( $act_data ) || $act_data['act_code'] !== $code ) {
|
445 |
+
//code mismatch
|
446 |
+
wp_die( SwpmUtils::_( 'Activation code mismatch. Cannot activate this account. Please contact the site admin.' ) );
|
447 |
+
}
|
448 |
+
//activation code match
|
449 |
+
delete_option( 'swpm_email_activation_data_usr_' . $member_id );
|
450 |
+
//store rego form id in constant so FB addon could use it
|
451 |
+
if ( ! empty( $act_data['fb_form_id'] ) ) {
|
452 |
+
define( 'SWPM_EMAIL_ACTIVATION_FORM_ID', $act_data['fb_form_id'] );
|
453 |
+
}
|
454 |
+
$activation_account_status = apply_filters( 'swpm_activation_feature_override_account_status', 'active' );
|
455 |
+
SwpmMemberUtils::update_account_state( $member_id, $activation_account_status );
|
456 |
+
$this->member_info = (array) $member;
|
457 |
+
$this->member_info['plain_password'] = SwpmUtils::crypt( $act_data['plain_password'], 'd' );
|
458 |
+
$this->send_reg_email();
|
459 |
+
|
460 |
+
$msg = '<div class="swpm_temporary_msg" style="font-weight: bold;">' . SwpmUtils::_( 'Success! Your account has been activated successfully.' ) . '</div>';
|
461 |
+
|
462 |
+
$after_rego_url = SwpmSettings::get_instance()->get_value( 'after-rego-redirect-page-url' );
|
463 |
+
$after_rego_url = apply_filters( 'swpm_after_registration_redirect_url', $after_rego_url );
|
464 |
+
if ( ! empty( $after_rego_url ) ) {
|
465 |
+
//Yes. Need to redirect to this after registration page
|
466 |
+
SwpmLog::log_simple_debug( 'After registration redirect is configured in settings. Redirecting user to: ' . $after_rego_url, true );
|
467 |
+
SwpmMiscUtils::show_temporary_message_then_redirect( $msg, $after_rego_url );
|
468 |
+
exit( 0 );
|
469 |
+
}
|
470 |
+
|
471 |
+
//show success message and redirect to login page
|
472 |
+
SwpmMiscUtils::show_temporary_message_then_redirect( $msg, $login_page_url );
|
473 |
+
exit( 0 );
|
474 |
+
}
|
475 |
+
|
476 |
+
public function resend_activation_email() {
|
477 |
+
$login_page_url = SwpmSettings::get_instance()->get_value( 'login-page-url' );
|
478 |
+
|
479 |
+
$member_id = FILTER_INPUT( INPUT_GET, 'swpm_member_id', FILTER_SANITIZE_NUMBER_INT );
|
480 |
+
|
481 |
+
$member = SwpmMemberUtils::get_user_by_id( $member_id );
|
482 |
+
if ( empty( $member ) ) {
|
483 |
+
//can't find member
|
484 |
+
echo SwpmUtils::_( 'Cannot find member account.' );
|
485 |
+
wp_die();
|
486 |
+
}
|
487 |
+
if ( $member->account_state !== 'activation_required' ) {
|
488 |
+
//account already active
|
489 |
+
$acc_active_msg = SwpmUtils::_( 'Account already active. ' ) . '<a href="' . $login_page_url . '">' . SwpmUtils::_( 'click here' ) . '</a>' . SwpmUtils::_( ' to login.' );
|
490 |
+
echo $acc_active_msg;
|
491 |
+
wp_die();
|
492 |
+
}
|
493 |
+
$act_data = get_option( 'swpm_email_activation_data_usr_' . $member_id );
|
494 |
+
if ( ! empty( $act_data ) ) {
|
495 |
+
//looks like activation data has been removed for some reason. We won't be able to have member's plain password in this case
|
496 |
+
$act_data['plain_password'] = '';
|
497 |
+
}
|
498 |
+
|
499 |
+
delete_option( 'swpm_email_activation_data_usr_' . $member_id );
|
500 |
+
|
501 |
+
$this->member_info = (array) $member;
|
502 |
+
$this->member_info['plain_password'] = SwpmUtils::crypt( $act_data['plain_password'], 'd' );
|
503 |
+
$this->email_activation = true;
|
504 |
+
$this->send_reg_email();
|
505 |
+
|
506 |
+
$msg = '<div class="swpm_temporary_msg" style="font-weight: bold;">' . SwpmUtils::_( 'Activation email has been sent. Please check your email and activate your account.' ) . '</div>';
|
507 |
+
SwpmMiscUtils::show_temporary_message_then_redirect( $msg, $login_page_url );
|
508 |
+
wp_die();
|
509 |
+
}
|
510 |
|
511 |
}
|
classes/class.swpm-init-time-tasks.php
CHANGED
@@ -1,209 +1,212 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class SwpmInitTimeTasks {
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
}
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class SwpmInitTimeTasks {
|
4 |
+
|
5 |
+
public function __construct() {
|
6 |
+
|
7 |
+
}
|
8 |
+
|
9 |
+
public function do_init_tasks() {
|
10 |
+
|
11 |
+
//Set up localisation. First loaded ones will override strings present in later loaded file.
|
12 |
+
//Allows users to have a customized language in a different folder.
|
13 |
+
$locale = apply_filters( 'plugin_locale', get_locale(), 'simple-membership' );
|
14 |
+
load_textdomain( 'simple-membership', WP_LANG_DIR . "/simple-membership-$locale.mo" );
|
15 |
+
load_plugin_textdomain( 'simple-membership', false, SIMPLE_WP_MEMBERSHIP_DIRNAME . '/languages/' );
|
16 |
+
|
17 |
+
if ( ! isset( $_COOKIE['swpm_session'] ) ) { // give a unique ID to current session.
|
18 |
+
$uid = md5( microtime() );
|
19 |
+
$_COOKIE['swpm_session'] = $uid; // fake it for current session/
|
20 |
+
setcookie( 'swpm_session', $uid, 0, '/' );
|
21 |
+
}
|
22 |
+
|
23 |
+
//Crete the custom post types
|
24 |
+
$this->create_post_type();
|
25 |
+
|
26 |
+
//Do frontend-only init time tasks
|
27 |
+
if ( ! is_admin() ) {
|
28 |
+
SwpmAuth::get_instance();
|
29 |
+
|
30 |
+
$this->check_and_handle_auto_login();
|
31 |
+
$this->verify_and_delete_account();
|
32 |
+
|
33 |
+
$swpm_logout = filter_input( INPUT_GET, 'swpm-logout' );
|
34 |
+
if ( ! empty( $swpm_logout ) ) {
|
35 |
+
SwpmAuth::get_instance()->logout();
|
36 |
+
$redirect_url = apply_filters( 'swpm_after_logout_redirect_url', SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL );
|
37 |
+
wp_redirect( trailingslashit( $redirect_url ) );
|
38 |
+
exit( 0 );
|
39 |
+
}
|
40 |
+
$this->process_password_reset();
|
41 |
+
$this->register_member();
|
42 |
+
$this->check_and_do_email_activation();
|
43 |
+
$this->edit_profile();
|
44 |
+
SwpmCommentFormRelated::check_and_restrict_comment_posting_to_members();
|
45 |
+
} else {
|
46 |
+
//Do admin side init time tasks
|
47 |
+
if ( current_user_can( SWPM_MANAGEMENT_PERMISSION ) ) {
|
48 |
+
//Admin dashboard side stuff
|
49 |
+
$this->admin_init();
|
50 |
+
}
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
public function admin_init() {
|
55 |
+
$createswpmuser = filter_input( INPUT_POST, 'createswpmuser' );
|
56 |
+
if ( ! empty( $createswpmuser ) ) {
|
57 |
+
SwpmAdminRegistration::get_instance()->register_admin_end();
|
58 |
+
}
|
59 |
+
$editswpmuser = filter_input( INPUT_POST, 'editswpmuser' );
|
60 |
+
if ( ! empty( $editswpmuser ) ) {
|
61 |
+
$id = filter_input( INPUT_GET, 'member_id', FILTER_VALIDATE_INT );
|
62 |
+
SwpmAdminRegistration::get_instance()->edit_admin_end( $id );
|
63 |
+
}
|
64 |
+
$createswpmlevel = filter_input( INPUT_POST, 'createswpmlevel' );
|
65 |
+
if ( ! empty( $createswpmlevel ) ) {
|
66 |
+
SwpmMembershipLevel::get_instance()->create_level();
|
67 |
+
}
|
68 |
+
$editswpmlevel = filter_input( INPUT_POST, 'editswpmlevel' );
|
69 |
+
if ( ! empty( $editswpmlevel ) ) {
|
70 |
+
$id = filter_input( INPUT_GET, 'id' );
|
71 |
+
SwpmMembershipLevel::get_instance()->edit_level( $id );
|
72 |
+
}
|
73 |
+
$update_category_list = filter_input( INPUT_POST, 'update_category_list' );
|
74 |
+
if ( ! empty( $update_category_list ) ) {
|
75 |
+
include_once 'class.swpm-category-list.php';
|
76 |
+
SwpmCategoryList::update_category_list();
|
77 |
+
}
|
78 |
+
$update_post_list = filter_input( INPUT_POST, 'update_post_list' );
|
79 |
+
if ( ! empty( $update_post_list ) ) {
|
80 |
+
include_once 'class.swpm-post-list.php';
|
81 |
+
SwpmPostList::update_post_list();
|
82 |
+
}
|
83 |
+
}
|
84 |
+
|
85 |
+
public function create_post_type() {
|
86 |
+
//The payment button data for membership levels will be stored using this CPT
|
87 |
+
register_post_type(
|
88 |
+
'swpm_payment_button',
|
89 |
+
array(
|
90 |
+
'public' => false,
|
91 |
+
'publicly_queryable' => false,
|
92 |
+
'show_ui' => false,
|
93 |
+
'query_var' => false,
|
94 |
+
'rewrite' => false,
|
95 |
+
'capability_type' => 'page',
|
96 |
+
'has_archive' => false,
|
97 |
+
'hierarchical' => false,
|
98 |
+
'supports' => array( 'title', 'editor' ),
|
99 |
+
)
|
100 |
+
);
|
101 |
+
|
102 |
+
//Transactions will be stored using this CPT in parallel with swpm_payments_tbl DB table
|
103 |
+
$args = array(
|
104 |
+
'supports' => array( '' ),
|
105 |
+
'hierarchical' => false,
|
106 |
+
'public' => false,
|
107 |
+
'show_ui' => false,
|
108 |
+
'can_export' => false,
|
109 |
+
'has_archive' => false,
|
110 |
+
'exclude_from_search' => true,
|
111 |
+
'publicly_queryable' => false,
|
112 |
+
'capability_type' => 'post',
|
113 |
+
);
|
114 |
+
register_post_type( 'swpm_transactions', $args );
|
115 |
+
}
|
116 |
+
|
117 |
+
private function verify_and_delete_account() {
|
118 |
+
include_once SIMPLE_WP_MEMBERSHIP_PATH . 'classes/class.swpm-members.php';
|
119 |
+
$delete_account = filter_input( INPUT_GET, 'swpm_delete_account' );
|
120 |
+
if ( empty( $delete_account ) ) {
|
121 |
+
return;
|
122 |
+
}
|
123 |
+
$password = filter_input( INPUT_POST, 'account_delete_confirm_pass', FILTER_UNSAFE_RAW );
|
124 |
+
|
125 |
+
$auth = SwpmAuth::get_instance();
|
126 |
+
if ( ! $auth->is_logged_in() ) {
|
127 |
+
return;
|
128 |
+
}
|
129 |
+
if ( empty( $password ) ) {
|
130 |
+
SwpmUtils::account_delete_confirmation_ui();
|
131 |
+
}
|
132 |
+
|
133 |
+
$nonce_field = filter_input( INPUT_POST, 'account_delete_confirm_nonce' );
|
134 |
+
if ( empty( $nonce_field ) || ! wp_verify_nonce( $nonce_field, 'swpm_account_delete_confirm' ) ) {
|
135 |
+
SwpmUtils::account_delete_confirmation_ui( SwpmUtils::_( 'Sorry, Nonce verification failed.' ) );
|
136 |
+
}
|
137 |
+
if ( $auth->match_password( $password ) ) {
|
138 |
+
$auth->delete();
|
139 |
+
wp_safe_redirect( get_home_url() );
|
140 |
+
exit( 0 );
|
141 |
+
} else {
|
142 |
+
SwpmUtils::account_delete_confirmation_ui( SwpmUtils::_( "Sorry, Password didn't match." ) );
|
143 |
+
}
|
144 |
+
}
|
145 |
+
|
146 |
+
public function process_password_reset() {
|
147 |
+
$message = '';
|
148 |
+
$swpm_reset = filter_input( INPUT_POST, 'swpm-reset' );
|
149 |
+
$swpm_reset_email = filter_input( INPUT_POST, 'swpm_reset_email', FILTER_UNSAFE_RAW );
|
150 |
+
if ( ! empty( $swpm_reset ) ) {
|
151 |
+
SwpmFrontRegistration::get_instance()->reset_password( $swpm_reset_email );
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
private function register_member() {
|
156 |
+
$registration = filter_input( INPUT_POST, 'swpm_registration_submit' );
|
157 |
+
if ( ! empty( $registration ) ) {
|
158 |
+
SwpmFrontRegistration::get_instance()->register_front_end();
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
private function check_and_do_email_activation() {
|
163 |
+
$email_activation = filter_input( INPUT_GET, 'swpm_email_activation', FILTER_SANITIZE_NUMBER_INT );
|
164 |
+
if ( ! empty( $email_activation ) ) {
|
165 |
+
SwpmFrontRegistration::get_instance()->email_activation();
|
166 |
+
}
|
167 |
+
//also check activation email resend request
|
168 |
+
$email_activation_resend = filter_input( INPUT_GET, 'swpm_resend_activation_email', FILTER_SANITIZE_NUMBER_INT );
|
169 |
+
if ( ! empty( $email_activation_resend ) ) {
|
170 |
+
SwpmFrontRegistration::get_instance()->resend_activation_email();
|
171 |
+
}
|
172 |
+
}
|
173 |
+
|
174 |
+
private function edit_profile() {
|
175 |
+
$swpm_editprofile_submit = filter_input( INPUT_POST, 'swpm_editprofile_submit' );
|
176 |
+
if ( ! empty( $swpm_editprofile_submit ) ) {
|
177 |
+
SwpmFrontRegistration::get_instance()->edit_profile_front_end();
|
178 |
+
//TODO - allow an option to do a redirect if successful edit profile form submission?
|
179 |
+
}
|
180 |
+
}
|
181 |
+
|
182 |
+
public function check_and_handle_auto_login() {
|
183 |
+
|
184 |
+
if ( isset( $_REQUEST['swpm_auto_login'] ) && $_REQUEST['swpm_auto_login'] == '1' ) {
|
185 |
+
//Handle the auto login
|
186 |
+
SwpmLog::log_simple_debug( 'Handling auto login request...', true );
|
187 |
+
|
188 |
+
$enable_auto_login = SwpmSettings::get_instance()->get_value( 'auto-login-after-rego' );
|
189 |
+
if ( empty( $enable_auto_login ) ) {
|
190 |
+
SwpmLog::log_simple_debug( 'Auto login after registration feature is disabled in settings.', true );
|
191 |
+
return;
|
192 |
+
}
|
193 |
+
|
194 |
+
//Check auto login nonce value
|
195 |
+
$auto_login_nonce = isset( $_REQUEST['swpm_auto_login_nonce'] ) ? $_REQUEST['swpm_auto_login_nonce'] : '';
|
196 |
+
if ( ! wp_verify_nonce( $auto_login_nonce, 'swpm-auto-login-nonce' ) ) {
|
197 |
+
SwpmLog::log_simple_debug( 'Error! Auto login nonce verification check failed!', false );
|
198 |
+
wp_die( 'Auto login nonce verification check failed!' );
|
199 |
+
}
|
200 |
+
|
201 |
+
//Perform the login
|
202 |
+
$auth = SwpmAuth::get_instance();
|
203 |
+
$user = apply_filters( 'swpm_user_name', filter_input( INPUT_GET, 'swpm_user_name' ) );
|
204 |
+
$user = sanitize_user( $user );
|
205 |
+
$encoded_pass = filter_input( INPUT_GET, 'swpm_encoded_pw' );
|
206 |
+
$pass = base64_decode( $encoded_pass );
|
207 |
+
$auth->login( $user, $pass );
|
208 |
+
SwpmLog::log_simple_debug( 'Auto login request completed for: ' . $user, true );
|
209 |
+
}
|
210 |
+
}
|
211 |
+
|
212 |
+
}
|
classes/class.swpm-members.php
CHANGED
@@ -1,674 +1,766 @@
|
|
1 |
<?php
|
2 |
-
if (!class_exists('WP_List_Table')) {
|
3 |
-
|
4 |
}
|
5 |
|
6 |
class SwpmMembers extends WP_List_Table {
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
+
if ( ! class_exists( 'WP_List_Table' ) ) {
|
3 |
+
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
|
4 |
}
|
5 |
|
6 |
class SwpmMembers extends WP_List_Table {
|
7 |
|
8 |
+
function __construct() {
|
9 |
+
parent::__construct(
|
10 |
+
array(
|
11 |
+
'singular' => SwpmUtils::_( 'Member' ),
|
12 |
+
'plural' => SwpmUtils::_( 'Members' ),
|
13 |
+
'ajax' => false,
|
14 |
+
)
|
15 |
+
);
|
16 |
+
}
|
17 |
+
|
18 |
+
function get_columns() {
|
19 |
+
return array(
|
20 |
+
'cb' => '<input type="checkbox" />',
|
21 |
+
'member_id' => SwpmUtils::_( 'ID' ),
|
22 |
+
'user_name' => SwpmUtils::_( 'Username' ),
|
23 |
+
'first_name' => SwpmUtils::_( 'First Name' ),
|
24 |
+
'last_name' => SwpmUtils::_( 'Last Name' ),
|
25 |
+
'email' => SwpmUtils::_( 'Email' ),
|
26 |
+
'alias' => SwpmUtils::_( 'Membership Level' ),
|
27 |
+
'subscription_starts' => SwpmUtils::_( 'Access Starts' ),
|
28 |
+
'account_state' => SwpmUtils::_( 'Account State' ),
|
29 |
+
'last_accessed' => SwpmUtils::_( 'Last Login Date' ),
|
30 |
+
);
|
31 |
+
}
|
32 |
+
|
33 |
+
function get_sortable_columns() {
|
34 |
+
return array(
|
35 |
+
'member_id' => array( 'member_id', true ), //True means already sorted
|
36 |
+
'user_name' => array( 'user_name', false ),
|
37 |
+
'first_name' => array( 'first_name', false ),
|
38 |
+
'last_name' => array( 'last_name', false ),
|
39 |
+
'email' => array( 'email', false ),
|
40 |
+
'alias' => array( 'alias', false ),
|
41 |
+
'account_state' => array( 'account_state', false ),
|
42 |
+
'last_accessed' => array( 'last_accessed', false ),
|
43 |
+
);
|
44 |
+
}
|
45 |
+
|
46 |
+
function get_bulk_actions() {
|
47 |
+
$actions = array(
|
48 |
+
'bulk_delete' => SwpmUtils::_( 'Delete' ),
|
49 |
+
'bulk_active' => SwpmUtils::_( 'Set Status to Active' ),
|
50 |
+
'bulk_active_notify' => SwpmUtils::_( 'Set Status to Active and Notify' ),
|
51 |
+
'bulk_inactive' => SwpmUtils::_( 'Set Status to Inactive' ),
|
52 |
+
'bulk_pending' => SwpmUtils::_( 'Set Status to Pending' ),
|
53 |
+
'bulk_expired' => SwpmUtils::_( 'Set Status to Expired' ),
|
54 |
+
);
|
55 |
+
return $actions;
|
56 |
+
}
|
57 |
+
|
58 |
+
function column_default( $item, $column_name ) {
|
59 |
+
return $item[ $column_name ];
|
60 |
+
}
|
61 |
+
|
62 |
+
function column_account_state( $item ) {
|
63 |
+
$acc_state_str = ucfirst( $item['account_state'] );
|
64 |
+
return SwpmUtils::_( $acc_state_str );
|
65 |
+
}
|
66 |
+
|
67 |
+
function column_member_id( $item ) {
|
68 |
+
$delete_swpmuser_nonce = wp_create_nonce( 'delete_swpmuser_admin_end' );
|
69 |
+
$actions = array(
|
70 |
+
'edit' => sprintf( '<a href="admin.php?page=simple_wp_membership&member_action=edit&member_id=%s">Edit</a>', $item['member_id'] ),
|
71 |
+
'delete' => sprintf( '<a href="admin.php?page=simple_wp_membership&member_action=delete&member_id=%s&delete_swpmuser_nonce=%s" onclick="return confirm(\'Are you sure you want to delete this entry?\')">Delete</a>', $item['member_id'], $delete_swpmuser_nonce ),
|
72 |
+
);
|
73 |
+
return $item['member_id'] . $this->row_actions( $actions );
|
74 |
+
}
|
75 |
+
|
76 |
+
function column_user_name( $item ) {
|
77 |
+
$user_name = $item['user_name'];
|
78 |
+
if ( empty( $user_name ) ) {
|
79 |
+
$user_name = '[' . SwpmUtils::_( 'incomplete' ) . ']';
|
80 |
+
}
|
81 |
+
return $user_name;
|
82 |
+
}
|
83 |
+
|
84 |
+
function column_cb( $item ) {
|
85 |
+
return sprintf(
|
86 |
+
'<input type="checkbox" name="members[]" value="%s" />',
|
87 |
+
$item['member_id']
|
88 |
+
);
|
89 |
+
}
|
90 |
+
|
91 |
+
function prepare_items() {
|
92 |
+
global $wpdb;
|
93 |
+
|
94 |
+
$this->process_bulk_action();
|
95 |
+
|
96 |
+
$query = 'SELECT * FROM ' . $wpdb->prefix . 'swpm_members_tbl';
|
97 |
+
$query .= ' LEFT JOIN ' . $wpdb->prefix . 'swpm_membership_tbl';
|
98 |
+
$query .= ' ON ( membership_level = id ) ';
|
99 |
+
|
100 |
+
//Get the search string (if any)
|
101 |
+
$s = filter_input( INPUT_GET, 's' );
|
102 |
+
if ( empty( $s ) ) {
|
103 |
+
$s = filter_input( INPUT_POST, 's' );
|
104 |
+
}
|
105 |
+
|
106 |
+
$status = filter_input( INPUT_GET, 'status' );
|
107 |
+
$filters = array();
|
108 |
+
|
109 |
+
//Add the search parameter to the query
|
110 |
+
if ( ! empty( $s ) ) {
|
111 |
+
$s = sanitize_text_field( $s );
|
112 |
+
$s = trim( $s ); //Trim the input
|
113 |
+
$filters[] = "( user_name LIKE '%" . strip_tags( $s ) . "%' "
|
114 |
+
. " OR first_name LIKE '%" . strip_tags( $s ) . "%' "
|
115 |
+
. " OR last_name LIKE '%" . strip_tags( $s ) . "%' "
|
116 |
+
. " OR email LIKE '%" . strip_tags( $s ) . "%' "
|
117 |
+
. " OR address_city LIKE '%" . strip_tags( $s ) . "%' "
|
118 |
+
. " OR address_state LIKE '%" . strip_tags( $s ) . "%' "
|
119 |
+
. " OR country LIKE '%" . strip_tags( $s ) . "%' "
|
120 |
+
. " OR company_name LIKE '%" . strip_tags( $s ) . "%' )";
|
121 |
+
}
|
122 |
+
|
123 |
+
//Add account status filtering to the query
|
124 |
+
if ( ! empty( $status ) ) {
|
125 |
+
if ( $status == 'incomplete' ) {
|
126 |
+
$filters[] = "user_name = ''";
|
127 |
+
} else {
|
128 |
+
$filters[] = "account_state = '" . $status . "'";
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
//Add membership level filtering
|
133 |
+
$membership_level = filter_input( INPUT_GET, 'membership_level', FILTER_SANITIZE_NUMBER_INT );
|
134 |
+
|
135 |
+
if ( ! empty( $membership_level ) ) {
|
136 |
+
$filters[] = sprintf( "membership_level = '%d'", $membership_level );
|
137 |
+
}
|
138 |
+
|
139 |
+
//Build the WHERE clause of the query string
|
140 |
+
if ( ! empty( $filters ) ) {
|
141 |
+
$filter_str = '';
|
142 |
+
foreach ( $filters as $ind => $filter ) {
|
143 |
+
$filter_str .= $ind === 0 ? $filter : ' AND ' . $filter;
|
144 |
+
}
|
145 |
+
$query .= 'WHERE ' . $filter_str;
|
146 |
+
}
|
147 |
+
|
148 |
+
//Build the orderby and order query parameters
|
149 |
+
$orderby = filter_input( INPUT_GET, 'orderby' );
|
150 |
+
$orderby = empty( $orderby ) ? 'member_id' : $orderby;
|
151 |
+
$order = filter_input( INPUT_GET, 'order' );
|
152 |
+
$order = empty( $order ) ? 'DESC' : $order;
|
153 |
+
$sortable_columns = $this->get_sortable_columns();
|
154 |
+
$orderby = SwpmUtils::sanitize_value_by_array( $orderby, $sortable_columns );
|
155 |
+
$order = SwpmUtils::sanitize_value_by_array(
|
156 |
+
$order,
|
157 |
+
array(
|
158 |
+
'DESC' => '1',
|
159 |
+
'ASC' => '1',
|
160 |
+
)
|
161 |
+
);
|
162 |
+
$query .= ' ORDER BY ' . $orderby . ' ' . $order;
|
163 |
+
|
164 |
+
//Execute the query
|
165 |
+
$totalitems = $wpdb->query( $query ); //return the total number of affected rows
|
166 |
+
//Pagination setup
|
167 |
+
$perpage = apply_filters( 'swpm_members_menu_items_per_page', 50 );
|
168 |
+
$paged = filter_input( INPUT_GET, 'paged' );
|
169 |
+
if ( empty( $paged ) || ! is_numeric( $paged ) || $paged <= 0 ) {
|
170 |
+
$paged = 1;
|
171 |
+
}
|
172 |
+
$totalpages = ceil( $totalitems / $perpage );
|
173 |
+
if ( ! empty( $paged ) && ! empty( $perpage ) ) {
|
174 |
+
$offset = ( $paged - 1 ) * $perpage;
|
175 |
+
$query .= ' LIMIT ' . (int) $offset . ',' . (int) $perpage;
|
176 |
+
}
|
177 |
+
$this->set_pagination_args(
|
178 |
+
array(
|
179 |
+
'total_items' => $totalitems,
|
180 |
+
'total_pages' => $totalpages,
|
181 |
+
'per_page' => $perpage,
|
182 |
+
)
|
183 |
+
);
|
184 |
+
|
185 |
+
$columns = $this->get_columns();
|
186 |
+
$hidden = array();
|
187 |
+
$sortable = $this->get_sortable_columns();
|
188 |
+
|
189 |
+
$this->_column_headers = array( $columns, $hidden, $sortable );
|
190 |
+
$this->items = $wpdb->get_results( $query, ARRAY_A );
|
191 |
+
}
|
192 |
+
|
193 |
+
function get_user_count_by_account_state() {
|
194 |
+
global $wpdb;
|
195 |
+
$query = 'SELECT count(member_id) AS count, account_state FROM ' . $wpdb->prefix . 'swpm_members_tbl GROUP BY account_state';
|
196 |
+
$result = $wpdb->get_results( $query, ARRAY_A );
|
197 |
+
$count = array();
|
198 |
+
|
199 |
+
$all = 0;
|
200 |
+
foreach ( $result as $row ) {
|
201 |
+
$count[ $row['account_state'] ] = $row['count'];
|
202 |
+
$all += intval( $row['count'] );
|
203 |
+
}
|
204 |
+
$count ['all'] = $all;
|
205 |
+
|
206 |
+
$count_incomplete_query = 'SELECT COUNT(*) FROM ' . $wpdb->prefix . "swpm_members_tbl WHERE user_name = ''";
|
207 |
+
$count['incomplete'] = $wpdb->get_var( $count_incomplete_query );
|
208 |
+
|
209 |
+
return $count;
|
210 |
+
}
|
211 |
+
|
212 |
+
function no_items() {
|
213 |
+
_e( 'No member found.', 'simple-membership' );
|
214 |
+
}
|
215 |
+
|
216 |
+
function process_form_request() {
|
217 |
+
if ( isset( $_REQUEST['member_id'] ) ) {
|
218 |
+
//This is a member profile edit action
|
219 |
+
$record_id = sanitize_text_field( $_REQUEST['member_id'] );
|
220 |
+
if ( ! is_numeric( $record_id ) ) {
|
221 |
+
wp_die( 'Error! ID must be numeric.' );
|
222 |
+
}
|
223 |
+
return $this->edit( absint( $record_id ) );
|
224 |
+
}
|
225 |
+
|
226 |
+
//This is an profile add action.
|
227 |
+
return $this->add();
|
228 |
+
}
|
229 |
+
|
230 |
+
function add() {
|
231 |
+
$form = apply_filters( 'swpm_admin_registration_form_override', '' );
|
232 |
+
if ( ! empty( $form ) ) {
|
233 |
+
echo $form;
|
234 |
+
return;
|
235 |
+
}
|
236 |
+
global $wpdb;
|
237 |
+
$member = SwpmTransfer::$default_fields;
|
238 |
+
$member['member_since'] = date( 'Y-m-d' );
|
239 |
+
$member['subscription_starts'] = date( 'Y-m-d' );
|
240 |
+
if ( isset( $_POST['createswpmuser'] ) ) {
|
241 |
+
$member = array_map( 'sanitize_text_field', $_POST );
|
242 |
+
}
|
243 |
+
extract( $member, EXTR_SKIP );
|
244 |
+
$query = 'SELECT * FROM ' . $wpdb->prefix . 'swpm_membership_tbl WHERE id !=1 ';
|
245 |
+
$levels = $wpdb->get_results( $query, ARRAY_A );
|
246 |
+
include_once SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_add.php';
|
247 |
+
return false;
|
248 |
+
}
|
249 |
+
|
250 |
+
function edit( $id ) {
|
251 |
+
global $wpdb;
|
252 |
+
$id = absint( $id );
|
253 |
+
$query = "SELECT * FROM {$wpdb->prefix}swpm_members_tbl WHERE member_id = $id";
|
254 |
+
$member = $wpdb->get_row( $query, ARRAY_A );
|
255 |
+
if ( isset( $_POST['editswpmuser'] ) ) {
|
256 |
+
$_POST['user_name'] = sanitize_text_field( $member['user_name'] );
|
257 |
+
$_POST['email'] = sanitize_email( $member['email'] );
|
258 |
+
foreach ( $_POST as $key => $value ) {
|
259 |
+
$key = sanitize_text_field( $key );
|
260 |
+
if ( $key == 'email' ) {
|
261 |
+
$member[ $key ] = sanitize_email( $value );
|
262 |
+
} else {
|
263 |
+
$member[ $key ] = sanitize_text_field( $value );
|
264 |
+
}
|
265 |
+
}
|
266 |
+
}
|
267 |
+
extract( $member, EXTR_SKIP );
|
268 |
+
$query = 'SELECT * FROM ' . $wpdb->prefix . 'swpm_membership_tbl WHERE id !=1 ';
|
269 |
+
$levels = $wpdb->get_results( $query, ARRAY_A );
|
270 |
+
include_once SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_edit.php';
|
271 |
+
return false;
|
272 |
+
}
|
273 |
+
|
274 |
+
function process_bulk_action() {
|
275 |
+
//Detect when a bulk action is being triggered... then perform the action.
|
276 |
+
$members = isset( $_REQUEST['members'] ) ? $_REQUEST['members'] : array();
|
277 |
+
$members = array_map( 'sanitize_text_field', $members );
|
278 |
+
|
279 |
+
$current_action = $this->current_action();
|
280 |
+
if ( ! empty( $current_action ) ) {
|
281 |
+
//Bulk operation action. Lets make sure multiple records were selected before going ahead.
|
282 |
+
if ( empty( $members ) ) {
|
283 |
+
echo '<div id="message" class="error"><p>Error! You need to select multiple records to perform a bulk action!</p></div>';
|
284 |
+
return;
|
285 |
+
}
|
286 |
+
} else {
|
287 |
+
//No bulk operation.
|
288 |
+
return;
|
289 |
+
}
|
290 |
+
|
291 |
+
//perform the bulk operation according to the selection
|
292 |
+
if ( 'bulk_delete' === $current_action ) {
|
293 |
+
foreach ( $members as $record_id ) {
|
294 |
+
if ( ! is_numeric( $record_id ) ) {
|
295 |
+
wp_die( 'Error! ID must be numeric.' );
|
296 |
+
}
|
297 |
+
self::delete_user_by_id( $record_id );
|
298 |
+
}
|
299 |
+
echo '<div id="message" class="updated fade"><p>Selected records deleted successfully!</p></div>';
|
300 |
+
return;
|
301 |
+
} elseif ( 'bulk_active' === $current_action ) {
|
302 |
+
$this->bulk_set_status( $members, 'active' );
|
303 |
+
} elseif ( 'bulk_active_notify' == $current_action ) {
|
304 |
+
$this->bulk_set_status( $members, 'active', true );
|
305 |
+
} elseif ( 'bulk_inactive' == $current_action ) {
|
306 |
+
$this->bulk_set_status( $members, 'inactive' );
|
307 |
+
} elseif ( 'bulk_pending' == $current_action ) {
|
308 |
+
$this->bulk_set_status( $members, 'pending' );
|
309 |
+
} elseif ( 'bulk_expired' == $current_action ) {
|
310 |
+
$this->bulk_set_status( $members, 'expired' );
|
311 |
+
}
|
312 |
+
|
313 |
+
echo '<div id="message" class="updated fade"><p>Bulk operation completed successfully!</p></div>';
|
314 |
+
}
|
315 |
+
|
316 |
+
function bulk_set_status( $members, $status, $notify = false ) {
|
317 |
+
$ids = implode( ',', array_map( 'absint', $members ) );
|
318 |
+
if ( empty( $ids ) ) {
|
319 |
+
return;
|
320 |
+
}
|
321 |
+
global $wpdb;
|
322 |
+
$query = 'UPDATE ' . $wpdb->prefix . 'swpm_members_tbl ' .
|
323 |
+
" SET account_state = '" . $status . "' WHERE member_id in (" . $ids . ')';
|
324 |
+
$wpdb->query( $query );
|
325 |
+
|
326 |
+
if ( $notify ) {
|
327 |
+
$settings = SwpmSettings::get_instance();
|
328 |
+
|
329 |
+
$emails = $wpdb->get_col( 'SELECT email FROM ' . $wpdb->prefix . 'swpm_members_tbl ' . " WHERE member_id IN ( $ids ) " );
|
330 |
+
|
331 |
+
$subject = $settings->get_value( 'bulk-activate-notify-mail-subject' );
|
332 |
+
if ( empty( $subject ) ) {
|
333 |
+
$subject = 'Account Activated!';
|
334 |
+
}
|
335 |
+
$body = $settings->get_value( 'bulk-activate-notify-mail-body' );
|
336 |
+
if ( empty( $body ) ) {
|
337 |
+
$body = 'Hi, Your account has been activated successfully!';
|
338 |
+
}
|
339 |
+
|
340 |
+
$from_address = $settings->get_value( 'email-from' );
|
341 |
+
$to_email_list = implode( ',', $emails );
|
342 |
+
$headers = 'From: ' . $from_address . "\r\n";
|
343 |
+
$headers .= 'bcc: ' . $to_email_list . "\r\n";
|
344 |
+
$subject = apply_filters( 'swpm_email_bulk_set_status_subject', $subject );
|
345 |
+
$body = apply_filters( 'swpm_email_bulk_set_status_body', $body );
|
346 |
+
SwpmMiscUtils::mail( array()/* $email_list */, $subject, $body, $headers );
|
347 |
+
SwpmLog::log_simple_debug( 'Bulk activation email notification sent. Activation email sent to the following email: ' . $to_email_list, true );
|
348 |
+
}
|
349 |
+
}
|
350 |
+
|
351 |
+
function delete() {
|
352 |
+
if ( isset( $_REQUEST['member_id'] ) ) {
|
353 |
+
//Check we are on the admin end and user has management permission
|
354 |
+
SwpmMiscUtils::check_user_permission_and_is_admin( 'member deletion by admin' );
|
355 |
+
|
356 |
+
//Check nonce
|
357 |
+
if ( ! isset( $_REQUEST['delete_swpmuser_nonce'] ) || ! wp_verify_nonce( $_REQUEST['delete_swpmuser_nonce'], 'delete_swpmuser_admin_end' ) ) {
|
358 |
+
//Nonce check failed.
|
359 |
+
wp_die( SwpmUtils::_( 'Error! Nonce verification failed for user delete from admin end.' ) );
|
360 |
+
}
|
361 |
+
|
362 |
+
$id = sanitize_text_field( $_REQUEST['member_id'] );
|
363 |
+
$id = absint( $id );
|
364 |
+
self::delete_user_by_id( $id );
|
365 |
+
}
|
366 |
+
}
|
367 |
+
|
368 |
+
public static function delete_user_by_id( $id ) {
|
369 |
+
if ( ! is_numeric( $id ) ) {
|
370 |
+
wp_die( 'Error! Member ID must be numeric.' );
|
371 |
+
}
|
372 |
+
$swpm_user = SwpmMemberUtils::get_user_by_id( $id );
|
373 |
+
$user_name = $swpm_user->user_name;
|
374 |
+
self::delete_wp_user( $user_name ); //Deletes the WP User record
|
375 |
+
self::delete_swpm_user_by_id( $id ); //Deletes the SWPM record
|
376 |
+
}
|
377 |
+
|
378 |
+
public static function delete_swpm_user_by_id( $id ) {
|
379 |
+
self::delete_user_subs( $id );
|
380 |
+
global $wpdb;
|
381 |
+
$query = 'DELETE FROM ' . $wpdb->prefix . "swpm_members_tbl WHERE member_id = $id";
|
382 |
+
$wpdb->query( $query );
|
383 |
+
}
|
384 |
+
|
385 |
+
public static function delete_wp_user( $user_name ) {
|
386 |
+
$wp_user_id = username_exists( $user_name );
|
387 |
+
if ( empty( $wp_user_id ) || ! is_numeric( $wp_user_id ) ) {
|
388 |
+
return;
|
389 |
+
}
|
390 |
+
|
391 |
+
if ( ! self::is_wp_super_user( $wp_user_id ) ) {
|
392 |
+
//Not an admin user so it is safe to delete this user.
|
393 |
+
include_once ABSPATH . 'wp-admin/includes/user.php';
|
394 |
+
wp_delete_user( $wp_user_id, 1 ); //assigns all related to this user to admin.
|
395 |
+
} else {
|
396 |
+
//This is an admin user. So not going to delete the WP User record.
|
397 |
+
SwpmTransfer::get_instance()->set( 'status', 'For safety, we do not allow deletion of any associated WordPress account with administrator role.' );
|
398 |
+
return;
|
399 |
+
}
|
400 |
+
}
|
401 |
+
|
402 |
+
private static function delete_user_subs( $id ) {
|
403 |
+
$member = SwpmMemberUtils::get_user_by_id( $id );
|
404 |
+
if ( ! $member ) {
|
405 |
+
return false;
|
406 |
+
}
|
407 |
+
// let's check if Stripe subscription needs to be cancelled
|
408 |
+
global $wpdb;
|
409 |
+
$q = $wpdb->prepare(
|
410 |
+
'SELECT *
|
411 |
+
FROM `' . $wpdb->prefix . 'swpm_payments_tbl`
|
412 |
+
WHERE email = %s
|
413 |
+
AND (gateway = "stripe" OR gateway = "stripe-sca-subs")
|
414 |
+
AND subscr_id != ""',
|
415 |
+
array( $member->email )
|
416 |
+
);
|
417 |
+
|
418 |
+
$res = $wpdb->get_results( $q, ARRAY_A );
|
419 |
+
|
420 |
+
if ( ! $res ) {
|
421 |
+
return false;
|
422 |
+
}
|
423 |
+
|
424 |
+
foreach ( $res as $sub ) {
|
425 |
+
|
426 |
+
if ( substr( $sub['subscr_id'], 0, 4 ) !== 'sub_' ) {
|
427 |
+
//not Stripe subscription
|
428 |
+
continue;
|
429 |
+
}
|
430 |
+
|
431 |
+
//let's find the payment button
|
432 |
+
$q = $wpdb->prepare( "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key='subscr_id' AND meta_value=%s", $sub['subscr_id'] );
|
433 |
+
$res_post = $wpdb->get_row( $q );
|
434 |
+
|
435 |
+
if ( ! $res_post ) {
|
436 |
+
//no button found
|
437 |
+
continue;
|
438 |
+
}
|
439 |
+
|
440 |
+
$button_id = get_post_meta( $res_post->post_id, 'payment_button_id', true );
|
441 |
+
|
442 |
+
$button = get_post( $button_id );
|
443 |
+
|
444 |
+
if ( ! $button ) {
|
445 |
+
//no button found
|
446 |
+
continue;
|
447 |
+
}
|
448 |
+
|
449 |
+
SwpmLog::log_simple_debug( 'Attempting to cancel Stripe Subscription ' . $sub['subscr_id'], true );
|
450 |
+
|
451 |
+
$is_live = get_post_meta( $button_id, 'is_live', true );
|
452 |
+
if ( $is_live ) {
|
453 |
+
SwpmLog::log_simple_debug( 'Payment was made in live mode. Using test API key details.', true );
|
454 |
+
$secret_key = get_post_meta( $button_id, 'stripe_live_secret_key', true ); //Use live API key
|
455 |
+
} else {
|
456 |
+
SwpmLog::log_simple_debug( 'Payment was made in sandbox mode. Using test API key details.', true );
|
457 |
+
$secret_key = get_post_meta( $button_id, 'stripe_test_secret_key', true ); //Use sandbox API key
|
458 |
+
}
|
459 |
+
//Include the Stripe library.
|
460 |
+
SwpmMiscUtils::load_stripe_lib();
|
461 |
+
|
462 |
+
\Stripe\Stripe::setApiKey( $secret_key );
|
463 |
+
|
464 |
+
$error = null;
|
465 |
+
// Let's try to cancel subscription
|
466 |
+
try {
|
467 |
+
$sub = \Stripe\Subscription::retrieve( $sub['subscr_id'] );
|
468 |
+
$sub->cancel();
|
469 |
+
} catch ( Exception $e ) {
|
470 |
+
SwpmLog::log_simple_debug( 'Error occurred during Stripe Subscription cancellation. ' . $e->getMessage(), false );
|
471 |
+
$body = $e->getJsonBody();
|
472 |
+
$error = $body['error'];
|
473 |
+
$error_string = wp_json_encode( $error );
|
474 |
+
SwpmLog::log_simple_debug( 'Error details: ' . $error_string, false );
|
475 |
+
}
|
476 |
+
if ( ! isset( $error ) ) {
|
477 |
+
SwpmLog::log_simple_debug( 'Stripe Subscription has been cancelled.', true );
|
478 |
+
}
|
479 |
+
}
|
480 |
+
}
|
481 |
+
|
482 |
+
public static function is_wp_super_user( $wp_user_id ) {
|
483 |
+
$user_data = get_userdata( $wp_user_id );
|
484 |
+
if ( empty( $user_data ) ) {
|
485 |
+
//Not an admin user if we can't find his data for the given ID.
|
486 |
+
return false;
|
487 |
+
}
|
488 |
+
if ( isset( $user_data->wp_capabilities['administrator'] ) ) {//Check capability
|
489 |
+
//admin user
|
490 |
+
return true;
|
491 |
+
}
|
492 |
+
if ( $user_data->wp_user_level == 10 ) {//Check for old style wp user level
|
493 |
+
//admin user
|
494 |
+
return true;
|
495 |
+
}
|
496 |
+
//This is not an admin user
|
497 |
+
return false;
|
498 |
+
}
|
499 |
+
|
500 |
+
function bulk_operation_menu() {
|
501 |
+
echo '<div id="poststuff"><div id="post-body">';
|
502 |
+
|
503 |
+
if ( isset( $_REQUEST['swpm_bulk_change_level_process'] ) ) {
|
504 |
+
//Check nonce
|
505 |
+
$swpm_bulk_change_level_nonce = filter_input( INPUT_POST, 'swpm_bulk_change_level_nonce' );
|
506 |
+
if ( ! wp_verify_nonce( $swpm_bulk_change_level_nonce, 'swpm_bulk_change_level_nonce_action' ) ) {
|
507 |
+
//Nonce check failed.
|
508 |
+
wp_die( SwpmUtils::_( 'Error! Nonce security verification failed for Bulk Change Membership Level action. Clear cache and try again.' ) );
|
509 |
+
}
|
510 |
+
|
511 |
+
$errorMsg = '';
|
512 |
+
$from_level_id = sanitize_text_field( $_REQUEST['swpm_bulk_change_level_from'] );
|
513 |
+
$to_level_id = sanitize_text_field( $_REQUEST['swpm_bulk_change_level_to'] );
|
514 |
+
|
515 |
+
if ( $from_level_id == 'please_select' || $to_level_id == 'please_select' ) {
|
516 |
+
$errorMsg = SwpmUtils::_( 'Error! Please select a membership level first.' );
|
517 |
+
}
|
518 |
+
|
519 |
+
if ( empty( $errorMsg ) ) {//No validation errors so go ahead
|
520 |
+
$member_records = SwpmMemberUtils::get_all_members_of_a_level( $from_level_id );
|
521 |
+
if ( $member_records ) {
|
522 |
+
foreach ( $member_records as $row ) {
|
523 |
+
$member_id = $row->member_id;
|
524 |
+
SwpmMemberUtils::update_membership_level( $member_id, $to_level_id );
|
525 |
+
}
|
526 |
+
}
|
527 |
+
}
|
528 |
+
|
529 |
+
$message = '';
|
530 |
+
if ( ! empty( $errorMsg ) ) {
|
531 |
+
$message = $errorMsg;
|
532 |
+
} else {
|
533 |
+
$message = SwpmUtils::_( 'Membership level change operation completed successfully.' );
|
534 |
+
}
|
535 |
+
echo '<div id="message" class="updated fade"><p><strong>';
|
536 |
+
echo $message;
|
537 |
+
echo '</strong></p></div>';
|
538 |
+
}
|
539 |
+
|
540 |
+
if ( isset( $_REQUEST['swpm_bulk_user_start_date_change_process'] ) ) {
|
541 |
+
//Check nonce
|
542 |
+
$swpm_bulk_start_date_nonce = filter_input( INPUT_POST, 'swpm_bulk_start_date_nonce' );
|
543 |
+
if ( ! wp_verify_nonce( $swpm_bulk_start_date_nonce, 'swpm_bulk_start_date_nonce_action' ) ) {
|
544 |
+
//Nonce check failed.
|
545 |
+
wp_die( SwpmUtils::_( 'Error! Nonce security verification failed for Bulk Change Access Starts Date action. Clear cache and try again.' ) );
|
546 |
+
}
|
547 |
+
|
548 |
+
$errorMsg = '';
|
549 |
+
$level_id = sanitize_text_field( $_REQUEST['swpm_bulk_user_start_date_change_level'] );
|
550 |
+
$new_date = sanitize_text_field( $_REQUEST['swpm_bulk_user_start_date_change_date'] );
|
551 |
+
|
552 |
+
if ( $level_id == 'please_select' ) {
|
553 |
+
$errorMsg = SwpmUtils::_( 'Error! Please select a membership level first.' );
|
554 |
+
}
|
555 |
+
|
556 |
+
if ( empty( $errorMsg ) ) {//No validation errors so go ahead
|
557 |
+
$member_records = SwpmMemberUtils::get_all_members_of_a_level( $level_id );
|
558 |
+
if ( $member_records ) {
|
559 |
+
foreach ( $member_records as $row ) {
|
560 |
+
$member_id = $row->member_id;
|
561 |
+
SwpmMemberUtils::update_access_starts_date( $member_id, $new_date );
|
562 |
+
}
|
563 |
+
}
|
564 |
+
}
|
565 |
+
|
566 |
+
$message = '';
|
567 |
+
if ( ! empty( $errorMsg ) ) {
|
568 |
+
$message = $errorMsg;
|
569 |
+
} else {
|
570 |
+
$message = SwpmUtils::_( 'Access starts date change operation successfully completed.' );
|
571 |
+
}
|
572 |
+
echo '<div id="message" class="updated fade"><p><strong>';
|
573 |
+
echo $message;
|
574 |
+
echo '</strong></p></div>';
|
575 |
+
}
|
576 |
+
?>
|
577 |
+
|
578 |
+
<div class="postbox">
|
579 |
+
<h3 class="hndle"><label for="title"><?php SwpmUtils::e( 'Bulk Update Membership Level of Members' ); ?></label></h3>
|
580 |
+
<div class="inside">
|
581 |
+
<p>
|
582 |
+
<?php SwpmUtils::e( 'You can manually change the membership level of any member by editing the record from the members menu. ' ); ?>
|
583 |
+
<?php SwpmUtils::e( 'You can use the following option to bulk update the membership level of users who belong to the level you select below.' ); ?>
|
584 |
+
</p>
|
585 |
+
<form method="post" action="">
|
586 |
+
<input type="hidden" name="swpm_bulk_change_level_nonce" value="<?php echo wp_create_nonce( 'swpm_bulk_change_level_nonce_action' ); ?>" />
|
587 |
+
|
588 |
+
<table width="100%" border="0" cellspacing="0" cellpadding="6">
|
589 |
+
<tr valign="top">
|
590 |
+
<td width="25%" align="left">
|
591 |
+
<strong><?php SwpmUtils::e( 'Membership Level: ' ); ?></strong>
|
592 |
+
</td>
|
593 |
+
<td align="left">
|
594 |
+
<select name="swpm_bulk_change_level_from">
|
595 |
+
<option value="please_select"><?php SwpmUtils::e( 'Select Current Level' ); ?></option>
|
596 |
+
<?php echo SwpmUtils::membership_level_dropdown(); ?>
|
597 |
+
</select>
|
598 |
+
<p class="description"><?php SwpmUtils::e( 'Select the current membership level (the membership level of all members who are in this level will be updated).' ); ?></p>
|
599 |
+
</td>
|
600 |
+
</tr>
|
601 |
+
|
602 |
+
<tr valign="top">
|
603 |
+
<td width="25%" align="left">
|
604 |
+
<strong><?php SwpmUtils::e( 'Level to Change to: ' ); ?></strong>
|
605 |
+
</td>
|
606 |
+
<td align="left">
|
607 |
+
<select name="swpm_bulk_change_level_to">
|
608 |
+
<option value="please_select"><?php SwpmUtils::e( 'Select Target Level' ); ?></option>
|
609 |
+
<?php echo SwpmUtils::membership_level_dropdown(); ?>
|
610 |
+
</select>
|
611 |
+
<p class="description"><?php SwpmUtils::e( 'Select the new membership level.' ); ?></p>
|
612 |
+
</td>
|
613 |
+
</tr>
|
614 |
+
|
615 |
+
<tr valign="top">
|
616 |
+
<td width="25%" align="left">
|
617 |
+
<input type="submit" class="button" name="swpm_bulk_change_level_process" value="<?php SwpmUtils::e( 'Bulk Change Membership Level' ); ?>" />
|
618 |
+
</td>
|
619 |
+
<td align="left"></td>
|
620 |
+
</tr>
|
621 |
+
|
622 |
+
</table>
|
623 |
+
</form>
|
624 |
+
</div></div>
|
625 |
+
|
626 |
+
<div class="postbox">
|
627 |
+
<h3 class="hndle"><label for="title"><?php SwpmUtils::e( 'Bulk Update Access Starts Date of Members' ); ?></label></h3>
|
628 |
+
<div class="inside">
|
629 |
+
|
630 |
+
<p>
|
631 |
+
<?php SwpmUtils::e( 'The access starts date of a member is set to the day the user registers. This date value is used to calculate how long the member can access your content that are protected with a duration type protection in the membership level. ' ); ?>
|
632 |
+
<?php SwpmUtils::e( 'You can manually set a specific access starts date value of all members who belong to a particular level using the following option.' ); ?>
|
633 |
+
</p>
|
634 |
+
<form method="post" action="">
|
635 |
+
<input type="hidden" name="swpm_bulk_start_date_nonce" value="<?php echo wp_create_nonce( 'swpm_bulk_start_date_nonce_action' ); ?>" />
|
636 |
+
|
637 |
+
<table width="100%" border="0" cellspacing="0" cellpadding="6">
|
638 |
+
<tr valign="top">
|
639 |
+
<td width="25%" align="left">
|
640 |
+
<strong><?php SwpmUtils::e( 'Membership Level: ' ); ?></strong>
|
641 |
+
</td><td align="left">
|
642 |
+
<select name="swpm_bulk_user_start_date_change_level">
|
643 |
+
<option value="please_select"><?php SwpmUtils::e( 'Select Level' ); ?></option>
|
644 |
+
<?php echo SwpmUtils::membership_level_dropdown(); ?>
|
645 |
+
</select>
|
646 |
+
<p class="description"><?php SwpmUtils::e( 'Select the Membership level (the access start date of all members who are in this level will be updated).' ); ?></p>
|
647 |
+
</td>
|
648 |
+
</tr>
|
649 |
+
|
650 |
+
<tr valign="top">
|
651 |
+
<td width="25%" align="left">
|
652 |
+
<strong>Access Starts Date: </strong>
|
653 |
+
</td><td align="left">
|
654 |
+
<input name="swpm_bulk_user_start_date_change_date" id="swpm_bulk_user_start_date_change_date" class="swpm-select-date" type="text" size="20" value="<?php echo ( date( 'Y-m-d' ) ); ?>" />
|
655 |
+
<p class="description"><?php SwpmUtils::e( 'Specify the access starts date value.' ); ?></p>
|
656 |
+
</td>
|
657 |
+
</tr>
|
658 |
+
|
659 |
+
<tr valign="top">
|
660 |
+
<td width="25%" align="left">
|
661 |
+
<input type="submit" class="button" name="swpm_bulk_user_start_date_change_process" value="<?php SwpmUtils::e( 'Bulk Change Access Starts Date' ); ?>" />
|
662 |
+
</td>
|
663 |
+
<td align="left"></td>
|
664 |
+
</tr>
|
665 |
+
|
666 |
+
</table>
|
667 |
+
</form>
|
668 |
+
</div></div>
|
669 |
+
|
670 |
+
<script>
|
671 |
+
jQuery(document).ready(function ($) {
|
672 |
+
$('#swpm_bulk_user_start_date_change_date').datepicker({dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true, yearRange: "-100:+100"});
|
673 |
+
});
|
674 |
+
</script>
|
675 |
+
<?php
|
676 |
+
echo '</div></div>'; //<!-- end of #poststuff #post-body -->
|
677 |
+
}
|
678 |
+
|
679 |
+
function show_all_members() {
|
680 |
+
ob_start();
|
681 |
+
$status = filter_input( INPUT_GET, 'status' );
|
682 |
+
include_once SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_members_list.php';
|
683 |
+
$output = ob_get_clean();
|
684 |
+
return $output;
|
685 |
+
}
|
686 |
+
|
687 |
+
function handle_main_members_admin_menu() {
|
688 |
+
do_action( 'swpm_members_menu_start' );
|
689 |
+
|
690 |
+
//Check current_user_can() or die.
|
691 |
+
SwpmMiscUtils::check_user_permission_and_is_admin( 'Main Members Admin Menu' );
|
692 |
+
|
693 |
+
$action = filter_input( INPUT_GET, 'member_action' );
|
694 |
+
$action = empty( $action ) ? filter_input( INPUT_POST, 'action' ) : $action;
|
695 |
+
$selected = $action;
|
696 |
+
?>
|
697 |
+
<div class="wrap swpm-admin-menu-wrap"><!-- start wrap -->
|
698 |
+
|
699 |
+
<h1><?php echo SwpmUtils::_( 'Simple WP Membership::Members' ); ?><!-- page title -->
|
700 |
+
<a href="admin.php?page=simple_wp_membership&member_action=add" class="add-new-h2"><?php echo SwpmUtils::_( 'Add New' ); ?></a>
|
701 |
+
</h1>
|
702 |
+
|
703 |
+
<h2 class="nav-tab-wrapper swpm-members-nav-tab-wrapper"><!-- start nav menu tabs -->
|
704 |
+
<a class="nav-tab <?php echo ( $selected == '' ) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership"><?php echo SwpmUtils::_( 'Members' ); ?></a>
|
705 |
+
<a class="nav-tab <?php echo ( $selected == 'add' ) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership&member_action=add"><?php echo SwpmUtils::_( 'Add Member' ); ?></a>
|
706 |
+
<a class="nav-tab <?php echo ( $selected == 'bulk' ) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership&member_action=bulk"><?php echo SwpmUtils::_( 'Bulk Operation' ); ?></a>
|
707 |
+
<?php
|
708 |
+
if ( $selected == 'edit' ) {//Only show the "edit member" tab when a member profile is being edited from the admin side.
|
709 |
+
echo '<a class="nav-tab nav-tab-active" href="#">Edit Member</a>';
|
710 |
+
}
|
711 |
+
|
712 |
+
//Trigger hooks that allows an extension to add extra nav tabs in the members menu.
|
713 |
+
do_action( 'swpm_members_menu_nav_tabs', $selected );
|
714 |
+
|
715 |
+
$menu_tabs = apply_filters( 'swpm_members_additional_menu_tabs_array', array() );
|
716 |
+
foreach ( $menu_tabs as $member_action => $title ) {
|
717 |
+
?>
|
718 |
+
<a class="nav-tab <?php echo ( $selected == $member_action ) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership&member_action=<?php echo $member_action; ?>" ><?php SwpmUtils::e( $title ); ?></a>
|
719 |
+
<?php
|
720 |
+
}
|
721 |
+
?>
|
722 |
+
</h2><!-- end nav menu tabs -->
|
723 |
+
<?php
|
724 |
+
do_action( 'swpm_members_menu_after_nav_tabs' );
|
725 |
+
|
726 |
+
//Trigger hook so anyone listening for this particular action can handle the output.
|
727 |
+
do_action( 'swpm_members_menu_body_' . $action );
|
728 |
+
|
729 |
+
//Allows an addon to completely override the body section of the members admin menu for a given action.
|
730 |
+
$output = apply_filters( 'swpm_members_menu_body_override', '', $action );
|
731 |
+
if ( ! empty( $output ) ) {
|
732 |
+
//An addon has overriden the body of this page for the given action. So no need to do anything in core.
|
733 |
+
echo $output;
|
734 |
+
echo '</div>'; //<!-- end of wrap -->
|
735 |
+
return;
|
736 |
+
}
|
737 |
+
|
738 |
+
//Switch case for the various different actions handled by the core plugin.
|
739 |
+
switch ( $action ) {
|
740 |
+
case 'members_list':
|
741 |
+
//Show the members listing
|
742 |
+
echo $this->show_all_members();
|
743 |
+
break;
|
744 |
+
case 'add':
|
745 |
+
//Process member profile add
|
746 |
+
$this->process_form_request();
|
747 |
+
break;
|
748 |
+
case 'edit':
|
749 |
+
//Process member profile edit
|
750 |
+
$this->process_form_request();
|
751 |
+
break;
|
752 |
+
case 'bulk':
|
753 |
+
//Handle the bulk operation menu
|
754 |
+
$this->bulk_operation_menu();
|
755 |
+
break;
|
756 |
+
default:
|
757 |
+
//Show the members listing page by default.
|
758 |
+
echo $this->show_all_members();
|
759 |
+
break;
|
760 |
+
}
|
761 |
+
|
762 |
+
echo '</div>'; //<!-- end of wrap -->
|
763 |
+
}
|
764 |
+
|
765 |
+
}
|
766 |
+
|
classes/class.swpm-registration.php
CHANGED
@@ -7,110 +7,117 @@
|
|
7 |
*/
|
8 |
abstract class SwpmRegistration {
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
}
|
113 |
|
114 |
-
function swpm_enclose_var($n) {
|
115 |
-
|
116 |
}
|
7 |
*/
|
8 |
abstract class SwpmRegistration {
|
9 |
|
10 |
+
protected $member_info = array();
|
11 |
+
var $email_activation = false;
|
12 |
+
protected static $_intance = null;
|
13 |
+
|
14 |
+
//public abstract static function get_instance();
|
15 |
+
protected function send_reg_email() {
|
16 |
+
global $wpdb;
|
17 |
+
if ( empty( $this->member_info ) ) {
|
18 |
+
return false;
|
19 |
+
}
|
20 |
+
|
21 |
+
$member_info = $this->member_info;
|
22 |
+
$settings = SwpmSettings::get_instance();
|
23 |
+
$subject = $settings->get_value( 'reg-complete-mail-subject' );
|
24 |
+
$body = $settings->get_value( 'reg-complete-mail-body' );
|
25 |
+
|
26 |
+
if ( $this->email_activation ) {
|
27 |
+
$swpm_user = SwpmMemberUtils::get_user_by_user_name( $member_info['user_name'] );
|
28 |
+
$member_id = $swpm_user->member_id;
|
29 |
+
$act_code = md5( uniqid() . $member_id );
|
30 |
+
$enc_pass = SwpmUtils::crypt( $member_info['plain_password'] );
|
31 |
+
$user_data = array(
|
32 |
+
'timestamp' => time(),
|
33 |
+
'act_code' => $act_code,
|
34 |
+
'plain_password' => $enc_pass,
|
35 |
+
);
|
36 |
+
$user_data = apply_filters( 'swpm_email_activation_data', $user_data );
|
37 |
+
update_option( 'swpm_email_activation_data_usr_' . $member_id, $user_data, false );
|
38 |
+
$body = $settings->get_value( 'email-activation-mail-body' );
|
39 |
+
$subject = $settings->get_value( 'email-activation-mail-subject' );
|
40 |
+
$activation_link = add_query_arg(
|
41 |
+
array(
|
42 |
+
'swpm_email_activation' => '1',
|
43 |
+
'swpm_member_id' => $member_id,
|
44 |
+
'swpm_token' => $act_code,
|
45 |
+
),
|
46 |
+
get_home_url()
|
47 |
+
);
|
48 |
+
$member_info['activation_link'] = $activation_link;
|
49 |
+
}
|
50 |
+
|
51 |
+
$from_address = $settings->get_value( 'email-from' );
|
52 |
+
$login_link = $settings->get_value( 'login-page-url' );
|
53 |
+
$headers = 'From: ' . $from_address . "\r\n";
|
54 |
+
$member_info['membership_level_name'] = SwpmPermission::get_instance( $member_info['membership_level'] )->get( 'alias' );
|
55 |
+
$member_info['password'] = $member_info['plain_password'];
|
56 |
+
$member_info['login_link'] = $login_link;
|
57 |
+
$values = array_values( $member_info );
|
58 |
+
$keys = array_map( 'swpm_enclose_var', array_keys( $member_info ) );
|
59 |
+
$body = html_entity_decode( $body );
|
60 |
+
$body = str_replace( $keys, $values, $body );
|
61 |
+
|
62 |
+
$swpm_user = SwpmMemberUtils::get_user_by_user_name( $member_info['user_name'] );
|
63 |
+
$member_id = $swpm_user->member_id;
|
64 |
+
$body = SwpmMiscUtils::replace_dynamic_tags( $body, $member_id ); //Do the standard merge var replacement.
|
65 |
+
|
66 |
+
$email = sanitize_email( filter_input( INPUT_POST, 'email', FILTER_UNSAFE_RAW ) );
|
67 |
+
|
68 |
+
if ( empty( $email ) ) {
|
69 |
+
$email = $swpm_user->email;
|
70 |
+
}
|
71 |
+
|
72 |
+
$body = apply_filters( 'swpm_registration_complete_email_body', $body ); //This filter can be used to modify the registration complete email body dynamically.
|
73 |
+
//Send notification email to the member
|
74 |
+
$subject = apply_filters( 'swpm_email_registration_complete_subject', $subject );
|
75 |
+
$body = apply_filters( 'swpm_email_registration_complete_body', $body ); //You can override the email to empty to disable this email.
|
76 |
+
if ( ! empty( $body ) ) {
|
77 |
+
SwpmMiscUtils::mail( trim( $email ), $subject, $body, $headers );
|
78 |
+
SwpmLog::log_simple_debug( 'Member registration complete email sent to: ' . $email . '. From email address value used: ' . $from_address, true );
|
79 |
+
} else {
|
80 |
+
SwpmLog::log_simple_debug( 'NOTICE: Registration complete email body value is empty. Member registration complete email will NOT be sent.', true );
|
81 |
+
}
|
82 |
+
|
83 |
+
if ( $settings->get_value( 'enable-admin-notification-after-reg' ) && ! $this->email_activation ) {
|
84 |
+
//Send notification email to the site admin
|
85 |
+
$admin_notification = $settings->get_value( 'admin-notification-email' );
|
86 |
+
$admin_notification = empty( $admin_notification ) ? $from_address : $admin_notification;
|
87 |
+
$notify_emails_array = explode( ',', $admin_notification );
|
88 |
+
|
89 |
+
$headers = 'From: ' . $from_address . "\r\n";
|
90 |
+
|
91 |
+
$admin_notify_subject = $settings->get_value( 'reg-complete-mail-subject-admin' );
|
92 |
+
if ( empty( $admin_notify_subject ) ) {
|
93 |
+
$admin_notify_subject = 'Notification of New Member Registration';
|
94 |
+
}
|
95 |
+
|
96 |
+
$admin_notify_body = $settings->get_value( 'reg-complete-mail-body-admin' );
|
97 |
+
if ( empty( $admin_notify_body ) ) {
|
98 |
+
$admin_notify_body = "A new member has completed the registration.\n\n" .
|
99 |
+
"Username: {user_name}\n" .
|
100 |
+
"Email: {email}\n\n" .
|
101 |
+
"Please login to the admin dashboard to view details of this user.\n\n" .
|
102 |
+
"You can customize this email message from the Email Settings menu of the plugin.\n\n" .
|
103 |
+
'Thank You';
|
104 |
+
}
|
105 |
+
$additional_args = array( 'password' => $member_info['plain_password'] );
|
106 |
+
$admin_notify_body = SwpmMiscUtils::replace_dynamic_tags( $admin_notify_body, $member_id, $additional_args ); //Do the standard merge var replacement.
|
107 |
+
|
108 |
+
foreach ( $notify_emails_array as $to_email ) {
|
109 |
+
$to_email = trim( $to_email );
|
110 |
+
$admin_notify_subject = apply_filters( 'swpm_email_admin_notify_subject', $admin_notify_subject );
|
111 |
+
$admin_notify_body = apply_filters( 'swpm_email_admin_notify_body', $admin_notify_body );
|
112 |
+
SwpmMiscUtils::mail( $to_email, $admin_notify_subject, $admin_notify_body, $headers );
|
113 |
+
SwpmLog::log_simple_debug( 'Admin notification email sent to: ' . $to_email, true );
|
114 |
+
}
|
115 |
+
}
|
116 |
+
return true;
|
117 |
+
}
|
118 |
|
119 |
}
|
120 |
|
121 |
+
function swpm_enclose_var( $n ) {
|
122 |
+
return '{' . $n . '}';
|
123 |
}
|
classes/class.swpm-settings.php
CHANGED
@@ -2,608 +2,1150 @@
|
|
2 |
|
3 |
class SwpmSettings {
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
class SwpmSettings {
|
4 |
|
5 |
+
private static $_this;
|
6 |
+
private $settings;
|
7 |
+
public $current_tab;
|
8 |
+
private $tabs;
|
9 |
+
|
10 |
+
private function __construct() {
|
11 |
+
$this->settings = (array) get_option( 'swpm-settings' );
|
12 |
+
}
|
13 |
+
|
14 |
+
public function init_config_hooks() {
|
15 |
+
//This function is called from "admin_init"
|
16 |
+
//It sets up the various tabs and the fields for the settings admin page.
|
17 |
+
|
18 |
+
if ( is_admin() ) { // for frontend just load settings but dont try to render settings page.
|
19 |
+
//Read the value of tab query arg.
|
20 |
+
$tab = isset( $_REQUEST['tab'] ) ? sanitize_text_field( $_REQUEST['tab'] ) : 1;
|
21 |
+
$this->current_tab = empty( $tab ) ? 1 : $tab;
|
22 |
+
|
23 |
+
//Setup the available settings tabs array.
|
24 |
+
$this->tabs = array(
|
25 |
+
1 => SwpmUtils::_( 'General Settings' ),
|
26 |
+
2 => SwpmUtils::_( 'Payment Settings' ),
|
27 |
+
3 => SwpmUtils::_( 'Email Settings' ),
|
28 |
+
4 => SwpmUtils::_( 'Tools' ),
|
29 |
+
5 => SwpmUtils::_( 'Advanced Settings' ),
|
30 |
+
6 => SwpmUtils::_( 'Addons Settings' ),
|
31 |
+
);
|
32 |
+
|
33 |
+
//Register the draw tab action hook. It will be triggered using do_action("swpm-draw-settings-nav-tabs")
|
34 |
+
add_action( 'swpm-draw-settings-nav-tabs', array( &$this, 'draw_tabs' ) );
|
35 |
+
|
36 |
+
//Register the various settings fields for the current tab.
|
37 |
+
$method = 'tab_' . $this->current_tab;
|
38 |
+
if ( method_exists( $this, $method ) ) {
|
39 |
+
$this->$method();
|
40 |
+
}
|
41 |
+
}
|
42 |
+
}
|
43 |
+
|
44 |
+
private function tab_1() {
|
45 |
+
//Register settings sections and fileds for the general settings tab.
|
46 |
+
|
47 |
+
register_setting( 'swpm-settings-tab-1', 'swpm-settings', array( &$this, 'sanitize_tab_1' ) );
|
48 |
+
|
49 |
+
//This settings section has no heading
|
50 |
+
add_settings_section( 'swpm-general-post-submission-check', '', array( &$this, 'swpm_general_post_submit_check_callback' ), 'simple_wp_membership_settings' );
|
51 |
+
|
52 |
+
add_settings_section( 'swpm-documentation', SwpmUtils::_( 'Plugin Documentation' ), array( &$this, 'swpm_documentation_callback' ), 'simple_wp_membership_settings' );
|
53 |
+
add_settings_section( 'general-settings', SwpmUtils::_( 'General Settings' ), array( &$this, 'general_settings_callback' ), 'simple_wp_membership_settings' );
|
54 |
+
add_settings_field(
|
55 |
+
'enable-free-membership',
|
56 |
+
SwpmUtils::_( 'Enable Free Membership' ),
|
57 |
+
array( &$this, 'checkbox_callback' ),
|
58 |
+
'simple_wp_membership_settings',
|
59 |
+
'general-settings',
|
60 |
+
array(
|
61 |
+
'item' => 'enable-free-membership',
|
62 |
+
'message' => SwpmUtils::_( 'Enable/disable registration for free membership level. When you enable this option, make sure to specify a free membership level ID in the field below.' ),
|
63 |
+
)
|
64 |
+
);
|
65 |
+
add_settings_field(
|
66 |
+
'free-membership-id',
|
67 |
+
SwpmUtils::_( 'Free Membership Level ID' ),
|
68 |
+
array( &$this, 'textfield_small_callback' ),
|
69 |
+
'simple_wp_membership_settings',
|
70 |
+
'general-settings',
|
71 |
+
array(
|
72 |
+
'item' => 'free-membership-id',
|
73 |
+
'message' => SwpmUtils::_( 'Assign free membership level ID' ),
|
74 |
+
)
|
75 |
+
);
|
76 |
+
add_settings_field(
|
77 |
+
'enable-moretag',
|
78 |
+
SwpmUtils::_( 'Enable More Tag Protection' ),
|
79 |
+
array( &$this, 'checkbox_callback' ),
|
80 |
+
'simple_wp_membership_settings',
|
81 |
+
'general-settings',
|
82 |
+
array(
|
83 |
+
'item' => 'enable-moretag',
|
84 |
+
'message' => SwpmUtils::_( 'Enables or disables "more" tag protection in the posts and pages. Anything after the More tag is protected. Anything before the more tag is teaser content.' ),
|
85 |
+
)
|
86 |
+
);
|
87 |
+
add_settings_field(
|
88 |
+
'hide-adminbar',
|
89 |
+
SwpmUtils::_( 'Hide Adminbar' ),
|
90 |
+
array( &$this, 'checkbox_callback' ),
|
91 |
+
'simple_wp_membership_settings',
|
92 |
+
'general-settings',
|
93 |
+
array(
|
94 |
+
'item' => 'hide-adminbar',
|
95 |
+
'message' => SwpmUtils::_( 'WordPress shows an admin toolbar to the logged in users of the site. Check this if you want to hide that admin toolbar in the frontend of your site.' ),
|
96 |
+
)
|
97 |
+
);
|
98 |
+
add_settings_field(
|
99 |
+
'show-adminbar-admin-only',
|
100 |
+
SwpmUtils::_( 'Show Adminbar to Admin' ),
|
101 |
+
array( &$this, 'checkbox_callback' ),
|
102 |
+
'simple_wp_membership_settings',
|
103 |
+
'general-settings',
|
104 |
+
array(
|
105 |
+
'item' => 'show-adminbar-admin-only',
|
106 |
+
'message' => SwpmUtils::_( 'Use this option if you want to show the admin toolbar to admin users only. The admin toolbar will be hidden for all other users.' ),
|
107 |
+
)
|
108 |
+
);
|
109 |
+
add_settings_field(
|
110 |
+
'disable-access-to-wp-dashboard',
|
111 |
+
SwpmUtils::_( 'Disable Access to WP Dashboard' ),
|
112 |
+
array( &$this, 'checkbox_callback' ),
|
113 |
+
'simple_wp_membership_settings',
|
114 |
+
'general-settings',
|
115 |
+
array(
|
116 |
+
'item' => 'disable-access-to-wp-dashboard',
|
117 |
+
'message' => SwpmUtils::_( 'WordPress allows a standard wp user to be able to go to the wp-admin URL and access his profile from the wp dashbaord. Using this option will prevent any non admin users from going to the wp dashboard.' ),
|
118 |
+
)
|
119 |
+
);
|
120 |
+
|
121 |
+
add_settings_field(
|
122 |
+
'default-account-status',
|
123 |
+
SwpmUtils::_( 'Default Account Status' ),
|
124 |
+
array( &$this, 'selectbox_callback' ),
|
125 |
+
'simple_wp_membership_settings',
|
126 |
+
'general-settings',
|
127 |
+
array(
|
128 |
+
'item' => 'default-account-status',
|
129 |
+
'options' => SwpmUtils::get_account_state_options(),
|
130 |
+
'default' => 'active',
|
131 |
+
'message' => SwpmUtils::_( 'Select the default account status for newly registered users. If you want to manually approve the members then you can set the status to "Pending".' ),
|
132 |
+
)
|
133 |
+
);
|
134 |
+
|
135 |
+
add_settings_field(
|
136 |
+
'members-login-to-comment',
|
137 |
+
SwpmUtils::_( 'Members Must be Logged in to Comment' ),
|
138 |
+
array( &$this, 'checkbox_callback' ),
|
139 |
+
'simple_wp_membership_settings',
|
140 |
+
'general-settings',
|
141 |
+
array(
|
142 |
+
'item' => 'members-login-to-comment',
|
143 |
+
'message' => SwpmUtils::_( 'Enable this option if you only want the members of the site to be able to post a comment.' ),
|
144 |
+
)
|
145 |
+
);
|
146 |
+
|
147 |
+
/*
|
148 |
+
add_settings_field('protect-everything', SwpmUtils::_('Protect Everything'),
|
149 |
+
array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'general-settings',
|
150 |
+
array('item' => 'protect-everything',
|
151 |
+
'message'=>SwpmUtils::_('Check this box if you want to protect all posts/pages by default.')));
|
152 |
+
*/
|
153 |
+
|
154 |
+
add_settings_section( 'pages-settings', SwpmUtils::_( 'Pages Settings' ), array( &$this, 'pages_settings_callback' ), 'simple_wp_membership_settings' );
|
155 |
+
add_settings_field(
|
156 |
+
'login-page-url',
|
157 |
+
SwpmUtils::_( 'Login Page URL' ),
|
158 |
+
array( &$this, 'textfield_long_callback' ),
|
159 |
+
'simple_wp_membership_settings',
|
160 |
+
'pages-settings',
|
161 |
+
array(
|
162 |
+
'item' => 'login-page-url',
|
163 |
+
'message' => '',
|
164 |
+
)
|
165 |
+
);
|
166 |
+
add_settings_field(
|
167 |
+
'registration-page-url',
|
168 |
+
SwpmUtils::_( 'Registration Page URL' ),
|
169 |
+
array( &$this, 'textfield_long_callback' ),
|
170 |
+
'simple_wp_membership_settings',
|
171 |
+
'pages-settings',
|
172 |
+
array(
|
173 |
+
'item' => 'registration-page-url',
|
174 |
+
'message' => '',
|
175 |
+
)
|
176 |
+
);
|
177 |
+
add_settings_field(
|
178 |
+
'join-us-page-url',
|
179 |
+
SwpmUtils::_( 'Join Us Page URL' ),
|
180 |
+
array( &$this, 'textfield_long_callback' ),
|
181 |
+
'simple_wp_membership_settings',
|
182 |
+
'pages-settings',
|
183 |
+
array(
|
184 |
+
'item' => 'join-us-page-url',
|
185 |
+
'message' => '',
|
186 |
+
)
|
187 |
+
);
|
188 |
+
add_settings_field(
|
189 |
+
'profile-page-url',
|
190 |
+
SwpmUtils::_( 'Edit Profile Page URL' ),
|
191 |
+
array( &$this, 'textfield_long_callback' ),
|
192 |
+
'simple_wp_membership_settings',
|
193 |
+
'pages-settings',
|
194 |
+
array(
|
195 |
+
'item' => 'profile-page-url',
|
196 |
+
'message' => '',
|
197 |
+
)
|
198 |
+
);
|
199 |
+
add_settings_field(
|
200 |
+
'reset-page-url',
|
201 |
+
SwpmUtils::_( 'Password Reset Page URL' ),
|
202 |
+
array( &$this, 'textfield_long_callback' ),
|
203 |
+
'simple_wp_membership_settings',
|
204 |
+
'pages-settings',
|
205 |
+
array(
|
206 |
+
'item' => 'reset-page-url',
|
207 |
+
'message' => '',
|
208 |
+
)
|
209 |
+
);
|
210 |
+
|
211 |
+
add_settings_section( 'debug-settings', SwpmUtils::_( 'Test & Debug Settings' ), array( &$this, 'testndebug_settings_callback' ), 'simple_wp_membership_settings' );
|
212 |
+
|
213 |
+
$debug_field_help_text = SwpmUtils::_( 'Check this option to enable debug logging.' );
|
214 |
+
$debug_field_help_text .= SwpmUtils::_( ' This can be useful when troubleshooting an issue. Turn it off and reset the log files after the troubleshooting is complete.' );
|
215 |
+
$debug_field_help_text .= '<br />';
|
216 |
+
$debug_field_help_text .= '<br />- ' . SwpmUtils::_( 'View general debug log file by clicking ' ) . '<a href="' . SIMPLE_WP_MEMBERSHIP_URL . '/log.txt" target="_blank">' . SwpmUtils::_( 'here' ) . '</a>.';
|
217 |
+
$debug_field_help_text .= '<br />- ' . SwpmUtils::_( 'View login related debug log file by clicking ' ) . '<a href="' . SIMPLE_WP_MEMBERSHIP_URL . '/log-auth.txt" target="_blank">' . SwpmUtils::_( 'here' ) . '</a>.';
|
218 |
+
$debug_field_help_text .= '<br />- ' . SwpmUtils::_( 'Reset debug log files by clicking ' ) . '<a href="admin.php?page=simple_wp_membership_settings&swmp_reset_log=1" target="_blank">' . SwpmUtils::_( 'here' ) . '</a>.';
|
219 |
+
add_settings_field(
|
220 |
+
'enable-debug',
|
221 |
+
SwpmUtils::_( 'Enable Debug' ),
|
222 |
+
array( &$this, 'checkbox_callback' ),
|
223 |
+
'simple_wp_membership_settings',
|
224 |
+
'debug-settings',
|
225 |
+
array(
|
226 |
+
'item' => 'enable-debug',
|
227 |
+
'message' => $debug_field_help_text,
|
228 |
+
)
|
229 |
+
);
|
230 |
+
add_settings_field(
|
231 |
+
'enable-sandbox-testing',
|
232 |
+
SwpmUtils::_( 'Enable Sandbox Testing' ),
|
233 |
+
array( &$this, 'checkbox_callback' ),
|
234 |
+
'simple_wp_membership_settings',
|
235 |
+
'debug-settings',
|
236 |
+
array(
|
237 |
+
'item' => 'enable-sandbox-testing',
|
238 |
+
'message' => SwpmUtils::_( 'Enable this option if you want to do sandbox payment testing.' ),
|
239 |
+
)
|
240 |
+
);
|
241 |
+
}
|
242 |
+
|
243 |
+
private function tab_2() {
|
244 |
+
//Register settings sections and fileds for the payment settings tab.
|
245 |
+
}
|
246 |
+
|
247 |
+
private function tab_3() {
|
248 |
+
//Register settings sections and fileds for the email settings tab.
|
249 |
+
|
250 |
+
register_setting( 'swpm-settings-tab-3', 'swpm-settings', array( &$this, 'sanitize_tab_3' ) );
|
251 |
+
|
252 |
+
add_settings_section( 'email-settings-overview', SwpmUtils::_( 'Email Settings Overview' ), array( &$this, 'email_settings_overview_callback' ), 'simple_wp_membership_settings' );
|
253 |
+
add_settings_section( 'email-misc-settings', SwpmUtils::_( 'Email Misc. Settings' ), array( &$this, 'email_misc_settings_callback' ), 'simple_wp_membership_settings' );
|
254 |
+
|
255 |
+
add_settings_field(
|
256 |
+
'email-misc-from',
|
257 |
+
SwpmUtils::_( 'From Email Address' ),
|
258 |
+
array( &$this, 'textfield_callback' ),
|
259 |
+
'simple_wp_membership_settings',
|
260 |
+
'email-misc-settings',
|
261 |
+
array(
|
262 |
+
'item' => 'email-from',
|
263 |
+
'message' => 'This value will be used as the sender\'s address for the emails. Example value: Your Name <sales@your-domain.com>',
|
264 |
+
)
|
265 |
+
);
|
266 |
+
|
267 |
+
add_settings_field(
|
268 |
+
'email-enable-html',
|
269 |
+
SwpmUtils::_( 'Allow HTML in Emails' ),
|
270 |
+
array( $this, 'checkbox_callback' ),
|
271 |
+
'simple_wp_membership_settings',
|
272 |
+
'email-misc-settings',
|
273 |
+
array(
|
274 |
+
'item' => 'email-enable-html',
|
275 |
+
'message' => 'Enables HTML support in emails. We recommend using plain text (non HTML) email as it has better email delivery rate.',
|
276 |
+
)
|
277 |
+
);
|
278 |
+
|
279 |
+
//Prompt to complete registration email settings
|
280 |
+
add_settings_section( 'reg-prompt-email-settings', SwpmUtils::_( 'Email Settings (Prompt to Complete Registration )' ), array( &$this, 'reg_prompt_email_settings_callback' ), 'simple_wp_membership_settings' );
|
281 |
+
add_settings_field(
|
282 |
+
'reg-prompt-complete-mail-subject',
|
283 |
+
SwpmUtils::_( 'Email Subject' ),
|
284 |
+
array( &$this, 'textfield_callback' ),
|
285 |
+
'simple_wp_membership_settings',
|
286 |
+
'reg-prompt-email-settings',
|
287 |
+
array(
|
288 |
+
'item' => 'reg-prompt-complete-mail-subject',
|
289 |
+
'message' => '',
|
290 |
+
)
|
291 |
+
);
|
292 |
+
add_settings_field(
|
293 |
+
'reg-prompt-complete-mail-body',
|
294 |
+
SwpmUtils::_( 'Email Body' ),
|
295 |
+
array( &$this, 'wp_editor_callback' ),
|
296 |
+
'simple_wp_membership_settings',
|
297 |
+
'reg-prompt-email-settings',
|
298 |
+
array(
|
299 |
+
'item' => 'reg-prompt-complete-mail-body',
|
300 |
+
'message' => '',
|
301 |
+
)
|
302 |
+
);
|
303 |
+
|
304 |
+
//Registration complete email settings
|
305 |
+
$msg_for_admin_notify_email_field = SwpmUtils::_( 'Enter the email address where you want the admin notification email to be sent to.' );
|
306 |
+
$msg_for_admin_notify_email_field .= SwpmUtils::_( ' You can put multiple email addresses separated by comma (,) in the above field to send the notification to multiple email addresses.' );
|
307 |
+
|
308 |
+
$msg_for_admin_notify_email_subj = SwpmUtils::_( 'Enter the subject for the admin notification email.' );
|
309 |
+
$admin_notify_email_body_msg = SwpmUtils::_( 'This email will be sent to the admin when a new user completes the membership registration. Only works if you have enabled the "Send Notification to Admin" option above.' );
|
310 |
+
|
311 |
+
add_settings_section( 'reg-email-settings', SwpmUtils::_( 'Email Settings (Registration Complete)' ), array( &$this, 'reg_email_settings_callback' ), 'simple_wp_membership_settings' );
|
312 |
+
add_settings_field(
|
313 |
+
'reg-complete-mail-subject',
|
314 |
+
SwpmUtils::_( 'Email Subject' ),
|
315 |
+
array( &$this, 'textfield_callback' ),
|
316 |
+
'simple_wp_membership_settings',
|
317 |
+
'reg-email-settings',
|
318 |
+
array(
|
319 |
+
'item' => 'reg-complete-mail-subject',
|
320 |
+
'message' => '',
|
321 |
+
)
|
322 |
+
);
|
323 |
+
add_settings_field(
|
324 |
+
'reg-complete-mail-body',
|
325 |
+
SwpmUtils::_( 'Email Body' ),
|
326 |
+
array( &$this, 'wp_editor_callback' ),
|
327 |
+
'simple_wp_membership_settings',
|
328 |
+
'reg-email-settings',
|
329 |
+
array(
|
330 |
+
'item' => 'reg-complete-mail-body',
|
331 |
+
'message' => '',
|
332 |
+
)
|
333 |
+
);
|
334 |
+
add_settings_field(
|
335 |
+
'enable-admin-notification-after-reg',
|
336 |
+
SwpmUtils::_( 'Send Notification to Admin' ),
|
337 |
+
array( &$this, 'checkbox_callback' ),
|
338 |
+
'simple_wp_membership_settings',
|
339 |
+
'reg-email-settings',
|
340 |
+
array(
|
341 |
+
'item' => 'enable-admin-notification-after-reg',
|
342 |
+
'message' => SwpmUtils::_( 'Enable this option if you want the admin to receive a notification when a member registers.' ),
|
343 |
+
)
|
344 |
+
);
|
345 |
+
add_settings_field(
|
346 |
+
'admin-notification-email',
|
347 |
+
SwpmUtils::_( 'Admin Email Address' ),
|
348 |
+
array( &$this, 'textfield_callback' ),
|
349 |
+
'simple_wp_membership_settings',
|
350 |
+
'reg-email-settings',
|
351 |
+
array(
|
352 |
+
'item' => 'admin-notification-email',
|
353 |
+
'message' => $msg_for_admin_notify_email_field,
|
354 |
+
)
|
355 |
+
);
|
356 |
+
add_settings_field(
|
357 |
+
'reg-complete-mail-subject-admin',
|
358 |
+
SwpmUtils::_( 'Admin Notification Email Subject' ),
|
359 |
+
array( &$this, 'textfield_callback' ),
|
360 |
+
'simple_wp_membership_settings',
|
361 |
+
'reg-email-settings',
|
362 |
+
array(
|
363 |
+
'item' => 'reg-complete-mail-subject-admin',
|
364 |
+
'message' => $msg_for_admin_notify_email_subj,
|
365 |
+
)
|
366 |
+
);
|
367 |
+
add_settings_field(
|
368 |
+
'reg-complete-mail-body-admin',
|
369 |
+
SwpmUtils::_( 'Admin Notification Email Body' ),
|
370 |
+
array( &$this, 'wp_editor_callback' ),
|
371 |
+
'simple_wp_membership_settings',
|
372 |
+
'reg-email-settings',
|
373 |
+
array(
|
374 |
+
'item' => 'reg-complete-mail-body-admin',
|
375 |
+
'message' => $admin_notify_email_body_msg,
|
376 |
+
)
|
377 |
+
);
|
378 |
+
|
379 |
+
add_settings_field(
|
380 |
+
'enable-notification-after-manual-user-add',
|
381 |
+
SwpmUtils::_( 'Send Email to Member When Added via Admin Dashboard' ),
|
382 |
+
array( &$this, 'checkbox_callback' ),
|
383 |
+
'simple_wp_membership_settings',
|
384 |
+
'reg-email-settings',
|
385 |
+
array(
|
386 |
+
'item' => 'enable-notification-after-manual-user-add',
|
387 |
+
'message' => '',
|
388 |
+
)
|
389 |
+
);
|
390 |
+
|
391 |
+
//Password reset email settings
|
392 |
+
add_settings_section( 'reset-password-settings', SwpmUtils::_( 'Email Settings (Password Reset)' ), array( &$this, 'reset_password_settings_callback' ), 'simple_wp_membership_settings' );
|
393 |
+
add_settings_field(
|
394 |
+
'reset-mail-subject',
|
395 |
+
SwpmUtils::_( 'Email Subject' ),
|
396 |
+
array( &$this, 'textfield_callback' ),
|
397 |
+
'simple_wp_membership_settings',
|
398 |
+
'reset-password-settings',
|
399 |
+
array(
|
400 |
+
'item' => 'reset-mail-subject',
|
401 |
+
'message' => '',
|
402 |
+
)
|
403 |
+
);
|
404 |
+
add_settings_field(
|
405 |
+
'reset-mail-body',
|
406 |
+
SwpmUtils::_( 'Email Body' ),
|
407 |
+
array( &$this, 'wp_editor_callback' ),
|
408 |
+
'simple_wp_membership_settings',
|
409 |
+
'reset-password-settings',
|
410 |
+
array(
|
411 |
+
'item' => 'reset-mail-body',
|
412 |
+
'message' => '',
|
413 |
+
)
|
414 |
+
);
|
415 |
+
|
416 |
+
//Account upgrade email settings
|
417 |
+
add_settings_section( 'upgrade-email-settings', SwpmUtils::_( ' Email Settings (Account Upgrade Notification)' ), array( &$this, 'upgrade_email_settings_callback' ), 'simple_wp_membership_settings' );
|
418 |
+
add_settings_field(
|
419 |
+
'upgrade-complete-mail-subject',
|
420 |
+
SwpmUtils::_( 'Email Subject' ),
|
421 |
+
array( &$this, 'textfield_callback' ),
|
422 |
+
'simple_wp_membership_settings',
|
423 |
+
'upgrade-email-settings',
|
424 |
+
array(
|
425 |
+
'item' => 'upgrade-complete-mail-subject',
|
426 |
+
'message' => '',
|
427 |
+
)
|
428 |
+
);
|
429 |
+
add_settings_field(
|
430 |
+
'upgrade-complete-mail-body',
|
431 |
+
SwpmUtils::_( 'Email Body' ),
|
432 |
+
array( &$this, 'wp_editor_callback' ),
|
433 |
+
'simple_wp_membership_settings',
|
434 |
+
'upgrade-email-settings',
|
435 |
+
array(
|
436 |
+
'item' => 'upgrade-complete-mail-body',
|
437 |
+
'message' => '',
|
438 |
+
)
|
439 |
+
);
|
440 |
+
add_settings_field(
|
441 |
+
'disable-email-after-upgrade',
|
442 |
+
SwpmUtils::_( 'Disable Email Notification After Upgrade' ),
|
443 |
+
array( &$this, 'checkbox_callback' ),
|
444 |
+
'simple_wp_membership_settings',
|
445 |
+
'upgrade-email-settings',
|
446 |
+
array(
|
447 |
+
'item' => 'disable-email-after-upgrade',
|
448 |
+
'message' => SwpmUtils::_( 'You can use this option to disable the email notification that gets sent to the members when they make a payment for upgrade or renewal.' ),
|
449 |
+
)
|
450 |
+
);
|
451 |
+
|
452 |
+
//Bulk account activate and notify email settings.
|
453 |
+
add_settings_section( 'bulk-activate-email-settings', SwpmUtils::_( ' Email Settings (Bulk Account Activate Notification)' ), array( &$this, 'bulk_activate_email_settings_callback' ), 'simple_wp_membership_settings' );
|
454 |
+
add_settings_field(
|
455 |
+
'bulk-activate-notify-mail-subject',
|
456 |
+
SwpmUtils::_( 'Email Subject' ),
|
457 |
+
array( &$this, 'textfield_callback' ),
|
458 |
+
'simple_wp_membership_settings',
|
459 |
+
'bulk-activate-email-settings',
|
460 |
+
array(
|
461 |
+
'item' => 'bulk-activate-notify-mail-subject',
|
462 |
+
'message' => '',
|
463 |
+
)
|
464 |
+
);
|
465 |
+
add_settings_field(
|
466 |
+
'bulk-activate-notify-mail-body',
|
467 |
+
SwpmUtils::_( 'Email Body' ),
|
468 |
+
array( &$this, 'wp_editor_callback' ),
|
469 |
+
'simple_wp_membership_settings',
|
470 |
+
'bulk-activate-email-settings',
|
471 |
+
array(
|
472 |
+
'item' => 'bulk-activate-notify-mail-body',
|
473 |
+
'message' => '',
|
474 |
+
)
|
475 |
+
);
|
476 |
+
|
477 |
+
//Email activation email settings.
|
478 |
+
add_settings_section( 'email-activation-email-settings', SwpmUtils::_( ' Email Settings (Email Activation)' ), array( &$this, 'email_activation_email_settings_callback' ), 'simple_wp_membership_settings' );
|
479 |
+
add_settings_field(
|
480 |
+
'email-activation-mail-subject',
|
481 |
+
SwpmUtils::_( 'Email Subject' ),
|
482 |
+
array( &$this, 'textfield_callback' ),
|
483 |
+
'simple_wp_membership_settings',
|
484 |
+
'email-activation-email-settings',
|
485 |
+
array(
|
486 |
+
'item' => 'email-activation-mail-subject',
|
487 |
+
'message' => '',
|
488 |
+
)
|
489 |
+
);
|
490 |
+
add_settings_field(
|
491 |
+
'email-activation-mail-body',
|
492 |
+
SwpmUtils::_( 'Email Body' ),
|
493 |
+
array( &$this, 'wp_editor_callback' ),
|
494 |
+
'simple_wp_membership_settings',
|
495 |
+
'email-activation-email-settings',
|
496 |
+
array(
|
497 |
+
'item' => 'email-activation-mail-body',
|
498 |
+
'message' => '',
|
499 |
+
)
|
500 |
+
);
|
501 |
+
}
|
502 |
+
|
503 |
+
private function tab_4() {
|
504 |
+
//Register settings sections and fileds for the tools tab.
|
505 |
+
}
|
506 |
+
|
507 |
+
private function tab_5() {
|
508 |
+
//Register settings sections and fileds for the advanced settings tab.
|
509 |
+
|
510 |
+
register_setting( 'swpm-settings-tab-5', 'swpm-settings', array( &$this, 'sanitize_tab_5' ) );
|
511 |
+
|
512 |
+
add_settings_section( 'advanced-settings', SwpmUtils::_( 'Advanced Settings' ), array( &$this, 'advanced_settings_callback' ), 'simple_wp_membership_settings' );
|
513 |
+
|
514 |
+
add_settings_field(
|
515 |
+
'enable-expired-account-login',
|
516 |
+
SwpmUtils::_( 'Enable Expired Account Login' ),
|
517 |
+
array( &$this, 'checkbox_callback' ),
|
518 |
+
'simple_wp_membership_settings',
|
519 |
+
'advanced-settings',
|
520 |
+
array(
|
521 |
+
'item' => 'enable-expired-account-login',
|
522 |
+
'message' => SwpmUtils::_( "When enabled, expired members will be able to log into the system but won't be able to view any protected content. This allows them to easily renew their account by making another payment." ),
|
523 |
+
)
|
524 |
+
);
|
525 |
+
|
526 |
+
add_settings_field(
|
527 |
+
'renewal-page-url',
|
528 |
+
SwpmUtils::_( 'Membership Renewal URL' ),
|
529 |
+
array( &$this, 'textfield_long_callback' ),
|
530 |
+
'simple_wp_membership_settings',
|
531 |
+
'advanced-settings',
|
532 |
+
array(
|
533 |
+
'item' => 'renewal-page-url',
|
534 |
+
'message' => SwpmUtils::_( 'You can create a renewal page for your site. Read <a href="https://simple-membership-plugin.com/creating-membership-renewal-button/" target="_blank">this documentation</a> to learn how to create a renewal page.' ),
|
535 |
+
)
|
536 |
+
);
|
537 |
+
|
538 |
+
add_settings_field(
|
539 |
+
'after-rego-redirect-page-url',
|
540 |
+
SwpmUtils::_( 'After Registration Redirect URL' ),
|
541 |
+
array( &$this, 'textfield_long_callback' ),
|
542 |
+
'simple_wp_membership_settings',
|
543 |
+
'advanced-settings',
|
544 |
+
array(
|
545 |
+
'item' => 'after-rego-redirect-page-url',
|
546 |
+
'message' => SwpmUtils::_( 'You can enter an URL here to redirect the members to this page after they submit the registration form. Read <a href="https://simple-membership-plugin.com/configure-after-registration-redirect-for-members/" target="_blank">this documentation</a> to learn how to setup after registration redirect.' ),
|
547 |
+
)
|
548 |
+
);
|
549 |
+
|
550 |
+
add_settings_field(
|
551 |
+
'auto-login-after-rego',
|
552 |
+
SwpmUtils::_( 'Enable Auto Login After Registration' ),
|
553 |
+
array( &$this, 'checkbox_callback' ),
|
554 |
+
'simple_wp_membership_settings',
|
555 |
+
'advanced-settings',
|
556 |
+
array(
|
557 |
+
'item' => 'auto-login-after-rego',
|
558 |
+
'message' => SwpmUtils::_( 'Use this option if you want the members to be automatically logged into your site right after they complete the registration. This option will override any after registration redirection and instead it will trigger the after login redirection. Read <a href="https://simple-membership-plugin.com/configure-auto-login-after-registration-members/" target="_blank">this documentation</a> to learn more.' ),
|
559 |
+
)
|
560 |
+
);
|
561 |
+
|
562 |
+
add_settings_field(
|
563 |
+
'after-logout-redirection-url',
|
564 |
+
SwpmUtils::_( 'After Logout Redirect URL' ),
|
565 |
+
array( &$this, 'textfield_long_callback' ),
|
566 |
+
'simple_wp_membership_settings',
|
567 |
+
'advanced-settings',
|
568 |
+
array(
|
569 |
+
'item' => 'after-logout-redirection-url',
|
570 |
+
'message' => SwpmUtils::_( 'You can enter an URL here to redirect the members to this page after they click the logout link to logout from your site.' ),
|
571 |
+
)
|
572 |
+
);
|
573 |
+
|
574 |
+
add_settings_field(
|
575 |
+
'logout-member-on-browser-close',
|
576 |
+
SwpmUtils::_( 'Logout Member on Browser Close' ),
|
577 |
+
array( &$this, 'checkbox_callback' ),
|
578 |
+
'simple_wp_membership_settings',
|
579 |
+
'advanced-settings',
|
580 |
+
array(
|
581 |
+
'item' => 'logout-member-on-browser-close',
|
582 |
+
'message' => SwpmUtils::_( 'Enable this option if you want the member to be logged out of the account when he closes the browser.' ),
|
583 |
+
)
|
584 |
+
);
|
585 |
+
|
586 |
+
add_settings_field(
|
587 |
+
'allow-account-deletion',
|
588 |
+
SwpmUtils::_( 'Allow Account Deletion' ),
|
589 |
+
array( &$this, 'checkbox_callback' ),
|
590 |
+
'simple_wp_membership_settings',
|
591 |
+
'advanced-settings',
|
592 |
+
array(
|
593 |
+
'item' => 'allow-account-deletion',
|
594 |
+
'message' => SwpmUtils::_( 'Allow users to delete their accounts.' ),
|
595 |
+
)
|
596 |
+
);
|
597 |
+
|
598 |
+
add_settings_field(
|
599 |
+
'force-strong-passwords',
|
600 |
+
SwpmUtils::_( 'Force Strong Password for Members' ),
|
601 |
+
array( &$this, 'checkbox_callback' ),
|
602 |
+
'simple_wp_membership_settings',
|
603 |
+
'advanced-settings',
|
604 |
+
array(
|
605 |
+
'item' => 'force-strong-passwords',
|
606 |
+
'message' => SwpmUtils::_( 'Enable this if you want the users to be forced to use a strong password for their accounts.' ),
|
607 |
+
)
|
608 |
+
);
|
609 |
+
|
610 |
+
add_settings_field(
|
611 |
+
'use-wordpress-timezone',
|
612 |
+
SwpmUtils::_( 'Use WordPress Timezone' ),
|
613 |
+
array( &$this, 'checkbox_callback' ),
|
614 |
+
'simple_wp_membership_settings',
|
615 |
+
'advanced-settings',
|
616 |
+
array(
|
617 |
+
'item' => 'use-wordpress-timezone',
|
618 |
+
'message' => SwpmUtils::_( 'Use this option if you want to use the timezone value specified in your WordPress General Settings interface.' ),
|
619 |
+
)
|
620 |
+
);
|
621 |
+
|
622 |
+
add_settings_field(
|
623 |
+
'delete-pending-account',
|
624 |
+
SwpmUtils::_( 'Auto Delete Pending Account' ),
|
625 |
+
array( &$this, 'selectbox_callback' ),
|
626 |
+
'simple_wp_membership_settings',
|
627 |
+
'advanced-settings',
|
628 |
+
array(
|
629 |
+
'item' => 'delete-pending-account',
|
630 |
+
'options' => array(
|
631 |
+
0 => 'Do not delete',
|
632 |
+
1 => 'Older than 1 month',
|
633 |
+
2 => 'Older than 2 months',
|
634 |
+
),
|
635 |
+
'default' => '0',
|
636 |
+
'message' => SwpmUtils::_( 'Select how long you want to keep "pending" account.' ),
|
637 |
+
)
|
638 |
+
);
|
639 |
+
|
640 |
+
add_settings_field(
|
641 |
+
'admin-dashboard-access-permission',
|
642 |
+
SwpmUtils::_( 'Admin Dashboard Access Permission' ),
|
643 |
+
array( &$this, 'selectbox_callback' ),
|
644 |
+
'simple_wp_membership_settings',
|
645 |
+
'advanced-settings',
|
646 |
+
array(
|
647 |
+
'item' => 'admin-dashboard-access-permission',
|
648 |
+
'options' => array(
|
649 |
+
'manage_options' => 'Admin',
|
650 |
+
'edit_pages' => 'Editor',
|
651 |
+
'edit_published_posts' => 'Author',
|
652 |
+
'edit_posts' => 'Contributor',
|
653 |
+
),
|
654 |
+
'default' => 'manage_options',
|
655 |
+
'message' => SwpmUtils::_( 'SWPM admin dashboard is accessible to admin users only (just like any other plugin). You can allow users with other WP user role to access the SWPM admin dashboard by selecting a value here.' ),
|
656 |
+
)
|
657 |
+
);
|
658 |
+
|
659 |
+
add_settings_field(
|
660 |
+
'force-wp-user-sync',
|
661 |
+
SwpmUtils::_( 'Force WP User Synchronization' ),
|
662 |
+
array( &$this, 'checkbox_callback' ),
|
663 |
+
'simple_wp_membership_settings',
|
664 |
+
'advanced-settings',
|
665 |
+
array(
|
666 |
+
'item' => 'force-wp-user-sync',
|
667 |
+
'message' => SwpmUtils::_( 'Enable this option if you want to force the member login to be synchronized with WP user account. This can be useful if you are using another plugin that uses WP user records. For example: bbPress plugin.' ),
|
668 |
+
)
|
669 |
+
);
|
670 |
+
|
671 |
+
//Auto create SWPM user related settings section
|
672 |
+
add_settings_section( 'auto-create-swpm-user-settings', SwpmUtils::_( 'Create Member Accounts for New WP Users' ), array( &$this, 'advanced_settings_auto_create_swpm_uses_settings_callback' ), 'simple_wp_membership_settings' );
|
673 |
+
|
674 |
+
add_settings_field(
|
675 |
+
'enable-auto-create-swpm-members',
|
676 |
+
SwpmUtils::_( 'Enable Auto Create Member Accounts' ),
|
677 |
+
array( &$this, 'checkbox_callback' ),
|
678 |
+
'simple_wp_membership_settings',
|
679 |
+
'auto-create-swpm-user-settings',
|
680 |
+
array(
|
681 |
+
'item' => 'enable-auto-create-swpm-members',
|
682 |
+
'message' => SwpmUtils::_( 'Enable this option to automatically create member accounts for any new WP user that is created by another plugin.' ),
|
683 |
+
)
|
684 |
+
);
|
685 |
+
|
686 |
+
$levels_array = SwpmMembershipLevelUtils::get_all_membership_levels_in_array();
|
687 |
+
add_settings_field(
|
688 |
+
'auto-create-default-membership-level',
|
689 |
+
SwpmUtils::_( 'Default Membership Level' ),
|
690 |
+
array( &$this, 'selectbox_callback' ),
|
691 |
+
'simple_wp_membership_settings',
|
692 |
+
'auto-create-swpm-user-settings',
|
693 |
+
array(
|
694 |
+
'item' => 'auto-create-default-membership-level',
|
695 |
+
'options' => $levels_array,
|
696 |
+
'default' => '',
|
697 |
+
'message' => SwpmUtils::_( 'When automatically creating a member account using this feature, the membership level of the user will be set to the one you specify here.' ),
|
698 |
+
)
|
699 |
+
);
|
700 |
+
|
701 |
+
$status_array = SwpmUtils::get_account_state_options();
|
702 |
+
add_settings_field(
|
703 |
+
'auto-create-default-account-status',
|
704 |
+
SwpmUtils::_( 'Default Account Status' ),
|
705 |
+
array( &$this, 'selectbox_callback' ),
|
706 |
+
'simple_wp_membership_settings',
|
707 |
+
'auto-create-swpm-user-settings',
|
708 |
+
array(
|
709 |
+
'item' => 'auto-create-default-account-status',
|
710 |
+
'options' => $status_array,
|
711 |
+
'default' => '',
|
712 |
+
'message' => SwpmUtils::_( 'When automatically creating a member account using this feature, the membership account status of the user will be set to the one you specify here.' ),
|
713 |
+
)
|
714 |
+
);
|
715 |
+
|
716 |
+
add_settings_field(
|
717 |
+
'payment-notification-forward-url',
|
718 |
+
SwpmUtils::_( 'Payment Notification Forward URL' ),
|
719 |
+
array( &$this, 'textfield_long_callback' ),
|
720 |
+
'simple_wp_membership_settings',
|
721 |
+
'advanced-settings',
|
722 |
+
array(
|
723 |
+
'item' => 'payment-notification-forward-url',
|
724 |
+
'message' => SwpmUtils::_( 'You can enter an URL here to forward the payment notification after the membership payment has been processed by this plugin. Useful if you want to forward the payment notification to an external script for further processing.' ),
|
725 |
+
)
|
726 |
+
);
|
727 |
+
|
728 |
+
//Terms and conditions section
|
729 |
+
add_settings_section( 'terms-and-conditions', SwpmUtils::_( 'Terms and Conditions' ), array( &$this, 'advanced_settings_terms_and_conditions_callback' ), 'simple_wp_membership_settings' );
|
730 |
+
|
731 |
+
add_settings_field(
|
732 |
+
'enable-terms-and-conditions',
|
733 |
+
SwpmUtils::_( 'Enable Terms and Conditions' ),
|
734 |
+
array( &$this, 'checkbox_callback' ),
|
735 |
+
'simple_wp_membership_settings',
|
736 |
+
'terms-and-conditions',
|
737 |
+
array(
|
738 |
+
'item' => 'enable-terms-and-conditions',
|
739 |
+
'message' => SwpmUtils::_( 'Users must accept the terms before they can complete the registration.' ),
|
740 |
+
)
|
741 |
+
);
|
742 |
+
add_settings_field(
|
743 |
+
'terms-and-conditions-page-url',
|
744 |
+
SwpmUtils::_( 'Terms and Conditions Page URL' ),
|
745 |
+
array( &$this, 'textfield_long_callback' ),
|
746 |
+
'simple_wp_membership_settings',
|
747 |
+
'terms-and-conditions',
|
748 |
+
array(
|
749 |
+
'item' => 'terms-and-conditions-page-url',
|
750 |
+
'message' => SwpmUtils::_( 'Enter the URL of your terms and conditions page. You can create a WordPress page and specify your terms in there then specify the URL of that page in the above field.' ),
|
751 |
+
)
|
752 |
+
);
|
753 |
+
add_settings_field(
|
754 |
+
'enable-privacy-policy',
|
755 |
+
SwpmUtils::_( 'Enable Privacy Policy' ),
|
756 |
+
array( &$this, 'checkbox_callback' ),
|
757 |
+
'simple_wp_membership_settings',
|
758 |
+
'terms-and-conditions',
|
759 |
+
array(
|
760 |
+
'item' => 'enable-privacy-policy',
|
761 |
+
'message' => SwpmUtils::_( 'Users must accept it before they can complete the registration.' ),
|
762 |
+
)
|
763 |
+
);
|
764 |
+
add_settings_field(
|
765 |
+
'privacy-policy-page-url',
|
766 |
+
SwpmUtils::_( 'Privacy Policy Page URL' ),
|
767 |
+
array( &$this, 'textfield_long_callback' ),
|
768 |
+
'simple_wp_membership_settings',
|
769 |
+
'terms-and-conditions',
|
770 |
+
array(
|
771 |
+
'item' => 'privacy-policy-page-url',
|
772 |
+
'message' => SwpmUtils::_( 'Enter the URL of your privacy policy page.' ),
|
773 |
+
)
|
774 |
+
);
|
775 |
+
}
|
776 |
+
|
777 |
+
private function tab_6() {
|
778 |
+
//Register settings sections and fileds for the addon settings tab.
|
779 |
+
}
|
780 |
+
|
781 |
+
public static function get_instance() {
|
782 |
+
self::$_this = empty( self::$_this ) ? new SwpmSettings() : self::$_this;
|
783 |
+
return self::$_this;
|
784 |
+
}
|
785 |
+
|
786 |
+
public function selectbox_callback( $args ) {
|
787 |
+
$item = $args['item'];
|
788 |
+
$options = $args['options'];
|
789 |
+
$default = $args['default'];
|
790 |
+
$msg = isset( $args['message'] ) ? $args['message'] : '';
|
791 |
+
$selected = esc_attr( $this->get_value( $item ), $default );
|
792 |
+
echo "<select name='swpm-settings[" . $item . "]' >";
|
793 |
+
foreach ( $options as $key => $value ) {
|
794 |
+
$is_selected = ( $key == $selected ) ? 'selected="selected"' : '';
|
795 |
+
echo '<option ' . $is_selected . ' value="' . esc_attr( $key ) . '">' . esc_attr( $value ) . '</option>';
|
796 |
+
}
|
797 |
+
echo '</select>';
|
798 |
+
echo '<br/><i>' . $msg . '</i>';
|
799 |
+
}
|
800 |
+
|
801 |
+
public function checkbox_callback( $args ) {
|
802 |
+
$item = $args['item'];
|
803 |
+
$msg = isset( $args['message'] ) ? $args['message'] : '';
|
804 |
+
$is = esc_attr( $this->get_value( $item ) );
|
805 |
+
echo "<input type='checkbox' $is name='swpm-settings[" . $item . "]' value=\"checked='checked'\" />";
|
806 |
+
echo '<br/><i>' . $msg . '</i>';
|
807 |
+
}
|
808 |
+
|
809 |
+
public function textarea_callback( $args ) {
|
810 |
+
$item = $args['item'];
|
811 |
+
$msg = isset( $args['message'] ) ? $args['message'] : '';
|
812 |
+
$text = esc_attr( $this->get_value( $item ) );
|
813 |
+
echo "<textarea name='swpm-settings[" . $item . "]' rows='6' cols='60' >" . $text . '</textarea>';
|
814 |
+
echo '<br/><i>' . $msg . '</i>';
|
815 |
+
}
|
816 |
+
|
817 |
+
public function textfield_small_callback( $args ) {
|
818 |
+
$item = $args['item'];
|
819 |
+
$msg = isset( $args['message'] ) ? $args['message'] : '';
|
820 |
+
$text = esc_attr( $this->get_value( $item ) );
|
821 |
+
echo "<input type='text' name='swpm-settings[" . $item . "]' size='5' value='" . $text . "' />";
|
822 |
+
echo '<br/><i>' . $msg . '</i>';
|
823 |
+
}
|
824 |
+
|
825 |
+
public function textfield_callback( $args ) {
|
826 |
+
$item = $args['item'];
|
827 |
+
$msg = isset( $args['message'] ) ? $args['message'] : '';
|
828 |
+
$text = esc_attr( $this->get_value( $item ) );
|
829 |
+
echo "<input type='text' name='swpm-settings[" . $item . "]' size='50' value='" . $text . "' />";
|
830 |
+
echo '<br/><i>' . $msg . '</i>';
|
831 |
+
}
|
832 |
+
|
833 |
+
public function textfield_long_callback( $args ) {
|
834 |
+
$item = $args['item'];
|
835 |
+
$msg = isset( $args['message'] ) ? $args['message'] : '';
|
836 |
+
$text = esc_attr( $this->get_value( $item ) );
|
837 |
+
echo "<input type='text' name='swpm-settings[" . $item . "]' size='100' value='" . $text . "' />";
|
838 |
+
echo '<br/><i>' . $msg . '</i>';
|
839 |
+
}
|
840 |
+
|
841 |
+
public function set_default_editor( $r ) {
|
842 |
+
$r = 'html';
|
843 |
+
return $r;
|
844 |
+
}
|
845 |
+
|
846 |
+
public function wp_editor_callback( $args ) {
|
847 |
+
$item = $args['item'];
|
848 |
+
$msg = isset( $args['message'] ) ? $args['message'] : '';
|
849 |
+
$text = $this->get_value( $item );
|
850 |
+
$html_enabled = $this->get_value( 'email-enable-html' );
|
851 |
+
add_filter( 'wp_default_editor', array( $this, 'set_default_editor' ) );
|
852 |
+
echo '<style>#wp-' . esc_attr( sprintf( '%s', $item ) ) . '-wrap{max-width:40em;}</style>';
|
853 |
+
wp_editor(
|
854 |
+
html_entity_decode( $text ),
|
855 |
+
$item,
|
856 |
+
array(
|
857 |
+
'textarea_name' => 'swpm-settings[' . $item . ']',
|
858 |
+
'teeny' => true,
|
859 |
+
'default_editor' => ! empty( $html_enabled ) ? 'QuickTags' : '',
|
860 |
+
'textarea_rows' => 15,
|
861 |
+
)
|
862 |
+
);
|
863 |
+
remove_filter( 'wp_default_editor', array( $this, 'set_default_editor' ) );
|
864 |
+
echo "<p class=\"description\">{$msg}</p>";
|
865 |
+
}
|
866 |
+
|
867 |
+
public function swpm_documentation_callback() {
|
868 |
+
?>
|
869 |
+
<div class="swpm-orange-box">
|
870 |
+
<?php printf( SwpmUtils::_( 'Visit the %s to read setup and configuration documentation.' ), '<a target="_blank" href="https://simple-membership-plugin.com/">' . SwpmUtils::_( 'Simple Membership Plugin Site' ) . '</a>' ); ?>
|
871 |
+
<?php printf( SwpmUtils::_( 'Please %s if you like the plugin.' ), '<a href="https://wordpress.org/support/view/plugin-reviews/simple-membership?filter=5" target="_blank">' . SwpmUtils::_( 'give us a rating' ) . '</a>' ); ?>
|
872 |
+
</div>
|
873 |
+
<?php
|
874 |
+
}
|
875 |
+
|
876 |
+
public function swpm_general_post_submit_check_callback() {
|
877 |
+
//Log file reset handler
|
878 |
+
if ( isset( $_REQUEST['swmp_reset_log'] ) ) {
|
879 |
+
if ( SwpmLog::reset_swmp_log_files() ) {
|
880 |
+
echo '<div id="message" class="updated fade"><p>Debug log files have been reset!</p></div>';
|
881 |
+
} else {
|
882 |
+
echo '<div id="message" class="updated fade"><p>Debug log files could not be reset!</p></div>';
|
883 |
+
}
|
884 |
+
}
|
885 |
+
|
886 |
+
//Show settings updated message
|
887 |
+
if ( isset( $_REQUEST['settings-updated'] ) ) {
|
888 |
+
echo '<div id="message" class="updated fade"><p>' . SwpmUtils::_( 'Settings updated!' ) . '</p></div>';
|
889 |
+
}
|
890 |
+
}
|
891 |
+
|
892 |
+
public function general_settings_callback() {
|
893 |
+
SwpmUtils::e( 'General Plugin Settings.' );
|
894 |
+
}
|
895 |
+
|
896 |
+
public function pages_settings_callback() {
|
897 |
+
SwpmUtils::e( 'Page Setup and URL Related settings.' );
|
898 |
+
|
899 |
+
echo '<p>';
|
900 |
+
SwpmUtils::e( 'The following pages are required for the plugin to function correctly. These pages were automatically created by the plugin at install time.' );
|
901 |
+
echo '</p>';
|
902 |
+
}
|
903 |
+
|
904 |
+
public function testndebug_settings_callback() {
|
905 |
+
SwpmUtils::e( 'Testing and Debug Related Settings.' );
|
906 |
+
}
|
907 |
+
|
908 |
+
public function reg_email_settings_callback() {
|
909 |
+
SwpmUtils::e( 'This email will be sent to your users when they complete the registration and become a member.' );
|
910 |
+
}
|
911 |
+
|
912 |
+
public function reset_password_settings_callback() {
|
913 |
+
SwpmUtils::e( 'This email will be sent to your users when they use the password reset functionality.' );
|
914 |
+
}
|
915 |
+
|
916 |
+
public function email_settings_overview_callback() {
|
917 |
+
echo '<div class="swpm-grey-box">';
|
918 |
+
echo '<p>';
|
919 |
+
SwpmUtils::e( 'This interface lets you custsomize the various emails that gets sent to your members for various actions. The default settings should be good to get your started.' );
|
920 |
+
echo '</p>';
|
921 |
+
|
922 |
+
echo '<p>';
|
923 |
+
echo '<a href="https://simple-membership-plugin.com/email-merge-tags-email-shortcodes-for-email-customization/" target="_blank">' . SwpmUtils::_( 'This documentation' ) . '</a>';
|
924 |
+
SwpmUtils::e( ' explains what email merge tags you can use in the email body field to customize it (if you want to).' );
|
925 |
+
echo '</p>';
|
926 |
+
echo '</div>';
|
927 |
+
}
|
928 |
+
|
929 |
+
public function email_misc_settings_callback() {
|
930 |
+
|
931 |
+
//Show settings updated message when it is updated
|
932 |
+
if ( isset( $_REQUEST['settings-updated'] ) ) {
|
933 |
+
//This status message need to be in the callback function to prevent header sent warning
|
934 |
+
echo '<div id="message" class="updated fade"><p>' . SwpmUtils::_( 'Settings updated!' ) . '</p></div>';
|
935 |
+
}
|
936 |
+
|
937 |
+
SwpmUtils::e( 'Settings in this section apply to all emails.' );
|
938 |
+
}
|
939 |
+
|
940 |
+
public function upgrade_email_settings_callback() {
|
941 |
+
SwpmUtils::e( 'This email will be sent to your users after account upgrade (when an existing member pays for a new membership level).' );
|
942 |
+
}
|
943 |
+
|
944 |
+
public function bulk_activate_email_settings_callback() {
|
945 |
+
SwpmUtils::e( 'This email will be sent to your members when you use the bulk account activate and notify action.' );
|
946 |
+
SwpmUtils::e( ' You cannot use email merge tags in this email. You can only use generic text.' );
|
947 |
+
}
|
948 |
+
|
949 |
+
public function email_activation_email_settings_callback() {
|
950 |
+
SwpmUtils::e( 'This email will be sent if Email Activation is enabled for a Membership Level.' );
|
951 |
+
}
|
952 |
+
|
953 |
+
public function reg_prompt_email_settings_callback() {
|
954 |
+
SwpmUtils::e( 'This email will be sent to prompt users to complete registration after the payment.' );
|
955 |
+
}
|
956 |
+
|
957 |
+
public function advanced_settings_callback() {
|
958 |
+
|
959 |
+
//Show settings updated message when it is updated
|
960 |
+
if ( isset( $_REQUEST['settings-updated'] ) ) {
|
961 |
+
//This status message need to be in the callback function to prevent header sent warning
|
962 |
+
echo '<div id="message" class="updated fade"><p>' . SwpmUtils::_( 'Settings updated!' ) . '</p></div>';
|
963 |
+
}
|
964 |
+
|
965 |
+
SwpmUtils::e( 'This page allows you to configure some advanced features of the plugin.' );
|
966 |
+
}
|
967 |
+
|
968 |
+
public function advanced_settings_auto_create_swpm_uses_settings_callback() {
|
969 |
+
SwpmUtils::e( 'This section allows you to configure automatic creation of member accounts when new WP User records are created by another plugin. It can be useful if you are using another plugin that creates WP user records and you want them to be recognized in the membership plugin.' );
|
970 |
+
}
|
971 |
+
|
972 |
+
public function advanced_settings_terms_and_conditions_callback() {
|
973 |
+
SwpmUtils::e( 'This section allows you to configure terms and conditions and privacy policy that users must accept at registration time.' );
|
974 |
+
}
|
975 |
+
|
976 |
+
public function sanitize_tab_1( $input ) {
|
977 |
+
if ( empty( $this->settings ) ) {
|
978 |
+
$this->settings = (array) get_option( 'swpm-settings' );
|
979 |
+
}
|
980 |
+
$output = $this->settings;
|
981 |
+
//general settings block
|
982 |
+
|
983 |
+
$output['hide-adminbar'] = isset( $input['hide-adminbar'] ) ? esc_attr( $input['hide-adminbar'] ) : '';
|
984 |
+
$output['show-adminbar-admin-only'] = isset( $input['show-adminbar-admin-only'] ) ? esc_attr( $input['show-adminbar-admin-only'] ) : '';
|
985 |
+
$output['disable-access-to-wp-dashboard'] = isset( $input['disable-access-to-wp-dashboard'] ) ? esc_attr( $input['disable-access-to-wp-dashboard'] ) : '';
|
986 |
+
|
987 |
+
$output['protect-everything'] = isset( $input['protect-everything'] ) ? esc_attr( $input['protect-everything'] ) : '';
|
988 |
+
$output['enable-free-membership'] = isset( $input['enable-free-membership'] ) ? esc_attr( $input['enable-free-membership'] ) : '';
|
989 |
+
$output['enable-moretag'] = isset( $input['enable-moretag'] ) ? esc_attr( $input['enable-moretag'] ) : '';
|
990 |
+
$output['enable-debug'] = isset( $input['enable-debug'] ) ? esc_attr( $input['enable-debug'] ) : '';
|
991 |
+
$output['enable-sandbox-testing'] = isset( $input['enable-sandbox-testing'] ) ? esc_attr( $input['enable-sandbox-testing'] ) : '';
|
992 |
+
|
993 |
+
$output['free-membership-id'] = ( $input['free-membership-id'] != 1 ) ? absint( $input['free-membership-id'] ) : '';
|
994 |
+
$output['login-page-url'] = esc_url( $input['login-page-url'] );
|
995 |
+
$output['registration-page-url'] = esc_url( $input['registration-page-url'] );
|
996 |
+
$output['profile-page-url'] = esc_url( $input['profile-page-url'] );
|
997 |
+
$output['reset-page-url'] = esc_url( $input['reset-page-url'] );
|
998 |
+
$output['join-us-page-url'] = esc_url( $input['join-us-page-url'] );
|
999 |
+
$output['default-account-status'] = esc_attr( $input['default-account-status'] );
|
1000 |
+
$output['members-login-to-comment'] = isset( $input['members-login-to-comment'] ) ? esc_attr( $input['members-login-to-comment'] ) : '';
|
1001 |
+
|
1002 |
+
return $output;
|
1003 |
+
}
|
1004 |
+
|
1005 |
+
public function sanitize_tab_3( $input ) {
|
1006 |
+
if ( empty( $this->settings ) ) {
|
1007 |
+
$this->settings = (array) get_option( 'swpm-settings' );
|
1008 |
+
}
|
1009 |
+
$output = $this->settings;
|
1010 |
+
$output['reg-complete-mail-subject'] = sanitize_text_field( $input['reg-complete-mail-subject'] );
|
1011 |
+
$output['reg-complete-mail-body'] = $input['reg-complete-mail-body'];
|
1012 |
+
$output['reg-complete-mail-subject-admin'] = sanitize_text_field( $input['reg-complete-mail-subject-admin'] );
|
1013 |
+
$output['reg-complete-mail-body-admin'] = $input['reg-complete-mail-body-admin'];
|
1014 |
+
|
1015 |
+
$output['reset-mail-subject'] = sanitize_text_field( $input['reset-mail-subject'] );
|
1016 |
+
$output['reset-mail-body'] = $input['reset-mail-body'];
|
1017 |
+
|
1018 |
+
$output['upgrade-complete-mail-subject'] = sanitize_text_field( $input['upgrade-complete-mail-subject'] );
|
1019 |
+
$output['upgrade-complete-mail-body'] = $input['upgrade-complete-mail-body'];
|
1020 |
+
$output['disable-email-after-upgrade'] = isset( $input['disable-email-after-upgrade'] ) ? esc_attr( $input['disable-email-after-upgrade'] ) : '';
|
1021 |
+
|
1022 |
+
$output['bulk-activate-notify-mail-subject'] = sanitize_text_field( $input['bulk-activate-notify-mail-subject'] );
|
1023 |
+
$output['bulk-activate-notify-mail-body'] = $input['bulk-activate-notify-mail-body'];
|
1024 |
+
|
1025 |
+
$output['email-activation-mail-subject'] = sanitize_text_field( $input['email-activation-mail-subject'] );
|
1026 |
+
$output['email-activation-mail-body'] = $input['email-activation-mail-body'];
|
1027 |
+
|
1028 |
+
$output['reg-prompt-complete-mail-subject'] = sanitize_text_field( $input['reg-prompt-complete-mail-subject'] );
|
1029 |
+
$output['reg-prompt-complete-mail-body'] = $input['reg-prompt-complete-mail-body'];
|
1030 |
+
$output['email-from'] = trim( $input['email-from'] );
|
1031 |
+
$output['email-enable-html'] = isset( $input['email-enable-html'] ) ? esc_attr( $input['email-enable-html'] ) : '';
|
1032 |
+
$output['enable-admin-notification-after-reg'] = isset( $input['enable-admin-notification-after-reg'] ) ? esc_attr( $input['enable-admin-notification-after-reg'] ) : '';
|
1033 |
+
$output['admin-notification-email'] = sanitize_text_field( $input['admin-notification-email'] );
|
1034 |
+
$output['enable-notification-after-manual-user-add'] = isset( $input['enable-notification-after-manual-user-add'] ) ? esc_attr( $input['enable-notification-after-manual-user-add'] ) : '';
|
1035 |
+
|
1036 |
+
return $output;
|
1037 |
+
}
|
1038 |
+
|
1039 |
+
public function sanitize_tab_5( $input ) {
|
1040 |
+
if ( empty( $this->settings ) ) {
|
1041 |
+
$this->settings = (array) get_option( 'swpm-settings' );
|
1042 |
+
}
|
1043 |
+
$output = $this->settings;
|
1044 |
+
$output['enable-expired-account-login'] = isset( $input['enable-expired-account-login'] ) ? esc_attr( $input['enable-expired-account-login'] ) : '';
|
1045 |
+
$output['logout-member-on-browser-close'] = isset( $input['logout-member-on-browser-close'] ) ? esc_attr( $input['logout-member-on-browser-close'] ) : '';
|
1046 |
+
$output['allow-account-deletion'] = isset( $input['allow-account-deletion'] ) ? esc_attr( $input['allow-account-deletion'] ) : '';
|
1047 |
+
$output['use-wordpress-timezone'] = isset( $input['use-wordpress-timezone'] ) ? esc_attr( $input['use-wordpress-timezone'] ) : '';
|
1048 |
+
$output['delete-pending-account'] = isset( $input['delete-pending-account'] ) ? esc_attr( $input['delete-pending-account'] ) : 0;
|
1049 |
+
$output['admin-dashboard-access-permission'] = isset( $input['admin-dashboard-access-permission'] ) ? esc_attr( $input['admin-dashboard-access-permission'] ) : '';
|
1050 |
+
$output['renewal-page-url'] = esc_url( $input['renewal-page-url'] );
|
1051 |
+
$output['after-rego-redirect-page-url'] = esc_url( $input['after-rego-redirect-page-url'] );
|
1052 |
+
$output['after-logout-redirection-url'] = esc_url( $input['after-logout-redirection-url'] );
|
1053 |
+
$output['force-strong-passwords'] = isset( $input['force-strong-passwords'] ) ? esc_attr( $input['force-strong-passwords'] ) : '';
|
1054 |
+
$output['auto-login-after-rego'] = isset( $input['auto-login-after-rego'] ) ? esc_attr( $input['auto-login-after-rego'] ) : '';
|
1055 |
+
$output['force-wp-user-sync'] = isset( $input['force-wp-user-sync'] ) ? esc_attr( $input['force-wp-user-sync'] ) : '';
|
1056 |
+
$output['payment-notification-forward-url'] = esc_url( $input['payment-notification-forward-url'] );
|
1057 |
+
|
1058 |
+
//Auto create swpm user related settings
|
1059 |
+
$output['enable-auto-create-swpm-members'] = isset( $input['enable-auto-create-swpm-members'] ) ? esc_attr( $input['enable-auto-create-swpm-members'] ) : '';
|
1060 |
+
$output['auto-create-default-membership-level'] = isset( $input['auto-create-default-membership-level'] ) ? esc_attr( $input['auto-create-default-membership-level'] ) : '';
|
1061 |
+
$output['auto-create-default-account-status'] = isset( $input['auto-create-default-account-status'] ) ? esc_attr( $input['auto-create-default-account-status'] ) : '';
|
1062 |
+
//Terms and conditions related settings
|
1063 |
+
$output['enable-terms-and-conditions'] = isset( $input['enable-terms-and-conditions'] ) ? esc_attr( $input['enable-terms-and-conditions'] ) : '';
|
1064 |
+
$output['terms-and-conditions-page-url'] = esc_url( $input['terms-and-conditions-page-url'] );
|
1065 |
+
$output['enable-privacy-policy'] = isset( $input['enable-privacy-policy'] ) ? esc_attr( $input['enable-privacy-policy'] ) : '';
|
1066 |
+
$output['privacy-policy-page-url'] = esc_url( $input['privacy-policy-page-url'] );
|
1067 |
+
return $output;
|
1068 |
+
}
|
1069 |
+
|
1070 |
+
public function get_value( $key, $default = '' ) {
|
1071 |
+
if ( isset( $this->settings[ $key ] ) ) {
|
1072 |
+
return $this->settings[ $key ];
|
1073 |
+
}
|
1074 |
+
return $default;
|
1075 |
+
}
|
1076 |
+
|
1077 |
+
public function set_value( $key, $value ) {
|
1078 |
+
$this->settings[ $key ] = $value;
|
1079 |
+
return $this;
|
1080 |
+
}
|
1081 |
+
|
1082 |
+
public function save() {
|
1083 |
+
update_option( 'swpm-settings', $this->settings );
|
1084 |
+
}
|
1085 |
+
|
1086 |
+
public function draw_tabs() {
|
1087 |
+
$current = $this->current_tab;
|
1088 |
+
?>
|
1089 |
+
<h2 class="nav-tab-wrapper">
|
1090 |
+
<?php foreach ( $this->tabs as $id => $label ) { ?>
|
1091 |
+
<a class="nav-tab <?php echo ( $current == $id ) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_settings&tab=<?php echo $id; ?>"><?php echo $label; ?></a>
|
1092 |
+
<?php } ?>
|
1093 |
+
</h2>
|
1094 |
+
<?php
|
1095 |
+
}
|
1096 |
+
|
1097 |
+
public function handle_main_settings_admin_menu() {
|
1098 |
+
do_action( 'swpm_settings_menu_start' );
|
1099 |
+
|
1100 |
+
//Check current_user_can() or die.
|
1101 |
+
SwpmMiscUtils::check_user_permission_and_is_admin( 'Main Settings Menu' );
|
1102 |
+
|
1103 |
+
?>
|
1104 |
+
<div class="wrap swpm-admin-menu-wrap"><!-- start wrap -->
|
1105 |
+
|
1106 |
+
<h1><?php echo SwpmUtils::_( 'Simple WP Membership::Settings' ); ?></h1><!-- page title -->
|
1107 |
+
|
1108 |
+
<!-- start nav menu tabs -->
|
1109 |
+
<?php do_action( 'swpm-draw-settings-nav-tabs' ); ?>
|
1110 |
+
<!-- end nav menu tabs -->
|
1111 |
+
<?php
|
1112 |
+
do_action( 'swpm_settings_menu_after_nav_tabs' );
|
1113 |
+
|
1114 |
+
//Switch to handle the body of each of the various settings pages based on the currently selected tab
|
1115 |
+
$current_tab = $this->current_tab;
|
1116 |
+
switch ( $current_tab ) {
|
1117 |
+
case 1:
|
1118 |
+
//General settings
|
1119 |
+
include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_settings.php';
|
1120 |
+
break;
|
1121 |
+
case 2:
|
1122 |
+
//Payment settings
|
1123 |
+
include SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/admin_payment_settings.php';
|
1124 |
+
break;
|
1125 |
+
case 3:
|
1126 |
+
//Email settings
|
1127 |
+
include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_settings.php';
|
1128 |
+
break;
|
1129 |
+
case 4:
|
1130 |
+
//Tools
|
1131 |
+
include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_tools_settings.php';
|
1132 |
+
break;
|
1133 |
+
case 5:
|
1134 |
+
//Advanced settings
|
1135 |
+
include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_settings.php';
|
1136 |
+
break;
|
1137 |
+
case 6:
|
1138 |
+
//Addon settings
|
1139 |
+
include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_addon_settings.php';
|
1140 |
+
break;
|
1141 |
+
default:
|
1142 |
+
//The default fallback (general settings)
|
1143 |
+
include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_settings.php';
|
1144 |
+
break;
|
1145 |
+
}
|
1146 |
+
|
1147 |
+
echo '</div>'; //<!-- end of wrap -->
|
1148 |
+
}
|
1149 |
+
|
1150 |
+
}
|
1151 |
+
|
classes/class.swpm-transactions.php
CHANGED
@@ -1,74 +1,82 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Provides some helpful functions to deal with the transactions
|
5 |
-
*/
|
6 |
-
|
7 |
-
class SwpmTransactions {
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Provides some helpful functions to deal with the transactions
|
5 |
+
*/
|
6 |
+
|
7 |
+
class SwpmTransactions {
|
8 |
+
|
9 |
+
static function save_txn_record( $ipn_data, $items = array() ) {
|
10 |
+
global $wpdb;
|
11 |
+
|
12 |
+
$current_date = date( 'Y-m-d' );
|
13 |
+
$custom_var = self::parse_custom_var( $ipn_data['custom'] );
|
14 |
+
|
15 |
+
$txn_data = array();
|
16 |
+
$txn_data['email'] = $ipn_data['payer_email'];
|
17 |
+
$txn_data['first_name'] = $ipn_data['first_name'];
|
18 |
+
$txn_data['last_name'] = $ipn_data['last_name'];
|
19 |
+
$txn_data['ip_address'] = $ipn_data['ip'];
|
20 |
+
$txn_data['member_id'] = isset ( $custom_var['swpm_id'] ) ? $custom_var['swpm_id'] : '';
|
21 |
+
$txn_data['membership_level'] = isset ( $custom_var['subsc_ref'] ) ? $custom_var['subsc_ref'] : '';
|
22 |
+
|
23 |
+
$txn_data['txn_date'] = $current_date;
|
24 |
+
$txn_data['txn_id'] = $ipn_data['txn_id'];
|
25 |
+
$txn_data['subscr_id'] = $ipn_data['subscr_id'];
|
26 |
+
$txn_data['reference'] = isset( $custom_var['reference'] ) ? $custom_var['reference'] : '';
|
27 |
+
$txn_data['payment_amount'] = $ipn_data['mc_gross'];
|
28 |
+
$txn_data['gateway'] = $ipn_data['gateway'];
|
29 |
+
$txn_data['status'] = $ipn_data['status'];
|
30 |
+
|
31 |
+
$txn_data = array_filter( $txn_data );//Remove any null values.
|
32 |
+
$wpdb->insert( $wpdb->prefix . 'swpm_payments_tbl', $txn_data );
|
33 |
+
|
34 |
+
$db_row_id = $wpdb->insert_id;
|
35 |
+
|
36 |
+
//let's also store transactions data in swpm_transactions CPT
|
37 |
+
$post = array();
|
38 |
+
$post['post_title'] = '';
|
39 |
+
$post['post_status'] = 'publish';
|
40 |
+
$post['content'] = '';
|
41 |
+
$post['post_type'] = 'swpm_transactions';
|
42 |
+
|
43 |
+
$post_id = wp_insert_post( $post );
|
44 |
+
|
45 |
+
update_post_meta( $post_id, 'db_row_id', $db_row_id );
|
46 |
+
|
47 |
+
if ( isset( $ipn_data['payment_button_id'] ) ) {
|
48 |
+
$txn_data['payment_button_id'] = $ipn_data['payment_button_id'];
|
49 |
+
}
|
50 |
+
|
51 |
+
if ( isset( $ipn_data['is_live'] ) ) {
|
52 |
+
$txn_data['is_live'] = $ipn_data['is_live'];
|
53 |
+
}
|
54 |
+
|
55 |
+
foreach ( $txn_data as $key => $value ) {
|
56 |
+
update_post_meta( $post_id, $key, $value );
|
57 |
+
}
|
58 |
+
|
59 |
+
do_action( 'swpm_txn_record_saved', $txn_data, $db_row_id, $post_id );
|
60 |
+
|
61 |
+
}
|
62 |
+
|
63 |
+
static function parse_custom_var( $custom ) {
|
64 |
+
$delimiter = '&';
|
65 |
+
$customvariables = array();
|
66 |
+
|
67 |
+
$namevaluecombos = explode( $delimiter, $custom );
|
68 |
+
foreach ( $namevaluecombos as $keyval_unparsed ) {
|
69 |
+
$equalsignposition = strpos( $keyval_unparsed, '=' );
|
70 |
+
if ( $equalsignposition === false ) {
|
71 |
+
$customvariables[ $keyval_unparsed ] = '';
|
72 |
+
continue;
|
73 |
+
}
|
74 |
+
$key = substr( $keyval_unparsed, 0, $equalsignposition );
|
75 |
+
$value = substr( $keyval_unparsed, $equalsignposition + 1 );
|
76 |
+
$customvariables[ $key ] = $value;
|
77 |
+
}
|
78 |
+
|
79 |
+
return $customvariables;
|
80 |
+
}
|
81 |
+
|
82 |
+
}
|
classes/class.swpm-utils-misc.php
CHANGED
@@ -1,508 +1,735 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class SwpmMiscUtils {
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
<strong>Free Membership</strong>
|
13 |
-
<br />
|
14 |
-
You get unlimited access to free membership content
|
15 |
-
<br />
|
16 |
-
<em><strong>Price: Free!</strong></em>
|
17 |
-
<br /><br />Link the following image to go to the Registration Page if you want your visitors to be able to create a free membership account<br /><br />
|
18 |
-
<img title="Join Now" src="' . SIMPLE_WP_MEMBERSHIP_URL . '/images/join-now-button-image.gif" alt="Join Now Button" width="277" height="82" />
|
19 |
-
<p style="border-bottom:1px solid #ccc;padding-bottom:10px;margin-bottom:10px;"></p>';
|
20 |
-
|
21 |
-
|
22 |
-
[ ==> Insert Payment Button For Your Paid Membership Levels Here <== ]
|
23 |
-
<p style="border-bottom:1px solid #ccc;padding-bottom:10px;margin-bottom:10px;"></p>';
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class SwpmMiscUtils {
|
4 |
+
|
5 |
+
public static function create_mandatory_wp_pages() {
|
6 |
+
$settings = SwpmSettings::get_instance();
|
7 |
+
|
8 |
+
//Create join us page
|
9 |
+
$swpm_join_page_content = '<p style="color:red;font-weight:bold;">This page and the content has been automatically generated for you to give you a basic idea of how a "Join Us" page should look like. You can customize this page however you like it by editing this page from your WordPress page editor.</p>';
|
10 |
+
$swpm_join_page_content .= '<p style="font-weight:bold;">If you end up changing the URL of this page then make sure to update the URL value in the settings menu of the plugin.</p>';
|
11 |
+
$swpm_join_page_content .= '<p style="border-top:1px solid #ccc;padding-top:10px;margin-top:10px;"></p>
|
12 |
+
<strong>Free Membership</strong>
|
13 |
+
<br />
|
14 |
+
You get unlimited access to free membership content
|
15 |
+
<br />
|
16 |
+
<em><strong>Price: Free!</strong></em>
|
17 |
+
<br /><br />Link the following image to go to the Registration Page if you want your visitors to be able to create a free membership account<br /><br />
|
18 |
+
<img title="Join Now" src="' . SIMPLE_WP_MEMBERSHIP_URL . '/images/join-now-button-image.gif" alt="Join Now Button" width="277" height="82" />
|
19 |
+
<p style="border-bottom:1px solid #ccc;padding-bottom:10px;margin-bottom:10px;"></p>';
|
20 |
+
$swpm_join_page_content .= '<p><strong>You can register for a Free Membership or pay for one of the following membership options</strong></p>';
|
21 |
+
$swpm_join_page_content .= '<p style="border-top:1px solid #ccc;padding-top:10px;margin-top:10px;"></p>
|
22 |
+
[ ==> Insert Payment Button For Your Paid Membership Levels Here <== ]
|
23 |
+
<p style="border-bottom:1px solid #ccc;padding-bottom:10px;margin-bottom:10px;"></p>';
|
24 |
+
|
25 |
+
$swpm_join_page = array(
|
26 |
+
'post_title' => 'Join Us',
|
27 |
+
'post_name' => 'membership-join',
|
28 |
+
'post_content' => $swpm_join_page_content,
|
29 |
+
'post_parent' => 0,
|
30 |
+
'post_status' => 'publish',
|
31 |
+
'post_type' => 'page',
|
32 |
+
'comment_status' => 'closed',
|
33 |
+
'ping_status' => 'closed',
|
34 |
+
);
|
35 |
+
|
36 |
+
$join_page_obj = get_page_by_path( 'membership-join' );
|
37 |
+
if ( ! $join_page_obj ) {
|
38 |
+
$join_page_id = wp_insert_post( $swpm_join_page );
|
39 |
+
} else {
|
40 |
+
$join_page_id = $join_page_obj->ID;
|
41 |
+
if ( $join_page_obj->post_status == 'trash' ) { //For cases where page may be in trash, bring it out of trash
|
42 |
+
wp_update_post(
|
43 |
+
array(
|
44 |
+
'ID' => $join_page_obj->ID,
|
45 |
+
'post_status' => 'publish',
|
46 |
+
)
|
47 |
+
);
|
48 |
+
}
|
49 |
+
}
|
50 |
+
$swpm_join_page_permalink = get_permalink( $join_page_id );
|
51 |
+
$settings->set_value( 'join-us-page-url', $swpm_join_page_permalink );
|
52 |
+
|
53 |
+
//Create registration page
|
54 |
+
$swpm_rego_page = array(
|
55 |
+
'post_title' => SwpmUtils::_( 'Registration' ),
|
56 |
+
'post_name' => 'membership-registration',
|
57 |
+
'post_content' => '[swpm_registration_form]',
|
58 |
+
'post_parent' => $join_page_id,
|
59 |
+
'post_status' => 'publish',
|
60 |
+
'post_type' => 'page',
|
61 |
+
'comment_status' => 'closed',
|
62 |
+
'ping_status' => 'closed',
|
63 |
+
);
|
64 |
+
$rego_page_obj = get_page_by_path( 'membership-registration' );
|
65 |
+
if ( ! $rego_page_obj ) {
|
66 |
+
$rego_page_id = wp_insert_post( $swpm_rego_page );
|
67 |
+
} else {
|
68 |
+
$rego_page_id = $rego_page_obj->ID;
|
69 |
+
if ( $rego_page_obj->post_status == 'trash' ) { //For cases where page may be in trash, bring it out of trash
|
70 |
+
wp_update_post(
|
71 |
+
array(
|
72 |
+
'ID' => $rego_page_obj->ID,
|
73 |
+
'post_status' => 'publish',
|
74 |
+
)
|
75 |
+
);
|
76 |
+
}
|
77 |
+
}
|
78 |
+
$swpm_rego_page_permalink = get_permalink( $rego_page_id );
|
79 |
+
$settings->set_value( 'registration-page-url', $swpm_rego_page_permalink );
|
80 |
+
|
81 |
+
//Create login page
|
82 |
+
$swpm_login_page = array(
|
83 |
+
'post_title' => SwpmUtils::_( 'Member Login' ),
|
84 |
+
'post_name' => 'membership-login',
|
85 |
+
'post_content' => '[swpm_login_form]',
|
86 |
+
'post_parent' => 0,
|
87 |
+
'post_status' => 'publish',
|
88 |
+
'post_type' => 'page',
|
89 |
+
'comment_status' => 'closed',
|
90 |
+
'ping_status' => 'closed',
|
91 |
+
);
|
92 |
+
$login_page_obj = get_page_by_path( 'membership-login' );
|
93 |
+
if ( ! $login_page_obj ) {
|
94 |
+
$login_page_id = wp_insert_post( $swpm_login_page );
|
95 |
+
} else {
|
96 |
+
$login_page_id = $login_page_obj->ID;
|
97 |
+
if ( $login_page_obj->post_status == 'trash' ) { //For cases where page may be in trash, bring it out of trash
|
98 |
+
wp_update_post(
|
99 |
+
array(
|
100 |
+
'ID' => $login_page_obj->ID,
|
101 |
+
'post_status' => 'publish',
|
102 |
+
)
|
103 |
+
);
|
104 |
+
}
|
105 |
+
}
|
106 |
+
$swpm_login_page_permalink = get_permalink( $login_page_id );
|
107 |
+
$settings->set_value( 'login-page-url', $swpm_login_page_permalink );
|
108 |
+
|
109 |
+
//Create profile page
|
110 |
+
$swpm_profile_page = array(
|
111 |
+
'post_title' => SwpmUtils::_( 'Profile' ),
|
112 |
+
'post_name' => 'membership-profile',
|
113 |
+
'post_content' => '[swpm_profile_form]',
|
114 |
+
'post_parent' => $login_page_id,
|
115 |
+
'post_status' => 'publish',
|
116 |
+
'post_type' => 'page',
|
117 |
+
'comment_status' => 'closed',
|
118 |
+
'ping_status' => 'closed',
|
119 |
+
);
|
120 |
+
$profile_page_obj = get_page_by_path( 'membership-profile' );
|
121 |
+
if ( ! $profile_page_obj ) {
|
122 |
+
$profile_page_id = wp_insert_post( $swpm_profile_page );
|
123 |
+
} else {
|
124 |
+
$profile_page_id = $profile_page_obj->ID;
|
125 |
+
if ( $profile_page_obj->post_status == 'trash' ) { //For cases where page may be in trash, bring it out of trash
|
126 |
+
wp_update_post(
|
127 |
+
array(
|
128 |
+
'ID' => $profile_page_obj->ID,
|
129 |
+
'post_status' => 'publish',
|
130 |
+
)
|
131 |
+
);
|
132 |
+
}
|
133 |
+
}
|
134 |
+
$swpm_profile_page_permalink = get_permalink( $profile_page_id );
|
135 |
+
$settings->set_value( 'profile-page-url', $swpm_profile_page_permalink );
|
136 |
+
|
137 |
+
//Create reset page
|
138 |
+
$swpm_reset_page = array(
|
139 |
+
'post_title' => SwpmUtils::_( 'Password Reset' ),
|
140 |
+
'post_name' => 'password-reset',
|
141 |
+
'post_content' => '[swpm_reset_form]',
|
142 |
+
'post_parent' => $login_page_id,
|
143 |
+
'post_status' => 'publish',
|
144 |
+
'post_type' => 'page',
|
145 |
+
'comment_status' => 'closed',
|
146 |
+
'ping_status' => 'closed',
|
147 |
+
);
|
148 |
+
$reset_page_obj = get_page_by_path( 'password-reset' );
|
149 |
+
if ( ! $profile_page_obj ) {
|
150 |
+
$reset_page_id = wp_insert_post( $swpm_reset_page );
|
151 |
+
} else {
|
152 |
+
$reset_page_id = $reset_page_obj->ID;
|
153 |
+
if ( $reset_page_obj->post_status == 'trash' ) { //For cases where page may be in trash, bring it out of trash
|
154 |
+
wp_update_post(
|
155 |
+
array(
|
156 |
+
'ID' => $reset_page_obj->ID,
|
157 |
+
'post_status' => 'publish',
|
158 |
+
)
|
159 |
+
);
|
160 |
+
}
|
161 |
+
}
|
162 |
+
$swpm_reset_page_permalink = get_permalink( $reset_page_id );
|
163 |
+
$settings->set_value( 'reset-page-url', $swpm_reset_page_permalink );
|
164 |
+
|
165 |
+
$settings->save(); //Save all settings object changes
|
166 |
+
}
|
167 |
+
|
168 |
+
public static function redirect_to_url( $url ) {
|
169 |
+
if ( empty( $url ) ) {
|
170 |
+
return;
|
171 |
+
}
|
172 |
+
$url = apply_filters( 'swpm_redirect_to_url', $url );
|
173 |
+
|
174 |
+
if ( ! preg_match( '/http/', $url ) ) {//URL value is incorrect
|
175 |
+
echo '<p>Error! The URL value you entered in the plugin configuration is incorrect.</p>';
|
176 |
+
echo '<p>A URL must always have the "http" keyword in it.</p>';
|
177 |
+
echo '<p style="font-weight: bold;">The URL value you currently configured is: <br />' . $url . '</p>';
|
178 |
+
echo '<p>Here are some examples of correctly formatted URL values for your reference: <br />http://www.example.com<br/>http://example.com<br />https://www.example.com</p>';
|
179 |
+
echo '<p>Find the field where you entered this incorrect URL value and correct the mistake then try again.</p>';
|
180 |
+
exit;
|
181 |
+
}
|
182 |
+
if ( ! headers_sent() ) {
|
183 |
+
header( 'Location: ' . $url );
|
184 |
+
} else {
|
185 |
+
echo '<meta http-equiv="refresh" content="0;url=' . $url . '" />';
|
186 |
+
}
|
187 |
+
exit;
|
188 |
+
}
|
189 |
+
|
190 |
+
public static function show_temporary_message_then_redirect( $msg, $redirect_url, $timeout = 5 ) {
|
191 |
+
$timeout = absint( $timeout );
|
192 |
+
$redirect_html = sprintf( '<meta http-equiv="refresh" content="%d; url=\'%s\'" />', $timeout, $redirect_url );
|
193 |
+
$redir_msg = SwpmUtils::_( 'You will be automatically redirected in a few seconds. If not, please %s.' );
|
194 |
+
$redir_msg = sprintf( $redir_msg, '<a href="' . $redirect_url . '">' . SwpmUtils::_( 'click here' ) . '</a>' );
|
195 |
+
|
196 |
+
$msg = $msg . '<br/><br/>' . $redir_msg . $redirect_html;
|
197 |
+
$title = SwpmUtils::_( 'Action Status' );
|
198 |
+
wp_die( $msg, $title );
|
199 |
+
}
|
200 |
+
|
201 |
+
public static function get_current_page_url() {
|
202 |
+
$pageURL = 'http';
|
203 |
+
|
204 |
+
if ( isset( $_SERVER['SCRIPT_URI'] ) && ! empty( $_SERVER['SCRIPT_URI'] ) ) {
|
205 |
+
$pageURL = $_SERVER['SCRIPT_URI'];
|
206 |
+
$pageURL = apply_filters( 'swpm_get_current_page_url_filter', $pageURL );
|
207 |
+
return $pageURL;
|
208 |
+
}
|
209 |
+
|
210 |
+
if ( isset( $_SERVER['HTTPS'] ) && ( $_SERVER['HTTPS'] == 'on' ) ) {
|
211 |
+
$pageURL .= 's';
|
212 |
+
}
|
213 |
+
$pageURL .= '://';
|
214 |
+
if ( isset( $_SERVER['SERVER_PORT'] ) && ( $_SERVER['SERVER_PORT'] != '80' ) && ( $_SERVER['SERVER_PORT'] != '443' ) ) {
|
215 |
+
$pageURL .= ltrim( $_SERVER['SERVER_NAME'], '.*' ) . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
|
216 |
+
} else {
|
217 |
+
$pageURL .= ltrim( $_SERVER['SERVER_NAME'], '.*' ) . $_SERVER['REQUEST_URI'];
|
218 |
+
}
|
219 |
+
|
220 |
+
$pageURL = apply_filters( 'swpm_get_current_page_url_filter', $pageURL );
|
221 |
+
|
222 |
+
return $pageURL;
|
223 |
+
}
|
224 |
+
|
225 |
+
/*
|
226 |
+
* This is an alternative to the get_current_page_url() function. It needs to be tested on many different server conditions before it can be utilized
|
227 |
+
*/
|
228 |
+
public static function get_current_page_url_alt() {
|
229 |
+
$url_parts = array();
|
230 |
+
$url_parts['proto'] = 'http';
|
231 |
+
|
232 |
+
if ( isset( $_SERVER['SCRIPT_URI'] ) && ! empty( $_SERVER['SCRIPT_URI'] ) ) {
|
233 |
+
return $_SERVER['SCRIPT_URI'];
|
234 |
+
}
|
235 |
+
|
236 |
+
if ( isset( $_SERVER['HTTPS'] ) && ( $_SERVER['HTTPS'] == 'on' ) ) {
|
237 |
+
$url_parts['proto'] = 'https';
|
238 |
+
}
|
239 |
+
|
240 |
+
$url_parts['port'] = '';
|
241 |
+
if ( isset( $_SERVER['SERVER_PORT'] ) && ( $_SERVER['SERVER_PORT'] != '80' ) && ( $_SERVER['SERVER_PORT'] != '443' ) ) {
|
242 |
+
$url_parts['port'] = $_SERVER['SERVER_PORT'];
|
243 |
+
}
|
244 |
+
|
245 |
+
$url_parts['domain'] = ltrim( $_SERVER['SERVER_NAME'], '.*' );
|
246 |
+
$url_parts['uri'] = $_SERVER['REQUEST_URI'];
|
247 |
+
|
248 |
+
$url_parts = apply_filters( 'swpm_get_current_page_url_alt_filter', $url_parts );
|
249 |
+
|
250 |
+
$pageURL = sprintf( '%s://%s%s%s', $url_parts['proto'], $url_parts['domain'], ! empty( $url_parts['port'] ) ? ':' . $url_parts['port'] : '', $url_parts['uri'] );
|
251 |
+
|
252 |
+
return $pageURL;
|
253 |
+
}
|
254 |
+
|
255 |
+
/*
|
256 |
+
* Returns just the domain name. Something like example.com
|
257 |
+
*/
|
258 |
+
|
259 |
+
public static function get_home_url_without_http_and_www() {
|
260 |
+
$site_url = get_site_url();
|
261 |
+
$parse = parse_url( $site_url );
|
262 |
+
$site_url = $parse['host'];
|
263 |
+
$site_url = str_replace( 'https://', '', $site_url );
|
264 |
+
$site_url = str_replace( 'http://', '', $site_url );
|
265 |
+
if ( preg_match( '/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $site_url, $regs ) ) {
|
266 |
+
$site_url = $regs['domain'];
|
267 |
+
}
|
268 |
+
return $site_url;
|
269 |
+
}
|
270 |
+
|
271 |
+
public static function replace_dynamic_tags( $msg_body, $member_id, $additional_args = '' ) {
|
272 |
+
$settings = SwpmSettings::get_instance();
|
273 |
+
$user_record = SwpmMemberUtils::get_user_by_id( $member_id );
|
274 |
+
|
275 |
+
$password = '';
|
276 |
+
$reg_link = '';
|
277 |
+
if ( ! empty( $additional_args ) ) {
|
278 |
+
$password = isset( $additional_args['password'] ) ? $additional_args['password'] : $password;
|
279 |
+
$reg_link = isset( $additional_args['reg_link'] ) ? $additional_args['reg_link'] : $reg_link;
|
280 |
+
}
|
281 |
+
$login_link = $settings->get_value( 'login-page-url' );
|
282 |
+
|
283 |
+
//Construct the primary address value
|
284 |
+
$primary_address = '';
|
285 |
+
if ( ! empty( $user_record->address_street ) && ! empty( $user_record->address_city ) ) {
|
286 |
+
//An address value is present.
|
287 |
+
$primary_address .= $user_record->address_street;
|
288 |
+
$primary_address .= "\n" . $user_record->address_city;
|
289 |
+
if ( ! empty( $user_record->address_state ) ) {
|
290 |
+
$primary_address .= ' ' . $user_record->address_state;
|
291 |
+
}
|
292 |
+
if ( ! empty( $user_record->address_zipcode ) ) {
|
293 |
+
$primary_address .= ' ' . $user_record->address_zipcode;
|
294 |
+
}
|
295 |
+
if ( ! empty( $user_record->country ) ) {
|
296 |
+
$primary_address .= "\n" . $user_record->country;
|
297 |
+
}
|
298 |
+
}
|
299 |
+
|
300 |
+
$membership_level_name = SwpmMembershipLevelUtils::get_membership_level_name_of_a_member( $member_id );
|
301 |
+
//Format some field values
|
302 |
+
$member_since_formatted = SwpmUtils::get_formatted_date_according_to_wp_settings( $user_record->member_since );
|
303 |
+
$subsc_starts_formatted = SwpmUtils::get_formatted_date_according_to_wp_settings( $user_record->subscription_starts );
|
304 |
+
|
305 |
+
//Define the replacable tags
|
306 |
+
$tags = array(
|
307 |
+
'{member_id}',
|
308 |
+
'{user_name}',
|
309 |
+
'{first_name}',
|
310 |
+
'{last_name}',
|
311 |
+
'{membership_level}',
|
312 |
+
'{membership_level_name}',
|
313 |
+
'{account_state}',
|
314 |
+
'{email}',
|
315 |
+
'{phone}',
|
316 |
+
'{member_since}',
|
317 |
+
'{subscription_starts}',
|
318 |
+
'{company_name}',
|
319 |
+
'{password}',
|
320 |
+
'{login_link}',
|
321 |
+
'{reg_link}',
|
322 |
+
'{primary_address}',
|
323 |
+
);
|
324 |
+
|
325 |
+
//Define the values
|
326 |
+
$vals = array(
|
327 |
+
$member_id,
|
328 |
+
$user_record->user_name,
|
329 |
+
$user_record->first_name,
|
330 |
+
$user_record->last_name,
|
331 |
+
$user_record->membership_level,
|
332 |
+
$membership_level_name,
|
333 |
+
$user_record->account_state,
|
334 |
+
$user_record->email,
|
335 |
+
$user_record->phone,
|
336 |
+
$member_since_formatted,
|
337 |
+
$subsc_starts_formatted,
|
338 |
+
$user_record->company_name,
|
339 |
+
$password,
|
340 |
+
$login_link,
|
341 |
+
$reg_link,
|
342 |
+
$primary_address,
|
343 |
+
);
|
344 |
+
|
345 |
+
$msg_body = str_replace( $tags, $vals, $msg_body );
|
346 |
+
return $msg_body;
|
347 |
+
}
|
348 |
+
|
349 |
+
public static function get_login_link() {
|
350 |
+
$login_url = SwpmSettings::get_instance()->get_value( 'login-page-url' );
|
351 |
+
$joinus_url = SwpmSettings::get_instance()->get_value( 'join-us-page-url' );
|
352 |
+
if ( empty( $login_url ) || empty( $joinus_url ) ) {
|
353 |
+
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. '
|
354 |
+
. 'Please contact <a href="mailto:' . get_option( 'admin_email' ) . '">Admin</a>';
|
355 |
+
}
|
356 |
+
|
357 |
+
//Create the login/protection message
|
358 |
+
$filtered_login_url = apply_filters( 'swpm_get_login_link_url', $login_url ); //Addons can override the login URL value using this filter.
|
359 |
+
$login_msg = '';
|
360 |
+
$login_msg .= SwpmUtils::_( 'Please' ) . ' <a class="swpm-login-link" href="' . $filtered_login_url . '">' . SwpmUtils::_( 'Login' ) . '</a>. ';
|
361 |
+
$login_msg .= SwpmUtils::_( 'Not a Member?' ) . ' <a href="' . $joinus_url . '">' . SwpmUtils::_( 'Join Us' ) . '</a>';
|
362 |
+
|
363 |
+
return $login_msg;
|
364 |
+
}
|
365 |
+
|
366 |
+
public static function get_renewal_link() {
|
367 |
+
$renewal = SwpmSettings::get_instance()->get_value( 'renewal-page-url' );
|
368 |
+
if ( empty( $renewal ) ) {
|
369 |
+
//No renewal page is configured so don't show any renewal page link. It is okay to have no renewal page configured.
|
370 |
+
return '';
|
371 |
+
}
|
372 |
+
return SwpmUtils::_( 'Please' ) . ' <a class="swpm-renewal-link" href="' . $renewal . '">' . SwpmUtils::_( 'renew' ) . '</a> ' . SwpmUtils::_( ' your account to gain access to this content.' );
|
373 |
+
}
|
374 |
+
|
375 |
+
public static function compare_url( $url1, $url2 ) {
|
376 |
+
$url1 = trailingslashit( strtolower( $url1 ) );
|
377 |
+
$url2 = trailingslashit( strtolower( $url2 ) );
|
378 |
+
if ( $url1 == $url2 ) {
|
379 |
+
return true;
|
380 |
+
}
|
381 |
+
|
382 |
+
$url1 = parse_url( $url1 );
|
383 |
+
$url2 = parse_url( $url2 );
|
384 |
+
|
385 |
+
$components = array( 'scheme', 'host', 'port', 'path' );
|
386 |
+
|
387 |
+
foreach ( $components as $key => $value ) {
|
388 |
+
if ( ! isset( $url1[ $value ] ) && ! isset( $url2[ $value ] ) ) {
|
389 |
+
continue;
|
390 |
+
}
|
391 |
+
|
392 |
+
if ( ! isset( $url2[ $value ] ) ) {
|
393 |
+
return false;
|
394 |
+
}
|
395 |
+
if ( ! isset( $url1[ $value ] ) ) {
|
396 |
+
return false;
|
397 |
+
}
|
398 |
+
|
399 |
+
if ( $url1[ $value ] != $url2[ $value ] ) {
|
400 |
+
return false;
|
401 |
+
}
|
402 |
+
}
|
403 |
+
|
404 |
+
if ( ! isset( $url1['query'] ) && ! isset( $url2['query'] ) ) {
|
405 |
+
return true;
|
406 |
+
}
|
407 |
+
|
408 |
+
if ( ! isset( $url2['query'] ) ) {
|
409 |
+
return false;
|
410 |
+
}
|
411 |
+
if ( ! isset( $url1['query'] ) ) {
|
412 |
+
return false;
|
413 |
+
}
|
414 |
+
|
415 |
+
return strpos( $url1['query'], $url2['query'] ) || strpos( $url2['query'], $url1['query'] );
|
416 |
+
}
|
417 |
+
|
418 |
+
public static function is_swpm_admin_page() {
|
419 |
+
if ( isset( $_GET['page'] ) && ( stripos( $_GET['page'], 'simple_wp_membership' ) !== false ) ) {
|
420 |
+
//This is an admin page of the SWPM plugin
|
421 |
+
return true;
|
422 |
+
}
|
423 |
+
return false;
|
424 |
+
}
|
425 |
+
|
426 |
+
public static function check_user_permission_and_is_admin( $action_name ) {
|
427 |
+
//Check we are on the admin end
|
428 |
+
if ( ! is_admin() ) {
|
429 |
+
//Error! This is not on the admin end. This can only be done from the admin side
|
430 |
+
wp_die( SwpmUtils::_( 'Error! This action (' . $action_name . ') can only be done from admin end.' ) );
|
431 |
+
}
|
432 |
+
|
433 |
+
//Check user has management permission
|
434 |
+
if ( ! current_user_can( SWPM_MANAGEMENT_PERMISSION ) ) {
|
435 |
+
//Error! Only management users can do this
|
436 |
+
wp_die( SwpmUtils::_( 'Error! This action (' . $action_name . ') can only be done by an user with management permission.' ) );
|
437 |
+
}
|
438 |
+
}
|
439 |
+
|
440 |
+
public static function format_raw_content_for_front_end_display( $raw_content ) {
|
441 |
+
$formatted_content = wptexturize( $raw_content );
|
442 |
+
$formatted_content = convert_smilies( $formatted_content );
|
443 |
+
$formatted_content = convert_chars( $formatted_content );
|
444 |
+
$formatted_content = wpautop( $formatted_content );
|
445 |
+
$formatted_content = shortcode_unautop( $formatted_content );
|
446 |
+
$formatted_content = prepend_attachment( $formatted_content );
|
447 |
+
$formatted_content = capital_P_dangit( $formatted_content );
|
448 |
+
$formatted_content = do_shortcode( $formatted_content );
|
449 |
+
|
450 |
+
return $formatted_content;
|
451 |
+
}
|
452 |
+
|
453 |
+
public static function get_countries_dropdown( $country = '' ) {
|
454 |
+
$countries = array(
|
455 |
+
'Afghanistan',
|
456 |
+
'Albania',
|
457 |
+
'Algeria',
|
458 |
+
'Andorra',
|
459 |
+
'Angola',
|
460 |
+
'Antigua and Barbuda',
|
461 |
+
'Argentina',
|
462 |
+
'Armenia',
|
463 |
+
'Aruba',
|
464 |
+
'Australia',
|
465 |
+
'Austria',
|
466 |
+
'Azerbaijan',
|
467 |
+
'Bahamas',
|
468 |
+
'Bahrain',
|
469 |
+
'Bangladesh',
|
470 |
+
'Barbados',
|
471 |
+
'Belarus',
|
472 |
+
'Belgium',
|
473 |
+
'Belize',
|
474 |
+
'Benin',
|
475 |
+
'Bhutan',
|
476 |
+
'Bolivia',
|
477 |
+
'Bonaire',
|
478 |
+
'Bosnia and Herzegovina',
|
479 |
+
'Botswana',
|
480 |
+
'Brazil',
|
481 |
+
'Brunei',
|
482 |
+
'Bulgaria',
|
483 |
+
'Burkina Faso',
|
484 |
+
'Burundi',
|
485 |
+
'Cambodia',
|
486 |
+
'Cameroon',
|
487 |
+
'Canada',
|
488 |
+
'Cape Verde',
|
489 |
+
'Central African Republic',
|
490 |
+
'Chad',
|
491 |
+
'Chile',
|
492 |
+
'China',
|
493 |
+
'Colombia',
|
494 |
+
'Comoros',
|
495 |
+
'Congo (Brazzaville)',
|
496 |
+
'Congo',
|
497 |
+
'Costa Rica',
|
498 |
+
"Cote d\'Ivoire",
|
499 |
+
'Croatia',
|
500 |
+
'Cuba',
|
501 |
+
'Curacao',
|
502 |
+
'Cyprus',
|
503 |
+
'Czech Republic',
|
504 |
+
'Denmark',
|
505 |
+
'Djibouti',
|
506 |
+
'Dominica',
|
507 |
+
'Dominican Republic',
|
508 |
+
'East Timor (Timor Timur)',
|
509 |
+
'Ecuador',
|
510 |
+
'Egypt',
|
511 |
+
'El Salvador',
|
512 |
+
'Equatorial Guinea',
|
513 |
+
'Eritrea',
|
514 |
+
'Estonia',
|
515 |
+
'Ethiopia',
|
516 |
+
'Fiji',
|
517 |
+
'Finland',
|
518 |
+
'France',
|
519 |
+
'Gabon',
|
520 |
+
'Gambia, The',
|
521 |
+
'Georgia',
|
522 |
+
'Germany',
|
523 |
+
'Ghana',
|
524 |
+
'Greece',
|
525 |
+
'Grenada',
|
526 |
+
'Guatemala',
|
527 |
+
'Guinea',
|
528 |
+
'Guinea-Bissau',
|
529 |
+
'Guyana',
|
530 |
+
'Haiti',
|
531 |
+
'Honduras',
|
532 |
+
'Hong Kong',
|
533 |
+
'Hungary',
|
534 |
+
'Iceland',
|
535 |
+
'India',
|
536 |
+
'Indonesia',
|
537 |
+
'Iran',
|
538 |
+
'Iraq',
|
539 |
+
'Ireland',
|
540 |
+
'Israel',
|
541 |
+
'Italy',
|
542 |
+
'Jamaica',
|
543 |
+
'Japan',
|
544 |
+
'Jordan',
|
545 |
+
'Kazakhstan',
|
546 |
+
'Kenya',
|
547 |
+
'Kiribati',
|
548 |
+
'Korea, North',
|
549 |
+
'Korea, South',
|
550 |
+
'Kuwait',
|
551 |
+
'Kyrgyzstan',
|
552 |
+
'Laos',
|
553 |
+
'Latvia',
|
554 |
+
'Lebanon',
|
555 |
+
'Lesotho',
|
556 |
+
'Liberia',
|
557 |
+
'Libya',
|
558 |
+
'Liechtenstein',
|
559 |
+
'Lithuania',
|
560 |
+
'Luxembourg',
|
561 |
+
'Macedonia',
|
562 |
+
'Madagascar',
|
563 |
+
'Malawi',
|
564 |
+
'Malaysia',
|
565 |
+
'Maldives',
|
566 |
+
'Mali',
|
567 |
+
'Malta',
|
568 |
+
'Marshall Islands',
|
569 |
+
'Mauritania',
|
570 |
+
'Mauritius',
|
571 |
+
'Mexico',
|
572 |
+
'Micronesia',
|
573 |
+
'Moldova',
|
574 |
+
'Monaco',
|
575 |
+
'Mongolia',
|
576 |
+
'Montenegro',
|
577 |
+
'Morocco',
|
578 |
+
'Mozambique',
|
579 |
+
'Myanmar',
|
580 |
+
'Namibia',
|
581 |
+
'Nauru',
|
582 |
+
'Nepa',
|
583 |
+
'Netherlands',
|
584 |
+
'New Zealand',
|
585 |
+
'Nicaragua',
|
586 |
+
'Niger',
|
587 |
+
'Nigeria',
|
588 |
+
'Norway',
|
589 |
+
'Oman',
|
590 |
+
'Pakistan',
|
591 |
+
'Palau',
|
592 |
+
'Panama',
|
593 |
+
'Papua New Guinea',
|
594 |
+
'Paraguay',
|
595 |
+
'Peru',
|
596 |
+
'Philippines',
|
597 |
+
'Poland',
|
598 |
+
'Portugal',
|
599 |
+
'Qatar',
|
600 |
+
'Romania',
|
601 |
+
'Russia',
|
602 |
+
'Rwanda',
|
603 |
+
'Saint Kitts and Nevis',
|
604 |
+
'Saint Lucia',
|
605 |
+
'Saint Vincent',
|
606 |
+
'Samoa',
|
607 |
+
'San Marino',
|
608 |
+
'Sao Tome and Principe',
|
609 |
+
'Saudi Arabia',
|
610 |
+
'Senegal',
|
611 |
+
'Serbia',
|
612 |
+
'Seychelles',
|
613 |
+
'Sierra Leone',
|
614 |
+
'Singapore',
|
615 |
+
'Slovakia',
|
616 |
+
'Slovenia',
|
617 |
+
'Solomon Islands',
|
618 |
+
'Somalia',
|
619 |
+
'South Africa',
|
620 |
+
'Spain',
|
621 |
+
'Sri Lanka',
|
622 |
+
'Sudan',
|
623 |
+
'Suriname',
|
624 |
+
'Swaziland',
|
625 |
+
'Sweden',
|
626 |
+
'Switzerland',
|
627 |
+
'Syria',
|
628 |
+
'Taiwan',
|
629 |
+
'Tajikistan',
|
630 |
+
'Tanzania',
|
631 |
+
'Thailand',
|
632 |
+
'Togo',
|
633 |
+
'Tonga',
|
634 |
+
'Trinidad and Tobago',
|
635 |
+
'Tunisia',
|
636 |
+
'Turkey',
|
637 |
+
'Turkmenistan',
|
638 |
+
'Tuvalu',
|
639 |
+
'Uganda',
|
640 |
+
'Ukraine',
|
641 |
+
'United Arab Emirates',
|
642 |
+
'United Kingdom',
|
643 |
+
'United States of America',
|
644 |
+
'Uruguay',
|
645 |
+
'Uzbekistan',
|
646 |
+
'Vanuatu',
|
647 |
+
'Vatican City',
|
648 |
+
'Venezuela',
|
649 |
+
'Vietnam',
|
650 |
+
'Yemen',
|
651 |
+
'Zambia',
|
652 |
+
'Zimbabwe',
|
653 |
+
);
|
654 |
+
//let's try to "guess" country name
|
655 |
+
$curr_lev = -1;
|
656 |
+
$guess_country = '';
|
657 |
+
foreach ( $countries as $country_name ) {
|
658 |
+
similar_text( strtolower( $country ), strtolower( $country_name ), $lev );
|
659 |
+
if ( $lev >= $curr_lev ) {
|
660 |
+
//this is closest match so far
|
661 |
+
$curr_lev = $lev;
|
662 |
+
$guess_country = $country_name;
|
663 |
+
}
|
664 |
+
if ( $curr_lev == 100 ) {
|
665 |
+
//exact match
|
666 |
+
break;
|
667 |
+
}
|
668 |
+
}
|
669 |
+
if ( $curr_lev <= 80 ) {
|
670 |
+
// probably bad guess
|
671 |
+
$guess_country = '';
|
672 |
+
}
|
673 |
+
$countries_dropdown = '';
|
674 |
+
//let's add "(Please select)" option
|
675 |
+
$countries_dropdown .= "\r\n" . '<option value=""' . ( $country == '' ? ' selected' : '' ) . '>' . SwpmUtils::_( '(Please Select)' ) . '</option>';
|
676 |
+
if ( $guess_country == '' && $country != '' ) {
|
677 |
+
//since we haven't guessed the country name, let's add current value to the options
|
678 |
+
$countries_dropdown .= "\r\n" . '<option value="' . $country . '" selected>' . $country . '</option>';
|
679 |
+
}
|
680 |
+
if ( $guess_country != '' ) {
|
681 |
+
$country = $guess_country;
|
682 |
+
}
|
683 |
+
foreach ( $countries as $country_name ) {
|
684 |
+
$countries_dropdown .= "\r\n" . '<option value="' . $country_name . '"' . ( strtolower( $country_name ) == strtolower( $country ) ? ' selected' : '' ) . '>' . $country_name . '</option>';
|
685 |
+
}
|
686 |
+
return $countries_dropdown;
|
687 |
+
}
|
688 |
+
|
689 |
+
public static function get_button_type_name( $button_type ) {
|
690 |
+
$btnTypesNames = array(
|
691 |
+
'pp_buy_now' => SwpmUtils::_( 'PayPal Buy Now' ),
|
692 |
+
'pp_subscription' => SwpmUtils::_( 'PayPal Subscription' ),
|
693 |
+
'pp_smart_checkout' => SwpmUtils::_( 'PayPal Smart Checkout' ),
|
694 |
+
'stripe_buy_now' => SwpmUtils::_( 'Stripe Buy Now' ),
|
695 |
+
'stripe_subscription' => SwpmUtils::_( 'Stripe Subscription' ),
|
696 |
+
'stripe_sca_buy_now' => SwpmUtils::_( 'Stripe SCA Buy Now' ),
|
697 |
+
'stripe_sca_subscription' => SwpmUtils::_( 'Stripe SCA Subscription' ),
|
698 |
+
'braintree_buy_now' => SwpmUtils::_( 'Braintree Buy Now' ),
|
699 |
+
);
|
700 |
+
|
701 |
+
$button_type_name = $button_type;
|
702 |
+
|
703 |
+
if ( array_key_exists( $button_type, $btnTypesNames ) ) {
|
704 |
+
$button_type_name = $btnTypesNames[ $button_type ];
|
705 |
+
}
|
706 |
+
|
707 |
+
return $button_type_name;
|
708 |
+
}
|
709 |
+
|
710 |
+
public static function format_money( $amount, $currency = false ) {
|
711 |
+
$formatted = number_format( $amount, 2 );
|
712 |
+
if ( $currency ) {
|
713 |
+
$formatted .= ' ' . $currency;
|
714 |
+
}
|
715 |
+
return $formatted;
|
716 |
+
}
|
717 |
+
|
718 |
+
public static function load_stripe_lib() {
|
719 |
+
//this function loads Stripe PHP SDK and ensures only once instance is loaded
|
720 |
+
if ( ! class_exists( '\Stripe\Stripe' ) ) {
|
721 |
+
require_once SIMPLE_WP_MEMBERSHIP_PATH . 'lib/stripe-gateway/init.php';
|
722 |
+
}
|
723 |
+
}
|
724 |
+
|
725 |
+
public static function mail( $email, $subject, $email_body, $headers ) {
|
726 |
+
$settings = SwpmSettings::get_instance();
|
727 |
+
$html_enabled = $settings->get_value( 'email-enable-html' );
|
728 |
+
if ( ! empty( $html_enabled ) ) {
|
729 |
+
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
|
730 |
+
$email_body = nl2br( $email_body );
|
731 |
+
}
|
732 |
+
wp_mail( $email, $subject, $email_body, $headers );
|
733 |
+
}
|
734 |
+
|
735 |
+
}
|
classes/class.swpm-utils.php
CHANGED
@@ -2,516 +2,523 @@
|
|
2 |
|
3 |
abstract class SwpmUtils {
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
|
517 |
}
|
2 |
|
3 |
abstract class SwpmUtils {
|
4 |
|
5 |
+
public static function is_ajax() {
|
6 |
+
return defined( 'DOING_AJAX' ) && DOING_AJAX;
|
7 |
+
}
|
8 |
+
|
9 |
+
/*
|
10 |
+
* This function handles various initial setup tasks that need to be executed very early on (before other functions of the plugin is called).
|
11 |
+
*/
|
12 |
+
|
13 |
+
public static function do_misc_initial_plugin_setup_tasks() {
|
14 |
+
|
15 |
+
//Management role/permission setup
|
16 |
+
$admin_dashboard_permission = SwpmSettings::get_instance()->get_value( 'admin-dashboard-access-permission' );
|
17 |
+
if ( empty( $admin_dashboard_permission ) ) {
|
18 |
+
//By default only admins can manage/see admin dashboard
|
19 |
+
define( 'SWPM_MANAGEMENT_PERMISSION', 'manage_options' );
|
20 |
+
} else {
|
21 |
+
define( 'SWPM_MANAGEMENT_PERMISSION', $admin_dashboard_permission );
|
22 |
+
}
|
23 |
+
|
24 |
+
//Set timezone preference (if enabled in settings)
|
25 |
+
$use_wp_timezone = SwpmSettings::get_instance()->get_value( 'use-wordpress-timezone' );
|
26 |
+
if ( ! empty( $use_wp_timezone ) ) {//Set the wp timezone
|
27 |
+
$wp_timezone_string = get_option( 'timezone_string' );
|
28 |
+
if ( ! empty( $wp_timezone_string ) ) {
|
29 |
+
date_default_timezone_set( $wp_timezone_string );
|
30 |
+
}
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
public static function subscription_type_dropdown( $selected ) {
|
35 |
+
return '<option ' . ( ( $selected == SwpmMembershipLevel::NO_EXPIRY ) ? 'selected="selected"' : '' ) . ' value="' . SwpmMembershipLevel::NO_EXPIRY . '">No Expiry</option>' .
|
36 |
+
'<option ' . ( ( $selected == SwpmMembershipLevel::DAYS ) ? 'selected="selected"' : '' ) . ' value="' . SwpmMembershipLevel::DAYS . '">Day(s)</option>' .
|
37 |
+
'<option ' . ( ( $selected == SwpmMembershipLevel::WEEKS ) ? 'selected="selected"' : '' ) . ' value="' . SwpmMembershipLevel::WEEKS . '">Week(s)</option>' .
|
38 |
+
'<option ' . ( ( $selected == SwpmMembershipLevel::MONTHS ) ? 'selected="selected"' : '' ) . ' value="' . SwpmMembershipLevel::MONTHS . '">Month(s)</option>' .
|
39 |
+
'<option ' . ( ( $selected == SwpmMembershipLevel::YEARS ) ? 'selected="selected"' : '' ) . ' value="' . SwpmMembershipLevel::YEARS . '">Year(s)</option>' .
|
40 |
+
'<option ' . ( ( $selected == SwpmMembershipLevel::FIXED_DATE ) ? 'selected="selected"' : '' ) . ' value="' . SwpmMembershipLevel::FIXED_DATE . '">Fixed Date</option>';
|
41 |
+
}
|
42 |
+
|
43 |
+
// $subscript_period must be integer.
|
44 |
+
public static function calculate_subscription_period_days( $subcript_period, $subscription_duration_type ) {
|
45 |
+
if ( $subscription_duration_type == SwpmMembershipLevel::NO_EXPIRY ) {
|
46 |
+
return 'noexpire';
|
47 |
+
}
|
48 |
+
if ( ! is_numeric( $subcript_period ) ) {
|
49 |
+
throw new Exception( ' subcript_period parameter must be integer in SwpmUtils::calculate_subscription_period_days method' );
|
50 |
+
}
|
51 |
+
switch ( strtolower( $subscription_duration_type ) ) {
|
52 |
+
case SwpmMembershipLevel::DAYS:
|
53 |
+
break;
|
54 |
+
case SwpmMembershipLevel::WEEKS:
|
55 |
+
$subcript_period = $subcript_period * 7;
|
56 |
+
break;
|
57 |
+
case SwpmMembershipLevel::MONTHS:
|
58 |
+
$subcript_period = $subcript_period * 30;
|
59 |
+
break;
|
60 |
+
case SwpmMembershipLevel::YEARS:
|
61 |
+
$subcript_period = $subcript_period * 365;
|
62 |
+
break;
|
63 |
+
}
|
64 |
+
return $subcript_period;
|
65 |
+
}
|
66 |
+
|
67 |
+
public static function get_expiration_timestamp( $user ) {
|
68 |
+
$permission = SwpmPermission::get_instance( $user->membership_level );
|
69 |
+
if ( SwpmMembershipLevel::FIXED_DATE == $permission->get( 'subscription_duration_type' ) ) {
|
70 |
+
return strtotime( $permission->get( 'subscription_period' ) );
|
71 |
+
}
|
72 |
+
$days = self::calculate_subscription_period_days( $permission->get( 'subscription_period' ), $permission->get( 'subscription_duration_type' ) );
|
73 |
+
if ( $days == 'noexpire' ) {
|
74 |
+
return PHP_INT_MAX; // which is equivalent to
|
75 |
+
}
|
76 |
+
return strtotime( $user->subscription_starts . ' ' . $days . ' days' );
|
77 |
+
}
|
78 |
+
|
79 |
+
public static function is_subscription_expired( $user ) {
|
80 |
+
$expiration_timestamp = self::get_expiration_timestamp( $user );
|
81 |
+
if ( $expiration_timestamp < time() ) {
|
82 |
+
//Account expired.
|
83 |
+
return true;
|
84 |
+
}
|
85 |
+
return false;
|
86 |
+
}
|
87 |
+
|
88 |
+
/*
|
89 |
+
* Returns a formatted expiry date string (of a member). This can be useful to echo the date value.
|
90 |
+
*/
|
91 |
+
|
92 |
+
public static function get_formatted_expiry_date( $start_date, $subscription_duration, $subscription_duration_type ) {
|
93 |
+
if ( $subscription_duration_type == SwpmMembershipLevel::FIXED_DATE ) {
|
94 |
+
//Membership will expire after a fixed date.
|
95 |
+
return self::get_formatted_and_translated_date_according_to_wp_settings( $subscription_duration );
|
96 |
+
}
|
97 |
+
|
98 |
+
$expires = self::calculate_subscription_period_days( $subscription_duration, $subscription_duration_type );
|
99 |
+
if ( $expires == 'noexpire' ) {
|
100 |
+
//Membership is set to no expiry or until cancelled.
|
101 |
+
return self::_( 'Never' );
|
102 |
+
}
|
103 |
+
|
104 |
+
//Membership is set to a duration expiry settings.
|
105 |
+
return date_i18n( get_option( 'date_format' ), strtotime( $start_date . ' ' . $expires . ' days' ) );
|
106 |
+
}
|
107 |
+
|
108 |
+
public static function gender_dropdown( $selected = 'not specified' ) {
|
109 |
+
return '<option ' . ( ( strtolower( $selected ) == 'male' ) ? 'selected="selected"' : '' ) . ' value="male">Male</option>' .
|
110 |
+
'<option ' . ( ( strtolower( $selected ) == 'female' ) ? 'selected="selected"' : '' ) . ' value="female">Female</option>' .
|
111 |
+
'<option ' . ( ( strtolower( $selected ) == 'not specified' ) ? 'selected="selected"' : '' ) . ' value="not specified">Not Specified</option>';
|
112 |
+
}
|
113 |
+
|
114 |
+
public static function get_account_state_options() {
|
115 |
+
return array(
|
116 |
+
'active' => self::_( 'Active' ),
|
117 |
+
'inactive' => self::_( 'Inactive' ),
|
118 |
+
'activation_required' => self::_( 'Activation Required' ),
|
119 |
+
'pending' => self::_( 'Pending' ),
|
120 |
+
'expired' => self::_( 'Expired' ),
|
121 |
+
);
|
122 |
+
}
|
123 |
+
|
124 |
+
public static function account_state_dropdown( $selected = 'active' ) {
|
125 |
+
$options = self::get_account_state_options();
|
126 |
+
$html = '';
|
127 |
+
foreach ( $options as $key => $value ) {
|
128 |
+
$html .= '<option ' . ( ( strtolower( $selected ) == $key ) ? 'selected="selected"' : '' ) . ' value="' . $key . '"> ' . $value . '</option>';
|
129 |
+
}
|
130 |
+
return $html;
|
131 |
+
}
|
132 |
+
|
133 |
+
public static function membership_level_dropdown( $selected = 0 ) {
|
134 |
+
$options = '';
|
135 |
+
global $wpdb;
|
136 |
+
$query = 'SELECT alias, id FROM ' . $wpdb->prefix . 'swpm_membership_tbl WHERE id != 1';
|
137 |
+
$levels = $wpdb->get_results( $query );
|
138 |
+
foreach ( $levels as $level ) {
|
139 |
+
$options .= '<option ' . ( $selected == $level->id ? 'selected="selected"' : '' ) . ' value="' . $level->id . '" >' . $level->alias . '</option>';
|
140 |
+
}
|
141 |
+
return $options;
|
142 |
+
}
|
143 |
+
|
144 |
+
public static function get_all_membership_level_ids() {
|
145 |
+
global $wpdb;
|
146 |
+
$query = 'SELECT id FROM ' . $wpdb->prefix . 'swpm_membership_tbl WHERE id != 1';
|
147 |
+
return $wpdb->get_col( $query );
|
148 |
+
}
|
149 |
+
|
150 |
+
public static function get_membership_level_row_by_id( $level_id ) {
|
151 |
+
global $wpdb;
|
152 |
+
$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'swpm_membership_tbl WHERE id=%d', $level_id );
|
153 |
+
$level_resultset = $wpdb->get_row( $query );
|
154 |
+
return $level_resultset;
|
155 |
+
}
|
156 |
+
|
157 |
+
public static function membership_level_id_exists( $level_id ) {
|
158 |
+
//Returns true if the specified membership level exists in the system. Returns false if the level has been deleted (or doesn't exist).
|
159 |
+
$all_level_ids = self::get_all_membership_level_ids();
|
160 |
+
if ( in_array( $level_id, $all_level_ids ) ) {
|
161 |
+
//Valid level ID
|
162 |
+
return true;
|
163 |
+
} else {
|
164 |
+
return false;
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
public static function get_registration_complete_prompt_link( $for = 'all', $send_email = false, $member_id = '' ) {
|
169 |
+
$members = array();
|
170 |
+
global $wpdb;
|
171 |
+
switch ( $for ) {
|
172 |
+
case 'one':
|
173 |
+
if ( empty( $member_id ) ) {
|
174 |
+
return array();
|
175 |
+
}
|
176 |
+
$query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}swpm_members_tbl WHERE member_id = %d", $member_id );
|
177 |
+
$members = $wpdb->get_results( $query );
|
178 |
+
break;
|
179 |
+
case 'all':
|
180 |
+
$query = "SELECT * FROM {$wpdb->prefix}swpm_members_tbl WHERE reg_code != '' ";
|
181 |
+
$members = $wpdb->get_results( $query );
|
182 |
+
break;
|
183 |
+
}
|
184 |
+
$settings = SwpmSettings::get_instance();
|
185 |
+
$separator = '?';
|
186 |
+
$url = $settings->get_value( 'registration-page-url' );
|
187 |
+
if ( strpos( $url, '?' ) !== false ) {
|
188 |
+
$separator = '&';
|
189 |
+
}
|
190 |
+
|
191 |
+
$links = array();
|
192 |
+
foreach ( $members as $member ) {
|
193 |
+
$reg_url = $url . $separator . 'member_id=' . $member->member_id . '&code=' . $member->reg_code;
|
194 |
+
if ( $send_email && empty( $member->user_name ) ) {
|
195 |
+
$tags = array( '{first_name}', '{last_name}', '{reg_link}' );
|
196 |
+
$vals = array( $member->first_name, $member->last_name, $reg_url );
|
197 |
+
|
198 |
+
$subject = $settings->get_value( 'reg-prompt-complete-mail-subject' );
|
199 |
+
if ( empty( $subject ) ) {
|
200 |
+
$subject = 'Please complete your registration';
|
201 |
+
}
|
202 |
+
|
203 |
+
$body = $settings->get_value( 'reg-prompt-complete-mail-body' );
|
204 |
+
if ( empty( $body ) ) {
|
205 |
+
$body = "Please use the following link to complete your registration. \n {reg_link}";
|
206 |
+
}
|
207 |
+
$body = html_entity_decode( $body );
|
208 |
+
$email_body = str_replace( $tags, $vals, $body );
|
209 |
+
|
210 |
+
$from_address = $settings->get_value( 'email-from' );
|
211 |
+
$headers = 'From: ' . $from_address . "\r\n";
|
212 |
+
|
213 |
+
$subject = apply_filters( 'swpm_email_complete_your_registration_subject', $subject );
|
214 |
+
$email_body = apply_filters( 'swpm_email_complete_your_registration_body', $email_body );
|
215 |
+
SwpmMiscUtils::mail( $member->email, $subject, $email_body, $headers );
|
216 |
+
SwpmLog::log_simple_debug( 'Prompt to complete registration email sent to: ' . $member->email . '. From email address value used: ' . $from_address, true );
|
217 |
+
}
|
218 |
+
$links[] = $reg_url;
|
219 |
+
}
|
220 |
+
return $links;
|
221 |
+
}
|
222 |
+
|
223 |
+
/* This function is deprecated and will be removed in the future. Use SwpmMemberUtils::update_wp_user_role() instead */
|
224 |
+
|
225 |
+
public static function update_wp_user_Role( $wp_user_id, $role ) {
|
226 |
+
// Deprecated function.
|
227 |
+
SwpmMemberUtils::update_wp_user_role( $wp_user_id, $role );
|
228 |
+
}
|
229 |
+
|
230 |
+
public static function update_wp_user( $wp_user_name, $swpm_data ) {
|
231 |
+
$wp_user_info = array();
|
232 |
+
if ( isset( $swpm_data['email'] ) ) {
|
233 |
+
$wp_user_info['user_email'] = $swpm_data['email'];
|
234 |
+
}
|
235 |
+
if ( isset( $swpm_data['first_name'] ) ) {
|
236 |
+
$wp_user_info['first_name'] = $swpm_data['first_name'];
|
237 |
+
}
|
238 |
+
if ( isset( $swpm_data['last_name'] ) ) {
|
239 |
+
$wp_user_info['last_name'] = $swpm_data['last_name'];
|
240 |
+
}
|
241 |
+
if ( isset( $swpm_data['plain_password'] ) ) {
|
242 |
+
$wp_user_info['user_pass'] = $swpm_data['plain_password'];
|
243 |
+
}
|
244 |
+
|
245 |
+
$wp_user = get_user_by( 'login', $wp_user_name );
|
246 |
+
|
247 |
+
if ( $wp_user ) {
|
248 |
+
$wp_user_info['ID'] = $wp_user->ID;
|
249 |
+
return wp_update_user( $wp_user_info );
|
250 |
+
}
|
251 |
+
return false;
|
252 |
+
}
|
253 |
+
|
254 |
+
public static function create_wp_user( $wp_user_data ) {
|
255 |
+
|
256 |
+
//Check if the email belongs to an existing wp user account.
|
257 |
+
$wp_user_id = email_exists( $wp_user_data['user_email'] );
|
258 |
+
if ( $wp_user_id ) {
|
259 |
+
//A wp user account exist with this email.
|
260 |
+
//Check if the user has admin role.
|
261 |
+
$admin_user = SwpmMemberUtils::wp_user_has_admin_role( $wp_user_id );
|
262 |
+
if ( $admin_user ) {
|
263 |
+
//This email belongs to an admin user. Update is not allowed on admin users. Show error message then exit.
|
264 |
+
$error_msg = '<p>This email address (' . $wp_user_data['user_email'] . ') belongs to an admin user. This email cannot be used to register a new account on this site.</p>';
|
265 |
+
wp_die( $error_msg );
|
266 |
+
}
|
267 |
+
}
|
268 |
+
|
269 |
+
//At this point 1) A WP User with this email doesn't exist. Or 2) The associated wp user doesn't have admin role
|
270 |
+
//Lets create a new wp user record or attach the SWPM profile to an existing user accordingly.
|
271 |
+
|
272 |
+
if ( self::is_multisite_install() ) {
|
273 |
+
//WP Multi-Sit install
|
274 |
+
global $blog_id;
|
275 |
+
if ( $wp_user_id ) {
|
276 |
+
//If user exists then just add him to current blog.
|
277 |
+
add_existing_user_to_blog(
|
278 |
+
array(
|
279 |
+
'user_id' => $wp_user_id,
|
280 |
+
'role' => 'subscriber',
|
281 |
+
)
|
282 |
+
);
|
283 |
+
return $wp_user_id;
|
284 |
+
}
|
285 |
+
$wp_user_id = wpmu_create_user( $wp_user_data['user_login'], $wp_user_data['password'], $wp_user_data['user_email'] );
|
286 |
+
$role = 'subscriber'; //TODO - add user as a subscriber first. The subsequent update user role function to update the role to the correct one
|
287 |
+
add_user_to_blog( $blog_id, $wp_user_id, $role );
|
288 |
+
} else {
|
289 |
+
//WP Single site install
|
290 |
+
if ( $wp_user_id ) {
|
291 |
+
return $wp_user_id;
|
292 |
+
}
|
293 |
+
$wp_user_id = wp_create_user( $wp_user_data['user_login'], $wp_user_data['password'], $wp_user_data['user_email'] );
|
294 |
+
}
|
295 |
+
$wp_user_data['ID'] = $wp_user_id;
|
296 |
+
wp_update_user( $wp_user_data ); //Core WP function. Updates the user info and role.
|
297 |
+
|
298 |
+
return $wp_user_id;
|
299 |
+
}
|
300 |
+
|
301 |
+
public static function is_multisite_install() {
|
302 |
+
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
|
303 |
+
return true;
|
304 |
+
} else {
|
305 |
+
return false;
|
306 |
+
}
|
307 |
+
}
|
308 |
+
|
309 |
+
public static function _( $msg ) {
|
310 |
+
return __( $msg, 'simple-membership' );
|
311 |
+
}
|
312 |
+
|
313 |
+
public static function e( $msg ) {
|
314 |
+
_e( $msg, 'simple-membership' );
|
315 |
+
}
|
316 |
+
|
317 |
+
/*
|
318 |
+
* Deprecated. Instead use SwpmUtils::has_admin_management_permission()
|
319 |
+
*/
|
320 |
+
|
321 |
+
public static function is_admin() {
|
322 |
+
//This function returns true if the current user has WordPress admin management permission (not to be mistaken with SWPM admin permission.
|
323 |
+
//This function is NOT like the WordPress's is_admin() function which determins if we are on the admin end of the site.
|
324 |
+
//TODO - rename this function to something like is_admin_user()
|
325 |
+
return current_user_can( 'manage_options' );
|
326 |
+
}
|
327 |
+
|
328 |
+
public static function has_admin_management_permission() {
|
329 |
+
if ( current_user_can( SWPM_MANAGEMENT_PERMISSION ) ) {
|
330 |
+
return true;
|
331 |
+
} else {
|
332 |
+
return false;
|
333 |
+
}
|
334 |
+
}
|
335 |
+
|
336 |
+
/*
|
337 |
+
* Formats the given date value according to the WP date format settings. This function is useful for displaying a human readable date value to the user.
|
338 |
+
*/
|
339 |
+
public static function get_formatted_date_according_to_wp_settings( $date ) {
|
340 |
+
$date_format = get_option( 'date_format' );
|
341 |
+
if ( empty( $date_format ) ) {
|
342 |
+
//WordPress's date form settings is not set. Lets set a default format.
|
343 |
+
$date_format = 'Y-m-d';
|
344 |
+
}
|
345 |
+
|
346 |
+
$date_obj = new DateTime( $date );
|
347 |
+
$formatted_date = $date_obj->format( $date_format ); //Format the date value using date format settings
|
348 |
+
return $formatted_date;
|
349 |
+
}
|
350 |
+
|
351 |
+
/*
|
352 |
+
* Formats and Translates the given date value according to the WP date format settings. This function is useful for displaying a human readable date value to the user.
|
353 |
+
* The $date argument value must be in nromal date format (2025-01-15). The function will use strtotime() function to convert it to unix time then use it.
|
354 |
+
*/
|
355 |
+
public static function get_formatted_and_translated_date_according_to_wp_settings( $date ) {
|
356 |
+
$date_format = get_option( 'date_format' );
|
357 |
+
if ( empty( $date_format ) ) {
|
358 |
+
//WordPress's date form settings is not set. Lets set a default format.
|
359 |
+
$date_format = 'Y-m-d';
|
360 |
+
}
|
361 |
+
|
362 |
+
$formatted_translated_date = date_i18n( $date_format, strtotime( $date ) );
|
363 |
+
return $formatted_translated_date;
|
364 |
+
}
|
365 |
+
|
366 |
+
public static function swpm_username_exists( $user_name ) {
|
367 |
+
global $wpdb;
|
368 |
+
$member_table = $wpdb->prefix . 'swpm_members_tbl';
|
369 |
+
$query = $wpdb->prepare( 'SELECT member_id FROM ' . $member_table . ' WHERE user_name=%s', sanitize_user( $user_name ) );
|
370 |
+
return $wpdb->get_var( $query );
|
371 |
+
}
|
372 |
+
|
373 |
+
public static function get_free_level() {
|
374 |
+
$encrypted = filter_input( INPUT_POST, 'level_identifier' );
|
375 |
+
if ( ! empty( $encrypted ) ) {
|
376 |
+
return SwpmPermission::get_instance( $encrypted )->get( 'id' );
|
377 |
+
}
|
378 |
+
|
379 |
+
$is_free = SwpmSettings::get_instance()->get_value( 'enable-free-membership' );
|
380 |
+
$free_level = absint( SwpmSettings::get_instance()->get_value( 'free-membership-id' ) );
|
381 |
+
|
382 |
+
return ( $is_free ) ? $free_level : null;
|
383 |
+
}
|
384 |
+
|
385 |
+
public static function is_paid_registration() {
|
386 |
+
$member_id = filter_input( INPUT_GET, 'member_id', FILTER_SANITIZE_NUMBER_INT );
|
387 |
+
$code = filter_input( INPUT_GET, 'code', FILTER_SANITIZE_STRING );
|
388 |
+
if ( ! empty( $member_id ) && ! empty( $code ) ) {
|
389 |
+
return true;
|
390 |
+
}
|
391 |
+
return false;
|
392 |
+
}
|
393 |
+
|
394 |
+
public static function get_paid_member_info() {
|
395 |
+
$member_id = filter_input( INPUT_GET, 'member_id', FILTER_SANITIZE_NUMBER_INT );
|
396 |
+
$code = filter_input( INPUT_GET, 'code', FILTER_SANITIZE_STRING );
|
397 |
+
global $wpdb;
|
398 |
+
if ( ! empty( $member_id ) && ! empty( $code ) ) {
|
399 |
+
$query = 'SELECT * FROM ' . $wpdb->prefix . 'swpm_members_tbl WHERE member_id= %d AND reg_code=%s';
|
400 |
+
$query = $wpdb->prepare( $query, $member_id, $code );
|
401 |
+
return $wpdb->get_row( $query );
|
402 |
+
}
|
403 |
+
return null;
|
404 |
+
}
|
405 |
+
|
406 |
+
public static function get_incomplete_paid_member_info_by_ip() {
|
407 |
+
global $wpdb;
|
408 |
+
$user_ip = self::get_user_ip_address();
|
409 |
+
if ( ! empty( $user_ip ) ) {
|
410 |
+
//Lets check if a payment has been confirmed from this user's IP and the profile needs to be completed (where username is empty).
|
411 |
+
$username = '';
|
412 |
+
$query = 'SELECT * FROM ' . $wpdb->prefix . 'swpm_members_tbl WHERE last_accessed_from_ip=%s AND user_name=%s';
|
413 |
+
$query = $wpdb->prepare( $query, $user_ip, $username );
|
414 |
+
$result = $wpdb->get_row( $query );
|
415 |
+
return $result;
|
416 |
+
}
|
417 |
+
return null;
|
418 |
+
}
|
419 |
+
|
420 |
+
public static function account_delete_confirmation_ui( $msg = '' ) {
|
421 |
+
ob_start();
|
422 |
+
include SIMPLE_WP_MEMBERSHIP_PATH . 'views/account_delete_warning.php';
|
423 |
+
ob_get_flush();
|
424 |
+
wp_die( '', '', array( 'back_link' => true ) );
|
425 |
+
}
|
426 |
+
|
427 |
+
public static function delete_account_button() {
|
428 |
+
$allow_account_deletion = SwpmSettings::get_instance()->get_value( 'allow-account-deletion' );
|
429 |
+
if ( empty( $allow_account_deletion ) ) {
|
430 |
+
return '';
|
431 |
+
}
|
432 |
+
|
433 |
+
$account_delete_link = '<div class="swpm-profile-account-delete-section">';
|
434 |
+
$account_delete_link .= '<a href="' . SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL . '/?swpm_delete_account=1"><div class="swpm-account-delete-button">' . self::_( 'Delete Account' ) . '</div></a>';
|
435 |
+
$account_delete_link .= '</div>';
|
436 |
+
return $account_delete_link;
|
437 |
+
}
|
438 |
+
|
439 |
+
public static function encrypt_password( $plain_password ) {
|
440 |
+
include_once ABSPATH . WPINC . '/class-phpass.php';
|
441 |
+
$wp_hasher = new PasswordHash( 8, true );
|
442 |
+
$password_hash = $wp_hasher->HashPassword( trim( $plain_password ) );
|
443 |
+
return $password_hash;
|
444 |
+
}
|
445 |
+
|
446 |
+
public static function get_restricted_image_url() {
|
447 |
+
return SIMPLE_WP_MEMBERSHIP_URL . '/images/restricted-icon.png';
|
448 |
+
}
|
449 |
+
|
450 |
+
/*
|
451 |
+
* Checks if the string exists in the array key value of the provided array. If it doesn't exist, it returns the first key element from the valid values.
|
452 |
+
*/
|
453 |
+
|
454 |
+
public static function sanitize_value_by_array( $val_to_check, $valid_values ) {
|
455 |
+
$keys = array_keys( $valid_values );
|
456 |
+
$keys = array_map( 'strtolower', $keys );
|
457 |
+
if ( in_array( $val_to_check, $keys ) ) {
|
458 |
+
return $val_to_check;
|
459 |
+
}
|
460 |
+
return reset( $keys ); //Return he first element from the valid values
|
461 |
+
}
|
462 |
+
|
463 |
+
public static function get_user_ip_address() {
|
464 |
+
$user_ip = '';
|
465 |
+
if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
|
466 |
+
$user_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
467 |
+
} else {
|
468 |
+
$user_ip = $_SERVER['REMOTE_ADDR'];
|
469 |
+
}
|
470 |
+
|
471 |
+
if ( strstr( $user_ip, ',' ) ) {
|
472 |
+
$ip_values = explode( ',', $user_ip );
|
473 |
+
$user_ip = $ip_values['0'];
|
474 |
+
}
|
475 |
+
|
476 |
+
return apply_filters( 'swpm_get_user_ip_address', $user_ip );
|
477 |
+
}
|
478 |
+
|
479 |
+
public static function is_first_click_free( &$content ) {
|
480 |
+
$is_first_click = false;
|
481 |
+
$args = array( $is_first_click, $content );
|
482 |
+
$filtered = apply_filters( 'swpm_first_click_free', $args );
|
483 |
+
list($is_first_click, $content) = $filtered;
|
484 |
+
return $is_first_click;
|
485 |
+
}
|
486 |
+
|
487 |
+
private static function crypt_fallback( $string, $action = 'e' ) {
|
488 |
+
if ( $action === 'e' ) {
|
489 |
+
return base64_encode( $string );
|
490 |
+
} else {
|
491 |
+
return base64_decode( $string );
|
492 |
+
}
|
493 |
+
}
|
494 |
+
|
495 |
+
public static function crypt( $string, $action = 'e' ) {
|
496 |
+
//check if openssl module is enabled
|
497 |
+
if ( ! extension_loaded( 'openssl' ) ) {
|
498 |
+
// no openssl extension loaded. Can't ecnrypt
|
499 |
+
return self::crypt_fallback( $string, $action );
|
500 |
+
}
|
501 |
+
//check if encrypt method is supported
|
502 |
+
$encrypt_method = 'aes-256-ctr';
|
503 |
+
$available_methods = openssl_get_cipher_methods();
|
504 |
+
if ( ! in_array( $encrypt_method, $available_methods ) ) {
|
505 |
+
// no ecryption method supported. Can't encrypt
|
506 |
+
return self::crypt_fallback( $string, $action );
|
507 |
+
}
|
508 |
+
|
509 |
+
$output = false;
|
510 |
+
$secret_key = wp_salt( 'auth' );
|
511 |
+
$secret_iv = wp_salt( 'secure_auth' );
|
512 |
+
$key = hash( 'sha256', $secret_key );
|
513 |
+
$iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
|
514 |
+
|
515 |
+
if ( $action == 'e' ) {
|
516 |
+
$output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
|
517 |
+
} elseif ( $action == 'd' ) {
|
518 |
+
$output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
|
519 |
+
}
|
520 |
+
|
521 |
+
return $output;
|
522 |
+
}
|
523 |
|
524 |
}
|
classes/class.swpm-wp-loaded-tasks.php
CHANGED
@@ -76,6 +76,7 @@ class SwpmWpLoadedTasks {
|
|
76 |
$swpm_process_stripe_sca_subscription = filter_input( INPUT_GET, 'swpm_process_stripe_sca_subscription' );
|
77 |
$hook = filter_input( INPUT_GET, 'hook', FILTER_SANITIZE_NUMBER_INT );
|
78 |
if ( $swpm_process_stripe_sca_subscription == '1' ) {
|
|
|
79 |
if ( $hook ) {
|
80 |
include SIMPLE_WP_MEMBERSHIP_PATH . 'ipn/swpm-stripe-subscription-ipn.php';
|
81 |
} else {
|
76 |
$swpm_process_stripe_sca_subscription = filter_input( INPUT_GET, 'swpm_process_stripe_sca_subscription' );
|
77 |
$hook = filter_input( INPUT_GET, 'hook', FILTER_SANITIZE_NUMBER_INT );
|
78 |
if ( $swpm_process_stripe_sca_subscription == '1' ) {
|
79 |
+
//$hook == 1 means it is a background post via webshooks. Otherwise it is direct post to the script after payment (at the time of payment).
|
80 |
if ( $hook ) {
|
81 |
include SIMPLE_WP_MEMBERSHIP_PATH . 'ipn/swpm-stripe-subscription-ipn.php';
|
82 |
} else {
|
classes/shortcode-related/class.swpm-shortcodes-handler.php
CHANGED
@@ -10,6 +10,8 @@ class SwpmShortcodesHandler {
|
|
10 |
add_shortcode('swpm_show_expiry_date', array(&$this, 'swpm_show_expiry_date_sc'));
|
11 |
|
12 |
add_shortcode('swpm_mini_login', array(&$this, 'swpm_show_mini_login_sc'));
|
|
|
|
|
13 |
}
|
14 |
|
15 |
public function swpm_payment_button_sc($args) {
|
@@ -127,4 +129,52 @@ class SwpmShortcodesHandler {
|
|
127 |
$output .= '</div>';
|
128 |
return $output;
|
129 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
}
|
10 |
add_shortcode('swpm_show_expiry_date', array(&$this, 'swpm_show_expiry_date_sc'));
|
11 |
|
12 |
add_shortcode('swpm_mini_login', array(&$this, 'swpm_show_mini_login_sc'));
|
13 |
+
|
14 |
+
add_shortcode('swpm_paypal_subscription_cancel_link', array(&$this, 'swpm_pp_cancel_subs_link_sc'));
|
15 |
}
|
16 |
|
17 |
public function swpm_payment_button_sc($args) {
|
129 |
$output .= '</div>';
|
130 |
return $output;
|
131 |
}
|
132 |
+
|
133 |
+
public function swpm_pp_cancel_subs_link_sc($args){
|
134 |
+
extract(shortcode_atts(array(
|
135 |
+
'merchant_id' => '',
|
136 |
+
'anchor_text' => '',
|
137 |
+
), $args));
|
138 |
+
|
139 |
+
if (empty($merchant_id)){
|
140 |
+
return '<p class="swpm-red-box">Error! You need to specify your secure PayPal merchant ID in the shortcode using the "merchant_id" parameter.</p>';
|
141 |
+
}
|
142 |
+
|
143 |
+
$output = '';
|
144 |
+
$settings = SwpmSettings::get_instance();
|
145 |
+
|
146 |
+
//Check if the member is logged-in
|
147 |
+
if (SwpmMemberUtils::is_member_logged_in()) {
|
148 |
+
$user_id = SwpmMemberUtils::get_logged_in_members_id();
|
149 |
+
}
|
150 |
+
|
151 |
+
if (!empty($user_id)) {
|
152 |
+
//The user is logged-in
|
153 |
+
|
154 |
+
//Set the default anchor text (if one is provided via teh shortcode).
|
155 |
+
if(empty($anchor_text)){
|
156 |
+
$anchor_text = SwpmUtils::_('Unsubscribe from PayPal');
|
157 |
+
}
|
158 |
+
|
159 |
+
$output .= '<div class="swpm-paypal-subscription-cancel-link">';
|
160 |
+
$sandbox_enabled = $settings->get_value('enable-sandbox-testing');
|
161 |
+
if ( $sandbox_enabled ) {
|
162 |
+
//Sandbox mode
|
163 |
+
$output .= '<a href="https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=' . $merchant_id . '" _fcksavedurl="https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=' . $merchant_id . '">';
|
164 |
+
$output .= $anchor_text;
|
165 |
+
$output .= '</a>';
|
166 |
+
} else {
|
167 |
+
//Live mode
|
168 |
+
$output .= '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=' . $merchant_id . '" _fcksavedurl="https://www.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=' . $merchant_id . '">';
|
169 |
+
$output .= $anchor_text;
|
170 |
+
$output .= '</a>';
|
171 |
+
}
|
172 |
+
$output .= '</div>';
|
173 |
+
|
174 |
+
} else {
|
175 |
+
//The user is NOT logged-in
|
176 |
+
$output .= '<p>' . SwpmUtils::_('You are not logged-in as a member') . '</p>';
|
177 |
+
}
|
178 |
+
return $output;
|
179 |
+
}
|
180 |
}
|
ipn/swpm-stripe-sca-subscription-ipn.php
CHANGED
@@ -10,7 +10,10 @@ class SwpmStripeSCASubscriptionIpnHandler {
|
|
10 |
}
|
11 |
|
12 |
public function handle_stripe_ipn() {
|
13 |
-
|
|
|
|
|
|
|
14 |
// SwpmLog::log_simple_debug(print_r($_REQUEST, true), true);//Useful for debugging purpose
|
15 |
|
16 |
// Read and sanitize the request parameters.
|
@@ -49,7 +52,7 @@ class SwpmStripeSCASubscriptionIpnHandler {
|
|
49 |
|
50 |
// Include the Stripe library.
|
51 |
SwpmMiscUtils::load_stripe_lib();
|
52 |
-
|
53 |
try {
|
54 |
\Stripe\Stripe::setApiKey( $secret_key );
|
55 |
|
@@ -181,6 +184,9 @@ class SwpmStripeSCASubscriptionIpnHandler {
|
|
181 |
$ipn_data['address_zipcode'] = isset( $bd_addr->postal_code ) ? $bd_addr->postal_code : '';
|
182 |
$ipn_data['address_country'] = isset( $bd_addr->country ) ? $bd_addr->country : '';
|
183 |
|
|
|
|
|
|
|
184 |
// Handle the membership signup related tasks.
|
185 |
swpm_handle_subsc_signup_stand_alone( $ipn_data, $membership_level_id, $txn_id, $swpm_id );
|
186 |
|
10 |
}
|
11 |
|
12 |
public function handle_stripe_ipn() {
|
13 |
+
//This will get executed only for direct post (not webhooks). So it is executed at the time of payment in the browser (via HTTP POST). When the "hook" query arg is not set.
|
14 |
+
//The webhooks are handled by the "swpm-stripe-subscription-ipn.php" script.
|
15 |
+
|
16 |
+
SwpmLog::log_simple_debug( 'Stripe SCA Subscription IPN (HTTP POST) received. Processing request...', true );
|
17 |
// SwpmLog::log_simple_debug(print_r($_REQUEST, true), true);//Useful for debugging purpose
|
18 |
|
19 |
// Read and sanitize the request parameters.
|
52 |
|
53 |
// Include the Stripe library.
|
54 |
SwpmMiscUtils::load_stripe_lib();
|
55 |
+
|
56 |
try {
|
57 |
\Stripe\Stripe::setApiKey( $secret_key );
|
58 |
|
184 |
$ipn_data['address_zipcode'] = isset( $bd_addr->postal_code ) ? $bd_addr->postal_code : '';
|
185 |
$ipn_data['address_country'] = isset( $bd_addr->country ) ? $bd_addr->country : '';
|
186 |
|
187 |
+
$ipn_data['payment_button_id'] = $button_id;
|
188 |
+
$ipn_data['is_live'] = ! $sandbox_enabled;
|
189 |
+
|
190 |
// Handle the membership signup related tasks.
|
191 |
swpm_handle_subsc_signup_stand_alone( $ipn_data, $membership_level_id, $txn_id, $swpm_id );
|
192 |
|
ipn/swpm-stripe-subscription-ipn.php
CHANGED
@@ -10,8 +10,16 @@ class SwpmStripeSubscriptionIpnHandler {
|
|
10 |
}
|
11 |
|
12 |
public function handle_stripe_ipn() {
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
@@ -19,7 +27,7 @@ class SwpmStripeSubscriptionIpnHandler {
|
|
19 |
|
20 |
$input = @file_get_contents( 'php://input' );
|
21 |
if ( empty( $input ) ) {
|
22 |
-
SwpmLog::log_simple_debug( 'Stripe
|
23 |
echo 'Empty Webhook data received.';
|
24 |
die;
|
25 |
}
|
@@ -27,10 +35,12 @@ class SwpmStripeSubscriptionIpnHandler {
|
|
27 |
$event_json = json_decode( $input );
|
28 |
|
29 |
$type = $event_json->type;
|
30 |
-
|
|
|
31 |
if ( 'customer.subscription.deleted' === $type || 'charge.refunded' === $type ) {
|
32 |
// Subscription expired or refunded event
|
33 |
-
|
|
|
34 |
// Let's form minimal ipn_data array for swpm_handle_subsc_cancel_stand_alone
|
35 |
$customer = $event_json->data->object->customer;
|
36 |
$subscr_id = $event_json->data->object->id;
|
@@ -40,11 +50,29 @@ class SwpmStripeSubscriptionIpnHandler {
|
|
40 |
|
41 |
swpm_handle_subsc_cancel_stand_alone( $ipn_data );
|
42 |
}
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
return;
|
45 |
}
|
46 |
|
47 |
-
|
|
|
|
|
48 |
// SwpmLog::log_simple_debug(print_r($_REQUEST, true), true);//Useful for debugging purpose
|
49 |
// Include the Stripe library.
|
50 |
SwpmMiscUtils::load_stripe_lib();
|
@@ -105,11 +133,11 @@ class SwpmStripeSubscriptionIpnHandler {
|
|
105 |
$error = $body['error'];
|
106 |
$error_string = print_r( $error, true );
|
107 |
SwpmLog::log_simple_debug( 'Error details: ' . $error_string, false );
|
108 |
-
wp_die( esc_html( 'Stripe
|
109 |
}
|
110 |
|
111 |
// Everything went ahead smoothly with the charge.
|
112 |
-
SwpmLog::log_simple_debug( 'Stripe
|
113 |
|
114 |
// let's add button_id to metadata
|
115 |
$customer->metadata = array( 'button_id' => $button_id );
|
@@ -152,6 +180,9 @@ class SwpmStripeSubscriptionIpnHandler {
|
|
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 |
|
@@ -170,7 +201,7 @@ class SwpmStripeSubscriptionIpnHandler {
|
|
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
|
174 |
SwpmMiscUtils::redirect_to_url( $return_url );
|
175 |
}
|
176 |
|
10 |
}
|
11 |
|
12 |
public function handle_stripe_ipn() {
|
13 |
+
|
14 |
+
/*
|
15 |
+
* [Imp] This comment explains how this script handles both the first time HTTP Post after payment and the webhooks.
|
16 |
+
* If the "hook" query arg is set then that means it is a webhook notification. It will be used for certain actions like (update, cancel, refund, etc). Others will be ignored.
|
17 |
+
* The first time payment in browser is handled via HTTP POST (when the "hook" query arg is not set).
|
18 |
+
*/
|
19 |
+
|
20 |
+
if ( isset( $_GET['hook'] ) ) {
|
21 |
+
// This is Webhook notification from Stripe
|
22 |
+
|
23 |
// TODO: add Webhook Signing Secret verification
|
24 |
// To do this, we need to get customer ID, retreive its details from Stripe, get button_id from metadata
|
25 |
// and see if the button has Signing Secret option set. If it is - we need to check signatures
|
27 |
|
28 |
$input = @file_get_contents( 'php://input' );
|
29 |
if ( empty( $input ) ) {
|
30 |
+
SwpmLog::log_simple_debug( 'Stripe subscription webhook sent empty data or page was accessed directly. Aborting.', false );
|
31 |
echo 'Empty Webhook data received.';
|
32 |
die;
|
33 |
}
|
35 |
$event_json = json_decode( $input );
|
36 |
|
37 |
$type = $event_json->type;
|
38 |
+
SwpmLog::log_simple_debug( sprintf( 'Stripe subscription webhook received: %s. Checking if we need to handle this webhook.', $type ), true );
|
39 |
+
|
40 |
if ( 'customer.subscription.deleted' === $type || 'charge.refunded' === $type ) {
|
41 |
// Subscription expired or refunded event
|
42 |
+
//SwpmLog::log_simple_debug( sprintf( 'Stripe Subscription Webhook %s received. Processing request...', $type ), true );
|
43 |
+
|
44 |
// Let's form minimal ipn_data array for swpm_handle_subsc_cancel_stand_alone
|
45 |
$customer = $event_json->data->object->customer;
|
46 |
$subscr_id = $event_json->data->object->id;
|
50 |
|
51 |
swpm_handle_subsc_cancel_stand_alone( $ipn_data );
|
52 |
}
|
53 |
+
|
54 |
+
if ( $type == 'customer.subscription.updated') {
|
55 |
+
// Subscription updated
|
56 |
+
//SwpmLog::log_simple_debug( sprintf( 'Stripe Subscription Webhook %s received. Processing request...', $type ), true );
|
57 |
+
|
58 |
+
// Let's form minimal ipn_data array for swpm_handle_subsc_cancel_stand_alone
|
59 |
+
$customer = $event_json->data->object->customer;
|
60 |
+
$subscr_id = $event_json->data->object->id;
|
61 |
+
$ipn_data = array();
|
62 |
+
$ipn_data['subscr_id'] = $subscr_id;
|
63 |
+
$ipn_data['parent_txn_id'] = $customer;
|
64 |
+
|
65 |
+
swpm_update_member_subscription_start_date_if_applicable( $ipn_data );
|
66 |
+
}
|
67 |
+
|
68 |
+
//End of the webhook notification execution.
|
69 |
+
http_response_code( 200 ); // Tells Stripe we received this notification
|
70 |
return;
|
71 |
}
|
72 |
|
73 |
+
//The following will get executed only for DIRECT post (not webhooks). So it is executed at the time of payment in the browser (via HTTP POST). When the "hook" query arg is not set.
|
74 |
+
|
75 |
+
SwpmLog::log_simple_debug( 'Stripe subscription IPN received. Processing request...', true );
|
76 |
// SwpmLog::log_simple_debug(print_r($_REQUEST, true), true);//Useful for debugging purpose
|
77 |
// Include the Stripe library.
|
78 |
SwpmMiscUtils::load_stripe_lib();
|
133 |
$error = $body['error'];
|
134 |
$error_string = print_r( $error, true );
|
135 |
SwpmLog::log_simple_debug( 'Error details: ' . $error_string, false );
|
136 |
+
wp_die( esc_html( 'Stripe subscription Error! ' . $e->getMessage() . $error_string ) );
|
137 |
}
|
138 |
|
139 |
// Everything went ahead smoothly with the charge.
|
140 |
+
SwpmLog::log_simple_debug( 'Stripe subscription successful.', true );
|
141 |
|
142 |
// let's add button_id to metadata
|
143 |
$customer->metadata = array( 'button_id' => $button_id );
|
180 |
$ipn_data['address_zipcode'] = '';
|
181 |
$ipn_data['country'] = '';
|
182 |
|
183 |
+
$ipn_data['payment_button_id'] = $button_id;
|
184 |
+
$ipn_data['is_live'] = ! $sandbox_enabled;
|
185 |
+
|
186 |
// Handle the membership signup related tasks.
|
187 |
swpm_handle_subsc_signup_stand_alone( $ipn_data, $membership_level_id, $txn_id, $swpm_id );
|
188 |
|
201 |
$return_url = SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL;
|
202 |
}
|
203 |
SwpmLog::log_simple_debug( 'Redirecting customer to: ' . $return_url, true );
|
204 |
+
SwpmLog::log_simple_debug( 'End of Stripe subscription IPN processing.', true, true );
|
205 |
SwpmMiscUtils::redirect_to_url( $return_url );
|
206 |
}
|
207 |
|
ipn/swpm_handle_subsc_ipn.php
CHANGED
@@ -5,7 +5,7 @@ function swpm_handle_subsc_signup_stand_alone( $ipn_data, $subsc_ref, $unique_re
|
|
5 |
$settings = SwpmSettings::get_instance();
|
6 |
$membership_level = $subsc_ref;
|
7 |
|
8 |
-
if ( isset( $ipn_data['subscr_id'] ) && !empty( $ipn_data['subscr_id'] ) ) {
|
9 |
$subscr_id = $ipn_data['subscr_id'];
|
10 |
} else {
|
11 |
$subscr_id = $unique_ref;
|
@@ -99,17 +99,17 @@ function swpm_handle_subsc_signup_stand_alone( $ipn_data, $subsc_ref, $unique_re
|
|
99 |
$additional_args = array();
|
100 |
$email_body = SwpmMiscUtils::replace_dynamic_tags( $body, $swpm_id, $additional_args );
|
101 |
$headers = 'From: ' . $from_address . "\r\n";
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
// End of existing user account upgrade/update.
|
114 |
} else {
|
115 |
// create new member account.
|
@@ -172,15 +172,15 @@ function swpm_handle_subsc_signup_stand_alone( $ipn_data, $subsc_ref, $unique_re
|
|
172 |
$additional_args = array( 'reg_link' => $reg_url );
|
173 |
$email_body = SwpmMiscUtils::replace_dynamic_tags( $body, $id, $additional_args );
|
174 |
$headers = 'From: ' . $from_address . "\r\n";
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
}
|
185 |
|
186 |
}
|
@@ -193,8 +193,11 @@ function swpm_handle_subsc_cancel_stand_alone( $ipn_data, $refund = false ) {
|
|
193 |
|
194 |
global $wpdb;
|
195 |
|
196 |
-
|
197 |
-
|
|
|
|
|
|
|
198 |
|
199 |
swpm_debug_log_subsc( 'Refund/Cancellation check - lets see if a member account needs to be deactivated.', true );
|
200 |
// swpm_debug_log_subsc("Parent txn id: " . $ipn_data['parent_txn_id'] . ", Subscr ID: " . $ipn_data['subscr_id'] . ", SWPM ID: " . $swpm_id, true);.
|
@@ -245,9 +248,9 @@ function swpm_handle_subsc_cancel_stand_alone( $ipn_data, $refund = false ) {
|
|
245 |
swpm_debug_log_subsc( 'Membership level ID of the member is: ' . $level_id, true );
|
246 |
$level_row = SwpmUtils::get_membership_level_row_by_id( $level_id );
|
247 |
$subs_duration_type = $level_row->subscription_duration_type;
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
if ( SwpmMembershipLevel::NO_EXPIRY == $subs_duration_type ) {
|
252 |
// This is a level with "no expiry" or "until cancelled" duration.
|
253 |
swpm_debug_log_subsc( 'This is a level with "no expiry" or "until cancelled" duration', true );
|
@@ -256,7 +259,7 @@ function swpm_handle_subsc_cancel_stand_alone( $ipn_data, $refund = false ) {
|
|
256 |
$account_state = 'inactive';
|
257 |
SwpmMemberUtils::update_account_state( $member_id, $account_state );
|
258 |
swpm_debug_log_subsc( 'Subscription cancellation or end of term received! Member account deactivated. Member ID: ' . $member_id, true );
|
259 |
-
}
|
260 |
// This is a level with a "fixed expiry date" duration.
|
261 |
swpm_debug_log_subsc( 'This is a level with a "fixed expiry date" duration.', true );
|
262 |
swpm_debug_log_subsc( 'Nothing to do here. The account will expire on the fixed set date.', true );
|
@@ -282,13 +285,15 @@ function swpm_handle_subsc_cancel_stand_alone( $ipn_data, $refund = false ) {
|
|
282 |
|
283 |
function swpm_update_member_subscription_start_date_if_applicable( $ipn_data ) {
|
284 |
global $wpdb;
|
285 |
-
$email
|
286 |
-
$subscr_id
|
287 |
$account_state = SwpmSettings::get_instance()->get_value( 'default-account-status', 'active' );
|
288 |
swpm_debug_log_subsc( 'Updating subscription start date if applicable for this subscription payment. Subscriber ID: ' . $subscr_id . ' Email: ' . $email, true );
|
289 |
|
290 |
// We can also query using the email address or SWPM ID (if present in custom var).
|
291 |
-
|
|
|
|
|
292 |
if ( $query_db ) {
|
293 |
$swpm_id = $query_db->member_id;
|
294 |
$current_primary_level = $query_db->membership_level;
|
@@ -313,7 +318,7 @@ function swpm_update_member_subscription_start_date_if_applicable( $ipn_data ) {
|
|
313 |
swpm_debug_log_subsc( 'Value after update - Subscriber ID: ' . $member_record->subscr_id . ', Start Date: ' . $member_record->subscription_starts, true );
|
314 |
} else {
|
315 |
swpm_debug_log_subsc( 'Did not find an existing record in the members table for subscriber ID: ' . $subscr_id, true );
|
316 |
-
swpm_debug_log_subsc( 'This
|
317 |
}
|
318 |
}
|
319 |
|
5 |
$settings = SwpmSettings::get_instance();
|
6 |
$membership_level = $subsc_ref;
|
7 |
|
8 |
+
if ( isset( $ipn_data['subscr_id'] ) && ! empty( $ipn_data['subscr_id'] ) ) {
|
9 |
$subscr_id = $ipn_data['subscr_id'];
|
10 |
} else {
|
11 |
$subscr_id = $unique_ref;
|
99 |
$additional_args = array();
|
100 |
$email_body = SwpmMiscUtils::replace_dynamic_tags( $body, $swpm_id, $additional_args );
|
101 |
$headers = 'From: ' . $from_address . "\r\n";
|
102 |
+
|
103 |
+
$subject = apply_filters( 'swpm_email_upgrade_complete_subject', $subject );
|
104 |
+
$email_body = apply_filters( 'swpm_email_upgrade_complete_body', $email_body );
|
105 |
+
|
106 |
+
if ( $settings->get_value( 'disable-email-after-upgrade' ) ) {
|
107 |
+
swpm_debug_log_subsc( 'The disable upgrade email settings is checked. No account upgrade/update email will be sent.', true );
|
108 |
+
//Nothing to do.
|
109 |
+
} else {
|
110 |
+
SwpmMiscUtils::mail( $email, $subject, $email_body, $headers );
|
111 |
+
swpm_debug_log_subsc( 'Member upgrade/update completion email successfully sent to: ' . $email, true );
|
112 |
+
}
|
113 |
// End of existing user account upgrade/update.
|
114 |
} else {
|
115 |
// create new member account.
|
172 |
$additional_args = array( 'reg_link' => $reg_url );
|
173 |
$email_body = SwpmMiscUtils::replace_dynamic_tags( $body, $id, $additional_args );
|
174 |
$headers = 'From: ' . $from_address . "\r\n";
|
175 |
+
|
176 |
+
$subject = apply_filters( 'swpm_email_complete_registration_subject', $subject );
|
177 |
+
$email_body = apply_filters( 'swpm_email_complete_registration_body', $email_body );
|
178 |
+
if ( empty( $email_body ) ) {
|
179 |
+
swpm_debug_log_subsc( 'Notice: Member signup (prompt to complete registration) email body has been set empty via the filter hook. No email will be sent.', true );
|
180 |
+
} else {
|
181 |
+
SwpmMiscUtils::mail( $email, $subject, $email_body, $headers );
|
182 |
+
swpm_debug_log_subsc( 'Member signup (prompt to complete registration) email successfully sent to: ' . $email, true );
|
183 |
+
}
|
184 |
}
|
185 |
|
186 |
}
|
193 |
|
194 |
global $wpdb;
|
195 |
|
196 |
+
$swpm_id = '';
|
197 |
+
if ( isset( $ipn_data['custom'] ) ){
|
198 |
+
$customvariables = SwpmTransactions::parse_custom_var( $ipn_data['custom'] );
|
199 |
+
$swpm_id = $customvariables['swpm_id'];
|
200 |
+
}
|
201 |
|
202 |
swpm_debug_log_subsc( 'Refund/Cancellation check - lets see if a member account needs to be deactivated.', true );
|
203 |
// swpm_debug_log_subsc("Parent txn id: " . $ipn_data['parent_txn_id'] . ", Subscr ID: " . $ipn_data['subscr_id'] . ", SWPM ID: " . $swpm_id, true);.
|
248 |
swpm_debug_log_subsc( 'Membership level ID of the member is: ' . $level_id, true );
|
249 |
$level_row = SwpmUtils::get_membership_level_row_by_id( $level_id );
|
250 |
$subs_duration_type = $level_row->subscription_duration_type;
|
251 |
+
|
252 |
+
swpm_debug_log_subsc( 'Subscription duration type: ' . $subs_duration_type, true );
|
253 |
+
|
254 |
if ( SwpmMembershipLevel::NO_EXPIRY == $subs_duration_type ) {
|
255 |
// This is a level with "no expiry" or "until cancelled" duration.
|
256 |
swpm_debug_log_subsc( 'This is a level with "no expiry" or "until cancelled" duration', true );
|
259 |
$account_state = 'inactive';
|
260 |
SwpmMemberUtils::update_account_state( $member_id, $account_state );
|
261 |
swpm_debug_log_subsc( 'Subscription cancellation or end of term received! Member account deactivated. Member ID: ' . $member_id, true );
|
262 |
+
} elseif ( SwpmMembershipLevel::FIXED_DATE == $subs_duration_type ) {
|
263 |
// This is a level with a "fixed expiry date" duration.
|
264 |
swpm_debug_log_subsc( 'This is a level with a "fixed expiry date" duration.', true );
|
265 |
swpm_debug_log_subsc( 'Nothing to do here. The account will expire on the fixed set date.', true );
|
285 |
|
286 |
function swpm_update_member_subscription_start_date_if_applicable( $ipn_data ) {
|
287 |
global $wpdb;
|
288 |
+
$email = isset( $ipn_data['payer_email'] ) ? $ipn_data['payer_email'] : '';
|
289 |
+
$subscr_id = $ipn_data['subscr_id'];
|
290 |
$account_state = SwpmSettings::get_instance()->get_value( 'default-account-status', 'active' );
|
291 |
swpm_debug_log_subsc( 'Updating subscription start date if applicable for this subscription payment. Subscriber ID: ' . $subscr_id . ' Email: ' . $email, true );
|
292 |
|
293 |
// We can also query using the email address or SWPM ID (if present in custom var).
|
294 |
+
|
295 |
+
//Try to find the profile with the given subscr_id. It will exact match subscr_id or match subscr_id|123
|
296 |
+
$query_db = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}swpm_members_tbl WHERE subscr_id = %s OR subscr_id LIKE %s", $subscr_id, $subscr_id.'|%' ), OBJECT );
|
297 |
if ( $query_db ) {
|
298 |
$swpm_id = $query_db->member_id;
|
299 |
$current_primary_level = $query_db->membership_level;
|
318 |
swpm_debug_log_subsc( 'Value after update - Subscriber ID: ' . $member_record->subscr_id . ', Start Date: ' . $member_record->subscription_starts, true );
|
319 |
} else {
|
320 |
swpm_debug_log_subsc( 'Did not find an existing record in the members table for subscriber ID: ' . $subscr_id, true );
|
321 |
+
swpm_debug_log_subsc( 'This could be a new subscription payment for a new subscription agreement.', true );
|
322 |
}
|
323 |
}
|
324 |
|
lib/braintree/lib/Braintree/WebhookTestingGateway.php
CHANGED
@@ -549,10 +549,10 @@ class WebhookTestingGateway
|
|
549 |
|
550 |
private static function _timestamp()
|
551 |
{
|
552 |
-
$originalZone = date_default_timezone_get();
|
553 |
-
date_default_timezone_set('UTC');
|
554 |
-
|
555 |
-
date_default_timezone_set($originalZone);
|
556 |
|
557 |
return $timestamp;
|
558 |
}
|
549 |
|
550 |
private static function _timestamp()
|
551 |
{
|
552 |
+
// $originalZone = date_default_timezone_get();
|
553 |
+
// date_default_timezone_set('UTC');
|
554 |
+
$timestamp = strftime('%Y-%m-%dT%TZ');
|
555 |
+
// date_default_timezone_set($originalZone);
|
556 |
|
557 |
return $timestamp;
|
558 |
}
|
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: 5.3
|
7 |
-
Stable tag: 3.9.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -158,6 +158,16 @@ https://simple-membership-plugin.com/
|
|
158 |
|
159 |
== Changelog ==
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
= 3.9.2 =
|
162 |
- Spanish translation language files updated.
|
163 |
- Added more debug logging statement in the IPN handling script for easier troubleshooting.
|
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: 5.3
|
7 |
+
Stable tag: 3.9.4
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
158 |
|
159 |
== Changelog ==
|
160 |
|
161 |
+
= 3.9.4 =
|
162 |
+
- Commented out call to date_default_timezone_set() function for WP5.3.
|
163 |
+
- Updated some comments in the SwpmAjax class.
|
164 |
+
- Added an extra content protection check for post preview URL.
|
165 |
+
|
166 |
+
= 3.9.3 =
|
167 |
+
- Added the option to enable HTML email in the email settings menu of the plugin.
|
168 |
+
- The Stripe subscription updated event is now handled by the plugin.
|
169 |
+
- A new shortcode to create a PayPal subscription cancellation link that a member can use to view the subscription from their account and cancel.
|
170 |
+
|
171 |
= 3.9.2 =
|
172 |
- Spanish translation language files updated.
|
173 |
- Added more debug logging statement in the IPN handling script for easier troubleshooting.
|
simple-wp-membership.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Simple WordPress Membership
|
4 |
-
Version: 3.9.
|
5 |
Plugin URI: https://simple-membership-plugin.com/
|
6 |
Author: smp7, wp.insider
|
7 |
Author URI: https://simple-membership-plugin.com/
|
@@ -19,7 +19,7 @@ include_once('classes/class.simple-wp-membership.php');
|
|
19 |
include_once('classes/class.swpm-cronjob.php');
|
20 |
include_once('swpm-compat.php');
|
21 |
|
22 |
-
define('SIMPLE_WP_MEMBERSHIP_VER', '3.9.
|
23 |
define('SIMPLE_WP_MEMBERSHIP_DB_VER', '1.3');
|
24 |
define('SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL', home_url());
|
25 |
define('SIMPLE_WP_MEMBERSHIP_PATH', dirname(__FILE__) . '/');
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Simple WordPress Membership
|
4 |
+
Version: 3.9.4
|
5 |
Plugin URI: https://simple-membership-plugin.com/
|
6 |
Author: smp7, wp.insider
|
7 |
Author URI: https://simple-membership-plugin.com/
|
19 |
include_once('classes/class.swpm-cronjob.php');
|
20 |
include_once('swpm-compat.php');
|
21 |
|
22 |
+
define('SIMPLE_WP_MEMBERSHIP_VER', '3.9.4');
|
23 |
define('SIMPLE_WP_MEMBERSHIP_DB_VER', '1.3');
|
24 |
define('SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL', home_url());
|
25 |
define('SIMPLE_WP_MEMBERSHIP_PATH', dirname(__FILE__) . '/');
|