1
2
3
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
|
<?php
class SwpmInitTimeTasks {
public function __construct() { }
public function do_init_tasks() {
//Set up localisation. First loaded ones will override strings present in later loaded file. //Allows users to have a customized language in a different folder. $locale = apply_filters('plugin_locale', get_locale(), 'simple-membership'); load_textdomain('simple-membership', WP_LANG_DIR . "/simple-membership-$locale.mo"); load_plugin_textdomain('simple-membership', false, SIMPLE_WP_MEMBERSHIP_DIRNAME . '/languages/');
if (!isset($_COOKIE['swpm_session'])) { // give a unique ID to current session. $uid = md5(microtime()); $_COOKIE['swpm_session'] = $uid; // fake it for current session/ setcookie('swpm_session', $uid, 0, '/'); }
//Crete the custom post types $this->create_post_type();
//Do frontend-only init time tasks if (!is_admin()) { SwpmAuth::get_instance();
$this->check_and_handle_auto_login(); $this->verify_and_delete_account();
$swpm_logout = filter_input(INPUT_GET, 'swpm-logout'); if (!empty($swpm_logout)) { SwpmAuth::get_instance()->logout(); $redirect_url = apply_filters('swpm_after_logout_redirect_url', SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL); wp_redirect(trailingslashit($redirect_url)); exit(0); } $this->process_password_reset(); $this->register_member(); $this->check_and_do_email_activation(); $this->edit_profile(); SwpmCommentFormRelated::check_and_restrict_comment_posting_to_members(); } else { //Do admin side init time tasks if (current_user_can(SWPM_MANAGEMENT_PERMISSION)) { //Admin dashboard side stuff $this->admin_init(); } } }
public function admin_init() { $createswpmuser = filter_input(INPUT_POST, 'createswpmuser'); if (!empty($createswpmuser)) { SwpmAdminRegistration::get_instance()->register_admin_end(); } $editswpmuser = filter_input(INPUT_POST, 'editswpmuser'); if (!empty($editswpmuser)) { $id = filter_input(INPUT_GET, 'member_id', FILTER_VALIDATE_INT); SwpmAdminRegistration::get_instance()->edit_admin_end($id); } $createswpmlevel = filter_input(INPUT_POST, 'createswpmlevel'); if (!empty($createswpmlevel)) { SwpmMembershipLevel::get_instance()->create_level(); } $editswpmlevel = filter_input(INPUT_POST, 'editswpmlevel'); if (!empty($editswpmlevel)) { $id = filter_input(INPUT_GET, 'id'); SwpmMembershipLevel::get_instance()->edit_level($id); } $update_category_list = filter_input(INPUT_POST, 'update_category_list'); if (!empty($update_category_list)) { include_once('class.swpm-category-list.php'); SwpmCategoryList::update_category_list(); } $update_post_list = filter_input(INPUT_POST, 'update_post_list'); if (!empty($update_post_list)) { include_once('class.swpm-post-list.php'); SwpmPostList::update_post_list(); } }
public function create_post_type() { //The payment button data for membership levels will be stored using this CPT register_post_type('swpm_payment_button', array( 'public' => false, 'publicly_queryable' => false, 'show_ui' => false, 'query_var' => false, 'rewrite' => false, 'capability_type' => 'page', 'has_archive' => false, 'hierarchical' => false, 'supports' => array('title', 'editor') )); }
private function verify_and_delete_account() { include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'classes/class.swpm-members.php'); $delete_account = filter_input(INPUT_GET, 'swpm_delete_account'); if (empty($delete_account)) { return; } $password = filter_input(INPUT_POST, 'account_delete_confirm_pass', FILTER_UNSAFE_RAW);
$auth = SwpmAuth::get_instance(); if (!$auth->is_logged_in()) { return; } if (empty($password)) { SwpmUtils::account_delete_confirmation_ui(); }
$nonce_field = filter_input(INPUT_POST, 'account_delete_confirm_nonce'); if (empty($nonce_field) || !wp_verify_nonce($nonce_field, 'swpm_account_delete_confirm')) { SwpmUtils::account_delete_confirmation_ui(SwpmUtils::_("Sorry, Nonce verification failed.")); } if ($auth->match_password($password)) { $auth->delete(); wp_safe_redirect(get_home_url()); exit(0); } else { SwpmUtils::account_delete_confirmation_ui(SwpmUtils::_("Sorry, Password didn't match.")); } }
public function process_password_reset() { $message = ""; $swpm_reset = filter_input(INPUT_POST, 'swpm-reset'); $swpm_reset_email = filter_input(INPUT_POST, 'swpm_reset_email', FILTER_UNSAFE_RAW); if (!empty($swpm_reset)) { SwpmFrontRegistration::get_instance()->reset_password($swpm_reset_email); } }
private function register_member() { $registration = filter_input(INPUT_POST, 'swpm_registration_submit'); if (!empty($registration)) { SwpmFrontRegistration::get_instance()->register_front_end(); } }
private function check_and_do_email_activation() { $email_activation = filter_input(INPUT_GET, 'swpm_email_activation', FILTER_SANITIZE_NUMBER_INT); if (!empty($email_activation)) { SwpmFrontRegistration::get_instance()->email_activation(); } //also check activation email resend request $email_activation_resend = filter_input(INPUT_GET, 'swpm_resend_activation_email', FILTER_SANITIZE_NUMBER_INT); if (!empty($email_activation_resend)) { SwpmFrontRegistration::get_instance()->resend_activation_email(); } }
private function edit_profile() { $swpm_editprofile_submit = filter_input(INPUT_POST, 'swpm_editprofile_submit'); if (!empty($swpm_editprofile_submit)) { SwpmFrontRegistration::get_instance()->edit_profile_front_end(); //TODO - allow an option to do a redirect if successful edit profile form submission? } }
public function check_and_handle_auto_login() {
if (isset($_REQUEST['swpm_auto_login']) && $_REQUEST['swpm_auto_login'] == '1') { //Handle the auto login SwpmLog::log_simple_debug("Handling auto login request...", true);
$enable_auto_login = SwpmSettings::get_instance()->get_value('auto-login-after-rego'); if (empty($enable_auto_login)) { SwpmLog::log_simple_debug("Auto login after registration feature is disabled in settings.", true); return; }
//Check auto login nonce value $auto_login_nonce = isset($_REQUEST['swpm_auto_login_nonce']) ? $_REQUEST['swpm_auto_login_nonce'] : ''; if (!wp_verify_nonce($auto_login_nonce, 'swpm-auto-login-nonce')) { SwpmLog::log_simple_debug("Error! Auto login nonce verification check failed!", false); wp_die("Auto login nonce verification check failed!"); }
//Perform the login $auth = SwpmAuth::get_instance(); $user = apply_filters('swpm_user_name', filter_input(INPUT_GET, 'swpm_user_name')); $user = sanitize_user($user); $encoded_pass = filter_input(INPUT_GET, 'swpm_encoded_pw'); $pass = base64_decode($encoded_pass); $auth->login($user, $pass); SwpmLog::log_simple_debug("Auto login request completed for: " . $user, true); } }
}
|