Version Description
- Fixed an issue with the category protection menu after the class refactoring work.
- Fixed the unique key in the DB table
Download this release
Release Info
Developer | mra13 |
Plugin | Simple Membership |
Version | 2.2.6 |
Comparing to | |
See all releases |
Code changes from version 2.2.4 to 2.2.6
- classes/admin-includes/class.swpm-payments-list-table.php +153 -0
- classes/class.simple-wp-membership.php +237 -221
- classes/class.swpm-access-control.php +109 -0
- classes/class.swpm-admin-registration.php +92 -0
- classes/class.swpm-ajax.php +36 -0
- classes/class.swpm-auth-permission-collection.php +9 -0
- classes/class.swpm-auth.php +291 -0
- classes/class.swpm-category-list.php +115 -0
- classes/class.swpm-cronjob.php +60 -0
- classes/class.swpm-form.php +308 -0
- classes/class.swpm-front-form.php +7 -0
- classes/class.swpm-front-registration.php +206 -0
- classes/class.swpm-installation.php +241 -0
- classes/class.swpm-level-form.php +126 -0
- classes/class.swpm-log.php +77 -0
- classes/class.swpm-member-utils.php +43 -0
- classes/class.swpm-members.php +198 -0
- classes/class.swpm-membership-level-custom.php +93 -0
- classes/class.swpm-membership-level-utils.php +10 -0
- classes/class.swpm-membership-level.php +70 -0
- classes/class.swpm-membership-levels.php +188 -0
- classes/class.swpm-messages.php +23 -0
- classes/class.swpm-misc-utils.php +167 -0
- classes/class.swpm-notification-bus.php +10 -0
- classes/class.swpm-permission-collection.php +49 -0
- classes/class.swpm-permission.php +65 -0
- classes/class.swpm-protection-base.php +296 -0
- classes/class.swpm-protection.php +69 -0
- classes/class.swpm-registration.php +42 -0
- classes/class.swpm-session.php +0 -0
- classes/class.swpm-settings.php +395 -0
- classes/class.swpm-transactions.php +55 -0
- classes/class.swpm-transfer.php +65 -0
- classes/class.swpm-utils.php +385 -0
- classes/common/class.swpm-list-table.php +1138 -0
- ipn/swpm_handle_pp_ipn.php +3 -3
- ipn/swpm_handle_subsc_ipn.php +3 -3
- readme.txt +7 -1
- simple-wp-membership.php +17 -13
- swpm-compat.php +102 -0
- views/add.php +8 -8
- views/admin_add.php +10 -10
- views/admin_add_level.php +16 -16
- views/admin_add_ons_page.php +1 -1
- views/admin_addon_settings.php +2 -2
- views/admin_category_list.php +4 -4
- views/admin_edit.php +12 -12
- views/admin_edit_level.php +17 -17
- views/admin_member_form_common_part.php +14 -14
- views/admin_members.php +4 -4
- views/admin_membership_level_menu.php +3 -3
- views/admin_membership_levels.php +3 -3
- views/admin_membership_manage.php +1 -1
- views/admin_payment_settings.php +6 -6
- views/admin_payments_page.php +13 -14
- views/admin_settings.php +1 -1
- views/admin_tools_settings.php +9 -9
- views/edit.php +16 -16
- views/forgot_password.php +2 -2
- views/loggedin.php +5 -5
- views/login.php +6 -6
classes/admin-includes/class.swpm-payments-list-table.php
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'classes/common/class.swpm-list-table.php');
|
4 |
+
|
5 |
+
class SWPMPaymentsListTable extends SWPM_List_Table {
|
6 |
+
|
7 |
+
function __construct() {
|
8 |
+
global $status, $page;
|
9 |
+
|
10 |
+
//Set parent defaults
|
11 |
+
parent::__construct(array(
|
12 |
+
'singular' => 'transaction', //singular name of the listed records
|
13 |
+
'plural' => 'transactions', //plural name of the listed records
|
14 |
+
'ajax' => false //does this table support ajax?
|
15 |
+
));
|
16 |
+
}
|
17 |
+
|
18 |
+
function column_default($item, $column_name) {
|
19 |
+
//Just print the data for that column
|
20 |
+
return $item[$column_name];
|
21 |
+
}
|
22 |
+
|
23 |
+
function column_id($item) {
|
24 |
+
|
25 |
+
//Build row actions
|
26 |
+
$actions = array(
|
27 |
+
/* 'edit' => sprintf('<a href="admin.php?page=simple_wp_membership_payments&edit_txn=%s">Edit</a>', $item['id']),//TODO - Will be implemented in a future date */
|
28 |
+
'delete' => sprintf('<a href="admin.php?page=simple_wp_membership_payments&action=delete_txn&id=%s" onclick="return confirm(\'Are you sure you want to delete this record?\')">Delete</a>', $item['id']),
|
29 |
+
);
|
30 |
+
|
31 |
+
//Return the refid column contents
|
32 |
+
return $item['id'] . $this->row_actions($actions);
|
33 |
+
}
|
34 |
+
|
35 |
+
function column_cb($item) {
|
36 |
+
return sprintf(
|
37 |
+
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
|
38 |
+
/* $1%s */ $this->_args['singular'], //Let's reuse singular label (affiliate)
|
39 |
+
/* $2%s */ $item['id'] //The value of the checkbox should be the record's key/id
|
40 |
+
);
|
41 |
+
}
|
42 |
+
|
43 |
+
function get_columns() {
|
44 |
+
$columns = array(
|
45 |
+
'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
|
46 |
+
'id' => 'Row ID',
|
47 |
+
'email' => 'Email Address',
|
48 |
+
'first_name' => 'First Name',
|
49 |
+
'last_name' => 'Last Name',
|
50 |
+
'txn_date' => 'Date',
|
51 |
+
'txn_id' => 'Transaction ID',
|
52 |
+
'payment_amount' => 'Amount',
|
53 |
+
'membership_level' => 'Membership Level'
|
54 |
+
);
|
55 |
+
return $columns;
|
56 |
+
}
|
57 |
+
|
58 |
+
function get_sortable_columns() {
|
59 |
+
$sortable_columns = array(
|
60 |
+
'id' => array('id', false), //true means its already sorted
|
61 |
+
'membership_level' => array('membership_level', false),
|
62 |
+
);
|
63 |
+
return $sortable_columns;
|
64 |
+
}
|
65 |
+
|
66 |
+
function get_bulk_actions() {
|
67 |
+
$actions = array(
|
68 |
+
'delete' => 'Delete'
|
69 |
+
);
|
70 |
+
return $actions;
|
71 |
+
}
|
72 |
+
|
73 |
+
function process_bulk_action() {
|
74 |
+
//Detect when a bulk action is being triggered... //print_r($_GET);
|
75 |
+
if ('delete' === $this->current_action()) {
|
76 |
+
$records_to_delete = $_GET['transaction'];
|
77 |
+
if (empty($records_to_delete)) {
|
78 |
+
echo '<div id="message" class="updated fade"><p>Error! You need to select multiple records to perform a bulk action!</p></div>';
|
79 |
+
return;
|
80 |
+
}
|
81 |
+
foreach ($records_to_delete as $record_id) {
|
82 |
+
global $wpdb;
|
83 |
+
$payments_table_name = $wpdb->prefix . "swpm_payments_tbl";
|
84 |
+
$updatedb = "DELETE FROM $payments_table_name WHERE id='$record_id'";
|
85 |
+
$results = $wpdb->query($updatedb);
|
86 |
+
}
|
87 |
+
echo '<div id="message" class="updated fade"><p>Selected records deleted successfully!</p></div>';
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
function delete_record($record_id) {
|
92 |
+
global $wpdb;
|
93 |
+
$payments_table_name = $wpdb->prefix . "swpm_payments_tbl";
|
94 |
+
$delete_command = "DELETE FROM " . $payments_table_name . " WHERE id = '$record_id'";
|
95 |
+
$result = $wpdb->query($delete_command);
|
96 |
+
}
|
97 |
+
|
98 |
+
function prepare_items() {
|
99 |
+
|
100 |
+
// Lets decide how many records per page to show
|
101 |
+
$per_page = 50;
|
102 |
+
|
103 |
+
$columns = $this->get_columns();
|
104 |
+
$hidden = array();
|
105 |
+
$sortable = $this->get_sortable_columns();
|
106 |
+
|
107 |
+
$this->_column_headers = array($columns, $hidden, $sortable);
|
108 |
+
|
109 |
+
$this->process_bulk_action();
|
110 |
+
|
111 |
+
// This checks for sorting input and sorts the data.
|
112 |
+
$orderby_column = isset($_GET['orderby']) ? $_GET['orderby'] : '';
|
113 |
+
$sort_order = isset($_GET['order']) ? $_GET['order'] : '';
|
114 |
+
if (empty($orderby_column)) {
|
115 |
+
$orderby_column = "id";
|
116 |
+
$sort_order = "DESC";
|
117 |
+
}
|
118 |
+
global $wpdb;
|
119 |
+
$payments_table_name = $wpdb->prefix . "swpm_payments_tbl";
|
120 |
+
|
121 |
+
//pagination requirement
|
122 |
+
$current_page = $this->get_pagenum();
|
123 |
+
|
124 |
+
if (isset($_POST['swpm_txn_search'])) {//Only load the searched records
|
125 |
+
$search_term = trim(strip_tags($_POST['swpm_txn_search']));
|
126 |
+
$prepare_query = $wpdb->prepare("SELECT * FROM " . $payments_table_name . " WHERE `email` LIKE '%%%s%%' OR `txn_id` LIKE '%%%s%%' OR `first_name` LIKE '%%%s%%' OR `last_name` LIKE '%%%s%%'", $search_term, $search_term, $search_term, $search_term);
|
127 |
+
$data = $wpdb->get_results($prepare_query, ARRAY_A);
|
128 |
+
$total_items = count($data);
|
129 |
+
} else {//Load all data in an optimized way (so it is only loading data for the current page)
|
130 |
+
$query = "SELECT COUNT(*) FROM $payments_table_name";
|
131 |
+
$total_items = $wpdb->get_var($query);
|
132 |
+
|
133 |
+
//pagination requirement
|
134 |
+
$query = "SELECT * FROM $payments_table_name ORDER BY $orderby_column $sort_order";
|
135 |
+
|
136 |
+
$offset = ($current_page - 1) * $per_page;
|
137 |
+
$query.=' LIMIT ' . (int) $offset . ',' . (int) $per_page;
|
138 |
+
|
139 |
+
$data = $wpdb->get_results($query, ARRAY_A);
|
140 |
+
}
|
141 |
+
|
142 |
+
// Now we add our *sorted* data to the items property, where it can be used by the rest of the class.
|
143 |
+
$this->items = $data;
|
144 |
+
|
145 |
+
//pagination requirement
|
146 |
+
$this->set_pagination_args(array(
|
147 |
+
'total_items' => $total_items, //WE have to calculate the total number of items
|
148 |
+
'per_page' => $per_page, //WE have to determine how many items to show on a page
|
149 |
+
'total_pages' => ceil($total_items / $per_page) //WE have to calculate the total number of pages
|
150 |
+
));
|
151 |
+
}
|
152 |
+
|
153 |
+
}
|
classes/class.simple-wp-membership.php
CHANGED
@@ -1,44 +1,45 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
include_once('class.
|
4 |
-
include_once('class.
|
5 |
-
include_once('class.
|
6 |
-
include_once('class.
|
7 |
-
include_once('class.
|
8 |
-
include_once('class.
|
9 |
-
include_once('class.
|
10 |
-
include_once('class.
|
11 |
-
include_once('class.
|
12 |
-
include_once('class.
|
13 |
-
include_once('class.
|
14 |
-
include_once('class.
|
15 |
-
include_once('class.
|
16 |
-
include_once('class.
|
17 |
-
include_once('class.
|
18 |
-
include_once('class.
|
19 |
-
include_once('class.
|
20 |
-
include_once('class.
|
21 |
-
include_once('class.
|
22 |
-
include_once('class.
|
23 |
-
include_once('class.
|
24 |
-
include_once('class.
|
25 |
-
include_once('class.
|
26 |
-
include_once('class.
|
27 |
-
include_once('class.
|
28 |
|
29 |
class SimpleWpMembership {
|
|
|
30 |
public function __construct() {
|
31 |
-
add_action('admin_menu', array(&$this, 'menu'));
|
32 |
add_action('init', array(&$this, 'init'));
|
33 |
|
34 |
-
add_filter('the_content', array(&$this, 'filter_content'),11,1);
|
35 |
add_filter('widget_text', 'do_shortcode');
|
36 |
add_filter('show_admin_bar', array(&$this, 'hide_adminbar'));
|
37 |
add_filter('comment_text', array(&$this, 'filter_comment'));
|
38 |
add_filter('wp_get_attachment_url', array(&$this, 'filter_attachment_url'), 10, 2);
|
39 |
add_filter('wp_get_attachment_metadata', array(&$this, 'filter_attachment'), 10, 2);
|
40 |
-
add_filter('attachment_fields_to_save', array(&$this,'save_attachment_extra'), 10, 2);
|
41 |
-
add_filter('the_content_more_link', array(&$this, 'filter_moretag'), 10, 2
|
42 |
|
43 |
add_shortcode("swpm_registration_form", array(&$this, 'registration_form'));
|
44 |
add_shortcode('swpm_profile_form', array(&$this, 'profile_form'));
|
@@ -53,109 +54,120 @@ class SimpleWpMembership {
|
|
53 |
add_action('profile_update', array(&$this, 'sync_with_wp_profile'), 10, 2);
|
54 |
add_action('wp_logout', array(&$this, 'wp_logout'));
|
55 |
add_action('wp_authenticate', array(&$this, 'wp_login'), 1, 2);
|
56 |
-
add_action('swpm_logout', array(&$this, 'swpm_logout'));
|
57 |
-
|
58 |
//AJAX hooks
|
59 |
-
add_action('wp_ajax_swpm_validate_email', '
|
60 |
-
add_action('wp_ajax_nopriv_swpm_validate_email', '
|
61 |
-
add_action('wp_ajax_swpm_validate_user_name', '
|
62 |
-
add_action('wp_ajax_nopriv_swpm_validate_user_name', '
|
63 |
|
64 |
//init is too early for settings api.
|
65 |
add_action('admin_init', array(&$this, 'admin_init_hook'));
|
66 |
add_action('plugins_loaded', array(&$this, "plugins_loaded"));
|
67 |
add_action('password_reset', array(&$this, 'wp_password_reset_hook'), 10, 2);
|
68 |
}
|
69 |
-
|
70 |
-
{
|
71 |
-
$swpm_id =
|
72 |
-
if (!empty($swpm_id)){
|
73 |
-
$password_hash =
|
74 |
global $wpdb;
|
75 |
$wpdb->update($wpdb->prefix . "swpm_members_tbl", array('password' => $password_hash), array('member_id' => $swpm_id));
|
76 |
-
}
|
77 |
}
|
78 |
-
|
79 |
public function save_attachment_extra($post, $attachment) {
|
80 |
$this->save_postdata($post['ID']);
|
81 |
return $post;
|
82 |
}
|
83 |
-
|
84 |
-
|
|
|
85 |
return $content;
|
86 |
}
|
87 |
-
|
88 |
-
$acl =
|
89 |
-
if (has_post_thumbnail($post_id)){
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
94 |
$content['file'] = 'restricted-icon.png';
|
95 |
$content['width'] = '400';
|
96 |
$content['height'] = '400';
|
97 |
}
|
98 |
-
|
99 |
-
if (isset($content['sizes'])){
|
100 |
-
if ($content['sizes']['thumbnail']){
|
101 |
$content['sizes']['thumbnail']['file'] = 'restricted-icon.png';
|
102 |
$content['sizes']['thumbnail']['mime-type'] = 'image/png';
|
103 |
}
|
104 |
-
if ($content['sizes']['medium']){
|
105 |
$content['sizes']['medium']['file'] = 'restricted-icon.png';
|
106 |
$content['sizes']['medium']['mime-type'] = 'image/png';
|
107 |
}
|
108 |
-
if ($content['sizes']['post-thumbnail']){
|
109 |
$content['sizes']['post-thumbnail']['file'] = 'restricted-icon.png';
|
110 |
$content['sizes']['post-thumbnail']['mime-type'] = 'image/png';
|
111 |
}
|
112 |
}
|
113 |
return $content;
|
114 |
}
|
115 |
-
|
116 |
-
public function filter_attachment_url($content, $post_id){
|
117 |
-
if(is_admin()){//No need to filter on the admin side
|
118 |
return $content;
|
119 |
}
|
120 |
-
$acl =
|
121 |
-
if (has_post_thumbnail($post_id)){
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
126 |
}
|
127 |
-
|
128 |
-
public function admin_init_hook(){
|
129 |
-
|
130 |
$addon_saved = filter_input(INPUT_POST, 'swpm-addon-settings');
|
131 |
-
if(!empty($addon_saved)){
|
132 |
do_action('swpm_addon_settings_save');
|
133 |
}
|
134 |
}
|
135 |
-
|
136 |
-
public function hide_adminbar(){
|
137 |
-
if (!is_user_logged_in()){//Never show admin bar if the user is not even logged in
|
138 |
return false;
|
139 |
}
|
140 |
-
$hide =
|
141 |
-
return $hide? FALSE: TRUE;
|
142 |
}
|
143 |
-
|
144 |
-
|
|
|
145 |
}
|
|
|
146 |
public static function swpm_login($user, $pass, $rememberme = true) {
|
147 |
if (is_user_logged_in()) {
|
148 |
$current_user = wp_get_current_user();
|
149 |
-
if ($current_user->user_login == $user){
|
150 |
return;
|
151 |
}
|
152 |
}
|
153 |
$user = wp_signon(array('user_login' => $user, 'user_password' => $pass, 'remember' => $rememberme), is_ssl());
|
154 |
-
if (
|
155 |
-
wp_set_current_user(
|
156 |
}
|
157 |
do_action('swpm_after_login');
|
158 |
-
if (!
|
159 |
wp_redirect(site_url());
|
160 |
}
|
161 |
}
|
@@ -168,16 +180,18 @@ class SimpleWpMembership {
|
|
168 |
}
|
169 |
|
170 |
public function wp_login($username, $password) {
|
171 |
-
$auth =
|
172 |
-
if (($auth->is_logged_in() &&($auth->userData->user_name == $username))) {
|
173 |
return;
|
174 |
}
|
175 |
-
if(!empty($username)) {
|
|
|
|
|
176 |
}
|
177 |
|
178 |
public function wp_logout() {
|
179 |
-
$auth =
|
180 |
-
if ($auth->is_logged_in()){
|
181 |
$auth->logout();
|
182 |
}
|
183 |
}
|
@@ -188,7 +202,7 @@ class SimpleWpMembership {
|
|
188 |
$query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE " . ' user_name=%s', $wp_user_data->user_login);
|
189 |
$profile = $wpdb->get_row($query, ARRAY_A);
|
190 |
$profile = (array) $profile;
|
191 |
-
if (empty($profile)){
|
192 |
return;
|
193 |
}
|
194 |
$profile['user_name'] = $wp_user_data->user_login;
|
@@ -201,36 +215,37 @@ class SimpleWpMembership {
|
|
201 |
|
202 |
public function login() {
|
203 |
ob_start();
|
204 |
-
$auth =
|
205 |
-
if ($auth->is_logged_in()){
|
206 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/loggedin.php');
|
207 |
-
}
|
208 |
-
|
209 |
-
$setting = BSettings::get_instance();
|
210 |
$password_reset_url = $setting->get_value('reset-page-url');
|
211 |
$join_url = $setting->get_value('join-us-page-url');
|
212 |
|
213 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/login.php');
|
214 |
-
|
215 |
}
|
216 |
return ob_get_clean();
|
217 |
}
|
218 |
|
219 |
public function reset() {
|
220 |
$succeeded = $this->notices();
|
221 |
-
if($succeeded){
|
222 |
return '';
|
223 |
}
|
224 |
ob_start();
|
225 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/forgot_password.php');
|
226 |
return ob_get_clean();
|
227 |
}
|
|
|
228 |
public function profile_form() {
|
229 |
-
$auth =
|
230 |
$this->notices();
|
231 |
if ($auth->is_logged_in()) {
|
232 |
$out = apply_filters('swpm_profile_form_override', '');
|
233 |
-
if (!empty($out)){
|
|
|
|
|
234 |
$user_data = (array) $auth->userData;
|
235 |
$user_data['membership_level_alias'] = $auth->get('alias');
|
236 |
ob_start();
|
@@ -238,27 +253,28 @@ class SimpleWpMembership {
|
|
238 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/edit.php');
|
239 |
return ob_get_clean();
|
240 |
}
|
241 |
-
return
|
242 |
}
|
243 |
|
244 |
public function notices() {
|
245 |
-
$message =
|
246 |
$succeeded = false;
|
247 |
-
if (empty($message)) {
|
|
|
|
|
248 |
if ($message['succeeded']) {
|
249 |
echo "<div id='message' class='updated'>";
|
250 |
$succeeded = true;
|
251 |
-
} else{
|
252 |
echo "<div id='message' class='error'>";
|
253 |
}
|
254 |
echo $message['message'];
|
255 |
$extra = isset($message['extra']) ? $message['extra'] : array();
|
256 |
-
if (is_string($extra)){
|
257 |
echo $extra;
|
258 |
-
}
|
259 |
-
else if (is_array($extra)) {
|
260 |
echo '<ul>';
|
261 |
-
foreach ($extra as $key => $value){
|
262 |
echo '<li>' . $value . '</li>';
|
263 |
}
|
264 |
echo '</ul>';
|
@@ -270,10 +286,8 @@ class SimpleWpMembership {
|
|
270 |
public function meta_box() {
|
271 |
if (function_exists('add_meta_box')) {
|
272 |
$post_types = get_post_types();
|
273 |
-
foreach ($post_types as $post_type => $post_type){
|
274 |
-
add_meta_box('swpm_sectionid',
|
275 |
-
__('Simple WP Membership Protection', 'swpm'),
|
276 |
-
array(&$this, 'inner_custom_box'), $post_type, 'advanced');
|
277 |
}
|
278 |
} else {//older version doesn't have custom post type so modification isn't needed.
|
279 |
add_action('dbx_post_advanced', array(&$this, 'show_old_custom_box'));
|
@@ -297,74 +311,72 @@ class SimpleWpMembership {
|
|
297 |
global $post, $wpdb;
|
298 |
$id = $post->ID;
|
299 |
// Use nonce for verification
|
300 |
-
$is_protected =
|
301 |
echo '<input type="hidden" name="swpm_noncename" id="swpm_noncename" value="' .
|
302 |
wp_create_nonce(plugin_basename(__FILE__)) . '" />';
|
303 |
// The actual fields for data entry
|
304 |
echo '<h4>' . __("Do you want to protect this content?", 'swpm') . '</h4>';
|
305 |
echo '<input type="radio" ' . ((!$is_protected) ? 'checked' : "") .
|
306 |
-
|
307 |
echo '<input type="radio" ' . (($is_protected) ? 'checked' : "") .
|
308 |
-
|
309 |
echo '<h4>' . __("Select the membership level that can access this content:", 'swpm') . "</h4>";
|
310 |
$query = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
|
311 |
$levels = $wpdb->get_results($query, ARRAY_A);
|
312 |
foreach ($levels as $level) {
|
313 |
-
echo '<input type="checkbox" ' . (
|
314 |
-
|
315 |
}
|
316 |
}
|
317 |
|
318 |
public function save_postdata($post_id) {
|
319 |
global $wpdb;
|
320 |
-
$post_type = filter_input(INPUT_POST,'post_type');
|
321 |
-
$swpm_protect_post = filter_input(INPUT_POST,'swpm_protect_post');
|
322 |
$swpm_noncename = filter_input(INPUT_POST, 'swpm_noncename');
|
323 |
-
if (wp_is_post_revision($post_id)){
|
324 |
return;
|
325 |
}
|
326 |
-
if (!wp_verify_nonce($swpm_noncename, plugin_basename(__FILE__))){
|
327 |
return $post_id;
|
328 |
}
|
329 |
-
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
|
330 |
return $post_id;
|
331 |
}
|
332 |
-
if ('page' == $post_type
|
333 |
-
if (!current_user_can('edit_page', $post_id)){
|
334 |
return $post_id;
|
335 |
}
|
336 |
} else {
|
337 |
-
if (!current_user_can('edit_post', $post_id)){
|
338 |
return $post_id;
|
339 |
}
|
340 |
}
|
341 |
-
if (empty($swpm_protect_post)){
|
342 |
return;
|
343 |
}
|
344 |
// OK, we're authenticated: we need to find and save the data
|
345 |
$isprotected = ($swpm_protect_post == 2);
|
346 |
-
$args =
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
$swpm_protection_level = filter_input_array(INPUT_POST, $args);
|
351 |
$swpm_protection_level = $swpm_protection_level['swpm_protection_level'];
|
352 |
if (!empty($post_type)) {
|
353 |
-
if($isprotected){
|
354 |
-
|
355 |
-
}
|
356 |
-
|
357 |
-
BProtection::get_instance()->remove(array($post_id),$post_type);
|
358 |
}
|
359 |
-
|
360 |
$query = "SELECT id FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
|
361 |
$level_ids = $wpdb->get_col($query);
|
362 |
-
foreach ($level_ids as $level){
|
363 |
-
if(isset($swpm_protection_level[$level])){
|
364 |
-
|
365 |
-
}
|
366 |
-
|
367 |
-
BPermission::get_instance($level)->remove(array($post_id), $post_type)->save();
|
368 |
}
|
369 |
}
|
370 |
}
|
@@ -375,22 +387,26 @@ class SimpleWpMembership {
|
|
375 |
}
|
376 |
|
377 |
public function filter_comment($content) {
|
378 |
-
$acl =
|
379 |
global $comment;
|
380 |
return $acl->filter_post($comment->comment_post_ID, $content);
|
381 |
}
|
382 |
|
383 |
public function filter_content($content) {
|
384 |
-
if (is_preview()) {
|
385 |
-
|
|
|
|
|
386 |
global $post;
|
387 |
return $acl->filter_post($post->ID, $content);
|
388 |
}
|
389 |
|
390 |
public function filter_moretag($more_link, $more_link_text = "More") {
|
391 |
-
$moretag =
|
392 |
-
if (empty($moretag)) {
|
393 |
-
|
|
|
|
|
394 |
global $post;
|
395 |
return $acl->filter_post_with_moretag($post->ID, $more_link, $more_link_text);
|
396 |
}
|
@@ -398,21 +414,21 @@ class SimpleWpMembership {
|
|
398 |
public function admin_init() {
|
399 |
$createswpmuser = filter_input(INPUT_POST, 'createswpmuser');
|
400 |
if (!empty($createswpmuser)) {
|
401 |
-
|
402 |
}
|
403 |
$editswpmuser = filter_input(INPUT_POST, 'editswpmuser');
|
404 |
if (!empty($editswpmuser)) {
|
405 |
$id = filter_input(INPUT_GET, 'member_id', FILTER_VALIDATE_INT);
|
406 |
-
|
407 |
}
|
408 |
$createswpmlevel = filter_input(INPUT_POST, 'createswpmlevel');
|
409 |
if (!empty($createswpmlevel)) {
|
410 |
-
|
411 |
}
|
412 |
$editswpmlevel = filter_input(INPUT_POST, 'editswpmlevel');
|
413 |
if (!empty($editswpmlevel)) {
|
414 |
$id = filter_input(INPUT_GET, 'id');
|
415 |
-
|
416 |
}
|
417 |
}
|
418 |
|
@@ -420,9 +436,9 @@ class SimpleWpMembership {
|
|
420 |
|
421 |
//Set up localisation. First loaded ones will override strings present in later loaded file.
|
422 |
//Allows users to have a customized language in a different folder.
|
423 |
-
$locale = apply_filters(
|
424 |
-
load_textdomain(
|
425 |
-
|
426 |
|
427 |
if (!isset($_COOKIE['swpm_session'])) { // give a unique ID to current session.
|
428 |
$uid = md5(microtime());
|
@@ -430,15 +446,15 @@ class SimpleWpMembership {
|
|
430 |
setcookie('swpm_session', $uid, 0, '/');
|
431 |
}
|
432 |
|
433 |
-
if(current_user_can('manage_options')){ // admin stuff
|
434 |
$this->admin_init();
|
435 |
}
|
436 |
-
if (!is_admin()){ //frontend stuff
|
437 |
-
|
438 |
$this->verify_and_delete_account();
|
439 |
$swpm_logout = filter_input(INPUT_GET, 'swpm-logout');
|
440 |
if (!empty($swpm_logout)) {
|
441 |
-
|
442 |
wp_redirect(home_url());
|
443 |
}
|
444 |
$this->process_password_reset();
|
@@ -451,7 +467,7 @@ class SimpleWpMembership {
|
|
451 |
public function swpm_ipn_listener() {
|
452 |
$swpm_process_ipn = filter_input(INPUT_GET, 'swpm_process_ipn');
|
453 |
if ($swpm_process_ipn == '1') {
|
454 |
-
include(SIMPLE_WP_MEMBERSHIP_PATH.'ipn/swpm_handle_pp_ipn.php');
|
455 |
exit;
|
456 |
}
|
457 |
}
|
@@ -461,14 +477,14 @@ class SimpleWpMembership {
|
|
461 |
$swpm_reset = filter_input(INPUT_POST, 'swpm-reset');
|
462 |
$swpm_reset_email = filter_input(INPUT_POST, 'swpm_reset_email', FILTER_UNSAFE_RAW);
|
463 |
if (!empty($swpm_reset)) {
|
464 |
-
|
465 |
}
|
466 |
}
|
467 |
|
468 |
private function edit_profile() {
|
469 |
-
$swpm_editprofile_submit = filter_input(INPUT_POST, 'swpm_editprofile_submit');
|
470 |
if (!empty($swpm_editprofile_submit)) {
|
471 |
-
|
472 |
//todo: do a redirect
|
473 |
}
|
474 |
}
|
@@ -478,10 +494,10 @@ class SimpleWpMembership {
|
|
478 |
wp_enqueue_script('password-strength-meter');
|
479 |
wp_enqueue_script('swpm.password-meter', SIMPLE_WP_MEMBERSHIP_URL . '/js/swpm.password-meter.js');
|
480 |
wp_enqueue_style('jquery.tools.dateinput', SIMPLE_WP_MEMBERSHIP_URL . '/css/jquery.tools.dateinput.css');
|
481 |
-
wp_enqueue_script('jquery.tools', SIMPLE_WP_MEMBERSHIP_URL . '/js/jquery.tools18.min.js');
|
482 |
-
$settings = array('statusChangeEmailHead'=>
|
483 |
-
|
484 |
-
wp_localize_script(
|
485 |
}
|
486 |
|
487 |
public function front_library() {
|
@@ -498,19 +514,19 @@ class SimpleWpMembership {
|
|
498 |
|
499 |
public function registration_form($atts) {
|
500 |
$succeeded = $this->notices();
|
501 |
-
if($succeeded){
|
502 |
return;
|
503 |
}
|
504 |
-
$is_free =
|
505 |
-
$free_level = absint(
|
506 |
-
$level = isset($atts['level'])? absint($atts['level']): ($is_free? $free_level: null);
|
507 |
-
return
|
508 |
}
|
509 |
|
510 |
private function register_member() {
|
511 |
$registration = filter_input(INPUT_POST, 'swpm_registration_submit');
|
512 |
if (!empty($registration)) {
|
513 |
-
|
514 |
}
|
515 |
}
|
516 |
|
@@ -520,25 +536,20 @@ class SimpleWpMembership {
|
|
520 |
add_menu_page(__("WP Membership", 'swpm'), __("WP Membership", 'swpm')
|
521 |
, 'manage_options', $menu_parent_slug, array(&$this, "admin_members")
|
522 |
, SIMPLE_WP_MEMBERSHIP_URL . '/images/logo.png');
|
523 |
-
add_submenu_page($menu_parent_slug, __("Members", 'swpm'), __('Members', 'swpm'),
|
524 |
-
|
525 |
-
add_submenu_page($menu_parent_slug, __("
|
526 |
-
|
527 |
-
add_submenu_page($menu_parent_slug, __("
|
528 |
-
|
529 |
-
add_submenu_page($menu_parent_slug, __("Payments", 'swpm'), __("Payments", 'swpm'),
|
530 |
-
'manage_options', 'simple_wp_membership_payments', array(&$this, "payments_menu"));
|
531 |
-
add_submenu_page($menu_parent_slug, __("Add-ons", 'swpm'), __("Add-ons", 'swpm'),
|
532 |
-
'manage_options', 'simple_wp_membership_addons', array(&$this, "add_ons_menu"));
|
533 |
-
|
534 |
do_action('swpm_after_main_admin_menu', $menu_parent_slug);
|
535 |
|
536 |
$this->meta_box();
|
537 |
}
|
538 |
|
539 |
public function admin_membership_levels() {
|
540 |
-
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'classes/class.
|
541 |
-
$levels = new
|
542 |
$level_action = filter_input(INPUT_GET, 'level_action');
|
543 |
$action2 = filter_input(INPUT_GET, 'action2');
|
544 |
$action = $level_action ? $level_action : ($action2 ? $action2 : "");
|
@@ -563,10 +574,10 @@ class SimpleWpMembership {
|
|
563 |
}
|
564 |
|
565 |
public function admin_members() {
|
566 |
-
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'classes/class.
|
567 |
-
$members = new
|
568 |
$action = filter_input(INPUT_GET, 'member_action');
|
569 |
-
$action = empty($action)? filter_input(INPUT_POST, 'action') : $action;
|
570 |
switch ($action) {
|
571 |
case 'add':
|
572 |
case 'edit':
|
@@ -582,16 +593,16 @@ class SimpleWpMembership {
|
|
582 |
}
|
583 |
|
584 |
public function admin_settings() {
|
585 |
-
$current_tab =
|
586 |
switch ($current_tab) {
|
587 |
case 6:
|
588 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_addon_settings.php');
|
589 |
-
break;
|
590 |
case 4:
|
591 |
-
$link_for = filter_input(INPUT_POST, 'swpm_link_for',FILTER_SANITIZE_STRING);
|
592 |
-
$member_id = filter_input(INPUT_POST, 'member_id',FILTER_SANITIZE_NUMBER_INT);
|
593 |
-
$send_email = filter_input(INPUT_POST, 'swpm_reminder_email',FILTER_SANITIZE_NUMBER_INT);
|
594 |
-
$links =
|
595 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_tools_settings.php');
|
596 |
break;
|
597 |
case 2:
|
@@ -602,59 +613,64 @@ class SimpleWpMembership {
|
|
602 |
break;
|
603 |
}
|
604 |
}
|
605 |
-
|
606 |
-
public function payments_menu(){
|
607 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_payments_page.php');
|
608 |
}
|
609 |
-
|
610 |
-
public function add_ons_menu(){
|
611 |
-
|
612 |
}
|
613 |
|
614 |
-
public function plugins_loaded(){
|
615 |
//Runs when plugins_loaded action gets fired
|
616 |
-
if(is_admin()){
|
617 |
//Check and run DB upgrade operation (if needed)
|
618 |
if (get_option('swpm_db_version') != SIMPLE_WP_MEMBERSHIP_DB_VER) {
|
619 |
-
include_once('class.
|
620 |
-
|
621 |
}
|
622 |
-
}
|
623 |
}
|
624 |
-
|
625 |
public static function activate() {
|
626 |
wp_schedule_event(time(), 'daily', 'swpm_account_status_event');
|
627 |
wp_schedule_event(time(), 'daily', 'swpm_delete_pending_account_event');
|
628 |
-
include_once('class.
|
629 |
-
|
630 |
}
|
631 |
-
|
632 |
public function deactivate() {
|
633 |
wp_clear_scheduled_hook('swpm_account_status_event');
|
634 |
-
wp_clear_scheduled_hook('swpm_delete_pending_account_event');
|
635 |
}
|
636 |
-
|
637 |
-
|
|
|
638 |
$delete_account = filter_input(INPUT_GET, 'delete_account');
|
639 |
-
if (empty($delete_account)) {
|
640 |
-
|
|
|
|
|
641 |
|
642 |
-
$auth =
|
643 |
-
if (!$auth->is_logged_in()){
|
644 |
-
|
645 |
-
|
|
|
|
|
646 |
}
|
647 |
-
|
648 |
$nonce_field = filter_input(INPUT_POST, 'account_delete_confirm_nonce');
|
649 |
-
if (empty($nonce_field) || !wp_verify_nonce($nonce_field, 'swpm_account_delete_confirm')){
|
650 |
-
|
651 |
-
}
|
652 |
-
if ($auth->match_password($password)){
|
653 |
$auth->delete();
|
654 |
wp_redirect(home_url());
|
655 |
-
}
|
656 |
-
|
657 |
-
BUtils::account_delete_confirmation_ui(BUtils::_("Sorry, Password didn't match."));
|
658 |
}
|
659 |
}
|
|
|
660 |
}
|
1 |
<?php
|
2 |
|
3 |
+
include_once('class.swpm-misc-utils.php');
|
4 |
+
include_once('class.swpm-utils.php');
|
5 |
+
include_once('class.swpm-member-utils.php');
|
6 |
+
include_once('class.swpm-settings.php');
|
7 |
+
include_once('class.swpm-protection.php');
|
8 |
+
include_once('class.swpm-permission.php');
|
9 |
+
include_once('class.swpm-auth.php');
|
10 |
+
include_once('class.swpm-access-control.php');
|
11 |
+
include_once('class.swpm-form.php');
|
12 |
+
include_once('class.swpm-transfer.php');
|
13 |
+
include_once('class.swpm-front-form.php');
|
14 |
+
include_once('class.swpm-level-form.php');
|
15 |
+
include_once('class.swpm-membership-levels.php');
|
16 |
+
include_once('class.swpm-log.php');
|
17 |
+
include_once('class.swpm-messages.php');
|
18 |
+
include_once('class.swpm-ajax.php');
|
19 |
+
include_once('class.swpm-registration.php');
|
20 |
+
include_once('class.swpm-front-registration.php');
|
21 |
+
include_once('class.swpm-admin-registration.php');
|
22 |
+
include_once('class.swpm-membership-level.php');
|
23 |
+
include_once('class.swpm-membership-level-custom.php');
|
24 |
+
include_once('class.swpm-membership-level-utils.php');
|
25 |
+
include_once('class.swpm-permission-collection.php');
|
26 |
+
include_once('class.swpm-auth-permission-collection.php');
|
27 |
+
include_once('class.swpm-transactions.php');
|
28 |
|
29 |
class SimpleWpMembership {
|
30 |
+
|
31 |
public function __construct() {
|
32 |
+
add_action('admin_menu', array(&$this, 'menu'));
|
33 |
add_action('init', array(&$this, 'init'));
|
34 |
|
35 |
+
add_filter('the_content', array(&$this, 'filter_content'), 11, 1);
|
36 |
add_filter('widget_text', 'do_shortcode');
|
37 |
add_filter('show_admin_bar', array(&$this, 'hide_adminbar'));
|
38 |
add_filter('comment_text', array(&$this, 'filter_comment'));
|
39 |
add_filter('wp_get_attachment_url', array(&$this, 'filter_attachment_url'), 10, 2);
|
40 |
add_filter('wp_get_attachment_metadata', array(&$this, 'filter_attachment'), 10, 2);
|
41 |
+
add_filter('attachment_fields_to_save', array(&$this, 'save_attachment_extra'), 10, 2);
|
42 |
+
add_filter('the_content_more_link', array(&$this, 'filter_moretag'), 10, 2);
|
43 |
|
44 |
add_shortcode("swpm_registration_form", array(&$this, 'registration_form'));
|
45 |
add_shortcode('swpm_profile_form', array(&$this, 'profile_form'));
|
54 |
add_action('profile_update', array(&$this, 'sync_with_wp_profile'), 10, 2);
|
55 |
add_action('wp_logout', array(&$this, 'wp_logout'));
|
56 |
add_action('wp_authenticate', array(&$this, 'wp_login'), 1, 2);
|
57 |
+
add_action('swpm_logout', array(&$this, 'swpm_logout'));
|
58 |
+
|
59 |
//AJAX hooks
|
60 |
+
add_action('wp_ajax_swpm_validate_email', 'SwpmAjax::validate_email_ajax');
|
61 |
+
add_action('wp_ajax_nopriv_swpm_validate_email', 'SwpmAjax::validate_email_ajax');
|
62 |
+
add_action('wp_ajax_swpm_validate_user_name', 'SwpmAjax::validate_user_name_ajax');
|
63 |
+
add_action('wp_ajax_nopriv_swpm_validate_user_name', 'SwpmAjax::validate_user_name_ajax');
|
64 |
|
65 |
//init is too early for settings api.
|
66 |
add_action('admin_init', array(&$this, 'admin_init_hook'));
|
67 |
add_action('plugins_loaded', array(&$this, "plugins_loaded"));
|
68 |
add_action('password_reset', array(&$this, 'wp_password_reset_hook'), 10, 2);
|
69 |
}
|
70 |
+
|
71 |
+
function wp_password_reset_hook($user, $pass) {
|
72 |
+
$swpm_id = SwpmUtils::get_user_by_user_name($user->user_login);
|
73 |
+
if (!empty($swpm_id)) {
|
74 |
+
$password_hash = SwpmUtils::encrypt_password($pass);
|
75 |
global $wpdb;
|
76 |
$wpdb->update($wpdb->prefix . "swpm_members_tbl", array('password' => $password_hash), array('member_id' => $swpm_id));
|
77 |
+
}
|
78 |
}
|
79 |
+
|
80 |
public function save_attachment_extra($post, $attachment) {
|
81 |
$this->save_postdata($post['ID']);
|
82 |
return $post;
|
83 |
}
|
84 |
+
|
85 |
+
public function filter_attachment($content, $post_id) {
|
86 |
+
if (is_admin()) {//No need to filter on the admin side
|
87 |
return $content;
|
88 |
}
|
89 |
+
|
90 |
+
$acl = SwpmAccessControl::get_instance();
|
91 |
+
if (has_post_thumbnail($post_id)) {
|
92 |
+
return $content;
|
93 |
+
}
|
94 |
+
if ($acl->can_i_read_post($post_id)) {
|
95 |
+
return $content;
|
96 |
+
}
|
97 |
+
|
98 |
+
|
99 |
+
if (isset($content['file'])) {
|
100 |
$content['file'] = 'restricted-icon.png';
|
101 |
$content['width'] = '400';
|
102 |
$content['height'] = '400';
|
103 |
}
|
104 |
+
|
105 |
+
if (isset($content['sizes'])) {
|
106 |
+
if ($content['sizes']['thumbnail']) {
|
107 |
$content['sizes']['thumbnail']['file'] = 'restricted-icon.png';
|
108 |
$content['sizes']['thumbnail']['mime-type'] = 'image/png';
|
109 |
}
|
110 |
+
if ($content['sizes']['medium']) {
|
111 |
$content['sizes']['medium']['file'] = 'restricted-icon.png';
|
112 |
$content['sizes']['medium']['mime-type'] = 'image/png';
|
113 |
}
|
114 |
+
if ($content['sizes']['post-thumbnail']) {
|
115 |
$content['sizes']['post-thumbnail']['file'] = 'restricted-icon.png';
|
116 |
$content['sizes']['post-thumbnail']['mime-type'] = 'image/png';
|
117 |
}
|
118 |
}
|
119 |
return $content;
|
120 |
}
|
121 |
+
|
122 |
+
public function filter_attachment_url($content, $post_id) {
|
123 |
+
if (is_admin()) {//No need to filter on the admin side
|
124 |
return $content;
|
125 |
}
|
126 |
+
$acl = SwpmAccessControl::get_instance();
|
127 |
+
if (has_post_thumbnail($post_id)) {
|
128 |
+
return $content;
|
129 |
+
}
|
130 |
+
|
131 |
+
if ($acl->can_i_read_post($post_id)) {
|
132 |
+
return $content;
|
133 |
+
}
|
134 |
+
|
135 |
+
return SwpmUtils::get_restricted_image_url();
|
136 |
}
|
137 |
+
|
138 |
+
public function admin_init_hook() {
|
139 |
+
SwpmSettings::get_instance()->init_config_hooks();
|
140 |
$addon_saved = filter_input(INPUT_POST, 'swpm-addon-settings');
|
141 |
+
if (!empty($addon_saved)) {
|
142 |
do_action('swpm_addon_settings_save');
|
143 |
}
|
144 |
}
|
145 |
+
|
146 |
+
public function hide_adminbar() {
|
147 |
+
if (!is_user_logged_in()) {//Never show admin bar if the user is not even logged in
|
148 |
return false;
|
149 |
}
|
150 |
+
$hide = SwpmSettings::get_instance()->get_value('hide-adminbar');
|
151 |
+
return $hide ? FALSE : TRUE;
|
152 |
}
|
153 |
+
|
154 |
+
public function shutdown() {
|
155 |
+
SwpmLog::writeall();
|
156 |
}
|
157 |
+
|
158 |
public static function swpm_login($user, $pass, $rememberme = true) {
|
159 |
if (is_user_logged_in()) {
|
160 |
$current_user = wp_get_current_user();
|
161 |
+
if ($current_user->user_login == $user) {
|
162 |
return;
|
163 |
}
|
164 |
}
|
165 |
$user = wp_signon(array('user_login' => $user, 'user_password' => $pass, 'remember' => $rememberme), is_ssl());
|
166 |
+
if (is_a($user, 'WP_User')) {
|
167 |
+
wp_set_current_user($user->ID, $user->user_login);
|
168 |
}
|
169 |
do_action('swpm_after_login');
|
170 |
+
if (!SwpmUtils::is_ajax()) {
|
171 |
wp_redirect(site_url());
|
172 |
}
|
173 |
}
|
180 |
}
|
181 |
|
182 |
public function wp_login($username, $password) {
|
183 |
+
$auth = SwpmAuth::get_instance();
|
184 |
+
if (($auth->is_logged_in() && ($auth->userData->user_name == $username))) {
|
185 |
return;
|
186 |
}
|
187 |
+
if (!empty($username)) {
|
188 |
+
$auth->login($username, $password, true);
|
189 |
+
}
|
190 |
}
|
191 |
|
192 |
public function wp_logout() {
|
193 |
+
$auth = SwpmAuth::get_instance();
|
194 |
+
if ($auth->is_logged_in()) {
|
195 |
$auth->logout();
|
196 |
}
|
197 |
}
|
202 |
$query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE " . ' user_name=%s', $wp_user_data->user_login);
|
203 |
$profile = $wpdb->get_row($query, ARRAY_A);
|
204 |
$profile = (array) $profile;
|
205 |
+
if (empty($profile)) {
|
206 |
return;
|
207 |
}
|
208 |
$profile['user_name'] = $wp_user_data->user_login;
|
215 |
|
216 |
public function login() {
|
217 |
ob_start();
|
218 |
+
$auth = SwpmAuth::get_instance();
|
219 |
+
if ($auth->is_logged_in()) {
|
220 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/loggedin.php');
|
221 |
+
} else {
|
222 |
+
$setting = SwpmSettings::get_instance();
|
|
|
223 |
$password_reset_url = $setting->get_value('reset-page-url');
|
224 |
$join_url = $setting->get_value('join-us-page-url');
|
225 |
|
226 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/login.php');
|
|
|
227 |
}
|
228 |
return ob_get_clean();
|
229 |
}
|
230 |
|
231 |
public function reset() {
|
232 |
$succeeded = $this->notices();
|
233 |
+
if ($succeeded) {
|
234 |
return '';
|
235 |
}
|
236 |
ob_start();
|
237 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/forgot_password.php');
|
238 |
return ob_get_clean();
|
239 |
}
|
240 |
+
|
241 |
public function profile_form() {
|
242 |
+
$auth = SwpmAuth::get_instance();
|
243 |
$this->notices();
|
244 |
if ($auth->is_logged_in()) {
|
245 |
$out = apply_filters('swpm_profile_form_override', '');
|
246 |
+
if (!empty($out)) {
|
247 |
+
return $out;
|
248 |
+
}
|
249 |
$user_data = (array) $auth->userData;
|
250 |
$user_data['membership_level_alias'] = $auth->get('alias');
|
251 |
ob_start();
|
253 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/edit.php');
|
254 |
return ob_get_clean();
|
255 |
}
|
256 |
+
return SwpmUtils::_('You are not logged in.');
|
257 |
}
|
258 |
|
259 |
public function notices() {
|
260 |
+
$message = SwpmTransfer::get_instance()->get('status');
|
261 |
$succeeded = false;
|
262 |
+
if (empty($message)) {
|
263 |
+
return false;
|
264 |
+
}
|
265 |
if ($message['succeeded']) {
|
266 |
echo "<div id='message' class='updated'>";
|
267 |
$succeeded = true;
|
268 |
+
} else {
|
269 |
echo "<div id='message' class='error'>";
|
270 |
}
|
271 |
echo $message['message'];
|
272 |
$extra = isset($message['extra']) ? $message['extra'] : array();
|
273 |
+
if (is_string($extra)) {
|
274 |
echo $extra;
|
275 |
+
} else if (is_array($extra)) {
|
|
|
276 |
echo '<ul>';
|
277 |
+
foreach ($extra as $key => $value) {
|
278 |
echo '<li>' . $value . '</li>';
|
279 |
}
|
280 |
echo '</ul>';
|
286 |
public function meta_box() {
|
287 |
if (function_exists('add_meta_box')) {
|
288 |
$post_types = get_post_types();
|
289 |
+
foreach ($post_types as $post_type => $post_type) {
|
290 |
+
add_meta_box('swpm_sectionid', __('Simple WP Membership Protection', 'swpm'), array(&$this, 'inner_custom_box'), $post_type, 'advanced');
|
|
|
|
|
291 |
}
|
292 |
} else {//older version doesn't have custom post type so modification isn't needed.
|
293 |
add_action('dbx_post_advanced', array(&$this, 'show_old_custom_box'));
|
311 |
global $post, $wpdb;
|
312 |
$id = $post->ID;
|
313 |
// Use nonce for verification
|
314 |
+
$is_protected = SwpmProtection::get_instance()->is_protected($id);
|
315 |
echo '<input type="hidden" name="swpm_noncename" id="swpm_noncename" value="' .
|
316 |
wp_create_nonce(plugin_basename(__FILE__)) . '" />';
|
317 |
// The actual fields for data entry
|
318 |
echo '<h4>' . __("Do you want to protect this content?", 'swpm') . '</h4>';
|
319 |
echo '<input type="radio" ' . ((!$is_protected) ? 'checked' : "") .
|
320 |
+
' name="swpm_protect_post" value="1" /> No, Do not protect this content. <br/>';
|
321 |
echo '<input type="radio" ' . (($is_protected) ? 'checked' : "") .
|
322 |
+
' name="swpm_protect_post" value="2" /> Yes, Protect this content.<br/>';
|
323 |
echo '<h4>' . __("Select the membership level that can access this content:", 'swpm') . "</h4>";
|
324 |
$query = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
|
325 |
$levels = $wpdb->get_results($query, ARRAY_A);
|
326 |
foreach ($levels as $level) {
|
327 |
+
echo '<input type="checkbox" ' . (SwpmPermission::get_instance($level['id'])->is_permitted($id) ? "checked='checked'" : "") .
|
328 |
+
' name="swpm_protection_level[' . $level['id'] . ']" value="' . $level['id'] . '" /> ' . $level['alias'] . "<br/>";
|
329 |
}
|
330 |
}
|
331 |
|
332 |
public function save_postdata($post_id) {
|
333 |
global $wpdb;
|
334 |
+
$post_type = filter_input(INPUT_POST, 'post_type');
|
335 |
+
$swpm_protect_post = filter_input(INPUT_POST, 'swpm_protect_post');
|
336 |
$swpm_noncename = filter_input(INPUT_POST, 'swpm_noncename');
|
337 |
+
if (wp_is_post_revision($post_id)) {
|
338 |
return;
|
339 |
}
|
340 |
+
if (!wp_verify_nonce($swpm_noncename, plugin_basename(__FILE__))) {
|
341 |
return $post_id;
|
342 |
}
|
343 |
+
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
|
344 |
return $post_id;
|
345 |
}
|
346 |
+
if ('page' == $post_type) {
|
347 |
+
if (!current_user_can('edit_page', $post_id)) {
|
348 |
return $post_id;
|
349 |
}
|
350 |
} else {
|
351 |
+
if (!current_user_can('edit_post', $post_id)) {
|
352 |
return $post_id;
|
353 |
}
|
354 |
}
|
355 |
+
if (empty($swpm_protect_post)) {
|
356 |
return;
|
357 |
}
|
358 |
// OK, we're authenticated: we need to find and save the data
|
359 |
$isprotected = ($swpm_protect_post == 2);
|
360 |
+
$args = array('swpm_protection_level' => array(
|
361 |
+
'filter' => FILTER_VALIDATE_INT,
|
362 |
+
'flags' => FILTER_REQUIRE_ARRAY,
|
363 |
+
));
|
364 |
$swpm_protection_level = filter_input_array(INPUT_POST, $args);
|
365 |
$swpm_protection_level = $swpm_protection_level['swpm_protection_level'];
|
366 |
if (!empty($post_type)) {
|
367 |
+
if ($isprotected) {
|
368 |
+
SwpmProtection::get_instance()->apply(array($post_id), $post_type);
|
369 |
+
} else {
|
370 |
+
SwpmProtection::get_instance()->remove(array($post_id), $post_type);
|
|
|
371 |
}
|
372 |
+
SwpmProtection::get_instance()->save();
|
373 |
$query = "SELECT id FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
|
374 |
$level_ids = $wpdb->get_col($query);
|
375 |
+
foreach ($level_ids as $level) {
|
376 |
+
if (isset($swpm_protection_level[$level])) {
|
377 |
+
SwpmPermission::get_instance($level)->apply(array($post_id), $post_type)->save();
|
378 |
+
} else {
|
379 |
+
SwpmPermission::get_instance($level)->remove(array($post_id), $post_type)->save();
|
|
|
380 |
}
|
381 |
}
|
382 |
}
|
387 |
}
|
388 |
|
389 |
public function filter_comment($content) {
|
390 |
+
$acl = SwpmAccessControl::get_instance();
|
391 |
global $comment;
|
392 |
return $acl->filter_post($comment->comment_post_ID, $content);
|
393 |
}
|
394 |
|
395 |
public function filter_content($content) {
|
396 |
+
if (is_preview()) {
|
397 |
+
return $content;
|
398 |
+
}
|
399 |
+
$acl = SwpmAccessControl::get_instance();
|
400 |
global $post;
|
401 |
return $acl->filter_post($post->ID, $content);
|
402 |
}
|
403 |
|
404 |
public function filter_moretag($more_link, $more_link_text = "More") {
|
405 |
+
$moretag = SwpmSettings::get_instance()->get_value('enable-moretag');
|
406 |
+
if (empty($moretag)) {
|
407 |
+
return $more_link;
|
408 |
+
}
|
409 |
+
$acl = SwpmAccessControl::get_instance();
|
410 |
global $post;
|
411 |
return $acl->filter_post_with_moretag($post->ID, $more_link, $more_link_text);
|
412 |
}
|
414 |
public function admin_init() {
|
415 |
$createswpmuser = filter_input(INPUT_POST, 'createswpmuser');
|
416 |
if (!empty($createswpmuser)) {
|
417 |
+
SwpmAdminRegistration::get_instance()->register();
|
418 |
}
|
419 |
$editswpmuser = filter_input(INPUT_POST, 'editswpmuser');
|
420 |
if (!empty($editswpmuser)) {
|
421 |
$id = filter_input(INPUT_GET, 'member_id', FILTER_VALIDATE_INT);
|
422 |
+
SwpmAdminRegistration::get_instance()->edit($id);
|
423 |
}
|
424 |
$createswpmlevel = filter_input(INPUT_POST, 'createswpmlevel');
|
425 |
if (!empty($createswpmlevel)) {
|
426 |
+
SwpmMembershipLevel::get_instance()->create();
|
427 |
}
|
428 |
$editswpmlevel = filter_input(INPUT_POST, 'editswpmlevel');
|
429 |
if (!empty($editswpmlevel)) {
|
430 |
$id = filter_input(INPUT_GET, 'id');
|
431 |
+
SwpmMembershipLevel::get_instance()->edit($id);
|
432 |
}
|
433 |
}
|
434 |
|
436 |
|
437 |
//Set up localisation. First loaded ones will override strings present in later loaded file.
|
438 |
//Allows users to have a customized language in a different folder.
|
439 |
+
$locale = apply_filters('plugin_locale', get_locale(), 'swpm');
|
440 |
+
load_textdomain('swpm', WP_LANG_DIR . "/swpm-$locale.mo");
|
441 |
+
load_plugin_textdomain('swpm', false, SIMPLE_WP_MEMBERSHIP_DIRNAME . '/languages/');
|
442 |
|
443 |
if (!isset($_COOKIE['swpm_session'])) { // give a unique ID to current session.
|
444 |
$uid = md5(microtime());
|
446 |
setcookie('swpm_session', $uid, 0, '/');
|
447 |
}
|
448 |
|
449 |
+
if (current_user_can('manage_options')) { // admin stuff
|
450 |
$this->admin_init();
|
451 |
}
|
452 |
+
if (!is_admin()) { //frontend stuff
|
453 |
+
SwpmAuth::get_instance();
|
454 |
$this->verify_and_delete_account();
|
455 |
$swpm_logout = filter_input(INPUT_GET, 'swpm-logout');
|
456 |
if (!empty($swpm_logout)) {
|
457 |
+
SwpmAuth::get_instance()->logout();
|
458 |
wp_redirect(home_url());
|
459 |
}
|
460 |
$this->process_password_reset();
|
467 |
public function swpm_ipn_listener() {
|
468 |
$swpm_process_ipn = filter_input(INPUT_GET, 'swpm_process_ipn');
|
469 |
if ($swpm_process_ipn == '1') {
|
470 |
+
include(SIMPLE_WP_MEMBERSHIP_PATH . 'ipn/swpm_handle_pp_ipn.php');
|
471 |
exit;
|
472 |
}
|
473 |
}
|
477 |
$swpm_reset = filter_input(INPUT_POST, 'swpm-reset');
|
478 |
$swpm_reset_email = filter_input(INPUT_POST, 'swpm_reset_email', FILTER_UNSAFE_RAW);
|
479 |
if (!empty($swpm_reset)) {
|
480 |
+
SwpmFrontRegistration::get_instance()->reset_password($swpm_reset_email);
|
481 |
}
|
482 |
}
|
483 |
|
484 |
private function edit_profile() {
|
485 |
+
$swpm_editprofile_submit = filter_input(INPUT_POST, 'swpm_editprofile_submit');
|
486 |
if (!empty($swpm_editprofile_submit)) {
|
487 |
+
SwpmFrontRegistration::get_instance()->edit();
|
488 |
//todo: do a redirect
|
489 |
}
|
490 |
}
|
494 |
wp_enqueue_script('password-strength-meter');
|
495 |
wp_enqueue_script('swpm.password-meter', SIMPLE_WP_MEMBERSHIP_URL . '/js/swpm.password-meter.js');
|
496 |
wp_enqueue_style('jquery.tools.dateinput', SIMPLE_WP_MEMBERSHIP_URL . '/css/jquery.tools.dateinput.css');
|
497 |
+
wp_enqueue_script('jquery.tools', SIMPLE_WP_MEMBERSHIP_URL . '/js/jquery.tools18.min.js');
|
498 |
+
$settings = array('statusChangeEmailHead' => SwpmSettings::get_instance()->get_value('account-change-email-subject'),
|
499 |
+
'statusChangeEmailBody' => SwpmSettings::get_instance()->get_value('account-change-email-body'));
|
500 |
+
wp_localize_script('swpm.password-meter', 'SwpmSettings', $settings);
|
501 |
}
|
502 |
|
503 |
public function front_library() {
|
514 |
|
515 |
public function registration_form($atts) {
|
516 |
$succeeded = $this->notices();
|
517 |
+
if ($succeeded) {
|
518 |
return;
|
519 |
}
|
520 |
+
$is_free = SwpmSettings::get_instance()->get_value('enable-free-membership');
|
521 |
+
$free_level = absint(SwpmSettings::get_instance()->get_value('free-membership-id'));
|
522 |
+
$level = isset($atts['level']) ? absint($atts['level']) : ($is_free ? $free_level : null);
|
523 |
+
return SwpmFrontRegistration::get_instance()->regigstration_ui($level);
|
524 |
}
|
525 |
|
526 |
private function register_member() {
|
527 |
$registration = filter_input(INPUT_POST, 'swpm_registration_submit');
|
528 |
if (!empty($registration)) {
|
529 |
+
SwpmFrontRegistration::get_instance()->register();
|
530 |
}
|
531 |
}
|
532 |
|
536 |
add_menu_page(__("WP Membership", 'swpm'), __("WP Membership", 'swpm')
|
537 |
, 'manage_options', $menu_parent_slug, array(&$this, "admin_members")
|
538 |
, SIMPLE_WP_MEMBERSHIP_URL . '/images/logo.png');
|
539 |
+
add_submenu_page($menu_parent_slug, __("Members", 'swpm'), __('Members', 'swpm'), 'manage_options', 'simple_wp_membership', array(&$this, "admin_members"));
|
540 |
+
add_submenu_page($menu_parent_slug, __("Membership Levels", 'swpm'), __("Membership Levels", 'swpm'), 'manage_options', 'simple_wp_membership_levels', array(&$this, "admin_membership_levels"));
|
541 |
+
add_submenu_page($menu_parent_slug, __("Settings", 'swpm'), __("Settings", 'swpm'), 'manage_options', 'simple_wp_membership_settings', array(&$this, "admin_settings"));
|
542 |
+
add_submenu_page($menu_parent_slug, __("Payments", 'swpm'), __("Payments", 'swpm'), 'manage_options', 'simple_wp_membership_payments', array(&$this, "payments_menu"));
|
543 |
+
add_submenu_page($menu_parent_slug, __("Add-ons", 'swpm'), __("Add-ons", 'swpm'), 'manage_options', 'simple_wp_membership_addons', array(&$this, "add_ons_menu"));
|
544 |
+
|
|
|
|
|
|
|
|
|
|
|
545 |
do_action('swpm_after_main_admin_menu', $menu_parent_slug);
|
546 |
|
547 |
$this->meta_box();
|
548 |
}
|
549 |
|
550 |
public function admin_membership_levels() {
|
551 |
+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'classes/class.swpm-membership-levels.php');
|
552 |
+
$levels = new SwpmMembershipLevels();
|
553 |
$level_action = filter_input(INPUT_GET, 'level_action');
|
554 |
$action2 = filter_input(INPUT_GET, 'action2');
|
555 |
$action = $level_action ? $level_action : ($action2 ? $action2 : "");
|
574 |
}
|
575 |
|
576 |
public function admin_members() {
|
577 |
+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'classes/class.swpm-members.php');
|
578 |
+
$members = new SwpmMembers();
|
579 |
$action = filter_input(INPUT_GET, 'member_action');
|
580 |
+
$action = empty($action) ? filter_input(INPUT_POST, 'action') : $action;
|
581 |
switch ($action) {
|
582 |
case 'add':
|
583 |
case 'edit':
|
593 |
}
|
594 |
|
595 |
public function admin_settings() {
|
596 |
+
$current_tab = SwpmSettings::get_instance()->current_tab;
|
597 |
switch ($current_tab) {
|
598 |
case 6:
|
599 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_addon_settings.php');
|
600 |
+
break;
|
601 |
case 4:
|
602 |
+
$link_for = filter_input(INPUT_POST, 'swpm_link_for', FILTER_SANITIZE_STRING);
|
603 |
+
$member_id = filter_input(INPUT_POST, 'member_id', FILTER_SANITIZE_NUMBER_INT);
|
604 |
+
$send_email = filter_input(INPUT_POST, 'swpm_reminder_email', FILTER_SANITIZE_NUMBER_INT);
|
605 |
+
$links = SwpmUtils::get_registration_link($link_for, $send_email, $member_id);
|
606 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_tools_settings.php');
|
607 |
break;
|
608 |
case 2:
|
613 |
break;
|
614 |
}
|
615 |
}
|
616 |
+
|
617 |
+
public function payments_menu() {
|
618 |
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_payments_page.php');
|
619 |
}
|
620 |
+
|
621 |
+
public function add_ons_menu() {
|
622 |
+
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_add_ons_page.php');
|
623 |
}
|
624 |
|
625 |
+
public function plugins_loaded() {
|
626 |
//Runs when plugins_loaded action gets fired
|
627 |
+
if (is_admin()) {
|
628 |
//Check and run DB upgrade operation (if needed)
|
629 |
if (get_option('swpm_db_version') != SIMPLE_WP_MEMBERSHIP_DB_VER) {
|
630 |
+
include_once('class.swpm-installation.php');
|
631 |
+
SwpmInstallation::run_safe_installer();
|
632 |
}
|
633 |
+
}
|
634 |
}
|
635 |
+
|
636 |
public static function activate() {
|
637 |
wp_schedule_event(time(), 'daily', 'swpm_account_status_event');
|
638 |
wp_schedule_event(time(), 'daily', 'swpm_delete_pending_account_event');
|
639 |
+
include_once('class.swpm-installation.php');
|
640 |
+
SwpmInstallation::run_safe_installer();
|
641 |
}
|
642 |
+
|
643 |
public function deactivate() {
|
644 |
wp_clear_scheduled_hook('swpm_account_status_event');
|
645 |
+
wp_clear_scheduled_hook('swpm_delete_pending_account_event');
|
646 |
}
|
647 |
+
|
648 |
+
private function verify_and_delete_account() {
|
649 |
+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'classes/class.swpm-members.php');
|
650 |
$delete_account = filter_input(INPUT_GET, 'delete_account');
|
651 |
+
if (empty($delete_account)) {
|
652 |
+
return;
|
653 |
+
}
|
654 |
+
$password = filter_input(INPUT_POST, 'account_delete_confirm_pass', FILTER_UNSAFE_RAW);
|
655 |
|
656 |
+
$auth = SwpmAuth::get_instance();
|
657 |
+
if (!$auth->is_logged_in()) {
|
658 |
+
return;
|
659 |
+
}
|
660 |
+
if (empty($password)) {
|
661 |
+
SwpmUtils::account_delete_confirmation_ui();
|
662 |
}
|
663 |
+
|
664 |
$nonce_field = filter_input(INPUT_POST, 'account_delete_confirm_nonce');
|
665 |
+
if (empty($nonce_field) || !wp_verify_nonce($nonce_field, 'swpm_account_delete_confirm')) {
|
666 |
+
SwpmUtils::account_delete_confirmation_ui(SwpmUtils::_("Sorry, Nonce verification failed."));
|
667 |
+
}
|
668 |
+
if ($auth->match_password($password)) {
|
669 |
$auth->delete();
|
670 |
wp_redirect(home_url());
|
671 |
+
} else {
|
672 |
+
SwpmUtils::account_delete_confirmation_ui(SwpmUtils::_("Sorry, Password didn't match."));
|
|
|
673 |
}
|
674 |
}
|
675 |
+
|
676 |
}
|
classes/class.swpm-access-control.php
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class SwpmAccessControl {
|
3 |
+
private $lastError;
|
4 |
+
private $moretags;
|
5 |
+
private static $_this;
|
6 |
+
private function __construct(){
|
7 |
+
$this->lastError = '';
|
8 |
+
$this->moretags = array();
|
9 |
+
}
|
10 |
+
public static function get_instance(){
|
11 |
+
self::$_this = empty(self::$_this)? new SwpmAccessControl():self::$_this;
|
12 |
+
return self::$_this;
|
13 |
+
}
|
14 |
+
|
15 |
+
public function can_i_read_post($id){
|
16 |
+
$this->lastError = '';
|
17 |
+
global $post;
|
18 |
+
$auth = SwpmAuth::get_instance();
|
19 |
+
$protect_everything = SwpmSettings::get_instance()->get_value('protect-everything');
|
20 |
+
if(!empty($protect_everything)){
|
21 |
+
$error_msg = SwpmUtils::_( 'You need to login to view this content. ' ) . SwpmSettings::get_instance()->get_login_link();
|
22 |
+
$this->lastError = apply_filters('swpm_not_logged_in_post_msg', $error_msg);
|
23 |
+
return false;
|
24 |
+
}
|
25 |
+
$protected = SwpmProtection::get_instance();
|
26 |
+
if (!$protected->is_protected($id)){ return true;}
|
27 |
+
if(!$auth->is_logged_in()){
|
28 |
+
$error_msg = SwpmUtils::_( 'You need to login to view this content. ' ) . SwpmSettings::get_instance()->get_login_link();
|
29 |
+
$this->lastError = apply_filters('swpm_not_logged_in_post_msg', $error_msg);
|
30 |
+
return false;
|
31 |
+
}
|
32 |
+
|
33 |
+
if ($auth->is_expired_account()){
|
34 |
+
$error_msg = '<div class="swpm-account-expired-msg swpm-yellow-box">'.SwpmUtils::_('Your account has expired. Please renew your account to gain access to this content.').'</div>';
|
35 |
+
$this->lastError = apply_filters('swpm_account_expired_msg', $error_msg);
|
36 |
+
return false;
|
37 |
+
}
|
38 |
+
$protect_older_posts = apply_filters('swpm_should_protect_older_post', false, $id);
|
39 |
+
if ($protect_older_posts){
|
40 |
+
$this->lastError = apply_filters ('swpm_restricted_post_msg_older_post',
|
41 |
+
SwpmUtils::_('This content can only be viewed by members who joined on or before ' . date(get_option( 'date_format' ), strtotime($post->post_date)))) ;
|
42 |
+
return false;
|
43 |
+
}
|
44 |
+
$perms = SwpmPermission::get_instance($auth->get('membership_level'));
|
45 |
+
if($perms->is_permitted($id)) {return true;}
|
46 |
+
$this->lastError = apply_filters ('swpm_restricted_post_msg', '<div class="swpm-no-access-msg">'.SwpmUtils::_('This content is not permitted for your membership level.').'</div>') ;
|
47 |
+
return false;
|
48 |
+
}
|
49 |
+
public function can_i_read_comment($id){
|
50 |
+
$this->lastError = '';
|
51 |
+
$protected = SwpmProtection::get_instance();
|
52 |
+
if (!$protected->is_protected_comment($id)){ return true;}
|
53 |
+
$auth = SwpmAuth::get_instance();
|
54 |
+
if(!$auth->is_logged_in()){
|
55 |
+
$this->lastError = apply_filters('swpm_not_logged_in_comment_msg', SwpmUtils::_("You need to login to view this content. ")
|
56 |
+
. SwpmSettings::get_instance()->get_login_link());
|
57 |
+
return false;
|
58 |
+
}
|
59 |
+
if ($auth->is_expired_account()){
|
60 |
+
$error_msg = '<div class="swpm-account-expired-msg swpm-yellow-box">'.SwpmUtils::_('Your account has expired. Please renew your account to gain access to this content.').'</div>';
|
61 |
+
$this->lastError = apply_filters('swpm_account_expired_msg', $error_msg);
|
62 |
+
return false;
|
63 |
+
}
|
64 |
+
$perms = SwpmPermission::get_instance($auth->get('membership_level'));
|
65 |
+
if($perms->is_permitted_comment($id)) {return true; }
|
66 |
+
$this->lastError = apply_filters ('swpm_restricted_comment_msg', '<div class="swpm-no-access-msg">'.SwpmUtils::_("This content is not permitted for your membership level.").'</div>' );
|
67 |
+
return false;
|
68 |
+
}
|
69 |
+
public function why(){
|
70 |
+
return $this->lastError;
|
71 |
+
}
|
72 |
+
public function filter_post($id,$content){
|
73 |
+
if(in_array($id, $this->moretags)) {return $content; }
|
74 |
+
if($this->can_i_read_post($id)) {return $content; }
|
75 |
+
$moretag = SwpmSettings::get_instance()->get_value('enable-moretag');
|
76 |
+
if (empty($moretag)){
|
77 |
+
return $this->lastError;
|
78 |
+
}
|
79 |
+
$post = get_post($id);
|
80 |
+
$post_segments = explode( '<!--more-->', $post->post_content);
|
81 |
+
|
82 |
+
if (count($post_segments) >= 2){
|
83 |
+
if (SwpmAuth::get_instance()->is_logged_in()){
|
84 |
+
$error_msg = '<div class="swpm-margin-top-10">' . SwpmUtils::_(" The rest of the content is not permitted for your membership level.") . '</div>';
|
85 |
+
$this->lastError = apply_filters ('swpm_restricted_more_tag_msg', $error_msg);
|
86 |
+
}
|
87 |
+
else {
|
88 |
+
$error_msg = '<div class="swpm-margin-top-10">' . SwpmUtils::_("You need to login to view the rest of the content. ") . SwpmSettings::get_instance()->get_login_link() . '</div>';
|
89 |
+
$this->lastError = apply_filters('swpm_not_logged_in_more_tag_msg', $error_msg);
|
90 |
+
}
|
91 |
+
|
92 |
+
return do_shortcode($post_segments[0]) . $this->lastError;
|
93 |
+
}
|
94 |
+
|
95 |
+
return $this->lastError;
|
96 |
+
}
|
97 |
+
public function filter_comment($id,$content){
|
98 |
+
if($this->can_i_read_comment($id)) { return $content; }
|
99 |
+
return $this->lastError;
|
100 |
+
}
|
101 |
+
public function filter_post_with_moretag($id, $more_link, $more_link_text){
|
102 |
+
$this->moretags[] = $id;
|
103 |
+
if($this->can_i_read_post($id)) {
|
104 |
+
return $more_link;
|
105 |
+
}
|
106 |
+
$msg = SwpmUtils::_("You need to login to view the rest of the content. ") . SwpmSettings::get_instance()->get_login_link();
|
107 |
+
return apply_filters('swpm_not_logged_in_more_tag_msg', $msg);
|
108 |
+
}
|
109 |
+
}
|
classes/class.swpm-admin-registration.php
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Description of BAdminRegistration
|
5 |
+
*
|
6 |
+
*/
|
7 |
+
class SwpmAdminRegistration extends SwpmRegistration {
|
8 |
+
public static function get_instance(){
|
9 |
+
self::$_intance = empty(self::$_intance)? new SwpmAdminRegistration():self::$_intance;
|
10 |
+
return self::$_intance;
|
11 |
+
}
|
12 |
+
public function show_form() {
|
13 |
+
|
14 |
+
}
|
15 |
+
|
16 |
+
public function register() {
|
17 |
+
global $wpdb;
|
18 |
+
$member = SwpmTransfer::$default_fields;
|
19 |
+
$form = new SwpmForm($member);
|
20 |
+
if ($form->is_valid()) {
|
21 |
+
$member_info = $form->get_sanitized();
|
22 |
+
$account_status = SwpmSettings::get_instance()->get_value('default-account-status', 'active');
|
23 |
+
$member_info['account_state'] = $account_status;
|
24 |
+
$plain_password = $member_info['plain_password'];
|
25 |
+
unset($member_info['plain_password']);
|
26 |
+
$wpdb->insert($wpdb->prefix . "swpm_members_tbl", $member_info);
|
27 |
+
/* * ******************** register to wordpress ********** */
|
28 |
+
$query = $wpdb->prepare("SELECT role FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id = %d", $member_info['membership_level']) ;
|
29 |
+
$wp_user_info = array();
|
30 |
+
$wp_user_info['user_nicename'] = implode('-', explode(' ', $member_info['user_name']));
|
31 |
+
$wp_user_info['display_name'] = $member_info['user_name'];
|
32 |
+
$wp_user_info['user_email'] = $member_info['email'];
|
33 |
+
$wp_user_info['nickname'] = $member_info['user_name'];
|
34 |
+
if (isset($member_info['first_name'])){$wp_user_info['first_name'] = $member_info['first_name']; }
|
35 |
+
if (isset($member_info['last_name'])){$wp_user_info['last_name'] = $member_info['last_name'];}
|
36 |
+
$wp_user_info['user_login'] = $member_info['user_name'];
|
37 |
+
$wp_user_info['password'] = $plain_password;
|
38 |
+
$wp_user_info['role'] = $wpdb->get_var($query);
|
39 |
+
$wp_user_info['user_registered'] = date('Y-m-d H:i:s');
|
40 |
+
SwpmUtils::create_wp_user($wp_user_info);
|
41 |
+
/* * ******************** register to wordpress ********** */
|
42 |
+
$send_notification = SwpmSettings::get_instance()->get_value('enable-notification-after-manual-user-add');
|
43 |
+
$member_info['plain_password'] = $plain_password;
|
44 |
+
$this->member_info = $member_info;
|
45 |
+
if (!empty($send_notification)){
|
46 |
+
$this->send_reg_email();
|
47 |
+
}
|
48 |
+
$message = array('succeeded' => true, 'message' => SwpmUtils::_('Registration Successful.'));
|
49 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
50 |
+
wp_redirect('admin.php?page=simple_wp_membership');
|
51 |
+
return;
|
52 |
+
}
|
53 |
+
$message = array('succeeded' => false, 'message' => SwpmUtils::_('Please correct the following:'), 'extra' => $form->get_errors());
|
54 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
55 |
+
}
|
56 |
+
public function edit($id){
|
57 |
+
global $wpdb;
|
58 |
+
$query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE member_id = %d", $id);
|
59 |
+
$member = $wpdb->get_row($query, ARRAY_A);
|
60 |
+
$email_address = $member['email'];
|
61 |
+
$user_name = $member['user_name'];
|
62 |
+
unset($member['member_id']);
|
63 |
+
unset($member['user_name']);
|
64 |
+
$form = new SwpmForm($member);
|
65 |
+
if ($form->is_valid()) {
|
66 |
+
$member = $form->get_sanitized();
|
67 |
+
SwpmUtils::update_wp_user($user_name, $member);
|
68 |
+
unset($member['plain_password']);
|
69 |
+
$wpdb->update($wpdb->prefix . "swpm_members_tbl", $member, array('member_id' => $id));
|
70 |
+
$message = array('succeeded' => true, 'message' => 'Updated Successfully.');
|
71 |
+
do_action('swpm_admin_edit_custom_fields', $member + array('member_id'=>$id));
|
72 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
73 |
+
$send_notification = filter_input(INPUT_POST, 'account_status_change');
|
74 |
+
if (!empty($send_notification)){
|
75 |
+
$settings = SwpmSettings::get_instance();
|
76 |
+
$from_address = $settings->get_value('email-from');
|
77 |
+
$headers = 'From: ' . $from_address . "\r\n";
|
78 |
+
$subject = filter_input(INPUT_POST,'notificationmailhead');
|
79 |
+
$body = filter_input(INPUT_POST, 'notificationmailbody');
|
80 |
+
$settings->set_value('account-change-email-body', $body)->set_value('account-change-email-subject', $subject)->save();
|
81 |
+
$member['login_link'] = $settings->get_value('login-page-url');
|
82 |
+
$values = array_values($member);
|
83 |
+
$keys = array_map('swpm_enclose_var', array_keys($member));
|
84 |
+
$body = str_replace($keys, $values, $body);
|
85 |
+
wp_mail($email_address, $subject, $body, $headers);
|
86 |
+
}
|
87 |
+
wp_redirect('admin.php?page=simple_wp_membership');
|
88 |
+
}
|
89 |
+
$message = array('succeeded' => false, 'message' => SwpmUtils::_('Please correct the following:'), 'extra' => $form->get_errors());
|
90 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
91 |
+
}
|
92 |
+
}
|
classes/class.swpm-ajax.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Description of BAjax
|
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');
|
11 |
+
$field_id = filter_input(INPUT_GET, 'fieldId');
|
12 |
+
$member_id = filter_input(INPUT_GET, 'member_id');
|
13 |
+
if (!is_email($field_value)){
|
14 |
+
echo '[ "' . $field_id . '",false, "'.SwpmUtils::_('Invalid Email Address').'" ]' ;
|
15 |
+
exit;
|
16 |
+
}
|
17 |
+
$table = $wpdb->prefix . "swpm_members_tbl";
|
18 |
+
$query = $wpdb->prepare("SELECT member_id FROM $table WHERE email = %s", $field_value);
|
19 |
+
$db_id = $wpdb->get_var($query) ;
|
20 |
+
$exists = ($db_id > 0) && $db_id != $member_id;
|
21 |
+
echo '[ "' . $field_id . (($exists) ? '",false, "χ '.SwpmUtils::_('Aready taken').'"]' : '",true, "√ Available"]');
|
22 |
+
exit;
|
23 |
+
}
|
24 |
+
|
25 |
+
public static function validate_user_name_ajax() {
|
26 |
+
global $wpdb;
|
27 |
+
$field_value = filter_input(INPUT_GET, 'fieldValue');
|
28 |
+
$field_id = filter_input(INPUT_GET, 'fieldId');
|
29 |
+
$table = $wpdb->prefix . "swpm_members_tbl";
|
30 |
+
$query = $wpdb->prepare("SELECT COUNT(*) FROM $table WHERE user_name = %s", $field_value);
|
31 |
+
$exists = $wpdb->get_var($query) > 0;
|
32 |
+
echo '[ "' . $field_id . (($exists) ? '",false,"χ '. SwpmUtils::_('Aready taken'). '"]' :
|
33 |
+
'",true,"√ '.SwpmUtils::_('Available'). '"]');
|
34 |
+
exit;
|
35 |
+
}
|
36 |
+
}
|
classes/class.swpm-auth-permission-collection.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Description of BAuthPermissionCollection
|
4 |
+
*
|
5 |
+
* @author nur
|
6 |
+
*/
|
7 |
+
class SwpmAuthPermissionCollection extends SwpmPermissionCollection{
|
8 |
+
//put your code here
|
9 |
+
}
|
classes/class.swpm-auth.php
ADDED
@@ -0,0 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
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 |
+
$this->isLoggedIn = false;
|
14 |
+
$this->userData = null;
|
15 |
+
$this->protected = SwpmProtection::get_instance();
|
16 |
+
}
|
17 |
+
private function init(){
|
18 |
+
$valid = $this->validate();
|
19 |
+
//Blog::log_simple_debug("init:". ($valid? "valid": "invalid"), true);
|
20 |
+
if (!$valid){
|
21 |
+
$this->authenticate();
|
22 |
+
}
|
23 |
+
}
|
24 |
+
public static function get_instance() {
|
25 |
+
if (empty(self::$_this)){
|
26 |
+
self::$_this = new SwpmAuth();
|
27 |
+
self::$_this->init();
|
28 |
+
}
|
29 |
+
return self::$_this;
|
30 |
+
}
|
31 |
+
|
32 |
+
private function authenticate($user = null, $pass = null) {
|
33 |
+
global $wpdb;
|
34 |
+
$swpm_password = empty($pass)?filter_input(INPUT_POST, 'swpm_password') : $pass;
|
35 |
+
$swpm_user_name = empty($user)? apply_filters('swpm_user_name', filter_input(INPUT_POST, 'swpm_user_name')) : $user;
|
36 |
+
//Blog::log_simple_debug("Authenticate:" . $swpm_user_name, true);
|
37 |
+
if (!empty($swpm_user_name) && !empty($swpm_password)) {
|
38 |
+
$user = sanitize_user($swpm_user_name);
|
39 |
+
$pass = trim($swpm_password);
|
40 |
+
$query = "SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE user_name = %s";
|
41 |
+
$userData = $wpdb->get_row($wpdb->prepare($query, $user));
|
42 |
+
$this->userData = $userData;
|
43 |
+
if (!$userData) {
|
44 |
+
$this->isLoggedIn = false;
|
45 |
+
$this->userData = null;
|
46 |
+
$this->lastStatusMsg = SwpmUtils::_("User Not Found.");
|
47 |
+
return false;
|
48 |
+
}
|
49 |
+
$check = $this->check_password($pass, $userData->password);
|
50 |
+
if (!$check) {
|
51 |
+
$this->isLoggedIn = false;
|
52 |
+
$this->userData = null;
|
53 |
+
$this->lastStatusMsg = SwpmUtils::_("Password Empty or Invalid.");
|
54 |
+
return false;
|
55 |
+
}
|
56 |
+
if ($this->check_constraints()) {
|
57 |
+
$rememberme = filter_input(INPUT_POST, 'rememberme');
|
58 |
+
$remember = empty($rememberme) ? false : true;
|
59 |
+
$this->set_cookie($remember);
|
60 |
+
$this->isLoggedIn = true;
|
61 |
+
$this->lastStatusMsg = "Logged In.";
|
62 |
+
SwpmLog::log_simple_debug("swpm_login action.", true);
|
63 |
+
do_action('swpm_login', $user, $pass, $remember);
|
64 |
+
return true;
|
65 |
+
}
|
66 |
+
}
|
67 |
+
return false;
|
68 |
+
}
|
69 |
+
|
70 |
+
private function check_constraints() {
|
71 |
+
if (empty($this->userData)){
|
72 |
+
return false;
|
73 |
+
}
|
74 |
+
$enable_expired_login = SwpmSettings::get_instance()->get_value('enable-expired-account-login', '');
|
75 |
+
|
76 |
+
$can_login = true;
|
77 |
+
if( $this->userData->account_state == 'inactive'){
|
78 |
+
$this->lastStatusMsg = SwpmUtils::_('Account is inactive.');
|
79 |
+
$can_login = false;
|
80 |
+
}
|
81 |
+
else if( $this->userData->account_state == 'pending'){
|
82 |
+
$this->lastStatusMsg = SwpmUtils::_('Account is pending.');
|
83 |
+
$can_login = false;
|
84 |
+
}
|
85 |
+
else if( ($this->userData->account_state == 'expired') && empty($enable_expired_login) ){
|
86 |
+
$this->lastStatusMsg = SwpmUtils::_('Account has expired.');
|
87 |
+
$can_login = false;
|
88 |
+
}
|
89 |
+
|
90 |
+
if(!$can_login){
|
91 |
+
$this->isLoggedIn = false;
|
92 |
+
$this->userData = null;
|
93 |
+
return false;
|
94 |
+
}
|
95 |
+
|
96 |
+
if (SwpmUtils::is_subscription_expired($this->userData)){
|
97 |
+
if ($this->userData->account_state == 'active'){
|
98 |
+
global $wpdb;
|
99 |
+
$wpdb->update(
|
100 |
+
$wpdb->prefix . 'swpm_members_tbl',
|
101 |
+
array( 'account_state' => 'expired'),
|
102 |
+
array( 'member_id' => $this->userData->member_id ),
|
103 |
+
array( '%s'),
|
104 |
+
array( '%d' )
|
105 |
+
);
|
106 |
+
}
|
107 |
+
if (empty($enable_expired_login)){
|
108 |
+
$this->lastStatusMsg = SwpmUtils::_('Account has expired.');
|
109 |
+
$this->isLoggedIn = false;
|
110 |
+
$this->userData = null;
|
111 |
+
return false;
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
$this->permitted = SwpmPermission::get_instance($this->userData->membership_level);
|
116 |
+
$this->lastStatusMsg = SwpmUtils::_("You are logged in as:") . $this->userData->user_name;
|
117 |
+
$this->isLoggedIn = true;
|
118 |
+
return true;
|
119 |
+
}
|
120 |
+
|
121 |
+
private function check_password($password, $hash) {
|
122 |
+
global $wp_hasher;
|
123 |
+
if (empty($password)){
|
124 |
+
return false;
|
125 |
+
}
|
126 |
+
if (empty($wp_hasher)) {
|
127 |
+
require_once( ABSPATH . 'wp-includes/class-phpass.php');
|
128 |
+
$wp_hasher = new PasswordHash(8, TRUE);
|
129 |
+
}
|
130 |
+
return $wp_hasher->CheckPassword($password, $hash);
|
131 |
+
}
|
132 |
+
public function match_password($password){
|
133 |
+
if (!$this->is_logged_in()) {return false;}
|
134 |
+
return $this->check_password($password, $this->get('password'));
|
135 |
+
}
|
136 |
+
public function login($user, $pass, $remember = '', $secure = '') {
|
137 |
+
SwpmLog::log_simple_debug("login",true);
|
138 |
+
if ($this->isLoggedIn){
|
139 |
+
return;
|
140 |
+
}
|
141 |
+
if ($this->authenticate($user, $pass) && $this->validate()) {
|
142 |
+
$this->set_cookie($remember, $secure);
|
143 |
+
} else {
|
144 |
+
$this->isLoggedIn = false;
|
145 |
+
$this->userData = null;
|
146 |
+
}
|
147 |
+
return $this->lastStatusMsg;
|
148 |
+
}
|
149 |
+
|
150 |
+
public function logout() {
|
151 |
+
if (!$this->isLoggedIn){
|
152 |
+
return;
|
153 |
+
}
|
154 |
+
setcookie(SIMPLE_WP_MEMBERSHIP_AUTH, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN);
|
155 |
+
setcookie(SIMPLE_WP_MEMBERSHIP_SEC_AUTH, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN);
|
156 |
+
$this->userData = null;
|
157 |
+
$this->isLoggedIn = false;
|
158 |
+
$this->lastStatusMsg = SwpmUtils::_("Logged Out Successfully.");
|
159 |
+
do_action('swpm_logout');
|
160 |
+
}
|
161 |
+
|
162 |
+
private function set_cookie($remember = '', $secure = '') {
|
163 |
+
if ($remember){
|
164 |
+
$expiration = time() + 1209600; // 14 days
|
165 |
+
$expire = $expiration + 43200; // 12 hours grace period
|
166 |
+
}
|
167 |
+
else{
|
168 |
+
$expiration = time() + 172800; // 2 days.
|
169 |
+
$expire = $expiration;//The minimum cookie expiration should be at least couple of days.
|
170 |
+
}
|
171 |
+
|
172 |
+
$expiration_timestamp = SwpmUtils::get_expiration_timestamp($this->userData);
|
173 |
+
$enable_expired_login = SwpmSettings::get_instance()->get_value('enable-expired-account-login', '');
|
174 |
+
// make sure cookie doesn't live beyond account expiration date.
|
175 |
+
// but if expired account login is enabled then ignore if account is expired
|
176 |
+
$expiration = empty($enable_expired_login)? min ($expiration,$expiration_timestamp) : $expiration;
|
177 |
+
$pass_frag = substr($this->userData->password, 8, 4);
|
178 |
+
$scheme = 'auth';
|
179 |
+
if (!$secure){
|
180 |
+
$secure = is_ssl();
|
181 |
+
}
|
182 |
+
$key = SwpmAuth::b_hash($this->userData->user_name . $pass_frag . '|' . $expiration, $scheme);
|
183 |
+
$hash = hash_hmac('md5', $this->userData->user_name . '|' . $expiration, $key);
|
184 |
+
$auth_cookie = $this->userData->user_name . '|' . $expiration . '|' . $hash;
|
185 |
+
$auth_cookie_name = $secure ? SIMPLE_WP_MEMBERSHIP_SEC_AUTH : SIMPLE_WP_MEMBERSHIP_AUTH;
|
186 |
+
//setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true);
|
187 |
+
setcookie($auth_cookie_name, $auth_cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure, true);
|
188 |
+
}
|
189 |
+
|
190 |
+
private function validate() {
|
191 |
+
$auth_cookie_name = is_ssl() ? SIMPLE_WP_MEMBERSHIP_SEC_AUTH : SIMPLE_WP_MEMBERSHIP_AUTH;
|
192 |
+
if (!isset($_COOKIE[$auth_cookie_name]) || empty($_COOKIE[$auth_cookie_name])){
|
193 |
+
return false;
|
194 |
+
}
|
195 |
+
$cookie_elements = explode('|', $_COOKIE[$auth_cookie_name]);
|
196 |
+
if (count($cookie_elements) != 3){
|
197 |
+
return false;
|
198 |
+
}
|
199 |
+
SwpmLog::log_simple_debug("validate:" . $_COOKIE[$auth_cookie_name],true);
|
200 |
+
list($username, $expiration, $hmac) = $cookie_elements;
|
201 |
+
$expired = $expiration;
|
202 |
+
// Allow a grace period for POST and AJAX requests
|
203 |
+
if (defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD']){
|
204 |
+
$expired += HOUR_IN_SECONDS;
|
205 |
+
}
|
206 |
+
// Quick check to see if an honest cookie has expired
|
207 |
+
if ($expired < time()) {
|
208 |
+
$this->lastStatusMsg = SwpmUtils::_("Session Expired."); //do_action('auth_cookie_expired', $cookie_elements);
|
209 |
+
return false;
|
210 |
+
}
|
211 |
+
SwpmLog::log_simple_debug("validate:Session Expired",true);
|
212 |
+
global $wpdb;
|
213 |
+
$query = " SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE user_name = %s";
|
214 |
+
$user = $wpdb->get_row($wpdb->prepare($query, $username));
|
215 |
+
if (empty($user)) {
|
216 |
+
$this->lastStatusMsg = SwpmUtils::_("Invalid User Name");
|
217 |
+
return false;
|
218 |
+
}
|
219 |
+
SwpmLog::log_simple_debug("validate:Invalid User Name:" . serialize($user),true);
|
220 |
+
$pass_frag = substr($user->password, 8, 4);
|
221 |
+
$key = SwpmAuth::b_hash($username . $pass_frag . '|' . $expiration);
|
222 |
+
$hash = hash_hmac('md5', $username . '|' . $expiration, $key);
|
223 |
+
if ($hmac != $hash) {
|
224 |
+
$this->lastStatusMsg = SwpmUtils::_("Sorry! Something went wrong");
|
225 |
+
return false;
|
226 |
+
}
|
227 |
+
SwpmLog::log_simple_debug("validate:bad hash",true);
|
228 |
+
if ($expiration < time()){
|
229 |
+
$GLOBALS['login_grace_period'] = 1;
|
230 |
+
}
|
231 |
+
$this->userData = $user;
|
232 |
+
return $this->check_constraints();
|
233 |
+
}
|
234 |
+
|
235 |
+
public static function b_hash($data, $scheme = 'auth') {
|
236 |
+
$salt = wp_salt($scheme) . 'j4H!B3TA,J4nIn4.';
|
237 |
+
return hash_hmac('md5', $data, $salt);
|
238 |
+
}
|
239 |
+
|
240 |
+
public function is_logged_in() {
|
241 |
+
return $this->isLoggedIn;
|
242 |
+
}
|
243 |
+
|
244 |
+
public function get($key, $default = "") {
|
245 |
+
if (isset($this->userData->$key)){
|
246 |
+
return $this->userData->$key;
|
247 |
+
}
|
248 |
+
if (isset($this->permitted->$key)){
|
249 |
+
return $this->permitted->$key;
|
250 |
+
}
|
251 |
+
if (!empty($this->permitted)){
|
252 |
+
return $this->permitted->get($key, $default);
|
253 |
+
}
|
254 |
+
return $default;
|
255 |
+
}
|
256 |
+
|
257 |
+
public function get_message() {
|
258 |
+
return $this->lastStatusMsg;
|
259 |
+
}
|
260 |
+
public function get_expire_date(){
|
261 |
+
if ($this->isLoggedIn){
|
262 |
+
return SwpmUtils::get_expire_date(
|
263 |
+
$this->get('subscription_starts'),
|
264 |
+
$this->get('subscription_period'),
|
265 |
+
$this->get('subscription_duration_type'));
|
266 |
+
}
|
267 |
+
return "";
|
268 |
+
}
|
269 |
+
public function delete(){
|
270 |
+
if (!$this->is_logged_in()) {return ;}
|
271 |
+
$user_name = $this->get('user_name');
|
272 |
+
$user_id = $this->get('member_id');
|
273 |
+
wp_clear_auth_cookie();
|
274 |
+
$this->logout();
|
275 |
+
SwpmMembers::delete_swpm_user_by_id($user_id);
|
276 |
+
SwpmMembers::delete_wp_user($user_name);
|
277 |
+
}
|
278 |
+
|
279 |
+
public function reload_user_data(){
|
280 |
+
if (!$this->is_logged_in()) {return ;}
|
281 |
+
global $wpdb;
|
282 |
+
$query = "SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE member_id = %d";
|
283 |
+
$this->userData = $wpdb->get_row($wpdb->prepare($query, $this->userData->member_id));
|
284 |
+
|
285 |
+
}
|
286 |
+
public function is_expired_account(){
|
287 |
+
// should be called after logging in.
|
288 |
+
if (!$this->is_logged_in()) {return null;}
|
289 |
+
return $this->get('account_state') === 'expired';
|
290 |
+
}
|
291 |
+
}
|
classes/class.swpm-category-list.php
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* BCategoryList
|
5 |
+
*
|
6 |
+
* @author nur
|
7 |
+
*/
|
8 |
+
if (!class_exists('WP_List_Table')) {
|
9 |
+
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
10 |
+
}
|
11 |
+
|
12 |
+
class SwpmCategoryList extends WP_List_Table {
|
13 |
+
|
14 |
+
public $selected_level_id = 1;
|
15 |
+
public $category;
|
16 |
+
|
17 |
+
function __construct() {
|
18 |
+
parent::__construct(array(
|
19 |
+
'singular' => SwpmUtils::_('Membership Level'),
|
20 |
+
'plural' => SwpmUtils::_('Membership Levels'),
|
21 |
+
'ajax' => false
|
22 |
+
));
|
23 |
+
$this->category = array();
|
24 |
+
$selected = filter_input(INPUT_POST, 'membership_level_id');
|
25 |
+
$this->selected_level_id = empty($selected) ? 1 : $selected;
|
26 |
+
$this->category = ($this->selected_level_id == 1) ?
|
27 |
+
SwpmProtection::get_instance() :
|
28 |
+
SwpmPermission::get_instance($this->selected_level_id);
|
29 |
+
}
|
30 |
+
|
31 |
+
function get_columns() {
|
32 |
+
return array(
|
33 |
+
'cb' => '<input type="checkbox" />'
|
34 |
+
, 'term_id' => SwpmUtils::_('ID')
|
35 |
+
, 'name' => SwpmUtils::_('Name')
|
36 |
+
, 'description' => SwpmUtils::_('Description')
|
37 |
+
, 'count' => SwpmUtils::_('Count')
|
38 |
+
);
|
39 |
+
}
|
40 |
+
|
41 |
+
function get_sortable_columns() {
|
42 |
+
return array(
|
43 |
+
'name' => array('name', true)
|
44 |
+
);
|
45 |
+
}
|
46 |
+
|
47 |
+
function column_default($item, $column_name) {
|
48 |
+
return stripslashes($item->$column_name);
|
49 |
+
}
|
50 |
+
|
51 |
+
function column_term_id($item) {
|
52 |
+
return $item->term_id;
|
53 |
+
}
|
54 |
+
|
55 |
+
function column_cb($item) {
|
56 |
+
return sprintf(
|
57 |
+
'<input type="hidden" name="ids_in_page[]" value="%s">
|
58 |
+
<input type="checkbox" %s name="ids[]" value="%s" />', $item->term_id, $this->category->in_categories($item->term_id) ? "checked" : "", $item->term_id
|
59 |
+
);
|
60 |
+
}
|
61 |
+
|
62 |
+
function prepare_items() {
|
63 |
+
$submitted = filter_input(INPUT_POST, 'update_category_list');
|
64 |
+
if (!empty($submitted)) {
|
65 |
+
$args = array('ids' => array(
|
66 |
+
'filter' => FILTER_VALIDATE_INT,
|
67 |
+
'flags' => FILTER_REQUIRE_ARRAY,
|
68 |
+
));
|
69 |
+
$filtered = filter_input_array(INPUT_POST, $args);
|
70 |
+
$ids = $filtered['ids'];
|
71 |
+
$args = array('ids_in_page' => array(
|
72 |
+
'filter' => FILTER_VALIDATE_INT,
|
73 |
+
'flags' => FILTER_REQUIRE_ARRAY,
|
74 |
+
));
|
75 |
+
$filtered = filter_input_array(INPUT_POST, $args);
|
76 |
+
$ids_in_page = $filtered['ids_in_page'];
|
77 |
+
$this->category->remove($ids_in_page, 'category')->apply($ids, 'category')->save();
|
78 |
+
$message = array('succeeded' => true, 'message' => SwpmUtils::_('Updated! '));
|
79 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
80 |
+
}
|
81 |
+
$all_categories = array();
|
82 |
+
$all_cat_ids = get_categories(array('hide_empty' => '0'));
|
83 |
+
$totalitems = count($all_cat_ids);
|
84 |
+
$perpage = 100;
|
85 |
+
$paged = !empty($_GET["paged"]) ? mysql_real_escape_string($_GET["paged"]) : '';
|
86 |
+
if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
|
87 |
+
$paged = 1;
|
88 |
+
}
|
89 |
+
$totalpages = ceil($totalitems / $perpage);
|
90 |
+
$offset = 0;
|
91 |
+
if (!empty($paged) && !empty($perpage)) {
|
92 |
+
$offset = ($paged - 1) * $perpage;
|
93 |
+
}
|
94 |
+
for ($i = $offset; $i < ((int) $offset + (int) $perpage) && !empty($all_cat_ids[$i]); $i++) {
|
95 |
+
$all_categories[] = $all_cat_ids[$i];
|
96 |
+
}
|
97 |
+
$this->set_pagination_args(array(
|
98 |
+
"total_items" => $totalitems,
|
99 |
+
"total_pages" => $totalpages,
|
100 |
+
"per_page" => $perpage,
|
101 |
+
));
|
102 |
+
|
103 |
+
$columns = $this->get_columns();
|
104 |
+
$hidden = array();
|
105 |
+
$sortable = $this->get_sortable_columns();
|
106 |
+
|
107 |
+
$this->_column_headers = array($columns, $hidden, $sortable);
|
108 |
+
$this->items = $all_categories;
|
109 |
+
}
|
110 |
+
|
111 |
+
function no_items() {
|
112 |
+
SwpmUtils::e('No category found.');
|
113 |
+
}
|
114 |
+
|
115 |
+
}
|
classes/class.swpm-cronjob.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Description of BCronJob
|
4 |
+
*
|
5 |
+
* @author nur
|
6 |
+
*/
|
7 |
+
class SwpmCronJob {
|
8 |
+
public function __construct() {
|
9 |
+
add_action('swpm_account_status_event', array(&$this, 'update_account_status'));
|
10 |
+
add_action('swpm_delete_pending_account_event',array(&$this, 'delete_pending_account'));
|
11 |
+
}
|
12 |
+
|
13 |
+
public function update_account_status(){
|
14 |
+
global $wpdb;
|
15 |
+
for($counter = 0;; $counter += 100){
|
16 |
+
$query = $wpdb->prepare("SELECT member_id, membership_level, subscription_starts, account_state
|
17 |
+
FROM {$wpdb->prefix}swpm_members_tbl LIMIT %d, 100", $counter);
|
18 |
+
$results = $wpdb->get_results($query);
|
19 |
+
if (empty($results)) {break;}
|
20 |
+
$expired = array();
|
21 |
+
foreach($results as $result){
|
22 |
+
$timestamp = SwpmUtils::get_expiration_timestamp($result);
|
23 |
+
if ($timestamp < time() && $result->account_state == 'active'){
|
24 |
+
$expired[] = $result->member_id;
|
25 |
+
}
|
26 |
+
}
|
27 |
+
if (count($expired)>0){
|
28 |
+
$query = "UPDATE {$wpdb->prefix}swpm_members_tbl
|
29 |
+
SET account_state='expired' WHERE member_id IN (" . implode(',', $expired) . ")";
|
30 |
+
$wpdb->query($query);
|
31 |
+
}
|
32 |
+
}
|
33 |
+
}
|
34 |
+
|
35 |
+
public function delete_pending_account(){
|
36 |
+
global $wpdb;
|
37 |
+
$interval = SwpmSettings::get_instance()->get_value('delete-pending-account');
|
38 |
+
if (empty($interval)) {return;}
|
39 |
+
for($counter = 0;; $counter += 100){
|
40 |
+
$query = $wpdb->prepare("SELECT member_id
|
41 |
+
FROM
|
42 |
+
{$wpdb->prefix}swpm_members_tbl
|
43 |
+
WHERE account_state='pending'
|
44 |
+
AND subscription_starts < DATE_SUB(NOW(), INTERVAL %d MONTH) LIMIT %d, 100",
|
45 |
+
$interval, $counter);
|
46 |
+
$results = $wpdb->get_results($query);
|
47 |
+
if (empty($results)) {break;}
|
48 |
+
$to_delete = array();
|
49 |
+
foreach($results as $result){
|
50 |
+
$to_delete[] = $result->member_id;
|
51 |
+
}
|
52 |
+
if (count($to_delete)>0){
|
53 |
+
SwpmLog::log_simple_debug("Auto deleting pending account.", true);
|
54 |
+
$query = "DELETE FROM {$wpdb->prefix}swpm_members_tbl
|
55 |
+
WHERE member_id IN (" . implode(',', $to_delete) . ")";
|
56 |
+
$wpdb->query($query);
|
57 |
+
}
|
58 |
+
}
|
59 |
+
}
|
60 |
+
}
|
classes/class.swpm-form.php
ADDED
@@ -0,0 +1,308 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class SwpmForm {
|
4 |
+
|
5 |
+
protected $fields;
|
6 |
+
protected $op;
|
7 |
+
protected $errors;
|
8 |
+
protected $sanitized;
|
9 |
+
|
10 |
+
public function __construct($fields) {
|
11 |
+
$this->fields = $fields;
|
12 |
+
$this->sanitized = array();
|
13 |
+
$this->validate_wp_user_email();
|
14 |
+
if ($this->is_valid()){
|
15 |
+
foreach ($fields as $key => $value){
|
16 |
+
$this->$key();
|
17 |
+
}
|
18 |
+
}
|
19 |
+
}
|
20 |
+
protected function validate_wp_user_email(){
|
21 |
+
$user_name = filter_input(INPUT_POST, 'user_name',FILTER_SANITIZE_STRING);
|
22 |
+
$email = filter_input(INPUT_POST, 'email', FILTER_UNSAFE_RAW);
|
23 |
+
if (empty($user_name)) {return;}
|
24 |
+
$user = get_user_by('login', $user_name);
|
25 |
+
if ($user && ($user->email != $email)){
|
26 |
+
$this->errors['wp_email'] = SwpmUtils::_('Wordpress account exists with given user name. But given email doesn\'t match.');
|
27 |
+
return;
|
28 |
+
}
|
29 |
+
$user = get_user_by('email', $email);
|
30 |
+
if($user && ($user_name != $user->login)){
|
31 |
+
$this->errors['wp_user'] = SwpmUtils::_('Wordpress account exists with given email. But given user name doesn\'t match.');
|
32 |
+
|
33 |
+
}
|
34 |
+
}
|
35 |
+
protected function user_name() {
|
36 |
+
global $wpdb;
|
37 |
+
if (!empty($this->fields['user_name'])){return;}
|
38 |
+
$user_name = filter_input(INPUT_POST, 'user_name',FILTER_SANITIZE_STRING);
|
39 |
+
if (empty($user_name)) {
|
40 |
+
$this->errors['user_name'] = SwpmUtils::_('User name is required');
|
41 |
+
return;
|
42 |
+
}
|
43 |
+
if (preg_match("/^[a-zA-Z0-9!@#$%&*+\/=?^_`{|}~\.-]+$/", $user_name) === 0) {
|
44 |
+
$this->errors['user_name'] = SwpmUtils::_('User name contains invalid character');
|
45 |
+
return;
|
46 |
+
}
|
47 |
+
$saned = sanitize_text_field($user_name);
|
48 |
+
$query = "SELECT count(member_id) FROM {$wpdb->prefix}swpm_members_tbl WHERE user_name= %s";
|
49 |
+
$result = $wpdb->get_var($wpdb->prepare($query, strip_tags($saned)));
|
50 |
+
if ($result > 0) {
|
51 |
+
if ($saned != $this->fields['user_name']) {
|
52 |
+
$this->errors['user_name'] = SwpmUtils::_('User name already exists.');
|
53 |
+
return;
|
54 |
+
}
|
55 |
+
}
|
56 |
+
$this->sanitized['user_name'] = $saned;
|
57 |
+
}
|
58 |
+
|
59 |
+
protected function first_name() {
|
60 |
+
$first_name = filter_input(INPUT_POST, 'first_name', FILTER_SANITIZE_STRING);
|
61 |
+
if (empty($first_name)) {return;}
|
62 |
+
$this->sanitized['first_name'] = sanitize_text_field($first_name);
|
63 |
+
}
|
64 |
+
|
65 |
+
protected function last_name() {
|
66 |
+
$last_name = filter_input(INPUT_POST, 'last_name', FILTER_SANITIZE_STRING);
|
67 |
+
if (empty($last_name)) {return;}
|
68 |
+
$this->sanitized['last_name'] = sanitize_text_field($last_name);
|
69 |
+
}
|
70 |
+
|
71 |
+
protected function password() {
|
72 |
+
$password = filter_input(INPUT_POST, 'password',FILTER_UNSAFE_RAW);
|
73 |
+
$password_re = filter_input(INPUT_POST, 'password_re',FILTER_UNSAFE_RAW);
|
74 |
+
if (empty($this->fields['password']) && empty($password)) {
|
75 |
+
$this->errors['password'] = SwpmUtils::_('Password is required');
|
76 |
+
return;
|
77 |
+
}
|
78 |
+
if (!empty($password)) {
|
79 |
+
$saned = sanitize_text_field($password);
|
80 |
+
$saned_re = sanitize_text_field($password_re);
|
81 |
+
if ($saned != $saned_re){
|
82 |
+
$this->errors['password'] = SwpmUtils::_('Password mismatch');
|
83 |
+
}
|
84 |
+
$this->sanitized['plain_password'] = $password;
|
85 |
+
$this->sanitized['password'] = SwpmUtils::encrypt_password(trim($password)); //should use $saned??;
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
protected function email() {
|
90 |
+
global $wpdb;
|
91 |
+
$email = filter_input(INPUT_POST, 'email', FILTER_UNSAFE_RAW);
|
92 |
+
if (empty($email)) {
|
93 |
+
$this->errors['email'] = SwpmUtils::_('Email is required');
|
94 |
+
return;
|
95 |
+
}
|
96 |
+
if (!is_email($email)) {
|
97 |
+
$this->errors['email'] = SwpmUtils::_('Email is invalid');
|
98 |
+
return;
|
99 |
+
}
|
100 |
+
$saned = sanitize_email($email);
|
101 |
+
$query = "SELECT count(member_id) FROM {$wpdb->prefix}swpm_members_tbl WHERE email= %s";
|
102 |
+
$member_id = filter_input(INPUT_GET, 'member_id', FILTER_SANITIZE_NUMBER_INT);
|
103 |
+
if (!empty($member_id)) {
|
104 |
+
$query .= ' AND member_id !=%d';
|
105 |
+
$result = $wpdb->get_var($wpdb->prepare($query, strip_tags($saned), $member_id));
|
106 |
+
}
|
107 |
+
else{
|
108 |
+
$result = $wpdb->get_var($wpdb->prepare($query, strip_tags($saned)));
|
109 |
+
}
|
110 |
+
|
111 |
+
if ($result > 0) {
|
112 |
+
if ($saned != $this->fields['email']) {
|
113 |
+
$this->errors['email'] = SwpmUtils::_('Email is already used.');
|
114 |
+
return;
|
115 |
+
}
|
116 |
+
}
|
117 |
+
$this->sanitized['email'] = $saned;
|
118 |
+
}
|
119 |
+
|
120 |
+
protected function phone() {
|
121 |
+
$phone = filter_input(INPUT_POST, 'phone', FILTER_UNSAFE_RAW);
|
122 |
+
if (empty($phone)) {return;}
|
123 |
+
$saned = wp_kses($phone, array());
|
124 |
+
$this->sanitized['phone'] = $saned;
|
125 |
+
return;
|
126 |
+
//Not doing phone number validation
|
127 |
+
|
128 |
+
// $saned = wp_kses($phone, array());
|
129 |
+
// $this->sanitized['phone'] = $saned;
|
130 |
+
// if (strlen($saned) > 9 && preg_match('/^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$/', $saned)){
|
131 |
+
// $this->sanitized['phone'] = $saned;
|
132 |
+
// }
|
133 |
+
// else{
|
134 |
+
// $this->errors['phone'] = BUtils::_('Phone number is invalid');
|
135 |
+
// }
|
136 |
+
}
|
137 |
+
|
138 |
+
protected function address_street() {
|
139 |
+
$address_street = filter_input(INPUT_POST, 'address_street', FILTER_SANITIZE_STRING);
|
140 |
+
if (empty($address_street)) { return;}
|
141 |
+
$this->sanitized['address_street'] = wp_kses($address_street, array());
|
142 |
+
}
|
143 |
+
|
144 |
+
protected function address_city() {
|
145 |
+
$address_city = filter_input(INPUT_POST, 'address_city', FILTER_SANITIZE_STRING);
|
146 |
+
if (empty($address_city)){ return; }
|
147 |
+
$this->sanitized['address_city'] = wp_kses($address_city, array());
|
148 |
+
}
|
149 |
+
|
150 |
+
protected function address_state() {
|
151 |
+
$address_state = filter_input(INPUT_POST, 'address_state', FILTER_SANITIZE_STRING);
|
152 |
+
if (empty($address_state)) {return;}
|
153 |
+
$this->sanitized['address_state'] = wp_kses($address_state, array());
|
154 |
+
}
|
155 |
+
|
156 |
+
protected function address_zipcode() {
|
157 |
+
$address_zipcode = filter_input(INPUT_POST, 'address_zipcode', FILTER_UNSAFE_RAW);
|
158 |
+
if (empty($address_zipcode)){ return;}
|
159 |
+
$this->sanitized['address_zipcode'] = wp_kses($address_zipcode, array());
|
160 |
+
}
|
161 |
+
|
162 |
+
protected function country() {
|
163 |
+
$country = filter_input(INPUT_POST, 'country', FILTER_SANITIZE_STRING);
|
164 |
+
if (empty($country)){ return;}
|
165 |
+
$this->sanitized['country'] = wp_kses($country, array());
|
166 |
+
}
|
167 |
+
|
168 |
+
protected function company_name() {
|
169 |
+
$company_name = filter_input(INPUT_POST, 'company_name', FILTER_SANITIZE_STRING);
|
170 |
+
$this->sanitized['company_name'] = $company_name;
|
171 |
+
}
|
172 |
+
|
173 |
+
protected function member_since() {
|
174 |
+
$member_since = filter_input(INPUT_POST, 'member_since', FILTER_UNSAFE_RAW);
|
175 |
+
if (empty($member_since)) {return;}
|
176 |
+
if (preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $member_since)){
|
177 |
+
$this->sanitized['member_since'] = sanitize_text_field($member_since);
|
178 |
+
return;
|
179 |
+
}
|
180 |
+
$this->errors['member_since'] = SwpmUtils::_('Member since field is invalid');
|
181 |
+
|
182 |
+
}
|
183 |
+
|
184 |
+
protected function subscription_starts() {
|
185 |
+
$subscription_starts = filter_input(INPUT_POST, 'subscription_starts', FILTER_SANITIZE_STRING);
|
186 |
+
if(empty($subscription_starts)) {return ;}
|
187 |
+
if (preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $subscription_starts)){
|
188 |
+
$this->sanitized['subscription_starts'] = sanitize_text_field($subscription_starts);
|
189 |
+
return;
|
190 |
+
}
|
191 |
+
$this->errors['subscription_starts'] = SwpmUtils::_('Access starts field is invalid');
|
192 |
+
}
|
193 |
+
|
194 |
+
protected function gender() {
|
195 |
+
$gender = filter_input(INPUT_POST, 'gender', FILTER_SANITIZE_STRING);
|
196 |
+
if(empty($gender)) {return;}
|
197 |
+
if (in_array($gender, array('male', 'female', 'not specified'))){
|
198 |
+
$this->sanitized['gender'] = $gender;
|
199 |
+
}
|
200 |
+
else{
|
201 |
+
$this->errors['gender'] = SwpmUtils::_('Gender field is invalid');
|
202 |
+
}
|
203 |
+
}
|
204 |
+
|
205 |
+
protected function account_state() {
|
206 |
+
$account_state = filter_input(INPUT_POST, 'account_state', FILTER_SANITIZE_STRING);
|
207 |
+
if(empty($account_state)) {return;}
|
208 |
+
if (in_array($account_state, array('active', 'pending', 'inactive', 'expired'))){
|
209 |
+
$this->sanitized['account_state'] = $account_state;
|
210 |
+
}
|
211 |
+
else{
|
212 |
+
$this->errors['account_state'] = SwpmUtils::_('Account state field is invalid');
|
213 |
+
}
|
214 |
+
}
|
215 |
+
|
216 |
+
protected function membership_level() {
|
217 |
+
$membership_level = filter_input(INPUT_POST, 'membership_level', FILTER_SANITIZE_NUMBER_INT);
|
218 |
+
if ($membership_level == 1){
|
219 |
+
$this->errors['membership_level'] = SwpmUtils::_('Invalid membership level');
|
220 |
+
return;
|
221 |
+
}
|
222 |
+
|
223 |
+
if (empty($membership_level)) {return;}
|
224 |
+
$this->sanitized['membership_level'] = $membership_level;
|
225 |
+
}
|
226 |
+
|
227 |
+
protected function password_re() {
|
228 |
+
|
229 |
+
}
|
230 |
+
|
231 |
+
protected function last_accessed() {
|
232 |
+
|
233 |
+
}
|
234 |
+
|
235 |
+
protected function last_accessed_from_ip() {
|
236 |
+
|
237 |
+
}
|
238 |
+
|
239 |
+
protected function referrer() {
|
240 |
+
|
241 |
+
}
|
242 |
+
|
243 |
+
protected function extra_info() {
|
244 |
+
|
245 |
+
}
|
246 |
+
|
247 |
+
protected function reg_code() {
|
248 |
+
|
249 |
+
}
|
250 |
+
|
251 |
+
protected function txn_id() {
|
252 |
+
|
253 |
+
}
|
254 |
+
|
255 |
+
protected function subscr_id() {
|
256 |
+
$subscr_id = filter_input(INPUT_POST, 'subscr_id', FILTER_SANITIZE_STRING);
|
257 |
+
$this->sanitized['subscr_id'] = $subscr_id;
|
258 |
+
}
|
259 |
+
|
260 |
+
protected function flags() {
|
261 |
+
|
262 |
+
}
|
263 |
+
|
264 |
+
protected function more_membership_levels() {
|
265 |
+
|
266 |
+
}
|
267 |
+
|
268 |
+
protected function initial_membership_level() {
|
269 |
+
|
270 |
+
}
|
271 |
+
|
272 |
+
protected function home_page() {
|
273 |
+
|
274 |
+
}
|
275 |
+
|
276 |
+
protected function notes() {
|
277 |
+
|
278 |
+
}
|
279 |
+
|
280 |
+
protected function profile_image() {
|
281 |
+
|
282 |
+
}
|
283 |
+
|
284 |
+
protected function expiry_1st() {
|
285 |
+
|
286 |
+
}
|
287 |
+
|
288 |
+
protected function expiry_2nd() {
|
289 |
+
|
290 |
+
}
|
291 |
+
|
292 |
+
protected function member_id() {
|
293 |
+
|
294 |
+
}
|
295 |
+
|
296 |
+
public function is_valid() {
|
297 |
+
return count($this->errors) < 1;
|
298 |
+
}
|
299 |
+
|
300 |
+
public function get_sanitized() {
|
301 |
+
return $this->sanitized;
|
302 |
+
}
|
303 |
+
|
304 |
+
public function get_errors() {
|
305 |
+
return $this->errors;
|
306 |
+
}
|
307 |
+
|
308 |
+
}
|
classes/class.swpm-front-form.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class SwpmFrontForm extends SwpmForm{
|
4 |
+
public function membership_level(){
|
5 |
+
|
6 |
+
}
|
7 |
+
}
|
classes/class.swpm-front-registration.php
ADDED
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Description of BFrontRegistration
|
5 |
+
*
|
6 |
+
* @author nur
|
7 |
+
*/
|
8 |
+
class SwpmFrontRegistration extends SwpmRegistration {
|
9 |
+
public static function get_instance(){
|
10 |
+
self::$_intance = empty(self::$_intance)? new SwpmFrontRegistration():self::$_intance;
|
11 |
+
return self::$_intance;
|
12 |
+
}
|
13 |
+
public function regigstration_ui($level){
|
14 |
+
$settings_configs = SwpmSettings::get_instance();
|
15 |
+
$joinuspage_url = $settings_configs->get_value('join-us-page-url');
|
16 |
+
$membership_level = '';
|
17 |
+
$member_id = filter_input(INPUT_GET, 'member_id', FILTER_SANITIZE_NUMBER_INT);
|
18 |
+
$code = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_STRING);
|
19 |
+
|
20 |
+
global $wpdb;
|
21 |
+
if (SwpmUtils::is_paid_registration()){
|
22 |
+
$member = $member = SwpmUtils::get_paid_member_info();
|
23 |
+
if (empty($member)){
|
24 |
+
SwpmUtils::e('Error! Invalid Request. Could not find a match for the given security code and the user ID.');
|
25 |
+
}
|
26 |
+
$membership_level = $member->membership_level;
|
27 |
+
}
|
28 |
+
else if (!empty($level)) {
|
29 |
+
$member = SwpmTransfer::$default_fields;
|
30 |
+
$membership_level = absint($level);
|
31 |
+
}
|
32 |
+
if (empty($membership_level)) {
|
33 |
+
$joinuspage_link = '<a href="' . $joinuspage_url . '">Join us</a>';
|
34 |
+
SwpmUtils::e('Free membership is disabled on this site. Please make a payment from the ' . $joinuspage_link . ' page to pay for a premium membership.');
|
35 |
+
return;
|
36 |
+
}
|
37 |
+
$form = apply_filters('swpm_registration_form_override', '', $membership_level);
|
38 |
+
if (!empty($form)) {return $form;}
|
39 |
+
|
40 |
+
$mebership_info = SwpmPermission::get_instance($membership_level);
|
41 |
+
$membership_level = $mebership_info->get('id');
|
42 |
+
if (empty($membership_level)) {
|
43 |
+
return "Membership Level Not Found.";
|
44 |
+
}
|
45 |
+
$level_identifier = md5($membership_level);
|
46 |
+
$membership_level_alias = $mebership_info->get('alias');
|
47 |
+
$swpm_registration_submit = filter_input(INPUT_POST, 'swpm_registration_submit');
|
48 |
+
if (!empty($swpm_registration_submit)){
|
49 |
+
$member = $_POST;
|
50 |
+
}
|
51 |
+
ob_start();
|
52 |
+
extract((array)$member, EXTR_SKIP);
|
53 |
+
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/add.php');
|
54 |
+
return ob_get_clean();
|
55 |
+
}
|
56 |
+
public function register() {
|
57 |
+
if($this->create_swpm_user()&&$this->create_wp_user()&&$this->send_reg_email()){
|
58 |
+
do_action('swpm_front_end_registration_complete');
|
59 |
+
|
60 |
+
$login_page_url = SwpmSettings::get_instance()->get_value('login-page-url');
|
61 |
+
$after_rego_msg = '<p>'. SwpmUtils::_('Registration Successful. '). SwpmUtils::_('Please').' <a href="' . $login_page_url . '">'.SwpmUtils::_('Login').'</a></p>';
|
62 |
+
$message = array('succeeded' => true, 'message' => $after_rego_msg);
|
63 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
64 |
+
return;
|
65 |
+
}
|
66 |
+
}
|
67 |
+
private function create_swpm_user(){
|
68 |
+
global $wpdb;
|
69 |
+
$member = SwpmTransfer::$default_fields;
|
70 |
+
$form = new SwpmFrontForm($member);
|
71 |
+
if (!$form->is_valid()) {
|
72 |
+
$message = array('succeeded' => false, 'message' => SwpmUtils::_('Please correct the following'),
|
73 |
+
'extra' => $form->get_errors());
|
74 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
75 |
+
return false;
|
76 |
+
}
|
77 |
+
|
78 |
+
|
79 |
+
$member_info = $form->get_sanitized();
|
80 |
+
$free_level = SwpmUtils::get_free_level();
|
81 |
+
$account_status = SwpmSettings::get_instance()->get_value('default-account-status', 'active');
|
82 |
+
$member_info['last_accessed_from_ip'] = SwpmTransfer::get_real_ip_addr();
|
83 |
+
$member_info['member_since'] = date("Y-m-d");
|
84 |
+
$member_info['subscription_starts'] = date("Y-m-d");
|
85 |
+
$member_info['account_state'] = $account_status;
|
86 |
+
$plain_password = $member_info['plain_password'];
|
87 |
+
unset($member_info['plain_password']);
|
88 |
+
|
89 |
+
if (SwpmUtils::is_paid_registration()){
|
90 |
+
$member_info['reg_code'] = '';
|
91 |
+
$member_id = filter_input(INPUT_GET, 'member_id', FILTER_SANITIZE_NUMBER_INT);
|
92 |
+
$code = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_STRING);
|
93 |
+
$wpdb->update($wpdb->prefix . "swpm_members_tbl", $member_info,
|
94 |
+
array('member_id' => $member_id,'reg_code'=>$code));
|
95 |
+
|
96 |
+
$query = $wpdb->prepare('SELECT membership_level FROM ' . $wpdb->prefix . 'swpm_members_tbl WHERE member_id=%d', $member_id);
|
97 |
+
$member_info['membership_level'] = $wpdb->get_var( $query );
|
98 |
+
$last_insert_id = $member_id;
|
99 |
+
}
|
100 |
+
else if (!empty($free_level)){
|
101 |
+
$member_info['membership_level'] = $free_level;
|
102 |
+
$wpdb->insert($wpdb->prefix . "swpm_members_tbl", $member_info);
|
103 |
+
$last_insert_id = $wpdb->insert_id;
|
104 |
+
}
|
105 |
+
else{
|
106 |
+
$message = array('succeeded' => false, 'message' => SwpmUtils::_('Membership Level Couldn\'t be found.'));
|
107 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
108 |
+
return false;
|
109 |
+
}
|
110 |
+
$member_info['plain_password'] = $plain_password;
|
111 |
+
$this->member_info = $member_info;
|
112 |
+
return true;
|
113 |
+
}
|
114 |
+
private function create_wp_user(){
|
115 |
+
global $wpdb;
|
116 |
+
$member_info = $this->member_info;
|
117 |
+
$query = $wpdb->prepare("SELECT role FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id = %d", $member_info['membership_level']) ;
|
118 |
+
$wp_user_info = array();
|
119 |
+
$wp_user_info['user_nicename'] = implode('-', explode(' ', $member_info['user_name']));
|
120 |
+
$wp_user_info['display_name'] = $member_info['user_name'];
|
121 |
+
$wp_user_info['user_email'] = $member_info['email'];
|
122 |
+
$wp_user_info['nickname'] = $member_info['user_name'];
|
123 |
+
$wp_user_info['first_name'] = $member_info['first_name'];
|
124 |
+
$wp_user_info['last_name'] = $member_info['last_name'];
|
125 |
+
$wp_user_info['user_login'] = $member_info['user_name'];
|
126 |
+
$wp_user_info['password'] = $member_info['plain_password'];
|
127 |
+
$wp_user_info['role'] = $wpdb->get_var($query);
|
128 |
+
$wp_user_info['user_registered'] = date('Y-m-d H:i:s');
|
129 |
+
SwpmUtils::create_wp_user($wp_user_info);
|
130 |
+
return true;
|
131 |
+
}
|
132 |
+
public function edit() {
|
133 |
+
global $wpdb;
|
134 |
+
$auth = SwpmAuth::get_instance();
|
135 |
+
if (!$auth->is_logged_in()) {
|
136 |
+
return;
|
137 |
+
}
|
138 |
+
$user_data = (array) $auth->userData;
|
139 |
+
unset($user_data['permitted']);
|
140 |
+
$form = new SwpmForm($user_data);
|
141 |
+
if ($form->is_valid()) {
|
142 |
+
global $wpdb;
|
143 |
+
$member_info = $form->get_sanitized();
|
144 |
+
// update corresponding wp user.
|
145 |
+
SwpmUtils::update_wp_user($auth->get('user_name'),$member_info);
|
146 |
+
if (isset($member_info['plain_password'])) {
|
147 |
+
unset($member_info['plain_password']);
|
148 |
+
}
|
149 |
+
|
150 |
+
$wpdb->update(
|
151 |
+
$wpdb->prefix . "swpm_members_tbl", $member_info, array('member_id' => $auth->get('member_id')));
|
152 |
+
$auth->reload_user_data();
|
153 |
+
$message = array('succeeded' => true, 'message' => 'Profile Updated.');
|
154 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
155 |
+
} else {
|
156 |
+
$message = array('succeeded' => false, 'message' => SwpmUtils::_('Please correct the following'),
|
157 |
+
'extra' => $form->get_errors());
|
158 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
159 |
+
return;
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
public function reset_password($email) {
|
164 |
+
$email = sanitize_email($email);
|
165 |
+
if (!is_email($email)) {
|
166 |
+
$message = '<div class="swpm-reset-pw-error">' . SwpmUtils::_("Email address not valid.") . '</div>';
|
167 |
+
$message = array('succeeded' => false, 'message' => $message);
|
168 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
169 |
+
return;
|
170 |
+
}
|
171 |
+
global $wpdb;
|
172 |
+
$query = 'SELECT member_id,user_name,first_name, last_name FROM ' .
|
173 |
+
$wpdb->prefix . 'swpm_members_tbl ' .
|
174 |
+
' WHERE email = %s';
|
175 |
+
$user = $wpdb->get_row($wpdb->prepare($query, $email));
|
176 |
+
if (empty($user)) {
|
177 |
+
$message = '<div class="swpm-reset-pw-error">' . SwpmUtils::_("No user not found with that email address.") .'</div>';
|
178 |
+
$message .= '<div class="swpm-reset-pw-error-email">' . SwpmUtils::_("Email Address: ") . $email .'</div>';
|
179 |
+
$message = array('succeeded' => false, 'message' => $message);
|
180 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
181 |
+
return;
|
182 |
+
}
|
183 |
+
$settings = SwpmSettings::get_instance();
|
184 |
+
$password = wp_generate_password();
|
185 |
+
|
186 |
+
$password_hash = SwpmUtils::encrypt_password(trim($password)); //should use $saned??;
|
187 |
+
$wpdb->update($wpdb->prefix . "swpm_members_tbl", array('password' => $password_hash), array('member_id' => $user->member_id));
|
188 |
+
|
189 |
+
// update wp user pass.
|
190 |
+
SwpmUtils::update_wp_user($user->user_name, array('plain_password'=>$password));
|
191 |
+
|
192 |
+
$body = $settings->get_value('reset-mail-body');
|
193 |
+
$subject = $settings->get_value('reset-mail-subject');
|
194 |
+
$search = array('{user_name}', '{first_name}', '{last_name}', '{password}');
|
195 |
+
$replace = array($user->user_name, $user->first_name, $user->last_name, $password);
|
196 |
+
$body = str_replace($search, $replace, $body);
|
197 |
+
$from = $settings->get_value('email-from');
|
198 |
+
$headers = "From: " . $from . "\r\n";
|
199 |
+
wp_mail($email, $subject, $body, $headers);
|
200 |
+
$message = '<div class="swpm-reset-pw-success">' . SwpmUtils::_("New password has been sent to your email address.") .'</div>';
|
201 |
+
$message .= '<div class="swpm-reset-pw-success-email">' . SwpmUtils::_("Email Address: ") . $email .'</div>';
|
202 |
+
|
203 |
+
$message = array('succeeded' => false, 'message' => $message);
|
204 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
205 |
+
}
|
206 |
+
}
|
classes/class.swpm-installation.php
ADDED
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Description of BInstallation
|
5 |
+
*
|
6 |
+
* @author nur
|
7 |
+
*/
|
8 |
+
class SwpmInstallation {
|
9 |
+
/*
|
10 |
+
* This function is capable of handing both single site or multi-site install and upgrade all in one.
|
11 |
+
*/
|
12 |
+
|
13 |
+
static function run_safe_installer() {
|
14 |
+
global $wpdb;
|
15 |
+
|
16 |
+
//Do this if multi-site setup
|
17 |
+
if (function_exists('is_multisite') && is_multisite()) {
|
18 |
+
// check if it is a network activation - if so, run the activation function for each blog id
|
19 |
+
if (isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) {
|
20 |
+
$old_blog = $wpdb->blogid;
|
21 |
+
// Get all blog ids
|
22 |
+
$blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
|
23 |
+
foreach ($blogids as $blog_id) {
|
24 |
+
switch_to_blog($blog_id);
|
25 |
+
SwpmInstallation::installer();
|
26 |
+
SwpmInstallation::initdb();
|
27 |
+
}
|
28 |
+
switch_to_blog($old_blog);
|
29 |
+
return;
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
//Do this if single site standard install
|
34 |
+
SwpmInstallation::installer();
|
35 |
+
SwpmInstallation::initdb();
|
36 |
+
}
|
37 |
+
|
38 |
+
public static function installer() {
|
39 |
+
global $wpdb;
|
40 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
41 |
+
|
42 |
+
$charset_collate = '';
|
43 |
+
if (!empty($wpdb->charset)) {
|
44 |
+
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
45 |
+
} else {
|
46 |
+
$charset_collate = "DEFAULT CHARSET=utf8";
|
47 |
+
}
|
48 |
+
if (!empty($wpdb->collate)) {
|
49 |
+
$charset_collate .= " COLLATE $wpdb->collate";
|
50 |
+
}
|
51 |
+
|
52 |
+
$sql = "CREATE TABLE " . $wpdb->prefix . "swpm_members_tbl (
|
53 |
+
member_id int(12) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
54 |
+
user_name varchar(32) NOT NULL,
|
55 |
+
first_name varchar(32) DEFAULT '',
|
56 |
+
last_name varchar(32) DEFAULT '',
|
57 |
+
password varchar(64) NOT NULL,
|
58 |
+
member_since date NOT NULL DEFAULT '0000-00-00',
|
59 |
+
membership_level smallint(6) NOT NULL,
|
60 |
+
more_membership_levels VARCHAR(100) DEFAULT NULL,
|
61 |
+
account_state enum('active','inactive','expired','pending','unsubscribed') DEFAULT 'pending',
|
62 |
+
last_accessed datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
63 |
+
last_accessed_from_ip varchar(64) NOT NULL,
|
64 |
+
email varchar(64) DEFAULT NULL,
|
65 |
+
phone varchar(64) DEFAULT NULL,
|
66 |
+
address_street varchar(255) DEFAULT NULL,
|
67 |
+
address_city varchar(255) DEFAULT NULL,
|
68 |
+
address_state varchar(255) DEFAULT NULL,
|
69 |
+
address_zipcode varchar(255) DEFAULT NULL,
|
70 |
+
home_page varchar(255) DEFAULT NULL,
|
71 |
+
country varchar(255) DEFAULT NULL,
|
72 |
+
gender enum('male','female','not specified') DEFAULT 'not specified',
|
73 |
+
referrer varchar(255) DEFAULT NULL,
|
74 |
+
extra_info text,
|
75 |
+
reg_code varchar(255) DEFAULT NULL,
|
76 |
+
subscription_starts date DEFAULT NULL,
|
77 |
+
initial_membership_level smallint(6) DEFAULT NULL,
|
78 |
+
txn_id varchar(64) DEFAULT '',
|
79 |
+
subscr_id varchar(32) DEFAULT '',
|
80 |
+
company_name varchar(100) DEFAULT '',
|
81 |
+
notes text DEFAULT NULL,
|
82 |
+
flags int(11) DEFAULT '0',
|
83 |
+
profile_image varchar(255) DEFAULT ''
|
84 |
+
)" . $charset_collate . ";";
|
85 |
+
dbDelta($sql);
|
86 |
+
|
87 |
+
$sql = "CREATE TABLE " . $wpdb->prefix . "swpm_membership_tbl (
|
88 |
+
id int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
89 |
+
alias varchar(127) NOT NULL,
|
90 |
+
role varchar(255) NOT NULL DEFAULT 'subscriber',
|
91 |
+
permissions tinyint(4) NOT NULL DEFAULT '0',
|
92 |
+
subscription_period varchar(11) NOT NULL DEFAULT '-1',
|
93 |
+
subscription_duration_type tinyint NOT NULL default 0,
|
94 |
+
subscription_unit VARCHAR(20) NULL,
|
95 |
+
loginredirect_page text NULL,
|
96 |
+
category_list longtext,
|
97 |
+
page_list longtext,
|
98 |
+
post_list longtext,
|
99 |
+
comment_list longtext,
|
100 |
+
attachment_list longtext,
|
101 |
+
custom_post_list longtext,
|
102 |
+
disable_bookmark_list longtext,
|
103 |
+
options longtext,
|
104 |
+
protect_older_posts tinyint(1) NOT NULL DEFAULT '0',
|
105 |
+
campaign_name varchar(60) NOT NULL DEFAULT ''
|
106 |
+
)" . $charset_collate . " AUTO_INCREMENT=1 ;";
|
107 |
+
dbDelta($sql);
|
108 |
+
$sql = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id = 1";
|
109 |
+
$results = $wpdb->get_row($sql);
|
110 |
+
if (is_null($results)) {
|
111 |
+
$sql = "INSERT INTO " . $wpdb->prefix . "swpm_membership_tbl (
|
112 |
+
id ,
|
113 |
+
alias ,
|
114 |
+
role ,
|
115 |
+
permissions ,
|
116 |
+
subscription_period ,
|
117 |
+
subscription_unit,
|
118 |
+
loginredirect_page,
|
119 |
+
category_list ,
|
120 |
+
page_list ,
|
121 |
+
post_list ,
|
122 |
+
comment_list,
|
123 |
+
disable_bookmark_list,
|
124 |
+
options,
|
125 |
+
campaign_name
|
126 |
+
)VALUES (1 , 'Content Protection', 'administrator', '15', '0',NULL,NULL, NULL , NULL , NULL , NULL,NULL,NULL,'');";
|
127 |
+
$wpdb->query($sql);
|
128 |
+
}
|
129 |
+
$sql = "UPDATE " . $wpdb->prefix . "swpm_membership_tbl SET subscription_duration_type = 1 WHERE subscription_unit='days' AND subscription_duration_type = 0";
|
130 |
+
$wpdb->query($sql);
|
131 |
+
|
132 |
+
$sql = "UPDATE " . $wpdb->prefix . "swpm_membership_tbl SET subscription_duration_type = 2 WHERE subscription_unit='weeks' AND subscription_duration_type = 0";
|
133 |
+
$wpdb->query($sql);
|
134 |
+
|
135 |
+
$sql = "UPDATE " . $wpdb->prefix . "swpm_membership_tbl SET subscription_duration_type = 3 WHERE subscription_unit='months' AND subscription_duration_type = 0";
|
136 |
+
$wpdb->query($sql);
|
137 |
+
|
138 |
+
$sql = "UPDATE " . $wpdb->prefix . "swpm_membership_tbl SET subscription_duration_type = 4 WHERE subscription_unit='years' AND subscription_duration_type = 0";
|
139 |
+
$wpdb->query($sql);
|
140 |
+
$sql = "CREATE TABLE " . $wpdb->prefix . "swpm_membership_meta_tbl (
|
141 |
+
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
142 |
+
level_id int(11) NOT NULL,
|
143 |
+
meta_key varchar(255) NOT NULL,
|
144 |
+
meta_label varchar(255) NULL,
|
145 |
+
meta_value text,
|
146 |
+
meta_type varchar(255) NOT NULL DEFAULT 'text',
|
147 |
+
meta_default text,
|
148 |
+
meta_context varchar(255) NOT NULL DEFAULT 'default',
|
149 |
+
KEY level_id (level_id),
|
150 |
+
UNIQUE KEY meta_key_id (level_id,meta_key(191))
|
151 |
+
)" . $charset_collate . " AUTO_INCREMENT=1 ;";
|
152 |
+
dbDelta($sql);
|
153 |
+
|
154 |
+
$sql = "CREATE TABLE " . $wpdb->prefix . "swpm_payments_tbl (
|
155 |
+
id int(12) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
156 |
+
email varchar(64) DEFAULT NULL,
|
157 |
+
first_name varchar(32) DEFAULT '',
|
158 |
+
last_name varchar(32) DEFAULT '',
|
159 |
+
member_id varchar(16) DEFAULT '',
|
160 |
+
membership_level varchar(16) DEFAULT '',
|
161 |
+
txn_date date NOT NULL default '0000-00-00',
|
162 |
+
txn_id varchar(128) NOT NULL default '',
|
163 |
+
subscr_id varchar(128) NOT NULL default '',
|
164 |
+
reference varchar(128) NOT NULL default '',
|
165 |
+
payment_amount varchar(32) NOT NULL default '',
|
166 |
+
gateway varchar(16) DEFAULT '',
|
167 |
+
status varchar(16) DEFAULT '',
|
168 |
+
ip_address varchar(64) default ''
|
169 |
+
)" . $charset_collate . ";";
|
170 |
+
dbDelta($sql);
|
171 |
+
|
172 |
+
//Save the current DB version
|
173 |
+
update_option("swpm_db_version", SIMPLE_WP_MEMBERSHIP_DB_VER);
|
174 |
+
}
|
175 |
+
|
176 |
+
public static function initdb() {
|
177 |
+
$settings = SwpmSettings::get_instance();
|
178 |
+
|
179 |
+
$installed_version = $settings->get_value('swpm-active-version');
|
180 |
+
|
181 |
+
//Set other default settings values
|
182 |
+
$reg_prompt_email_subject = "Complete your registration";
|
183 |
+
$reg_prompt_email_body = "Dear {first_name} {last_name}" .
|
184 |
+
"\n\nThank you for joining us!" .
|
185 |
+
"\n\nPlease complete your registration by visiting the following link:" .
|
186 |
+
"\n\n{reg_link}" .
|
187 |
+
"\n\nThank You";
|
188 |
+
$reg_email_subject = "Your registration is complete";
|
189 |
+
$reg_email_body = "Dear {first_name} {last_name}\n\n" .
|
190 |
+
"Your registration is now complete!\n\n" .
|
191 |
+
"Registration details:\n" .
|
192 |
+
"Username: {user_name}\n" .
|
193 |
+
"Password: {password}\n\n" .
|
194 |
+
"Please login to the member area at the following URL:\n\n" .
|
195 |
+
"{login_link}\n\n" .
|
196 |
+
"Thank You";
|
197 |
+
|
198 |
+
$upgrade_email_subject = "Subject for email sent after account upgrade";
|
199 |
+
$upgrade_email_body = "Dear {first_name} {last_name}" .
|
200 |
+
"\n\nYour Account Has Been Upgraded." .
|
201 |
+
"\n\nThank You";
|
202 |
+
$reset_email_subject = get_bloginfo('name') . ": New Password";
|
203 |
+
$reset_email_body = "Dear {first_name} {last_name}" .
|
204 |
+
"\n\nHere is your new password" .
|
205 |
+
"\n\nUser name: {user_name}" .
|
206 |
+
"\n\nPassword: {password}" .
|
207 |
+
"\n\nThank You";
|
208 |
+
|
209 |
+
$status_change_email_subject = "Account Updated!";
|
210 |
+
$status_change_email_body = "Dear {first_name} {last_name}," .
|
211 |
+
"\n\n Your account status has been updated!" .
|
212 |
+
" Please login to the member area at the following URL:" .
|
213 |
+
"\n\n {login_link}" .
|
214 |
+
"\n\nThank You";
|
215 |
+
|
216 |
+
if (empty($installed_version)) {
|
217 |
+
//Do fresh install tasks
|
218 |
+
|
219 |
+
/* * * Create the mandatory pages (if they are not there) ** */
|
220 |
+
SwpmMiscUtils::create_mandatory_wp_pages();
|
221 |
+
/* * * End of page creation ** */
|
222 |
+
$settings->set_value('reg-complete-mail-subject', stripslashes($reg_email_subject))
|
223 |
+
->set_value('reg-complete-mail-body', stripslashes($reg_email_body))
|
224 |
+
->set_value('reg-prompt-complete-mail-subject', stripslashes($reg_prompt_email_subject))
|
225 |
+
->set_value('reg-prompt-complete-mail-body', stripslashes($reg_prompt_email_body))
|
226 |
+
->set_value('upgrade-complete-mail-subject', stripslashes($upgrade_email_subject))
|
227 |
+
->set_value('upgrade-complete-mail-body', stripslashes($upgrade_email_body))
|
228 |
+
->set_value('reset-mail-subject', stripslashes($reset_email_subject))
|
229 |
+
->set_value('reset-mail-body', stripslashes($reset_email_body))
|
230 |
+
->set_value('account-change-email-subject', stripslashes($status_change_email_subject))
|
231 |
+
->set_value('account-change-email-body', stripslashes($status_change_email_body))
|
232 |
+
->set_value('email-from', trim(get_option('admin_email')));
|
233 |
+
}
|
234 |
+
if (version_compare($installed_version, SIMPLE_WP_MEMBERSHIP_VER) == -1) {
|
235 |
+
//Do upgrade tasks
|
236 |
+
}
|
237 |
+
|
238 |
+
$settings->set_value('swpm-active-version', SIMPLE_WP_MEMBERSHIP_VER)->save(); //save everything.
|
239 |
+
}
|
240 |
+
|
241 |
+
}
|
classes/class.swpm-level-form.php
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class SwpmLevelForm {
|
4 |
+
|
5 |
+
protected $fields;
|
6 |
+
protected $op;
|
7 |
+
protected $errors;
|
8 |
+
protected $sanitized;
|
9 |
+
|
10 |
+
public function __construct($fields) {
|
11 |
+
$this->fields = $fields;
|
12 |
+
$this->sanitized = array();
|
13 |
+
foreach ($fields as $key => $value)
|
14 |
+
$this->$key();
|
15 |
+
}
|
16 |
+
|
17 |
+
protected function id() {
|
18 |
+
|
19 |
+
}
|
20 |
+
|
21 |
+
protected function alias() {
|
22 |
+
$alias = filter_input(INPUT_POST, 'alias');
|
23 |
+
$this->sanitized['alias'] = sanitize_text_field($alias);
|
24 |
+
}
|
25 |
+
|
26 |
+
protected function role() {
|
27 |
+
$role = filter_input(INPUT_POST, 'role');
|
28 |
+
$this->sanitized['role'] = sanitize_text_field($role);
|
29 |
+
}
|
30 |
+
|
31 |
+
protected function permissions() {
|
32 |
+
$this->sanitized['permissions'] = 63;
|
33 |
+
}
|
34 |
+
|
35 |
+
protected function subscription_period() {
|
36 |
+
$subscript_duration_type = filter_input(INPUT_POST, 'subscription_duration_type');
|
37 |
+
|
38 |
+
if ($subscript_duration_type == SwpmMembershipLevel::NO_EXPIRY) {
|
39 |
+
$this->sanitized['subscription_period'] = "";
|
40 |
+
return;
|
41 |
+
}
|
42 |
+
|
43 |
+
$subscription_period = filter_input(INPUT_POST, 'subscription_period_'. $subscript_duration_type);
|
44 |
+
if (($subscript_duration_type == SwpmMembershipLevel::FIXED_DATE)){
|
45 |
+
$dateinfo = date_parse($subscription_period);
|
46 |
+
if ($dateinfo['warning_count']|| $dateinfo['error_count']){
|
47 |
+
$this->errors['subscription_period'] = SwpmUtils::_("Date format is not valid.");
|
48 |
+
return;
|
49 |
+
}
|
50 |
+
$this->sanitized['subscription_period'] = sanitize_text_field($subscription_period);
|
51 |
+
return;
|
52 |
+
}
|
53 |
+
|
54 |
+
if (!is_numeric($subscription_period)) {
|
55 |
+
$this->errors['subscription_period'] = SwpmUtils::_("Access duration must be > 0.");
|
56 |
+
return;
|
57 |
+
}
|
58 |
+
$this->sanitized['subscription_period'] = sanitize_text_field($subscription_period);
|
59 |
+
}
|
60 |
+
|
61 |
+
protected function subscription_duration_type(){
|
62 |
+
$subscription_duration_type = filter_input(INPUT_POST, 'subscription_duration_type');
|
63 |
+
$this->sanitized['subscription_duration_type'] = $subscription_duration_type;
|
64 |
+
return;
|
65 |
+
}
|
66 |
+
protected function subscription_unit(){
|
67 |
+
|
68 |
+
}
|
69 |
+
protected function loginredirect_page() {
|
70 |
+
|
71 |
+
}
|
72 |
+
|
73 |
+
protected function category_list() {
|
74 |
+
|
75 |
+
}
|
76 |
+
|
77 |
+
protected function page_list() {
|
78 |
+
|
79 |
+
}
|
80 |
+
|
81 |
+
protected function post_list() {
|
82 |
+
|
83 |
+
}
|
84 |
+
|
85 |
+
protected function comment_list() {
|
86 |
+
|
87 |
+
}
|
88 |
+
|
89 |
+
protected function attachment_list() {
|
90 |
+
|
91 |
+
}
|
92 |
+
|
93 |
+
protected function custom_post_list() {
|
94 |
+
|
95 |
+
}
|
96 |
+
|
97 |
+
protected function disable_bookmark_list() {
|
98 |
+
|
99 |
+
}
|
100 |
+
|
101 |
+
protected function options() {
|
102 |
+
|
103 |
+
}
|
104 |
+
|
105 |
+
protected function campaign_name() {
|
106 |
+
|
107 |
+
}
|
108 |
+
|
109 |
+
protected function protect_older_posts() {
|
110 |
+
$checked = filter_input(INPUT_POST, 'protect_older_posts');
|
111 |
+
$this->sanitized['protect_older_posts'] = empty($checked) ? 0 : 1;
|
112 |
+
}
|
113 |
+
|
114 |
+
public function is_valid() {
|
115 |
+
return count($this->errors) < 1;
|
116 |
+
}
|
117 |
+
|
118 |
+
public function get_sanitized() {
|
119 |
+
return $this->sanitized;
|
120 |
+
}
|
121 |
+
|
122 |
+
public function get_errors() {
|
123 |
+
return $this->errors;
|
124 |
+
}
|
125 |
+
|
126 |
+
}
|
classes/class.swpm-log.php
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class SwpmLog {
|
4 |
+
private $error;
|
5 |
+
private $warn;
|
6 |
+
private $notice;
|
7 |
+
private static $intance;
|
8 |
+
private function __construct() {
|
9 |
+
$this->error = array();
|
10 |
+
$this->warn = array();
|
11 |
+
$this->notice = array();
|
12 |
+
}
|
13 |
+
public static function get_logger($context = ''){
|
14 |
+
$context = empty($context)? 'default': $context;
|
15 |
+
if (!isset(self::$intance[$context])){
|
16 |
+
self::$intance[$context] = new SwpmLog();
|
17 |
+
}
|
18 |
+
return self::$intance[$context];
|
19 |
+
}
|
20 |
+
public function error($msg){
|
21 |
+
$this->error[] = $msg;
|
22 |
+
}
|
23 |
+
public function warn($msg){
|
24 |
+
$this->warn[] = $msg;
|
25 |
+
}
|
26 |
+
public function debug($msg){
|
27 |
+
$this->notice[] = $msg;
|
28 |
+
}
|
29 |
+
public function get($to_screen = false){
|
30 |
+
$msg = '';
|
31 |
+
foreach ($this->error as $error ){
|
32 |
+
$msg .= 'ERROR: ' . $error . ($to_screen?"<br/>":"\n");
|
33 |
+
}
|
34 |
+
foreach($this->warn as $warn){
|
35 |
+
$msg .= 'WARN: ' . $warn . ($to_screen?"<br/>":"\n");
|
36 |
+
}
|
37 |
+
foreach ($this->notice as $notice){
|
38 |
+
$msg = 'NOTICE: ' . $notice . ($to_screen?"<br/>":"\n");
|
39 |
+
}
|
40 |
+
return $msg;
|
41 |
+
}
|
42 |
+
public static function writeall($path = ''){
|
43 |
+
if (empty($path)) {$path = SIMPLE_WP_MEMBERSHIP_PATH . 'log.txt';}
|
44 |
+
$fp = fopen($path, 'a');
|
45 |
+
$date = date("Y-m-d H:i:s");
|
46 |
+
fwrite($fp, strtoupper($date) . ":\n");
|
47 |
+
fwrite($fp, str_repeat('-=', (strlen($date)+1.0)/2.0) . "\n");
|
48 |
+
foreach (self::$intance as $context=>$intance){
|
49 |
+
fwrite($fp, strtoupper($context) . ":\n");
|
50 |
+
fwrite($fp, str_repeat('=', strlen($context)+1) . "\n");
|
51 |
+
fwrite($fp, $intance->get());
|
52 |
+
}
|
53 |
+
fclose($fp);
|
54 |
+
}
|
55 |
+
|
56 |
+
public static function log_simple_debug($message, $success, $end = false) {
|
57 |
+
$settings = SwpmSettings::get_instance();
|
58 |
+
$debug_enabled = $settings->get_value('enable-debug');
|
59 |
+
if (empty($debug_enabled)) {//Debug is not enabled
|
60 |
+
return;
|
61 |
+
}
|
62 |
+
|
63 |
+
//Lets write to the log file
|
64 |
+
$debug_log_file_name = SIMPLE_WP_MEMBERSHIP_PATH . 'log.txt';
|
65 |
+
|
66 |
+
// Timestamp
|
67 |
+
$text = '[' . date('m/d/Y g:i A') . '] - ' . (($success) ? 'SUCCESS :' : 'FAILURE :') . $message . "\n";
|
68 |
+
if ($end) {
|
69 |
+
$text .= "\n------------------------------------------------------------------\n\n";
|
70 |
+
}
|
71 |
+
// Write to log
|
72 |
+
$fp = fopen($debug_log_file_name, 'a');
|
73 |
+
fwrite($fp, $text);
|
74 |
+
fclose($fp); // close file
|
75 |
+
}
|
76 |
+
|
77 |
+
}
|
classes/class.swpm-member-utils.php
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* BMemberUtils
|
5 |
+
*
|
6 |
+
* @author nur
|
7 |
+
*/
|
8 |
+
class SwpmMemberUtils {
|
9 |
+
|
10 |
+
public static function is_member_logged_in() {
|
11 |
+
$auth = SwpmAuth::get_instance();
|
12 |
+
if ($auth->is_logged_in()) {
|
13 |
+
return true;
|
14 |
+
} else {
|
15 |
+
return false;
|
16 |
+
}
|
17 |
+
}
|
18 |
+
|
19 |
+
public static function get_logged_in_members_id() {
|
20 |
+
$auth = SwpmAuth::get_instance();
|
21 |
+
if (!$auth->is_logged_in()) {
|
22 |
+
return SwpmUtils::_("User is not logged in.");
|
23 |
+
}
|
24 |
+
return $auth->get('member_id');
|
25 |
+
}
|
26 |
+
|
27 |
+
public static function get_logged_in_members_level() {
|
28 |
+
$auth = SwpmAuth::get_instance();
|
29 |
+
if (!$auth->is_logged_in()) {
|
30 |
+
return SwpmUtils::_("User is not logged in.");
|
31 |
+
}
|
32 |
+
return $auth->get('membership_level');
|
33 |
+
}
|
34 |
+
|
35 |
+
public static function get_logged_in_members_level_name() {
|
36 |
+
$auth = SwpmAuth::get_instance();
|
37 |
+
if ($auth->is_logged_in()) {
|
38 |
+
return $auth->get('alias');
|
39 |
+
}
|
40 |
+
return SwpmUtils::_("User is not logged in.");
|
41 |
+
}
|
42 |
+
|
43 |
+
}
|
classes/class.swpm-members.php
ADDED
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class SwpmMembers extends WP_List_Table {
|
4 |
+
|
5 |
+
function __construct() {
|
6 |
+
parent::__construct(array(
|
7 |
+
'singular' => SwpmUtils::_('Member'),
|
8 |
+
'plural' => SwpmUtils::_('Members'),
|
9 |
+
'ajax' => false
|
10 |
+
));
|
11 |
+
}
|
12 |
+
|
13 |
+
function get_columns() {
|
14 |
+
return array(
|
15 |
+
'cb' => '<input type="checkbox" />'
|
16 |
+
, 'member_id' => SwpmUtils::_('ID')
|
17 |
+
, 'user_name' => SwpmUtils::_('User Name')
|
18 |
+
, 'first_name' => SwpmUtils::_('First Name')
|
19 |
+
, 'last_name' => SwpmUtils::_('Last Name')
|
20 |
+
, 'email' => SwpmUtils::_('Email')
|
21 |
+
, 'alias' => SwpmUtils::_('Membership Level')
|
22 |
+
, 'subscription_starts' => SwpmUtils::_('Access Starts')
|
23 |
+
, 'account_state' => SwpmUtils::_('Account State')
|
24 |
+
);
|
25 |
+
}
|
26 |
+
|
27 |
+
function get_sortable_columns() {
|
28 |
+
return array(
|
29 |
+
'member_id' => array('member_id', true),
|
30 |
+
'user_name' => array('user_name', true)
|
31 |
+
);
|
32 |
+
}
|
33 |
+
|
34 |
+
function get_bulk_actions() {
|
35 |
+
$actions = array(
|
36 |
+
'bulk_delete' => SwpmUtils::_('Delete')
|
37 |
+
);
|
38 |
+
return $actions;
|
39 |
+
}
|
40 |
+
|
41 |
+
function column_default($item, $column_name) {
|
42 |
+
return $item[$column_name];
|
43 |
+
}
|
44 |
+
|
45 |
+
function column_member_id($item) {
|
46 |
+
$actions = array(
|
47 |
+
'edit' => sprintf('<a href="admin.php?page=%s&member_action=edit&member_id=%s">Edit</a>', $_REQUEST['page'], $item['member_id']),
|
48 |
+
'delete' => sprintf('<a href="?page=%s&member_action=delete&member_id=%s"
|
49 |
+
onclick="return confirm(\'Are you sure you want to delete this entry?\')">Delete</a>', $_REQUEST['page'], $item['member_id']),
|
50 |
+
);
|
51 |
+
return $item['member_id'] . $this->row_actions($actions);
|
52 |
+
}
|
53 |
+
|
54 |
+
function column_cb($item) {
|
55 |
+
return sprintf(
|
56 |
+
'<input type="checkbox" name="members[]" value="%s" />', $item['member_id']
|
57 |
+
);
|
58 |
+
}
|
59 |
+
|
60 |
+
function prepare_items() {
|
61 |
+
global $wpdb;
|
62 |
+
$query = "SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl";
|
63 |
+
$query .= " LEFT JOIN " . $wpdb->prefix . "swpm_membership_tbl";
|
64 |
+
$query .= " ON ( membership_level = id ) ";
|
65 |
+
$s = filter_input(INPUT_POST, 's');
|
66 |
+
if (!empty($s)){
|
67 |
+
$query .= " WHERE user_name LIKE '%" . strip_tags($s) . "%' "
|
68 |
+
. " OR first_name LIKE '%" . strip_tags($s) . "%' "
|
69 |
+
. " OR last_name LIKE '%" . strip_tags($s) . "%' ";
|
70 |
+
}
|
71 |
+
$orderby = filter_input(INPUT_GET, 'orderby');
|
72 |
+
$orderby = empty($orderby) ? 'user_name' : $orderby ;
|
73 |
+
$order = filter_input(INPUT_GET, 'order');
|
74 |
+
$order = empty($order) ? 'DESC' : $order;
|
75 |
+
|
76 |
+
$sortable_columns = $this->get_sortable_columns();
|
77 |
+
$orderby = SwpmUtils::sanitize_value_by_array($orderby, $sortable_columns);
|
78 |
+
$order = SwpmUtils::sanitize_value_by_array($order, array('DESC' => '1', 'ASC' => '1'));
|
79 |
+
|
80 |
+
$query.=' ORDER BY ' . $orderby . ' ' . $order;
|
81 |
+
$totalitems = $wpdb->query($query); //return the total number of affected rows
|
82 |
+
$perpage = 20;
|
83 |
+
$paged = filter_input(INPUT_GET, 'paged');
|
84 |
+
if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
|
85 |
+
$paged = 1;
|
86 |
+
}
|
87 |
+
$totalpages = ceil($totalitems / $perpage);
|
88 |
+
if (!empty($paged) && !empty($perpage)) {
|
89 |
+
$offset = ($paged - 1) * $perpage;
|
90 |
+
$query.=' LIMIT ' . (int) $offset . ',' . (int) $perpage;
|
91 |
+
}
|
92 |
+
$this->set_pagination_args(array(
|
93 |
+
"total_items" => $totalitems,
|
94 |
+
"total_pages" => $totalpages,
|
95 |
+
"per_page" => $perpage,
|
96 |
+
));
|
97 |
+
|
98 |
+
$columns = $this->get_columns();
|
99 |
+
$hidden = array();
|
100 |
+
$sortable = $this->get_sortable_columns();
|
101 |
+
|
102 |
+
$this->_column_headers = array($columns, $hidden, $sortable);
|
103 |
+
$this->items = $wpdb->get_results($query, ARRAY_A);
|
104 |
+
}
|
105 |
+
|
106 |
+
function no_items() {
|
107 |
+
_e('No Member found.');
|
108 |
+
}
|
109 |
+
|
110 |
+
function process_form_request() {
|
111 |
+
if (isset($_REQUEST['member_id']))
|
112 |
+
return $this->edit(absint($_REQUEST['member_id']));
|
113 |
+
return $this->add();
|
114 |
+
}
|
115 |
+
|
116 |
+
function add() {
|
117 |
+
$form = apply_filters('swpm_admin_registration_form_override', '');
|
118 |
+
if (!empty($form)) {echo $form;return;}
|
119 |
+
global $wpdb;
|
120 |
+
$member = SwpmTransfer::$default_fields;
|
121 |
+
$member['member_since'] = date('Y-m-d');
|
122 |
+
$member['subscription_starts'] = date('Y-m-d');
|
123 |
+
if (isset($_POST['createswpmuser'])) {
|
124 |
+
$member = $_POST;
|
125 |
+
}
|
126 |
+
extract($member, EXTR_SKIP);
|
127 |
+
$query = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
|
128 |
+
$levels = $wpdb->get_results($query, ARRAY_A);
|
129 |
+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_add.php');
|
130 |
+
return false;
|
131 |
+
}
|
132 |
+
|
133 |
+
function edit($id) {
|
134 |
+
global $wpdb;
|
135 |
+
$id = absint($id);
|
136 |
+
$query = "SELECT * FROM {$wpdb->prefix}swpm_members_tbl WHERE member_id = $id";
|
137 |
+
$member = $wpdb->get_row($query, ARRAY_A);
|
138 |
+
if (isset($_POST["editswpmuser"])) {
|
139 |
+
$_POST['user_name'] = $member['user_name'];
|
140 |
+
$_POST['email'] = $member['email'];
|
141 |
+
$member = $_POST;
|
142 |
+
}
|
143 |
+
extract($member, EXTR_SKIP);
|
144 |
+
$query = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
|
145 |
+
$levels = $wpdb->get_results($query, ARRAY_A);
|
146 |
+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_edit.php');
|
147 |
+
return false;
|
148 |
+
}
|
149 |
+
|
150 |
+
function delete() {
|
151 |
+
global $wpdb;
|
152 |
+
if (isset($_REQUEST['members'])) {
|
153 |
+
$members = $_REQUEST['members'];
|
154 |
+
if (!empty($members)) {
|
155 |
+
$members = array_map('absint', $members);
|
156 |
+
foreach ($members as $swpm_id) {
|
157 |
+
$user_name = SwpmUtils::get_user_by_id(absint($swpm_id));
|
158 |
+
SwpmMembers::delete_wp_user($user_name);
|
159 |
+
}
|
160 |
+
$query = "DELETE FROM " . $wpdb->prefix . "swpm_members_tbl WHERE member_id IN (" . implode(',', $members) . ")";
|
161 |
+
$wpdb->query($query);
|
162 |
+
}
|
163 |
+
}
|
164 |
+
else if (isset($_REQUEST['member_id'])) {
|
165 |
+
$id = absint($_REQUEST['member_id']);
|
166 |
+
SwpmMembers::delete_user_by_id($id);
|
167 |
+
}
|
168 |
+
}
|
169 |
+
public static function delete_user_by_id($id){
|
170 |
+
$user_name = SwpmUtils::get_user_by_id($id);
|
171 |
+
SwpmMembers::delete_wp_user($user_name);
|
172 |
+
SwpmMembers::delete_swpm_user_by_id($id);
|
173 |
+
}
|
174 |
+
|
175 |
+
public static function delete_swpm_user_by_id($id){
|
176 |
+
global $wpdb;
|
177 |
+
$query = "DELETE FROM " . $wpdb->prefix . "swpm_members_tbl WHERE member_id = $id";
|
178 |
+
$wpdb->query($query);
|
179 |
+
}
|
180 |
+
function show() {
|
181 |
+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_members.php');
|
182 |
+
}
|
183 |
+
|
184 |
+
public static function delete_wp_user($user_name) {
|
185 |
+
$wp_user_id = username_exists($user_name);
|
186 |
+
$ud = get_userdata($wp_user_id);
|
187 |
+
if (!empty($ud) && (isset($ud->wp_capabilities['administrator']) || $ud->wp_user_level == 10)) {
|
188 |
+
SwpmTransfer::get_instance()->set('status', 'For consistency, we do not allow deleting any associated wordpress account with administrator role.<br/>'
|
189 |
+
. 'Please delete from <a href="users.php">Users</a> menu.');
|
190 |
+
return;
|
191 |
+
}
|
192 |
+
if ($wp_user_id) {
|
193 |
+
include_once(ABSPATH . 'wp-admin/includes/user.php');
|
194 |
+
wp_delete_user($wp_user_id, 1); //assigns all related to this user to admin.
|
195 |
+
}
|
196 |
+
}
|
197 |
+
|
198 |
+
}
|
classes/class.swpm-membership-level-custom.php
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Description of BMembershipLevelCustom
|
4 |
+
*
|
5 |
+
* @author nur
|
6 |
+
*/
|
7 |
+
class SwpmMembershipLevelCustom {
|
8 |
+
private static $instances = array();
|
9 |
+
private $level_id;
|
10 |
+
private $fields;
|
11 |
+
private function __construct() {
|
12 |
+
$this->fields = array();
|
13 |
+
}
|
14 |
+
public static function get_instance_by_id($level_id){
|
15 |
+
if (!isset(self::$instances[$level_id])){
|
16 |
+
self::$instances[$level_id] = new SwpmMembershipLevelCustom();
|
17 |
+
self::$instances[$level_id]->level_id = $level_id;
|
18 |
+
self::$instances[$level_id]->load_by_id($level_id);
|
19 |
+
}
|
20 |
+
return self::$instances[$level_id];
|
21 |
+
}
|
22 |
+
public function load_by_id($level_id){
|
23 |
+
global $wpdb;
|
24 |
+
$query = 'SELECT * FROM ' . $wpdb->prefix . 'swpm_membership_meta_tbl WHERE level_id=%d';
|
25 |
+
$results = $wpdb->get_results($wpdb->prepare($query, $level_id), ARRAY_A);
|
26 |
+
foreach($results as $result){
|
27 |
+
$this->fields[$result['meta_key']] = $result;
|
28 |
+
}
|
29 |
+
}
|
30 |
+
public function set($item){
|
31 |
+
$meta_key = preg_replace('|[^A-Z0-9_]|i', '', $item['meta_key']);
|
32 |
+
$new = array(
|
33 |
+
'meta_key'=>$meta_key,
|
34 |
+
'level_id'=>$this->level_id,
|
35 |
+
'meta_label'=> isset($item['meta_label'])?$item['meta_label']:'',
|
36 |
+
'meta_value'=>$item['meta_value'],
|
37 |
+
'meta_type'=> isset($item['meta_type'])?$item['meta_type']:'text',
|
38 |
+
'meta_default'=> isset($item['meta_default'])?$item['meta_default']:'',
|
39 |
+
'meta_context'=> $item['meta_context'],
|
40 |
+
);
|
41 |
+
if (isset($this->fields[$meta_key])){
|
42 |
+
$new['id'] = $this->fields[$meta_key]['id'];
|
43 |
+
$this->fields[$meta_key] = $new;
|
44 |
+
}
|
45 |
+
else{
|
46 |
+
$this->fields[$meta_key] = $new;
|
47 |
+
}
|
48 |
+
$this->save($this->fields[$meta_key]);
|
49 |
+
return $this;
|
50 |
+
}
|
51 |
+
public function get($meta_key, $default=''){
|
52 |
+
$meta_key = preg_replace('|[^A-Z0-9_]|i', '', $meta_key);
|
53 |
+
if (isset($this->fields[$meta_key])){
|
54 |
+
return maybe_unserialize($this->fields[$meta_key]['meta_value']);
|
55 |
+
|
56 |
+
}
|
57 |
+
return $default;
|
58 |
+
}
|
59 |
+
public function get_by_context($context){
|
60 |
+
$result = array();
|
61 |
+
foreach ($this->fields as $key=>$field){
|
62 |
+
if ($field['meta_context'] == $context){
|
63 |
+
$result[$key] = $field;
|
64 |
+
}
|
65 |
+
}
|
66 |
+
return $result;
|
67 |
+
}
|
68 |
+
private function save($field){
|
69 |
+
global $wpdb;
|
70 |
+
if (!isset($field['meta_key'])){retern;} // cannot continue without key field.
|
71 |
+
$meta_key = preg_replace('|[^A-Z0-9_]|i', '', $field['meta_key']);
|
72 |
+
$query = $wpdb->prepare(
|
73 |
+
'REPLACE INTO ' . $wpdb->prefix. 'swpm_membership_meta_tbl
|
74 |
+
(level_id, meta_key, meta_label, meta_value, meta_type, meta_default, meta_context)
|
75 |
+
VALUES(%d, %s, %s, %s, %s, %s, %s); ',
|
76 |
+
$this->level_id,
|
77 |
+
$meta_key,
|
78 |
+
isset($field['meta_label'])? sanitize_text_field($field['meta_label']): '',
|
79 |
+
isset($field['meta_value'])? sanitize_text_field($field['meta_value']): '',
|
80 |
+
'text', // at the moment we have only one type
|
81 |
+
'',
|
82 |
+
isset($field['meta_context'])? sanitize_text_field($field['meta_context']): 'default'
|
83 |
+
);
|
84 |
+
|
85 |
+
$wpdb->query($query);
|
86 |
+
}
|
87 |
+
public static function get_value_by_key($level_id, $key, $default= ''){
|
88 |
+
return SwpmMembershipLevelCustom::get_instance_by_id($level_id)->get($key, $default);
|
89 |
+
}
|
90 |
+
public static function get_value_by_context($level_id, $context){
|
91 |
+
return SwpmMembershipLevelCustom::get_instance_by_id($level_id)->get_by_context($context);
|
92 |
+
}
|
93 |
+
}
|
classes/class.swpm-membership-level-utils.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* BMembershipLevelUtils
|
5 |
+
*
|
6 |
+
* @author nur
|
7 |
+
*/
|
8 |
+
class SwpmMembershipLevelUtils {
|
9 |
+
|
10 |
+
}
|
classes/class.swpm-membership-level.php
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Description of BMembershipLevel
|
5 |
+
*
|
6 |
+
* @author nur
|
7 |
+
*/
|
8 |
+
class SwpmMembershipLevel {
|
9 |
+
const NO_EXPIRY = 0;
|
10 |
+
const DAYS = 1;
|
11 |
+
const WEEKS = 2;
|
12 |
+
const MONTHS = 3;
|
13 |
+
const YEARS = 4;
|
14 |
+
const FIXED_DATE = 5;
|
15 |
+
|
16 |
+
private static $_instance = null;
|
17 |
+
|
18 |
+
private function __construct() {
|
19 |
+
;
|
20 |
+
}
|
21 |
+
|
22 |
+
public static function get_instance() {
|
23 |
+
self::$_instance = empty(self::$_instance) ? new SwpmMembershipLevel() : self::$_instance;
|
24 |
+
return self::$_instance;
|
25 |
+
}
|
26 |
+
|
27 |
+
public function create() {
|
28 |
+
global $wpdb;
|
29 |
+
$level = SwpmTransfer::$default_level_fields;
|
30 |
+
$form = new SwpmLevelForm($level);
|
31 |
+
if ($form->is_valid()) {
|
32 |
+
$level_info = $form->get_sanitized();
|
33 |
+
$wpdb->insert($wpdb->prefix . "swpm_membership_tbl", $level_info);
|
34 |
+
$id = $wpdb->insert_id;
|
35 |
+
$custom = apply_filters('swpm_admin_add_membership_level', array());
|
36 |
+
$this->save_custom_fields($id, $custom);
|
37 |
+
$message = array('succeeded' => true, 'message' => SwpmUtils::_('Membership Level Creation Successful.'));
|
38 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
39 |
+
wp_redirect('admin.php?page=simple_wp_membership_levels');
|
40 |
+
return;
|
41 |
+
}
|
42 |
+
$message = array('succeeded' => false, 'message' => SwpmUtils::_('Please correct the following:'), 'extra' => $form->get_errors());
|
43 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
44 |
+
}
|
45 |
+
|
46 |
+
public function edit($id) {
|
47 |
+
global $wpdb;
|
48 |
+
$query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id = %d", $id);
|
49 |
+
$level = $wpdb->get_row($query, ARRAY_A);
|
50 |
+
$form = new SwpmLevelForm($level);
|
51 |
+
if ($form->is_valid()) {
|
52 |
+
$wpdb->update($wpdb->prefix . "swpm_membership_tbl", $form->get_sanitized(), array('id' => $id));
|
53 |
+
//@todo meta table and collect all relevant info and pass as argument
|
54 |
+
$custom = apply_filters('swpm_admin_edit_membership_level', array(), $id);
|
55 |
+
$this->save_custom_fields($id, $custom);
|
56 |
+
$message = array('succeeded' => true, 'message' => SwpmUtils::_('Updated Successfully.'));
|
57 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
58 |
+
wp_redirect('admin.php?page=simple_wp_membership_levels');
|
59 |
+
return;
|
60 |
+
}
|
61 |
+
$message = array('succeeded' => false, 'message' => SwpmUtils::_('Please correct the following:'), 'extra' => $form->get_errors());
|
62 |
+
SwpmTransfer::get_instance()->set('status', $message);
|
63 |
+
}
|
64 |
+
private function save_custom_fields($level_id, $data){
|
65 |
+
$custom_obj = SwpmMembershipLevelCustom::get_instance_by_id($level_id);
|
66 |
+
foreach ($data as $item){
|
67 |
+
$custom_obj->set($item);
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
classes/class.swpm-membership-levels.php
ADDED
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!class_exists('WP_List_Table'))
|
4 |
+
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
5 |
+
|
6 |
+
class SwpmMembershipLevels extends WP_List_Table {
|
7 |
+
|
8 |
+
function __construct() {
|
9 |
+
parent::__construct(array(
|
10 |
+
'singular' => SwpmUtils::_('Membership Level'),
|
11 |
+
'plural' => SwpmUtils::_('Membership Levels'),
|
12 |
+
'ajax' => false
|
13 |
+
));
|
14 |
+
}
|
15 |
+
|
16 |
+
function get_columns() {
|
17 |
+
return array(
|
18 |
+
'cb' => '<input type="checkbox" />'
|
19 |
+
, 'id' => SwpmUtils::_('ID')
|
20 |
+
, 'alias' => SwpmUtils::_('Membership Level')
|
21 |
+
, 'role' => SwpmUtils::_('Role')
|
22 |
+
, 'valid_for' => SwpmUtils::_('Access Valid For/Until')
|
23 |
+
);
|
24 |
+
}
|
25 |
+
|
26 |
+
function get_sortable_columns() {
|
27 |
+
return array(
|
28 |
+
'id' => array('id', true),
|
29 |
+
'alias' => array('alias', true)
|
30 |
+
);
|
31 |
+
}
|
32 |
+
|
33 |
+
function get_bulk_actions() {
|
34 |
+
$actions = array(
|
35 |
+
'bulk_delete' => SwpmUtils::_('Delete')
|
36 |
+
);
|
37 |
+
return $actions;
|
38 |
+
}
|
39 |
+
|
40 |
+
function column_default($item, $column_name) {
|
41 |
+
if ($column_name == 'valid_for') {
|
42 |
+
if ($item['subscription_duration_type'] == SwpmMembershipLevel::NO_EXPIRY) {
|
43 |
+
return 'No Expiry';
|
44 |
+
}
|
45 |
+
if ($item['subscription_duration_type'] == SwpmMembershipLevel::FIXED_DATE) {
|
46 |
+
return date(get_option('date_format'), strtotime($item['subscription_period']));
|
47 |
+
}
|
48 |
+
if ($item['subscription_duration_type'] == SwpmMembershipLevel::DAYS) {
|
49 |
+
return $item['subscription_period'] . " Day(s)";
|
50 |
+
}
|
51 |
+
if ($item['subscription_duration_type'] == SwpmMembershipLevel::WEEKS) {
|
52 |
+
return $item['subscription_period'] . " Week(s)";
|
53 |
+
}
|
54 |
+
if ($item['subscription_duration_type'] == SwpmMembershipLevel::MONTHS) {
|
55 |
+
return $item['subscription_period'] . " Month(s)";
|
56 |
+
}
|
57 |
+
if ($item['subscription_duration_type'] == SwpmMembershipLevel::YEARS) {
|
58 |
+
return $item['subscription_period'] . " Year(s)";
|
59 |
+
}
|
60 |
+
}
|
61 |
+
if ($column_name == 'role') {
|
62 |
+
return ucfirst($item['role']);
|
63 |
+
}
|
64 |
+
return stripslashes($item[$column_name]);
|
65 |
+
}
|
66 |
+
|
67 |
+
function column_id($item) {
|
68 |
+
$actions = array(
|
69 |
+
'edit' => sprintf('<a href="admin.php?page=%s&level_action=edit&id=%s">Edit</a>', $_REQUEST['page'], $item['id']),
|
70 |
+
'delete' => sprintf('<a href="?page=%s&level_action=delete&id=%s"
|
71 |
+
onclick="return confirm(\'Are you sure you want to delete this entry?\')">Delete</a>', $_REQUEST['page'], $item['id']),
|
72 |
+
);
|
73 |
+
return $item['id'] . $this->row_actions($actions);
|
74 |
+
}
|
75 |
+
|
76 |
+
function column_cb($item) {
|
77 |
+
return sprintf(
|
78 |
+
'<input type="checkbox" name="ids[]" value="%s" />', $item['id']
|
79 |
+
);
|
80 |
+
}
|
81 |
+
|
82 |
+
function prepare_items() {
|
83 |
+
global $wpdb;
|
84 |
+
$query = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
|
85 |
+
if (isset($_POST['s']))
|
86 |
+
$query .= " AND alias LIKE '%" . strip_tags($_POST['s']) . "%' ";
|
87 |
+
$orderby = !empty($_GET["orderby"]) ? mysql_real_escape_string($_GET["orderby"]) : 'id';
|
88 |
+
$order = !empty($_GET["order"]) ? mysql_real_escape_string($_GET["order"]) : 'DESC';
|
89 |
+
|
90 |
+
$sortable_columns = $this->get_sortable_columns();
|
91 |
+
$orderby = SwpmUtils::sanitize_value_by_array($orderby, $sortable_columns);
|
92 |
+
$order = SwpmUtils::sanitize_value_by_array($order, array('DESC' => '1', 'ASC' => '1'));
|
93 |
+
|
94 |
+
if (!empty($orderby) && !empty($order)) {
|
95 |
+
$query.=' ORDER BY ' . $orderby . ' ' . $order;
|
96 |
+
}
|
97 |
+
|
98 |
+
$totalitems = $wpdb->query($query); //return the total number of affected rows
|
99 |
+
$perpage = 20;
|
100 |
+
$paged = !empty($_GET["paged"]) ? mysql_real_escape_string($_GET["paged"]) : '';
|
101 |
+
if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
|
102 |
+
$paged = 1;
|
103 |
+
}
|
104 |
+
$totalpages = ceil($totalitems / $perpage);
|
105 |
+
if (!empty($paged) && !empty($perpage)) {
|
106 |
+
$offset = ($paged - 1) * $perpage;
|
107 |
+
$query.=' LIMIT ' . (int) $offset . ',' . (int) $perpage;
|
108 |
+
}
|
109 |
+
$this->set_pagination_args(array(
|
110 |
+
"total_items" => $totalitems,
|
111 |
+
"total_pages" => $totalpages,
|
112 |
+
"per_page" => $perpage,
|
113 |
+
));
|
114 |
+
|
115 |
+
$columns = $this->get_columns();
|
116 |
+
$hidden = array();
|
117 |
+
$sortable = $this->get_sortable_columns();
|
118 |
+
|
119 |
+
$this->_column_headers = array($columns, $hidden, $sortable);
|
120 |
+
$this->items = $wpdb->get_results($query, ARRAY_A);
|
121 |
+
}
|
122 |
+
|
123 |
+
function no_items() {
|
124 |
+
SwpmUtils::e('No membership levels found.');
|
125 |
+
}
|
126 |
+
|
127 |
+
function process_form_request() {
|
128 |
+
if (isset($_REQUEST['id'])) {
|
129 |
+
return $this->edit($_REQUEST['id']);
|
130 |
+
}
|
131 |
+
return $this->add();
|
132 |
+
}
|
133 |
+
|
134 |
+
function add() {
|
135 |
+
global $wpdb;
|
136 |
+
$member = SwpmTransfer::$default_fields;
|
137 |
+
if (isset($_POST['createswpmlevel'])) {
|
138 |
+
$member = $_POST;
|
139 |
+
}
|
140 |
+
extract($member, EXTR_SKIP);
|
141 |
+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_add_level.php');
|
142 |
+
return false;
|
143 |
+
}
|
144 |
+
|
145 |
+
function edit($id) {
|
146 |
+
global $wpdb;
|
147 |
+
$query = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}swpm_membership_tbl WHERE id = %d", absint($id));
|
148 |
+
$membership = $wpdb->get_row($query, ARRAY_A);
|
149 |
+
extract($membership, EXTR_SKIP);
|
150 |
+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_edit_level.php');
|
151 |
+
return false;
|
152 |
+
}
|
153 |
+
|
154 |
+
function delete() {
|
155 |
+
global $wpdb;
|
156 |
+
if (isset($_REQUEST['ids'])) {
|
157 |
+
$members = $_REQUEST['ids'];
|
158 |
+
if (!empty($members)) {
|
159 |
+
$members = array_map('absint', $members);
|
160 |
+
$members = implode(',', $members);
|
161 |
+
$query = "DELETE FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id IN (" . $members . ")";
|
162 |
+
$wpdb->query($query);
|
163 |
+
}
|
164 |
+
} else if (isset($_REQUEST['id'])) {
|
165 |
+
$id = absint($_REQUEST['id']);
|
166 |
+
$query = $wpdb->prepare("DELETE FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id = %d", $id);
|
167 |
+
$wpdb->query($query);
|
168 |
+
}
|
169 |
+
}
|
170 |
+
|
171 |
+
function show() {
|
172 |
+
$selected = 1;
|
173 |
+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_membership_levels.php');
|
174 |
+
}
|
175 |
+
|
176 |
+
function manage() {
|
177 |
+
$selected = 2;
|
178 |
+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_membership_manage.php');
|
179 |
+
}
|
180 |
+
|
181 |
+
function manage_categroy() {
|
182 |
+
$selected = 3;
|
183 |
+
include_once('class.swpm-category-list.php');
|
184 |
+
$category_list = new SwpmCategoryList();
|
185 |
+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_category_list.php');
|
186 |
+
}
|
187 |
+
|
188 |
+
}
|
classes/class.swpm-messages.php
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
*
|
5 |
+
* @author nur
|
6 |
+
*/
|
7 |
+
class SwpmMessages {
|
8 |
+
private $messages;
|
9 |
+
public function __construct() {
|
10 |
+
$this->messages = array();
|
11 |
+
}
|
12 |
+
public function get($key){
|
13 |
+
if(isset($this->messages[$key])){
|
14 |
+
$m = $this->messages[$key];
|
15 |
+
$this->messages[$key] ='';
|
16 |
+
return $m;
|
17 |
+
}
|
18 |
+
return '';
|
19 |
+
}
|
20 |
+
public function set($key, $value){
|
21 |
+
$this->messages[$key] = $value;
|
22 |
+
}
|
23 |
+
}
|
classes/class.swpm-misc-utils.php
ADDED
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(array('ID' => $join_page_obj->ID, 'post_status' => 'publish'));
|
43 |
+
}
|
44 |
+
}
|
45 |
+
$swpm_join_page_permalink = get_permalink($join_page_id);
|
46 |
+
$settings->set_value('join-us-page-url', $swpm_join_page_permalink);
|
47 |
+
|
48 |
+
//Create registration page
|
49 |
+
$swpm_rego_page = array(
|
50 |
+
'post_title' => SwpmUtils::_('Registration'),
|
51 |
+
'post_name' => 'membership-registration',
|
52 |
+
'post_content' => '[swpm_registration_form]',
|
53 |
+
'post_parent' => $join_page_id,
|
54 |
+
'post_status' => 'publish',
|
55 |
+
'post_type' => 'page',
|
56 |
+
'comment_status' => 'closed',
|
57 |
+
'ping_status' => 'closed'
|
58 |
+
);
|
59 |
+
$rego_page_obj = get_page_by_path('membership-registration');
|
60 |
+
if (!$rego_page_obj) {
|
61 |
+
$rego_page_id = wp_insert_post($swpm_rego_page);
|
62 |
+
} else {
|
63 |
+
$rego_page_id = $rego_page_obj->ID;
|
64 |
+
if ($rego_page_obj->post_status == 'trash') { //For cases where page may be in trash, bring it out of trash
|
65 |
+
wp_update_post(array('ID' => $rego_page_obj->ID, 'post_status' => 'publish'));
|
66 |
+
}
|
67 |
+
}
|
68 |
+
$swpm_rego_page_permalink = get_permalink($rego_page_id);
|
69 |
+
$settings->set_value('registration-page-url', $swpm_rego_page_permalink);
|
70 |
+
|
71 |
+
//Create login page
|
72 |
+
$swpm_login_page = array(
|
73 |
+
'post_title' => SwpmUtils::_('Member Login'),
|
74 |
+
'post_name' => 'membership-login',
|
75 |
+
'post_content' => '[swpm_login_form]',
|
76 |
+
'post_parent' => 0,
|
77 |
+
'post_status' => 'publish',
|
78 |
+
'post_type' => 'page',
|
79 |
+
'comment_status' => 'closed',
|
80 |
+
'ping_status' => 'closed'
|
81 |
+
);
|
82 |
+
$login_page_obj = get_page_by_path('membership-login');
|
83 |
+
if (!$login_page_obj) {
|
84 |
+
$login_page_id = wp_insert_post($swpm_login_page);
|
85 |
+
} else {
|
86 |
+
$login_page_id = $login_page_obj->ID;
|
87 |
+
if ($login_page_obj->post_status == 'trash') { //For cases where page may be in trash, bring it out of trash
|
88 |
+
wp_update_post(array('ID' => $login_page_obj->ID, 'post_status' => 'publish'));
|
89 |
+
}
|
90 |
+
}
|
91 |
+
$swpm_login_page_permalink = get_permalink($login_page_id);
|
92 |
+
$settings->set_value('login-page-url', $swpm_login_page_permalink);
|
93 |
+
|
94 |
+
//Create profile page
|
95 |
+
$swpm_profile_page = array(
|
96 |
+
'post_title' => SwpmUtils::_('Profile'),
|
97 |
+
'post_name' => 'membership-profile',
|
98 |
+
'post_content' => '[swpm_profile_form]',
|
99 |
+
'post_parent' => $login_page_id,
|
100 |
+
'post_status' => 'publish',
|
101 |
+
'post_type' => 'page',
|
102 |
+
'comment_status' => 'closed',
|
103 |
+
'ping_status' => 'closed'
|
104 |
+
);
|
105 |
+
$profile_page_obj = get_page_by_path('membership-profile');
|
106 |
+
if (!$profile_page_obj) {
|
107 |
+
$profile_page_id = wp_insert_post($swpm_profile_page);
|
108 |
+
} else {
|
109 |
+
$profile_page_id = $profile_page_obj->ID;
|
110 |
+
if ($profile_page_obj->post_status == 'trash') { //For cases where page may be in trash, bring it out of trash
|
111 |
+
wp_update_post(array('ID' => $profile_page_obj->ID, 'post_status' => 'publish'));
|
112 |
+
}
|
113 |
+
}
|
114 |
+
$swpm_profile_page_permalink = get_permalink($profile_page_id);
|
115 |
+
$settings->set_value('profile-page-url', $swpm_profile_page_permalink);
|
116 |
+
|
117 |
+
//Create reset page
|
118 |
+
$swpm_reset_page = array(
|
119 |
+
'post_title' => SwpmUtils::_('Password Reset'),
|
120 |
+
'post_name' => 'password-reset',
|
121 |
+
'post_content' => '[swpm_reset_form]',
|
122 |
+
'post_parent' => $login_page_id,
|
123 |
+
'post_status' => 'publish',
|
124 |
+
'post_type' => 'page',
|
125 |
+
'comment_status' => 'closed',
|
126 |
+
'ping_status' => 'closed'
|
127 |
+
);
|
128 |
+
$reset_page_obj = get_page_by_path('password-reset');
|
129 |
+
if (!$profile_page_obj) {
|
130 |
+
$reset_page_id = wp_insert_post($swpm_reset_page);
|
131 |
+
} else {
|
132 |
+
$reset_page_id = $reset_page_obj->ID;
|
133 |
+
if ($reset_page_obj->post_status == 'trash') { //For cases where page may be in trash, bring it out of trash
|
134 |
+
wp_update_post(array('ID' => $reset_page_obj->ID, 'post_status' => 'publish'));
|
135 |
+
}
|
136 |
+
}
|
137 |
+
$swpm_reset_page_permalink = get_permalink($reset_page_id);
|
138 |
+
$settings->set_value('reset-page-url', $swpm_reset_page_permalink);
|
139 |
+
|
140 |
+
$settings->save(); //Save all settings object changes
|
141 |
+
}
|
142 |
+
|
143 |
+
public static function reset_swmp_log_files() {
|
144 |
+
$log_reset = true;
|
145 |
+
$logfile_list = array(
|
146 |
+
SIMPLE_WP_MEMBERSHIP_PATH.'/log.txt',
|
147 |
+
);
|
148 |
+
|
149 |
+
foreach ($logfile_list as $logfile) {
|
150 |
+
if (empty($logfile)) {
|
151 |
+
continue;
|
152 |
+
}
|
153 |
+
|
154 |
+
$text = '[' . date('m/d/Y g:i A') . '] - SUCCESS : Log file reset';
|
155 |
+
$text .= "\n------------------------------------------------------------------\n\n";
|
156 |
+
$fp = fopen($logfile, 'w');
|
157 |
+
if ($fp != FALSE) {
|
158 |
+
@fwrite($fp, $text);
|
159 |
+
@fclose($fp);
|
160 |
+
} else {
|
161 |
+
$log_reset = false;
|
162 |
+
}
|
163 |
+
}
|
164 |
+
return $log_reset;
|
165 |
+
}
|
166 |
+
|
167 |
+
}
|
classes/class.swpm-notification-bus.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Description of BNotificationBus
|
5 |
+
*
|
6 |
+
* @author nur
|
7 |
+
*/
|
8 |
+
class SwpmNotificationBus {
|
9 |
+
|
10 |
+
}
|
classes/class.swpm-permission-collection.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* To change this license header, choose License Headers in Project Properties.
|
5 |
+
* To change this template file, choose Tools | Templates
|
6 |
+
* and open the template in the editor.
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Description of bPermissionCollection
|
11 |
+
*
|
12 |
+
* @author nur
|
13 |
+
*/
|
14 |
+
class SwpmPermissionCollection {
|
15 |
+
protected $permissions;
|
16 |
+
protected static $instance;
|
17 |
+
|
18 |
+
protected function __construct() {
|
19 |
+
$this->permissions = array();
|
20 |
+
}
|
21 |
+
|
22 |
+
public static function get_instance(){
|
23 |
+
self::$_this = empty(self::$_this)? new SwpmPermissionCollection():self::$_this;
|
24 |
+
return self::$_this;
|
25 |
+
}
|
26 |
+
|
27 |
+
public function load($level_ids = array()){
|
28 |
+
if (empty($level_ids)){
|
29 |
+
global $wpdb;
|
30 |
+
$level_ids = $wpdb->get_col("SELECT id FROM {$wpdb->prefix}swpm_membership_tbl WHERE id != 1");
|
31 |
+
}
|
32 |
+
|
33 |
+
foreach($level_ids as $id){
|
34 |
+
$this->permissions[] = SwpmPermission::get_instance($id);
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
public function get_permitted_levels($post_id){
|
39 |
+
$levels = array();
|
40 |
+
|
41 |
+
foreach($this->permissions as $permission){
|
42 |
+
if ($permission->is_permitted($post_id)){
|
43 |
+
$levels[$permission->get($id)] = $permission->get('alias');
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
return $levels;
|
48 |
+
}
|
49 |
+
}
|
classes/class.swpm-permission.php
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
include_once('class.swpm-protection-base.php');
|
4 |
+
|
5 |
+
class SwpmPermission extends SwpmProtectionBase {
|
6 |
+
|
7 |
+
private static $_this = array();
|
8 |
+
|
9 |
+
private function __construct($level_id) {
|
10 |
+
$this->init($level_id);
|
11 |
+
}
|
12 |
+
|
13 |
+
public static function get_instance($level_id) {
|
14 |
+
if ($level_id == 1 || $level_id == md5(1)) {
|
15 |
+
wp_die('Invalid Membership level!');
|
16 |
+
}
|
17 |
+
$key = is_numeric($level_id) ? md5($level_id) : $level_id;
|
18 |
+
if (!isset(self::$_this[$key])) {
|
19 |
+
self::$_this[$key] = new SwpmPermission($level_id);
|
20 |
+
}
|
21 |
+
|
22 |
+
return self::$_this[$key];
|
23 |
+
}
|
24 |
+
|
25 |
+
public function is_permitted($id) {
|
26 |
+
return $this->post_in_parent_categories($id) || $this->post_in_categories($id) || $this->in_posts($id) || $this->in_pages($id) || $this->in_attachments($id) || $this->in_custom_posts($id);
|
27 |
+
}
|
28 |
+
|
29 |
+
public function is_permitted_attachment($id) {
|
30 |
+
return (($this->bitmap & 16) === 16) && $this->in_attachments($id);
|
31 |
+
}
|
32 |
+
|
33 |
+
public function is_permitted_custom_post($id) {
|
34 |
+
return (($this->bitmap & 32) === 32) && $this->in_custom_posts($id);
|
35 |
+
}
|
36 |
+
|
37 |
+
public function is_permitted_category($id) {
|
38 |
+
return (($this->bitmap & 1) === 1) && $this->in_categories($id);
|
39 |
+
}
|
40 |
+
|
41 |
+
public function is_post_in_permitted_category($post_id) {
|
42 |
+
return (($this->bitmap & 1) === 1) && $this->post_in_categories($post_id);
|
43 |
+
}
|
44 |
+
|
45 |
+
public function is_permitted_post($id) {
|
46 |
+
return (($this->bitmap & 4) === 4) && $this->in_posts($id);
|
47 |
+
}
|
48 |
+
|
49 |
+
public function is_permitted_page($id) {
|
50 |
+
return (($this->bitmap & 8) === 8) && $this->in_pages($id);
|
51 |
+
}
|
52 |
+
|
53 |
+
public function is_permitted_comment($id) {
|
54 |
+
return (($this->bitmap & 2) === 2) && $this->in_comments($id);
|
55 |
+
}
|
56 |
+
|
57 |
+
public function is_post_in_permitted_parent_category($post_id) {
|
58 |
+
return (($this->bitmap & 1) === 1) && $this->post_in_parent_categories($post_id);
|
59 |
+
}
|
60 |
+
|
61 |
+
public function is_permitted_parent_category($id) {
|
62 |
+
return (($this->bitmap & 1) === 1) && $this->in_parent_categories($id);
|
63 |
+
}
|
64 |
+
|
65 |
+
}
|
classes/class.swpm-protection-base.php
ADDED
@@ -0,0 +1,296 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
abstract class SwpmProtectionBase {
|
4 |
+
|
5 |
+
protected $bitmap;
|
6 |
+
protected $posts;
|
7 |
+
protected $pages;
|
8 |
+
protected $comments;
|
9 |
+
protected $categories;
|
10 |
+
protected $attachments;
|
11 |
+
protected $custom_posts;
|
12 |
+
protected $details;
|
13 |
+
protected $options;
|
14 |
+
|
15 |
+
private function __construct() {
|
16 |
+
|
17 |
+
}
|
18 |
+
|
19 |
+
protected function init($level_id) {
|
20 |
+
global $wpdb;
|
21 |
+
$this->owning_level_id = $level_id;
|
22 |
+
$query = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}swpm_membership_tbl WHERE "
|
23 |
+
. (is_numeric($level_id) ? 'id = %d' : 'md5(id) = %s' ), $level_id);
|
24 |
+
$result = $wpdb->get_row($query);
|
25 |
+
|
26 |
+
$this->bitmap = isset($result->permissions) ? $result->permissions : 0;
|
27 |
+
$this->posts = isset($result->post_list) ? (array) unserialize($result->post_list) : array();
|
28 |
+
$this->pages = isset($result->page_list) ? (array) unserialize($result->page_list) : array();
|
29 |
+
$this->comments = isset($result->comment_list) ? (array) unserialize($result->comment_list) : array();
|
30 |
+
$this->categories = isset($result->category_list) ? (array) unserialize($result->category_list) : array();
|
31 |
+
$this->attachments = isset($result->attachment_list) ? (array) unserialize($result->attachment_list) : array();
|
32 |
+
$this->custom_posts = isset($result->custom_post_list) ? (array) unserialize($result->custom_post_list) : array();
|
33 |
+
$this->options = isset($result->options) ? (array) unserialize($result->options) : array();
|
34 |
+
$this->disable_bookmark = isset($result->disable_bookmark_list) ? (array) unserialize($result->disable_bookmark_list) : array();
|
35 |
+
$this->details = (array) $result;
|
36 |
+
}
|
37 |
+
|
38 |
+
public function apply($ids, $type) {
|
39 |
+
$post_types = get_post_types(array('public' => true, '_builtin' => false));
|
40 |
+
if (in_array($type, $post_types)) {
|
41 |
+
$type = 'custom_post';
|
42 |
+
}
|
43 |
+
return $this->update_perms($ids, true, $type);
|
44 |
+
}
|
45 |
+
|
46 |
+
public function remove($ids, $type) {
|
47 |
+
$post_types = get_post_types(array('public' => true, '_builtin' => false));
|
48 |
+
if (in_array($type, $post_types)) {
|
49 |
+
$type = 'custom_post';
|
50 |
+
}
|
51 |
+
return $this->update_perms($ids, false, $type);
|
52 |
+
}
|
53 |
+
|
54 |
+
public function get_options() {
|
55 |
+
return $this->options;
|
56 |
+
}
|
57 |
+
|
58 |
+
public function get_posts() {
|
59 |
+
return $this->posts;
|
60 |
+
}
|
61 |
+
|
62 |
+
public function get_pages() {
|
63 |
+
return $this->pages;
|
64 |
+
}
|
65 |
+
|
66 |
+
public function get_comments() {
|
67 |
+
return $this->comments;
|
68 |
+
}
|
69 |
+
|
70 |
+
public function get_categories() {
|
71 |
+
return $this->categories;
|
72 |
+
}
|
73 |
+
|
74 |
+
public function get_attachments() {
|
75 |
+
return $this->attachments;
|
76 |
+
}
|
77 |
+
|
78 |
+
public function get_custom_posts() {
|
79 |
+
return $this->custom_posts;
|
80 |
+
}
|
81 |
+
|
82 |
+
public function is_bookmark_disabled($id) {
|
83 |
+
$posts = isset($this->disable_bookmark['posts']) ?
|
84 |
+
(array) $this->disable_bookmark['posts'] : array();
|
85 |
+
$pages = isset($this->disable_bookmark['pages']) ?
|
86 |
+
(array) $this->disable_bookmark['pages'] : array();
|
87 |
+
return in_array($id, $pages) || in_array($id, $posts);
|
88 |
+
}
|
89 |
+
|
90 |
+
public function in_posts($id) {
|
91 |
+
return (/* ($this->bitmap&4)===4) && */in_array($id, (array) $this->posts));
|
92 |
+
}
|
93 |
+
|
94 |
+
public function in_pages($id) {
|
95 |
+
return (/* ($this->bitmap&8)===8) && */ in_array($id, (array) $this->pages));
|
96 |
+
}
|
97 |
+
|
98 |
+
public function in_attachments($id) {
|
99 |
+
return (/* ($this->bitmap&16)===16) && */in_array($id, (array) $this->attachments));
|
100 |
+
}
|
101 |
+
|
102 |
+
public function in_custom_posts($id) {
|
103 |
+
return (/* ($this->bitmap&32)===32) && */ in_array($id, (array) $this->custom_posts));
|
104 |
+
}
|
105 |
+
|
106 |
+
public function in_comments($id) {
|
107 |
+
return (/* ($this->bitmap&2)===2) && */ in_array($id, (array) $this->comments));
|
108 |
+
}
|
109 |
+
|
110 |
+
public function in_categories($id) {
|
111 |
+
if (empty($this->categories))
|
112 |
+
return false;
|
113 |
+
return (/* ($this->bitmap&1)===1) && */ in_array($id, (array) $this->categories));
|
114 |
+
}
|
115 |
+
|
116 |
+
public function post_in_categories($post_id) {
|
117 |
+
if (empty($this->categories))
|
118 |
+
return false;
|
119 |
+
return (/* ($this->bitmap&1)===1) && */ in_category((array) $this->categories, $post_id));
|
120 |
+
}
|
121 |
+
|
122 |
+
public function in_parent_categories($id) {
|
123 |
+
if (empty($this->categories))
|
124 |
+
return false;
|
125 |
+
$parents = explode(',', get_category_parents($id, false, ','));
|
126 |
+
$parents = array_unique($parents);
|
127 |
+
foreach ($parents as $parent) {
|
128 |
+
if (empty($parent))
|
129 |
+
continue;
|
130 |
+
if (/* (($this->bitmap&1)===1) && */(in_array($parent, (array) $this->categories)))
|
131 |
+
return true;
|
132 |
+
}
|
133 |
+
return false;
|
134 |
+
}
|
135 |
+
|
136 |
+
public function post_in_parent_categories($post_id) {
|
137 |
+
if (empty($this->categories))
|
138 |
+
return false;
|
139 |
+
$cats = get_the_category($post_id);
|
140 |
+
$parents = array();
|
141 |
+
foreach ($cats as $key => $cat) {
|
142 |
+
$parents = array_merge($parents, explode(',', get_category_parents($cat->cat_ID, false, ',')));
|
143 |
+
}
|
144 |
+
$parents = array_unique($parents);
|
145 |
+
foreach ($parents as $parent) {
|
146 |
+
if (empty($parent))
|
147 |
+
continue;
|
148 |
+
if (/* (($this->bitmap&1)===1) && */(in_array(get_cat_ID($parent), (array) $this->categories)))
|
149 |
+
return true;
|
150 |
+
}
|
151 |
+
return false;
|
152 |
+
}
|
153 |
+
|
154 |
+
public function add_posts($ids) {
|
155 |
+
return $this->update_perms($ids, true, 'post');
|
156 |
+
}
|
157 |
+
|
158 |
+
public function add_pages($ids) {
|
159 |
+
return $this->update_perms($ids, true, 'page');
|
160 |
+
}
|
161 |
+
|
162 |
+
public function add_attachments($ids) {
|
163 |
+
return $this->update_perms($ids, true, 'attachment');
|
164 |
+
}
|
165 |
+
|
166 |
+
public function add_comments($ids) {
|
167 |
+
return $this->update_perms($ids, true, 'comment');
|
168 |
+
}
|
169 |
+
|
170 |
+
public function add_categories($ids) {
|
171 |
+
return $this->update_perms($ids, true, 'category');
|
172 |
+
}
|
173 |
+
|
174 |
+
public function add_custom_posts($ids) {
|
175 |
+
return $this->update_perms($ids, true, 'custom_post');
|
176 |
+
}
|
177 |
+
|
178 |
+
public function remove_posts($ids) {
|
179 |
+
return $this->update_perms($ids, false, 'post');
|
180 |
+
}
|
181 |
+
|
182 |
+
public function remove_pages($ids) {
|
183 |
+
return $this->update_perms($ids, false, 'page');
|
184 |
+
}
|
185 |
+
|
186 |
+
public function remove_attachments($ids) {
|
187 |
+
return $this->update_perms($ids, false, 'attachment');
|
188 |
+
}
|
189 |
+
|
190 |
+
public function remove_comments($ids) {
|
191 |
+
return $this->update_perms($ids, false, 'comment');
|
192 |
+
}
|
193 |
+
|
194 |
+
public function remove_categories($ids) {
|
195 |
+
return $this->update_perms($ids, false, 'category');
|
196 |
+
}
|
197 |
+
|
198 |
+
public function remove_custom_posts($ids) {
|
199 |
+
return $this->update_perms($ids, false, 'custom_post');
|
200 |
+
}
|
201 |
+
|
202 |
+
private function update_perms($ids, $set, $type) {
|
203 |
+
$list = null;
|
204 |
+
$index = '';
|
205 |
+
if (empty($ids)) {
|
206 |
+
return $this;
|
207 |
+
}
|
208 |
+
$ids = (array) $ids;
|
209 |
+
switch ($type) {
|
210 |
+
case 'page':
|
211 |
+
$list = $this->pages;
|
212 |
+
$index = 'page_list';
|
213 |
+
break;
|
214 |
+
case 'post':
|
215 |
+
$list = $this->posts;
|
216 |
+
$index = 'post_list';
|
217 |
+
break;
|
218 |
+
case 'attachment':
|
219 |
+
$list = $this->attachments;
|
220 |
+
$index = 'attachment_list';
|
221 |
+
break;
|
222 |
+
case 'comment':
|
223 |
+
$list = $this->comments;
|
224 |
+
$index = 'comment_list';
|
225 |
+
break;
|
226 |
+
case 'category':
|
227 |
+
$list = $this->categories;
|
228 |
+
$index = 'category_list';
|
229 |
+
break;
|
230 |
+
case 'custom_post':
|
231 |
+
$list = $this->custom_posts;
|
232 |
+
$index = 'custom_post_list';
|
233 |
+
break;
|
234 |
+
default:
|
235 |
+
break;
|
236 |
+
}
|
237 |
+
|
238 |
+
if (!empty($index)) {
|
239 |
+
if ($set) {
|
240 |
+
$list = array_merge($list, $ids);
|
241 |
+
$list = array_unique($list);
|
242 |
+
} else {
|
243 |
+
$list = array_diff($list, $ids);
|
244 |
+
}
|
245 |
+
switch ($type) {
|
246 |
+
case 'page':
|
247 |
+
$this->pages = $list;
|
248 |
+
break;
|
249 |
+
case 'post':
|
250 |
+
$this->posts = $list;
|
251 |
+
break;
|
252 |
+
case 'attachment':
|
253 |
+
$this->attachments = $list;
|
254 |
+
break;
|
255 |
+
case 'comment':
|
256 |
+
$this->comments = $list;
|
257 |
+
break;
|
258 |
+
case 'category':
|
259 |
+
$this->categories = $list;
|
260 |
+
break;
|
261 |
+
case 'custom_post':
|
262 |
+
$this->custom_posts = $list;
|
263 |
+
break;
|
264 |
+
default:
|
265 |
+
break;
|
266 |
+
}
|
267 |
+
$this->details[$index] = $list;
|
268 |
+
}
|
269 |
+
return $this;
|
270 |
+
}
|
271 |
+
|
272 |
+
public function save() {
|
273 |
+
global $wpdb;
|
274 |
+
$data = array();
|
275 |
+
|
276 |
+
$list_type = array('page_list', 'post_list', 'attachment_list',
|
277 |
+
'custom_post_list', 'comment_list', 'category_list');
|
278 |
+
foreach ($this->details as $key => $value) {
|
279 |
+
if ($key == 'id')
|
280 |
+
continue;
|
281 |
+
if (is_serialized($value) || !in_array($key, $list_type))
|
282 |
+
$data[$key] = $value;
|
283 |
+
else
|
284 |
+
$data[$key] = serialize($value);
|
285 |
+
}
|
286 |
+
$wpdb->update($wpdb->prefix . "swpm_membership_tbl", $data, array('id' => $this->owning_level_id));
|
287 |
+
}
|
288 |
+
|
289 |
+
public function get($key, $default = '') {
|
290 |
+
if (isset($this->details[$key])) {
|
291 |
+
return $this->details[$key];
|
292 |
+
}
|
293 |
+
return $default;
|
294 |
+
}
|
295 |
+
|
296 |
+
}
|
classes/class.swpm-protection.php
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
include_once('class.swpm-protection-base.php');
|
4 |
+
|
5 |
+
class SwpmProtection extends SwpmProtectionBase {
|
6 |
+
|
7 |
+
private static $_this;
|
8 |
+
|
9 |
+
private function __construct() {
|
10 |
+
$this->msg = "";
|
11 |
+
$this->init(1);
|
12 |
+
}
|
13 |
+
|
14 |
+
public static function get_instance() {
|
15 |
+
self::$_this = empty(self::$_this) ? (new SwpmProtection()) : self::$_this;
|
16 |
+
return self::$_this;
|
17 |
+
}
|
18 |
+
|
19 |
+
public function is_protected($id) {
|
20 |
+
if ($this->post_in_parent_categories($id) || $this->post_in_categories($id)) {
|
21 |
+
$this->msg = '<p style="background: #FFF6D5; border: 1px solid #D1B655; color: #3F2502; margin: 10px 0px 10px 0px; padding: 5px 5px 5px 10px;">
|
22 |
+
The category or parent category of this post is protected. You can change the category protection settings from the <a href="admin.php?page=eMember_membership_level_menu&level_action=2" target="_blank">manage content protection</a> menu.
|
23 |
+
</p>';
|
24 |
+
return true;
|
25 |
+
}
|
26 |
+
return $this->in_posts($id) || $this->in_pages($id) || $this->in_attachments($id) || $this->in_custom_posts($id);
|
27 |
+
}
|
28 |
+
|
29 |
+
public function get_last_message() {
|
30 |
+
return $this->msg;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function is_protected_post($id) {
|
34 |
+
return /* (($this->bitmap&4) != 4) && */ $this->in_posts($id);
|
35 |
+
}
|
36 |
+
|
37 |
+
public function is_protected_page($id) {
|
38 |
+
return /* (($this->bitmap&4) != 4) && */ $this->in_pages($id);
|
39 |
+
}
|
40 |
+
|
41 |
+
public function is_protected_attachment($id) {
|
42 |
+
return /* (($this->bitmap&16)!=16) && */ $this->in_attachments($id);
|
43 |
+
}
|
44 |
+
|
45 |
+
public function is_protected_custom_post($id) {
|
46 |
+
return /* (($this->bitmap&32)!=32) && */ $this->in_custom_posts($id);
|
47 |
+
}
|
48 |
+
|
49 |
+
public function is_protected_comment($id) {
|
50 |
+
return /* (($this->bitmap&2)!=2) && */ $this->in_comments($id);
|
51 |
+
}
|
52 |
+
|
53 |
+
public function is_post_in_protected_category($post_id) {
|
54 |
+
return /* (($this->bitmap&1)!=1) && */ $this->post_in_categories($post_id);
|
55 |
+
}
|
56 |
+
|
57 |
+
public function is_post_in_protected_parent_category($post_id) {
|
58 |
+
return /* (($this->bitmap&1)!=1) && */ $this->post_in_parent_categories($post_id);
|
59 |
+
}
|
60 |
+
|
61 |
+
public function is_protected_category($id) {
|
62 |
+
return /* (($this->bitmap&1)!=1) && */ $this->in_categories($id);
|
63 |
+
}
|
64 |
+
|
65 |
+
public function is_protected_parent_category($id) {
|
66 |
+
return /* (($this->bitmap&1)!=1) && */ $this->in_parent_categories($id);
|
67 |
+
}
|
68 |
+
|
69 |
+
}
|
classes/class.swpm-registration.php
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Description of BRegistration
|
5 |
+
*
|
6 |
+
* @author nur
|
7 |
+
*/
|
8 |
+
abstract class SwpmRegistration {
|
9 |
+
protected $member_info = array();
|
10 |
+
protected static $_intance = null;
|
11 |
+
//public abstract static function get_instance();
|
12 |
+
protected function send_reg_email(){
|
13 |
+
global $wpdb;
|
14 |
+
if (empty($this->member_info)) {return false;}
|
15 |
+
$member_info = $this->member_info;
|
16 |
+
$settings = SwpmSettings::get_instance();
|
17 |
+
$subject = $settings->get_value('reg-complete-mail-subject');
|
18 |
+
$body = $settings->get_value('reg-complete-mail-body');
|
19 |
+
$from_address = $settings->get_value('email-from');
|
20 |
+
$login_link = $settings->get_value('login-page-url');
|
21 |
+
$headers = 'From: ' . $from_address . "\r\n";
|
22 |
+
$member_info['membership_level_name'] = SwpmPermission::get_instance($member_info['membership_level'])->get('alias');
|
23 |
+
$member_info['password'] = $member_info['plain_password'];
|
24 |
+
$member_info['login_link'] = $login_link;
|
25 |
+
$values = array_values($member_info);
|
26 |
+
$keys = array_map('swpm_enclose_var', array_keys($member_info));
|
27 |
+
$body = str_replace($keys, $values, $body);
|
28 |
+
$email = sanitize_email(filter_input(INPUT_POST, 'email', FILTER_UNSAFE_RAW));
|
29 |
+
wp_mail(trim($email), $subject, $body, $headers);
|
30 |
+
if ($settings->get_value('enable-admin-notification-after-reg')) {
|
31 |
+
$subject = "Notification of New Member Registration";
|
32 |
+
$body = "A new member has registered. The following email was sent to the member." .
|
33 |
+
"\n\n-------Member Email----------\n" . $body .
|
34 |
+
"\n\n------End------\n";
|
35 |
+
wp_mail($from_address, $subject, $body, $headers);
|
36 |
+
}
|
37 |
+
return true;
|
38 |
+
}
|
39 |
+
}
|
40 |
+
function swpm_enclose_var($n){
|
41 |
+
return '{'.$n .'}';
|
42 |
+
}
|
classes/class.swpm-session.php
ADDED
File without changes
|
classes/class.swpm-settings.php
ADDED
@@ -0,0 +1,395 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class SwpmSettings {
|
4 |
+
|
5 |
+
private static $_this;
|
6 |
+
private $settings;
|
7 |
+
public $current_tab;
|
8 |
+
private $tabs;
|
9 |
+
private function __construct() {
|
10 |
+
$this->settings = (array) get_option('swpm-settings');
|
11 |
+
}
|
12 |
+
public function init_config_hooks(){
|
13 |
+
$page = filter_input(INPUT_GET, 'page');
|
14 |
+
// if($page == 'simple_wp_membership_settings'){
|
15 |
+
if(is_admin()){ // for frontend just load settings but dont try to render settings page.
|
16 |
+
$tab = filter_input(INPUT_GET, 'tab');
|
17 |
+
$tab = empty($tab)?filter_input(INPUT_POST, 'tab'):$tab;
|
18 |
+
$this->current_tab = empty($tab) ? 1 : $tab;
|
19 |
+
$this->tabs = array(1=> 'General Settings', 2=> 'Payment Settings',
|
20 |
+
3=> 'Email Settings', 4=> 'Tools', 5=>'Advanced Settings', 6=> 'Addons Settings');
|
21 |
+
add_action('swpm-draw-tab', array(&$this, 'draw_tabs'));
|
22 |
+
$method = 'tab_' . $this->current_tab;
|
23 |
+
if (method_exists($this, $method)){
|
24 |
+
$this->$method();
|
25 |
+
}
|
26 |
+
}
|
27 |
+
}
|
28 |
+
private function tab_1() {
|
29 |
+
|
30 |
+
register_setting('swpm-settings-tab-1', 'swpm-settings', array(&$this, 'sanitize_tab_1'));
|
31 |
+
|
32 |
+
//This settings section has no heading
|
33 |
+
add_settings_section('swpm-general-post-submission-check', '',
|
34 |
+
array(&$this, 'swpm_general_post_submit_check_callback'), 'simple_wp_membership_settings');
|
35 |
+
|
36 |
+
add_settings_section('swpm-documentation', SwpmUtils::_('Plugin Documentation'),
|
37 |
+
array(&$this, 'swpm_documentation_callback'), 'simple_wp_membership_settings');
|
38 |
+
add_settings_section('general-settings', SwpmUtils::_('General Settings'),
|
39 |
+
array(&$this, 'general_settings_callback'), 'simple_wp_membership_settings');
|
40 |
+
add_settings_field('enable-free-membership', SwpmUtils::_('Enable Free Membership'),
|
41 |
+
array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'general-settings',
|
42 |
+
array('item' => 'enable-free-membership',
|
43 |
+
'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.')));
|
44 |
+
add_settings_field('free-membership-id', SwpmUtils::_('Free Membership Level ID'),
|
45 |
+
array(&$this, 'textfield_small_callback'), 'simple_wp_membership_settings', 'general-settings',
|
46 |
+
array('item' => 'free-membership-id',
|
47 |
+
'message'=> SwpmUtils::_('Assign free membership level ID')));
|
48 |
+
add_settings_field('enable-moretag', SwpmUtils::_('Enable More Tag Protection'),
|
49 |
+
array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'general-settings',
|
50 |
+
array('item' => 'enable-moretag',
|
51 |
+
'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.')));
|
52 |
+
add_settings_field('hide-adminbar', SwpmUtils::_('Hide Adminbar'),
|
53 |
+
array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'general-settings',
|
54 |
+
array('item' => 'hide-adminbar',
|
55 |
+
'message'=>SwpmUtils::_('WordPress shows an admin toolbar to the logged in users of the site. Check this box if you want to hide that admin toolbar in the fronend of your site.')));
|
56 |
+
|
57 |
+
add_settings_field('default-account-status', SwpmUtils::_('Default Account Status'),
|
58 |
+
array(&$this, 'selectbox_callback'), 'simple_wp_membership_settings', 'general-settings',
|
59 |
+
array('item' => 'default-account-status',
|
60 |
+
'options'=> SwpmUtils::get_account_state_options(),
|
61 |
+
'default'=>'active',
|
62 |
+
'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".')));
|
63 |
+
add_settings_field('allow-account-deletion', SwpmUtils::_('Allow Account Deletion'),
|
64 |
+
array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'general-settings',
|
65 |
+
array('item' => 'allow-account-deletion',
|
66 |
+
'options'=> SwpmUtils::get_account_state_options(),
|
67 |
+
'message'=>SwpmUtils::_('Allow users to delete their accounts.')));
|
68 |
+
add_settings_field('delete-pending-account', SwpmUtils::_('Auto Delete Pending Account'),
|
69 |
+
array(&$this, 'selectbox_callback'), 'simple_wp_membership_settings', 'general-settings',
|
70 |
+
array('item' => 'delete-pending-account',
|
71 |
+
'options'=> array(0 => 'Do not delete', 1=>'Older than 1 month', 2=> 'Older than 2 months'),
|
72 |
+
'default'=>'0',
|
73 |
+
'message'=>SwpmUtils::_('Select how long you want to keep "pending" account.')));
|
74 |
+
/*add_settings_field('protect-everything', BUtils::_('Protect Everything'),
|
75 |
+
array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'general-settings',
|
76 |
+
array('item' => 'protect-everything',
|
77 |
+
'message'=>BUtils::_('Check this box if you want to protect all posts/pages by default.')));*/
|
78 |
+
|
79 |
+
add_settings_section('pages-settings', SwpmUtils::_('Pages Settings'),
|
80 |
+
array(&$this, 'pages_settings_callback'), 'simple_wp_membership_settings');
|
81 |
+
add_settings_field('login-page-url', SwpmUtils::_('Login Page URL'),
|
82 |
+
array(&$this, 'textfield_long_callback'), 'simple_wp_membership_settings', 'pages-settings',
|
83 |
+
array('item' => 'login-page-url',
|
84 |
+
'message'=>''));
|
85 |
+
add_settings_field('registration-page-url', SwpmUtils::_('Registration Page URL'),
|
86 |
+
array(&$this, 'textfield_long_callback'), 'simple_wp_membership_settings', 'pages-settings',
|
87 |
+
array('item' => 'registration-page-url',
|
88 |
+
'message'=>''));
|
89 |
+
add_settings_field('join-us-page-url', SwpmUtils::_('Join Us Page URL'),
|
90 |
+
array(&$this, 'textfield_long_callback'), 'simple_wp_membership_settings', 'pages-settings',
|
91 |
+
array('item' => 'join-us-page-url',
|
92 |
+
'message'=>''));
|
93 |
+
add_settings_field('profile-page-url', SwpmUtils::_('Edit Profile Page URL'),
|
94 |
+
array(&$this, 'textfield_long_callback'), 'simple_wp_membership_settings', 'pages-settings',
|
95 |
+
array('item' => 'profile-page-url',
|
96 |
+
'message'=>''));
|
97 |
+
add_settings_field('reset-page-url', SwpmUtils::_('Password Reset Page URL'),
|
98 |
+
array(&$this, 'textfield_long_callback'), 'simple_wp_membership_settings', 'pages-settings',
|
99 |
+
array('item' => 'reset-page-url',
|
100 |
+
'message'=>''));
|
101 |
+
|
102 |
+
add_settings_section('debug-settings', SwpmUtils::_('Test & Debug Settings'),
|
103 |
+
array(&$this, 'testndebug_settings_callback'), 'simple_wp_membership_settings');
|
104 |
+
|
105 |
+
$debug_field_help_text = SwpmUtils::_('Check this option to enable debug logging.');
|
106 |
+
$debug_field_help_text .= '<br />- View debug log file by clicking <a href="'.SIMPLE_WP_MEMBERSHIP_URL.'/log.txt" target="_blank">here</a>.';
|
107 |
+
$debug_field_help_text .= '<br />- Reset debug log file by clicking <a href="admin.php?page=simple_wp_membership_settings&swmp_reset_log=1" target="_blank">here</a>.';
|
108 |
+
add_settings_field('enable-debug', 'Enable Debug',
|
109 |
+
array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'debug-settings',
|
110 |
+
array('item' => 'enable-debug',
|
111 |
+
'message'=> $debug_field_help_text));
|
112 |
+
add_settings_field('enable-sandbox-testing', SwpmUtils::_('Enable Sandbox Testing'),
|
113 |
+
array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'debug-settings',
|
114 |
+
array('item' => 'enable-sandbox-testing',
|
115 |
+
'message'=>SwpmUtils::_('Enable this option if you want to do sandbox payment testing.')));
|
116 |
+
|
117 |
+
}
|
118 |
+
|
119 |
+
private function tab_2() {
|
120 |
+
}
|
121 |
+
|
122 |
+
private function tab_3() {
|
123 |
+
register_setting('swpm-settings-tab-3', 'swpm-settings', array(&$this, 'sanitize_tab_3'));
|
124 |
+
|
125 |
+
add_settings_section('email-misc-settings', SwpmUtils::_('Email Misc. Settings'),
|
126 |
+
array(&$this, 'email_misc_settings_callback'), 'simple_wp_membership_settings');
|
127 |
+
add_settings_field('email-misc-from', SwpmUtils::_('From Email Address'),
|
128 |
+
array(&$this, 'textfield_callback'), 'simple_wp_membership_settings', 'email-misc-settings',
|
129 |
+
array('item' => 'email-from',
|
130 |
+
'message'=>''));
|
131 |
+
|
132 |
+
add_settings_section('reg-prompt-email-settings', SwpmUtils::_('Email Settings (Prompt to Complete Registration )'),
|
133 |
+
array(&$this, 'reg_prompt_email_settings_callback'), 'simple_wp_membership_settings');
|
134 |
+
add_settings_field('reg-prompt-complete-mail-subject', SwpmUtils::_('Email Subject'),
|
135 |
+
array(&$this, 'textfield_callback'), 'simple_wp_membership_settings', 'reg-prompt-email-settings',
|
136 |
+
array('item' => 'reg-prompt-complete-mail-subject',
|
137 |
+
'message'=>''));
|
138 |
+
add_settings_field('reg-prompt-complete-mail-body', SwpmUtils::_('Email Body'),
|
139 |
+
array(&$this, 'textarea_callback'), 'simple_wp_membership_settings', 'reg-prompt-email-settings',
|
140 |
+
array('item' => 'reg-prompt-complete-mail-body',
|
141 |
+
'message'=>''));
|
142 |
+
|
143 |
+
add_settings_section('reg-email-settings', SwpmUtils::_('Email Settings (Registration Complete)'),
|
144 |
+
array(&$this, 'reg_email_settings_callback'), 'simple_wp_membership_settings');
|
145 |
+
add_settings_field('reg-complete-mail-subject', SwpmUtils::_('Email Subject'),
|
146 |
+
array(&$this, 'textfield_callback'), 'simple_wp_membership_settings', 'reg-email-settings',
|
147 |
+
array('item' => 'reg-complete-mail-subject',
|
148 |
+
'message'=>''));
|
149 |
+
add_settings_field('reg-complete-mail-body', SwpmUtils::_('Email Body'),
|
150 |
+
array(&$this, 'textarea_callback'), 'simple_wp_membership_settings', 'reg-email-settings',
|
151 |
+
array('item' => 'reg-complete-mail-body',
|
152 |
+
'message'=>''));
|
153 |
+
add_settings_field('enable-admin-notification-after-reg', SwpmUtils::_('Send Notification To Admin'),
|
154 |
+
array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'reg-email-settings',
|
155 |
+
array('item' => 'enable-admin-notification-after-reg',
|
156 |
+
'message'=>''));
|
157 |
+
add_settings_field('enable-notification-after-manual-user-add', SwpmUtils::_('Send Email to Member When Added via Admin Dashboard'),
|
158 |
+
array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'reg-email-settings',
|
159 |
+
array('item' => 'enable-notification-after-manual-user-add',
|
160 |
+
'message'=>''));
|
161 |
+
|
162 |
+
add_settings_section('upgrade-email-settings', SwpmUtils::_(' Email Settings (Account Upgrade Notification)'),
|
163 |
+
array(&$this, 'upgrade_email_settings_callback'), 'simple_wp_membership_settings');
|
164 |
+
add_settings_field('upgrade-complete-mail-subject', SwpmUtils::_('Email Subject'),
|
165 |
+
array(&$this, 'textfield_callback'), 'simple_wp_membership_settings', 'upgrade-email-settings',
|
166 |
+
array('item' => 'upgrade-complete-mail-subject',
|
167 |
+
'message'=>''));
|
168 |
+
add_settings_field('upgrade-complete-mail-body', SwpmUtils::_('Email Body'),
|
169 |
+
array(&$this, 'textarea_callback'), 'simple_wp_membership_settings', 'upgrade-email-settings',
|
170 |
+
array('item' => 'upgrade-complete-mail-body',
|
171 |
+
'message'=>''));
|
172 |
+
}
|
173 |
+
|
174 |
+
private function tab_4(){
|
175 |
+
}
|
176 |
+
|
177 |
+
private function tab_5(){
|
178 |
+
register_setting('swpm-settings-tab-5', 'swpm-settings', array(&$this, 'sanitize_tab_5'));
|
179 |
+
|
180 |
+
add_settings_section('advanced-settings', SwpmUtils::_('Advanced Settings'),
|
181 |
+
array(&$this, 'advanced_settings_callback'), 'simple_wp_membership_settings');
|
182 |
+
|
183 |
+
add_settings_field('enable-expired-account-login', SwpmUtils::_('Enable Expired Account Login'),
|
184 |
+
array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'advanced-settings',
|
185 |
+
array('item' => 'enable-expired-account-login',
|
186 |
+
'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.")));
|
187 |
+
}
|
188 |
+
|
189 |
+
private function tab_6(){
|
190 |
+
}
|
191 |
+
|
192 |
+
public static function get_instance() {
|
193 |
+
self::$_this = empty(self::$_this) ? new SwpmSettings() : self::$_this;
|
194 |
+
return self::$_this;
|
195 |
+
}
|
196 |
+
public function selectbox_callback($args){
|
197 |
+
$item = $args['item'];
|
198 |
+
$options = $args['options'];
|
199 |
+
$default = $args['default'];
|
200 |
+
$msg = isset($args['message'])?$args['message']: '';
|
201 |
+
$selected = esc_attr($this->get_value($item), $default);
|
202 |
+
echo "<select name='swpm-settings[" . $item . "]' >";
|
203 |
+
foreach($options as $key => $value){
|
204 |
+
$is_selected = ($key == $selected)? 'selected="selected"': '';
|
205 |
+
echo '<option ' . $is_selected . ' value="'. esc_attr($key) . '">' . esc_attr($value) . '</option>';
|
206 |
+
}
|
207 |
+
echo '</select>';
|
208 |
+
echo '<br/><i>'.$msg.'</i>';
|
209 |
+
}
|
210 |
+
public function checkbox_callback($args) {
|
211 |
+
$item = $args['item'];
|
212 |
+
$msg = isset($args['message'])?$args['message']: '';
|
213 |
+
$is = esc_attr($this->get_value($item));
|
214 |
+
echo "<input type='checkbox' $is name='swpm-settings[" . $item . "]' value=\"checked='checked'\" />";
|
215 |
+
echo '<br/><i>'.$msg.'</i>';
|
216 |
+
}
|
217 |
+
|
218 |
+
public function textarea_callback($args) {
|
219 |
+
$item = $args['item'];
|
220 |
+
$msg = isset($args['message'])?$args['message']: '';
|
221 |
+
$text = esc_attr($this->get_value($item));
|
222 |
+
echo "<textarea name='swpm-settings[" . $item . "]' rows='6' cols='60' >" . $text . "</textarea>";
|
223 |
+
echo '<br/><i>'.$msg.'</i>';
|
224 |
+
}
|
225 |
+
|
226 |
+
public function textfield_small_callback($args) {
|
227 |
+
$item = $args['item'];
|
228 |
+
$msg = isset($args['message'])?$args['message']: '';
|
229 |
+
$text = esc_attr($this->get_value($item));
|
230 |
+
echo "<input type='text' name='swpm-settings[" . $item . "]' size='5' value='" . $text . "' />";
|
231 |
+
echo '<br/><i>'.$msg.'</i>';
|
232 |
+
}
|
233 |
+
|
234 |
+
public function textfield_callback($args) {
|
235 |
+
$item = $args['item'];
|
236 |
+
$msg = isset($args['message'])?$args['message']: '';
|
237 |
+
$text = esc_attr($this->get_value($item));
|
238 |
+
echo "<input type='text' name='swpm-settings[" . $item . "]' size='50' value='" . $text . "' />";
|
239 |
+
echo '<br/><i>'.$msg.'</i>';
|
240 |
+
}
|
241 |
+
|
242 |
+
public function textfield_long_callback($args) {
|
243 |
+
$item = $args['item'];
|
244 |
+
$msg = isset($args['message'])?$args['message']: '';
|
245 |
+
$text = esc_attr($this->get_value($item));
|
246 |
+
echo "<input type='text' name='swpm-settings[" . $item . "]' size='100' value='" . $text . "' />";
|
247 |
+
echo '<br/><i>'.$msg.'</i>';
|
248 |
+
}
|
249 |
+
|
250 |
+
public function swpm_documentation_callback() {
|
251 |
+
?>
|
252 |
+
<div style="background: none repeat scroll 0 0 #FFF6D5;border: 1px solid #D1B655;color: #3F2502;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
|
253 |
+
<p>Visit the
|
254 |
+
<a target="_blank" href="https://simple-membership-plugin.com/">Simple Membership Plugin Site</a>
|
255 |
+
to read setup and configuration documentation. Please <a href="https://wordpress.org/support/view/plugin-reviews/simple-membership?filter=5" target="_blank">give us a rating</a> if you like the plugin.
|
256 |
+
</p>
|
257 |
+
</div>
|
258 |
+
<?php
|
259 |
+
}
|
260 |
+
|
261 |
+
public function swpm_general_post_submit_check_callback(){
|
262 |
+
//Log file reset handler
|
263 |
+
if(isset($_REQUEST['swmp_reset_log'])){
|
264 |
+
if(SwpmMiscUtils::reset_swmp_log_files()){
|
265 |
+
echo '<div id="message" class="updated fade"><p>Debug log files have been reset!</p></div>';
|
266 |
+
}
|
267 |
+
else{
|
268 |
+
echo '<div id="message" class="updated fade"><p>Debug log files could not be reset!</p></div>';
|
269 |
+
}
|
270 |
+
}
|
271 |
+
|
272 |
+
//Show settings updated message
|
273 |
+
if(isset($_REQUEST['settings-updated'])){
|
274 |
+
echo '<div id="message" class="updated fade"><p>' . SwpmUtils::_('Settings updated!') . '</p></div>';
|
275 |
+
}
|
276 |
+
}
|
277 |
+
|
278 |
+
public function general_settings_callback() {
|
279 |
+
SwpmUtils::e('General Plugin Settings.');
|
280 |
+
}
|
281 |
+
|
282 |
+
public function pages_settings_callback() {
|
283 |
+
SwpmUtils::e('Page Setup and URL Related settings.');
|
284 |
+
}
|
285 |
+
public function testndebug_settings_callback(){
|
286 |
+
SwpmUtils::e('Testing and Debug Related Settings.');
|
287 |
+
}
|
288 |
+
public function reg_email_settings_callback() {
|
289 |
+
SwpmUtils::e('This email will be sent to your users when they complete the registration and become a member.');
|
290 |
+
}
|
291 |
+
public function email_misc_settings_callback(){
|
292 |
+
SwpmUtils::e('Settings in this section apply to all emails.');
|
293 |
+
}
|
294 |
+
public function upgrade_email_settings_callback() {
|
295 |
+
SwpmUtils::e('This email will be sent to your users after account upgrade.');
|
296 |
+
}
|
297 |
+
public function reg_prompt_email_settings_callback() {
|
298 |
+
SwpmUtils::e('This email will be sent to prompt user to complete registration.');
|
299 |
+
}
|
300 |
+
public function advanced_settings_callback(){
|
301 |
+
SwpmUtils::e('This page allows you to configure some advanced features of the plugin.');
|
302 |
+
}
|
303 |
+
|
304 |
+
public function sanitize_tab_1($input) {
|
305 |
+
if (empty($this->settings)){
|
306 |
+
$this->settings = (array) get_option('swpm-settings');
|
307 |
+
}
|
308 |
+
$output = $this->settings;
|
309 |
+
//general settings block
|
310 |
+
|
311 |
+
$output['hide-adminbar'] = isset($input['hide-adminbar'])? esc_attr($input['hide-adminbar']) : "";
|
312 |
+
$output['protect-everything'] = isset($input['protect-everything'])? esc_attr($input['protect-everything']) : "";
|
313 |
+
$output['enable-free-membership'] = isset($input['enable-free-membership'])? esc_attr($input['enable-free-membership']) : "";
|
314 |
+
$output['enable-moretag'] = isset($input['enable-moretag'])? esc_attr($input['enable-moretag']) : "";
|
315 |
+
$output['enable-debug'] = isset($input['enable-debug'])? esc_attr($input['enable-debug']) : "";
|
316 |
+
$output['enable-sandbox-testing'] = isset($input['enable-sandbox-testing'])? esc_attr($input['enable-sandbox-testing']) : "";
|
317 |
+
$output['allow-account-deletion'] = isset($input['allow-account-deletion'])? esc_attr($input['allow-account-deletion']) : "";
|
318 |
+
|
319 |
+
$output['free-membership-id'] = ($input['free-membership-id'] != 1) ? absint($input['free-membership-id']) : '';
|
320 |
+
$output['login-page-url'] = esc_url($input['login-page-url']);
|
321 |
+
$output['registration-page-url'] = esc_url($input['registration-page-url']);
|
322 |
+
$output['profile-page-url'] = esc_url($input['profile-page-url']);
|
323 |
+
$output['reset-page-url'] = esc_url($input['reset-page-url']);
|
324 |
+
$output['join-us-page-url'] = esc_url($input['join-us-page-url']);
|
325 |
+
$output['default-account-status'] = esc_attr($input['default-account-status']);
|
326 |
+
return $output;
|
327 |
+
}
|
328 |
+
|
329 |
+
public function sanitize_tab_3($input) {
|
330 |
+
if (empty($this->settings)){
|
331 |
+
$this->settings = (array) get_option('swpm-settings');
|
332 |
+
}
|
333 |
+
$output = $this->settings;
|
334 |
+
$output['reg-complete-mail-subject'] = sanitize_text_field($input['reg-complete-mail-subject']);
|
335 |
+
$output['reg-complete-mail-body'] = wp_kses_data(force_balance_tags($input['reg-complete-mail-body']));
|
336 |
+
|
337 |
+
$output['upgrade-complete-mail-subject'] = sanitize_text_field($input['upgrade-complete-mail-subject']);
|
338 |
+
$output['upgrade-complete-mail-body'] = wp_kses_data(force_balance_tags($input['upgrade-complete-mail-body']));
|
339 |
+
|
340 |
+
$output['reg-prompt-complete-mail-subject'] = sanitize_text_field($input['reg-prompt-complete-mail-subject']);
|
341 |
+
$output['reg-prompt-complete-mail-body'] = wp_kses_data(force_balance_tags($input['reg-prompt-complete-mail-body']));
|
342 |
+
$output['email-from'] = trim($input['email-from']);
|
343 |
+
$output['enable-admin-notification-after-reg'] = isset($input['enable-admin-notification-after-reg'])? esc_attr($input['enable-admin-notification-after-reg']) : "";
|
344 |
+
$output['enable-notification-after-manual-user-add'] = isset($input['enable-notification-after-manual-user-add'])? esc_attr($input['enable-notification-after-manual-user-add']) : "";
|
345 |
+
|
346 |
+
return $output;
|
347 |
+
}
|
348 |
+
|
349 |
+
public function sanitize_tab_5($input){
|
350 |
+
if (empty($this->settings)){
|
351 |
+
$this->settings = (array) get_option('swpm-settings');
|
352 |
+
}
|
353 |
+
$output = $this->settings;
|
354 |
+
$output['enable-expired-account-login'] = isset($input['enable-expired-account-login'])? esc_attr($input['enable-expired-account-login']) : "";
|
355 |
+
|
356 |
+
return $output;
|
357 |
+
}
|
358 |
+
public function get_value($key, $default = "") {
|
359 |
+
if (isset($this->settings[$key])){
|
360 |
+
return $this->settings[$key];
|
361 |
+
}
|
362 |
+
return $default;
|
363 |
+
}
|
364 |
+
|
365 |
+
public function set_value($key, $value) {
|
366 |
+
$this->settings[$key] = $value;
|
367 |
+
return $this;
|
368 |
+
}
|
369 |
+
|
370 |
+
public function save() {
|
371 |
+
update_option('swpm-settings', $this->settings);
|
372 |
+
}
|
373 |
+
|
374 |
+
public function draw_tabs() {
|
375 |
+
$current = $this->current_tab;
|
376 |
+
?>
|
377 |
+
<h3 class="nav-tab-wrapper">
|
378 |
+
<?php foreach ($this->tabs as $id=>$label):?>
|
379 |
+
<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>
|
380 |
+
<?php endforeach;?>
|
381 |
+
</h3>
|
382 |
+
<?php
|
383 |
+
}
|
384 |
+
|
385 |
+
public function get_login_link() {
|
386 |
+
$login = $this->get_value('login-page-url');
|
387 |
+
$joinus = $this->get_value('join-us-page-url');
|
388 |
+
if (empty ($login) || empty($joinus)){
|
389 |
+
return '<span style="color:red;">Simple Membership is not configured correctly.'
|
390 |
+
. 'Please contact <a href="mailto:' . get_option('admin_email'). '">Admin</a>';
|
391 |
+
}
|
392 |
+
return SwpmUtils::_('Please'). ' <a class="swpm-login-link" href="' . $login . '">' . SwpmUtils::_('Login') . '</a>. '. SwpmUtils::_('Not a Member?').' <a href="' . $joinus . '">'.SwpmUtils::_('Join Us').'</a>';
|
393 |
+
}
|
394 |
+
|
395 |
+
}
|
classes/class.swpm-transactions.php
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = SwpmTransactions::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['last_name'] = $ipn_data['last_name'];
|
20 |
+
$txn_data['ip_address'] = $ipn_data['ip'];
|
21 |
+
$txn_data['member_id'] = $ipn_data['swpm_id'];
|
22 |
+
$txn_data['membership_level'] = $custom_var['subsc_ref'];
|
23 |
+
|
24 |
+
$txn_data['txn_date'] = $current_date;
|
25 |
+
$txn_data['txn_id'] = $ipn_data['txn_id'];
|
26 |
+
$txn_data['subscr_id'] = $ipn_data['subscr_id'];
|
27 |
+
$txn_data['reference'] = $custom_var['reference'];
|
28 |
+
$txn_data['payment_amount'] = $ipn_data['mc_gross'];
|
29 |
+
$txn_data['gateway'] = $ipn_data['gateway'];
|
30 |
+
$txn_data['status'] = $ipn_data['status'];
|
31 |
+
|
32 |
+
$wpdb->insert($wpdb->prefix . "swpm_payments_tbl", $txn_data);
|
33 |
+
|
34 |
+
}
|
35 |
+
|
36 |
+
static function parse_custom_var($custom) {
|
37 |
+
$delimiter = "&";
|
38 |
+
$customvariables = array();
|
39 |
+
|
40 |
+
$namevaluecombos = explode($delimiter, $custom);
|
41 |
+
foreach ($namevaluecombos as $keyval_unparsed) {
|
42 |
+
$equalsignposition = strpos($keyval_unparsed, '=');
|
43 |
+
if ($equalsignposition === false) {
|
44 |
+
$customvariables[$keyval_unparsed] = '';
|
45 |
+
continue;
|
46 |
+
}
|
47 |
+
$key = substr($keyval_unparsed, 0, $equalsignposition);
|
48 |
+
$value = substr($keyval_unparsed, $equalsignposition + 1);
|
49 |
+
$customvariables[$key] = $value;
|
50 |
+
}
|
51 |
+
|
52 |
+
return $customvariables;
|
53 |
+
}
|
54 |
+
|
55 |
+
}
|
classes/class.swpm-transfer.php
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class SwpmTransfer {
|
4 |
+
|
5 |
+
public static $default_fields = array(
|
6 |
+
'first_name' => '', 'last_name' => '',
|
7 |
+
'user_name' => '', 'email' => '',
|
8 |
+
'password' => '',
|
9 |
+
'phone' => '', 'account_state' => '',
|
10 |
+
'member_since' => '', 'subscription_starts' => '',
|
11 |
+
'address_street' => '', 'address_city' => '',
|
12 |
+
'address_state' => '', 'address_zipcode' => '',
|
13 |
+
'company_name' => '', 'country' => '',
|
14 |
+
'gender' => 'not specified',
|
15 |
+
'membership_level' => '2');
|
16 |
+
public static $default_level_fields = array(
|
17 |
+
'alias' => '', 'role' => '',
|
18 |
+
'subscription_period' => '', 'subscription_duration_type' => SwpmMembershipLevel::NO_EXPIRY);
|
19 |
+
public static $admin_messages = array();
|
20 |
+
private static $_this;
|
21 |
+
private $message;
|
22 |
+
|
23 |
+
private function __contruct() {
|
24 |
+
$this->message = get_option('swpm-messages');
|
25 |
+
}
|
26 |
+
|
27 |
+
public static function get_instance() {
|
28 |
+
self::$_this = empty(self::$_this) ? new SwpmTransfer() : self::$_this;
|
29 |
+
self::$_this->message = get_option('swpm-messages');
|
30 |
+
return self::$_this;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function get($key) {
|
34 |
+
$sesion_key = $_COOKIE['swpm_session'];
|
35 |
+
$m = '';
|
36 |
+
if (isset($this->message[$sesion_key])){
|
37 |
+
$m = $this->message[$sesion_key]->get($key);
|
38 |
+
}
|
39 |
+
update_option('swpm-messages', $this->message);
|
40 |
+
return $m;
|
41 |
+
}
|
42 |
+
|
43 |
+
public function set($key, $value) {
|
44 |
+
$sesion_key = $_COOKIE['swpm_session'];
|
45 |
+
if (!isset($this->message[$sesion_key])){
|
46 |
+
$this->message[$sesion_key] = new SwpmMessages();
|
47 |
+
}
|
48 |
+
$this->message[$sesion_key]->set($key,$value);
|
49 |
+
update_option('swpm-messages', $this->message);
|
50 |
+
}
|
51 |
+
|
52 |
+
public static function get_real_ip_addr() {
|
53 |
+
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
|
54 |
+
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
55 |
+
}
|
56 |
+
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
|
57 |
+
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
58 |
+
}
|
59 |
+
else{
|
60 |
+
$ip = $_SERVER['REMOTE_ADDR'];
|
61 |
+
}
|
62 |
+
return $ip;
|
63 |
+
}
|
64 |
+
|
65 |
+
}
|
classes/class.swpm-utils.php
ADDED
@@ -0,0 +1,385 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* BUtils
|
5 |
+
*
|
6 |
+
* @author nur
|
7 |
+
*/
|
8 |
+
abstract class SwpmUtils {
|
9 |
+
|
10 |
+
public static function is_ajax() {
|
11 |
+
return defined('DOING_AJAX') && DOING_AJAX;
|
12 |
+
}
|
13 |
+
|
14 |
+
public static function subscription_type_dropdown($selected) {
|
15 |
+
return '<option ' . (($selected == SwpmMembershipLevel::NO_EXPIRY) ? 'selected="selected"' : "") . ' value="' . SwpmMembershipLevel::NO_EXPIRY . '">No Expiry</option>' .
|
16 |
+
'<option ' . (($selected == SwpmMembershipLevel::DAYS) ? 'selected="selected"' : "") . ' value="' . SwpmMembershipLevel::DAYS . '">Day(s)</option>' .
|
17 |
+
'<option ' . (($selected == SwpmMembershipLevel::WEEKS) ? 'selected="selected"' : "") . ' value="' . SwpmMembershipLevel::WEEKS . '">Week(s)</option>' .
|
18 |
+
'<option ' . (($selected == SwpmMembershipLevel::MONTHS) ? 'selected="selected"' : "") . ' value="' . SwpmMembershipLevel::MONTHS . '">Month(s)</option>' .
|
19 |
+
'<option ' . (($selected == SwpmMembershipLevel::YEARS) ? 'selected="selected"' : "") . ' value="' . SwpmMembershipLevel::YEARS . '">Year(s)</option>' .
|
20 |
+
'<option ' . (($selected == SwpmMembershipLevel::FIXED_DATE) ? 'selected="selected"' : "") . ' value="' . SwpmMembershipLevel::FIXED_DATE . '">Fixed Date</option>';
|
21 |
+
}
|
22 |
+
|
23 |
+
// $subscript_period must be integer.
|
24 |
+
public static function calculate_subscription_period_days($subcript_period, $subscription_duration_type) {
|
25 |
+
if ($subscription_duration_type == SwpmMembershipLevel::NO_EXPIRY) {
|
26 |
+
return 'noexpire';
|
27 |
+
}
|
28 |
+
if (!is_numeric($subcript_period)) {
|
29 |
+
throw new Exception(" subcript_period parameter must be integer in BUtils::calculate_subscription_period_days method");
|
30 |
+
}
|
31 |
+
switch (strtolower($subscription_duration_type)) {
|
32 |
+
case SwpmMembershipLevel::DAYS:
|
33 |
+
break;
|
34 |
+
case SwpmMembershipLevel::WEEKS:
|
35 |
+
$subcript_period = $subcript_period * 7;
|
36 |
+
break;
|
37 |
+
case SwpmMembershipLevel::MONTHS:
|
38 |
+
$subcript_period = $subcript_period * 30;
|
39 |
+
break;
|
40 |
+
case SwpmMembershipLevel::YEARS:
|
41 |
+
$subcript_period = $subcript_period * 365;
|
42 |
+
break;
|
43 |
+
}
|
44 |
+
return $subcript_period;
|
45 |
+
}
|
46 |
+
|
47 |
+
public static function get_expiration_timestamp($user) {
|
48 |
+
$permission = SwpmPermission::get_instance($user->membership_level);
|
49 |
+
if (SwpmMembershipLevel::FIXED_DATE == $permission->get('subscription_duration_type')) {
|
50 |
+
return strtotime($permission->get('subscription_period'));
|
51 |
+
}
|
52 |
+
$days = self::calculate_subscription_period_days(
|
53 |
+
$permission->get('subscription_period'), $permission->get('subscription_duration_type'));
|
54 |
+
if ($days == 'noexpire') {
|
55 |
+
return PHP_INT_MAX; // which is equivalent to
|
56 |
+
}
|
57 |
+
return strtotime($user->subscription_starts . ' ' . $days . ' days');
|
58 |
+
}
|
59 |
+
|
60 |
+
public static function is_subscription_expired($user) {
|
61 |
+
$expiration_timestamp = SwpmUtils::get_expiration_timestamp($user);
|
62 |
+
return $expiration_timestamp < time();
|
63 |
+
}
|
64 |
+
|
65 |
+
public static function gender_dropdown($selected = 'not specified') {
|
66 |
+
return '<option ' . ((strtolower($selected) == 'male') ? 'selected="selected"' : "") . ' value="male">Male</option>' .
|
67 |
+
'<option ' . ((strtolower($selected) == 'female') ? 'selected="selected"' : "") . ' value="female">Female</option>' .
|
68 |
+
'<option ' . ((strtolower($selected) == 'not specified') ? 'selected="selected"' : "") . ' value="not specified">Not Specified</option>';
|
69 |
+
}
|
70 |
+
|
71 |
+
public static function get_account_state_options() {
|
72 |
+
return array('active' => SwpmUtils::_('Active'),
|
73 |
+
'inactive' => SwpmUtils::_('Inactive'),
|
74 |
+
'pending' => SwpmUtils::_('Pending'),
|
75 |
+
'expired' => SwpmUtils::_('Expired'),);
|
76 |
+
}
|
77 |
+
|
78 |
+
public static function account_state_dropdown($selected = 'active') {
|
79 |
+
$options = self::get_account_state_options();
|
80 |
+
$html = '';
|
81 |
+
foreach ($options as $key => $value) {
|
82 |
+
$html .= '<option ' . ((strtolower($selected) == $key) ? 'selected="selected"' : "") . ' value="' . $key . '"> ' . $value . '</option>';
|
83 |
+
}
|
84 |
+
return $html;
|
85 |
+
}
|
86 |
+
|
87 |
+
public static function membership_level_dropdown($selected = 0) {
|
88 |
+
$options = '';
|
89 |
+
global $wpdb;
|
90 |
+
$query = "SELECT alias, id FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id != 1";
|
91 |
+
$levels = $wpdb->get_results($query);
|
92 |
+
foreach ($levels as $level) {
|
93 |
+
$options .= '<option ' . ($selected == $level->id ? 'selected="selected"' : '') . ' value="' . $level->id . '" >' . $level->alias . '</option>';
|
94 |
+
}
|
95 |
+
return $options;
|
96 |
+
}
|
97 |
+
|
98 |
+
public static function get_all_membership_level_ids() {
|
99 |
+
global $wpdb;
|
100 |
+
$query = "SELECT id FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id != 1";
|
101 |
+
return $wpdb->get_col($query);
|
102 |
+
}
|
103 |
+
|
104 |
+
public static function get_user_by_id($swpm_id) {
|
105 |
+
global $wpdb;
|
106 |
+
$query = $wpdb->prepare("SELECT user_name FROM {$wpdb->prefix}swpm_members_tbl WHERE member_id = %d", $swpm_id);
|
107 |
+
return $wpdb->get_var($query);
|
108 |
+
}
|
109 |
+
|
110 |
+
public static function get_user_by_user_name($swpm_user_name) {
|
111 |
+
global $wpdb;
|
112 |
+
$query = $wpdb->prepare("SELECT member_id FROM {$wpdb->prefix}swpm_members_tbl WHERE user_name = %s", $swpm_user_name);
|
113 |
+
return $wpdb->get_var($query);
|
114 |
+
}
|
115 |
+
|
116 |
+
public static function get_registration_link($for = 'all', $send_email = false, $member_id = '') {
|
117 |
+
$members = array();
|
118 |
+
global $wpdb;
|
119 |
+
switch ($for) {
|
120 |
+
case 'one':
|
121 |
+
if (empty($member_id)) {
|
122 |
+
return array();
|
123 |
+
}
|
124 |
+
$query = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}swpm_members_tbl WHERE member_id = %d", $member_id);
|
125 |
+
$members = $wpdb->get_results($query);
|
126 |
+
break;
|
127 |
+
case 'all':
|
128 |
+
$query = "SELECT * FROM {$wpdb->prefix}swpm_members_tbl WHERE reg_code != '' ";
|
129 |
+
$members = $wpdb->get_results($query);
|
130 |
+
break;
|
131 |
+
}
|
132 |
+
$settings = SwpmSettings::get_instance();
|
133 |
+
$separator = '?';
|
134 |
+
$url = $settings->get_value('registration-page-url');
|
135 |
+
if (strpos($url, '?') !== false) {
|
136 |
+
$separator = '&';
|
137 |
+
}
|
138 |
+
$subject = $settings->get_value('reg-complete-mail-subject');
|
139 |
+
if (empty($subject)) {
|
140 |
+
$subject = "Please complete your registration";
|
141 |
+
}
|
142 |
+
$body = $settings->get_value('reg-complete-mail-body');
|
143 |
+
if (empty($body)) {
|
144 |
+
$body = "Please use the following link to complete your registration. \n {reg_link}";
|
145 |
+
}
|
146 |
+
$from_address = $settings->get_value('email-from');
|
147 |
+
$links = array();
|
148 |
+
foreach ($members as $member) {
|
149 |
+
$reg_url = $url . $separator . 'member_id=' . $member->member_id . '&code=' . $member->reg_code;
|
150 |
+
if (!empty($send_email) && empty($member->user_name)) {
|
151 |
+
$tags = array("{first_name}", "{last_name}", "{reg_link}");
|
152 |
+
$vals = array($member->first_name, $member->last_name, $reg_url);
|
153 |
+
$email_body = str_replace($tags, $vals, $body);
|
154 |
+
$headers = 'From: ' . $from_address . "\r\n";
|
155 |
+
wp_mail($member->email, $subject, $email_body, $headers);
|
156 |
+
}
|
157 |
+
$links[] = $reg_url;
|
158 |
+
}
|
159 |
+
return $links;
|
160 |
+
}
|
161 |
+
|
162 |
+
public static function update_wp_user_Role($wp_user_id, $role) {
|
163 |
+
$preserve_role = 'yes';
|
164 |
+
if ($preserve_role) {
|
165 |
+
return;
|
166 |
+
}
|
167 |
+
if (self::is_multisite_install()) {//MS install
|
168 |
+
return; //TODO - don't do this for MS install
|
169 |
+
}
|
170 |
+
$caps = get_user_meta($wp_user_id, 'wp_capabilities', true);
|
171 |
+
if (in_array('administrator', array_keys((array) $caps))) {
|
172 |
+
return;
|
173 |
+
}
|
174 |
+
do_action('set_user_role', $wp_user_id, $role); //Fire the action for other plugin(s)
|
175 |
+
wp_update_user(array('ID' => $wp_user_id, 'role' => $role));
|
176 |
+
$roles = new WP_Roles();
|
177 |
+
$level = $roles->roles[$role]['capabilities'];
|
178 |
+
if (isset($level['level_10']) && $level['level_10']) {
|
179 |
+
update_user_meta($wp_user_id, 'wp_user_level', 10);
|
180 |
+
return;
|
181 |
+
}
|
182 |
+
if (isset($level['level_9']) && $level['level_9']) {
|
183 |
+
update_user_meta($wp_user_id, 'wp_user_level', 9);
|
184 |
+
return;
|
185 |
+
}
|
186 |
+
if (isset($level['level_8']) && $level['level_8']) {
|
187 |
+
update_user_meta($wp_user_id, 'wp_user_level', 8);
|
188 |
+
return;
|
189 |
+
}
|
190 |
+
if (isset($level['level_7']) && $level['level_7']) {
|
191 |
+
update_user_meta($wp_user_id, 'wp_user_level', 7);
|
192 |
+
return;
|
193 |
+
}
|
194 |
+
if (isset($level['level_6']) && $level['level_6']) {
|
195 |
+
update_user_meta($wp_user_id, 'wp_user_level', 6);
|
196 |
+
return;
|
197 |
+
}
|
198 |
+
if (isset($level['level_5']) && $level['level_5']) {
|
199 |
+
update_user_meta($wp_user_id, 'wp_user_level', 5);
|
200 |
+
return;
|
201 |
+
}
|
202 |
+
if (isset($level['level_4']) && $level['level_4']) {
|
203 |
+
update_user_meta($wp_user_id, 'wp_user_level', 4);
|
204 |
+
return;
|
205 |
+
}
|
206 |
+
if (isset($level['level_3']) && $level['level_3']) {
|
207 |
+
update_user_meta($wp_user_id, 'wp_user_level', 3);
|
208 |
+
return;
|
209 |
+
}
|
210 |
+
if (isset($level['level_2']) && $level['level_2']) {
|
211 |
+
update_user_meta($wp_user_id, 'wp_user_level', 2);
|
212 |
+
return;
|
213 |
+
}
|
214 |
+
if (isset($level['level_1']) && $level['level_1']) {
|
215 |
+
update_user_meta($wp_user_id, 'wp_user_level', 1);
|
216 |
+
return;
|
217 |
+
}
|
218 |
+
if (isset($level['level_0']) && $level['level_0']) {
|
219 |
+
update_user_meta($wp_user_id, 'wp_user_level', 0);
|
220 |
+
return;
|
221 |
+
}
|
222 |
+
}
|
223 |
+
|
224 |
+
public static function update_wp_user($wp_user_name, $swpm_data) {
|
225 |
+
$wp_user_info = array();
|
226 |
+
if (isset($swpm_data['email'])) {
|
227 |
+
$wp_user_info['user_email'] = $swpm_data['email'];
|
228 |
+
}
|
229 |
+
if (isset($swpm_data['first_name'])) {
|
230 |
+
$wp_user_info['first_name'] = $swpm_data['first_name'];
|
231 |
+
}
|
232 |
+
if (isset($swpm_data['last_name'])) {
|
233 |
+
$wp_user_info['last_name'] = $swpm_data['last_name'];
|
234 |
+
}
|
235 |
+
if (isset($swpm_data['plain_password'])) {
|
236 |
+
$wp_user_info['user_pass'] = $swpm_data['plain_password'];
|
237 |
+
}
|
238 |
+
|
239 |
+
$wp_user = get_user_by('login', $wp_user_name);
|
240 |
+
|
241 |
+
if ($wp_user) {
|
242 |
+
$wp_user_info['ID'] = $wp_user->ID;
|
243 |
+
return wp_update_user($wp_user_info);
|
244 |
+
}
|
245 |
+
return false;
|
246 |
+
}
|
247 |
+
|
248 |
+
public static function create_wp_user($wp_user_data) {
|
249 |
+
if (self::is_multisite_install()) {//MS install
|
250 |
+
global $blog_id;
|
251 |
+
if ($wp_user_id = email_exists($wp_user_data['user_email'])) {// if user exists then just add him to current blog.
|
252 |
+
add_existing_user_to_blog(array('user_id' => $wp_user_id, 'role' => 'subscriber'));
|
253 |
+
return $wp_user_id;
|
254 |
+
}
|
255 |
+
$wp_user_id = wpmu_create_user($wp_user_data['user_login'], $wp_user_data['password'], $wp_user_data['user_email']);
|
256 |
+
$role = 'subscriber'; //TODO - add user as a subscriber first. The subsequent update user role function to update the role to the correct one
|
257 |
+
add_user_to_blog($blog_id, $wp_user_id, $role);
|
258 |
+
} else {//Single site install
|
259 |
+
$wp_user_id = email_exists($wp_user_data['user_email']);
|
260 |
+
if ($wp_user_id) {
|
261 |
+
return $wp_user_id;
|
262 |
+
}
|
263 |
+
$wp_user_id = wp_create_user($wp_user_data['user_login'], $wp_user_data['password'], $wp_user_data['user_email']);
|
264 |
+
}
|
265 |
+
$wp_user_data['ID'] = $wp_user_id;
|
266 |
+
wp_update_user($wp_user_data);
|
267 |
+
$user_info = get_userdata($wp_user_id);
|
268 |
+
$user_cap = (isset($user_info->wp_capabilities) && is_array($user_info->wp_capabilities)) ? array_keys($user_info->wp_capabilities) : array();
|
269 |
+
if (!in_array('administrator', $user_cap)) {
|
270 |
+
SwpmUtils::update_wp_user_Role($wp_user_id, $wp_user_data['role']);
|
271 |
+
}
|
272 |
+
return $wp_user_id;
|
273 |
+
}
|
274 |
+
|
275 |
+
public static function is_multisite_install() {
|
276 |
+
if (function_exists('is_multisite') && is_multisite()) {
|
277 |
+
return true;
|
278 |
+
} else {
|
279 |
+
return false;
|
280 |
+
}
|
281 |
+
}
|
282 |
+
|
283 |
+
public static function _($msg) {
|
284 |
+
return __($msg, 'swpm');
|
285 |
+
}
|
286 |
+
|
287 |
+
public static function e($msg) {
|
288 |
+
_e($msg, 'swpm');
|
289 |
+
}
|
290 |
+
|
291 |
+
public static function is_admin() {
|
292 |
+
return current_user_can('manage_options');
|
293 |
+
}
|
294 |
+
|
295 |
+
public static function get_expire_date($start_date, $subscription_duration, $subscription_duration_type) {
|
296 |
+
if ($subscription_duration_type == SwpmMembershipLevel::FIXED_DATE) { //will expire after a fixed date.
|
297 |
+
return date(get_option('date_format'), strtotime($subscription_duration));
|
298 |
+
}
|
299 |
+
$expires = self::calculate_subscription_period_days($subscription_duration, $subscription_duration_type);
|
300 |
+
if ($expires == 'noexpire') {// its set to no expiry until cancelled
|
301 |
+
return SwpmUtils::_('Never');
|
302 |
+
}
|
303 |
+
|
304 |
+
return date(get_option('date_format'), strtotime($start_date . ' ' . $expires . ' days'));
|
305 |
+
}
|
306 |
+
|
307 |
+
public static function swpm_username_exists($user_name) {
|
308 |
+
global $wpdb;
|
309 |
+
$member_table = $wpdb->prefix . 'swpm_members_tbl';
|
310 |
+
$query = $wpdb->prepare('SELECT member_id FROM ' . $member_table . ' WHERE user_name=%s', sanitize_user($user_name));
|
311 |
+
return $wpdb->get_var($query);
|
312 |
+
}
|
313 |
+
|
314 |
+
public static function get_free_level() {
|
315 |
+
$encrypted = filter_input(INPUT_POST, 'level_identifier');
|
316 |
+
global $wpdb;
|
317 |
+
if (!empty($encrypted)) {
|
318 |
+
return SwpmPermission::get_instance($encrypted)->get('id');
|
319 |
+
}
|
320 |
+
|
321 |
+
$is_free = SwpmSettings::get_instance()->get_value('enable-free-membership');
|
322 |
+
$free_level = absint(SwpmSettings::get_instance()->get_value('free-membership-id'));
|
323 |
+
|
324 |
+
return ($is_free) ? $free_level : null;
|
325 |
+
}
|
326 |
+
|
327 |
+
public static function is_paid_registration() {
|
328 |
+
$member_id = filter_input(INPUT_GET, 'member_id', FILTER_SANITIZE_NUMBER_INT);
|
329 |
+
$code = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_STRING);
|
330 |
+
return !empty($member_id) && !empty($code);
|
331 |
+
}
|
332 |
+
|
333 |
+
public static function get_paid_member_info() {
|
334 |
+
$member_id = filter_input(INPUT_GET, 'member_id', FILTER_SANITIZE_NUMBER_INT);
|
335 |
+
$code = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_STRING);
|
336 |
+
global $wpdb;
|
337 |
+
if (!empty($member_id) && !empty($code)) {
|
338 |
+
$query = 'SELECT * FROM ' . $wpdb->prefix . 'swpm_members_tbl WHERE member_id= %d AND reg_code=%s';
|
339 |
+
$query = $wpdb->prepare($query, $member_id, $code);
|
340 |
+
return $wpdb->get_row($query);
|
341 |
+
}
|
342 |
+
return null;
|
343 |
+
}
|
344 |
+
|
345 |
+
public static function account_delete_confirmation_ui($msg = "") {
|
346 |
+
ob_start();
|
347 |
+
include(SIMPLE_WP_MEMBERSHIP_PATH . 'views/account_delete_warning.php');
|
348 |
+
ob_get_flush();
|
349 |
+
wp_die("", "", array('back_link' => true));
|
350 |
+
}
|
351 |
+
|
352 |
+
public static function delete_account_button() {
|
353 |
+
$allow_account_deletion = SwpmSettings::get_instance()->get_value('allow-account-deletion');
|
354 |
+
if (empty($allow_account_deletion)) {
|
355 |
+
return "";
|
356 |
+
}
|
357 |
+
|
358 |
+
return '<a href="/?delete_account=1"><div class="swpm-account-delete-button">' . SwpmUtils::_("Delete Account") . '</div></a>';
|
359 |
+
}
|
360 |
+
|
361 |
+
public static function encrypt_password($plain_password) {
|
362 |
+
include_once(ABSPATH . WPINC . '/class-phpass.php');
|
363 |
+
$wp_hasher = new PasswordHash(8, TRUE);
|
364 |
+
$password_hash = $wp_hasher->HashPassword(trim($plain_password));
|
365 |
+
return $password_hash;
|
366 |
+
}
|
367 |
+
|
368 |
+
public static function get_restricted_image_url() {
|
369 |
+
return SIMPLE_WP_MEMBERSHIP_URL . '/images/restricted-icon.png';
|
370 |
+
}
|
371 |
+
|
372 |
+
/*
|
373 |
+
* 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.
|
374 |
+
*/
|
375 |
+
|
376 |
+
public static function sanitize_value_by_array($val_to_check, $valid_values) {
|
377 |
+
$keys = array_keys($valid_values);
|
378 |
+
$keys = array_map('strtolower', $keys);
|
379 |
+
if (in_array($val_to_check, $keys)) {
|
380 |
+
return $val_to_check;
|
381 |
+
}
|
382 |
+
return reset($keys); //Return he first element from the valid values
|
383 |
+
}
|
384 |
+
|
385 |
+
}
|
classes/common/class.swpm-list-table.php
ADDED
@@ -0,0 +1,1138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Base class for displaying a list of items in an ajaxified HTML table.
|
4 |
+
* Use this class to display list table.
|
5 |
+
* This will prevent list table from breaking when WordPress changes the implementation of core list table class in the future.
|
6 |
+
*/
|
7 |
+
|
8 |
+
class SWPM_List_Table {
|
9 |
+
|
10 |
+
/**
|
11 |
+
* The current list of items
|
12 |
+
*
|
13 |
+
* @since 3.1.0
|
14 |
+
* @var array
|
15 |
+
* @access public
|
16 |
+
*/
|
17 |
+
public $items;
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Various information about the current table
|
21 |
+
*
|
22 |
+
* @since 3.1.0
|
23 |
+
* @var array
|
24 |
+
* @access protected
|
25 |
+
*/
|
26 |
+
protected $_args;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Various information needed for displaying the pagination
|
30 |
+
*
|
31 |
+
* @since 3.1.0
|
32 |
+
* @var array
|
33 |
+
*/
|
34 |
+
protected $_pagination_args = array();
|
35 |
+
|
36 |
+
/**
|
37 |
+
* The current screen
|
38 |
+
*
|
39 |
+
* @since 3.1.0
|
40 |
+
* @var object
|
41 |
+
* @access protected
|
42 |
+
*/
|
43 |
+
protected $screen;
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Cached bulk actions
|
47 |
+
*
|
48 |
+
* @since 3.1.0
|
49 |
+
* @var array
|
50 |
+
* @access private
|
51 |
+
*/
|
52 |
+
private $_actions;
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Cached pagination output
|
56 |
+
*
|
57 |
+
* @since 3.1.0
|
58 |
+
* @var string
|
59 |
+
* @access private
|
60 |
+
*/
|
61 |
+
private $_pagination;
|
62 |
+
|
63 |
+
/**
|
64 |
+
* The view switcher modes.
|
65 |
+
*
|
66 |
+
* @since 4.1.0
|
67 |
+
* @var array
|
68 |
+
* @access protected
|
69 |
+
*/
|
70 |
+
protected $modes = array();
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Stores the value returned by ->get_column_info()
|
74 |
+
*
|
75 |
+
* @var array
|
76 |
+
*/
|
77 |
+
protected $_column_headers;
|
78 |
+
|
79 |
+
protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
|
80 |
+
|
81 |
+
protected $compat_methods = array( 'set_pagination_args', 'get_views', 'get_bulk_actions', 'bulk_actions',
|
82 |
+
'row_actions', 'months_dropdown', 'view_switcher', 'comments_bubble', 'get_items_per_page', 'pagination',
|
83 |
+
'get_sortable_columns', 'get_column_info', 'get_table_classes', 'display_tablenav', 'extra_tablenav',
|
84 |
+
'single_row_columns' );
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Constructor.
|
88 |
+
*
|
89 |
+
* The child class should call this constructor from its own constructor to override
|
90 |
+
* the default $args.
|
91 |
+
*
|
92 |
+
* @since 3.1.0
|
93 |
+
* @access public
|
94 |
+
*
|
95 |
+
* @param array|string $args {
|
96 |
+
* Array or string of arguments.
|
97 |
+
*
|
98 |
+
* @type string $plural Plural value used for labels and the objects being listed.
|
99 |
+
* This affects things such as CSS class-names and nonces used
|
100 |
+
* in the list table, e.g. 'posts'. Default empty.
|
101 |
+
* @type string $singular Singular label for an object being listed, e.g. 'post'.
|
102 |
+
* Default empty
|
103 |
+
* @type bool $ajax Whether the list table supports AJAX. This includes loading
|
104 |
+
* and sorting data, for example. If true, the class will call
|
105 |
+
* the {@see _js_vars()} method in the footer to provide variables
|
106 |
+
* to any scripts handling AJAX events. Default false.
|
107 |
+
* @type string $screen String containing the hook name used to determine the current
|
108 |
+
* screen. If left null, the current screen will be automatically set.
|
109 |
+
* Default null.
|
110 |
+
* }
|
111 |
+
*/
|
112 |
+
public function __construct( $args = array() ) {
|
113 |
+
$args = wp_parse_args( $args, array(
|
114 |
+
'plural' => '',
|
115 |
+
'singular' => '',
|
116 |
+
'ajax' => false,
|
117 |
+
'screen' => null,
|
118 |
+
) );
|
119 |
+
|
120 |
+
$this->screen = convert_to_screen( $args['screen'] );
|
121 |
+
|
122 |
+
add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
|
123 |
+
|
124 |
+
if ( !$args['plural'] )
|
125 |
+
$args['plural'] = $this->screen->base;
|
126 |
+
|
127 |
+
$args['plural'] = sanitize_key( $args['plural'] );
|
128 |
+
$args['singular'] = sanitize_key( $args['singular'] );
|
129 |
+
|
130 |
+
$this->_args = $args;
|
131 |
+
|
132 |
+
if ( $args['ajax'] ) {
|
133 |
+
// wp_enqueue_script( 'list-table' );
|
134 |
+
add_action( 'admin_footer', array( $this, '_js_vars' ) );
|
135 |
+
}
|
136 |
+
|
137 |
+
if ( empty( $this->modes ) ) {
|
138 |
+
$this->modes = array(
|
139 |
+
'list' => __( 'List View' ),
|
140 |
+
'excerpt' => __( 'Excerpt View' )
|
141 |
+
);
|
142 |
+
}
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Make private properties readable for backwards compatibility.
|
147 |
+
*
|
148 |
+
* @since 4.0.0
|
149 |
+
* @access public
|
150 |
+
*
|
151 |
+
* @param string $name Property to get.
|
152 |
+
* @return mixed Property.
|
153 |
+
*/
|
154 |
+
public function __get( $name ) {
|
155 |
+
if ( in_array( $name, $this->compat_fields ) ) {
|
156 |
+
return $this->$name;
|
157 |
+
}
|
158 |
+
}
|
159 |
+
|
160 |
+
/**
|
161 |
+
* Make private properties settable for backwards compatibility.
|
162 |
+
*
|
163 |
+
* @since 4.0.0
|
164 |
+
* @access public
|
165 |
+
*
|
166 |
+
* @param string $name Property to check if set.
|
167 |
+
* @param mixed $value Property value.
|
168 |
+
* @return mixed Newly-set property.
|
169 |
+
*/
|
170 |
+
public function __set( $name, $value ) {
|
171 |
+
if ( in_array( $name, $this->compat_fields ) ) {
|
172 |
+
return $this->$name = $value;
|
173 |
+
}
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* Make private properties checkable for backwards compatibility.
|
178 |
+
*
|
179 |
+
* @since 4.0.0
|
180 |
+
* @access public
|
181 |
+
*
|
182 |
+
* @param string $name Property to check if set.
|
183 |
+
* @return bool Whether the property is set.
|
184 |
+
*/
|
185 |
+
public function __isset( $name ) {
|
186 |
+
if ( in_array( $name, $this->compat_fields ) ) {
|
187 |
+
return isset( $this->$name );
|
188 |
+
}
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Make private properties un-settable for backwards compatibility.
|
193 |
+
*
|
194 |
+
* @since 4.0.0
|
195 |
+
* @access public
|
196 |
+
*
|
197 |
+
* @param string $name Property to unset.
|
198 |
+
*/
|
199 |
+
public function __unset( $name ) {
|
200 |
+
if ( in_array( $name, $this->compat_fields ) ) {
|
201 |
+
unset( $this->$name );
|
202 |
+
}
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Make private/protected methods readable for backwards compatibility.
|
207 |
+
*
|
208 |
+
* @since 4.0.0
|
209 |
+
* @access public
|
210 |
+
*
|
211 |
+
* @param callable $name Method to call.
|
212 |
+
* @param array $arguments Arguments to pass when calling.
|
213 |
+
* @return mixed|bool Return value of the callback, false otherwise.
|
214 |
+
*/
|
215 |
+
public function __call( $name, $arguments ) {
|
216 |
+
if ( in_array( $name, $this->compat_methods ) ) {
|
217 |
+
return call_user_func_array( array( $this, $name ), $arguments );
|
218 |
+
}
|
219 |
+
return false;
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Checks the current user's permissions
|
224 |
+
*
|
225 |
+
* @since 3.1.0
|
226 |
+
* @access public
|
227 |
+
* @abstract
|
228 |
+
*/
|
229 |
+
public function ajax_user_can() {
|
230 |
+
die( 'function WP_List_Table::ajax_user_can() must be over-ridden in a sub-class.' );
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Prepares the list of items for displaying.
|
235 |
+
* @uses WP_List_Table::set_pagination_args()
|
236 |
+
*
|
237 |
+
* @since 3.1.0
|
238 |
+
* @access public
|
239 |
+
* @abstract
|
240 |
+
*/
|
241 |
+
public function prepare_items() {
|
242 |
+
die( 'function WP_List_Table::prepare_items() must be over-ridden in a sub-class.' );
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* An internal method that sets all the necessary pagination arguments
|
247 |
+
*
|
248 |
+
* @param array $args An associative array with information about the pagination
|
249 |
+
* @access protected
|
250 |
+
*/
|
251 |
+
protected function set_pagination_args( $args ) {
|
252 |
+
$args = wp_parse_args( $args, array(
|
253 |
+
'total_items' => 0,
|
254 |
+
'total_pages' => 0,
|
255 |
+
'per_page' => 0,
|
256 |
+
) );
|
257 |
+
|
258 |
+
if ( !$args['total_pages'] && $args['per_page'] > 0 )
|
259 |
+
$args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
|
260 |
+
|
261 |
+
// Redirect if page number is invalid and headers are not already sent.
|
262 |
+
if ( ! headers_sent() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
|
263 |
+
wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
|
264 |
+
exit;
|
265 |
+
}
|
266 |
+
|
267 |
+
$this->_pagination_args = $args;
|
268 |
+
}
|
269 |
+
|
270 |
+
/**
|
271 |
+
* Access the pagination args.
|
272 |
+
*
|
273 |
+
* @since 3.1.0
|
274 |
+
* @access public
|
275 |
+
*
|
276 |
+
* @param string $key Pagination argument to retrieve. Common values include 'total_items',
|
277 |
+
* 'total_pages', 'per_page', or 'infinite_scroll'.
|
278 |
+
* @return int Number of items that correspond to the given pagination argument.
|
279 |
+
*/
|
280 |
+
public function get_pagination_arg( $key ) {
|
281 |
+
if ( 'page' == $key )
|
282 |
+
return $this->get_pagenum();
|
283 |
+
|
284 |
+
if ( isset( $this->_pagination_args[$key] ) )
|
285 |
+
return $this->_pagination_args[$key];
|
286 |
+
}
|
287 |
+
|
288 |
+
/**
|
289 |
+
* Whether the table has items to display or not
|
290 |
+
*
|
291 |
+
* @since 3.1.0
|
292 |
+
* @access public
|
293 |
+
*
|
294 |
+
* @return bool
|
295 |
+
*/
|
296 |
+
public function has_items() {
|
297 |
+
return !empty( $this->items );
|
298 |
+
}
|
299 |
+
|
300 |
+
/**
|
301 |
+
* Message to be displayed when there are no items
|
302 |
+
*
|
303 |
+
* @since 3.1.0
|
304 |
+
* @access public
|
305 |
+
*/
|
306 |
+
public function no_items() {
|
307 |
+
_e( 'No items found.' );
|
308 |
+
}
|
309 |
+
|
310 |
+
/**
|
311 |
+
* Display the search box.
|
312 |
+
*
|
313 |
+
* @since 3.1.0
|
314 |
+
* @access public
|
315 |
+
*
|
316 |
+
* @param string $text The search button text
|
317 |
+
* @param string $input_id The search input id
|
318 |
+
*/
|
319 |
+
public function search_box( $text, $input_id ) {
|
320 |
+
if ( empty( $_REQUEST['s'] ) && !$this->has_items() )
|
321 |
+
return;
|
322 |
+
|
323 |
+
$input_id = $input_id . '-search-input';
|
324 |
+
|
325 |
+
if ( ! empty( $_REQUEST['orderby'] ) )
|
326 |
+
echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
|
327 |
+
if ( ! empty( $_REQUEST['order'] ) )
|
328 |
+
echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
|
329 |
+
if ( ! empty( $_REQUEST['post_mime_type'] ) )
|
330 |
+
echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
|
331 |
+
if ( ! empty( $_REQUEST['detached'] ) )
|
332 |
+
echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
|
333 |
+
?>
|
334 |
+
<p class="search-box">
|
335 |
+
<label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
|
336 |
+
<input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
|
337 |
+
<?php submit_button( $text, 'button', '', false, array('id' => 'search-submit') ); ?>
|
338 |
+
</p>
|
339 |
+
<?php
|
340 |
+
}
|
341 |
+
|
342 |
+
/**
|
343 |
+
* Get an associative array ( id => link ) with the list
|
344 |
+
* of views available on this table.
|
345 |
+
*
|
346 |
+
* @since 3.1.0
|
347 |
+
* @access protected
|
348 |
+
*
|
349 |
+
* @return array
|
350 |
+
*/
|
351 |
+
protected function get_views() {
|
352 |
+
return array();
|
353 |
+
}
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Display the list of views available on this table.
|
357 |
+
*
|
358 |
+
* @since 3.1.0
|
359 |
+
* @access public
|
360 |
+
*/
|
361 |
+
public function views() {
|
362 |
+
$views = $this->get_views();
|
363 |
+
/**
|
364 |
+
* Filter the list of available list table views.
|
365 |
+
*
|
366 |
+
* The dynamic portion of the hook name, `$this->screen->id`, refers
|
367 |
+
* to the ID of the current screen, usually a string.
|
368 |
+
*
|
369 |
+
* @since 3.5.0
|
370 |
+
*
|
371 |
+
* @param array $views An array of available list table views.
|
372 |
+
*/
|
373 |
+
$views = apply_filters( "views_{$this->screen->id}", $views );
|
374 |
+
|
375 |
+
if ( empty( $views ) )
|
376 |
+
return;
|
377 |
+
|
378 |
+
echo "<ul class='subsubsub'>\n";
|
379 |
+
foreach ( $views as $class => $view ) {
|
380 |
+
$views[ $class ] = "\t<li class='$class'>$view";
|
381 |
+
}
|
382 |
+
echo implode( " |</li>\n", $views ) . "</li>\n";
|
383 |
+
echo "</ul>";
|
384 |
+
}
|
385 |
+
|
386 |
+
/**
|
387 |
+
* Get an associative array ( option_name => option_title ) with the list
|
388 |
+
* of bulk actions available on this table.
|
389 |
+
*
|
390 |
+
* @since 3.1.0
|
391 |
+
* @access protected
|
392 |
+
*
|
393 |
+
* @return array
|
394 |
+
*/
|
395 |
+
protected function get_bulk_actions() {
|
396 |
+
return array();
|
397 |
+
}
|
398 |
+
|
399 |
+
/**
|
400 |
+
* Display the bulk actions dropdown.
|
401 |
+
*
|
402 |
+
* @since 3.1.0
|
403 |
+
* @access protected
|
404 |
+
*
|
405 |
+
* @param string $which The location of the bulk actions: 'top' or 'bottom'.
|
406 |
+
* This is designated as optional for backwards-compatibility.
|
407 |
+
*/
|
408 |
+
protected function bulk_actions( $which = '' ) {
|
409 |
+
if ( is_null( $this->_actions ) ) {
|
410 |
+
$no_new_actions = $this->_actions = $this->get_bulk_actions();
|
411 |
+
/**
|
412 |
+
* Filter the list table Bulk Actions drop-down.
|
413 |
+
*
|
414 |
+
* The dynamic portion of the hook name, `$this->screen->id`, refers
|
415 |
+
* to the ID of the current screen, usually a string.
|
416 |
+
*
|
417 |
+
* This filter can currently only be used to remove bulk actions.
|
418 |
+
*
|
419 |
+
* @since 3.5.0
|
420 |
+
*
|
421 |
+
* @param array $actions An array of the available bulk actions.
|
422 |
+
*/
|
423 |
+
$this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
|
424 |
+
$this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
|
425 |
+
$two = '';
|
426 |
+
} else {
|
427 |
+
$two = '2';
|
428 |
+
}
|
429 |
+
|
430 |
+
if ( empty( $this->_actions ) )
|
431 |
+
return;
|
432 |
+
|
433 |
+
echo "<label for='bulk-action-selector-" . esc_attr( $which ) . "' class='screen-reader-text'>" . __( 'Select bulk action' ) . "</label>";
|
434 |
+
echo "<select name='action$two' id='bulk-action-selector-" . esc_attr( $which ) . "'>\n";
|
435 |
+
echo "<option value='-1' selected='selected'>" . __( 'Bulk Actions' ) . "</option>\n";
|
436 |
+
|
437 |
+
foreach ( $this->_actions as $name => $title ) {
|
438 |
+
$class = 'edit' == $name ? ' class="hide-if-no-js"' : '';
|
439 |
+
|
440 |
+
echo "\t<option value='$name'$class>$title</option>\n";
|
441 |
+
}
|
442 |
+
|
443 |
+
echo "</select>\n";
|
444 |
+
|
445 |
+
submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
|
446 |
+
echo "\n";
|
447 |
+
}
|
448 |
+
|
449 |
+
/**
|
450 |
+
* Get the current action selected from the bulk actions dropdown.
|
451 |
+
*
|
452 |
+
* @since 3.1.0
|
453 |
+
* @access public
|
454 |
+
*
|
455 |
+
* @return string|bool The action name or False if no action was selected
|
456 |
+
*/
|
457 |
+
public function current_action() {
|
458 |
+
if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) )
|
459 |
+
return false;
|
460 |
+
|
461 |
+
if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
|
462 |
+
return $_REQUEST['action'];
|
463 |
+
|
464 |
+
if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] )
|
465 |
+
return $_REQUEST['action2'];
|
466 |
+
|
467 |
+
return false;
|
468 |
+
}
|
469 |
+
|
470 |
+
/**
|
471 |
+
* Generate row actions div
|
472 |
+
*
|
473 |
+
* @since 3.1.0
|
474 |
+
* @access protected
|
475 |
+
*
|
476 |
+
* @param array $actions The list of actions
|
477 |
+
* @param bool $always_visible Whether the actions should be always visible
|
478 |
+
* @return string
|
479 |
+
*/
|
480 |
+
protected function row_actions( $actions, $always_visible = false ) {
|
481 |
+
$action_count = count( $actions );
|
482 |
+
$i = 0;
|
483 |
+
|
484 |
+
if ( !$action_count )
|
485 |
+
return '';
|
486 |
+
|
487 |
+
$out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
|
488 |
+
foreach ( $actions as $action => $link ) {
|
489 |
+
++$i;
|
490 |
+
( $i == $action_count ) ? $sep = '' : $sep = ' | ';
|
491 |
+
$out .= "<span class='$action'>$link$sep</span>";
|
492 |
+
}
|
493 |
+
$out .= '</div>';
|
494 |
+
|
495 |
+
return $out;
|
496 |
+
}
|
497 |
+
|
498 |
+
/**
|
499 |
+
* Display a monthly dropdown for filtering items
|
500 |
+
*
|
501 |
+
* @since 3.1.0
|
502 |
+
* @access protected
|
503 |
+
*
|
504 |
+
* @param string $post_type
|
505 |
+
*/
|
506 |
+
protected function months_dropdown( $post_type ) {
|
507 |
+
global $wpdb, $wp_locale;
|
508 |
+
|
509 |
+
/**
|
510 |
+
* Filter whether to remove the 'Months' drop-down from the post list table.
|
511 |
+
*
|
512 |
+
* @since 4.2.0
|
513 |
+
*
|
514 |
+
* @param bool $disable Whether to disable the drop-down. Default false.
|
515 |
+
* @param string $post_type The post type.
|
516 |
+
*/
|
517 |
+
if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) {
|
518 |
+
return;
|
519 |
+
}
|
520 |
+
|
521 |
+
$months = $wpdb->get_results( $wpdb->prepare( "
|
522 |
+
SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
|
523 |
+
FROM $wpdb->posts
|
524 |
+
WHERE post_type = %s
|
525 |
+
ORDER BY post_date DESC
|
526 |
+
", $post_type ) );
|
527 |
+
|
528 |
+
/**
|
529 |
+
* Filter the 'Months' drop-down results.
|
530 |
+
*
|
531 |
+
* @since 3.7.0
|
532 |
+
*
|
533 |
+
* @param object $months The months drop-down query results.
|
534 |
+
* @param string $post_type The post type.
|
535 |
+
*/
|
536 |
+
$months = apply_filters( 'months_dropdown_results', $months, $post_type );
|
537 |
+
|
538 |
+
$month_count = count( $months );
|
539 |
+
|
540 |
+
if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
|
541 |
+
return;
|
542 |
+
|
543 |
+
$m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
|
544 |
+
?>
|
545 |
+
<label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date' ); ?></label>
|
546 |
+
<select name="m" id="filter-by-date">
|
547 |
+
<option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option>
|
548 |
+
<?php
|
549 |
+
foreach ( $months as $arc_row ) {
|
550 |
+
if ( 0 == $arc_row->year )
|
551 |
+
continue;
|
552 |
+
|
553 |
+
$month = zeroise( $arc_row->month, 2 );
|
554 |
+
$year = $arc_row->year;
|
555 |
+
|
556 |
+
printf( "<option %s value='%s'>%s</option>\n",
|
557 |
+
selected( $m, $year . $month, false ),
|
558 |
+
esc_attr( $arc_row->year . $month ),
|
559 |
+
/* translators: 1: month name, 2: 4-digit year */
|
560 |
+
sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
|
561 |
+
);
|
562 |
+
}
|
563 |
+
?>
|
564 |
+
</select>
|
565 |
+
<?php
|
566 |
+
}
|
567 |
+
|
568 |
+
/**
|
569 |
+
* Display a view switcher
|
570 |
+
*
|
571 |
+
* @since 3.1.0
|
572 |
+
* @access protected
|
573 |
+
*
|
574 |
+
* @param string $current_mode
|
575 |
+
*/
|
576 |
+
protected function view_switcher( $current_mode ) {
|
577 |
+
?>
|
578 |
+
<input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
|
579 |
+
<div class="view-switch">
|
580 |
+
<?php
|
581 |
+
foreach ( $this->modes as $mode => $title ) {
|
582 |
+
$classes = array( 'view-' . $mode );
|
583 |
+
if ( $current_mode == $mode )
|
584 |
+
$classes[] = 'current';
|
585 |
+
printf(
|
586 |
+
"<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n",
|
587 |
+
esc_url( add_query_arg( 'mode', $mode ) ),
|
588 |
+
implode( ' ', $classes ),
|
589 |
+
$title
|
590 |
+
);
|
591 |
+
}
|
592 |
+
?>
|
593 |
+
</div>
|
594 |
+
<?php
|
595 |
+
}
|
596 |
+
|
597 |
+
/**
|
598 |
+
* Display a comment count bubble
|
599 |
+
*
|
600 |
+
* @since 3.1.0
|
601 |
+
* @access protected
|
602 |
+
*
|
603 |
+
* @param int $post_id The post ID.
|
604 |
+
* @param int $pending_comments Number of pending comments.
|
605 |
+
*/
|
606 |
+
protected function comments_bubble( $post_id, $pending_comments ) {
|
607 |
+
$pending_phrase = sprintf( __( '%s pending' ), number_format( $pending_comments ) );
|
608 |
+
|
609 |
+
if ( $pending_comments )
|
610 |
+
echo '<strong>';
|
611 |
+
|
612 |
+
echo "<a href='" . esc_url( add_query_arg( 'p', $post_id, admin_url( 'edit-comments.php' ) ) ) . "' title='" . esc_attr( $pending_phrase ) . "' class='post-com-count'><span class='comment-count'>" . number_format_i18n( get_comments_number() ) . "</span></a>";
|
613 |
+
|
614 |
+
if ( $pending_comments )
|
615 |
+
echo '</strong>';
|
616 |
+
}
|
617 |
+
|
618 |
+
/**
|
619 |
+
* Get the current page number
|
620 |
+
*
|
621 |
+
* @since 3.1.0
|
622 |
+
* @access public
|
623 |
+
*
|
624 |
+
* @return int
|
625 |
+
*/
|
626 |
+
public function get_pagenum() {
|
627 |
+
$pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
|
628 |
+
|
629 |
+
if( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
|
630 |
+
$pagenum = $this->_pagination_args['total_pages'];
|
631 |
+
|
632 |
+
return max( 1, $pagenum );
|
633 |
+
}
|
634 |
+
|
635 |
+
/**
|
636 |
+
* Get number of items to display on a single page
|
637 |
+
*
|
638 |
+
* @since 3.1.0
|
639 |
+
* @access protected
|
640 |
+
*
|
641 |
+
* @param string $option
|
642 |
+
* @param int $default
|
643 |
+
* @return int
|
644 |
+
*/
|
645 |
+
protected function get_items_per_page( $option, $default = 20 ) {
|
646 |
+
$per_page = (int) get_user_option( $option );
|
647 |
+
if ( empty( $per_page ) || $per_page < 1 )
|
648 |
+
$per_page = $default;
|
649 |
+
|
650 |
+
/**
|
651 |
+
* Filter the number of items to be displayed on each page of the list table.
|
652 |
+
*
|
653 |
+
* The dynamic hook name, $option, refers to the `per_page` option depending
|
654 |
+
* on the type of list table in use. Possible values include: 'edit_comments_per_page',
|
655 |
+
* 'sites_network_per_page', 'site_themes_network_per_page', 'themes_network_per_page',
|
656 |
+
* 'users_network_per_page', 'edit_post_per_page', 'edit_page_per_page',
|
657 |
+
* 'edit_{$post_type}_per_page', etc.
|
658 |
+
*
|
659 |
+
* @since 2.9.0
|
660 |
+
*
|
661 |
+
* @param int $per_page Number of items to be displayed. Default 20.
|
662 |
+
*/
|
663 |
+
return (int) apply_filters( $option, $per_page );
|
664 |
+
}
|
665 |
+
|
666 |
+
/**
|
667 |
+
* Display the pagination.
|
668 |
+
*
|
669 |
+
* @since 3.1.0
|
670 |
+
* @access protected
|
671 |
+
*
|
672 |
+
* @param string $which
|
673 |
+
*/
|
674 |
+
protected function pagination( $which ) {
|
675 |
+
if ( empty( $this->_pagination_args ) ) {
|
676 |
+
return;
|
677 |
+
}
|
678 |
+
|
679 |
+
$total_items = $this->_pagination_args['total_items'];
|
680 |
+
$total_pages = $this->_pagination_args['total_pages'];
|
681 |
+
$infinite_scroll = false;
|
682 |
+
if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
|
683 |
+
$infinite_scroll = $this->_pagination_args['infinite_scroll'];
|
684 |
+
}
|
685 |
+
|
686 |
+
$output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
|
687 |
+
|
688 |
+
$current = $this->get_pagenum();
|
689 |
+
|
690 |
+
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
|
691 |
+
|
692 |
+
$current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
|
693 |
+
|
694 |
+
$page_links = array();
|
695 |
+
|
696 |
+
$disable_first = $disable_last = '';
|
697 |
+
if ( $current == 1 ) {
|
698 |
+
$disable_first = ' disabled';
|
699 |
+
}
|
700 |
+
if ( $current == $total_pages ) {
|
701 |
+
$disable_last = ' disabled';
|
702 |
+
}
|
703 |
+
$page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
|
704 |
+
'first-page' . $disable_first,
|
705 |
+
esc_attr__( 'Go to the first page' ),
|
706 |
+
esc_url( remove_query_arg( 'paged', $current_url ) ),
|
707 |
+
'«'
|
708 |
+
);
|
709 |
+
|
710 |
+
$page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
|
711 |
+
'prev-page' . $disable_first,
|
712 |
+
esc_attr__( 'Go to the previous page' ),
|
713 |
+
esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
|
714 |
+
'‹'
|
715 |
+
);
|
716 |
+
|
717 |
+
if ( 'bottom' == $which ) {
|
718 |
+
$html_current_page = $current;
|
719 |
+
} else {
|
720 |
+
$html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' title='%s' type='text' name='paged' value='%s' size='%d' />",
|
721 |
+
'<label for="current-page-selector" class="screen-reader-text">' . __( 'Select Page' ) . '</label>',
|
722 |
+
esc_attr__( 'Current page' ),
|
723 |
+
$current,
|
724 |
+
strlen( $total_pages )
|
725 |
+
);
|
726 |
+
}
|
727 |
+
$html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
|
728 |
+
$page_links[] = '<span class="paging-input">' . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . '</span>';
|
729 |
+
|
730 |
+
$page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
|
731 |
+
'next-page' . $disable_last,
|
732 |
+
esc_attr__( 'Go to the next page' ),
|
733 |
+
esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
|
734 |
+
'›'
|
735 |
+
);
|
736 |
+
|
737 |
+
$page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
|
738 |
+
'last-page' . $disable_last,
|
739 |
+
esc_attr__( 'Go to the last page' ),
|
740 |
+
esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
|
741 |
+
'»'
|
742 |
+
);
|
743 |
+
|
744 |
+
$pagination_links_class = 'pagination-links';
|
745 |
+
if ( ! empty( $infinite_scroll ) ) {
|
746 |
+
$pagination_links_class = ' hide-if-js';
|
747 |
+
}
|
748 |
+
$output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
|
749 |
+
|
750 |
+
if ( $total_pages ) {
|
751 |
+
$page_class = $total_pages < 2 ? ' one-page' : '';
|
752 |
+
} else {
|
753 |
+
$page_class = ' no-pages';
|
754 |
+
}
|
755 |
+
$this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
|
756 |
+
|
757 |
+
echo $this->_pagination;
|
758 |
+
}
|
759 |
+
|
760 |
+
/**
|
761 |
+
* Get a list of columns. The format is:
|
762 |
+
* 'internal-name' => 'Title'
|
763 |
+
*
|
764 |
+
* @since 3.1.0
|
765 |
+
* @access public
|
766 |
+
* @abstract
|
767 |
+
*
|
768 |
+
* @return array
|
769 |
+
*/
|
770 |
+
public function get_columns() {
|
771 |
+
die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' );
|
772 |
+
}
|
773 |
+
|
774 |
+
/**
|
775 |
+
* Get a list of sortable columns. The format is:
|
776 |
+
* 'internal-name' => 'orderby'
|
777 |
+
* or
|
778 |
+
* 'internal-name' => array( 'orderby', true )
|
779 |
+
*
|
780 |
+
* The second format will make the initial sorting order be descending
|
781 |
+
*
|
782 |
+
* @since 3.1.0
|
783 |
+
* @access protected
|
784 |
+
*
|
785 |
+
* @return array
|
786 |
+
*/
|
787 |
+
protected function get_sortable_columns() {
|
788 |
+
return array();
|
789 |
+
}
|
790 |
+
|
791 |
+
/**
|
792 |
+
* Get a list of all, hidden and sortable columns, with filter applied
|
793 |
+
*
|
794 |
+
* @since 3.1.0
|
795 |
+
* @access protected
|
796 |
+
*
|
797 |
+
* @return array
|
798 |
+
*/
|
799 |
+
protected function get_column_info() {
|
800 |
+
if ( isset( $this->_column_headers ) )
|
801 |
+
return $this->_column_headers;
|
802 |
+
|
803 |
+
$columns = get_column_headers( $this->screen );
|
804 |
+
$hidden = get_hidden_columns( $this->screen );
|
805 |
+
|
806 |
+
$sortable_columns = $this->get_sortable_columns();
|
807 |
+
/**
|
808 |
+
* Filter the list table sortable columns for a specific screen.
|
809 |
+
*
|
810 |
+
* The dynamic portion of the hook name, `$this->screen->id`, refers
|
811 |
+
* to the ID of the current screen, usually a string.
|
812 |
+
*
|
813 |
+
* @since 3.5.0
|
814 |
+
*
|
815 |
+
* @param array $sortable_columns An array of sortable columns.
|
816 |
+
*/
|
817 |
+
$_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
|
818 |
+
|
819 |
+
$sortable = array();
|
820 |
+
foreach ( $_sortable as $id => $data ) {
|
821 |
+
if ( empty( $data ) )
|
822 |
+
continue;
|
823 |
+
|
824 |
+
$data = (array) $data;
|
825 |
+
if ( !isset( $data[1] ) )
|
826 |
+
$data[1] = false;
|
827 |
+
|
828 |
+
$sortable[$id] = $data;
|
829 |
+
}
|
830 |
+
|
831 |
+
$this->_column_headers = array( $columns, $hidden, $sortable );
|
832 |
+
|
833 |
+
return $this->_column_headers;
|
834 |
+
}
|
835 |
+
|
836 |
+
/**
|
837 |
+
* Return number of visible columns
|
838 |
+
*
|
839 |
+
* @since 3.1.0
|
840 |
+
* @access public
|
841 |
+
*
|
842 |
+
* @return int
|
843 |
+
*/
|
844 |
+
public function get_column_count() {
|
845 |
+
list ( $columns, $hidden ) = $this->get_column_info();
|
846 |
+
$hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
|
847 |
+
return count( $columns ) - count( $hidden );
|
848 |
+
}
|
849 |
+
|
850 |
+
/**
|
851 |
+
* Print column headers, accounting for hidden and sortable columns.
|
852 |
+
*
|
853 |
+
* @since 3.1.0
|
854 |
+
* @access public
|
855 |
+
*
|
856 |
+
* @param bool $with_id Whether to set the id attribute or not
|
857 |
+
*/
|
858 |
+
public function print_column_headers( $with_id = true ) {
|
859 |
+
list( $columns, $hidden, $sortable ) = $this->get_column_info();
|
860 |
+
|
861 |
+
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
|
862 |
+
$current_url = remove_query_arg( 'paged', $current_url );
|
863 |
+
|
864 |
+
if ( isset( $_GET['orderby'] ) )
|
865 |
+
$current_orderby = $_GET['orderby'];
|
866 |
+
else
|
867 |
+
$current_orderby = '';
|
868 |
+
|
869 |
+
if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] )
|
870 |
+
$current_order = 'desc';
|
871 |
+
else
|
872 |
+
$current_order = 'asc';
|
873 |
+
|
874 |
+
if ( ! empty( $columns['cb'] ) ) {
|
875 |
+
static $cb_counter = 1;
|
876 |
+
$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
|
877 |
+
. '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
|
878 |
+
$cb_counter++;
|
879 |
+
}
|
880 |
+
|
881 |
+
foreach ( $columns as $column_key => $column_display_name ) {
|
882 |
+
$class = array( 'manage-column', "column-$column_key" );
|
883 |
+
|
884 |
+
$style = '';
|
885 |
+
if ( in_array( $column_key, $hidden ) )
|
886 |
+
$style = 'display:none;';
|
887 |
+
|
888 |
+
$style = ' style="' . $style . '"';
|
889 |
+
|
890 |
+
if ( 'cb' == $column_key )
|
891 |
+
$class[] = 'check-column';
|
892 |
+
elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )
|
893 |
+
$class[] = 'num';
|
894 |
+
|
895 |
+
if ( isset( $sortable[$column_key] ) ) {
|
896 |
+
list( $orderby, $desc_first ) = $sortable[$column_key];
|
897 |
+
|
898 |
+
if ( $current_orderby == $orderby ) {
|
899 |
+
$order = 'asc' == $current_order ? 'desc' : 'asc';
|
900 |
+
$class[] = 'sorted';
|
901 |
+
$class[] = $current_order;
|
902 |
+
} else {
|
903 |
+
$order = $desc_first ? 'desc' : 'asc';
|
904 |
+
$class[] = 'sortable';
|
905 |
+
$class[] = $desc_first ? 'asc' : 'desc';
|
906 |
+
}
|
907 |
+
|
908 |
+
$column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
|
909 |
+
}
|
910 |
+
|
911 |
+
$id = $with_id ? "id='$column_key'" : '';
|
912 |
+
|
913 |
+
if ( !empty( $class ) )
|
914 |
+
$class = "class='" . join( ' ', $class ) . "'";
|
915 |
+
|
916 |
+
echo "<th scope='col' $id $class $style>$column_display_name</th>";
|
917 |
+
}
|
918 |
+
}
|
919 |
+
|
920 |
+
/**
|
921 |
+
* Display the table
|
922 |
+
*
|
923 |
+
* @since 3.1.0
|
924 |
+
* @access public
|
925 |
+
*/
|
926 |
+
public function display() {
|
927 |
+
$singular = $this->_args['singular'];
|
928 |
+
|
929 |
+
$this->display_tablenav( 'top' );
|
930 |
+
|
931 |
+
?>
|
932 |
+
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
|
933 |
+
<thead>
|
934 |
+
<tr>
|
935 |
+
<?php $this->print_column_headers(); ?>
|
936 |
+
</tr>
|
937 |
+
</thead>
|
938 |
+
|
939 |
+
<tbody id="the-list"<?php
|
940 |
+
if ( $singular ) {
|
941 |
+
echo " data-wp-lists='list:$singular'";
|
942 |
+
} ?>>
|
943 |
+
<?php $this->display_rows_or_placeholder(); ?>
|
944 |
+
</tbody>
|
945 |
+
|
946 |
+
<tfoot>
|
947 |
+
<tr>
|
948 |
+
<?php $this->print_column_headers( false ); ?>
|
949 |
+
</tr>
|
950 |
+
</tfoot>
|
951 |
+
|
952 |
+
</table>
|
953 |
+
<?php
|
954 |
+
$this->display_tablenav( 'bottom' );
|
955 |
+
}
|
956 |
+
|
957 |
+
/**
|
958 |
+
* Get a list of CSS classes for the list table table tag.
|
959 |
+
*
|
960 |
+
* @since 3.1.0
|
961 |
+
* @access protected
|
962 |
+
*
|
963 |
+
* @return array List of CSS classes for the table tag.
|
964 |
+
*/
|
965 |
+
protected function get_table_classes() {
|
966 |
+
return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
|
967 |
+
}
|
968 |
+
|
969 |
+
/**
|
970 |
+
* Generate the table navigation above or below the table
|
971 |
+
*
|
972 |
+
* @since 3.1.0
|
973 |
+
* @access protected
|
974 |
+
* @param string $which
|
975 |
+
*/
|
976 |
+
protected function display_tablenav( $which ) {
|
977 |
+
if ( 'top' == $which )
|
978 |
+
wp_nonce_field( 'bulk-' . $this->_args['plural'] );
|
979 |
+
?>
|
980 |
+
<div class="tablenav <?php echo esc_attr( $which ); ?>">
|
981 |
+
|
982 |
+
<div class="alignleft actions bulkactions">
|
983 |
+
<?php $this->bulk_actions( $which ); ?>
|
984 |
+
</div>
|
985 |
+
<?php
|
986 |
+
$this->extra_tablenav( $which );
|
987 |
+
$this->pagination( $which );
|
988 |
+
?>
|
989 |
+
|
990 |
+
<br class="clear" />
|
991 |
+
</div>
|
992 |
+
<?php
|
993 |
+
}
|
994 |
+
|
995 |
+
/**
|
996 |
+
* Extra controls to be displayed between bulk actions and pagination
|
997 |
+
*
|
998 |
+
* @since 3.1.0
|
999 |
+
* @access protected
|
1000 |
+
*
|
1001 |
+
* @param string $which
|
1002 |
+
*/
|
1003 |
+
protected function extra_tablenav( $which ) {}
|
1004 |
+
|
1005 |
+
/**
|
1006 |
+
* Generate the tbody element for the list table.
|
1007 |
+
*
|
1008 |
+
* @since 3.1.0
|
1009 |
+
* @access public
|
1010 |
+
*/
|
1011 |
+
public function display_rows_or_placeholder() {
|
1012 |
+
if ( $this->has_items() ) {
|
1013 |
+
$this->display_rows();
|
1014 |
+
} else {
|
1015 |
+
echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
|
1016 |
+
$this->no_items();
|
1017 |
+
echo '</td></tr>';
|
1018 |
+
}
|
1019 |
+
}
|
1020 |
+
|
1021 |
+
/**
|
1022 |
+
* Generate the table rows
|
1023 |
+
*
|
1024 |
+
* @since 3.1.0
|
1025 |
+
* @access public
|
1026 |
+
*/
|
1027 |
+
public function display_rows() {
|
1028 |
+
foreach ( $this->items as $item )
|
1029 |
+
$this->single_row( $item );
|
1030 |
+
}
|
1031 |
+
|
1032 |
+
/**
|
1033 |
+
* Generates content for a single row of the table
|
1034 |
+
*
|
1035 |
+
* @since 3.1.0
|
1036 |
+
* @access public
|
1037 |
+
*
|
1038 |
+
* @param object $item The current item
|
1039 |
+
*/
|
1040 |
+
public function single_row( $item ) {
|
1041 |
+
echo '<tr>';
|
1042 |
+
$this->single_row_columns( $item );
|
1043 |
+
echo '</tr>';
|
1044 |
+
}
|
1045 |
+
|
1046 |
+
protected function column_default( $item, $column_name ) {}
|
1047 |
+
|
1048 |
+
protected function column_cb( $item ) {}
|
1049 |
+
|
1050 |
+
/**
|
1051 |
+
* Generates the columns for a single row of the table
|
1052 |
+
*
|
1053 |
+
* @since 3.1.0
|
1054 |
+
* @access protected
|
1055 |
+
*
|
1056 |
+
* @param object $item The current item
|
1057 |
+
*/
|
1058 |
+
protected function single_row_columns( $item ) {
|
1059 |
+
list( $columns, $hidden ) = $this->get_column_info();
|
1060 |
+
|
1061 |
+
foreach ( $columns as $column_name => $column_display_name ) {
|
1062 |
+
$class = "class='$column_name column-$column_name'";
|
1063 |
+
|
1064 |
+
$style = '';
|
1065 |
+
if ( in_array( $column_name, $hidden ) )
|
1066 |
+
$style = ' style="display:none;"';
|
1067 |
+
|
1068 |
+
$attributes = "$class$style";
|
1069 |
+
|
1070 |
+
if ( 'cb' == $column_name ) {
|
1071 |
+
echo '<th scope="row" class="check-column">';
|
1072 |
+
echo $this->column_cb( $item );
|
1073 |
+
echo '</th>';
|
1074 |
+
}
|
1075 |
+
elseif ( method_exists( $this, 'column_' . $column_name ) ) {
|
1076 |
+
echo "<td $attributes>";
|
1077 |
+
echo call_user_func( array( $this, 'column_' . $column_name ), $item );
|
1078 |
+
echo "</td>";
|
1079 |
+
}
|
1080 |
+
else {
|
1081 |
+
echo "<td $attributes>";
|
1082 |
+
echo $this->column_default( $item, $column_name );
|
1083 |
+
echo "</td>";
|
1084 |
+
}
|
1085 |
+
}
|
1086 |
+
}
|
1087 |
+
|
1088 |
+
/**
|
1089 |
+
* Handle an incoming ajax request (called from admin-ajax.php)
|
1090 |
+
*
|
1091 |
+
* @since 3.1.0
|
1092 |
+
* @access public
|
1093 |
+
*/
|
1094 |
+
public function ajax_response() {
|
1095 |
+
$this->prepare_items();
|
1096 |
+
|
1097 |
+
ob_start();
|
1098 |
+
if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
|
1099 |
+
$this->display_rows();
|
1100 |
+
} else {
|
1101 |
+
$this->display_rows_or_placeholder();
|
1102 |
+
}
|
1103 |
+
|
1104 |
+
$rows = ob_get_clean();
|
1105 |
+
|
1106 |
+
$response = array( 'rows' => $rows );
|
1107 |
+
|
1108 |
+
if ( isset( $this->_pagination_args['total_items'] ) ) {
|
1109 |
+
$response['total_items_i18n'] = sprintf(
|
1110 |
+
_n( '1 item', '%s items', $this->_pagination_args['total_items'] ),
|
1111 |
+
number_format_i18n( $this->_pagination_args['total_items'] )
|
1112 |
+
);
|
1113 |
+
}
|
1114 |
+
if ( isset( $this->_pagination_args['total_pages'] ) ) {
|
1115 |
+
$response['total_pages'] = $this->_pagination_args['total_pages'];
|
1116 |
+
$response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
|
1117 |
+
}
|
1118 |
+
|
1119 |
+
die( wp_json_encode( $response ) );
|
1120 |
+
}
|
1121 |
+
|
1122 |
+
/**
|
1123 |
+
* Send required variables to JavaScript land
|
1124 |
+
*
|
1125 |
+
* @access public
|
1126 |
+
*/
|
1127 |
+
public function _js_vars() {
|
1128 |
+
$args = array(
|
1129 |
+
'class' => get_class( $this ),
|
1130 |
+
'screen' => array(
|
1131 |
+
'id' => $this->screen->id,
|
1132 |
+
'base' => $this->screen->base,
|
1133 |
+
)
|
1134 |
+
);
|
1135 |
+
|
1136 |
+
printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) );
|
1137 |
+
}
|
1138 |
+
}
|
ipn/swpm_handle_pp_ipn.php
CHANGED
@@ -183,7 +183,7 @@ class swpm_paypal_ipn_handler {
|
|
183 |
$this->debug_log('Saving transaction data to the database table.', true);
|
184 |
$this->ipn_data['gateway'] = 'paypal';
|
185 |
$this->ipn_data['status'] = $this->ipn_data['payment_status'];
|
186 |
-
|
187 |
$this->debug_log('Transaction data saved.', true);
|
188 |
|
189 |
|
@@ -310,7 +310,7 @@ class swpm_paypal_ipn_handler {
|
|
310 |
|
311 |
function debug_log($message,$success,$end=false)
|
312 |
{
|
313 |
-
|
314 |
}
|
315 |
}
|
316 |
|
@@ -318,7 +318,7 @@ class swpm_paypal_ipn_handler {
|
|
318 |
|
319 |
$ipn_handler_instance = new swpm_paypal_ipn_handler();
|
320 |
|
321 |
-
$settings =
|
322 |
$debug_enabled = $settings->get_value('enable-debug');
|
323 |
if(!empty($debug_enabled))//debug is enabled in the system
|
324 |
{
|
183 |
$this->debug_log('Saving transaction data to the database table.', true);
|
184 |
$this->ipn_data['gateway'] = 'paypal';
|
185 |
$this->ipn_data['status'] = $this->ipn_data['payment_status'];
|
186 |
+
SwpmTransactions::save_txn_record($this->ipn_data, $cart_items);
|
187 |
$this->debug_log('Transaction data saved.', true);
|
188 |
|
189 |
|
310 |
|
311 |
function debug_log($message,$success,$end=false)
|
312 |
{
|
313 |
+
SwpmLog::log_simple_debug($message, $success, $end);
|
314 |
}
|
315 |
}
|
316 |
|
318 |
|
319 |
$ipn_handler_instance = new swpm_paypal_ipn_handler();
|
320 |
|
321 |
+
$settings = SwpmSettings::get_instance();
|
322 |
$debug_enabled = $settings->get_value('enable-debug');
|
323 |
if(!empty($debug_enabled))//debug is enabled in the system
|
324 |
{
|
ipn/swpm_handle_subsc_ipn.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
function swpm_handle_subsc_signup_stand_alone($ipn_data,$subsc_ref,$unique_ref,$swpm_id='')
|
4 |
{
|
5 |
global $wpdb;
|
6 |
-
$settings =
|
7 |
$members_table_name = $wpdb->prefix . "swpm_members_tbl";
|
8 |
$membership_level_table = $wpdb->prefix . "swpm_membership_tbl";
|
9 |
$membership_level = $subsc_ref;
|
@@ -180,7 +180,7 @@ function swpm_update_member_subscription_start_date_if_applicable($ipn_data)
|
|
180 |
$membership_level_table = $wpdb->prefix . "swpm_membership_tbl";
|
181 |
$email = $ipn_data['payer_email'];
|
182 |
$subscr_id = $ipn_data['subscr_id'];
|
183 |
-
$account_state =
|
184 |
swpm_debug_log_subsc("Updating subscription start date if applicable for this subscription payment. Subscriber ID: ".$subscr_id." Email: ".$email,true);
|
185 |
|
186 |
//We can also query using the email address
|
@@ -202,7 +202,7 @@ function swpm_update_member_subscription_start_date_if_applicable($ipn_data)
|
|
202 |
|
203 |
function swpm_debug_log_subsc($message,$success,$end=false)
|
204 |
{
|
205 |
-
$settings =
|
206 |
$debug_enabled = $settings->get_value('enable-debug');
|
207 |
if (empty($debug_enabled)) {//Debug is not enabled
|
208 |
return;
|
3 |
function swpm_handle_subsc_signup_stand_alone($ipn_data,$subsc_ref,$unique_ref,$swpm_id='')
|
4 |
{
|
5 |
global $wpdb;
|
6 |
+
$settings = SwpmSettings::get_instance();
|
7 |
$members_table_name = $wpdb->prefix . "swpm_members_tbl";
|
8 |
$membership_level_table = $wpdb->prefix . "swpm_membership_tbl";
|
9 |
$membership_level = $subsc_ref;
|
180 |
$membership_level_table = $wpdb->prefix . "swpm_membership_tbl";
|
181 |
$email = $ipn_data['payer_email'];
|
182 |
$subscr_id = $ipn_data['subscr_id'];
|
183 |
+
$account_state = SwpmSettings::get_instance()->get_value('default-account-status', 'active');
|
184 |
swpm_debug_log_subsc("Updating subscription start date if applicable for this subscription payment. Subscriber ID: ".$subscr_id." Email: ".$email,true);
|
185 |
|
186 |
//We can also query using the email address
|
202 |
|
203 |
function swpm_debug_log_subsc($message,$success,$end=false)
|
204 |
{
|
205 |
+
$settings = SwpmSettings::get_instance();
|
206 |
$debug_enabled = $settings->get_value('enable-debug');
|
207 |
if (empty($debug_enabled)) {//Debug is not enabled
|
208 |
return;
|
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,
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 4.2
|
7 |
-
Stable tag: 2.2.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -105,6 +105,12 @@ Please visit the memberhsip plugin page to view screenshots:
|
|
105 |
https://simple-membership-plugin.com/
|
106 |
|
107 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
= 2.2.4 =
|
110 |
- Fixed an issue with not being able to unprotect the category protection.
|
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,
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 4.2
|
7 |
+
Stable tag: 2.2.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
105 |
https://simple-membership-plugin.com/
|
106 |
|
107 |
== Changelog ==
|
108 |
+
= 2.2.6 =
|
109 |
+
- Fixed an issue with the category protection menu after the class refactoring work.
|
110 |
+
- Fixed the unique key in the DB table
|
111 |
+
|
112 |
+
= 2.2.5 =
|
113 |
+
- Refactored all the class names to use the "swpm" slug to remove potential conflict with other plugins with similar class names.
|
114 |
|
115 |
= 2.2.4 =
|
116 |
- Fixed an issue with not being able to unprotect the category protection.
|
simple-wp-membership.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Simple WordPress Membership
|
4 |
-
Version: v2.2.
|
5 |
Plugin URI: https://simple-membership-plugin.com/
|
6 |
Author: smp7, wp.insider
|
7 |
Author URI: https://simple-membership-plugin.com/
|
@@ -9,29 +9,32 @@ Description: A flexible, well-supported, and easy-to-use WordPress membership pl
|
|
9 |
*/
|
10 |
|
11 |
//Direct access to this file is not permitted
|
12 |
-
if (realpath
|
13 |
exit("Do not access this file directly.");
|
14 |
}
|
15 |
|
16 |
include_once('classes/class.simple-wp-membership.php');
|
17 |
-
include_once('classes/class.
|
|
|
18 |
|
19 |
-
define('SIMPLE_WP_MEMBERSHIP_VER', '2.2.
|
20 |
define('SIMPLE_WP_MEMBERSHIP_DB_VER', '1.2');
|
21 |
define('SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL', home_url());
|
22 |
define('SIMPLE_WP_MEMBERSHIP_PATH', dirname(__FILE__) . '/');
|
23 |
-
define('SIMPLE_WP_MEMBERSHIP_URL', plugins_url('',__FILE__));
|
24 |
define('SIMPLE_WP_MEMBERSHIP_DIRNAME', dirname(plugin_basename(__FILE__)));
|
25 |
-
if (!defined('COOKIEHASH')) {
|
26 |
-
define('
|
27 |
-
|
|
|
|
|
28 |
|
29 |
-
register_activation_hook(
|
30 |
-
register_deactivation_hook(
|
31 |
-
add_action('swpm_login','SimpleWpMembership::swpm_login', 10,3);
|
32 |
|
33 |
$simple_membership = new SimpleWpMembership();
|
34 |
-
$simple_membership_cron = new
|
35 |
|
36 |
//Add settings link in plugins listing page
|
37 |
function swpm_add_settings_link($links, $file) {
|
@@ -41,4 +44,5 @@ function swpm_add_settings_link($links, $file) {
|
|
41 |
}
|
42 |
return $links;
|
43 |
}
|
44 |
-
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Simple WordPress Membership
|
4 |
+
Version: v2.2.6
|
5 |
Plugin URI: https://simple-membership-plugin.com/
|
6 |
Author: smp7, wp.insider
|
7 |
Author URI: https://simple-membership-plugin.com/
|
9 |
*/
|
10 |
|
11 |
//Direct access to this file is not permitted
|
12 |
+
if (realpath(__FILE__) === realpath($_SERVER["SCRIPT_FILENAME"])) {
|
13 |
exit("Do not access this file directly.");
|
14 |
}
|
15 |
|
16 |
include_once('classes/class.simple-wp-membership.php');
|
17 |
+
include_once('classes/class.swpm-cronjob.php');
|
18 |
+
include_once('swpm-compat.php');
|
19 |
|
20 |
+
define('SIMPLE_WP_MEMBERSHIP_VER', '2.2.6');
|
21 |
define('SIMPLE_WP_MEMBERSHIP_DB_VER', '1.2');
|
22 |
define('SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL', home_url());
|
23 |
define('SIMPLE_WP_MEMBERSHIP_PATH', dirname(__FILE__) . '/');
|
24 |
+
define('SIMPLE_WP_MEMBERSHIP_URL', plugins_url('', __FILE__));
|
25 |
define('SIMPLE_WP_MEMBERSHIP_DIRNAME', dirname(plugin_basename(__FILE__)));
|
26 |
+
if (!defined('COOKIEHASH')) {
|
27 |
+
define('COOKIEHASH', md5(get_site_option('siteurl')));
|
28 |
+
}
|
29 |
+
define('SIMPLE_WP_MEMBERSHIP_AUTH', 'simple_wp_membership_' . COOKIEHASH);
|
30 |
+
define('SIMPLE_WP_MEMBERSHIP_SEC_AUTH', 'simple_wp_membership_sec_' . COOKIEHASH);
|
31 |
|
32 |
+
register_activation_hook(SIMPLE_WP_MEMBERSHIP_PATH . 'simple-wp-membership.php', 'SimpleWpMembership::activate');
|
33 |
+
register_deactivation_hook(SIMPLE_WP_MEMBERSHIP_PATH . 'simple-wp-membership.php', 'SimpleWpMembership::deactivate');
|
34 |
+
add_action('swpm_login', 'SimpleWpMembership::swpm_login', 10, 3);
|
35 |
|
36 |
$simple_membership = new SimpleWpMembership();
|
37 |
+
$simple_membership_cron = new SwpmCronJob();
|
38 |
|
39 |
//Add settings link in plugins listing page
|
40 |
function swpm_add_settings_link($links, $file) {
|
44 |
}
|
45 |
return $links;
|
46 |
}
|
47 |
+
|
48 |
+
add_filter('plugin_action_links', 'swpm_add_settings_link', 10, 2);
|
swpm-compat.php
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*** TODO - This file exists for backwards compatibility only. Remove it at a later date. ***/
|
4 |
+
class miscUtils extends SwpmMiscUtils {
|
5 |
+
|
6 |
+
}
|
7 |
+
|
8 |
+
class BUtils extends SwpmUtils {
|
9 |
+
|
10 |
+
}
|
11 |
+
|
12 |
+
class BMemberUtils extends SwpmMemberUtils {
|
13 |
+
|
14 |
+
}
|
15 |
+
|
16 |
+
class BSettings extends SwpmSettings {
|
17 |
+
|
18 |
+
}
|
19 |
+
|
20 |
+
class BProtection extends SwpmProtection {
|
21 |
+
|
22 |
+
}
|
23 |
+
|
24 |
+
class BPermission extends SwpmPermission {
|
25 |
+
|
26 |
+
}
|
27 |
+
|
28 |
+
class BAuth extends SwpmAuth {
|
29 |
+
|
30 |
+
}
|
31 |
+
|
32 |
+
class BAccessControl extends SwpmAccessControl {
|
33 |
+
|
34 |
+
}
|
35 |
+
|
36 |
+
class BForm extends SwpmForm {
|
37 |
+
|
38 |
+
}
|
39 |
+
|
40 |
+
class BTransfer extends SwpmTransfer {
|
41 |
+
|
42 |
+
}
|
43 |
+
|
44 |
+
class BFrontForm extends SwpmFrontForm {
|
45 |
+
|
46 |
+
}
|
47 |
+
|
48 |
+
class BLevelForm extends SwpmLevelForm {
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
class BMembershipLevels extends SwpmMembershipLevels {
|
53 |
+
|
54 |
+
}
|
55 |
+
|
56 |
+
class BLog extends SwpmLog {
|
57 |
+
|
58 |
+
}
|
59 |
+
|
60 |
+
class BMessages extends SwpmMessages {
|
61 |
+
|
62 |
+
}
|
63 |
+
|
64 |
+
class BAjax extends SwpmAjax {
|
65 |
+
|
66 |
+
}
|
67 |
+
|
68 |
+
class BRegistration extends SwpmRegistration {
|
69 |
+
|
70 |
+
}
|
71 |
+
|
72 |
+
class BFrontRegistration extends SwpmFrontRegistration {
|
73 |
+
|
74 |
+
}
|
75 |
+
|
76 |
+
class BAdminRegistration extends SwpmAdminRegistration {
|
77 |
+
|
78 |
+
}
|
79 |
+
|
80 |
+
class BMembershipLevel extends SwpmMembershipLevel {
|
81 |
+
|
82 |
+
}
|
83 |
+
|
84 |
+
class BMembershipLevelCustom extends SwpmMembershipLevelCustom {
|
85 |
+
|
86 |
+
}
|
87 |
+
|
88 |
+
class BMembershipLevelUtils extends SwpmMembershipLevelUtils {
|
89 |
+
|
90 |
+
}
|
91 |
+
|
92 |
+
class BPermissionCollection extends SwpmPermissionCollection {
|
93 |
+
|
94 |
+
}
|
95 |
+
|
96 |
+
class BAuthPermissionCollection extends SwpmAuthPermissionCollection {
|
97 |
+
|
98 |
+
}
|
99 |
+
|
100 |
+
class BTransactions extends SwpmTransactions {
|
101 |
+
|
102 |
+
}
|
views/add.php
CHANGED
@@ -3,38 +3,38 @@
|
|
3 |
<input type ="hidden" name="level_identifier" value="<?php echo $level_identifier?>" />
|
4 |
<table>
|
5 |
<tr>
|
6 |
-
<td><label for="user_name"><?php echo
|
7 |
<td><input type="text" id="user_name" class="validate[required,custom[noapostrophe],custom[SWPMUserName],minSize[4],ajax[ajaxUserCall]]" value="<?php echo $user_name;?>" tabindex="1" size="50" name="user_name" /></td>
|
8 |
</tr>
|
9 |
<tr>
|
10 |
-
<td><label for="email"><?php echo
|
11 |
<td><input type="text" id="email" class="validate[required,custom[email],ajax[ajaxEmailCall]]" value="<?php echo $email;?>" tabindex="2" size="50" name="email" /></td>
|
12 |
</tr>
|
13 |
<tr>
|
14 |
-
<td><label for="password"><?php echo
|
15 |
<td><input type="password" autocomplete="off" id="password" value="" tabindex="3" size="50" name="password" /></td>
|
16 |
</tr>
|
17 |
<tr>
|
18 |
-
<td><label for="password_re"><?php echo
|
19 |
<td><input type="password" autocomplete="off" id="password_re" value="" tabindex="4" size="50" name="password_re" /></td>
|
20 |
</tr>
|
21 |
<tr>
|
22 |
-
<td><label for="first_name"><?php echo
|
23 |
<td><input type="text" id="first_name" value="<?php echo $first_name;?>" tabindex="5" size="50" name="first_name" /></td>
|
24 |
</tr>
|
25 |
<tr>
|
26 |
-
<td><label for="last_name"><?php echo
|
27 |
<td><input type="text" id="last_name" value="<?php echo $last_name;?>" tabindex="6" size="50" name="last_name" /></td>
|
28 |
</tr>
|
29 |
<tr>
|
30 |
-
<td><label for="membership_level"><?php echo
|
31 |
<td>
|
32 |
<?php echo $membership_level_alias;?>
|
33 |
<input type="hidden" value="<?php echo $membership_level;?>" size="50" name="membership_level" tabindex="7" id="membership_level" />
|
34 |
</td>
|
35 |
</tr>
|
36 |
</table>
|
37 |
-
<p align="center"><input type="submit" value="<?php echo
|
38 |
<input type="hidden" name="action" value="custom_posts" />
|
39 |
<?php wp_nonce_field( 'name_of_my_action','name_of_nonce_field' ); ?>
|
40 |
</form>
|
3 |
<input type ="hidden" name="level_identifier" value="<?php echo $level_identifier?>" />
|
4 |
<table>
|
5 |
<tr>
|
6 |
+
<td><label for="user_name"><?php echo SwpmUtils::_('User Name') ?></label></td>
|
7 |
<td><input type="text" id="user_name" class="validate[required,custom[noapostrophe],custom[SWPMUserName],minSize[4],ajax[ajaxUserCall]]" value="<?php echo $user_name;?>" tabindex="1" size="50" name="user_name" /></td>
|
8 |
</tr>
|
9 |
<tr>
|
10 |
+
<td><label for="email"><?php echo SwpmUtils::_('Email') ?></label></td>
|
11 |
<td><input type="text" id="email" class="validate[required,custom[email],ajax[ajaxEmailCall]]" value="<?php echo $email;?>" tabindex="2" size="50" name="email" /></td>
|
12 |
</tr>
|
13 |
<tr>
|
14 |
+
<td><label for="password"><?php echo SwpmUtils::_('Password') ?></label></td>
|
15 |
<td><input type="password" autocomplete="off" id="password" value="" tabindex="3" size="50" name="password" /></td>
|
16 |
</tr>
|
17 |
<tr>
|
18 |
+
<td><label for="password_re"><?php echo SwpmUtils::_('Repeat Password') ?></label></td>
|
19 |
<td><input type="password" autocomplete="off" id="password_re" value="" tabindex="4" size="50" name="password_re" /></td>
|
20 |
</tr>
|
21 |
<tr>
|
22 |
+
<td><label for="first_name"><?php echo SwpmUtils::_('First Name') ?></label></td>
|
23 |
<td><input type="text" id="first_name" value="<?php echo $first_name;?>" tabindex="5" size="50" name="first_name" /></td>
|
24 |
</tr>
|
25 |
<tr>
|
26 |
+
<td><label for="last_name"><?php echo SwpmUtils::_('Last Name') ?></label></td>
|
27 |
<td><input type="text" id="last_name" value="<?php echo $last_name;?>" tabindex="6" size="50" name="last_name" /></td>
|
28 |
</tr>
|
29 |
<tr>
|
30 |
+
<td><label for="membership_level"><?php echo SwpmUtils::_('Membership Level') ?></label></td>
|
31 |
<td>
|
32 |
<?php echo $membership_level_alias;?>
|
33 |
<input type="hidden" value="<?php echo $membership_level;?>" size="50" name="membership_level" tabindex="7" id="membership_level" />
|
34 |
</td>
|
35 |
</tr>
|
36 |
</table>
|
37 |
+
<p align="center"><input type="submit" value="<?php echo SwpmUtils::_('Register') ?>" tabindex="8" id="submit" name="swpm_registration_submit" /></p>
|
38 |
<input type="hidden" name="action" value="custom_posts" />
|
39 |
<?php wp_nonce_field( 'name_of_my_action','name_of_nonce_field' ); ?>
|
40 |
</form>
|
views/admin_add.php
CHANGED
@@ -3,32 +3,32 @@
|
|
3 |
<form action="" method="post" name="swpm-create-user" id="swpm-create-user" class="validate"<?php do_action('user_new_form_tag');?>>
|
4 |
<input name="action" type="hidden" value="createuser" />
|
5 |
<?php wp_nonce_field( 'create-swpmuser', '_wpnonce_create-swpmuser' ) ?>
|
6 |
-
<h3><?php echo
|
7 |
-
<p><?php echo
|
8 |
<table class="form-table">
|
9 |
<tbody>
|
10 |
<tr class="form-required">
|
11 |
-
<th scope="row"><label for="user_name"><?php echo
|
12 |
<td><input class="regular-text validate[required,custom[noapostrophe],custom[SWPMUserName],minSize[4],ajax[ajaxUserCall]]" name="user_name" type="text" id="user_name" value="<?php echo esc_attr(stripslashes($user_name)); ?>" aria-required="true" /></td>
|
13 |
</tr>
|
14 |
<tr class="form-required">
|
15 |
-
<th scope="row"><label for="email"><?php echo
|
16 |
<td><input name="email" class="regular-text validate[required,custom[email],ajax[ajaxEmailCall]]" type="text" id="email" value="<?php echo esc_attr($email); ?>" /></td>
|
17 |
</tr>
|
18 |
<tr class="form-required">
|
19 |
-
<th scope="row"><label for="password"><?php echo
|
20 |
<td><input class="regular-text" name="password" type="password" id="pass1" autocomplete="off" />
|
21 |
<br />
|
22 |
<input class="regular-text" name="password_re" type="password" id="pass2" autocomplete="off" />
|
23 |
<br />
|
24 |
-
<div id="pass-strength-result"><?php echo
|
25 |
-
<p class="description indicator-hint"><?php echo
|
26 |
</td>
|
27 |
</tr>
|
28 |
<tr>
|
29 |
-
<th scope="row"><label for="account_state"><?php echo
|
30 |
<td><select class="regular-text" name="account_state" id="account_state">
|
31 |
-
<?php echo
|
32 |
</select>
|
33 |
</td>
|
34 |
</tr>
|
@@ -36,7 +36,7 @@
|
|
36 |
</tbody>
|
37 |
</table>
|
38 |
<?php include('admin_member_form_common_js.php');?>
|
39 |
-
<?php submit_button(
|
40 |
</form>
|
41 |
</div>
|
42 |
<script>
|
3 |
<form action="" method="post" name="swpm-create-user" id="swpm-create-user" class="validate"<?php do_action('user_new_form_tag');?>>
|
4 |
<input name="action" type="hidden" value="createuser" />
|
5 |
<?php wp_nonce_field( 'create-swpmuser', '_wpnonce_create-swpmuser' ) ?>
|
6 |
+
<h3><?php echo SwpmUtils::_('Add Member') ?></h3>
|
7 |
+
<p><?php echo SwpmUtils::_('Create a brand new user and add it to this site.'); ?></p>
|
8 |
<table class="form-table">
|
9 |
<tbody>
|
10 |
<tr class="form-required">
|
11 |
+
<th scope="row"><label for="user_name"><?php echo SwpmUtils::_('User name'); ?> <span class="description"><?php echo SwpmUtils::_('(required)'); ?></span></label></th>
|
12 |
<td><input class="regular-text validate[required,custom[noapostrophe],custom[SWPMUserName],minSize[4],ajax[ajaxUserCall]]" name="user_name" type="text" id="user_name" value="<?php echo esc_attr(stripslashes($user_name)); ?>" aria-required="true" /></td>
|
13 |
</tr>
|
14 |
<tr class="form-required">
|
15 |
+
<th scope="row"><label for="email"><?php echo SwpmUtils::_('E-mail'); ?> <span class="description"><?php echo SwpmUtils::_('(required)'); ?></span></label></th>
|
16 |
<td><input name="email" class="regular-text validate[required,custom[email],ajax[ajaxEmailCall]]" type="text" id="email" value="<?php echo esc_attr($email); ?>" /></td>
|
17 |
</tr>
|
18 |
<tr class="form-required">
|
19 |
+
<th scope="row"><label for="password"><?php echo SwpmUtils::_('Password'); ?> <span class="description"><?php /* translators: password input field */_e('(twice, required)'); ?></span></label></th>
|
20 |
<td><input class="regular-text" name="password" type="password" id="pass1" autocomplete="off" />
|
21 |
<br />
|
22 |
<input class="regular-text" name="password_re" type="password" id="pass2" autocomplete="off" />
|
23 |
<br />
|
24 |
+
<div id="pass-strength-result"><?php echo SwpmUtils::_('Strength indicator'); ?></div>
|
25 |
+
<p class="description indicator-hint"><?php echo SwpmUtils::_('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ & ).'); ?></p>
|
26 |
</td>
|
27 |
</tr>
|
28 |
<tr>
|
29 |
+
<th scope="row"><label for="account_state"><?php echo SwpmUtils::_('Account Status'); ?></label></th>
|
30 |
<td><select class="regular-text" name="account_state" id="account_state">
|
31 |
+
<?php echo SwpmUtils::account_state_dropdown('active');?>
|
32 |
</select>
|
33 |
</td>
|
34 |
</tr>
|
36 |
</tbody>
|
37 |
</table>
|
38 |
<?php include('admin_member_form_common_js.php');?>
|
39 |
+
<?php submit_button( SwpmUtils::_('Add New Member '), 'primary', 'createswpmuser', true, array( 'id' => 'createswpmusersub' ) ); ?>
|
40 |
</form>
|
41 |
</div>
|
42 |
<script>
|
views/admin_add_level.php
CHANGED
@@ -3,39 +3,39 @@
|
|
3 |
<form action="" method="post" name="swpm-create-level" id="swpm-create-level" class="validate"<?php do_action('level_new_form_tag');?>>
|
4 |
<input name="action" type="hidden" value="createlevel" />
|
5 |
<h3>Add Membership Level</h3>
|
6 |
-
<p><?php echo
|
7 |
<?php wp_nonce_field( 'create-swpmlevel', '_wpnonce_create-swpmlevel' ) ?>
|
8 |
<table class="form-table">
|
9 |
<tbody>
|
10 |
<tr>
|
11 |
-
<th scope="row"><label for="alias"><?php echo
|
12 |
<td><input class="regular-text validate[required]" name="alias" type="text" id="alias" value="" aria-required="true" /></td>
|
13 |
</tr>
|
14 |
<tr class="form-field form-required">
|
15 |
-
<th scope="row"><label for="role"><?php echo
|
16 |
<td><select class="regular-text" name="role"><?php wp_dropdown_roles( 'subscriber' ); ?></select></td>
|
17 |
</tr>
|
18 |
<tr>
|
19 |
-
<th scope="row"><label for="subscription_period"><?php echo
|
20 |
</th>
|
21 |
<td>
|
22 |
-
<p><input type="radio" checked="checked" value="<?php echo
|
23 |
-
<p><input type="radio" value="<?php echo
|
24 |
-
<input type="text" value="" name="subscription_period_<?php echo
|
25 |
-
<p><input type="radio" value="<?php echo
|
26 |
-
<input type="text" value="" name="subscription_period_<?php echo
|
27 |
-
<p><input type="radio" value="<?php echo
|
28 |
-
<input type="text" value="" name="subscription_period_<?php echo
|
29 |
-
<p><input type="radio" value="<?php echo
|
30 |
-
<input type="text" value="" name="subscription_period_<?php echo
|
31 |
-
<p><input type="radio" value="<?php echo
|
32 |
-
<input type="text" class="swpm-date-picker" value="<?php echo date('Y-m-d');?>" name="subscription_period_<?php echo
|
33 |
</td>
|
34 |
</tr>
|
35 |
<?php echo apply_filters('swpm_admin_add_membership_level_ui', '');?>
|
36 |
</tbody>
|
37 |
</table>
|
38 |
-
<?php submit_button(
|
39 |
</form>
|
40 |
</div>
|
41 |
<script>
|
3 |
<form action="" method="post" name="swpm-create-level" id="swpm-create-level" class="validate"<?php do_action('level_new_form_tag');?>>
|
4 |
<input name="action" type="hidden" value="createlevel" />
|
5 |
<h3>Add Membership Level</h3>
|
6 |
+
<p><?php echo SwpmUtils::_('Create new membership level.'); ?></p>
|
7 |
<?php wp_nonce_field( 'create-swpmlevel', '_wpnonce_create-swpmlevel' ) ?>
|
8 |
<table class="form-table">
|
9 |
<tbody>
|
10 |
<tr>
|
11 |
+
<th scope="row"><label for="alias"><?php echo SwpmUtils::_('Membership Level Name'); ?> <span class="description"><?php echo SwpmUtils::_('(required)'); ?></span></label></th>
|
12 |
<td><input class="regular-text validate[required]" name="alias" type="text" id="alias" value="" aria-required="true" /></td>
|
13 |
</tr>
|
14 |
<tr class="form-field form-required">
|
15 |
+
<th scope="row"><label for="role"><?php echo SwpmUtils::_('Default WordPress Role'); ?> <span class="description"><?php echo SwpmUtils::_('(required)'); ?></span></label></th>
|
16 |
<td><select class="regular-text" name="role"><?php wp_dropdown_roles( 'subscriber' ); ?></select></td>
|
17 |
</tr>
|
18 |
<tr>
|
19 |
+
<th scope="row"><label for="subscription_period"><?php echo SwpmUtils::_('Access Duration'); ?> <span class="description"><?php echo SwpmUtils::_('(required)'); ?></span></label>
|
20 |
</th>
|
21 |
<td>
|
22 |
+
<p><input type="radio" checked="checked" value="<?php echo SwpmMembershipLevel::NO_EXPIRY?>" name="subscription_duration_type" /> <?php echo SwpmUtils::_('No Expiry (Access for this level will not expire until cancelled')?>)</p>
|
23 |
+
<p><input type="radio" value="<?php echo SwpmMembershipLevel::DAYS ?>" name="subscription_duration_type" /> <?php echo SwpmUtils::_('Expire After')?>
|
24 |
+
<input type="text" value="" name="subscription_period_<?php echo SwpmMembershipLevel::DAYS ?>"> <?php echo SwpmUtils::_('Days (Access expires after given number of days)')?></p>
|
25 |
+
<p><input type="radio" value="<?php echo SwpmMembershipLevel::WEEKS?>" name="subscription_duration_type" /> <?php echo SwpmUtils::_('Expire After')?>
|
26 |
+
<input type="text" value="" name="subscription_period_<?php echo SwpmMembershipLevel::WEEKS ?>"> <?php echo SwpmUtils::_('Weeks (Access expires after given number of weeks')?></p>
|
27 |
+
<p><input type="radio" value="<?php echo SwpmMembershipLevel::MONTHS?>" name="subscription_duration_type" /> <?php echo SwpmUtils::_('Expire After')?>
|
28 |
+
<input type="text" value="" name="subscription_period_<?php echo SwpmMembershipLevel::MONTHS?>"> <?php echo SwpmUtils::_('Months (Access expires after given number of months)')?></p>
|
29 |
+
<p><input type="radio" value="<?php echo SwpmMembershipLevel::YEARS?>" name="subscription_duration_type" /> <?php echo SwpmUtils::_('Expire After')?>
|
30 |
+
<input type="text" value="" name="subscription_period_<?php echo SwpmMembershipLevel::YEARS?>"> <?php echo SwpmUtils::_('Years (Access expires after given number of years)')?></p>
|
31 |
+
<p><input type="radio" value="<?php echo SwpmMembershipLevel::FIXED_DATE?>" name="subscription_duration_type" /> <?php echo SwpmUtils::_('Fixed Date Expiry')?>
|
32 |
+
<input type="text" class="swpm-date-picker" value="<?php echo date('Y-m-d');?>" name="subscription_period_<?php echo SwpmMembershipLevel::FIXED_DATE?>"> <?php echo SwpmUtils::_('(Access expires on a fixed date)')?></p>
|
33 |
</td>
|
34 |
</tr>
|
35 |
<?php echo apply_filters('swpm_admin_add_membership_level_ui', '');?>
|
36 |
</tbody>
|
37 |
</table>
|
38 |
+
<?php submit_button( SwpmUtils::_('Add New Membership Level '), 'primary', 'createswpmlevel', true, array( 'id' => 'createswpmlevelsub' ) ); ?>
|
39 |
</form>
|
40 |
</div>
|
41 |
<script>
|
views/admin_add_ons_page.php
CHANGED
@@ -3,7 +3,7 @@ $output = '';
|
|
3 |
echo '<link type="text/css" rel="stylesheet" href="' . SIMPLE_WP_MEMBERSHIP_URL . '/css/swpm.addons.listing.css" />' . "\n";
|
4 |
?>
|
5 |
|
6 |
-
<h1><?php echo
|
7 |
<div class="wrap">
|
8 |
|
9 |
<?php
|
3 |
echo '<link type="text/css" rel="stylesheet" href="' . SIMPLE_WP_MEMBERSHIP_URL . '/css/swpm.addons.listing.css" />' . "\n";
|
4 |
?>
|
5 |
|
6 |
+
<h1><?php echo SwpmUtils::_('Simple WP Membership::Add-ons') ?></h1>
|
7 |
<div class="wrap">
|
8 |
|
9 |
<?php
|
views/admin_addon_settings.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php screen_icon( 'options-general' );?>
|
2 |
-
<h1><?php echo
|
3 |
<div class="wrap">
|
4 |
<?php do_action("swpm-draw-tab"); ?>
|
5 |
|
6 |
<p>
|
7 |
-
<?php echo
|
8 |
</p>
|
9 |
<form action="" method="POST">
|
10 |
<input type="hidden" name="tab" value="<?php echo $current_tab;?>" />
|
1 |
<?php screen_icon( 'options-general' );?>
|
2 |
+
<h1><?php echo SwpmUtils::_('Simple WP Membership::Settings')?></h1>
|
3 |
<div class="wrap">
|
4 |
<?php do_action("swpm-draw-tab"); ?>
|
5 |
|
6 |
<p>
|
7 |
+
<?php echo SwpmUtils::_("Some of the simple membership plugin's addon settings and options will be displayed here (if you have them)")?>
|
8 |
</p>
|
9 |
<form action="" method="POST">
|
10 |
<input type="hidden" name="tab" value="<?php echo $current_tab;?>" />
|
views/admin_category_list.php
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
<div class="wrap">
|
2 |
-
<h2><?php screen_icon('users'); ?><?php echo
|
3 |
<?php include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_membership_level_menu.php'); ?>
|
4 |
|
5 |
<div style="background: none repeat scroll 0 0 #FFF6D5;border: 1px solid #D1B655;color: #3F2502;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
|
6 |
<p>
|
7 |
-
<?php echo
|
8 |
</p>
|
9 |
<p>
|
10 |
-
<?php echo
|
11 |
</p>
|
12 |
</div>
|
13 |
<form id="category_list_form" method="post">
|
@@ -17,7 +17,7 @@
|
|
17 |
|
18 |
<select id="membership_level_id" name="membership_level_id">
|
19 |
<option <?php echo $category_list->selected_level_id==1? "selected": "" ?> value="1">General Protection</option>
|
20 |
-
<?php echo
|
21 |
</select>
|
22 |
</p>
|
23 |
<p class="swpm-select-box-left"><input type="submit" class="button-primary" name="update_category_list" value="Update"></p>
|
1 |
<div class="wrap">
|
2 |
+
<h2><?php screen_icon('users'); ?><?php echo SwpmUtils::_('Simple WP Membership::Categories') ?></h2>
|
3 |
<?php include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_membership_level_menu.php'); ?>
|
4 |
|
5 |
<div style="background: none repeat scroll 0 0 #FFF6D5;border: 1px solid #D1B655;color: #3F2502;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
|
6 |
<p>
|
7 |
+
<?php echo SwpmUtils::_('First of all, globally protect the category on your site by selecting "General Protection" from the drop-down box below and then select the categories that should be protected from non-logged in users.'); ?>
|
8 |
</p>
|
9 |
<p>
|
10 |
+
<?php echo SwpmUtils::_('Next, select an existing membership level from the drop-down box below and then select the categories you want to grant access to (for that particular membership level).'); ?>
|
11 |
</p>
|
12 |
</div>
|
13 |
<form id="category_list_form" method="post">
|
17 |
|
18 |
<select id="membership_level_id" name="membership_level_id">
|
19 |
<option <?php echo $category_list->selected_level_id==1? "selected": "" ?> value="1">General Protection</option>
|
20 |
+
<?php echo SwpmUtils::membership_level_dropdown($category_list->selected_level_id); ?>
|
21 |
</select>
|
22 |
</p>
|
23 |
<p class="swpm-select-box-left"><input type="submit" class="button-primary" name="update_category_list" value="Update"></p>
|
views/admin_edit.php
CHANGED
@@ -2,42 +2,42 @@
|
|
2 |
<form action="" method="post" name="swpm-edit-user" id="swpm-edit-user" class="validate"<?php do_action('user_new_form_tag');?>>
|
3 |
<input name="action" type="hidden" value="edituser" />
|
4 |
<?php wp_nonce_field( 'edit-swpmuser', '_wpnonce_edit-swpmuser' ) ?>
|
5 |
-
<h3><?php echo
|
6 |
-
<p><?php echo
|
7 |
<table class="form-table">
|
8 |
<tr class="form-field form-required">
|
9 |
-
<th scope="row"><label for="user_name"><?php echo
|
10 |
<td><?php echo esc_attr($user_name); ?></td>
|
11 |
</tr>
|
12 |
<tr class="form-required">
|
13 |
-
<th scope="row"><label for="email"><?php echo
|
14 |
<td><input name="email" class="regular-text validate[required,custom[email],ajax[ajaxEmailCall]]" type="text" id="email" value="<?php echo esc_attr($email); ?>" /></td>
|
15 |
</tr>
|
16 |
<tr class="">
|
17 |
-
<th scope="row"><label for="password"><?php echo
|
18 |
<td><input class="regular-text" name="password" type="password" id="pass1" autocomplete="off" /><br />
|
19 |
<input class="regular-text" name="password_re" type="password" id="pass2" autocomplete="off" />
|
20 |
<br />
|
21 |
-
<div id="pass-strength-result"><?php echo
|
22 |
-
<p class="description indicator-hint"><?php echo
|
23 |
</td>
|
24 |
</tr>
|
25 |
<tr>
|
26 |
-
<th scope="row"><label for="account_state"><?php echo
|
27 |
<td><select class="regular-text" name="account_state" id="account_state">
|
28 |
-
<?php echo
|
29 |
</select>
|
30 |
</td>
|
31 |
</tr>
|
32 |
<tr>
|
33 |
-
<th scope="row"><label for="account_state_change"><?php echo
|
34 |
<td><input type="checkbox" id="account_status_change" name="account_status_change" />
|
35 |
<p class="description indicator-hint">You can use this option to send a quick notification email to this member (the email will be sent when you hit the save button below).</p>
|
36 |
</td>
|
37 |
</tr>
|
38 |
<?php include('admin_member_form_common_part.php');?>
|
39 |
<tr>
|
40 |
-
<th scope="row"><label for="subscr_id"><?php echo
|
41 |
<td><input class="regular-text" name="subscr_id" type="text" id="subscr_id" value="<?php echo esc_attr($subscr_id); ?>" /></td>
|
42 |
</tr>
|
43 |
|
@@ -45,7 +45,7 @@
|
|
45 |
|
46 |
<?php include('admin_member_form_common_js.php');?>
|
47 |
<?php echo apply_filters('swpm_admin_custom_fields', '',$membership_level);?>
|
48 |
-
<?php submit_button(
|
49 |
</form>
|
50 |
</div>
|
51 |
<script>
|
2 |
<form action="" method="post" name="swpm-edit-user" id="swpm-edit-user" class="validate"<?php do_action('user_new_form_tag');?>>
|
3 |
<input name="action" type="hidden" value="edituser" />
|
4 |
<?php wp_nonce_field( 'edit-swpmuser', '_wpnonce_edit-swpmuser' ) ?>
|
5 |
+
<h3><?php echo SwpmUtils::_('Edit Member') ?></h3>
|
6 |
+
<p><?php echo SwpmUtils::_('Edit existing member details.'); ?></p>
|
7 |
<table class="form-table">
|
8 |
<tr class="form-field form-required">
|
9 |
+
<th scope="row"><label for="user_name"><?php echo SwpmUtils::_('Username'); ?> <span class="description"><?php echo SwpmUtils::_('(required)'); ?></span></label></th>
|
10 |
<td><?php echo esc_attr($user_name); ?></td>
|
11 |
</tr>
|
12 |
<tr class="form-required">
|
13 |
+
<th scope="row"><label for="email"><?php echo SwpmUtils::_('E-mail'); ?> <span class="description"><?php echo SwpmUtils::_('(required)'); ?></span></label></th>
|
14 |
<td><input name="email" class="regular-text validate[required,custom[email],ajax[ajaxEmailCall]]" type="text" id="email" value="<?php echo esc_attr($email); ?>" /></td>
|
15 |
</tr>
|
16 |
<tr class="">
|
17 |
+
<th scope="row"><label for="password"><?php echo SwpmUtils::_('Password'); ?> <span class="description"><?php /* translators: password input field */_e('(twice, leave empty to retain old password)'); ?></span></label></th>
|
18 |
<td><input class="regular-text" name="password" type="password" id="pass1" autocomplete="off" /><br />
|
19 |
<input class="regular-text" name="password_re" type="password" id="pass2" autocomplete="off" />
|
20 |
<br />
|
21 |
+
<div id="pass-strength-result"><?php echo SwpmUtils::_('Strength indicator'); ?></div>
|
22 |
+
<p class="description indicator-hint"><?php echo SwpmUtils::_('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ & ).'); ?></p>
|
23 |
</td>
|
24 |
</tr>
|
25 |
<tr>
|
26 |
+
<th scope="row"><label for="account_state"><?php echo SwpmUtils::_('Account Status'); ?></label></th>
|
27 |
<td><select class="regular-text" name="account_state" id="account_state">
|
28 |
+
<?php echo SwpmUtils::account_state_dropdown($account_state);?>
|
29 |
</select>
|
30 |
</td>
|
31 |
</tr>
|
32 |
<tr>
|
33 |
+
<th scope="row"><label for="account_state_change"><?php echo SwpmUtils::_('Notify User'); ?></label></th>
|
34 |
<td><input type="checkbox" id="account_status_change" name="account_status_change" />
|
35 |
<p class="description indicator-hint">You can use this option to send a quick notification email to this member (the email will be sent when you hit the save button below).</p>
|
36 |
</td>
|
37 |
</tr>
|
38 |
<?php include('admin_member_form_common_part.php');?>
|
39 |
<tr>
|
40 |
+
<th scope="row"><label for="subscr_id"><?php echo SwpmUtils::_('Subscriber ID/Reference') ?> </label></th>
|
41 |
<td><input class="regular-text" name="subscr_id" type="text" id="subscr_id" value="<?php echo esc_attr($subscr_id); ?>" /></td>
|
42 |
</tr>
|
43 |
|
45 |
|
46 |
<?php include('admin_member_form_common_js.php');?>
|
47 |
<?php echo apply_filters('swpm_admin_custom_fields', '',$membership_level);?>
|
48 |
+
<?php submit_button( SwpmUtils::_('Edit User '), 'primary', 'editswpmuser', true, array( 'id' => 'createswpmusersub' ) ); ?>
|
49 |
</form>
|
50 |
</div>
|
51 |
<script>
|
views/admin_edit_level.php
CHANGED
@@ -2,43 +2,43 @@
|
|
2 |
<form action="" method="post" name="swpm-edit-level" id="swpm-edit-level" class="validate"<?php do_action('level_edit_form_tag');?>>
|
3 |
<input name="action" type="hidden" value="editlevel" />
|
4 |
<?php wp_nonce_field( 'edit-swpmlevel', '_wpnonce_edit-swpmlevel' ) ?>
|
5 |
-
<h3><?php echo
|
6 |
-
<p><?php echo
|
7 |
<table class="form-table">
|
8 |
<tbody>
|
9 |
<tr>
|
10 |
-
<th scope="row"><label for="alias"><?php echo
|
11 |
<td><input class="regular-text validate[required]" name="alias" type="text" id="alias" value="<?php echo stripslashes($alias);?>" aria-required="true" /></td>
|
12 |
</tr>
|
13 |
<tr class="form-field form-required">
|
14 |
-
<th scope="row"><label for="role"><?php echo
|
15 |
<td><select class="regular-text" name="role"><?php wp_dropdown_roles( $role ); ?></select></td>
|
16 |
</tr>
|
17 |
<tr>
|
18 |
-
<th scope="row"><label for="subscription_period"><?php echo
|
19 |
</th>
|
20 |
<td>
|
21 |
-
<p><input type="radio" <?php echo checked(
|
22 |
-
<p><input type="radio" <?php echo checked(
|
23 |
-
<input type="text" value="<?php echo checked(
|
24 |
|
25 |
-
<p><input type="radio" <?php echo checked(
|
26 |
-
<input type="text" value="<?php echo checked(
|
27 |
|
28 |
-
<p><input type="radio" <?php echo checked(
|
29 |
-
<input type="text" value="<?php echo checked(
|
30 |
|
31 |
-
<p><input type="radio" <?php echo checked(
|
32 |
-
<input type="text" value="<?php echo checked(
|
33 |
|
34 |
-
<p><input type="radio" <?php echo checked(
|
35 |
-
<input type="text" class="swpm-date-picker" value="<?php echo checked(
|
36 |
</td>
|
37 |
</tr>
|
38 |
<?php echo apply_filters('swpm_admin_edit_membership_level_ui', '', $id);?>
|
39 |
</tbody>
|
40 |
</table>
|
41 |
-
<?php submit_button(
|
42 |
</form>
|
43 |
</div>
|
44 |
<script>
|
2 |
<form action="" method="post" name="swpm-edit-level" id="swpm-edit-level" class="validate"<?php do_action('level_edit_form_tag');?>>
|
3 |
<input name="action" type="hidden" value="editlevel" />
|
4 |
<?php wp_nonce_field( 'edit-swpmlevel', '_wpnonce_edit-swpmlevel' ) ?>
|
5 |
+
<h3><?php echo SwpmUtils::_('Edit membership level'); ?></h3>
|
6 |
+
<p><?php echo SwpmUtils::_('Edit membership level.'); ?></p>
|
7 |
<table class="form-table">
|
8 |
<tbody>
|
9 |
<tr>
|
10 |
+
<th scope="row"><label for="alias"><?php echo SwpmUtils::_('Membership Level Name'); ?> <span class="description"><?php echo SwpmUtils::_('(required)'); ?></span></label></th>
|
11 |
<td><input class="regular-text validate[required]" name="alias" type="text" id="alias" value="<?php echo stripslashes($alias);?>" aria-required="true" /></td>
|
12 |
</tr>
|
13 |
<tr class="form-field form-required">
|
14 |
+
<th scope="row"><label for="role"><?php echo SwpmUtils::_('Default WordPress Role'); ?> <span class="description"><?php echo SwpmUtils::_('(required)'); ?></span></label></th>
|
15 |
<td><select class="regular-text" name="role"><?php wp_dropdown_roles( $role ); ?></select></td>
|
16 |
</tr>
|
17 |
<tr>
|
18 |
+
<th scope="row"><label for="subscription_period"><?php echo SwpmUtils::_('Access Duration'); ?> <span class="description"><?php echo SwpmUtils::_('(required)'); ?></span></label>
|
19 |
</th>
|
20 |
<td>
|
21 |
+
<p><input type="radio" <?php echo checked(SwpmMembershipLevel::NO_EXPIRY,$subscription_duration_type,false)?> value="<?php echo SwpmMembershipLevel::NO_EXPIRY?>" name="subscription_duration_type" /> <?php echo SwpmUtils::_('No Expiry (Access for this level will not expire until cancelled)')?></p>
|
22 |
+
<p><input type="radio" <?php echo checked(SwpmMembershipLevel::DAYS,$subscription_duration_type,false)?> value="<?php echo SwpmMembershipLevel::DAYS ?>" name="subscription_duration_type" /> <?php echo SwpmUtils::_('Expire After')?>
|
23 |
+
<input type="text" value="<?php echo checked(SwpmMembershipLevel::DAYS,$subscription_duration_type,false)? $subscription_period: "";?>" name="subscription_period_<?php echo SwpmMembershipLevel::DAYS ?>"> <?php echo SwpmUtils::_('Days (Access expires after given number of days)')?></p>
|
24 |
|
25 |
+
<p><input type="radio" <?php echo checked(SwpmMembershipLevel::WEEKS,$subscription_duration_type,false)?> value="<?php echo SwpmMembershipLevel::WEEKS?>" name="subscription_duration_type" /> <?php echo SwpmUtils::_('Expire After')?>
|
26 |
+
<input type="text" value="<?php echo checked(SwpmMembershipLevel::WEEKS,$subscription_duration_type,false)? $subscription_period: "";?>" name="subscription_period_<?php echo SwpmMembershipLevel::WEEKS ?>"> <?php echo SwpmUtils::_('Weeks (Access expires after given number of weeks)')?></p>
|
27 |
|
28 |
+
<p><input type="radio" <?php echo checked(SwpmMembershipLevel::MONTHS,$subscription_duration_type,false)?> value="<?php echo SwpmMembershipLevel::MONTHS?>" name="subscription_duration_type" /> <?php echo SwpmUtils::_('Expire After')?>
|
29 |
+
<input type="text" value="<?php echo checked(SwpmMembershipLevel::MONTHS,$subscription_duration_type,false)? $subscription_period: "";?>" name="subscription_period_<?php echo SwpmMembershipLevel::MONTHS?>"> <?php echo SwpmUtils::_('Months (Access expires after given number of months)')?></p>
|
30 |
|
31 |
+
<p><input type="radio" <?php echo checked(SwpmMembershipLevel::YEARS,$subscription_duration_type,false)?> value="<?php echo SwpmMembershipLevel::YEARS?>" name="subscription_duration_type" /> <?php echo SwpmUtils::_('Expire After')?>
|
32 |
+
<input type="text" value="<?php echo checked(SwpmMembershipLevel::YEARS,$subscription_duration_type,false)? $subscription_period: "";?>" name="subscription_period_<?php echo SwpmMembershipLevel::YEARS?>"> <?php echo SwpmUtils::_('Years (Access expires after given number of years)')?></p>
|
33 |
|
34 |
+
<p><input type="radio" <?php echo checked(SwpmMembershipLevel::FIXED_DATE,$subscription_duration_type,false)?> value="<?php echo SwpmMembershipLevel::FIXED_DATE?>" name="subscription_duration_type" /> <?php echo SwpmUtils::_('Fixed Date Expiry')?>
|
35 |
+
<input type="text" class="swpm-date-picker" value="<?php echo checked(SwpmMembershipLevel::FIXED_DATE,$subscription_duration_type,false)? $subscription_period: "";?>" name="subscription_period_<?php echo SwpmMembershipLevel::FIXED_DATE?>" id="subscription_period_<?php echo SwpmMembershipLevel::FIXED_DATE?>"> <?php echo SwpmUtils::_('(Access expires on a fixed date)')?></p>
|
36 |
</td>
|
37 |
</tr>
|
38 |
<?php echo apply_filters('swpm_admin_edit_membership_level_ui', '', $id);?>
|
39 |
</tbody>
|
40 |
</table>
|
41 |
+
<?php submit_button(SwpmUtils::_('Edit Membership Level '), 'primary', 'editswpmlevel', true, array( 'id' => 'editswpmlevelsub' ) ); ?>
|
42 |
</form>
|
43 |
</div>
|
44 |
<script>
|
views/admin_member_form_common_part.php
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<tr>
|
2 |
-
<th scope="row"><label for="membership_level"><?php echo
|
3 |
<td><select class="regular-text" name="membership_level" id="membership_level">
|
4 |
<?php foreach ($levels as $level):?>
|
5 |
<option <?php echo ($level['id'] == $membership_level)? "selected='selected'": "";?> value="<?php echo $level['id'];?>"> <?php echo $level['alias']?></option>
|
@@ -8,53 +8,53 @@
|
|
8 |
</td>
|
9 |
</tr>
|
10 |
<tr>
|
11 |
-
<th scope="row"><label for="subscription_starts"><?php echo
|
12 |
<td><input class="regular-text" name="subscription_starts" type="text" id="subscription_starts" value="<?php echo esc_attr($subscription_starts); ?>" /></td>
|
13 |
</tr>
|
14 |
<tr>
|
15 |
-
<th scope="row"><label for="first_name"><?php echo
|
16 |
<td><input class="regular-text" name="first_name" type="text" id="first_name" value="<?php echo esc_attr($first_name); ?>" /></td>
|
17 |
</tr>
|
18 |
<tr>
|
19 |
-
<th scope="row"><label for="last_name"><?php echo
|
20 |
<td><input class="regular-text" name="last_name" type="text" id="last_name" value="<?php echo esc_attr($last_name); ?>" /></td>
|
21 |
</tr>
|
22 |
<tr>
|
23 |
-
<th scope="row"><label for="gender"><?php echo
|
24 |
<td><select class="regular-text" name="gender" id="gender">
|
25 |
-
<?php echo
|
26 |
</select>
|
27 |
</td>
|
28 |
</tr>
|
29 |
<tr>
|
30 |
-
<th scope="row"><label for="phone"><?php echo
|
31 |
<td><input class="regular-text" name="phone" type="text" id="phone" value="<?php echo esc_attr($phone); ?>" /></td>
|
32 |
</tr>
|
33 |
<tr>
|
34 |
-
<th scope="row"><label for="address_street"><?php echo
|
35 |
<td><input class="regular-text" name="address_street" type="text" id="address_street" value="<?php echo esc_attr($address_street); ?>" /></td>
|
36 |
</tr>
|
37 |
<tr>
|
38 |
-
<th scope="row"><label for="address_city"><?php echo
|
39 |
<td><input class="regular-text" name="address_city" type="text" id="address_city" value="<?php echo esc_attr($address_city); ?>" /></td>
|
40 |
</tr>
|
41 |
<tr>
|
42 |
-
<th scope="row"><label for="address_state"><?php echo
|
43 |
<td><input class="regular-text" name="address_state" type="text" id="address_state" value="<?php echo esc_attr($address_state); ?>" /></td>
|
44 |
</tr>
|
45 |
<tr>
|
46 |
-
<th scope="row"><label for="address_zipcode"><?php echo
|
47 |
<td><input class="regular-text" name="address_zipcode" type="text" id="address_zipcode" value="<?php echo esc_attr($address_zipcode); ?>" /></td>
|
48 |
</tr>
|
49 |
<tr>
|
50 |
-
<th scope="row"><label for="country"><?php echo
|
51 |
<td><input class="regular-text" name="country" type="text" id="country" value="<?php echo esc_attr($country); ?>" /></td>
|
52 |
</tr>
|
53 |
<tr>
|
54 |
-
<th scope="row"><label for="company_name"><?php echo
|
55 |
<td><input name="company_name" type="text" id="company_name" class="code regular-text" value="<?php echo esc_attr($company_name); ?>" /></td>
|
56 |
</tr>
|
57 |
<tr>
|
58 |
-
<th scope="row"><label for="member_since"><?php echo
|
59 |
<td><input class="regular-text" name="member_since" type="text" id="member_since" value="<?php echo esc_attr($member_since); ?>" /></td>
|
60 |
</tr>
|
1 |
<tr>
|
2 |
+
<th scope="row"><label for="membership_level"><?php echo SwpmUtils::_('Membership Level'); ?></label></th>
|
3 |
<td><select class="regular-text" name="membership_level" id="membership_level">
|
4 |
<?php foreach ($levels as $level):?>
|
5 |
<option <?php echo ($level['id'] == $membership_level)? "selected='selected'": "";?> value="<?php echo $level['id'];?>"> <?php echo $level['alias']?></option>
|
8 |
</td>
|
9 |
</tr>
|
10 |
<tr>
|
11 |
+
<th scope="row"><label for="subscription_starts"><?php echo SwpmUtils::_('Access Starts') ?> </label></th>
|
12 |
<td><input class="regular-text" name="subscription_starts" type="text" id="subscription_starts" value="<?php echo esc_attr($subscription_starts); ?>" /></td>
|
13 |
</tr>
|
14 |
<tr>
|
15 |
+
<th scope="row"><label for="first_name"><?php echo SwpmUtils::_('First Name') ?> </label></th>
|
16 |
<td><input class="regular-text" name="first_name" type="text" id="first_name" value="<?php echo esc_attr($first_name); ?>" /></td>
|
17 |
</tr>
|
18 |
<tr>
|
19 |
+
<th scope="row"><label for="last_name"><?php echo SwpmUtils::_('Last Name') ?> </label></th>
|
20 |
<td><input class="regular-text" name="last_name" type="text" id="last_name" value="<?php echo esc_attr($last_name); ?>" /></td>
|
21 |
</tr>
|
22 |
<tr>
|
23 |
+
<th scope="row"><label for="gender"><?php echo SwpmUtils::_('Gender'); ?></label></th>
|
24 |
<td><select class="regular-text" name="gender" id="gender">
|
25 |
+
<?php echo SwpmUtils::gender_dropdown($gender) ?>
|
26 |
</select>
|
27 |
</td>
|
28 |
</tr>
|
29 |
<tr>
|
30 |
+
<th scope="row"><label for="phone"><?php echo SwpmUtils::_('Phone') ?> </label></th>
|
31 |
<td><input class="regular-text" name="phone" type="text" id="phone" value="<?php echo esc_attr($phone); ?>" /></td>
|
32 |
</tr>
|
33 |
<tr>
|
34 |
+
<th scope="row"><label for="address_street"><?php echo SwpmUtils::_('Street') ?> </label></th>
|
35 |
<td><input class="regular-text" name="address_street" type="text" id="address_street" value="<?php echo esc_attr($address_street); ?>" /></td>
|
36 |
</tr>
|
37 |
<tr>
|
38 |
+
<th scope="row"><label for="address_city"><?php echo SwpmUtils::_('City') ?> </label></th>
|
39 |
<td><input class="regular-text" name="address_city" type="text" id="address_city" value="<?php echo esc_attr($address_city); ?>" /></td>
|
40 |
</tr>
|
41 |
<tr>
|
42 |
+
<th scope="row"><label for="address_state"><?php echo SwpmUtils::_('State') ?> </label></th>
|
43 |
<td><input class="regular-text" name="address_state" type="text" id="address_state" value="<?php echo esc_attr($address_state); ?>" /></td>
|
44 |
</tr>
|
45 |
<tr>
|
46 |
+
<th scope="row"><label for="address_zipcode"><?php echo SwpmUtils::_('Zipcode') ?> </label></th>
|
47 |
<td><input class="regular-text" name="address_zipcode" type="text" id="address_zipcode" value="<?php echo esc_attr($address_zipcode); ?>" /></td>
|
48 |
</tr>
|
49 |
<tr>
|
50 |
+
<th scope="row"><label for="country"><?php echo SwpmUtils::_('Country') ?> </label></th>
|
51 |
<td><input class="regular-text" name="country" type="text" id="country" value="<?php echo esc_attr($country); ?>" /></td>
|
52 |
</tr>
|
53 |
<tr>
|
54 |
+
<th scope="row"><label for="company_name"><?php echo SwpmUtils::_('Company') ?></label></th>
|
55 |
<td><input name="company_name" type="text" id="company_name" class="code regular-text" value="<?php echo esc_attr($company_name); ?>" /></td>
|
56 |
</tr>
|
57 |
<tr>
|
58 |
+
<th scope="row"><label for="member_since"><?php echo SwpmUtils::_('Member Since') ?> </label></th>
|
59 |
<td><input class="regular-text" name="member_since" type="text" id="member_since" value="<?php echo esc_attr($member_since); ?>" /></td>
|
60 |
</tr>
|
views/admin_members.php
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
<div class="wrap">
|
2 |
-
<h2><?php screen_icon('users'); ?><?php echo
|
3 |
-
<a href="admin.php?page=simple_wp_membership&member_action=add" class="add-new-h2"><?php echo
|
4 |
<form method="post">
|
5 |
<p class="search-box">
|
6 |
<label class="screen-reader-text" for="search_id-search-input">
|
7 |
search:</label>
|
8 |
<input id="search_id-search-input" type="text" name="s" value="" />
|
9 |
-
<input id="search-submit" class="button" type="submit" name="" value="<?php echo
|
10 |
<input type="hidden" name="page" value="simple_wp_membership" />
|
11 |
</p>
|
12 |
</form>
|
@@ -16,6 +16,6 @@
|
|
16 |
</form>
|
17 |
|
18 |
<p>
|
19 |
-
<a href="admin.php?page=simple_wp_membership&member_action=add" class="button-primary"><?php echo
|
20 |
</p>
|
21 |
</div><!-- end of wrap -->
|
1 |
<div class="wrap">
|
2 |
+
<h2><?php screen_icon('users'); ?><?php echo SwpmUtils::_('Simple WP Membership::Members') ?>
|
3 |
+
<a href="admin.php?page=simple_wp_membership&member_action=add" class="add-new-h2"><?php echo SwpmUtils::_('Add New'); ?></a></h2>
|
4 |
<form method="post">
|
5 |
<p class="search-box">
|
6 |
<label class="screen-reader-text" for="search_id-search-input">
|
7 |
search:</label>
|
8 |
<input id="search_id-search-input" type="text" name="s" value="" />
|
9 |
+
<input id="search-submit" class="button" type="submit" name="" value="<?php echo SwpmUtils::_('search')?>" />
|
10 |
<input type="hidden" name="page" value="simple_wp_membership" />
|
11 |
</p>
|
12 |
</form>
|
16 |
</form>
|
17 |
|
18 |
<p>
|
19 |
+
<a href="admin.php?page=simple_wp_membership&member_action=add" class="button-primary"><?php echo SwpmUtils::_('Add New')?></a>
|
20 |
</p>
|
21 |
</div><!-- end of wrap -->
|
views/admin_membership_level_menu.php
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<h3 class="nav-tab-wrapper">
|
2 |
-
<a class="nav-tab <?php echo ($selected==1) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels"><?php echo
|
3 |
-
<a class="nav-tab <?php echo ($selected==2) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=manage"><?php echo
|
4 |
-
<a class="nav-tab <?php echo ($selected==3) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=category_list"><?php echo
|
5 |
</h3>
|
1 |
<h3 class="nav-tab-wrapper">
|
2 |
+
<a class="nav-tab <?php echo ($selected==1) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels"><?php echo SwpmUtils::_('Membership level') ?></a>
|
3 |
+
<a class="nav-tab <?php echo ($selected==2) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=manage"><?php echo SwpmUtils::_('Manage Content Production') ?></a>
|
4 |
+
<a class="nav-tab <?php echo ($selected==3) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=category_list"><?php echo SwpmUtils::_('Category Protection') ?></a>
|
5 |
</h3>
|
views/admin_membership_levels.php
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<div class="wrap">
|
2 |
-
<h2><?php screen_icon('users'); ?><?php echo
|
3 |
<a href="admin.php?page=simple_wp_membership_levels&level_action=add" class="add-new-h2"><?php echo esc_html_x('Add New', 'Level'); ?></a></h2>
|
4 |
<?php include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_membership_level_menu.php'); ?>
|
5 |
<form method="post">
|
@@ -7,7 +7,7 @@
|
|
7 |
<label class="screen-reader-text" for="search_id-search-input">
|
8 |
search:</label>
|
9 |
<input id="search_id-search-input" type="text" name="s" value="" />
|
10 |
-
<input id="search-submit" class="button" type="submit" name="" value="<?php echo
|
11 |
<input type="hidden" name="page" value="simple_wp_membership" />
|
12 |
</p>
|
13 |
</form>
|
@@ -17,7 +17,7 @@
|
|
17 |
</form>
|
18 |
|
19 |
<p>
|
20 |
-
<a href="admin.php?page=simple_wp_membership_levels&level_action=add" class="button-primary"><?php echo
|
21 |
</p>
|
22 |
|
23 |
</div><!-- end of .wrap -->
|
1 |
<div class="wrap">
|
2 |
+
<h2><?php screen_icon('users'); ?><?php echo SwpmUtils::_('Simple WP Membership::Membership Levels') ?>
|
3 |
<a href="admin.php?page=simple_wp_membership_levels&level_action=add" class="add-new-h2"><?php echo esc_html_x('Add New', 'Level'); ?></a></h2>
|
4 |
<?php include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_membership_level_menu.php'); ?>
|
5 |
<form method="post">
|
7 |
<label class="screen-reader-text" for="search_id-search-input">
|
8 |
search:</label>
|
9 |
<input id="search_id-search-input" type="text" name="s" value="" />
|
10 |
+
<input id="search-submit" class="button" type="submit" name="" value="<?php echo SwpmUtils::_('search')?>" />
|
11 |
<input type="hidden" name="page" value="simple_wp_membership" />
|
12 |
</p>
|
13 |
</form>
|
17 |
</form>
|
18 |
|
19 |
<p>
|
20 |
+
<a href="admin.php?page=simple_wp_membership_levels&level_action=add" class="button-primary"><?php echo SwpmUtils::_('Add New') ?></a>
|
21 |
</p>
|
22 |
|
23 |
</div><!-- end of .wrap -->
|
views/admin_membership_manage.php
CHANGED
@@ -14,7 +14,7 @@
|
|
14 |
<br />5. Hit the Update/Save Button to save the changes.
|
15 |
|
16 |
<br /><br />
|
17 |
-
<h3><?php echo
|
18 |
|
19 |
<img src="<?php echo SIMPLE_WP_MEMBERSHIP_URL.'/images/simple-membership-content-protection-usage.png'; ?>" alt="Content protection example usage">
|
20 |
|
14 |
<br />5. Hit the Update/Save Button to save the changes.
|
15 |
|
16 |
<br /><br />
|
17 |
+
<h3><?php echo SwpmUtils::_('Example Content Protection Settings')?></h3>
|
18 |
|
19 |
<img src="<?php echo SIMPLE_WP_MEMBERSHIP_URL.'/images/simple-membership-content-protection-usage.png'; ?>" alt="Content protection example usage">
|
20 |
|
views/admin_payment_settings.php
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<?php screen_icon( 'options-general' );?>
|
2 |
-
<h1><?php echo
|
3 |
<div class="wrap">
|
4 |
|
5 |
<?php do_action("swpm-draw-tab"); ?>
|
@@ -24,21 +24,21 @@ if(isset($_POST['swpm_generate_adv_code']))
|
|
24 |
}
|
25 |
else{
|
26 |
echo '<div id="message" class="updated fade"><p><strong>';
|
27 |
-
|
28 |
echo '</strong></p></div>';
|
29 |
}
|
30 |
}
|
31 |
?>
|
32 |
<div class="postbox">
|
33 |
-
<h3><label for="title"><?php echo
|
34 |
<div class="inside">
|
35 |
|
36 |
-
<p><strong><?php echo
|
37 |
|
38 |
<form action="" method="post">
|
39 |
-
<?php echo
|
40 |
<input type="text" value="" size="4" name="swpm_paypal_adv_member_level">
|
41 |
-
<input type="submit" value="<?php echo
|
42 |
</form>
|
43 |
|
44 |
</div></div>
|
1 |
<?php screen_icon( 'options-general' );?>
|
2 |
+
<h1><?php echo SwpmUtils::_('Simple WP Membership::Settings')?></h1>
|
3 |
<div class="wrap">
|
4 |
|
5 |
<?php do_action("swpm-draw-tab"); ?>
|
24 |
}
|
25 |
else{
|
26 |
echo '<div id="message" class="updated fade"><p><strong>';
|
27 |
+
SwpmUtils::e( 'Error! The membership level ID ('.$mem_level.') you specified is incorrect. Please check this value again.');
|
28 |
echo '</strong></p></div>';
|
29 |
}
|
30 |
}
|
31 |
?>
|
32 |
<div class="postbox">
|
33 |
+
<h3><label for="title"><?php echo SwpmUtils::_('PayPal Integration Settings')?></label></h3>
|
34 |
<div class="inside">
|
35 |
|
36 |
+
<p><strong><?php echo SwpmUtils::_('Generate the "Advanced Variables" Code for your PayPal button')?></strong></p>
|
37 |
|
38 |
<form action="" method="post">
|
39 |
+
<?php echo SwpmUtils::_('Enter the Membership Level ID')?>
|
40 |
<input type="text" value="" size="4" name="swpm_paypal_adv_member_level">
|
41 |
+
<input type="submit" value="<?php echo SwpmUtils::_('Generate Code')?>" class="button-primary" name="swpm_generate_adv_code">
|
42 |
</form>
|
43 |
|
44 |
</div></div>
|
views/admin_payments_page.php
CHANGED
@@ -2,47 +2,46 @@
|
|
2 |
$output = '';
|
3 |
?>
|
4 |
|
5 |
-
<h1><?php echo
|
6 |
<div class="wrap">
|
7 |
<div id="poststuff"><div id="post-body">
|
8 |
|
9 |
<div style="background: #DDDDDD;border: 1px solid #CCCCCC;color: #383838;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
|
10 |
<p>
|
11 |
-
<?php echo
|
12 |
</p>
|
13 |
</div>
|
14 |
-
|
15 |
<div class="postbox">
|
16 |
<h3><label for="title">Search Transaction</label></h3>
|
17 |
<div class="inside">
|
18 |
-
<?php echo
|
19 |
<br /><br />
|
20 |
<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
|
21 |
-
<input name="swpm_txn_search" type="text" size="40" value="<?php echo isset($_POST['swpm_txn_search'])? $_POST['swpm_txn_search']: ''; ?>"/>
|
22 |
-
<input type="submit" name="swpm_txn_search_btn" class="button" value="<?php echo
|
23 |
</form>
|
24 |
</div></div>
|
25 |
|
26 |
<?php
|
27 |
-
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'classes/admin-includes/swpm-payments-list-table.php');
|
28 |
//Create an instance of our package class...
|
29 |
-
$payments_list_table = new
|
30 |
-
|
31 |
//Check if an action was performed
|
32 |
if (isset($_REQUEST['action'])) { //Do list table form row action tasks
|
33 |
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete_txn') { //Delete link was clicked for a row in list table
|
34 |
$record_id = strip_tags($_REQUEST['id']);
|
35 |
$payments_list_table->delete_record($record_id);
|
36 |
$success_msg = '<div id="message" class="updated"><p><strong>';
|
37 |
-
$success_msg .=
|
38 |
$success_msg .= '</strong></p></div>';
|
39 |
echo $success_msg;
|
40 |
}
|
41 |
}
|
42 |
-
|
43 |
//Fetch, prepare, sort, and filter our data...
|
44 |
$payments_list_table->prepare_items();
|
45 |
-
|
46 |
?>
|
47 |
<form id="tables-filter" method="get" onSubmit="return confirm('Are you sure you want to perform this bulk operation on the selected entries?');">
|
48 |
<!-- For plugins, we also need to ensure that the form posts back to our current page -->
|
@@ -50,6 +49,6 @@ $output = '';
|
|
50 |
<!-- Now we can render the completed list table -->
|
51 |
<?php $payments_list_table->display(); ?>
|
52 |
</form>
|
53 |
-
|
54 |
-
</div></div><!-- end of poststuff and post-body -->
|
55 |
</div><!-- end of .wrap -->
|
2 |
$output = '';
|
3 |
?>
|
4 |
|
5 |
+
<h1><?php echo SwpmUtils::_('Simple Membership::Payments') ?></h1>
|
6 |
<div class="wrap">
|
7 |
<div id="poststuff"><div id="post-body">
|
8 |
|
9 |
<div style="background: #DDDDDD;border: 1px solid #CCCCCC;color: #383838;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
|
10 |
<p>
|
11 |
+
<?php echo SwpmUtils::_('All the payments/transactions of your members are recorded here.'); ?>
|
12 |
</p>
|
13 |
</div>
|
14 |
+
|
15 |
<div class="postbox">
|
16 |
<h3><label for="title">Search Transaction</label></h3>
|
17 |
<div class="inside">
|
18 |
+
<?php echo SwpmUtils::_('Search for a transaction by using email or name'); ?>
|
19 |
<br /><br />
|
20 |
<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
|
21 |
+
<input name="swpm_txn_search" type="text" size="40" value="<?php echo isset($_POST['swpm_txn_search']) ? $_POST['swpm_txn_search'] : ''; ?>"/>
|
22 |
+
<input type="submit" name="swpm_txn_search_btn" class="button" value="<?php echo SwpmUtils::_('Search'); ?>" />
|
23 |
</form>
|
24 |
</div></div>
|
25 |
|
26 |
<?php
|
27 |
+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'classes/admin-includes/class.swpm-payments-list-table.php');
|
28 |
//Create an instance of our package class...
|
29 |
+
$payments_list_table = new SWPMPaymentsListTable();
|
30 |
+
|
31 |
//Check if an action was performed
|
32 |
if (isset($_REQUEST['action'])) { //Do list table form row action tasks
|
33 |
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete_txn') { //Delete link was clicked for a row in list table
|
34 |
$record_id = strip_tags($_REQUEST['id']);
|
35 |
$payments_list_table->delete_record($record_id);
|
36 |
$success_msg = '<div id="message" class="updated"><p><strong>';
|
37 |
+
$success_msg .= SwpmUtils::_('The selected entry was deleted!');
|
38 |
$success_msg .= '</strong></p></div>';
|
39 |
echo $success_msg;
|
40 |
}
|
41 |
}
|
42 |
+
|
43 |
//Fetch, prepare, sort, and filter our data...
|
44 |
$payments_list_table->prepare_items();
|
|
|
45 |
?>
|
46 |
<form id="tables-filter" method="get" onSubmit="return confirm('Are you sure you want to perform this bulk operation on the selected entries?');">
|
47 |
<!-- For plugins, we also need to ensure that the form posts back to our current page -->
|
49 |
<!-- Now we can render the completed list table -->
|
50 |
<?php $payments_list_table->display(); ?>
|
51 |
</form>
|
52 |
+
|
53 |
+
</div></div><!-- end of poststuff and post-body -->
|
54 |
</div><!-- end of .wrap -->
|
views/admin_settings.php
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<?php screen_icon( 'options-general' );?>
|
2 |
-
<h1><?php echo
|
3 |
<div class="wrap">
|
4 |
<?php do_action("swpm-draw-tab"); ?>
|
5 |
<form action="options.php" method="POST">
|
1 |
<?php screen_icon( 'options-general' );?>
|
2 |
+
<h1><?php echo SwpmUtils::_('Simple WP Membership::Settings') ?></h1>
|
3 |
<div class="wrap">
|
4 |
<?php do_action("swpm-draw-tab"); ?>
|
5 |
<form action="options.php" method="POST">
|
views/admin_tools_settings.php
CHANGED
@@ -1,37 +1,37 @@
|
|
1 |
<?php screen_icon( 'options-general' );?>
|
2 |
-
<h1><?php echo
|
3 |
<div class="wrap">
|
4 |
|
5 |
<?php do_action("swpm-draw-tab"); ?>
|
6 |
|
7 |
<div id="poststuff"><div id="post-body">
|
8 |
<div class="postbox">
|
9 |
-
<h3><label for="title"><?php echo
|
10 |
<div class="inside">
|
11 |
|
12 |
-
<p><strong><?php echo
|
13 |
|
14 |
<form action="" method="post">
|
15 |
<table>
|
16 |
<tr>
|
17 |
-
<?php echo
|
18 |
<br /><input type="radio" value="one" name="swpm_link_for" />For a Particular Member ID
|
19 |
<input type="text" name="member_id" size="5" value="" />
|
20 |
-
<br /> <strong> <?php echo
|
21 |
-
<br /><input type="radio" checked="checked" value="all" name="swpm_link_for" /> <?php echo
|
22 |
</tr>
|
23 |
<tr>
|
24 |
-
<td><?php echo
|
25 |
<?php foreach ($links as $key=>$link):?>
|
26 |
<input type="text" size="100" readonly="readonly" name="link[<?php echo $key?>]" value="<?php echo $link;?>"/><br/>
|
27 |
<?php endforeach;?>
|
28 |
</td>
|
29 |
</tr>
|
30 |
<tr>
|
31 |
-
<td><?php echo
|
32 |
</tr>
|
33 |
<tr>
|
34 |
-
<td><input type="submit" name="submit" class="button-primary" value="<?php echo
|
35 |
</tr>
|
36 |
</table>
|
37 |
</form>
|
1 |
<?php screen_icon( 'options-general' );?>
|
2 |
+
<h1><?php echo SwpmUtils::_('Simple WP Membership::Settings')?></h1>
|
3 |
<div class="wrap">
|
4 |
|
5 |
<?php do_action("swpm-draw-tab"); ?>
|
6 |
|
7 |
<div id="poststuff"><div id="post-body">
|
8 |
<div class="postbox">
|
9 |
+
<h3><label for="title"><?php echo SwpmUtils::_('Generate a Registration Completion link')?></label></h3>
|
10 |
<div class="inside">
|
11 |
|
12 |
+
<p><strong><?php echo SwpmUtils::_('You can manually generate a registration completion link here and give it to your customer if they have missed the email that was automatically sent out to them after the payment.')?></strong></p>
|
13 |
|
14 |
<form action="" method="post">
|
15 |
<table>
|
16 |
<tr>
|
17 |
+
<?php echo SwpmUtils::_('Generate Registration Completion Link')?>
|
18 |
<br /><input type="radio" value="one" name="swpm_link_for" />For a Particular Member ID
|
19 |
<input type="text" name="member_id" size="5" value="" />
|
20 |
+
<br /> <strong> <?php echo SwpmUtils::_('OR')?> </strong>
|
21 |
+
<br /><input type="radio" checked="checked" value="all" name="swpm_link_for" /> <?php echo SwpmUtils::_('For All Pending Registrations')?>
|
22 |
</tr>
|
23 |
<tr>
|
24 |
+
<td><?php echo SwpmUtils::_('Registration Completion Links Will Appear Below:')?><br/>
|
25 |
<?php foreach ($links as $key=>$link):?>
|
26 |
<input type="text" size="100" readonly="readonly" name="link[<?php echo $key?>]" value="<?php echo $link;?>"/><br/>
|
27 |
<?php endforeach;?>
|
28 |
</td>
|
29 |
</tr>
|
30 |
<tr>
|
31 |
+
<td><?php echo SwpmUtils::_('Send Registration Reminder Email too')?> <input type="checkbox" value="checked" name="swpm_reminder_email"></td>
|
32 |
</tr>
|
33 |
<tr>
|
34 |
+
<td><input type="submit" name="submit" class="button-primary" value="<?php echo SwpmUtils::_('Submit')?>" /></td>
|
35 |
</tr>
|
36 |
</table>
|
37 |
</form>
|
views/edit.php
CHANGED
@@ -1,63 +1,63 @@
|
|
1 |
<form id="swpm-editprofile-form" name="swpm-editprofile-form" method="post" action="">
|
2 |
<table>
|
3 |
<tr>
|
4 |
-
<td><label for="user_name"><?php echo
|
5 |
<td><?php echo $user_name ?></td>
|
6 |
</tr>
|
7 |
<tr>
|
8 |
-
<td><label for="email"><?php echo
|
9 |
<td><input type="text" id="email" class="validate[required,custom[email],ajax[ajaxEmailCall]]" value="<?php echo $email;?>" tabindex="2" size="50" name="email" /></td>
|
10 |
</tr>
|
11 |
<tr>
|
12 |
-
<td><label for="password"><?php echo
|
13 |
<td><input type="text" id="password" value="" tabindex="1" size="50" name="password" /></td>
|
14 |
</tr>
|
15 |
<tr>
|
16 |
-
<td><label for="password_re"><?php echo
|
17 |
<td><input type="text" id="password_re" value="" tabindex="2" size="50" name="password_re" /></td>
|
18 |
</tr>
|
19 |
<tr>
|
20 |
-
<td><label for="first_name"><?php echo
|
21 |
<td><input type="text" id="first_name" value="<?php echo $first_name; ?>" tabindex="3" size="50" name="first_name" /></td>
|
22 |
</tr>
|
23 |
<tr>
|
24 |
-
<td><label for="last_name"><?php echo
|
25 |
<td><input type="text" id="last_name" value="<?php echo $last_name; ?>" tabindex="4" size="50" name="last_name" /></td>
|
26 |
</tr>
|
27 |
<tr>
|
28 |
-
<td><label for="phone"><?php echo
|
29 |
<td><input type="text" id="phone" value="<?php echo $phone; ?>" tabindex="5" size="50" name="phone" /></td>
|
30 |
</tr>
|
31 |
<tr>
|
32 |
-
<td><label for="address_street"><?php echo
|
33 |
<td><input type="text" id="address_street" value="<?php echo $address_street; ?>" tabindex="6" size="50" name="address_street" /></td>
|
34 |
</tr>
|
35 |
<tr>
|
36 |
-
<td><label for="address_city"><?php echo
|
37 |
<td><input type="text" id="address_city" value="<?php echo $address_city; ?>" tabindex="7" size="50" name="address_city" /></td>
|
38 |
</tr>
|
39 |
<tr>
|
40 |
-
<td><label for="address_state"><?php echo
|
41 |
<td><input type="text" id="address_state" value="<?php echo $address_state; ?>" tabindex="8" size="50" name="address_state" /></td>
|
42 |
</tr>
|
43 |
<tr>
|
44 |
-
<td><label for="address_zipcode"><?php echo
|
45 |
<td><input type="text" id="address_zipcode" value="<?php echo $address_zipcode; ?>" tabindex="9" size="50" name="address_zipcode" /></td>
|
46 |
</tr>
|
47 |
<tr>
|
48 |
-
<td><label for="country"><?php echo
|
49 |
<td><input type="text" id="country" value="<?php echo $country; ?>" tabindex="10" size="50" name="country" /></td>
|
50 |
</tr>
|
51 |
<tr>
|
52 |
-
<td><label for="membership_level"><?php echo
|
53 |
<td>
|
54 |
<?php echo $membership_level_alias; ?>
|
55 |
</td>
|
56 |
</tr>
|
57 |
</table>
|
58 |
-
<p align="center"><input type="submit" value="<?php echo
|
59 |
</p>
|
60 |
-
<?php echo
|
61 |
|
62 |
<input type="hidden" name="action" value="custom_posts" />
|
63 |
<?php wp_nonce_field('name_of_my_action', 'name_of_nonce_field'); ?>
|
@@ -65,7 +65,7 @@
|
|
65 |
<script>
|
66 |
jQuery(document).ready(function($){
|
67 |
$.validationEngineLanguage.allRules['ajaxEmailCall']['url']= '<?php echo admin_url('admin-ajax.php');?>';
|
68 |
-
$.validationEngineLanguage.allRules['ajaxEmailCall']['extraData'] = '&action=swpm_validate_email&member_id=<?php echo
|
69 |
$("#swpm-editprofile-form").validationEngine('attach');
|
70 |
});
|
71 |
</script>
|
1 |
<form id="swpm-editprofile-form" name="swpm-editprofile-form" method="post" action="">
|
2 |
<table>
|
3 |
<tr>
|
4 |
+
<td><label for="user_name"><?php echo SwpmUtils::_('User Name') ?></label></td>
|
5 |
<td><?php echo $user_name ?></td>
|
6 |
</tr>
|
7 |
<tr>
|
8 |
+
<td><label for="email"><?php echo SwpmUtils::_('Email')?></label></td>
|
9 |
<td><input type="text" id="email" class="validate[required,custom[email],ajax[ajaxEmailCall]]" value="<?php echo $email;?>" tabindex="2" size="50" name="email" /></td>
|
10 |
</tr>
|
11 |
<tr>
|
12 |
+
<td><label for="password"><?php echo SwpmUtils::_('Password')?></label></td>
|
13 |
<td><input type="text" id="password" value="" tabindex="1" size="50" name="password" /></td>
|
14 |
</tr>
|
15 |
<tr>
|
16 |
+
<td><label for="password_re"><?php echo SwpmUtils::_('Repeat Password')?></label></td>
|
17 |
<td><input type="text" id="password_re" value="" tabindex="2" size="50" name="password_re" /></td>
|
18 |
</tr>
|
19 |
<tr>
|
20 |
+
<td><label for="first_name"><?php echo SwpmUtils::_('First Name')?></label></td>
|
21 |
<td><input type="text" id="first_name" value="<?php echo $first_name; ?>" tabindex="3" size="50" name="first_name" /></td>
|
22 |
</tr>
|
23 |
<tr>
|
24 |
+
<td><label for="last_name"><?php echo SwpmUtils::_('Last Name')?></label></td>
|
25 |
<td><input type="text" id="last_name" value="<?php echo $last_name; ?>" tabindex="4" size="50" name="last_name" /></td>
|
26 |
</tr>
|
27 |
<tr>
|
28 |
+
<td><label for="phone"><?php echo SwpmUtils::_('Phone')?></label></td>
|
29 |
<td><input type="text" id="phone" value="<?php echo $phone; ?>" tabindex="5" size="50" name="phone" /></td>
|
30 |
</tr>
|
31 |
<tr>
|
32 |
+
<td><label for="address_street"><?php echo SwpmUtils::_('Street')?></label></td>
|
33 |
<td><input type="text" id="address_street" value="<?php echo $address_street; ?>" tabindex="6" size="50" name="address_street" /></td>
|
34 |
</tr>
|
35 |
<tr>
|
36 |
+
<td><label for="address_city"><?php echo SwpmUtils::_('City')?></label></td>
|
37 |
<td><input type="text" id="address_city" value="<?php echo $address_city; ?>" tabindex="7" size="50" name="address_city" /></td>
|
38 |
</tr>
|
39 |
<tr>
|
40 |
+
<td><label for="address_state"><?php echo SwpmUtils::_('State')?></label></td>
|
41 |
<td><input type="text" id="address_state" value="<?php echo $address_state; ?>" tabindex="8" size="50" name="address_state" /></td>
|
42 |
</tr>
|
43 |
<tr>
|
44 |
+
<td><label for="address_zipcode"><?php echo SwpmUtils::_('Zipcode')?></label></td>
|
45 |
<td><input type="text" id="address_zipcode" value="<?php echo $address_zipcode; ?>" tabindex="9" size="50" name="address_zipcode" /></td>
|
46 |
</tr>
|
47 |
<tr>
|
48 |
+
<td><label for="country"><?php echo SwpmUtils::_('Country') ?></label></td>
|
49 |
<td><input type="text" id="country" value="<?php echo $country; ?>" tabindex="10" size="50" name="country" /></td>
|
50 |
</tr>
|
51 |
<tr>
|
52 |
+
<td><label for="membership_level"><?php echo SwpmUtils::_('Membership Level')?></label></td>
|
53 |
<td>
|
54 |
<?php echo $membership_level_alias; ?>
|
55 |
</td>
|
56 |
</tr>
|
57 |
</table>
|
58 |
+
<p align="center"><input type="submit" value="<?php echo SwpmUtils::_('Update')?>" tabindex="11" id="submit" name="swpm_editprofile_submit" />
|
59 |
</p>
|
60 |
+
<?php echo SwpmUtils::delete_account_button(); ?>
|
61 |
|
62 |
<input type="hidden" name="action" value="custom_posts" />
|
63 |
<?php wp_nonce_field('name_of_my_action', 'name_of_nonce_field'); ?>
|
65 |
<script>
|
66 |
jQuery(document).ready(function($){
|
67 |
$.validationEngineLanguage.allRules['ajaxEmailCall']['url']= '<?php echo admin_url('admin-ajax.php');?>';
|
68 |
+
$.validationEngineLanguage.allRules['ajaxEmailCall']['extraData'] = '&action=swpm_validate_email&member_id=<?php echo SwpmAuth::get_instance()->get('member_id'); ?>';
|
69 |
$("#swpm-editprofile-form").validationEngine('attach');
|
70 |
});
|
71 |
</script>
|
views/forgot_password.php
CHANGED
@@ -2,14 +2,14 @@
|
|
2 |
<form id="swpm-reset-form" name="swpm-reset-form" method="post" action="">
|
3 |
<table width="95%" border="0" cellpadding="3" cellspacing="5" class="forms">
|
4 |
<tr>
|
5 |
-
<td colspan="2"><label for="swpm_reset_email" class="swpm_label"><?php echo
|
6 |
</tr>
|
7 |
<tr>
|
8 |
<td colspan="2"><input type="text" class="swpm_text_field" id="swpm_reset_email" value="" size="40" name="swpm_reset_email" /></td>
|
9 |
</tr>
|
10 |
<tr>
|
11 |
<td colspan="2">
|
12 |
-
<input type="submit" name="swpm-reset" value="<?php echo
|
13 |
</td>
|
14 |
</tr>
|
15 |
</table>
|
2 |
<form id="swpm-reset-form" name="swpm-reset-form" method="post" action="">
|
3 |
<table width="95%" border="0" cellpadding="3" cellspacing="5" class="forms">
|
4 |
<tr>
|
5 |
+
<td colspan="2"><label for="swpm_reset_email" class="swpm_label"><?php echo SwpmUtils::_('Email Address')?></label></td>
|
6 |
</tr>
|
7 |
<tr>
|
8 |
<td colspan="2"><input type="text" class="swpm_text_field" id="swpm_reset_email" value="" size="40" name="swpm_reset_email" /></td>
|
9 |
</tr>
|
10 |
<tr>
|
11 |
<td colspan="2">
|
12 |
+
<input type="submit" name="swpm-reset" value="<?php echo SwpmUtils::_('Reset Password')?>"/>
|
13 |
</td>
|
14 |
</tr>
|
15 |
</table>
|
views/loggedin.php
CHANGED
@@ -1,21 +1,21 @@
|
|
1 |
<div class="swpm-login-widget-logged">
|
2 |
<div class="swpm-logged-username">
|
3 |
-
<div class="swpm-logged-username-label swpm-logged-label"><?php echo
|
4 |
<div class="swpm-logged-username-value swpm-logged-value"><?php echo $auth->get('user_name'); ?></div>
|
5 |
</div>
|
6 |
<div class="swpm-logged-status">
|
7 |
-
<div class="swpm-logged-status-label swpm-logged-label"><?php echo
|
8 |
<div class="swpm-logged-status-value swpm-logged-value"><?php echo ucfirst($auth->get('account_state')); ?></div>
|
9 |
</div>
|
10 |
<div class="swpm-logged-membership">
|
11 |
-
<div class="swpm-logged-membership-label swpm-logged-label"><?php echo
|
12 |
<div class="swpm-logged-membership-value swpm-logged-value"><?php echo $auth->get('alias'); ?></div>
|
13 |
</div>
|
14 |
<div class="swpm-logged-expiry">
|
15 |
-
<div class="swpm-logged-expiry-label swpm-logged-label"><?php echo
|
16 |
<div class="swpm-logged-expiry-value swpm-logged-value"><?php echo $auth->get_expire_date(); ?></div>
|
17 |
</div>
|
18 |
<div class="swpm-logged-logout-link">
|
19 |
-
<a href="?swpm-logout=true"><?php echo
|
20 |
</div>
|
21 |
</div>
|
1 |
<div class="swpm-login-widget-logged">
|
2 |
<div class="swpm-logged-username">
|
3 |
+
<div class="swpm-logged-username-label swpm-logged-label"><?php echo SwpmUtils::_('Logged in as') ?></div>
|
4 |
<div class="swpm-logged-username-value swpm-logged-value"><?php echo $auth->get('user_name'); ?></div>
|
5 |
</div>
|
6 |
<div class="swpm-logged-status">
|
7 |
+
<div class="swpm-logged-status-label swpm-logged-label"><?php echo SwpmUtils::_('Account Status') ?></div>
|
8 |
<div class="swpm-logged-status-value swpm-logged-value"><?php echo ucfirst($auth->get('account_state')); ?></div>
|
9 |
</div>
|
10 |
<div class="swpm-logged-membership">
|
11 |
+
<div class="swpm-logged-membership-label swpm-logged-label"><?php echo SwpmUtils::_('Membership') ?></div>
|
12 |
<div class="swpm-logged-membership-value swpm-logged-value"><?php echo $auth->get('alias'); ?></div>
|
13 |
</div>
|
14 |
<div class="swpm-logged-expiry">
|
15 |
+
<div class="swpm-logged-expiry-label swpm-logged-label"><?php echo SwpmUtils::_('Account Expiry') ?></div>
|
16 |
<div class="swpm-logged-expiry-value swpm-logged-value"><?php echo $auth->get_expire_date(); ?></div>
|
17 |
</div>
|
18 |
<div class="swpm-logged-logout-link">
|
19 |
+
<a href="?swpm-logout=true"><?php echo SwpmUtils::_('Logout') ?></a>
|
20 |
</div>
|
21 |
</div>
|
views/login.php
CHANGED
@@ -2,29 +2,29 @@
|
|
2 |
<form id="swpm-login-form" name="swpm-login-form" method="post" action="">
|
3 |
<div class="swpm-login-form-inner">
|
4 |
<div class="swpm-username-label">
|
5 |
-
<label for="swpm_user_name" class="swpm-label"><?php echo
|
6 |
</div>
|
7 |
<div class="swpm-username-input">
|
8 |
<input type="text" class="swpm-text-field swpm-username-field" id="swpm_user_name" value="" size="30" name="swpm_user_name" />
|
9 |
</div>
|
10 |
<div class="swpm-password-label">
|
11 |
-
<label for="swpm_password" class="swpm-label"><?php echo
|
12 |
</div>
|
13 |
<div class="swpm-password-input">
|
14 |
<input type="password" class="swpm-text-field swpm-password-field" id="swpm_password" value="" size="30" name="swpm_password" />
|
15 |
</div>
|
16 |
<div class="swpm-remember-me">
|
17 |
<span class="swpm-remember-checkbox"><input type="checkbox" name="rememberme" value="checked='checked'"></span>
|
18 |
-
<span class="swpm-rember-label"> <?php echo
|
19 |
</div>
|
20 |
<div class="swpm-login-submit">
|
21 |
-
<input type="submit" name="swpm-login" value="<?php echo
|
22 |
</div>
|
23 |
<div class="swpm-forgot-pass-link">
|
24 |
-
<a id="forgot_pass" href="<?php echo $password_reset_url; ?>"><?php echo
|
25 |
</div>
|
26 |
<div class="swpm-join-us-link">
|
27 |
-
<a id="register" class="register_link" href="<?php echo $join_url; ?>"><?php echo
|
28 |
</div>
|
29 |
<div class="swpm-login-action-msg">
|
30 |
<span class="swpm-login-widget-action-msg"><?php echo $auth->get_message(); ?></span>
|
2 |
<form id="swpm-login-form" name="swpm-login-form" method="post" action="">
|
3 |
<div class="swpm-login-form-inner">
|
4 |
<div class="swpm-username-label">
|
5 |
+
<label for="swpm_user_name" class="swpm-label"><?php echo SwpmUtils::_('Username') ?></label>
|
6 |
</div>
|
7 |
<div class="swpm-username-input">
|
8 |
<input type="text" class="swpm-text-field swpm-username-field" id="swpm_user_name" value="" size="30" name="swpm_user_name" />
|
9 |
</div>
|
10 |
<div class="swpm-password-label">
|
11 |
+
<label for="swpm_password" class="swpm-label"><?php echo SwpmUtils::_('Password') ?></label>
|
12 |
</div>
|
13 |
<div class="swpm-password-input">
|
14 |
<input type="password" class="swpm-text-field swpm-password-field" id="swpm_password" value="" size="30" name="swpm_password" />
|
15 |
</div>
|
16 |
<div class="swpm-remember-me">
|
17 |
<span class="swpm-remember-checkbox"><input type="checkbox" name="rememberme" value="checked='checked'"></span>
|
18 |
+
<span class="swpm-rember-label"> <?php echo SwpmUtils::_('Remember Me') ?></span>
|
19 |
</div>
|
20 |
<div class="swpm-login-submit">
|
21 |
+
<input type="submit" name="swpm-login" value="<?php echo SwpmUtils::_('Login') ?>"/>
|
22 |
</div>
|
23 |
<div class="swpm-forgot-pass-link">
|
24 |
+
<a id="forgot_pass" href="<?php echo $password_reset_url; ?>"><?php echo SwpmUtils::_('Forgot Password') ?>?</a>
|
25 |
</div>
|
26 |
<div class="swpm-join-us-link">
|
27 |
+
<a id="register" class="register_link" href="<?php echo $join_url; ?>"><?php echo SwpmUtils::_('Join Us') ?></a>
|
28 |
</div>
|
29 |
<div class="swpm-login-action-msg">
|
30 |
<span class="swpm-login-widget-action-msg"><?php echo $auth->get_message(); ?></span>
|