Version Description
- Added back shortcode menu item previously removed in 3.3.0.
- Added new handling in wpmem_is_blocked() for validating rest api requests.
- Added new wpmem_is_rest() function to the plugin's API, determines if the request is a rest request.
- Fixed issue with dropdown, mutliple select, and radio field types that allowed white space in resulting value.
- Fixed issue with register/profile update validation if email is removed via wpmem_fields filter hook.
- Fixed issue with prev/next post links to not show hidden posts if user is logged in but does not have a membership.
- Fixed issue with hidden posts when membership products are used. Hidden posts not assigned a membership remained hidden.
- Fixed issue with menus where logged in/logged out settings were not applied unless membership products were enabled.
- Moved wpmem_post_register_data action to fire hooked to user_register at priority 20. Changed email actions to fire at priority 25. See release announcement for more detail of implications.
- Code improvement to reCAPTCHA.
- Code improvement to excerpt generation.
- Code improvement to expiration date generation.
- Code improvement to hidden posts when using membership products.
- Code improvement changed user_register hook priority for post_register_data() to "9" to allow for custom meta fields to be available to any user_register function using the default priority (10) or later.
Download this release
Release Info
Developer | cbutlerjr |
Plugin | WP-Members Membership Plugin |
Version | 3.3.2 |
Comparing to | |
See all releases |
Code changes from version 3.3.1 to 3.3.2
- admin/post.php +6 -0
- assets/css/admin.css +117 -117
- assets/css/forms/generic-no-float.css +2 -2
- assets/css/forms/generic-rigid.css +2 -2
- assets/js/admin.js +227 -227
- assets/js/shortcodes_tinymce.js +222 -0
- assets/js/shortcodes_tinymce.min.js +1 -0
- inc/dialogs.php +4 -3
- inc/email.php +10 -0
- includes/admin/admin.php +143 -143
- includes/admin/api.php +116 -116
- includes/admin/class-wp-members-admin-api.php +2 -0
- includes/admin/class-wp-members-admin-posts.php +15 -0
- includes/admin/class-wp-members-admin-users.php +10 -3
- includes/admin/class-wp-members-tinymce-buttons.php +66 -0
- includes/admin/dialogs.php +257 -257
- includes/admin/tabs/class-wp-members-admin-tab-captcha.php +305 -305
- includes/admin/tabs/class-wp-members-admin-tab-dialogs.php +126 -126
- includes/admin/tabs/class-wp-members-admin-tab-dropins.php +230 -230
- includes/admin/tabs/class-wp-members-admin-tab-emails.php +164 -164
- includes/admin/tabs/class-wp-members-admin-tab-fields.php +758 -758
- includes/admin/tabs/class-wp-members-admin-tab-options.php +2 -2
- includes/admin/tabs/class-wp-members-dropins-table.php +192 -192
- includes/admin/tabs/class-wp-members-fields-table.php +167 -167
- includes/api/api-email.php +118 -118
- includes/api/api-forms.php +19 -3
- includes/api/api-products.php +18 -18
- includes/api/api-users.php +762 -771
- includes/api/api-utilities.php +340 -340
- includes/api/api.php +406 -381
- includes/class-wp-members-captcha.php +250 -233
- includes/class-wp-members-email.php +555 -555
- includes/class-wp-members-forms.php +2068 -2059
- includes/class-wp-members-menus.php +10 -6
- includes/class-wp-members-shortcodes.php +8 -3
- includes/class-wp-members-user.php +63 -54
- includes/class-wp-members.php +153 -58
- includes/deprecated.php +3 -3
- includes/install.php +2 -2
- includes/legacy/dialogs.php +574 -574
- readme.txt +29 -5
- templates/tos.php +38 -38
- uninstall.php +90 -90
- wp-members.php +3 -3
admin/post.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Included for legacy reasons: backward compatibility.
|
4 |
+
*
|
5 |
+
* Remove later.
|
6 |
+
*/
|
assets/css/admin.css
CHANGED
@@ -1,118 +1,118 @@
|
|
1 |
-
/**
|
2 |
-
* WP-Members Admin Styles CSS
|
3 |
-
*
|
4 |
-
* CSS for the WP-Members admin panels
|
5 |
-
*
|
6 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
7 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
8 |
-
* Copyright (c) 2006-
|
9 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
10 |
-
*
|
11 |
-
* @package WP-Members
|
12 |
-
* @author Chad Butler
|
13 |
-
* @copyright 2006-
|
14 |
-
*/
|
15 |
-
|
16 |
-
|
17 |
-
.wpmem_tbl_drag {
|
18 |
-
background:#fffbcc;
|
19 |
-
font-weight: bold;
|
20 |
-
border: 1px solid #990000;
|
21 |
-
}
|
22 |
-
|
23 |
-
.column-wpmem_block {
|
24 |
-
width: 80px;
|
25 |
-
}
|
26 |
-
|
27 |
-
#addfieldform li,
|
28 |
-
#editfieldform li,
|
29 |
-
#updatesettings li {
|
30 |
-
padding: 5px 0;
|
31 |
-
}
|
32 |
-
|
33 |
-
#addfieldform label,
|
34 |
-
#editfieldform label,
|
35 |
-
#updatesettings label {
|
36 |
-
float:left;
|
37 |
-
width: 166px;
|
38 |
-
clear: both;
|
39 |
-
display: block;
|
40 |
-
}
|
41 |
-
|
42 |
-
#addfieldform .add-field-indent,
|
43 |
-
#editfieldform .add-field-indent {
|
44 |
-
margin-left: 165px;
|
45 |
-
}
|
46 |
-
|
47 |
-
#fields_postbox,
|
48 |
-
#add_field_postbox {
|
49 |
-
min-width:950px;
|
50 |
-
}
|
51 |
-
|
52 |
-
.req {
|
53 |
-
color: #f00;
|
54 |
-
}
|
55 |
-
|
56 |
-
#the-list {
|
57 |
-
cursor: move;
|
58 |
-
}
|
59 |
-
#sort, #edit {
|
60 |
-
width: 30px;
|
61 |
-
}
|
62 |
-
|
63 |
-
#wpmem_block input {
|
64 |
-
vertical-align: -webkit-baseline-middle;
|
65 |
-
margin: 0 0 8px 0;
|
66 |
-
}
|
67 |
-
#wpmem_block label {
|
68 |
-
margin: 0 0 0 8px;
|
69 |
-
}
|
70 |
-
#wpmem_ok_block_status {
|
71 |
-
margin: 5px 0 0 0;
|
72 |
-
}
|
73 |
-
#wpmem_post_block_status {
|
74 |
-
font-weight: 600;
|
75 |
-
}
|
76 |
-
#wpmem_post_icon_0 {
|
77 |
-
color: red;
|
78 |
-
}
|
79 |
-
#wpmem_post_icon_1 {
|
80 |
-
color: green;
|
81 |
-
}
|
82 |
-
#wpmem_post_icon_2 {
|
83 |
-
color: black;
|
84 |
-
}
|
85 |
-
#wpmem_product_enabled {
|
86 |
-
color: green;
|
87 |
-
}
|
88 |
-
#s2id__wpmem_products,
|
89 |
-
.select2-search-field,
|
90 |
-
#_wpmem_products {
|
91 |
-
width: 100%;
|
92 |
-
}
|
93 |
-
|
94 |
-
/** User Profile Tabs **/
|
95 |
-
#wpmem_user_profile_tabs {
|
96 |
-
padding: 0px;
|
97 |
-
background: none;
|
98 |
-
border-width: 0px;
|
99 |
-
}
|
100 |
-
#wpmem_user_profile_tabs .ui-tabs-nav {
|
101 |
-
padding-left: 0px;
|
102 |
-
background: transparent;
|
103 |
-
border-width: 0px 0px 1px 0px;
|
104 |
-
-moz-border-radius: 0px;
|
105 |
-
-webkit-border-radius: 0px;
|
106 |
-
border-radius: 0px;
|
107 |
-
}
|
108 |
-
#wpmem_user_profile_tabs .ui-tabs-panel {
|
109 |
-
background: #fff;
|
110 |
-
border-width: 0px 1px 1px 1px;
|
111 |
-
}
|
112 |
-
#wpmem_user_profile_tabs .ui-state-active {
|
113 |
-
border: 1px solid #006799;
|
114 |
-
background: #008ec2;
|
115 |
-
}
|
116 |
-
#wpmem_user_profile_tabs .ui-state-active a {
|
117 |
-
color: #fff;
|
118 |
}
|
1 |
+
/**
|
2 |
+
* WP-Members Admin Styles CSS
|
3 |
+
*
|
4 |
+
* CSS for the WP-Members admin panels
|
5 |
+
*
|
6 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
7 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
8 |
+
* Copyright (c) 2006-2020 Chad Butler
|
9 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
10 |
+
*
|
11 |
+
* @package WP-Members
|
12 |
+
* @author Chad Butler
|
13 |
+
* @copyright 2006-2020
|
14 |
+
*/
|
15 |
+
|
16 |
+
|
17 |
+
.wpmem_tbl_drag {
|
18 |
+
background:#fffbcc;
|
19 |
+
font-weight: bold;
|
20 |
+
border: 1px solid #990000;
|
21 |
+
}
|
22 |
+
|
23 |
+
.column-wpmem_block {
|
24 |
+
width: 80px;
|
25 |
+
}
|
26 |
+
|
27 |
+
#addfieldform li,
|
28 |
+
#editfieldform li,
|
29 |
+
#updatesettings li {
|
30 |
+
padding: 5px 0;
|
31 |
+
}
|
32 |
+
|
33 |
+
#addfieldform label,
|
34 |
+
#editfieldform label,
|
35 |
+
#updatesettings label {
|
36 |
+
float:left;
|
37 |
+
width: 166px;
|
38 |
+
clear: both;
|
39 |
+
display: block;
|
40 |
+
}
|
41 |
+
|
42 |
+
#addfieldform .add-field-indent,
|
43 |
+
#editfieldform .add-field-indent {
|
44 |
+
margin-left: 165px;
|
45 |
+
}
|
46 |
+
|
47 |
+
#fields_postbox,
|
48 |
+
#add_field_postbox {
|
49 |
+
min-width:950px;
|
50 |
+
}
|
51 |
+
|
52 |
+
.req {
|
53 |
+
color: #f00;
|
54 |
+
}
|
55 |
+
|
56 |
+
#the-list {
|
57 |
+
cursor: move;
|
58 |
+
}
|
59 |
+
#sort, #edit {
|
60 |
+
width: 30px;
|
61 |
+
}
|
62 |
+
|
63 |
+
#wpmem_block input {
|
64 |
+
vertical-align: -webkit-baseline-middle;
|
65 |
+
margin: 0 0 8px 0;
|
66 |
+
}
|
67 |
+
#wpmem_block label {
|
68 |
+
margin: 0 0 0 8px;
|
69 |
+
}
|
70 |
+
#wpmem_ok_block_status {
|
71 |
+
margin: 5px 0 0 0;
|
72 |
+
}
|
73 |
+
#wpmem_post_block_status {
|
74 |
+
font-weight: 600;
|
75 |
+
}
|
76 |
+
#wpmem_post_icon_0 {
|
77 |
+
color: red;
|
78 |
+
}
|
79 |
+
#wpmem_post_icon_1 {
|
80 |
+
color: green;
|
81 |
+
}
|
82 |
+
#wpmem_post_icon_2 {
|
83 |
+
color: black;
|
84 |
+
}
|
85 |
+
#wpmem_product_enabled {
|
86 |
+
color: green;
|
87 |
+
}
|
88 |
+
#s2id__wpmem_products,
|
89 |
+
.select2-search-field,
|
90 |
+
#_wpmem_products {
|
91 |
+
width: 100%;
|
92 |
+
}
|
93 |
+
|
94 |
+
/** User Profile Tabs **/
|
95 |
+
#wpmem_user_profile_tabs {
|
96 |
+
padding: 0px;
|
97 |
+
background: none;
|
98 |
+
border-width: 0px;
|
99 |
+
}
|
100 |
+
#wpmem_user_profile_tabs .ui-tabs-nav {
|
101 |
+
padding-left: 0px;
|
102 |
+
background: transparent;
|
103 |
+
border-width: 0px 0px 1px 0px;
|
104 |
+
-moz-border-radius: 0px;
|
105 |
+
-webkit-border-radius: 0px;
|
106 |
+
border-radius: 0px;
|
107 |
+
}
|
108 |
+
#wpmem_user_profile_tabs .ui-tabs-panel {
|
109 |
+
background: #fff;
|
110 |
+
border-width: 0px 1px 1px 1px;
|
111 |
+
}
|
112 |
+
#wpmem_user_profile_tabs .ui-state-active {
|
113 |
+
border: 1px solid #006799;
|
114 |
+
background: #008ec2;
|
115 |
+
}
|
116 |
+
#wpmem_user_profile_tabs .ui-state-active a {
|
117 |
+
color: #fff;
|
118 |
}
|
assets/css/forms/generic-no-float.css
CHANGED
@@ -5,12 +5,12 @@
|
|
5 |
*
|
6 |
* This file is part of the WP-Members plugin by Chad Butler
|
7 |
* You can find out more about this plugin at https://rocketgeek.com
|
8 |
-
* Copyright (c) 2006-
|
9 |
* WP-Members(tm) is a trademark of butlerblog.com
|
10 |
*
|
11 |
* @package WP-Members
|
12 |
* @author Chad Butler
|
13 |
-
* @copyright 2006-
|
14 |
*/
|
15 |
|
16 |
/*
|
5 |
*
|
6 |
* This file is part of the WP-Members plugin by Chad Butler
|
7 |
* You can find out more about this plugin at https://rocketgeek.com
|
8 |
+
* Copyright (c) 2006-2020 Chad Butler
|
9 |
* WP-Members(tm) is a trademark of butlerblog.com
|
10 |
*
|
11 |
* @package WP-Members
|
12 |
* @author Chad Butler
|
13 |
+
* @copyright 2006-2020
|
14 |
*/
|
15 |
|
16 |
/*
|
assets/css/forms/generic-rigid.css
CHANGED
@@ -5,12 +5,12 @@
|
|
5 |
*
|
6 |
* This file is part of the WP-Members plugin by Chad Butler
|
7 |
* You can find out more about this plugin at https://rocketgeek.com
|
8 |
-
* Copyright (c) 2006-
|
9 |
* WP-Members(tm) is a trademark of butlerblog.com
|
10 |
*
|
11 |
* @package WP-Members
|
12 |
* @author Chad Butler
|
13 |
-
* @copyright 2006-
|
14 |
*/
|
15 |
|
16 |
/*
|
5 |
*
|
6 |
* This file is part of the WP-Members plugin by Chad Butler
|
7 |
* You can find out more about this plugin at https://rocketgeek.com
|
8 |
+
* Copyright (c) 2006-2020 Chad Butler
|
9 |
* WP-Members(tm) is a trademark of butlerblog.com
|
10 |
*
|
11 |
* @package WP-Members
|
12 |
* @author Chad Butler
|
13 |
+
* @copyright 2006-2020
|
14 |
*/
|
15 |
|
16 |
/*
|
assets/js/admin.js
CHANGED
@@ -1,228 +1,228 @@
|
|
1 |
-
/**
|
2 |
-
* WP-Members Admin JavaScript Functions
|
3 |
-
*
|
4 |
-
* Contains the JavaScript functions for WP-Members admin.
|
5 |
-
*
|
6 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
7 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
8 |
-
* Copyright (c) 2006-
|
9 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
10 |
-
*
|
11 |
-
* @package WP-Members
|
12 |
-
* @author Chad Butler
|
13 |
-
* @copyright 2006-
|
14 |
-
*/
|
15 |
-
|
16 |
-
|
17 |
-
/**
|
18 |
-
* JS for forms field table drag-and-drop.
|
19 |
-
*
|
20 |
-
* @since 3.1.2
|
21 |
-
*/
|
22 |
-
(function($) {
|
23 |
-
$(document).ready(function($) {
|
24 |
-
$("#the-list").sortable({
|
25 |
-
items: '.list_item',
|
26 |
-
opacity: 0.6,
|
27 |
-
cursor: 'move',
|
28 |
-
axis: 'y',
|
29 |
-
update: function() {
|
30 |
-
var order = $(this).sortable('serialize') + '&action=wpmem_do_field_reorder';
|
31 |
-
$.post(ajaxurl, order, function(response) {
|
32 |
-
alert(response);
|
33 |
-
});
|
34 |
-
$('.list_item').each(function(i) {
|
35 |
-
$(this).data('id', i + 1); // updates the data object
|
36 |
-
$(this).attr('list_item', i + 1); // updates the attribute
|
37 |
-
});
|
38 |
-
}
|
39 |
-
});
|
40 |
-
});
|
41 |
-
})(jQuery);
|
42 |
-
|
43 |
-
|
44 |
-
/**
|
45 |
-
* JS for displaying custom url for:
|
46 |
-
* - Profile page
|
47 |
-
* - Register page
|
48 |
-
* - Custom stylesheet
|
49 |
-
*
|
50 |
-
* @since 2.9.6
|
51 |
-
*/
|
52 |
-
(function($) {
|
53 |
-
$(document).ready(function() {
|
54 |
-
if ($("#wpmem_logpage_select").val() == 'use_custom')
|
55 |
-
$("#wpmem_logpage_custom").show();
|
56 |
-
else
|
57 |
-
$("#wpmem_logpage_custom").hide();
|
58 |
-
if ($("#wpmem_regpage_select").val() == 'use_custom')
|
59 |
-
$("#wpmem_regpage_custom").show();
|
60 |
-
else
|
61 |
-
$("#wpmem_regpage_custom").hide();
|
62 |
-
if ($("#wpmem_mspage_select").val() == 'use_custom')
|
63 |
-
$("#wpmem_mspage_custom").show();
|
64 |
-
else
|
65 |
-
$("#wpmem_mspage_custom").hide();
|
66 |
-
if ($("#wpmem_stylesheet_select").val() == 'use_custom')
|
67 |
-
$("#wpmem_stylesheet_custom").show();
|
68 |
-
else
|
69 |
-
$("#wpmem_stylesheet_custom").hide();
|
70 |
-
$("#wpmem_logpage_select").change(function() {
|
71 |
-
if ($("#wpmem_logpage_select").val() == 'use_custom')
|
72 |
-
$("#wpmem_logpage_custom").show();
|
73 |
-
else
|
74 |
-
$("#wpmem_logpage_custom").hide();
|
75 |
-
});
|
76 |
-
$("#wpmem_regpage_select").change(function() {
|
77 |
-
if ($("#wpmem_regpage_select").val() == 'use_custom')
|
78 |
-
$("#wpmem_regpage_custom").show();
|
79 |
-
else
|
80 |
-
$("#wpmem_regpage_custom").hide();
|
81 |
-
});
|
82 |
-
$("#wpmem_mspage_select").change(function() {
|
83 |
-
if ($("#wpmem_mspage_select").val() == 'use_custom')
|
84 |
-
$("#wpmem_mspage_custom").show();
|
85 |
-
else
|
86 |
-
$("#wpmem_mspage_custom").hide();
|
87 |
-
});
|
88 |
-
$("#wpmem_stylesheet_select").change(function() {
|
89 |
-
if ($("#wpmem_stylesheet_select").val() == 'use_custom')
|
90 |
-
$("#wpmem_stylesheet_custom").show();
|
91 |
-
else
|
92 |
-
$("#wpmem_stylesheet_custom").hide();
|
93 |
-
});
|
94 |
-
});
|
95 |
-
})(jQuery);
|
96 |
-
|
97 |
-
|
98 |
-
/**
|
99 |
-
* JS for displaying additional info for checkbox/dropdowns
|
100 |
-
*
|
101 |
-
* @since 2.9.6
|
102 |
-
*/
|
103 |
-
(function($) {
|
104 |
-
$(document).ready(function() {
|
105 |
-
$("#wpmem_allowhtml").hide();
|
106 |
-
$("#wpmem_rows_cols").hide();
|
107 |
-
$("#wpmem_min_max").hide();
|
108 |
-
$("#wpmem_checkbox_info").hide();
|
109 |
-
$("#wpmem_dropdown_info").hide();
|
110 |
-
$("#wpmem_file_info").hide();
|
111 |
-
$("#wpmem_delimiter_info").hide();
|
112 |
-
$("#wpmem_hidden_info").hide();
|
113 |
-
});
|
114 |
-
$(document).ready(function() {
|
115 |
-
$("#wpmem_field_type_select").change(function() {
|
116 |
-
if ($("#wpmem_field_type_select").val() == 'text'
|
117 |
-
|| $("#wpmem_field_type_select").val() == 'password'
|
118 |
-
|| $("#wpmem_field_type_select").val() == 'email'
|
119 |
-
|| $("#wpmem_field_type_select").val() == 'url'
|
120 |
-
|| $("#wpmem_field_type_select").val() == 'number'
|
121 |
-
|| $("#wpmem_field_type_select").val() == 'date'
|
122 |
-
|| $("#wpmem_field_type_select").val() == 'textarea' )
|
123 |
-
$("#wpmem_placeholder").show();
|
124 |
-
else
|
125 |
-
$("#wpmem_placeholder").hide();
|
126 |
-
if ($("#wpmem_field_type_select").val() == 'text'
|
127 |
-
|| $("#wpmem_field_type_select").val() == 'password'
|
128 |
-
|| $("#wpmem_field_type_select").val() == 'email'
|
129 |
-
|| $("#wpmem_field_type_select").val() == 'url'
|
130 |
-
|| $("#wpmem_field_type_select").val() == 'number'
|
131 |
-
|| $("#wpmem_field_type_select").val() == 'date' ) {
|
132 |
-
$("#wpmem_pattern").show();
|
133 |
-
$("#wpmem_title").show();
|
134 |
-
} else {
|
135 |
-
$("#wpmem_pattern").hide();
|
136 |
-
$("#wpmem_title").hide();
|
137 |
-
}
|
138 |
-
if ($("#wpmem_field_type_select").val() == 'textarea' ) {
|
139 |
-
$("#wpmem_allowhtml").show();
|
140 |
-
$("#wpmem_rows_cols").show();
|
141 |
-
} else {
|
142 |
-
$("#wpmem_allowhtml").hide();
|
143 |
-
$("#wpmem_rows_cols").hide();
|
144 |
-
}
|
145 |
-
if ($("#wpmem_field_type_select").val() == 'number' || $("#wpmem_field_type_select").val() == 'date' )
|
146 |
-
$("#wpmem_min_max").show();
|
147 |
-
else
|
148 |
-
$("#wpmem_min_max").hide();
|
149 |
-
if ($("#wpmem_field_type_select").val() == 'checkbox') {
|
150 |
-
$("#wpmem_checkbox_info").show();
|
151 |
-
$("#add_checked_value").prop('required',true);
|
152 |
-
} else {
|
153 |
-
$("#wpmem_checkbox_info").hide();
|
154 |
-
$("#add_checked_value").prop('required',false);
|
155 |
-
}
|
156 |
-
if ( $("#wpmem_field_type_select").val() == 'select'
|
157 |
-
|| $("#wpmem_field_type_select").val() == 'multiselect'
|
158 |
-
|| $("#wpmem_field_type_select").val() == 'radio'
|
159 |
-
|| $("#wpmem_field_type_select").val() == 'multicheckbox'
|
160 |
-
) {
|
161 |
-
$("#wpmem_dropdown_info").show();
|
162 |
-
$("#add_dropdown_value").prop('required',true);
|
163 |
-
} else {
|
164 |
-
$("#wpmem_dropdown_info").hide();
|
165 |
-
$("#add_dropdown_value").prop('required',false);
|
166 |
-
}
|
167 |
-
if ( $("#wpmem_field_type_select").val() == 'multiselect' || $("#wpmem_field_type_select").val() == 'multicheckbox'
|
168 |
-
)
|
169 |
-
$("#wpmem_delimiter_info").show();
|
170 |
-
else
|
171 |
-
$("#wpmem_delimiter_info").hide();
|
172 |
-
if ($("#wpmem_field_type_select").val() == 'file' || $("#wpmem_field_type_select").val() == 'image' )
|
173 |
-
$("#wpmem_file_info").show();
|
174 |
-
else
|
175 |
-
$("#wpmem_file_info").hide();
|
176 |
-
if ($("#wpmem_field_type_select").val() == 'hidden') {
|
177 |
-
$("#wpmem_hidden_info").show();
|
178 |
-
$("#add_hidden_value").prop('required',true);
|
179 |
-
} else {
|
180 |
-
$("#wpmem_hidden_info").hide();
|
181 |
-
$("#add_hidden_value").prop('required',false);
|
182 |
-
}
|
183 |
-
});
|
184 |
-
});
|
185 |
-
})(jQuery);
|
186 |
-
|
187 |
-
/**
|
188 |
-
* JS for post block status meta box
|
189 |
-
*
|
190 |
-
* @since 3.2.1
|
191 |
-
*/
|
192 |
-
(function($) {
|
193 |
-
$(document).ready(function() {
|
194 |
-
$("#wpmem_block").hide();
|
195 |
-
});
|
196 |
-
$(document).ready(function() {
|
197 |
-
$("#wpmem_edit_block_status").click(function() {
|
198 |
-
$("#wpmem_block").show('normal');
|
199 |
-
$("#wpmem_edit_block_status").hide();
|
200 |
-
});
|
201 |
-
$("#wpmem_cancel_block_status").click(function() {
|
202 |
-
$("#wpmem_block").hide('normal');
|
203 |
-
$("#wpmem_edit_block_status").show();
|
204 |
-
$("#wpmem_post_block_status").text($("input[name=wpmem_block_original_label]").val());
|
205 |
-
$('#wpmem_post_block_status_' + $('input[name=wpmem_block_original_value]')).val().prop("checked", true);
|
206 |
-
});
|
207 |
-
$("#wpmem_ok_block_status").click(function() {
|
208 |
-
$("#wpmem_block").hide('normal');
|
209 |
-
$("#wpmem_edit_block_status").show();
|
210 |
-
$("#wpmem_post_block_status").text($("input[name=wpmem_block]:checked + label").text());
|
211 |
-
if($('#wpmem_block_status_0').is(':checked')) {
|
212 |
-
$("#wpmem_post_icon_0").show();
|
213 |
-
$("#wpmem_post_icon_1").hide();
|
214 |
-
$("#wpmem_post_icon_2").hide();
|
215 |
-
}
|
216 |
-
if($('#wpmem_block_status_1').is(':checked')) {
|
217 |
-
$("#wpmem_post_icon_0").hide();
|
218 |
-
$("#wpmem_post_icon_1").show();
|
219 |
-
$("#wpmem_post_icon_2").hide();
|
220 |
-
}
|
221 |
-
if($('#wpmem_block_status_2').is(':checked')) {
|
222 |
-
$("#wpmem_post_icon_0").hide();
|
223 |
-
$("#wpmem_post_icon_1").hide();
|
224 |
-
$("#wpmem_post_icon_2").show();
|
225 |
-
}
|
226 |
-
});
|
227 |
-
});
|
228 |
})(jQuery);
|
1 |
+
/**
|
2 |
+
* WP-Members Admin JavaScript Functions
|
3 |
+
*
|
4 |
+
* Contains the JavaScript functions for WP-Members admin.
|
5 |
+
*
|
6 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
7 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
8 |
+
* Copyright (c) 2006-2020 Chad Butler
|
9 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
10 |
+
*
|
11 |
+
* @package WP-Members
|
12 |
+
* @author Chad Butler
|
13 |
+
* @copyright 2006-2020
|
14 |
+
*/
|
15 |
+
|
16 |
+
|
17 |
+
/**
|
18 |
+
* JS for forms field table drag-and-drop.
|
19 |
+
*
|
20 |
+
* @since 3.1.2
|
21 |
+
*/
|
22 |
+
(function($) {
|
23 |
+
$(document).ready(function($) {
|
24 |
+
$("#the-list").sortable({
|
25 |
+
items: '.list_item',
|
26 |
+
opacity: 0.6,
|
27 |
+
cursor: 'move',
|
28 |
+
axis: 'y',
|
29 |
+
update: function() {
|
30 |
+
var order = $(this).sortable('serialize') + '&action=wpmem_do_field_reorder';
|
31 |
+
$.post(ajaxurl, order, function(response) {
|
32 |
+
alert(response);
|
33 |
+
});
|
34 |
+
$('.list_item').each(function(i) {
|
35 |
+
$(this).data('id', i + 1); // updates the data object
|
36 |
+
$(this).attr('list_item', i + 1); // updates the attribute
|
37 |
+
});
|
38 |
+
}
|
39 |
+
});
|
40 |
+
});
|
41 |
+
})(jQuery);
|
42 |
+
|
43 |
+
|
44 |
+
/**
|
45 |
+
* JS for displaying custom url for:
|
46 |
+
* - Profile page
|
47 |
+
* - Register page
|
48 |
+
* - Custom stylesheet
|
49 |
+
*
|
50 |
+
* @since 2.9.6
|
51 |
+
*/
|
52 |
+
(function($) {
|
53 |
+
$(document).ready(function() {
|
54 |
+
if ($("#wpmem_logpage_select").val() == 'use_custom')
|
55 |
+
$("#wpmem_logpage_custom").show();
|
56 |
+
else
|
57 |
+
$("#wpmem_logpage_custom").hide();
|
58 |
+
if ($("#wpmem_regpage_select").val() == 'use_custom')
|
59 |
+
$("#wpmem_regpage_custom").show();
|
60 |
+
else
|
61 |
+
$("#wpmem_regpage_custom").hide();
|
62 |
+
if ($("#wpmem_mspage_select").val() == 'use_custom')
|
63 |
+
$("#wpmem_mspage_custom").show();
|
64 |
+
else
|
65 |
+
$("#wpmem_mspage_custom").hide();
|
66 |
+
if ($("#wpmem_stylesheet_select").val() == 'use_custom')
|
67 |
+
$("#wpmem_stylesheet_custom").show();
|
68 |
+
else
|
69 |
+
$("#wpmem_stylesheet_custom").hide();
|
70 |
+
$("#wpmem_logpage_select").change(function() {
|
71 |
+
if ($("#wpmem_logpage_select").val() == 'use_custom')
|
72 |
+
$("#wpmem_logpage_custom").show();
|
73 |
+
else
|
74 |
+
$("#wpmem_logpage_custom").hide();
|
75 |
+
});
|
76 |
+
$("#wpmem_regpage_select").change(function() {
|
77 |
+
if ($("#wpmem_regpage_select").val() == 'use_custom')
|
78 |
+
$("#wpmem_regpage_custom").show();
|
79 |
+
else
|
80 |
+
$("#wpmem_regpage_custom").hide();
|
81 |
+
});
|
82 |
+
$("#wpmem_mspage_select").change(function() {
|
83 |
+
if ($("#wpmem_mspage_select").val() == 'use_custom')
|
84 |
+
$("#wpmem_mspage_custom").show();
|
85 |
+
else
|
86 |
+
$("#wpmem_mspage_custom").hide();
|
87 |
+
});
|
88 |
+
$("#wpmem_stylesheet_select").change(function() {
|
89 |
+
if ($("#wpmem_stylesheet_select").val() == 'use_custom')
|
90 |
+
$("#wpmem_stylesheet_custom").show();
|
91 |
+
else
|
92 |
+
$("#wpmem_stylesheet_custom").hide();
|
93 |
+
});
|
94 |
+
});
|
95 |
+
})(jQuery);
|
96 |
+
|
97 |
+
|
98 |
+
/**
|
99 |
+
* JS for displaying additional info for checkbox/dropdowns
|
100 |
+
*
|
101 |
+
* @since 2.9.6
|
102 |
+
*/
|
103 |
+
(function($) {
|
104 |
+
$(document).ready(function() {
|
105 |
+
$("#wpmem_allowhtml").hide();
|
106 |
+
$("#wpmem_rows_cols").hide();
|
107 |
+
$("#wpmem_min_max").hide();
|
108 |
+
$("#wpmem_checkbox_info").hide();
|
109 |
+
$("#wpmem_dropdown_info").hide();
|
110 |
+
$("#wpmem_file_info").hide();
|
111 |
+
$("#wpmem_delimiter_info").hide();
|
112 |
+
$("#wpmem_hidden_info").hide();
|
113 |
+
});
|
114 |
+
$(document).ready(function() {
|
115 |
+
$("#wpmem_field_type_select").change(function() {
|
116 |
+
if ($("#wpmem_field_type_select").val() == 'text'
|
117 |
+
|| $("#wpmem_field_type_select").val() == 'password'
|
118 |
+
|| $("#wpmem_field_type_select").val() == 'email'
|
119 |
+
|| $("#wpmem_field_type_select").val() == 'url'
|
120 |
+
|| $("#wpmem_field_type_select").val() == 'number'
|
121 |
+
|| $("#wpmem_field_type_select").val() == 'date'
|
122 |
+
|| $("#wpmem_field_type_select").val() == 'textarea' )
|
123 |
+
$("#wpmem_placeholder").show();
|
124 |
+
else
|
125 |
+
$("#wpmem_placeholder").hide();
|
126 |
+
if ($("#wpmem_field_type_select").val() == 'text'
|
127 |
+
|| $("#wpmem_field_type_select").val() == 'password'
|
128 |
+
|| $("#wpmem_field_type_select").val() == 'email'
|
129 |
+
|| $("#wpmem_field_type_select").val() == 'url'
|
130 |
+
|| $("#wpmem_field_type_select").val() == 'number'
|
131 |
+
|| $("#wpmem_field_type_select").val() == 'date' ) {
|
132 |
+
$("#wpmem_pattern").show();
|
133 |
+
$("#wpmem_title").show();
|
134 |
+
} else {
|
135 |
+
$("#wpmem_pattern").hide();
|
136 |
+
$("#wpmem_title").hide();
|
137 |
+
}
|
138 |
+
if ($("#wpmem_field_type_select").val() == 'textarea' ) {
|
139 |
+
$("#wpmem_allowhtml").show();
|
140 |
+
$("#wpmem_rows_cols").show();
|
141 |
+
} else {
|
142 |
+
$("#wpmem_allowhtml").hide();
|
143 |
+
$("#wpmem_rows_cols").hide();
|
144 |
+
}
|
145 |
+
if ($("#wpmem_field_type_select").val() == 'number' || $("#wpmem_field_type_select").val() == 'date' )
|
146 |
+
$("#wpmem_min_max").show();
|
147 |
+
else
|
148 |
+
$("#wpmem_min_max").hide();
|
149 |
+
if ($("#wpmem_field_type_select").val() == 'checkbox') {
|
150 |
+
$("#wpmem_checkbox_info").show();
|
151 |
+
$("#add_checked_value").prop('required',true);
|
152 |
+
} else {
|
153 |
+
$("#wpmem_checkbox_info").hide();
|
154 |
+
$("#add_checked_value").prop('required',false);
|
155 |
+
}
|
156 |
+
if ( $("#wpmem_field_type_select").val() == 'select'
|
157 |
+
|| $("#wpmem_field_type_select").val() == 'multiselect'
|
158 |
+
|| $("#wpmem_field_type_select").val() == 'radio'
|
159 |
+
|| $("#wpmem_field_type_select").val() == 'multicheckbox'
|
160 |
+
) {
|
161 |
+
$("#wpmem_dropdown_info").show();
|
162 |
+
$("#add_dropdown_value").prop('required',true);
|
163 |
+
} else {
|
164 |
+
$("#wpmem_dropdown_info").hide();
|
165 |
+
$("#add_dropdown_value").prop('required',false);
|
166 |
+
}
|
167 |
+
if ( $("#wpmem_field_type_select").val() == 'multiselect' || $("#wpmem_field_type_select").val() == 'multicheckbox'
|
168 |
+
)
|
169 |
+
$("#wpmem_delimiter_info").show();
|
170 |
+
else
|
171 |
+
$("#wpmem_delimiter_info").hide();
|
172 |
+
if ($("#wpmem_field_type_select").val() == 'file' || $("#wpmem_field_type_select").val() == 'image' )
|
173 |
+
$("#wpmem_file_info").show();
|
174 |
+
else
|
175 |
+
$("#wpmem_file_info").hide();
|
176 |
+
if ($("#wpmem_field_type_select").val() == 'hidden') {
|
177 |
+
$("#wpmem_hidden_info").show();
|
178 |
+
$("#add_hidden_value").prop('required',true);
|
179 |
+
} else {
|
180 |
+
$("#wpmem_hidden_info").hide();
|
181 |
+
$("#add_hidden_value").prop('required',false);
|
182 |
+
}
|
183 |
+
});
|
184 |
+
});
|
185 |
+
})(jQuery);
|
186 |
+
|
187 |
+
/**
|
188 |
+
* JS for post block status meta box
|
189 |
+
*
|
190 |
+
* @since 3.2.1
|
191 |
+
*/
|
192 |
+
(function($) {
|
193 |
+
$(document).ready(function() {
|
194 |
+
$("#wpmem_block").hide();
|
195 |
+
});
|
196 |
+
$(document).ready(function() {
|
197 |
+
$("#wpmem_edit_block_status").click(function() {
|
198 |
+
$("#wpmem_block").show('normal');
|
199 |
+
$("#wpmem_edit_block_status").hide();
|
200 |
+
});
|
201 |
+
$("#wpmem_cancel_block_status").click(function() {
|
202 |
+
$("#wpmem_block").hide('normal');
|
203 |
+
$("#wpmem_edit_block_status").show();
|
204 |
+
$("#wpmem_post_block_status").text($("input[name=wpmem_block_original_label]").val());
|
205 |
+
$('#wpmem_post_block_status_' + $('input[name=wpmem_block_original_value]')).val().prop("checked", true);
|
206 |
+
});
|
207 |
+
$("#wpmem_ok_block_status").click(function() {
|
208 |
+
$("#wpmem_block").hide('normal');
|
209 |
+
$("#wpmem_edit_block_status").show();
|
210 |
+
$("#wpmem_post_block_status").text($("input[name=wpmem_block]:checked + label").text());
|
211 |
+
if($('#wpmem_block_status_0').is(':checked')) {
|
212 |
+
$("#wpmem_post_icon_0").show();
|
213 |
+
$("#wpmem_post_icon_1").hide();
|
214 |
+
$("#wpmem_post_icon_2").hide();
|
215 |
+
}
|
216 |
+
if($('#wpmem_block_status_1').is(':checked')) {
|
217 |
+
$("#wpmem_post_icon_0").hide();
|
218 |
+
$("#wpmem_post_icon_1").show();
|
219 |
+
$("#wpmem_post_icon_2").hide();
|
220 |
+
}
|
221 |
+
if($('#wpmem_block_status_2').is(':checked')) {
|
222 |
+
$("#wpmem_post_icon_0").hide();
|
223 |
+
$("#wpmem_post_icon_1").hide();
|
224 |
+
$("#wpmem_post_icon_2").show();
|
225 |
+
}
|
226 |
+
});
|
227 |
+
});
|
228 |
})(jQuery);
|
assets/js/shortcodes_tinymce.js
ADDED
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function () {
|
2 |
+
"use strict";
|
3 |
+
|
4 |
+
var wcShortcodeManager = function(editor, url) {
|
5 |
+
var wcDummyContent = 'Sample Content';
|
6 |
+
var wcParagraphContent = '<p>Sample Content</p>';
|
7 |
+
|
8 |
+
|
9 |
+
editor.addButton('wpmem_shortcodes_button', function() {
|
10 |
+
return {
|
11 |
+
title: "WP-Members Shortcodes",
|
12 |
+
tooltip: "WP-Members Shortcodes",
|
13 |
+
icon: "user",
|
14 |
+
type: 'menubutton',
|
15 |
+
icons: false,
|
16 |
+
menu: [
|
17 |
+
{
|
18 |
+
text: 'WP-Members Shortcodes',
|
19 |
+
},
|
20 |
+
{
|
21 |
+
text: 'Login Forms',
|
22 |
+
menu: [
|
23 |
+
{
|
24 |
+
text: "basic login",
|
25 |
+
onclick: function(){
|
26 |
+
editor.insertContent('[wpmem_form login]');
|
27 |
+
}
|
28 |
+
},
|
29 |
+
{
|
30 |
+
text: "login + redirect",
|
31 |
+
onclick: function(){
|
32 |
+
editor.insertContent('[wpmem_form login redirect_to="https://mysite.com/my-page/"]');
|
33 |
+
}
|
34 |
+
},
|
35 |
+
{
|
36 |
+
text: "login + logged in content",
|
37 |
+
onclick: function(){
|
38 |
+
editor.insertContent('[wpmem_form login]<br />This displays when logged in<br />[/wpmem_form]');
|
39 |
+
}
|
40 |
+
},
|
41 |
+
{
|
42 |
+
text: "login + redirect + content",
|
43 |
+
onclick: function(){
|
44 |
+
editor.insertContent('[wpmem_form login redirect_to="https://mysite.com/my-page/"]<br />This displays when logged in<br />[/wpmem_form]');
|
45 |
+
}
|
46 |
+
},
|
47 |
+
]
|
48 |
+
},
|
49 |
+
{
|
50 |
+
text: 'Registration Forms',
|
51 |
+
menu: [
|
52 |
+
{
|
53 |
+
text: "basic registration",
|
54 |
+
onclick: function(){
|
55 |
+
editor.insertContent('[wpmem_form register]');
|
56 |
+
}
|
57 |
+
},
|
58 |
+
{
|
59 |
+
text: "registration + redirect",
|
60 |
+
onclick: function(){
|
61 |
+
editor.insertContent('[wpmem_form register redirect_to="https://mysite.com/my-page/"]');
|
62 |
+
}
|
63 |
+
},
|
64 |
+
{
|
65 |
+
text: "registration + logged in content",
|
66 |
+
onclick: function(){
|
67 |
+
editor.insertContent('[wpmem_form register]<br />This displays when logged in<br />[/wpmem_form]');
|
68 |
+
}
|
69 |
+
},
|
70 |
+
{
|
71 |
+
text: "registration + redirect + content",
|
72 |
+
onclick: function(){
|
73 |
+
editor.insertContent('[wpmem_form register redirect_to="https://mysite.com/my-page/"]<br />This displays when logged in<br />[/wpmem_form]');
|
74 |
+
}
|
75 |
+
},
|
76 |
+
]
|
77 |
+
},
|
78 |
+
{
|
79 |
+
text: 'User Profile',
|
80 |
+
menu: [
|
81 |
+
{
|
82 |
+
text: "User Profile Page",
|
83 |
+
onclick: function(){
|
84 |
+
editor.insertContent('[wpmem_profile]');
|
85 |
+
}
|
86 |
+
},
|
87 |
+
{
|
88 |
+
text: "|"
|
89 |
+
},
|
90 |
+
{
|
91 |
+
text: "Individual Components (optional):"
|
92 |
+
},
|
93 |
+
{
|
94 |
+
text: "Password Reset/Change",
|
95 |
+
onclick: function(){
|
96 |
+
editor.insertContent('[wpmem_form password]');
|
97 |
+
}
|
98 |
+
},
|
99 |
+
{
|
100 |
+
text: "Password Reset Only",
|
101 |
+
onclick: function(){
|
102 |
+
editor.insertContent('[wpmem_logged_out][wpmem_form password][/wpmem_logged_out]');
|
103 |
+
}
|
104 |
+
},
|
105 |
+
{
|
106 |
+
text: "Password Change Only",
|
107 |
+
onclick: function(){
|
108 |
+
editor.insertContent('[wpmem_logged_in][wpmem_form password][/wpmem_logged_in]');
|
109 |
+
}
|
110 |
+
},
|
111 |
+
{
|
112 |
+
text: "User Data Edit",
|
113 |
+
onclick: function(){
|
114 |
+
editor.insertContent('[wpmem_logged_in][wpmem_form user_edit][/wpmem_logged_in]');
|
115 |
+
}
|
116 |
+
},
|
117 |
+
{
|
118 |
+
text: "Forgot Username",
|
119 |
+
onclick: function(){
|
120 |
+
editor.insertContent('[wpmem_logged_out][wpmem_form forgot_username][/wpmem_logged_out]');
|
121 |
+
}
|
122 |
+
},
|
123 |
+
]
|
124 |
+
},
|
125 |
+
{
|
126 |
+
text: 'Content Restriction',
|
127 |
+
menu: [
|
128 |
+
{
|
129 |
+
text: "logged in content",
|
130 |
+
onclick: function(){
|
131 |
+
editor.insertContent('[wpmem_logged_in]<br />This displays when logged in<br />[/wpmem_logged_in]');
|
132 |
+
}
|
133 |
+
},
|
134 |
+
{
|
135 |
+
text: "logged out content",
|
136 |
+
onclick: function(){
|
137 |
+
editor.insertContent('[wpmem_logged_out]<br />This displays when logged out<br />[/wpmem_logged_out]');
|
138 |
+
}
|
139 |
+
},
|
140 |
+
]
|
141 |
+
},
|
142 |
+
{
|
143 |
+
text: 'Links',
|
144 |
+
menu: [
|
145 |
+
{
|
146 |
+
text: "log in/log out link",
|
147 |
+
onclick: function(){
|
148 |
+
editor.insertContent('[wpmem_loginout]');
|
149 |
+
}
|
150 |
+
},
|
151 |
+
{
|
152 |
+
text: "|"
|
153 |
+
},
|
154 |
+
{
|
155 |
+
text: "basic logout link",
|
156 |
+
onclick: function(){
|
157 |
+
editor.insertContent('[wpmem_logout]');
|
158 |
+
}
|
159 |
+
},
|
160 |
+
{
|
161 |
+
text: "logout link + custom link text",
|
162 |
+
onclick: function(){
|
163 |
+
editor.insertContent('[wpmem_logout]This the link text[/wpmem_logout]');
|
164 |
+
}
|
165 |
+
},
|
166 |
+
{
|
167 |
+
text: "|"
|
168 |
+
},
|
169 |
+
{
|
170 |
+
text: "log in link",
|
171 |
+
onclick: function(){
|
172 |
+
editor.insertContent('[wpmem_login_link]');
|
173 |
+
}
|
174 |
+
},
|
175 |
+
{
|
176 |
+
text: "log in link + custom link text",
|
177 |
+
onclick: function(){
|
178 |
+
editor.insertContent('[wpmem_login_link]Link Text[/wpmem_login_link]');
|
179 |
+
}
|
180 |
+
},
|
181 |
+
{
|
182 |
+
text: "|"
|
183 |
+
},
|
184 |
+
{
|
185 |
+
text: "register link",
|
186 |
+
onclick: function(){
|
187 |
+
editor.insertContent('[wpmem_reg_link]');
|
188 |
+
}
|
189 |
+
},
|
190 |
+
{
|
191 |
+
text: "register link + custom link text",
|
192 |
+
onclick: function(){
|
193 |
+
editor.insertContent('[wpmem_reg_link]Link Text[/wpmem_reg_link]');
|
194 |
+
}
|
195 |
+
}
|
196 |
+
]
|
197 |
+
},
|
198 |
+
{
|
199 |
+
text: 'User Fields',
|
200 |
+
onclick: function(){
|
201 |
+
editor.insertContent('[wpmem_field field=user_login]');
|
202 |
+
}
|
203 |
+
},
|
204 |
+
{
|
205 |
+
text: 'User Count',
|
206 |
+
onclick: function(){
|
207 |
+
editor.insertContent('[wpmem_show_count label="Active Users: " key=active value=1]');
|
208 |
+
}
|
209 |
+
},
|
210 |
+
{
|
211 |
+
text: 'User Avatar',
|
212 |
+
onclick: function(){
|
213 |
+
editor.insertContent('[wpmem_avatar]');
|
214 |
+
}
|
215 |
+
},
|
216 |
+
]
|
217 |
+
}
|
218 |
+
});
|
219 |
+
};
|
220 |
+
|
221 |
+
tinymce.PluginManager.add( "wpmem_shortcodes", wcShortcodeManager );
|
222 |
+
})();
|
assets/js/shortcodes_tinymce.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
!function(){"use strict";tinymce.PluginManager.add("wpmem_shortcodes",function(t,e){t.addButton("wpmem_shortcodes_button",function(){return{title:"WP-Members Shortcodes",tooltip:"WP-Members Shortcodes",icon:"user",type:"menubutton",icons:!1,menu:[{text:"WP-Members Shortcodes"},{text:"Login Forms",menu:[{text:"basic login",onclick:function(){t.insertContent("[wpmem_form login]")}},{text:"login + redirect",onclick:function(){t.insertContent('[wpmem_form login redirect_to="https://mysite.com/my-page/"]')}},{text:"login + logged in content",onclick:function(){t.insertContent("[wpmem_form login]<br />This displays when logged in<br />[/wpmem_form]")}},{text:"login + redirect + content",onclick:function(){t.insertContent('[wpmem_form login redirect_to="https://mysite.com/my-page/"]<br />This displays when logged in<br />[/wpmem_form]')}}]},{text:"Registration Forms",menu:[{text:"basic registration",onclick:function(){t.insertContent("[wpmem_form register]")}},{text:"registration + redirect",onclick:function(){t.insertContent('[wpmem_form register redirect_to="https://mysite.com/my-page/"]')}},{text:"registration + logged in content",onclick:function(){t.insertContent("[wpmem_form register]<br />This displays when logged in<br />[/wpmem_form]")}},{text:"registration + redirect + content",onclick:function(){t.insertContent('[wpmem_form register redirect_to="https://mysite.com/my-page/"]<br />This displays when logged in<br />[/wpmem_form]')}}]},{text:"User Profile",menu:[{text:"User Profile Page",onclick:function(){t.insertContent("[wpmem_profile]")}},{text:"|"},{text:"Individual Components (optional):"},{text:"Password Reset/Change",onclick:function(){t.insertContent("[wpmem_form password]")}},{text:"Password Reset Only",onclick:function(){t.insertContent("[wpmem_logged_out][wpmem_form password][/wpmem_logged_out]")}},{text:"Password Change Only",onclick:function(){t.insertContent("[wpmem_logged_in][wpmem_form password][/wpmem_logged_in]")}},{text:"User Data Edit",onclick:function(){t.insertContent("[wpmem_logged_in][wpmem_form user_edit][/wpmem_logged_in]")}},{text:"Forgot Username",onclick:function(){t.insertContent("[wpmem_logged_out][wpmem_form forgot_username][/wpmem_logged_out]")}}]},{text:"Content Restriction",menu:[{text:"logged in content",onclick:function(){t.insertContent("[wpmem_logged_in]<br />This displays when logged in<br />[/wpmem_logged_in]")}},{text:"logged out content",onclick:function(){t.insertContent("[wpmem_logged_out]<br />This displays when logged out<br />[/wpmem_logged_out]")}}]},{text:"Links",menu:[{text:"log in/log out link",onclick:function(){t.insertContent("[wpmem_loginout]")}},{text:"|"},{text:"basic logout link",onclick:function(){t.insertContent("[wpmem_logout]")}},{text:"logout link + custom link text",onclick:function(){t.insertContent("[wpmem_logout]This the link text[/wpmem_logout]")}},{text:"|"},{text:"log in link",onclick:function(){t.insertContent("[wpmem_login_link]")}},{text:"log in link + custom link text",onclick:function(){t.insertContent("[wpmem_login_link]Link Text[/wpmem_login_link]")}},{text:"|"},{text:"register link",onclick:function(){t.insertContent("[wpmem_reg_link]")}},{text:"register link + custom link text",onclick:function(){t.insertContent("[wpmem_reg_link]Link Text[/wpmem_reg_link]")}}]},{text:"User Fields",onclick:function(){t.insertContent("[wpmem_field field=user_login]")}},{text:"User Count",onclick:function(){t.insertContent('[wpmem_show_count label="Active Users: " key=active value=1]')}},{text:"User Avatar",onclick:function(){t.insertContent("[wpmem_avatar]")}}]}})})}();
|
inc/dialogs.php
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Included for legacy reasons: backward compatibility with
|
4 |
-
* WP-Members
|
5 |
-
*
|
6 |
-
* this file causes a PHP notice for
|
|
|
7 |
*
|
8 |
* Remove later.
|
9 |
*/
|
1 |
<?php
|
2 |
/**
|
3 |
* Included for legacy reasons: backward compatibility with
|
4 |
+
* older WP-Members extensions and custom snippets. Those
|
5 |
+
* will actually still work, and there is no front end issue,
|
6 |
+
* but removing this file causes a PHP error notice for
|
7 |
+
* certain configurations.
|
8 |
*
|
9 |
* Remove later.
|
10 |
*/
|
inc/email.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Included for legacy reasons: backward compatibility with
|
4 |
+
* older WP-Members extensions and custom snippets. Those
|
5 |
+
* will actually still work, and there is no front end issue,
|
6 |
+
* but removing this file causes a PHP error notice for
|
7 |
+
* certain configurations.
|
8 |
+
*
|
9 |
+
* Remove later.
|
10 |
+
*/
|
includes/admin/admin.php
CHANGED
@@ -1,144 +1,144 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members Admin Functions
|
4 |
-
*
|
5 |
-
* Functions to manage administration.
|
6 |
-
*
|
7 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
-
* Copyright (c) 2006-
|
10 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
-
*
|
12 |
-
* @package WP-Members
|
13 |
-
* @author Chad Butler
|
14 |
-
* @copyright 2006-
|
15 |
-
*
|
16 |
-
* Functions included:
|
17 |
-
* - wpmem_admin
|
18 |
-
* - wpmem_admin_do_tab
|
19 |
-
* - wpmem_admin_tabs
|
20 |
-
* - wpmem_admin_action
|
21 |
-
* - wpmem_admin_add_new_user
|
22 |
-
*/
|
23 |
-
|
24 |
-
// Exit if accessed directly.
|
25 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
26 |
-
exit();
|
27 |
-
}
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Primary admin function.
|
31 |
-
*
|
32 |
-
* @since 2.1.0
|
33 |
-
* @since 3.1.0 Added WP_Members_Admin_API.
|
34 |
-
*
|
35 |
-
* @global object $wpmem The WP_Members object.
|
36 |
-
*/
|
37 |
-
function wpmem_admin() {
|
38 |
-
|
39 |
-
$did_update = ( isset( $_POST['wpmem_admin_a'] ) ) ? wpmem_admin_action( sanitize_text_field( $_POST['wpmem_admin_a'] ) ) : false;
|
40 |
-
|
41 |
-
global $wpmem;
|
42 |
-
|
43 |
-
if ( $wpmem->captcha ) {
|
44 |
-
add_filter( 'wpmem_admin_tabs', array( 'WP_Members_Admin_Tab_Captcha', 'add_tab' ) );
|
45 |
-
add_action( 'wpmem_admin_do_tab', array( 'WP_Members_Admin_Tab_Captcha', 'do_tab' ), 1, 1 );
|
46 |
-
}
|
47 |
-
if ( $wpmem->dropins ) {
|
48 |
-
add_filter( 'wpmem_admin_tabs', array( 'WP_Members_Admin_Tab_Dropins', 'add_tab' ) );
|
49 |
-
add_action( 'wpmem_admin_do_tab', array( 'WP_Members_Admin_Tab_Dropins', 'do_tab' ), 1, 1 );
|
50 |
-
} ?>
|
51 |
-
|
52 |
-
<div class="wrap">
|
53 |
-
<?php
|
54 |
-
$tab = sanitize_text_field( wpmem_get( 'tab', 'options', 'get' ) );
|
55 |
-
|
56 |
-
// Render the tab being displayed.
|
57 |
-
$wpmem->admin->do_tabs( $tab );
|
58 |
-
|
59 |
-
// Render any warning messages.
|
60 |
-
wpmem_a_do_warnings( $did_update );
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Fires at the end of creating an admin panel tab.
|
64 |
-
*
|
65 |
-
* This action is part of the plugin's admin panel API for adding
|
66 |
-
* additional admin tabs. This action is for adding content for
|
67 |
-
* a custom tab.
|
68 |
-
*
|
69 |
-
* @since 2.8.0
|
70 |
-
*
|
71 |
-
* @param string $tab The tab being generated.
|
72 |
-
*/
|
73 |
-
do_action( 'wpmem_admin_do_tab', $tab );
|
74 |
-
?>
|
75 |
-
</div><!-- .wrap --><?php
|
76 |
-
|
77 |
-
return;
|
78 |
-
}
|
79 |
-
|
80 |
-
|
81 |
-
/**
|
82 |
-
* Handles the various update actions for the default tabs.
|
83 |
-
*
|
84 |
-
* @since 2.8.0
|
85 |
-
*
|
86 |
-
* @param string $action The action that is being done.
|
87 |
-
* @return string $did_update The update message result.
|
88 |
-
*/
|
89 |
-
function wpmem_admin_action( $action ) {
|
90 |
-
|
91 |
-
$did_update = ''; // makes sure $did_update is defined
|
92 |
-
switch ( $action ) {
|
93 |
-
|
94 |
-
case 'update_settings':
|
95 |
-
case 'update_cpts':
|
96 |
-
$did_update = WP_Members_Admin_Tab_Options::update( $action );
|
97 |
-
break;
|
98 |
-
|
99 |
-
case 'update_dialogs':
|
100 |
-
$did_update = WP_Members_Admin_Tab_Dialogs::update();
|
101 |
-
break;
|
102 |
-
|
103 |
-
case 'update_emails':
|
104 |
-
$did_update = WP_Members_Admin_Tab_Emails::update();
|
105 |
-
break;
|
106 |
-
|
107 |
-
case 'update_captcha':
|
108 |
-
$did_update = WP_Members_Admin_Tab_Captcha::update();
|
109 |
-
break;
|
110 |
-
}
|
111 |
-
|
112 |
-
return $did_update;
|
113 |
-
}
|
114 |
-
|
115 |
-
|
116 |
-
/**
|
117 |
-
* Adds WP-Members custom fields to the WP Add New User form.
|
118 |
-
*
|
119 |
-
* @since 2.9.1
|
120 |
-
*
|
121 |
-
* @global stdClass $wpmem
|
122 |
-
*/
|
123 |
-
function wpmem_admin_add_new_user() {
|
124 |
-
global $wpmem;
|
125 |
-
// Output the custom registration fields.
|
126 |
-
echo $wpmem->forms->wp_newuser_form();
|
127 |
-
return;
|
128 |
-
}
|
129 |
-
|
130 |
-
/**
|
131 |
-
* Wrapper for WP_Members_Admin_Tab_Options::page_list()
|
132 |
-
*
|
133 |
-
* This function gets used by extensions outside of WP-Members, so it needs to stay (for now).
|
134 |
-
*
|
135 |
-
* @since 3.3.0
|
136 |
-
*
|
137 |
-
* @param string $val
|
138 |
-
* @param boolean $show_custom_url
|
139 |
-
*/
|
140 |
-
function wpmem_admin_page_list( $val, $show_custom_url = true ) {
|
141 |
-
return WP_Members_Admin_Tab_Options::page_list( $val, $show_custom_url );
|
142 |
-
}
|
143 |
-
|
144 |
// End of File.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members Admin Functions
|
4 |
+
*
|
5 |
+
* Functions to manage administration.
|
6 |
+
*
|
7 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
+
* Copyright (c) 2006-2020 Chad Butler
|
10 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
+
*
|
12 |
+
* @package WP-Members
|
13 |
+
* @author Chad Butler
|
14 |
+
* @copyright 2006-2020
|
15 |
+
*
|
16 |
+
* Functions included:
|
17 |
+
* - wpmem_admin
|
18 |
+
* - wpmem_admin_do_tab
|
19 |
+
* - wpmem_admin_tabs
|
20 |
+
* - wpmem_admin_action
|
21 |
+
* - wpmem_admin_add_new_user
|
22 |
+
*/
|
23 |
+
|
24 |
+
// Exit if accessed directly.
|
25 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
26 |
+
exit();
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Primary admin function.
|
31 |
+
*
|
32 |
+
* @since 2.1.0
|
33 |
+
* @since 3.1.0 Added WP_Members_Admin_API.
|
34 |
+
*
|
35 |
+
* @global object $wpmem The WP_Members object.
|
36 |
+
*/
|
37 |
+
function wpmem_admin() {
|
38 |
+
|
39 |
+
$did_update = ( isset( $_POST['wpmem_admin_a'] ) ) ? wpmem_admin_action( sanitize_text_field( $_POST['wpmem_admin_a'] ) ) : false;
|
40 |
+
|
41 |
+
global $wpmem;
|
42 |
+
|
43 |
+
if ( $wpmem->captcha ) {
|
44 |
+
add_filter( 'wpmem_admin_tabs', array( 'WP_Members_Admin_Tab_Captcha', 'add_tab' ) );
|
45 |
+
add_action( 'wpmem_admin_do_tab', array( 'WP_Members_Admin_Tab_Captcha', 'do_tab' ), 1, 1 );
|
46 |
+
}
|
47 |
+
if ( $wpmem->dropins ) {
|
48 |
+
add_filter( 'wpmem_admin_tabs', array( 'WP_Members_Admin_Tab_Dropins', 'add_tab' ) );
|
49 |
+
add_action( 'wpmem_admin_do_tab', array( 'WP_Members_Admin_Tab_Dropins', 'do_tab' ), 1, 1 );
|
50 |
+
} ?>
|
51 |
+
|
52 |
+
<div class="wrap">
|
53 |
+
<?php
|
54 |
+
$tab = sanitize_text_field( wpmem_get( 'tab', 'options', 'get' ) );
|
55 |
+
|
56 |
+
// Render the tab being displayed.
|
57 |
+
$wpmem->admin->do_tabs( $tab );
|
58 |
+
|
59 |
+
// Render any warning messages.
|
60 |
+
wpmem_a_do_warnings( $did_update );
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Fires at the end of creating an admin panel tab.
|
64 |
+
*
|
65 |
+
* This action is part of the plugin's admin panel API for adding
|
66 |
+
* additional admin tabs. This action is for adding content for
|
67 |
+
* a custom tab.
|
68 |
+
*
|
69 |
+
* @since 2.8.0
|
70 |
+
*
|
71 |
+
* @param string $tab The tab being generated.
|
72 |
+
*/
|
73 |
+
do_action( 'wpmem_admin_do_tab', $tab );
|
74 |
+
?>
|
75 |
+
</div><!-- .wrap --><?php
|
76 |
+
|
77 |
+
return;
|
78 |
+
}
|
79 |
+
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Handles the various update actions for the default tabs.
|
83 |
+
*
|
84 |
+
* @since 2.8.0
|
85 |
+
*
|
86 |
+
* @param string $action The action that is being done.
|
87 |
+
* @return string $did_update The update message result.
|
88 |
+
*/
|
89 |
+
function wpmem_admin_action( $action ) {
|
90 |
+
|
91 |
+
$did_update = ''; // makes sure $did_update is defined
|
92 |
+
switch ( $action ) {
|
93 |
+
|
94 |
+
case 'update_settings':
|
95 |
+
case 'update_cpts':
|
96 |
+
$did_update = WP_Members_Admin_Tab_Options::update( $action );
|
97 |
+
break;
|
98 |
+
|
99 |
+
case 'update_dialogs':
|
100 |
+
$did_update = WP_Members_Admin_Tab_Dialogs::update();
|
101 |
+
break;
|
102 |
+
|
103 |
+
case 'update_emails':
|
104 |
+
$did_update = WP_Members_Admin_Tab_Emails::update();
|
105 |
+
break;
|
106 |
+
|
107 |
+
case 'update_captcha':
|
108 |
+
$did_update = WP_Members_Admin_Tab_Captcha::update();
|
109 |
+
break;
|
110 |
+
}
|
111 |
+
|
112 |
+
return $did_update;
|
113 |
+
}
|
114 |
+
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Adds WP-Members custom fields to the WP Add New User form.
|
118 |
+
*
|
119 |
+
* @since 2.9.1
|
120 |
+
*
|
121 |
+
* @global stdClass $wpmem
|
122 |
+
*/
|
123 |
+
function wpmem_admin_add_new_user() {
|
124 |
+
global $wpmem;
|
125 |
+
// Output the custom registration fields.
|
126 |
+
echo $wpmem->forms->wp_newuser_form();
|
127 |
+
return;
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Wrapper for WP_Members_Admin_Tab_Options::page_list()
|
132 |
+
*
|
133 |
+
* This function gets used by extensions outside of WP-Members, so it needs to stay (for now).
|
134 |
+
*
|
135 |
+
* @since 3.3.0
|
136 |
+
*
|
137 |
+
* @param string $val
|
138 |
+
* @param boolean $show_custom_url
|
139 |
+
*/
|
140 |
+
function wpmem_admin_page_list( $val, $show_custom_url = true ) {
|
141 |
+
return WP_Members_Admin_Tab_Options::page_list( $val, $show_custom_url );
|
142 |
+
}
|
143 |
+
|
144 |
// End of File.
|
includes/admin/api.php
CHANGED
@@ -1,117 +1,117 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members Admin API Functions
|
4 |
-
*
|
5 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
-
* Copyright (c) 2006-
|
8 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
-
*
|
10 |
-
* @package WP-Members
|
11 |
-
* @author Chad Butler
|
12 |
-
* @copyright 2006-
|
13 |
-
*
|
14 |
-
* Functions included:
|
15 |
-
* - wpmem_add_custom_email
|
16 |
-
* - wpmem_add_custom_dialog
|
17 |
-
* - wpmem_is_tab
|
18 |
-
*/
|
19 |
-
|
20 |
-
// Exit if accessed directly.
|
21 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
22 |
-
exit();
|
23 |
-
}
|
24 |
-
|
25 |
-
/**
|
26 |
-
* Wrapper function for adding custom emails.
|
27 |
-
*
|
28 |
-
* @since 3.1.1
|
29 |
-
*
|
30 |
-
* @global object $wpmem The WP_Members object class.
|
31 |
-
* @param string $tag Slug for the custom email.
|
32 |
-
* @param string $heading Heading to display in admin panel.
|
33 |
-
* @param string $subject_input Slug for the subject.
|
34 |
-
* @param string $message_input Slug for the message body.
|
35 |
-
*/
|
36 |
-
function wpmem_add_custom_email( $tag, $heading, $subject_input, $message_input ) {
|
37 |
-
global $wpmem;
|
38 |
-
$args = array(
|
39 |
-
'name' => $tag,
|
40 |
-
'heading' => $heading,
|
41 |
-
'subject_input' => $subject_input,
|
42 |
-
'body_input' => $message_input,
|
43 |
-
);
|
44 |
-
$wpmem->admin->add_email( $args );
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Checks the current tab being displayed in the admin panel.
|
49 |
-
*
|
50 |
-
* @since 3.1.4
|
51 |
-
*
|
52 |
-
* @param string $tab The tab slug.
|
53 |
-
* @return bool
|
54 |
-
*/
|
55 |
-
function wpmem_is_tab( $tab ) {
|
56 |
-
return ( $tab == wpmem_get( 'tab', false, 'get' ) ) ? true : false;
|
57 |
-
}
|
58 |
-
|
59 |
-
/**
|
60 |
-
* Utility function generates link to user profile.
|
61 |
-
*
|
62 |
-
* @since 3.1.7
|
63 |
-
*
|
64 |
-
* @param int $user_id
|
65 |
-
* @return string user profile URL.
|
66 |
-
*/
|
67 |
-
function wpmem_admin_user_profile( $user_id ) {
|
68 |
-
return add_query_arg( 'user_id', $user_id, admin_url( 'user-edit.php' ) );
|
69 |
-
}
|
70 |
-
|
71 |
-
/**
|
72 |
-
* Wrapper for form_post_url().
|
73 |
-
*
|
74 |
-
* @since 3.1.8
|
75 |
-
*
|
76 |
-
* @global object $wpmem The WP_Members Object.
|
77 |
-
* @param string $tab The plugin tab being displayed.
|
78 |
-
* @param mixed $args Array of additional arguments|boolean. Default: false.
|
79 |
-
* @return string $url
|
80 |
-
*/
|
81 |
-
function wpmem_admin_form_post_url( $args = false ) {
|
82 |
-
global $wpmem;
|
83 |
-
return $wpmem->admin->form_post_url( $args );
|
84 |
-
}
|
85 |
-
|
86 |
-
/**
|
87 |
-
* Returns an array of WordPress reserved terms.
|
88 |
-
*
|
89 |
-
* @since 3.0.2
|
90 |
-
* @since 3.2.3 Moved to Admin API as wrapper for WP_Members_Admin_API::wp_reserved_terms().
|
91 |
-
*
|
92 |
-
* @global object $wpmem
|
93 |
-
* @return array An array of WordPress reserved terms.
|
94 |
-
*/
|
95 |
-
function wpmem_wp_reserved_terms() {
|
96 |
-
global $wpmem;
|
97 |
-
return $wpmem->admin->wp_reserved_terms();
|
98 |
-
}
|
99 |
-
|
100 |
-
/**
|
101 |
-
* Export all or selected users
|
102 |
-
*
|
103 |
-
* @since 2.9.7
|
104 |
-
* @since 3.2.0 Updated to use fputcsv.
|
105 |
-
* @since 3.2.1 Added user data filters.
|
106 |
-
* @since 3.3.0 Call object class static method.
|
107 |
-
*
|
108 |
-
* @global object $wpmem
|
109 |
-
*
|
110 |
-
* @param array $args
|
111 |
-
* @param array $users
|
112 |
-
*/
|
113 |
-
function wpmem_export_users( $args, $users = null ) {
|
114 |
-
global $wpmem;
|
115 |
-
include_once( $wpmem->path . 'includes/admin/class-wp-members-export.php' );
|
116 |
-
WP_Members_Export::export_users( $args, $users );
|
117 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members Admin API Functions
|
4 |
+
*
|
5 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
+
* Copyright (c) 2006-2020 Chad Butler
|
8 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
+
*
|
10 |
+
* @package WP-Members
|
11 |
+
* @author Chad Butler
|
12 |
+
* @copyright 2006-2020
|
13 |
+
*
|
14 |
+
* Functions included:
|
15 |
+
* - wpmem_add_custom_email
|
16 |
+
* - wpmem_add_custom_dialog
|
17 |
+
* - wpmem_is_tab
|
18 |
+
*/
|
19 |
+
|
20 |
+
// Exit if accessed directly.
|
21 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
22 |
+
exit();
|
23 |
+
}
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Wrapper function for adding custom emails.
|
27 |
+
*
|
28 |
+
* @since 3.1.1
|
29 |
+
*
|
30 |
+
* @global object $wpmem The WP_Members object class.
|
31 |
+
* @param string $tag Slug for the custom email.
|
32 |
+
* @param string $heading Heading to display in admin panel.
|
33 |
+
* @param string $subject_input Slug for the subject.
|
34 |
+
* @param string $message_input Slug for the message body.
|
35 |
+
*/
|
36 |
+
function wpmem_add_custom_email( $tag, $heading, $subject_input, $message_input ) {
|
37 |
+
global $wpmem;
|
38 |
+
$args = array(
|
39 |
+
'name' => $tag,
|
40 |
+
'heading' => $heading,
|
41 |
+
'subject_input' => $subject_input,
|
42 |
+
'body_input' => $message_input,
|
43 |
+
);
|
44 |
+
$wpmem->admin->add_email( $args );
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Checks the current tab being displayed in the admin panel.
|
49 |
+
*
|
50 |
+
* @since 3.1.4
|
51 |
+
*
|
52 |
+
* @param string $tab The tab slug.
|
53 |
+
* @return bool
|
54 |
+
*/
|
55 |
+
function wpmem_is_tab( $tab ) {
|
56 |
+
return ( $tab == wpmem_get( 'tab', false, 'get' ) ) ? true : false;
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Utility function generates link to user profile.
|
61 |
+
*
|
62 |
+
* @since 3.1.7
|
63 |
+
*
|
64 |
+
* @param int $user_id
|
65 |
+
* @return string user profile URL.
|
66 |
+
*/
|
67 |
+
function wpmem_admin_user_profile( $user_id ) {
|
68 |
+
return add_query_arg( 'user_id', $user_id, admin_url( 'user-edit.php' ) );
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Wrapper for form_post_url().
|
73 |
+
*
|
74 |
+
* @since 3.1.8
|
75 |
+
*
|
76 |
+
* @global object $wpmem The WP_Members Object.
|
77 |
+
* @param string $tab The plugin tab being displayed.
|
78 |
+
* @param mixed $args Array of additional arguments|boolean. Default: false.
|
79 |
+
* @return string $url
|
80 |
+
*/
|
81 |
+
function wpmem_admin_form_post_url( $args = false ) {
|
82 |
+
global $wpmem;
|
83 |
+
return $wpmem->admin->form_post_url( $args );
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Returns an array of WordPress reserved terms.
|
88 |
+
*
|
89 |
+
* @since 3.0.2
|
90 |
+
* @since 3.2.3 Moved to Admin API as wrapper for WP_Members_Admin_API::wp_reserved_terms().
|
91 |
+
*
|
92 |
+
* @global object $wpmem
|
93 |
+
* @return array An array of WordPress reserved terms.
|
94 |
+
*/
|
95 |
+
function wpmem_wp_reserved_terms() {
|
96 |
+
global $wpmem;
|
97 |
+
return $wpmem->admin->wp_reserved_terms();
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Export all or selected users
|
102 |
+
*
|
103 |
+
* @since 2.9.7
|
104 |
+
* @since 3.2.0 Updated to use fputcsv.
|
105 |
+
* @since 3.2.1 Added user data filters.
|
106 |
+
* @since 3.3.0 Call object class static method.
|
107 |
+
*
|
108 |
+
* @global object $wpmem
|
109 |
+
*
|
110 |
+
* @param array $args
|
111 |
+
* @param array $users
|
112 |
+
*/
|
113 |
+
function wpmem_export_users( $args, $users = null ) {
|
114 |
+
global $wpmem;
|
115 |
+
include_once( $wpmem->path . 'includes/admin/class-wp-members-export.php' );
|
116 |
+
WP_Members_Export::export_users( $args, $users );
|
117 |
}
|
includes/admin/class-wp-members-admin-api.php
CHANGED
@@ -169,6 +169,8 @@ class WP_Members_Admin_API {
|
|
169 |
add_action( 'admin_footer-edit.php', array( 'WP_Members_Admin_Posts', 'bulk_action' ) );
|
170 |
add_action( 'load-edit.php', array( 'WP_Members_Admin_Posts', 'page_load' ) );
|
171 |
add_action( 'admin_notices', array( 'WP_Members_Admin_Posts', 'notices' ) );
|
|
|
|
|
172 |
}
|
173 |
|
174 |
if ( ! is_multisite() && current_user_can( 'manage_options' ) ) {
|
169 |
add_action( 'admin_footer-edit.php', array( 'WP_Members_Admin_Posts', 'bulk_action' ) );
|
170 |
add_action( 'load-edit.php', array( 'WP_Members_Admin_Posts', 'page_load' ) );
|
171 |
add_action( 'admin_notices', array( 'WP_Members_Admin_Posts', 'notices' ) );
|
172 |
+
add_action( 'load-post.php', array( 'WP_Members_Admin_Posts', 'load_tinymce' ) );
|
173 |
+
add_action( 'load-post-new.php', array( 'WP_Members_Admin_Posts', 'load_tinymce' ) );
|
174 |
}
|
175 |
|
176 |
if ( ! is_multisite() && current_user_can( 'manage_options' ) ) {
|
includes/admin/class-wp-members-admin-posts.php
CHANGED
@@ -388,4 +388,19 @@ class WP_Members_Admin_Posts {
|
|
388 |
}
|
389 |
}
|
390 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
391 |
}
|
388 |
}
|
389 |
}
|
390 |
|
391 |
+
/**
|
392 |
+
* Adds shortcode dropdown to post editor tinymce.
|
393 |
+
*
|
394 |
+
* @since 3.0
|
395 |
+
* @since 3.3.2 Added to posts class as static
|
396 |
+
*
|
397 |
+
* @global object $wpmem_shortcode The WP_Members_TinyMCE_Buttons object.
|
398 |
+
*/
|
399 |
+
static function load_tinymce() {
|
400 |
+
if ( version_compare( get_bloginfo( 'version' ), '3.9', '>=' ) ) {
|
401 |
+
global $wpmem, $wpmem_shortcode;
|
402 |
+
include( $wpmem->path . 'includes/admin/class-wp-members-tinymce-buttons.php' );
|
403 |
+
$wpmem_shortcode = new WP_Members_TinyMCE_Buttons;
|
404 |
+
}
|
405 |
+
}
|
406 |
}
|
includes/admin/class-wp-members-admin-users.php
CHANGED
@@ -317,8 +317,8 @@ class WP_Members_Admin_Users {
|
|
317 |
* @type string The HTML for the view.
|
318 |
* }
|
319 |
*/
|
320 |
-
$views = apply_filters( 'wpmem_views_users', $views );
|
321 |
-
|
322 |
return $views;
|
323 |
}
|
324 |
|
@@ -459,7 +459,14 @@ class WP_Members_Admin_Users {
|
|
459 |
|
460 |
$query_where = str_replace( 'WHERE 1=1', $replace_query, $user_search->query_where );
|
461 |
|
462 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
463 |
|
464 |
$user_search->query_where = $query_where;
|
465 |
}
|
317 |
* @type string The HTML for the view.
|
318 |
* }
|
319 |
*/
|
320 |
+
$views = apply_filters( 'wpmem_views_users', $views, $show );
|
321 |
+
|
322 |
return $views;
|
323 |
}
|
324 |
|
459 |
|
460 |
$query_where = str_replace( 'WHERE 1=1', $replace_query, $user_search->query_where );
|
461 |
|
462 |
+
/**
|
463 |
+
* Filters the pre_user_query being applied.
|
464 |
+
*
|
465 |
+
* @since 3.3.0
|
466 |
+
*
|
467 |
+
* @param string $query_where
|
468 |
+
*/
|
469 |
+
$query_where = apply_filters( 'wpmem_query_where', $query_where, $show );
|
470 |
|
471 |
$user_search->query_where = $query_where;
|
472 |
}
|
includes/admin/class-wp-members-tinymce-buttons.php
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class to add WP-Members shortcodes to the post editor.
|
4 |
+
*
|
5 |
+
* @since 3.0
|
6 |
+
*/
|
7 |
+
|
8 |
+
// Exit if accessed directly.
|
9 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
10 |
+
exit();
|
11 |
+
}
|
12 |
+
|
13 |
+
class WP_Members_TinyMCE_Buttons {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Initialize WP-Members TinyMCE Button.
|
17 |
+
*
|
18 |
+
* @since 3.0
|
19 |
+
*/
|
20 |
+
function __construct() {
|
21 |
+
|
22 |
+
if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
|
23 |
+
return;
|
24 |
+
}
|
25 |
+
|
26 |
+
if ( get_user_option( 'rich_editing' ) == 'true' ) {
|
27 |
+
add_filter( 'mce_external_plugins', array( &$this, 'add_plugin' ) );
|
28 |
+
add_filter( 'mce_buttons', array( &$this, 'register_button' ) );
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Load the correct plugin file.
|
34 |
+
*
|
35 |
+
* @since 3.0
|
36 |
+
* @since 3.3.2 Added minified js.
|
37 |
+
*
|
38 |
+
* @global object $wpmem
|
39 |
+
* @param array $plugin_array
|
40 |
+
* @return array $plugin_array
|
41 |
+
*/
|
42 |
+
function add_plugin( $plugin_array ) {
|
43 |
+
|
44 |
+
global $wpmem;
|
45 |
+
|
46 |
+
if ( version_compare( get_bloginfo( 'version' ), '3.9', '>' ) ) {
|
47 |
+
$plugin_array['wpmem_shortcodes'] = $wpmem->url . 'assets/js/shortcodes_tinymce' . wpmem_get_suffix() . '.js?ver=' . $wpmem->version;
|
48 |
+
}
|
49 |
+
return $plugin_array;
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Register the button.
|
54 |
+
*
|
55 |
+
* @since 3.0
|
56 |
+
*
|
57 |
+
* @param array $buttons
|
58 |
+
* @return array $buttons
|
59 |
+
*/
|
60 |
+
function register_button( $buttons ) {
|
61 |
+
array_push( $buttons, "wpmem_shortcodes_button" );
|
62 |
+
return $buttons;
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
// End of File.
|
includes/admin/dialogs.php
CHANGED
@@ -1,258 +1,258 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members Admin Functions
|
4 |
-
*
|
5 |
-
* Handles functions that output admin dialogs to adminstrative users.
|
6 |
-
*
|
7 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
-
* Copyright (c) 2006-
|
10 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
-
*
|
12 |
-
* @package WP-Members
|
13 |
-
* @author Chad Butler
|
14 |
-
* @copyright 2006-
|
15 |
-
*
|
16 |
-
* Functions included:
|
17 |
-
* - wpmem_a_do_warnings
|
18 |
-
* - wpmem_a_warning_msg
|
19 |
-
* - wpmem_a_meta_box
|
20 |
-
* - wpmem_a_rss_box
|
21 |
-
* - butlerblog_dashboard_widget
|
22 |
-
* - butlerblog_feed_output
|
23 |
-
*/
|
24 |
-
|
25 |
-
// Exit if accessed directly.
|
26 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
27 |
-
exit();
|
28 |
-
}
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Outputs the various admin warning messages.
|
32 |
-
*
|
33 |
-
* @since 2.8.0
|
34 |
-
*
|
35 |
-
* @param string $did_update Contains the update message.
|
36 |
-
* @param array $wpmem_settings Array containing the plugin settings.
|
37 |
-
*/
|
38 |
-
function wpmem_a_do_warnings( $did_update ) {
|
39 |
-
|
40 |
-
global $wpmem;
|
41 |
-
|
42 |
-
/** This filter is documented in /includes/class-wp-members-admin-api.php */
|
43 |
-
$dialogs = apply_filters( 'wpmem_dialogs', get_option( 'wpmembers_dialogs' ) );
|
44 |
-
|
45 |
-
if ( $did_update != false ) {?>
|
46 |
-
<div id="message" class="updated fade"><p><strong><?php echo $did_update; ?></strong></p></div><?php
|
47 |
-
}
|
48 |
-
|
49 |
-
/*
|
50 |
-
* Warning messages
|
51 |
-
*/
|
52 |
-
|
53 |
-
// Are warnings turned off?
|
54 |
-
$warnings_on = ( $wpmem->warnings == 0 ) ? true : false;
|
55 |
-
|
56 |
-
// Is there an active warning?
|
57 |
-
$warning_active = false;
|
58 |
-
|
59 |
-
// Settings allow anyone to register.
|
60 |
-
if ( get_option( 'users_can_register' ) != 0 && $warnings_on ) {
|
61 |
-
wpmem_a_warning_msg( 'users_can_register' );
|
62 |
-
$warning_active = true;
|
63 |
-
}
|
64 |
-
|
65 |
-
// Settings allow anyone to comment.
|
66 |
-
if ( get_option( 'comment_registration' ) !=1 && $warnings_on ) {
|
67 |
-
wpmem_a_warning_msg( 'comment_registration' );
|
68 |
-
$warning_active = true;
|
69 |
-
}
|
70 |
-
|
71 |
-
// Rss set to full text feeds.
|
72 |
-
if ( get_option( 'rss_use_excerpt' ) !=1 && $warnings_on ) {
|
73 |
-
wpmem_a_warning_msg( 'rss_use_excerpt' );
|
74 |
-
$warning_active = true;
|
75 |
-
}
|
76 |
-
|
77 |
-
// Holding registrations but haven't changed default successful registration message.
|
78 |
-
if ( $warnings_on && $wpmem->mod_reg == 1 && $dialogs['success'] == $wpmem->get_text( 'success' ) ) {
|
79 |
-
wpmem_a_warning_msg( 'success' );
|
80 |
-
$warning_active = true;
|
81 |
-
}
|
82 |
-
|
83 |
-
// Haven't entered recaptcha api keys.
|
84 |
-
if ( $warnings_on && $wpmem->captcha > 0 ) {
|
85 |
-
$wpmem_captcha = get_option( 'wpmembers_captcha' );
|
86 |
-
if ( 1 == $wpmem->captcha || 3 == $wpmem->captcha ) {
|
87 |
-
if ( ! $wpmem_captcha['recaptcha']['public'] || ! $wpmem_captcha['recaptcha']['private'] ) {
|
88 |
-
wpmem_a_warning_msg( 'wpmembers_captcha' );
|
89 |
-
$warning_active = true;
|
90 |
-
}
|
91 |
-
}
|
92 |
-
}
|
93 |
-
|
94 |
-
// If there is an active warning, display message about warnings.
|
95 |
-
if ( $warning_active ) {
|
96 |
-
wpmem_a_warning_msg( 'warning_active' );
|
97 |
-
}
|
98 |
-
|
99 |
-
}
|
100 |
-
|
101 |
-
|
102 |
-
/**
|
103 |
-
* Assembles the various admin warning messages.
|
104 |
-
*
|
105 |
-
* @since 2.4.0
|
106 |
-
* @since 3.1.0 Changed $msg argument to string.
|
107 |
-
*
|
108 |
-
* @param string $msg The number for which message should be displayed.
|
109 |
-
*/
|
110 |
-
function wpmem_a_warning_msg( $msg ) {
|
111 |
-
|
112 |
-
$strong_msg = $remain_msg = $span_msg = '';
|
113 |
-
|
114 |
-
switch ( $msg ) {
|
115 |
-
|
116 |
-
case 'users_can_register':
|
117 |
-
$strong_msg = __( 'Your WP settings allow anyone to register - this is not the recommended setting.', 'wp-members' );
|
118 |
-
$remain_msg = sprintf( __( 'You can %s change this here %s making sure the box next to "Anyone can register" is unchecked.', 'wp-members'), '<a href="options-general.php">', '</a>' );
|
119 |
-
$span_msg = __( 'This setting allows a link on the /wp-login.php page to register using the WP native registration process thus circumventing any registration you are using with WP-Members. In some cases, this may suit the users wants/needs, but most users should uncheck this option. If you do not change this setting, you can choose to ignore these warning messages under WP-Members Settings.', 'wp-members' );
|
120 |
-
break;
|
121 |
-
|
122 |
-
case 'comment_registration':
|
123 |
-
$strong_msg = __( 'Your WP settings allow anyone to comment - this is not the recommended setting.', 'wp-members' );
|
124 |
-
$remain_msg = sprintf( __( 'You can %s change this here %s by checking the box next to "Users must be registered and logged in to comment."', 'wp-members' ), '<a href="options-discussion.php">', '</a>' );
|
125 |
-
$span_msg = __( 'This setting allows any users to comment, whether or not they are registered. Depending on how you are using WP-Members will determine whether you should change this setting or not. If you do not change this setting, you can choose to ignore these warning messages under WP-Members Settings.', 'wp-members' );
|
126 |
-
break;
|
127 |
-
|
128 |
-
case 'rss_use_excerpt':
|
129 |
-
$strong_msg = __( 'Your WP settings allow full text rss feeds - this is not the recommended setting.', 'wp-members' );
|
130 |
-
$remain_msg = sprintf( __( 'You can %s change this here %s by changing "For each article in a feed, show" to "Summary."', 'wp-members' ), '<a href="options-reading.php">' , '</a>' );
|
131 |
-
$span_msg = __( 'Leaving this set to full text allows anyone to read your protected content in an RSS reader. Changing this to Summary prevents this as your feeds will only show summary text.', 'wp-members' );
|
132 |
-
break;
|
133 |
-
|
134 |
-
case 'success':
|
135 |
-
$strong_msg = __( 'You have set WP-Members to hold registrations for approval', 'wp-members' );
|
136 |
-
$remain_msg = __( 'but you have not changed the default message for "Registration Completed" under "WP-Members Dialogs and Error Messages." You should change this message to let users know they are pending approval.', 'wp-members' );
|
137 |
-
break;
|
138 |
-
|
139 |
-
case 'wpmembers_captcha':
|
140 |
-
$strong_msg = __( 'You have turned on reCAPTCHA', 'wp-members');
|
141 |
-
$remain_msg = __( 'but you have not entered API keys. You will need both a public and private key. The CAPTCHA will not display unless a valid API key is included.', 'wp-members' );
|
142 |
-
break;
|
143 |
-
|
144 |
-
case 'warning_active':
|
145 |
-
$strong_msg = __( 'You have active settings that are not recommended.', 'wp-members' );
|
146 |
-
$remain_msg = __( 'If you will not be changing these settings, you can turn off these warning messages by checking the "Ignore warning messages" in the settings below.', 'wp-members' );
|
147 |
-
break;
|
148 |
-
|
149 |
-
}
|
150 |
-
|
151 |
-
if ( $span_msg ) {
|
152 |
-
$span_msg = ' [<span title="' . $span_msg . '">why is this?</span>]';
|
153 |
-
}
|
154 |
-
echo '<div class="error"><p><strong>' . $strong_msg . '</strong> ' . $remain_msg . $span_msg . '</p></div>';
|
155 |
-
|
156 |
-
}
|
157 |
-
|
158 |
-
|
159 |
-
/**
|
160 |
-
* Assemble the side meta box.
|
161 |
-
*
|
162 |
-
* @since 2.8.0
|
163 |
-
*
|
164 |
-
* @global object $wpmem
|
165 |
-
*/
|
166 |
-
function wpmem_a_meta_box() {
|
167 |
-
|
168 |
-
global $wpmem;
|
169 |
-
|
170 |
-
?><div class="postbox">
|
171 |
-
<h3><span>WP-Members Information</span></h3>
|
172 |
-
<div class="inside">
|
173 |
-
|
174 |
-
<p><strong><?php _e( 'Version:', 'wp-members' ); echo " " . $wpmem->version; ?></strong><br />
|
175 |
-
<a href="https://rocketgeek.com/plugins/wp-members/quick-start-guide/"><?php _e( 'Quick Start Guide', 'wp-members' ); ?></a><br />
|
176 |
-
<a href="https://rocketgeek.com/plugins/wp-members/users-guide/"><?php _e( 'Online User Guide', 'wp-members' ); ?></a><br />
|
177 |
-
<a href="https://rocketgeek.com/plugins/wp-members/users-guide/faqs/"><?php _e( 'FAQs', 'wp-members' ); ?></a>
|
178 |
-
<?php if( ! defined( 'WPMEM_REMOVE_ATTR' ) ) { ?>
|
179 |
-
<br /><br /><a href="https://rocketgeek.com/about/site-membership-subscription/">Find out how to get access</a> to WP-Members private members forum, premium code snippets, tutorials, and add-on modules!
|
180 |
-
<?php } ?>
|
181 |
-
</p>
|
182 |
-
|
183 |
-
<p><i>
|
184 |
-
<?php _e( 'Thank you for using WP-Members', 'wp-members' ); ?>™!<br /><br />
|
185 |
-
<?php _e( 'A plugin developed by', 'wp-members' ); ?> <a href="http://butlerblog.com">Chad Butler</a><br />
|
186 |
-
<?php _e( 'Follow', 'wp-members' ); ?> ButlerBlog: <a href="http://feeds.butlerblog.com/butlerblog" target="_blank">RSS</a> | <a href="http://www.twitter.com/butlerblog" target="_blank">Twitter</a><br />
|
187 |
-
Copyright © 2006-<?php echo date("Y"); ?><br /><br />
|
188 |
-
Premium support and installation service <a href="https://rocketgeek.com/about/site-membership-subscription/">available at rocketgeek.com</a>.
|
189 |
-
</i></p>
|
190 |
-
</div>
|
191 |
-
</div><?php
|
192 |
-
}
|
193 |
-
|
194 |
-
|
195 |
-
/**
|
196 |
-
* Assemble the rocketgeek.com rss feed box.
|
197 |
-
*
|
198 |
-
* @since 2.8.0
|
199 |
-
*/
|
200 |
-
function wpmem_a_rss_box() {
|
201 |
-
|
202 |
-
?><div class="postbox">
|
203 |
-
<h3><span><?php _e( 'Latest from RocketGeek', 'wp-members' ); ?></span></h3>
|
204 |
-
<div class="inside"><?php
|
205 |
-
wp_widget_rss_output( array(
|
206 |
-
'url' => 'https://rocketgeek.com/feed/', //put your feed URL here
|
207 |
-
'title' => __( 'Latest from RocketGeek', 'wp-members' ),
|
208 |
-
'items' => 4, //how many posts to show
|
209 |
-
'show_summary' => 0,
|
210 |
-
'show_author' => 0,
|
211 |
-
'show_date' => 0,
|
212 |
-
) );?>
|
213 |
-
</div>
|
214 |
-
</div><?php
|
215 |
-
}
|
216 |
-
|
217 |
-
/**
|
218 |
-
* Adds the rating request meta box.
|
219 |
-
*
|
220 |
-
* @since 3.2.0
|
221 |
-
*/
|
222 |
-
function wpmem_a_rating_box() {
|
223 |
-
?><div class="postbox">
|
224 |
-
<h3><?php _e( 'Like WP-Members?', 'wp-members' ); ?></h3>
|
225 |
-
<div class="inside"><?php echo sprintf( __( 'If you like WP-Members please give it a %s★★★★★%s rating. Thanks!!', 'wp-members' ), '<a href="https://wordpress.org/support/plugin/wp-members/reviews?rate=5#new-post">', '</a>' ); ?></div>
|
226 |
-
</div><?php
|
227 |
-
}
|
228 |
-
|
229 |
-
|
230 |
-
/**
|
231 |
-
* Add the dashboard widget.
|
232 |
-
*
|
233 |
-
* @since 2.8.0
|
234 |
-
*/
|
235 |
-
function butlerblog_dashboard_widget() {
|
236 |
-
wp_add_dashboard_widget( 'dashboard_custom_feed', __( 'Latest from ButlerBlog', 'wp-members' ), 'butlerblog_feed_output' );
|
237 |
-
}
|
238 |
-
|
239 |
-
|
240 |
-
/**
|
241 |
-
* Output the rss feed for the dashboard widget.
|
242 |
-
*
|
243 |
-
* @since 2.8.0
|
244 |
-
*/
|
245 |
-
function butlerblog_feed_output() {
|
246 |
-
echo '<div class="rss-widget">';
|
247 |
-
wp_widget_rss_output( array(
|
248 |
-
'url' => 'https://feeds.feedburner.com/butlerblog',
|
249 |
-
'title' => __( 'Latest from ButlerBlog', 'wp-members' ),
|
250 |
-
'items' => 5,
|
251 |
-
'show_summary' => 0,
|
252 |
-
'show_author' => 0,
|
253 |
-
'show_date' => 1,
|
254 |
-
) );
|
255 |
-
echo "</div>";
|
256 |
-
}
|
257 |
-
|
258 |
// End of file.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members Admin Functions
|
4 |
+
*
|
5 |
+
* Handles functions that output admin dialogs to adminstrative users.
|
6 |
+
*
|
7 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
+
* Copyright (c) 2006-2020 Chad Butler
|
10 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
+
*
|
12 |
+
* @package WP-Members
|
13 |
+
* @author Chad Butler
|
14 |
+
* @copyright 2006-2020
|
15 |
+
*
|
16 |
+
* Functions included:
|
17 |
+
* - wpmem_a_do_warnings
|
18 |
+
* - wpmem_a_warning_msg
|
19 |
+
* - wpmem_a_meta_box
|
20 |
+
* - wpmem_a_rss_box
|
21 |
+
* - butlerblog_dashboard_widget
|
22 |
+
* - butlerblog_feed_output
|
23 |
+
*/
|
24 |
+
|
25 |
+
// Exit if accessed directly.
|
26 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
27 |
+
exit();
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Outputs the various admin warning messages.
|
32 |
+
*
|
33 |
+
* @since 2.8.0
|
34 |
+
*
|
35 |
+
* @param string $did_update Contains the update message.
|
36 |
+
* @param array $wpmem_settings Array containing the plugin settings.
|
37 |
+
*/
|
38 |
+
function wpmem_a_do_warnings( $did_update ) {
|
39 |
+
|
40 |
+
global $wpmem;
|
41 |
+
|
42 |
+
/** This filter is documented in /includes/class-wp-members-admin-api.php */
|
43 |
+
$dialogs = apply_filters( 'wpmem_dialogs', get_option( 'wpmembers_dialogs' ) );
|
44 |
+
|
45 |
+
if ( $did_update != false ) {?>
|
46 |
+
<div id="message" class="updated fade"><p><strong><?php echo $did_update; ?></strong></p></div><?php
|
47 |
+
}
|
48 |
+
|
49 |
+
/*
|
50 |
+
* Warning messages
|
51 |
+
*/
|
52 |
+
|
53 |
+
// Are warnings turned off?
|
54 |
+
$warnings_on = ( $wpmem->warnings == 0 ) ? true : false;
|
55 |
+
|
56 |
+
// Is there an active warning?
|
57 |
+
$warning_active = false;
|
58 |
+
|
59 |
+
// Settings allow anyone to register.
|
60 |
+
if ( get_option( 'users_can_register' ) != 0 && $warnings_on ) {
|
61 |
+
wpmem_a_warning_msg( 'users_can_register' );
|
62 |
+
$warning_active = true;
|
63 |
+
}
|
64 |
+
|
65 |
+
// Settings allow anyone to comment.
|
66 |
+
if ( get_option( 'comment_registration' ) !=1 && $warnings_on ) {
|
67 |
+
wpmem_a_warning_msg( 'comment_registration' );
|
68 |
+
$warning_active = true;
|
69 |
+
}
|
70 |
+
|
71 |
+
// Rss set to full text feeds.
|
72 |
+
if ( get_option( 'rss_use_excerpt' ) !=1 && $warnings_on ) {
|
73 |
+
wpmem_a_warning_msg( 'rss_use_excerpt' );
|
74 |
+
$warning_active = true;
|
75 |
+
}
|
76 |
+
|
77 |
+
// Holding registrations but haven't changed default successful registration message.
|
78 |
+
if ( $warnings_on && $wpmem->mod_reg == 1 && $dialogs['success'] == $wpmem->get_text( 'success' ) ) {
|
79 |
+
wpmem_a_warning_msg( 'success' );
|
80 |
+
$warning_active = true;
|
81 |
+
}
|
82 |
+
|
83 |
+
// Haven't entered recaptcha api keys.
|
84 |
+
if ( $warnings_on && $wpmem->captcha > 0 ) {
|
85 |
+
$wpmem_captcha = get_option( 'wpmembers_captcha' );
|
86 |
+
if ( 1 == $wpmem->captcha || 3 == $wpmem->captcha ) {
|
87 |
+
if ( ! $wpmem_captcha['recaptcha']['public'] || ! $wpmem_captcha['recaptcha']['private'] ) {
|
88 |
+
wpmem_a_warning_msg( 'wpmembers_captcha' );
|
89 |
+
$warning_active = true;
|
90 |
+
}
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
// If there is an active warning, display message about warnings.
|
95 |
+
if ( $warning_active ) {
|
96 |
+
wpmem_a_warning_msg( 'warning_active' );
|
97 |
+
}
|
98 |
+
|
99 |
+
}
|
100 |
+
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Assembles the various admin warning messages.
|
104 |
+
*
|
105 |
+
* @since 2.4.0
|
106 |
+
* @since 3.1.0 Changed $msg argument to string.
|
107 |
+
*
|
108 |
+
* @param string $msg The number for which message should be displayed.
|
109 |
+
*/
|
110 |
+
function wpmem_a_warning_msg( $msg ) {
|
111 |
+
|
112 |
+
$strong_msg = $remain_msg = $span_msg = '';
|
113 |
+
|
114 |
+
switch ( $msg ) {
|
115 |
+
|
116 |
+
case 'users_can_register':
|
117 |
+
$strong_msg = __( 'Your WP settings allow anyone to register - this is not the recommended setting.', 'wp-members' );
|
118 |
+
$remain_msg = sprintf( __( 'You can %s change this here %s making sure the box next to "Anyone can register" is unchecked.', 'wp-members'), '<a href="options-general.php">', '</a>' );
|
119 |
+
$span_msg = __( 'This setting allows a link on the /wp-login.php page to register using the WP native registration process thus circumventing any registration you are using with WP-Members. In some cases, this may suit the users wants/needs, but most users should uncheck this option. If you do not change this setting, you can choose to ignore these warning messages under WP-Members Settings.', 'wp-members' );
|
120 |
+
break;
|
121 |
+
|
122 |
+
case 'comment_registration':
|
123 |
+
$strong_msg = __( 'Your WP settings allow anyone to comment - this is not the recommended setting.', 'wp-members' );
|
124 |
+
$remain_msg = sprintf( __( 'You can %s change this here %s by checking the box next to "Users must be registered and logged in to comment."', 'wp-members' ), '<a href="options-discussion.php">', '</a>' );
|
125 |
+
$span_msg = __( 'This setting allows any users to comment, whether or not they are registered. Depending on how you are using WP-Members will determine whether you should change this setting or not. If you do not change this setting, you can choose to ignore these warning messages under WP-Members Settings.', 'wp-members' );
|
126 |
+
break;
|
127 |
+
|
128 |
+
case 'rss_use_excerpt':
|
129 |
+
$strong_msg = __( 'Your WP settings allow full text rss feeds - this is not the recommended setting.', 'wp-members' );
|
130 |
+
$remain_msg = sprintf( __( 'You can %s change this here %s by changing "For each article in a feed, show" to "Summary."', 'wp-members' ), '<a href="options-reading.php">' , '</a>' );
|
131 |
+
$span_msg = __( 'Leaving this set to full text allows anyone to read your protected content in an RSS reader. Changing this to Summary prevents this as your feeds will only show summary text.', 'wp-members' );
|
132 |
+
break;
|
133 |
+
|
134 |
+
case 'success':
|
135 |
+
$strong_msg = __( 'You have set WP-Members to hold registrations for approval', 'wp-members' );
|
136 |
+
$remain_msg = __( 'but you have not changed the default message for "Registration Completed" under "WP-Members Dialogs and Error Messages." You should change this message to let users know they are pending approval.', 'wp-members' );
|
137 |
+
break;
|
138 |
+
|
139 |
+
case 'wpmembers_captcha':
|
140 |
+
$strong_msg = __( 'You have turned on reCAPTCHA', 'wp-members');
|
141 |
+
$remain_msg = __( 'but you have not entered API keys. You will need both a public and private key. The CAPTCHA will not display unless a valid API key is included.', 'wp-members' );
|
142 |
+
break;
|
143 |
+
|
144 |
+
case 'warning_active':
|
145 |
+
$strong_msg = __( 'You have active settings that are not recommended.', 'wp-members' );
|
146 |
+
$remain_msg = __( 'If you will not be changing these settings, you can turn off these warning messages by checking the "Ignore warning messages" in the settings below.', 'wp-members' );
|
147 |
+
break;
|
148 |
+
|
149 |
+
}
|
150 |
+
|
151 |
+
if ( $span_msg ) {
|
152 |
+
$span_msg = ' [<span title="' . $span_msg . '">why is this?</span>]';
|
153 |
+
}
|
154 |
+
echo '<div class="error"><p><strong>' . $strong_msg . '</strong> ' . $remain_msg . $span_msg . '</p></div>';
|
155 |
+
|
156 |
+
}
|
157 |
+
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Assemble the side meta box.
|
161 |
+
*
|
162 |
+
* @since 2.8.0
|
163 |
+
*
|
164 |
+
* @global object $wpmem
|
165 |
+
*/
|
166 |
+
function wpmem_a_meta_box() {
|
167 |
+
|
168 |
+
global $wpmem;
|
169 |
+
|
170 |
+
?><div class="postbox">
|
171 |
+
<h3><span>WP-Members Information</span></h3>
|
172 |
+
<div class="inside">
|
173 |
+
|
174 |
+
<p><strong><?php _e( 'Version:', 'wp-members' ); echo " " . $wpmem->version; ?></strong><br />
|
175 |
+
<a href="https://rocketgeek.com/plugins/wp-members/quick-start-guide/"><?php _e( 'Quick Start Guide', 'wp-members' ); ?></a><br />
|
176 |
+
<a href="https://rocketgeek.com/plugins/wp-members/users-guide/"><?php _e( 'Online User Guide', 'wp-members' ); ?></a><br />
|
177 |
+
<a href="https://rocketgeek.com/plugins/wp-members/users-guide/faqs/"><?php _e( 'FAQs', 'wp-members' ); ?></a>
|
178 |
+
<?php if( ! defined( 'WPMEM_REMOVE_ATTR' ) ) { ?>
|
179 |
+
<br /><br /><a href="https://rocketgeek.com/about/site-membership-subscription/">Find out how to get access</a> to WP-Members private members forum, premium code snippets, tutorials, and add-on modules!
|
180 |
+
<?php } ?>
|
181 |
+
</p>
|
182 |
+
|
183 |
+
<p><i>
|
184 |
+
<?php _e( 'Thank you for using WP-Members', 'wp-members' ); ?>™!<br /><br />
|
185 |
+
<?php _e( 'A plugin developed by', 'wp-members' ); ?> <a href="http://butlerblog.com">Chad Butler</a><br />
|
186 |
+
<?php _e( 'Follow', 'wp-members' ); ?> ButlerBlog: <a href="http://feeds.butlerblog.com/butlerblog" target="_blank">RSS</a> | <a href="http://www.twitter.com/butlerblog" target="_blank">Twitter</a><br />
|
187 |
+
Copyright © 2006-<?php echo date("Y"); ?><br /><br />
|
188 |
+
Premium support and installation service <a href="https://rocketgeek.com/about/site-membership-subscription/">available at rocketgeek.com</a>.
|
189 |
+
</i></p>
|
190 |
+
</div>
|
191 |
+
</div><?php
|
192 |
+
}
|
193 |
+
|
194 |
+
|
195 |
+
/**
|
196 |
+
* Assemble the rocketgeek.com rss feed box.
|
197 |
+
*
|
198 |
+
* @since 2.8.0
|
199 |
+
*/
|
200 |
+
function wpmem_a_rss_box() {
|
201 |
+
|
202 |
+
?><div class="postbox">
|
203 |
+
<h3><span><?php _e( 'Latest from RocketGeek', 'wp-members' ); ?></span></h3>
|
204 |
+
<div class="inside"><?php
|
205 |
+
wp_widget_rss_output( array(
|
206 |
+
'url' => 'https://rocketgeek.com/feed/', //put your feed URL here
|
207 |
+
'title' => __( 'Latest from RocketGeek', 'wp-members' ),
|
208 |
+
'items' => 4, //how many posts to show
|
209 |
+
'show_summary' => 0,
|
210 |
+
'show_author' => 0,
|
211 |
+
'show_date' => 0,
|
212 |
+
) );?>
|
213 |
+
</div>
|
214 |
+
</div><?php
|
215 |
+
}
|
216 |
+
|
217 |
+
/**
|
218 |
+
* Adds the rating request meta box.
|
219 |
+
*
|
220 |
+
* @since 3.2.0
|
221 |
+
*/
|
222 |
+
function wpmem_a_rating_box() {
|
223 |
+
?><div class="postbox">
|
224 |
+
<h3><?php _e( 'Like WP-Members?', 'wp-members' ); ?></h3>
|
225 |
+
<div class="inside"><?php echo sprintf( __( 'If you like WP-Members please give it a %s★★★★★%s rating. Thanks!!', 'wp-members' ), '<a href="https://wordpress.org/support/plugin/wp-members/reviews?rate=5#new-post">', '</a>' ); ?></div>
|
226 |
+
</div><?php
|
227 |
+
}
|
228 |
+
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Add the dashboard widget.
|
232 |
+
*
|
233 |
+
* @since 2.8.0
|
234 |
+
*/
|
235 |
+
function butlerblog_dashboard_widget() {
|
236 |
+
wp_add_dashboard_widget( 'dashboard_custom_feed', __( 'Latest from ButlerBlog', 'wp-members' ), 'butlerblog_feed_output' );
|
237 |
+
}
|
238 |
+
|
239 |
+
|
240 |
+
/**
|
241 |
+
* Output the rss feed for the dashboard widget.
|
242 |
+
*
|
243 |
+
* @since 2.8.0
|
244 |
+
*/
|
245 |
+
function butlerblog_feed_output() {
|
246 |
+
echo '<div class="rss-widget">';
|
247 |
+
wp_widget_rss_output( array(
|
248 |
+
'url' => 'https://feeds.feedburner.com/butlerblog',
|
249 |
+
'title' => __( 'Latest from ButlerBlog', 'wp-members' ),
|
250 |
+
'items' => 5,
|
251 |
+
'show_summary' => 0,
|
252 |
+
'show_author' => 0,
|
253 |
+
'show_date' => 1,
|
254 |
+
) );
|
255 |
+
echo "</div>";
|
256 |
+
}
|
257 |
+
|
258 |
// End of file.
|
includes/admin/tabs/class-wp-members-admin-tab-captcha.php
CHANGED
@@ -1,306 +1,306 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members Admin Functions
|
4 |
-
*
|
5 |
-
* Functions to manage the captcha tab.
|
6 |
-
*
|
7 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
-
* Copyright (c) 2006-
|
10 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
-
*
|
12 |
-
* @package WP-Members
|
13 |
-
* @author Chad Butler
|
14 |
-
* @copyright 2006-
|
15 |
-
*/
|
16 |
-
|
17 |
-
// Exit if accessed directly.
|
18 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
19 |
-
exit();
|
20 |
-
}
|
21 |
-
|
22 |
-
class WP_Members_Admin_Tab_Captcha {
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Creates the captcha tab.
|
26 |
-
*
|
27 |
-
* @since 2.8.0
|
28 |
-
* @since 3.3.0 Ported to do_tab().
|
29 |
-
*
|
30 |
-
* @param string $tab The admin tab being displayed.
|
31 |
-
* @return string|bool The captcha options tab, otherwise false.
|
32 |
-
*/
|
33 |
-
public static function do_tab( $tab ) {
|
34 |
-
if ( $tab == 'captcha' ) {
|
35 |
-
return self::build_settings();
|
36 |
-
} else {
|
37 |
-
return false;
|
38 |
-
}
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Adds the captcha tab.
|
43 |
-
*
|
44 |
-
* @since 2.8.0
|
45 |
-
* @since 3.3.0 Ported wpmem_add_captcha_tab() to add_tab().
|
46 |
-
*
|
47 |
-
* @param array $tabs The array of tabs for the admin panel.
|
48 |
-
* @return array The updated array of tabs for the admin panel.
|
49 |
-
*/
|
50 |
-
public static function add_tab( $tabs ) {
|
51 |
-
return array_merge( $tabs, array( 'captcha' => 'Captcha' ) );
|
52 |
-
}
|
53 |
-
|
54 |
-
/**
|
55 |
-
* Builds the captcha options.
|
56 |
-
*
|
57 |
-
* @since 2.4.0
|
58 |
-
* @since 3.3.0 Ported wpmem_a_build_captcha_options() to build_settings().
|
59 |
-
*/
|
60 |
-
public static function build_settings() {
|
61 |
-
|
62 |
-
// Global settings.
|
63 |
-
global $wpmem;
|
64 |
-
|
65 |
-
$wpmem_captcha = get_option( 'wpmembers_captcha' );
|
66 |
-
$url = home_url();
|
67 |
-
$help_link = sprintf( __( 'See the %sUsers Guide on CAPTCHA%s.', 'wp-members' ), '<a href="https://rocketgeek.com/plugins/wp-members/users-guide/registration/using-captcha/" target="_blank">', '</a>' );
|
68 |
-
?>
|
69 |
-
<div class="metabox-holder has-right-sidebar">
|
70 |
-
|
71 |
-
<div class="inner-sidebar">
|
72 |
-
<?php wpmem_a_meta_box(); ?>
|
73 |
-
<div class="postbox">
|
74 |
-
<h3><span><?php _e( 'Need help?', 'wp-members' ); ?></span></h3>
|
75 |
-
<div class="inside">
|
76 |
-
<strong><i><?php echo $help_link; ?></i></strong>
|
77 |
-
</div>
|
78 |
-
</div>
|
79 |
-
</div> <!-- .inner-sidebar -->
|
80 |
-
|
81 |
-
<div id="post-body">
|
82 |
-
<div id="post-body-content">
|
83 |
-
<div class="postbox">
|
84 |
-
|
85 |
-
<h3><?php _e( 'Manage reCAPTCHA Options', 'wp-members' ); ?></h3>
|
86 |
-
<div class="inside">
|
87 |
-
<form name="updatecaptchaform" id="updatecaptchaform" method="post" action="<?php echo wpmem_admin_form_post_url(); ?>">
|
88 |
-
<?php wp_nonce_field( 'wpmem-update-captcha' ); ?>
|
89 |
-
<table class="form-table">
|
90 |
-
<?php // if reCAPTCHA is enabled...
|
91 |
-
if ( $wpmem->captcha == 1 ) {
|
92 |
-
$show_update_button = true;
|
93 |
-
$private_key = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['private'] : '';
|
94 |
-
$public_key = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['public'] : '';
|
95 |
-
$captcha_theme = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['theme'] : '';
|
96 |
-
?>
|
97 |
-
<tr>
|
98 |
-
<td colspan="2">
|
99 |
-
<p><?php _e( 'reCAPTCHA is a free, accessible CAPTCHA service that helps to digitize books while blocking spam on your blog.', 'wp-members' ); ?></p>
|
100 |
-
<p><?php printf( __( 'reCAPTCHA asks commenters to retype two words scanned from a book to prove that they are a human. This verifies that they are not a spambot while also correcting the automatic scans of old books. So you get less spam, and the world gets accurately digitized books. Everybody wins! For details, visit the %s reCAPTCHA website%s', 'wp-members' ), '<a href="http://www.google.com/recaptcha/intro/index.html" target="_blank">', '</a>' ); ?>.</p>
|
101 |
-
<p>
|
102 |
-
</td>
|
103 |
-
</tr>
|
104 |
-
<tr valign="top">
|
105 |
-
<th scope="row"><?php _e( 'reCAPTCHA Keys', 'wp-members' ); ?></th>
|
106 |
-
<td>
|
107 |
-
<?php printf( __( 'reCAPTCHA requires an API key, consisting of a "public" and a "private" key. You can sign up for a %s free reCAPTCHA key%s', 'wp-members' ), "<a href=\"https://www.google.com/recaptcha/admin#whyrecaptcha\" target=\"_blank\">", '</a>' ); ?>.<br />
|
108 |
-
<?php _e( 'Public Key', 'wp-members' ); ?>: <input type="text" name="wpmem_captcha_publickey" size="50" value="<?php echo $public_key; ?>" /><br />
|
109 |
-
<?php _e( 'Private Key', 'wp-members' ); ?>: <input type="text" name="wpmem_captcha_privatekey" size="50" value="<?php echo $private_key; ?>" />
|
110 |
-
</td>
|
111 |
-
</tr>
|
112 |
-
<tr valign="top">
|
113 |
-
<th scope="row"><?php _e( 'Choose Theme', 'wp-members' ); ?></th>
|
114 |
-
<td>
|
115 |
-
<select name="wpmem_captcha_theme"><?php
|
116 |
-
echo wpmem_create_formfield( __( 'Red', 'wp-members' ), 'option', 'red', $captcha_theme );
|
117 |
-
echo wpmem_create_formfield( __( 'White', 'wp-members' ), 'option', 'white', $captcha_theme );
|
118 |
-
echo wpmem_create_formfield( __( 'Black Glass', 'wp-members' ), 'option', 'blackglass', $captcha_theme );
|
119 |
-
echo wpmem_create_formfield( __( 'Clean', 'wp-members' ), 'option', 'clean', $captcha_theme ); ?>
|
120 |
-
</select>
|
121 |
-
</td>
|
122 |
-
</tr>
|
123 |
-
<?php
|
124 |
-
// if reCAPTCHA v2 is enabled...
|
125 |
-
} elseif ( 3 == $wpmem->captcha || 4 == $wpmem->captcha ) {
|
126 |
-
$show_update_button = true;
|
127 |
-
$private_key = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['private'] : '';
|
128 |
-
$public_key = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['public'] : '';
|
129 |
-
?>
|
130 |
-
<tr valign="top">
|
131 |
-
<th scope="row"><?php _e( 'reCAPTCHA Keys', 'wp-members' ); ?></th>
|
132 |
-
<td>
|
133 |
-
<?php printf( __( 'reCAPTCHA requires an API key, consisting of a "site" and a "secret" key. You can sign up for a %s free reCAPTCHA key%s', 'wp-members' ), "<a href=\"https://www.google.com/recaptcha/admin#whyrecaptcha\" target=\"_blank\">", '</a>' ); ?>.<br />
|
134 |
-
<p><label><?php _e( 'Site Key', 'wp-members' ); ?>:</label><br /><input type="text" name="wpmem_captcha_publickey" size="60" value="<?php echo $public_key; ?>" /></p>
|
135 |
-
<p><label><?php _e( 'Secret Key', 'wp-members' ); ?>:</label><br /><input type="text" name="wpmem_captcha_privatekey" size="60" value="<?php echo $private_key; ?>" /></p>
|
136 |
-
</td>
|
137 |
-
</tr>
|
138 |
-
<?php
|
139 |
-
// If Really Simple CAPTCHA is enabled.
|
140 |
-
} elseif ( $wpmem->captcha == 2 ) {
|
141 |
-
|
142 |
-
// Setup defaults.
|
143 |
-
$defaults = array(
|
144 |
-
'characters' => 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789',
|
145 |
-
'num_char' => '4',
|
146 |
-
'dim_w' => '72',
|
147 |
-
'dim_h' => '30',
|
148 |
-
'font_color' => '0,0,0',
|
149 |
-
'bg_color' => '255,255,255',
|
150 |
-
'font_size' => '12',
|
151 |
-
'kerning' => '14',
|
152 |
-
'img_type' => 'png',
|
153 |
-
);
|
154 |
-
|
155 |
-
$args = ( isset( $wpmem_captcha['really_simple'] ) && is_array( $wpmem_captcha['really_simple'] ) ) ? $wpmem_captcha['really_simple'] : array();
|
156 |
-
|
157 |
-
$args = wp_parse_args( $args, $defaults );
|
158 |
-
|
159 |
-
// Explode colors.
|
160 |
-
$font_color = explode( ',', $args['font_color'] );
|
161 |
-
$bg_color = explode( ',', $args['bg_color'] );
|
162 |
-
|
163 |
-
$show_update_button = true;
|
164 |
-
if ( is_plugin_active( 'really-simple-captcha/really-simple-captcha.php' ) ) { ?>
|
165 |
-
<tr>
|
166 |
-
<th scope="row"><?php _e( 'Characters for image', 'wp-members' ); ?></th>
|
167 |
-
<td><input name="characters" type="text" size="34" value="<?php echo $args['characters']; ?>" /></td>
|
168 |
-
</tr>
|
169 |
-
<tr>
|
170 |
-
<th scope="row"><?php _e( 'Number of characters', 'wp-members' ); ?></th>
|
171 |
-
<td><input name="num_char" type="text" size="2" value="<?php echo $args['num_char']; ?>" /></td>
|
172 |
-
</tr>
|
173 |
-
<tr>
|
174 |
-
<th scope="row"><?php _e( 'Image dimensions', 'wp-members' ); ?></th>
|
175 |
-
<td><?php _e( 'Width' ); ?> <input name="dim_w" type="text" size="2" value="<?php echo $args['dim_w']; ?>" /> <?php _e( 'Height' ); ?> <input name="dim_h" type="text" size="2" value="<?php echo $args['dim_h']; ?>" /></td>
|
176 |
-
</tr>
|
177 |
-
<tr>
|
178 |
-
<th scope="row"><?php _e( 'Font color of characters', 'wp-members' ); ?></th>
|
179 |
-
<td>R:<input name="font_color_r" type="text" size="2" value="<?php echo $font_color[0]; ?>" /> G:<input name="font_color_g" type="text" size="2" value="<?php echo $font_color[1]; ?>" /> B:<input name="font_color_b" type="text" size="2" value="<?php echo $font_color[2]; ?>" /></td>
|
180 |
-
</tr>
|
181 |
-
<tr>
|
182 |
-
<th scope="row"><?php _e( 'Background color of image', 'wp-members' ); ?></th>
|
183 |
-
<td>R:<input name="bg_color_r" type="text" size="2" value="<?php echo $bg_color[0]; ?>" /> G:<input name="bg_color_g" type="text" size="2" value="<?php echo $bg_color[1]; ?>" /> B:<input name="bg_color_b" type="text" size="2" value="<?php echo $bg_color[2]; ?>" /></td>
|
184 |
-
</tr>
|
185 |
-
<tr>
|
186 |
-
<th scope="row"><?php _e( 'Font size', 'wp-members' ); ?></th>
|
187 |
-
<td><input name="font_size" type="text" value="<?php echo $args['font_size']; ?>" /></td>
|
188 |
-
</tr>
|
189 |
-
<tr>
|
190 |
-
<th scope="row"><?php _e( 'Width between characters', 'wp-members' ); ?></th>
|
191 |
-
<td><input name="kerning" type="text" value="<?php echo $args['kerning']; ?>" /></td>
|
192 |
-
</tr>
|
193 |
-
<tr>
|
194 |
-
<th scope="row"><?php _e( 'Image type', 'wp-members' ); ?></th>
|
195 |
-
<td><select name="img_type">
|
196 |
-
<option<?php echo ( $args['img_type'] == 'png' ) ? ' selected' : ''; ?>>png</option>
|
197 |
-
<option<?php echo ( $args['img_type'] == 'gif' ) ? ' selected' : ''; ?>>gif</option>
|
198 |
-
<option<?php echo ( $args['img_type'] == 'jpg' ) ? ' selected' : ''; ?>>jpg</option>
|
199 |
-
</select>
|
200 |
-
</td>
|
201 |
-
</tr><?php
|
202 |
-
|
203 |
-
} else {
|
204 |
-
|
205 |
-
$show_update_button = false; ?>
|
206 |
-
<tr>
|
207 |
-
<td colspan="2">
|
208 |
-
<p><?php _e( 'To use Really Simple CAPTCHA, you must have the Really Simple CAPTCHA plugin installed and activated.', 'wp-members' ); ?></p>
|
209 |
-
<p><?php _e( sprintf( 'You can download Really Simple CAPTCHA from the %swordpress.org plugin repository%s.', '<a href="http://wordpress.org/plugins/really-simple-captcha/">', '</a>' ), 'wp-members' ); ?></p>
|
210 |
-
</td>
|
211 |
-
</tr><?php
|
212 |
-
}
|
213 |
-
} // End if RSC is selected.
|
214 |
-
if ( $show_update_button ) {
|
215 |
-
|
216 |
-
switch ( $wpmem->captcha ) {
|
217 |
-
case 1:
|
218 |
-
$captcha_type = 'recaptcha';
|
219 |
-
break;
|
220 |
-
case 2:
|
221 |
-
$captcha_type = 'really_simple';
|
222 |
-
break;
|
223 |
-
case 3:
|
224 |
-
case 4:
|
225 |
-
$captcha_type = 'recaptcha2';
|
226 |
-
break;
|
227 |
-
} ?>
|
228 |
-
<tr valign="top">
|
229 |
-
<th scope="row"> </th>
|
230 |
-
<td>
|
231 |
-
<input type="hidden" name="wpmem_recaptcha_type" value="<?php echo $captcha_type ?>" />
|
232 |
-
<input type="hidden" name="wpmem_admin_a" value="update_captcha" />
|
233 |
-
<?php submit_button( __( 'Update CAPTCHA Settings', 'wp-members' ) ); ?>
|
234 |
-
</td>
|
235 |
-
</tr>
|
236 |
-
<?php } ?>
|
237 |
-
</table>
|
238 |
-
</form>
|
239 |
-
</div><!-- .inside -->
|
240 |
-
</div>
|
241 |
-
</div><!-- #post-body-content -->
|
242 |
-
</div><!-- #post-body -->
|
243 |
-
</div><!-- .metabox-holder -->
|
244 |
-
<?php
|
245 |
-
}
|
246 |
-
|
247 |
-
/**
|
248 |
-
* Updates the captcha options.
|
249 |
-
*
|
250 |
-
* @since 2.8
|
251 |
-
* @since 3.3.0 Ported wpmem_update_captcha() to update().
|
252 |
-
*
|
253 |
-
* @return string The captcha option update message.
|
254 |
-
*/
|
255 |
-
public static function update() {
|
256 |
-
|
257 |
-
// Check nonce.
|
258 |
-
check_admin_referer( 'wpmem-update-captcha' );
|
259 |
-
|
260 |
-
$settings = get_option( 'wpmembers_captcha' );
|
261 |
-
$update_type = sanitize_text_field( $_POST['wpmem_recaptcha_type'] );
|
262 |
-
$new_settings = array();
|
263 |
-
|
264 |
-
// If there are no current settings.
|
265 |
-
if ( ! $settings ) {
|
266 |
-
$settings = array();
|
267 |
-
}
|
268 |
-
|
269 |
-
if ( $update_type == 'recaptcha' || $update_type == 'recaptcha2' ) {
|
270 |
-
if ( array_key_exists( 'really_simple', $settings ) ) {
|
271 |
-
// Updating recaptcha but need to maintain really_simple.
|
272 |
-
$new_settings['really_simple'] = $settings['really_simple'];
|
273 |
-
}
|
274 |
-
$new_settings['recaptcha'] = array(
|
275 |
-
'public' => sanitize_text_field( $_POST['wpmem_captcha_publickey'] ),
|
276 |
-
'private' => sanitize_text_field( $_POST['wpmem_captcha_privatekey'] ),
|
277 |
-
);
|
278 |
-
if ( $update_type == 'recaptcha' && isset( $_POST['wpmem_captcha_theme'] ) ) {
|
279 |
-
$new_settings['recaptcha']['theme'] = sanitize_text_field( $_POST['wpmem_captcha_theme'] );
|
280 |
-
}
|
281 |
-
}
|
282 |
-
|
283 |
-
if ( $update_type == 'really_simple' ) {
|
284 |
-
if ( array_key_exists( 'recaptcha', $settings ) ) {
|
285 |
-
// Updating really_simple but need to maintain recaptcha.
|
286 |
-
$new_settings['recaptcha'] = $settings['recaptcha'];
|
287 |
-
}
|
288 |
-
$font_color = sanitize_text_field( $_POST['font_color_r'] ) . ',' . sanitize_text_field( $_POST['font_color_g'] ) . ',' . sanitize_text_field( $_POST['font_color_b'] );
|
289 |
-
$bg_color = sanitize_text_field( $_POST['bg_color_r'] ) . ',' . sanitize_text_field( $_POST['bg_color_g'] ) . ',' . sanitize_text_field( $_POST['bg_color_b'] );
|
290 |
-
$new_settings['really_simple'] = array(
|
291 |
-
'characters' => sanitize_text_field( $_POST['characters'] ),
|
292 |
-
'num_char' => sanitize_text_field( $_POST['num_char'] ),
|
293 |
-
'dim_w' => sanitize_text_field( $_POST['dim_w'] ),
|
294 |
-
'dim_h' => sanitize_text_field( $_POST['dim_h'] ),
|
295 |
-
'font_color' => $font_color,
|
296 |
-
'bg_color' => $bg_color,
|
297 |
-
'font_size' => sanitize_text_field( $_POST['font_size'] ),
|
298 |
-
'kerning' => sanitize_text_field( $_POST['kerning'] ),
|
299 |
-
'img_type' => sanitize_text_field( $_POST['img_type'] ),
|
300 |
-
);
|
301 |
-
}
|
302 |
-
|
303 |
-
update_option( 'wpmembers_captcha', $new_settings );
|
304 |
-
return __( 'CAPTCHA was updated for WP-Members', 'wp-members' );
|
305 |
-
}
|
306 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members Admin Functions
|
4 |
+
*
|
5 |
+
* Functions to manage the captcha tab.
|
6 |
+
*
|
7 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
+
* Copyright (c) 2006-2020 Chad Butler
|
10 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
+
*
|
12 |
+
* @package WP-Members
|
13 |
+
* @author Chad Butler
|
14 |
+
* @copyright 2006-2020
|
15 |
+
*/
|
16 |
+
|
17 |
+
// Exit if accessed directly.
|
18 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
19 |
+
exit();
|
20 |
+
}
|
21 |
+
|
22 |
+
class WP_Members_Admin_Tab_Captcha {
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Creates the captcha tab.
|
26 |
+
*
|
27 |
+
* @since 2.8.0
|
28 |
+
* @since 3.3.0 Ported to do_tab().
|
29 |
+
*
|
30 |
+
* @param string $tab The admin tab being displayed.
|
31 |
+
* @return string|bool The captcha options tab, otherwise false.
|
32 |
+
*/
|
33 |
+
public static function do_tab( $tab ) {
|
34 |
+
if ( $tab == 'captcha' ) {
|
35 |
+
return self::build_settings();
|
36 |
+
} else {
|
37 |
+
return false;
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Adds the captcha tab.
|
43 |
+
*
|
44 |
+
* @since 2.8.0
|
45 |
+
* @since 3.3.0 Ported wpmem_add_captcha_tab() to add_tab().
|
46 |
+
*
|
47 |
+
* @param array $tabs The array of tabs for the admin panel.
|
48 |
+
* @return array The updated array of tabs for the admin panel.
|
49 |
+
*/
|
50 |
+
public static function add_tab( $tabs ) {
|
51 |
+
return array_merge( $tabs, array( 'captcha' => 'Captcha' ) );
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Builds the captcha options.
|
56 |
+
*
|
57 |
+
* @since 2.4.0
|
58 |
+
* @since 3.3.0 Ported wpmem_a_build_captcha_options() to build_settings().
|
59 |
+
*/
|
60 |
+
public static function build_settings() {
|
61 |
+
|
62 |
+
// Global settings.
|
63 |
+
global $wpmem;
|
64 |
+
|
65 |
+
$wpmem_captcha = get_option( 'wpmembers_captcha' );
|
66 |
+
$url = home_url();
|
67 |
+
$help_link = sprintf( __( 'See the %sUsers Guide on CAPTCHA%s.', 'wp-members' ), '<a href="https://rocketgeek.com/plugins/wp-members/users-guide/registration/using-captcha/" target="_blank">', '</a>' );
|
68 |
+
?>
|
69 |
+
<div class="metabox-holder has-right-sidebar">
|
70 |
+
|
71 |
+
<div class="inner-sidebar">
|
72 |
+
<?php wpmem_a_meta_box(); ?>
|
73 |
+
<div class="postbox">
|
74 |
+
<h3><span><?php _e( 'Need help?', 'wp-members' ); ?></span></h3>
|
75 |
+
<div class="inside">
|
76 |
+
<strong><i><?php echo $help_link; ?></i></strong>
|
77 |
+
</div>
|
78 |
+
</div>
|
79 |
+
</div> <!-- .inner-sidebar -->
|
80 |
+
|
81 |
+
<div id="post-body">
|
82 |
+
<div id="post-body-content">
|
83 |
+
<div class="postbox">
|
84 |
+
|
85 |
+
<h3><?php _e( 'Manage reCAPTCHA Options', 'wp-members' ); ?></h3>
|
86 |
+
<div class="inside">
|
87 |
+
<form name="updatecaptchaform" id="updatecaptchaform" method="post" action="<?php echo wpmem_admin_form_post_url(); ?>">
|
88 |
+
<?php wp_nonce_field( 'wpmem-update-captcha' ); ?>
|
89 |
+
<table class="form-table">
|
90 |
+
<?php // if reCAPTCHA is enabled...
|
91 |
+
if ( $wpmem->captcha == 1 ) {
|
92 |
+
$show_update_button = true;
|
93 |
+
$private_key = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['private'] : '';
|
94 |
+
$public_key = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['public'] : '';
|
95 |
+
$captcha_theme = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['theme'] : '';
|
96 |
+
?>
|
97 |
+
<tr>
|
98 |
+
<td colspan="2">
|
99 |
+
<p><?php _e( 'reCAPTCHA is a free, accessible CAPTCHA service that helps to digitize books while blocking spam on your blog.', 'wp-members' ); ?></p>
|
100 |
+
<p><?php printf( __( 'reCAPTCHA asks commenters to retype two words scanned from a book to prove that they are a human. This verifies that they are not a spambot while also correcting the automatic scans of old books. So you get less spam, and the world gets accurately digitized books. Everybody wins! For details, visit the %s reCAPTCHA website%s', 'wp-members' ), '<a href="http://www.google.com/recaptcha/intro/index.html" target="_blank">', '</a>' ); ?>.</p>
|
101 |
+
<p>
|
102 |
+
</td>
|
103 |
+
</tr>
|
104 |
+
<tr valign="top">
|
105 |
+
<th scope="row"><?php _e( 'reCAPTCHA Keys', 'wp-members' ); ?></th>
|
106 |
+
<td>
|
107 |
+
<?php printf( __( 'reCAPTCHA requires an API key, consisting of a "public" and a "private" key. You can sign up for a %s free reCAPTCHA key%s', 'wp-members' ), "<a href=\"https://www.google.com/recaptcha/admin#whyrecaptcha\" target=\"_blank\">", '</a>' ); ?>.<br />
|
108 |
+
<?php _e( 'Public Key', 'wp-members' ); ?>: <input type="text" name="wpmem_captcha_publickey" size="50" value="<?php echo $public_key; ?>" /><br />
|
109 |
+
<?php _e( 'Private Key', 'wp-members' ); ?>: <input type="text" name="wpmem_captcha_privatekey" size="50" value="<?php echo $private_key; ?>" />
|
110 |
+
</td>
|
111 |
+
</tr>
|
112 |
+
<tr valign="top">
|
113 |
+
<th scope="row"><?php _e( 'Choose Theme', 'wp-members' ); ?></th>
|
114 |
+
<td>
|
115 |
+
<select name="wpmem_captcha_theme"><?php
|
116 |
+
echo wpmem_create_formfield( __( 'Red', 'wp-members' ), 'option', 'red', $captcha_theme );
|
117 |
+
echo wpmem_create_formfield( __( 'White', 'wp-members' ), 'option', 'white', $captcha_theme );
|
118 |
+
echo wpmem_create_formfield( __( 'Black Glass', 'wp-members' ), 'option', 'blackglass', $captcha_theme );
|
119 |
+
echo wpmem_create_formfield( __( 'Clean', 'wp-members' ), 'option', 'clean', $captcha_theme ); ?>
|
120 |
+
</select>
|
121 |
+
</td>
|
122 |
+
</tr>
|
123 |
+
<?php
|
124 |
+
// if reCAPTCHA v2 is enabled...
|
125 |
+
} elseif ( 3 == $wpmem->captcha || 4 == $wpmem->captcha ) {
|
126 |
+
$show_update_button = true;
|
127 |
+
$private_key = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['private'] : '';
|
128 |
+
$public_key = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['public'] : '';
|
129 |
+
?>
|
130 |
+
<tr valign="top">
|
131 |
+
<th scope="row"><?php _e( 'reCAPTCHA Keys', 'wp-members' ); ?></th>
|
132 |
+
<td>
|
133 |
+
<?php printf( __( 'reCAPTCHA requires an API key, consisting of a "site" and a "secret" key. You can sign up for a %s free reCAPTCHA key%s', 'wp-members' ), "<a href=\"https://www.google.com/recaptcha/admin#whyrecaptcha\" target=\"_blank\">", '</a>' ); ?>.<br />
|
134 |
+
<p><label><?php _e( 'Site Key', 'wp-members' ); ?>:</label><br /><input type="text" name="wpmem_captcha_publickey" size="60" value="<?php echo $public_key; ?>" /></p>
|
135 |
+
<p><label><?php _e( 'Secret Key', 'wp-members' ); ?>:</label><br /><input type="text" name="wpmem_captcha_privatekey" size="60" value="<?php echo $private_key; ?>" /></p>
|
136 |
+
</td>
|
137 |
+
</tr>
|
138 |
+
<?php
|
139 |
+
// If Really Simple CAPTCHA is enabled.
|
140 |
+
} elseif ( $wpmem->captcha == 2 ) {
|
141 |
+
|
142 |
+
// Setup defaults.
|
143 |
+
$defaults = array(
|
144 |
+
'characters' => 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789',
|
145 |
+
'num_char' => '4',
|
146 |
+
'dim_w' => '72',
|
147 |
+
'dim_h' => '30',
|
148 |
+
'font_color' => '0,0,0',
|
149 |
+
'bg_color' => '255,255,255',
|
150 |
+
'font_size' => '12',
|
151 |
+
'kerning' => '14',
|
152 |
+
'img_type' => 'png',
|
153 |
+
);
|
154 |
+
|
155 |
+
$args = ( isset( $wpmem_captcha['really_simple'] ) && is_array( $wpmem_captcha['really_simple'] ) ) ? $wpmem_captcha['really_simple'] : array();
|
156 |
+
|
157 |
+
$args = wp_parse_args( $args, $defaults );
|
158 |
+
|
159 |
+
// Explode colors.
|
160 |
+
$font_color = explode( ',', $args['font_color'] );
|
161 |
+
$bg_color = explode( ',', $args['bg_color'] );
|
162 |
+
|
163 |
+
$show_update_button = true;
|
164 |
+
if ( is_plugin_active( 'really-simple-captcha/really-simple-captcha.php' ) ) { ?>
|
165 |
+
<tr>
|
166 |
+
<th scope="row"><?php _e( 'Characters for image', 'wp-members' ); ?></th>
|
167 |
+
<td><input name="characters" type="text" size="34" value="<?php echo $args['characters']; ?>" /></td>
|
168 |
+
</tr>
|
169 |
+
<tr>
|
170 |
+
<th scope="row"><?php _e( 'Number of characters', 'wp-members' ); ?></th>
|
171 |
+
<td><input name="num_char" type="text" size="2" value="<?php echo $args['num_char']; ?>" /></td>
|
172 |
+
</tr>
|
173 |
+
<tr>
|
174 |
+
<th scope="row"><?php _e( 'Image dimensions', 'wp-members' ); ?></th>
|
175 |
+
<td><?php _e( 'Width' ); ?> <input name="dim_w" type="text" size="2" value="<?php echo $args['dim_w']; ?>" /> <?php _e( 'Height' ); ?> <input name="dim_h" type="text" size="2" value="<?php echo $args['dim_h']; ?>" /></td>
|
176 |
+
</tr>
|
177 |
+
<tr>
|
178 |
+
<th scope="row"><?php _e( 'Font color of characters', 'wp-members' ); ?></th>
|
179 |
+
<td>R:<input name="font_color_r" type="text" size="2" value="<?php echo $font_color[0]; ?>" /> G:<input name="font_color_g" type="text" size="2" value="<?php echo $font_color[1]; ?>" /> B:<input name="font_color_b" type="text" size="2" value="<?php echo $font_color[2]; ?>" /></td>
|
180 |
+
</tr>
|
181 |
+
<tr>
|
182 |
+
<th scope="row"><?php _e( 'Background color of image', 'wp-members' ); ?></th>
|
183 |
+
<td>R:<input name="bg_color_r" type="text" size="2" value="<?php echo $bg_color[0]; ?>" /> G:<input name="bg_color_g" type="text" size="2" value="<?php echo $bg_color[1]; ?>" /> B:<input name="bg_color_b" type="text" size="2" value="<?php echo $bg_color[2]; ?>" /></td>
|
184 |
+
</tr>
|
185 |
+
<tr>
|
186 |
+
<th scope="row"><?php _e( 'Font size', 'wp-members' ); ?></th>
|
187 |
+
<td><input name="font_size" type="text" value="<?php echo $args['font_size']; ?>" /></td>
|
188 |
+
</tr>
|
189 |
+
<tr>
|
190 |
+
<th scope="row"><?php _e( 'Width between characters', 'wp-members' ); ?></th>
|
191 |
+
<td><input name="kerning" type="text" value="<?php echo $args['kerning']; ?>" /></td>
|
192 |
+
</tr>
|
193 |
+
<tr>
|
194 |
+
<th scope="row"><?php _e( 'Image type', 'wp-members' ); ?></th>
|
195 |
+
<td><select name="img_type">
|
196 |
+
<option<?php echo ( $args['img_type'] == 'png' ) ? ' selected' : ''; ?>>png</option>
|
197 |
+
<option<?php echo ( $args['img_type'] == 'gif' ) ? ' selected' : ''; ?>>gif</option>
|
198 |
+
<option<?php echo ( $args['img_type'] == 'jpg' ) ? ' selected' : ''; ?>>jpg</option>
|
199 |
+
</select>
|
200 |
+
</td>
|
201 |
+
</tr><?php
|
202 |
+
|
203 |
+
} else {
|
204 |
+
|
205 |
+
$show_update_button = false; ?>
|
206 |
+
<tr>
|
207 |
+
<td colspan="2">
|
208 |
+
<p><?php _e( 'To use Really Simple CAPTCHA, you must have the Really Simple CAPTCHA plugin installed and activated.', 'wp-members' ); ?></p>
|
209 |
+
<p><?php _e( sprintf( 'You can download Really Simple CAPTCHA from the %swordpress.org plugin repository%s.', '<a href="http://wordpress.org/plugins/really-simple-captcha/">', '</a>' ), 'wp-members' ); ?></p>
|
210 |
+
</td>
|
211 |
+
</tr><?php
|
212 |
+
}
|
213 |
+
} // End if RSC is selected.
|
214 |
+
if ( $show_update_button ) {
|
215 |
+
|
216 |
+
switch ( $wpmem->captcha ) {
|
217 |
+
case 1:
|
218 |
+
$captcha_type = 'recaptcha';
|
219 |
+
break;
|
220 |
+
case 2:
|
221 |
+
$captcha_type = 'really_simple';
|
222 |
+
break;
|
223 |
+
case 3:
|
224 |
+
case 4:
|
225 |
+
$captcha_type = 'recaptcha2';
|
226 |
+
break;
|
227 |
+
} ?>
|
228 |
+
<tr valign="top">
|
229 |
+
<th scope="row"> </th>
|
230 |
+
<td>
|
231 |
+
<input type="hidden" name="wpmem_recaptcha_type" value="<?php echo $captcha_type ?>" />
|
232 |
+
<input type="hidden" name="wpmem_admin_a" value="update_captcha" />
|
233 |
+
<?php submit_button( __( 'Update CAPTCHA Settings', 'wp-members' ) ); ?>
|
234 |
+
</td>
|
235 |
+
</tr>
|
236 |
+
<?php } ?>
|
237 |
+
</table>
|
238 |
+
</form>
|
239 |
+
</div><!-- .inside -->
|
240 |
+
</div>
|
241 |
+
</div><!-- #post-body-content -->
|
242 |
+
</div><!-- #post-body -->
|
243 |
+
</div><!-- .metabox-holder -->
|
244 |
+
<?php
|
245 |
+
}
|
246 |
+
|
247 |
+
/**
|
248 |
+
* Updates the captcha options.
|
249 |
+
*
|
250 |
+
* @since 2.8
|
251 |
+
* @since 3.3.0 Ported wpmem_update_captcha() to update().
|
252 |
+
*
|
253 |
+
* @return string The captcha option update message.
|
254 |
+
*/
|
255 |
+
public static function update() {
|
256 |
+
|
257 |
+
// Check nonce.
|
258 |
+
check_admin_referer( 'wpmem-update-captcha' );
|
259 |
+
|
260 |
+
$settings = get_option( 'wpmembers_captcha' );
|
261 |
+
$update_type = sanitize_text_field( $_POST['wpmem_recaptcha_type'] );
|
262 |
+
$new_settings = array();
|
263 |
+
|
264 |
+
// If there are no current settings.
|
265 |
+
if ( ! $settings ) {
|
266 |
+
$settings = array();
|
267 |
+
}
|
268 |
+
|
269 |
+
if ( $update_type == 'recaptcha' || $update_type == 'recaptcha2' ) {
|
270 |
+
if ( array_key_exists( 'really_simple', $settings ) ) {
|
271 |
+
// Updating recaptcha but need to maintain really_simple.
|
272 |
+
$new_settings['really_simple'] = $settings['really_simple'];
|
273 |
+
}
|
274 |
+
$new_settings['recaptcha'] = array(
|
275 |
+
'public' => sanitize_text_field( $_POST['wpmem_captcha_publickey'] ),
|
276 |
+
'private' => sanitize_text_field( $_POST['wpmem_captcha_privatekey'] ),
|
277 |
+
);
|
278 |
+
if ( $update_type == 'recaptcha' && isset( $_POST['wpmem_captcha_theme'] ) ) {
|
279 |
+
$new_settings['recaptcha']['theme'] = sanitize_text_field( $_POST['wpmem_captcha_theme'] );
|
280 |
+
}
|
281 |
+
}
|
282 |
+
|
283 |
+
if ( $update_type == 'really_simple' ) {
|
284 |
+
if ( array_key_exists( 'recaptcha', $settings ) ) {
|
285 |
+
// Updating really_simple but need to maintain recaptcha.
|
286 |
+
$new_settings['recaptcha'] = $settings['recaptcha'];
|
287 |
+
}
|
288 |
+
$font_color = sanitize_text_field( $_POST['font_color_r'] ) . ',' . sanitize_text_field( $_POST['font_color_g'] ) . ',' . sanitize_text_field( $_POST['font_color_b'] );
|
289 |
+
$bg_color = sanitize_text_field( $_POST['bg_color_r'] ) . ',' . sanitize_text_field( $_POST['bg_color_g'] ) . ',' . sanitize_text_field( $_POST['bg_color_b'] );
|
290 |
+
$new_settings['really_simple'] = array(
|
291 |
+
'characters' => sanitize_text_field( $_POST['characters'] ),
|
292 |
+
'num_char' => sanitize_text_field( $_POST['num_char'] ),
|
293 |
+
'dim_w' => sanitize_text_field( $_POST['dim_w'] ),
|
294 |
+
'dim_h' => sanitize_text_field( $_POST['dim_h'] ),
|
295 |
+
'font_color' => $font_color,
|
296 |
+
'bg_color' => $bg_color,
|
297 |
+
'font_size' => sanitize_text_field( $_POST['font_size'] ),
|
298 |
+
'kerning' => sanitize_text_field( $_POST['kerning'] ),
|
299 |
+
'img_type' => sanitize_text_field( $_POST['img_type'] ),
|
300 |
+
);
|
301 |
+
}
|
302 |
+
|
303 |
+
update_option( 'wpmembers_captcha', $new_settings );
|
304 |
+
return __( 'CAPTCHA was updated for WP-Members', 'wp-members' );
|
305 |
+
}
|
306 |
}
|
includes/admin/tabs/class-wp-members-admin-tab-dialogs.php
CHANGED
@@ -1,127 +1,127 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members Admin functions
|
4 |
-
*
|
5 |
-
* Static functions to manage the dialogs tab.
|
6 |
-
*
|
7 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
-
* Copyright (c) 2006-
|
10 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
-
*
|
12 |
-
* @package WP-Members
|
13 |
-
* @author Chad Butler
|
14 |
-
* @copyright 2006-
|
15 |
-
*/
|
16 |
-
|
17 |
-
// Exit if accessed directly.
|
18 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
19 |
-
exit();
|
20 |
-
}
|
21 |
-
|
22 |
-
class WP_Members_Admin_Tab_Dialogs {
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Creates the tab.
|
26 |
-
*
|
27 |
-
* @since 3.2.0
|
28 |
-
* @since 3.3.0 Ported from wpmem_a_dialogs_tab().
|
29 |
-
*
|
30 |
-
* @param string $tab The admin tab being displayed.
|
31 |
-
* @return string|bool The tab html, otherwise false.
|
32 |
-
*/
|
33 |
-
static function do_tab( $tab ) {
|
34 |
-
if ( $tab == 'dialogs' || ! $tab ) {
|
35 |
-
// Render the tab.
|
36 |
-
return self::build_settings();
|
37 |
-
} else {
|
38 |
-
return false;
|
39 |
-
}
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Builds the dialogs panel.
|
44 |
-
*
|
45 |
-
* @since 2.2.2
|
46 |
-
* @since 3.3.0 Ported from wpmem_a_build_dialogs().
|
47 |
-
*
|
48 |
-
* @global object $wpmem
|
49 |
-
*/
|
50 |
-
static function build_settings() {
|
51 |
-
global $wpmem; ?>
|
52 |
-
<div class="metabox-holder has-right-sidebar">
|
53 |
-
|
54 |
-
<div class="inner-sidebar">
|
55 |
-
<?php wpmem_a_meta_box(); ?>
|
56 |
-
<div class="postbox">
|
57 |
-
<h3><span><?php _e( 'Need help?', 'wp-members' ); ?></span></h3>
|
58 |
-
<div class="inside">
|
59 |
-
<strong><i>See the <a href="https://rocketgeek.com/plugins/wp-members/users-guide/plugin-settings/dialogs/" target="_blank">Users Guide on dialogs</a>.</i></strong>
|
60 |
-
</div>
|
61 |
-
</div>
|
62 |
-
</div> <!-- .inner-sidebar -->
|
63 |
-
|
64 |
-
<div id="post-body">
|
65 |
-
<div id="post-body-content">
|
66 |
-
<div class="postbox">
|
67 |
-
<h3><span>WP-Members <?php _e( 'Dialogs and Error Messages', 'wp-members' ); ?></span></h3>
|
68 |
-
<div class="inside">
|
69 |
-
<p><?php printf( __( 'You can customize the text for dialogs and error messages. Simple HTML is allowed %s etc.', 'wp-members' ), '- <p>, <b>, <i>,' ); ?></p>
|
70 |
-
<form name="updatedialogform" id="updatedialogform" method="post" action="<?php echo esc_url( wpmem_admin_form_post_url() ); ?>">
|
71 |
-
<?php wp_nonce_field( 'wpmem-update-dialogs' ); ?>
|
72 |
-
<table class="form-table">
|
73 |
-
<?php if ( ! empty ( $wpmem->admin->dialogs ) ) {
|
74 |
-
foreach( $wpmem->admin->dialogs as $dialog ) {
|
75 |
-
$wpmem->admin->do_dialog_input( $dialog );
|
76 |
-
}
|
77 |
-
} ?>
|
78 |
-
<?php $wpmem_tos = stripslashes( get_option( 'wpmembers_tos' ) ); ?>
|
79 |
-
<tr valign="top">
|
80 |
-
<th scope="row"><?php _e( 'Terms of Service (TOS)', 'wp-members' ); ?></th>
|
81 |
-
<td><textarea name="dialogs_tos" rows="3" cols="50" id="" class="large-text code"><?php echo esc_textarea( $wpmem_tos ); ?></textarea></td>
|
82 |
-
</tr>
|
83 |
-
<tr valign="top">
|
84 |
-
<th scope="row"> </th>
|
85 |
-
<td>
|
86 |
-
<input type="hidden" name="wpmem_admin_a" value="update_dialogs" />
|
87 |
-
<?php submit_button( __( 'Update Dialogs', 'wp-members' ) ); ?>
|
88 |
-
</td>
|
89 |
-
</tr>
|
90 |
-
</table>
|
91 |
-
</form>
|
92 |
-
</div><!-- .inside -->
|
93 |
-
</div><!-- #post-box -->
|
94 |
-
</div><!-- #post-body-content -->
|
95 |
-
</div><!-- #post-body -->
|
96 |
-
</div> <!-- .metabox-holder -->
|
97 |
-
<?php
|
98 |
-
}
|
99 |
-
|
100 |
-
|
101 |
-
/**
|
102 |
-
* Updates the dialog settings.
|
103 |
-
*
|
104 |
-
* @since 2.8.0
|
105 |
-
* @since 3.3.0 Ported from wpmem_update_dialogs().
|
106 |
-
*
|
107 |
-
* @global object $wpmem
|
108 |
-
* @return string The dialogs updated message.
|
109 |
-
*/
|
110 |
-
static function update() {
|
111 |
-
|
112 |
-
global $wpmem;
|
113 |
-
|
114 |
-
// Check nonce.
|
115 |
-
check_admin_referer( 'wpmem-update-dialogs' );
|
116 |
-
|
117 |
-
if ( ! empty ( $wpmem->admin->dialogs ) ) {
|
118 |
-
$wpmem->admin->dialog_update();
|
119 |
-
}
|
120 |
-
|
121 |
-
// Terms of Service.
|
122 |
-
update_option( 'wpmembers_tos', wp_kses( $_POST['dialogs_tos'], 'post' ) );
|
123 |
-
|
124 |
-
return __( 'WP-Members dialogs were updated', 'wp-members' );
|
125 |
-
}
|
126 |
-
|
127 |
} // End of file.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members Admin functions
|
4 |
+
*
|
5 |
+
* Static functions to manage the dialogs tab.
|
6 |
+
*
|
7 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
+
* Copyright (c) 2006-2020 Chad Butler
|
10 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
+
*
|
12 |
+
* @package WP-Members
|
13 |
+
* @author Chad Butler
|
14 |
+
* @copyright 2006-2020
|
15 |
+
*/
|
16 |
+
|
17 |
+
// Exit if accessed directly.
|
18 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
19 |
+
exit();
|
20 |
+
}
|
21 |
+
|
22 |
+
class WP_Members_Admin_Tab_Dialogs {
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Creates the tab.
|
26 |
+
*
|
27 |
+
* @since 3.2.0
|
28 |
+
* @since 3.3.0 Ported from wpmem_a_dialogs_tab().
|
29 |
+
*
|
30 |
+
* @param string $tab The admin tab being displayed.
|
31 |
+
* @return string|bool The tab html, otherwise false.
|
32 |
+
*/
|
33 |
+
static function do_tab( $tab ) {
|
34 |
+
if ( $tab == 'dialogs' || ! $tab ) {
|
35 |
+
// Render the tab.
|
36 |
+
return self::build_settings();
|
37 |
+
} else {
|
38 |
+
return false;
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Builds the dialogs panel.
|
44 |
+
*
|
45 |
+
* @since 2.2.2
|
46 |
+
* @since 3.3.0 Ported from wpmem_a_build_dialogs().
|
47 |
+
*
|
48 |
+
* @global object $wpmem
|
49 |
+
*/
|
50 |
+
static function build_settings() {
|
51 |
+
global $wpmem; ?>
|
52 |
+
<div class="metabox-holder has-right-sidebar">
|
53 |
+
|
54 |
+
<div class="inner-sidebar">
|
55 |
+
<?php wpmem_a_meta_box(); ?>
|
56 |
+
<div class="postbox">
|
57 |
+
<h3><span><?php _e( 'Need help?', 'wp-members' ); ?></span></h3>
|
58 |
+
<div class="inside">
|
59 |
+
<strong><i>See the <a href="https://rocketgeek.com/plugins/wp-members/users-guide/plugin-settings/dialogs/" target="_blank">Users Guide on dialogs</a>.</i></strong>
|
60 |
+
</div>
|
61 |
+
</div>
|
62 |
+
</div> <!-- .inner-sidebar -->
|
63 |
+
|
64 |
+
<div id="post-body">
|
65 |
+
<div id="post-body-content">
|
66 |
+
<div class="postbox">
|
67 |
+
<h3><span>WP-Members <?php _e( 'Dialogs and Error Messages', 'wp-members' ); ?></span></h3>
|
68 |
+
<div class="inside">
|
69 |
+
<p><?php printf( __( 'You can customize the text for dialogs and error messages. Simple HTML is allowed %s etc.', 'wp-members' ), '- <p>, <b>, <i>,' ); ?></p>
|
70 |
+
<form name="updatedialogform" id="updatedialogform" method="post" action="<?php echo esc_url( wpmem_admin_form_post_url() ); ?>">
|
71 |
+
<?php wp_nonce_field( 'wpmem-update-dialogs' ); ?>
|
72 |
+
<table class="form-table">
|
73 |
+
<?php if ( ! empty ( $wpmem->admin->dialogs ) ) {
|
74 |
+
foreach( $wpmem->admin->dialogs as $dialog ) {
|
75 |
+
$wpmem->admin->do_dialog_input( $dialog );
|
76 |
+
}
|
77 |
+
} ?>
|
78 |
+
<?php $wpmem_tos = stripslashes( get_option( 'wpmembers_tos' ) ); ?>
|
79 |
+
<tr valign="top">
|
80 |
+
<th scope="row"><?php _e( 'Terms of Service (TOS)', 'wp-members' ); ?></th>
|
81 |
+
<td><textarea name="dialogs_tos" rows="3" cols="50" id="" class="large-text code"><?php echo esc_textarea( $wpmem_tos ); ?></textarea></td>
|
82 |
+
</tr>
|
83 |
+
<tr valign="top">
|
84 |
+
<th scope="row"> </th>
|
85 |
+
<td>
|
86 |
+
<input type="hidden" name="wpmem_admin_a" value="update_dialogs" />
|
87 |
+
<?php submit_button( __( 'Update Dialogs', 'wp-members' ) ); ?>
|
88 |
+
</td>
|
89 |
+
</tr>
|
90 |
+
</table>
|
91 |
+
</form>
|
92 |
+
</div><!-- .inside -->
|
93 |
+
</div><!-- #post-box -->
|
94 |
+
</div><!-- #post-body-content -->
|
95 |
+
</div><!-- #post-body -->
|
96 |
+
</div> <!-- .metabox-holder -->
|
97 |
+
<?php
|
98 |
+
}
|
99 |
+
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Updates the dialog settings.
|
103 |
+
*
|
104 |
+
* @since 2.8.0
|
105 |
+
* @since 3.3.0 Ported from wpmem_update_dialogs().
|
106 |
+
*
|
107 |
+
* @global object $wpmem
|
108 |
+
* @return string The dialogs updated message.
|
109 |
+
*/
|
110 |
+
static function update() {
|
111 |
+
|
112 |
+
global $wpmem;
|
113 |
+
|
114 |
+
// Check nonce.
|
115 |
+
check_admin_referer( 'wpmem-update-dialogs' );
|
116 |
+
|
117 |
+
if ( ! empty ( $wpmem->admin->dialogs ) ) {
|
118 |
+
$wpmem->admin->dialog_update();
|
119 |
+
}
|
120 |
+
|
121 |
+
// Terms of Service.
|
122 |
+
update_option( 'wpmembers_tos', wp_kses( $_POST['dialogs_tos'], 'post' ) );
|
123 |
+
|
124 |
+
return __( 'WP-Members dialogs were updated', 'wp-members' );
|
125 |
+
}
|
126 |
+
|
127 |
} // End of file.
|
includes/admin/tabs/class-wp-members-admin-tab-dropins.php
CHANGED
@@ -1,231 +1,231 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members Admin functions
|
4 |
-
*
|
5 |
-
* Static functions to manage the plugin dropins tab.
|
6 |
-
*
|
7 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
-
* Copyright (c) 2006-
|
10 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
-
*
|
12 |
-
* @package WP-Members
|
13 |
-
* @author Chad Butler
|
14 |
-
* @copyright 2006-
|
15 |
-
*/
|
16 |
-
|
17 |
-
// Exit if accessed directly.
|
18 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
19 |
-
exit();
|
20 |
-
}
|
21 |
-
|
22 |
-
class WP_Members_Admin_Tab_Dropins {
|
23 |
-
|
24 |
-
function __construct() {
|
25 |
-
self::load_dependencies();
|
26 |
-
}
|
27 |
-
|
28 |
-
public static function load_dependencies() {
|
29 |
-
/**
|
30 |
-
* Load WP_Members_Fields_Table object
|
31 |
-
*/
|
32 |
-
if ( ! class_exists( 'WP_List_Table' ) ) {
|
33 |
-
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
34 |
-
}
|
35 |
-
}
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Display the Dropins tab.
|
39 |
-
*
|
40 |
-
* @since 3.1.9
|
41 |
-
*
|
42 |
-
* @global $wpmem
|
43 |
-
*/
|
44 |
-
public static function render_tab() { ?>
|
45 |
-
<div class="wrap">
|
46 |
-
<?php
|
47 |
-
|
48 |
-
global $wpmem;
|
49 |
-
|
50 |
-
// Get old settings to see if they are being updated.
|
51 |
-
$old_settings = get_option( 'wpmembers_dropins' );
|
52 |
-
|
53 |
-
// Update settings.
|
54 |
-
$wpmem_dropins_saved = false;
|
55 |
-
if ( ( isset( $_GET['tab'] ) && $_GET['tab'] == 'dropins' ) && isset( $_POST['wpmembers_dropins'] ) ) {
|
56 |
-
$settings = array();
|
57 |
-
$post_vals = wpmem_get( 'wpmembers_dropins', false );
|
58 |
-
if ( $post_vals ) {
|
59 |
-
foreach ( $post_vals as $key => $val ) {
|
60 |
-
// Check against default strings. Only save if different.
|
61 |
-
if ( html_entity_decode( wpmem_gettext( $key ) ) != html_entity_decode( $val ) ) {
|
62 |
-
$settings['text'][ $key ] = $val;
|
63 |
-
} else {
|
64 |
-
if ( ! empty( $old_settings['text'] ) && array_key_exists( $key, $old_settings['text'] ) ) {
|
65 |
-
$settings['text'][ $key ] = $val;
|
66 |
-
}
|
67 |
-
}
|
68 |
-
}
|
69 |
-
// Double check settings for defaults.
|
70 |
-
foreach ( $settings['text'] as $k => $v ) {
|
71 |
-
if ( wpmem_gettext( $k ) == $v ) {
|
72 |
-
unset( $settings['text'][ $k ] );
|
73 |
-
}
|
74 |
-
}
|
75 |
-
}
|
76 |
-
|
77 |
-
// If there are any changes, update settings.
|
78 |
-
if ( ! empty( $settings ) ) {
|
79 |
-
update_option( 'wpmembers_dropins', $settings );
|
80 |
-
} else {
|
81 |
-
// Delete if empty.
|
82 |
-
delete_option( 'wpmembers_dropins' );
|
83 |
-
}
|
84 |
-
|
85 |
-
$wpmem_dropins_saved = true;
|
86 |
-
}
|
87 |
-
if ( $wpmem_dropins_saved ) { ?>
|
88 |
-
<div id="message" class="message"><p><strong><?php _e( 'WP-Members Dropin settings were updated', 'wp-members' ); ?></strong></p></div>
|
89 |
-
<?php } ?>
|
90 |
-
|
91 |
-
<?php
|
92 |
-
}
|
93 |
-
|
94 |
-
/**
|
95 |
-
* Adds Dropins Tab to the admin tab array.
|
96 |
-
*
|
97 |
-
* @since 3.1.9
|
98 |
-
*
|
99 |
-
* @param array $tabs The WP-Members admin panel tabs array.
|
100 |
-
*/
|
101 |
-
public static function add_tab( $tabs ) {
|
102 |
-
return array_merge(
|
103 |
-
array_slice( $tabs, 0, 1 ),
|
104 |
-
array( 'dropins' => 'Dropins' ),
|
105 |
-
array_slice( $tabs, 1 )
|
106 |
-
);
|
107 |
-
}
|
108 |
-
|
109 |
-
/**
|
110 |
-
* Builds the Dropins tab in the admin.
|
111 |
-
*
|
112 |
-
* @since 3.1.9
|
113 |
-
*
|
114 |
-
* @param string $tab The WP-Members admin panel tab being displayed.
|
115 |
-
*/
|
116 |
-
public static function do_tab( $tab ) {
|
117 |
-
if ( $tab == 'dropins' ) {
|
118 |
-
self::do_table();
|
119 |
-
}
|
120 |
-
return;
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* Check dropins directory.
|
125 |
-
*
|
126 |
-
* @since 3.1.9
|
127 |
-
*
|
128 |
-
* @return boolean
|
129 |
-
*/
|
130 |
-
public static function check_dir() {
|
131 |
-
|
132 |
-
/** This filter is documented in inc/class-wp-members.php */
|
133 |
-
$dir = apply_filters( 'wpmem_dropin_dir', $wpmem->dropin_dir );
|
134 |
-
$check = false;
|
135 |
-
if ( file_exists( $dir ) ) {
|
136 |
-
$file = $dir . '.htaccess';
|
137 |
-
if ( ! file_exists ( $file ) ) {
|
138 |
-
$check = self::create_htaccess( $file );
|
139 |
-
} else {
|
140 |
-
$handle = fopen( $file, "r" );
|
141 |
-
if ( $handle ) {
|
142 |
-
// Read file line-by-line
|
143 |
-
while ( ( $buffer = fgets( $handle ) ) !== false ) {
|
144 |
-
if ( strpos( $buffer, "Options -Indexes" ) !== false )
|
145 |
-
$check = true;
|
146 |
-
break;
|
147 |
-
}
|
148 |
-
}
|
149 |
-
fclose( $handle );
|
150 |
-
$check = ( false === $check ) ? self::create_htaccess( $file ) : $check;
|
151 |
-
}
|
152 |
-
}
|
153 |
-
return $check;
|
154 |
-
}
|
155 |
-
|
156 |
-
/**
|
157 |
-
* Creates .htaccess in dropins directory if none exists.
|
158 |
-
*
|
159 |
-
* @since 3.1.9
|
160 |
-
*
|
161 |
-
* @param string
|
162 |
-
* @return boolean
|
163 |
-
*/
|
164 |
-
public static function create_htaccess( $file ) {
|
165 |
-
$handle = fopen( $file, "w" );
|
166 |
-
fwrite( $handle, "Options -Indexes" );
|
167 |
-
fclose( $handle );
|
168 |
-
return ( $handle ) ? true : false;
|
169 |
-
}
|
170 |
-
|
171 |
-
/**
|
172 |
-
* Function to display the table of fields in the field manager tab.
|
173 |
-
*
|
174 |
-
* @since 3.1.9
|
175 |
-
*
|
176 |
-
* @global object $wpmem
|
177 |
-
*/
|
178 |
-
public static function do_table() {
|
179 |
-
global $wpmem;
|
180 |
-
|
181 |
-
// Get the dropin folder.
|
182 |
-
/** This filter is documented in inc/class-wp-members.php */
|
183 |
-
$folder = apply_filters( 'wpmem_dropin_folder', $wpmem->dropin_dir );
|
184 |
-
|
185 |
-
// Set file headers for dropins.
|
186 |
-
$headers = array(
|
187 |
-
'Dropin Name' => 'Dropin Name',
|
188 |
-
'Dropin Description' => 'Dropin Description',
|
189 |
-
'Version' => 'Version',
|
190 |
-
);
|
191 |
-
|
192 |
-
// Array container for dropin file info.
|
193 |
-
$field_items = array();
|
194 |
-
|
195 |
-
// Parse dropins.
|
196 |
-
foreach ( glob( $folder . '*.php' ) as $filename ) {
|
197 |
-
$file_data = get_file_data( $filename, $headers );
|
198 |
-
|
199 |
-
$filename = explode( '/', $filename );
|
200 |
-
$filename = end( $filename );
|
201 |
-
if ( ! empty( $file_data['Dropin Name'] ) ) {
|
202 |
-
$field_items[] = array(
|
203 |
-
'dropin_enabled' => '',
|
204 |
-
'dropin_name' => $file_data['Dropin Name'],
|
205 |
-
'dropin_file' => $filename,
|
206 |
-
'dropin_version' => $file_data['Version'],
|
207 |
-
'dropin_description' => $file_data['Dropin Description'],
|
208 |
-
);
|
209 |
-
}
|
210 |
-
}
|
211 |
-
|
212 |
-
// Set up table.
|
213 |
-
include_once( $wpmem->path . 'includes/admin/tabs/class-wp-members-dropins-table.php' );
|
214 |
-
$table = new WP_Members_Dropins_Table();
|
215 |
-
|
216 |
-
$heading = __( 'Manage Dropins', 'wp-members' );
|
217 |
-
$loc_info = __( 'Current dropin folder: ', 'wp-members' );
|
218 |
-
$loc_desc = __( 'You can change location of the dropin folder using the <code>wpmem_dropin_folder</code> filter.', 'wp-members' );
|
219 |
-
echo '<div class="wrap">';
|
220 |
-
printf( '<h3 class="title">%s</h3>', $heading );
|
221 |
-
printf( '<p><strong>%s</strong></p>', $loc_info );
|
222 |
-
printf( '<p>%s</p>', $loc_desc );
|
223 |
-
printf( '<form name="updatedropinsform" id="updatedropinsform" method="post" action="%s">', wpmem_admin_form_post_url() );
|
224 |
-
$table->items = $field_items;
|
225 |
-
$table->prepare_items();
|
226 |
-
$table->display();
|
227 |
-
echo '</form>';
|
228 |
-
echo '</div>';
|
229 |
-
}
|
230 |
-
|
231 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members Admin functions
|
4 |
+
*
|
5 |
+
* Static functions to manage the plugin dropins tab.
|
6 |
+
*
|
7 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
+
* Copyright (c) 2006-2020 Chad Butler
|
10 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
+
*
|
12 |
+
* @package WP-Members
|
13 |
+
* @author Chad Butler
|
14 |
+
* @copyright 2006-2020
|
15 |
+
*/
|
16 |
+
|
17 |
+
// Exit if accessed directly.
|
18 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
19 |
+
exit();
|
20 |
+
}
|
21 |
+
|
22 |
+
class WP_Members_Admin_Tab_Dropins {
|
23 |
+
|
24 |
+
function __construct() {
|
25 |
+
self::load_dependencies();
|
26 |
+
}
|
27 |
+
|
28 |
+
public static function load_dependencies() {
|
29 |
+
/**
|
30 |
+
* Load WP_Members_Fields_Table object
|
31 |
+
*/
|
32 |
+
if ( ! class_exists( 'WP_List_Table' ) ) {
|
33 |
+
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Display the Dropins tab.
|
39 |
+
*
|
40 |
+
* @since 3.1.9
|
41 |
+
*
|
42 |
+
* @global $wpmem
|
43 |
+
*/
|
44 |
+
public static function render_tab() { ?>
|
45 |
+
<div class="wrap">
|
46 |
+
<?php
|
47 |
+
|
48 |
+
global $wpmem;
|
49 |
+
|
50 |
+
// Get old settings to see if they are being updated.
|
51 |
+
$old_settings = get_option( 'wpmembers_dropins' );
|
52 |
+
|
53 |
+
// Update settings.
|
54 |
+
$wpmem_dropins_saved = false;
|
55 |
+
if ( ( isset( $_GET['tab'] ) && $_GET['tab'] == 'dropins' ) && isset( $_POST['wpmembers_dropins'] ) ) {
|
56 |
+
$settings = array();
|
57 |
+
$post_vals = wpmem_get( 'wpmembers_dropins', false );
|
58 |
+
if ( $post_vals ) {
|
59 |
+
foreach ( $post_vals as $key => $val ) {
|
60 |
+
// Check against default strings. Only save if different.
|
61 |
+
if ( html_entity_decode( wpmem_gettext( $key ) ) != html_entity_decode( $val ) ) {
|
62 |
+
$settings['text'][ $key ] = $val;
|
63 |
+
} else {
|
64 |
+
if ( ! empty( $old_settings['text'] ) && array_key_exists( $key, $old_settings['text'] ) ) {
|
65 |
+
$settings['text'][ $key ] = $val;
|
66 |
+
}
|
67 |
+
}
|
68 |
+
}
|
69 |
+
// Double check settings for defaults.
|
70 |
+
foreach ( $settings['text'] as $k => $v ) {
|
71 |
+
if ( wpmem_gettext( $k ) == $v ) {
|
72 |
+
unset( $settings['text'][ $k ] );
|
73 |
+
}
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
// If there are any changes, update settings.
|
78 |
+
if ( ! empty( $settings ) ) {
|
79 |
+
update_option( 'wpmembers_dropins', $settings );
|
80 |
+
} else {
|
81 |
+
// Delete if empty.
|
82 |
+
delete_option( 'wpmembers_dropins' );
|
83 |
+
}
|
84 |
+
|
85 |
+
$wpmem_dropins_saved = true;
|
86 |
+
}
|
87 |
+
if ( $wpmem_dropins_saved ) { ?>
|
88 |
+
<div id="message" class="message"><p><strong><?php _e( 'WP-Members Dropin settings were updated', 'wp-members' ); ?></strong></p></div>
|
89 |
+
<?php } ?>
|
90 |
+
|
91 |
+
<?php
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Adds Dropins Tab to the admin tab array.
|
96 |
+
*
|
97 |
+
* @since 3.1.9
|
98 |
+
*
|
99 |
+
* @param array $tabs The WP-Members admin panel tabs array.
|
100 |
+
*/
|
101 |
+
public static function add_tab( $tabs ) {
|
102 |
+
return array_merge(
|
103 |
+
array_slice( $tabs, 0, 1 ),
|
104 |
+
array( 'dropins' => 'Dropins' ),
|
105 |
+
array_slice( $tabs, 1 )
|
106 |
+
);
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Builds the Dropins tab in the admin.
|
111 |
+
*
|
112 |
+
* @since 3.1.9
|
113 |
+
*
|
114 |
+
* @param string $tab The WP-Members admin panel tab being displayed.
|
115 |
+
*/
|
116 |
+
public static function do_tab( $tab ) {
|
117 |
+
if ( $tab == 'dropins' ) {
|
118 |
+
self::do_table();
|
119 |
+
}
|
120 |
+
return;
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Check dropins directory.
|
125 |
+
*
|
126 |
+
* @since 3.1.9
|
127 |
+
*
|
128 |
+
* @return boolean
|
129 |
+
*/
|
130 |
+
public static function check_dir() {
|
131 |
+
|
132 |
+
/** This filter is documented in inc/class-wp-members.php */
|
133 |
+
$dir = apply_filters( 'wpmem_dropin_dir', $wpmem->dropin_dir );
|
134 |
+
$check = false;
|
135 |
+
if ( file_exists( $dir ) ) {
|
136 |
+
$file = $dir . '.htaccess';
|
137 |
+
if ( ! file_exists ( $file ) ) {
|
138 |
+
$check = self::create_htaccess( $file );
|
139 |
+
} else {
|
140 |
+
$handle = fopen( $file, "r" );
|
141 |
+
if ( $handle ) {
|
142 |
+
// Read file line-by-line
|
143 |
+
while ( ( $buffer = fgets( $handle ) ) !== false ) {
|
144 |
+
if ( strpos( $buffer, "Options -Indexes" ) !== false )
|
145 |
+
$check = true;
|
146 |
+
break;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
fclose( $handle );
|
150 |
+
$check = ( false === $check ) ? self::create_htaccess( $file ) : $check;
|
151 |
+
}
|
152 |
+
}
|
153 |
+
return $check;
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Creates .htaccess in dropins directory if none exists.
|
158 |
+
*
|
159 |
+
* @since 3.1.9
|
160 |
+
*
|
161 |
+
* @param string
|
162 |
+
* @return boolean
|
163 |
+
*/
|
164 |
+
public static function create_htaccess( $file ) {
|
165 |
+
$handle = fopen( $file, "w" );
|
166 |
+
fwrite( $handle, "Options -Indexes" );
|
167 |
+
fclose( $handle );
|
168 |
+
return ( $handle ) ? true : false;
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Function to display the table of fields in the field manager tab.
|
173 |
+
*
|
174 |
+
* @since 3.1.9
|
175 |
+
*
|
176 |
+
* @global object $wpmem
|
177 |
+
*/
|
178 |
+
public static function do_table() {
|
179 |
+
global $wpmem;
|
180 |
+
|
181 |
+
// Get the dropin folder.
|
182 |
+
/** This filter is documented in inc/class-wp-members.php */
|
183 |
+
$folder = apply_filters( 'wpmem_dropin_folder', $wpmem->dropin_dir );
|
184 |
+
|
185 |
+
// Set file headers for dropins.
|
186 |
+
$headers = array(
|
187 |
+
'Dropin Name' => 'Dropin Name',
|
188 |
+
'Dropin Description' => 'Dropin Description',
|
189 |
+
'Version' => 'Version',
|
190 |
+
);
|
191 |
+
|
192 |
+
// Array container for dropin file info.
|
193 |
+
$field_items = array();
|
194 |
+
|
195 |
+
// Parse dropins.
|
196 |
+
foreach ( glob( $folder . '*.php' ) as $filename ) {
|
197 |
+
$file_data = get_file_data( $filename, $headers );
|
198 |
+
|
199 |
+
$filename = explode( '/', $filename );
|
200 |
+
$filename = end( $filename );
|
201 |
+
if ( ! empty( $file_data['Dropin Name'] ) ) {
|
202 |
+
$field_items[] = array(
|
203 |
+
'dropin_enabled' => '',
|
204 |
+
'dropin_name' => $file_data['Dropin Name'],
|
205 |
+
'dropin_file' => $filename,
|
206 |
+
'dropin_version' => $file_data['Version'],
|
207 |
+
'dropin_description' => $file_data['Dropin Description'],
|
208 |
+
);
|
209 |
+
}
|
210 |
+
}
|
211 |
+
|
212 |
+
// Set up table.
|
213 |
+
include_once( $wpmem->path . 'includes/admin/tabs/class-wp-members-dropins-table.php' );
|
214 |
+
$table = new WP_Members_Dropins_Table();
|
215 |
+
|
216 |
+
$heading = __( 'Manage Dropins', 'wp-members' );
|
217 |
+
$loc_info = __( 'Current dropin folder: ', 'wp-members' );
|
218 |
+
$loc_desc = __( 'You can change location of the dropin folder using the <code>wpmem_dropin_folder</code> filter.', 'wp-members' );
|
219 |
+
echo '<div class="wrap">';
|
220 |
+
printf( '<h3 class="title">%s</h3>', $heading );
|
221 |
+
printf( '<p><strong>%s</strong></p>', $loc_info );
|
222 |
+
printf( '<p>%s</p>', $loc_desc );
|
223 |
+
printf( '<form name="updatedropinsform" id="updatedropinsform" method="post" action="%s">', wpmem_admin_form_post_url() );
|
224 |
+
$table->items = $field_items;
|
225 |
+
$table->prepare_items();
|
226 |
+
$table->display();
|
227 |
+
echo '</form>';
|
228 |
+
echo '</div>';
|
229 |
+
}
|
230 |
+
|
231 |
}
|
includes/admin/tabs/class-wp-members-admin-tab-emails.php
CHANGED
@@ -1,165 +1,165 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members Admin Functions
|
4 |
-
*
|
5 |
-
* Functions to manage the emails tab.
|
6 |
-
*
|
7 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
-
* Copyright (c) 2006-
|
10 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
-
*
|
12 |
-
* @package WP-Members
|
13 |
-
* @author Chad Butler
|
14 |
-
* @copyright 2006-
|
15 |
-
*/
|
16 |
-
|
17 |
-
// Exit if accessed directly.
|
18 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
19 |
-
exit();
|
20 |
-
}
|
21 |
-
|
22 |
-
class WP_Members_Admin_Tab_Emails {
|
23 |
-
/**
|
24 |
-
* Creates the tab.
|
25 |
-
*
|
26 |
-
* @since 3.2.0
|
27 |
-
* @since 3.3.0 Ported from wpmem_a_emails_tab().
|
28 |
-
*
|
29 |
-
* @param string $tab The admin tab being displayed.
|
30 |
-
* @return string|bool The tab html, otherwise false.
|
31 |
-
*/
|
32 |
-
static function do_tab( $tab ) {
|
33 |
-
if ( $tab == 'emails' || ! $tab ) {
|
34 |
-
// Render the tab.
|
35 |
-
return self::build_settings();
|
36 |
-
} else {
|
37 |
-
return false;
|
38 |
-
}
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Builds the emails panel.
|
43 |
-
*
|
44 |
-
* @since 2.7.0
|
45 |
-
* @since 3.3.0 Ported wpmem_a_build_emails().
|
46 |
-
*
|
47 |
-
* @global object $wpmem
|
48 |
-
*/
|
49 |
-
static function build_settings() {
|
50 |
-
|
51 |
-
global $wpmem; ?>
|
52 |
-
<div class="metabox-holder">
|
53 |
-
|
54 |
-
<div id="post-body">
|
55 |
-
<div id="post-body-content">
|
56 |
-
<div class="postbox">
|
57 |
-
<h3><span>WP-Members <?php _e( 'Email Messages', 'wp-members' ); ?></span></h3>
|
58 |
-
<div class="inside">
|
59 |
-
<p>
|
60 |
-
<?php _e( 'You can customize the content of the emails sent by the plugin.', 'wp-members' ); ?><br />
|
61 |
-
<a href="https://rocketgeek.com/plugins/wp-members/users-guide/customizing-emails/" target="_blank">
|
62 |
-
<?php _e( 'A list of shortcodes is available here.', 'wp-members' ); ?></a>
|
63 |
-
</p>
|
64 |
-
<hr />
|
65 |
-
<form name="updateemailform" id="updateemailform" method="post" action="<?php echo esc_url( wpmem_admin_form_post_url() ); ?>">
|
66 |
-
<?php wp_nonce_field( 'wpmem-update-emails' ); ?>
|
67 |
-
<table class="form-table">
|
68 |
-
<tr valign="top">
|
69 |
-
<th scope="row"><?php _e( 'Set a custom email address', 'wp-members' ); ?></th>
|
70 |
-
<td><input type="text" name="wp_mail_from" size="40" value="<?php echo esc_attr( $wpmem->email->from ); ?>" /> <span class="description"><?php _e( '(optional)', 'wp-members' ); ?> email@yourdomain.com</span></td>
|
71 |
-
</tr>
|
72 |
-
<tr valign="top">
|
73 |
-
<th scope="row"><?php _e( 'Set a custom email name', 'wp-members' ); ?></th>
|
74 |
-
<td><input type="text" name="wp_mail_from_name" size="40" value="<?php echo esc_attr( stripslashes( $wpmem->email->from_name ) ); ?>" /> <span class="description"><?php _e( '(optional)', 'wp-members' ); ?> John Smith</span></td>
|
75 |
-
</tr>
|
76 |
-
<tr><td colspan="2"><hr /></td></tr>
|
77 |
-
<?php if ( ! empty ( $wpmem->admin->emails ) ) {
|
78 |
-
foreach( $wpmem->admin->emails as $email ) {
|
79 |
-
$wpmem->admin->do_email_input( $email );
|
80 |
-
}
|
81 |
-
}
|
82 |
-
$arr = get_option( 'wpmembers_email_footer' ); ?>
|
83 |
-
<tr valign="top">
|
84 |
-
<th scope="row"><strong><?php echo __( "Email Signature", 'wp-members' ); ?></strong> <span class="description"><?php _e( '(optional)', 'wp-members' ); ?></span></th>
|
85 |
-
<td><textarea name="<?php echo 'wpmembers_email_footer_body'; ?>" rows="10" cols="50" id="" class="large-text code"><?php echo esc_textarea( stripslashes( $arr ) ); ?></textarea></td>
|
86 |
-
</tr>
|
87 |
-
<tr><td colspan="2"><hr /></td></tr>
|
88 |
-
<tr valign="top">
|
89 |
-
<th scope="row"> </th>
|
90 |
-
<td>
|
91 |
-
<input type="hidden" name="wpmem_admin_a" value="update_emails" />
|
92 |
-
<?php submit_button( __( 'Update Emails', 'wp-members' ) ); ?>
|
93 |
-
</td>
|
94 |
-
</tr>
|
95 |
-
</table>
|
96 |
-
</form>
|
97 |
-
</div><!-- .inside -->
|
98 |
-
</div><!-- #post-box -->
|
99 |
-
<div class="postbox">
|
100 |
-
<h3><span><?php _e( 'Need help?', 'wp-members' ); ?></span></h3>
|
101 |
-
<div class="inside">
|
102 |
-
<strong><i>See the <a href="https://rocketgeek.com/plugins/wp-members/users-guide/plugin-settings/emails/" target="_blank">Users Guide on email options</a>.</i></strong>
|
103 |
-
</div>
|
104 |
-
</div>
|
105 |
-
</div> <!-- #post-body-content -->
|
106 |
-
</div><!-- #post-body -->
|
107 |
-
</div><!-- .metabox-holder -->
|
108 |
-
<?php
|
109 |
-
}
|
110 |
-
|
111 |
-
|
112 |
-
/**
|
113 |
-
* Updates the email message settings.
|
114 |
-
*
|
115 |
-
* @since 2.8.0
|
116 |
-
* @since 3.3.0 Ported from wpmem_update_emails().
|
117 |
-
*
|
118 |
-
* @global object $wpmem The WP_Members object class.
|
119 |
-
* @return string The emails updated message.
|
120 |
-
*/
|
121 |
-
static function update() {
|
122 |
-
|
123 |
-
global $wpmem;
|
124 |
-
|
125 |
-
// Check nonce.
|
126 |
-
check_admin_referer( 'wpmem-update-emails' );
|
127 |
-
|
128 |
-
// Update the email address (if applicable).
|
129 |
-
if ( $wpmem->email->from != $_POST['wp_mail_from'] || $wpmem->email->from_name != $_POST['wp_mail_from_name'] ) {
|
130 |
-
$wpmem->email->from = sanitize_email( $_POST['wp_mail_from'] );
|
131 |
-
$wpmem->email->from_name = sanitize_text_field( $_POST['wp_mail_from_name'] );
|
132 |
-
update_option( 'wpmembers_email_wpfrom', $wpmem->email->from );
|
133 |
-
update_option( 'wpmembers_email_wpname', $wpmem->email->from_name );
|
134 |
-
}
|
135 |
-
|
136 |
-
// Update the various emails being used.
|
137 |
-
( $wpmem->mod_reg == 0 ) ? $arr = array( 'wpmembers_email_newreg' ) : $arr = array( 'wpmembers_email_newmod', 'wpmembers_email_appmod' );
|
138 |
-
array_push( $arr, 'wpmembers_email_repass' );
|
139 |
-
array_push( $arr, 'wpmembers_email_getuser' );
|
140 |
-
( $wpmem->notify == 1 ) ? array_push( $arr, 'wpmembers_email_notify' ) : false;
|
141 |
-
array_push( $arr, 'wpmembers_email_footer' );
|
142 |
-
|
143 |
-
for ( $row = 0; $row < ( count( $arr ) - 1 ); $row++ ) {
|
144 |
-
$arr2 = array(
|
145 |
-
"subj" => sanitize_text_field( $_POST[ $arr[ $row ] . '_subj' ] ),
|
146 |
-
"body" => wp_kses( $_POST[ $arr[ $row ] . '_body' ], 'post' ),
|
147 |
-
);
|
148 |
-
update_option( $arr[ $row ], $arr2, false );
|
149 |
-
$arr2 = '';
|
150 |
-
}
|
151 |
-
|
152 |
-
// Updated the email footer.
|
153 |
-
update_option( $arr[ $row ], wp_kses( $_POST[ $arr[ $row ] . '_body' ], 'post' ), false );
|
154 |
-
|
155 |
-
if ( ! empty ( $wpmem->admin->emails ) ) {
|
156 |
-
foreach( $wpmem->admin->emails as $email ) {
|
157 |
-
$wpmem->admin->email_update( $email );
|
158 |
-
}
|
159 |
-
}
|
160 |
-
|
161 |
-
return __( 'WP-Members emails were updated', 'wp-members' );
|
162 |
-
|
163 |
-
}
|
164 |
-
|
165 |
} // End of file.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members Admin Functions
|
4 |
+
*
|
5 |
+
* Functions to manage the emails tab.
|
6 |
+
*
|
7 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
+
* Copyright (c) 2006-2020 Chad Butler
|
10 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
+
*
|
12 |
+
* @package WP-Members
|
13 |
+
* @author Chad Butler
|
14 |
+
* @copyright 2006-2020
|
15 |
+
*/
|
16 |
+
|
17 |
+
// Exit if accessed directly.
|
18 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
19 |
+
exit();
|
20 |
+
}
|
21 |
+
|
22 |
+
class WP_Members_Admin_Tab_Emails {
|
23 |
+
/**
|
24 |
+
* Creates the tab.
|
25 |
+
*
|
26 |
+
* @since 3.2.0
|
27 |
+
* @since 3.3.0 Ported from wpmem_a_emails_tab().
|
28 |
+
*
|
29 |
+
* @param string $tab The admin tab being displayed.
|
30 |
+
* @return string|bool The tab html, otherwise false.
|
31 |
+
*/
|
32 |
+
static function do_tab( $tab ) {
|
33 |
+
if ( $tab == 'emails' || ! $tab ) {
|
34 |
+
// Render the tab.
|
35 |
+
return self::build_settings();
|
36 |
+
} else {
|
37 |
+
return false;
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Builds the emails panel.
|
43 |
+
*
|
44 |
+
* @since 2.7.0
|
45 |
+
* @since 3.3.0 Ported wpmem_a_build_emails().
|
46 |
+
*
|
47 |
+
* @global object $wpmem
|
48 |
+
*/
|
49 |
+
static function build_settings() {
|
50 |
+
|
51 |
+
global $wpmem; ?>
|
52 |
+
<div class="metabox-holder">
|
53 |
+
|
54 |
+
<div id="post-body">
|
55 |
+
<div id="post-body-content">
|
56 |
+
<div class="postbox">
|
57 |
+
<h3><span>WP-Members <?php _e( 'Email Messages', 'wp-members' ); ?></span></h3>
|
58 |
+
<div class="inside">
|
59 |
+
<p>
|
60 |
+
<?php _e( 'You can customize the content of the emails sent by the plugin.', 'wp-members' ); ?><br />
|
61 |
+
<a href="https://rocketgeek.com/plugins/wp-members/users-guide/customizing-emails/" target="_blank">
|
62 |
+
<?php _e( 'A list of shortcodes is available here.', 'wp-members' ); ?></a>
|
63 |
+
</p>
|
64 |
+
<hr />
|
65 |
+
<form name="updateemailform" id="updateemailform" method="post" action="<?php echo esc_url( wpmem_admin_form_post_url() ); ?>">
|
66 |
+
<?php wp_nonce_field( 'wpmem-update-emails' ); ?>
|
67 |
+
<table class="form-table">
|
68 |
+
<tr valign="top">
|
69 |
+
<th scope="row"><?php _e( 'Set a custom email address', 'wp-members' ); ?></th>
|
70 |
+
<td><input type="text" name="wp_mail_from" size="40" value="<?php echo esc_attr( $wpmem->email->from ); ?>" /> <span class="description"><?php _e( '(optional)', 'wp-members' ); ?> email@yourdomain.com</span></td>
|
71 |
+
</tr>
|
72 |
+
<tr valign="top">
|
73 |
+
<th scope="row"><?php _e( 'Set a custom email name', 'wp-members' ); ?></th>
|
74 |
+
<td><input type="text" name="wp_mail_from_name" size="40" value="<?php echo esc_attr( stripslashes( $wpmem->email->from_name ) ); ?>" /> <span class="description"><?php _e( '(optional)', 'wp-members' ); ?> John Smith</span></td>
|
75 |
+
</tr>
|
76 |
+
<tr><td colspan="2"><hr /></td></tr>
|
77 |
+
<?php if ( ! empty ( $wpmem->admin->emails ) ) {
|
78 |
+
foreach( $wpmem->admin->emails as $email ) {
|
79 |
+
$wpmem->admin->do_email_input( $email );
|
80 |
+
}
|
81 |
+
}
|
82 |
+
$arr = get_option( 'wpmembers_email_footer' ); ?>
|
83 |
+
<tr valign="top">
|
84 |
+
<th scope="row"><strong><?php echo __( "Email Signature", 'wp-members' ); ?></strong> <span class="description"><?php _e( '(optional)', 'wp-members' ); ?></span></th>
|
85 |
+
<td><textarea name="<?php echo 'wpmembers_email_footer_body'; ?>" rows="10" cols="50" id="" class="large-text code"><?php echo esc_textarea( stripslashes( $arr ) ); ?></textarea></td>
|
86 |
+
</tr>
|
87 |
+
<tr><td colspan="2"><hr /></td></tr>
|
88 |
+
<tr valign="top">
|
89 |
+
<th scope="row"> </th>
|
90 |
+
<td>
|
91 |
+
<input type="hidden" name="wpmem_admin_a" value="update_emails" />
|
92 |
+
<?php submit_button( __( 'Update Emails', 'wp-members' ) ); ?>
|
93 |
+
</td>
|
94 |
+
</tr>
|
95 |
+
</table>
|
96 |
+
</form>
|
97 |
+
</div><!-- .inside -->
|
98 |
+
</div><!-- #post-box -->
|
99 |
+
<div class="postbox">
|
100 |
+
<h3><span><?php _e( 'Need help?', 'wp-members' ); ?></span></h3>
|
101 |
+
<div class="inside">
|
102 |
+
<strong><i>See the <a href="https://rocketgeek.com/plugins/wp-members/users-guide/plugin-settings/emails/" target="_blank">Users Guide on email options</a>.</i></strong>
|
103 |
+
</div>
|
104 |
+
</div>
|
105 |
+
</div> <!-- #post-body-content -->
|
106 |
+
</div><!-- #post-body -->
|
107 |
+
</div><!-- .metabox-holder -->
|
108 |
+
<?php
|
109 |
+
}
|
110 |
+
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Updates the email message settings.
|
114 |
+
*
|
115 |
+
* @since 2.8.0
|
116 |
+
* @since 3.3.0 Ported from wpmem_update_emails().
|
117 |
+
*
|
118 |
+
* @global object $wpmem The WP_Members object class.
|
119 |
+
* @return string The emails updated message.
|
120 |
+
*/
|
121 |
+
static function update() {
|
122 |
+
|
123 |
+
global $wpmem;
|
124 |
+
|
125 |
+
// Check nonce.
|
126 |
+
check_admin_referer( 'wpmem-update-emails' );
|
127 |
+
|
128 |
+
// Update the email address (if applicable).
|
129 |
+
if ( $wpmem->email->from != $_POST['wp_mail_from'] || $wpmem->email->from_name != $_POST['wp_mail_from_name'] ) {
|
130 |
+
$wpmem->email->from = sanitize_email( $_POST['wp_mail_from'] );
|
131 |
+
$wpmem->email->from_name = sanitize_text_field( $_POST['wp_mail_from_name'] );
|
132 |
+
update_option( 'wpmembers_email_wpfrom', $wpmem->email->from );
|
133 |
+
update_option( 'wpmembers_email_wpname', $wpmem->email->from_name );
|
134 |
+
}
|
135 |
+
|
136 |
+
// Update the various emails being used.
|
137 |
+
( $wpmem->mod_reg == 0 ) ? $arr = array( 'wpmembers_email_newreg' ) : $arr = array( 'wpmembers_email_newmod', 'wpmembers_email_appmod' );
|
138 |
+
array_push( $arr, 'wpmembers_email_repass' );
|
139 |
+
array_push( $arr, 'wpmembers_email_getuser' );
|
140 |
+
( $wpmem->notify == 1 ) ? array_push( $arr, 'wpmembers_email_notify' ) : false;
|
141 |
+
array_push( $arr, 'wpmembers_email_footer' );
|
142 |
+
|
143 |
+
for ( $row = 0; $row < ( count( $arr ) - 1 ); $row++ ) {
|
144 |
+
$arr2 = array(
|
145 |
+
"subj" => sanitize_text_field( $_POST[ $arr[ $row ] . '_subj' ] ),
|
146 |
+
"body" => wp_kses( $_POST[ $arr[ $row ] . '_body' ], 'post' ),
|
147 |
+
);
|
148 |
+
update_option( $arr[ $row ], $arr2, false );
|
149 |
+
$arr2 = '';
|
150 |
+
}
|
151 |
+
|
152 |
+
// Updated the email footer.
|
153 |
+
update_option( $arr[ $row ], wp_kses( $_POST[ $arr[ $row ] . '_body' ], 'post' ), false );
|
154 |
+
|
155 |
+
if ( ! empty ( $wpmem->admin->emails ) ) {
|
156 |
+
foreach( $wpmem->admin->emails as $email ) {
|
157 |
+
$wpmem->admin->email_update( $email );
|
158 |
+
}
|
159 |
+
}
|
160 |
+
|
161 |
+
return __( 'WP-Members emails were updated', 'wp-members' );
|
162 |
+
|
163 |
+
}
|
164 |
+
|
165 |
} // End of file.
|
includes/admin/tabs/class-wp-members-admin-tab-fields.php
CHANGED
@@ -1,759 +1,759 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members Admin Functions
|
4 |
-
*
|
5 |
-
* Functions to manage the fields tab.
|
6 |
-
*
|
7 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
-
* Copyright (c) 2006-
|
10 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
-
*
|
12 |
-
* @package WP-Members
|
13 |
-
* @author Chad Butler
|
14 |
-
* @copyright 2006-
|
15 |
-
*/
|
16 |
-
|
17 |
-
// Exit if accessed directly.
|
18 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
19 |
-
exit();
|
20 |
-
}
|
21 |
-
|
22 |
-
class WP_Members_Admin_Tab_Fields {
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Creates the fields tab.
|
26 |
-
*
|
27 |
-
* @since 3.0.1
|
28 |
-
* @since 3.3.0 Renamed wpmem_a_fields_tab() to do_tab().
|
29 |
-
*
|
30 |
-
* @param string $tab The admin tab being displayed.
|
31 |
-
* @return string|bool The fields tab, otherwise false.
|
32 |
-
*/
|
33 |
-
public static function do_tab( $tab ) {
|
34 |
-
if ( $tab == 'fields' ) {
|
35 |
-
// Render the fields tab.
|
36 |
-
WP_Members_Admin_Tab_Fields::build_settings();
|
37 |
-
return;
|
38 |
-
}
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Scripts needed for the fields tab.
|
43 |
-
*
|
44 |
-
* @since 3.1.8
|
45 |
-
* @sinec 3.3.0 Renamed wpmem_a_fields_tab_scripts() to enqueue_scripts
|
46 |
-
*/
|
47 |
-
public static function enqueue_scripts() {
|
48 |
-
wp_enqueue_script( 'jquery-ui-sortable' );
|
49 |
-
}
|
50 |
-
|
51 |
-
/**
|
52 |
-
* Function to write the field edit link.
|
53 |
-
*
|
54 |
-
* @since 2.8
|
55 |
-
* @since 3.3.0 Renamed wpmem_fields_edit_link() to do_edit_link();
|
56 |
-
*
|
57 |
-
* @param string $field_id The option name of the field to be edited
|
58 |
-
*/
|
59 |
-
public static function do_edit_link( $field_id ) {
|
60 |
-
$link_args = array(
|
61 |
-
'page' => 'wpmem-settings',
|
62 |
-
'tab' => 'fields',
|
63 |
-
'mode' => 'edit',
|
64 |
-
'edit' => 'field',
|
65 |
-
'field' => $field_id,
|
66 |
-
);
|
67 |
-
$link = add_query_arg( $link_args, admin_url( 'options-general.php' ) );
|
68 |
-
return '<a href="' . $link . '">' . __( 'Edit' ) . '</a>';
|
69 |
-
}
|
70 |
-
|
71 |
-
/**
|
72 |
-
* Renders the content of the fields tab.
|
73 |
-
*
|
74 |
-
* @since 3.1.8
|
75 |
-
* @since 3.3.0 Renamed from wpmem_a_render_fields_tab() to build_settings().
|
76 |
-
*
|
77 |
-
* @global object $wpmem The WP_Members Object.
|
78 |
-
* @global string $did_update
|
79 |
-
* @global string $delete_action
|
80 |
-
*/
|
81 |
-
public static function build_settings() {
|
82 |
-
|
83 |
-
global $wpmem, $did_update, $delete_action;
|
84 |
-
$wpmem_fields = wpmem_fields();
|
85 |
-
$edit_meta = sanitize_text_field( wpmem_get( 'field', false, 'get' ) );
|
86 |
-
$add_meta = sanitize_text_field( wpmem_get( 'add_field', false ) );
|
87 |
-
|
88 |
-
if ( 'delete' == $delete_action ) {
|
89 |
-
|
90 |
-
$delete_fields = wpmem_get( 'delete' ); ?>
|
91 |
-
|
92 |
-
<?php if ( empty( $delete_fields ) ) { ?>
|
93 |
-
<p><?php _e( 'No fields selected for deletion', 'wp-members' ); ?></p>
|
94 |
-
<?php } else { ?>
|
95 |
-
<p><?php _e( 'Are you sure you want to delete the following fields?', 'wp-members' ); ?></p>
|
96 |
-
<?php foreach ( $delete_fields as $meta ) {
|
97 |
-
$meta = esc_html( $meta );
|
98 |
-
echo esc_html( $wpmem->fields[ $meta ]['label'] ) . ' (meta key: ' . $meta . ')<br />';
|
99 |
-
} ?>
|
100 |
-
<form name="<?php echo esc_attr( $delete_action ); ?>" id="<?php echo esc_attr( $delete_action ); ?>" method="post" action="<?php echo esc_url( wpmem_admin_form_post_url() ); ?>">
|
101 |
-
<?php wp_nonce_field( 'wpmem-confirm-delete' ); ?>
|
102 |
-
<input type="hidden" name="delete_fields" value="<?php echo esc_attr( implode( ",", $delete_fields ) ); ?>" />
|
103 |
-
<input type="hidden" name="dodelete" value="delete_confirmed" />
|
104 |
-
<?php submit_button( 'Delete Fields' ); ?>
|
105 |
-
</form><?php
|
106 |
-
}
|
107 |
-
} else {
|
108 |
-
|
109 |
-
if ( 'delete_confirmed' == wpmem_get( 'dodelete' ) ) {
|
110 |
-
|
111 |
-
check_admin_referer( 'wpmem-confirm-delete' );
|
112 |
-
|
113 |
-
$delete_fields = sanitize_text_field( wpmem_get( 'delete_fields', array() ) );
|
114 |
-
$delete_fields = explode( ",", $delete_fields );
|
115 |
-
$wpmem_new_fields = array();
|
116 |
-
foreach ( $wpmem_fields as $field ) {
|
117 |
-
if ( ! in_array( $field[2], $delete_fields ) ) {
|
118 |
-
$wpmem_new_fields[] = $field;
|
119 |
-
}
|
120 |
-
}
|
121 |
-
update_option( 'wpmembers_fields', $wpmem_new_fields );
|
122 |
-
$did_update = __( 'Fields deleted', 'wp-members' );
|
123 |
-
}
|
124 |
-
|
125 |
-
if ( $did_update ) { ?>
|
126 |
-
<div id="message" class="updated fade"><p><strong><?php echo $did_update; ?></strong></p></div>
|
127 |
-
<?php }
|
128 |
-
if ( $edit_meta || $add_meta ) {
|
129 |
-
$mode = ( $edit_meta ) ? sanitize_text_field( wpmem_get( 'mode', false, 'get' ) ) : 'add';
|
130 |
-
self::build_field_edit( $mode, $wpmem_fields, $edit_meta );
|
131 |
-
} else {
|
132 |
-
self::build_field_table();
|
133 |
-
} ?>
|
134 |
-
<h3><span><?php _e( 'Need help?', 'wp-members' ); ?></span></h3>
|
135 |
-
<div class="inside">
|
136 |
-
<strong><i><a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/fields/" target="_blank"><?php _e( 'Field Manager Documentation', 'wp-members' ); ?></a></i></strong>
|
137 |
-
</div>
|
138 |
-
<?php
|
139 |
-
}
|
140 |
-
}
|
141 |
-
|
142 |
-
/**
|
143 |
-
* Function to dispay the add/edit field form.
|
144 |
-
*
|
145 |
-
* @since 2.8
|
146 |
-
* @since 3.1.8 Changed name from wpmem_a_field_edit().
|
147 |
-
* @since 3.3.0 Changed name from wpmem_a_render_fields_tab_field_edit() to build_field_edit().
|
148 |
-
*
|
149 |
-
* @global object $wpmem The WP_Members Object.
|
150 |
-
* @param string $mode The mode for the function (edit|add)
|
151 |
-
* @param array|null $wpmem_fields The array of fields
|
152 |
-
* @param string|null $field The field being edited
|
153 |
-
*/
|
154 |
-
public static function build_field_edit( $mode, $wpmem_fields, $meta_key ) {
|
155 |
-
global $wpmem;
|
156 |
-
$fields = wpmem_fields();
|
157 |
-
if ( $mode == 'edit' ) {
|
158 |
-
$field = $fields[ $meta_key ];
|
159 |
-
}
|
160 |
-
$form_action = ( $mode == 'edit' ) ? 'editfieldform' : 'addfieldform';
|
161 |
-
$span_optional = '<span class="description">' . __( '(optional)', 'wp-members' ) . '</span>';
|
162 |
-
$span_required = '<span class="req">' . __( '(required)', 'wp-members' ) . '</span>';
|
163 |
-
$form_submit = array( 'mode' => $mode );
|
164 |
-
if ( isset( $_GET['field'] ) ) {
|
165 |
-
$form_submit['field'] = $meta_key;
|
166 |
-
} ?>
|
167 |
-
<h3 class="title"><?php ( $mode == 'edit' ) ? _e( 'Edit Field', 'wp-members' ) : _e( 'Add a Field', 'wp-members' ); ?></h3>
|
168 |
-
<form name="<?php echo $form_action; ?>" id="<?php echo $form_action; ?>" method="post" action="<?php echo wpmem_admin_form_post_url( $form_submit ); ?>">
|
169 |
-
<?php wp_nonce_field( 'wpmem_add_field' ); ?>
|
170 |
-
<ul>
|
171 |
-
<li>
|
172 |
-
<label><?php _e( 'Field Label', 'wp-members' ); ?> <?php echo $span_required; ?></label>
|
173 |
-
<input type="text" name="add_name" value="<?php echo ( $mode == 'edit' ) ? $field['label'] : false; ?>" required />
|
174 |
-
<?php _e( 'The name of the field as it will be displayed to the user.', 'wp-members' ); ?>
|
175 |
-
</li>
|
176 |
-
<li>
|
177 |
-
<label><?php _e( 'Meta Key', 'wp-members' ); ?> <?php echo $span_required; ?></label>
|
178 |
-
<?php if ( $mode == 'edit' ) {
|
179 |
-
echo "<span>$meta_key</span>"; ?>
|
180 |
-
<input type="hidden" name="add_option" value="<?php echo $meta_key; ?>" required />
|
181 |
-
<?php } else { ?>
|
182 |
-
<input type="text" name="add_option" value="" />
|
183 |
-
<?php _e( 'The database meta value for the field. It must be unique and contain no spaces (underscores are ok).', 'wp-members' ); ?>
|
184 |
-
<?php } ?>
|
185 |
-
</li>
|
186 |
-
<li>
|
187 |
-
<label><?php _e( 'Field Type', 'wp-members' ); ?></label>
|
188 |
-
<?php if ( $mode == 'edit' ) {
|
189 |
-
echo '<span>' . $field['type'] . '</span>'; ?>
|
190 |
-
<input type="hidden" name="add_type" value="<?php echo $field['type']; ?>" />
|
191 |
-
<?php } else { ?>
|
192 |
-
<select name="add_type" id="wpmem_field_type_select">
|
193 |
-
<option value="text"><?php _e( 'text', 'wp-members' ); ?></option>
|
194 |
-
<option value="email"><?php _e( 'email', 'wp-members' ); ?></option>
|
195 |
-
<option value="textarea"><?php _e( 'textarea', 'wp-members' ); ?></option>
|
196 |
-
<option value="checkbox"><?php _e( 'checkbox', 'wp-members' ); ?></option>
|
197 |
-
<option value="multicheckbox"><?php _e( 'multiple checkbox', 'wp-members' ); ?></option>
|
198 |
-
<option value="select"><?php _e( 'select (dropdown)', 'wp-members' ); ?></option>
|
199 |
-
<option value="multiselect"><?php _e( 'multiple select', 'wp-members' ); ?></option>
|
200 |
-
<option value="radio"><?php _e( 'radio group', 'wp-members' ); ?></option>
|
201 |
-
<option value="password"><?php _e( 'password', 'wp-members' ); ?></option>
|
202 |
-
<option value="image"><?php _e( 'image', 'wp-members' ); ?></option>
|
203 |
-
<option value="file"><?php _e( 'file', 'wp-members' ); ?></option>
|
204 |
-
<option value="url"><?php _e( 'url', 'wp-members' ); ?></option>
|
205 |
-
<option value="number"><?php _e( 'number', 'wp-members' ); ?></option>
|
206 |
-
<option value="date"><?php _e( 'date', 'wp-members' ); ?></option>
|
207 |
-
<option value="hidden"><?php _e( 'hidden', 'wp-members' ); ?></option>
|
208 |
-
<?php if ( $wpmem->enable_products ) { ?>
|
209 |
-
<option value="membership"><?php _e( 'membership', 'wp-members' ); ?></option>
|
210 |
-
<?php } ?>
|
211 |
-
</select>
|
212 |
-
<?php } ?>
|
213 |
-
</li>
|
214 |
-
<li>
|
215 |
-
<label><?php _e( 'Display?', 'wp-members' ); ?></label>
|
216 |
-
<?php if ( 'username' != $meta_key && 'user_email' != $meta_key ) { ?>
|
217 |
-
<input type="checkbox" name="add_display" value="y" <?php echo ( $mode == 'edit' ) ? checked( true, $field['register'] ) : false; ?> />
|
218 |
-
<?php } else { ?>
|
219 |
-
<span><?php _e( 'This field is always displayed', 'wp-members' ); ?></span>
|
220 |
-
<input type="hidden" name="add_display" value="y" />
|
221 |
-
<?php } ?>
|
222 |
-
</li>
|
223 |
-
<li>
|
224 |
-
<label><?php _e( 'Required?', 'wp-members' ); ?></label>
|
225 |
-
<?php if ( 'username' != $meta_key && 'user_email' != $meta_key ) { ?>
|
226 |
-
<input type="checkbox" name="add_required" value="y" <?php echo ( $mode == 'edit' ) ? checked( true, $field['required'] ) : false; ?> />
|
227 |
-
<?php } else { ?>
|
228 |
-
<span><?php _e( 'This field is always required', 'wp-members' ); ?></span>
|
229 |
-
<input type="hidden" name="add_required" value="y" />
|
230 |
-
<?php } ?>
|
231 |
-
</li>
|
232 |
-
<!--<div id="wpmem_allowhtml">
|
233 |
-
<li>
|
234 |
-
<label><?php _e( 'Allow HTML?', 'wp-members' ); ?></label>
|
235 |
-
<input type="checkbox" name="add_html" value="y" <?php echo ( $mode == 'edit' ) ? checked( true, $field['html'] ) : false; ?> />
|
236 |
-
</li>
|
237 |
-
</div>-->
|
238 |
-
<?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'text', 'password', 'email', 'url', 'number', 'date', 'textarea' ) ) ) ) ) { ?>
|
239 |
-
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_placeholder">' : ''; ?>
|
240 |
-
<li>
|
241 |
-
<label><?php _e( 'Placeholder', 'wp-members' ); ?></label>
|
242 |
-
<input type="text" name="add_placeholder" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['placeholder'] ) ? $field['placeholder'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
243 |
-
</li>
|
244 |
-
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
245 |
-
<?php } ?>
|
246 |
-
<?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'text', 'password', 'email', 'url', 'number', 'date' ) ) ) ) ) { ?>
|
247 |
-
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_pattern">' : ''; ?>
|
248 |
-
<li>
|
249 |
-
<label><?php _e( 'Pattern', 'wp-members' ); ?></label>
|
250 |
-
<input type="text" name="add_pattern" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['pattern'] ) ? $field['pattern'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
251 |
-
</li>
|
252 |
-
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
253 |
-
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_title">' : ''; ?>
|
254 |
-
<li>
|
255 |
-
<label><?php _e( 'Title', 'wp-members' ); ?></label>
|
256 |
-
<input type="text" name="add_title" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['title'] ) ? $field['title'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
257 |
-
</li>
|
258 |
-
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
259 |
-
<?php } ?>
|
260 |
-
|
261 |
-
<?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'number', 'date' ) ) ) ) ) { ?>
|
262 |
-
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_min_max">' : ''; ?>
|
263 |
-
<li>
|
264 |
-
<label><?php _e( 'Minimum Value', 'wp-members' ); ?></label>
|
265 |
-
<input type="text" name="add_min" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['min'] ) ? $field['min'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
266 |
-
</li>
|
267 |
-
<li>
|
268 |
-
<label><?php _e( 'Maximum Value', 'wp-members' ); ?></label>
|
269 |
-
<input type="text" name="add_max" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['max'] ) ? $field['max'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
270 |
-
</li>
|
271 |
-
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
272 |
-
<?php } ?>
|
273 |
-
<?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'textarea' ) ) ) ) ) { ?>
|
274 |
-
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_rows_cols">' : ''; ?>
|
275 |
-
<li>
|
276 |
-
<label><?php _e( 'Rows', 'wp-members' ); ?></label>
|
277 |
-
<input type="number" name="add_rows" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['rows'] ) ? $field['rows'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
278 |
-
</li>
|
279 |
-
<li>
|
280 |
-
<label><?php _e( 'Columns', 'wp-members' ); ?></label>
|
281 |
-
<input type="number" name="add_cols" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['cols'] ) ? $field['cols'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
282 |
-
</li>
|
283 |
-
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
284 |
-
<?php } ?>
|
285 |
-
<?php if ( $mode == 'add' || ( $mode == 'edit' && ( $field['type'] == 'file' || $field['type'] == 'image' ) ) ) { ?>
|
286 |
-
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_file_info">' : ''; ?>
|
287 |
-
<li>
|
288 |
-
<label><?php _e( 'Accepted file types:', 'wp-members' ); ?></label>
|
289 |
-
<input type="text" name="add_file_value" value="<?php echo ( $mode == 'edit' && ( $field['type'] == 'file' || $field['type'] == 'image' ) ) ? $field['file_types'] : false; ?>" />
|
290 |
-
</li>
|
291 |
-
<li>
|
292 |
-
<label> </label>
|
293 |
-
<span class="description"><?php _e( 'Accepted file types should be set like this: jpg|jpeg|png|gif', 'wp-members' ); ?></span>
|
294 |
-
</li>
|
295 |
-
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
296 |
-
<?php } ?>
|
297 |
-
<?php if ( $mode == 'add' || ( $mode == 'edit' && $field['type'] == 'checkbox' ) ) { ?>
|
298 |
-
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_checkbox_info">' : ''; ?>
|
299 |
-
<li>
|
300 |
-
<label><?php _e( 'Checked by default?', 'wp-members' ); ?></label>
|
301 |
-
<input type="checkbox" name="add_checked_default" value="y" <?php echo ( $mode == 'edit' && $field['type'] == 'checkbox' ) ? checked( true, $field['checked_default'] ) : false; ?> />
|
302 |
-
</li>
|
303 |
-
<li>
|
304 |
-
<label><?php _e( 'Stored value if checked:', 'wp-members' ); ?> <span class="req"><?php _e( '(required)', 'wp-members' ); ?></span></label>
|
305 |
-
<input type="text" name="add_checked_value" id="add_checked_value" value="<?php echo ( $mode == 'edit' && $field['type'] == 'checkbox' ) ? $field['checked_value'] : false; ?>" />
|
306 |
-
</li>
|
307 |
-
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
308 |
-
<?php }
|
309 |
-
|
310 |
-
if ( isset( $field['type'] ) ) {
|
311 |
-
$additional_settings = ( $field['type'] == 'select' || $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' || $field['type'] == 'radio' ) ? true : false;
|
312 |
-
$delimiter_settings = ( $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' ) ? true : false;
|
313 |
-
}
|
314 |
-
if ( $mode == 'add' || ( $mode == 'edit' && $additional_settings ) ) { ?>
|
315 |
-
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_dropdown_info">' : ''; ?>
|
316 |
-
<?php if ( $mode == 'add' || ( $mode == 'edit' && $delimiter_settings ) ) {
|
317 |
-
echo ( $mode == 'add' ) ? '<div id="wpmem_delimiter_info">' : '';
|
318 |
-
if ( isset( $field['delimiter'] ) && ( "|" == $field['delimiter'] || "," == $field['delimiter'] ) ) {
|
319 |
-
$delimiter = $field['delimiter'];
|
320 |
-
} else {
|
321 |
-
$delimiter = "|";
|
322 |
-
}
|
323 |
-
?>
|
324 |
-
<li>
|
325 |
-
<label><?php _e( 'Stored values delimiter:', 'wp-members' ); ?></label>
|
326 |
-
<select name = "add_delimiter_value">
|
327 |
-
<option value="|" <?php selected( '|', $delimiter ); ?>>pipe "|"</option>
|
328 |
-
<option value="," <?php selected( ',', $delimiter ); ?>>comma ","</option>
|
329 |
-
</select>
|
330 |
-
</li>
|
331 |
-
<?php echo ( $mode == 'add' ) ? '</div>' : '';
|
332 |
-
} ?>
|
333 |
-
<li>
|
334 |
-
<label style="vertical-align:top"><?php _e( 'Values (Displayed|Stored):', 'wp-members' ); ?> <?php echo $span_required; ?></label>
|
335 |
-
<textarea name="add_dropdown_value" id="add_dropdown_value" rows="5" cols="40"><?php
|
336 |
-
// Accomodate editing the current dropdown values or create dropdown value example.
|
337 |
-
if ( $mode == 'edit' ) {
|
338 |
-
for ( $row = 0; $row < count( $field['values'] ); $row++ ) {
|
339 |
-
// If the row contains commas (i.e. 1,000-10,000), wrap in double quotes.
|
340 |
-
if ( strstr( $field['values'][ $row ], ',' ) ) {
|
341 |
-
echo '"' . $field['values'][ $row ]; echo ( $row == count( $field['values'] )- 1 ) ? '"' : "\",\n";
|
342 |
-
} else {
|
343 |
-
echo $field['values'][ $row ]; echo ( $row == count( $field['values'] )- 1 ) ? "" : ",\n";
|
344 |
-
} }
|
345 |
-
} else {
|
346 |
-
if (version_compare(PHP_VERSION, '5.3.0') >= 0) { ?>
|
347 |
-
---- Select One ----|,
|
348 |
-
Choice One|choice_one,
|
349 |
-
"1,000|one_thousand",
|
350 |
-
"1,000-10,000|1,000-10,000",
|
351 |
-
Last Row|last_row<?php } else { ?>
|
352 |
-
---- Select One ----|,
|
353 |
-
Choice One|choice_one,
|
354 |
-
Choice 2|choice_two,
|
355 |
-
Last Row|last_row<?php } } ?></textarea>
|
356 |
-
</li>
|
357 |
-
<li>
|
358 |
-
<label> </label>
|
359 |
-
<span class="description"><?php _e( 'Options should be Option Name|option_value,', 'wp-members' ); ?></span>
|
360 |
-
</li>
|
361 |
-
<li>
|
362 |
-
<label> </label>
|
363 |
-
<span class="description"><a href="https://rocketgeek.com/plugins/wp-members/users-guide/registration/choosing-fields/" target="_blank"><?php _e( 'Visit plugin site for more information', 'wp-members' ); ?></a></span>
|
364 |
-
</li>
|
365 |
-
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
366 |
-
<?php } ?>
|
367 |
-
<?php if ( $mode == 'add' || ( $mode == 'edit' && $field['type'] == 'hidden' ) ) { ?>
|
368 |
-
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_hidden_info">' : ''; ?>
|
369 |
-
<li>
|
370 |
-
<label><?php _e( 'Value', 'wp-members' ); ?> <?php echo $span_required; ?></label>
|
371 |
-
<input type="text" name="add_hidden_value" id="add_hidden_value" value="<?php echo ( $mode == 'edit' && $field['type'] == 'hidden' ) ? $field['value'] : ''; ?>" />
|
372 |
-
</li>
|
373 |
-
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
374 |
-
<?php } ?>
|
375 |
-
</ul><br />
|
376 |
-
<?php if ( $mode == 'edit' ) { ?><input type="hidden" name="field_arr" value="<?php echo $meta_key; ?>" /><?php } ?>
|
377 |
-
<?php if ( 'add' == $mode ) {
|
378 |
-
$ids = array();
|
379 |
-
foreach ( $fields as $f ) {
|
380 |
-
$ids[] = $f[0];
|
381 |
-
}
|
382 |
-
sort( $ids );
|
383 |
-
$field_order_id = end( $ids ) + 1;
|
384 |
-
} else {
|
385 |
-
$field_order_id = $field[0];
|
386 |
-
} ?>
|
387 |
-
<input type="hidden" name="add_order_id" value="<?php echo $field_order_id; ?>" />
|
388 |
-
<input type="hidden" name="wpmem_admin_a" value="<?php echo ( $mode == 'edit' ) ? 'edit_field' : 'add_field'; ?>" />
|
389 |
-
<?php $text = ( $mode == 'edit' ) ? __( 'Edit Field', 'wp-members' ) : __( 'Add Field', 'wp-members' ); ?>
|
390 |
-
<?php submit_button( $text ); ?>
|
391 |
-
<p><a href="<?php echo add_query_arg( array( 'page' => 'wpmem-settings', 'tab' => 'fields' ), get_admin_url() . 'options-general.php' ); ?>">« <?php _e( 'Return to Fields Table', 'wp-members' ); ?></a></p>
|
392 |
-
</form><?php
|
393 |
-
}
|
394 |
-
|
395 |
-
/**
|
396 |
-
* Function to display the table of fields in the field manager tab.
|
397 |
-
*
|
398 |
-
* @since 2.8.0
|
399 |
-
* @since 3.1.8 Changed name from wpmem_a_field_table().
|
400 |
-
* @since 3.3.0 Changed namme from wpmem_a_render_fields_tab_field_table() to build_field_table().
|
401 |
-
*
|
402 |
-
* @global object $wpmem
|
403 |
-
*/
|
404 |
-
public static function build_field_table() {
|
405 |
-
global $wpmem;
|
406 |
-
|
407 |
-
$wpmem_ut_fields_skip = array( 'username', 'user_email', 'confirm_email', 'password', 'confirm_password' );
|
408 |
-
$wpmem_ut_fields = get_option( 'wpmembers_utfields' );
|
409 |
-
$wpmem_us_fields_skip = array( 'username', 'user_email', 'confirm_email', 'password', 'confirm_password' );
|
410 |
-
$wpmem_us_fields = get_option( 'wpmembers_usfields' );
|
411 |
-
|
412 |
-
$wpmem_fields = get_option( 'wpmembers_fields', array() );
|
413 |
-
foreach ( $wpmem_fields as $key => $field ) {
|
414 |
-
|
415 |
-
// @todo - transitional until new array keys
|
416 |
-
if ( is_numeric( $key ) ) {
|
417 |
-
// Adjust for profile @todo - temporary until new array keys.
|
418 |
-
if ( isset( $field['profile'] ) ) {
|
419 |
-
$profile = ( true === $field['profile'] ) ? 'y' : 'n';
|
420 |
-
} else {
|
421 |
-
$profile = $field[4];
|
422 |
-
}
|
423 |
-
|
424 |
-
$meta = $field[2];
|
425 |
-
$ut_checked = ( ( $wpmem_ut_fields ) && ( in_array( $field[1], $wpmem_ut_fields ) ) ) ? $field[1] : '';
|
426 |
-
$us_checked = ( ( $wpmem_us_fields ) && ( in_array( $field[1], $wpmem_us_fields ) ) ) ? $field[1] : '';
|
427 |
-
$field_items[] = array(
|
428 |
-
'order' => $field[0],
|
429 |
-
'label' => $field[1],
|
430 |
-
'meta' => $meta,
|
431 |
-
'type' => $field[3],
|
432 |
-
'display' => ( 'user_email' != $meta && 'username' != $meta ) ? wpmem_create_formfield( $meta . "_display", 'checkbox', 'y', $field[4] ) : '',
|
433 |
-
'req' => ( 'user_email' != $meta && 'username' != $meta ) ? wpmem_create_formfield( $meta . "_required", 'checkbox', 'y', $field[5] ) : '',
|
434 |
-
'profile' => ( 'user_email' != $meta && 'username' != $meta ) ? wpmem_create_formfield( $meta . "_profile", 'checkbox', 'y', $profile ) : '',
|
435 |
-
'userscrn' => ( ! in_array( $meta, $wpmem_ut_fields_skip ) ) ? wpmem_create_formfield( 'ut_fields[' . $meta . ']', 'checkbox', $field[1], $ut_checked ) : '',
|
436 |
-
'usearch' => ( ! in_array( $meta, $wpmem_us_fields_skip ) ) ? wpmem_create_formfield( 'us_fields[' . $meta . ']', 'checkbox', $field[1], $us_checked ) : '',
|
437 |
-
'edit' => self::do_edit_link( $meta ),
|
438 |
-
'sort' => '<span class="dashicons dashicons-sort" title="' . __( 'Drag and drop to reorder fields', 'wp-members' ) . '"></span>',
|
439 |
-
);
|
440 |
-
}
|
441 |
-
}
|
442 |
-
|
443 |
-
$extra_user_screen_items = array(
|
444 |
-
'user_registered' => __( 'Registration Date', 'wp-members' ),
|
445 |
-
'active' => __( 'Active', 'wp-members' ),
|
446 |
-
'wpmem_reg_ip' => __( 'Registration IP', 'wp-members' ),
|
447 |
-
'exp_type' => __( 'Subscription Type', 'wp-members' ),
|
448 |
-
'expires' => __( 'Expires', 'wp-members' ),
|
449 |
-
'user_id' => __( 'User ID', 'wp-members' ),
|
450 |
-
);
|
451 |
-
|
452 |
-
foreach ( $extra_user_screen_items as $key => $item ) {
|
453 |
-
$ut_checked = ( ( $wpmem_ut_fields ) && ( in_array( $item, $wpmem_ut_fields ) ) ) ? $item : '';
|
454 |
-
if ( 'user_id' == $key
|
455 |
-
|| 'user_registered' == $key
|
456 |
-
|| 'wpmem_reg_ip' == $key
|
457 |
-
|| ( 'active' == $key && 1 == $wpmem->mod_reg )
|
458 |
-
|| defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 && ( 'exp_type' == $key || 'expires' == $key ) ) {
|
459 |
-
$user_screen_items[ $key ] = array( 'label' => __( $item, 'wp-members' ), 'meta' => $key,
|
460 |
-
'userscrn' => wpmem_create_formfield( "ut_fields[{$key}]", 'checkbox', $item, $ut_checked ),
|
461 |
-
);
|
462 |
-
}
|
463 |
-
}
|
464 |
-
|
465 |
-
foreach ( $user_screen_items as $screen_item ) {
|
466 |
-
$field_items[] = array(
|
467 |
-
'label' => $screen_item['label'],
|
468 |
-
'meta' => $screen_item['meta'],
|
469 |
-
'type' => '',
|
470 |
-
'display' => '',
|
471 |
-
'req' => '',
|
472 |
-
'profile' => '',
|
473 |
-
'userscrn' => $screen_item['userscrn'],
|
474 |
-
'usearch' => '',
|
475 |
-
'edit' => '',
|
476 |
-
'sort' => '',
|
477 |
-
);
|
478 |
-
}
|
479 |
-
|
480 |
-
$table = new WP_Members_Fields_Table();
|
481 |
-
|
482 |
-
$heading = __( 'Manage Fields', 'wp-members' );
|
483 |
-
//$description = __( 'Displaying fields for:', 'wp-members' );
|
484 |
-
//$which_form = $wpmem->form_tags[ $wpmem->admin->current_form ];
|
485 |
-
|
486 |
-
echo '<div class="wrap">';
|
487 |
-
printf( '<h3 class="title">%s</h3>', $heading );
|
488 |
-
//printf( '<p>%s <strong>%s</strong></p>', $description, $which_form );
|
489 |
-
printf( '<form name="updatefieldform" id="updatefieldform" method="post" action="%s">', wpmem_admin_form_post_url() );
|
490 |
-
|
491 |
-
$table->items = $field_items;
|
492 |
-
$table->prepare_items();
|
493 |
-
$table->display();
|
494 |
-
echo '</form>';
|
495 |
-
echo '</div>';
|
496 |
-
}
|
497 |
-
|
498 |
-
/**
|
499 |
-
* Javascript to ID the fields table and add curser style to rows.
|
500 |
-
*
|
501 |
-
* @since 3.1.8
|
502 |
-
* @since 3.3.0 Changed from wpmem_bulk_fields_actions() to bulk_actions().
|
503 |
-
*/
|
504 |
-
|
505 |
-
public static function bulk_actions() {
|
506 |
-
if ( 'wpmem-settings' == wpmem_get( 'page', false, 'get' ) && 'fields' == wpmem_get( 'tab', false, 'get' ) ) {
|
507 |
-
?><script type="text/javascript">
|
508 |
-
(function($) {
|
509 |
-
$(document).ready(function() {
|
510 |
-
$("table").attr("id", "wpmem-fields");
|
511 |
-
/**$("tr").attr('style', 'cursor:move;');**/
|
512 |
-
});
|
513 |
-
})(jQuery);
|
514 |
-
jQuery('<input id="add_field" name="add_field" class="button action" type="submit" value="<?php _e( 'Add Field', 'wp-members' ); ?>" />').appendTo(".top .bulkactions");
|
515 |
-
jQuery('<input id="add_field" name="add_field" class="button action" type="submit" value="<?php _e( 'Add Field', 'wp-members' ); ?>" />').appendTo(".bottom .bulkactions");
|
516 |
-
</script><?php
|
517 |
-
}
|
518 |
-
}
|
519 |
-
|
520 |
-
/**
|
521 |
-
* Updates fields.
|
522 |
-
*
|
523 |
-
* Derived from wpmem_update_fields()
|
524 |
-
*
|
525 |
-
* @since 3.1.8
|
526 |
-
* @since 3.3.0 Changed from wpmem_admin_fields_update() to update().
|
527 |
-
*
|
528 |
-
* @global object $wpmem
|
529 |
-
* @global string $did_update
|
530 |
-
* @global string $add_field_err_msg The add field error message
|
531 |
-
*/
|
532 |
-
public static function update() {
|
533 |
-
|
534 |
-
global $wpmem, $did_update, $delete_action;
|
535 |
-
|
536 |
-
if ( 'wpmem-settings' == wpmem_get( 'page', false, 'get' ) && 'fields' == wpmem_get( 'tab', false, 'get' ) ) {
|
537 |
-
// Get the current fields.
|
538 |
-
$wpmem_fields = get_option( 'wpmembers_fields' );
|
539 |
-
|
540 |
-
$action = sanitize_text_field( wpmem_get( 'action', false ) );
|
541 |
-
$action = ( -1 == $action ) ? sanitize_text_field( wpmem_get( 'action2' ) ) : $action;
|
542 |
-
|
543 |
-
$delete_action = false;
|
544 |
-
|
545 |
-
if ( 'save' == $action ) {
|
546 |
-
|
547 |
-
// Check nonce.
|
548 |
-
check_admin_referer( 'bulk-settings_page_wpmem-settings' );
|
549 |
-
|
550 |
-
// Update user table fields.
|
551 |
-
$arr = ( isset( $_POST['ut_fields'] ) ) ? $_POST['ut_fields'] : array();
|
552 |
-
$ut_fields_arr = array();
|
553 |
-
foreach ( $arr as $key => $item ) {
|
554 |
-
$ut_fields_arr[ sanitize_text_field( $key ) ] = sanitize_text_field( $item );
|
555 |
-
}
|
556 |
-
update_option( 'wpmembers_utfields', $ut_fields_arr );
|
557 |
-
|
558 |
-
// Update user search fields.
|
559 |
-
$arr = ( isset( $_POST['us_fields'] ) ) ? $_POST['us_fields'] : array();
|
560 |
-
$us_fields_arr = array();
|
561 |
-
foreach ( $arr as $key => $item ) {
|
562 |
-
$us_fields_arr[ sanitize_text_field( $key ) ] = sanitize_text_field( $item );
|
563 |
-
}
|
564 |
-
update_option( 'wpmembers_usfields', $us_fields_arr );
|
565 |
-
|
566 |
-
// Update display/required settings
|
567 |
-
foreach ( $wpmem_fields as $key => $field ) {
|
568 |
-
$meta_key = $field[2];
|
569 |
-
if ( 'username' == $meta_key || 'user_email' == $meta_key ) {
|
570 |
-
$wpmem_fields[ $key ][4] = 'y';
|
571 |
-
$wpmem_fields[ $key ][5] = 'y';
|
572 |
-
$wpmem_fields[ $key ]['profile'] = ( 'username' == $meta_key ) ? false : true;
|
573 |
-
} else {
|
574 |
-
$wpmem_fields[ $key ][4] = ( wpmem_get( $meta_key . "_display" ) ) ? 'y' : '';
|
575 |
-
$wpmem_fields[ $key ][5] = ( wpmem_get( $meta_key . "_required" ) ) ? 'y' : '';
|
576 |
-
$wpmem_fields[ $key ]['profile'] = ( wpmem_get( $meta_key . '_profile' ) ) ? true : false;
|
577 |
-
}
|
578 |
-
}
|
579 |
-
update_option( 'wpmembers_fields', $wpmem_fields );
|
580 |
-
$wpmem->load_fields();
|
581 |
-
$did_update = __( 'WP-Members fields were updated', 'wp-members' );
|
582 |
-
return $did_update;
|
583 |
-
|
584 |
-
} elseif ( 'delete' == $action ) {
|
585 |
-
|
586 |
-
// Check nonce.
|
587 |
-
check_admin_referer( 'bulk-settings_page_wpmem-settings' );
|
588 |
-
|
589 |
-
$delete_action = 'delete';
|
590 |
-
|
591 |
-
} elseif ( ( 'add_field' == wpmem_get( 'wpmem_admin_a' ) || 'edit_field' == wpmem_get( 'wpmem_admin_a' ) ) && check_admin_referer( 'wpmem_add_field' ) ) {
|
592 |
-
|
593 |
-
// Set action.
|
594 |
-
$action = sanitize_text_field( wpmem_get( 'wpmem_admin_a' ) );
|
595 |
-
|
596 |
-
global $add_field_err_msg;
|
597 |
-
|
598 |
-
$add_field_err_msg = false;
|
599 |
-
$add_name = sanitize_text_field( wpmem_get( 'add_name' ) );
|
600 |
-
$add_option = sanitize_text_field( wpmem_get( 'add_option' ) );
|
601 |
-
|
602 |
-
// Error check that field label and option name are included and unique.
|
603 |
-
$add_field_err_msg = ( ! $add_name ) ? __( 'Field Label is required. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
|
604 |
-
$add_field_err_msg = ( ! $add_option ) ? __( 'Meta Key is required. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
|
605 |
-
|
606 |
-
$add_field_err_msg = ( ! preg_match("/^[A-Za-z0-9_]*$/", $add_option ) ) ? __( 'Meta Key must contain only letters, numbers, and underscores', 'wp-members' ) : $add_field_err_msg;
|
607 |
-
|
608 |
-
// Check for duplicate field names.
|
609 |
-
$chk_fields = array();
|
610 |
-
foreach ( $wpmem_fields as $field ) {
|
611 |
-
$chk_fields[] = $field[2];
|
612 |
-
}
|
613 |
-
$add_field_err_msg = ( in_array( $add_option, $chk_fields ) ) ? __( 'A field with that meta key already exists', 'wp-members' ) : $add_field_err_msg;
|
614 |
-
|
615 |
-
// Error check for reserved terms.
|
616 |
-
$reserved_terms = wpmem_wp_reserved_terms();
|
617 |
-
if ( in_array( strtolower( $add_option ), $reserved_terms ) ) {
|
618 |
-
$add_field_err_msg = sprintf( __( 'Sorry, "%s" is a <a href="https://codex.wordpress.org/Function_Reference/register_taxonomy#Reserved_Terms" target="_blank">reserved term</a>. Field was not added.', 'wp-members' ), $add_option );
|
619 |
-
}
|
620 |
-
|
621 |
-
// Error check option name for spaces and replace with underscores.
|
622 |
-
$us_option = preg_replace( "/ /", '_', $add_option );
|
623 |
-
|
624 |
-
$arr = array();
|
625 |
-
|
626 |
-
$type = sanitize_text_field( wpmem_get( 'add_type' ) );
|
627 |
-
|
628 |
-
$arr[0] = filter_var( wpmem_get( 'add_order_id' ), FILTER_SANITIZE_NUMBER_INT );
|
629 |
-
$arr[1] = sanitize_text_field( stripslashes( wpmem_get( 'add_name' ) ) );
|
630 |
-
$arr[2] = $us_option;
|
631 |
-
$arr[3] = $type;
|
632 |
-
$arr[4] = ( 'y' == wpmem_get( 'add_display', 'n' ) ) ? 'y' : 'n';
|
633 |
-
$arr[5] = ( 'y' == wpmem_get( 'add_required', 'n' ) ) ? 'y' : 'n';
|
634 |
-
|
635 |
-
// Mark native fields:
|
636 |
-
$native_fields = array( 'user_login', 'user_pass', 'user_nicename', 'user_email', 'user_url', 'user_registered', 'display_name', 'first_name', 'last_name', 'nickname', 'description' );
|
637 |
-
$arr[6] = ( in_array( $us_option, $native_fields ) ) ? 'y' : 'n';
|
638 |
-
|
639 |
-
if ( 'text' == $type || 'email' == $type || 'textarea' == $type || 'password' == $type || 'url' == $type || 'number' == $type || 'date' == $type ) {
|
640 |
-
$arr['placeholder'] = sanitize_text_field( stripslashes( wpmem_get( 'add_placeholder' ) ) );
|
641 |
-
}
|
642 |
-
|
643 |
-
if ( 'text' == $type || 'email' == $type || 'password' == $type || 'url' == $type || 'number' == $type || 'date' == $type ) {
|
644 |
-
$arr['pattern'] = sanitize_text_field( stripslashes( wpmem_get( 'add_pattern' ) ) );
|
645 |
-
$arr['title'] = sanitize_text_field( stripslashes( wpmem_get( 'add_title' ) ) );
|
646 |
-
}
|
647 |
-
|
648 |
-
if ( 'number' == $type || 'date' == $type ) {
|
649 |
-
$arr['min'] = filter_var( wpmem_get( 'add_min' ), FILTER_SANITIZE_NUMBER_INT );
|
650 |
-
$arr['max'] = filter_var( wpmem_get( 'add_max' ), FILTER_SANITIZE_NUMBER_INT );
|
651 |
-
}
|
652 |
-
|
653 |
-
if ( 'textarea' == $type ) {
|
654 |
-
$arr['rows'] = filter_var( wpmem_get( 'add_rows' ), FILTER_SANITIZE_NUMBER_INT );
|
655 |
-
$arr['cols'] = filter_var( wpmem_get( 'add_cols' ), FILTER_SANITIZE_NUMBER_INT );
|
656 |
-
}
|
657 |
-
|
658 |
-
if ( $type == 'checkbox' ) {
|
659 |
-
$add_field_err_msg = ( ! $_POST['add_checked_value'] ) ? __( 'Checked value is required for checkboxes. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
|
660 |
-
$arr[7] = sanitize_text_field( wpmem_get( 'add_checked_value', false ) );
|
661 |
-
$arr[8] = ( 'y' == wpmem_get( 'add_checked_default', 'n' ) ) ? 'y' : 'n';
|
662 |
-
}
|
663 |
-
|
664 |
-
if ( $type == 'select'
|
665 |
-
|| $type == 'multiselect'
|
666 |
-
|| $type == 'radio'
|
667 |
-
|| $type == 'multicheckbox'
|
668 |
-
) {
|
669 |
-
// Get the values.
|
670 |
-
$str = stripslashes( sanitize_textarea_field( $_POST['add_dropdown_value'] ) );
|
671 |
-
// Remove linebreaks.
|
672 |
-
$str = trim( str_replace( array("\r", "\r\n", "\n"), '', $str ) );
|
673 |
-
// Create array.
|
674 |
-
if ( ! function_exists( 'str_getcsv' ) ) {
|
675 |
-
$arr[7] = explode( ',', $str );
|
676 |
-
} else {
|
677 |
-
$arr[7] = str_getcsv( $str, ',', '"' );
|
678 |
-
}
|
679 |
-
// If multiselect or multicheckbox, set delimiter.
|
680 |
-
if ( 'multiselect' == $type || 'multicheckbox' == $type ) {
|
681 |
-
$arr[8] = ( ',' === wpmem_get( 'add_delimiter_value', '|' ) ) ? ',' : '|';
|
682 |
-
}
|
683 |
-
}
|
684 |
-
|
685 |
-
if ( $type == 'file' || $type == 'image' ) {
|
686 |
-
$arr[7] = sanitize_text_field( stripslashes( $_POST['add_file_value'] ) );
|
687 |
-
}
|
688 |
-
|
689 |
-
if ( wpmem_get( 'add_type' ) == 'hidden' ) {
|
690 |
-
$add_field_err_msg = ( ! $_POST['add_hidden_value'] ) ? __( 'A value is required for hidden fields. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
|
691 |
-
$arr[7] = ( isset( $_POST['add_hidden_value'] ) ) ? sanitize_text_field( stripslashes( $_POST['add_hidden_value'] ) ) : '';
|
692 |
-
}
|
693 |
-
|
694 |
-
if ( $action == 'add_field' ) {
|
695 |
-
if ( ! $add_field_err_msg ) {
|
696 |
-
array_push( $wpmem_fields, $arr );
|
697 |
-
$did_update = sprintf( __( '%s was added', 'wp-members' ), esc_html( $_POST['add_name'] ) );
|
698 |
-
} else {
|
699 |
-
$did_update = $add_field_err_msg;
|
700 |
-
}
|
701 |
-
} else {
|
702 |
-
for ( $row = 0; $row < count( $wpmem_fields ); $row++ ) {
|
703 |
-
if ( $wpmem_fields[ $row ][2] == wpmem_get( 'field', false, 'get' ) ) {
|
704 |
-
$arr[0] = $wpmem_fields[ $row ][0];
|
705 |
-
foreach ( $arr as $key => $value ) {
|
706 |
-
$wpmem_fields[ $row ][ $key ] = $arr[ $key ];
|
707 |
-
}
|
708 |
-
}
|
709 |
-
}
|
710 |
-
$did_update = sprintf( __( '%s was updated', 'wp-members' ), esc_html( stripslashes( $add_name ) ) );
|
711 |
-
$did_update.= '<p><a href="' . esc_url( add_query_arg( array( 'page' => 'wpmem-settings', 'tab' => 'fields' ), get_admin_url() . 'options-general.php' ) ) . '">« ' . __( 'Return to Fields Table', 'wp-members' ) . '</a></p>';
|
712 |
-
}
|
713 |
-
|
714 |
-
$wpmem_newfields = $wpmem_fields;
|
715 |
-
|
716 |
-
update_option( 'wpmembers_fields', $wpmem_newfields );
|
717 |
-
$wpmem->load_fields();
|
718 |
-
return $did_update;
|
719 |
-
}
|
720 |
-
}
|
721 |
-
}
|
722 |
-
|
723 |
-
/**
|
724 |
-
* Reorders form fields.
|
725 |
-
*
|
726 |
-
* @since 2.5.1
|
727 |
-
* @since 3.1.8 Rebuilt for new List Table.
|
728 |
-
* @since 3.3.0 Merged do_field_reorder() and field_reorder().
|
729 |
-
*/
|
730 |
-
public static function do_field_reorder() {
|
731 |
-
|
732 |
-
// Start fresh.
|
733 |
-
$new_order = $wpmem_fields = $field = $key = $wpmem_new_fields = $id = $k = '';
|
734 |
-
$wpmem_fields = get_option( 'wpmembers_fields' );
|
735 |
-
|
736 |
-
// Get the list items
|
737 |
-
$new_order = $_POST;
|
738 |
-
|
739 |
-
// Put fields in the proper order for the current form.
|
740 |
-
$wpmem_new_fields = array();
|
741 |
-
foreach ( $new_order['list_items'] as $id ) {
|
742 |
-
foreach( $wpmem_fields as $val ) {
|
743 |
-
if ( $val[0] == $id ) {
|
744 |
-
$wpmem_new_fields[] = $val;
|
745 |
-
}
|
746 |
-
}
|
747 |
-
}
|
748 |
-
|
749 |
-
// Save fields array with new current form field order.
|
750 |
-
update_option( 'wpmembers_fields', $wpmem_new_fields );
|
751 |
-
|
752 |
-
// Indicate successful transaction.
|
753 |
-
_e( 'Form field order updated.', 'wp-members' );
|
754 |
-
|
755 |
-
die(); // This is required to return a proper result.
|
756 |
-
|
757 |
-
}
|
758 |
-
}
|
759 |
// End of file.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members Admin Functions
|
4 |
+
*
|
5 |
+
* Functions to manage the fields tab.
|
6 |
+
*
|
7 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
+
* Copyright (c) 2006-2020 Chad Butler
|
10 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
+
*
|
12 |
+
* @package WP-Members
|
13 |
+
* @author Chad Butler
|
14 |
+
* @copyright 2006-2020
|
15 |
+
*/
|
16 |
+
|
17 |
+
// Exit if accessed directly.
|
18 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
19 |
+
exit();
|
20 |
+
}
|
21 |
+
|
22 |
+
class WP_Members_Admin_Tab_Fields {
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Creates the fields tab.
|
26 |
+
*
|
27 |
+
* @since 3.0.1
|
28 |
+
* @since 3.3.0 Renamed wpmem_a_fields_tab() to do_tab().
|
29 |
+
*
|
30 |
+
* @param string $tab The admin tab being displayed.
|
31 |
+
* @return string|bool The fields tab, otherwise false.
|
32 |
+
*/
|
33 |
+
public static function do_tab( $tab ) {
|
34 |
+
if ( $tab == 'fields' ) {
|
35 |
+
// Render the fields tab.
|
36 |
+
WP_Members_Admin_Tab_Fields::build_settings();
|
37 |
+
return;
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Scripts needed for the fields tab.
|
43 |
+
*
|
44 |
+
* @since 3.1.8
|
45 |
+
* @sinec 3.3.0 Renamed wpmem_a_fields_tab_scripts() to enqueue_scripts
|
46 |
+
*/
|
47 |
+
public static function enqueue_scripts() {
|
48 |
+
wp_enqueue_script( 'jquery-ui-sortable' );
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Function to write the field edit link.
|
53 |
+
*
|
54 |
+
* @since 2.8
|
55 |
+
* @since 3.3.0 Renamed wpmem_fields_edit_link() to do_edit_link();
|
56 |
+
*
|
57 |
+
* @param string $field_id The option name of the field to be edited
|
58 |
+
*/
|
59 |
+
public static function do_edit_link( $field_id ) {
|
60 |
+
$link_args = array(
|
61 |
+
'page' => 'wpmem-settings',
|
62 |
+
'tab' => 'fields',
|
63 |
+
'mode' => 'edit',
|
64 |
+
'edit' => 'field',
|
65 |
+
'field' => $field_id,
|
66 |
+
);
|
67 |
+
$link = add_query_arg( $link_args, admin_url( 'options-general.php' ) );
|
68 |
+
return '<a href="' . $link . '">' . __( 'Edit' ) . '</a>';
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Renders the content of the fields tab.
|
73 |
+
*
|
74 |
+
* @since 3.1.8
|
75 |
+
* @since 3.3.0 Renamed from wpmem_a_render_fields_tab() to build_settings().
|
76 |
+
*
|
77 |
+
* @global object $wpmem The WP_Members Object.
|
78 |
+
* @global string $did_update
|
79 |
+
* @global string $delete_action
|
80 |
+
*/
|
81 |
+
public static function build_settings() {
|
82 |
+
|
83 |
+
global $wpmem, $did_update, $delete_action;
|
84 |
+
$wpmem_fields = wpmem_fields();
|
85 |
+
$edit_meta = sanitize_text_field( wpmem_get( 'field', false, 'get' ) );
|
86 |
+
$add_meta = sanitize_text_field( wpmem_get( 'add_field', false ) );
|
87 |
+
|
88 |
+
if ( 'delete' == $delete_action ) {
|
89 |
+
|
90 |
+
$delete_fields = wpmem_get( 'delete' ); ?>
|
91 |
+
|
92 |
+
<?php if ( empty( $delete_fields ) ) { ?>
|
93 |
+
<p><?php _e( 'No fields selected for deletion', 'wp-members' ); ?></p>
|
94 |
+
<?php } else { ?>
|
95 |
+
<p><?php _e( 'Are you sure you want to delete the following fields?', 'wp-members' ); ?></p>
|
96 |
+
<?php foreach ( $delete_fields as $meta ) {
|
97 |
+
$meta = esc_html( $meta );
|
98 |
+
echo esc_html( $wpmem->fields[ $meta ]['label'] ) . ' (meta key: ' . $meta . ')<br />';
|
99 |
+
} ?>
|
100 |
+
<form name="<?php echo esc_attr( $delete_action ); ?>" id="<?php echo esc_attr( $delete_action ); ?>" method="post" action="<?php echo esc_url( wpmem_admin_form_post_url() ); ?>">
|
101 |
+
<?php wp_nonce_field( 'wpmem-confirm-delete' ); ?>
|
102 |
+
<input type="hidden" name="delete_fields" value="<?php echo esc_attr( implode( ",", $delete_fields ) ); ?>" />
|
103 |
+
<input type="hidden" name="dodelete" value="delete_confirmed" />
|
104 |
+
<?php submit_button( 'Delete Fields' ); ?>
|
105 |
+
</form><?php
|
106 |
+
}
|
107 |
+
} else {
|
108 |
+
|
109 |
+
if ( 'delete_confirmed' == wpmem_get( 'dodelete' ) ) {
|
110 |
+
|
111 |
+
check_admin_referer( 'wpmem-confirm-delete' );
|
112 |
+
|
113 |
+
$delete_fields = sanitize_text_field( wpmem_get( 'delete_fields', array() ) );
|
114 |
+
$delete_fields = explode( ",", $delete_fields );
|
115 |
+
$wpmem_new_fields = array();
|
116 |
+
foreach ( $wpmem_fields as $field ) {
|
117 |
+
if ( ! in_array( $field[2], $delete_fields ) ) {
|
118 |
+
$wpmem_new_fields[] = $field;
|
119 |
+
}
|
120 |
+
}
|
121 |
+
update_option( 'wpmembers_fields', $wpmem_new_fields );
|
122 |
+
$did_update = __( 'Fields deleted', 'wp-members' );
|
123 |
+
}
|
124 |
+
|
125 |
+
if ( $did_update ) { ?>
|
126 |
+
<div id="message" class="updated fade"><p><strong><?php echo $did_update; ?></strong></p></div>
|
127 |
+
<?php }
|
128 |
+
if ( $edit_meta || $add_meta ) {
|
129 |
+
$mode = ( $edit_meta ) ? sanitize_text_field( wpmem_get( 'mode', false, 'get' ) ) : 'add';
|
130 |
+
self::build_field_edit( $mode, $wpmem_fields, $edit_meta );
|
131 |
+
} else {
|
132 |
+
self::build_field_table();
|
133 |
+
} ?>
|
134 |
+
<h3><span><?php _e( 'Need help?', 'wp-members' ); ?></span></h3>
|
135 |
+
<div class="inside">
|
136 |
+
<strong><i><a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/fields/" target="_blank"><?php _e( 'Field Manager Documentation', 'wp-members' ); ?></a></i></strong>
|
137 |
+
</div>
|
138 |
+
<?php
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Function to dispay the add/edit field form.
|
144 |
+
*
|
145 |
+
* @since 2.8
|
146 |
+
* @since 3.1.8 Changed name from wpmem_a_field_edit().
|
147 |
+
* @since 3.3.0 Changed name from wpmem_a_render_fields_tab_field_edit() to build_field_edit().
|
148 |
+
*
|
149 |
+
* @global object $wpmem The WP_Members Object.
|
150 |
+
* @param string $mode The mode for the function (edit|add)
|
151 |
+
* @param array|null $wpmem_fields The array of fields
|
152 |
+
* @param string|null $field The field being edited
|
153 |
+
*/
|
154 |
+
public static function build_field_edit( $mode, $wpmem_fields, $meta_key ) {
|
155 |
+
global $wpmem;
|
156 |
+
$fields = wpmem_fields();
|
157 |
+
if ( $mode == 'edit' ) {
|
158 |
+
$field = $fields[ $meta_key ];
|
159 |
+
}
|
160 |
+
$form_action = ( $mode == 'edit' ) ? 'editfieldform' : 'addfieldform';
|
161 |
+
$span_optional = '<span class="description">' . __( '(optional)', 'wp-members' ) . '</span>';
|
162 |
+
$span_required = '<span class="req">' . __( '(required)', 'wp-members' ) . '</span>';
|
163 |
+
$form_submit = array( 'mode' => $mode );
|
164 |
+
if ( isset( $_GET['field'] ) ) {
|
165 |
+
$form_submit['field'] = $meta_key;
|
166 |
+
} ?>
|
167 |
+
<h3 class="title"><?php ( $mode == 'edit' ) ? _e( 'Edit Field', 'wp-members' ) : _e( 'Add a Field', 'wp-members' ); ?></h3>
|
168 |
+
<form name="<?php echo $form_action; ?>" id="<?php echo $form_action; ?>" method="post" action="<?php echo wpmem_admin_form_post_url( $form_submit ); ?>">
|
169 |
+
<?php wp_nonce_field( 'wpmem_add_field' ); ?>
|
170 |
+
<ul>
|
171 |
+
<li>
|
172 |
+
<label><?php _e( 'Field Label', 'wp-members' ); ?> <?php echo $span_required; ?></label>
|
173 |
+
<input type="text" name="add_name" value="<?php echo ( $mode == 'edit' ) ? $field['label'] : false; ?>" required />
|
174 |
+
<?php _e( 'The name of the field as it will be displayed to the user.', 'wp-members' ); ?>
|
175 |
+
</li>
|
176 |
+
<li>
|
177 |
+
<label><?php _e( 'Meta Key', 'wp-members' ); ?> <?php echo $span_required; ?></label>
|
178 |
+
<?php if ( $mode == 'edit' ) {
|
179 |
+
echo "<span>$meta_key</span>"; ?>
|
180 |
+
<input type="hidden" name="add_option" value="<?php echo $meta_key; ?>" required />
|
181 |
+
<?php } else { ?>
|
182 |
+
<input type="text" name="add_option" value="" />
|
183 |
+
<?php _e( 'The database meta value for the field. It must be unique and contain no spaces (underscores are ok).', 'wp-members' ); ?>
|
184 |
+
<?php } ?>
|
185 |
+
</li>
|
186 |
+
<li>
|
187 |
+
<label><?php _e( 'Field Type', 'wp-members' ); ?></label>
|
188 |
+
<?php if ( $mode == 'edit' ) {
|
189 |
+
echo '<span>' . $field['type'] . '</span>'; ?>
|
190 |
+
<input type="hidden" name="add_type" value="<?php echo $field['type']; ?>" />
|
191 |
+
<?php } else { ?>
|
192 |
+
<select name="add_type" id="wpmem_field_type_select">
|
193 |
+
<option value="text"><?php _e( 'text', 'wp-members' ); ?></option>
|
194 |
+
<option value="email"><?php _e( 'email', 'wp-members' ); ?></option>
|
195 |
+
<option value="textarea"><?php _e( 'textarea', 'wp-members' ); ?></option>
|
196 |
+
<option value="checkbox"><?php _e( 'checkbox', 'wp-members' ); ?></option>
|
197 |
+
<option value="multicheckbox"><?php _e( 'multiple checkbox', 'wp-members' ); ?></option>
|
198 |
+
<option value="select"><?php _e( 'select (dropdown)', 'wp-members' ); ?></option>
|
199 |
+
<option value="multiselect"><?php _e( 'multiple select', 'wp-members' ); ?></option>
|
200 |
+
<option value="radio"><?php _e( 'radio group', 'wp-members' ); ?></option>
|
201 |
+
<option value="password"><?php _e( 'password', 'wp-members' ); ?></option>
|
202 |
+
<option value="image"><?php _e( 'image', 'wp-members' ); ?></option>
|
203 |
+
<option value="file"><?php _e( 'file', 'wp-members' ); ?></option>
|
204 |
+
<option value="url"><?php _e( 'url', 'wp-members' ); ?></option>
|
205 |
+
<option value="number"><?php _e( 'number', 'wp-members' ); ?></option>
|
206 |
+
<option value="date"><?php _e( 'date', 'wp-members' ); ?></option>
|
207 |
+
<option value="hidden"><?php _e( 'hidden', 'wp-members' ); ?></option>
|
208 |
+
<?php if ( $wpmem->enable_products ) { ?>
|
209 |
+
<option value="membership"><?php _e( 'membership', 'wp-members' ); ?></option>
|
210 |
+
<?php } ?>
|
211 |
+
</select>
|
212 |
+
<?php } ?>
|
213 |
+
</li>
|
214 |
+
<li>
|
215 |
+
<label><?php _e( 'Display?', 'wp-members' ); ?></label>
|
216 |
+
<?php if ( 'username' != $meta_key && 'user_email' != $meta_key ) { ?>
|
217 |
+
<input type="checkbox" name="add_display" value="y" <?php echo ( $mode == 'edit' ) ? checked( true, $field['register'] ) : false; ?> />
|
218 |
+
<?php } else { ?>
|
219 |
+
<span><?php _e( 'This field is always displayed', 'wp-members' ); ?></span>
|
220 |
+
<input type="hidden" name="add_display" value="y" />
|
221 |
+
<?php } ?>
|
222 |
+
</li>
|
223 |
+
<li>
|
224 |
+
<label><?php _e( 'Required?', 'wp-members' ); ?></label>
|
225 |
+
<?php if ( 'username' != $meta_key && 'user_email' != $meta_key ) { ?>
|
226 |
+
<input type="checkbox" name="add_required" value="y" <?php echo ( $mode == 'edit' ) ? checked( true, $field['required'] ) : false; ?> />
|
227 |
+
<?php } else { ?>
|
228 |
+
<span><?php _e( 'This field is always required', 'wp-members' ); ?></span>
|
229 |
+
<input type="hidden" name="add_required" value="y" />
|
230 |
+
<?php } ?>
|
231 |
+
</li>
|
232 |
+
<!--<div id="wpmem_allowhtml">
|
233 |
+
<li>
|
234 |
+
<label><?php _e( 'Allow HTML?', 'wp-members' ); ?></label>
|
235 |
+
<input type="checkbox" name="add_html" value="y" <?php echo ( $mode == 'edit' ) ? checked( true, $field['html'] ) : false; ?> />
|
236 |
+
</li>
|
237 |
+
</div>-->
|
238 |
+
<?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'text', 'password', 'email', 'url', 'number', 'date', 'textarea' ) ) ) ) ) { ?>
|
239 |
+
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_placeholder">' : ''; ?>
|
240 |
+
<li>
|
241 |
+
<label><?php _e( 'Placeholder', 'wp-members' ); ?></label>
|
242 |
+
<input type="text" name="add_placeholder" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['placeholder'] ) ? $field['placeholder'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
243 |
+
</li>
|
244 |
+
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
245 |
+
<?php } ?>
|
246 |
+
<?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'text', 'password', 'email', 'url', 'number', 'date' ) ) ) ) ) { ?>
|
247 |
+
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_pattern">' : ''; ?>
|
248 |
+
<li>
|
249 |
+
<label><?php _e( 'Pattern', 'wp-members' ); ?></label>
|
250 |
+
<input type="text" name="add_pattern" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['pattern'] ) ? $field['pattern'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
251 |
+
</li>
|
252 |
+
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
253 |
+
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_title">' : ''; ?>
|
254 |
+
<li>
|
255 |
+
<label><?php _e( 'Title', 'wp-members' ); ?></label>
|
256 |
+
<input type="text" name="add_title" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['title'] ) ? $field['title'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
257 |
+
</li>
|
258 |
+
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
259 |
+
<?php } ?>
|
260 |
+
|
261 |
+
<?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'number', 'date' ) ) ) ) ) { ?>
|
262 |
+
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_min_max">' : ''; ?>
|
263 |
+
<li>
|
264 |
+
<label><?php _e( 'Minimum Value', 'wp-members' ); ?></label>
|
265 |
+
<input type="text" name="add_min" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['min'] ) ? $field['min'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
266 |
+
</li>
|
267 |
+
<li>
|
268 |
+
<label><?php _e( 'Maximum Value', 'wp-members' ); ?></label>
|
269 |
+
<input type="text" name="add_max" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['max'] ) ? $field['max'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
270 |
+
</li>
|
271 |
+
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
272 |
+
<?php } ?>
|
273 |
+
<?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'textarea' ) ) ) ) ) { ?>
|
274 |
+
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_rows_cols">' : ''; ?>
|
275 |
+
<li>
|
276 |
+
<label><?php _e( 'Rows', 'wp-members' ); ?></label>
|
277 |
+
<input type="number" name="add_rows" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['rows'] ) ? $field['rows'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
278 |
+
</li>
|
279 |
+
<li>
|
280 |
+
<label><?php _e( 'Columns', 'wp-members' ); ?></label>
|
281 |
+
<input type="number" name="add_cols" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['cols'] ) ? $field['cols'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
|
282 |
+
</li>
|
283 |
+
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
284 |
+
<?php } ?>
|
285 |
+
<?php if ( $mode == 'add' || ( $mode == 'edit' && ( $field['type'] == 'file' || $field['type'] == 'image' ) ) ) { ?>
|
286 |
+
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_file_info">' : ''; ?>
|
287 |
+
<li>
|
288 |
+
<label><?php _e( 'Accepted file types:', 'wp-members' ); ?></label>
|
289 |
+
<input type="text" name="add_file_value" value="<?php echo ( $mode == 'edit' && ( $field['type'] == 'file' || $field['type'] == 'image' ) ) ? $field['file_types'] : false; ?>" />
|
290 |
+
</li>
|
291 |
+
<li>
|
292 |
+
<label> </label>
|
293 |
+
<span class="description"><?php _e( 'Accepted file types should be set like this: jpg|jpeg|png|gif', 'wp-members' ); ?></span>
|
294 |
+
</li>
|
295 |
+
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
296 |
+
<?php } ?>
|
297 |
+
<?php if ( $mode == 'add' || ( $mode == 'edit' && $field['type'] == 'checkbox' ) ) { ?>
|
298 |
+
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_checkbox_info">' : ''; ?>
|
299 |
+
<li>
|
300 |
+
<label><?php _e( 'Checked by default?', 'wp-members' ); ?></label>
|
301 |
+
<input type="checkbox" name="add_checked_default" value="y" <?php echo ( $mode == 'edit' && $field['type'] == 'checkbox' ) ? checked( true, $field['checked_default'] ) : false; ?> />
|
302 |
+
</li>
|
303 |
+
<li>
|
304 |
+
<label><?php _e( 'Stored value if checked:', 'wp-members' ); ?> <span class="req"><?php _e( '(required)', 'wp-members' ); ?></span></label>
|
305 |
+
<input type="text" name="add_checked_value" id="add_checked_value" value="<?php echo ( $mode == 'edit' && $field['type'] == 'checkbox' ) ? $field['checked_value'] : false; ?>" />
|
306 |
+
</li>
|
307 |
+
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
308 |
+
<?php }
|
309 |
+
|
310 |
+
if ( isset( $field['type'] ) ) {
|
311 |
+
$additional_settings = ( $field['type'] == 'select' || $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' || $field['type'] == 'radio' ) ? true : false;
|
312 |
+
$delimiter_settings = ( $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' ) ? true : false;
|
313 |
+
}
|
314 |
+
if ( $mode == 'add' || ( $mode == 'edit' && $additional_settings ) ) { ?>
|
315 |
+
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_dropdown_info">' : ''; ?>
|
316 |
+
<?php if ( $mode == 'add' || ( $mode == 'edit' && $delimiter_settings ) ) {
|
317 |
+
echo ( $mode == 'add' ) ? '<div id="wpmem_delimiter_info">' : '';
|
318 |
+
if ( isset( $field['delimiter'] ) && ( "|" == $field['delimiter'] || "," == $field['delimiter'] ) ) {
|
319 |
+
$delimiter = $field['delimiter'];
|
320 |
+
} else {
|
321 |
+
$delimiter = "|";
|
322 |
+
}
|
323 |
+
?>
|
324 |
+
<li>
|
325 |
+
<label><?php _e( 'Stored values delimiter:', 'wp-members' ); ?></label>
|
326 |
+
<select name = "add_delimiter_value">
|
327 |
+
<option value="|" <?php selected( '|', $delimiter ); ?>>pipe "|"</option>
|
328 |
+
<option value="," <?php selected( ',', $delimiter ); ?>>comma ","</option>
|
329 |
+
</select>
|
330 |
+
</li>
|
331 |
+
<?php echo ( $mode == 'add' ) ? '</div>' : '';
|
332 |
+
} ?>
|
333 |
+
<li>
|
334 |
+
<label style="vertical-align:top"><?php _e( 'Values (Displayed|Stored):', 'wp-members' ); ?> <?php echo $span_required; ?></label>
|
335 |
+
<textarea name="add_dropdown_value" id="add_dropdown_value" rows="5" cols="40"><?php
|
336 |
+
// Accomodate editing the current dropdown values or create dropdown value example.
|
337 |
+
if ( $mode == 'edit' ) {
|
338 |
+
for ( $row = 0; $row < count( $field['values'] ); $row++ ) {
|
339 |
+
// If the row contains commas (i.e. 1,000-10,000), wrap in double quotes.
|
340 |
+
if ( strstr( $field['values'][ $row ], ',' ) ) {
|
341 |
+
echo '"' . $field['values'][ $row ]; echo ( $row == count( $field['values'] )- 1 ) ? '"' : "\",\n";
|
342 |
+
} else {
|
343 |
+
echo $field['values'][ $row ]; echo ( $row == count( $field['values'] )- 1 ) ? "" : ",\n";
|
344 |
+
} }
|
345 |
+
} else {
|
346 |
+
if (version_compare(PHP_VERSION, '5.3.0') >= 0) { ?>
|
347 |
+
---- Select One ----|,
|
348 |
+
Choice One|choice_one,
|
349 |
+
"1,000|one_thousand",
|
350 |
+
"1,000-10,000|1,000-10,000",
|
351 |
+
Last Row|last_row<?php } else { ?>
|
352 |
+
---- Select One ----|,
|
353 |
+
Choice One|choice_one,
|
354 |
+
Choice 2|choice_two,
|
355 |
+
Last Row|last_row<?php } } ?></textarea>
|
356 |
+
</li>
|
357 |
+
<li>
|
358 |
+
<label> </label>
|
359 |
+
<span class="description"><?php _e( 'Options should be Option Name|option_value,', 'wp-members' ); ?></span>
|
360 |
+
</li>
|
361 |
+
<li>
|
362 |
+
<label> </label>
|
363 |
+
<span class="description"><a href="https://rocketgeek.com/plugins/wp-members/users-guide/registration/choosing-fields/" target="_blank"><?php _e( 'Visit plugin site for more information', 'wp-members' ); ?></a></span>
|
364 |
+
</li>
|
365 |
+
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
366 |
+
<?php } ?>
|
367 |
+
<?php if ( $mode == 'add' || ( $mode == 'edit' && $field['type'] == 'hidden' ) ) { ?>
|
368 |
+
<?php echo ( $mode == 'add' ) ? '<div id="wpmem_hidden_info">' : ''; ?>
|
369 |
+
<li>
|
370 |
+
<label><?php _e( 'Value', 'wp-members' ); ?> <?php echo $span_required; ?></label>
|
371 |
+
<input type="text" name="add_hidden_value" id="add_hidden_value" value="<?php echo ( $mode == 'edit' && $field['type'] == 'hidden' ) ? $field['value'] : ''; ?>" />
|
372 |
+
</li>
|
373 |
+
<?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
|
374 |
+
<?php } ?>
|
375 |
+
</ul><br />
|
376 |
+
<?php if ( $mode == 'edit' ) { ?><input type="hidden" name="field_arr" value="<?php echo $meta_key; ?>" /><?php } ?>
|
377 |
+
<?php if ( 'add' == $mode ) {
|
378 |
+
$ids = array();
|
379 |
+
foreach ( $fields as $f ) {
|
380 |
+
$ids[] = $f[0];
|
381 |
+
}
|
382 |
+
sort( $ids );
|
383 |
+
$field_order_id = end( $ids ) + 1;
|
384 |
+
} else {
|
385 |
+
$field_order_id = $field[0];
|
386 |
+
} ?>
|
387 |
+
<input type="hidden" name="add_order_id" value="<?php echo $field_order_id; ?>" />
|
388 |
+
<input type="hidden" name="wpmem_admin_a" value="<?php echo ( $mode == 'edit' ) ? 'edit_field' : 'add_field'; ?>" />
|
389 |
+
<?php $text = ( $mode == 'edit' ) ? __( 'Edit Field', 'wp-members' ) : __( 'Add Field', 'wp-members' ); ?>
|
390 |
+
<?php submit_button( $text ); ?>
|
391 |
+
<p><a href="<?php echo add_query_arg( array( 'page' => 'wpmem-settings', 'tab' => 'fields' ), get_admin_url() . 'options-general.php' ); ?>">« <?php _e( 'Return to Fields Table', 'wp-members' ); ?></a></p>
|
392 |
+
</form><?php
|
393 |
+
}
|
394 |
+
|
395 |
+
/**
|
396 |
+
* Function to display the table of fields in the field manager tab.
|
397 |
+
*
|
398 |
+
* @since 2.8.0
|
399 |
+
* @since 3.1.8 Changed name from wpmem_a_field_table().
|
400 |
+
* @since 3.3.0 Changed namme from wpmem_a_render_fields_tab_field_table() to build_field_table().
|
401 |
+
*
|
402 |
+
* @global object $wpmem
|
403 |
+
*/
|
404 |
+
public static function build_field_table() {
|
405 |
+
global $wpmem;
|
406 |
+
|
407 |
+
$wpmem_ut_fields_skip = array( 'username', 'user_email', 'confirm_email', 'password', 'confirm_password' );
|
408 |
+
$wpmem_ut_fields = get_option( 'wpmembers_utfields' );
|
409 |
+
$wpmem_us_fields_skip = array( 'username', 'user_email', 'confirm_email', 'password', 'confirm_password' );
|
410 |
+
$wpmem_us_fields = get_option( 'wpmembers_usfields' );
|
411 |
+
|
412 |
+
$wpmem_fields = get_option( 'wpmembers_fields', array() );
|
413 |
+
foreach ( $wpmem_fields as $key => $field ) {
|
414 |
+
|
415 |
+
// @todo - transitional until new array keys
|
416 |
+
if ( is_numeric( $key ) ) {
|
417 |
+
// Adjust for profile @todo - temporary until new array keys.
|
418 |
+
if ( isset( $field['profile'] ) ) {
|
419 |
+
$profile = ( true === $field['profile'] ) ? 'y' : 'n';
|
420 |
+
} else {
|
421 |
+
$profile = $field[4];
|
422 |
+
}
|
423 |
+
|
424 |
+
$meta = $field[2];
|
425 |
+
$ut_checked = ( ( $wpmem_ut_fields ) && ( in_array( $field[1], $wpmem_ut_fields ) ) ) ? $field[1] : '';
|
426 |
+
$us_checked = ( ( $wpmem_us_fields ) && ( in_array( $field[1], $wpmem_us_fields ) ) ) ? $field[1] : '';
|
427 |
+
$field_items[] = array(
|
428 |
+
'order' => $field[0],
|
429 |
+
'label' => $field[1],
|
430 |
+
'meta' => $meta,
|
431 |
+
'type' => $field[3],
|
432 |
+
'display' => ( 'user_email' != $meta && 'username' != $meta ) ? wpmem_create_formfield( $meta . "_display", 'checkbox', 'y', $field[4] ) : '',
|
433 |
+
'req' => ( 'user_email' != $meta && 'username' != $meta ) ? wpmem_create_formfield( $meta . "_required", 'checkbox', 'y', $field[5] ) : '',
|
434 |
+
'profile' => ( 'user_email' != $meta && 'username' != $meta ) ? wpmem_create_formfield( $meta . "_profile", 'checkbox', 'y', $profile ) : '',
|
435 |
+
'userscrn' => ( ! in_array( $meta, $wpmem_ut_fields_skip ) ) ? wpmem_create_formfield( 'ut_fields[' . $meta . ']', 'checkbox', $field[1], $ut_checked ) : '',
|
436 |
+
'usearch' => ( ! in_array( $meta, $wpmem_us_fields_skip ) ) ? wpmem_create_formfield( 'us_fields[' . $meta . ']', 'checkbox', $field[1], $us_checked ) : '',
|
437 |
+
'edit' => self::do_edit_link( $meta ),
|
438 |
+
'sort' => '<span class="dashicons dashicons-sort" title="' . __( 'Drag and drop to reorder fields', 'wp-members' ) . '"></span>',
|
439 |
+
);
|
440 |
+
}
|
441 |
+
}
|
442 |
+
|
443 |
+
$extra_user_screen_items = array(
|
444 |
+
'user_registered' => __( 'Registration Date', 'wp-members' ),
|
445 |
+
'active' => __( 'Active', 'wp-members' ),
|
446 |
+
'wpmem_reg_ip' => __( 'Registration IP', 'wp-members' ),
|
447 |
+
'exp_type' => __( 'Subscription Type', 'wp-members' ),
|
448 |
+
'expires' => __( 'Expires', 'wp-members' ),
|
449 |
+
'user_id' => __( 'User ID', 'wp-members' ),
|
450 |
+
);
|
451 |
+
|
452 |
+
foreach ( $extra_user_screen_items as $key => $item ) {
|
453 |
+
$ut_checked = ( ( $wpmem_ut_fields ) && ( in_array( $item, $wpmem_ut_fields ) ) ) ? $item : '';
|
454 |
+
if ( 'user_id' == $key
|
455 |
+
|| 'user_registered' == $key
|
456 |
+
|| 'wpmem_reg_ip' == $key
|
457 |
+
|| ( 'active' == $key && 1 == $wpmem->mod_reg )
|
458 |
+
|| defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 && ( 'exp_type' == $key || 'expires' == $key ) ) {
|
459 |
+
$user_screen_items[ $key ] = array( 'label' => __( $item, 'wp-members' ), 'meta' => $key,
|
460 |
+
'userscrn' => wpmem_create_formfield( "ut_fields[{$key}]", 'checkbox', $item, $ut_checked ),
|
461 |
+
);
|
462 |
+
}
|
463 |
+
}
|
464 |
+
|
465 |
+
foreach ( $user_screen_items as $screen_item ) {
|
466 |
+
$field_items[] = array(
|
467 |
+
'label' => $screen_item['label'],
|
468 |
+
'meta' => $screen_item['meta'],
|
469 |
+
'type' => '',
|
470 |
+
'display' => '',
|
471 |
+
'req' => '',
|
472 |
+
'profile' => '',
|
473 |
+
'userscrn' => $screen_item['userscrn'],
|
474 |
+
'usearch' => '',
|
475 |
+
'edit' => '',
|
476 |
+
'sort' => '',
|
477 |
+
);
|
478 |
+
}
|
479 |
+
|
480 |
+
$table = new WP_Members_Fields_Table();
|
481 |
+
|
482 |
+
$heading = __( 'Manage Fields', 'wp-members' );
|
483 |
+
//$description = __( 'Displaying fields for:', 'wp-members' );
|
484 |
+
//$which_form = $wpmem->form_tags[ $wpmem->admin->current_form ];
|
485 |
+
|
486 |
+
echo '<div class="wrap">';
|
487 |
+
printf( '<h3 class="title">%s</h3>', $heading );
|
488 |
+
//printf( '<p>%s <strong>%s</strong></p>', $description, $which_form );
|
489 |
+
printf( '<form name="updatefieldform" id="updatefieldform" method="post" action="%s">', wpmem_admin_form_post_url() );
|
490 |
+
|
491 |
+
$table->items = $field_items;
|
492 |
+
$table->prepare_items();
|
493 |
+
$table->display();
|
494 |
+
echo '</form>';
|
495 |
+
echo '</div>';
|
496 |
+
}
|
497 |
+
|
498 |
+
/**
|
499 |
+
* Javascript to ID the fields table and add curser style to rows.
|
500 |
+
*
|
501 |
+
* @since 3.1.8
|
502 |
+
* @since 3.3.0 Changed from wpmem_bulk_fields_actions() to bulk_actions().
|
503 |
+
*/
|
504 |
+
|
505 |
+
public static function bulk_actions() {
|
506 |
+
if ( 'wpmem-settings' == wpmem_get( 'page', false, 'get' ) && 'fields' == wpmem_get( 'tab', false, 'get' ) ) {
|
507 |
+
?><script type="text/javascript">
|
508 |
+
(function($) {
|
509 |
+
$(document).ready(function() {
|
510 |
+
$("table").attr("id", "wpmem-fields");
|
511 |
+
/**$("tr").attr('style', 'cursor:move;');**/
|
512 |
+
});
|
513 |
+
})(jQuery);
|
514 |
+
jQuery('<input id="add_field" name="add_field" class="button action" type="submit" value="<?php _e( 'Add Field', 'wp-members' ); ?>" />').appendTo(".top .bulkactions");
|
515 |
+
jQuery('<input id="add_field" name="add_field" class="button action" type="submit" value="<?php _e( 'Add Field', 'wp-members' ); ?>" />').appendTo(".bottom .bulkactions");
|
516 |
+
</script><?php
|
517 |
+
}
|
518 |
+
}
|
519 |
+
|
520 |
+
/**
|
521 |
+
* Updates fields.
|
522 |
+
*
|
523 |
+
* Derived from wpmem_update_fields()
|
524 |
+
*
|
525 |
+
* @since 3.1.8
|
526 |
+
* @since 3.3.0 Changed from wpmem_admin_fields_update() to update().
|
527 |
+
*
|
528 |
+
* @global object $wpmem
|
529 |
+
* @global string $did_update
|
530 |
+
* @global string $add_field_err_msg The add field error message
|
531 |
+
*/
|
532 |
+
public static function update() {
|
533 |
+
|
534 |
+
global $wpmem, $did_update, $delete_action;
|
535 |
+
|
536 |
+
if ( 'wpmem-settings' == wpmem_get( 'page', false, 'get' ) && 'fields' == wpmem_get( 'tab', false, 'get' ) ) {
|
537 |
+
// Get the current fields.
|
538 |
+
$wpmem_fields = get_option( 'wpmembers_fields' );
|
539 |
+
|
540 |
+
$action = sanitize_text_field( wpmem_get( 'action', false ) );
|
541 |
+
$action = ( -1 == $action ) ? sanitize_text_field( wpmem_get( 'action2' ) ) : $action;
|
542 |
+
|
543 |
+
$delete_action = false;
|
544 |
+
|
545 |
+
if ( 'save' == $action ) {
|
546 |
+
|
547 |
+
// Check nonce.
|
548 |
+
check_admin_referer( 'bulk-settings_page_wpmem-settings' );
|
549 |
+
|
550 |
+
// Update user table fields.
|
551 |
+
$arr = ( isset( $_POST['ut_fields'] ) ) ? $_POST['ut_fields'] : array();
|
552 |
+
$ut_fields_arr = array();
|
553 |
+
foreach ( $arr as $key => $item ) {
|
554 |
+
$ut_fields_arr[ sanitize_text_field( $key ) ] = sanitize_text_field( $item );
|
555 |
+
}
|
556 |
+
update_option( 'wpmembers_utfields', $ut_fields_arr );
|
557 |
+
|
558 |
+
// Update user search fields.
|
559 |
+
$arr = ( isset( $_POST['us_fields'] ) ) ? $_POST['us_fields'] : array();
|
560 |
+
$us_fields_arr = array();
|
561 |
+
foreach ( $arr as $key => $item ) {
|
562 |
+
$us_fields_arr[ sanitize_text_field( $key ) ] = sanitize_text_field( $item );
|
563 |
+
}
|
564 |
+
update_option( 'wpmembers_usfields', $us_fields_arr );
|
565 |
+
|
566 |
+
// Update display/required settings
|
567 |
+
foreach ( $wpmem_fields as $key => $field ) {
|
568 |
+
$meta_key = $field[2];
|
569 |
+
if ( 'username' == $meta_key || 'user_email' == $meta_key ) {
|
570 |
+
$wpmem_fields[ $key ][4] = 'y';
|
571 |
+
$wpmem_fields[ $key ][5] = 'y';
|
572 |
+
$wpmem_fields[ $key ]['profile'] = ( 'username' == $meta_key ) ? false : true;
|
573 |
+
} else {
|
574 |
+
$wpmem_fields[ $key ][4] = ( wpmem_get( $meta_key . "_display" ) ) ? 'y' : '';
|
575 |
+
$wpmem_fields[ $key ][5] = ( wpmem_get( $meta_key . "_required" ) ) ? 'y' : '';
|
576 |
+
$wpmem_fields[ $key ]['profile'] = ( wpmem_get( $meta_key . '_profile' ) ) ? true : false;
|
577 |
+
}
|
578 |
+
}
|
579 |
+
update_option( 'wpmembers_fields', $wpmem_fields );
|
580 |
+
$wpmem->load_fields();
|
581 |
+
$did_update = __( 'WP-Members fields were updated', 'wp-members' );
|
582 |
+
return $did_update;
|
583 |
+
|
584 |
+
} elseif ( 'delete' == $action ) {
|
585 |
+
|
586 |
+
// Check nonce.
|
587 |
+
check_admin_referer( 'bulk-settings_page_wpmem-settings' );
|
588 |
+
|
589 |
+
$delete_action = 'delete';
|
590 |
+
|
591 |
+
} elseif ( ( 'add_field' == wpmem_get( 'wpmem_admin_a' ) || 'edit_field' == wpmem_get( 'wpmem_admin_a' ) ) && check_admin_referer( 'wpmem_add_field' ) ) {
|
592 |
+
|
593 |
+
// Set action.
|
594 |
+
$action = sanitize_text_field( wpmem_get( 'wpmem_admin_a' ) );
|
595 |
+
|
596 |
+
global $add_field_err_msg;
|
597 |
+
|
598 |
+
$add_field_err_msg = false;
|
599 |
+
$add_name = sanitize_text_field( wpmem_get( 'add_name' ) );
|
600 |
+
$add_option = sanitize_text_field( wpmem_get( 'add_option' ) );
|
601 |
+
|
602 |
+
// Error check that field label and option name are included and unique.
|
603 |
+
$add_field_err_msg = ( ! $add_name ) ? __( 'Field Label is required. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
|
604 |
+
$add_field_err_msg = ( ! $add_option ) ? __( 'Meta Key is required. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
|
605 |
+
|
606 |
+
$add_field_err_msg = ( ! preg_match("/^[A-Za-z0-9_]*$/", $add_option ) ) ? __( 'Meta Key must contain only letters, numbers, and underscores', 'wp-members' ) : $add_field_err_msg;
|
607 |
+
|
608 |
+
// Check for duplicate field names.
|
609 |
+
$chk_fields = array();
|
610 |
+
foreach ( $wpmem_fields as $field ) {
|
611 |
+
$chk_fields[] = $field[2];
|
612 |
+
}
|
613 |
+
$add_field_err_msg = ( in_array( $add_option, $chk_fields ) ) ? __( 'A field with that meta key already exists', 'wp-members' ) : $add_field_err_msg;
|
614 |
+
|
615 |
+
// Error check for reserved terms.
|
616 |
+
$reserved_terms = wpmem_wp_reserved_terms();
|
617 |
+
if ( in_array( strtolower( $add_option ), $reserved_terms ) ) {
|
618 |
+
$add_field_err_msg = sprintf( __( 'Sorry, "%s" is a <a href="https://codex.wordpress.org/Function_Reference/register_taxonomy#Reserved_Terms" target="_blank">reserved term</a>. Field was not added.', 'wp-members' ), $add_option );
|
619 |
+
}
|
620 |
+
|
621 |
+
// Error check option name for spaces and replace with underscores.
|
622 |
+
$us_option = preg_replace( "/ /", '_', $add_option );
|
623 |
+
|
624 |
+
$arr = array();
|
625 |
+
|
626 |
+
$type = sanitize_text_field( wpmem_get( 'add_type' ) );
|
627 |
+
|
628 |
+
$arr[0] = filter_var( wpmem_get( 'add_order_id' ), FILTER_SANITIZE_NUMBER_INT );
|
629 |
+
$arr[1] = sanitize_text_field( stripslashes( wpmem_get( 'add_name' ) ) );
|
630 |
+
$arr[2] = $us_option;
|
631 |
+
$arr[3] = $type;
|
632 |
+
$arr[4] = ( 'y' == wpmem_get( 'add_display', 'n' ) ) ? 'y' : 'n';
|
633 |
+
$arr[5] = ( 'y' == wpmem_get( 'add_required', 'n' ) ) ? 'y' : 'n';
|
634 |
+
|
635 |
+
// Mark native fields:
|
636 |
+
$native_fields = array( 'user_login', 'user_pass', 'user_nicename', 'user_email', 'user_url', 'user_registered', 'display_name', 'first_name', 'last_name', 'nickname', 'description' );
|
637 |
+
$arr[6] = ( in_array( $us_option, $native_fields ) ) ? 'y' : 'n';
|
638 |
+
|
639 |
+
if ( 'text' == $type || 'email' == $type || 'textarea' == $type || 'password' == $type || 'url' == $type || 'number' == $type || 'date' == $type ) {
|
640 |
+
$arr['placeholder'] = sanitize_text_field( stripslashes( wpmem_get( 'add_placeholder' ) ) );
|
641 |
+
}
|
642 |
+
|
643 |
+
if ( 'text' == $type || 'email' == $type || 'password' == $type || 'url' == $type || 'number' == $type || 'date' == $type ) {
|
644 |
+
$arr['pattern'] = sanitize_text_field( stripslashes( wpmem_get( 'add_pattern' ) ) );
|
645 |
+
$arr['title'] = sanitize_text_field( stripslashes( wpmem_get( 'add_title' ) ) );
|
646 |
+
}
|
647 |
+
|
648 |
+
if ( 'number' == $type || 'date' == $type ) {
|
649 |
+
$arr['min'] = filter_var( wpmem_get( 'add_min' ), FILTER_SANITIZE_NUMBER_INT );
|
650 |
+
$arr['max'] = filter_var( wpmem_get( 'add_max' ), FILTER_SANITIZE_NUMBER_INT );
|
651 |
+
}
|
652 |
+
|
653 |
+
if ( 'textarea' == $type ) {
|
654 |
+
$arr['rows'] = filter_var( wpmem_get( 'add_rows' ), FILTER_SANITIZE_NUMBER_INT );
|
655 |
+
$arr['cols'] = filter_var( wpmem_get( 'add_cols' ), FILTER_SANITIZE_NUMBER_INT );
|
656 |
+
}
|
657 |
+
|
658 |
+
if ( $type == 'checkbox' ) {
|
659 |
+
$add_field_err_msg = ( ! $_POST['add_checked_value'] ) ? __( 'Checked value is required for checkboxes. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
|
660 |
+
$arr[7] = sanitize_text_field( wpmem_get( 'add_checked_value', false ) );
|
661 |
+
$arr[8] = ( 'y' == wpmem_get( 'add_checked_default', 'n' ) ) ? 'y' : 'n';
|
662 |
+
}
|
663 |
+
|
664 |
+
if ( $type == 'select'
|
665 |
+
|| $type == 'multiselect'
|
666 |
+
|| $type == 'radio'
|
667 |
+
|| $type == 'multicheckbox'
|
668 |
+
) {
|
669 |
+
// Get the values.
|
670 |
+
$str = stripslashes( sanitize_textarea_field( $_POST['add_dropdown_value'] ) );
|
671 |
+
// Remove linebreaks.
|
672 |
+
$str = trim( str_replace( array("\r", "\r\n", "\n"), '', $str ) );
|
673 |
+
// Create array.
|
674 |
+
if ( ! function_exists( 'str_getcsv' ) ) {
|
675 |
+
$arr[7] = explode( ',', $str );
|
676 |
+
} else {
|
677 |
+
$arr[7] = str_getcsv( $str, ',', '"' );
|
678 |
+
}
|
679 |
+
// If multiselect or multicheckbox, set delimiter.
|
680 |
+
if ( 'multiselect' == $type || 'multicheckbox' == $type ) {
|
681 |
+
$arr[8] = ( ',' === wpmem_get( 'add_delimiter_value', '|' ) ) ? ',' : '|';
|
682 |
+
}
|
683 |
+
}
|
684 |
+
|
685 |
+
if ( $type == 'file' || $type == 'image' ) {
|
686 |
+
$arr[7] = sanitize_text_field( stripslashes( $_POST['add_file_value'] ) );
|
687 |
+
}
|
688 |
+
|
689 |
+
if ( wpmem_get( 'add_type' ) == 'hidden' ) {
|
690 |
+
$add_field_err_msg = ( ! $_POST['add_hidden_value'] ) ? __( 'A value is required for hidden fields. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
|
691 |
+
$arr[7] = ( isset( $_POST['add_hidden_value'] ) ) ? sanitize_text_field( stripslashes( $_POST['add_hidden_value'] ) ) : '';
|
692 |
+
}
|
693 |
+
|
694 |
+
if ( $action == 'add_field' ) {
|
695 |
+
if ( ! $add_field_err_msg ) {
|
696 |
+
array_push( $wpmem_fields, $arr );
|
697 |
+
$did_update = sprintf( __( '%s was added', 'wp-members' ), esc_html( $_POST['add_name'] ) );
|
698 |
+
} else {
|
699 |
+
$did_update = $add_field_err_msg;
|
700 |
+
}
|
701 |
+
} else {
|
702 |
+
for ( $row = 0; $row < count( $wpmem_fields ); $row++ ) {
|
703 |
+
if ( $wpmem_fields[ $row ][2] == wpmem_get( 'field', false, 'get' ) ) {
|
704 |
+
$arr[0] = $wpmem_fields[ $row ][0];
|
705 |
+
foreach ( $arr as $key => $value ) {
|
706 |
+
$wpmem_fields[ $row ][ $key ] = $arr[ $key ];
|
707 |
+
}
|
708 |
+
}
|
709 |
+
}
|
710 |
+
$did_update = sprintf( __( '%s was updated', 'wp-members' ), esc_html( stripslashes( $add_name ) ) );
|
711 |
+
$did_update.= '<p><a href="' . esc_url( add_query_arg( array( 'page' => 'wpmem-settings', 'tab' => 'fields' ), get_admin_url() . 'options-general.php' ) ) . '">« ' . __( 'Return to Fields Table', 'wp-members' ) . '</a></p>';
|
712 |
+
}
|
713 |
+
|
714 |
+
$wpmem_newfields = $wpmem_fields;
|
715 |
+
|
716 |
+
update_option( 'wpmembers_fields', $wpmem_newfields );
|
717 |
+
$wpmem->load_fields();
|
718 |
+
return $did_update;
|
719 |
+
}
|
720 |
+
}
|
721 |
+
}
|
722 |
+
|
723 |
+
/**
|
724 |
+
* Reorders form fields.
|
725 |
+
*
|
726 |
+
* @since 2.5.1
|
727 |
+
* @since 3.1.8 Rebuilt for new List Table.
|
728 |
+
* @since 3.3.0 Merged do_field_reorder() and field_reorder().
|
729 |
+
*/
|
730 |
+
public static function do_field_reorder() {
|
731 |
+
|
732 |
+
// Start fresh.
|
733 |
+
$new_order = $wpmem_fields = $field = $key = $wpmem_new_fields = $id = $k = '';
|
734 |
+
$wpmem_fields = get_option( 'wpmembers_fields' );
|
735 |
+
|
736 |
+
// Get the list items
|
737 |
+
$new_order = $_POST;
|
738 |
+
|
739 |
+
// Put fields in the proper order for the current form.
|
740 |
+
$wpmem_new_fields = array();
|
741 |
+
foreach ( $new_order['list_items'] as $id ) {
|
742 |
+
foreach( $wpmem_fields as $val ) {
|
743 |
+
if ( $val[0] == $id ) {
|
744 |
+
$wpmem_new_fields[] = $val;
|
745 |
+
}
|
746 |
+
}
|
747 |
+
}
|
748 |
+
|
749 |
+
// Save fields array with new current form field order.
|
750 |
+
update_option( 'wpmembers_fields', $wpmem_new_fields );
|
751 |
+
|
752 |
+
// Indicate successful transaction.
|
753 |
+
_e( 'Form field order updated.', 'wp-members' );
|
754 |
+
|
755 |
+
die(); // This is required to return a proper result.
|
756 |
+
|
757 |
+
}
|
758 |
+
}
|
759 |
// End of file.
|
includes/admin/tabs/class-wp-members-admin-tab-options.php
CHANGED
@@ -6,12 +6,12 @@
|
|
6 |
*
|
7 |
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
-
* Copyright (c) 2006-
|
10 |
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
*
|
12 |
* @package WP-Members
|
13 |
* @author Chad Butler
|
14 |
-
* @copyright 2006-
|
15 |
*/
|
16 |
|
17 |
// Exit if accessed directly.
|
6 |
*
|
7 |
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
+
* Copyright (c) 2006-2020 Chad Butler
|
10 |
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
*
|
12 |
* @package WP-Members
|
13 |
* @author Chad Butler
|
14 |
+
* @copyright 2006-2020
|
15 |
*/
|
16 |
|
17 |
// Exit if accessed directly.
|
includes/admin/tabs/class-wp-members-dropins-table.php
CHANGED
@@ -1,193 +1,193 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members WP_Members_Dropins_Table class
|
4 |
-
*
|
5 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
-
* Copyright (c) 2006-
|
8 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
-
*
|
10 |
-
* @package WP-Members
|
11 |
-
* @author Chad Butler
|
12 |
-
* @copyright 2006-
|
13 |
-
*/
|
14 |
-
|
15 |
-
// Exit if accessed directly.
|
16 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
17 |
-
exit();
|
18 |
-
}
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Extends the WP_List_Table to create a table of dropin files.
|
22 |
-
*
|
23 |
-
* @since 3.1.9
|
24 |
-
*/
|
25 |
-
class WP_Members_Dropins_Table extends WP_List_Table {
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Constructor.
|
29 |
-
*
|
30 |
-
* @since 3.1.9
|
31 |
-
*/
|
32 |
-
function __construct(){
|
33 |
-
global $status, $page;
|
34 |
-
|
35 |
-
//Set parent defaults
|
36 |
-
parent::__construct( array(
|
37 |
-
'singular' => 'dropin',
|
38 |
-
'plural' => 'dropins',
|
39 |
-
'ajax' => false,
|
40 |
-
) );
|
41 |
-
|
42 |
-
$this->dropins = get_option( 'wpmembers_dropins', array() ); //print_r( $this->dropins );
|
43 |
-
}
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Checkbox at start of row.
|
47 |
-
*
|
48 |
-
* @since 3.1.9
|
49 |
-
*
|
50 |
-
* @param $item
|
51 |
-
* @return string The checkbox.
|
52 |
-
*/
|
53 |
-
function column_cb( $item ) {
|
54 |
-
global $wpmem;
|
55 |
-
$checked = checked( true, in_array( $item['dropin_file'], $wpmem->dropins_enabled ), false );
|
56 |
-
//return sprintf( '<input type="checkbox" name="delete[]" value="%s" title="%s" />', $item['dropin_file'], __( 'delete', 'wp-members' ) );
|
57 |
-
return sprintf( '<input type="checkbox" name="%s[]" value="%s" %s />', $this->_args['singular'], $item['dropin_file'], $checked );
|
58 |
-
}
|
59 |
-
|
60 |
-
/**
|
61 |
-
* Returns table columns.
|
62 |
-
*
|
63 |
-
* @since 3.1.9
|
64 |
-
*
|
65 |
-
* @return array
|
66 |
-
*/
|
67 |
-
function get_columns() {
|
68 |
-
return array(
|
69 |
-
'cb' => '<input type="checkbox" />',
|
70 |
-
'dropin_name' => __( 'Name', 'wp-members' ),
|
71 |
-
'dropin_enabled' => __( 'Enabled', 'wp-members' ),
|
72 |
-
'dropin_file' => __( 'File', 'wp-members' ),
|
73 |
-
'dropin_version' => __( 'Version', 'wp-members' ),
|
74 |
-
'dropin_description' => __( 'Description', 'wp-members' ),
|
75 |
-
);
|
76 |
-
}
|
77 |
-
|
78 |
-
/**
|
79 |
-
* Set up table columns.
|
80 |
-
*
|
81 |
-
* @since 3.1.9
|
82 |
-
*/
|
83 |
-
function prepare_items() {
|
84 |
-
$columns = $this->get_columns();
|
85 |
-
$hidden = array();
|
86 |
-
$sortable = array();
|
87 |
-
$this->_column_headers = array( $columns, $hidden, $sortable );
|
88 |
-
$this->process_bulk_action();
|
89 |
-
}
|
90 |
-
|
91 |
-
/**
|
92 |
-
* Iterates through the columns
|
93 |
-
*
|
94 |
-
* @since 3.1.9
|
95 |
-
*
|
96 |
-
* @param array $item
|
97 |
-
* @param string $column_name
|
98 |
-
* @return string $item[ $column_name ]
|
99 |
-
*/
|
100 |
-
function column_default( $item, $column_name ) {
|
101 |
-
switch( $column_name ) {
|
102 |
-
default:
|
103 |
-
return $item[ $column_name ];
|
104 |
-
}
|
105 |
-
}
|
106 |
-
|
107 |
-
/**
|
108 |
-
* Sets actions in the bulk menu.
|
109 |
-
*
|
110 |
-
* @since 3.1.9
|
111 |
-
*
|
112 |
-
* @return array $actions
|
113 |
-
*/
|
114 |
-
function get_bulk_actions() {
|
115 |
-
$actions = array(
|
116 |
-
//'delete' => __( 'Delete Selected', 'wp-members' ),
|
117 |
-
'save' => __( 'Save Settings', 'wp-members' ),
|
118 |
-
);
|
119 |
-
return $actions;
|
120 |
-
}
|
121 |
-
|
122 |
-
/**
|
123 |
-
* Handles "delete" column - checkbox
|
124 |
-
*
|
125 |
-
* @since 3.1.9
|
126 |
-
*
|
127 |
-
* @param array $item
|
128 |
-
* @return string
|
129 |
-
*/
|
130 |
-
function column_delete( $item ) {
|
131 |
-
|
132 |
-
}
|
133 |
-
|
134 |
-
/**
|
135 |
-
* Sets rows so that they have field IDs in the id.
|
136 |
-
*
|
137 |
-
* @since 3.1.9
|
138 |
-
*
|
139 |
-
* @global wpmem
|
140 |
-
* @param array $columns
|
141 |
-
*/
|
142 |
-
function single_row( $columns ) {
|
143 |
-
echo '<tr id="list_items_' . $columns['dropin_name'] . '" class="list_item" list_item="' . $columns['dropin_name'] . '">';
|
144 |
-
echo $this->single_row_columns( $columns );
|
145 |
-
echo "</tr>\n";
|
146 |
-
}
|
147 |
-
|
148 |
-
public function process_bulk_action() {
|
149 |
-
|
150 |
-
global $wpmem;
|
151 |
-
|
152 |
-
//nonce validations,etc
|
153 |
-
|
154 |
-
$dir_chk = WP_Members_Admin_Tab_Dropins::check_dir();
|
155 |
-
|
156 |
-
//echo ( $dir_chk ) ? '.htaccess OK!' : 'NO .htaccess!!!';
|
157 |
-
|
158 |
-
$action = $this->current_action();
|
159 |
-
|
160 |
-
switch ( $action ) {
|
161 |
-
|
162 |
-
case 'delete':
|
163 |
-
|
164 |
-
// Do whatever you want
|
165 |
-
//wp_safe_redirect( esc_url( add_query_arg() ) );
|
166 |
-
break;
|
167 |
-
|
168 |
-
case 'save':
|
169 |
-
$settings = array();
|
170 |
-
//echo "SAVING SETTINGS";print_r( $_REQUEST['dropin'] );
|
171 |
-
if ( wpmem_get( 'dropin' ) ) {
|
172 |
-
foreach( wpmem_get( 'dropin' ) as $dropin ) {
|
173 |
-
$settings[] = $dropin;
|
174 |
-
}
|
175 |
-
update_option( 'wpmembers_dropins', $settings, true );
|
176 |
-
} else {
|
177 |
-
delete_option( 'wpmembers_dropins' );
|
178 |
-
}
|
179 |
-
$wpmem->dropins_enabled = $settings;
|
180 |
-
echo '<div id="message" class="message"><p><strong>' . __( 'WP-Members Dropin settings were updated', 'wp-members' ) . '</strong></p></div>';
|
181 |
-
break;
|
182 |
-
|
183 |
-
default:
|
184 |
-
// do nothing or something else
|
185 |
-
return;
|
186 |
-
break;
|
187 |
-
}
|
188 |
-
return;
|
189 |
-
}
|
190 |
-
|
191 |
-
}
|
192 |
-
|
193 |
// End of file.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members WP_Members_Dropins_Table class
|
4 |
+
*
|
5 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
+
* Copyright (c) 2006-2020 Chad Butler
|
8 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
+
*
|
10 |
+
* @package WP-Members
|
11 |
+
* @author Chad Butler
|
12 |
+
* @copyright 2006-2020
|
13 |
+
*/
|
14 |
+
|
15 |
+
// Exit if accessed directly.
|
16 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
17 |
+
exit();
|
18 |
+
}
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Extends the WP_List_Table to create a table of dropin files.
|
22 |
+
*
|
23 |
+
* @since 3.1.9
|
24 |
+
*/
|
25 |
+
class WP_Members_Dropins_Table extends WP_List_Table {
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Constructor.
|
29 |
+
*
|
30 |
+
* @since 3.1.9
|
31 |
+
*/
|
32 |
+
function __construct(){
|
33 |
+
global $status, $page;
|
34 |
+
|
35 |
+
//Set parent defaults
|
36 |
+
parent::__construct( array(
|
37 |
+
'singular' => 'dropin',
|
38 |
+
'plural' => 'dropins',
|
39 |
+
'ajax' => false,
|
40 |
+
) );
|
41 |
+
|
42 |
+
$this->dropins = get_option( 'wpmembers_dropins', array() ); //print_r( $this->dropins );
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Checkbox at start of row.
|
47 |
+
*
|
48 |
+
* @since 3.1.9
|
49 |
+
*
|
50 |
+
* @param $item
|
51 |
+
* @return string The checkbox.
|
52 |
+
*/
|
53 |
+
function column_cb( $item ) {
|
54 |
+
global $wpmem;
|
55 |
+
$checked = checked( true, in_array( $item['dropin_file'], $wpmem->dropins_enabled ), false );
|
56 |
+
//return sprintf( '<input type="checkbox" name="delete[]" value="%s" title="%s" />', $item['dropin_file'], __( 'delete', 'wp-members' ) );
|
57 |
+
return sprintf( '<input type="checkbox" name="%s[]" value="%s" %s />', $this->_args['singular'], $item['dropin_file'], $checked );
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Returns table columns.
|
62 |
+
*
|
63 |
+
* @since 3.1.9
|
64 |
+
*
|
65 |
+
* @return array
|
66 |
+
*/
|
67 |
+
function get_columns() {
|
68 |
+
return array(
|
69 |
+
'cb' => '<input type="checkbox" />',
|
70 |
+
'dropin_name' => __( 'Name', 'wp-members' ),
|
71 |
+
'dropin_enabled' => __( 'Enabled', 'wp-members' ),
|
72 |
+
'dropin_file' => __( 'File', 'wp-members' ),
|
73 |
+
'dropin_version' => __( 'Version', 'wp-members' ),
|
74 |
+
'dropin_description' => __( 'Description', 'wp-members' ),
|
75 |
+
);
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Set up table columns.
|
80 |
+
*
|
81 |
+
* @since 3.1.9
|
82 |
+
*/
|
83 |
+
function prepare_items() {
|
84 |
+
$columns = $this->get_columns();
|
85 |
+
$hidden = array();
|
86 |
+
$sortable = array();
|
87 |
+
$this->_column_headers = array( $columns, $hidden, $sortable );
|
88 |
+
$this->process_bulk_action();
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Iterates through the columns
|
93 |
+
*
|
94 |
+
* @since 3.1.9
|
95 |
+
*
|
96 |
+
* @param array $item
|
97 |
+
* @param string $column_name
|
98 |
+
* @return string $item[ $column_name ]
|
99 |
+
*/
|
100 |
+
function column_default( $item, $column_name ) {
|
101 |
+
switch( $column_name ) {
|
102 |
+
default:
|
103 |
+
return $item[ $column_name ];
|
104 |
+
}
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Sets actions in the bulk menu.
|
109 |
+
*
|
110 |
+
* @since 3.1.9
|
111 |
+
*
|
112 |
+
* @return array $actions
|
113 |
+
*/
|
114 |
+
function get_bulk_actions() {
|
115 |
+
$actions = array(
|
116 |
+
//'delete' => __( 'Delete Selected', 'wp-members' ),
|
117 |
+
'save' => __( 'Save Settings', 'wp-members' ),
|
118 |
+
);
|
119 |
+
return $actions;
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Handles "delete" column - checkbox
|
124 |
+
*
|
125 |
+
* @since 3.1.9
|
126 |
+
*
|
127 |
+
* @param array $item
|
128 |
+
* @return string
|
129 |
+
*/
|
130 |
+
function column_delete( $item ) {
|
131 |
+
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Sets rows so that they have field IDs in the id.
|
136 |
+
*
|
137 |
+
* @since 3.1.9
|
138 |
+
*
|
139 |
+
* @global wpmem
|
140 |
+
* @param array $columns
|
141 |
+
*/
|
142 |
+
function single_row( $columns ) {
|
143 |
+
echo '<tr id="list_items_' . $columns['dropin_name'] . '" class="list_item" list_item="' . $columns['dropin_name'] . '">';
|
144 |
+
echo $this->single_row_columns( $columns );
|
145 |
+
echo "</tr>\n";
|
146 |
+
}
|
147 |
+
|
148 |
+
public function process_bulk_action() {
|
149 |
+
|
150 |
+
global $wpmem;
|
151 |
+
|
152 |
+
//nonce validations,etc
|
153 |
+
|
154 |
+
$dir_chk = WP_Members_Admin_Tab_Dropins::check_dir();
|
155 |
+
|
156 |
+
//echo ( $dir_chk ) ? '.htaccess OK!' : 'NO .htaccess!!!';
|
157 |
+
|
158 |
+
$action = $this->current_action();
|
159 |
+
|
160 |
+
switch ( $action ) {
|
161 |
+
|
162 |
+
case 'delete':
|
163 |
+
|
164 |
+
// Do whatever you want
|
165 |
+
//wp_safe_redirect( esc_url( add_query_arg() ) );
|
166 |
+
break;
|
167 |
+
|
168 |
+
case 'save':
|
169 |
+
$settings = array();
|
170 |
+
//echo "SAVING SETTINGS";print_r( $_REQUEST['dropin'] );
|
171 |
+
if ( wpmem_get( 'dropin' ) ) {
|
172 |
+
foreach( wpmem_get( 'dropin' ) as $dropin ) {
|
173 |
+
$settings[] = $dropin;
|
174 |
+
}
|
175 |
+
update_option( 'wpmembers_dropins', $settings, true );
|
176 |
+
} else {
|
177 |
+
delete_option( 'wpmembers_dropins' );
|
178 |
+
}
|
179 |
+
$wpmem->dropins_enabled = $settings;
|
180 |
+
echo '<div id="message" class="message"><p><strong>' . __( 'WP-Members Dropin settings were updated', 'wp-members' ) . '</strong></p></div>';
|
181 |
+
break;
|
182 |
+
|
183 |
+
default:
|
184 |
+
// do nothing or something else
|
185 |
+
return;
|
186 |
+
break;
|
187 |
+
}
|
188 |
+
return;
|
189 |
+
}
|
190 |
+
|
191 |
+
}
|
192 |
+
|
193 |
// End of file.
|
includes/admin/tabs/class-wp-members-fields-table.php
CHANGED
@@ -1,168 +1,168 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members WP_Members_Fields_Table class
|
4 |
-
*
|
5 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
-
* Copyright (c) 2006-
|
8 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
-
*
|
10 |
-
* @package WP-Members
|
11 |
-
* @author Chad Butler
|
12 |
-
* @copyright 2006-
|
13 |
-
*/
|
14 |
-
|
15 |
-
// Exit if accessed directly.
|
16 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
17 |
-
exit();
|
18 |
-
}
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Extends the WP_List_Table to create a table of form fields.
|
22 |
-
*
|
23 |
-
* @since 3.1.8
|
24 |
-
*/
|
25 |
-
class WP_Members_Fields_Table extends WP_List_Table {
|
26 |
-
|
27 |
-
private $excludes = array( 'user_registered', 'active', 'wpmem_reg_ip', 'exp_type', 'expires', 'user_id' );
|
28 |
-
|
29 |
-
private $no_delete = array( 'username', 'user_email', 'first_name', 'last_name', 'user_url' );
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Checkbox at start of row.
|
33 |
-
*
|
34 |
-
* @since 3.1.8
|
35 |
-
*
|
36 |
-
* @param $item
|
37 |
-
* @return string The checkbox.
|
38 |
-
*/
|
39 |
-
function column_cb( $item ) {
|
40 |
-
if ( in_array( $item['meta'], $this->no_delete ) || in_array( $item['meta'], $this->excludes ) ) {
|
41 |
-
return;
|
42 |
-
} else {
|
43 |
-
return sprintf( '<input type="checkbox" name="delete[]" value="%s" title="%s" />', $item['meta'], __( 'delete', 'wp-members' ) );
|
44 |
-
}
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Returns table columns.
|
49 |
-
*
|
50 |
-
* @since 3.1.8
|
51 |
-
*
|
52 |
-
* @return array
|
53 |
-
*/
|
54 |
-
function get_columns() {
|
55 |
-
return array(
|
56 |
-
'cb' => '<input type="checkbox" />',
|
57 |
-
'label' => __( 'Display Label', 'wp-members' ),
|
58 |
-
'meta' => __( 'Meta Key', 'wp-members' ),
|
59 |
-
'type' => __( 'Field Type', 'wp-members' ),
|
60 |
-
'display' => __( 'Display?', 'wp-members' ), // __( 'Registration', 'wp-members' ), @todo Wait until fix
|
61 |
-
'req' => __( 'Required', 'wp-members' ),
|
62 |
-
//'profile' => __( 'Profile', 'wp-members' ), @todo Wait until fix
|
63 |
-
'userscrn' => __( 'Users Screen', 'wp-members' ),
|
64 |
-
'usearch' => __( 'Users Search', 'wp-members' ),
|
65 |
-
'edit' => __( 'Edit', 'wp-members' ),
|
66 |
-
'sort' => __( 'Sort', 'wp-members' ),
|
67 |
-
);
|
68 |
-
}
|
69 |
-
|
70 |
-
/**
|
71 |
-
* Set up table columns.
|
72 |
-
*
|
73 |
-
* @since 3.1.8
|
74 |
-
*/
|
75 |
-
function prepare_items() {
|
76 |
-
$columns = $this->get_columns();
|
77 |
-
$hidden = array();
|
78 |
-
$sortable = array();
|
79 |
-
$this->_column_headers = array( $columns, $hidden, $sortable );
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* Iterates through the columns
|
84 |
-
*
|
85 |
-
* @since 3.1.8
|
86 |
-
*
|
87 |
-
* @param array $item
|
88 |
-
* @param string $column_name
|
89 |
-
* @return string $item[ $column_name ]
|
90 |
-
*/
|
91 |
-
function column_default( $item, $column_name ) {
|
92 |
-
switch( $column_name ) {
|
93 |
-
default:
|
94 |
-
return $item[ $column_name ];
|
95 |
-
}
|
96 |
-
}
|
97 |
-
|
98 |
-
/**
|
99 |
-
* Sets actions in the bulk menu.
|
100 |
-
*
|
101 |
-
* @since 3.1.8
|
102 |
-
*
|
103 |
-
* @return array $actions
|
104 |
-
*/
|
105 |
-
function get_bulk_actions() {
|
106 |
-
$actions = array(
|
107 |
-
'delete' => __( 'Delete Selected', 'wp-members' ),
|
108 |
-
'save' => __( 'Save Settings', 'wp-members' ),
|
109 |
-
);
|
110 |
-
return $actions;
|
111 |
-
}
|
112 |
-
|
113 |
-
/**
|
114 |
-
* Handles "delete" column - checkbox
|
115 |
-
*
|
116 |
-
* @since 3.1.8
|
117 |
-
*
|
118 |
-
* @param array $item
|
119 |
-
* @return string
|
120 |
-
*/
|
121 |
-
function column_delete( $item ) {
|
122 |
-
$can_delete = ( $item['meta_key'] == 'user_nicename' || $item['meta_key'] == 'display_name' || $item['meta_key'] == 'nickname' ) ? true : false;
|
123 |
-
return ( ( $can_delete ) || ! $item['native'] ) ? sprintf( $item['native'] . '<input type="checkbox" name="field[%s]" value="delete" />', $item['meta'] ) : '';
|
124 |
-
}
|
125 |
-
|
126 |
-
/**
|
127 |
-
* Sets rows so that they have field IDs in the id.
|
128 |
-
*
|
129 |
-
* @since 3.1.8
|
130 |
-
*
|
131 |
-
* @global wpmem
|
132 |
-
* @param array $columns
|
133 |
-
*/
|
134 |
-
function single_row( $columns ) {
|
135 |
-
if ( in_array( $columns['meta'], $this->excludes ) ) {
|
136 |
-
echo '<tr id="' . esc_attr( $columns['meta'] ) . '" class="nodrag nodrop">';
|
137 |
-
echo $this->single_row_columns( $columns );
|
138 |
-
echo "</tr>\n";
|
139 |
-
} else {
|
140 |
-
echo '<tr id="list_items_' . esc_attr( $columns['order'] ) . '" class="list_item" list_item="' . esc_attr( $columns['order'] ) . '">';
|
141 |
-
echo $this->single_row_columns( $columns );
|
142 |
-
echo "</tr>\n";
|
143 |
-
}
|
144 |
-
}
|
145 |
-
|
146 |
-
public function process_bulk_action() {
|
147 |
-
|
148 |
-
//nonce validations,etc
|
149 |
-
|
150 |
-
$action = $this->current_action();
|
151 |
-
|
152 |
-
switch ( $action ) {
|
153 |
-
|
154 |
-
case 'delete':
|
155 |
-
|
156 |
-
// Do whatever you want
|
157 |
-
wp_safe_redirect( esc_url( add_query_arg() ) );
|
158 |
-
break;
|
159 |
-
|
160 |
-
default:
|
161 |
-
// do nothing or something else
|
162 |
-
return;
|
163 |
-
break;
|
164 |
-
}
|
165 |
-
return;
|
166 |
-
}
|
167 |
-
|
168 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members WP_Members_Fields_Table class
|
4 |
+
*
|
5 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
+
* Copyright (c) 2006-2020 Chad Butler
|
8 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
+
*
|
10 |
+
* @package WP-Members
|
11 |
+
* @author Chad Butler
|
12 |
+
* @copyright 2006-2020
|
13 |
+
*/
|
14 |
+
|
15 |
+
// Exit if accessed directly.
|
16 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
17 |
+
exit();
|
18 |
+
}
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Extends the WP_List_Table to create a table of form fields.
|
22 |
+
*
|
23 |
+
* @since 3.1.8
|
24 |
+
*/
|
25 |
+
class WP_Members_Fields_Table extends WP_List_Table {
|
26 |
+
|
27 |
+
private $excludes = array( 'user_registered', 'active', 'wpmem_reg_ip', 'exp_type', 'expires', 'user_id' );
|
28 |
+
|
29 |
+
private $no_delete = array( 'username', 'user_email', 'first_name', 'last_name', 'user_url' );
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Checkbox at start of row.
|
33 |
+
*
|
34 |
+
* @since 3.1.8
|
35 |
+
*
|
36 |
+
* @param $item
|
37 |
+
* @return string The checkbox.
|
38 |
+
*/
|
39 |
+
function column_cb( $item ) {
|
40 |
+
if ( in_array( $item['meta'], $this->no_delete ) || in_array( $item['meta'], $this->excludes ) ) {
|
41 |
+
return;
|
42 |
+
} else {
|
43 |
+
return sprintf( '<input type="checkbox" name="delete[]" value="%s" title="%s" />', $item['meta'], __( 'delete', 'wp-members' ) );
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Returns table columns.
|
49 |
+
*
|
50 |
+
* @since 3.1.8
|
51 |
+
*
|
52 |
+
* @return array
|
53 |
+
*/
|
54 |
+
function get_columns() {
|
55 |
+
return array(
|
56 |
+
'cb' => '<input type="checkbox" />',
|
57 |
+
'label' => __( 'Display Label', 'wp-members' ),
|
58 |
+
'meta' => __( 'Meta Key', 'wp-members' ),
|
59 |
+
'type' => __( 'Field Type', 'wp-members' ),
|
60 |
+
'display' => __( 'Display?', 'wp-members' ), // __( 'Registration', 'wp-members' ), @todo Wait until fix
|
61 |
+
'req' => __( 'Required', 'wp-members' ),
|
62 |
+
//'profile' => __( 'Profile', 'wp-members' ), @todo Wait until fix
|
63 |
+
'userscrn' => __( 'Users Screen', 'wp-members' ),
|
64 |
+
'usearch' => __( 'Users Search', 'wp-members' ),
|
65 |
+
'edit' => __( 'Edit', 'wp-members' ),
|
66 |
+
'sort' => __( 'Sort', 'wp-members' ),
|
67 |
+
);
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Set up table columns.
|
72 |
+
*
|
73 |
+
* @since 3.1.8
|
74 |
+
*/
|
75 |
+
function prepare_items() {
|
76 |
+
$columns = $this->get_columns();
|
77 |
+
$hidden = array();
|
78 |
+
$sortable = array();
|
79 |
+
$this->_column_headers = array( $columns, $hidden, $sortable );
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Iterates through the columns
|
84 |
+
*
|
85 |
+
* @since 3.1.8
|
86 |
+
*
|
87 |
+
* @param array $item
|
88 |
+
* @param string $column_name
|
89 |
+
* @return string $item[ $column_name ]
|
90 |
+
*/
|
91 |
+
function column_default( $item, $column_name ) {
|
92 |
+
switch( $column_name ) {
|
93 |
+
default:
|
94 |
+
return $item[ $column_name ];
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Sets actions in the bulk menu.
|
100 |
+
*
|
101 |
+
* @since 3.1.8
|
102 |
+
*
|
103 |
+
* @return array $actions
|
104 |
+
*/
|
105 |
+
function get_bulk_actions() {
|
106 |
+
$actions = array(
|
107 |
+
'delete' => __( 'Delete Selected', 'wp-members' ),
|
108 |
+
'save' => __( 'Save Settings', 'wp-members' ),
|
109 |
+
);
|
110 |
+
return $actions;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Handles "delete" column - checkbox
|
115 |
+
*
|
116 |
+
* @since 3.1.8
|
117 |
+
*
|
118 |
+
* @param array $item
|
119 |
+
* @return string
|
120 |
+
*/
|
121 |
+
function column_delete( $item ) {
|
122 |
+
$can_delete = ( $item['meta_key'] == 'user_nicename' || $item['meta_key'] == 'display_name' || $item['meta_key'] == 'nickname' ) ? true : false;
|
123 |
+
return ( ( $can_delete ) || ! $item['native'] ) ? sprintf( $item['native'] . '<input type="checkbox" name="field[%s]" value="delete" />', $item['meta'] ) : '';
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Sets rows so that they have field IDs in the id.
|
128 |
+
*
|
129 |
+
* @since 3.1.8
|
130 |
+
*
|
131 |
+
* @global wpmem
|
132 |
+
* @param array $columns
|
133 |
+
*/
|
134 |
+
function single_row( $columns ) {
|
135 |
+
if ( in_array( $columns['meta'], $this->excludes ) ) {
|
136 |
+
echo '<tr id="' . esc_attr( $columns['meta'] ) . '" class="nodrag nodrop">';
|
137 |
+
echo $this->single_row_columns( $columns );
|
138 |
+
echo "</tr>\n";
|
139 |
+
} else {
|
140 |
+
echo '<tr id="list_items_' . esc_attr( $columns['order'] ) . '" class="list_item" list_item="' . esc_attr( $columns['order'] ) . '">';
|
141 |
+
echo $this->single_row_columns( $columns );
|
142 |
+
echo "</tr>\n";
|
143 |
+
}
|
144 |
+
}
|
145 |
+
|
146 |
+
public function process_bulk_action() {
|
147 |
+
|
148 |
+
//nonce validations,etc
|
149 |
+
|
150 |
+
$action = $this->current_action();
|
151 |
+
|
152 |
+
switch ( $action ) {
|
153 |
+
|
154 |
+
case 'delete':
|
155 |
+
|
156 |
+
// Do whatever you want
|
157 |
+
wp_safe_redirect( esc_url( add_query_arg() ) );
|
158 |
+
break;
|
159 |
+
|
160 |
+
default:
|
161 |
+
// do nothing or something else
|
162 |
+
return;
|
163 |
+
break;
|
164 |
+
}
|
165 |
+
return;
|
166 |
+
}
|
167 |
+
|
168 |
}
|
includes/api/api-email.php
CHANGED
@@ -1,119 +1,119 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members Email API Functions
|
4 |
-
*
|
5 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
-
* Copyright (c) 2006-
|
8 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
-
*
|
10 |
-
* @package WP-Members
|
11 |
-
* @subpackage WP-Members API Functions
|
12 |
-
* @author Chad Butler
|
13 |
-
* @copyright 2006-
|
14 |
-
*/
|
15 |
-
|
16 |
-
/**
|
17 |
-
* Returns the wp_mail from address (if set).
|
18 |
-
*
|
19 |
-
* @since 2.7
|
20 |
-
* @since 3.1 Converted to use email var in object.
|
21 |
-
*
|
22 |
-
* @global object $wpmem
|
23 |
-
* @return string $wpmem_mail_from|$email
|
24 |
-
*/
|
25 |
-
function wpmem_mail_from() {
|
26 |
-
global $wpmem;
|
27 |
-
return $wpmem->email->from;
|
28 |
-
}
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Returns the wp_mail from name (if set).
|
32 |
-
*
|
33 |
-
* @since 2.7
|
34 |
-
* @since 3.1 Converted to use email var in object.
|
35 |
-
*
|
36 |
-
* @global object $wpmem
|
37 |
-
* @return string $wpmem_mail_from_name|$name
|
38 |
-
*/
|
39 |
-
function wpmem_mail_from_name() {
|
40 |
-
global $wpmem;
|
41 |
-
return $wpmem->email->from_name;
|
42 |
-
}
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Builds emails for the user.
|
46 |
-
*
|
47 |
-
* @since 3.2.3
|
48 |
-
*
|
49 |
-
* @global object $wpmem The WP_Members object.
|
50 |
-
* @param mixed $args {
|
51 |
-
* Settings arguments or The User's ID.
|
52 |
-
*
|
53 |
-
* @type int $user_id
|
54 |
-
* @type string $password
|
55 |
-
* @type string $tag
|
56 |
-
* @type array $wpmem_fields
|
57 |
-
* @type array $fields
|
58 |
-
* @type array $custom {
|
59 |
-
* Settings for custom email if used (optional).
|
60 |
-
*
|
61 |
-
* @type string $subj The email subject.
|
62 |
-
* @type string $body The email message body.
|
63 |
-
* @type string $tag The email tag.
|
64 |
-
* }
|
65 |
-
* }
|
66 |
-
* @param string $password Password from the registration process.
|
67 |
-
* @param string $tag Indicates the email being sent (newreg|newmod|appmod|repass|getuser).
|
68 |
-
* @param array $wpmem_fields Array of the WP-Members fields (defaults to null).
|
69 |
-
* @param array $fields Array of the registration data (defaults to null).
|
70 |
-
* @param array $custom {
|
71 |
-
* Array of custom email information (defaults to null).
|
72 |
-
*
|
73 |
-
* @type string $subj The email subject.
|
74 |
-
* @type string $body The email message body.
|
75 |
-
* @type string $tag The email tag.
|
76 |
-
* }
|
77 |
-
*
|
78 |
-
* @todo Will probably change the WP_Members_Email::to_user() arguments to just accept the array.
|
79 |
-
*/
|
80 |
-
function wpmem_email_to_user( $args, $password = null, $tag = null, $wpmem_fields = null, $field_data = null, $custom = null ) {
|
81 |
-
global $wpmem;
|
82 |
-
if ( is_array( $args ) ) {
|
83 |
-
$user_id = $args['user_id'];
|
84 |
-
$password = $args['password'];
|
85 |
-
$tag = $args['tag'];
|
86 |
-
$wpmem_fields = $args['wpmem_fields'];
|
87 |
-
$field_data = $args['field_data'];
|
88 |
-
$custom = $args['custom'];
|
89 |
-
} else {
|
90 |
-
$user_id = $args;
|
91 |
-
}
|
92 |
-
$wpmem->email->to_user( $user_id, $password, $tag, $wpmem_fields, $field_data, $custom );
|
93 |
-
return;
|
94 |
-
}
|
95 |
-
|
96 |
-
if ( ! function_exists( 'wpmem_notify_admin' ) ):
|
97 |
-
/**
|
98 |
-
* Builds the email for admin notification of new user registration.
|
99 |
-
*
|
100 |
-
* @since 2.3
|
101 |
-
* @since 3.2.3 Changed inputs.
|
102 |
-
*
|
103 |
-
* @global object $wpmem The WP_Members object.
|
104 |
-
* @param mixed $args Settings arguments or The User's ID.
|
105 |
-
* @param array $wpmem_fields Array of the WP-Members fields (defaults to null).
|
106 |
-
* @param array $field_data Array of the registration data (defaults to null).
|
107 |
-
*/
|
108 |
-
function wpmem_notify_admin( $args, $wpmem_fields = null, $field_data = null ) {
|
109 |
-
global $wpmem;
|
110 |
-
if ( is_array( $args ) ) {
|
111 |
-
$user_id = $args['user_id'];
|
112 |
-
$wpmem_fields = $args['wpmem_fields'];
|
113 |
-
$field_data = $args['field_data'];
|
114 |
-
} else {
|
115 |
-
$user_id = $args;
|
116 |
-
}
|
117 |
-
$wpmem->email->notify_admin( $user_id, $wpmem_fields, $field_data );
|
118 |
-
}
|
119 |
endif;
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members Email API Functions
|
4 |
+
*
|
5 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
+
* Copyright (c) 2006-2020 Chad Butler
|
8 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
+
*
|
10 |
+
* @package WP-Members
|
11 |
+
* @subpackage WP-Members API Functions
|
12 |
+
* @author Chad Butler
|
13 |
+
* @copyright 2006-2020
|
14 |
+
*/
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Returns the wp_mail from address (if set).
|
18 |
+
*
|
19 |
+
* @since 2.7
|
20 |
+
* @since 3.1 Converted to use email var in object.
|
21 |
+
*
|
22 |
+
* @global object $wpmem
|
23 |
+
* @return string $wpmem_mail_from|$email
|
24 |
+
*/
|
25 |
+
function wpmem_mail_from() {
|
26 |
+
global $wpmem;
|
27 |
+
return $wpmem->email->from;
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Returns the wp_mail from name (if set).
|
32 |
+
*
|
33 |
+
* @since 2.7
|
34 |
+
* @since 3.1 Converted to use email var in object.
|
35 |
+
*
|
36 |
+
* @global object $wpmem
|
37 |
+
* @return string $wpmem_mail_from_name|$name
|
38 |
+
*/
|
39 |
+
function wpmem_mail_from_name() {
|
40 |
+
global $wpmem;
|
41 |
+
return $wpmem->email->from_name;
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Builds emails for the user.
|
46 |
+
*
|
47 |
+
* @since 3.2.3
|
48 |
+
*
|
49 |
+
* @global object $wpmem The WP_Members object.
|
50 |
+
* @param mixed $args {
|
51 |
+
* Settings arguments or The User's ID.
|
52 |
+
*
|
53 |
+
* @type int $user_id
|
54 |
+
* @type string $password
|
55 |
+
* @type string $tag
|
56 |
+
* @type array $wpmem_fields
|
57 |
+
* @type array $fields
|
58 |
+
* @type array $custom {
|
59 |
+
* Settings for custom email if used (optional).
|
60 |
+
*
|
61 |
+
* @type string $subj The email subject.
|
62 |
+
* @type string $body The email message body.
|
63 |
+
* @type string $tag The email tag.
|
64 |
+
* }
|
65 |
+
* }
|
66 |
+
* @param string $password Password from the registration process.
|
67 |
+
* @param string $tag Indicates the email being sent (newreg|newmod|appmod|repass|getuser).
|
68 |
+
* @param array $wpmem_fields Array of the WP-Members fields (defaults to null).
|
69 |
+
* @param array $fields Array of the registration data (defaults to null).
|
70 |
+
* @param array $custom {
|
71 |
+
* Array of custom email information (defaults to null).
|
72 |
+
*
|
73 |
+
* @type string $subj The email subject.
|
74 |
+
* @type string $body The email message body.
|
75 |
+
* @type string $tag The email tag.
|
76 |
+
* }
|
77 |
+
*
|
78 |
+
* @todo Will probably change the WP_Members_Email::to_user() arguments to just accept the array.
|
79 |
+
*/
|
80 |
+
function wpmem_email_to_user( $args, $password = null, $tag = null, $wpmem_fields = null, $field_data = null, $custom = null ) {
|
81 |
+
global $wpmem;
|
82 |
+
if ( is_array( $args ) ) {
|
83 |
+
$user_id = $args['user_id'];
|
84 |
+
$password = $args['password'];
|
85 |
+
$tag = $args['tag'];
|
86 |
+
$wpmem_fields = $args['wpmem_fields'];
|
87 |
+
$field_data = $args['field_data'];
|
88 |
+
$custom = $args['custom'];
|
89 |
+
} else {
|
90 |
+
$user_id = $args;
|
91 |
+
}
|
92 |
+
$wpmem->email->to_user( $user_id, $password, $tag, $wpmem_fields, $field_data, $custom );
|
93 |
+
return;
|
94 |
+
}
|
95 |
+
|
96 |
+
if ( ! function_exists( 'wpmem_notify_admin' ) ):
|
97 |
+
/**
|
98 |
+
* Builds the email for admin notification of new user registration.
|
99 |
+
*
|
100 |
+
* @since 2.3
|
101 |
+
* @since 3.2.3 Changed inputs.
|
102 |
+
*
|
103 |
+
* @global object $wpmem The WP_Members object.
|
104 |
+
* @param mixed $args Settings arguments or The User's ID.
|
105 |
+
* @param array $wpmem_fields Array of the WP-Members fields (defaults to null).
|
106 |
+
* @param array $field_data Array of the registration data (defaults to null).
|
107 |
+
*/
|
108 |
+
function wpmem_notify_admin( $args, $wpmem_fields = null, $field_data = null ) {
|
109 |
+
global $wpmem;
|
110 |
+
if ( is_array( $args ) ) {
|
111 |
+
$user_id = $args['user_id'];
|
112 |
+
$wpmem_fields = $args['wpmem_fields'];
|
113 |
+
$field_data = $args['field_data'];
|
114 |
+
} else {
|
115 |
+
$user_id = $args;
|
116 |
+
}
|
117 |
+
$wpmem->email->notify_admin( $user_id, $wpmem_fields, $field_data );
|
118 |
+
}
|
119 |
endif;
|
includes/api/api-forms.php
CHANGED
@@ -4,13 +4,13 @@
|
|
4 |
*
|
5 |
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
-
* Copyright (c) 2006-
|
8 |
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
*
|
10 |
* @package WP-Members
|
11 |
* @subpackage WP-Members API Functions
|
12 |
* @author Chad Butler
|
13 |
-
* @copyright 2006-
|
14 |
*/
|
15 |
|
16 |
if ( ! function_exists( 'wpmem_login_form' ) ):
|
@@ -71,6 +71,19 @@ function wpmem_login_form( $args, $arr = false ) {
|
|
71 |
}
|
72 |
endif;
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
/**
|
75 |
* Invokes a registration or user profile update form.
|
76 |
*
|
@@ -273,11 +286,14 @@ function wpmem_fields( $tag = '', $form = 'default' ) {
|
|
273 |
* Filters the fields array.
|
274 |
*
|
275 |
* @since 3.1.7
|
|
|
276 |
*
|
277 |
* @param array $wpmem->fields
|
278 |
* @param string $tag (optional)
|
279 |
*/
|
280 |
-
|
|
|
|
|
281 |
}
|
282 |
|
283 |
/**
|
4 |
*
|
5 |
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
+
* Copyright (c) 2006-2020 Chad Butler
|
8 |
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
*
|
10 |
* @package WP-Members
|
11 |
* @subpackage WP-Members API Functions
|
12 |
* @author Chad Butler
|
13 |
+
* @copyright 2006-2020
|
14 |
*/
|
15 |
|
16 |
if ( ! function_exists( 'wpmem_login_form' ) ):
|
71 |
}
|
72 |
endif;
|
73 |
|
74 |
+
/**
|
75 |
+
* Use the WP login form.
|
76 |
+
*
|
77 |
+
* @since 3.3.2
|
78 |
+
*
|
79 |
+
* @global stdClass $wpmem
|
80 |
+
* @param array $args
|
81 |
+
*/
|
82 |
+
function wpmem_wp_login_form( $args ) {
|
83 |
+
global $wpmem;
|
84 |
+
return $wpmem->forms->wp_login_form( $args );
|
85 |
+
}
|
86 |
+
|
87 |
/**
|
88 |
* Invokes a registration or user profile update form.
|
89 |
*
|
286 |
* Filters the fields array.
|
287 |
*
|
288 |
* @since 3.1.7
|
289 |
+
* @since 3.3.2 Change object var and return.
|
290 |
*
|
291 |
* @param array $wpmem->fields
|
292 |
* @param string $tag (optional)
|
293 |
*/
|
294 |
+
$wpmem->fields = apply_filters( 'wpmem_fields', $wpmem->fields, $tag );
|
295 |
+
|
296 |
+
return $wpmem->fields;
|
297 |
}
|
298 |
|
299 |
/**
|
includes/api/api-products.php
CHANGED
@@ -1,19 +1,19 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members API Functions
|
4 |
-
*
|
5 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
-
* Copyright (c) 2006-
|
8 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
-
*
|
10 |
-
* @package WP-Members
|
11 |
-
* @subpackage WP-Members API Functions
|
12 |
-
* @author Chad Butler
|
13 |
-
* @copyright 2006-
|
14 |
-
*/
|
15 |
-
|
16 |
-
function wpmem_get_product_post_list( $product_key ) {
|
17 |
-
global $wpmem;
|
18 |
-
return $wpmem->membership->get_all_posts( $product_key );
|
19 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members API Functions
|
4 |
+
*
|
5 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
+
* Copyright (c) 2006-2020 Chad Butler
|
8 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
+
*
|
10 |
+
* @package WP-Members
|
11 |
+
* @subpackage WP-Members API Functions
|
12 |
+
* @author Chad Butler
|
13 |
+
* @copyright 2006-2020
|
14 |
+
*/
|
15 |
+
|
16 |
+
function wpmem_get_product_post_list( $product_key ) {
|
17 |
+
global $wpmem;
|
18 |
+
return $wpmem->membership->get_all_posts( $product_key );
|
19 |
}
|
includes/api/api-users.php
CHANGED
@@ -1,772 +1,763 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members User API Functions
|
4 |
-
*
|
5 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
-
* Copyright (c) 2006-
|
8 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
-
*
|
10 |
-
* @package WP-Members
|
11 |
-
* @subpackage WP-Members API Functions
|
12 |
-
* @author Chad Butler
|
13 |
-
* @copyright 2006-
|
14 |
-
*/
|
15 |
-
|
16 |
-
/**
|
17 |
-
* Checks if a user exists.
|
18 |
-
*
|
19 |
-
* @since 3.2.5
|
20 |
-
*
|
21 |
-
* @param $user_id
|
22 |
-
* @return boolean
|
23 |
-
*/
|
24 |
-
function wpmem_is_user( $user_id ) {
|
25 |
-
$user = get_userdata( $user_id );
|
26 |
-
return ( $user ) ? true : false;
|
27 |
-
}
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Returns the current user's current role.
|
31 |
-
*
|
32 |
-
* Note that users may have more than one role. This returns
|
33 |
-
* whatever the internal pointer is set to. Usually, this will
|
34 |
-
* be the first element in the array, but not always.
|
35 |
-
* @see: https://www.php.net/manual/en/function.current.php
|
36 |
-
*
|
37 |
-
* @since 3.3.0
|
38 |
-
*
|
39 |
-
* @param int $user_id
|
40 |
-
* @return mixed If the user is set and has roles, the current user role, otherwise false.
|
41 |
-
*/
|
42 |
-
function wpmem_get_user_role( $user_id = false ) {
|
43 |
-
$user = ( $user_id ) ? get_userdata( $user_id ) : wp_get_current_user();
|
44 |
-
return ( $user ) ? current( $user->roles ) : false;
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Checks if user has a particular role.
|
49 |
-
*
|
50 |
-
* Utility function to check if a given user has a specific role. Users can
|
51 |
-
* have multiple roles assigned, so it checks the role array rather than using
|
52 |
-
* the incorrect method of current_user_can( 'role_name' ). The function can
|
53 |
-
* check the role of the current user (default) or a specific user (if $user_id
|
54 |
-
* is passed).
|
55 |
-
*
|
56 |
-
* @since 3.1.1
|
57 |
-
* @since 3.1.6 Include accepting an array of roles to check.
|
58 |
-
* @since 3.1.9 Return false if user is not logged in.
|
59 |
-
* @since 3.2.0 Change return false to not logged in AND no user id.
|
60 |
-
*
|
61 |
-
* @global object $current_user Current user object.
|
62 |
-
* @global object $wpmem WP_Members object.
|
63 |
-
* @param string|array $role Slug or array of slugs of the role being checked.
|
64 |
-
* @param int $user_id ID of the user being checked (optional).
|
65 |
-
* @return boolean $has_role True if user has the role, otherwise false.
|
66 |
-
*/
|
67 |
-
function wpmem_user_has_role( $role, $user_id = false ) {
|
68 |
-
if ( ! is_user_logged_in() && ! $user_id ) {
|
69 |
-
return false;
|
70 |
-
}
|
71 |
-
global $current_user, $wpmem;
|
72 |
-
$has_role = false;
|
73 |
-
if ( $user_id ) {
|
74 |
-
$user = get_userdata( $user_id );
|
75 |
-
} else {
|
76 |
-
$user = ( isset( $current_user ) ) ? $current_user : wp_get_current_user();
|
77 |
-
}
|
78 |
-
if ( is_array( $role ) ) {
|
79 |
-
foreach ( $role as $r ) {
|
80 |
-
if ( in_array( $r, $user->roles ) ) {
|
81 |
-
return true;
|
82 |
-
}
|
83 |
-
}
|
84 |
-
} else {
|
85 |
-
return ( in_array( $role, $user->roles ) ) ? true : $has_role;
|
86 |
-
}
|
87 |
-
}
|
88 |
-
|
89 |
-
/**
|
90 |
-
* Gets user meta.
|
91 |
-
*
|
92 |
-
* It may seem like WP already has this feature. And it does. But most user meta
|
93 |
-
* are single, and WP's get_user_meta() defaults to "false" for the $single
|
94 |
-
* argument. This function provides a shorthand that assumes a string value for
|
95 |
-
* the meta result and drops the $single argument.
|
96 |
-
*
|
97 |
-
* @since 3.3.0
|
98 |
-
*
|
99 |
-
* @param int $user_id
|
100 |
-
* @param string $meta_key
|
101 |
-
* @return string $result
|
102 |
-
*/
|
103 |
-
function wpmem_get_user_meta( $user_id, $meta_key ) {
|
104 |
-
return get_user_meta( $user_id, $meta_key, true );
|
105 |
-
}
|
106 |
-
|
107 |
-
/**
|
108 |
-
* Checks if a user has a given meta value.
|
109 |
-
*
|
110 |
-
* @since 3.1.8
|
111 |
-
* @since 3.3.0 Added wpmem_user_has_meta filter.
|
112 |
-
* @since 3.3.0 Added array check for multi-value fields (multicheckbox and multiselect).
|
113 |
-
*
|
114 |
-
* @global object $wpmem WP_Members object.
|
115 |
-
*
|
116 |
-
* @param string $meta Meta key being checked.
|
117 |
-
* @param string $value Value the meta key should have (optional).
|
118 |
-
* @param int $user_id ID of the user being checked (optional).
|
119 |
-
* @return boolean $has_meta True if user has the meta value, otherwise false.
|
120 |
-
*/
|
121 |
-
function wpmem_user_has_meta( $meta, $value = false, $user_id = false ) {
|
122 |
-
|
123 |
-
global $wpmem;
|
124 |
-
|
125 |
-
// Get the user ID.
|
126 |
-
$user_id = ( $user_id ) ? $user_id : get_current_user_id();
|
127 |
-
|
128 |
-
// Get field type.
|
129 |
-
$fields = wpmem_fields();
|
130 |
-
$multi = ( ( isset( $fields[ $meta ] ) ) && ( 'multicheckbox' == $fields[ $meta ]['type'] || 'multiselect' == $fields[ $meta ]['type'] ) ) ? true : false;
|
131 |
-
|
132 |
-
// Get meta.
|
133 |
-
$has_meta = false;
|
134 |
-
$user_value = get_user_meta( $user_id, $meta, true );
|
135 |
-
|
136 |
-
// Check meta.
|
137 |
-
if ( $value ) {
|
138 |
-
if ( $multi ) {
|
139 |
-
// Check array of values.
|
140 |
-
$user_value = explode( $fields[ $meta ]['delimiter'], $user_value );
|
141 |
-
$has_meta = ( in_array( $value, $user_value ) ) ? true : $has_meta;
|
142 |
-
} else {
|
143 |
-
// Straight comparison.
|
144 |
-
$has_meta = ( $user_value == $value ) ? true : $has_meta;
|
145 |
-
}
|
146 |
-
} else {
|
147 |
-
// Check if the user has any meta value (regardless of actual value).
|
148 |
-
$has_meta = ( $user_value ) ? true : $has_meta;
|
149 |
-
}
|
150 |
-
|
151 |
-
/**
|
152 |
-
* Filter the user has meta result.
|
153 |
-
*
|
154 |
-
* @since 3.3.0
|
155 |
-
*
|
156 |
-
* @param bool $has_meta True if the user has the value, otherwise false.
|
157 |
-
* @param int $user_id The user ID being checked.
|
158 |
-
* @param string $user_value The user's stored meta value (false if none).
|
159 |
-
*/
|
160 |
-
return apply_filters( 'wpmem_user_has_meta', $has_meta, $user_id, $user_value );
|
161 |
-
}
|
162 |
-
|
163 |
-
/**
|
164 |
-
* Checks if a user is activated.
|
165 |
-
*
|
166 |
-
* @since 3.1.7
|
167 |
-
* @since 3.2.3 Now a wrapper for WP_Members_Users::is_user_activated().
|
168 |
-
*
|
169 |
-
* @global object $wpmem
|
170 |
-
* @param int $user_id
|
171 |
-
* @return bool
|
172 |
-
*/
|
173 |
-
function wpmem_is_user_activated( $user_id = false ) {
|
174 |
-
global $wpmem;
|
175 |
-
return $wpmem->user->is_user_activated( $user_id );
|
176 |
-
}
|
177 |
-
|
178 |
-
/**
|
179 |
-
* Gets an array of the user's registration data.
|
180 |
-
*
|
181 |
-
* Returns an array keyed by meta keys of the user's registration data for
|
182 |
-
* all fields in the WP-Members Fields. Returns the current user unless
|
183 |
-
* a user ID is specified.
|
184 |
-
*
|
185 |
-
* @since 3.2.0
|
186 |
-
*
|
187 |
-
* @global object $wpmem
|
188 |
-
* @param integer $user_id
|
189 |
-
* @param bool $all
|
190 |
-
* @return array $user_fields
|
191 |
-
*/
|
192 |
-
function wpmem_user_data( $user_id = false, $all = false ) {
|
193 |
-
global $wpmem;
|
194 |
-
return $wpmem->user->user_data( $user_id, $all );
|
195 |
-
}
|
196 |
-
|
197 |
-
/**
|
198 |
-
* Updates a user's role.
|
199 |
-
*
|
200 |
-
* This is a wrapper for $wpmem->update_user_role(). It can add a role to a
|
201 |
-
* user, change or remove the user's role. If no action is specified it will
|
202 |
-
* change the role.
|
203 |
-
*
|
204 |
-
* @since 3.2.0
|
205 |
-
*
|
206 |
-
* @global object $wpmem
|
207 |
-
* @param integer $user_id (required)
|
208 |
-
* @param string $role (required)
|
209 |
-
* @param string $action (optional add|remove|set default:set)
|
210 |
-
*/
|
211 |
-
function wpmem_update_user_role( $user_id, $role, $action = 'set' ) {
|
212 |
-
global $wpmem;
|
213 |
-
$wpmem->user->update_user_role( $user_id, $role, $action );
|
214 |
-
}
|
215 |
-
|
216 |
-
/**
|
217 |
-
* A function for checking user access criteria.
|
218 |
-
*
|
219 |
-
* @since 3.2.0
|
220 |
-
* @since 3.2.3 Reversed order of arguments.
|
221 |
-
*
|
222 |
-
* @param mixed $product
|
223 |
-
* @param integer $user_id User ID (optional|default: false).
|
224 |
-
* @return boolean $access If user has access.
|
225 |
-
*/
|
226 |
-
function wpmem_user_has_access( $product, $user_id = false ) {
|
227 |
-
global $wpmem;
|
228 |
-
return $wpmem->user->has_access( $product, $user_id );
|
229 |
-
}
|
230 |
-
|
231 |
-
/**
|
232 |
-
* Sets product access for a user.
|
233 |
-
*
|
234 |
-
* @since 3.2.3
|
235 |
-
* @since 3.2.6 Added $date to set a specific expiration date.
|
236 |
-
*
|
237 |
-
* @global object $wpmem
|
238 |
-
* @param string $product The meta key of the product.
|
239 |
-
* @param int $user_id
|
240 |
-
* @param string $date Expiration date (optional) format: MySQL timestamp
|
241 |
-
* @return bool $result
|
242 |
-
*/
|
243 |
-
function wpmem_set_user_product( $product, $user_id = false, $date = false ) {
|
244 |
-
global $wpmem;
|
245 |
-
return $wpmem->user->set_user_product( $product, $user_id, $date );
|
246 |
-
}
|
247 |
-
|
248 |
-
/**
|
249 |
-
* Removes product access for a user.
|
250 |
-
*
|
251 |
-
* @since 3.2.3
|
252 |
-
*
|
253 |
-
* @global object $wpmem
|
254 |
-
* @param string $product
|
255 |
-
* @param int $user_id
|
256 |
-
*/
|
257 |
-
function wpmem_remove_user_product( $product, $user_id = false ) {
|
258 |
-
global $wpmem;
|
259 |
-
$wpmem->user->remove_user_product( $product, $user_id );
|
260 |
-
return;
|
261 |
-
}
|
262 |
-
|
263 |
-
/**
|
264 |
-
* Gets memberships a user has.
|
265 |
-
*
|
266 |
-
* @since 3.3.0
|
267 |
-
*
|
268 |
-
* @global stdClass $wpmem
|
269 |
-
* @param int $user_id
|
270 |
-
*/
|
271 |
-
function wpmem_get_user_products( $user_id = false ) {
|
272 |
-
global $wpmem;
|
273 |
-
return ( $user_id ) ? $wpmem->user->get_user_products( $user_id ) : $wpmem->user->access;
|
274 |
-
}
|
275 |
-
|
276 |
-
/**
|
277 |
-
* Sets a user as logged in.
|
278 |
-
*
|
279 |
-
* @since 3.2.3
|
280 |
-
*
|
281 |
-
* @global object $wpmem
|
282 |
-
* @param int $user_id
|
283 |
-
*/
|
284 |
-
function wpmem_set_as_logged_in( $user_id ) {
|
285 |
-
global $wpmem;
|
286 |
-
$wpmem->user->set_as_logged_in( $user_id );
|
287 |
-
}
|
288 |
-
|
289 |
-
if ( ! function_exists( 'wpmem_login' ) ):
|
290 |
-
/**
|
291 |
-
* Logs in the user.
|
292 |
-
*
|
293 |
-
* Logs in the the user using wp_signon (since 2.5.2). If login is
|
294 |
-
* successful, it will set a cookie using wp_set_auth_cookie (since 2.7.7),
|
295 |
-
* then it redirects and exits; otherwise "loginfailed" is returned.
|
296 |
-
*
|
297 |
-
* @since 0.1.0
|
298 |
-
* @since 2.5.2 Now uses wp_signon().
|
299 |
-
* @since 2.7.7 Sets cookie using wp_set_auth_cookie().
|
300 |
-
* @since 3.0.0 Removed wp_set_auth_cookie(), this already happens in wp_signon().
|
301 |
-
* @since 3.1.7 Now a wrapper for login() in WP_Members_Users Class.
|
302 |
-
* @since 3.2.4 Moved to user API (could be deprecated).
|
303 |
-
*
|
304 |
-
* @global object $wpmem
|
305 |
-
* @return string Returns "loginfailed" if the login fails.
|
306 |
-
*/
|
307 |
-
function wpmem_login() {
|
308 |
-
global $wpmem;
|
309 |
-
return $wpmem->user->login();
|
310 |
-
} // End of login function.
|
311 |
-
endif;
|
312 |
-
|
313 |
-
if ( ! function_exists( 'wpmem_logout' ) ):
|
314 |
-
/**
|
315 |
-
* Logs the user out then redirects.
|
316 |
-
*
|
317 |
-
* @since 2.0.0
|
318 |
-
* @since 3.1.6 Added wp_destroy_current_session(), removed nocache_headers().
|
319 |
-
* @since 3.1.7 Now a wrapper for logout() in WP_Members_Users Class.
|
320 |
-
* @since 3.2.4 Moved to user API (could be deprecated).
|
321 |
-
*
|
322 |
-
* @global object $wpmem
|
323 |
-
* @param string $redirect_to The URL to redirect to at logout.
|
324 |
-
*/
|
325 |
-
function wpmem_logout( $redirect_to = false ) {
|
326 |
-
global $wpmem;
|
327 |
-
$wpmem->user->logout( $redirect_to );
|
328 |
-
}
|
329 |
-
endif;
|
330 |
-
|
331 |
-
if ( ! function_exists( 'wpmem_change_password' ) ):
|
332 |
-
/**
|
333 |
-
* Handles user password change (not reset).
|
334 |
-
*
|
335 |
-
* @since 2.1.0
|
336 |
-
* @since 3.1.7 Now a wrapper for password_update() in WP_Members_Users Class.
|
337 |
-
* @since 3.2.4 Moved to user API (could be deprecated).
|
338 |
-
*
|
339 |
-
* @global int $user_ID The WordPress user ID.
|
340 |
-
*
|
341 |
-
* @return string The value for $wpmem->regchk
|
342 |
-
*/
|
343 |
-
function wpmem_change_password() {
|
344 |
-
global $wpmem;
|
345 |
-
return $wpmem->user->password_update( 'change' );
|
346 |
-
}
|
347 |
-
endif;
|
348 |
-
|
349 |
-
if ( ! function_exists( 'wpmem_reset_password' ) ):
|
350 |
-
/**
|
351 |
-
* Resets a forgotten password.
|
352 |
-
*
|
353 |
-
* @since 2.1.0
|
354 |
-
* @since 3.1.7 Now a wrapper for password_update() in WP_Members_Users Class.
|
355 |
-
* @since 3.2.4 Moved to user API (could be deprecated).
|
356 |
-
*
|
357 |
-
* @global object $wpmem The WP-Members object class.
|
358 |
-
*
|
359 |
-
* @return string The value for $wpmem->regchk
|
360 |
-
*/
|
361 |
-
function wpmem_reset_password() {
|
362 |
-
global $wpmem;
|
363 |
-
return $wpmem->user->password_update( 'reset' );
|
364 |
-
}
|
365 |
-
endif;
|
366 |
-
|
367 |
-
/**
|
368 |
-
* Handles retrieving a forgotten username.
|
369 |
-
*
|
370 |
-
* @since 3.0.8
|
371 |
-
* @since 3.1.6 Dependencies now loaded by object.
|
372 |
-
* @since 3.1.8 Now a wrapper for $wpmem->retrieve_username() in WP_Members_Users Class.
|
373 |
-
* @since 3.2.4 Moved to user API (could be deprecated).
|
374 |
-
*
|
375 |
-
* @global object $wpmem The WP-Members object class.
|
376 |
-
*
|
377 |
-
* @return string $regchk The regchk value.
|
378 |
-
*/
|
379 |
-
function wpmem_retrieve_username() {
|
380 |
-
global $wpmem;
|
381 |
-
return $wpmem->user->retrieve_username();
|
382 |
-
}
|
383 |
-
|
384 |
-
/**
|
385 |
-
* Creates a membership number.
|
386 |
-
*
|
387 |
-
* @since 3.1.1
|
388 |
-
* @since 3.2.0 Changed "lead" to "pad".
|
389 |
-
*
|
390 |
-
* @param array $args {
|
391 |
-
* @type string $option The wp_options name for the counter setting (required).
|
392 |
-
* @type string $meta_key The field's meta key (required).
|
393 |
-
* @type int $start Number to start with (optional, default 0).
|
394 |
-
* @type int $increment Number to increment by (optional, default 1).
|
395 |
-
* @type int $digits Number of digits for the number (optional).
|
396 |
-
* @type boolen $pad Pad leading zeros (optional, default true).
|
397 |
-
* }
|
398 |
-
* @return string $membersip_number
|
399 |
-
*/
|
400 |
-
function wpmem_create_membership_number( $args ) {
|
401 |
-
global $wpmem;
|
402 |
-
return $wpmem->api->generate_membership_number( $args );
|
403 |
-
}
|
404 |
-
|
405 |
-
/**
|
406 |
-
* Activates a user.
|
407 |
-
*
|
408 |
-
* If registration is moderated, sets the activated flag
|
409 |
-
* in the usermeta. Flag prevents login when $wpmem->mod_reg
|
410 |
-
* is true (1). Function is fired from bulk user edit or
|
411 |
-
* user profile update.
|
412 |
-
*
|
413 |
-
* @uses $wpdb WordPress Database object.
|
414 |
-
*
|
415 |
-
* @since 2.4
|
416 |
-
* @since 3.1.6 Dependencies now loaded by object.
|
417 |
-
* @since 3.2.4 Renamed from wpmem_a_activate_user().
|
418 |
-
* @since 3.3.0 Moved to user API.
|
419 |
-
*
|
420 |
-
* @param int $user_id
|
421 |
-
*/
|
422 |
-
function wpmem_activate_user( $user_id ) {
|
423 |
-
|
424 |
-
global $wpmem;
|
425 |
-
|
426 |
-
// Define new_pass.
|
427 |
-
$new_pass = '';
|
428 |
-
|
429 |
-
// If passwords are user defined skip this.
|
430 |
-
if ( ! wpmem_user_sets_password() ) {
|
431 |
-
$new_pass = wp_generate_password();
|
432 |
-
wp_set_password( $new_pass, $user_id );
|
433 |
-
}
|
434 |
-
|
435 |
-
// @todo this should be taken out, use the wpmem_user_activated hook instead.
|
436 |
-
// If subscriptions can expire, and the user has no expiration date, set one.
|
437 |
-
if ( $wpmem->use_exp == 1 && ! get_user_meta( $user_id, 'expires', true ) ) {
|
438 |
-
if ( function_exists( 'wpmem_set_exp' ) ) {
|
439 |
-
wpmem_set_exp( $user_id );
|
440 |
-
}
|
441 |
-
}
|
442 |
-
|
443 |
-
// Generate and send user approved email to user.
|
444 |
-
wpmem_email_to_user( $user_id, $new_pass, 2 );
|
445 |
-
|
446 |
-
// Set the active flag in usermeta.
|
447 |
-
update_user_meta( $user_id, 'active', 1 );
|
448 |
-
|
449 |
-
/**
|
450 |
-
* Fires after the user activation process is complete.
|
451 |
-
*
|
452 |
-
* @since 2.8.2
|
453 |
-
*
|
454 |
-
* @param int $user_id The user's ID.
|
455 |
-
*/
|
456 |
-
do_action( 'wpmem_user_activated', $user_id );
|
457 |
-
|
458 |
-
return;
|
459 |
-
}
|
460 |
-
|
461 |
-
/**
|
462 |
-
* Deactivates a user.
|
463 |
-
*
|
464 |
-
* Reverses the active flag from the activation process
|
465 |
-
* preventing login when registration is moderated.
|
466 |
-
*
|
467 |
-
* @since 2.7.1
|
468 |
-
* @since 3.2.4 Renamed from wpmem_a_deactivate_user().
|
469 |
-
* @since 3.3.0 Moved to user API.
|
470 |
-
*
|
471 |
-
* @param int $user_id
|
472 |
-
*/
|
473 |
-
function wpmem_deactivate_user( $user_id ) {
|
474 |
-
update_user_meta( $user_id, 'active', 0 );
|
475 |
-
|
476 |
-
/**
|
477 |
-
* Fires after the user deactivation process is complete.
|
478 |
-
*
|
479 |
-
* @since 2.9.9
|
480 |
-
*
|
481 |
-
* @param int $user_id The user's ID.
|
482 |
-
*/
|
483 |
-
do_action( 'wpmem_user_deactivated', $user_id );
|
484 |
-
}
|
485 |
-
|
486 |
-
/**
|
487 |
-
* Updates the user_status value in the wp_users table.
|
488 |
-
*
|
489 |
-
* @since Unknown
|
490 |
-
* @since 3.3.0 Moved to User API.
|
491 |
-
*
|
492 |
-
* @global object $wpdb
|
493 |
-
*
|
494 |
-
* @param int $user_id
|
495 |
-
* @param string $status
|
496 |
-
*/
|
497 |
-
function wpmem_set_user_status( $user_id, $status ) {
|
498 |
-
global $wpdb;
|
499 |
-
$wpdb->update( $wpdb->users, array( 'user_status' => $status ), array( 'ID' => $user_id ) );
|
500 |
-
return;
|
501 |
-
}
|
502 |
-
|
503 |
-
/**
|
504 |
-
* Register function.
|
505 |
-
*
|
506 |
-
* Handles registering new users and updating existing users.
|
507 |
-
*
|
508 |
-
* @since 2.2.1
|
509 |
-
* @since 2.7.2 Added pre/post process actions.
|
510 |
-
* @since 2.8.2 Added validation and data filters.
|
511 |
-
* @since 2.9.3 Added validation for multisite.
|
512 |
-
* @since 3.0.0 Moved from wp-members-register.php to /inc/register.php.
|
513 |
-
* @since 3.3.0 Ported from wpmem_registration in /inc/register.php (now deprecated).
|
514 |
-
*
|
515 |
-
* @todo Review what should be in the API function and what should be moved to object classes.
|
516 |
-
*
|
517 |
-
* @global int $user_ID
|
518 |
-
* @global object $wpmem
|
519 |
-
* @global string $wpmem_themsg
|
520 |
-
* @global array $userdata
|
521 |
-
*
|
522 |
-
* @param string $tag Identifies 'register' or 'update'.
|
523 |
-
* @return string $wpmem_themsg|success|editsuccess
|
524 |
-
*/
|
525 |
-
function wpmem_user_register( $tag ) {
|
526 |
-
|
527 |
-
// Get the globals.
|
528 |
-
global $user_ID, $wpmem, $wpmem_themsg, $userdata;
|
529 |
-
|
530 |
-
$wpmem->user->register_validate( $tag );
|
531 |
-
|
532 |
-
switch ( $tag ) {
|
533 |
-
|
534 |
-
case "register":
|
535 |
-
|
536 |
-
/**
|
537 |
-
* Filter registration data after validation before data insertion.
|
538 |
-
*
|
539 |
-
* @since 2.8.2
|
540 |
-
*
|
541 |
-
* @param array $wpmem->user->post_data An array of the registration field data.
|
542 |
-
* @param string $tag A switch to indicate the action (new|edit).
|
543 |
-
*/
|
544 |
-
$wpmem->user->post_data = apply_filters( 'wpmem_register_data', $wpmem->user->post_data, 'new' );
|
545 |
-
|
546 |
-
/**
|
547 |
-
* Fires before any insertion/emails.
|
548 |
-
*
|
549 |
-
* This action is the final step in pre registering a user. This
|
550 |
-
* can be used for attaching custom validation to the registration
|
551 |
-
* process. It cannot be used for changing any user registration
|
552 |
-
* data. Use the wpmem_register_data filter for that.
|
553 |
-
*
|
554 |
-
* @since 2.7.2
|
555 |
-
*
|
556 |
-
* @param array $wpmem->user->post_data The user's submitted registration data.
|
557 |
-
*/
|
558 |
-
do_action( 'wpmem_pre_register_data', $wpmem->user->post_data );
|
559 |
-
|
560 |
-
// If the _pre_register_data hook sends back an error message.
|
561 |
-
if ( $wpmem_themsg ) {
|
562 |
-
return $wpmem_themsg;
|
563 |
-
}
|
564 |
-
|
565 |
-
// Main new user fields are ready.
|
566 |
-
$new_user_fields = array (
|
567 |
-
'user_pass' => $wpmem->user->post_data['password'],
|
568 |
-
'user_login' => $wpmem->user->post_data['username'],
|
569 |
-
'user_nicename' => $wpmem->user->post_data['user_nicename'],
|
570 |
-
'user_email' => $wpmem->user->post_data['user_email'],
|
571 |
-
'display_name' => $wpmem->user->post_data['display_name'],
|
572 |
-
'nickname' => $wpmem->user->post_data['nickname'],
|
573 |
-
'user_registered' => $wpmem->user->post_data['user_registered'],
|
574 |
-
'role' => $wpmem->user->post_data['user_role']
|
575 |
-
);
|
576 |
-
|
577 |
-
// Get any excluded meta fields.
|
578 |
-
$wpmem->excluded_meta = wpmem_get_excluded_meta( 'register' );
|
579 |
-
|
580 |
-
// Fields for wp_insert_user: user_url, first_name, last_name, description, jabber, aim, yim.
|
581 |
-
$new_user_fields_meta = array( 'user_url', 'first_name', 'last_name', 'description', 'jabber', 'aim', 'yim' );
|
582 |
-
foreach ( $wpmem->fields as $meta_key => $field ) {
|
583 |
-
if ( in_array( $meta_key, $new_user_fields_meta ) ) {
|
584 |
-
if ( $field['register'] && ! in_array( $meta_key, $wpmem->excluded_meta ) ) {
|
585 |
-
$new_user_fields[ $meta_key ] = $wpmem->user->post_data[ $meta_key ];
|
586 |
-
}
|
587 |
-
}
|
588 |
-
}
|
589 |
-
|
590 |
-
// Inserts to wp_users table.
|
591 |
-
|
592 |
-
|
593 |
-
/**
|
594 |
-
* Fires after
|
595 |
-
*
|
596 |
-
* @since 2.7.
|
597 |
-
*
|
598 |
-
* @
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
*
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
'
|
679 |
-
'
|
680 |
-
'
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
'
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
/**
|
764 |
-
* Filter the IP result.
|
765 |
-
*
|
766 |
-
* @since 3.3.0
|
767 |
-
*
|
768 |
-
* @param string $ip
|
769 |
-
*/
|
770 |
-
return apply_filters( 'wpmem_get_ip', $ip );
|
771 |
-
}
|
772 |
// End of file.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members User API Functions
|
4 |
+
*
|
5 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
+
* Copyright (c) 2006-2020 Chad Butler
|
8 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
+
*
|
10 |
+
* @package WP-Members
|
11 |
+
* @subpackage WP-Members API Functions
|
12 |
+
* @author Chad Butler
|
13 |
+
* @copyright 2006-2020
|
14 |
+
*/
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Checks if a user exists.
|
18 |
+
*
|
19 |
+
* @since 3.2.5
|
20 |
+
*
|
21 |
+
* @param $user_id
|
22 |
+
* @return boolean
|
23 |
+
*/
|
24 |
+
function wpmem_is_user( $user_id ) {
|
25 |
+
$user = get_userdata( $user_id );
|
26 |
+
return ( $user ) ? true : false;
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Returns the current user's current role.
|
31 |
+
*
|
32 |
+
* Note that users may have more than one role. This returns
|
33 |
+
* whatever the internal pointer is set to. Usually, this will
|
34 |
+
* be the first element in the array, but not always.
|
35 |
+
* @see: https://www.php.net/manual/en/function.current.php
|
36 |
+
*
|
37 |
+
* @since 3.3.0
|
38 |
+
*
|
39 |
+
* @param int $user_id
|
40 |
+
* @return mixed If the user is set and has roles, the current user role, otherwise false.
|
41 |
+
*/
|
42 |
+
function wpmem_get_user_role( $user_id = false ) {
|
43 |
+
$user = ( $user_id ) ? get_userdata( $user_id ) : wp_get_current_user();
|
44 |
+
return ( $user ) ? current( $user->roles ) : false;
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Checks if user has a particular role.
|
49 |
+
*
|
50 |
+
* Utility function to check if a given user has a specific role. Users can
|
51 |
+
* have multiple roles assigned, so it checks the role array rather than using
|
52 |
+
* the incorrect method of current_user_can( 'role_name' ). The function can
|
53 |
+
* check the role of the current user (default) or a specific user (if $user_id
|
54 |
+
* is passed).
|
55 |
+
*
|
56 |
+
* @since 3.1.1
|
57 |
+
* @since 3.1.6 Include accepting an array of roles to check.
|
58 |
+
* @since 3.1.9 Return false if user is not logged in.
|
59 |
+
* @since 3.2.0 Change return false to not logged in AND no user id.
|
60 |
+
*
|
61 |
+
* @global object $current_user Current user object.
|
62 |
+
* @global object $wpmem WP_Members object.
|
63 |
+
* @param string|array $role Slug or array of slugs of the role being checked.
|
64 |
+
* @param int $user_id ID of the user being checked (optional).
|
65 |
+
* @return boolean $has_role True if user has the role, otherwise false.
|
66 |
+
*/
|
67 |
+
function wpmem_user_has_role( $role, $user_id = false ) {
|
68 |
+
if ( ! is_user_logged_in() && ! $user_id ) {
|
69 |
+
return false;
|
70 |
+
}
|
71 |
+
global $current_user, $wpmem;
|
72 |
+
$has_role = false;
|
73 |
+
if ( $user_id ) {
|
74 |
+
$user = get_userdata( $user_id );
|
75 |
+
} else {
|
76 |
+
$user = ( isset( $current_user ) ) ? $current_user : wp_get_current_user();
|
77 |
+
}
|
78 |
+
if ( is_array( $role ) ) {
|
79 |
+
foreach ( $role as $r ) {
|
80 |
+
if ( in_array( $r, $user->roles ) ) {
|
81 |
+
return true;
|
82 |
+
}
|
83 |
+
}
|
84 |
+
} else {
|
85 |
+
return ( in_array( $role, $user->roles ) ) ? true : $has_role;
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Gets user meta.
|
91 |
+
*
|
92 |
+
* It may seem like WP already has this feature. And it does. But most user meta
|
93 |
+
* are single, and WP's get_user_meta() defaults to "false" for the $single
|
94 |
+
* argument. This function provides a shorthand that assumes a string value for
|
95 |
+
* the meta result and drops the $single argument.
|
96 |
+
*
|
97 |
+
* @since 3.3.0
|
98 |
+
*
|
99 |
+
* @param int $user_id
|
100 |
+
* @param string $meta_key
|
101 |
+
* @return string $result
|
102 |
+
*/
|
103 |
+
function wpmem_get_user_meta( $user_id, $meta_key ) {
|
104 |
+
return get_user_meta( $user_id, $meta_key, true );
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Checks if a user has a given meta value.
|
109 |
+
*
|
110 |
+
* @since 3.1.8
|
111 |
+
* @since 3.3.0 Added wpmem_user_has_meta filter.
|
112 |
+
* @since 3.3.0 Added array check for multi-value fields (multicheckbox and multiselect).
|
113 |
+
*
|
114 |
+
* @global object $wpmem WP_Members object.
|
115 |
+
*
|
116 |
+
* @param string $meta Meta key being checked.
|
117 |
+
* @param string $value Value the meta key should have (optional).
|
118 |
+
* @param int $user_id ID of the user being checked (optional).
|
119 |
+
* @return boolean $has_meta True if user has the meta value, otherwise false.
|
120 |
+
*/
|
121 |
+
function wpmem_user_has_meta( $meta, $value = false, $user_id = false ) {
|
122 |
+
|
123 |
+
global $wpmem;
|
124 |
+
|
125 |
+
// Get the user ID.
|
126 |
+
$user_id = ( $user_id ) ? $user_id : get_current_user_id();
|
127 |
+
|
128 |
+
// Get field type.
|
129 |
+
$fields = wpmem_fields();
|
130 |
+
$multi = ( ( isset( $fields[ $meta ] ) ) && ( 'multicheckbox' == $fields[ $meta ]['type'] || 'multiselect' == $fields[ $meta ]['type'] ) ) ? true : false;
|
131 |
+
|
132 |
+
// Get meta.
|
133 |
+
$has_meta = false;
|
134 |
+
$user_value = get_user_meta( $user_id, $meta, true );
|
135 |
+
|
136 |
+
// Check meta.
|
137 |
+
if ( $value ) {
|
138 |
+
if ( $multi ) {
|
139 |
+
// Check array of values.
|
140 |
+
$user_value = explode( $fields[ $meta ]['delimiter'], $user_value );
|
141 |
+
$has_meta = ( in_array( $value, $user_value ) ) ? true : $has_meta;
|
142 |
+
} else {
|
143 |
+
// Straight comparison.
|
144 |
+
$has_meta = ( $user_value == $value ) ? true : $has_meta;
|
145 |
+
}
|
146 |
+
} else {
|
147 |
+
// Check if the user has any meta value (regardless of actual value).
|
148 |
+
$has_meta = ( $user_value ) ? true : $has_meta;
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Filter the user has meta result.
|
153 |
+
*
|
154 |
+
* @since 3.3.0
|
155 |
+
*
|
156 |
+
* @param bool $has_meta True if the user has the value, otherwise false.
|
157 |
+
* @param int $user_id The user ID being checked.
|
158 |
+
* @param string $user_value The user's stored meta value (false if none).
|
159 |
+
*/
|
160 |
+
return apply_filters( 'wpmem_user_has_meta', $has_meta, $user_id, $user_value );
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Checks if a user is activated.
|
165 |
+
*
|
166 |
+
* @since 3.1.7
|
167 |
+
* @since 3.2.3 Now a wrapper for WP_Members_Users::is_user_activated().
|
168 |
+
*
|
169 |
+
* @global object $wpmem
|
170 |
+
* @param int $user_id
|
171 |
+
* @return bool
|
172 |
+
*/
|
173 |
+
function wpmem_is_user_activated( $user_id = false ) {
|
174 |
+
global $wpmem;
|
175 |
+
return $wpmem->user->is_user_activated( $user_id );
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Gets an array of the user's registration data.
|
180 |
+
*
|
181 |
+
* Returns an array keyed by meta keys of the user's registration data for
|
182 |
+
* all fields in the WP-Members Fields. Returns the current user unless
|
183 |
+
* a user ID is specified.
|
184 |
+
*
|
185 |
+
* @since 3.2.0
|
186 |
+
*
|
187 |
+
* @global object $wpmem
|
188 |
+
* @param integer $user_id
|
189 |
+
* @param bool $all
|
190 |
+
* @return array $user_fields
|
191 |
+
*/
|
192 |
+
function wpmem_user_data( $user_id = false, $all = false ) {
|
193 |
+
global $wpmem;
|
194 |
+
return $wpmem->user->user_data( $user_id, $all );
|
195 |
+
}
|
196 |
+
|
197 |
+
/**
|
198 |
+
* Updates a user's role.
|
199 |
+
*
|
200 |
+
* This is a wrapper for $wpmem->update_user_role(). It can add a role to a
|
201 |
+
* user, change or remove the user's role. If no action is specified it will
|
202 |
+
* change the role.
|
203 |
+
*
|
204 |
+
* @since 3.2.0
|
205 |
+
*
|
206 |
+
* @global object $wpmem
|
207 |
+
* @param integer $user_id (required)
|
208 |
+
* @param string $role (required)
|
209 |
+
* @param string $action (optional add|remove|set default:set)
|
210 |
+
*/
|
211 |
+
function wpmem_update_user_role( $user_id, $role, $action = 'set' ) {
|
212 |
+
global $wpmem;
|
213 |
+
$wpmem->user->update_user_role( $user_id, $role, $action );
|
214 |
+
}
|
215 |
+
|
216 |
+
/**
|
217 |
+
* A function for checking user access criteria.
|
218 |
+
*
|
219 |
+
* @since 3.2.0
|
220 |
+
* @since 3.2.3 Reversed order of arguments.
|
221 |
+
*
|
222 |
+
* @param mixed $product
|
223 |
+
* @param integer $user_id User ID (optional|default: false).
|
224 |
+
* @return boolean $access If user has access.
|
225 |
+
*/
|
226 |
+
function wpmem_user_has_access( $product, $user_id = false ) {
|
227 |
+
global $wpmem;
|
228 |
+
return $wpmem->user->has_access( $product, $user_id );
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Sets product access for a user.
|
233 |
+
*
|
234 |
+
* @since 3.2.3
|
235 |
+
* @since 3.2.6 Added $date to set a specific expiration date.
|
236 |
+
*
|
237 |
+
* @global object $wpmem
|
238 |
+
* @param string $product The meta key of the product.
|
239 |
+
* @param int $user_id
|
240 |
+
* @param string $date Expiration date (optional) format: MySQL timestamp
|
241 |
+
* @return bool $result
|
242 |
+
*/
|
243 |
+
function wpmem_set_user_product( $product, $user_id = false, $date = false ) {
|
244 |
+
global $wpmem;
|
245 |
+
return $wpmem->user->set_user_product( $product, $user_id, $date );
|
246 |
+
}
|
247 |
+
|
248 |
+
/**
|
249 |
+
* Removes product access for a user.
|
250 |
+
*
|
251 |
+
* @since 3.2.3
|
252 |
+
*
|
253 |
+
* @global object $wpmem
|
254 |
+
* @param string $product
|
255 |
+
* @param int $user_id
|
256 |
+
*/
|
257 |
+
function wpmem_remove_user_product( $product, $user_id = false ) {
|
258 |
+
global $wpmem;
|
259 |
+
$wpmem->user->remove_user_product( $product, $user_id );
|
260 |
+
return;
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Gets memberships a user has.
|
265 |
+
*
|
266 |
+
* @since 3.3.0
|
267 |
+
*
|
268 |
+
* @global stdClass $wpmem
|
269 |
+
* @param int $user_id
|
270 |
+
*/
|
271 |
+
function wpmem_get_user_products( $user_id = false ) {
|
272 |
+
global $wpmem;
|
273 |
+
return ( $user_id ) ? $wpmem->user->get_user_products( $user_id ) : $wpmem->user->access;
|
274 |
+
}
|
275 |
+
|
276 |
+
/**
|
277 |
+
* Sets a user as logged in.
|
278 |
+
*
|
279 |
+
* @since 3.2.3
|
280 |
+
*
|
281 |
+
* @global object $wpmem
|
282 |
+
* @param int $user_id
|
283 |
+
*/
|
284 |
+
function wpmem_set_as_logged_in( $user_id ) {
|
285 |
+
global $wpmem;
|
286 |
+
$wpmem->user->set_as_logged_in( $user_id );
|
287 |
+
}
|
288 |
+
|
289 |
+
if ( ! function_exists( 'wpmem_login' ) ):
|
290 |
+
/**
|
291 |
+
* Logs in the user.
|
292 |
+
*
|
293 |
+
* Logs in the the user using wp_signon (since 2.5.2). If login is
|
294 |
+
* successful, it will set a cookie using wp_set_auth_cookie (since 2.7.7),
|
295 |
+
* then it redirects and exits; otherwise "loginfailed" is returned.
|
296 |
+
*
|
297 |
+
* @since 0.1.0
|
298 |
+
* @since 2.5.2 Now uses wp_signon().
|
299 |
+
* @since 2.7.7 Sets cookie using wp_set_auth_cookie().
|
300 |
+
* @since 3.0.0 Removed wp_set_auth_cookie(), this already happens in wp_signon().
|
301 |
+
* @since 3.1.7 Now a wrapper for login() in WP_Members_Users Class.
|
302 |
+
* @since 3.2.4 Moved to user API (could be deprecated).
|
303 |
+
*
|
304 |
+
* @global object $wpmem
|
305 |
+
* @return string Returns "loginfailed" if the login fails.
|
306 |
+
*/
|
307 |
+
function wpmem_login() {
|
308 |
+
global $wpmem;
|
309 |
+
return $wpmem->user->login();
|
310 |
+
} // End of login function.
|
311 |
+
endif;
|
312 |
+
|
313 |
+
if ( ! function_exists( 'wpmem_logout' ) ):
|
314 |
+
/**
|
315 |
+
* Logs the user out then redirects.
|
316 |
+
*
|
317 |
+
* @since 2.0.0
|
318 |
+
* @since 3.1.6 Added wp_destroy_current_session(), removed nocache_headers().
|
319 |
+
* @since 3.1.7 Now a wrapper for logout() in WP_Members_Users Class.
|
320 |
+
* @since 3.2.4 Moved to user API (could be deprecated).
|
321 |
+
*
|
322 |
+
* @global object $wpmem
|
323 |
+
* @param string $redirect_to The URL to redirect to at logout.
|
324 |
+
*/
|
325 |
+
function wpmem_logout( $redirect_to = false ) {
|
326 |
+
global $wpmem;
|
327 |
+
$wpmem->user->logout( $redirect_to );
|
328 |
+
}
|
329 |
+
endif;
|
330 |
+
|
331 |
+
if ( ! function_exists( 'wpmem_change_password' ) ):
|
332 |
+
/**
|
333 |
+
* Handles user password change (not reset).
|
334 |
+
*
|
335 |
+
* @since 2.1.0
|
336 |
+
* @since 3.1.7 Now a wrapper for password_update() in WP_Members_Users Class.
|
337 |
+
* @since 3.2.4 Moved to user API (could be deprecated).
|
338 |
+
*
|
339 |
+
* @global int $user_ID The WordPress user ID.
|
340 |
+
*
|
341 |
+
* @return string The value for $wpmem->regchk
|
342 |
+
*/
|
343 |
+
function wpmem_change_password() {
|
344 |
+
global $wpmem;
|
345 |
+
return $wpmem->user->password_update( 'change' );
|
346 |
+
}
|
347 |
+
endif;
|
348 |
+
|
349 |
+
if ( ! function_exists( 'wpmem_reset_password' ) ):
|
350 |
+
/**
|
351 |
+
* Resets a forgotten password.
|
352 |
+
*
|
353 |
+
* @since 2.1.0
|
354 |
+
* @since 3.1.7 Now a wrapper for password_update() in WP_Members_Users Class.
|
355 |
+
* @since 3.2.4 Moved to user API (could be deprecated).
|
356 |
+
*
|
357 |
+
* @global object $wpmem The WP-Members object class.
|
358 |
+
*
|
359 |
+
* @return string The value for $wpmem->regchk
|
360 |
+
*/
|
361 |
+
function wpmem_reset_password() {
|
362 |
+
global $wpmem;
|
363 |
+
return $wpmem->user->password_update( 'reset' );
|
364 |
+
}
|
365 |
+
endif;
|
366 |
+
|
367 |
+
/**
|
368 |
+
* Handles retrieving a forgotten username.
|
369 |
+
*
|
370 |
+
* @since 3.0.8
|
371 |
+
* @since 3.1.6 Dependencies now loaded by object.
|
372 |
+
* @since 3.1.8 Now a wrapper for $wpmem->retrieve_username() in WP_Members_Users Class.
|
373 |
+
* @since 3.2.4 Moved to user API (could be deprecated).
|
374 |
+
*
|
375 |
+
* @global object $wpmem The WP-Members object class.
|
376 |
+
*
|
377 |
+
* @return string $regchk The regchk value.
|
378 |
+
*/
|
379 |
+
function wpmem_retrieve_username() {
|
380 |
+
global $wpmem;
|
381 |
+
return $wpmem->user->retrieve_username();
|
382 |
+
}
|
383 |
+
|
384 |
+
/**
|
385 |
+
* Creates a membership number.
|
386 |
+
*
|
387 |
+
* @since 3.1.1
|
388 |
+
* @since 3.2.0 Changed "lead" to "pad".
|
389 |
+
*
|
390 |
+
* @param array $args {
|
391 |
+
* @type string $option The wp_options name for the counter setting (required).
|
392 |
+
* @type string $meta_key The field's meta key (required).
|
393 |
+
* @type int $start Number to start with (optional, default 0).
|
394 |
+
* @type int $increment Number to increment by (optional, default 1).
|
395 |
+
* @type int $digits Number of digits for the number (optional).
|
396 |
+
* @type boolen $pad Pad leading zeros (optional, default true).
|
397 |
+
* }
|
398 |
+
* @return string $membersip_number
|
399 |
+
*/
|
400 |
+
function wpmem_create_membership_number( $args ) {
|
401 |
+
global $wpmem;
|
402 |
+
return $wpmem->api->generate_membership_number( $args );
|
403 |
+
}
|
404 |
+
|
405 |
+
/**
|
406 |
+
* Activates a user.
|
407 |
+
*
|
408 |
+
* If registration is moderated, sets the activated flag
|
409 |
+
* in the usermeta. Flag prevents login when $wpmem->mod_reg
|
410 |
+
* is true (1). Function is fired from bulk user edit or
|
411 |
+
* user profile update.
|
412 |
+
*
|
413 |
+
* @uses $wpdb WordPress Database object.
|
414 |
+
*
|
415 |
+
* @since 2.4
|
416 |
+
* @since 3.1.6 Dependencies now loaded by object.
|
417 |
+
* @since 3.2.4 Renamed from wpmem_a_activate_user().
|
418 |
+
* @since 3.3.0 Moved to user API.
|
419 |
+
*
|
420 |
+
* @param int $user_id
|
421 |
+
*/
|
422 |
+
function wpmem_activate_user( $user_id ) {
|
423 |
+
|
424 |
+
global $wpmem;
|
425 |
+
|
426 |
+
// Define new_pass.
|
427 |
+
$new_pass = '';
|
428 |
+
|
429 |
+
// If passwords are user defined skip this.
|
430 |
+
if ( ! wpmem_user_sets_password() ) {
|
431 |
+
$new_pass = wp_generate_password();
|
432 |
+
wp_set_password( $new_pass, $user_id );
|
433 |
+
}
|
434 |
+
|
435 |
+
// @todo this should be taken out, use the wpmem_user_activated hook instead.
|
436 |
+
// If subscriptions can expire, and the user has no expiration date, set one.
|
437 |
+
if ( $wpmem->use_exp == 1 && ! get_user_meta( $user_id, 'expires', true ) ) {
|
438 |
+
if ( function_exists( 'wpmem_set_exp' ) ) {
|
439 |
+
wpmem_set_exp( $user_id );
|
440 |
+
}
|
441 |
+
}
|
442 |
+
|
443 |
+
// Generate and send user approved email to user.
|
444 |
+
wpmem_email_to_user( $user_id, $new_pass, 2 );
|
445 |
+
|
446 |
+
// Set the active flag in usermeta.
|
447 |
+
update_user_meta( $user_id, 'active', 1 );
|
448 |
+
|
449 |
+
/**
|
450 |
+
* Fires after the user activation process is complete.
|
451 |
+
*
|
452 |
+
* @since 2.8.2
|
453 |
+
*
|
454 |
+
* @param int $user_id The user's ID.
|
455 |
+
*/
|
456 |
+
do_action( 'wpmem_user_activated', $user_id );
|
457 |
+
|
458 |
+
return;
|
459 |
+
}
|
460 |
+
|
461 |
+
/**
|
462 |
+
* Deactivates a user.
|
463 |
+
*
|
464 |
+
* Reverses the active flag from the activation process
|
465 |
+
* preventing login when registration is moderated.
|
466 |
+
*
|
467 |
+
* @since 2.7.1
|
468 |
+
* @since 3.2.4 Renamed from wpmem_a_deactivate_user().
|
469 |
+
* @since 3.3.0 Moved to user API.
|
470 |
+
*
|
471 |
+
* @param int $user_id
|
472 |
+
*/
|
473 |
+
function wpmem_deactivate_user( $user_id ) {
|
474 |
+
update_user_meta( $user_id, 'active', 0 );
|
475 |
+
|
476 |
+
/**
|
477 |
+
* Fires after the user deactivation process is complete.
|
478 |
+
*
|
479 |
+
* @since 2.9.9
|
480 |
+
*
|
481 |
+
* @param int $user_id The user's ID.
|
482 |
+
*/
|
483 |
+
do_action( 'wpmem_user_deactivated', $user_id );
|
484 |
+
}
|
485 |
+
|
486 |
+
/**
|
487 |
+
* Updates the user_status value in the wp_users table.
|
488 |
+
*
|
489 |
+
* @since Unknown
|
490 |
+
* @since 3.3.0 Moved to User API.
|
491 |
+
*
|
492 |
+
* @global object $wpdb
|
493 |
+
*
|
494 |
+
* @param int $user_id
|
495 |
+
* @param string $status
|
496 |
+
*/
|
497 |
+
function wpmem_set_user_status( $user_id, $status ) {
|
498 |
+
global $wpdb;
|
499 |
+
$wpdb->update( $wpdb->users, array( 'user_status' => $status ), array( 'ID' => $user_id ) );
|
500 |
+
return;
|
501 |
+
}
|
502 |
+
|
503 |
+
/**
|
504 |
+
* Register function.
|
505 |
+
*
|
506 |
+
* Handles registering new users and updating existing users.
|
507 |
+
*
|
508 |
+
* @since 2.2.1
|
509 |
+
* @since 2.7.2 Added pre/post process actions.
|
510 |
+
* @since 2.8.2 Added validation and data filters.
|
511 |
+
* @since 2.9.3 Added validation for multisite.
|
512 |
+
* @since 3.0.0 Moved from wp-members-register.php to /inc/register.php.
|
513 |
+
* @since 3.3.0 Ported from wpmem_registration in /inc/register.php (now deprecated).
|
514 |
+
*
|
515 |
+
* @todo Review what should be in the API function and what should be moved to object classes.
|
516 |
+
*
|
517 |
+
* @global int $user_ID
|
518 |
+
* @global object $wpmem
|
519 |
+
* @global string $wpmem_themsg
|
520 |
+
* @global array $userdata
|
521 |
+
*
|
522 |
+
* @param string $tag Identifies 'register' or 'update'.
|
523 |
+
* @return string $wpmem_themsg|success|editsuccess
|
524 |
+
*/
|
525 |
+
function wpmem_user_register( $tag ) {
|
526 |
+
|
527 |
+
// Get the globals.
|
528 |
+
global $user_ID, $wpmem, $wpmem_themsg, $userdata;
|
529 |
+
|
530 |
+
$wpmem->user->register_validate( $tag );
|
531 |
+
|
532 |
+
switch ( $tag ) {
|
533 |
+
|
534 |
+
case "register":
|
535 |
+
|
536 |
+
/**
|
537 |
+
* Filter registration data after validation before data insertion.
|
538 |
+
*
|
539 |
+
* @since 2.8.2
|
540 |
+
*
|
541 |
+
* @param array $wpmem->user->post_data An array of the registration field data.
|
542 |
+
* @param string $tag A switch to indicate the action (new|edit).
|
543 |
+
*/
|
544 |
+
$wpmem->user->post_data = apply_filters( 'wpmem_register_data', $wpmem->user->post_data, 'new' );
|
545 |
+
|
546 |
+
/**
|
547 |
+
* Fires before any insertion/emails.
|
548 |
+
*
|
549 |
+
* This action is the final step in pre registering a user. This
|
550 |
+
* can be used for attaching custom validation to the registration
|
551 |
+
* process. It cannot be used for changing any user registration
|
552 |
+
* data. Use the wpmem_register_data filter for that.
|
553 |
+
*
|
554 |
+
* @since 2.7.2
|
555 |
+
*
|
556 |
+
* @param array $wpmem->user->post_data The user's submitted registration data.
|
557 |
+
*/
|
558 |
+
do_action( 'wpmem_pre_register_data', $wpmem->user->post_data );
|
559 |
+
|
560 |
+
// If the _pre_register_data hook sends back an error message.
|
561 |
+
if ( $wpmem_themsg ) {
|
562 |
+
return $wpmem_themsg;
|
563 |
+
}
|
564 |
+
|
565 |
+
// Main new user fields are ready.
|
566 |
+
$new_user_fields = array (
|
567 |
+
'user_pass' => $wpmem->user->post_data['password'],
|
568 |
+
'user_login' => $wpmem->user->post_data['username'],
|
569 |
+
'user_nicename' => $wpmem->user->post_data['user_nicename'],
|
570 |
+
'user_email' => $wpmem->user->post_data['user_email'],
|
571 |
+
'display_name' => $wpmem->user->post_data['display_name'],
|
572 |
+
'nickname' => $wpmem->user->post_data['nickname'],
|
573 |
+
'user_registered' => $wpmem->user->post_data['user_registered'],
|
574 |
+
'role' => $wpmem->user->post_data['user_role']
|
575 |
+
);
|
576 |
+
|
577 |
+
// Get any excluded meta fields.
|
578 |
+
$wpmem->excluded_meta = wpmem_get_excluded_meta( 'register' );
|
579 |
+
|
580 |
+
// Fields for wp_insert_user: user_url, first_name, last_name, description, jabber, aim, yim.
|
581 |
+
$new_user_fields_meta = array( 'user_url', 'first_name', 'last_name', 'description', 'jabber', 'aim', 'yim' );
|
582 |
+
foreach ( $wpmem->fields as $meta_key => $field ) {
|
583 |
+
if ( in_array( $meta_key, $new_user_fields_meta ) ) {
|
584 |
+
if ( $field['register'] && ! in_array( $meta_key, $wpmem->excluded_meta ) ) {
|
585 |
+
$new_user_fields[ $meta_key ] = $wpmem->user->post_data[ $meta_key ];
|
586 |
+
}
|
587 |
+
}
|
588 |
+
}
|
589 |
+
|
590 |
+
// Inserts to wp_users table.
|
591 |
+
wp_insert_user( $new_user_fields );
|
592 |
+
|
593 |
+
/**
|
594 |
+
* Fires after registration is complete.
|
595 |
+
*
|
596 |
+
* @since 2.7.1
|
597 |
+
* @since 3.1.0 Added $fields
|
598 |
+
* @since 3.1.7 Changed $fields to $this->post_data
|
599 |
+
* @since 3.3.0 Moved to registration function.
|
600 |
+
*
|
601 |
+
* @param array $wpmem->user->post_data The user's submitted registration data.
|
602 |
+
*/
|
603 |
+
do_action( 'wpmem_register_redirect', $wpmem->user->post_data );
|
604 |
+
|
605 |
+
// successful registration message
|
606 |
+
return "success";
|
607 |
+
break;
|
608 |
+
|
609 |
+
case "update":
|
610 |
+
|
611 |
+
if ( $wpmem_themsg ) {
|
612 |
+
return "updaterr";
|
613 |
+
exit();
|
614 |
+
}
|
615 |
+
|
616 |
+
/*
|
617 |
+
* Doing a check for existing email is not the same as a new reg. check first to
|
618 |
+
* see if it's different, then check if it is a valid address and it exists.
|
619 |
+
*/
|
620 |
+
global $current_user; wp_get_current_user();
|
621 |
+
if ( isset( $wpmem->user->post_data['user_email'] ) ) {
|
622 |
+
if ( $wpmem->user->post_data['user_email'] != $current_user->user_email ) {
|
623 |
+
if ( email_exists( $wpmem->user->post_data['user_email'] ) ) {
|
624 |
+
return "email";
|
625 |
+
exit();
|
626 |
+
}
|
627 |
+
if ( in_array( 'user_email', $wpmem->fields ) && ! is_email( $wpmem->user->post_data['user_email']) ) {
|
628 |
+
$wpmem_themsg = $wpmem->get_text( 'reg_valid_email' );
|
629 |
+
return "updaterr";
|
630 |
+
exit();
|
631 |
+
}
|
632 |
+
}
|
633 |
+
}
|
634 |
+
|
635 |
+
// If form includes email confirmation, validate that they match.
|
636 |
+
if ( array_key_exists( 'confirm_email', $wpmem->user->post_data ) && $wpmem->user->post_data['confirm_email'] != $wpmem->user->post_data ['user_email'] ) {
|
637 |
+
$wpmem_themsg = $wpmem->get_text( 'reg_email_match' );
|
638 |
+
return "updaterr";
|
639 |
+
exit();
|
640 |
+
}
|
641 |
+
|
642 |
+
// Add the user_ID to the fields array.
|
643 |
+
$wpmem->user->post_data['ID'] = $user_ID;
|
644 |
+
|
645 |
+
/** This filter is documented in register.php */
|
646 |
+
$wpmem->user->post_data = apply_filters( 'wpmem_register_data', $wpmem->user->post_data, 'edit' );
|
647 |
+
|
648 |
+
/**
|
649 |
+
* Fires before data insertion.
|
650 |
+
*
|
651 |
+
* This action is the final step in pre updating a user. This
|
652 |
+
* can be used for attaching custom validation to the update
|
653 |
+
* process. It cannot be used for changing any user update
|
654 |
+
* data. Use the wpmem_register_data filter for that.
|
655 |
+
*
|
656 |
+
* @since 2.7.2
|
657 |
+
*
|
658 |
+
* @param array $wpmem->user->post_data The user's submitted update data.
|
659 |
+
*/
|
660 |
+
do_action( 'wpmem_pre_update_data', $wpmem->user->post_data );
|
661 |
+
|
662 |
+
// If the _pre_update_data hook sends back an error message.
|
663 |
+
if ( $wpmem_themsg ){
|
664 |
+
return "updaterr";
|
665 |
+
}
|
666 |
+
|
667 |
+
// A list of fields that can be updated by wp_update_user.
|
668 |
+
$native_fields = array(
|
669 |
+
'user_nicename',
|
670 |
+
'user_url',
|
671 |
+
'user_email',
|
672 |
+
'display_name',
|
673 |
+
'nickname',
|
674 |
+
'first_name',
|
675 |
+
'last_name',
|
676 |
+
'description',
|
677 |
+
'role',
|
678 |
+
'jabber',
|
679 |
+
'aim',
|
680 |
+
'yim'
|
681 |
+
);
|
682 |
+
$native_update = array( 'ID' => $wpmem->user->post_data['ID'] );
|
683 |
+
|
684 |
+
foreach ( $wpmem->fields as $meta_key => $field ) {
|
685 |
+
// If the field is not excluded, update accordingly.
|
686 |
+
if ( ! in_array( $meta_key, wpmem_get_excluded_meta( 'update' ) ) ) {
|
687 |
+
if ( 'file' != $field['type'] && 'image' != $field['type'] ) {
|
688 |
+
switch ( $meta_key ) {
|
689 |
+
|
690 |
+
// If the field can be updated by wp_update_user.
|
691 |
+
case( in_array( $meta_key, $native_fields ) ):
|
692 |
+
$wpmem->user->post_data[ $meta_key ] = ( isset( $wpmem->user->post_data[ $meta_key ] ) ) ? $wpmem->user->post_data[ $meta_key ] : '';
|
693 |
+
$native_update[ $meta_key ] = $wpmem->user->post_data[ $meta_key ];
|
694 |
+
break;
|
695 |
+
|
696 |
+
// If the field is password.
|
697 |
+
case( 'password' ):
|
698 |
+
// Do nothing.
|
699 |
+
break;
|
700 |
+
|
701 |
+
// Everything else goes into wp_usermeta.
|
702 |
+
default:
|
703 |
+
if ( ( 'register' == $tag && true == $field['register'] ) || ( 'update' == $tag && true == $field['profile'] ) ) {
|
704 |
+
update_user_meta( $wpmem->user->post_data['ID'], $meta_key, $wpmem->user->post_data[ $meta_key ] );
|
705 |
+
}
|
706 |
+
break;
|
707 |
+
}
|
708 |
+
}
|
709 |
+
}
|
710 |
+
}
|
711 |
+
|
712 |
+
// Handle file uploads, if any.
|
713 |
+
if ( ! empty( $_FILES ) ) {
|
714 |
+
$wpmem->user->upload_user_files( $wpmem->user->post_data['ID'], $wpmem->fields );
|
715 |
+
}
|
716 |
+
|
717 |
+
// Update wp_update_user fields.
|
718 |
+
wp_update_user( $native_update );
|
719 |
+
|
720 |
+
/**
|
721 |
+
* Fires at the end of user update data insertion.
|
722 |
+
*
|
723 |
+
* @since 2.7.2
|
724 |
+
*
|
725 |
+
* @param array $wpmem->user->post_data The user's submitted registration data.
|
726 |
+
*/
|
727 |
+
do_action( 'wpmem_post_update_data', $wpmem->user->post_data );
|
728 |
+
|
729 |
+
return "editsuccess"; exit();
|
730 |
+
break;
|
731 |
+
}
|
732 |
+
} // End registration function.
|
733 |
+
|
734 |
+
/**
|
735 |
+
* Get user IP address.
|
736 |
+
*
|
737 |
+
* From Pippin.
|
738 |
+
* @link https://gist.github.com/pippinsplugins/9641841
|
739 |
+
*
|
740 |
+
* @since 3.3.0
|
741 |
+
*
|
742 |
+
* @return string $ip.
|
743 |
+
*/
|
744 |
+
function wpmem_get_user_ip() {
|
745 |
+
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
|
746 |
+
//check ip from share internet
|
747 |
+
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
748 |
+
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
|
749 |
+
//to check ip is pass from proxy
|
750 |
+
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
751 |
+
} else {
|
752 |
+
$ip = $_SERVER['REMOTE_ADDR'];
|
753 |
+
}
|
754 |
+
/**
|
755 |
+
* Filter the IP result.
|
756 |
+
*
|
757 |
+
* @since 3.3.0
|
758 |
+
*
|
759 |
+
* @param string $ip
|
760 |
+
*/
|
761 |
+
return apply_filters( 'wpmem_get_ip', $ip );
|
762 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
763 |
// End of file.
|
includes/api/api-utilities.php
CHANGED
@@ -1,341 +1,341 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members Utility Functions
|
4 |
-
*
|
5 |
-
* Handles primary functions that are carried out in most
|
6 |
-
* situations. Includes commonly used utility functions.
|
7 |
-
*
|
8 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
9 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
10 |
-
* Copyright (c) 2006-
|
11 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
12 |
-
*
|
13 |
-
* @package WP-Members
|
14 |
-
* @subpackage WP-Members Utility Functions
|
15 |
-
* @author Chad Butler
|
16 |
-
* @copyright 2006-
|
17 |
-
*/
|
18 |
-
|
19 |
-
if ( ! function_exists( 'wpmem_securify' ) ):
|
20 |
-
/**
|
21 |
-
* The Securify Content Filter.
|
22 |
-
*
|
23 |
-
* This is the primary function that picks up where wpmem() leaves off.
|
24 |
-
* Determines whether content is shown or hidden for both post and pages.
|
25 |
-
* Since 3.0, this function is a wrapper for $wpmem->do_securify().
|
26 |
-
*
|
27 |
-
* @since 2.0.0
|
28 |
-
* @since 3.0.0 Now a wrapper for $wpmem->do_securify().
|
29 |
-
* @since 3.2.4 Moved to utility API (could be deprecated).
|
30 |
-
*
|
31 |
-
* @global object $wpmem The WP-Members object class.
|
32 |
-
*
|
33 |
-
* @param string $content Content of the current post.
|
34 |
-
* @return string $content Content of the current post or replaced content if post is blocked and user is not logged in.
|
35 |
-
*/
|
36 |
-
function wpmem_securify( $content = null ) {
|
37 |
-
global $wpmem;
|
38 |
-
return $wpmem->do_securify( $content );
|
39 |
-
}
|
40 |
-
endif;
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Sets an array of user meta fields to be excluded from update/insert.
|
44 |
-
*
|
45 |
-
* @since 2.9.3
|
46 |
-
* @since Unknown Now a wrapper for get_excluded_fields().
|
47 |
-
*
|
48 |
-
* @param string $tag A tag so we know where the function is being used.
|
49 |
-
* @return array Array of fields to be excluded from the registration form.
|
50 |
-
*/
|
51 |
-
function wpmem_get_excluded_meta( $tag ) {
|
52 |
-
global $wpmem;
|
53 |
-
return $wpmem->excluded_fields( $tag );
|
54 |
-
}
|
55 |
-
|
56 |
-
/**
|
57 |
-
* Returns http:// or https:// depending on ssl.
|
58 |
-
*
|
59 |
-
* @since 2.9.8
|
60 |
-
* @deprecated 3.2.3 Use wpmem_force_ssl() instead.
|
61 |
-
*
|
62 |
-
* @return string https://|http:// depending on whether ssl is being used.
|
63 |
-
*/
|
64 |
-
function wpmem_use_ssl() {
|
65 |
-
return ( is_ssl() ) ? 'https://' : 'http://';
|
66 |
-
}
|
67 |
-
|
68 |
-
/**
|
69 |
-
* Forces a URL to be secure (ssl).
|
70 |
-
*
|
71 |
-
* @since 3.2.3
|
72 |
-
*
|
73 |
-
* @param string $url URL to be make secure.
|
74 |
-
* @return string The secure URL.
|
75 |
-
*/
|
76 |
-
function wpmem_force_ssl( $url ) {
|
77 |
-
return ( is_ssl() ) ? preg_replace( "/^http:/i", "https:", $url ) : $url;
|
78 |
-
}
|
79 |
-
|
80 |
-
/**
|
81 |
-
* Log debugging errors.
|
82 |
-
*
|
83 |
-
* @since 3.1.2
|
84 |
-
*
|
85 |
-
* @param mixed (string|array|object) $log Information to write in the WP debug file.
|
86 |
-
*/
|
87 |
-
function wpmem_write_log ( $log ) {
|
88 |
-
if ( is_array( $log ) || is_object( $log ) ) {
|
89 |
-
error_log( print_r( $log, true ) );
|
90 |
-
} else {
|
91 |
-
error_log( $log );
|
92 |
-
}
|
93 |
-
}
|
94 |
-
|
95 |
-
/**
|
96 |
-
* String manipulation utility.
|
97 |
-
*
|
98 |
-
* Manipulates a given string based on the location of another string to return
|
99 |
-
* a requested part or parts of the original string. For extracting a string
|
100 |
-
* to get what is before or after, the returned result is a string. If the
|
101 |
-
* string is requested to be "split" by the needle string, an array containing
|
102 |
-
* the parts before, after, and the "needle" are returned.
|
103 |
-
*
|
104 |
-
* @since 3.2.0
|
105 |
-
*
|
106 |
-
* @param string $needle
|
107 |
-
* @param string $haystack
|
108 |
-
* @param string $position (before|after|split default: 'after')
|
109 |
-
* @param boolean $keep_needle (default:true)
|
110 |
-
* @return string|array $new {
|
111 |
-
* An array of the original string, as split by the "needle" string.
|
112 |
-
*
|
113 |
-
* @type string $before
|
114 |
-
* @type string $after
|
115 |
-
* @type string $needle
|
116 |
-
* }
|
117 |
-
*/
|
118 |
-
function wpmem_get_sub_str( $needle, $haystack, $position = 'after', $keep_needle = true ) {
|
119 |
-
$pos = strpos( $haystack, $needle );
|
120 |
-
if ( false === $pos ) {
|
121 |
-
return $haystack;
|
122 |
-
} else {
|
123 |
-
if ( 'before' == $position ) {
|
124 |
-
$new = ( substr( $haystack, 0, $pos ) );
|
125 |
-
$new = ( $keep_needle ) ? $string . $needle : $new;
|
126 |
-
} elseif ( 'after' == $position ) {
|
127 |
-
$new = ( substr( $haystack, $pos+strlen( $needle ) ) );
|
128 |
-
$new = ( $keep_needle ) ? $needle . $string : $new;
|
129 |
-
} elseif ( 'split' == $position ) {
|
130 |
-
$before = ( substr( $haystack, 0, $pos ) );
|
131 |
-
$after = ( substr( $haystack, $pos+strlen( $needle ) ) );
|
132 |
-
$new = array(
|
133 |
-
'before' => $before,
|
134 |
-
'after' => $after,
|
135 |
-
'needle' => $needle,
|
136 |
-
);
|
137 |
-
}
|
138 |
-
}
|
139 |
-
return $new;
|
140 |
-
}
|
141 |
-
|
142 |
-
if ( ! function_exists( 'wpmem_do_excerpt' ) ):
|
143 |
-
/**
|
144 |
-
* Creates an excerpt on the fly if there is no 'more' tag.
|
145 |
-
*
|
146 |
-
* @since 2.6
|
147 |
-
* @since 3.2.3 Now a wrapper for WP_Members::do_excerpt().
|
148 |
-
*
|
149 |
-
* @global object $wpmem The WP_Members object.
|
150 |
-
*
|
151 |
-
* @param string $content
|
152 |
-
* @return string $content
|
153 |
-
*/
|
154 |
-
function wpmem_do_excerpt( $content ) {
|
155 |
-
global $wpmem;
|
156 |
-
$content = $wpmem->do_excerpt( $content );
|
157 |
-
return $content;
|
158 |
-
}
|
159 |
-
endif;
|
160 |
-
|
161 |
-
if ( ! function_exists( 'wpmem_texturize' ) ):
|
162 |
-
/**
|
163 |
-
* Overrides the wptexturize filter.
|
164 |
-
*
|
165 |
-
* Currently only used for the login form to remove the <br> tag that WP puts in after the "Remember Me".
|
166 |
-
*
|
167 |
-
* @since 2.6.4
|
168 |
-
* @since 3.2.3 Now a wrapper for WP_Members::texturize().
|
169 |
-
*
|
170 |
-
* @todo Possibly deprecate or severely alter this process as its need may be obsolete.
|
171 |
-
*
|
172 |
-
* @global object $wpmem
|
173 |
-
* @param string $content
|
174 |
-
* @return string $new_content
|
175 |
-
*/
|
176 |
-
function wpmem_texturize( $content ) {
|
177 |
-
global $wpmem;
|
178 |
-
return $wpmem->texturize( $content );
|
179 |
-
}
|
180 |
-
endif;
|
181 |
-
|
182 |
-
/**
|
183 |
-
* Inserts array items at a specific point in an array.
|
184 |
-
*
|
185 |
-
* @since 3.1.6
|
186 |
-
* @since 3.2.3 Moved to utilities api.
|
187 |
-
*
|
188 |
-
* @param array $array Original array.
|
189 |
-
* @param array $new Array of new items to insert into $array.
|
190 |
-
* @param string $key Array key to insert new items before or after.
|
191 |
-
* @param string $loc Location to insert relative to $key (before|after) default:after.
|
192 |
-
* @return array Original array with new items inserted.
|
193 |
-
*/
|
194 |
-
function wpmem_array_insert( array $array, array $new, $key, $loc = 'after' ) {
|
195 |
-
$keys = array_keys( $array );
|
196 |
-
if ( 'before' == $loc ) {
|
197 |
-
$pos = (int) array_search( $key, $keys );
|
198 |
-
} else {
|
199 |
-
$index = array_search( $key, $keys );
|
200 |
-
$pos = ( false === $index ) ? count( $array ) : $index + 1;
|
201 |
-
}
|
202 |
-
return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) );
|
203 |
-
}
|
204 |
-
|
205 |
-
/**
|
206 |
-
* Wrapper for load_dropins()
|
207 |
-
*
|
208 |
-
* @since 3.1.4
|
209 |
-
* @since 3.2.3 Moved to utilities api.
|
210 |
-
*
|
211 |
-
* @global object $wpmem The WP_Members object.
|
212 |
-
*/
|
213 |
-
function wpmem_load_dropins() {
|
214 |
-
global $wpmem;
|
215 |
-
$wpmem->load_dropins();
|
216 |
-
}
|
217 |
-
|
218 |
-
/**
|
219 |
-
* Display a localized date based on the WP date format setting.
|
220 |
-
*
|
221 |
-
* @since 3.2.4
|
222 |
-
*
|
223 |
-
* @param mixed $args
|
224 |
-
* @return date $date
|
225 |
-
*/
|
226 |
-
function wpmem_format_date( $args ) {
|
227 |
-
if ( ! is_array( $args ) ) {
|
228 |
-
$args = array( 'date' => $args );
|
229 |
-
}
|
230 |
-
|
231 |
-
$defaults = array(
|
232 |
-
'date_format' => get_option( 'date_format' ),
|
233 |
-
'localize' => true,
|
234 |
-
'timestamp' => false,
|
235 |
-
);
|
236 |
-
|
237 |
-
$args = wp_parse_args( $args, $deafults );
|
238 |
-
|
239 |
-
/**
|
240 |
-
* Filter the date display and format settings.
|
241 |
-
*
|
242 |
-
* @since 3.2.4
|
243 |
-
*
|
244 |
-
* @param arrag $args
|
245 |
-
*/
|
246 |
-
$args = apply_filters( 'wpmem_format_date_args', $args );
|
247 |
-
$date = ( true === $args['timestamp'] ) ? $args['date'] : strtotime( $args['date'] );
|
248 |
-
$date = ( true === $args['localize'] ) ? date_i18n( $args['date_format'], $date ) : date( $args['date_format'], $date );
|
249 |
-
return $date;
|
250 |
-
}
|
251 |
-
|
252 |
-
/**
|
253 |
-
* Call a shortcode function by tag name.
|
254 |
-
*
|
255 |
-
* Use this function for directly calling a shortcode without using do_shortcode.
|
256 |
-
* do_shortcode() runs an extensive regex that goes through every shortcode in
|
257 |
-
* the WP global $shortcode_tags. That's a lot of processing wasted if all you
|
258 |
-
* want to do is run a specific shortcode/function. Yes, you could run the callback
|
259 |
-
* directly, but what if that callback is in a class instance method? This utlitiy
|
260 |
-
* allows you to run a shortcode function directly, regardless of whether it is
|
261 |
-
* a direct function or in a class. It comes from an article by J.D. Grimes on this
|
262 |
-
* subject and I've provided a link to that article.
|
263 |
-
*
|
264 |
-
* @author J.D. Grimes
|
265 |
-
* @link https://codesymphony.co/dont-do_shortcode/
|
266 |
-
*
|
267 |
-
* @since 3.2.5
|
268 |
-
*
|
269 |
-
* @param string $tag The shortcode whose function to call.
|
270 |
-
* @param array $atts The attributes to pass to the shortcode function. Optional.
|
271 |
-
* @param array $content The shortcode's content. Default is null (none).
|
272 |
-
*
|
273 |
-
* @return string|bool False on failure, the result of the shortcode on success.
|
274 |
-
*/
|
275 |
-
function wpmem_do_shortcode( $tag, array $atts = array(), $content = null ) {
|
276 |
-
|
277 |
-
global $shortcode_tags;
|
278 |
-
|
279 |
-
if ( ! isset( $shortcode_tags[ $tag ] ) ) {
|
280 |
-
return false;
|
281 |
-
}
|
282 |
-
|
283 |
-
return call_user_func( $shortcode_tags[ $tag ], $atts, $content, $tag );
|
284 |
-
}
|
285 |
-
|
286 |
-
/**
|
287 |
-
* Checks if a password is part of registration.
|
288 |
-
*
|
289 |
-
* Used for moderated registration to determine if a user sets their
|
290 |
-
* own password at registration. If so, password is not set during
|
291 |
-
* user activation.
|
292 |
-
*
|
293 |
-
* @since 3.3.0
|
294 |
-
*/
|
295 |
-
function wpmem_user_sets_password() {
|
296 |
-
$chk_pass = false;
|
297 |
-
$wpmem_fields = wpmem_fields();
|
298 |
-
foreach ( $wpmem_fields as $field ) {
|
299 |
-
if ( $field['type'] == 'password' && $field['register'] ) {
|
300 |
-
$chk_pass = true;
|
301 |
-
break;
|
302 |
-
}
|
303 |
-
}
|
304 |
-
return $chk_pass;
|
305 |
-
}
|
306 |
-
|
307 |
-
/**
|
308 |
-
* Better unserialization than WP's maybe_unserialize().
|
309 |
-
*
|
310 |
-
* Sanitizes array output before returning. If the unserialized result is an
|
311 |
-
* array, then it runs the result through wpmem_sanitize_array(), which
|
312 |
-
* sanitizes each individual array element.
|
313 |
-
*
|
314 |
-
* @since 3.3.0
|
315 |
-
*
|
316 |
-
* @param mixed $original
|
317 |
-
* @return mixed $original
|
318 |
-
*/
|
319 |
-
function wpmem_maybe_unserialize( $original ) {
|
320 |
-
if ( is_serialized( $original ) ) { // don't attempt to unserialize data that wasn't serialized going in
|
321 |
-
$original = unserialize( $original );
|
322 |
-
}
|
323 |
-
return ( is_array( $original ) ) ? wpmem_sanitize_array( $original ) : $original;
|
324 |
-
}
|
325 |
-
|
326 |
-
/**
|
327 |
-
* Determines whether to use a .min suffix for a script/style file.
|
328 |
-
*
|
329 |
-
* @since 3.3.0
|
330 |
-
*
|
331 |
-
* @param boolean $echo
|
332 |
-
*/
|
333 |
-
function wpmem_get_suffix( $echo = false ) {
|
334 |
-
$suffix = ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) ? '' : '.min';
|
335 |
-
if ( true === $echo ) {
|
336 |
-
echo $suffix;
|
337 |
-
return;
|
338 |
-
} else {
|
339 |
-
return $suffix;
|
340 |
-
}
|
341 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members Utility Functions
|
4 |
+
*
|
5 |
+
* Handles primary functions that are carried out in most
|
6 |
+
* situations. Includes commonly used utility functions.
|
7 |
+
*
|
8 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
9 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
10 |
+
* Copyright (c) 2006-2020 Chad Butler
|
11 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
12 |
+
*
|
13 |
+
* @package WP-Members
|
14 |
+
* @subpackage WP-Members Utility Functions
|
15 |
+
* @author Chad Butler
|
16 |
+
* @copyright 2006-2020
|
17 |
+
*/
|
18 |
+
|
19 |
+
if ( ! function_exists( 'wpmem_securify' ) ):
|
20 |
+
/**
|
21 |
+
* The Securify Content Filter.
|
22 |
+
*
|
23 |
+
* This is the primary function that picks up where wpmem() leaves off.
|
24 |
+
* Determines whether content is shown or hidden for both post and pages.
|
25 |
+
* Since 3.0, this function is a wrapper for $wpmem->do_securify().
|
26 |
+
*
|
27 |
+
* @since 2.0.0
|
28 |
+
* @since 3.0.0 Now a wrapper for $wpmem->do_securify().
|
29 |
+
* @since 3.2.4 Moved to utility API (could be deprecated).
|
30 |
+
*
|
31 |
+
* @global object $wpmem The WP-Members object class.
|
32 |
+
*
|
33 |
+
* @param string $content Content of the current post.
|
34 |
+
* @return string $content Content of the current post or replaced content if post is blocked and user is not logged in.
|
35 |
+
*/
|
36 |
+
function wpmem_securify( $content = null ) {
|
37 |
+
global $wpmem;
|
38 |
+
return $wpmem->do_securify( $content );
|
39 |
+
}
|
40 |
+
endif;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Sets an array of user meta fields to be excluded from update/insert.
|
44 |
+
*
|
45 |
+
* @since 2.9.3
|
46 |
+
* @since Unknown Now a wrapper for get_excluded_fields().
|
47 |
+
*
|
48 |
+
* @param string $tag A tag so we know where the function is being used.
|
49 |
+
* @return array Array of fields to be excluded from the registration form.
|
50 |
+
*/
|
51 |
+
function wpmem_get_excluded_meta( $tag ) {
|
52 |
+
global $wpmem;
|
53 |
+
return $wpmem->excluded_fields( $tag );
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Returns http:// or https:// depending on ssl.
|
58 |
+
*
|
59 |
+
* @since 2.9.8
|
60 |
+
* @deprecated 3.2.3 Use wpmem_force_ssl() instead.
|
61 |
+
*
|
62 |
+
* @return string https://|http:// depending on whether ssl is being used.
|
63 |
+
*/
|
64 |
+
function wpmem_use_ssl() {
|
65 |
+
return ( is_ssl() ) ? 'https://' : 'http://';
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Forces a URL to be secure (ssl).
|
70 |
+
*
|
71 |
+
* @since 3.2.3
|
72 |
+
*
|
73 |
+
* @param string $url URL to be make secure.
|
74 |
+
* @return string The secure URL.
|
75 |
+
*/
|
76 |
+
function wpmem_force_ssl( $url ) {
|
77 |
+
return ( is_ssl() ) ? preg_replace( "/^http:/i", "https:", $url ) : $url;
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Log debugging errors.
|
82 |
+
*
|
83 |
+
* @since 3.1.2
|
84 |
+
*
|
85 |
+
* @param mixed (string|array|object) $log Information to write in the WP debug file.
|
86 |
+
*/
|
87 |
+
function wpmem_write_log ( $log ) {
|
88 |
+
if ( is_array( $log ) || is_object( $log ) ) {
|
89 |
+
error_log( print_r( $log, true ) );
|
90 |
+
} else {
|
91 |
+
error_log( $log );
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* String manipulation utility.
|
97 |
+
*
|
98 |
+
* Manipulates a given string based on the location of another string to return
|
99 |
+
* a requested part or parts of the original string. For extracting a string
|
100 |
+
* to get what is before or after, the returned result is a string. If the
|
101 |
+
* string is requested to be "split" by the needle string, an array containing
|
102 |
+
* the parts before, after, and the "needle" are returned.
|
103 |
+
*
|
104 |
+
* @since 3.2.0
|
105 |
+
*
|
106 |
+
* @param string $needle
|
107 |
+
* @param string $haystack
|
108 |
+
* @param string $position (before|after|split default: 'after')
|
109 |
+
* @param boolean $keep_needle (default:true)
|
110 |
+
* @return string|array $new {
|
111 |
+
* An array of the original string, as split by the "needle" string.
|
112 |
+
*
|
113 |
+
* @type string $before
|
114 |
+
* @type string $after
|
115 |
+
* @type string $needle
|
116 |
+
* }
|
117 |
+
*/
|
118 |
+
function wpmem_get_sub_str( $needle, $haystack, $position = 'after', $keep_needle = true ) {
|
119 |
+
$pos = strpos( $haystack, $needle );
|
120 |
+
if ( false === $pos ) {
|
121 |
+
return $haystack;
|
122 |
+
} else {
|
123 |
+
if ( 'before' == $position ) {
|
124 |
+
$new = ( substr( $haystack, 0, $pos ) );
|
125 |
+
$new = ( $keep_needle ) ? $string . $needle : $new;
|
126 |
+
} elseif ( 'after' == $position ) {
|
127 |
+
$new = ( substr( $haystack, $pos+strlen( $needle ) ) );
|
128 |
+
$new = ( $keep_needle ) ? $needle . $string : $new;
|
129 |
+
} elseif ( 'split' == $position ) {
|
130 |
+
$before = ( substr( $haystack, 0, $pos ) );
|
131 |
+
$after = ( substr( $haystack, $pos+strlen( $needle ) ) );
|
132 |
+
$new = array(
|
133 |
+
'before' => $before,
|
134 |
+
'after' => $after,
|
135 |
+
'needle' => $needle,
|
136 |
+
);
|
137 |
+
}
|
138 |
+
}
|
139 |
+
return $new;
|
140 |
+
}
|
141 |
+
|
142 |
+
if ( ! function_exists( 'wpmem_do_excerpt' ) ):
|
143 |
+
/**
|
144 |
+
* Creates an excerpt on the fly if there is no 'more' tag.
|
145 |
+
*
|
146 |
+
* @since 2.6
|
147 |
+
* @since 3.2.3 Now a wrapper for WP_Members::do_excerpt().
|
148 |
+
*
|
149 |
+
* @global object $wpmem The WP_Members object.
|
150 |
+
*
|
151 |
+
* @param string $content
|
152 |
+
* @return string $content
|
153 |
+
*/
|
154 |
+
function wpmem_do_excerpt( $content ) {
|
155 |
+
global $wpmem;
|
156 |
+
$content = $wpmem->do_excerpt( $content );
|
157 |
+
return $content;
|
158 |
+
}
|
159 |
+
endif;
|
160 |
+
|
161 |
+
if ( ! function_exists( 'wpmem_texturize' ) ):
|
162 |
+
/**
|
163 |
+
* Overrides the wptexturize filter.
|
164 |
+
*
|
165 |
+
* Currently only used for the login form to remove the <br> tag that WP puts in after the "Remember Me".
|
166 |
+
*
|
167 |
+
* @since 2.6.4
|
168 |
+
* @since 3.2.3 Now a wrapper for WP_Members::texturize().
|
169 |
+
*
|
170 |
+
* @todo Possibly deprecate or severely alter this process as its need may be obsolete.
|
171 |
+
*
|
172 |
+
* @global object $wpmem
|
173 |
+
* @param string $content
|
174 |
+
* @return string $new_content
|
175 |
+
*/
|
176 |
+
function wpmem_texturize( $content ) {
|
177 |
+
global $wpmem;
|
178 |
+
return $wpmem->texturize( $content );
|
179 |
+
}
|
180 |
+
endif;
|
181 |
+
|
182 |
+
/**
|
183 |
+
* Inserts array items at a specific point in an array.
|
184 |
+
*
|
185 |
+
* @since 3.1.6
|
186 |
+
* @since 3.2.3 Moved to utilities api.
|
187 |
+
*
|
188 |
+
* @param array $array Original array.
|
189 |
+
* @param array $new Array of new items to insert into $array.
|
190 |
+
* @param string $key Array key to insert new items before or after.
|
191 |
+
* @param string $loc Location to insert relative to $key (before|after) default:after.
|
192 |
+
* @return array Original array with new items inserted.
|
193 |
+
*/
|
194 |
+
function wpmem_array_insert( array $array, array $new, $key, $loc = 'after' ) {
|
195 |
+
$keys = array_keys( $array );
|
196 |
+
if ( 'before' == $loc ) {
|
197 |
+
$pos = (int) array_search( $key, $keys );
|
198 |
+
} else {
|
199 |
+
$index = array_search( $key, $keys );
|
200 |
+
$pos = ( false === $index ) ? count( $array ) : $index + 1;
|
201 |
+
}
|
202 |
+
return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) );
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Wrapper for load_dropins()
|
207 |
+
*
|
208 |
+
* @since 3.1.4
|
209 |
+
* @since 3.2.3 Moved to utilities api.
|
210 |
+
*
|
211 |
+
* @global object $wpmem The WP_Members object.
|
212 |
+
*/
|
213 |
+
function wpmem_load_dropins() {
|
214 |
+
global $wpmem;
|
215 |
+
$wpmem->load_dropins();
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Display a localized date based on the WP date format setting.
|
220 |
+
*
|
221 |
+
* @since 3.2.4
|
222 |
+
*
|
223 |
+
* @param mixed $args
|
224 |
+
* @return date $date
|
225 |
+
*/
|
226 |
+
function wpmem_format_date( $args ) {
|
227 |
+
if ( ! is_array( $args ) ) {
|
228 |
+
$args = array( 'date' => $args );
|
229 |
+
}
|
230 |
+
|
231 |
+
$defaults = array(
|
232 |
+
'date_format' => get_option( 'date_format' ),
|
233 |
+
'localize' => true,
|
234 |
+
'timestamp' => false,
|
235 |
+
);
|
236 |
+
|
237 |
+
$args = wp_parse_args( $args, $deafults );
|
238 |
+
|
239 |
+
/**
|
240 |
+
* Filter the date display and format settings.
|
241 |
+
*
|
242 |
+
* @since 3.2.4
|
243 |
+
*
|
244 |
+
* @param arrag $args
|
245 |
+
*/
|
246 |
+
$args = apply_filters( 'wpmem_format_date_args', $args );
|
247 |
+
$date = ( true === $args['timestamp'] ) ? $args['date'] : strtotime( $args['date'] );
|
248 |
+
$date = ( true === $args['localize'] ) ? date_i18n( $args['date_format'], $date ) : date( $args['date_format'], $date );
|
249 |
+
return $date;
|
250 |
+
}
|
251 |
+
|
252 |
+
/**
|
253 |
+
* Call a shortcode function by tag name.
|
254 |
+
*
|
255 |
+
* Use this function for directly calling a shortcode without using do_shortcode.
|
256 |
+
* do_shortcode() runs an extensive regex that goes through every shortcode in
|
257 |
+
* the WP global $shortcode_tags. That's a lot of processing wasted if all you
|
258 |
+
* want to do is run a specific shortcode/function. Yes, you could run the callback
|
259 |
+
* directly, but what if that callback is in a class instance method? This utlitiy
|
260 |
+
* allows you to run a shortcode function directly, regardless of whether it is
|
261 |
+
* a direct function or in a class. It comes from an article by J.D. Grimes on this
|
262 |
+
* subject and I've provided a link to that article.
|
263 |
+
*
|
264 |
+
* @author J.D. Grimes
|
265 |
+
* @link https://codesymphony.co/dont-do_shortcode/
|
266 |
+
*
|
267 |
+
* @since 3.2.5
|
268 |
+
*
|
269 |
+
* @param string $tag The shortcode whose function to call.
|
270 |
+
* @param array $atts The attributes to pass to the shortcode function. Optional.
|
271 |
+
* @param array $content The shortcode's content. Default is null (none).
|
272 |
+
*
|
273 |
+
* @return string|bool False on failure, the result of the shortcode on success.
|
274 |
+
*/
|
275 |
+
function wpmem_do_shortcode( $tag, array $atts = array(), $content = null ) {
|
276 |
+
|
277 |
+
global $shortcode_tags;
|
278 |
+
|
279 |
+
if ( ! isset( $shortcode_tags[ $tag ] ) ) {
|
280 |
+
return false;
|
281 |
+
}
|
282 |
+
|
283 |
+
return call_user_func( $shortcode_tags[ $tag ], $atts, $content, $tag );
|
284 |
+
}
|
285 |
+
|
286 |
+
/**
|
287 |
+
* Checks if a password is part of registration.
|
288 |
+
*
|
289 |
+
* Used for moderated registration to determine if a user sets their
|
290 |
+
* own password at registration. If so, password is not set during
|
291 |
+
* user activation.
|
292 |
+
*
|
293 |
+
* @since 3.3.0
|
294 |
+
*/
|
295 |
+
function wpmem_user_sets_password() {
|
296 |
+
$chk_pass = false;
|
297 |
+
$wpmem_fields = wpmem_fields();
|
298 |
+
foreach ( $wpmem_fields as $field ) {
|
299 |
+
if ( $field['type'] == 'password' && $field['register'] ) {
|
300 |
+
$chk_pass = true;
|
301 |
+
break;
|
302 |
+
}
|
303 |
+
}
|
304 |
+
return $chk_pass;
|
305 |
+
}
|
306 |
+
|
307 |
+
/**
|
308 |
+
* Better unserialization than WP's maybe_unserialize().
|
309 |
+
*
|
310 |
+
* Sanitizes array output before returning. If the unserialized result is an
|
311 |
+
* array, then it runs the result through wpmem_sanitize_array(), which
|
312 |
+
* sanitizes each individual array element.
|
313 |
+
*
|
314 |
+
* @since 3.3.0
|
315 |
+
*
|
316 |
+
* @param mixed $original
|
317 |
+
* @return mixed $original
|
318 |
+
*/
|
319 |
+
function wpmem_maybe_unserialize( $original ) {
|
320 |
+
if ( is_serialized( $original ) ) { // don't attempt to unserialize data that wasn't serialized going in
|
321 |
+
$original = unserialize( $original );
|
322 |
+
}
|
323 |
+
return ( is_array( $original ) ) ? wpmem_sanitize_array( $original ) : $original;
|
324 |
+
}
|
325 |
+
|
326 |
+
/**
|
327 |
+
* Determines whether to use a .min suffix for a script/style file.
|
328 |
+
*
|
329 |
+
* @since 3.3.0
|
330 |
+
*
|
331 |
+
* @param boolean $echo
|
332 |
+
*/
|
333 |
+
function wpmem_get_suffix( $echo = false ) {
|
334 |
+
$suffix = ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) ? '' : '.min';
|
335 |
+
if ( true === $echo ) {
|
336 |
+
echo $suffix;
|
337 |
+
return;
|
338 |
+
} else {
|
339 |
+
return $suffix;
|
340 |
+
}
|
341 |
}
|
includes/api/api.php
CHANGED
@@ -1,382 +1,407 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members API Functions
|
4 |
-
*
|
5 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
-
* Copyright (c) 2006-
|
8 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
-
*
|
10 |
-
* @package WP-Members
|
11 |
-
* @subpackage WP-Members API Functions
|
12 |
-
* @author Chad Butler
|
13 |
-
* @copyright 2006-
|
14 |
-
*
|
15 |
-
* Functions included:
|
16 |
-
* - wpmem_redirect_to_login
|
17 |
-
* - wpmem_is_blocked
|
18 |
-
* - wpmem_login_url
|
19 |
-
* - wpmem_register_url
|
20 |
-
* - wpmem_profile_url
|
21 |
-
* - wpmem_current_url
|
22 |
-
* - wpmem_current_post_id
|
23 |
-
* - wpmem_gettext
|
24 |
-
* - wpmem_use_custom_dialog
|
25 |
-
* - wpmem_login_status
|
26 |
-
* - wpmem_get
|
27 |
-
* - wpmem_is_reg_page
|
28 |
-
* - wpmem_loginout
|
29 |
-
* - wpmem_display_message
|
30 |
-
*/
|
31 |
-
|
32 |
-
// Exit if accessed directly.
|
33 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
34 |
-
exit();
|
35 |
-
}
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Redirects a user to defined login page with return redirect.
|
39 |
-
*
|
40 |
-
* While a specific URL can be passed as an argument, the default will
|
41 |
-
* redirect the user back to the original page using wpmem_current_url().
|
42 |
-
*
|
43 |
-
* @since 3.0.2
|
44 |
-
* @since 3.1.1 Moved to API.
|
45 |
-
* @since 3.1.3 Added $redirect_to argument.
|
46 |
-
*
|
47 |
-
* @param string $redirect_to URL to redirect to (default: false).
|
48 |
-
*/
|
49 |
-
function wpmem_redirect_to_login( $redirect_to = false ) {
|
50 |
-
if ( ! is_user_logged_in() ) {
|
51 |
-
$redirect_to = ( $redirect_to ) ? $redirect_to : wpmem_current_url();
|
52 |
-
wp_safe_redirect( wpmem_login_url( $redirect_to ) );
|
53 |
-
exit();
|
54 |
-
}
|
55 |
-
return;
|
56 |
-
}
|
57 |
-
|
58 |
-
/**
|
59 |
-
* Checks if content is blocked (replaces wpmem_block()).
|
60 |
-
*
|
61 |
-
* @since 3.1.1
|
62 |
-
* @since 3.3.0 Added $post_id
|
63 |
-
*
|
64 |
-
* @global object $wpmem The WP-Members object class.
|
65 |
-
* @param int $post_id
|
66 |
-
* @return bool $block True if content is blocked, false
|
67 |
-
*/
|
68 |
-
function wpmem_is_blocked( $post_id = false ) {
|
69 |
-
global $wpmem;
|
70 |
-
return $wpmem->is_blocked( $post_id );
|
71 |
-
}
|
72 |
-
|
73 |
-
/**
|
74 |
-
*
|
75 |
-
*
|
76 |
-
* @since 3.3.
|
77 |
-
*
|
78 |
-
* @
|
79 |
-
*
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
*
|
89 |
-
*
|
90 |
-
* @
|
91 |
-
*
|
92 |
-
*
|
93 |
-
* @
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
*
|
122 |
-
*
|
123 |
-
*
|
124 |
-
* @
|
125 |
-
*
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
*
|
137 |
-
*
|
138 |
-
* @
|
139 |
-
* @
|
140 |
-
*
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
*
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
*
|
179 |
-
*
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
*
|
191 |
-
*
|
192 |
-
* @since 3.1.
|
193 |
-
*
|
194 |
-
* @
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
*
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
*
|
225 |
-
*
|
226 |
-
* @
|
227 |
-
* @
|
228 |
-
* @
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
function
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
*
|
310 |
-
*
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
*
|
349 |
-
*
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
// End of file.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members API Functions
|
4 |
+
*
|
5 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
6 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
7 |
+
* Copyright (c) 2006-2020 Chad Butler
|
8 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
9 |
+
*
|
10 |
+
* @package WP-Members
|
11 |
+
* @subpackage WP-Members API Functions
|
12 |
+
* @author Chad Butler
|
13 |
+
* @copyright 2006-2020
|
14 |
+
*
|
15 |
+
* Functions included:
|
16 |
+
* - wpmem_redirect_to_login
|
17 |
+
* - wpmem_is_blocked
|
18 |
+
* - wpmem_login_url
|
19 |
+
* - wpmem_register_url
|
20 |
+
* - wpmem_profile_url
|
21 |
+
* - wpmem_current_url
|
22 |
+
* - wpmem_current_post_id
|
23 |
+
* - wpmem_gettext
|
24 |
+
* - wpmem_use_custom_dialog
|
25 |
+
* - wpmem_login_status
|
26 |
+
* - wpmem_get
|
27 |
+
* - wpmem_is_reg_page
|
28 |
+
* - wpmem_loginout
|
29 |
+
* - wpmem_display_message
|
30 |
+
*/
|
31 |
+
|
32 |
+
// Exit if accessed directly.
|
33 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
34 |
+
exit();
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Redirects a user to defined login page with return redirect.
|
39 |
+
*
|
40 |
+
* While a specific URL can be passed as an argument, the default will
|
41 |
+
* redirect the user back to the original page using wpmem_current_url().
|
42 |
+
*
|
43 |
+
* @since 3.0.2
|
44 |
+
* @since 3.1.1 Moved to API.
|
45 |
+
* @since 3.1.3 Added $redirect_to argument.
|
46 |
+
*
|
47 |
+
* @param string $redirect_to URL to redirect to (default: false).
|
48 |
+
*/
|
49 |
+
function wpmem_redirect_to_login( $redirect_to = false ) {
|
50 |
+
if ( ! is_user_logged_in() ) {
|
51 |
+
$redirect_to = ( $redirect_to ) ? $redirect_to : wpmem_current_url();
|
52 |
+
wp_safe_redirect( wpmem_login_url( $redirect_to ) );
|
53 |
+
exit();
|
54 |
+
}
|
55 |
+
return;
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Checks if content is blocked (replaces wpmem_block()).
|
60 |
+
*
|
61 |
+
* @since 3.1.1
|
62 |
+
* @since 3.3.0 Added $post_id
|
63 |
+
*
|
64 |
+
* @global object $wpmem The WP-Members object class.
|
65 |
+
* @param int $post_id
|
66 |
+
* @return bool $block True if content is blocked, otherwise false.
|
67 |
+
*/
|
68 |
+
function wpmem_is_blocked( $post_id = false ) {
|
69 |
+
global $wpmem;
|
70 |
+
return $wpmem->is_blocked( $post_id );
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Checks if specific post is marked as hidden.
|
75 |
+
*
|
76 |
+
* @since 3.3.2
|
77 |
+
*
|
78 |
+
* @param int $post_id
|
79 |
+
* @return bool $block True if content is hidden, otherwise false.
|
80 |
+
*/
|
81 |
+
function wpmem_is_hidden( $post_id = false ) {
|
82 |
+
return ( 2 == get_post_meta( $post_id ) ) ? true : false;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Returns the block setting for a post.
|
87 |
+
*
|
88 |
+
* @since 3.3.0
|
89 |
+
*
|
90 |
+
* @global object $wpmem
|
91 |
+
*
|
92 |
+
* @param int $post_id
|
93 |
+
* @return int $block_value
|
94 |
+
*/
|
95 |
+
function wpmem_get_block_setting( $post_id ) {
|
96 |
+
return get_post_meta( $post_id, '_wpmem_block', true );
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Wrapper to get the login page location.
|
101 |
+
*
|
102 |
+
* @since 3.1.1
|
103 |
+
* @since 3.1.2 Added redirect_to parameter.
|
104 |
+
*
|
105 |
+
* @global object $wpmem The WP_Members object.
|
106 |
+
* @param string $redirect_to URL to return to (optional).
|
107 |
+
* @return string $url The login page url.
|
108 |
+
*/
|
109 |
+
function wpmem_login_url( $redirect_to = false ) {
|
110 |
+
global $wpmem;
|
111 |
+
if ( $redirect_to ) {
|
112 |
+
$url = add_query_arg( 'redirect_to', urlencode( $redirect_to ), $wpmem->user_pages['login'] );
|
113 |
+
} else {
|
114 |
+
$url = $wpmem->user_pages['login'];
|
115 |
+
}
|
116 |
+
return $url;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Wrapper to get the register page location.
|
121 |
+
*
|
122 |
+
* @since 3.1.1
|
123 |
+
*
|
124 |
+
* @global object $wpmem The WP_Members object.
|
125 |
+
* @return string The register page url.
|
126 |
+
*/
|
127 |
+
function wpmem_register_url() {
|
128 |
+
global $wpmem;
|
129 |
+
return $wpmem->user_pages['register'];
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Wrapper to get the profile page location.
|
134 |
+
*
|
135 |
+
* @since 3.1.1
|
136 |
+
* @since 3.1.2 Added $a parameter.
|
137 |
+
*
|
138 |
+
* @global object $wpmem The WP_Members object.
|
139 |
+
* @param string $a Action (optional).
|
140 |
+
* @return string The profile page url.
|
141 |
+
*/
|
142 |
+
function wpmem_profile_url( $a = false ) {
|
143 |
+
global $wpmem;
|
144 |
+
return ( $a ) ? add_query_arg( 'a', $a, $wpmem->user_pages['profile'] ) : $wpmem->user_pages['profile'];
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Returns an array of user pages.
|
149 |
+
*
|
150 |
+
* @since 3.1.2
|
151 |
+
* @since 3.1.3 Added array keys.
|
152 |
+
*
|
153 |
+
* @return array $pages {
|
154 |
+
* The URLs of login, register, and user profile pages.
|
155 |
+
*
|
156 |
+
* @type string $login
|
157 |
+
* @type string $register
|
158 |
+
* @type string $profile
|
159 |
+
* }
|
160 |
+
*/
|
161 |
+
function wpmem_user_pages() {
|
162 |
+
$pages = array(
|
163 |
+
'login' => trailingslashit( wpmem_login_url() ),
|
164 |
+
'register' => trailingslashit( wpmem_register_url() ),
|
165 |
+
'profile' => trailingslashit( wpmem_profile_url() ),
|
166 |
+
);
|
167 |
+
return $pages;
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Returns the current full url.
|
172 |
+
*
|
173 |
+
* @since 3.1.1
|
174 |
+
* @since 3.1.7 Added check for query string.
|
175 |
+
*
|
176 |
+
* @global object $wp
|
177 |
+
* @param boolean $slash Trailing slash the end of the url (default:true).
|
178 |
+
* @param boolean $getq Toggles getting the query string (default:true).
|
179 |
+
* @return string $url The current page full url path.
|
180 |
+
*/
|
181 |
+
function wpmem_current_url( $slash = true, $getq = true ) {
|
182 |
+
global $wp;
|
183 |
+
$url = home_url( add_query_arg( array(), $wp->request ) );
|
184 |
+
$url = ( $slash ) ? trailingslashit( $url ) : $url;
|
185 |
+
$url = ( $getq && count( $_GET ) > 0 ) ? $url . '?' . $_SERVER['QUERY_STRING'] : $url;
|
186 |
+
return $url;
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Gets post ID of current URL.
|
191 |
+
*
|
192 |
+
* @since 3.1.7
|
193 |
+
*
|
194 |
+
* @return int Post ID.
|
195 |
+
*/
|
196 |
+
function wpmem_current_post_id() {
|
197 |
+
return url_to_postid( wpmem_current_url() );
|
198 |
+
}
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Wrapper to return a string from the get_text function.
|
202 |
+
*
|
203 |
+
* @since 3.1.1
|
204 |
+
* @since 3.1.2 Added $echo argument.
|
205 |
+
*
|
206 |
+
* @global object $wpmem The WP_Members object.
|
207 |
+
* @param string $str The string to retrieve.
|
208 |
+
* @param bool $echo Print the string (default: false).
|
209 |
+
* @return string $str The localized string.
|
210 |
+
*/
|
211 |
+
function wpmem_gettext( $str, $echo = false ) {
|
212 |
+
global $wpmem;
|
213 |
+
if ( $echo ) {
|
214 |
+
echo $wpmem->get_text( $str );
|
215 |
+
} else {
|
216 |
+
return $wpmem->get_text( $str );
|
217 |
+
}
|
218 |
+
}
|
219 |
+
|
220 |
+
/**
|
221 |
+
* Wrapper to use custom dialog.
|
222 |
+
*
|
223 |
+
* @since 3.1.1
|
224 |
+
*
|
225 |
+
* @param array $defaults Dialog message defaults from the wpmem_msg_dialog_arr filter.
|
226 |
+
* @param string $tag The dialog tag/name.
|
227 |
+
* @param array $dialogs The dialog settings array (passed through filter).
|
228 |
+
* @return array $dialogs The dialog settings array (filtered).
|
229 |
+
*/
|
230 |
+
function wpmem_use_custom_dialog( $defaults, $tag, $dialogs ) {
|
231 |
+
$defaults['msg'] = __( $dialogs[ $tag ], 'wp-members' );
|
232 |
+
return $defaults;
|
233 |
+
}
|
234 |
+
|
235 |
+
/**
|
236 |
+
* Returns or displays the user's login status.
|
237 |
+
*
|
238 |
+
* @since 2.0.0
|
239 |
+
* @since 3.1.2 Moved to api.php, no longer pluggable.
|
240 |
+
* @since 3.1.6 Dependencies now loaded by object.
|
241 |
+
*
|
242 |
+
* @param boolean $echo Determines whether function should print result or not (default: true).
|
243 |
+
* @return string $status The user status string produced by wpmem_inc_memberlinks().
|
244 |
+
*/
|
245 |
+
function wpmem_login_status( $echo = true ) {
|
246 |
+
|
247 |
+
if ( is_user_logged_in() ) {
|
248 |
+
$status = wpmem_inc_memberlinks( 'status' );
|
249 |
+
if ( $echo ) {
|
250 |
+
echo $status;
|
251 |
+
}
|
252 |
+
return $status;
|
253 |
+
}
|
254 |
+
}
|
255 |
+
|
256 |
+
/**
|
257 |
+
* Utility function to validate $_POST, $_GET, and $_REQUEST.
|
258 |
+
*
|
259 |
+
* While this function retrieves data, remember that the data should generally be
|
260 |
+
* sanitized or escaped depending on how it is used.
|
261 |
+
*
|
262 |
+
* @since 3.1.3
|
263 |
+
*
|
264 |
+
* @param string $tag The form field or query string.
|
265 |
+
* @param string $default The default value (optional).
|
266 |
+
* @param string $type post|get|request (optional).
|
267 |
+
* @return string
|
268 |
+
*/
|
269 |
+
function wpmem_get( $tag, $default = '', $type = 'post' ) {
|
270 |
+
switch ( $type ) {
|
271 |
+
case 'get':
|
272 |
+
return ( isset( $_GET[ $tag ] ) ) ? $_GET[ $tag ] : $default;
|
273 |
+
break;
|
274 |
+
case 'request':
|
275 |
+
return ( isset( $_REQUEST[ $tag ] ) ) ? $_REQUEST[ $tag ] : $default;
|
276 |
+
break;
|
277 |
+
default: // case 'post':
|
278 |
+
return ( isset( $_POST[ $tag ] ) ) ? $_POST[ $tag ] : $default;
|
279 |
+
break;
|
280 |
+
}
|
281 |
+
}
|
282 |
+
|
283 |
+
/**
|
284 |
+
* Compares wpmem_reg_page value with the register page URL.
|
285 |
+
*
|
286 |
+
* @since 3.1.4
|
287 |
+
* @since 3.1.7 Added default of current page ID.
|
288 |
+
*
|
289 |
+
* @param string|int $check_page
|
290 |
+
* @return bool
|
291 |
+
*/
|
292 |
+
function wpmem_is_reg_page( $check = false ) {
|
293 |
+
if ( ! $check ) {
|
294 |
+
$check = get_the_ID();
|
295 |
+
} else {
|
296 |
+
if ( ! is_int( $check ) ) {
|
297 |
+
global $wpdb;
|
298 |
+
$sql = "SELECT ID FROM $wpdb->posts WHERE post_name = '$check' AND post_status = 'publish' LIMIT 1";
|
299 |
+
$arr = $wpdb->get_results( $sql, ARRAY_A );
|
300 |
+
$check = $arr[0]['ID'];
|
301 |
+
}
|
302 |
+
}
|
303 |
+
$reg_page = wpmem_get( 'wpmem_reg_page' );
|
304 |
+
$check_page = get_permalink( $check );
|
305 |
+
return ( $check_page == $reg_page ) ? true : false;
|
306 |
+
}
|
307 |
+
|
308 |
+
/**
|
309 |
+
* Creates a login/logout link.
|
310 |
+
*
|
311 |
+
* @since 3.1.6
|
312 |
+
*
|
313 |
+
* @param array $args {
|
314 |
+
* Array of arguments to customize output.
|
315 |
+
*
|
316 |
+
* @type string $login_redirect_to The url to redirect to after login (optional).
|
317 |
+
* @type string $logout_redirect_to The url to redirect to after logout (optional).
|
318 |
+
* @type string $login_text Text for the login link (optional).
|
319 |
+
* @type string $logout_text Text for the logout link (optional).
|
320 |
+
* }
|
321 |
+
* @param boolean $echo (default: false)
|
322 |
+
* @return string $link
|
323 |
+
*/
|
324 |
+
function wpmem_loginout( $args = array(), $echo = false ) {
|
325 |
+
$defaults = array(
|
326 |
+
'login_redirect_to' => ( isset( $args['login_redirect_to'] ) ) ? $args['login_redirect_to'] : wpmem_current_url(),
|
327 |
+
'logout_redirect_to' => ( isset( $args['logout_redirect_to'] ) ) ? $args['logout_redirect_to'] : wpmem_current_url(), // @todo - This is not currently active.
|
328 |
+
'login_text' => ( isset( $args['login_text'] ) ) ? $args['login_text'] : __( 'log in', 'wp-members' ),
|
329 |
+
'logout_text' => ( isset( $args['logout_text'] ) ) ? $args['logout_text'] : __( 'log out', 'wp-members' ),
|
330 |
+
);
|
331 |
+
$args = wp_parse_args( $args, $defaults );
|
332 |
+
$redirect = ( is_user_logged_in() ) ? $args['logout_redirect_to'] : $args['login_redirect_to'];
|
333 |
+
$text = ( is_user_logged_in() ) ? $args['logout_text'] : $args['login_text'];
|
334 |
+
if ( is_user_logged_in() ) {
|
335 |
+
/** This filter is defined in /inc/dialogs.php */
|
336 |
+
$link = apply_filters( 'wpmem_logout_link', add_query_arg( 'a', 'logout' ) );
|
337 |
+
} else {
|
338 |
+
$link = wpmem_login_url( $redirect );
|
339 |
+
}
|
340 |
+
$link = sprintf( '<a href="%s">%s</a>', $link, $text );
|
341 |
+
return $link;
|
342 |
+
}
|
343 |
+
|
344 |
+
/**
|
345 |
+
* Dispalays requested dialog.
|
346 |
+
*
|
347 |
+
* @since 3.2.0
|
348 |
+
*
|
349 |
+
* @todo Needs testing and finalization before release.
|
350 |
+
*/
|
351 |
+
function wpmem_display_message( $tag, $echo = true ) {
|
352 |
+
if ( $echo ) {
|
353 |
+
echo wpmem_inc_regmessage( $tag );
|
354 |
+
} else {
|
355 |
+
return wpmem_inc_regmessage( $tag );
|
356 |
+
}
|
357 |
+
}
|
358 |
+
|
359 |
+
/**
|
360 |
+
* Wrapper function for adding custom dialogs.
|
361 |
+
*
|
362 |
+
* @since 3.1.1
|
363 |
+
* @since 3.3.0 Moved to main API.
|
364 |
+
*
|
365 |
+
* @param array $dialogs Dialog settings array.
|
366 |
+
* @param string $tag Slug for dialog to be added.
|
367 |
+
* @param string $msg The dialog message.
|
368 |
+
* @param string $label Label for admin panel.
|
369 |
+
* @return array $dialogs Dialog settings array with prepped custom dialog added.
|
370 |
+
*/
|
371 |
+
function wpmem_add_custom_dialog( $dialogs, $tag, $msg, $label ) {
|
372 |
+
$msg = ( ! isset( $dialogs[ $tag ] ) ) ? $msg : $dialogs[ $tag ];
|
373 |
+
$dialogs[ $tag ] = array(
|
374 |
+
'name' => $tag,
|
375 |
+
'label' => $label,
|
376 |
+
'value' => $msg,
|
377 |
+
);
|
378 |
+
return $dialogs;
|
379 |
+
}
|
380 |
+
|
381 |
+
/**
|
382 |
+
* Gets an array of hidden post IDs.
|
383 |
+
*
|
384 |
+
* @since 3.3.1
|
385 |
+
*
|
386 |
+
* @global stdClass $wpmem
|
387 |
+
* @return array
|
388 |
+
*/
|
389 |
+
function wpmem_get_hidden_posts() {
|
390 |
+
global $wpmem;
|
391 |
+
return $wpmem->get_hidden_posts();
|
392 |
+
}
|
393 |
+
|
394 |
+
/**
|
395 |
+
* Conditional if REST request.
|
396 |
+
*
|
397 |
+
* @since 3.3.2
|
398 |
+
*
|
399 |
+
* @global stdClass $wpmem
|
400 |
+
* @return boolean
|
401 |
+
*/
|
402 |
+
function wpmem_is_rest() {
|
403 |
+
global $wpmem;
|
404 |
+
return $wpmem->is_rest;
|
405 |
+
}
|
406 |
+
|
407 |
// End of file.
|
includes/class-wp-members-captcha.php
CHANGED
@@ -1,234 +1,251 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* The WP_Members_User Class.
|
4 |
-
*
|
5 |
-
* This is the WP_Members User object class. This class contains functions
|
6 |
-
* for login, logout, registration and other user related methods.
|
7 |
-
*
|
8 |
-
* @package WP-Members
|
9 |
-
* @subpackage WP_Members_User Object Class
|
10 |
-
* @since 3.0.0
|
11 |
-
*/
|
12 |
-
|
13 |
-
// Exit if accessed directly.
|
14 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
15 |
-
exit();
|
16 |
-
}
|
17 |
-
|
18 |
-
class WP_Members_Captcha {
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Create reCAPTCHA form.
|
22 |
-
*
|
23 |
-
* @since 3.3.0 Replaces wpmem_inc_recaptcha().
|
24 |
-
*
|
25 |
-
* @param array $arr
|
26 |
-
* @return string $str HTML for reCAPTCHA display.
|
27 |
-
*/
|
28 |
-
static function recaptcha( $arr ) {
|
29 |
-
|
30 |
-
// Determine if reCAPTCHA should be another language.
|
31 |
-
$allowed_langs = array( 'nl', 'fr', 'de', 'pt', 'ru', 'es', 'tr' );
|
32 |
-
/** This filter is documented in wp-includes/l10n.php */
|
33 |
-
$locale = apply_filters( 'plugin_locale', get_locale(), 'wp-members' );
|
34 |
-
$compare_lang = strtolower( substr( $locale, -2 ) );
|
35 |
-
$use_the_lang = ( in_array( $compare_lang, $allowed_langs ) ) ? $compare_lang : false;
|
36 |
-
$lang = ( $use_the_lang ) ? ' lang : \'' . $use_the_lang . '\'' : '';
|
37 |
-
|
38 |
-
global $wpmem;
|
39 |
-
if ( $wpmem->captcha == 3 ) {
|
40 |
-
$str = '<script src="https://www.google.com/recaptcha/api.js" async defer></script>
|
41 |
-
<div class="g-recaptcha" data-sitekey="' . $arr['public'] . '"></div>';
|
42 |
-
}
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Filter the reCAPTCHA HTML.
|
46 |
-
*
|
47 |
-
* @since 2.7.4
|
48 |
-
*
|
49 |
-
* @param string $str A string of HTML for the reCAPTCHA.
|
50 |
-
*/
|
51 |
-
$str = apply_filters( 'wpmem_recaptcha', $str );
|
52 |
-
|
53 |
-
return $str;
|
54 |
-
}
|
55 |
-
|
56 |
-
/**
|
57 |
-
* Create Really Simple CAPTCHA.
|
58 |
-
*
|
59 |
-
* @since 3.3.0 Replaces wpmem_build_rs_captcha().
|
60 |
-
*
|
61 |
-
* @global object $wpmem The WP_Members object.
|
62 |
-
* @return array {
|
63 |
-
* HTML Form elements for Really Simple CAPTCHA.
|
64 |
-
*
|
65 |
-
* @type string label_text The raw text used for the label.
|
66 |
-
* @type string label The HTML for the label.
|
67 |
-
* @type string field The input tag and the CAPTCHA image.
|
68 |
-
* }
|
69 |
-
*/
|
70 |
-
static function rs_captcha() {
|
71 |
-
|
72 |
-
global $wpmem;
|
73 |
-
|
74 |
-
if ( defined( 'REALLYSIMPLECAPTCHA_VERSION' ) ) {
|
75 |
-
// setup defaults
|
76 |
-
$defaults = array(
|
77 |
-
'characters' => 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789',
|
78 |
-
'num_char' => '4',
|
79 |
-
'dim_w' => '72',
|
80 |
-
'dim_h' => '30',
|
81 |
-
'font_color' => '0,0,0',
|
82 |
-
'bg_color' => '255,255,255',
|
83 |
-
'font_size' => '12',
|
84 |
-
'kerning' => '14',
|
85 |
-
'img_type' => 'png',
|
86 |
-
);
|
87 |
-
$wpmem_captcha = get_option( 'wpmembers_captcha' );
|
88 |
-
|
89 |
-
$args = ( isset( $wpmem_captcha['really_simple'] ) && is_array( $wpmem_captcha['really_simple'] ) ) ? $wpmem_captcha['really_simple'] : array();
|
90 |
-
$args = wp_parse_args( $args, $defaults );
|
91 |
-
|
92 |
-
$img_size = array( $args['dim_w'], $args['dim_h'] );
|
93 |
-
$fg = explode( ",", $args['font_color'] );
|
94 |
-
$bg = explode( ",", $args['bg_color'] );
|
95 |
-
|
96 |
-
$wpmem_captcha = new ReallySimpleCaptcha();
|
97 |
-
$wpmem_captcha->chars = $args['characters'];
|
98 |
-
$wpmem_captcha->char_length = $args['num_char'];
|
99 |
-
$wpmem_captcha->img_size = $img_size;
|
100 |
-
$wpmem_captcha->fg = $fg;
|
101 |
-
$wpmem_captcha->bg = $bg;
|
102 |
-
$wpmem_captcha->font_size = $args['font_size'];
|
103 |
-
$wpmem_captcha->font_char_width = $args['kerning'];
|
104 |
-
$wpmem_captcha->img_type = $args['img_type'];
|
105 |
-
|
106 |
-
$wpmem_captcha_word = $wpmem_captcha->generate_random_word();
|
107 |
-
$wpmem_captcha_prefix = mt_rand();
|
108 |
-
$wpmem_captcha_image_name = $wpmem_captcha->generate_image( $wpmem_captcha_prefix, $wpmem_captcha_word );
|
109 |
-
|
110 |
-
/**
|
111 |
-
* Filters the default Really Simple Captcha folder location.
|
112 |
-
*
|
113 |
-
* @since 3.0
|
114 |
-
*
|
115 |
-
* @param string The default location of RS Captcha.
|
116 |
-
*/
|
117 |
-
$wpmem_captcha_image_url = apply_filters( 'wpmem_rs_captcha_folder', get_bloginfo('wpurl') . '/wp-content/plugins/really-simple-captcha/tmp/' );
|
118 |
-
|
119 |
-
$img_w = $wpmem_captcha->img_size[0];
|
120 |
-
$img_h = $wpmem_captcha->img_size[1];
|
121 |
-
$src = $wpmem_captcha_image_url . $wpmem_captcha_image_name;
|
122 |
-
$size = $wpmem_captcha->char_length;
|
123 |
-
$pre = $wpmem_captcha_prefix;
|
124 |
-
|
125 |
-
return array(
|
126 |
-
'label_text' => $wpmem->get_text( 'register_rscaptcha' ),
|
127 |
-
'label' => '<label class="text" for="captcha">' . $wpmem->get_text( 'register_rscaptcha' ) . '</label>',
|
128 |
-
'field' => '<input id="captcha_code" name="captcha_code" size="' . esc_attr( $size ) . '" type="text" />
|
129 |
-
<input id="captcha_prefix" name="captcha_prefix" type="hidden" value="' . esc_attr( $pre ) . '" />
|
130 |
-
<img src="' . esc_url( $src ) . '" alt="captcha" width="' . esc_attr( $img_w ) . '" height="' . esc_attr( $img_h ) . '" />'
|
131 |
-
);
|
132 |
-
} else {
|
133 |
-
return;
|
134 |
-
}
|
135 |
-
}
|
136 |
-
|
137 |
-
/**
|
138 |
-
* Process registration captcha.
|
139 |
-
*
|
140 |
-
* @since 3.1.6
|
141 |
-
* @since 3.3.0 Ported from wpmem_register_handle_captcha() in register.php.
|
142 |
-
*
|
143 |
-
* @global $wpmem
|
144 |
-
* @global $wpmem_themsg
|
145 |
-
* @return $string
|
146 |
-
*/
|
147 |
-
static function validate() {
|
148 |
-
|
149 |
-
global $wpmem, $wpmem_themsg;
|
150 |
-
|
151 |
-
// Get the captcha settings (api keys).
|
152 |
-
$wpmem_captcha = get_option( 'wpmembers_captcha' );
|
153 |
-
|
154 |
-
/*
|
155 |
-
* @todo reCAPTCHA v1 is deprecated by Google. It is also no longer allowed
|
156 |
-
* to be set for new installs of WP-Members. It is NOT compatible with
|
157 |
-
* PHP 7.1 and is therefore fully obsolete.
|
158 |
-
*/
|
159 |
-
// If captcha is on, check the captcha.
|
160 |
-
if ( $wpmem->captcha == 1 && $wpmem_captcha['recaptcha'] ) {
|
161 |
-
$wpmem->captcha = 3;
|
162 |
-
}
|
163 |
-
|
164 |
-
if ( 2 == $wpmem->captcha ) {
|
165 |
-
if ( defined( 'REALLYSIMPLECAPTCHA_VERSION' ) ) {
|
166 |
-
// Validate Really Simple Captcha.
|
167 |
-
$wpmem_captcha = new ReallySimpleCaptcha();
|
168 |
-
// This variable holds the CAPTCHA image prefix, which corresponds to the correct answer.
|
169 |
-
$wpmem_captcha_prefix = ( isset( $_POST['captcha_prefix'] ) ) ? $_POST['captcha_prefix'] : '';
|
170 |
-
// This variable holds the CAPTCHA response, entered by the user.
|
171 |
-
$wpmem_captcha_code = ( isset( $_POST['captcha_code'] ) ) ? $_POST['captcha_code'] : '';
|
172 |
-
// Check CAPTCHA validity.
|
173 |
-
$wpmem_captcha_correct = ( $wpmem_captcha->check( $wpmem_captcha_prefix, $wpmem_captcha_code ) ) ? true : false;
|
174 |
-
// Clean up the tmp directory.
|
175 |
-
$wpmem_captcha->remove( $wpmem_captcha_prefix );
|
176 |
-
$wpmem_captcha->cleanup();
|
177 |
-
// If CAPTCHA validation fails (incorrect value entered in CAPTCHA field), return an error.
|
178 |
-
if ( ! $wpmem_captcha_correct ) {
|
179 |
-
$wpmem_themsg = __( 'You have entered an incorrect code value. Please try again.', 'wp-members' );
|
180 |
-
return "empty";
|
181 |
-
}
|
182 |
-
}
|
183 |
-
}
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
if (
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The WP_Members_User Class.
|
4 |
+
*
|
5 |
+
* This is the WP_Members User object class. This class contains functions
|
6 |
+
* for login, logout, registration and other user related methods.
|
7 |
+
*
|
8 |
+
* @package WP-Members
|
9 |
+
* @subpackage WP_Members_User Object Class
|
10 |
+
* @since 3.0.0
|
11 |
+
*/
|
12 |
+
|
13 |
+
// Exit if accessed directly.
|
14 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
15 |
+
exit();
|
16 |
+
}
|
17 |
+
|
18 |
+
class WP_Members_Captcha {
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Create reCAPTCHA form.
|
22 |
+
*
|
23 |
+
* @since 3.3.0 Replaces wpmem_inc_recaptcha().
|
24 |
+
*
|
25 |
+
* @param array $arr
|
26 |
+
* @return string $str HTML for reCAPTCHA display.
|
27 |
+
*/
|
28 |
+
static function recaptcha( $arr ) {
|
29 |
+
|
30 |
+
// Determine if reCAPTCHA should be another language.
|
31 |
+
$allowed_langs = array( 'nl', 'fr', 'de', 'pt', 'ru', 'es', 'tr' );
|
32 |
+
/** This filter is documented in wp-includes/l10n.php */
|
33 |
+
$locale = apply_filters( 'plugin_locale', get_locale(), 'wp-members' );
|
34 |
+
$compare_lang = strtolower( substr( $locale, -2 ) );
|
35 |
+
$use_the_lang = ( in_array( $compare_lang, $allowed_langs ) ) ? $compare_lang : false;
|
36 |
+
$lang = ( $use_the_lang ) ? ' lang : \'' . $use_the_lang . '\'' : '';
|
37 |
+
|
38 |
+
global $wpmem;
|
39 |
+
if ( $wpmem->captcha == 3 ) {
|
40 |
+
$str = '<script src="https://www.google.com/recaptcha/api.js" async defer></script>
|
41 |
+
<div class="g-recaptcha" data-sitekey="' . $arr['public'] . '"></div>';
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Filter the reCAPTCHA HTML.
|
46 |
+
*
|
47 |
+
* @since 2.7.4
|
48 |
+
*
|
49 |
+
* @param string $str A string of HTML for the reCAPTCHA.
|
50 |
+
*/
|
51 |
+
$str = apply_filters( 'wpmem_recaptcha', $str );
|
52 |
+
|
53 |
+
return $str;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Create Really Simple CAPTCHA.
|
58 |
+
*
|
59 |
+
* @since 3.3.0 Replaces wpmem_build_rs_captcha().
|
60 |
+
*
|
61 |
+
* @global object $wpmem The WP_Members object.
|
62 |
+
* @return array {
|
63 |
+
* HTML Form elements for Really Simple CAPTCHA.
|
64 |
+
*
|
65 |
+
* @type string label_text The raw text used for the label.
|
66 |
+
* @type string label The HTML for the label.
|
67 |
+
* @type string field The input tag and the CAPTCHA image.
|
68 |
+
* }
|
69 |
+
*/
|
70 |
+
static function rs_captcha() {
|
71 |
+
|
72 |
+
global $wpmem;
|
73 |
+
|
74 |
+
if ( defined( 'REALLYSIMPLECAPTCHA_VERSION' ) ) {
|
75 |
+
// setup defaults
|
76 |
+
$defaults = array(
|
77 |
+
'characters' => 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789',
|
78 |
+
'num_char' => '4',
|
79 |
+
'dim_w' => '72',
|
80 |
+
'dim_h' => '30',
|
81 |
+
'font_color' => '0,0,0',
|
82 |
+
'bg_color' => '255,255,255',
|
83 |
+
'font_size' => '12',
|
84 |
+
'kerning' => '14',
|
85 |
+
'img_type' => 'png',
|
86 |
+
);
|
87 |
+
$wpmem_captcha = get_option( 'wpmembers_captcha' );
|
88 |
+
|
89 |
+
$args = ( isset( $wpmem_captcha['really_simple'] ) && is_array( $wpmem_captcha['really_simple'] ) ) ? $wpmem_captcha['really_simple'] : array();
|
90 |
+
$args = wp_parse_args( $args, $defaults );
|
91 |
+
|
92 |
+
$img_size = array( $args['dim_w'], $args['dim_h'] );
|
93 |
+
$fg = explode( ",", $args['font_color'] );
|
94 |
+
$bg = explode( ",", $args['bg_color'] );
|
95 |
+
|
96 |
+
$wpmem_captcha = new ReallySimpleCaptcha();
|
97 |
+
$wpmem_captcha->chars = $args['characters'];
|
98 |
+
$wpmem_captcha->char_length = $args['num_char'];
|
99 |
+
$wpmem_captcha->img_size = $img_size;
|
100 |
+
$wpmem_captcha->fg = $fg;
|
101 |
+
$wpmem_captcha->bg = $bg;
|
102 |
+
$wpmem_captcha->font_size = $args['font_size'];
|
103 |
+
$wpmem_captcha->font_char_width = $args['kerning'];
|
104 |
+
$wpmem_captcha->img_type = $args['img_type'];
|
105 |
+
|
106 |
+
$wpmem_captcha_word = $wpmem_captcha->generate_random_word();
|
107 |
+
$wpmem_captcha_prefix = mt_rand();
|
108 |
+
$wpmem_captcha_image_name = $wpmem_captcha->generate_image( $wpmem_captcha_prefix, $wpmem_captcha_word );
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Filters the default Really Simple Captcha folder location.
|
112 |
+
*
|
113 |
+
* @since 3.0
|
114 |
+
*
|
115 |
+
* @param string The default location of RS Captcha.
|
116 |
+
*/
|
117 |
+
$wpmem_captcha_image_url = apply_filters( 'wpmem_rs_captcha_folder', get_bloginfo('wpurl') . '/wp-content/plugins/really-simple-captcha/tmp/' );
|
118 |
+
|
119 |
+
$img_w = $wpmem_captcha->img_size[0];
|
120 |
+
$img_h = $wpmem_captcha->img_size[1];
|
121 |
+
$src = $wpmem_captcha_image_url . $wpmem_captcha_image_name;
|
122 |
+
$size = $wpmem_captcha->char_length;
|
123 |
+
$pre = $wpmem_captcha_prefix;
|
124 |
+
|
125 |
+
return array(
|
126 |
+
'label_text' => $wpmem->get_text( 'register_rscaptcha' ),
|
127 |
+
'label' => '<label class="text" for="captcha">' . $wpmem->get_text( 'register_rscaptcha' ) . '</label>',
|
128 |
+
'field' => '<input id="captcha_code" name="captcha_code" size="' . esc_attr( $size ) . '" type="text" />
|
129 |
+
<input id="captcha_prefix" name="captcha_prefix" type="hidden" value="' . esc_attr( $pre ) . '" />
|
130 |
+
<img src="' . esc_url( $src ) . '" alt="captcha" width="' . esc_attr( $img_w ) . '" height="' . esc_attr( $img_h ) . '" />'
|
131 |
+
);
|
132 |
+
} else {
|
133 |
+
return;
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Process registration captcha.
|
139 |
+
*
|
140 |
+
* @since 3.1.6
|
141 |
+
* @since 3.3.0 Ported from wpmem_register_handle_captcha() in register.php.
|
142 |
+
*
|
143 |
+
* @global $wpmem
|
144 |
+
* @global $wpmem_themsg
|
145 |
+
* @return $string
|
146 |
+
*/
|
147 |
+
static function validate() {
|
148 |
+
|
149 |
+
global $wpmem, $wpmem_themsg;
|
150 |
+
|
151 |
+
// Get the captcha settings (api keys).
|
152 |
+
$wpmem_captcha = get_option( 'wpmembers_captcha' );
|
153 |
+
|
154 |
+
/*
|
155 |
+
* @todo reCAPTCHA v1 is deprecated by Google. It is also no longer allowed
|
156 |
+
* to be set for new installs of WP-Members. It is NOT compatible with
|
157 |
+
* PHP 7.1 and is therefore fully obsolete.
|
158 |
+
*/
|
159 |
+
// If captcha is on, check the captcha.
|
160 |
+
if ( $wpmem->captcha == 1 && $wpmem_captcha['recaptcha'] ) {
|
161 |
+
$wpmem->captcha = 3;
|
162 |
+
}
|
163 |
+
|
164 |
+
if ( 2 == $wpmem->captcha ) {
|
165 |
+
if ( defined( 'REALLYSIMPLECAPTCHA_VERSION' ) ) {
|
166 |
+
// Validate Really Simple Captcha.
|
167 |
+
$wpmem_captcha = new ReallySimpleCaptcha();
|
168 |
+
// This variable holds the CAPTCHA image prefix, which corresponds to the correct answer.
|
169 |
+
$wpmem_captcha_prefix = ( isset( $_POST['captcha_prefix'] ) ) ? sanitize_text_field( $_POST['captcha_prefix'] ) : '';
|
170 |
+
// This variable holds the CAPTCHA response, entered by the user.
|
171 |
+
$wpmem_captcha_code = ( isset( $_POST['captcha_code'] ) ) ? sanitize_text_field( $_POST['captcha_code'] ) : '';
|
172 |
+
// Check CAPTCHA validity.
|
173 |
+
$wpmem_captcha_correct = ( $wpmem_captcha->check( $wpmem_captcha_prefix, $wpmem_captcha_code ) ) ? true : false;
|
174 |
+
// Clean up the tmp directory.
|
175 |
+
$wpmem_captcha->remove( $wpmem_captcha_prefix );
|
176 |
+
$wpmem_captcha->cleanup();
|
177 |
+
// If CAPTCHA validation fails (incorrect value entered in CAPTCHA field), return an error.
|
178 |
+
if ( ! $wpmem_captcha_correct ) {
|
179 |
+
$wpmem_themsg = __( 'You have entered an incorrect code value. Please try again.', 'wp-members' );
|
180 |
+
return "empty";
|
181 |
+
}
|
182 |
+
}
|
183 |
+
} else {
|
184 |
+
|
185 |
+
// It is reCAPTCHA.
|
186 |
+
$recaptcha_verify_url = 'https://www.google.com/recaptcha/api/siteverify?';
|
187 |
+
|
188 |
+
$privatekey = $wpmem_captcha['recaptcha']['private'];
|
189 |
+
|
190 |
+
if ( 3 == $wpmem->captcha && $wpmem_captcha['recaptcha'] ) {
|
191 |
+
|
192 |
+
$captcha = wpmem_get( 'g-recaptcha-response', false );
|
193 |
+
|
194 |
+
// If there is no captcha value, return error.
|
195 |
+
if ( ! $captcha ) {
|
196 |
+
$wpmem_themsg = $wpmem->get_text( 'reg_empty_captcha' );
|
197 |
+
return "empty";
|
198 |
+
}
|
199 |
+
|
200 |
+
// Build URL for captcha evaluation.
|
201 |
+
$url = $recaptcha_verify_url . http_build_query([
|
202 |
+
'secret' => $privatekey,
|
203 |
+
'response' => $captcha,
|
204 |
+
'remoteip' => wpmem_get_user_ip(),
|
205 |
+
]);
|
206 |
+
|
207 |
+
// Validate the captcha.
|
208 |
+
$response = wp_remote_fopen( $url );
|
209 |
+
|
210 |
+
// Decode the json response.
|
211 |
+
$response = json_decode( $response, true );
|
212 |
+
|
213 |
+
// If captcha validation was unsuccessful.
|
214 |
+
if ( false == $response['success'] ) {
|
215 |
+
$wpmem_themsg = $wpmem->get_text( 'reg_invalid_captcha' );
|
216 |
+
if ( WP_DEBUG && isset( $response['error-codes'] ) ) {
|
217 |
+
$wpmem_themsg.= '<br /><br />';
|
218 |
+
foreach( $response['error-codes'] as $code ) {
|
219 |
+
$wpmem_themsg.= "Error code: " . $code . "<br />";
|
220 |
+
}
|
221 |
+
}
|
222 |
+
return "empty";
|
223 |
+
}
|
224 |
+
} elseif ( 4 == $wpmem->captcha && $wpmem_captcha['recaptcha'] ) {
|
225 |
+
$captcha = wpmem_get( 'recaptcha_response', false );
|
226 |
+
if ( $_SERVER['REQUEST_METHOD'] === 'POST' && false !== $captcha ) {
|
227 |
+
|
228 |
+
// Make and decode POST request:
|
229 |
+
$url = $recaptcha_verify_url . http_build_query([
|
230 |
+
'secret' => $privatekey,
|
231 |
+
'response' => $captcha,
|
232 |
+
]);
|
233 |
+
$recaptcha = file_get_contents( $url );
|
234 |
+
$recaptcha = json_decode( $recaptcha );
|
235 |
+
|
236 |
+
// Take action based on the score returned:
|
237 |
+
if ( $recaptcha->score >= 0.5 ) {
|
238 |
+
// Verified - send email
|
239 |
+
} else {
|
240 |
+
$wpmem_themsg = $wpmem->get_text( 'reg_invalid_captcha' );
|
241 |
+
return "empty";
|
242 |
+
}
|
243 |
+
} else {
|
244 |
+
return "empty";
|
245 |
+
}
|
246 |
+
}
|
247 |
+
}
|
248 |
+
|
249 |
+
return "passed_captcha";
|
250 |
+
}
|
251 |
}
|
includes/class-wp-members-email.php
CHANGED
@@ -1,556 +1,556 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* The WP_Members Email Class.
|
4 |
-
*
|
5 |
-
* This class contains functions
|
6 |
-
* for the plugin's email functions.
|
7 |
-
*
|
8 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
9 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
10 |
-
* Copyright (c) 2006-
|
11 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
12 |
-
*
|
13 |
-
* @package WP-Members
|
14 |
-
* @subpackage WP_Members_Shortcodes
|
15 |
-
* @author Chad Butler
|
16 |
-
* @copyright 2006-
|
17 |
-
*/
|
18 |
-
|
19 |
-
// Exit if accessed directly.
|
20 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
21 |
-
exit();
|
22 |
-
}
|
23 |
-
|
24 |
-
class WP_Members_Email {
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Container email from address.
|
28 |
-
*
|
29 |
-
* @since 3.2.0
|
30 |
-
* @access public
|
31 |
-
* @var string
|
32 |
-
*/
|
33 |
-
public $from;
|
34 |
-
|
35 |
-
/**
|
36 |
-
* Container for email from name.
|
37 |
-
*
|
38 |
-
* @since 3.2.0
|
39 |
-
* @access public
|
40 |
-
* @var string
|
41 |
-
*/
|
42 |
-
public $from_name;
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Container for settings.
|
46 |
-
*
|
47 |
-
* @since 3.2.0
|
48 |
-
* @access public
|
49 |
-
* @var array
|
50 |
-
*/
|
51 |
-
public $settings;
|
52 |
-
|
53 |
-
/**
|
54 |
-
* Load custom from address.
|
55 |
-
*
|
56 |
-
* @since 3.3.0
|
57 |
-
*/
|
58 |
-
function load_from() {
|
59 |
-
$this->from = get_option( 'wpmembers_email_wpfrom', '' );
|
60 |
-
$this->from_name = get_option( 'wpmembers_email_wpname', '' );
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Builds emails for the user.
|
65 |
-
*
|
66 |
-
* @since 1.8.0
|
67 |
-
* @since 2.7.4 Added wpmem_email_headers and individual body/subject filters.
|
68 |
-
* @since 2.9.7 Major overhaul, added wpmem_email_filter filter.
|
69 |
-
* @since 3.1.0 Can filter in custom shortcodes with wpmem_email_shortcodes.
|
70 |
-
* @since 3.1.1 Added $custom argument for custom emails.
|
71 |
-
* @since 3.2.0 Changed wpmem_msurl key to wpmem_profile.
|
72 |
-
* @since 3.2.0 Changed toggle key to tag.
|
73 |
-
* @since 3.2.0 Moved to WP_Members_Email::to_user().
|
74 |
-
*
|
75 |
-
* @global object $wpmem The WP_Members object.
|
76 |
-
* @global string $wpmem_mail_from The email from address.
|
77 |
-
* @global string $wpmem_mail_from_name The email from name.
|
78 |
-
*
|
79 |
-
* @param int $user_ID The User's ID.
|
80 |
-
* @param string $password Password from the registration process.
|
81 |
-
* @param string $tag Tag indicating the email being sent (newreg|newmod|appmod|repass|getuser).
|
82 |
-
* @param array $wpmem_fields Array of the WP-Members fields (defaults to null).
|
83 |
-
* @param array $fields Array of the registration data (defaults to null).
|
84 |
-
* @param array $custom Array of custom email information (defaults to null).
|
85 |
-
*/
|
86 |
-
function to_user( $user_id, $password, $tag, $wpmem_fields = null, $field_data = null, $custom = null ) {
|
87 |
-
|
88 |
-
global $wpmem;
|
89 |
-
|
90 |
-
// Load from address.
|
91 |
-
$this->load_from();
|
92 |
-
|
93 |
-
// Handle backward compatibility for customizations that may call the email function directly.
|
94 |
-
$wpmem_fields = wpmem_fields();
|
95 |
-
|
96 |
-
//Determine email to be sent. Stored option is an array with keys 'body' and 'subj'.
|
97 |
-
$tag_array = array( 'newreg', 'newmod', 'appmod', 'repass', 'getuser' );
|
98 |
-
switch ( $tag ) {
|
99 |
-
case 0:
|
100 |
-
case 1:
|
101 |
-
case 2:
|
102 |
-
case 3:
|
103 |
-
case 4:
|
104 |
-
$tag = $tag_array[ $tag ];
|
105 |
-
$this->settings = get_option( 'wpmembers_email_' . $tag );
|
106 |
-
$this->settings['tag'] = $tag;
|
107 |
-
break;
|
108 |
-
default: // case 5:
|
109 |
-
// This is a custom email.
|
110 |
-
$this->settings['subj'] = $custom['subj'];
|
111 |
-
$this->settings['body'] = $custom['body'];
|
112 |
-
$this->settings['tag'] = ( isset( $custom['tag'] ) ) ? $custom['tag'] : '';
|
113 |
-
break;
|
114 |
-
}
|
115 |
-
|
116 |
-
// Get the user ID.
|
117 |
-
$user = new WP_User( $user_id );
|
118 |
-
|
119 |
-
// Userdata for default shortcodes.
|
120 |
-
$this->settings['user_id'] = $user_id;
|
121 |
-
$this->settings['user_login'] = stripslashes( $user->user_login );
|
122 |
-
$this->settings['user_email'] = stripslashes( $user->user_email );
|
123 |
-
$this->settings['blogname'] = wp_specialchars_decode( get_option ( 'blogname' ), ENT_QUOTES );
|
124 |
-
$this->settings['exp_type'] = ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) ? get_user_meta( $user_id, 'exp_type', true ) : '';
|
125 |
-
$this->settings['exp_date'] = ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) ? get_user_meta( $user_id, 'expires', true ) : '';
|
126 |
-
$this->settings['wpmem_profile'] = esc_url( $wpmem->user_pages['profile'] );
|
127 |
-
$this->settings['wpmem_reg'] = esc_url( $wpmem->user_pages['register'] );
|
128 |
-
$this->settings['wpmem_login'] = esc_url( $wpmem->user_pages['login'] );
|
129 |
-
$this->settings['reg_link'] = esc_url( get_user_meta( $user_id, 'wpmem_reg_url', true ) );
|
130 |
-
$this->settings['do_shortcodes'] = true;
|
131 |
-
$this->settings['add_footer'] = true;
|
132 |
-
$this->settings['footer'] = get_option( 'wpmembers_email_footer' );
|
133 |
-
$this->settings['disable'] = false;
|
134 |
-
$this->settings['toggle'] = $this->settings['tag']; // Deprecated since 3.2.0, but remains in the array for legacy reasons.
|
135 |
-
$this->settings['reset_link'] = esc_url_raw( add_query_arg( array( 'a' => 'pwdreset', 'key' => $password, 'id' => $user_id ), wpmem_profile_url() ) );
|
136 |
-
|
137 |
-
// Apply filters (if set) for the sending email address.
|
138 |
-
$default_header = ( $this->from && $this->from_name ) ? 'From: "' . $this->from_name . '" <' . $this->from . '>' : '';
|
139 |
-
|
140 |
-
/**
|
141 |
-
* Filters the email headers.
|
142 |
-
*
|
143 |
-
* @since 2.7.4
|
144 |
-
* @since 3.2.0 Changed toggle to tag.
|
145 |
-
*
|
146 |
-
* @param mixed $default_header The email headers.
|
147 |
-
* @param string $this->settings['tag'] Tag to determine what email is being generated (newreg|newmod|appmod|repass|admin).
|
148 |
-
*/
|
149 |
-
$this->settings['headers'] = apply_filters( 'wpmem_email_headers', $default_header, $this->settings['tag'] );
|
150 |
-
|
151 |
-
/**
|
152 |
-
* Filter the email.
|
153 |
-
*
|
154 |
-
* This filter passes the email subject, body, user ID, and several other
|
155 |
-
* settings and parameters for use in the filter function. It also passes an
|
156 |
-
* array of the WP-Members fields, and an array of the posted registration
|
157 |
-
* data from the register function.
|
158 |
-
*
|
159 |
-
* @since 2.9.7
|
160 |
-
* @since 3.1.0 Added footer content to the array.
|
161 |
-
* @since 3.2.0 Changed wpmem_msurl key to wpmem_profile.
|
162 |
-
* @since 3.2.0 Change toggle to tag.
|
163 |
-
*
|
164 |
-
* @param array $this->settings {
|
165 |
-
* An array containing email body, subject, user id, and additional settings.
|
166 |
-
*
|
167 |
-
* @type string subj
|
168 |
-
* @type string body
|
169 |
-
* @type string tag
|
170 |
-
* @type int user_id
|
171 |
-
* @type string user_login
|
172 |
-
* @type string user_email
|
173 |
-
* @type string blogname
|
174 |
-
* @type string exp_type
|
175 |
-
* @type string exp_date
|
176 |
-
* @type string wpmem_profile
|
177 |
-
* @type string reg_link
|
178 |
-
* @type string do_shortcodes
|
179 |
-
* @type bool add_footer
|
180 |
-
* @type string footer
|
181 |
-
* @type bool disable
|
182 |
-
* @type mixed headers
|
183 |
-
* @type string toggle Deprecated since 3.2.0
|
184 |
-
* }
|
185 |
-
* @param array $wpmem_fields An array of the WP-Members fields.
|
186 |
-
* @param array $field_data An array of the posted registration data.
|
187 |
-
*/
|
188 |
-
$this->settings = apply_filters( 'wpmem_email_filter', $this->settings, $wpmem_fields, $field_data );
|
189 |
-
|
190 |
-
// If emails are not disabled, continue the email process.
|
191 |
-
if ( ! $this->settings['disable'] ) {
|
192 |
-
|
193 |
-
/**
|
194 |
-
* Filters the email body based on tag.
|
195 |
-
*
|
196 |
-
* @since 2.7.4
|
197 |
-
* @deprecated 3.2.0 Use wpmem_email_filter instead.
|
198 |
-
*
|
199 |
-
* @param string $this->settings['body'] The body content of the new registration email.
|
200 |
-
*/
|
201 |
-
$this->settings['body'] = apply_filters( 'wpmem_email_' . $this->settings['tag'], $this->settings['body'] );
|
202 |
-
|
203 |
-
// Get the email footer if needed.
|
204 |
-
$foot = ( $this->settings['add_footer'] ) ? $this->settings['footer'] : '';
|
205 |
-
|
206 |
-
// If doing shortcode replacements.
|
207 |
-
if ( $this->settings['do_shortcodes'] ) {
|
208 |
-
|
209 |
-
$shortcodes = array(
|
210 |
-
'blogname' => $this->settings['blogname'],
|
211 |
-
'username' => $this->settings['user_login'],
|
212 |
-
'password' => $password,
|
213 |
-
'email' => $this->settings['user_email'],
|
214 |
-
'reglink' => $this->settings['reg_link'],
|
215 |
-
'members-area' => $this->settings['wpmem_profile'],
|
216 |
-
'user-profile' => $this->settings['wpmem_profile'],
|
217 |
-
'exp-type' => $this->settings['exp_type'],
|
218 |
-
'exp-data' => $this->settings['exp_date'],
|
219 |
-
'exp-date' => $this->settings['exp_date'],
|
220 |
-
'login' => $this->settings['wpmem_login'],
|
221 |
-
'register' => $this->settings['wpmem_reg'],
|
222 |
-
'reset_link' => $this->settings['reset_link'],
|
223 |
-
);
|
224 |
-
|
225 |
-
// Add custom field shortcodes.
|
226 |
-
foreach ( $wpmem_fields as $meta_key => $field ) {
|
227 |
-
if ( ! array_key_exists( $meta_key, $shortcodes ) ) {
|
228 |
-
$val = ( is_array( $field_data ) && $field['register'] ) ? $field_data[ $meta_key ] : get_user_meta( $user_id, $meta_key, true );
|
229 |
-
$shortcodes[ $meta_key ] = $val;
|
230 |
-
}
|
231 |
-
}
|
232 |
-
|
233 |
-
/**
|
234 |
-
* Filter available email shortcodes.
|
235 |
-
*
|
236 |
-
* @since 3.1.0
|
237 |
-
*
|
238 |
-
* @param array $shortcodes
|
239 |
-
* @param string $tag
|
240 |
-
*/
|
241 |
-
$shortcodes = apply_filters( 'wpmem_email_shortcodes', $shortcodes, $this->settings['tag'] );
|
242 |
-
|
243 |
-
$shortcd = array();
|
244 |
-
$replace = array();
|
245 |
-
foreach ( $shortcodes as $key => $val ) {
|
246 |
-
// Shortcodes.
|
247 |
-
$shortcd[] = '[' . $key . ']';
|
248 |
-
// Replacement values.
|
249 |
-
$replace[] = ( 'password' == $key ) ? $password : $val;
|
250 |
-
}
|
251 |
-
|
252 |
-
// Do replacements for subject, body, and footer shortcodes.
|
253 |
-
$this->settings['subj'] = str_replace( $shortcd, $replace, $this->settings['subj'] );
|
254 |
-
$this->settings['body'] = str_replace( $shortcd, $replace, $this->settings['body'] );
|
255 |
-
$foot = ( $this->settings['add_footer'] ) ? str_replace( $shortcd, $replace, $foot ) : '';
|
256 |
-
}
|
257 |
-
|
258 |
-
// Append footer if needed.
|
259 |
-
$this->settings['body'] = ( $this->settings['add_footer'] ) ? $this->settings['body'] . "\r\n" . $foot : $this->settings['body'];
|
260 |
-
|
261 |
-
// Send message.
|
262 |
-
$this->send( 'user' );
|
263 |
-
|
264 |
-
}
|
265 |
-
return;
|
266 |
-
}
|
267 |
-
|
268 |
-
/**
|
269 |
-
* Builds the email for admin notification of new user registration.
|
270 |
-
*
|
271 |
-
* @since 2.3
|
272 |
-
* @since 3.2.0 Moved to WP_Members_Email::notify_admin().
|
273 |
-
*
|
274 |
-
* @global object $wpmem The WP_Members object.
|
275 |
-
* @global string $wpmem_mail_from The email from address.
|
276 |
-
* @global string $wpmem_mail_from_name The email from name.
|
277 |
-
*
|
278 |
-
* @param int $user_id The User's ID.
|
279 |
-
* @param array $wpmem_fields Array of the WP-Members fields (defaults to null).
|
280 |
-
* @param array $field_data Array of the registration data (defaults to null).
|
281 |
-
*/
|
282 |
-
function notify_admin( $user_id, $wpmem_fields = null, $field_data = null ) {
|
283 |
-
|
284 |
-
global $wpmem;
|
285 |
-
|
286 |
-
// Load from address.
|
287 |
-
$this->load_from();
|
288 |
-
|
289 |
-
// Handle backward compatibility for customizations that may call the email function directly.
|
290 |
-
$wpmem_fields = wpmem_fields( 'admin_notify' );
|
291 |
-
|
292 |
-
// WP default user fields.
|
293 |
-
$wp_user_fields = array(
|
294 |
-
'user_login',
|
295 |
-
'user_nicename',
|
296 |
-
'user_url',
|
297 |
-
'user_registered',
|
298 |
-
'display_name',
|
299 |
-
'first_name',
|
300 |
-
'last_name',
|
301 |
-
'nickname',
|
302 |
-
'description',
|
303 |
-
);
|
304 |
-
|
305 |
-
// Get the user data.
|
306 |
-
$user = get_userdata( $user_id );
|
307 |
-
|
308 |
-
// Get the email stored values.
|
309 |
-
$this->settings = get_option( 'wpmembers_email_notify' );
|
310 |
-
|
311 |
-
// Userdata for default shortcodes.
|
312 |
-
$this->settings['user_id'] = $user_id;
|
313 |
-
$this->settings['user_login'] = stripslashes( $user->user_login );
|
314 |
-
$this->settings['user_email'] = stripslashes( $user->user_email );
|
315 |
-
$this->settings['blogname'] = wp_specialchars_decode( get_option ( 'blogname' ), ENT_QUOTES );
|
316 |
-
$this->settings['user_ip'] = ( is_array( $field_data ) ) ? $field_data['wpmem_reg_ip'] : get_user_meta( $user_id, 'wpmem_reg_ip', true );
|
317 |
-
$this->settings['reg_link'] = esc_url( get_user_meta( $user_id, 'wpmem_reg_url', true ) );
|
318 |
-
$this->settings['act_link'] = esc_url( add_query_arg( 'user_id', $user_id, get_admin_url( '', 'user-edit.php' ) ) );
|
319 |
-
$this->settings['exp_type'] = ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) ? get_user_meta( $user_id, 'exp_type', true ) : '';
|
320 |
-
$this->settings['exp_date'] = ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) ? get_user_meta( $user_id, 'expires', true ) : '';
|
321 |
-
$this->settings['do_shortcodes'] = true;
|
322 |
-
$this->settings['add_footer'] = true;
|
323 |
-
$this->settings['footer'] = get_option( 'wpmembers_email_footer' );
|
324 |
-
$this->settings['disable'] = false;
|
325 |
-
|
326 |
-
// Builds an array of the user data fields.
|
327 |
-
$field_arr = array();
|
328 |
-
foreach ( $wpmem_fields as $meta_key => $field ) {
|
329 |
-
if ( $field['register'] ) {
|
330 |
-
if ( ! in_array( $meta_key, wpmem_get_excluded_meta( 'email' ) ) ) {
|
331 |
-
if ( ( 'user_email' != $meta_key ) && ( 'password' != $meta_key ) ) {
|
332 |
-
if ( 'user_url' == $meta_key ) {
|
333 |
-
$val = esc_url( $user->user_url );
|
334 |
-
} elseif ( in_array( $meta_key, $wp_user_fields ) ) {
|
335 |
-
$val = esc_html( $user->{$meta_key} );
|
336 |
-
} elseif ( 'file' == $field['type'] || 'image' == $field['type'] ) {
|
337 |
-
$val = wp_get_attachment_url( get_user_meta( $user_id, $meta_key, true ) );
|
338 |
-
} else {
|
339 |
-
$val = ( is_array( $field_data ) ) ? esc_html( $field_data[ $meta_key ] ) : esc_html( get_user_meta( $user_id, $meta_key, true ) );
|
340 |
-
}
|
341 |
-
// $field_arr[ $field['label'] ] = $val; // @todo Consider (1) if this should be implemented, and (2) if it should be done here or location "B".
|
342 |
-
$field_arr[ __( $field['label'], 'wp-members' ) ] = $val;
|
343 |
-
}
|
344 |
-
}
|
345 |
-
}
|
346 |
-
}
|
347 |
-
$this->settings['field_arr'] = $field_arr;
|
348 |
-
|
349 |
-
// Apply filters (if set) for the sending email address.
|
350 |
-
$default_header = ( $this->from && $this->from_name ) ? 'From: "' . $this->from_name . '" <' . $this->from . '>' : '';
|
351 |
-
|
352 |
-
/** This filter is documented in class-wp-members-email.php */
|
353 |
-
$this->settings['headers'] = apply_filters( 'wpmem_email_headers', $default_header, 'admin' );
|
354 |
-
|
355 |
-
/**
|
356 |
-
* Filters the address the admin notification is sent to.
|
357 |
-
*
|
358 |
-
* @since 2.7.5
|
359 |
-
*
|
360 |
-
* @param string The email address of the admin to send to.
|
361 |
-
*/
|
362 |
-
$this->settings['admin_email'] = apply_filters( 'wpmem_notify_addr', get_option( 'admin_email' ) );
|
363 |
-
|
364 |
-
/**
|
365 |
-
* Filter the email.
|
366 |
-
*
|
367 |
-
* This is a new and more powerful filter than was previously available for
|
368 |
-
* emails. This new filter passes the email subject, body, user ID, and several
|
369 |
-
* other settings and parameters for use in the filter function. It also passes
|
370 |
-
* an array of the WP-Members fields, and an array of the posted registration
|
371 |
-
* data from the register function.
|
372 |
-
*
|
373 |
-
* @since 2.9.8
|
374 |
-
*
|
375 |
-
* @param array $this->settings P
|
376 |
-
* An array containing email body, subject, user id, and additional settings.
|
377 |
-
*
|
378 |
-
* @type string $subj
|
379 |
-
* @type string $body
|
380 |
-
* @type integer $user_id
|
381 |
-
* @type string $user_login
|
382 |
-
* @type string $user_email
|
383 |
-
* @type string $blogname
|
384 |
-
* @type string $user_ip
|
385 |
-
* @type string $reg_link
|
386 |
-
* @type string $act_link
|
387 |
-
* @type string $exp_type
|
388 |
-
* @type string $exp_date
|
389 |
-
* @type boolean $do_shortcodes
|
390 |
-
* @type boolean $add_footer
|
391 |
-
* @type boolean $footer
|
392 |
-
* @type boolean $disable
|
393 |
-
* @type array $field_arr
|
394 |
-
* @type string $headers
|
395 |
-
* @type string $admin_email
|
396 |
-
* }
|
397 |
-
* @param array $wpmem_fields An array of the WP-Members fields.
|
398 |
-
* @param array $field_data An array of the posted registration data.
|
399 |
-
*/
|
400 |
-
$this->settings = apply_filters( 'wpmem_notify_filter', $this->settings, $wpmem_fields, $field_data );
|
401 |
-
|
402 |
-
// If emails are not disabled, continue the email process.
|
403 |
-
if ( ! $this->settings['disable'] ) {
|
404 |
-
|
405 |
-
// Split field_arr into field_str.
|
406 |
-
$field_str = '';
|
407 |
-
foreach ( $this->settings['field_arr'] as $key => $val ) {
|
408 |
-
$field_str.= $key . ': ' . $val . "\r\n";
|
409 |
-
// @todo Location "B" to to label translation. Could be as follows:
|
410 |
-
// $field_str.= __( $key, 'wp-members' ) . ": " . $val . "\r\n";
|
411 |
-
}
|
412 |
-
|
413 |
-
// Get the email footer if needed.
|
414 |
-
$foot = ( $this->settings['add_footer'] ) ? $this->settings['footer'] : '';
|
415 |
-
|
416 |
-
// If doing shortcode replacements.
|
417 |
-
if ( $this->settings['do_shortcodes'] ) {
|
418 |
-
|
419 |
-
$shortcodes = array(
|
420 |
-
'blogname' => $this->settings['blogname'],
|
421 |
-
'username' => $this->settings['user_login'],
|
422 |
-
'email' => $this->settings['user_email'],
|
423 |
-
'reglink' => $this->settings['reg_link'],
|
424 |
-
'exp-type' => $this->settings['exp_type'],
|
425 |
-
'exp-data' => $this->settings['exp_date'],
|
426 |
-
'exp-date' => $this->settings['exp_date'],
|
427 |
-
'user-ip' => $this->settings['user_ip'],
|
428 |
-
'activate-user' => $this->settings['act_link'],
|
429 |
-
'fields' => $field_str,
|
430 |
-
);
|
431 |
-
|
432 |
-
// Add custom field shortcodes.
|
433 |
-
foreach ( $wpmem_fields as $meta_key => $field ) {
|
434 |
-
$val = ( is_array( $field_data ) && $field['register'] ) ? $field_data[ $meta_key ] : get_user_meta( $user_id, $meta_key, true );
|
435 |
-
$shortcodes[ $meta_key ] = $val;
|
436 |
-
}
|
437 |
-
|
438 |
-
/**
|
439 |
-
* Filter available email shortcodes.
|
440 |
-
*
|
441 |
-
* @since 3.1.0
|
442 |
-
*
|
443 |
-
* @param array $shortcodes
|
444 |
-
* @param string $toggle
|
445 |
-
*/
|
446 |
-
$shortcodes = apply_filters( 'wpmem_email_shortcodes', $shortcodes, 'notify' );
|
447 |
-
|
448 |
-
$shortcd = array();
|
449 |
-
$replace = array();
|
450 |
-
foreach ( $shortcodes as $key => $val ) {
|
451 |
-
// Shortcodes.
|
452 |
-
$shortcd[] = '[' . $key . ']';
|
453 |
-
// Replacement values.
|
454 |
-
$replace[] = $val;
|
455 |
-
}
|
456 |
-
|
457 |
-
// Create the custom field shortcodes.
|
458 |
-
foreach ( $wpmem_fields as $meta_key => $field ) {
|
459 |
-
$shortcd[] = '[' . $meta_key . ']';
|
460 |
-
$replace[] = ( is_array( $field_data ) && $field['register'] ) ? $field_data[ $meta_key ] : get_user_meta( $user_id, $meta_key, true );
|
461 |
-
}
|
462 |
-
|
463 |
-
// Get the subject, body, and footer shortcodes.
|
464 |
-
$this->settings['subj'] = str_replace( $shortcd, $replace, $this->settings['subj'] );
|
465 |
-
$this->settings['body'] = str_replace( $shortcd, $replace, $this->settings['body'] );
|
466 |
-
$foot = ( $this->settings['add_footer'] ) ? str_replace( $shortcd, $replace, $foot ) : '';
|
467 |
-
}
|
468 |
-
|
469 |
-
// Append footer if needed.
|
470 |
-
$this->settings['body'] = ( $this->settings['add_footer'] ) ? $this->settings['body'] . "\r\n" . $foot : $this->settings['body'];
|
471 |
-
|
472 |
-
/**
|
473 |
-
* Filters the admin notification email.
|
474 |
-
*
|
475 |
-
* This is the last chance to filter the message body. At this point
|
476 |
-
* it is just the text that will be in the message.
|
477 |
-
* @todo Consider deprecating this filter as it could be accomplished
|
478 |
-
* by the wp_mail filter, or a universal filter could be added
|
479 |
-
* to the new email send function.
|
480 |
-
*
|
481 |
-
* @since 2.8.2
|
482 |
-
*
|
483 |
-
* @param string $this->settings['body'] The admin notification email body.
|
484 |
-
*/
|
485 |
-
$this->settings['body'] = apply_filters( 'wpmem_email_notify', $this->settings['body'] );
|
486 |
-
|
487 |
-
// Send the message.
|
488 |
-
$this->send( 'admin' );
|
489 |
-
}
|
490 |
-
}
|
491 |
-
|
492 |
-
/**
|
493 |
-
* Filters the wp_mail from address (if set).
|
494 |
-
*
|
495 |
-
* @since 2.7
|
496 |
-
* @since 3.1.0 Converted to use email var in object.
|
497 |
-
* @since 3.2.0 Moved to WP_Members_Email::from().
|
498 |
-
*
|
499 |
-
* @global object $wpmem
|
500 |
-
*
|
501 |
-
* @param string $email
|
502 |
-
* @return string $wpmem_mail_from|$email
|
503 |
-
*/
|
504 |
-
function from( $email ) {
|
505 |
-
global $wpmem;
|
506 |
-
return ( $this->from ) ? $this->from : $email;
|
507 |
-
}
|
508 |
-
|
509 |
-
/**
|
510 |
-
* Filters the wp_mail from name (if set).
|
511 |
-
*
|
512 |
-
* @since 2.7
|
513 |
-
* @since 3.1.0 Converted to use email var in object.
|
514 |
-
* @since 3.2.0 Moved to WP_Members_Email::from_name().
|
515 |
-
*
|
516 |
-
* @global object $wpmem
|
517 |
-
*
|
518 |
-
* @param string $name
|
519 |
-
* @return string $wpmem_mail_from_name|$name
|
520 |
-
*/
|
521 |
-
function from_name( $name ) {
|
522 |
-
global $wpmem;
|
523 |
-
return ( $this->from_name ) ? stripslashes( $this->from_name ) : stripslashes( $name );
|
524 |
-
}
|
525 |
-
|
526 |
-
/**
|
527 |
-
* Sends email.
|
528 |
-
*
|
529 |
-
* @since 3.2.0
|
530 |
-
*
|
531 |
-
* @param string $to
|
532 |
-
* @return bool $result
|
533 |
-
*/
|
534 |
-
function send( $to ) {
|
535 |
-
$args['to'] = ( 'user' == $to ) ? $this->settings['user_email'] : $this->settings['admin_email'];
|
536 |
-
$args['subject'] = $this->settings['subj'];
|
537 |
-
$args['message'] = $this->settings['body'];
|
538 |
-
$args['headers'] = $this->settings['headers'];
|
539 |
-
// @todo Add attachments to arguments and email send (and probably in the original function).
|
540 |
-
/**
|
541 |
-
* Filter email send arguments.
|
542 |
-
*
|
543 |
-
* @since 3.2.5
|
544 |
-
*
|
545 |
-
* @param array $send_args
|
546 |
-
* @param string $to
|
547 |
-
* @param array $this->settings
|
548 |
-
*/
|
549 |
-
$args = apply_filters( 'wpmem_email_send_args', $args, $to, $this->settings );
|
550 |
-
// Apply WP's "from" and "from name" email filters.
|
551 |
-
add_filter( 'wp_mail_from', array( $this, 'from' ) );
|
552 |
-
add_filter( 'wp_mail_from_name', array( $this, 'from_name' ) );
|
553 |
-
$result = wp_mail( $args['to'], stripslashes( $args['subject'] ), stripslashes( $args['message'] ), $args['headers'] );
|
554 |
-
return $result;
|
555 |
-
}
|
556 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The WP_Members Email Class.
|
4 |
+
*
|
5 |
+
* This class contains functions
|
6 |
+
* for the plugin's email functions.
|
7 |
+
*
|
8 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
9 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
10 |
+
* Copyright (c) 2006-2020 Chad Butler
|
11 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
12 |
+
*
|
13 |
+
* @package WP-Members
|
14 |
+
* @subpackage WP_Members_Shortcodes
|
15 |
+
* @author Chad Butler
|
16 |
+
* @copyright 2006-2020
|
17 |
+
*/
|
18 |
+
|
19 |
+
// Exit if accessed directly.
|
20 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
21 |
+
exit();
|
22 |
+
}
|
23 |
+
|
24 |
+
class WP_Members_Email {
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Container email from address.
|
28 |
+
*
|
29 |
+
* @since 3.2.0
|
30 |
+
* @access public
|
31 |
+
* @var string
|
32 |
+
*/
|
33 |
+
public $from;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Container for email from name.
|
37 |
+
*
|
38 |
+
* @since 3.2.0
|
39 |
+
* @access public
|
40 |
+
* @var string
|
41 |
+
*/
|
42 |
+
public $from_name;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Container for settings.
|
46 |
+
*
|
47 |
+
* @since 3.2.0
|
48 |
+
* @access public
|
49 |
+
* @var array
|
50 |
+
*/
|
51 |
+
public $settings;
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Load custom from address.
|
55 |
+
*
|
56 |
+
* @since 3.3.0
|
57 |
+
*/
|
58 |
+
function load_from() {
|
59 |
+
$this->from = get_option( 'wpmembers_email_wpfrom', '' );
|
60 |
+
$this->from_name = get_option( 'wpmembers_email_wpname', '' );
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Builds emails for the user.
|
65 |
+
*
|
66 |
+
* @since 1.8.0
|
67 |
+
* @since 2.7.4 Added wpmem_email_headers and individual body/subject filters.
|
68 |
+
* @since 2.9.7 Major overhaul, added wpmem_email_filter filter.
|
69 |
+
* @since 3.1.0 Can filter in custom shortcodes with wpmem_email_shortcodes.
|
70 |
+
* @since 3.1.1 Added $custom argument for custom emails.
|
71 |
+
* @since 3.2.0 Changed wpmem_msurl key to wpmem_profile.
|
72 |
+
* @since 3.2.0 Changed toggle key to tag.
|
73 |
+
* @since 3.2.0 Moved to WP_Members_Email::to_user().
|
74 |
+
*
|
75 |
+
* @global object $wpmem The WP_Members object.
|
76 |
+
* @global string $wpmem_mail_from The email from address.
|
77 |
+
* @global string $wpmem_mail_from_name The email from name.
|
78 |
+
*
|
79 |
+
* @param int $user_ID The User's ID.
|
80 |
+
* @param string $password Password from the registration process.
|
81 |
+
* @param string $tag Tag indicating the email being sent (newreg|newmod|appmod|repass|getuser).
|
82 |
+
* @param array $wpmem_fields Array of the WP-Members fields (defaults to null).
|
83 |
+
* @param array $fields Array of the registration data (defaults to null).
|
84 |
+
* @param array $custom Array of custom email information (defaults to null).
|
85 |
+
*/
|
86 |
+
function to_user( $user_id, $password, $tag, $wpmem_fields = null, $field_data = null, $custom = null ) {
|
87 |
+
|
88 |
+
global $wpmem;
|
89 |
+
|
90 |
+
// Load from address.
|
91 |
+
$this->load_from();
|
92 |
+
|
93 |
+
// Handle backward compatibility for customizations that may call the email function directly.
|
94 |
+
$wpmem_fields = wpmem_fields();
|
95 |
+
|
96 |
+
//Determine email to be sent. Stored option is an array with keys 'body' and 'subj'.
|
97 |
+
$tag_array = array( 'newreg', 'newmod', 'appmod', 'repass', 'getuser' );
|
98 |
+
switch ( $tag ) {
|
99 |
+
case 0:
|
100 |
+
case 1:
|
101 |
+
case 2:
|
102 |
+
case 3:
|
103 |
+
case 4:
|
104 |
+
$tag = $tag_array[ $tag ];
|
105 |
+
$this->settings = get_option( 'wpmembers_email_' . $tag );
|
106 |
+
$this->settings['tag'] = $tag;
|
107 |
+
break;
|
108 |
+
default: // case 5:
|
109 |
+
// This is a custom email.
|
110 |
+
$this->settings['subj'] = $custom['subj'];
|
111 |
+
$this->settings['body'] = $custom['body'];
|
112 |
+
$this->settings['tag'] = ( isset( $custom['tag'] ) ) ? $custom['tag'] : '';
|
113 |
+
break;
|
114 |
+
}
|
115 |
+
|
116 |
+
// Get the user ID.
|
117 |
+
$user = new WP_User( $user_id );
|
118 |
+
|
119 |
+
// Userdata for default shortcodes.
|
120 |
+
$this->settings['user_id'] = $user_id;
|
121 |
+
$this->settings['user_login'] = stripslashes( $user->user_login );
|
122 |
+
$this->settings['user_email'] = stripslashes( $user->user_email );
|
123 |
+
$this->settings['blogname'] = wp_specialchars_decode( get_option ( 'blogname' ), ENT_QUOTES );
|
124 |
+
$this->settings['exp_type'] = ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) ? get_user_meta( $user_id, 'exp_type', true ) : '';
|
125 |
+
$this->settings['exp_date'] = ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) ? get_user_meta( $user_id, 'expires', true ) : '';
|
126 |
+
$this->settings['wpmem_profile'] = esc_url( $wpmem->user_pages['profile'] );
|
127 |
+
$this->settings['wpmem_reg'] = esc_url( $wpmem->user_pages['register'] );
|
128 |
+
$this->settings['wpmem_login'] = esc_url( $wpmem->user_pages['login'] );
|
129 |
+
$this->settings['reg_link'] = esc_url( get_user_meta( $user_id, 'wpmem_reg_url', true ) );
|
130 |
+
$this->settings['do_shortcodes'] = true;
|
131 |
+
$this->settings['add_footer'] = true;
|
132 |
+
$this->settings['footer'] = get_option( 'wpmembers_email_footer' );
|
133 |
+
$this->settings['disable'] = false;
|
134 |
+
$this->settings['toggle'] = $this->settings['tag']; // Deprecated since 3.2.0, but remains in the array for legacy reasons.
|
135 |
+
$this->settings['reset_link'] = esc_url_raw( add_query_arg( array( 'a' => 'pwdreset', 'key' => $password, 'id' => $user_id ), wpmem_profile_url() ) );
|
136 |
+
|
137 |
+
// Apply filters (if set) for the sending email address.
|
138 |
+
$default_header = ( $this->from && $this->from_name ) ? 'From: "' . $this->from_name . '" <' . $this->from . '>' : '';
|
139 |
+
|
140 |
+
/**
|
141 |
+
* Filters the email headers.
|
142 |
+
*
|
143 |
+
* @since 2.7.4
|
144 |
+
* @since 3.2.0 Changed toggle to tag.
|
145 |
+
*
|
146 |
+
* @param mixed $default_header The email headers.
|
147 |
+
* @param string $this->settings['tag'] Tag to determine what email is being generated (newreg|newmod|appmod|repass|admin).
|
148 |
+
*/
|
149 |
+
$this->settings['headers'] = apply_filters( 'wpmem_email_headers', $default_header, $this->settings['tag'] );
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Filter the email.
|
153 |
+
*
|
154 |
+
* This filter passes the email subject, body, user ID, and several other
|
155 |
+
* settings and parameters for use in the filter function. It also passes an
|
156 |
+
* array of the WP-Members fields, and an array of the posted registration
|
157 |
+
* data from the register function.
|
158 |
+
*
|
159 |
+
* @since 2.9.7
|
160 |
+
* @since 3.1.0 Added footer content to the array.
|
161 |
+
* @since 3.2.0 Changed wpmem_msurl key to wpmem_profile.
|
162 |
+
* @since 3.2.0 Change toggle to tag.
|
163 |
+
*
|
164 |
+
* @param array $this->settings {
|
165 |
+
* An array containing email body, subject, user id, and additional settings.
|
166 |
+
*
|
167 |
+
* @type string subj
|
168 |
+
* @type string body
|
169 |
+
* @type string tag
|
170 |
+
* @type int user_id
|
171 |
+
* @type string user_login
|
172 |
+
* @type string user_email
|
173 |
+
* @type string blogname
|
174 |
+
* @type string exp_type
|
175 |
+
* @type string exp_date
|
176 |
+
* @type string wpmem_profile
|
177 |
+
* @type string reg_link
|
178 |
+
* @type string do_shortcodes
|
179 |
+
* @type bool add_footer
|
180 |
+
* @type string footer
|
181 |
+
* @type bool disable
|
182 |
+
* @type mixed headers
|
183 |
+
* @type string toggle Deprecated since 3.2.0
|
184 |
+
* }
|
185 |
+
* @param array $wpmem_fields An array of the WP-Members fields.
|
186 |
+
* @param array $field_data An array of the posted registration data.
|
187 |
+
*/
|
188 |
+
$this->settings = apply_filters( 'wpmem_email_filter', $this->settings, $wpmem_fields, $field_data );
|
189 |
+
|
190 |
+
// If emails are not disabled, continue the email process.
|
191 |
+
if ( ! $this->settings['disable'] ) {
|
192 |
+
|
193 |
+
/**
|
194 |
+
* Filters the email body based on tag.
|
195 |
+
*
|
196 |
+
* @since 2.7.4
|
197 |
+
* @deprecated 3.2.0 Use wpmem_email_filter instead.
|
198 |
+
*
|
199 |
+
* @param string $this->settings['body'] The body content of the new registration email.
|
200 |
+
*/
|
201 |
+
$this->settings['body'] = apply_filters( 'wpmem_email_' . $this->settings['tag'], $this->settings['body'] );
|
202 |
+
|
203 |
+
// Get the email footer if needed.
|
204 |
+
$foot = ( $this->settings['add_footer'] ) ? $this->settings['footer'] : '';
|
205 |
+
|
206 |
+
// If doing shortcode replacements.
|
207 |
+
if ( $this->settings['do_shortcodes'] ) {
|
208 |
+
|
209 |
+
$shortcodes = array(
|
210 |
+
'blogname' => $this->settings['blogname'],
|
211 |
+
'username' => $this->settings['user_login'],
|
212 |
+
'password' => $password,
|
213 |
+
'email' => $this->settings['user_email'],
|
214 |
+
'reglink' => $this->settings['reg_link'],
|
215 |
+
'members-area' => $this->settings['wpmem_profile'],
|
216 |
+
'user-profile' => $this->settings['wpmem_profile'],
|
217 |
+
'exp-type' => $this->settings['exp_type'],
|
218 |
+
'exp-data' => $this->settings['exp_date'],
|
219 |
+
'exp-date' => $this->settings['exp_date'],
|
220 |
+
'login' => $this->settings['wpmem_login'],
|
221 |
+
'register' => $this->settings['wpmem_reg'],
|
222 |
+
'reset_link' => $this->settings['reset_link'],
|
223 |
+
);
|
224 |
+
|
225 |
+
// Add custom field shortcodes.
|
226 |
+
foreach ( $wpmem_fields as $meta_key => $field ) {
|
227 |
+
if ( ! array_key_exists( $meta_key, $shortcodes ) ) {
|
228 |
+
$val = ( is_array( $field_data ) && $field['register'] ) ? $field_data[ $meta_key ] : get_user_meta( $user_id, $meta_key, true );
|
229 |
+
$shortcodes[ $meta_key ] = $val;
|
230 |
+
}
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Filter available email shortcodes.
|
235 |
+
*
|
236 |
+
* @since 3.1.0
|
237 |
+
*
|
238 |
+
* @param array $shortcodes
|
239 |
+
* @param string $tag
|
240 |
+
*/
|
241 |
+
$shortcodes = apply_filters( 'wpmem_email_shortcodes', $shortcodes, $this->settings['tag'] );
|
242 |
+
|
243 |
+
$shortcd = array();
|
244 |
+
$replace = array();
|
245 |
+
foreach ( $shortcodes as $key => $val ) {
|
246 |
+
// Shortcodes.
|
247 |
+
$shortcd[] = '[' . $key . ']';
|
248 |
+
// Replacement values.
|
249 |
+
$replace[] = ( 'password' == $key ) ? $password : $val;
|
250 |
+
}
|
251 |
+
|
252 |
+
// Do replacements for subject, body, and footer shortcodes.
|
253 |
+
$this->settings['subj'] = str_replace( $shortcd, $replace, $this->settings['subj'] );
|
254 |
+
$this->settings['body'] = str_replace( $shortcd, $replace, $this->settings['body'] );
|
255 |
+
$foot = ( $this->settings['add_footer'] ) ? str_replace( $shortcd, $replace, $foot ) : '';
|
256 |
+
}
|
257 |
+
|
258 |
+
// Append footer if needed.
|
259 |
+
$this->settings['body'] = ( $this->settings['add_footer'] ) ? $this->settings['body'] . "\r\n" . $foot : $this->settings['body'];
|
260 |
+
|
261 |
+
// Send message.
|
262 |
+
$this->send( 'user' );
|
263 |
+
|
264 |
+
}
|
265 |
+
return;
|
266 |
+
}
|
267 |
+
|
268 |
+
/**
|
269 |
+
* Builds the email for admin notification of new user registration.
|
270 |
+
*
|
271 |
+
* @since 2.3
|
272 |
+
* @since 3.2.0 Moved to WP_Members_Email::notify_admin().
|
273 |
+
*
|
274 |
+
* @global object $wpmem The WP_Members object.
|
275 |
+
* @global string $wpmem_mail_from The email from address.
|
276 |
+
* @global string $wpmem_mail_from_name The email from name.
|
277 |
+
*
|
278 |
+
* @param int $user_id The User's ID.
|
279 |
+
* @param array $wpmem_fields Array of the WP-Members fields (defaults to null).
|
280 |
+
* @param array $field_data Array of the registration data (defaults to null).
|
281 |
+
*/
|
282 |
+
function notify_admin( $user_id, $wpmem_fields = null, $field_data = null ) {
|
283 |
+
|
284 |
+
global $wpmem;
|
285 |
+
|
286 |
+
// Load from address.
|
287 |
+
$this->load_from();
|
288 |
+
|
289 |
+
// Handle backward compatibility for customizations that may call the email function directly.
|
290 |
+
$wpmem_fields = wpmem_fields( 'admin_notify' );
|
291 |
+
|
292 |
+
// WP default user fields.
|
293 |
+
$wp_user_fields = array(
|
294 |
+
'user_login',
|
295 |
+
'user_nicename',
|
296 |
+
'user_url',
|
297 |
+
'user_registered',
|
298 |
+
'display_name',
|
299 |
+
'first_name',
|
300 |
+
'last_name',
|
301 |
+
'nickname',
|
302 |
+
'description',
|
303 |
+
);
|
304 |
+
|
305 |
+
// Get the user data.
|
306 |
+
$user = get_userdata( $user_id );
|
307 |
+
|
308 |
+
// Get the email stored values.
|
309 |
+
$this->settings = get_option( 'wpmembers_email_notify' );
|
310 |
+
|
311 |
+
// Userdata for default shortcodes.
|
312 |
+
$this->settings['user_id'] = $user_id;
|
313 |
+
$this->settings['user_login'] = stripslashes( $user->user_login );
|
314 |
+
$this->settings['user_email'] = stripslashes( $user->user_email );
|
315 |
+
$this->settings['blogname'] = wp_specialchars_decode( get_option ( 'blogname' ), ENT_QUOTES );
|
316 |
+
$this->settings['user_ip'] = ( is_array( $field_data ) ) ? $field_data['wpmem_reg_ip'] : get_user_meta( $user_id, 'wpmem_reg_ip', true );
|
317 |
+
$this->settings['reg_link'] = esc_url( get_user_meta( $user_id, 'wpmem_reg_url', true ) );
|
318 |
+
$this->settings['act_link'] = esc_url( add_query_arg( 'user_id', $user_id, get_admin_url( '', 'user-edit.php' ) ) );
|
319 |
+
$this->settings['exp_type'] = ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) ? get_user_meta( $user_id, 'exp_type', true ) : '';
|
320 |
+
$this->settings['exp_date'] = ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) ? get_user_meta( $user_id, 'expires', true ) : '';
|
321 |
+
$this->settings['do_shortcodes'] = true;
|
322 |
+
$this->settings['add_footer'] = true;
|
323 |
+
$this->settings['footer'] = get_option( 'wpmembers_email_footer' );
|
324 |
+
$this->settings['disable'] = false;
|
325 |
+
|
326 |
+
// Builds an array of the user data fields.
|
327 |
+
$field_arr = array();
|
328 |
+
foreach ( $wpmem_fields as $meta_key => $field ) {
|
329 |
+
if ( $field['register'] ) {
|
330 |
+
if ( ! in_array( $meta_key, wpmem_get_excluded_meta( 'email' ) ) ) {
|
331 |
+
if ( ( 'user_email' != $meta_key ) && ( 'password' != $meta_key ) ) {
|
332 |
+
if ( 'user_url' == $meta_key ) {
|
333 |
+
$val = esc_url( $user->user_url );
|
334 |
+
} elseif ( in_array( $meta_key, $wp_user_fields ) ) {
|
335 |
+
$val = esc_html( $user->{$meta_key} );
|
336 |
+
} elseif ( 'file' == $field['type'] || 'image' == $field['type'] ) {
|
337 |
+
$val = wp_get_attachment_url( get_user_meta( $user_id, $meta_key, true ) );
|
338 |
+
} else {
|
339 |
+
$val = ( is_array( $field_data ) ) ? esc_html( $field_data[ $meta_key ] ) : esc_html( get_user_meta( $user_id, $meta_key, true ) );
|
340 |
+
}
|
341 |
+
// $field_arr[ $field['label'] ] = $val; // @todo Consider (1) if this should be implemented, and (2) if it should be done here or location "B".
|
342 |
+
$field_arr[ __( $field['label'], 'wp-members' ) ] = $val;
|
343 |
+
}
|
344 |
+
}
|
345 |
+
}
|
346 |
+
}
|
347 |
+
$this->settings['field_arr'] = $field_arr;
|
348 |
+
|
349 |
+
// Apply filters (if set) for the sending email address.
|
350 |
+
$default_header = ( $this->from && $this->from_name ) ? 'From: "' . $this->from_name . '" <' . $this->from . '>' : '';
|
351 |
+
|
352 |
+
/** This filter is documented in class-wp-members-email.php */
|
353 |
+
$this->settings['headers'] = apply_filters( 'wpmem_email_headers', $default_header, 'admin' );
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Filters the address the admin notification is sent to.
|
357 |
+
*
|
358 |
+
* @since 2.7.5
|
359 |
+
*
|
360 |
+
* @param string The email address of the admin to send to.
|
361 |
+
*/
|
362 |
+
$this->settings['admin_email'] = apply_filters( 'wpmem_notify_addr', get_option( 'admin_email' ) );
|
363 |
+
|
364 |
+
/**
|
365 |
+
* Filter the email.
|
366 |
+
*
|
367 |
+
* This is a new and more powerful filter than was previously available for
|
368 |
+
* emails. This new filter passes the email subject, body, user ID, and several
|
369 |
+
* other settings and parameters for use in the filter function. It also passes
|
370 |
+
* an array of the WP-Members fields, and an array of the posted registration
|
371 |
+
* data from the register function.
|
372 |
+
*
|
373 |
+
* @since 2.9.8
|
374 |
+
*
|
375 |
+
* @param array $this->settings P
|
376 |
+
* An array containing email body, subject, user id, and additional settings.
|
377 |
+
*
|
378 |
+
* @type string $subj
|
379 |
+
* @type string $body
|
380 |
+
* @type integer $user_id
|
381 |
+
* @type string $user_login
|
382 |
+
* @type string $user_email
|
383 |
+
* @type string $blogname
|
384 |
+
* @type string $user_ip
|
385 |
+
* @type string $reg_link
|
386 |
+
* @type string $act_link
|
387 |
+
* @type string $exp_type
|
388 |
+
* @type string $exp_date
|
389 |
+
* @type boolean $do_shortcodes
|
390 |
+
* @type boolean $add_footer
|
391 |
+
* @type boolean $footer
|
392 |
+
* @type boolean $disable
|
393 |
+
* @type array $field_arr
|
394 |
+
* @type string $headers
|
395 |
+
* @type string $admin_email
|
396 |
+
* }
|
397 |
+
* @param array $wpmem_fields An array of the WP-Members fields.
|
398 |
+
* @param array $field_data An array of the posted registration data.
|
399 |
+
*/
|
400 |
+
$this->settings = apply_filters( 'wpmem_notify_filter', $this->settings, $wpmem_fields, $field_data );
|
401 |
+
|
402 |
+
// If emails are not disabled, continue the email process.
|
403 |
+
if ( ! $this->settings['disable'] ) {
|
404 |
+
|
405 |
+
// Split field_arr into field_str.
|
406 |
+
$field_str = '';
|
407 |
+
foreach ( $this->settings['field_arr'] as $key => $val ) {
|
408 |
+
$field_str.= $key . ': ' . $val . "\r\n";
|
409 |
+
// @todo Location "B" to to label translation. Could be as follows:
|
410 |
+
// $field_str.= __( $key, 'wp-members' ) . ": " . $val . "\r\n";
|
411 |
+
}
|
412 |
+
|
413 |
+
// Get the email footer if needed.
|
414 |
+
$foot = ( $this->settings['add_footer'] ) ? $this->settings['footer'] : '';
|
415 |
+
|
416 |
+
// If doing shortcode replacements.
|
417 |
+
if ( $this->settings['do_shortcodes'] ) {
|
418 |
+
|
419 |
+
$shortcodes = array(
|
420 |
+
'blogname' => $this->settings['blogname'],
|
421 |
+
'username' => $this->settings['user_login'],
|
422 |
+
'email' => $this->settings['user_email'],
|
423 |
+
'reglink' => $this->settings['reg_link'],
|
424 |
+
'exp-type' => $this->settings['exp_type'],
|
425 |
+
'exp-data' => $this->settings['exp_date'],
|
426 |
+
'exp-date' => $this->settings['exp_date'],
|
427 |
+
'user-ip' => $this->settings['user_ip'],
|
428 |
+
'activate-user' => $this->settings['act_link'],
|
429 |
+
'fields' => $field_str,
|
430 |
+
);
|
431 |
+
|
432 |
+
// Add custom field shortcodes.
|
433 |
+
foreach ( $wpmem_fields as $meta_key => $field ) {
|
434 |
+
$val = ( is_array( $field_data ) && $field['register'] ) ? $field_data[ $meta_key ] : get_user_meta( $user_id, $meta_key, true );
|
435 |
+
$shortcodes[ $meta_key ] = $val;
|
436 |
+
}
|
437 |
+
|
438 |
+
/**
|
439 |
+
* Filter available email shortcodes.
|
440 |
+
*
|
441 |
+
* @since 3.1.0
|
442 |
+
*
|
443 |
+
* @param array $shortcodes
|
444 |
+
* @param string $toggle
|
445 |
+
*/
|
446 |
+
$shortcodes = apply_filters( 'wpmem_email_shortcodes', $shortcodes, 'notify' );
|
447 |
+
|
448 |
+
$shortcd = array();
|
449 |
+
$replace = array();
|
450 |
+
foreach ( $shortcodes as $key => $val ) {
|
451 |
+
// Shortcodes.
|
452 |
+
$shortcd[] = '[' . $key . ']';
|
453 |
+
// Replacement values.
|
454 |
+
$replace[] = $val;
|
455 |
+
}
|
456 |
+
|
457 |
+
// Create the custom field shortcodes.
|
458 |
+
foreach ( $wpmem_fields as $meta_key => $field ) {
|
459 |
+
$shortcd[] = '[' . $meta_key . ']';
|
460 |
+
$replace[] = ( is_array( $field_data ) && $field['register'] ) ? $field_data[ $meta_key ] : get_user_meta( $user_id, $meta_key, true );
|
461 |
+
}
|
462 |
+
|
463 |
+
// Get the subject, body, and footer shortcodes.
|
464 |
+
$this->settings['subj'] = str_replace( $shortcd, $replace, $this->settings['subj'] );
|
465 |
+
$this->settings['body'] = str_replace( $shortcd, $replace, $this->settings['body'] );
|
466 |
+
$foot = ( $this->settings['add_footer'] ) ? str_replace( $shortcd, $replace, $foot ) : '';
|
467 |
+
}
|
468 |
+
|
469 |
+
// Append footer if needed.
|
470 |
+
$this->settings['body'] = ( $this->settings['add_footer'] ) ? $this->settings['body'] . "\r\n" . $foot : $this->settings['body'];
|
471 |
+
|
472 |
+
/**
|
473 |
+
* Filters the admin notification email.
|
474 |
+
*
|
475 |
+
* This is the last chance to filter the message body. At this point
|
476 |
+
* it is just the text that will be in the message.
|
477 |
+
* @todo Consider deprecating this filter as it could be accomplished
|
478 |
+
* by the wp_mail filter, or a universal filter could be added
|
479 |
+
* to the new email send function.
|
480 |
+
*
|
481 |
+
* @since 2.8.2
|
482 |
+
*
|
483 |
+
* @param string $this->settings['body'] The admin notification email body.
|
484 |
+
*/
|
485 |
+
$this->settings['body'] = apply_filters( 'wpmem_email_notify', $this->settings['body'] );
|
486 |
+
|
487 |
+
// Send the message.
|
488 |
+
$this->send( 'admin' );
|
489 |
+
}
|
490 |
+
}
|
491 |
+
|
492 |
+
/**
|
493 |
+
* Filters the wp_mail from address (if set).
|
494 |
+
*
|
495 |
+
* @since 2.7
|
496 |
+
* @since 3.1.0 Converted to use email var in object.
|
497 |
+
* @since 3.2.0 Moved to WP_Members_Email::from().
|
498 |
+
*
|
499 |
+
* @global object $wpmem
|
500 |
+
*
|
501 |
+
* @param string $email
|
502 |
+
* @return string $wpmem_mail_from|$email
|
503 |
+
*/
|
504 |
+
function from( $email ) {
|
505 |
+
global $wpmem;
|
506 |
+
return ( $this->from ) ? $this->from : $email;
|
507 |
+
}
|
508 |
+
|
509 |
+
/**
|
510 |
+
* Filters the wp_mail from name (if set).
|
511 |
+
*
|
512 |
+
* @since 2.7
|
513 |
+
* @since 3.1.0 Converted to use email var in object.
|
514 |
+
* @since 3.2.0 Moved to WP_Members_Email::from_name().
|
515 |
+
*
|
516 |
+
* @global object $wpmem
|
517 |
+
*
|
518 |
+
* @param string $name
|
519 |
+
* @return string $wpmem_mail_from_name|$name
|
520 |
+
*/
|
521 |
+
function from_name( $name ) {
|
522 |
+
global $wpmem;
|
523 |
+
return ( $this->from_name ) ? stripslashes( $this->from_name ) : stripslashes( $name );
|
524 |
+
}
|
525 |
+
|
526 |
+
/**
|
527 |
+
* Sends email.
|
528 |
+
*
|
529 |
+
* @since 3.2.0
|
530 |
+
*
|
531 |
+
* @param string $to
|
532 |
+
* @return bool $result
|
533 |
+
*/
|
534 |
+
function send( $to ) {
|
535 |
+
$args['to'] = ( 'user' == $to ) ? $this->settings['user_email'] : $this->settings['admin_email'];
|
536 |
+
$args['subject'] = $this->settings['subj'];
|
537 |
+
$args['message'] = $this->settings['body'];
|
538 |
+
$args['headers'] = $this->settings['headers'];
|
539 |
+
// @todo Add attachments to arguments and email send (and probably in the original function).
|
540 |
+
/**
|
541 |
+
* Filter email send arguments.
|
542 |
+
*
|
543 |
+
* @since 3.2.5
|
544 |
+
*
|
545 |
+
* @param array $send_args
|
546 |
+
* @param string $to
|
547 |
+
* @param array $this->settings
|
548 |
+
*/
|
549 |
+
$args = apply_filters( 'wpmem_email_send_args', $args, $to, $this->settings );
|
550 |
+
// Apply WP's "from" and "from name" email filters.
|
551 |
+
add_filter( 'wp_mail_from', array( $this, 'from' ) );
|
552 |
+
add_filter( 'wp_mail_from_name', array( $this, 'from_name' ) );
|
553 |
+
$result = wp_mail( $args['to'], stripslashes( $args['subject'] ), stripslashes( $args['message'] ), $args['headers'] );
|
554 |
+
return $result;
|
555 |
+
}
|
556 |
}
|
includes/class-wp-members-forms.php
CHANGED
@@ -1,2060 +1,2069 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* The WP_Members Forms Class.
|
4 |
-
*
|
5 |
-
* @package WP-Members
|
6 |
-
* @subpackage WP_Members Forms Object Class
|
7 |
-
* @since 3.1.0
|
8 |
-
*/
|
9 |
-
|
10 |
-
// Exit if accessed directly.
|
11 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
12 |
-
exit();
|
13 |
-
}
|
14 |
-
|
15 |
-
class WP_Members_Forms {
|
16 |
-
|
17 |
-
/**
|
18 |
-
* Plugin initialization function.
|
19 |
-
*
|
20 |
-
* @since 3.1.0
|
21 |
-
*/
|
22 |
-
function __construct() {
|
23 |
-
|
24 |
-
}
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Creates form fields
|
28 |
-
*
|
29 |
-
* Creates various form fields and returns them as a string.
|
30 |
-
*
|
31 |
-
* @since 3.1.0
|
32 |
-
* @since 3.1.1 Added $delimiter.
|
33 |
-
* @since 3.1.2 Changed $valtochk to $compare.
|
34 |
-
* @since 3.1.6 Added $placeholder.
|
35 |
-
* @since 3.1.7 Added number type & $min, $max, $title and $pattern attributes.
|
36 |
-
* @since 3.2.0 Added $id argument.
|
37 |
-
* @since 3.2.4 Added radio group and multiple checkbox individual item labels.
|
38 |
-
*
|
39 |
-
* @global object $wpmem The WP_Members object class.
|
40 |
-
* @param array $args {
|
41 |
-
* @type string $id
|
42 |
-
* @type string $name
|
43 |
-
* @type string $type
|
44 |
-
* @type string $value
|
45 |
-
* @type string $compare
|
46 |
-
* @type string $class
|
47 |
-
* @type boolean $required
|
48 |
-
* @type string $delimiter
|
49 |
-
* @type string $placeholder
|
50 |
-
* @type string $pattern
|
51 |
-
* @type string $title
|
52 |
-
* @type string $min
|
53 |
-
* @type string $max
|
54 |
-
* @type string $rows Number of rows for a textarea (default:5).
|
55 |
-
* @type string $cols Number of columns for a textarea (default:20).
|
56 |
-
* }
|
57 |
-
* @return string $str The field returned as a string.
|
58 |
-
*/
|
59 |
-
function create_form_field( $args ) {
|
60 |
-
|
61 |
-
global $wpmem;
|
62 |
-
|
63 |
-
// Set defaults for most possible $args.
|
64 |
-
$id = ( isset( $args['id'] ) ) ? esc_attr( $args['id'] ) : esc_attr( $args['name'] );
|
65 |
-
$name = esc_attr( $args['name'] );
|
66 |
-
$type = esc_attr( $args['type'] );
|
67 |
-
$value = ( isset( $args['value'] ) ) ? $args['value'] : '';
|
68 |
-
$compare = ( isset( $args['compare'] ) ) ? $args['compare'] : '';
|
69 |
-
$class = ( isset( $args['class'] ) ) ? $args['class'] : 'textbox';
|
70 |
-
$required = ( isset( $args['required'] ) ) ? $args['required'] : false;
|
71 |
-
$delimiter = ( isset( $args['delimiter'] ) ) ? $args['delimiter'] : '|';
|
72 |
-
$placeholder = ( isset( $args['placeholder'] ) ) ? $args['placeholder'] : false;
|
73 |
-
$pattern = ( isset( $args['pattern'] ) ) ? $args['pattern'] : false;
|
74 |
-
$title = ( isset( $args['title'] ) ) ? $args['title'] : false;
|
75 |
-
$file_types = ( isset( $args['file_types'] ) ) ? $args['file_types'] : false;
|
76 |
-
|
77 |
-
// Handle field creation by type.
|
78 |
-
switch ( $type ) {
|
79 |
-
|
80 |
-
/*
|
81 |
-
* Field types text|url|email|number|date are all handled essentially the
|
82 |
-
* same. The primary differences are CSS class (with a default fallback
|
83 |
-
* of 'textbox'), how values are escaped, and the application of min|max
|
84 |
-
* values for number fields.
|
85 |
-
*/
|
86 |
-
case "text":
|
87 |
-
case "url":
|
88 |
-
case "email":
|
89 |
-
case "number":
|
90 |
-
case "date":
|
91 |
-
$class = ( 'textbox' == $class ) ? "textbox" : $this->sanitize_class( $class );
|
92 |
-
switch ( $type ) {
|
93 |
-
case 'url':
|
94 |
-
$value = esc_url( $value );
|
95 |
-
break;
|
96 |
-
case 'email':
|
97 |
-
$value = esc_attr( wp_unslash( $value ) );
|
98 |
-
break;
|
99 |
-
default:
|
100 |
-
$value = stripslashes( esc_attr( $value ) ); // @todo Could email and default be combined? Both seem to unslash and esc_attr().
|
101 |
-
break;
|
102 |
-
}
|
103 |
-
$required = ( $required ) ? ' required' : '';
|
104 |
-
$placeholder = ( $placeholder ) ? ' placeholder="' . esc_attr( __( $placeholder, 'wp-members' ) ) . '"' : '';
|
105 |
-
$pattern = ( $pattern ) ? ' pattern="' . esc_attr( $pattern ) . '"' : '';
|
106 |
-
$title = ( $title ) ? ' title="' . esc_attr( __( $title, 'wp-members' ) ) . '"' : '';
|
107 |
-
$min = ( isset( $args['min'] ) && $args['min'] != '' ) ? ' min="' . esc_attr( $args['min'] ) . '"' : '';
|
108 |
-
$max = ( isset( $args['max'] ) && $args['max'] != '' ) ? ' max="' . esc_attr( $args['max'] ). '"' : '';
|
109 |
-
$str = "<input name=\"$name\" type=\"$type\" id=\"$id\" value=\"$value\" class=\"$class\"$placeholder$title$pattern$min$max" . ( ( $required ) ? " required " : "" ) . " />";
|
110 |
-
break;
|
111 |
-
|
112 |
-
case "password":
|
113 |
-
$class = $this->sanitize_class( $class );
|
114 |
-
$placeholder = ( $placeholder ) ? ' placeholder="' . esc_attr( __( $placeholder, 'wp-members' ) ) . '"' : '';
|
115 |
-
$pattern = ( $pattern ) ? ' pattern="' . esc_attr( $pattern ) . '"' : '';
|
116 |
-
$title = ( $title ) ? ' title="' . esc_attr( __( $title, 'wp-members' ) ) . '"' : '';
|
117 |
-
$str = "<input name=\"$name\" type=\"$type\" id=\"$id\" class=\"$class\"$placeholder$title$pattern" . ( ( $required ) ? " required " : "" ) . " />";
|
118 |
-
break;
|
119 |
-
|
120 |
-
case "image":
|
121 |
-
case "file":
|
122 |
-
if ( $file_types ) {
|
123 |
-
$file_types = explode( '|', $file_types );
|
124 |
-
foreach( $file_types as $file_type ) {
|
125 |
-
$array[] = "." . $file_type;
|
126 |
-
}
|
127 |
-
$accept = ' accept="' . implode( ",", $array ) . '"';
|
128 |
-
} else {
|
129 |
-
$accept = '';
|
130 |
-
}
|
131 |
-
$class = ( 'textbox' == $class ) ? "file" : $this->sanitize_class( $class );
|
132 |
-
$str = "<input name=\"$name\" type=\"file\" id=\"$id\" value=\"" . esc_attr( $value ) . "\" class=\"$class\"$accept" . ( ( $required ) ? " required " : "" ) . " />";
|
133 |
-
break;
|
134 |
-
|
135 |
-
case "checkbox":
|
136 |
-
$class = ( 'textbox' == $class ) ? "checkbox" : $this->sanitize_class( $class );
|
137 |
-
$str = "<input name=\"$name\" type=\"$type\" id=\"$id\" value=\"" . esc_attr( $value ) . "\"" . checked( $value, $compare, false ) . ( ( $required ) ? " required " : "" ) . " />";
|
138 |
-
break;
|
139 |
-
|
140 |
-
case "textarea":
|
141 |
-
$value = esc_textarea( stripslashes( $value ) ); // stripslashes( esc_textarea( $value ) );
|
142 |
-
$class = ( 'textbox' == $class ) ? "textarea" : $this->sanitize_class( $class );
|
143 |
-
$placeholder = ( $placeholder ) ? ' placeholder="' . esc_attr( __( $placeholder, 'wp-members' ) ) . '"' : '';
|
144 |
-
$rows = ( isset( $args['rows'] ) && $args['rows'] ) ? esc_attr( $args['rows'] ) : '5';
|
145 |
-
$cols = ( isset( $args['cols'] ) && $args['cols'] ) ? esc_attr( $args['cols'] ) : '20';
|
146 |
-
$str = "<textarea cols=\"$cols\" rows=\"$rows\" name=\"$name\" id=\"$id\" class=\"$class\"$placeholder" . ( ( $required ) ? " required " : "" ) . ">$value</textarea>";
|
147 |
-
break;
|
148 |
-
|
149 |
-
case "hidden":
|
150 |
-
$str = "<input name=\"$name\" type=\"$type\" value=\"" . esc_attr( $value ) . "\" />";
|
151 |
-
break;
|
152 |
-
|
153 |
-
case "option":
|
154 |
-
$str = "<option value=\"" . esc_attr( $value ) . "\" " . selected( $value, $compare, false ) . " >" . __( $name, 'wp-members' ) . "</option>";
|
155 |
-
break;
|
156 |
-
|
157 |
-
case "select":
|
158 |
-
case "multiselect":
|
159 |
-
case "membership":
|
160 |
-
$class = ( 'textbox' == $class && 'multiselect' != $type ) ? "dropdown" : $class;
|
161 |
-
$class = ( 'textbox' == $class && 'multiselect' == $type ) ? "multiselect" : $class;
|
162 |
-
$pname = ( 'multiselect' == $type ) ? $name . "[]" : $name;
|
163 |
-
$str = "<select name=\"$pname\" id=\"$id\" class=\"$class\"" . ( ( 'multiselect' == $type ) ? " multiple " : "" ) . ( ( $required ) ? " required " : "" ) . ">\n";
|
164 |
-
if ( 'membership' == $type ) {
|
165 |
-
$value = array( 'Choose membership|' );
|
166 |
-
foreach( $wpmem->membership->products as $membership_key => $membership_value ) {
|
167 |
-
$value[] = $membership_value['title'] . '|' . $membership_key;
|
168 |
-
}
|
169 |
-
}
|
170 |
-
foreach ( $value as $option ) {
|
171 |
-
$pieces = explode( '|', $option );
|
172 |
-
if ( 'multiselect' == $type ) {
|
173 |
-
$chk = '';
|
174 |
-
$values = ( empty( $compare ) ) ? array() : ( is_array( $compare ) ? $compare : explode( $delimiter, $compare ) );
|
175 |
-
} else {
|
176 |
-
$chk = $compare;
|
177 |
-
$values = array();
|
178 |
-
}
|
179 |
-
if ( isset( $pieces[1] ) && '' != $pieces[1] ) {
|
180 |
-
$chk = ( ( isset( $pieces[2] ) && '' == $compare ) || in_array( $pieces[1], $values ) ) ? $pieces[1] : $chk;
|
181 |
-
} else {
|
182 |
-
$chk = 'not selected';
|
183 |
-
}
|
184 |
-
$str = $str . "<option value=\"$pieces[1]\"" . selected( $pieces[1], $chk, false ) . ">" . esc_attr( __( $pieces[0], 'wp-members' ) ) . "</option>\n";
|
185 |
-
}
|
186 |
-
$str = $str . "</select>";
|
187 |
-
break;
|
188 |
-
|
189 |
-
case "multicheckbox":
|
190 |
-
$class = ( 'textbox' == $class ) ? "checkbox" : $class;
|
191 |
-
$str = '';
|
192 |
-
$num = 1;
|
193 |
-
foreach ( $value as $option ) {
|
194 |
-
$pieces = explode( '|', $option );
|
195 |
-
$values = ( empty( $compare ) ) ? array() : ( is_array( $compare ) ? $compare : explode( $delimiter, $compare ) );
|
196 |
-
$chk = ( isset( $pieces[2] ) && '' == $compare ) ? $pieces[1] : '';
|
197 |
-
if ( isset( $pieces[1] ) && '' != $pieces[1] ) {
|
198 |
-
$id_value = esc_attr( $id . '[' . $pieces[1] . ']' );
|
199 |
-
$label = wpmem_form_label( array( 'meta_key'=>$id_value, 'label'=>esc_html( __( $pieces[0], 'wp-members' ) ), 'type'=>'radio', 'id'=>$id_value ) );
|
200 |
-
$str = $str . $this->create_form_field( array(
|
201 |
-
'id' => $id_value,
|
202 |
-
'name' => $name . '[]',
|
203 |
-
'type' => 'checkbox',
|
204 |
-
'value' => $pieces[1],
|
205 |
-
'compare' => ( in_array( $pieces[1], $values ) ) ? $pieces[1] : $chk,
|
206 |
-
) ) . " " . $label . "<br />\n";
|
207 |
-
} else {
|
208 |
-
$str = $str . '<span class="div_multicheckbox_separator">' . esc_html( __( $pieces[0], 'wp-members' ) ) . "</span><br />\n";
|
209 |
-
}
|
210 |
-
}
|
211 |
-
break;
|
212 |
-
|
213 |
-
case "radio":
|
214 |
-
$class = ( 'textbox' == $class ) ? "radio" : $this->sanitize_class( $class );
|
215 |
-
$str = '';
|
216 |
-
$num = 1;
|
217 |
-
foreach ( $value as $option ) {
|
218 |
-
$pieces = explode( '|', $option );
|
219 |
-
$id_num = $id . '_' . $num;
|
220 |
-
if ( isset( $pieces[1] ) && '' != $pieces[1] ) {
|
221 |
-
$label = wpmem_form_label( array( 'meta_key'=>esc_attr( $id_num ), 'label'=>esc_html( __( $pieces[0], 'wp-members' ) ), 'type'=>'radio', 'id'=>esc_attr( "label_" . $id_num ) ) );
|
222 |
-
$str = $str . "<input type=\"radio\" name=\"$name\" id=\"" . esc_attr( $id_num ) . "\" value=\"" . esc_attr( $pieces[1] ) . '"' . checked( $pieces[1], $compare, false ) . ( ( $required ) ? " required " : " " ) . "> $label<br />\n";
|
223 |
-
$num++;
|
224 |
-
} else {
|
225 |
-
$str = $str . '<span class="div_radio_separator">' . esc_html( __( $pieces[0], 'wp-members' ) ) . "</span><br />\n";
|
226 |
-
}
|
227 |
-
}
|
228 |
-
break;
|
229 |
-
|
230 |
-
}
|
231 |
-
|
232 |
-
return $str;
|
233 |
-
} // End create_form_field()
|
234 |
-
|
235 |
-
/**
|
236 |
-
* Create form label.
|
237 |
-
*
|
238 |
-
* @since 3.1.7
|
239 |
-
* @since 3.2.4 Added $id
|
240 |
-
*
|
241 |
-
* @param array $args {
|
242 |
-
* @type string $meta_key
|
243 |
-
* @type string $label
|
244 |
-
* @type string $type
|
245 |
-
* @type string $id (optional)
|
246 |
-
* @type string $class (optional)
|
247 |
-
* @type string $required (optional)
|
248 |
-
* @type string $req_mark (optional)
|
249 |
-
* }
|
250 |
-
* @return string $label
|
251 |
-
*/
|
252 |
-
function create_form_label( $args ) {
|
253 |
-
global $wpmem;
|
254 |
-
|
255 |
-
$meta_key = $args['meta_key'];
|
256 |
-
$label = $args['label'];
|
257 |
-
$type = $args['type'];
|
258 |
-
$class = ( isset( $args['class'] ) ) ? $args['class'] : false;
|
259 |
-
$id = ( isset( $args['id'] ) ) ? $args['id'] : false;
|
260 |
-
$required = ( isset( $args['required'] ) ) ? $args['required'] : false;
|
261 |
-
$req_mark = ( isset( $args['req_mark'] ) ) ? $args['req_mark'] : false;
|
262 |
-
|
263 |
-
//$req_mark = ( ! $req_mark ) ? $wpmem->get_text( 'register_req_mark' ) : '*';
|
264 |
-
|
265 |
-
if ( ! $class ) {
|
266 |
-
$class = ( $type == 'password' || $type == 'email' || $type == 'url' ) ? 'text' : $type;
|
267 |
-
}
|
268 |
-
|
269 |
-
$id = ( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
|
270 |
-
|
271 |
-
$label = '<label for="' . esc_attr( $meta_key ) . '"' . $id . ' class="' . $this->sanitize_class( $class ) . '">' . __( $label, 'wp-members' );
|
272 |
-
$label = ( $required ) ? $label . $req_mark : $label;
|
273 |
-
$label = $label . '</label>';
|
274 |
-
|
275 |
-
return $label;
|
276 |
-
}
|
277 |
-
|
278 |
-
/**
|
279 |
-
* Sanitizes classes passed to the WP-Members form building functions.
|
280 |
-
*
|
281 |
-
* This generally uses just sanitize_html_class() but allows for
|
282 |
-
* whitespace so multiple classes can be passed (such as "regular-text code").
|
283 |
-
*
|
284 |
-
* @since 3.2.0
|
285 |
-
*
|
286 |
-
* @param string $class
|
287 |
-
* @return string sanitized_class
|
288 |
-
*/
|
289 |
-
function sanitize_class( $class ) {
|
290 |
-
// If no whitespace, just return WP sanitized class.
|
291 |
-
if ( ! strpos( $class, ' ' ) ) {
|
292 |
-
return sanitize_html_class( $class );
|
293 |
-
} else {
|
294 |
-
// Break string by whitespace, sanitize individual class names.
|
295 |
-
$class_array = explode( ' ', $class );
|
296 |
-
$len = count( $class_array ); $i = 0;
|
297 |
-
$sanitized_class = '';
|
298 |
-
foreach ( $class_array as $single_class ) {
|
299 |
-
$sanitized_class .= sanitize_html_class( $single_class );
|
300 |
-
$sanitized_class .= ( $i == $len - 1 ) ? '' : ' ';
|
301 |
-
$i++;
|
302 |
-
}
|
303 |
-
return $sanitized_class;
|
304 |
-
}
|
305 |
-
}
|
306 |
-
|
307 |
-
/**
|
308 |
-
* Sanitizes the text in an array.
|
309 |
-
*
|
310 |
-
* @since 3.2.9
|
311 |
-
*
|
312 |
-
* @param array $data
|
313 |
-
* @return array $data
|
314 |
-
*/
|
315 |
-
function sanitize_array( $data ) {
|
316 |
-
if ( is_array( $data ) ) {
|
317 |
-
foreach( $data as $key => $val ) {
|
318 |
-
$data[ $key ] = sanitize_text_field( $val );
|
319 |
-
}
|
320 |
-
}
|
321 |
-
return $data;
|
322 |
-
}
|
323 |
-
|
324 |
-
/**
|
325 |
-
* Sanitizes field based on field type.
|
326 |
-
*
|
327 |
-
* Obviously, this isn't an all inclusive function of every WordPress
|
328 |
-
* sanitization function. It is intended to handle sanitization of
|
329 |
-
* WP-Members form input and therefore includes the necessary methods
|
330 |
-
* that would relate to the WP-Members custom field types and can thus
|
331 |
-
* be used by looping through form data when the WP-Members fields are
|
332 |
-
* handled and validated.
|
333 |
-
*
|
334 |
-
* @since 3.2.9
|
335 |
-
* @since 3.3.0 Added email, file, and image.
|
336 |
-
*
|
337 |
-
* @param string $data
|
338 |
-
* @param string $type
|
339 |
-
* @return string $sanitized_data
|
340 |
-
*/
|
341 |
-
function sanitize_field( $data, $type ) {
|
342 |
-
|
343 |
-
switch ( $type ) {
|
344 |
-
|
345 |
-
case 'multiselect':
|
346 |
-
case 'multicheckbox':
|
347 |
-
$sanitized_data = $this->sanitize_array( $data );
|
348 |
-
break;
|
349 |
-
|
350 |
-
case 'textarea':
|
351 |
-
$sanitized_data = sanitize_textarea_field( $data );
|
352 |
-
break;
|
353 |
-
|
354 |
-
case 'email':
|
355 |
-
$sanitized_data = sanitize_email( $data );
|
356 |
-
break;
|
357 |
-
|
358 |
-
case 'file':
|
359 |
-
case 'image':
|
360 |
-
$sanitized_data = sanitize_file_name( $data );
|
361 |
-
break;
|
362 |
-
|
363 |
-
default:
|
364 |
-
$sanitized_data = sanitize_text_field( $data );
|
365 |
-
break;
|
366 |
-
}
|
367 |
-
|
368 |
-
return $sanitized_data;
|
369 |
-
}
|
370 |
-
|
371 |
-
/**
|
372 |
-
* Uploads file from the user.
|
373 |
-
*
|
374 |
-
* @since 3.1.0
|
375 |
-
*
|
376 |
-
* @param array $file
|
377 |
-
* @param int $user_id
|
378 |
-
* @return int|bool
|
379 |
-
*/
|
380 |
-
function do_file_upload( $file = array(), $user_id = false ) {
|
381 |
-
|
382 |
-
// Filter the upload directory.
|
383 |
-
add_filter( 'upload_dir', array( &$this,'file_upload_dir' ) );
|
384 |
-
|
385 |
-
// Set up user ID for use in upload process.
|
386 |
-
$this->file_user_id = ( $user_id ) ? $user_id : 0;
|
387 |
-
|
388 |
-
// Get WordPress file upload processing scripts.
|
389 |
-
require_once( ABSPATH . 'wp-admin/includes/file.php' );
|
390 |
-
|
391 |
-
$file_return = wp_handle_upload( $file, array( 'test_form' => false ) );
|
392 |
-
|
393 |
-
if ( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
|
394 |
-
return false;
|
395 |
-
} else {
|
396 |
-
|
397 |
-
$attachment = array(
|
398 |
-
'post_mime_type' => $file_return['type'],
|
399 |
-
'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $file_return['file'] ) ),
|
400 |
-
'post_content' => '',
|
401 |
-
'post_status' => 'inherit',
|
402 |
-
'guid' => $file_return['url'],
|
403 |
-
'post_author' => ( $user_id ) ? $user_id : '',
|
404 |
-
);
|
405 |
-
|
406 |
-
$attachment_id = wp_insert_attachment( $attachment, $file_return['url'] );
|
407 |
-
|
408 |
-
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
409 |
-
$attachment_data = wp_generate_attachment_metadata( $attachment_id, $file_return['file'] );
|
410 |
-
wp_update_attachment_metadata( $attachment_id, $attachment_data );
|
411 |
-
|
412 |
-
if ( 0 < intval( $attachment_id ) ) {
|
413 |
-
// Returns an array with file information.
|
414 |
-
return $attachment_id;
|
415 |
-
}
|
416 |
-
}
|
417 |
-
|
418 |
-
return false;
|
419 |
-
} // End upload_file()
|
420 |
-
|
421 |
-
/**
|
422 |
-
* Sets the file upload directory.
|
423 |
-
*
|
424 |
-
* This is a filter function for upload_dir.
|
425 |
-
*
|
426 |
-
* @link https://codex.wordpress.org/Plugin_API/Filter_Reference/upload_dir
|
427 |
-
*
|
428 |
-
* @since 3.1.0
|
429 |
-
*
|
430 |
-
* @param array $param {
|
431 |
-
* The directory information for upload.
|
432 |
-
*
|
433 |
-
* @type string $path
|
434 |
-
* @type string $url
|
435 |
-
* @type string $subdir
|
436 |
-
* @type string $basedir
|
437 |
-
* @type string $baseurl
|
438 |
-
* @type string $error
|
439 |
-
* }
|
440 |
-
* @return array $param
|
441 |
-
*/
|
442 |
-
function file_upload_dir( $param ) {
|
443 |
-
$user_id = ( isset( $this->file_user_id ) ) ? $this->file_user_id : null;
|
444 |
-
|
445 |
-
$args = array(
|
446 |
-
'user_id' => $user_id,
|
447 |
-
'wpmem_dir' => 'wpmembers/',
|
448 |
-
'user_dir' => 'user_files/' . $user_id,
|
449 |
-
);
|
450 |
-
/**
|
451 |
-
* Filter the user directory elements.
|
452 |
-
*
|
453 |
-
* @since 3.1.0
|
454 |
-
*
|
455 |
-
* @param array $args
|
456 |
-
*/
|
457 |
-
$args = apply_filters( 'wpmem_user_upload_dir', $args );
|
458 |
-
|
459 |
-
$param['subdir'] = '/' . $args['wpmem_dir'] . $args['user_dir'];
|
460 |
-
$param['path'] = $param['basedir'] . '/' . $args['wpmem_dir'] . $args['user_dir'];
|
461 |
-
$param['url'] = $param['baseurl'] . '/' . $args['wpmem_dir'] . $args['user_dir'];
|
462 |
-
|
463 |
-
return $param;
|
464 |
-
}
|
465 |
-
|
466 |
-
/**
|
467 |
-
* Login Form Builder.
|
468 |
-
*
|
469 |
-
* Builds the form used for login, change password, and reset password.
|
470 |
-
*
|
471 |
-
* @since 2.5.1
|
472 |
-
* @since 3.1.7 Moved to forms object class as login_form().
|
473 |
-
* @since 3.1.7 Added WP action login_form.
|
474 |
-
* @since 3.2.6 Added nonce to the short form.
|
475 |
-
*
|
476 |
-
* @param string $page
|
477 |
-
* @param array $arr {
|
478 |
-
* The elements needed to generate the form (login|reset password|forgotten password).
|
479 |
-
*
|
480 |
-
* @type string $heading Form heading text.
|
481 |
-
* @type string $action The form action (login|pwdchange|pwdreset|getusername).
|
482 |
-
* @type string $button_text Form submit button text.
|
483 |
-
* @type array $inputs {
|
484 |
-
* The form input values.
|
485 |
-
*
|
486 |
-
* @type array {
|
487 |
-
*
|
488 |
-
* @type string $name The field label.
|
489 |
-
* @type string $type Input type.
|
490 |
-
* @type string $tag Input tag name.
|
491 |
-
* @type string $class Input tag class.
|
492 |
-
* @type string $div Div wrapper class.
|
493 |
-
* }
|
494 |
-
* }
|
495 |
-
* @type string $redirect_to Optional. URL to redirect to.
|
496 |
-
* }
|
497 |
-
* @return string $form The HTML for the form as a string.
|
498 |
-
*/
|
499 |
-
function login_form( $mixed, $arr = array() ) {
|
500 |
-
|
501 |
-
// Handle legacy use.
|
502 |
-
if ( is_array( $mixed ) ) {
|
503 |
-
$page = $mixed['page'];
|
504 |
-
$arr = $mixed;
|
505 |
-
} else {
|
506 |
-
$page = $mixed;
|
507 |
-
}
|
508 |
-
|
509 |
-
|
510 |
-
// Set up redirect_to @todo This could be done in a separate method usable by both login & reg.
|
511 |
-
if ( isset( $_REQUEST['redirect_to'] ) ) {
|
512 |
-
$redirect_to = $_REQUEST['redirect_to'];
|
513 |
-
} else {
|
514 |
-
if ( isset( $arr['redirect_to'] ) ) {
|
515 |
-
$redirect_to = $arr['redirect_to'];
|
516 |
-
} else {
|
517 |
-
$redirect_to = ( isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : get_permalink();
|
518 |
-
}
|
519 |
-
}
|
520 |
-
|
521 |
-
global $wpmem;
|
522 |
-
|
523 |
-
// set up default wrappers
|
524 |
-
$defaults = array(
|
525 |
-
|
526 |
-
// wrappers
|
527 |
-
'heading_before' => '<legend>',
|
528 |
-
'heading_after' => '</legend>',
|
529 |
-
'fieldset_before' => '<fieldset>',
|
530 |
-
'fieldset_after' => '</fieldset>',
|
531 |
-
'main_div_before' => '<div id="wpmem_login">',
|
532 |
-
'main_div_after' => '</div>',
|
533 |
-
'txt_before' => '',
|
534 |
-
'txt_after' => '',
|
535 |
-
'row_before' => '',
|
536 |
-
'row_after' => '',
|
537 |
-
'buttons_before' => '<div class="button_div">',
|
538 |
-
'buttons_after' => '</div>',
|
539 |
-
'link_before' => '<div class="link-text">',
|
540 |
-
'link_after' => '</div>',
|
541 |
-
'link_span_before' => '<span class="link-text-%s">',
|
542 |
-
'link_span_after' => '</span>',
|
543 |
-
|
544 |
-
// classes & ids
|
545 |
-
'form_id' => 'wpmem_' . $arr['action'] . '_form',
|
546 |
-
'form_class' => 'form',
|
547 |
-
'button_id' => '',
|
548 |
-
'button_class' => 'buttons',
|
549 |
-
|
550 |
-
// other
|
551 |
-
'strip_breaks' => true,
|
552 |
-
'wrap_inputs' => true,
|
553 |
-
'remember_check' => true,
|
554 |
-
'n' => "\n",
|
555 |
-
't' => "\t",
|
556 |
-
'redirect_to' => $redirect_to,
|
557 |
-
'login_form_action' => true,
|
558 |
-
|
559 |
-
);
|
560 |
-
|
561 |
-
/**
|
562 |
-
* Filter the default form arguments.
|
563 |
-
*
|
564 |
-
* This filter accepts an array of various elements to replace the form defaults. This
|
565 |
-
* includes default tags, labels, text, and small items including various booleans.
|
566 |
-
*
|
567 |
-
* @since 2.9.0
|
568 |
-
* @since 3.3.0 Passes $defaults as an argument.
|
569 |
-
*
|
570 |
-
* @param array $args An array of arguments to merge with defaults.
|
571 |
-
* @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
|
572 |
-
*/
|
573 |
-
$args = apply_filters( 'wpmem_login_form_args', $defaults, $arr['action'] );
|
574 |
-
|
575 |
-
// Merge $args with defaults.
|
576 |
-
$args = wp_parse_args( $args, $defaults );
|
577 |
-
|
578 |
-
// Build the input rows.
|
579 |
-
foreach ( $arr['inputs'] as $input ) {
|
580 |
-
$label = '<label for="' . esc_attr( $input['tag'] ) . '">' . $input['name'] . '</label>';
|
581 |
-
$field = wpmem_form_field( array(
|
582 |
-
'name' => $input['tag'],
|
583 |
-
'type' => $input['type'],
|
584 |
-
'class' => $input['class'],
|
585 |
-
'required' => true,
|
586 |
-
) );
|
587 |
-
$field_before = ( $args['wrap_inputs'] ) ? '<div class="' . $this->sanitize_class( $input['div'] ) . '">' : '';
|
588 |
-
$field_after = ( $args['wrap_inputs'] ) ? '</div>' : '';
|
589 |
-
$rows[] = array(
|
590 |
-
'row_before' => $args['row_before'],
|
591 |
-
'label' => $label,
|
592 |
-
'field_before' => $field_before,
|
593 |
-
'field' => $field,
|
594 |
-
'field_after' => $field_after,
|
595 |
-
'row_after' => $args['row_after'],
|
596 |
-
);
|
597 |
-
}
|
598 |
-
|
599 |
-
/**
|
600 |
-
* Filter the array of form rows.
|
601 |
-
*
|
602 |
-
* This filter receives an array of the main rows in the form, each array element being
|
603 |
-
* an array of that particular row's pieces. This allows making changes to individual
|
604 |
-
* parts of a row without needing to parse through a string of HTML.
|
605 |
-
*
|
606 |
-
* @since 2.9.0
|
607 |
-
* @since 3.2.6 Added $arr parameter so all settings are passed.
|
608 |
-
*
|
609 |
-
* @param array $rows An array containing the form rows.
|
610 |
-
* @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
|
611 |
-
* @param array $arr An array containing all of the form settings.
|
612 |
-
*/
|
613 |
-
$rows = apply_filters( 'wpmem_login_form_rows', $rows, $arr['action'], $arr );
|
614 |
-
|
615 |
-
// Put the rows from the array into $form.
|
616 |
-
$form = '';
|
617 |
-
foreach ( $rows as $row_item ) {
|
618 |
-
$row = ( $row_item['row_before'] != '' ) ? $row_item['row_before'] . $args['n'] . $row_item['label'] . $args['n'] : $row_item['label'] . $args['n'];
|
619 |
-
$row .= ( $row_item['field_before'] != '' ) ? $row_item['field_before'] . $args['n'] . $args['t'] . $row_item['field'] . $args['n'] . $row_item['field_after'] . $args['n'] : $row_item['field'] . $args['n'];
|
620 |
-
$row .= ( $row_item['row_after'] != '' ) ? $row_item['row_after'] . $args['n'] : '';
|
621 |
-
$form.= $row;
|
622 |
-
}
|
623 |
-
|
624 |
-
// Handle outside elements added to the login form (currently ONLY for login).
|
625 |
-
if ( 'login' == $arr['action'] && $args['login_form_action'] ) {
|
626 |
-
ob_start();
|
627 |
-
/** This action is documented in wp-login.php */
|
628 |
-
do_action( 'login_form' );
|
629 |
-
$add_to_form = ob_get_contents();
|
630 |
-
ob_end_clean();
|
631 |
-
$form.= $add_to_form;
|
632 |
-
}
|
633 |
-
|
634 |
-
// Build hidden fields, filter, and add to the form.
|
635 |
-
$hidden = wpmem_create_formfield( 'redirect_to', 'hidden', esc_url( $args['redirect_to'] ) ) . $args['n'];
|
636 |
-
$hidden = $hidden . wpmem_create_formfield( 'a', 'hidden', $arr['action'] ) . $args['n'];
|
637 |
-
$hidden = ( $arr['action'] != 'login' ) ? $hidden . wpmem_create_formfield( 'formsubmit', 'hidden', '1' ) : $hidden;
|
638 |
-
|
639 |
-
/**
|
640 |
-
* Filter the hidden field HTML.
|
641 |
-
*
|
642 |
-
* @since 2.9.0
|
643 |
-
*
|
644 |
-
* @param string $hidden The generated HTML of hidden fields.
|
645 |
-
* @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
|
646 |
-
*/
|
647 |
-
$form = $form . apply_filters( 'wpmem_login_hidden_fields', $hidden, $arr['action'] );
|
648 |
-
|
649 |
-
// Build the buttons, filter, and add to the form.
|
650 |
-
if ( $arr['action'] == 'login' ) {
|
651 |
-
$args['remember_check'] = ( $args['remember_check'] ) ? $args['t'] . wpmem_create_formfield( 'rememberme', 'checkbox', 'forever' ) . ' ' . '<label for="rememberme">' . $wpmem->get_text( 'remember_me' ) . '</label> ' . $args['n'] : '';
|
652 |
-
$buttons = $args['remember_check'] . $args['t'] . '<input type="submit" name="Submit" value="' . esc_attr( $arr['button_text'] ) . '" class="' . $this->sanitize_class( $args['button_class'] ) . '" />' . $args['n'];
|
653 |
-
} else {
|
654 |
-
$buttons = '<input type="submit" name="Submit" value="' . esc_attr( $arr['button_text'] ) . '" class="' . $this->sanitize_class( $args['button_class'] ) . '" />' . $args['n'];
|
655 |
-
}
|
656 |
-
|
657 |
-
/**
|
658 |
-
* Filter the HTML for form buttons.
|
659 |
-
*
|
660 |
-
* The string includes the buttons, as well as the before/after wrapper elements.
|
661 |
-
*
|
662 |
-
* @since 2.9.0
|
663 |
-
*
|
664 |
-
* @param string $buttons The generated HTML of the form buttons.
|
665 |
-
* @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
|
666 |
-
*/
|
667 |
-
$form = $form . apply_filters( 'wpmem_login_form_buttons', $args['buttons_before'] . $args['n'] . $buttons . $args['buttons_after'] . $args['n'], $arr['action'] );
|
668 |
-
|
669 |
-
$links_array = array(
|
670 |
-
'forgot' => array(
|
671 |
-
'tag' => 'forgot',
|
672 |
-
'link' => add_query_arg( 'a', 'pwdreset', $wpmem->user_pages['profile'] ),
|
673 |
-
'page' => 'profile',
|
674 |
-
'action' => 'login',
|
675 |
-
),
|
676 |
-
'register' => array(
|
677 |
-
'tag' => 'reg',
|
678 |
-
'link' => $wpmem->user_pages['register'],
|
679 |
-
'page' => 'register',
|
680 |
-
'action' => 'login',
|
681 |
-
),
|
682 |
-
'username' => array(
|
683 |
-
'tag' => 'username',
|
684 |
-
'link' => add_query_arg( 'a', 'getusername', $wpmem->user_pages['profile'] ),
|
685 |
-
'page' => 'profile',
|
686 |
-
'action' => 'pwdreset',
|
687 |
-
),
|
688 |
-
);
|
689 |
-
foreach ( $links_array as $key => $value ) {
|
690 |
-
$tag = $value['tag'];
|
691 |
-
if ( ( $wpmem->user_pages[ $value['page'] ] || 'members' == $page ) && $value['action'] == $arr['action'] ) {
|
692 |
-
/**
|
693 |
-
* Filters register, forgot password, and forgot username links.
|
694 |
-
*
|
695 |
-
* @since 2.8.0
|
696 |
-
* @since 3.1.7 Combined all to a single process.
|
697 |
-
* @since 3.2.5 Added $tag parameter.
|
698 |
-
*
|
699 |
-
* @param string The raw link.
|
700 |
-
* @param string $tag forgot|reg|pwdreset.
|
701 |
-
*/
|
702 |
-
$link = apply_filters( "wpmem_{$tag}_link", $value['link'], $tag );
|
703 |
-
$str = $wpmem->get_text( "{$key}_link_before" ) . '<a href="' . esc_url( $link ) . '">' . $wpmem->get_text( "{$key}_link" ) . '</a>';
|
704 |
-
$link_str = $args['link_before'];
|
705 |
-
$link_str.= ( '' != $args['link_span_before'] ) ? sprintf( $args['link_span_before'], $key ) : '';
|
706 |
-
/**
|
707 |
-
* Filters the register, forgot password, and forgot username links HTML.
|
708 |
-
*
|
709 |
-
* @since 2.9.0
|
710 |
-
* @since 3.0.9 Added $link parameter.
|
711 |
-
* @since 3.1.7 Combined all to a single process.
|
712 |
-
* @since 3.2.5 Added $tag parameter.
|
713 |
-
*
|
714 |
-
* @param string $str The link HTML.
|
715 |
-
* @param string $link The link.
|
716 |
-
* @param string $tag forgot|reg|pwdreset.
|
717 |
-
*/
|
718 |
-
$link_str.= apply_filters( "wpmem_{$tag}_link_str", $str, $link, $tag );
|
719 |
-
$link_str.= ( '' != $args['link_span_after'] ) ? $args['link_span_after'] : '';
|
720 |
-
$link_str.= $args['link_after'] . $args['n'];
|
721 |
-
/*
|
722 |
-
* If this is the register link, and the current post type is set to
|
723 |
-
* display the register form, and the current page is not the login
|
724 |
-
* page, then do not add the register link, otherwise add the link.
|
725 |
-
*/
|
726 |
-
if ( 'register' == $key ) {
|
727 |
-
if ( ! isset( $wpmem->user_pages['register'] ) || '' == $wpmem->user_pages['register'] ) {
|
728 |
-
$form = $form;
|
729 |
-
} else {
|
730 |
-
if ( isset( $wpmem->user_pages['login'] ) && '' != $wpmem->user_pages['login'] ) {
|
731 |
-
$form = ( 1 == $wpmem->show_reg[ get_post_type( get_the_ID() ) ] && wpmem_current_url( true, false ) != wpmem_login_url() ) ? $form : $form . $link_str;
|
732 |
-
} else {
|
733 |
-
global $post;
|
734 |
-
if ( has_shortcode( $post->post_content, 'wpmem_profile' ) ) {
|
735 |
-
$form = $form;
|
736 |
-
} else {
|
737 |
-
$form = ( 1 == $wpmem->show_reg[ get_post_type( get_the_ID() ) ] && ! has_shortcode( $post->post_content, 'wpmem_form' ) ) ? $form : $form . $link_str;
|
738 |
-
}
|
739 |
-
}
|
740 |
-
}
|
741 |
-
} else {
|
742 |
-
$form = $form . $link_str;
|
743 |
-
}
|
744 |
-
}
|
745 |
-
}
|
746 |
-
|
747 |
-
// Apply the heading.
|
748 |
-
$form = $args['heading_before'] . $arr['heading'] . $args['heading_after'] . $args['n'] . $form;
|
749 |
-
|
750 |
-
// Apply fieldset wrapper.
|
751 |
-
$form = $args['fieldset_before'] . $args['n'] . $form . $args['fieldset_after'] . $args['n'];
|
752 |
-
|
753 |
-
// Apply nonce.
|
754 |
-
$form = wp_nonce_field( 'wpmem_shortform_nonce', '_wpmem_' . $arr['action'] . '_nonce', true, false ) . $args['n'] . $form;
|
755 |
-
|
756 |
-
// Apply form wrapper.
|
757 |
-
$form = '<form action="' . esc_url( get_permalink() ) . '" method="POST" id="' . $this->sanitize_class( $args['form_id'] ) . '" class="' . $this->sanitize_class( $args['form_class'] ) . '">' . $args['n'] . $form . '</form>';
|
758 |
-
|
759 |
-
// Apply anchor.
|
760 |
-
$form = '<a id="' . esc_attr( $arr['action'] ) . '"></a>' . $args['n'] . $form;
|
761 |
-
|
762 |
-
// Apply main wrapper.
|
763 |
-
$form = $args['main_div_before'] . $args['n'] . $form . $args['n'] . $args['main_div_after'];
|
764 |
-
|
765 |
-
// Apply wpmem_txt wrapper.
|
766 |
-
$form = $args['txt_before'] . $form . $args['txt_after'];
|
767 |
-
|
768 |
-
// Remove line breaks.
|
769 |
-
$form = ( $args['strip_breaks'] ) ? str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form ) : $form;
|
770 |
-
|
771 |
-
/**
|
772 |
-
* Filter the generated HTML of the entire form.
|
773 |
-
*
|
774 |
-
* @since 2.7.4
|
775 |
-
*
|
776 |
-
* @param string $form The HTML of the final generated form.
|
777 |
-
* @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
|
778 |
-
*/
|
779 |
-
$form = apply_filters( 'wpmem_login_form', $form, $arr['action'] );
|
780 |
-
|
781 |
-
/**
|
782 |
-
* Filter before the form.
|
783 |
-
*
|
784 |
-
* This rarely used filter allows you to stick any string onto the front of
|
785 |
-
* the generated form.
|
786 |
-
*
|
787 |
-
* @since 2.7.4
|
788 |
-
*
|
789 |
-
* @param string $str The HTML to add before the form. Default null.
|
790 |
-
* @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
|
791 |
-
*/
|
792 |
-
$form = apply_filters( 'wpmem_login_form_before', '', $arr['action'] ) . $form;
|
793 |
-
|
794 |
-
return $form;
|
795 |
-
} // End login_form.
|
796 |
-
|
797 |
-
/**
|
798 |
-
* Registration Form Builder.
|
799 |
-
*
|
800 |
-
* Outputs the form for new user registration and existing user edits.
|
801 |
-
*
|
802 |
-
* @since 2.5.1
|
803 |
-
* @since 3.1.7 Moved to forms object class as register_form().
|
804 |
-
* @since 3.2.5 use_nonce now obsolete (nonce is added automatically).
|
805 |
-
* @since 3.3.0 $heading argument obsolete.
|
806 |
-
*
|
807 |
-
* @global object $wpmem The WP_Members object.
|
808 |
-
* @global string $wpmem_regchk Used to determine if the form is in an error state.
|
809 |
-
* @global array $userdata Used to get the user's registration data if they are logged in (user profile edit).
|
810 |
-
* @param mixed $mixed (optional) String toggles between new registration ('new') and user profile edit ('edit'), or array containing settings arguments.
|
811 |
-
* @return string $form The HTML for the entire form as a string.
|
812 |
-
*/
|
813 |
-
function register_form( $mixed = 'new', $redirect_to = null ) {
|
814 |
-
|
815 |
-
// Handle legacy use.
|
816 |
-
if ( is_array( $mixed ) ) {
|
817 |
-
$id = ( isset( $mixed['id'] ) ) ? $mixed['id'] : '';
|
818 |
-
$tag = ( isset( $mixed['tag'] ) ) ? $mixed['tag'] : 'new';
|
819 |
-
$heading = ( isset( $mixed['heading'] ) ) ? $mixed['heading'] : '';
|
820 |
-
$redirect_to = ( isset( $mixed['redirect_to'] ) ) ? $mixed['redirect_to'] : '';
|
821 |
-
} else {
|
822 |
-
$id = 'default';
|
823 |
-
$tag = $mixed;
|
824 |
-
}
|
825 |
-
|
826 |
-
global $wpmem, $wpmem_regchk, $userdata;
|
827 |
-
|
828 |
-
// Set up default wrappers.
|
829 |
-
$defaults = array(
|
830 |
-
|
831 |
-
// Wrappers.
|
832 |
-
'heading_before' => '<legend>',
|
833 |
-
'heading_after' => '</legend>',
|
834 |
-
'fieldset_before' => '<fieldset>',
|
835 |
-
'fieldset_after' => '</fieldset>',
|
836 |
-
'main_div_before' => '<div id="wpmem_reg">',
|
837 |
-
'main_div_after' => '</div>',
|
838 |
-
'txt_before' => '',
|
839 |
-
'txt_after' => '',
|
840 |
-
'row_before' => '',
|
841 |
-
'row_after' => '',
|
842 |
-
'buttons_before' => '<div class="button_div">',
|
843 |
-
'buttons_after' => '</div>',
|
844 |
-
|
845 |
-
// Classes & ids.
|
846 |
-
'form_id' => ( 'new' == $tag ) ? 'wpmem_register_form' : 'wpmem_profile_form',
|
847 |
-
'form_class' => 'form',
|
848 |
-
'button_id' => '',
|
849 |
-
'button_class' => 'buttons',
|
850 |
-
|
851 |
-
// Required field tags and text.
|
852 |
-
'req_mark' => $wpmem->get_text( 'register_req_mark' ),
|
853 |
-
'req_label' => $wpmem->get_text( 'register_required' ),
|
854 |
-
'req_label_before' => '<div class="req-text">',
|
855 |
-
'req_label_after' => '</div>',
|
856 |
-
|
857 |
-
// Buttons.
|
858 |
-
'show_clear_form' => false,
|
859 |
-
'clear_form' => $wpmem->get_text( 'register_clear' ),
|
860 |
-
'submit_register' => $wpmem->get_text( 'register_submit' ),
|
861 |
-
'submit_update' => $wpmem->get_text( 'profile_submit' ),
|
862 |
-
|
863 |
-
// Other.
|
864 |
-
'post_to' => get_permalink(),
|
865 |
-
'strip_breaks' => true,
|
866 |
-
'wrap_inputs' => true,
|
867 |
-
'n' => "\n",
|
868 |
-
't' => "\t",
|
869 |
-
|
870 |
-
);
|
871 |
-
|
872 |
-
/**
|
873 |
-
* Filter the default form arguments.
|
874 |
-
*
|
875 |
-
* This filter accepts an array of various elements to replace the form defaults. This
|
876 |
-
* includes default tags, labels, text, and small items including various booleans.
|
877 |
-
*
|
878 |
-
* @since 2.9.0
|
879 |
-
* @since 3.2.5 Added $id
|
880 |
-
* @since 3.3.0 Passes $defaults as an argument.
|
881 |
-
*
|
882 |
-
* @param array An array of arguments to merge with defaults. Default null.
|
883 |
-
* @param string $tag Toggle new registration or profile update. new|edit.
|
884 |
-
* @param string $id An id for the form (optional).
|
885 |
-
*/
|
886 |
-
$args = apply_filters( 'wpmem_register_form_args', $defaults, $tag, $id );
|
887 |
-
|
888 |
-
// Merge $args with defaults.
|
889 |
-
$args = wp_parse_args( $args, $defaults );
|
890 |
-
|
891 |
-
// Get fields.
|
892 |
-
$wpmem_fields = wpmem_fields( $tag );
|
893 |
-
|
894 |
-
// Fields to skip for user profile update.
|
895 |
-
|
896 |
-
if ( 'edit' == $tag ) {
|
897 |
-
$pass_arr = array( 'username', 'password', 'confirm_password', 'password_confirm' );
|
898 |
-
// Skips tos on user edit page, unless they haven't got a value for tos.
|
899 |
-
if ( isset( $wpmem_fields['tos'] ) && ( $wpmem_fields['tos']['checked_value'] == get_user_meta( $userdata->ID, 'tos', true ) ) ) {
|
900 |
-
$pass_arr[] = 'tos';
|
901 |
-
}
|
902 |
-
foreach ( $pass_arr as $pass ) {
|
903 |
-
unset( $wpmem_fields[ $pass ] );
|
904 |
-
}
|
905 |
-
}
|
906 |
-
|
907 |
-
/**
|
908 |
-
* Filter the array of form fields.
|
909 |
-
*
|
910 |
-
* The form fields are stored in the WP options table as wpmembers_fields. This
|
911 |
-
* filter can filter that array after the option is retreived before the fields
|
912 |
-
* are parsed. This allows you to change the fields that may be used in the form
|
913 |
-
* on the fly.
|
914 |
-
*
|
915 |
-
* @since 2.9.0
|
916 |
-
* @deprecated 3.1.7 Use wpmem_fields instead.
|
917 |
-
*
|
918 |
-
* @param array The array of form fields.
|
919 |
-
* @param string $tag Toggle new registration or profile update. new|edit.
|
920 |
-
*/
|
921 |
-
$wpmem_fields = apply_filters( 'wpmem_register_fields_arr', $wpmem_fields, $tag );
|
922 |
-
|
923 |
-
$hidden_rows = array();
|
924 |
-
|
925 |
-
// Loop through the remaining fields.
|
926 |
-
foreach ( $wpmem_fields as $meta_key => $field ) {
|
927 |
-
|
928 |
-
// Start with a clean row.
|
929 |
-
$val = ''; $label = ''; $input = ''; $field_before = ''; $field_after = '';
|
930 |
-
|
931 |
-
// If the field is set to display and we aren't skipping, construct the row.
|
932 |
-
// if ( ( 'new' == $tag && $field['register'] ) || ( 'edit' == $tag && $field['profile'] ) ) { // @todo Wait for profile fix
|
933 |
-
if ( $field['register'] ) {
|
934 |
-
|
935 |
-
// Handle hidden fields
|
936 |
-
if ( 'hidden' == $field['type'] ) {
|
937 |
-
$do_row = false;
|
938 |
-
$hidden_rows[ $meta_key ] = wpmem_form_field( array(
|
939 |
-
'name' => $meta_key,
|
940 |
-
'type' => $field['type'],
|
941 |
-
'value' => $field['value'],
|
942 |
-
'compare' => $valtochk,
|
943 |
-
'required' => $field['required'],
|
944 |
-
) );
|
945 |
-
}
|
946 |
-
|
947 |
-
// Label for all but TOS and hidden fields.
|
948 |
-
if ( 'tos' != $meta_key && 'hidden' != $field['type'] ) {
|
949 |
-
|
950 |
-
$class = ( $field['type'] == 'password' || $field['type'] == 'email' || $field['type'] == 'url' ) ? 'text' : $field['type'];
|
951 |
-
|
952 |
-
$label = wpmem_form_label( array(
|
953 |
-
'meta_key' => $meta_key, //( 'username' == $meta_key ) ? 'user_login' : $meta_key,
|
954 |
-
'label' => __( $field['label'], 'wp-members' ),
|
955 |
-
'type' => $field['type'],
|
956 |
-
'class' => $class,
|
957 |
-
'required' => $field['required'],
|
958 |
-
'req_mark' => $args['req_mark']
|
959 |
-
) );
|
960 |
-
|
961 |
-
}
|
962 |
-
|
963 |
-
// Gets the field value for edit profile.
|
964 |
-
if ( ( 'edit' == $tag ) && ( '' == $wpmem->regchk ) ) {
|
965 |
-
switch ( $meta_key ) {
|
966 |
-
case( 'description' ):
|
967 |
-
case( 'textarea' == $field['type'] ):
|
968 |
-
$val = get_user_meta( $userdata->ID, $meta_key, 'true' ); // esc_textarea() is run when field is created.
|
969 |
-
break;
|
970 |
-
|
971 |
-
case 'user_email':
|
972 |
-
case 'confirm_email':
|
973 |
-
$val = sanitize_email( $userdata->user_email );
|
974 |
-
break;
|
975 |
-
|
976 |
-
case 'user_url':
|
977 |
-
$val = $userdata->user_url; // esc_url() is run when the field is created.
|
978 |
-
break;
|
979 |
-
|
980 |
-
case 'display_name':
|
981 |
-
$val = sanitize_text_field( $userdata->display_name );
|
982 |
-
break;
|
983 |
-
|
984 |
-
default:
|
985 |
-
$val = sanitize_text_field( get_user_meta( $userdata->ID, $meta_key, 'true' ) );
|
986 |
-
break;
|
987 |
-
}
|
988 |
-
|
989 |
-
} else {
|
990 |
-
if ( 'file' == $field['type'] ) {
|
991 |
-
$val = ( isset( $_FILES[ $meta_key ]['name'] ) ) ? sanitize_file_name( $_FILES[ $meta_key ]['name'] ) : '' ;
|
992 |
-
} else {
|
993 |
-
$val = ( isset( $_POST[ $meta_key ] ) ) ? $this->sanitize_field( $_POST[ $meta_key ], $field['type'] ) : '';
|
994 |
-
}
|
995 |
-
}
|
996 |
-
|
997 |
-
// Does the tos field.
|
998 |
-
if ( 'tos' == $meta_key ) {
|
999 |
-
|
1000 |
-
// $val = sanitize_text_field( wpmem_get( $meta_key, '' ) );
|
1001 |
-
|
1002 |
-
// Should be checked by default? and only if form hasn't been submitted.
|
1003 |
-
$val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val;
|
1004 |
-
$input = wpmem_form_field( array(
|
1005 |
-
'name' => $meta_key,
|
1006 |
-
'type' => $field['type'],
|
1007 |
-
'value' => $field['checked_value'],
|
1008 |
-
'compare' => $val,
|
1009 |
-
'required' => $field['required'],
|
1010 |
-
) );
|
1011 |
-
$input = ( $field['required'] ) ? $input . $args['req_mark'] : $input;
|
1012 |
-
|
1013 |
-
// Determine if TOS is a WP page or not.
|
1014 |
-
$tos_content = stripslashes( get_option( 'wpmembers_tos' ) );
|
1015 |
-
if ( has_shortcode( $tos_content, 'wpmem_tos' ) || has_shortcode( $tos_content, 'wp-members' ) ) {
|
1016 |
-
$tos_link_url = do_shortcode( $tos_content );
|
1017 |
-
$tos_link_tag = '<a href="' . esc_url( $tos_link_url ) . '" target="_blank">';
|
1018 |
-
} else {
|
1019 |
-
$tos_link_url = add_query_arg( 'tos', 'display' );
|
1020 |
-
$tos_link_tag = "<a href=\"#\" onClick=\"window.open('" . $tos_link_url . "','tos');\">";
|
1021 |
-
}
|
1022 |
-
|
1023 |
-
/**
|
1024 |
-
* Filter the TOS link.
|
1025 |
-
*
|
1026 |
-
* @since 3.2.6
|
1027 |
-
*
|
1028 |
-
* @param string $tos_link_tag
|
1029 |
-
* @param string $tos_link_url
|
1030 |
-
*/
|
1031 |
-
$tos_link_tag = apply_filters( 'wpmem_tos_link_tag', $tos_link_tag, $tos_link_url );
|
1032 |
-
|
1033 |
-
/**
|
1034 |
-
* Filter the TOS link text.
|
1035 |
-
*
|
1036 |
-
* @since 2.7.5
|
1037 |
-
*
|
1038 |
-
* @param string The link text.
|
1039 |
-
* @param string $tag Toggle new registration or profile update. new|edit.
|
1040 |
-
*/
|
1041 |
-
$tos_link_text = apply_filters( 'wpmem_tos_link_txt', $wpmem->get_text( 'register_tos' ), $tag );
|
1042 |
-
|
1043 |
-
// If filtered value is not the default label, use that, otherwise use label.
|
1044 |
-
// @note: if default changes, this check must change.
|
1045 |
-
if ( __( 'Please indicate that you agree to the %s Terms of Service %s', 'wp-members' ) == $tos_link_text ) {
|
1046 |
-
if ( __( 'TOS', 'wp-members' ) != $field['label'] && __( 'Terms of Service', 'wp-members' ) != $field['label'] ) {
|
1047 |
-
$tos_link_text = $field['label'];
|
1048 |
-
}
|
1049 |
-
}
|
1050 |
-
|
1051 |
-
// If tos string does not contain link identifiers (%s), wrap the whole string.
|
1052 |
-
if ( ! strpos( $tos_link_text, '%s' ) ) {
|
1053 |
-
$tos_link_text = '%s' . $tos_link_text . '%s';
|
1054 |
-
}
|
1055 |
-
|
1056 |
-
$input .= ' ' . sprintf( $tos_link_text, $tos_link_tag, '</a>' );
|
1057 |
-
|
1058 |
-
// In previous versions, the div class would end up being the same as the row before.
|
1059 |
-
$field_before = ( $args['wrap_inputs'] ) ? '<div class="div_text">' : '';
|
1060 |
-
$field_after = ( $args['wrap_inputs'] ) ? '</div>' : '';
|
1061 |
-
|
1062 |
-
} elseif ( 'hidden' != $field['type'] ) {
|
1063 |
-
|
1064 |
-
// For checkboxes.
|
1065 |
-
if ( 'checkbox' == $field['type'] ) {
|
1066 |
-
$valtochk = $val;
|
1067 |
-
$val = $field['checked_value'];
|
1068 |
-
// if it should it be checked by default (& only if form not submitted), then override above...
|
1069 |
-
if ( $field['checked_default'] && ( ! $_POST && $tag != 'edit' ) ) {
|
1070 |
-
$val = $valtochk = $field['checked_value'];
|
1071 |
-
}
|
1072 |
-
}
|
1073 |
-
|
1074 |
-
// For dropdown select.
|
1075 |
-
if ( $field['type'] == 'select' || $field['type'] == 'radio' || $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' ) {
|
1076 |
-
$valtochk = $val;
|
1077 |
-
$val = $field['values'];
|
1078 |
-
}
|
1079 |
-
|
1080 |
-
if ( ! isset( $valtochk ) ) {
|
1081 |
-
$valtochk = '';
|
1082 |
-
}
|
1083 |
-
|
1084 |
-
if ( 'edit' == $tag && ( 'file' == $field['type'] || 'image' == $field['type'] ) ) {
|
1085 |
-
|
1086 |
-
$attachment_url = wp_get_attachment_url( $val );
|
1087 |
-
$empty_file = '<span class="description">' . __( 'None' ) . '</span>';
|
1088 |
-
if ( 'file' == $field['type'] ) {
|
1089 |
-
$input = ( $attachment_url ) ? '<a href="' . esc_url( $attachment_url ) . '">' . get_the_title( $val ) . '</a>' : $empty_file;
|
1090 |
-
} else {
|
1091 |
-
$input = ( $attachment_url ) ? '<img src="' . esc_url( $attachment_url ) . '">' : $empty_file;
|
1092 |
-
}
|
1093 |
-
$input.= '<br />' . $wpmem->get_text( 'profile_upload' ) . '<br />';
|
1094 |
-
$input.= wpmem_form_field( array(
|
1095 |
-
'name' => $meta_key,
|
1096 |
-
'type' => $field['type'],
|
1097 |
-
'value' => $val,
|
1098 |
-
'compare' => $valtochk,
|
1099 |
-
'file_types' => $field['file_types'],
|
1100 |
-
) );
|
1101 |
-
|
1102 |
-
} else {
|
1103 |
-
|
1104 |
-
// For all other input types.
|
1105 |
-
$formfield_args = array(
|
1106 |
-
'name' => $meta_key, // ( 'username' == $meta_key ) ? 'user_login' : $meta_key,
|
1107 |
-
'type' => $field['type'],
|
1108 |
-
'value' => $val,
|
1109 |
-
'compare' => $valtochk,
|
1110 |
-
//'class' => ( $class ) ? $class : 'textbox',
|
1111 |
-
'required' => $field['required'],
|
1112 |
-
'placeholder' => ( isset( $field['placeholder'] ) ) ? $field['placeholder'] : '',
|
1113 |
-
'pattern' => ( isset( $field['pattern'] ) ) ? $field['pattern'] : false,
|
1114 |
-
'title' => ( isset( $field['title'] ) ) ? $field['title'] : false,
|
1115 |
-
'min' => ( isset( $field['min'] ) ) ? $field['min'] : false,
|
1116 |
-
'max' => ( isset( $field['max'] ) ) ? $field['max'] : false,
|
1117 |
-
'rows' => ( isset( $field['rows'] ) ) ? $field['rows'] : false,
|
1118 |
-
'cols' => ( isset( $field['cols'] ) ) ? $field['cols'] : false,
|
1119 |
-
'file_types' => ( isset( $field['file_types'] ) ) ? $field['file_types'] : false,
|
1120 |
-
);
|
1121 |
-
if ( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
|
1122 |
-
$formfield_args['delimiter'] = $field['delimiter'];
|
1123 |
-
}
|
1124 |
-
$input = wpmem_form_field( $formfield_args );
|
1125 |
-
|
1126 |
-
}
|
1127 |
-
|
1128 |
-
// Determine input wrappers.
|
1129 |
-
$field_before = ( $args['wrap_inputs'] ) ? '<div class="div_' . $class . '">' : '';
|
1130 |
-
$field_after = ( $args['wrap_inputs'] ) ? '</div>' : '';
|
1131 |
-
}
|
1132 |
-
|
1133 |
-
}
|
1134 |
-
|
1135 |
-
// If the row is set to display, add the row to the form array.
|
1136 |
-
if ( ( 'new' == $tag && $field['register'] ) || ( 'edit' == $tag && $field['profile'] ) ) {
|
1137 |
-
//if ( $field['register'] && 'hidden' != $field['type'] ) {
|
1138 |
-
if ( 'hidden' != $field['type'] ) {
|
1139 |
-
|
1140 |
-
$values = '';
|
1141 |
-
if ( 'multicheckbox' == $field['type'] || 'select' == $field['type'] || 'multiselect' == $field['type'] || 'radio' == $field['type'] ) {
|
1142 |
-
$values = $val;
|
1143 |
-
$val = $valtochk;
|
1144 |
-
}
|
1145 |
-
|
1146 |
-
$rows[ $meta_key ] = array(
|
1147 |
-
'meta' => $meta_key,
|
1148 |
-
'type' => $field['type'],
|
1149 |
-
'value' => $val,
|
1150 |
-
'values' => $values,
|
1151 |
-
'label_text' => __( $field['label'], 'wp-members' ),
|
1152 |
-
'row_before' => $args['row_before'],
|
1153 |
-
'label' => $label,
|
1154 |
-
'field_before' => $field_before,
|
1155 |
-
'field' => $input,
|
1156 |
-
'field_after' => $field_after,
|
1157 |
-
'row_after' => $args['row_after'],
|
1158 |
-
);
|
1159 |
-
}
|
1160 |
-
}
|
1161 |
-
}
|
1162 |
-
|
1163 |
-
// If captcha is Really Simple CAPTCHA.
|
1164 |
-
if ( $wpmem->captcha == 2 && $tag != 'edit' ) {
|
1165 |
-
// Include captcha functions.
|
1166 |
-
require_once( $wpmem->path . 'includes/class-wp-members-captcha.php' );
|
1167 |
-
// Build the captcha.
|
1168 |
-
$row = WP_Members_Captcha::rs_captcha();
|
1169 |
-
$rows['captcha'] = array(
|
1170 |
-
'meta' => '',
|
1171 |
-
'type' => 'text',
|
1172 |
-
'value' => '',
|
1173 |
-
'values' => '',
|
1174 |
-
'label_text' => $row['label_text'],
|
1175 |
-
'row_before' => $args['row_before'],
|
1176 |
-
'label' => $row['label'],
|
1177 |
-
'field_before' => ( $args['wrap_inputs'] ) ? '<div class="div_text">' : '',
|
1178 |
-
'field' => $row['field'],
|
1179 |
-
'field_after' => ( $args['wrap_inputs'] ) ? '</div>' : '',
|
1180 |
-
'row_after' => $args['row_after'],
|
1181 |
-
);
|
1182 |
-
}
|
1183 |
-
|
1184 |
-
/**
|
1185 |
-
* Filter the array of form rows.
|
1186 |
-
*
|
1187 |
-
* This filter receives an array of the main rows in the form, each array element being
|
1188 |
-
* an array of that particular row's pieces. This allows making changes to individual
|
1189 |
-
* parts of a row without needing to parse through a string of HTML.
|
1190 |
-
*
|
1191 |
-
* @since 2.9.0
|
1192 |
-
* @since 3.0.9 Added $rows['label_text'].
|
1193 |
-
* @since 3.1.0 Added $rows['key'].
|
1194 |
-
* @since 3.1.6 Deprecated $rows['order'].
|
1195 |
-
*
|
1196 |
-
* @param array $rows {
|
1197 |
-
* An array containing the form rows.
|
1198 |
-
*
|
1199 |
-
* @type string order Field display order. (deprecated as of 3.1.6)
|
1200 |
-
* @type string meta Field meta tag (not used for display).
|
1201 |
-
* @type string type Input field type (not used for display).
|
1202 |
-
* @type string value Input field value (not used for display).
|
1203 |
-
* @type string values Possible field values (dropdown, multiple select/check, radio).
|
1204 |
-
* @type string label_text Raw text for the label (not used for display).
|
1205 |
-
* @type string row_before Opening wrapper tag around the row.
|
1206 |
-
* @type string label Label tag.
|
1207 |
-
* @type string field_before Opening wrapper tag before the input tag.
|
1208 |
-
* @type string field The field input tag.
|
1209 |
-
* @type string field_after Closing wrapper tag around the input tag.
|
1210 |
-
* @type string row_after Closing wrapper tag around the row.
|
1211 |
-
* }
|
1212 |
-
* @param string $tag Toggle new registration or profile update. new|edit.
|
1213 |
-
*/
|
1214 |
-
$rows = apply_filters( 'wpmem_register_form_rows', $rows, $tag );
|
1215 |
-
|
1216 |
-
// Make sure all keys are set just in case someone didn't return a proper array through the filter.
|
1217 |
-
// @todo Merge this with the next foreach loop so we only have to foreach one time.
|
1218 |
-
$row_keys = array( 'meta', 'type', 'value', 'values', 'label_text', 'row_before', 'label', 'field_before', 'field', 'field_after', 'row_after' );
|
1219 |
-
foreach ( $rows as $meta_key => $row ) {
|
1220 |
-
foreach ( $row_keys as $check_key ) {
|
1221 |
-
$rows[ $meta_key ][ $check_key ] = ( isset( $rows[ $meta_key ][ $check_key ] ) ) ? $rows[ $meta_key ][ $check_key ] : '';
|
1222 |
-
}
|
1223 |
-
}
|
1224 |
-
|
1225 |
-
// Put the rows from the array into $form.
|
1226 |
-
$form = ''; $enctype = '';
|
1227 |
-
foreach ( $rows as $row_item ) {
|
1228 |
-
// Check form to see if we need multipart enctype.
|
1229 |
-
$enctype = ( $row_item['type'] == 'file' || $row_item['type'] == 'image' ) ? "multipart/form-data" : $enctype;
|
1230 |
-
// Assemble row pieces.
|
1231 |
-
$row = ( $row_item['row_before'] != '' ) ? $row_item['row_before'] . $args['n'] . $row_item['label'] . $args['n'] : $row_item['label'] . $args['n'];
|
1232 |
-
$row .= ( $row_item['field_before'] != '' ) ? $row_item['field_before'] . $args['n'] . $args['t'] . $row_item['field'] . $args['n'] . $row_item['field_after'] . $args['n'] : $row_item['field'] . $args['n'];
|
1233 |
-
$row .= ( $row_item['row_after'] != '' ) ? $row_item['row_after'] . $args['n'] : '';
|
1234 |
-
$form.= $row;
|
1235 |
-
}
|
1236 |
-
|
1237 |
-
// Do recaptcha if enabled.
|
1238 |
-
if ( ( 1 == $wpmem->captcha || 3 == $wpmem->captcha || 4 == $wpmem->captcha ) && $tag != 'edit' ) { // don't show on edit page!
|
1239 |
-
|
1240 |
-
// Include captcha functions.
|
1241 |
-
require_once( $wpmem->path . 'includes/class-wp-members-captcha.php' );
|
1242 |
-
|
1243 |
-
// Get the captcha options.
|
1244 |
-
$wpmem_captcha = get_option( 'wpmembers_captcha' );
|
1245 |
-
|
1246 |
-
if ( 4 == $wpmem->captcha ) {
|
1247 |
-
|
1248 |
-
$row = '<script src="https://www.google.com/recaptcha/api.js?render=' . $wpmem_captcha['recaptcha']['public'] . '"></script>';
|
1249 |
-
$row.= "<script>
|
1250 |
-
grecaptcha.ready(function () {
|
1251 |
-
grecaptcha.execute('" . $wpmem_captcha['recaptcha']['public'] . "', { action: 'contact' }).then(function (token) {
|
1252 |
-
var recaptchaResponse = document.getElementById('recaptchaResponse');
|
1253 |
-
recaptchaResponse.value = token;
|
1254 |
-
});
|
1255 |
-
});
|
1256 |
-
</script>";
|
1257 |
-
$row.= '<input type="hidden" name="recaptcha_response" id="recaptchaResponse">';
|
1258 |
-
|
1259 |
-
} else {
|
1260 |
-
|
1261 |
-
// Start with a clean row.
|
1262 |
-
$row = '';
|
1263 |
-
$row = '<div class="clear"></div>';
|
1264 |
-
$row.= '<div class="captcha">';
|
1265 |
-
|
1266 |
-
$row.= WP_Members_Captcha::recaptcha( $wpmem_captcha['recaptcha'] );
|
1267 |
-
|
1268 |
-
$row.= '</div>';
|
1269 |
-
}
|
1270 |
-
|
1271 |
-
// Add the captcha row to the form.
|
1272 |
-
/**
|
1273 |
-
* Filter the HTML for the CAPTCHA row.
|
1274 |
-
*
|
1275 |
-
* @since 2.9.0
|
1276 |
-
*
|
1277 |
-
* @param string The HTML for the entire row (includes HTML tags plus reCAPTCHA).
|
1278 |
-
* @param string $tag Toggle new registration or profile update. new|edit.
|
1279 |
-
*/
|
1280 |
-
$form.= apply_filters( 'wpmem_register_captcha_row', $args['row_before'] . $row . $args['row_after'], $tag );
|
1281 |
-
}
|
1282 |
-
|
1283 |
-
// Create hidden fields.
|
1284 |
-
$var = ( $tag == 'edit' ) ? 'update' : 'register';
|
1285 |
-
$redirect_to = ( isset( $_REQUEST['redirect_to'] ) ) ? $_REQUEST['redirect_to'] : ( ( $redirect_to ) ? $redirect_to : get_permalink() );
|
1286 |
-
$hidden_rows['_wpmem_a'] = '<input name="a" type="hidden" value="' . esc_attr( $var ) . '" />';
|
1287 |
-
$hidden_rows['_wpmem_reg_page'] = '<input name="wpmem_reg_page" type="hidden" value="' . esc_url( get_permalink() ) . '" />';
|
1288 |
-
if ( $redirect_to != get_permalink() ) {
|
1289 |
-
$hidden_rows['_wpmem_redirect_to'] = '<input name="redirect_to" type="hidden" value="' . esc_url( $redirect_to ) . '" />';
|
1290 |
-
}
|
1291 |
-
|
1292 |
-
/**
|
1293 |
-
* Filter the hidden form rows.
|
1294 |
-
*
|
1295 |
-
* @since 3.2.0
|
1296 |
-
*
|
1297 |
-
* @param array $hidden_rows
|
1298 |
-
* @param string $tag
|
1299 |
-
*/
|
1300 |
-
$hidden_rows = apply_filters( 'wpmem_register_hidden_rows', $hidden_rows, $tag );
|
1301 |
-
|
1302 |
-
// Assemble hidden fields HTML.
|
1303 |
-
$hidden = '';
|
1304 |
-
foreach ( $hidden_rows as $hidden_row ) {
|
1305 |
-
$hidden .= $hidden_row . $args['n'];
|
1306 |
-
}
|
1307 |
-
|
1308 |
-
/**
|
1309 |
-
* Filter the hidden field HTML.
|
1310 |
-
*
|
1311 |
-
* @since 2.9.0
|
1312 |
-
*
|
1313 |
-
* @param string $hidden The generated HTML of hidden fields.
|
1314 |
-
* @param string $tag Toggle new registration or profile update. new|edit.
|
1315 |
-
*/
|
1316 |
-
$hidden = apply_filters( 'wpmem_register_hidden_fields', $hidden, $tag );
|
1317 |
-
|
1318 |
-
// Add the hidden fields to the form.
|
1319 |
-
$form.= $hidden;
|
1320 |
-
|
1321 |
-
// Create buttons and wrapper.
|
1322 |
-
$button_text = ( $tag == 'edit' ) ? $args['submit_update'] : $args['submit_register'];
|
1323 |
-
$button_html = array(
|
1324 |
-
'reset' => ( $args['show_clear_form'] ) ? '<input name="reset" type="reset" value="' . esc_attr( $args['clear_form'] ) . '" class="' . $this->sanitize_class( $args['button_class'] ) . '" /> ' : '',
|
1325 |
-
'submit' => '<input name="submit" type="submit" value="' . esc_attr( $button_text ) . '" class="' . $this->sanitize_class( $args['button_class'] ) . '" />',
|
1326 |
-
);
|
1327 |
-
$buttons = $button_html['reset'] . $args['n'] . $button_html['submit'] . $args['n'];
|
1328 |
-
|
1329 |
-
/**
|
1330 |
-
* Filter the HTML for form buttons.
|
1331 |
-
*
|
1332 |
-
* The string passed through the filter includes the buttons, as well as the HTML wrapper elements.
|
1333 |
-
*
|
1334 |
-
* @since 2.9.0
|
1335 |
-
* @since 3.2.6 Added $button_html parameter
|
1336 |
-
*
|
1337 |
-
* @param string $buttons The generated HTML of the form buttons.
|
1338 |
-
* @param string $tag Toggle new registration or profile update. new|edit.
|
1339 |
-
* @param array $button_html The individual button html.
|
1340 |
-
*/
|
1341 |
-
$buttons = apply_filters( 'wpmem_register_form_buttons', $buttons, $tag, $button_html );
|
1342 |
-
|
1343 |
-
// Add the buttons to the form.
|
1344 |
-
$form.= $args['buttons_before'] . $args['n'] . $buttons . $args['buttons_after'] . $args['n'];
|
1345 |
-
|
1346 |
-
// Add the required field notation to the bottom of the form.
|
1347 |
-
$form.= $args['req_label_before'] . $args['req_label'] . $args['req_label_after'];
|
1348 |
-
|
1349 |
-
// Apply the heading.
|
1350 |
-
if ( 'edit' == $tag ) {
|
1351 |
-
/**
|
1352 |
-
* Filter the default heading in User Profile edit mode.
|
1353 |
-
*
|
1354 |
-
* @since 2.7.5
|
1355 |
-
* @since 3.3.0 Moved into main registration function (from profile shortcode).
|
1356 |
-
*
|
1357 |
-
* @param string The default edit mode heading.
|
1358 |
-
*/
|
1359 |
-
$heading = ( isset( $heading ) ) ? $headhing : apply_filters( 'wpmem_user_edit_heading', $wpmem->get_text( 'profile_heading' ) );
|
1360 |
-
} else {
|
1361 |
-
/**
|
1362 |
-
* Filter the registration form heading.
|
1363 |
-
*
|
1364 |
-
* @since 2.8.2
|
1365 |
-
*
|
1366 |
-
* @param string $str
|
1367 |
-
* @param string $tag Toggle new registration or profile update. new|edit.
|
1368 |
-
*/
|
1369 |
-
$heading = ( isset( $heading ) ) ? $headhing : apply_filters( 'wpmem_register_heading', $wpmem->get_text( 'register_heading' ), $tag );
|
1370 |
-
}
|
1371 |
-
$form = $args['heading_before'] . $heading . $args['heading_after'] . $args['n'] . $form;
|
1372 |
-
|
1373 |
-
// Apply fieldset wrapper.
|
1374 |
-
$form = $args['fieldset_before'] . $args['n'] . $form . $args['n'] . $args['fieldset_after'];
|
1375 |
-
|
1376 |
-
// Apply attribution if enabled.
|
1377 |
-
$form = $form . $this->attribution();
|
1378 |
-
|
1379 |
-
// Apply nonce. Nonce uses $tag value of the form processor, NOT the form builder.
|
1380 |
-
$nonce = ( $tag == 'edit' ) ? 'update' : 'register';
|
1381 |
-
$form = wp_nonce_field( 'wpmem_longform_nonce', '_wpmem_' . $nonce . '_nonce', true, false ) . $args['n'] . $form;
|
1382 |
-
|
1383 |
-
// Apply form wrapper.
|
1384 |
-
$enctype = ( $enctype == 'multipart/form-data' ) ? ' enctype="multipart/form-data"' : '';
|
1385 |
-
$form = '<form name="form" method="post"' . $enctype . ' action="' . esc_attr( $args['post_to'] ) . '" id="' . $this->sanitize_class( $args['form_id'] ) . '" class="' . $this->sanitize_class( $args['form_class'] ) . '">' . $args['n'] . $form . $args['n'] . '</form>';
|
1386 |
-
|
1387 |
-
// Apply anchor.
|
1388 |
-
$form = '<a id="register"></a>' . $args['n'] . $form;
|
1389 |
-
|
1390 |
-
// Apply main div wrapper.
|
1391 |
-
$form = $args['main_div_before'] . $args['n'] . $form . $args['n'] . $args['main_div_after'] . $args['n'];
|
1392 |
-
|
1393 |
-
// Apply wpmem_txt wrapper.
|
1394 |
-
$form = $args['txt_before'] . $form . $args['txt_after'];
|
1395 |
-
|
1396 |
-
// Remove line breaks if enabled for easier filtering later.
|
1397 |
-
$form = ( $args['strip_breaks'] ) ? $this->strip_breaks( $form, $rows ) : $form; //str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form ) : $form;
|
1398 |
-
|
1399 |
-
/**
|
1400 |
-
* Filter the generated HTML of the entire form.
|
1401 |
-
*
|
1402 |
-
* @since 2.7.4
|
1403 |
-
*
|
1404 |
-
* @param string $form The HTML of the final generated form.
|
1405 |
-
* @param string $tag Toggle new registration or profile update. new|edit.
|
1406 |
-
* @param array $rows {
|
1407 |
-
* An array containing the form rows.
|
1408 |
-
*
|
1409 |
-
* @type string order Field display order.
|
1410 |
-
* @type string meta Field meta tag (not used for display).
|
1411 |
-
* @type string type Input field type (not used for display).
|
1412 |
-
* @type string value Input field value (not used for display).
|
1413 |
-
* @type string values The possible values for the field (dropdown, multiple select/checkbox, radio group).
|
1414 |
-
* @type string label_text Raw text for the label (not used for display).
|
1415 |
-
* @type string row_before Opening wrapper tag around the row.
|
1416 |
-
* @type string label Label tag.
|
1417 |
-
* @type string field_before Opening wrapper tag before the input tag.
|
1418 |
-
* @type string field The field input tag.
|
1419 |
-
* @type string field_after Closing wrapper tag around the input tag.
|
1420 |
-
* @type string row_after Closing wrapper tag around the row.
|
1421 |
-
* }
|
1422 |
-
* @param string $hidden The HTML string of hidden fields
|
1423 |
-
*/
|
1424 |
-
$form = apply_filters( 'wpmem_register_form', $form, $tag, $rows, $hidden );
|
1425 |
-
|
1426 |
-
/**
|
1427 |
-
* Filter before the form.
|
1428 |
-
*
|
1429 |
-
* This rarely used filter allows you to stick any string onto the front of
|
1430 |
-
* the generated form.
|
1431 |
-
*
|
1432 |
-
* @since 2.7.4
|
1433 |
-
*
|
1434 |
-
* @param string $str The HTML to add before the form. Default null.
|
1435 |
-
* @param string $tag Toggle new registration or profile update. new|edit.
|
1436 |
-
*/
|
1437 |
-
$form = apply_filters( 'wpmem_register_form_before', '', $tag ) . $form;
|
1438 |
-
|
1439 |
-
// Return the generated form.
|
1440 |
-
return $form;
|
1441 |
-
} // End register_form().
|
1442 |
-
|
1443 |
-
/**
|
1444 |
-
* Strip line breaks from form.
|
1445 |
-
*
|
1446 |
-
* Function removes line breaks and tabs. Checks for textarea fields
|
1447 |
-
* before stripping line breaks.
|
1448 |
-
*
|
1449 |
-
* @since 3.1.8
|
1450 |
-
*
|
1451 |
-
* @param string $form
|
1452 |
-
* @param array $rows
|
1453 |
-
* @return string $form
|
1454 |
-
*/
|
1455 |
-
function strip_breaks( $form, $rows ) {
|
1456 |
-
foreach( $rows as $key => $row ) {
|
1457 |
-
if ( 'textarea' == $row['type'] ) {
|
1458 |
-
$textareas[ $key ] = $row['field'];
|
1459 |
-
}
|
1460 |
-
}
|
1461 |
-
$form = str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form );
|
1462 |
-
if ( ! empty ( $textareas ) ) {
|
1463 |
-
foreach ( $textareas as $textarea ) {
|
1464 |
-
$stripped = str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $textarea );
|
1465 |
-
$form = str_replace( $stripped, $textarea, $form );
|
1466 |
-
}
|
1467 |
-
}
|
1468 |
-
return $form;
|
1469 |
-
}
|
1470 |
-
|
1471 |
-
/**
|
1472 |
-
* Login Dialog.
|
1473 |
-
*
|
1474 |
-
* Loads the login form for user login.
|
1475 |
-
*
|
1476 |
-
* @since 1.8
|
1477 |
-
* @since 3.1.4 Global $wpmem_regchk no longer needed.
|
1478 |
-
* @since 3.2.0 Moved to forms class, renamed do_login_form().
|
1479 |
-
*
|
1480 |
-
* @global object $post The WordPress Post object.
|
1481 |
-
* @global object $wpmem The WP_Members object.
|
1482 |
-
* @param string $page If the form is being displayed in place of blocked content. Default: page.
|
1483 |
-
* @param string $redirect_to Redirect URL. Default: null.
|
1484 |
-
* @param string $show If the form is being displayed in place of blocked content. Default: show.
|
1485 |
-
* @return string $str The generated html for the login form.
|
1486 |
-
*/
|
1487 |
-
function do_login_form( $page = "page", $redirect_to = null, $show = 'show' ) {
|
1488 |
-
|
1489 |
-
global $post, $wpmem;
|
1490 |
-
|
1491 |
-
$msg = '';
|
1492 |
-
|
1493 |
-
if ( 'page' == $page ) {
|
1494 |
-
$msg = $this->add_restricted_msg();
|
1495 |
-
}
|
1496 |
-
|
1497 |
-
// Create the default inputs.
|
1498 |
-
$default_inputs = array(
|
1499 |
-
array(
|
1500 |
-
'name' => $wpmem->get_text( 'login_username' ),
|
1501 |
-
'type' => 'text',
|
1502 |
-
'tag' => 'log',
|
1503 |
-
'class' => 'username',
|
1504 |
-
'div' => 'div_text',
|
1505 |
-
),
|
1506 |
-
array(
|
1507 |
-
'name' => $wpmem->get_text( 'login_password' ),
|
1508 |
-
'type' => 'password',
|
1509 |
-
'tag' => 'pwd',
|
1510 |
-
'class' => 'password',
|
1511 |
-
'div' => 'div_text',
|
1512 |
-
),
|
1513 |
-
);
|
1514 |
-
|
1515 |
-
/**
|
1516 |
-
* Filter the array of login form fields.
|
1517 |
-
*
|
1518 |
-
* @since 2.9.0
|
1519 |
-
* @deprecated 3.3.0 Use wpmem_login_form_defaults instead.
|
1520 |
-
*
|
1521 |
-
* @param array $default_inputs An array matching the elements used by default.
|
1522 |
-
*/
|
1523 |
-
$default_inputs = apply_filters( 'wpmem_inc_login_inputs', $default_inputs );
|
1524 |
-
|
1525 |
-
$defaults = array(
|
1526 |
-
'heading' => $wpmem->get_text( 'login_heading' ),
|
1527 |
-
'action' => 'login',
|
1528 |
-
'button_text' => $wpmem->get_text( 'login_button' ),
|
1529 |
-
'inputs' => $default_inputs,
|
1530 |
-
'redirect_to' => $redirect_to,
|
1531 |
-
);
|
1532 |
-
|
1533 |
-
/**
|
1534 |
-
* Filter the arguments to override login form defaults.
|
1535 |
-
*
|
1536 |
-
* @since 2.9.0
|
1537 |
-
* @deprecated 3.3.0 Use wpmem_login_form_defaults instead.
|
1538 |
-
*
|
1539 |
-
* @param array $args An array of arguments to use. Default null.
|
1540 |
-
*/
|
1541 |
-
$args = apply_filters( 'wpmem_inc_login_args', '' );
|
1542 |
-
$arr = wp_parse_args( $args, $defaults );
|
1543 |
-
|
1544 |
-
/**
|
1545 |
-
* Filter the arguments to override login form defaults.
|
1546 |
-
*
|
1547 |
-
* @since 3.3.0
|
1548 |
-
*
|
1549 |
-
* @param array $args {
|
1550 |
-
* @type string $heading
|
1551 |
-
* @type string $action
|
1552 |
-
* @type string $button_text
|
1553 |
-
* @type string $redirect_to
|
1554 |
-
* @type array $inputs {
|
1555 |
-
* @type string $name
|
1556 |
-
* @type string $type
|
1557 |
-
* @type string $tag
|
1558 |
-
* @type string $class
|
1559 |
-
* @type string $div
|
1560 |
-
* }
|
1561 |
-
* }
|
1562 |
-
*/
|
1563 |
-
$arr = apply_filters( 'wpmem_login_form_defaults', $arr );
|
1564 |
-
|
1565 |
-
return ( $show == 'show' ) ? $msg . wpmem_login_form( $page, $arr ) : $msg;
|
1566 |
-
}
|
1567 |
-
|
1568 |
-
/**
|
1569 |
-
* Appends WP-Members registration fields to wp-login.php registration form.
|
1570 |
-
*
|
1571 |
-
* @since 2.8.7
|
1572 |
-
* @since 3.1.1 Updated to support new (3.1.0) field types.
|
1573 |
-
* @since 3.1.6 Updated to support new fields array. Added WC classes.
|
1574 |
-
* @since 3.1.8 Added $process parameter.
|
1575 |
-
* @since 3.3.0 Ported from wpmem_do_wp_register_form() in wp-registration.php.
|
1576 |
-
*
|
1577 |
-
* @global stdClass $wpmem
|
1578 |
-
* @param string $process
|
1579 |
-
*/
|
1580 |
-
function wp_register_form( $process = 'wp' ) {
|
1581 |
-
|
1582 |
-
global $wpmem;
|
1583 |
-
$wpmem_fields = wpmem_fields( $process );
|
1584 |
-
|
1585 |
-
// Check if this is WooCommerce account page.
|
1586 |
-
$is_woo = false;
|
1587 |
-
if ( 'woo' == $process ) {
|
1588 |
-
$is_woo = true;
|
1589 |
-
} else {
|
1590 |
-
if ( function_exists( 'is_account_page' ) ) {
|
1591 |
-
$is_woo = ( is_account_page() ) ? true : $is_woo;
|
1592 |
-
}
|
1593 |
-
}
|
1594 |
-
|
1595 |
-
if ( isset( $wpmem_fields ) && is_array( $wpmem_fields ) ) {
|
1596 |
-
|
1597 |
-
unset( $wpmem_fields['username'] );
|
1598 |
-
|
1599 |
-
foreach ( $wpmem_fields as $meta_key => $field ) {
|
1600 |
-
|
1601 |
-
$req = ( $field['required'] ) ? ( ( $is_woo ) ? ' <span class="required">*</span>' : ' <span class="req">' . __( '(required)' ) . '</span>' ) : '';
|
1602 |
-
|
1603 |
-
// File fields not yet supported for this form.
|
1604 |
-
if ( $field['register'] && $meta_key != 'user_email' && $field['type'] != 'file' && $field['type'] != 'image' ) {
|
1605 |
-
|
1606 |
-
if ( 'checkbox' == $field['type'] ) {
|
1607 |
-
|
1608 |
-
if ( 'tos' == $meta_key ) {
|
1609 |
-
$tos_content = stripslashes( get_option( 'wpmembers_tos' ) );
|
1610 |
-
if ( has_shortcode( $tos_content, 'wpmem_tos' ) || has_shortcode( $tos_content, 'wp-members' ) ) {
|
1611 |
-
$link = do_shortcode( $tos_content );
|
1612 |
-
$tos_pop = '<a href="' . esc_url( $link ) . '" target="_blank">';
|
1613 |
-
} else {
|
1614 |
-
$tos_pop = "<a href=\"#\" onClick=\"window.open('" . $wpmem->url . "/wp-members-tos.php','mywindow');\">";
|
1615 |
-
}
|
1616 |
-
/** This filter is documented in includes/class-wp-members-forms.php */
|
1617 |
-
$tos_link_text = apply_filters( 'wpmem_tos_link_txt', $wpmem->get_text( 'register_tos' ), 'new' );
|
1618 |
-
|
1619 |
-
// If filtered value is not the default label, use that, otherwise use label.
|
1620 |
-
// @note: if default changes, this check must change.
|
1621 |
-
if ( __( 'Please indicate that you agree to the %s Terms of Service %s', 'wp-members' ) == $tos_link_text ) {
|
1622 |
-
if ( __( 'TOS', 'wp-members' ) != $field['label'] && __( 'Terms of Service', 'wp-members' ) != $field['label'] ) {
|
1623 |
-
$tos_link_text = $field['label'];
|
1624 |
-
}
|
1625 |
-
}
|
1626 |
-
|
1627 |
-
// If tos string does not contain link identifiers (%s), wrap the whole string.
|
1628 |
-
if ( ! strpos( $tos_link_text, '%s' ) ) {
|
1629 |
-
$tos_link_text = '%s' . $tos_link_text . '%s';
|
1630 |
-
}
|
1631 |
-
|
1632 |
-
$tos_link_text = ' ' . sprintf( $tos_link_text, $tos_pop, '</a>' );
|
1633 |
-
|
1634 |
-
}
|
1635 |
-
|
1636 |
-
$label = ( 'tos' == $meta_key ) ? $tos_link_text : __( $field['label'], 'wp-members' );
|
1637 |
-
|
1638 |
-
$val = ( isset( $_POST[ $meta_key ] ) ) ? esc_attr( $_POST[ $meta_key ] ) : '';
|
1639 |
-
$val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val;
|
1640 |
-
|
1641 |
-
$row_before = '<p class="wpmem-checkbox">';
|
1642 |
-
$label = '<label for="' . $meta_key . '">' . $label . $req;
|
1643 |
-
$input = wpmem_form_field( $meta_key, $field['type'], $field['checked_value'], $val );
|
1644 |
-
$row_after = '</label></p>';
|
1645 |
-
|
1646 |
-
} elseif ( 'hidden' == $field['type'] ) {
|
1647 |
-
|
1648 |
-
// Handle hidden fields
|
1649 |
-
$row_before = '';
|
1650 |
-
$label = '';
|
1651 |
-
$input = wpmem_form_field( array(
|
1652 |
-
'name' => $meta_key,
|
1653 |
-
'type' => $field['type'],
|
1654 |
-
'value' => $field['value'],
|
1655 |
-
'compare' => $valtochk,
|
1656 |
-
'required' => $field['required'],
|
1657 |
-
) );
|
1658 |
-
$row_after = '';
|
1659 |
-
|
1660 |
-
} else {
|
1661 |
-
|
1662 |
-
$row_before = ( $is_woo ) ? '<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">' : '<p>';
|
1663 |
-
$label = '<label for="' . $meta_key . '">' . __( $field['label'], 'wp-members' ) . $req . '<br />';
|
1664 |
-
|
1665 |
-
// determine the field type and generate accordingly...
|
1666 |
-
|
1667 |
-
switch ( $field['type'] ) {
|
1668 |
-
|
1669 |
-
case( 'select' ):
|
1670 |
-
$val = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
|
1671 |
-
$input = wpmem_create_formfield( $meta_key, $field['type'], $field['values'], $val );
|
1672 |
-
break;
|
1673 |
-
|
1674 |
-
case( 'textarea' ):
|
1675 |
-
$input = '<textarea name="' . $meta_key . '" id="' . $meta_key . '" class="textarea">';
|
1676 |
-
$input.= ( isset( $_POST[ $meta_key ] ) ) ? esc_textarea( $_POST[ $meta_key ] ) : '';
|
1677 |
-
$input.= '</textarea>';
|
1678 |
-
break;
|
1679 |
-
|
1680 |
-
case( 'multiselect' ):
|
1681 |
-
case( 'multicheckbox' ):
|
1682 |
-
case( 'radio' ):
|
1683 |
-
$row_before = '<p class="' . $field['type'] . '">';
|
1684 |
-
$valtochk = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
|
1685 |
-
$formfield_args = array(
|
1686 |
-
'name' => $meta_key,
|
1687 |
-
'type' => $field['type'],
|
1688 |
-
'value' => $field['values'],
|
1689 |
-
'compare' => $valtochk,
|
1690 |
-
'required' => ( $field['required'] ) ? true : false,
|
1691 |
-
);
|
1692 |
-
if ( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
|
1693 |
-
$formfield_args['delimiter'] = $field['delimiter'];
|
1694 |
-
}
|
1695 |
-
$input = $this->create_form_field( $formfield_args );
|
1696 |
-
break;
|
1697 |
-
|
1698 |
-
case( 'file' ):
|
1699 |
-
case( 'image' ):
|
1700 |
-
// Field type not supported for this yet.
|
1701 |
-
break;
|
1702 |
-
|
1703 |
-
default:
|
1704 |
-
$class = ( $is_woo ) ? 'woocommerce-Input woocommerce-Input--text input-text' : 'input';
|
1705 |
-
//$input = '<input type="' . $field['type'] . '" name="' . $meta_key . '" id="' . $meta_key . '" class="' . $class . '" value="';
|
1706 |
-
$input = wpmem_form_field( array(
|
1707 |
-
'name' => $meta_key,
|
1708 |
-
'type' => $field['type'],
|
1709 |
-
'value' => $this->sanitize_field( wpmem_get( $meta_key, '' ), $field['type'] ),
|
1710 |
-
'compare' => ( isset( $field['compare'] ) ) ? $field['compare'] : '',
|
1711 |
-
'placeholder' => ( isset( $field['placeholder'] ) ) ? $field['placeholder'] : '',
|
1712 |
-
) );
|
1713 |
-
//$input.= ( isset( $_POST[ $meta_key ] ) ) ? esc_attr( $_POST[ $meta_key ] ) : '';
|
1714 |
-
//$input.= '" size="25" />';
|
1715 |
-
break;
|
1716 |
-
}
|
1717 |
-
|
1718 |
-
$row_after = '</label></p>';
|
1719 |
-
|
1720 |
-
}
|
1721 |
-
|
1722 |
-
// if the row is set to display, add the row to the form array
|
1723 |
-
$rows[ $meta_key ] = array(
|
1724 |
-
'type' => $field['type'],
|
1725 |
-
'row_before' => $row_before,
|
1726 |
-
'label' => $label,
|
1727 |
-
'field' => $input,
|
1728 |
-
'row_after' => $row_after,
|
1729 |
-
);
|
1730 |
-
}
|
1731 |
-
}
|
1732 |
-
|
1733 |
-
if ( isset( $rows ) && is_array( $rows ) ) {
|
1734 |
-
|
1735 |
-
/**
|
1736 |
-
* Filter the native registration form rows.
|
1737 |
-
*
|
1738 |
-
* @since 2.9.3.
|
1739 |
-
*
|
1740 |
-
* @param array $rows The custom rows added to the form.
|
1741 |
-
*/
|
1742 |
-
$rows = apply_filters( 'wpmem_native_form_rows', $rows );
|
1743 |
-
|
1744 |
-
foreach ( $rows as $row_item ) {
|
1745 |
-
if ( $row_item['type'] == 'checkbox' ) {
|
1746 |
-
echo $row_item['row_before'] . $row_item['field'] . $row_item['label'] . $row_item['row_after'];
|
1747 |
-
} else {
|
1748 |
-
echo $row_item['row_before'] . $row_item['label'] . $row_item['field'] . $row_item['row_after'];
|
1749 |
-
}
|
1750 |
-
}
|
1751 |
-
}
|
1752 |
-
}
|
1753 |
-
}
|
1754 |
-
|
1755 |
-
|
1756 |
-
/**
|
1757 |
-
* Appends WP-Members registration fields to Users > Add New User screen.
|
1758 |
-
*
|
1759 |
-
* @since 2.9.0
|
1760 |
-
* @since 3.1.1 Updated to support new (3.1.0) field types and user activation.
|
1761 |
-
* @since 3.1.6 Updated to support new fields array.
|
1762 |
-
* @since 3.3.0 Ported from wpmem_do_wp_newuser_form() in wp-registration.php.
|
1763 |
-
*
|
1764 |
-
* @global stdClass $wpmem
|
1765 |
-
*/
|
1766 |
-
function wp_newuser_form() {
|
1767 |
-
|
1768 |
-
global $wpmem;
|
1769 |
-
echo '<table class="form-table"><tbody>';
|
1770 |
-
|
1771 |
-
$wpmem_fields = wpmem_fields( 'add_new' );
|
1772 |
-
$exclude = wpmem_get_excluded_meta( 'wp-register' );
|
1773 |
-
|
1774 |
-
foreach ( $wpmem_fields as $meta_key => $field ) {
|
1775 |
-
|
1776 |
-
if ( ! $field['native'] && ! in_array( $meta_key, $exclude ) ) {
|
1777 |
-
|
1778 |
-
$req = ( $field['required'] ) ? ' <span class="description">' . __( '(required)' ) . '</span>' : '';
|
1779 |
-
|
1780 |
-
echo '<tr>
|
1781 |
-
<th scope="row">
|
1782 |
-
<label for="' . $meta_key . '">' . __( $field['label'], 'wp-members' ) . $req . '</label>
|
1783 |
-
</th>
|
1784 |
-
<td>';
|
1785 |
-
|
1786 |
-
// determine the field type and generate accordingly.
|
1787 |
-
|
1788 |
-
switch ( $field['type'] ) {
|
1789 |
-
|
1790 |
-
case( 'select' ):
|
1791 |
-
$val = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
|
1792 |
-
echo wpmem_create_formfield( $meta_key, $field['type'], $field['values'], $val );
|
1793 |
-
break;
|
1794 |
-
|
1795 |
-
case( 'textarea' ):
|
1796 |
-
echo '<textarea name="' . $meta_key . '" id="' . $meta_key . '" class="textarea">';
|
1797 |
-
echo ( isset( $_POST[ $meta_key ] ) ) ? esc_textarea( $_POST[ $meta_key ] ) : '';
|
1798 |
-
echo '</textarea>';
|
1799 |
-
break;
|
1800 |
-
|
1801 |
-
case( 'checkbox' ):
|
1802 |
-
$val = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
|
1803 |
-
$val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val;
|
1804 |
-
echo wpmem_create_formfield( $meta_key, $field['type'], $field['checked_value'], $val );
|
1805 |
-
break;
|
1806 |
-
|
1807 |
-
case( 'multiselect' ):
|
1808 |
-
case( 'multicheckbox' ):
|
1809 |
-
case( 'radio' ):
|
1810 |
-
$valtochk = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
|
1811 |
-
$formfield_args = array(
|
1812 |
-
'name' => $meta_key,
|
1813 |
-
'type' => $field['type'],
|
1814 |
-
'value' => $field['values'],
|
1815 |
-
'compare' => $valtochk,
|
1816 |
-
'required' => $field['required'],
|
1817 |
-
);
|
1818 |
-
if ( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
|
1819 |
-
$formfield_args['delimiter'] = $field['delimiter'];
|
1820 |
-
}
|
1821 |
-
echo $this->create_form_field( $formfield_args );
|
1822 |
-
break;
|
1823 |
-
|
1824 |
-
case( 'file' ):
|
1825 |
-
case( 'image' ):
|
1826 |
-
break;
|
1827 |
-
|
1828 |
-
default:
|
1829 |
-
echo '<input type="' . $field['type'] . '" name="' . $meta_key . '" id="' . $meta_key . '" class="input" value="'; echo ( isset( $_POST[ $meta_key ] ) ) ? esc_attr( $_POST[ $meta_key ] ) : ''; echo '" size="25" />';
|
1830 |
-
break;
|
1831 |
-
}
|
1832 |
-
|
1833 |
-
echo '</td>
|
1834 |
-
</tr>';
|
1835 |
-
|
1836 |
-
}
|
1837 |
-
}
|
1838 |
-
|
1839 |
-
// If moderated registration is enabled, add checkbox to set user as active.
|
1840 |
-
if ( 1 == $wpmem->mod_reg ) {
|
1841 |
-
echo '<tr>
|
1842 |
-
<th scope="row">
|
1843 |
-
<label for="activate_user">' . __( 'Activate this user?', 'wp-members' ) . '</label>
|
1844 |
-
</th>
|
1845 |
-
<td>' . $this->create_form_field( array( 'name' => 'activate_user', 'type' => 'checkbox', 'value' => 1, 'compare' => '' ) ) . '</td>
|
1846 |
-
</tr>';
|
1847 |
-
}
|
1848 |
-
|
1849 |
-
echo '</tbody></table>';
|
1850 |
-
|
1851 |
-
}
|
1852 |
-
|
1853 |
-
/**
|
1854 |
-
* Create an attribution link in the form.
|
1855 |
-
*
|
1856 |
-
* @since 2.6.0
|
1857 |
-
* @since 3.1.1 Updated to use new object setting.
|
1858 |
-
* @since 3.3.0 Ported from wpmem_inc_attribution() in forms.php.
|
1859 |
-
*
|
1860 |
-
* @global object $wpmem
|
1861 |
-
* @return string $str
|
1862 |
-
*/
|
1863 |
-
function attribution() {
|
1864 |
-
|
1865 |
-
global $wpmem;
|
1866 |
-
$str = '
|
1867 |
-
<div align="center">
|
1868 |
-
<small>Powered by <a href="https://rocketgeek.com" target="_blank">WP-Members</a></small>
|
1869 |
-
</div>';
|
1870 |
-
|
1871 |
-
return ( 1 == $wpmem->attrib ) ? $str : '';
|
1872 |
-
}
|
1873 |
-
|
1874 |
-
/**
|
1875 |
-
* Settings for building Short Form (login).
|
1876 |
-
*
|
1877 |
-
* Replaces individual legacy functions and filters for
|
1878 |
-
* the short forms, combined into a single method.
|
1879 |
-
*
|
1880 |
-
* @since 3.3.0
|
1881 |
-
*
|
1882 |
-
* @global stdClass $post
|
1883 |
-
* @global stdClass $wpmem
|
1884 |
-
*
|
1885 |
-
* @param string $form login|changepassword|resetpassword|forgotusername
|
1886 |
-
* @return string $form
|
1887 |
-
*/
|
1888 |
-
function do_shortform( $form, $page = "page", $redirect_to = null, $show = 'show' ) {
|
1889 |
-
|
1890 |
-
global $post, $wpmem;
|
1891 |
-
|
1892 |
-
$msg = '';
|
1893 |
-
|
1894 |
-
if ( "login" == $form && "page" == $page ) {
|
1895 |
-
$msg = $this->add_restricted_msg();
|
1896 |
-
}
|
1897 |
-
|
1898 |
-
$input_arrays = array(
|
1899 |
-
'login' => array(
|
1900 |
-
array(
|
1901 |
-
'name' => $wpmem->get_text( 'login_username' ),
|
1902 |
-
'type' => 'text',
|
1903 |
-
'tag' => 'log',
|
1904 |
-
'class' => 'username',
|
1905 |
-
'div' => 'div_text',
|
1906 |
-
),
|
1907 |
-
array(
|
1908 |
-
'name' => $wpmem->get_text( 'login_password' ),
|
1909 |
-
'type' => 'password',
|
1910 |
-
'tag' => 'pwd',
|
1911 |
-
'class' => 'password',
|
1912 |
-
'div' => 'div_text',
|
1913 |
-
),
|
1914 |
-
),
|
1915 |
-
'changepassword' => array(
|
1916 |
-
array(
|
1917 |
-
'name' => $wpmem->get_text( 'pwdchg_password1' ),
|
1918 |
-
'type' => 'password',
|
1919 |
-
'tag' => 'pass1',
|
1920 |
-
'class' => 'password',
|
1921 |
-
'div' => 'div_text',
|
1922 |
-
),
|
1923 |
-
array(
|
1924 |
-
'name' => $wpmem->get_text( 'pwdchg_password2' ),
|
1925 |
-
'type' => 'password',
|
1926 |
-
'tag' => 'pass2',
|
1927 |
-
'class' => 'password',
|
1928 |
-
'div' => 'div_text',
|
1929 |
-
),
|
1930 |
-
),
|
1931 |
-
'resetpassword' => array(
|
1932 |
-
array(
|
1933 |
-
'name' => $wpmem->get_text( 'pwdreset_username' ),
|
1934 |
-
'type' => 'text',
|
1935 |
-
'tag' => 'user',
|
1936 |
-
'class' => 'username',
|
1937 |
-
'div' => 'div_text',
|
1938 |
-
),
|
1939 |
-
array(
|
1940 |
-
'name' => $wpmem->get_text( 'pwdreset_email' ),
|
1941 |
-
'type' => 'text',
|
1942 |
-
'tag' => 'email',
|
1943 |
-
'class' => 'text',
|
1944 |
-
'div' => 'div_text',
|
1945 |
-
),
|
1946 |
-
),
|
1947 |
-
'forgotusername' => array(
|
1948 |
-
array(
|
1949 |
-
'name' => $wpmem->get_text( 'username_email' ),
|
1950 |
-
'type' => 'text',
|
1951 |
-
'tag' => 'user_email',
|
1952 |
-
'class' => 'username',
|
1953 |
-
'div' => 'div_text',
|
1954 |
-
),
|
1955 |
-
),
|
1956 |
-
);
|
1957 |
-
|
1958 |
-
/**
|
1959 |
-
* Filter the array of change password form fields.
|
1960 |
-
*
|
1961 |
-
* @since 2.9.0
|
1962 |
-
* @deprecated 3.3.0 Use wpmem_{$form}_form_defaults instead.
|
1963 |
-
*
|
1964 |
-
* @param array $default_inputs An array matching the elements used by default.
|
1965 |
-
*/
|
1966 |
-
$default_inputs = apply_filters( 'wpmem_inc_' . $form . '_inputs', $input_arrays[ $form ] );
|
1967 |
-
|
1968 |
-
$form_arrays = array(
|
1969 |
-
'login' => array(
|
1970 |
-
'heading' => $wpmem->get_text( 'login_heading' ),
|
1971 |
-
'action' => 'login',
|
1972 |
-
'button_text' => $wpmem->get_text( 'login_button' ),
|
1973 |
-
'inputs' => $default_inputs,
|
1974 |
-
'redirect_to' => $redirect_to,
|
1975 |
-
),
|
1976 |
-
'changepassword' => array(
|
1977 |
-
'heading' => $wpmem->get_text( 'pwdchg_heading' ),
|
1978 |
-
'action' => 'pwdchange',
|
1979 |
-
'button_text' => $wpmem->get_text( 'pwdchg_button' ),
|
1980 |
-
'inputs' => $default_inputs,
|
1981 |
-
),
|
1982 |
-
'resetpassword' => array(
|
1983 |
-
'heading' => $wpmem->get_text( 'pwdreset_heading' ),
|
1984 |
-
'action' => 'pwdreset',
|
1985 |
-
'button_text' => $wpmem->get_text( 'pwdreset_button' ),
|
1986 |
-
'inputs' => $default_inputs,
|
1987 |
-
),
|
1988 |
-
'forgotusername' => array(
|
1989 |
-
'heading' => $wpmem->get_text( 'username_heading' ),
|
1990 |
-
'action' => 'getusername',
|
1991 |
-
'button_text' => $wpmem->get_text( 'username_button' ),
|
1992 |
-
'inputs' => $default_inputs,
|
1993 |
-
),
|
1994 |
-
);
|
1995 |
-
|
1996 |
-
/**
|
1997 |
-
* Filter the arguments to override form defaults.
|
1998 |
-
*
|
1999 |
-
* @since 2.9.0
|
2000 |
-
* @deprecated 3.3.0 Use wpmem_inc_{$form}_defaults instead.
|
2001 |
-
*
|
2002 |
-
* @param array $args An array of arguments to use. Default null. (login|changepassword|resetpassword|forgotusername)
|
2003 |
-
*/
|
2004 |
-
$args = apply_filters( 'wpmem_inc_' . $form . '_args', '' );
|
2005 |
-
$arr = wp_parse_args( $args, $form_arrays[ $form ] );
|
2006 |
-
|
2007 |
-
/**
|
2008 |
-
* Filter the arguments to override change password form defaults.
|
2009 |
-
*
|
2010 |
-
* @since 3.3.0
|
2011 |
-
*
|
2012 |
-
* @param array $args An array of arguments to use. Default null. (login|changepassword|resetpassword|forgotusername)
|
2013 |
-
*/
|
2014 |
-
$arr = apply_filters( 'wpmem_' . $form . '_form_defaults', $arr );
|
2015 |
-
|
2016 |
-
return ( $show == 'show' ) ? $msg . $this->login_form( $page, $arr ) : $msg;
|
2017 |
-
}
|
2018 |
-
|
2019 |
-
/**
|
2020 |
-
* Applies the post restricted message above the short form.
|
2021 |
-
*
|
2022 |
-
* @since 3.3.0
|
2023 |
-
*
|
2024 |
-
* @global stdClass $wpmem
|
2025 |
-
*
|
2026 |
-
* @return string $str The generated message.
|
2027 |
-
*/
|
2028 |
-
private function add_restricted_msg() {
|
2029 |
-
|
2030 |
-
global $wpmem;
|
2031 |
-
|
2032 |
-
$str = '';
|
2033 |
-
|
2034 |
-
if ( $wpmem->regchk != "success" ) {
|
2035 |
-
|
2036 |
-
$dialogs = get_option( 'wpmembers_dialogs' );
|
2037 |
-
|
2038 |
-
// This shown above blocked content.
|
2039 |
-
$msg = $wpmem->get_text( 'restricted_msg' );
|
2040 |
-
$msg = ( $dialogs['restricted_msg'] == $msg ) ? $msg : __( stripslashes( $dialogs['restricted_msg'] ), 'wp-members' );
|
2041 |
-
$str = '<div id="wpmem_restricted_msg"><p>' . $msg . '</p></div>';
|
2042 |
-
|
2043 |
-
/**
|
2044 |
-
* Filter the post restricted message.
|
2045 |
-
*
|
2046 |
-
* @since 2.7.3
|
2047 |
-
* @since 3.2.0 Added raw message string and HTML as separate params.
|
2048 |
-
*
|
2049 |
-
* @param string $str The post restricted message with HTML.
|
2050 |
-
* @param string $msg The raw message string.
|
2051 |
-
* @param string The 'before' HTML wrapper.
|
2052 |
-
* @param string The 'after' HTML wrapper.
|
2053 |
-
*/
|
2054 |
-
$str = apply_filters( 'wpmem_restricted_msg', $str, $msg, '<div id="wpmem_restricted_msg"><p>', '</p></div>' );
|
2055 |
-
}
|
2056 |
-
|
2057 |
-
return $str;
|
2058 |
-
}
|
2059 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2060 |
} // End of WP_Members_Forms class.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The WP_Members Forms Class.
|
4 |
+
*
|
5 |
+
* @package WP-Members
|
6 |
+
* @subpackage WP_Members Forms Object Class
|
7 |
+
* @since 3.1.0
|
8 |
+
*/
|
9 |
+
|
10 |
+
// Exit if accessed directly.
|
11 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
12 |
+
exit();
|
13 |
+
}
|
14 |
+
|
15 |
+
class WP_Members_Forms {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Plugin initialization function.
|
19 |
+
*
|
20 |
+
* @since 3.1.0
|
21 |
+
*/
|
22 |
+
function __construct() {
|
23 |
+
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Creates form fields
|
28 |
+
*
|
29 |
+
* Creates various form fields and returns them as a string.
|
30 |
+
*
|
31 |
+
* @since 3.1.0
|
32 |
+
* @since 3.1.1 Added $delimiter.
|
33 |
+
* @since 3.1.2 Changed $valtochk to $compare.
|
34 |
+
* @since 3.1.6 Added $placeholder.
|
35 |
+
* @since 3.1.7 Added number type & $min, $max, $title and $pattern attributes.
|
36 |
+
* @since 3.2.0 Added $id argument.
|
37 |
+
* @since 3.2.4 Added radio group and multiple checkbox individual item labels.
|
38 |
+
*
|
39 |
+
* @global object $wpmem The WP_Members object class.
|
40 |
+
* @param array $args {
|
41 |
+
* @type string $id
|
42 |
+
* @type string $name
|
43 |
+
* @type string $type
|
44 |
+
* @type string $value
|
45 |
+
* @type string $compare
|
46 |
+
* @type string $class
|
47 |
+
* @type boolean $required
|
48 |
+
* @type string $delimiter
|
49 |
+
* @type string $placeholder
|
50 |
+
* @type string $pattern
|
51 |
+
* @type string $title
|
52 |
+
* @type string $min
|
53 |
+
* @type string $max
|
54 |
+
* @type string $rows Number of rows for a textarea (default:5).
|
55 |
+
* @type string $cols Number of columns for a textarea (default:20).
|
56 |
+
* }
|
57 |
+
* @return string $str The field returned as a string.
|
58 |
+
*/
|
59 |
+
function create_form_field( $args ) {
|
60 |
+
|
61 |
+
global $wpmem;
|
62 |
+
|
63 |
+
// Set defaults for most possible $args.
|
64 |
+
$id = ( isset( $args['id'] ) ) ? esc_attr( $args['id'] ) : esc_attr( $args['name'] );
|
65 |
+
$name = esc_attr( $args['name'] );
|
66 |
+
$type = esc_attr( $args['type'] );
|
67 |
+
$value = ( isset( $args['value'] ) ) ? $args['value'] : '';
|
68 |
+
$compare = ( isset( $args['compare'] ) ) ? $args['compare'] : '';
|
69 |
+
$class = ( isset( $args['class'] ) ) ? $args['class'] : 'textbox';
|
70 |
+
$required = ( isset( $args['required'] ) ) ? $args['required'] : false;
|
71 |
+
$delimiter = ( isset( $args['delimiter'] ) ) ? $args['delimiter'] : '|';
|
72 |
+
$placeholder = ( isset( $args['placeholder'] ) ) ? $args['placeholder'] : false;
|
73 |
+
$pattern = ( isset( $args['pattern'] ) ) ? $args['pattern'] : false;
|
74 |
+
$title = ( isset( $args['title'] ) ) ? $args['title'] : false;
|
75 |
+
$file_types = ( isset( $args['file_types'] ) ) ? $args['file_types'] : false;
|
76 |
+
|
77 |
+
// Handle field creation by type.
|
78 |
+
switch ( $type ) {
|
79 |
+
|
80 |
+
/*
|
81 |
+
* Field types text|url|email|number|date are all handled essentially the
|
82 |
+
* same. The primary differences are CSS class (with a default fallback
|
83 |
+
* of 'textbox'), how values are escaped, and the application of min|max
|
84 |
+
* values for number fields.
|
85 |
+
*/
|
86 |
+
case "text":
|
87 |
+
case "url":
|
88 |
+
case "email":
|
89 |
+
case "number":
|
90 |
+
case "date":
|
91 |
+
$class = ( 'textbox' == $class ) ? "textbox" : $this->sanitize_class( $class );
|
92 |
+
switch ( $type ) {
|
93 |
+
case 'url':
|
94 |
+
$value = esc_url( $value );
|
95 |
+
break;
|
96 |
+
case 'email':
|
97 |
+
$value = esc_attr( wp_unslash( $value ) );
|
98 |
+
break;
|
99 |
+
default:
|
100 |
+
$value = stripslashes( esc_attr( $value ) ); // @todo Could email and default be combined? Both seem to unslash and esc_attr().
|
101 |
+
break;
|
102 |
+
}
|
103 |
+
$required = ( $required ) ? ' required' : '';
|
104 |
+
$placeholder = ( $placeholder ) ? ' placeholder="' . esc_attr( __( $placeholder, 'wp-members' ) ) . '"' : '';
|
105 |
+
$pattern = ( $pattern ) ? ' pattern="' . esc_attr( $pattern ) . '"' : '';
|
106 |
+
$title = ( $title ) ? ' title="' . esc_attr( __( $title, 'wp-members' ) ) . '"' : '';
|
107 |
+
$min = ( isset( $args['min'] ) && $args['min'] != '' ) ? ' min="' . esc_attr( $args['min'] ) . '"' : '';
|
108 |
+
$max = ( isset( $args['max'] ) && $args['max'] != '' ) ? ' max="' . esc_attr( $args['max'] ). '"' : '';
|
109 |
+
$str = "<input name=\"$name\" type=\"$type\" id=\"$id\" value=\"$value\" class=\"$class\"$placeholder$title$pattern$min$max" . ( ( $required ) ? " required " : "" ) . " />";
|
110 |
+
break;
|
111 |
+
|
112 |
+
case "password":
|
113 |
+
$class = $this->sanitize_class( $class );
|
114 |
+
$placeholder = ( $placeholder ) ? ' placeholder="' . esc_attr( __( $placeholder, 'wp-members' ) ) . '"' : '';
|
115 |
+
$pattern = ( $pattern ) ? ' pattern="' . esc_attr( $pattern ) . '"' : '';
|
116 |
+
$title = ( $title ) ? ' title="' . esc_attr( __( $title, 'wp-members' ) ) . '"' : '';
|
117 |
+
$str = "<input name=\"$name\" type=\"$type\" id=\"$id\" class=\"$class\"$placeholder$title$pattern" . ( ( $required ) ? " required " : "" ) . " />";
|
118 |
+
break;
|
119 |
+
|
120 |
+
case "image":
|
121 |
+
case "file":
|
122 |
+
if ( $file_types ) {
|
123 |
+
$file_types = explode( '|', $file_types );
|
124 |
+
foreach( $file_types as $file_type ) {
|
125 |
+
$array[] = "." . $file_type;
|
126 |
+
}
|
127 |
+
$accept = ' accept="' . implode( ",", $array ) . '"';
|
128 |
+
} else {
|
129 |
+
$accept = '';
|
130 |
+
}
|
131 |
+
$class = ( 'textbox' == $class ) ? "file" : $this->sanitize_class( $class );
|
132 |
+
$str = "<input name=\"$name\" type=\"file\" id=\"$id\" value=\"" . esc_attr( $value ) . "\" class=\"$class\"$accept" . ( ( $required ) ? " required " : "" ) . " />";
|
133 |
+
break;
|
134 |
+
|
135 |
+
case "checkbox":
|
136 |
+
$class = ( 'textbox' == $class ) ? "checkbox" : $this->sanitize_class( $class );
|
137 |
+
$str = "<input name=\"$name\" type=\"$type\" id=\"$id\" value=\"" . esc_attr( $value ) . "\"" . checked( $value, $compare, false ) . ( ( $required ) ? " required " : "" ) . " />";
|
138 |
+
break;
|
139 |
+
|
140 |
+
case "textarea":
|
141 |
+
$value = esc_textarea( stripslashes( $value ) ); // stripslashes( esc_textarea( $value ) );
|
142 |
+
$class = ( 'textbox' == $class ) ? "textarea" : $this->sanitize_class( $class );
|
143 |
+
$placeholder = ( $placeholder ) ? ' placeholder="' . esc_attr( __( $placeholder, 'wp-members' ) ) . '"' : '';
|
144 |
+
$rows = ( isset( $args['rows'] ) && $args['rows'] ) ? esc_attr( $args['rows'] ) : '5';
|
145 |
+
$cols = ( isset( $args['cols'] ) && $args['cols'] ) ? esc_attr( $args['cols'] ) : '20';
|
146 |
+
$str = "<textarea cols=\"$cols\" rows=\"$rows\" name=\"$name\" id=\"$id\" class=\"$class\"$placeholder" . ( ( $required ) ? " required " : "" ) . ">$value</textarea>";
|
147 |
+
break;
|
148 |
+
|
149 |
+
case "hidden":
|
150 |
+
$str = "<input name=\"$name\" type=\"$type\" value=\"" . esc_attr( $value ) . "\" />";
|
151 |
+
break;
|
152 |
+
|
153 |
+
case "option":
|
154 |
+
$str = "<option value=\"" . esc_attr( $value ) . "\" " . selected( $value, $compare, false ) . " >" . __( $name, 'wp-members' ) . "</option>";
|
155 |
+
break;
|
156 |
+
|
157 |
+
case "select":
|
158 |
+
case "multiselect":
|
159 |
+
case "membership":
|
160 |
+
$class = ( 'textbox' == $class && 'multiselect' != $type ) ? "dropdown" : $class;
|
161 |
+
$class = ( 'textbox' == $class && 'multiselect' == $type ) ? "multiselect" : $class;
|
162 |
+
$pname = ( 'multiselect' == $type ) ? $name . "[]" : $name;
|
163 |
+
$str = "<select name=\"$pname\" id=\"$id\" class=\"$class\"" . ( ( 'multiselect' == $type ) ? " multiple " : "" ) . ( ( $required ) ? " required " : "" ) . ">\n";
|
164 |
+
if ( 'membership' == $type ) {
|
165 |
+
$value = array( 'Choose membership|' );
|
166 |
+
foreach( $wpmem->membership->products as $membership_key => $membership_value ) {
|
167 |
+
$value[] = $membership_value['title'] . '|' . $membership_key;
|
168 |
+
}
|
169 |
+
}
|
170 |
+
foreach ( $value as $option ) {
|
171 |
+
$pieces = array_map( 'trim', explode( '|', $option ) );
|
172 |
+
if ( 'multiselect' == $type ) {
|
173 |
+
$chk = '';
|
174 |
+
$values = ( empty( $compare ) ) ? array() : ( is_array( $compare ) ? $compare : explode( $delimiter, $compare ) );
|
175 |
+
} else {
|
176 |
+
$chk = $compare;
|
177 |
+
$values = array();
|
178 |
+
}
|
179 |
+
if ( isset( $pieces[1] ) && '' != $pieces[1] ) {
|
180 |
+
$chk = ( ( isset( $pieces[2] ) && '' == $compare ) || in_array( $pieces[1], $values ) ) ? $pieces[1] : $chk;
|
181 |
+
} else {
|
182 |
+
$chk = 'not selected';
|
183 |
+
}
|
184 |
+
$str = $str . "<option value=\"$pieces[1]\"" . selected( $pieces[1], $chk, false ) . ">" . esc_attr( __( $pieces[0], 'wp-members' ) ) . "</option>\n";
|
185 |
+
}
|
186 |
+
$str = $str . "</select>";
|
187 |
+
break;
|
188 |
+
|
189 |
+
case "multicheckbox":
|
190 |
+
$class = ( 'textbox' == $class ) ? "checkbox" : $class;
|
191 |
+
$str = '';
|
192 |
+
$num = 1;
|
193 |
+
foreach ( $value as $option ) {
|
194 |
+
$pieces = explode( '|', $option );
|
195 |
+
$values = ( empty( $compare ) ) ? array() : ( is_array( $compare ) ? $compare : explode( $delimiter, $compare ) );
|
196 |
+
$chk = ( isset( $pieces[2] ) && '' == $compare ) ? $pieces[1] : '';
|
197 |
+
if ( isset( $pieces[1] ) && '' != $pieces[1] ) {
|
198 |
+
$id_value = esc_attr( $id . '[' . $pieces[1] . ']' );
|
199 |
+
$label = wpmem_form_label( array( 'meta_key'=>$id_value, 'label'=>esc_html( __( $pieces[0], 'wp-members' ) ), 'type'=>'radio', 'id'=>$id_value ) );
|
200 |
+
$str = $str . $this->create_form_field( array(
|
201 |
+
'id' => $id_value,
|
202 |
+
'name' => $name . '[]',
|
203 |
+
'type' => 'checkbox',
|
204 |
+
'value' => $pieces[1],
|
205 |
+
'compare' => ( in_array( $pieces[1], $values ) ) ? $pieces[1] : $chk,
|
206 |
+
) ) . " " . $label . "<br />\n";
|
207 |
+
} else {
|
208 |
+
$str = $str . '<span class="div_multicheckbox_separator">' . esc_html( __( $pieces[0], 'wp-members' ) ) . "</span><br />\n";
|
209 |
+
}
|
210 |
+
}
|
211 |
+
break;
|
212 |
+
|
213 |
+
case "radio":
|
214 |
+
$class = ( 'textbox' == $class ) ? "radio" : $this->sanitize_class( $class );
|
215 |
+
$str = '';
|
216 |
+
$num = 1;
|
217 |
+
foreach ( $value as $option ) {
|
218 |
+
$pieces = explode( '|', $option );
|
219 |
+
$id_num = $id . '_' . $num;
|
220 |
+
if ( isset( $pieces[1] ) && '' != $pieces[1] ) {
|
221 |
+
$label = wpmem_form_label( array( 'meta_key'=>esc_attr( $id_num ), 'label'=>esc_html( __( $pieces[0], 'wp-members' ) ), 'type'=>'radio', 'id'=>esc_attr( "label_" . $id_num ) ) );
|
222 |
+
$str = $str . "<input type=\"radio\" name=\"$name\" id=\"" . esc_attr( $id_num ) . "\" value=\"" . esc_attr( $pieces[1] ) . '"' . checked( $pieces[1], $compare, false ) . ( ( $required ) ? " required " : " " ) . "> $label<br />\n";
|
223 |
+
$num++;
|
224 |
+
} else {
|
225 |
+
$str = $str . '<span class="div_radio_separator">' . esc_html( __( $pieces[0], 'wp-members' ) ) . "</span><br />\n";
|
226 |
+
}
|
227 |
+
}
|
228 |
+
break;
|
229 |
+
|
230 |
+
}
|
231 |
+
|
232 |
+
return $str;
|
233 |
+
} // End create_form_field()
|
234 |
+
|
235 |
+
/**
|
236 |
+
* Create form label.
|
237 |
+
*
|
238 |
+
* @since 3.1.7
|
239 |
+
* @since 3.2.4 Added $id
|
240 |
+
*
|
241 |
+
* @param array $args {
|
242 |
+
* @type string $meta_key
|
243 |
+
* @type string $label
|
244 |
+
* @type string $type
|
245 |
+
* @type string $id (optional)
|
246 |
+
* @type string $class (optional)
|
247 |
+
* @type string $required (optional)
|
248 |
+
* @type string $req_mark (optional)
|
249 |
+
* }
|
250 |
+
* @return string $label
|
251 |
+
*/
|
252 |
+
function create_form_label( $args ) {
|
253 |
+
global $wpmem;
|
254 |
+
|
255 |
+
$meta_key = $args['meta_key'];
|
256 |
+
$label = $args['label'];
|
257 |
+
$type = $args['type'];
|
258 |
+
$class = ( isset( $args['class'] ) ) ? $args['class'] : false;
|
259 |
+
$id = ( isset( $args['id'] ) ) ? $args['id'] : false;
|
260 |
+
$required = ( isset( $args['required'] ) ) ? $args['required'] : false;
|
261 |
+
$req_mark = ( isset( $args['req_mark'] ) ) ? $args['req_mark'] : false;
|
262 |
+
|
263 |
+
//$req_mark = ( ! $req_mark ) ? $wpmem->get_text( 'register_req_mark' ) : '*';
|
264 |
+
|
265 |
+
if ( ! $class ) {
|
266 |
+
$class = ( $type == 'password' || $type == 'email' || $type == 'url' ) ? 'text' : $type;
|
267 |
+
}
|
268 |
+
|
269 |
+
$id = ( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
|
270 |
+
|
271 |
+
$label = '<label for="' . esc_attr( $meta_key ) . '"' . $id . ' class="' . $this->sanitize_class( $class ) . '">' . __( $label, 'wp-members' );
|
272 |
+
$label = ( $required ) ? $label . $req_mark : $label;
|
273 |
+
$label = $label . '</label>';
|
274 |
+
|
275 |
+
return $label;
|
276 |
+
}
|
277 |
+
|
278 |
+
/**
|
279 |
+
* Sanitizes classes passed to the WP-Members form building functions.
|
280 |
+
*
|
281 |
+
* This generally uses just sanitize_html_class() but allows for
|
282 |
+
* whitespace so multiple classes can be passed (such as "regular-text code").
|
283 |
+
*
|
284 |
+
* @since 3.2.0
|
285 |
+
*
|
286 |
+
* @param string $class
|
287 |
+
* @return string sanitized_class
|
288 |
+
*/
|
289 |
+
function sanitize_class( $class ) {
|
290 |
+
// If no whitespace, just return WP sanitized class.
|
291 |
+
if ( ! strpos( $class, ' ' ) ) {
|
292 |
+
return sanitize_html_class( $class );
|
293 |
+
} else {
|
294 |
+
// Break string by whitespace, sanitize individual class names.
|
295 |
+
$class_array = explode( ' ', $class );
|
296 |
+
$len = count( $class_array ); $i = 0;
|
297 |
+
$sanitized_class = '';
|
298 |
+
foreach ( $class_array as $single_class ) {
|
299 |
+
$sanitized_class .= sanitize_html_class( $single_class );
|
300 |
+
$sanitized_class .= ( $i == $len - 1 ) ? '' : ' ';
|
301 |
+
$i++;
|
302 |
+
}
|
303 |
+
return $sanitized_class;
|
304 |
+
}
|
305 |
+
}
|
306 |
+
|
307 |
+
/**
|
308 |
+
* Sanitizes the text in an array.
|
309 |
+
*
|
310 |
+
* @since 3.2.9
|
311 |
+
*
|
312 |
+
* @param array $data
|
313 |
+
* @return array $data
|
314 |
+
*/
|
315 |
+
function sanitize_array( $data ) {
|
316 |
+
if ( is_array( $data ) ) {
|
317 |
+
foreach( $data as $key => $val ) {
|
318 |
+
$data[ $key ] = sanitize_text_field( $val );
|
319 |
+
}
|
320 |
+
}
|
321 |
+
return $data;
|
322 |
+
}
|
323 |
+
|
324 |
+
/**
|
325 |
+
* Sanitizes field based on field type.
|
326 |
+
*
|
327 |
+
* Obviously, this isn't an all inclusive function of every WordPress
|
328 |
+
* sanitization function. It is intended to handle sanitization of
|
329 |
+
* WP-Members form input and therefore includes the necessary methods
|
330 |
+
* that would relate to the WP-Members custom field types and can thus
|
331 |
+
* be used by looping through form data when the WP-Members fields are
|
332 |
+
* handled and validated.
|
333 |
+
*
|
334 |
+
* @since 3.2.9
|
335 |
+
* @since 3.3.0 Added email, file, and image.
|
336 |
+
*
|
337 |
+
* @param string $data
|
338 |
+
* @param string $type
|
339 |
+
* @return string $sanitized_data
|
340 |
+
*/
|
341 |
+
function sanitize_field( $data, $type ) {
|
342 |
+
|
343 |
+
switch ( $type ) {
|
344 |
+
|
345 |
+
case 'multiselect':
|
346 |
+
case 'multicheckbox':
|
347 |
+
$sanitized_data = $this->sanitize_array( $data );
|
348 |
+
break;
|
349 |
+
|
350 |
+
case 'textarea':
|
351 |
+
$sanitized_data = sanitize_textarea_field( $data );
|
352 |
+
break;
|
353 |
+
|
354 |
+
case 'email':
|
355 |
+
$sanitized_data = sanitize_email( $data );
|
356 |
+
break;
|
357 |
+
|
358 |
+
case 'file':
|
359 |
+
case 'image':
|
360 |
+
$sanitized_data = sanitize_file_name( $data );
|
361 |
+
break;
|
362 |
+
|
363 |
+
default:
|
364 |
+
$sanitized_data = sanitize_text_field( $data );
|
365 |
+
break;
|
366 |
+
}
|
367 |
+
|
368 |
+
return $sanitized_data;
|
369 |
+
}
|
370 |
+
|
371 |
+
/**
|
372 |
+
* Uploads file from the user.
|
373 |
+
*
|
374 |
+
* @since 3.1.0
|
375 |
+
*
|
376 |
+
* @param array $file
|
377 |
+
* @param int $user_id
|
378 |
+
* @return int|bool
|
379 |
+
*/
|
380 |
+
function do_file_upload( $file = array(), $user_id = false ) {
|
381 |
+
|
382 |
+
// Filter the upload directory.
|
383 |
+
add_filter( 'upload_dir', array( &$this,'file_upload_dir' ) );
|
384 |
+
|
385 |
+
// Set up user ID for use in upload process.
|
386 |
+
$this->file_user_id = ( $user_id ) ? $user_id : 0;
|
387 |
+
|
388 |
+
// Get WordPress file upload processing scripts.
|
389 |
+
require_once( ABSPATH . 'wp-admin/includes/file.php' );
|
390 |
+
|
391 |
+
$file_return = wp_handle_upload( $file, array( 'test_form' => false ) );
|
392 |
+
|
393 |
+
if ( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
|
394 |
+
return false;
|
395 |
+
} else {
|
396 |
+
|
397 |
+
$attachment = array(
|
398 |
+
'post_mime_type' => $file_return['type'],
|
399 |
+
'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $file_return['file'] ) ),
|
400 |
+
'post_content' => '',
|
401 |
+
'post_status' => 'inherit',
|
402 |
+
'guid' => $file_return['url'],
|
403 |
+
'post_author' => ( $user_id ) ? $user_id : '',
|
404 |
+
);
|
405 |
+
|
406 |
+
$attachment_id = wp_insert_attachment( $attachment, $file_return['url'] );
|
407 |
+
|
408 |
+
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
409 |
+
$attachment_data = wp_generate_attachment_metadata( $attachment_id, $file_return['file'] );
|
410 |
+
wp_update_attachment_metadata( $attachment_id, $attachment_data );
|
411 |
+
|
412 |
+
if ( 0 < intval( $attachment_id ) ) {
|
413 |
+
// Returns an array with file information.
|
414 |
+
return $attachment_id;
|
415 |
+
}
|
416 |
+
}
|
417 |
+
|
418 |
+
return false;
|
419 |
+
} // End upload_file()
|
420 |
+
|
421 |
+
/**
|
422 |
+
* Sets the file upload directory.
|
423 |
+
*
|
424 |
+
* This is a filter function for upload_dir.
|
425 |
+
*
|
426 |
+
* @link https://codex.wordpress.org/Plugin_API/Filter_Reference/upload_dir
|
427 |
+
*
|
428 |
+
* @since 3.1.0
|
429 |
+
*
|
430 |
+
* @param array $param {
|
431 |
+
* The directory information for upload.
|
432 |
+
*
|
433 |
+
* @type string $path
|
434 |
+
* @type string $url
|
435 |
+
* @type string $subdir
|
436 |
+
* @type string $basedir
|
437 |
+
* @type string $baseurl
|
438 |
+
* @type string $error
|
439 |
+
* }
|
440 |
+
* @return array $param
|
441 |
+
*/
|
442 |
+
function file_upload_dir( $param ) {
|
443 |
+
$user_id = ( isset( $this->file_user_id ) ) ? $this->file_user_id : null;
|
444 |
+
|
445 |
+
$args = array(
|
446 |
+
'user_id' => $user_id,
|
447 |
+
'wpmem_dir' => 'wpmembers/',
|
448 |
+
'user_dir' => 'user_files/' . $user_id,
|
449 |
+
);
|
450 |
+
/**
|
451 |
+
* Filter the user directory elements.
|
452 |
+
*
|
453 |
+
* @since 3.1.0
|
454 |
+
*
|
455 |
+
* @param array $args
|
456 |
+
*/
|
457 |
+
$args = apply_filters( 'wpmem_user_upload_dir', $args );
|
458 |
+
|
459 |
+
$param['subdir'] = '/' . $args['wpmem_dir'] . $args['user_dir'];
|
460 |
+
$param['path'] = $param['basedir'] . '/' . $args['wpmem_dir'] . $args['user_dir'];
|
461 |
+
$param['url'] = $param['baseurl'] . '/' . $args['wpmem_dir'] . $args['user_dir'];
|
462 |
+
|
463 |
+
return $param;
|
464 |
+
}
|
465 |
+
|
466 |
+
/**
|
467 |
+
* Login Form Builder.
|
468 |
+
*
|
469 |
+
* Builds the form used for login, change password, and reset password.
|
470 |
+
*
|
471 |
+
* @since 2.5.1
|
472 |
+
* @since 3.1.7 Moved to forms object class as login_form().
|
473 |
+
* @since 3.1.7 Added WP action login_form.
|
474 |
+
* @since 3.2.6 Added nonce to the short form.
|
475 |
+
*
|
476 |
+
* @param string $page
|
477 |
+
* @param array $arr {
|
478 |
+
* The elements needed to generate the form (login|reset password|forgotten password).
|
479 |
+
*
|
480 |
+
* @type string $heading Form heading text.
|
481 |
+
* @type string $action The form action (login|pwdchange|pwdreset|getusername).
|
482 |
+
* @type string $button_text Form submit button text.
|
483 |
+
* @type array $inputs {
|
484 |
+
* The form input values.
|
485 |
+
*
|
486 |
+
* @type array {
|
487 |
+
*
|
488 |
+
* @type string $name The field label.
|
489 |
+
* @type string $type Input type.
|
490 |
+
* @type string $tag Input tag name.
|
491 |
+
* @type string $class Input tag class.
|
492 |
+
* @type string $div Div wrapper class.
|
493 |
+
* }
|
494 |
+
* }
|
495 |
+
* @type string $redirect_to Optional. URL to redirect to.
|
496 |
+
* }
|
497 |
+
* @return string $form The HTML for the form as a string.
|
498 |
+
*/
|
499 |
+
function login_form( $mixed, $arr = array() ) {
|
500 |
+
|
501 |
+
// Handle legacy use.
|
502 |
+
if ( is_array( $mixed ) ) {
|
503 |
+
$page = $mixed['page'];
|
504 |
+
$arr = $mixed;
|
505 |
+
} else {
|
506 |
+
$page = $mixed;
|
507 |
+
}
|
508 |
+
|
509 |
+
|
510 |
+
// Set up redirect_to @todo This could be done in a separate method usable by both login & reg.
|
511 |
+
if ( isset( $_REQUEST['redirect_to'] ) ) {
|
512 |
+
$redirect_to = $_REQUEST['redirect_to'];
|
513 |
+
} else {
|
514 |
+
if ( isset( $arr['redirect_to'] ) ) {
|
515 |
+
$redirect_to = $arr['redirect_to'];
|
516 |
+
} else {
|
517 |
+
$redirect_to = ( isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : get_permalink();
|
518 |
+
}
|
519 |
+
}
|
520 |
+
|
521 |
+
global $wpmem;
|
522 |
+
|
523 |
+
// set up default wrappers
|
524 |
+
$defaults = array(
|
525 |
+
|
526 |
+
// wrappers
|
527 |
+
'heading_before' => '<legend>',
|
528 |
+
'heading_after' => '</legend>',
|
529 |
+
'fieldset_before' => '<fieldset>',
|
530 |
+
'fieldset_after' => '</fieldset>',
|
531 |
+
'main_div_before' => '<div id="wpmem_login">',
|
532 |
+
'main_div_after' => '</div>',
|
533 |
+
'txt_before' => '',
|
534 |
+
'txt_after' => '',
|
535 |
+
'row_before' => '',
|
536 |
+
'row_after' => '',
|
537 |
+
'buttons_before' => '<div class="button_div">',
|
538 |
+
'buttons_after' => '</div>',
|
539 |
+
'link_before' => '<div class="link-text">',
|
540 |
+
'link_after' => '</div>',
|
541 |
+
'link_span_before' => '<span class="link-text-%s">',
|
542 |
+
'link_span_after' => '</span>',
|
543 |
+
|
544 |
+
// classes & ids
|
545 |
+
'form_id' => 'wpmem_' . $arr['action'] . '_form',
|
546 |
+
'form_class' => 'form',
|
547 |
+
'button_id' => '',
|
548 |
+
'button_class' => 'buttons',
|
549 |
+
|
550 |
+
// other
|
551 |
+
'strip_breaks' => true,
|
552 |
+
'wrap_inputs' => true,
|
553 |
+
'remember_check' => true,
|
554 |
+
'n' => "\n",
|
555 |
+
't' => "\t",
|
556 |
+
'redirect_to' => $redirect_to,
|
557 |
+
'login_form_action' => true,
|
558 |
+
|
559 |
+
);
|
560 |
+
|
561 |
+
/**
|
562 |
+
* Filter the default form arguments.
|
563 |
+
*
|
564 |
+
* This filter accepts an array of various elements to replace the form defaults. This
|
565 |
+
* includes default tags, labels, text, and small items including various booleans.
|
566 |
+
*
|
567 |
+
* @since 2.9.0
|
568 |
+
* @since 3.3.0 Passes $defaults as an argument.
|
569 |
+
*
|
570 |
+
* @param array $args An array of arguments to merge with defaults.
|
571 |
+
* @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
|
572 |
+
*/
|
573 |
+
$args = apply_filters( 'wpmem_login_form_args', $defaults, $arr['action'] );
|
574 |
+
|
575 |
+
// Merge $args with defaults.
|
576 |
+
$args = wp_parse_args( $args, $defaults );
|
577 |
+
|
578 |
+
// Build the input rows.
|
579 |
+
foreach ( $arr['inputs'] as $input ) {
|
580 |
+
$label = '<label for="' . esc_attr( $input['tag'] ) . '">' . $input['name'] . '</label>';
|
581 |
+
$field = wpmem_form_field( array(
|
582 |
+
'name' => $input['tag'],
|
583 |
+
'type' => $input['type'],
|
584 |
+
'class' => $input['class'],
|
585 |
+
'required' => true,
|
586 |
+
) );
|
587 |
+
$field_before = ( $args['wrap_inputs'] ) ? '<div class="' . $this->sanitize_class( $input['div'] ) . '">' : '';
|
588 |
+
$field_after = ( $args['wrap_inputs'] ) ? '</div>' : '';
|
589 |
+
$rows[] = array(
|
590 |
+
'row_before' => $args['row_before'],
|
591 |
+
'label' => $label,
|
592 |
+
'field_before' => $field_before,
|
593 |
+
'field' => $field,
|
594 |
+
'field_after' => $field_after,
|
595 |
+
'row_after' => $args['row_after'],
|
596 |
+
);
|
597 |
+
}
|
598 |
+
|
599 |
+
/**
|
600 |
+
* Filter the array of form rows.
|
601 |
+
*
|
602 |
+
* This filter receives an array of the main rows in the form, each array element being
|
603 |
+
* an array of that particular row's pieces. This allows making changes to individual
|
604 |
+
* parts of a row without needing to parse through a string of HTML.
|
605 |
+
*
|
606 |
+
* @since 2.9.0
|
607 |
+
* @since 3.2.6 Added $arr parameter so all settings are passed.
|
608 |
+
*
|
609 |
+
* @param array $rows An array containing the form rows.
|
610 |
+
* @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
|
611 |
+
* @param array $arr An array containing all of the form settings.
|
612 |
+
*/
|
613 |
+
$rows = apply_filters( 'wpmem_login_form_rows', $rows, $arr['action'], $arr );
|
614 |
+
|
615 |
+
// Put the rows from the array into $form.
|
616 |
+
$form = '';
|
617 |
+
foreach ( $rows as $row_item ) {
|
618 |
+
$row = ( $row_item['row_before'] != '' ) ? $row_item['row_before'] . $args['n'] . $row_item['label'] . $args['n'] : $row_item['label'] . $args['n'];
|
619 |
+
$row .= ( $row_item['field_before'] != '' ) ? $row_item['field_before'] . $args['n'] . $args['t'] . $row_item['field'] . $args['n'] . $row_item['field_after'] . $args['n'] : $row_item['field'] . $args['n'];
|
620 |
+
$row .= ( $row_item['row_after'] != '' ) ? $row_item['row_after'] . $args['n'] : '';
|
621 |
+
$form.= $row;
|
622 |
+
}
|
623 |
+
|
624 |
+
// Handle outside elements added to the login form (currently ONLY for login).
|
625 |
+
if ( 'login' == $arr['action'] && $args['login_form_action'] ) {
|
626 |
+
ob_start();
|
627 |
+
/** This action is documented in wp-login.php */
|
628 |
+
do_action( 'login_form' );
|
629 |
+
$add_to_form = ob_get_contents();
|
630 |
+
ob_end_clean();
|
631 |
+
$form.= $add_to_form;
|
632 |
+
}
|
633 |
+
|
634 |
+
// Build hidden fields, filter, and add to the form.
|
635 |
+
$hidden = wpmem_create_formfield( 'redirect_to', 'hidden', esc_url( $args['redirect_to'] ) ) . $args['n'];
|
636 |
+
$hidden = $hidden . wpmem_create_formfield( 'a', 'hidden', $arr['action'] ) . $args['n'];
|
637 |
+
$hidden = ( $arr['action'] != 'login' ) ? $hidden . wpmem_create_formfield( 'formsubmit', 'hidden', '1' ) : $hidden;
|
638 |
+
|
639 |
+
/**
|
640 |
+
* Filter the hidden field HTML.
|
641 |
+
*
|
642 |
+
* @since 2.9.0
|
643 |
+
*
|
644 |
+
* @param string $hidden The generated HTML of hidden fields.
|
645 |
+
* @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
|
646 |
+
*/
|
647 |
+
$form = $form . apply_filters( 'wpmem_login_hidden_fields', $hidden, $arr['action'] );
|
648 |
+
|
649 |
+
// Build the buttons, filter, and add to the form.
|
650 |
+
if ( $arr['action'] == 'login' ) {
|
651 |
+
$args['remember_check'] = ( $args['remember_check'] ) ? $args['t'] . wpmem_create_formfield( 'rememberme', 'checkbox', 'forever' ) . ' ' . '<label for="rememberme">' . $wpmem->get_text( 'remember_me' ) . '</label> ' . $args['n'] : '';
|
652 |
+
$buttons = $args['remember_check'] . $args['t'] . '<input type="submit" name="Submit" value="' . esc_attr( $arr['button_text'] ) . '" class="' . $this->sanitize_class( $args['button_class'] ) . '" />' . $args['n'];
|
653 |
+
} else {
|
654 |
+
$buttons = '<input type="submit" name="Submit" value="' . esc_attr( $arr['button_text'] ) . '" class="' . $this->sanitize_class( $args['button_class'] ) . '" />' . $args['n'];
|
655 |
+
}
|
656 |
+
|
657 |
+
/**
|
658 |
+
* Filter the HTML for form buttons.
|
659 |
+
*
|
660 |
+
* The string includes the buttons, as well as the before/after wrapper elements.
|
661 |
+
*
|
662 |
+
* @since 2.9.0
|
663 |
+
*
|
664 |
+
* @param string $buttons The generated HTML of the form buttons.
|
665 |
+
* @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
|
666 |
+
*/
|
667 |
+
$form = $form . apply_filters( 'wpmem_login_form_buttons', $args['buttons_before'] . $args['n'] . $buttons . $args['buttons_after'] . $args['n'], $arr['action'] );
|
668 |
+
|
669 |
+
$links_array = array(
|
670 |
+
'forgot' => array(
|
671 |
+
'tag' => 'forgot',
|
672 |
+
'link' => add_query_arg( 'a', 'pwdreset', $wpmem->user_pages['profile'] ),
|
673 |
+
'page' => 'profile',
|
674 |
+
'action' => 'login',
|
675 |
+
),
|
676 |
+
'register' => array(
|
677 |
+
'tag' => 'reg',
|
678 |
+
'link' => $wpmem->user_pages['register'],
|
679 |
+
'page' => 'register',
|
680 |
+
'action' => 'login',
|
681 |
+
),
|
682 |
+
'username' => array(
|
683 |
+
'tag' => 'username',
|
684 |
+
'link' => add_query_arg( 'a', 'getusername', $wpmem->user_pages['profile'] ),
|
685 |
+
'page' => 'profile',
|
686 |
+
'action' => 'pwdreset',
|
687 |
+
),
|
688 |
+
);
|
689 |
+
foreach ( $links_array as $key => $value ) {
|
690 |
+
$tag = $value['tag'];
|
691 |
+
if ( ( $wpmem->user_pages[ $value['page'] ] || 'members' == $page ) && $value['action'] == $arr['action'] ) {
|
692 |
+
/**
|
693 |
+
* Filters register, forgot password, and forgot username links.
|
694 |
+
*
|
695 |
+
* @since 2.8.0
|
696 |
+
* @since 3.1.7 Combined all to a single process.
|
697 |
+
* @since 3.2.5 Added $tag parameter.
|
698 |
+
*
|
699 |
+
* @param string The raw link.
|
700 |
+
* @param string $tag forgot|reg|pwdreset.
|
701 |
+
*/
|
702 |
+
$link = apply_filters( "wpmem_{$tag}_link", $value['link'], $tag );
|
703 |
+
$str = $wpmem->get_text( "{$key}_link_before" ) . '<a href="' . esc_url( $link ) . '">' . $wpmem->get_text( "{$key}_link" ) . '</a>';
|
704 |
+
$link_str = $args['link_before'];
|
705 |
+
$link_str.= ( '' != $args['link_span_before'] ) ? sprintf( $args['link_span_before'], $key ) : '';
|
706 |
+
/**
|
707 |
+
* Filters the register, forgot password, and forgot username links HTML.
|
708 |
+
*
|
709 |
+
* @since 2.9.0
|
710 |
+
* @since 3.0.9 Added $link parameter.
|
711 |
+
* @since 3.1.7 Combined all to a single process.
|
712 |
+
* @since 3.2.5 Added $tag parameter.
|
713 |
+
*
|
714 |
+
* @param string $str The link HTML.
|
715 |
+
* @param string $link The link.
|
716 |
+
* @param string $tag forgot|reg|pwdreset.
|
717 |
+
*/
|
718 |
+
$link_str.= apply_filters( "wpmem_{$tag}_link_str", $str, $link, $tag );
|
719 |
+
$link_str.= ( '' != $args['link_span_after'] ) ? $args['link_span_after'] : '';
|
720 |
+
$link_str.= $args['link_after'] . $args['n'];
|
721 |
+
/*
|
722 |
+
* If this is the register link, and the current post type is set to
|
723 |
+
* display the register form, and the current page is not the login
|
724 |
+
* page, then do not add the register link, otherwise add the link.
|
725 |
+
*/
|
726 |
+
if ( 'register' == $key ) {
|
727 |
+
if ( ! isset( $wpmem->user_pages['register'] ) || '' == $wpmem->user_pages['register'] ) {
|
728 |
+
$form = $form;
|
729 |
+
} else {
|
730 |
+
if ( isset( $wpmem->user_pages['login'] ) && '' != $wpmem->user_pages['login'] ) {
|
731 |
+
$form = ( 1 == $wpmem->show_reg[ get_post_type( get_the_ID() ) ] && wpmem_current_url( true, false ) != wpmem_login_url() ) ? $form : $form . $link_str;
|
732 |
+
} else {
|
733 |
+
global $post;
|
734 |
+
if ( has_shortcode( $post->post_content, 'wpmem_profile' ) ) {
|
735 |
+
$form = $form;
|
736 |
+
} else {
|
737 |
+
$form = ( 1 == $wpmem->show_reg[ get_post_type( get_the_ID() ) ] && ! has_shortcode( $post->post_content, 'wpmem_form' ) ) ? $form : $form . $link_str;
|
738 |
+
}
|
739 |
+
}
|
740 |
+
}
|
741 |
+
} else {
|
742 |
+
$form = $form . $link_str;
|
743 |
+
}
|
744 |
+
}
|
745 |
+
}
|
746 |
+
|
747 |
+
// Apply the heading.
|
748 |
+
$form = $args['heading_before'] . $arr['heading'] . $args['heading_after'] . $args['n'] . $form;
|
749 |
+
|
750 |
+
// Apply fieldset wrapper.
|
751 |
+
$form = $args['fieldset_before'] . $args['n'] . $form . $args['fieldset_after'] . $args['n'];
|
752 |
+
|
753 |
+
// Apply nonce.
|
754 |
+
$form = wp_nonce_field( 'wpmem_shortform_nonce', '_wpmem_' . $arr['action'] . '_nonce', true, false ) . $args['n'] . $form;
|
755 |
+
|
756 |
+
// Apply form wrapper.
|
757 |
+
$form = '<form action="' . esc_url( get_permalink() ) . '" method="POST" id="' . $this->sanitize_class( $args['form_id'] ) . '" class="' . $this->sanitize_class( $args['form_class'] ) . '">' . $args['n'] . $form . '</form>';
|
758 |
+
|
759 |
+
// Apply anchor.
|
760 |
+
$form = '<a id="' . esc_attr( $arr['action'] ) . '"></a>' . $args['n'] . $form;
|
761 |
+
|
762 |
+
// Apply main wrapper.
|
763 |
+
$form = $args['main_div_before'] . $args['n'] . $form . $args['n'] . $args['main_div_after'];
|
764 |
+
|
765 |
+
// Apply wpmem_txt wrapper.
|
766 |
+
$form = $args['txt_before'] . $form . $args['txt_after'];
|
767 |
+
|
768 |
+
// Remove line breaks.
|
769 |
+
$form = ( $args['strip_breaks'] ) ? str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form ) : $form;
|
770 |
+
|
771 |
+
/**
|
772 |
+
* Filter the generated HTML of the entire form.
|
773 |
+
*
|
774 |
+
* @since 2.7.4
|
775 |
+
*
|
776 |
+
* @param string $form The HTML of the final generated form.
|
777 |
+
* @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
|
778 |
+
*/
|
779 |
+
$form = apply_filters( 'wpmem_login_form', $form, $arr['action'] );
|
780 |
+
|
781 |
+
/**
|
782 |
+
* Filter before the form.
|
783 |
+
*
|
784 |
+
* This rarely used filter allows you to stick any string onto the front of
|
785 |
+
* the generated form.
|
786 |
+
*
|
787 |
+
* @since 2.7.4
|
788 |
+
*
|
789 |
+
* @param string $str The HTML to add before the form. Default null.
|
790 |
+
* @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
|
791 |
+
*/
|
792 |
+
$form = apply_filters( 'wpmem_login_form_before', '', $arr['action'] ) . $form;
|
793 |
+
|
794 |
+
return $form;
|
795 |
+
} // End login_form.
|
796 |
+
|
797 |
+
/**
|
798 |
+
* Registration Form Builder.
|
799 |
+
*
|
800 |
+
* Outputs the form for new user registration and existing user edits.
|
801 |
+
*
|
802 |
+
* @since 2.5.1
|
803 |
+
* @since 3.1.7 Moved to forms object class as register_form().
|
804 |
+
* @since 3.2.5 use_nonce now obsolete (nonce is added automatically).
|
805 |
+
* @since 3.3.0 $heading argument obsolete.
|
806 |
+
*
|
807 |
+
* @global object $wpmem The WP_Members object.
|
808 |
+
* @global string $wpmem_regchk Used to determine if the form is in an error state.
|
809 |
+
* @global array $userdata Used to get the user's registration data if they are logged in (user profile edit).
|
810 |
+
* @param mixed $mixed (optional) String toggles between new registration ('new') and user profile edit ('edit'), or array containing settings arguments.
|
811 |
+
* @return string $form The HTML for the entire form as a string.
|
812 |
+
*/
|
813 |
+
function register_form( $mixed = 'new', $redirect_to = null ) {
|
814 |
+
|
815 |
+
// Handle legacy use.
|
816 |
+
if ( is_array( $mixed ) ) {
|
817 |
+
$id = ( isset( $mixed['id'] ) ) ? $mixed['id'] : '';
|
818 |
+
$tag = ( isset( $mixed['tag'] ) ) ? $mixed['tag'] : 'new';
|
819 |
+
$heading = ( isset( $mixed['heading'] ) ) ? $mixed['heading'] : '';
|
820 |
+
$redirect_to = ( isset( $mixed['redirect_to'] ) ) ? $mixed['redirect_to'] : '';
|
821 |
+
} else {
|
822 |
+
$id = 'default';
|
823 |
+
$tag = $mixed;
|
824 |
+
}
|
825 |
+
|
826 |
+
global $wpmem, $wpmem_regchk, $userdata;
|
827 |
+
|
828 |
+
// Set up default wrappers.
|
829 |
+
$defaults = array(
|
830 |
+
|
831 |
+
// Wrappers.
|
832 |
+
'heading_before' => '<legend>',
|
833 |
+
'heading_after' => '</legend>',
|
834 |
+
'fieldset_before' => '<fieldset>',
|
835 |
+
'fieldset_after' => '</fieldset>',
|
836 |
+
'main_div_before' => '<div id="wpmem_reg">',
|
837 |
+
'main_div_after' => '</div>',
|
838 |
+
'txt_before' => '',
|
839 |
+
'txt_after' => '',
|
840 |
+
'row_before' => '',
|
841 |
+
'row_after' => '',
|
842 |
+
'buttons_before' => '<div class="button_div">',
|
843 |
+
'buttons_after' => '</div>',
|
844 |
+
|
845 |
+
// Classes & ids.
|
846 |
+
'form_id' => ( 'new' == $tag ) ? 'wpmem_register_form' : 'wpmem_profile_form',
|
847 |
+
'form_class' => 'form',
|
848 |
+
'button_id' => '',
|
849 |
+
'button_class' => 'buttons',
|
850 |
+
|
851 |
+
// Required field tags and text.
|
852 |
+
'req_mark' => $wpmem->get_text( 'register_req_mark' ),
|
853 |
+
'req_label' => $wpmem->get_text( 'register_required' ),
|
854 |
+
'req_label_before' => '<div class="req-text">',
|
855 |
+
'req_label_after' => '</div>',
|
856 |
+
|
857 |
+
// Buttons.
|
858 |
+
'show_clear_form' => false,
|
859 |
+
'clear_form' => $wpmem->get_text( 'register_clear' ),
|
860 |
+
'submit_register' => $wpmem->get_text( 'register_submit' ),
|
861 |
+
'submit_update' => $wpmem->get_text( 'profile_submit' ),
|
862 |
+
|
863 |
+
// Other.
|
864 |
+
'post_to' => get_permalink(),
|
865 |
+
'strip_breaks' => true,
|
866 |
+
'wrap_inputs' => true,
|
867 |
+
'n' => "\n",
|
868 |
+
't' => "\t",
|
869 |
+
|
870 |
+
);
|
871 |
+
|
872 |
+
/**
|
873 |
+
* Filter the default form arguments.
|
874 |
+
*
|
875 |
+
* This filter accepts an array of various elements to replace the form defaults. This
|
876 |
+
* includes default tags, labels, text, and small items including various booleans.
|
877 |
+
*
|
878 |
+
* @since 2.9.0
|
879 |
+
* @since 3.2.5 Added $id
|
880 |
+
* @since 3.3.0 Passes $defaults as an argument.
|
881 |
+
*
|
882 |
+
* @param array An array of arguments to merge with defaults. Default null.
|
883 |
+
* @param string $tag Toggle new registration or profile update. new|edit.
|
884 |
+
* @param string $id An id for the form (optional).
|
885 |
+
*/
|
886 |
+
$args = apply_filters( 'wpmem_register_form_args', $defaults, $tag, $id );
|
887 |
+
|
888 |
+
// Merge $args with defaults.
|
889 |
+
$args = wp_parse_args( $args, $defaults );
|
890 |
+
|
891 |
+
// Get fields.
|
892 |
+
$wpmem_fields = wpmem_fields( $tag );
|
893 |
+
|
894 |
+
// Fields to skip for user profile update.
|
895 |
+
|
896 |
+
if ( 'edit' == $tag ) {
|
897 |
+
$pass_arr = array( 'username', 'password', 'confirm_password', 'password_confirm' );
|
898 |
+
// Skips tos on user edit page, unless they haven't got a value for tos.
|
899 |
+
if ( isset( $wpmem_fields['tos'] ) && ( $wpmem_fields['tos']['checked_value'] == get_user_meta( $userdata->ID, 'tos', true ) ) ) {
|
900 |
+
$pass_arr[] = 'tos';
|
901 |
+
}
|
902 |
+
foreach ( $pass_arr as $pass ) {
|
903 |
+
unset( $wpmem_fields[ $pass ] );
|
904 |
+
}
|
905 |
+
}
|
906 |
+
|
907 |
+
/**
|
908 |
+
* Filter the array of form fields.
|
909 |
+
*
|
910 |
+
* The form fields are stored in the WP options table as wpmembers_fields. This
|
911 |
+
* filter can filter that array after the option is retreived before the fields
|
912 |
+
* are parsed. This allows you to change the fields that may be used in the form
|
913 |
+
* on the fly.
|
914 |
+
*
|
915 |
+
* @since 2.9.0
|
916 |
+
* @deprecated 3.1.7 Use wpmem_fields instead.
|
917 |
+
*
|
918 |
+
* @param array The array of form fields.
|
919 |
+
* @param string $tag Toggle new registration or profile update. new|edit.
|
920 |
+
*/
|
921 |
+
$wpmem_fields = apply_filters( 'wpmem_register_fields_arr', $wpmem_fields, $tag );
|
922 |
+
|
923 |
+
$hidden_rows = array();
|
924 |
+
|
925 |
+
// Loop through the remaining fields.
|
926 |
+
foreach ( $wpmem_fields as $meta_key => $field ) {
|
927 |
+
|
928 |
+
// Start with a clean row.
|
929 |
+
$val = ''; $label = ''; $input = ''; $field_before = ''; $field_after = '';
|
930 |
+
|
931 |
+
// If the field is set to display and we aren't skipping, construct the row.
|
932 |
+
// if ( ( 'new' == $tag && $field['register'] ) || ( 'edit' == $tag && $field['profile'] ) ) { // @todo Wait for profile fix
|
933 |
+
if ( $field['register'] ) {
|
934 |
+
|
935 |
+
// Handle hidden fields
|
936 |
+
if ( 'hidden' == $field['type'] ) {
|
937 |
+
$do_row = false;
|
938 |
+
$hidden_rows[ $meta_key ] = wpmem_form_field( array(
|
939 |
+
'name' => $meta_key,
|
940 |
+
'type' => $field['type'],
|
941 |
+
'value' => $field['value'],
|
942 |
+
'compare' => $valtochk,
|
943 |
+
'required' => $field['required'],
|
944 |
+
) );
|
945 |
+
}
|
946 |
+
|
947 |
+
// Label for all but TOS and hidden fields.
|
948 |
+
if ( 'tos' != $meta_key && 'hidden' != $field['type'] ) {
|
949 |
+
|
950 |
+
$class = ( $field['type'] == 'password' || $field['type'] == 'email' || $field['type'] == 'url' ) ? 'text' : $field['type'];
|
951 |
+
|
952 |
+
$label = wpmem_form_label( array(
|
953 |
+
'meta_key' => $meta_key, //( 'username' == $meta_key ) ? 'user_login' : $meta_key,
|
954 |
+
'label' => __( $field['label'], 'wp-members' ),
|
955 |
+
'type' => $field['type'],
|
956 |
+
'class' => $class,
|
957 |
+
'required' => $field['required'],
|
958 |
+
'req_mark' => $args['req_mark']
|
959 |
+
) );
|
960 |
+
|
961 |
+
}
|
962 |
+
|
963 |
+
// Gets the field value for edit profile.
|
964 |
+
if ( ( 'edit' == $tag ) && ( '' == $wpmem->regchk ) ) {
|
965 |
+
switch ( $meta_key ) {
|
966 |
+
case( 'description' ):
|
967 |
+
case( 'textarea' == $field['type'] ):
|
968 |
+
$val = get_user_meta( $userdata->ID, $meta_key, 'true' ); // esc_textarea() is run when field is created.
|
969 |
+
break;
|
970 |
+
|
971 |
+
case 'user_email':
|
972 |
+
case 'confirm_email':
|
973 |
+
$val = sanitize_email( $userdata->user_email );
|
974 |
+
break;
|
975 |
+
|
976 |
+
case 'user_url':
|
977 |
+
$val = $userdata->user_url; // esc_url() is run when the field is created.
|
978 |
+
break;
|
979 |
+
|
980 |
+
case 'display_name':
|
981 |
+
$val = sanitize_text_field( $userdata->display_name );
|
982 |
+
break;
|
983 |
+
|
984 |
+
default:
|
985 |
+
$val = sanitize_text_field( get_user_meta( $userdata->ID, $meta_key, 'true' ) );
|
986 |
+
break;
|
987 |
+
}
|
988 |
+
|
989 |
+
} else {
|
990 |
+
if ( 'file' == $field['type'] ) {
|
991 |
+
$val = ( isset( $_FILES[ $meta_key ]['name'] ) ) ? sanitize_file_name( $_FILES[ $meta_key ]['name'] ) : '' ;
|
992 |
+
} else {
|
993 |
+
$val = ( isset( $_POST[ $meta_key ] ) ) ? $this->sanitize_field( $_POST[ $meta_key ], $field['type'] ) : '';
|
994 |
+
}
|
995 |
+
}
|
996 |
+
|
997 |
+
// Does the tos field.
|
998 |
+
if ( 'tos' == $meta_key ) {
|
999 |
+
|
1000 |
+
// $val = sanitize_text_field( wpmem_get( $meta_key, '' ) );
|
1001 |
+
|
1002 |
+
// Should be checked by default? and only if form hasn't been submitted.
|
1003 |
+
$val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val;
|
1004 |
+
$input = wpmem_form_field( array(
|
1005 |
+
'name' => $meta_key,
|
1006 |
+
'type' => $field['type'],
|
1007 |
+
'value' => $field['checked_value'],
|
1008 |
+
'compare' => $val,
|
1009 |
+
'required' => $field['required'],
|
1010 |
+
) );
|
1011 |
+
$input = ( $field['required'] ) ? $input . $args['req_mark'] : $input;
|
1012 |
+
|
1013 |
+
// Determine if TOS is a WP page or not.
|
1014 |
+
$tos_content = stripslashes( get_option( 'wpmembers_tos' ) );
|
1015 |
+
if ( has_shortcode( $tos_content, 'wpmem_tos' ) || has_shortcode( $tos_content, 'wp-members' ) ) {
|
1016 |
+
$tos_link_url = do_shortcode( $tos_content );
|
1017 |
+
$tos_link_tag = '<a href="' . esc_url( $tos_link_url ) . '" target="_blank">';
|
1018 |
+
} else {
|
1019 |
+
$tos_link_url = add_query_arg( 'tos', 'display' );
|
1020 |
+
$tos_link_tag = "<a href=\"#\" onClick=\"window.open('" . $tos_link_url . "','tos');\">";
|
1021 |
+
}
|
1022 |
+
|
1023 |
+
/**
|
1024 |
+
* Filter the TOS link.
|
1025 |
+
*
|
1026 |
+
* @since 3.2.6
|
1027 |
+
*
|
1028 |
+
* @param string $tos_link_tag
|
1029 |
+
* @param string $tos_link_url
|
1030 |
+
*/
|
1031 |
+
$tos_link_tag = apply_filters( 'wpmem_tos_link_tag', $tos_link_tag, $tos_link_url );
|
1032 |
+
|
1033 |
+
/**
|
1034 |
+
* Filter the TOS link text.
|
1035 |
+
*
|
1036 |
+
* @since 2.7.5
|
1037 |
+
*
|
1038 |
+
* @param string The link text.
|
1039 |
+
* @param string $tag Toggle new registration or profile update. new|edit.
|
1040 |
+
*/
|
1041 |
+
$tos_link_text = apply_filters( 'wpmem_tos_link_txt', $wpmem->get_text( 'register_tos' ), $tag );
|
1042 |
+
|
1043 |
+
// If filtered value is not the default label, use that, otherwise use label.
|
1044 |
+
// @note: if default changes, this check must change.
|
1045 |
+
if ( __( 'Please indicate that you agree to the %s Terms of Service %s', 'wp-members' ) == $tos_link_text ) {
|
1046 |
+
if ( __( 'TOS', 'wp-members' ) != $field['label'] && __( 'Terms of Service', 'wp-members' ) != $field['label'] ) {
|
1047 |
+
$tos_link_text = $field['label'];
|
1048 |
+
}
|
1049 |
+
}
|
1050 |
+
|
1051 |
+
// If tos string does not contain link identifiers (%s), wrap the whole string.
|
1052 |
+
if ( ! strpos( $tos_link_text, '%s' ) ) {
|
1053 |
+
$tos_link_text = '%s' . $tos_link_text . '%s';
|
1054 |
+
}
|
1055 |
+
|
1056 |
+
$input .= ' ' . sprintf( $tos_link_text, $tos_link_tag, '</a>' );
|
1057 |
+
|
1058 |
+
// In previous versions, the div class would end up being the same as the row before.
|
1059 |
+
$field_before = ( $args['wrap_inputs'] ) ? '<div class="div_text">' : '';
|
1060 |
+
$field_after = ( $args['wrap_inputs'] ) ? '</div>' : '';
|
1061 |
+
|
1062 |
+
} elseif ( 'hidden' != $field['type'] ) {
|
1063 |
+
|
1064 |
+
// For checkboxes.
|
1065 |
+
if ( 'checkbox' == $field['type'] ) {
|
1066 |
+
$valtochk = $val;
|
1067 |
+
$val = $field['checked_value'];
|
1068 |
+
// if it should it be checked by default (& only if form not submitted), then override above...
|
1069 |
+
if ( $field['checked_default'] && ( ! $_POST && $tag != 'edit' ) ) {
|
1070 |
+
$val = $valtochk = $field['checked_value'];
|
1071 |
+
}
|
1072 |
+
}
|
1073 |
+
|
1074 |
+
// For dropdown select.
|
1075 |
+
if ( $field['type'] == 'select' || $field['type'] == 'radio' || $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' ) {
|
1076 |
+
$valtochk = $val;
|
1077 |
+
$val = $field['values'];
|
1078 |
+
}
|
1079 |
+
|
1080 |
+
if ( ! isset( $valtochk ) ) {
|
1081 |
+
$valtochk = '';
|
1082 |
+
}
|
1083 |
+
|
1084 |
+
if ( 'edit' == $tag && ( 'file' == $field['type'] || 'image' == $field['type'] ) ) {
|
1085 |
+
|
1086 |
+
$attachment_url = wp_get_attachment_url( $val );
|
1087 |
+
$empty_file = '<span class="description">' . __( 'None' ) . '</span>';
|
1088 |
+
if ( 'file' == $field['type'] ) {
|
1089 |
+
$input = ( $attachment_url ) ? '<a href="' . esc_url( $attachment_url ) . '">' . get_the_title( $val ) . '</a>' : $empty_file;
|
1090 |
+
} else {
|
1091 |
+
$input = ( $attachment_url ) ? '<img src="' . esc_url( $attachment_url ) . '">' : $empty_file;
|
1092 |
+
}
|
1093 |
+
$input.= '<br />' . $wpmem->get_text( 'profile_upload' ) . '<br />';
|
1094 |
+
$input.= wpmem_form_field( array(
|
1095 |
+
'name' => $meta_key,
|
1096 |
+
'type' => $field['type'],
|
1097 |
+
'value' => $val,
|
1098 |
+
'compare' => $valtochk,
|
1099 |
+
'file_types' => $field['file_types'],
|
1100 |
+
) );
|
1101 |
+
|
1102 |
+
} else {
|
1103 |
+
|
1104 |
+
// For all other input types.
|
1105 |
+
$formfield_args = array(
|
1106 |
+
'name' => $meta_key, // ( 'username' == $meta_key ) ? 'user_login' : $meta_key,
|
1107 |
+
'type' => $field['type'],
|
1108 |
+
'value' => $val,
|
1109 |
+
'compare' => $valtochk,
|
1110 |
+
//'class' => ( $class ) ? $class : 'textbox',
|
1111 |
+
'required' => $field['required'],
|
1112 |
+
'placeholder' => ( isset( $field['placeholder'] ) ) ? $field['placeholder'] : '',
|
1113 |
+
'pattern' => ( isset( $field['pattern'] ) ) ? $field['pattern'] : false,
|
1114 |
+
'title' => ( isset( $field['title'] ) ) ? $field['title'] : false,
|
1115 |
+
'min' => ( isset( $field['min'] ) ) ? $field['min'] : false,
|
1116 |
+
'max' => ( isset( $field['max'] ) ) ? $field['max'] : false,
|
1117 |
+
'rows' => ( isset( $field['rows'] ) ) ? $field['rows'] : false,
|
1118 |
+
'cols' => ( isset( $field['cols'] ) ) ? $field['cols'] : false,
|
1119 |
+
'file_types' => ( isset( $field['file_types'] ) ) ? $field['file_types'] : false,
|
1120 |
+
);
|
1121 |
+
if ( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
|
1122 |
+
$formfield_args['delimiter'] = $field['delimiter'];
|
1123 |
+
}
|
1124 |
+
$input = wpmem_form_field( $formfield_args );
|
1125 |
+
|
1126 |
+
}
|
1127 |
+
|
1128 |
+
// Determine input wrappers.
|
1129 |
+
$field_before = ( $args['wrap_inputs'] ) ? '<div class="div_' . $class . '">' : '';
|
1130 |
+
$field_after = ( $args['wrap_inputs'] ) ? '</div>' : '';
|
1131 |
+
}
|
1132 |
+
|
1133 |
+
}
|
1134 |
+
|
1135 |
+
// If the row is set to display, add the row to the form array.
|
1136 |
+
if ( ( 'new' == $tag && $field['register'] ) || ( 'edit' == $tag && $field['profile'] ) ) {
|
1137 |
+
//if ( $field['register'] && 'hidden' != $field['type'] ) {
|
1138 |
+
if ( 'hidden' != $field['type'] ) {
|
1139 |
+
|
1140 |
+
$values = '';
|
1141 |
+
if ( 'multicheckbox' == $field['type'] || 'select' == $field['type'] || 'multiselect' == $field['type'] || 'radio' == $field['type'] ) {
|
1142 |
+
$values = $val;
|
1143 |
+
$val = $valtochk;
|
1144 |
+
}
|
1145 |
+
|
1146 |
+
$rows[ $meta_key ] = array(
|
1147 |
+
'meta' => $meta_key,
|
1148 |
+
'type' => $field['type'],
|
1149 |
+
'value' => $val,
|
1150 |
+
'values' => $values,
|
1151 |
+
'label_text' => __( $field['label'], 'wp-members' ),
|
1152 |
+
'row_before' => $args['row_before'],
|
1153 |
+
'label' => $label,
|
1154 |
+
'field_before' => $field_before,
|
1155 |
+
'field' => $input,
|
1156 |
+
'field_after' => $field_after,
|
1157 |
+
'row_after' => $args['row_after'],
|
1158 |
+
);
|
1159 |
+
}
|
1160 |
+
}
|
1161 |
+
}
|
1162 |
+
|
1163 |
+
// If captcha is Really Simple CAPTCHA.
|
1164 |
+
if ( $wpmem->captcha == 2 && $tag != 'edit' ) {
|
1165 |
+
// Include captcha functions.
|
1166 |
+
require_once( $wpmem->path . 'includes/class-wp-members-captcha.php' );
|
1167 |
+
// Build the captcha.
|
1168 |
+
$row = WP_Members_Captcha::rs_captcha();
|
1169 |
+
$rows['captcha'] = array(
|
1170 |
+
'meta' => '',
|
1171 |
+
'type' => 'text',
|
1172 |
+
'value' => '',
|
1173 |
+
'values' => '',
|
1174 |
+
'label_text' => $row['label_text'],
|
1175 |
+
'row_before' => $args['row_before'],
|
1176 |
+
'label' => $row['label'],
|
1177 |
+
'field_before' => ( $args['wrap_inputs'] ) ? '<div class="div_text">' : '',
|
1178 |
+
'field' => $row['field'],
|
1179 |
+
'field_after' => ( $args['wrap_inputs'] ) ? '</div>' : '',
|
1180 |
+
'row_after' => $args['row_after'],
|
1181 |
+
);
|
1182 |
+
}
|
1183 |
+
|
1184 |
+
/**
|
1185 |
+
* Filter the array of form rows.
|
1186 |
+
*
|
1187 |
+
* This filter receives an array of the main rows in the form, each array element being
|
1188 |
+
* an array of that particular row's pieces. This allows making changes to individual
|
1189 |
+
* parts of a row without needing to parse through a string of HTML.
|
1190 |
+
*
|
1191 |
+
* @since 2.9.0
|
1192 |
+
* @since 3.0.9 Added $rows['label_text'].
|
1193 |
+
* @since 3.1.0 Added $rows['key'].
|
1194 |
+
* @since 3.1.6 Deprecated $rows['order'].
|
1195 |
+
*
|
1196 |
+
* @param array $rows {
|
1197 |
+
* An array containing the form rows.
|
1198 |
+
*
|
1199 |
+
* @type string order Field display order. (deprecated as of 3.1.6)
|
1200 |
+
* @type string meta Field meta tag (not used for display).
|
1201 |
+
* @type string type Input field type (not used for display).
|
1202 |
+
* @type string value Input field value (not used for display).
|
1203 |
+
* @type string values Possible field values (dropdown, multiple select/check, radio).
|
1204 |
+
* @type string label_text Raw text for the label (not used for display).
|
1205 |
+
* @type string row_before Opening wrapper tag around the row.
|
1206 |
+
* @type string label Label tag.
|
1207 |
+
* @type string field_before Opening wrapper tag before the input tag.
|
1208 |
+
* @type string field The field input tag.
|
1209 |
+
* @type string field_after Closing wrapper tag around the input tag.
|
1210 |
+
* @type string row_after Closing wrapper tag around the row.
|
1211 |
+
* }
|
1212 |
+
* @param string $tag Toggle new registration or profile update. new|edit.
|
1213 |
+
*/
|
1214 |
+
$rows = apply_filters( 'wpmem_register_form_rows', $rows, $tag );
|
1215 |
+
|
1216 |
+
// Make sure all keys are set just in case someone didn't return a proper array through the filter.
|
1217 |
+
// @todo Merge this with the next foreach loop so we only have to foreach one time.
|
1218 |
+
$row_keys = array( 'meta', 'type', 'value', 'values', 'label_text', 'row_before', 'label', 'field_before', 'field', 'field_after', 'row_after' );
|
1219 |
+
foreach ( $rows as $meta_key => $row ) {
|
1220 |
+
foreach ( $row_keys as $check_key ) {
|
1221 |
+
$rows[ $meta_key ][ $check_key ] = ( isset( $rows[ $meta_key ][ $check_key ] ) ) ? $rows[ $meta_key ][ $check_key ] : '';
|
1222 |
+
}
|
1223 |
+
}
|
1224 |
+
|
1225 |
+
// Put the rows from the array into $form.
|
1226 |
+
$form = ''; $enctype = '';
|
1227 |
+
foreach ( $rows as $row_item ) {
|
1228 |
+
// Check form to see if we need multipart enctype.
|
1229 |
+
$enctype = ( $row_item['type'] == 'file' || $row_item['type'] == 'image' ) ? "multipart/form-data" : $enctype;
|
1230 |
+
// Assemble row pieces.
|
1231 |
+
$row = ( $row_item['row_before'] != '' ) ? $row_item['row_before'] . $args['n'] . $row_item['label'] . $args['n'] : $row_item['label'] . $args['n'];
|
1232 |
+
$row .= ( $row_item['field_before'] != '' ) ? $row_item['field_before'] . $args['n'] . $args['t'] . $row_item['field'] . $args['n'] . $row_item['field_after'] . $args['n'] : $row_item['field'] . $args['n'];
|
1233 |
+
$row .= ( $row_item['row_after'] != '' ) ? $row_item['row_after'] . $args['n'] : '';
|
1234 |
+
$form.= $row;
|
1235 |
+
}
|
1236 |
+
|
1237 |
+
// Do recaptcha if enabled.
|
1238 |
+
if ( ( 1 == $wpmem->captcha || 3 == $wpmem->captcha || 4 == $wpmem->captcha ) && $tag != 'edit' ) { // don't show on edit page!
|
1239 |
+
|
1240 |
+
// Include captcha functions.
|
1241 |
+
require_once( $wpmem->path . 'includes/class-wp-members-captcha.php' );
|
1242 |
+
|
1243 |
+
// Get the captcha options.
|
1244 |
+
$wpmem_captcha = get_option( 'wpmembers_captcha' );
|
1245 |
+
|
1246 |
+
if ( 4 == $wpmem->captcha ) {
|
1247 |
+
|
1248 |
+
$row = '<script src="https://www.google.com/recaptcha/api.js?render=' . $wpmem_captcha['recaptcha']['public'] . '"></script>';
|
1249 |
+
$row.= "<script>
|
1250 |
+
grecaptcha.ready(function () {
|
1251 |
+
grecaptcha.execute('" . $wpmem_captcha['recaptcha']['public'] . "', { action: 'contact' }).then(function (token) {
|
1252 |
+
var recaptchaResponse = document.getElementById('recaptchaResponse');
|
1253 |
+
recaptchaResponse.value = token;
|
1254 |
+
});
|
1255 |
+
});
|
1256 |
+
</script>";
|
1257 |
+
$row.= '<input type="hidden" name="recaptcha_response" id="recaptchaResponse">';
|
1258 |
+
|
1259 |
+
} else {
|
1260 |
+
|
1261 |
+
// Start with a clean row.
|
1262 |
+
$row = '';
|
1263 |
+
$row = '<div class="clear"></div>';
|
1264 |
+
$row.= '<div class="captcha">';
|
1265 |
+
|
1266 |
+
$row.= WP_Members_Captcha::recaptcha( $wpmem_captcha['recaptcha'] );
|
1267 |
+
|
1268 |
+
$row.= '</div>';
|
1269 |
+
}
|
1270 |
+
|
1271 |
+
// Add the captcha row to the form.
|
1272 |
+
/**
|
1273 |
+
* Filter the HTML for the CAPTCHA row.
|
1274 |
+
*
|
1275 |
+
* @since 2.9.0
|
1276 |
+
*
|
1277 |
+
* @param string The HTML for the entire row (includes HTML tags plus reCAPTCHA).
|
1278 |
+
* @param string $tag Toggle new registration or profile update. new|edit.
|
1279 |
+
*/
|
1280 |
+
$form.= apply_filters( 'wpmem_register_captcha_row', $args['row_before'] . $row . $args['row_after'], $tag );
|
1281 |
+
}
|
1282 |
+
|
1283 |
+
// Create hidden fields.
|
1284 |
+
$var = ( $tag == 'edit' ) ? 'update' : 'register';
|
1285 |
+
$redirect_to = ( isset( $_REQUEST['redirect_to'] ) ) ? $_REQUEST['redirect_to'] : ( ( $redirect_to ) ? $redirect_to : get_permalink() );
|
1286 |
+
$hidden_rows['_wpmem_a'] = '<input name="a" type="hidden" value="' . esc_attr( $var ) . '" />';
|
1287 |
+
$hidden_rows['_wpmem_reg_page'] = '<input name="wpmem_reg_page" type="hidden" value="' . esc_url( get_permalink() ) . '" />';
|
1288 |
+
if ( $redirect_to != get_permalink() ) {
|
1289 |
+
$hidden_rows['_wpmem_redirect_to'] = '<input name="redirect_to" type="hidden" value="' . esc_url( $redirect_to ) . '" />';
|
1290 |
+
}
|
1291 |
+
|
1292 |
+
/**
|
1293 |
+
* Filter the hidden form rows.
|
1294 |
+
*
|
1295 |
+
* @since 3.2.0
|
1296 |
+
*
|
1297 |
+
* @param array $hidden_rows
|
1298 |
+
* @param string $tag
|
1299 |
+
*/
|
1300 |
+
$hidden_rows = apply_filters( 'wpmem_register_hidden_rows', $hidden_rows, $tag );
|
1301 |
+
|
1302 |
+
// Assemble hidden fields HTML.
|
1303 |
+
$hidden = '';
|
1304 |
+
foreach ( $hidden_rows as $hidden_row ) {
|
1305 |
+
$hidden .= $hidden_row . $args['n'];
|
1306 |
+
}
|
1307 |
+
|
1308 |
+
/**
|
1309 |
+
* Filter the hidden field HTML.
|
1310 |
+
*
|
1311 |
+
* @since 2.9.0
|
1312 |
+
*
|
1313 |
+
* @param string $hidden The generated HTML of hidden fields.
|
1314 |
+
* @param string $tag Toggle new registration or profile update. new|edit.
|
1315 |
+
*/
|
1316 |
+
$hidden = apply_filters( 'wpmem_register_hidden_fields', $hidden, $tag );
|
1317 |
+
|
1318 |
+
// Add the hidden fields to the form.
|
1319 |
+
$form.= $hidden;
|
1320 |
+
|
1321 |
+
// Create buttons and wrapper.
|
1322 |
+
$button_text = ( $tag == 'edit' ) ? $args['submit_update'] : $args['submit_register'];
|
1323 |
+
$button_html = array(
|
1324 |
+
'reset' => ( $args['show_clear_form'] ) ? '<input name="reset" type="reset" value="' . esc_attr( $args['clear_form'] ) . '" class="' . $this->sanitize_class( $args['button_class'] ) . '" /> ' : '',
|
1325 |
+
'submit' => '<input name="submit" type="submit" value="' . esc_attr( $button_text ) . '" class="' . $this->sanitize_class( $args['button_class'] ) . '" />',
|
1326 |
+
);
|
1327 |
+
$buttons = $button_html['reset'] . $args['n'] . $button_html['submit'] . $args['n'];
|
1328 |
+
|
1329 |
+
/**
|
1330 |
+
* Filter the HTML for form buttons.
|
1331 |
+
*
|
1332 |
+
* The string passed through the filter includes the buttons, as well as the HTML wrapper elements.
|
1333 |
+
*
|
1334 |
+
* @since 2.9.0
|
1335 |
+
* @since 3.2.6 Added $button_html parameter
|
1336 |
+
*
|
1337 |
+
* @param string $buttons The generated HTML of the form buttons.
|
1338 |
+
* @param string $tag Toggle new registration or profile update. new|edit.
|
1339 |
+
* @param array $button_html The individual button html.
|
1340 |
+
*/
|
1341 |
+
$buttons = apply_filters( 'wpmem_register_form_buttons', $buttons, $tag, $button_html );
|
1342 |
+
|
1343 |
+
// Add the buttons to the form.
|
1344 |
+
$form.= $args['buttons_before'] . $args['n'] . $buttons . $args['buttons_after'] . $args['n'];
|
1345 |
+
|
1346 |
+
// Add the required field notation to the bottom of the form.
|
1347 |
+
$form.= $args['req_label_before'] . $args['req_label'] . $args['req_label_after'];
|
1348 |
+
|
1349 |
+
// Apply the heading.
|
1350 |
+
if ( 'edit' == $tag ) {
|
1351 |
+
/**
|
1352 |
+
* Filter the default heading in User Profile edit mode.
|
1353 |
+
*
|
1354 |
+
* @since 2.7.5
|
1355 |
+
* @since 3.3.0 Moved into main registration function (from profile shortcode).
|
1356 |
+
*
|
1357 |
+
* @param string The default edit mode heading.
|
1358 |
+
*/
|
1359 |
+
$heading = ( isset( $heading ) ) ? $headhing : apply_filters( 'wpmem_user_edit_heading', $wpmem->get_text( 'profile_heading' ) );
|
1360 |
+
} else {
|
1361 |
+
/**
|
1362 |
+
* Filter the registration form heading.
|
1363 |
+
*
|
1364 |
+
* @since 2.8.2
|
1365 |
+
*
|
1366 |
+
* @param string $str
|
1367 |
+
* @param string $tag Toggle new registration or profile update. new|edit.
|
1368 |
+
*/
|
1369 |
+
$heading = ( isset( $heading ) ) ? $headhing : apply_filters( 'wpmem_register_heading', $wpmem->get_text( 'register_heading' ), $tag );
|
1370 |
+
}
|
1371 |
+
$form = $args['heading_before'] . $heading . $args['heading_after'] . $args['n'] . $form;
|
1372 |
+
|
1373 |
+
// Apply fieldset wrapper.
|
1374 |
+
$form = $args['fieldset_before'] . $args['n'] . $form . $args['n'] . $args['fieldset_after'];
|
1375 |
+
|
1376 |
+
// Apply attribution if enabled.
|
1377 |
+
$form = $form . $this->attribution();
|
1378 |
+
|
1379 |
+
// Apply nonce. Nonce uses $tag value of the form processor, NOT the form builder.
|
1380 |
+
$nonce = ( $tag == 'edit' ) ? 'update' : 'register';
|
1381 |
+
$form = wp_nonce_field( 'wpmem_longform_nonce', '_wpmem_' . $nonce . '_nonce', true, false ) . $args['n'] . $form;
|
1382 |
+
|
1383 |
+
// Apply form wrapper.
|
1384 |
+
$enctype = ( $enctype == 'multipart/form-data' ) ? ' enctype="multipart/form-data"' : '';
|
1385 |
+
$form = '<form name="form" method="post"' . $enctype . ' action="' . esc_attr( $args['post_to'] ) . '" id="' . $this->sanitize_class( $args['form_id'] ) . '" class="' . $this->sanitize_class( $args['form_class'] ) . '">' . $args['n'] . $form . $args['n'] . '</form>';
|
1386 |
+
|
1387 |
+
// Apply anchor.
|
1388 |
+
$form = '<a id="register"></a>' . $args['n'] . $form;
|
1389 |
+
|
1390 |
+
// Apply main div wrapper.
|
1391 |
+
$form = $args['main_div_before'] . $args['n'] . $form . $args['n'] . $args['main_div_after'] . $args['n'];
|
1392 |
+
|
1393 |
+
// Apply wpmem_txt wrapper.
|
1394 |
+
$form = $args['txt_before'] . $form . $args['txt_after'];
|
1395 |
+
|
1396 |
+
// Remove line breaks if enabled for easier filtering later.
|
1397 |
+
$form = ( $args['strip_breaks'] ) ? $this->strip_breaks( $form, $rows ) : $form; //str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form ) : $form;
|
1398 |
+
|
1399 |
+
/**
|
1400 |
+
* Filter the generated HTML of the entire form.
|
1401 |
+
*
|
1402 |
+
* @since 2.7.4
|
1403 |
+
*
|
1404 |
+
* @param string $form The HTML of the final generated form.
|
1405 |
+
* @param string $tag Toggle new registration or profile update. new|edit.
|
1406 |
+
* @param array $rows {
|
1407 |
+
* An array containing the form rows.
|
1408 |
+
*
|
1409 |
+
* @type string order Field display order.
|
1410 |
+
* @type string meta Field meta tag (not used for display).
|
1411 |
+
* @type string type Input field type (not used for display).
|
1412 |
+
* @type string value Input field value (not used for display).
|
1413 |
+
* @type string values The possible values for the field (dropdown, multiple select/checkbox, radio group).
|
1414 |
+
* @type string label_text Raw text for the label (not used for display).
|
1415 |
+
* @type string row_before Opening wrapper tag around the row.
|
1416 |
+
* @type string label Label tag.
|
1417 |
+
* @type string field_before Opening wrapper tag before the input tag.
|
1418 |
+
* @type string field The field input tag.
|
1419 |
+
* @type string field_after Closing wrapper tag around the input tag.
|
1420 |
+
* @type string row_after Closing wrapper tag around the row.
|
1421 |
+
* }
|
1422 |
+
* @param string $hidden The HTML string of hidden fields
|
1423 |
+
*/
|
1424 |
+
$form = apply_filters( 'wpmem_register_form', $form, $tag, $rows, $hidden );
|
1425 |
+
|
1426 |
+
/**
|
1427 |
+
* Filter before the form.
|
1428 |
+
*
|
1429 |
+
* This rarely used filter allows you to stick any string onto the front of
|
1430 |
+
* the generated form.
|
1431 |
+
*
|
1432 |
+
* @since 2.7.4
|
1433 |
+
*
|
1434 |
+
* @param string $str The HTML to add before the form. Default null.
|
1435 |
+
* @param string $tag Toggle new registration or profile update. new|edit.
|
1436 |
+
*/
|
1437 |
+
$form = apply_filters( 'wpmem_register_form_before', '', $tag ) . $form;
|
1438 |
+
|
1439 |
+
// Return the generated form.
|
1440 |
+
return $form;
|
1441 |
+
} // End register_form().
|
1442 |
+
|
1443 |
+
/**
|
1444 |
+
* Strip line breaks from form.
|
1445 |
+
*
|
1446 |
+
* Function removes line breaks and tabs. Checks for textarea fields
|
1447 |
+
* before stripping line breaks.
|
1448 |
+
*
|
1449 |
+
* @since 3.1.8
|
1450 |
+
*
|
1451 |
+
* @param string $form
|
1452 |
+
* @param array $rows
|
1453 |
+
* @return string $form
|
1454 |
+
*/
|
1455 |
+
function strip_breaks( $form, $rows ) {
|
1456 |
+
foreach( $rows as $key => $row ) {
|
1457 |
+
if ( 'textarea' == $row['type'] ) {
|
1458 |
+
$textareas[ $key ] = $row['field'];
|
1459 |
+
}
|
1460 |
+
}
|
1461 |
+
$form = str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form );
|
1462 |
+
if ( ! empty ( $textareas ) ) {
|
1463 |
+
foreach ( $textareas as $textarea ) {
|
1464 |
+
$stripped = str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $textarea );
|
1465 |
+
$form = str_replace( $stripped, $textarea, $form );
|
1466 |
+
}
|
1467 |
+
}
|
1468 |
+
return $form;
|
1469 |
+
}
|
1470 |
+
|
1471 |
+
/**
|
1472 |
+
* Login Dialog.
|
1473 |
+
*
|
1474 |
+
* Loads the login form for user login.
|
1475 |
+
*
|
1476 |
+
* @since 1.8
|
1477 |
+
* @since 3.1.4 Global $wpmem_regchk no longer needed.
|
1478 |
+
* @since 3.2.0 Moved to forms class, renamed do_login_form().
|
1479 |
+
*
|
1480 |
+
* @global object $post The WordPress Post object.
|
1481 |
+
* @global object $wpmem The WP_Members object.
|
1482 |
+
* @param string $page If the form is being displayed in place of blocked content. Default: page.
|
1483 |
+
* @param string $redirect_to Redirect URL. Default: null.
|
1484 |
+
* @param string $show If the form is being displayed in place of blocked content. Default: show.
|
1485 |
+
* @return string $str The generated html for the login form.
|
1486 |
+
*/
|
1487 |
+
function do_login_form( $page = "page", $redirect_to = null, $show = 'show' ) {
|
1488 |
+
|
1489 |
+
global $post, $wpmem;
|
1490 |
+
|
1491 |
+
$msg = '';
|
1492 |
+
|
1493 |
+
if ( 'page' == $page ) {
|
1494 |
+
$msg = $this->add_restricted_msg();
|
1495 |
+
}
|
1496 |
+
|
1497 |
+
// Create the default inputs.
|
1498 |
+
$default_inputs = array(
|
1499 |
+
array(
|
1500 |
+
'name' => $wpmem->get_text( 'login_username' ),
|
1501 |
+
'type' => 'text',
|
1502 |
+
'tag' => 'log',
|
1503 |
+
'class' => 'username',
|
1504 |
+
'div' => 'div_text',
|
1505 |
+
),
|
1506 |
+
array(
|
1507 |
+
'name' => $wpmem->get_text( 'login_password' ),
|
1508 |
+
'type' => 'password',
|
1509 |
+
'tag' => 'pwd',
|
1510 |
+
'class' => 'password',
|
1511 |
+
'div' => 'div_text',
|
1512 |
+
),
|
1513 |
+
);
|
1514 |
+
|
1515 |
+
/**
|
1516 |
+
* Filter the array of login form fields.
|
1517 |
+
*
|
1518 |
+
* @since 2.9.0
|
1519 |
+
* @deprecated 3.3.0 Use wpmem_login_form_defaults instead.
|
1520 |
+
*
|
1521 |
+
* @param array $default_inputs An array matching the elements used by default.
|
1522 |
+
*/
|
1523 |
+
$default_inputs = apply_filters( 'wpmem_inc_login_inputs', $default_inputs );
|
1524 |
+
|
1525 |
+
$defaults = array(
|
1526 |
+
'heading' => $wpmem->get_text( 'login_heading' ),
|
1527 |
+
'action' => 'login',
|
1528 |
+
'button_text' => $wpmem->get_text( 'login_button' ),
|
1529 |
+
'inputs' => $default_inputs,
|
1530 |
+
'redirect_to' => $redirect_to,
|
1531 |
+
);
|
1532 |
+
|
1533 |
+
/**
|
1534 |
+
* Filter the arguments to override login form defaults.
|
1535 |
+
*
|
1536 |
+
* @since 2.9.0
|
1537 |
+
* @deprecated 3.3.0 Use wpmem_login_form_defaults instead.
|
1538 |
+
*
|
1539 |
+
* @param array $args An array of arguments to use. Default null.
|
1540 |
+
*/
|
1541 |
+
$args = apply_filters( 'wpmem_inc_login_args', '' );
|
1542 |
+
$arr = wp_parse_args( $args, $defaults );
|
1543 |
+
|
1544 |
+
/**
|
1545 |
+
* Filter the arguments to override login form defaults.
|
1546 |
+
*
|
1547 |
+
* @since 3.3.0
|
1548 |
+
*
|
1549 |
+
* @param array $args {
|
1550 |
+
* @type string $heading
|
1551 |
+
* @type string $action
|
1552 |
+
* @type string $button_text
|
1553 |
+
* @type string $redirect_to
|
1554 |
+
* @type array $inputs {
|
1555 |
+
* @type string $name
|
1556 |
+
* @type string $type
|
1557 |
+
* @type string $tag
|
1558 |
+
* @type string $class
|
1559 |
+
* @type string $div
|
1560 |
+
* }
|
1561 |
+
* }
|
1562 |
+
*/
|
1563 |
+
$arr = apply_filters( 'wpmem_login_form_defaults', $arr );
|
1564 |
+
|
1565 |
+
return ( $show == 'show' ) ? $msg . wpmem_login_form( $page, $arr ) : $msg;
|
1566 |
+
}
|
1567 |
+
|
1568 |
+
/**
|
1569 |
+
* Appends WP-Members registration fields to wp-login.php registration form.
|
1570 |
+
*
|
1571 |
+
* @since 2.8.7
|
1572 |
+
* @since 3.1.1 Updated to support new (3.1.0) field types.
|
1573 |
+
* @since 3.1.6 Updated to support new fields array. Added WC classes.
|
1574 |
+
* @since 3.1.8 Added $process parameter.
|
1575 |
+
* @since 3.3.0 Ported from wpmem_do_wp_register_form() in wp-registration.php.
|
1576 |
+
*
|
1577 |
+
* @global stdClass $wpmem
|
1578 |
+
* @param string $process
|
1579 |
+
*/
|
1580 |
+
function wp_register_form( $process = 'wp' ) {
|
1581 |
+
|
1582 |
+
global $wpmem;
|
1583 |
+
$wpmem_fields = wpmem_fields( $process );
|
1584 |
+
|
1585 |
+
// Check if this is WooCommerce account page.
|
1586 |
+
$is_woo = false;
|
1587 |
+
if ( 'woo' == $process ) {
|
1588 |
+
$is_woo = true;
|
1589 |
+
} else {
|
1590 |
+
if ( function_exists( 'is_account_page' ) ) {
|
1591 |
+
$is_woo = ( is_account_page() ) ? true : $is_woo;
|
1592 |
+
}
|
1593 |
+
}
|
1594 |
+
|
1595 |
+
if ( isset( $wpmem_fields ) && is_array( $wpmem_fields ) ) {
|
1596 |
+
|
1597 |
+
unset( $wpmem_fields['username'] );
|
1598 |
+
|
1599 |
+
foreach ( $wpmem_fields as $meta_key => $field ) {
|
1600 |
+
|
1601 |
+
$req = ( $field['required'] ) ? ( ( $is_woo ) ? ' <span class="required">*</span>' : ' <span class="req">' . __( '(required)' ) . '</span>' ) : '';
|
1602 |
+
|
1603 |
+
// File fields not yet supported for this form.
|
1604 |
+
if ( $field['register'] && $meta_key != 'user_email' && $field['type'] != 'file' && $field['type'] != 'image' ) {
|
1605 |
+
|
1606 |
+
if ( 'checkbox' == $field['type'] ) {
|
1607 |
+
|
1608 |
+
if ( 'tos' == $meta_key ) {
|
1609 |
+
$tos_content = stripslashes( get_option( 'wpmembers_tos' ) );
|
1610 |
+
if ( has_shortcode( $tos_content, 'wpmem_tos' ) || has_shortcode( $tos_content, 'wp-members' ) ) {
|
1611 |
+
$link = do_shortcode( $tos_content );
|
1612 |
+
$tos_pop = '<a href="' . esc_url( $link ) . '" target="_blank">';
|
1613 |
+
} else {
|
1614 |
+
$tos_pop = "<a href=\"#\" onClick=\"window.open('" . $wpmem->url . "/wp-members-tos.php','mywindow');\">";
|
1615 |
+
}
|
1616 |
+
/** This filter is documented in includes/class-wp-members-forms.php */
|
1617 |
+
$tos_link_text = apply_filters( 'wpmem_tos_link_txt', $wpmem->get_text( 'register_tos' ), 'new' );
|
1618 |
+
|
1619 |
+
// If filtered value is not the default label, use that, otherwise use label.
|
1620 |
+
// @note: if default changes, this check must change.
|
1621 |
+
if ( __( 'Please indicate that you agree to the %s Terms of Service %s', 'wp-members' ) == $tos_link_text ) {
|
1622 |
+
if ( __( 'TOS', 'wp-members' ) != $field['label'] && __( 'Terms of Service', 'wp-members' ) != $field['label'] ) {
|
1623 |
+
$tos_link_text = $field['label'];
|
1624 |
+
}
|
1625 |
+
}
|
1626 |
+
|
1627 |
+
// If tos string does not contain link identifiers (%s), wrap the whole string.
|
1628 |
+
if ( ! strpos( $tos_link_text, '%s' ) ) {
|
1629 |
+
$tos_link_text = '%s' . $tos_link_text . '%s';
|
1630 |
+
}
|
1631 |
+
|
1632 |
+
$tos_link_text = ' ' . sprintf( $tos_link_text, $tos_pop, '</a>' );
|
1633 |
+
|
1634 |
+
}
|
1635 |
+
|
1636 |
+
$label = ( 'tos' == $meta_key ) ? $tos_link_text : __( $field['label'], 'wp-members' );
|
1637 |
+
|
1638 |
+
$val = ( isset( $_POST[ $meta_key ] ) ) ? esc_attr( $_POST[ $meta_key ] ) : '';
|
1639 |
+
$val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val;
|
1640 |
+
|
1641 |
+
$row_before = '<p class="wpmem-checkbox">';
|
1642 |
+
$label = '<label for="' . $meta_key . '">' . $label . $req;
|
1643 |
+
$input = wpmem_form_field( $meta_key, $field['type'], $field['checked_value'], $val );
|
1644 |
+
$row_after = '</label></p>';
|
1645 |
+
|
1646 |
+
} elseif ( 'hidden' == $field['type'] ) {
|
1647 |
+
|
1648 |
+
// Handle hidden fields
|
1649 |
+
$row_before = '';
|
1650 |
+
$label = '';
|
1651 |
+
$input = wpmem_form_field( array(
|
1652 |
+
'name' => $meta_key,
|
1653 |
+
'type' => $field['type'],
|
1654 |
+
'value' => $field['value'],
|
1655 |
+
'compare' => $valtochk,
|
1656 |
+
'required' => $field['required'],
|
1657 |
+
) );
|
1658 |
+
$row_after = '';
|
1659 |
+
|
1660 |
+
} else {
|
1661 |
+
|
1662 |
+
$row_before = ( $is_woo ) ? '<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">' : '<p>';
|
1663 |
+
$label = '<label for="' . $meta_key . '">' . __( $field['label'], 'wp-members' ) . $req . '<br />';
|
1664 |
+
|
1665 |
+
// determine the field type and generate accordingly...
|
1666 |
+
|
1667 |
+
switch ( $field['type'] ) {
|
1668 |
+
|
1669 |
+
case( 'select' ):
|
1670 |
+
$val = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
|
1671 |
+
$input = wpmem_create_formfield( $meta_key, $field['type'], $field['values'], $val );
|
1672 |
+
break;
|
1673 |
+
|
1674 |
+
case( 'textarea' ):
|
1675 |
+
$input = '<textarea name="' . $meta_key . '" id="' . $meta_key . '" class="textarea">';
|
1676 |
+
$input.= ( isset( $_POST[ $meta_key ] ) ) ? esc_textarea( $_POST[ $meta_key ] ) : '';
|
1677 |
+
$input.= '</textarea>';
|
1678 |
+
break;
|
1679 |
+
|
1680 |
+
case( 'multiselect' ):
|
1681 |
+
case( 'multicheckbox' ):
|
1682 |
+
case( 'radio' ):
|
1683 |
+
$row_before = '<p class="' . $field['type'] . '">';
|
1684 |
+
$valtochk = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
|
1685 |
+
$formfield_args = array(
|
1686 |
+
'name' => $meta_key,
|
1687 |
+
'type' => $field['type'],
|
1688 |
+
'value' => $field['values'],
|
1689 |
+
'compare' => $valtochk,
|
1690 |
+
'required' => ( $field['required'] ) ? true : false,
|
1691 |
+
);
|
1692 |
+
if ( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
|
1693 |
+
$formfield_args['delimiter'] = $field['delimiter'];
|
1694 |
+
}
|
1695 |
+
$input = $this->create_form_field( $formfield_args );
|
1696 |
+
break;
|
1697 |
+
|
1698 |
+
case( 'file' ):
|
1699 |
+
case( 'image' ):
|
1700 |
+
// Field type not supported for this yet.
|
1701 |
+
break;
|
1702 |
+
|
1703 |
+
default:
|
1704 |
+
$class = ( $is_woo ) ? 'woocommerce-Input woocommerce-Input--text input-text' : 'input';
|
1705 |
+
//$input = '<input type="' . $field['type'] . '" name="' . $meta_key . '" id="' . $meta_key . '" class="' . $class . '" value="';
|
1706 |
+
$input = wpmem_form_field( array(
|
1707 |
+
'name' => $meta_key,
|
1708 |
+
'type' => $field['type'],
|
1709 |
+
'value' => $this->sanitize_field( wpmem_get( $meta_key, '' ), $field['type'] ),
|
1710 |
+
'compare' => ( isset( $field['compare'] ) ) ? $field['compare'] : '',
|
1711 |
+
'placeholder' => ( isset( $field['placeholder'] ) ) ? $field['placeholder'] : '',
|
1712 |
+
) );
|
1713 |
+
//$input.= ( isset( $_POST[ $meta_key ] ) ) ? esc_attr( $_POST[ $meta_key ] ) : '';
|
1714 |
+
//$input.= '" size="25" />';
|
1715 |
+
break;
|
1716 |
+
}
|
1717 |
+
|
1718 |
+
$row_after = '</label></p>';
|
1719 |
+
|
1720 |
+
}
|
1721 |
+
|
1722 |
+
// if the row is set to display, add the row to the form array
|
1723 |
+
$rows[ $meta_key ] = array(
|
1724 |
+
'type' => $field['type'],
|
1725 |
+
'row_before' => $row_before,
|
1726 |
+
'label' => $label,
|
1727 |
+
'field' => $input,
|
1728 |
+
'row_after' => $row_after,
|
1729 |
+
);
|
1730 |
+
}
|
1731 |
+
}
|
1732 |
+
|
1733 |
+
if ( isset( $rows ) && is_array( $rows ) ) {
|
1734 |
+
|
1735 |
+
/**
|
1736 |
+
* Filter the native registration form rows.
|
1737 |
+
*
|
1738 |
+
* @since 2.9.3.
|
1739 |
+
*
|
1740 |
+
* @param array $rows The custom rows added to the form.
|
1741 |
+
*/
|
1742 |
+
$rows = apply_filters( 'wpmem_native_form_rows', $rows );
|
1743 |
+
|
1744 |
+
foreach ( $rows as $row_item ) {
|
1745 |
+
if ( $row_item['type'] == 'checkbox' ) {
|
1746 |
+
echo $row_item['row_before'] . $row_item['field'] . $row_item['label'] . $row_item['row_after'];
|
1747 |
+
} else {
|
1748 |
+
echo $row_item['row_before'] . $row_item['label'] . $row_item['field'] . $row_item['row_after'];
|
1749 |
+
}
|
1750 |
+
}
|
1751 |
+
}
|
1752 |
+
}
|
1753 |
+
}
|
1754 |
+
|
1755 |
+
|
1756 |
+
/**
|
1757 |
+
* Appends WP-Members registration fields to Users > Add New User screen.
|
1758 |
+
*
|
1759 |
+
* @since 2.9.0
|
1760 |
+
* @since 3.1.1 Updated to support new (3.1.0) field types and user activation.
|
1761 |
+
* @since 3.1.6 Updated to support new fields array.
|
1762 |
+
* @since 3.3.0 Ported from wpmem_do_wp_newuser_form() in wp-registration.php.
|
1763 |
+
*
|
1764 |
+
* @global stdClass $wpmem
|
1765 |
+
*/
|
1766 |
+
function wp_newuser_form() {
|
1767 |
+
|
1768 |
+
global $wpmem;
|
1769 |
+
echo '<table class="form-table"><tbody>';
|
1770 |
+
|
1771 |
+
$wpmem_fields = wpmem_fields( 'add_new' );
|
1772 |
+
$exclude = wpmem_get_excluded_meta( 'wp-register' );
|
1773 |
+
|
1774 |
+
foreach ( $wpmem_fields as $meta_key => $field ) {
|
1775 |
+
|
1776 |
+
if ( ! $field['native'] && ! in_array( $meta_key, $exclude ) ) {
|
1777 |
+
|
1778 |
+
$req = ( $field['required'] ) ? ' <span class="description">' . __( '(required)' ) . '</span>' : '';
|
1779 |
+
|
1780 |
+
echo '<tr>
|
1781 |
+
<th scope="row">
|
1782 |
+
<label for="' . $meta_key . '">' . __( $field['label'], 'wp-members' ) . $req . '</label>
|
1783 |
+
</th>
|
1784 |
+
<td>';
|
1785 |
+
|
1786 |
+
// determine the field type and generate accordingly.
|
1787 |
+
|
1788 |
+
switch ( $field['type'] ) {
|
1789 |
+
|
1790 |
+
case( 'select' ):
|
1791 |
+
$val = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
|
1792 |
+
echo wpmem_create_formfield( $meta_key, $field['type'], $field['values'], $val );
|
1793 |
+
break;
|
1794 |
+
|
1795 |
+
case( 'textarea' ):
|
1796 |
+
echo '<textarea name="' . $meta_key . '" id="' . $meta_key . '" class="textarea">';
|
1797 |
+
echo ( isset( $_POST[ $meta_key ] ) ) ? esc_textarea( $_POST[ $meta_key ] ) : '';
|
1798 |
+
echo '</textarea>';
|
1799 |
+
break;
|
1800 |
+
|
1801 |
+
case( 'checkbox' ):
|
1802 |
+
$val = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
|
1803 |
+
$val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val;
|
1804 |
+
echo wpmem_create_formfield( $meta_key, $field['type'], $field['checked_value'], $val );
|
1805 |
+
break;
|
1806 |
+
|
1807 |
+
case( 'multiselect' ):
|
1808 |
+
case( 'multicheckbox' ):
|
1809 |
+
case( 'radio' ):
|
1810 |
+
$valtochk = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
|
1811 |
+
$formfield_args = array(
|
1812 |
+
'name' => $meta_key,
|
1813 |
+
'type' => $field['type'],
|
1814 |
+
'value' => $field['values'],
|
1815 |
+
'compare' => $valtochk,
|
1816 |
+
'required' => $field['required'],
|
1817 |
+
);
|
1818 |
+
if ( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
|
1819 |
+
$formfield_args['delimiter'] = $field['delimiter'];
|
1820 |
+
}
|
1821 |
+
echo $this->create_form_field( $formfield_args );
|
1822 |
+
break;
|
1823 |
+
|
1824 |
+
case( 'file' ):
|
1825 |
+
case( 'image' ):
|
1826 |
+
break;
|
1827 |
+
|
1828 |
+
default:
|
1829 |
+
echo '<input type="' . $field['type'] . '" name="' . $meta_key . '" id="' . $meta_key . '" class="input" value="'; echo ( isset( $_POST[ $meta_key ] ) ) ? esc_attr( $_POST[ $meta_key ] ) : ''; echo '" size="25" />';
|
1830 |
+
break;
|
1831 |
+
}
|
1832 |
+
|
1833 |
+
echo '</td>
|
1834 |
+
</tr>';
|
1835 |
+
|
1836 |
+
}
|
1837 |
+
}
|
1838 |
+
|
1839 |
+
// If moderated registration is enabled, add checkbox to set user as active.
|
1840 |
+
if ( 1 == $wpmem->mod_reg ) {
|
1841 |
+
echo '<tr>
|
1842 |
+
<th scope="row">
|
1843 |
+
<label for="activate_user">' . __( 'Activate this user?', 'wp-members' ) . '</label>
|
1844 |
+
</th>
|
1845 |
+
<td>' . $this->create_form_field( array( 'name' => 'activate_user', 'type' => 'checkbox', 'value' => 1, 'compare' => '' ) ) . '</td>
|
1846 |
+
</tr>';
|
1847 |
+
}
|
1848 |
+
|
1849 |
+
echo '</tbody></table>';
|
1850 |
+
|
1851 |
+
}
|
1852 |
+
|
1853 |
+
/**
|
1854 |
+
* Create an attribution link in the form.
|
1855 |
+
*
|
1856 |
+
* @since 2.6.0
|
1857 |
+
* @since 3.1.1 Updated to use new object setting.
|
1858 |
+
* @since 3.3.0 Ported from wpmem_inc_attribution() in forms.php.
|
1859 |
+
*
|
1860 |
+
* @global object $wpmem
|
1861 |
+
* @return string $str
|
1862 |
+
*/
|
1863 |
+
function attribution() {
|
1864 |
+
|
1865 |
+
global $wpmem;
|
1866 |
+
$str = '
|
1867 |
+
<div align="center">
|
1868 |
+
<small>Powered by <a href="https://rocketgeek.com" target="_blank">WP-Members</a></small>
|
1869 |
+
</div>';
|
1870 |
+
|
1871 |
+
return ( 1 == $wpmem->attrib ) ? $str : '';
|
1872 |
+
}
|
1873 |
+
|
1874 |
+
/**
|
1875 |
+
* Settings for building Short Form (login).
|
1876 |
+
*
|
1877 |
+
* Replaces individual legacy functions and filters for
|
1878 |
+
* the short forms, combined into a single method.
|
1879 |
+
*
|
1880 |
+
* @since 3.3.0
|
1881 |
+
*
|
1882 |
+
* @global stdClass $post
|
1883 |
+
* @global stdClass $wpmem
|
1884 |
+
*
|
1885 |
+
* @param string $form login|changepassword|resetpassword|forgotusername
|
1886 |
+
* @return string $form
|
1887 |
+
*/
|
1888 |
+
function do_shortform( $form, $page = "page", $redirect_to = null, $show = 'show' ) {
|
1889 |
+
|
1890 |
+
global $post, $wpmem;
|
1891 |
+
|
1892 |
+
$msg = '';
|
1893 |
+
|
1894 |
+
if ( "login" == $form && "page" == $page ) {
|
1895 |
+
$msg = $this->add_restricted_msg();
|
1896 |
+
}
|
1897 |
+
|
1898 |
+
$input_arrays = array(
|
1899 |
+
'login' => array(
|
1900 |
+
array(
|
1901 |
+
'name' => $wpmem->get_text( 'login_username' ),
|
1902 |
+
'type' => 'text',
|
1903 |
+
'tag' => 'log',
|
1904 |
+
'class' => 'username',
|
1905 |
+
'div' => 'div_text',
|
1906 |
+
),
|
1907 |
+
array(
|
1908 |
+
'name' => $wpmem->get_text( 'login_password' ),
|
1909 |
+
'type' => 'password',
|
1910 |
+
'tag' => 'pwd',
|
1911 |
+
'class' => 'password',
|
1912 |
+
'div' => 'div_text',
|
1913 |
+
),
|
1914 |
+
),
|
1915 |
+
'changepassword' => array(
|
1916 |
+
array(
|
1917 |
+
'name' => $wpmem->get_text( 'pwdchg_password1' ),
|
1918 |
+
'type' => 'password',
|
1919 |
+
'tag' => 'pass1',
|
1920 |
+
'class' => 'password',
|
1921 |
+
'div' => 'div_text',
|
1922 |
+
),
|
1923 |
+
array(
|
1924 |
+
'name' => $wpmem->get_text( 'pwdchg_password2' ),
|
1925 |
+
'type' => 'password',
|
1926 |
+
'tag' => 'pass2',
|
1927 |
+
'class' => 'password',
|
1928 |
+
'div' => 'div_text',
|
1929 |
+
),
|
1930 |
+
),
|
1931 |
+
'resetpassword' => array(
|
1932 |
+
array(
|
1933 |
+
'name' => $wpmem->get_text( 'pwdreset_username' ),
|
1934 |
+
'type' => 'text',
|
1935 |
+
'tag' => 'user',
|
1936 |
+
'class' => 'username',
|
1937 |
+
'div' => 'div_text',
|
1938 |
+
),
|
1939 |
+
array(
|
1940 |
+
'name' => $wpmem->get_text( 'pwdreset_email' ),
|
1941 |
+
'type' => 'text',
|
1942 |
+
'tag' => 'email',
|
1943 |
+
'class' => 'text',
|
1944 |
+
'div' => 'div_text',
|
1945 |
+
),
|
1946 |
+
),
|
1947 |
+
'forgotusername' => array(
|
1948 |
+
array(
|
1949 |
+
'name' => $wpmem->get_text( 'username_email' ),
|
1950 |
+
'type' => 'text',
|
1951 |
+
'tag' => 'user_email',
|
1952 |
+
'class' => 'username',
|
1953 |
+
'div' => 'div_text',
|
1954 |
+
),
|
1955 |
+
),
|
1956 |
+
);
|
1957 |
+
|
1958 |
+
/**
|
1959 |
+
* Filter the array of change password form fields.
|
1960 |
+
*
|
1961 |
+
* @since 2.9.0
|
1962 |
+
* @deprecated 3.3.0 Use wpmem_{$form}_form_defaults instead.
|
1963 |
+
*
|
1964 |
+
* @param array $default_inputs An array matching the elements used by default.
|
1965 |
+
*/
|
1966 |
+
$default_inputs = apply_filters( 'wpmem_inc_' . $form . '_inputs', $input_arrays[ $form ] );
|
1967 |
+
|
1968 |
+
$form_arrays = array(
|
1969 |
+
'login' => array(
|
1970 |
+
'heading' => $wpmem->get_text( 'login_heading' ),
|
1971 |
+
'action' => 'login',
|
1972 |
+
'button_text' => $wpmem->get_text( 'login_button' ),
|
1973 |
+
'inputs' => $default_inputs,
|
1974 |
+
'redirect_to' => $redirect_to,
|
1975 |
+
),
|
1976 |
+
'changepassword' => array(
|
1977 |
+
'heading' => $wpmem->get_text( 'pwdchg_heading' ),
|
1978 |
+
'action' => 'pwdchange',
|
1979 |
+
'button_text' => $wpmem->get_text( 'pwdchg_button' ),
|
1980 |
+
'inputs' => $default_inputs,
|
1981 |
+
),
|
1982 |
+
'resetpassword' => array(
|
1983 |
+
'heading' => $wpmem->get_text( 'pwdreset_heading' ),
|
1984 |
+
'action' => 'pwdreset',
|
1985 |
+
'button_text' => $wpmem->get_text( 'pwdreset_button' ),
|
1986 |
+
'inputs' => $default_inputs,
|
1987 |
+
),
|
1988 |
+
'forgotusername' => array(
|
1989 |
+
'heading' => $wpmem->get_text( 'username_heading' ),
|
1990 |
+
'action' => 'getusername',
|
1991 |
+
'button_text' => $wpmem->get_text( 'username_button' ),
|
1992 |
+
'inputs' => $default_inputs,
|
1993 |
+
),
|
1994 |
+
);
|
1995 |
+
|
1996 |
+
/**
|
1997 |
+
* Filter the arguments to override form defaults.
|
1998 |
+
*
|
1999 |
+
* @since 2.9.0
|
2000 |
+
* @deprecated 3.3.0 Use wpmem_inc_{$form}_defaults instead.
|
2001 |
+
*
|
2002 |
+
* @param array $args An array of arguments to use. Default null. (login|changepassword|resetpassword|forgotusername)
|
2003 |
+
*/
|
2004 |
+
$args = apply_filters( 'wpmem_inc_' . $form . '_args', '' );
|
2005 |
+
$arr = wp_parse_args( $args, $form_arrays[ $form ] );
|
2006 |
+
|
2007 |
+
/**
|
2008 |
+
* Filter the arguments to override change password form defaults.
|
2009 |
+
*
|
2010 |
+
* @since 3.3.0
|
2011 |
+
*
|
2012 |
+
* @param array $args An array of arguments to use. Default null. (login|changepassword|resetpassword|forgotusername)
|
2013 |
+
*/
|
2014 |
+
$arr = apply_filters( 'wpmem_' . $form . '_form_defaults', $arr );
|
2015 |
+
|
2016 |
+
return ( $show == 'show' ) ? $msg . $this->login_form( $page, $arr ) : $msg;
|
2017 |
+
}
|
2018 |
+
|
2019 |
+
/**
|
2020 |
+
* Applies the post restricted message above the short form.
|
2021 |
+
*
|
2022 |
+
* @since 3.3.0
|
2023 |
+
*
|
2024 |
+
* @global stdClass $wpmem
|
2025 |
+
*
|
2026 |
+
* @return string $str The generated message.
|
2027 |
+
*/
|
2028 |
+
private function add_restricted_msg() {
|
2029 |
+
|
2030 |
+
global $wpmem;
|
2031 |
+
|
2032 |
+
$str = '';
|
2033 |
+
|
2034 |
+
if ( $wpmem->regchk != "success" ) {
|
2035 |
+
|
2036 |
+
$dialogs = get_option( 'wpmembers_dialogs' );
|
2037 |
+
|
2038 |
+
// This shown above blocked content.
|
2039 |
+
$msg = $wpmem->get_text( 'restricted_msg' );
|
2040 |
+
$msg = ( $dialogs['restricted_msg'] == $msg ) ? $msg : __( stripslashes( $dialogs['restricted_msg'] ), 'wp-members' );
|
2041 |
+
$str = '<div id="wpmem_restricted_msg"><p>' . $msg . '</p></div>';
|
2042 |
+
|
2043 |
+
/**
|
2044 |
+
* Filter the post restricted message.
|
2045 |
+
*
|
2046 |
+
* @since 2.7.3
|
2047 |
+
* @since 3.2.0 Added raw message string and HTML as separate params.
|
2048 |
+
*
|
2049 |
+
* @param string $str The post restricted message with HTML.
|
2050 |
+
* @param string $msg The raw message string.
|
2051 |
+
* @param string The 'before' HTML wrapper.
|
2052 |
+
* @param string The 'after' HTML wrapper.
|
2053 |
+
*/
|
2054 |
+
$str = apply_filters( 'wpmem_restricted_msg', $str, $msg, '<div id="wpmem_restricted_msg"><p>', '</p></div>' );
|
2055 |
+
}
|
2056 |
+
|
2057 |
+
return $str;
|
2058 |
+
}
|
2059 |
+
|
2060 |
+
/**
|
2061 |
+
* Wrapper for handing the default WP login form.
|
2062 |
+
*
|
2063 |
+
* @since 3.3.2
|
2064 |
+
*/
|
2065 |
+
function wp_login_form( $args ) {
|
2066 |
+
|
2067 |
+
return wp_login_form( $args );
|
2068 |
+
}
|
2069 |
} // End of WP_Members_Forms class.
|
includes/class-wp-members-menus.php
CHANGED
@@ -283,7 +283,7 @@ class WP_Members_Menus {
|
|
283 |
global $wpmem;
|
284 |
$hide_children_of = array();
|
285 |
|
286 |
-
if (
|
287 |
|
288 |
// Iterate and remove set items.
|
289 |
foreach ( $items as $key => $item ) {
|
@@ -307,13 +307,17 @@ class WP_Members_Menus {
|
|
307 |
$visible = ( ! is_user_logged_in() ) ? true : false;
|
308 |
break;
|
309 |
default:
|
310 |
-
$
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
$
|
|
|
|
|
315 |
}
|
316 |
}
|
|
|
|
|
317 |
}
|
318 |
break;
|
319 |
}
|
283 |
global $wpmem;
|
284 |
$hide_children_of = array();
|
285 |
|
286 |
+
if ( ! empty( $items ) ) {
|
287 |
|
288 |
// Iterate and remove set items.
|
289 |
foreach ( $items as $key => $item ) {
|
307 |
$visible = ( ! is_user_logged_in() ) ? true : false;
|
308 |
break;
|
309 |
default:
|
310 |
+
if ( 1 == $wpmem->enable_products ) {
|
311 |
+
$visible = false;
|
312 |
+
if ( is_array( $item->restrictions ) && ! empty( $item->restrictions ) ) {
|
313 |
+
foreach ( $item->restrictions['products'] as $product ) {
|
314 |
+
if ( wpmem_user_has_access( $product ) ) {
|
315 |
+
$visible = true;
|
316 |
+
}
|
317 |
}
|
318 |
}
|
319 |
+
} else {
|
320 |
+
$visible = true;
|
321 |
}
|
322 |
break;
|
323 |
}
|
includes/class-wp-members-shortcodes.php
CHANGED
@@ -7,13 +7,13 @@
|
|
7 |
*
|
8 |
* This file is part of the WP-Members plugin by Chad Butler
|
9 |
* You can find out more about this plugin at https://rocketgeek.com
|
10 |
-
* Copyright (c) 2006-
|
11 |
* WP-Members(tm) is a trademark of butlerblog.com
|
12 |
*
|
13 |
* @package WP-Members
|
14 |
* @subpackage WP_Members_Shortcodes
|
15 |
* @author Chad Butler
|
16 |
-
* @copyright 2006-
|
17 |
*/
|
18 |
|
19 |
// Exit if accessed directly.
|
@@ -62,6 +62,7 @@ class WP_Members_Shortcodes {
|
|
62 |
* @since 3.1.3 Added forgot_username shortcode.
|
63 |
* @since 3.2.0 Moved to WP_Members_Shortcodes::forms().
|
64 |
* @since 3.2.0 Added id, exclude_fields, include_fields, and product attributes.
|
|
|
65 |
*
|
66 |
* @todo Complete support for id, exlude_fields, include_fields, and product attributes
|
67 |
* May require updates to core functions.
|
@@ -108,6 +109,10 @@ class WP_Members_Shortcodes {
|
|
108 |
// If $atts is an array, get the tag from the array so we know what form to render.
|
109 |
switch ( $atts ) {
|
110 |
|
|
|
|
|
|
|
|
|
111 |
case in_array( 'login', $atts ):
|
112 |
if ( is_user_logged_in() && '1' != $customizer ) {
|
113 |
/*
|
@@ -269,7 +274,7 @@ class WP_Members_Shortcodes {
|
|
269 |
if ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) {
|
270 |
if ( ! wpmem_chk_exp() ) {
|
271 |
$do_return = true;
|
272 |
-
} elseif ( $atts['msg'] == true ) {
|
273 |
$do_return = true;
|
274 |
$content = wpmem_sc_expmessage();
|
275 |
}
|
7 |
*
|
8 |
* This file is part of the WP-Members plugin by Chad Butler
|
9 |
* You can find out more about this plugin at https://rocketgeek.com
|
10 |
+
* Copyright (c) 2006-2020 Chad Butler
|
11 |
* WP-Members(tm) is a trademark of butlerblog.com
|
12 |
*
|
13 |
* @package WP-Members
|
14 |
* @subpackage WP_Members_Shortcodes
|
15 |
* @author Chad Butler
|
16 |
+
* @copyright 2006-2020
|
17 |
*/
|
18 |
|
19 |
// Exit if accessed directly.
|
62 |
* @since 3.1.3 Added forgot_username shortcode.
|
63 |
* @since 3.2.0 Moved to WP_Members_Shortcodes::forms().
|
64 |
* @since 3.2.0 Added id, exclude_fields, include_fields, and product attributes.
|
65 |
+
* @since 3.3.2 Added WP default login form.
|
66 |
*
|
67 |
* @todo Complete support for id, exlude_fields, include_fields, and product attributes
|
68 |
* May require updates to core functions.
|
109 |
// If $atts is an array, get the tag from the array so we know what form to render.
|
110 |
switch ( $atts ) {
|
111 |
|
112 |
+
case in_array( 'wp_login', $atts ):
|
113 |
+
$content = wpmem_wp_login_form( $atts );
|
114 |
+
break;
|
115 |
+
|
116 |
case in_array( 'login', $atts ):
|
117 |
if ( is_user_logged_in() && '1' != $customizer ) {
|
118 |
/*
|
274 |
if ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) {
|
275 |
if ( ! wpmem_chk_exp() ) {
|
276 |
$do_return = true;
|
277 |
+
} elseif ( $atts['msg'] == "true" ) {
|
278 |
$do_return = true;
|
279 |
$content = wpmem_sc_expmessage();
|
280 |
}
|
includes/class-wp-members-user.php
CHANGED
@@ -45,9 +45,10 @@ class WP_Members_User {
|
|
45 |
function __construct( $settings ) {
|
46 |
add_action( 'user_register', array( $this, 'set_reg_type' ), 1 );
|
47 |
add_action( 'user_register', array( $this, 'register_finalize' ), 5 ); // @todo This needs rigorous testing, especially front end processing such as WC.
|
48 |
-
add_action( 'user_register', array( $this, '
|
49 |
-
add_action( 'user_register', array( $this, '
|
50 |
-
add_action( 'user_register', array( $this, '
|
|
|
51 |
add_action( 'wpmem_register_redirect', array( $this, 'register_redirect' ) );
|
52 |
|
53 |
add_filter( 'registration_errors', array( $this, 'wp_register_validate' ), 10, 3 ); // native registration validation
|
@@ -197,16 +198,18 @@ class WP_Members_User {
|
|
197 |
return;
|
198 |
}
|
199 |
|
|
|
|
|
|
|
200 |
// Is this a registration or a user profile update?
|
201 |
if ( 'register' == $tag ) {
|
202 |
$this->post_data['username'] = sanitize_user( wpmem_get( 'username' ) );
|
203 |
}
|
204 |
|
205 |
// Add the user email to the $this->post_data array for _data hooks.
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
wpmem_fields();
|
210 |
|
211 |
// If this is an update, and tos is a field, and the user has the correct saved value, remove tos.
|
212 |
if ( 'update' == $tag && isset( $wpmem->fields['tos'] ) ) {
|
@@ -478,6 +481,28 @@ class WP_Members_User {
|
|
478 |
|
479 |
}
|
480 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
481 |
/**
|
482 |
* Sends emails on registration.
|
483 |
*
|
@@ -940,84 +965,68 @@ class WP_Members_User {
|
|
940 |
|
941 |
$user_id = ( ! $user_id ) ? get_current_user_id() : $user_id;
|
942 |
|
943 |
-
// Get legacy user product array @todo This will eventually be removed.
|
944 |
-
$user_products = get_user_meta( $user_id, '_wpmem_products', true );
|
945 |
-
$user_products = ( $user_products ) ? $user_products : array();
|
946 |
-
|
947 |
// New single meta format. @todo This remains when legacy array is removed.
|
948 |
-
$
|
949 |
|
950 |
// Convert date to add.
|
951 |
-
$
|
|
|
|
|
952 |
|
953 |
// If membership is an expiration product.
|
954 |
-
if ( is_array( $
|
955 |
// If this is setting a specific date.
|
956 |
if ( $set_date ) {
|
957 |
-
|
958 |
-
$user_products[ $product ] = date( 'Y-m-d H:i:s', strtotime( $set_date ) );
|
959 |
-
// @todo New version
|
960 |
-
$user_product = strtotime( $set_date );
|
961 |
} else {
|
962 |
// Either setting initial expiration based on set time period, or adding to the existing date (renewal/extending).
|
963 |
$raw_add = explode( "|", $wpmem->membership->products[ $product ]['expires'][0] );
|
964 |
$add_period = ( 1 < $raw_add[0] ) ? $raw_add[0] . " " . $raw_add[1] . "s" : $raw_add[0] . " " . $raw_add[1];
|
965 |
-
|
966 |
-
// Legacy first.
|
967 |
-
if ( isset( $user_products[ $product ] ) ) {
|
968 |
-
if ( isset( $wpmem->membership->products[ $product ]['no_gap'] ) && 1 == $wpmem->membership->products[ $product ]['no_gap'] ) {
|
969 |
-
// Add to the user's existing date (no gap).
|
970 |
-
//$user_products[ $product ] = date( 'Y-m-d H:i:s', strtotime( $add_period ) );
|
971 |
-
$user_products[ $product ] = date( 'Y-m-d H:i:s', strtotime( $add_period, strtotime( $user_products[ $product ] ) ) );
|
972 |
-
} else {
|
973 |
-
// Add to the user either from end or now (whichever is later; i.e. allow gaps (default)).
|
974 |
-
if ( $this->has_access( $product, $user_id ) ) {
|
975 |
-
// if not expired, set from when they expire.
|
976 |
-
$user_products[ $product ] = date( 'Y-m-d H:i:s', strtotime( $add_period, strtotime( $user_products[ $product ] ) ) );
|
977 |
-
} else {
|
978 |
-
// if expired, set from today.
|
979 |
-
$user_products[ $product ] = date( 'Y-m-d H:i:s', strtotime( $add_period ) );
|
980 |
-
}
|
981 |
-
}
|
982 |
-
|
983 |
-
} else {
|
984 |
-
// User doesn't have this membershp. Go ahead and add it.
|
985 |
-
$user_products[ $product ] = date( 'Y-m-d H:i:s', strtotime( $add_period ) );
|
986 |
-
}
|
987 |
|
988 |
// New single meta version.
|
989 |
-
if ( $
|
|
|
990 |
if ( isset( $wpmem->membership->products[ $product ]['no_gap'] ) && 1 == $wpmem->membership->products[ $product ]['no_gap'] ) {
|
991 |
// Add to the user's existing date (no gap).
|
992 |
-
$
|
993 |
} else {
|
994 |
// Add to the user either from end or now (whichever is later; i.e. allow gaps (default)).
|
995 |
if ( $this->has_access( $product, $user_id ) ) {
|
996 |
// if not expired, set from when they expire.
|
997 |
-
$
|
998 |
} else {
|
999 |
// if expired, set from today.
|
1000 |
-
$
|
1001 |
}
|
1002 |
}
|
1003 |
} else {
|
1004 |
// User doesn't have this membershp. Go ahead and add it.
|
1005 |
-
$
|
1006 |
}
|
1007 |
-
|
1008 |
}
|
1009 |
} else {
|
1010 |
-
|
1011 |
-
$user_products[ $product ] = true;
|
1012 |
-
// @todo New version
|
1013 |
-
$user_product = true;
|
1014 |
}
|
1015 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1016 |
// Update product setting.
|
1017 |
-
|
|
|
|
|
|
|
|
|
|
|
1018 |
update_user_meta( $user_id, '_wpmem_products', $user_products );
|
1019 |
-
// New, individual version.
|
1020 |
-
update_user_meta( $user_id, '_wpmem_products_' . $product, $user_product );
|
1021 |
|
1022 |
/**
|
1023 |
* Fires when a user product has been set.
|
@@ -1027,7 +1036,7 @@ class WP_Members_User {
|
|
1027 |
* @param int $user_id
|
1028 |
* @param string $product
|
1029 |
*/
|
1030 |
-
do_action( 'wpmem_user_product_set', $user_id, $product );
|
1031 |
|
1032 |
}
|
1033 |
|
45 |
function __construct( $settings ) {
|
46 |
add_action( 'user_register', array( $this, 'set_reg_type' ), 1 );
|
47 |
add_action( 'user_register', array( $this, 'register_finalize' ), 5 ); // @todo This needs rigorous testing, especially front end processing such as WC.
|
48 |
+
add_action( 'user_register', array( $this, 'post_register_data' ), 9 ); // Changed this to 9 so custom user meta is saved before the default (10) priority.
|
49 |
+
add_action( 'user_register', array( $this, 'set_user_exp' ), 25 );
|
50 |
+
add_action( 'user_register', array( $this, 'register_email_to_user' ), 25 ); // @todo This needs rigorous testing for integration with WC or WP native.
|
51 |
+
add_action( 'user_register', array( $this, 'register_email_to_admin' ), 25 ); // @todo This needs rigorous testing for integration with WC or WP native.register_email_to_admin
|
52 |
add_action( 'wpmem_register_redirect', array( $this, 'register_redirect' ) );
|
53 |
|
54 |
add_filter( 'registration_errors', array( $this, 'wp_register_validate' ), 10, 3 ); // native registration validation
|
198 |
return;
|
199 |
}
|
200 |
|
201 |
+
// Make sure fields are loaded.
|
202 |
+
wpmem_fields( $tag );
|
203 |
+
|
204 |
// Is this a registration or a user profile update?
|
205 |
if ( 'register' == $tag ) {
|
206 |
$this->post_data['username'] = sanitize_user( wpmem_get( 'username' ) );
|
207 |
}
|
208 |
|
209 |
// Add the user email to the $this->post_data array for _data hooks.
|
210 |
+
if ( isset( $wpmem->fields['user_email'] ) ) {
|
211 |
+
$this->post_data['user_email'] = sanitize_email( wpmem_get( 'user_email' ) );
|
212 |
+
}
|
|
|
213 |
|
214 |
// If this is an update, and tos is a field, and the user has the correct saved value, remove tos.
|
215 |
if ( 'update' == $tag && isset( $wpmem->fields['tos'] ) ) {
|
481 |
|
482 |
}
|
483 |
|
484 |
+
/**
|
485 |
+
* Fires wpmem_post_register_data action.
|
486 |
+
*
|
487 |
+
* @since 3.3.2
|
488 |
+
*
|
489 |
+
* @global stdClass $wpmem
|
490 |
+
* @param int $user_id
|
491 |
+
*/
|
492 |
+
function post_register_data( $user_id ) {
|
493 |
+
global $wpmem;
|
494 |
+
$wpmem->user->post_data['ID'] = $user_id;
|
495 |
+
/**
|
496 |
+
* Fires after user insertion but before email.
|
497 |
+
*
|
498 |
+
* @since 2.7.2
|
499 |
+
* @since 3.3.2 Hooked to user_register.
|
500 |
+
*
|
501 |
+
* @param array $wpmem->user->post_data The user's submitted registration data.
|
502 |
+
*/
|
503 |
+
do_action( 'wpmem_post_register_data', $wpmem->user->post_data );
|
504 |
+
}
|
505 |
+
|
506 |
/**
|
507 |
* Sends emails on registration.
|
508 |
*
|
965 |
|
966 |
$user_id = ( ! $user_id ) ? get_current_user_id() : $user_id;
|
967 |
|
|
|
|
|
|
|
|
|
968 |
// New single meta format. @todo This remains when legacy array is removed.
|
969 |
+
$prev_value = get_user_meta( $user_id, '_wpmem_products_' . $product, true );
|
970 |
|
971 |
// Convert date to add.
|
972 |
+
$expiration_period = ( isset( $wpmem->membership->products[ $product ]['expires'] ) ) ? $wpmem->membership->products[ $product ]['expires'] : false;
|
973 |
+
|
974 |
+
$renew = false;
|
975 |
|
976 |
// If membership is an expiration product.
|
977 |
+
if ( is_array( $expiration_period ) ) {
|
978 |
// If this is setting a specific date.
|
979 |
if ( $set_date ) {
|
980 |
+
$new_value = strtotime( $set_date );
|
|
|
|
|
|
|
981 |
} else {
|
982 |
// Either setting initial expiration based on set time period, or adding to the existing date (renewal/extending).
|
983 |
$raw_add = explode( "|", $wpmem->membership->products[ $product ]['expires'][0] );
|
984 |
$add_period = ( 1 < $raw_add[0] ) ? $raw_add[0] . " " . $raw_add[1] . "s" : $raw_add[0] . " " . $raw_add[1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
985 |
|
986 |
// New single meta version.
|
987 |
+
if ( $prev_value ) {
|
988 |
+
$renew = true;
|
989 |
if ( isset( $wpmem->membership->products[ $product ]['no_gap'] ) && 1 == $wpmem->membership->products[ $product ]['no_gap'] ) {
|
990 |
// Add to the user's existing date (no gap).
|
991 |
+
$new_value = strtotime( $add_period, $prev_value );
|
992 |
} else {
|
993 |
// Add to the user either from end or now (whichever is later; i.e. allow gaps (default)).
|
994 |
if ( $this->has_access( $product, $user_id ) ) {
|
995 |
// if not expired, set from when they expire.
|
996 |
+
$new_value = strtotime( $add_period, $prev_value );
|
997 |
} else {
|
998 |
// if expired, set from today.
|
999 |
+
$new_value = strtotime( $add_period );
|
1000 |
}
|
1001 |
}
|
1002 |
} else {
|
1003 |
// User doesn't have this membershp. Go ahead and add it.
|
1004 |
+
$new_value = strtotime( $add_period );
|
1005 |
}
|
|
|
1006 |
}
|
1007 |
} else {
|
1008 |
+
$new_value = true;
|
|
|
|
|
|
|
1009 |
}
|
1010 |
|
1011 |
+
/**
|
1012 |
+
* Filter the expiration date.
|
1013 |
+
*
|
1014 |
+
* @since 3.3.2
|
1015 |
+
*
|
1016 |
+
* @param int|boolean $new_value Unix timestamp of new expiration, true|false if not an expiry product.
|
1017 |
+
* @param int|boolean $prev_value The user's current value (prior to updating).
|
1018 |
+
* @param boolean $renew Is this a renewal transaction?
|
1019 |
+
*/
|
1020 |
+
$new_value = apply_filters( 'wpmem_user_product_set_expiration', $new_value, $prev_value, $renew );
|
1021 |
+
|
1022 |
// Update product setting.
|
1023 |
+
update_user_meta( $user_id, '_wpmem_products_' . $product, $new_value );
|
1024 |
+
|
1025 |
+
// Update the legacy setting.
|
1026 |
+
$user_products = get_user_meta( $user_id, '_wpmem_products', true );
|
1027 |
+
$user_products = ( $user_products ) ? $user_products : array();
|
1028 |
+
$user_products[ $product ] = ( true === $new_value ) ? true : date( 'Y-m-d H:i:s', $new_value );
|
1029 |
update_user_meta( $user_id, '_wpmem_products', $user_products );
|
|
|
|
|
1030 |
|
1031 |
/**
|
1032 |
* Fires when a user product has been set.
|
1036 |
* @param int $user_id
|
1037 |
* @param string $product
|
1038 |
*/
|
1039 |
+
do_action( 'wpmem_user_product_set', $user_id, $product, $new_value, $prev_value, $renew );
|
1040 |
|
1041 |
}
|
1042 |
|
includes/class-wp-members.php
CHANGED
@@ -281,7 +281,7 @@ class WP_Members {
|
|
281 |
public $select_style;
|
282 |
|
283 |
/**
|
284 |
-
* Container for dropin folder location
|
285 |
*
|
286 |
* @since 3.3.0
|
287 |
* @access public
|
@@ -289,6 +289,15 @@ class WP_Members {
|
|
289 |
*/
|
290 |
public $dropin_dir;
|
291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
/**
|
293 |
* Plugin initialization function.
|
294 |
*
|
@@ -397,36 +406,44 @@ class WP_Members {
|
|
397 |
do_action( 'wpmem_load_hooks' );
|
398 |
|
399 |
// Add actions.
|
400 |
-
|
401 |
-
add_action( '
|
|
|
|
|
402 |
add_action( 'admin_init', array( $this, 'load_admin' ) ); // check user role to load correct dashboard
|
403 |
-
add_action( '
|
|
|
404 |
add_action( 'login_enqueue_scripts', array( $this, 'enqueue_style_wp_login' ) ); // styles the native registration
|
405 |
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) ); // Enqueues the stylesheet.
|
406 |
add_action( 'wp_enqueue_scripts', array( $this, 'loginout_script' ) );
|
407 |
-
add_action( 'init', array( $this, 'load_textdomain' ) ); //add_action( 'plugins_loaded', 'wpmem_load_textdomain' );
|
408 |
-
add_action( 'init', array( $this->membership, 'add_cpt' ), 0 ); // Adds membership plans custom post type.
|
409 |
add_action( 'pre_get_posts', array( $this, 'do_hide_posts' ) );
|
410 |
add_action( 'customize_register', array( $this, 'customizer_settings' ) );
|
411 |
-
|
|
|
412 |
if ( is_user_logged_in() ) {
|
413 |
add_action( 'wpmem_pwd_change', array( $this->user, 'set_password' ), 9, 2 );
|
414 |
add_action( 'wpmem_pwd_change', array( $this->user, 'set_as_logged_in' ), 10 );
|
415 |
}
|
416 |
|
417 |
-
add_filter( 'register_form', 'wpmem_wp_register_form' );
|
418 |
add_action( 'woocommerce_register_form', 'wpmem_woo_register_form' );
|
419 |
|
420 |
// Add filters.
|
421 |
-
add_filter( 'the_content',
|
422 |
-
add_filter( '
|
423 |
-
add_filter( '
|
424 |
-
add_filter( '
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
430 |
|
431 |
// If registration is moderated, check for activation (blocks backend login by non-activated users).
|
432 |
if ( $this->mod_reg == 1 ) {
|
@@ -700,28 +717,26 @@ class WP_Members {
|
|
700 |
global $post;
|
701 |
|
702 |
if ( $post || $post_id ) {
|
703 |
-
|
704 |
-
|
705 |
-
$post = get_post( $post_id );
|
706 |
-
}
|
707 |
|
708 |
-
$meta = wpmem_get_block_setting( $
|
709 |
|
710 |
// Backward compatibility for old block/unblock meta.
|
711 |
if ( ! $meta ) {
|
712 |
// Check for old meta.
|
713 |
-
$old_block = get_post_meta( $
|
714 |
-
$old_unblock = get_post_meta( $
|
715 |
$meta = ( $old_block ) ? 1 : ( ( $old_unblock ) ? 0 : $meta );
|
716 |
}
|
717 |
|
718 |
// Setup defaults.
|
719 |
$defaults = array(
|
720 |
-
'post_id' => $
|
721 |
-
'post_type' => $
|
722 |
-
'block' => ( isset( $this->block[ $
|
723 |
'block_meta' => $meta,
|
724 |
-
'block_type' => ( isset( $this->block[ $
|
725 |
);
|
726 |
|
727 |
/**
|
@@ -739,7 +754,7 @@ class WP_Members {
|
|
739 |
// Merge $args with defaults.
|
740 |
$args = ( wp_parse_args( $args, $defaults ) );
|
741 |
|
742 |
-
if ( is_single() || is_page() ) {
|
743 |
switch( $args['block_type'] ) {
|
744 |
case 1: // If content is blocked by default.
|
745 |
$args['block'] = ( $args['block_meta'] == '0' ) ? false : $args['block'];
|
@@ -845,10 +860,10 @@ class WP_Members {
|
|
845 |
|
846 |
} elseif ( isset( $this->show_excerpt[ $post->post_type ] ) && $this->show_excerpt[ $post->post_type ] == 1 ) {
|
847 |
|
848 |
-
|
|
|
849 |
$content = wpmem_do_excerpt( $content );
|
850 |
} else {
|
851 |
-
$len = strpos( $content, '<span id="more' );
|
852 |
$content = substr( $content, 0, $len );
|
853 |
}
|
854 |
|
@@ -910,22 +925,26 @@ class WP_Members {
|
|
910 |
*
|
911 |
* @since 2.9.9
|
912 |
* @since 3.2.0 Moved wpmem_securify_comments() to main class, renamed.
|
|
|
913 |
*
|
914 |
-
* @
|
|
|
|
|
915 |
*/
|
916 |
-
function do_securify_comments( $open ) {
|
917 |
|
918 |
-
$open = ( ! is_user_logged_in() && wpmem_is_blocked() ) ? false : $open;
|
919 |
|
920 |
/**
|
921 |
* Filters whether comments are open or not.
|
922 |
*
|
923 |
* @since 3.0.0
|
924 |
* @since 3.2.0 Moved to main class.
|
|
|
925 |
*
|
926 |
* @param bool $open true if current post is open for comments, otherwise false.
|
927 |
*/
|
928 |
-
$open = apply_filters( 'wpmem_securify_comments', $open );
|
929 |
|
930 |
if ( ! $open ) {
|
931 |
/** This filter is documented in wp-includes/comment-template.php */
|
@@ -941,15 +960,61 @@ class WP_Members {
|
|
941 |
* @since 3.0.1
|
942 |
* @since 3.2.0 Moved wpmem_securify_comments_array() to main class, renamed.
|
943 |
*
|
944 |
-
* @
|
945 |
-
*
|
946 |
* @return array $comments The comments array.
|
947 |
*/
|
948 |
function do_securify_comments_array( $comments , $post_id ) {
|
949 |
-
$comments = ( ! is_user_logged_in() && wpmem_is_blocked() ) ? array() : $comments;
|
950 |
return $comments;
|
951 |
}
|
952 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
953 |
/**
|
954 |
* Adds the successful registration message on the login page if reg_nonce validates.
|
955 |
*
|
@@ -969,6 +1034,15 @@ class WP_Members {
|
|
969 |
return $content;
|
970 |
}
|
971 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
972 |
/**
|
973 |
* Gets an array of hidden post IDs.
|
974 |
*
|
@@ -1010,33 +1084,52 @@ class WP_Members {
|
|
1010 |
*
|
1011 |
* @since 3.2.0
|
1012 |
*
|
1013 |
-
* @
|
|
|
1014 |
*/
|
1015 |
function get_hidden_posts() {
|
1016 |
$hidden = array();
|
1017 |
-
|
1018 |
-
|
|
|
|
|
1019 |
}
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
// @todo This maybe should be a transient stored in the user object.
|
1024 |
$hidden = $this->hidden_posts();
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1032 |
}
|
1033 |
}
|
1034 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1035 |
}
|
1036 |
}
|
1037 |
return $hidden;
|
1038 |
}
|
1039 |
-
|
1040 |
/**
|
1041 |
* Hides posts based on settings and meta.
|
1042 |
*
|
@@ -1109,10 +1202,12 @@ class WP_Members {
|
|
1109 |
*/
|
1110 |
function filter_get_adjacent_post_where( $where ) {
|
1111 |
global $wpmem;
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
|
|
|
|
1116 |
}
|
1117 |
return $where;
|
1118 |
}
|
@@ -1698,7 +1793,7 @@ class WP_Members {
|
|
1698 |
$do_excerpt = true;
|
1699 |
}
|
1700 |
|
1701 |
-
if ( $do_excerpt ) {
|
1702 |
$content = wp_trim_words( $content, $args['length'], $args['more_link'] );
|
1703 |
// Check if the more link was added (note: singular has no more_link):
|
1704 |
if ( ! $is_singular && ! strpos( $content, $args['more_link'] ) ) {
|
281 |
public $select_style;
|
282 |
|
283 |
/**
|
284 |
+
* Container for dropin folder location.
|
285 |
*
|
286 |
* @since 3.3.0
|
287 |
* @access public
|
289 |
*/
|
290 |
public $dropin_dir;
|
291 |
|
292 |
+
/**
|
293 |
+
* REST conditional.
|
294 |
+
*
|
295 |
+
* @since 3.3.2
|
296 |
+
* @access public
|
297 |
+
* @var boolean
|
298 |
+
*/
|
299 |
+
public $is_rest = false;
|
300 |
+
|
301 |
/**
|
302 |
* Plugin initialization function.
|
303 |
*
|
406 |
do_action( 'wpmem_load_hooks' );
|
407 |
|
408 |
// Add actions.
|
409 |
+
|
410 |
+
add_action( 'init', array( $this, 'load_textdomain' ) ); //add_action( 'plugins_loaded', 'wpmem_load_textdomain' );
|
411 |
+
add_action( 'init', array( $this->membership, 'add_cpt' ), 0 ); // Adds membership plans custom post type.
|
412 |
+
add_action( 'widgets_init', array( $this, 'widget_init' ) ); // initializes the widget
|
413 |
add_action( 'admin_init', array( $this, 'load_admin' ) ); // check user role to load correct dashboard
|
414 |
+
add_action( 'rest_api_init', array( $this, 'rest_init' ) );
|
415 |
+
add_action( 'template_redirect', array( $this, 'get_action' ) );
|
416 |
add_action( 'login_enqueue_scripts', array( $this, 'enqueue_style_wp_login' ) ); // styles the native registration
|
417 |
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) ); // Enqueues the stylesheet.
|
418 |
add_action( 'wp_enqueue_scripts', array( $this, 'loginout_script' ) );
|
|
|
|
|
419 |
add_action( 'pre_get_posts', array( $this, 'do_hide_posts' ) );
|
420 |
add_action( 'customize_register', array( $this, 'customizer_settings' ) );
|
421 |
+
add_action( 'admin_menu', 'wpmem_admin_options' ); // adds admin menu
|
422 |
+
|
423 |
if ( is_user_logged_in() ) {
|
424 |
add_action( 'wpmem_pwd_change', array( $this->user, 'set_password' ), 9, 2 );
|
425 |
add_action( 'wpmem_pwd_change', array( $this->user, 'set_as_logged_in' ), 10 );
|
426 |
}
|
427 |
|
428 |
+
add_filter( 'register_form', 'wpmem_wp_register_form' ); // adds fields to the default wp registration
|
429 |
add_action( 'woocommerce_register_form', 'wpmem_woo_register_form' );
|
430 |
|
431 |
// Add filters.
|
432 |
+
add_filter( 'the_content', array( $this, 'do_securify' ), 99 );
|
433 |
+
add_filter( 'comments_open', array( $this, 'do_securify_comments' ), 99, 2 ); // securifies the comments
|
434 |
+
add_filter( 'wpmem_securify', array( $this, 'reg_securify' ) ); // adds success message on login form if redirected
|
435 |
+
add_filter( 'rest_prepare_post', array( $this, 'do_securify_rest' ), 10, 3 );
|
436 |
+
add_filter( 'rest_prepare_page', array( $this, 'do_securify_rest' ), 10, 3 );
|
437 |
+
foreach( $this->post_types as $post_type ) {
|
438 |
+
add_filter( "rest_prepare_{$post_type}", array( $this, 'do_securify_rest' ), 10, 3 );
|
439 |
+
}
|
440 |
+
|
441 |
+
//add_filter( 'query_vars', array( $this, 'add_query_vars' ), 10, 2 ); // adds custom query vars
|
442 |
+
add_filter( 'get_pages', array( $this, 'filter_get_pages' ) );
|
443 |
+
add_filter( 'wp_get_nav_menu_items', array( $this, 'filter_nav_menu_items' ), null, 3 );
|
444 |
+
add_filter( 'get_previous_post_where', array( $this, 'filter_get_adjacent_post_where' ) );
|
445 |
+
add_filter( 'get_next_post_where', array( $this, 'filter_get_adjacent_post_where' ) );
|
446 |
+
add_filter( 'allow_password_reset', array( $this->user, 'no_reset' ) ); // no password reset for non-activated users
|
447 |
|
448 |
// If registration is moderated, check for activation (blocks backend login by non-activated users).
|
449 |
if ( $this->mod_reg == 1 ) {
|
717 |
global $post;
|
718 |
|
719 |
if ( $post || $post_id ) {
|
720 |
+
|
721 |
+
$the_post = ( false === $post_id ) ? $post : get_post( $post_id );
|
|
|
|
|
722 |
|
723 |
+
$meta = wpmem_get_block_setting( $the_post->ID );
|
724 |
|
725 |
// Backward compatibility for old block/unblock meta.
|
726 |
if ( ! $meta ) {
|
727 |
// Check for old meta.
|
728 |
+
$old_block = get_post_meta( $the_post->ID, 'block', true );
|
729 |
+
$old_unblock = get_post_meta( $the_post->ID, 'unblock', true );
|
730 |
$meta = ( $old_block ) ? 1 : ( ( $old_unblock ) ? 0 : $meta );
|
731 |
}
|
732 |
|
733 |
// Setup defaults.
|
734 |
$defaults = array(
|
735 |
+
'post_id' => $the_post->ID,
|
736 |
+
'post_type' => $the_post->post_type,
|
737 |
+
'block' => ( isset( $this->block[ $the_post->post_type ] ) && $this->block[ $the_post->post_type ] == 1 ) ? true : false,
|
738 |
'block_meta' => $meta,
|
739 |
+
'block_type' => ( isset( $this->block[ $the_post->post_type ] ) ) ? $this->block[ $the_post->post_type ] : 0,
|
740 |
);
|
741 |
|
742 |
/**
|
754 |
// Merge $args with defaults.
|
755 |
$args = ( wp_parse_args( $args, $defaults ) );
|
756 |
|
757 |
+
if ( is_single() || is_page() || wpmem_is_rest() ) {
|
758 |
switch( $args['block_type'] ) {
|
759 |
case 1: // If content is blocked by default.
|
760 |
$args['block'] = ( $args['block_meta'] == '0' ) ? false : $args['block'];
|
860 |
|
861 |
} elseif ( isset( $this->show_excerpt[ $post->post_type ] ) && $this->show_excerpt[ $post->post_type ] == 1 ) {
|
862 |
|
863 |
+
$len = strpos( $content, '<span id="more' );
|
864 |
+
if ( false === $len ) {
|
865 |
$content = wpmem_do_excerpt( $content );
|
866 |
} else {
|
|
|
867 |
$content = substr( $content, 0, $len );
|
868 |
}
|
869 |
|
925 |
*
|
926 |
* @since 2.9.9
|
927 |
* @since 3.2.0 Moved wpmem_securify_comments() to main class, renamed.
|
928 |
+
* @since 3.3.2 Added $post_id.
|
929 |
*
|
930 |
+
* @param bool $open Whether the current post is open for comments.
|
931 |
+
* @param int $post_id The post ID.
|
932 |
+
* @return bool $open True if current post is open for comments, otherwise false.
|
933 |
*/
|
934 |
+
function do_securify_comments( $open, $post_id ) {
|
935 |
|
936 |
+
$open = ( ! is_user_logged_in() && wpmem_is_blocked( $post_id ) ) ? false : $open;
|
937 |
|
938 |
/**
|
939 |
* Filters whether comments are open or not.
|
940 |
*
|
941 |
* @since 3.0.0
|
942 |
* @since 3.2.0 Moved to main class.
|
943 |
+
* @since 3.3.2 Added $post_id.
|
944 |
*
|
945 |
* @param bool $open true if current post is open for comments, otherwise false.
|
946 |
*/
|
947 |
+
$open = apply_filters( 'wpmem_securify_comments', $open, $post_id );
|
948 |
|
949 |
if ( ! $open ) {
|
950 |
/** This filter is documented in wp-includes/comment-template.php */
|
960 |
* @since 3.0.1
|
961 |
* @since 3.2.0 Moved wpmem_securify_comments_array() to main class, renamed.
|
962 |
*
|
963 |
+
* @param array $comments
|
964 |
+
* @param int $post_id
|
965 |
* @return array $comments The comments array.
|
966 |
*/
|
967 |
function do_securify_comments_array( $comments , $post_id ) {
|
968 |
+
$comments = ( ! is_user_logged_in() && wpmem_is_blocked( $post_id ) ) ? array() : $comments;
|
969 |
return $comments;
|
970 |
}
|
971 |
|
972 |
+
/**
|
973 |
+
* Handles REST request.
|
974 |
+
*
|
975 |
+
* @since 3.3.2
|
976 |
+
*
|
977 |
+
* @param WP_REST_Response $response The response object.
|
978 |
+
* @param WP_Post $post Post object.
|
979 |
+
* @param WP_REST_Request $request Request object.
|
980 |
+
* @return
|
981 |
+
*/
|
982 |
+
function do_securify_rest( $response, $post, $request ) {
|
983 |
+
|
984 |
+
if ( ! is_user_logged_in() ) {
|
985 |
+
// Response for restricted content
|
986 |
+
$block_value = wpmem_is_blocked( $response->data['id'] );
|
987 |
+
if ( $block_value ) {
|
988 |
+
if ( isset( $response->data['content']['rendered'] ) ) {
|
989 |
+
/**
|
990 |
+
* Filters restricted content message.
|
991 |
+
*
|
992 |
+
* @since 3.3.2
|
993 |
+
*
|
994 |
+
* @param string $message
|
995 |
+
*/
|
996 |
+
$response->data['content']['rendered'] = apply_filters( "wpmem_securify_rest_{$post->post_type}_content", __( "You must be logged in to view this content.", 'wp-members' ) );
|
997 |
+
}
|
998 |
+
if ( isset( $response->data['excerpt']['rendered'] ) ) {
|
999 |
+
/**
|
1000 |
+
* Filters restricted excerpt message.
|
1001 |
+
*
|
1002 |
+
* @since 3.3.2
|
1003 |
+
*
|
1004 |
+
* @param string $message
|
1005 |
+
*/
|
1006 |
+
$response->data['excerpt']['rendered'] = apply_filters( "wpmem_securify_rest_{$post->post_type}_excerpt", __( "You must be logged in to view this content.", 'wp-members' ) );
|
1007 |
+
}
|
1008 |
+
}
|
1009 |
+
|
1010 |
+
// Response for hidden content. @todo This needs to be changed to check for whether the user has access (for internal requests).
|
1011 |
+
if ( ! is_admin() && in_array( $post->ID, $this->hidden_posts() ) ) {
|
1012 |
+
return new WP_REST_Response( __( 'The page you are looking for does not exist', 'wp-members' ), 404 );
|
1013 |
+
}
|
1014 |
+
}
|
1015 |
+
return $response;
|
1016 |
+
}
|
1017 |
+
|
1018 |
/**
|
1019 |
* Adds the successful registration message on the login page if reg_nonce validates.
|
1020 |
*
|
1034 |
return $content;
|
1035 |
}
|
1036 |
|
1037 |
+
/**
|
1038 |
+
* Runs if the REST API is initialized.
|
1039 |
+
*
|
1040 |
+
* @since 3.3.2
|
1041 |
+
*/
|
1042 |
+
function rest_init() {
|
1043 |
+
$this->is_rest = true;
|
1044 |
+
}
|
1045 |
+
|
1046 |
/**
|
1047 |
* Gets an array of hidden post IDs.
|
1048 |
*
|
1084 |
*
|
1085 |
* @since 3.2.0
|
1086 |
*
|
1087 |
+
* @global stdClass $wpdb
|
1088 |
+
* @return array $hidden
|
1089 |
*/
|
1090 |
function get_hidden_posts() {
|
1091 |
$hidden = array();
|
1092 |
+
|
1093 |
+
// Return empty array if this is the admin and user can edit posts.
|
1094 |
+
if ( is_admin() && current_user_can( 'edit_posts' ) ) {
|
1095 |
+
return $hidden;
|
1096 |
}
|
1097 |
+
|
1098 |
+
// If the user is not logged in, return all hidden posts.
|
1099 |
+
if ( ! is_user_logged_in() ) {
|
|
|
1100 |
$hidden = $this->hidden_posts();
|
1101 |
+
} else {
|
1102 |
+
// If the user is logged in.
|
1103 |
+
if ( 1 == $this->enable_products ) {
|
1104 |
+
// Get user product access.
|
1105 |
+
$hidden = $this->hidden_posts();
|
1106 |
+
$hidden = ( is_array( $hidden ) ) ? $hidden : array();
|
1107 |
+
|
1108 |
+
// Remove posts with a product the user has access to.
|
1109 |
+
foreach ( $this->membership->products as $key => $value ) {
|
1110 |
+
if ( isset( $this->user->access[ $key ] ) && ( true == $this->user->access[ $key ] || $this->user->is_current( $this->user->access[ $key ] ) ) ) {
|
1111 |
+
foreach ( $hidden as $post_id ) {
|
1112 |
+
if ( 1 == get_post_meta( $post_id, $this->membership->post_stem . $key, true ) ) {
|
1113 |
+
$hidden_key = array_search( $post_id, $hidden );
|
1114 |
+
unset( $hidden[ $hidden_key ] );
|
1115 |
+
}
|
1116 |
}
|
1117 |
}
|
1118 |
}
|
1119 |
+
|
1120 |
+
// Remove posts that don't have a product assignment (general login).
|
1121 |
+
foreach( $hidden as $hidden_key ) {
|
1122 |
+
$unattached = get_post_meta( $hidden_key, '_wpmem_products', true );
|
1123 |
+
if ( false == $unattached ) {
|
1124 |
+
$hidden_key = array_search( $hidden_key, $hidden );
|
1125 |
+
unset( $hidden[ $hidden_key ] );
|
1126 |
+
}
|
1127 |
+
}
|
1128 |
}
|
1129 |
}
|
1130 |
return $hidden;
|
1131 |
}
|
1132 |
+
|
1133 |
/**
|
1134 |
* Hides posts based on settings and meta.
|
1135 |
*
|
1202 |
*/
|
1203 |
function filter_get_adjacent_post_where( $where ) {
|
1204 |
global $wpmem;
|
1205 |
+
if ( ! is_user_logged_in() ) {
|
1206 |
+
$hidden_posts = $this->get_hidden_posts();
|
1207 |
+
if ( ! empty( $hidden_posts ) ) {
|
1208 |
+
$hidden = implode( ",", $hidden_posts );
|
1209 |
+
$where = $where . " AND p.ID NOT IN ( $hidden )";
|
1210 |
+
}
|
1211 |
}
|
1212 |
return $where;
|
1213 |
}
|
1793 |
$do_excerpt = true;
|
1794 |
}
|
1795 |
|
1796 |
+
if ( true === $do_excerpt ) {
|
1797 |
$content = wp_trim_words( $content, $args['length'], $args['more_link'] );
|
1798 |
// Check if the more link was added (note: singular has no more_link):
|
1799 |
if ( ! $is_singular && ! strpos( $content, $args['more_link'] ) ) {
|
includes/deprecated.php
CHANGED
@@ -8,12 +8,12 @@
|
|
8 |
*
|
9 |
* This file is part of the WP-Members plugin by Chad Butler
|
10 |
* You can find out more about this plugin at https://rocketgeek.com
|
11 |
-
* Copyright (c) 2006-
|
12 |
* WP-Members(tm) is a trademark of butlerblog.com
|
13 |
*
|
14 |
* @package WP-Members
|
15 |
* @author Chad Butler
|
16 |
-
* @copyright 2006-
|
17 |
*/
|
18 |
|
19 |
// Exit if accessed directly.
|
@@ -164,7 +164,7 @@ if ( ! function_exists( 'wpmem_inc_regemail' ) ):
|
|
164 |
function wpmem_inc_regemail( $user_id, $password, $toggle, $wpmem_fields = null, $field_data = null, $custom = null ) {
|
165 |
global $wpmem;
|
166 |
wpmem_write_log( "wpmem_inc_regemail() is deprecated since WP-Members 3.2.0. Use $ wpmem->email->to_user() instead" );
|
167 |
-
|
168 |
return;
|
169 |
}
|
170 |
endif;
|
8 |
*
|
9 |
* This file is part of the WP-Members plugin by Chad Butler
|
10 |
* You can find out more about this plugin at https://rocketgeek.com
|
11 |
+
* Copyright (c) 2006-2020 Chad Butler
|
12 |
* WP-Members(tm) is a trademark of butlerblog.com
|
13 |
*
|
14 |
* @package WP-Members
|
15 |
* @author Chad Butler
|
16 |
+
* @copyright 2006-2020
|
17 |
*/
|
18 |
|
19 |
// Exit if accessed directly.
|
164 |
function wpmem_inc_regemail( $user_id, $password, $toggle, $wpmem_fields = null, $field_data = null, $custom = null ) {
|
165 |
global $wpmem;
|
166 |
wpmem_write_log( "wpmem_inc_regemail() is deprecated since WP-Members 3.2.0. Use $ wpmem->email->to_user() instead" );
|
167 |
+
wpmem_email_to_user( $user_id, $password, $toggle, $wpmem_fields, $field_data, $custom );
|
168 |
return;
|
169 |
}
|
170 |
endif;
|
includes/install.php
CHANGED
@@ -6,12 +6,12 @@
|
|
6 |
*
|
7 |
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
-
* Copyright (c) 2006-
|
10 |
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
*
|
12 |
* @package WP-Members
|
13 |
* @author Chad Butler
|
14 |
-
* @copyright 2006-
|
15 |
*/
|
16 |
|
17 |
// Exit if accessed directly.
|
6 |
*
|
7 |
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
+
* Copyright (c) 2006-2020 Chad Butler
|
10 |
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
*
|
12 |
* @package WP-Members
|
13 |
* @author Chad Butler
|
14 |
+
* @copyright 2006-2020
|
15 |
*/
|
16 |
|
17 |
// Exit if accessed directly.
|
includes/legacy/dialogs.php
CHANGED
@@ -1,575 +1,575 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members Dialog Functions
|
4 |
-
*
|
5 |
-
* Handles functions that output front-end dialogs to end users.
|
6 |
-
*
|
7 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
-
* Copyright (c) 2006-
|
10 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
-
*
|
12 |
-
* @package WP-Members
|
13 |
-
* @author Chad Butler
|
14 |
-
* @copyright 2006-
|
15 |
-
*
|
16 |
-
* Functions Included:
|
17 |
-
* - wpmem_inc_loginfailed
|
18 |
-
* - wpmem_inc_regmessage
|
19 |
-
* - wpmem_inc_memberlinks
|
20 |
-
* - wpmem_page_pwd_reset
|
21 |
-
* - wpmem_page_user_edit
|
22 |
-
* - wpmem_page_forgot_username
|
23 |
-
* - wpmem_inc_forgotusername
|
24 |
-
*/
|
25 |
-
|
26 |
-
// Exit if accessed directly.
|
27 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
28 |
-
exit();
|
29 |
-
}
|
30 |
-
|
31 |
-
if ( ! function_exists( 'wpmem_inc_loginfailed' ) ):
|
32 |
-
/**
|
33 |
-
* Login Failed Dialog.
|
34 |
-
*
|
35 |
-
* Returns the login failed error message.
|
36 |
-
*
|
37 |
-
* @since 1.8
|
38 |
-
*
|
39 |
-
* @global object $wpmem The WP_Members object.
|
40 |
-
* @return string $str The generated html for the login failed message.
|
41 |
-
*/
|
42 |
-
function wpmem_inc_loginfailed() {
|
43 |
-
|
44 |
-
global $wpmem;
|
45 |
-
|
46 |
-
// Defaults.
|
47 |
-
$defaults = array(
|
48 |
-
'div_before' => '<div align="center" id="wpmem_msg">',
|
49 |
-
'div_after' => '</div>',
|
50 |
-
'heading_before' => '<h2>',
|
51 |
-
'heading' => $wpmem->get_text( 'login_failed_heading' ),
|
52 |
-
'heading_after' => '</h2>',
|
53 |
-
'p_before' => '<p>',
|
54 |
-
'message' => $wpmem->get_text( 'login_failed' ), // @todo $wpmem->error
|
55 |
-
'p_after' => '</p>',
|
56 |
-
'link' => '<a href="' . esc_url( $_SERVER['REQUEST_URI'] ) . '">' . $wpmem->get_text( 'login_failed_link' ) . '</a>',
|
57 |
-
);
|
58 |
-
|
59 |
-
/**
|
60 |
-
* Filter the login failed dialog arguments.
|
61 |
-
*
|
62 |
-
* @since 2.9.0
|
63 |
-
*
|
64 |
-
* @param array An array of arguments to merge with defaults.
|
65 |
-
*/
|
66 |
-
$args = apply_filters( 'wpmem_login_failed_args', '' );
|
67 |
-
|
68 |
-
// Merge $args with defaults.
|
69 |
-
$args = wp_parse_args( $args, $defaults );
|
70 |
-
|
71 |
-
$str = $args['div_before']
|
72 |
-
. $args['heading_before'] . $args['heading'] . $args['heading_after']
|
73 |
-
. $args['p_before'] . $args['message'] . $args['p_after']
|
74 |
-
. $args['p_before'] . $args['link'] . $args['p_after']
|
75 |
-
. $args['div_after'];
|
76 |
-
|
77 |
-
/**
|
78 |
-
* Filter the login failed dialog.
|
79 |
-
*
|
80 |
-
* @since 2.7.3
|
81 |
-
*
|
82 |
-
* @param string $str The login failed dialog.
|
83 |
-
*/
|
84 |
-
$str = apply_filters( 'wpmem_login_failed', $str );
|
85 |
-
|
86 |
-
return $str;
|
87 |
-
}
|
88 |
-
endif;
|
89 |
-
|
90 |
-
|
91 |
-
if ( ! function_exists( 'wpmem_inc_regmessage' ) ):
|
92 |
-
/**
|
93 |
-
* Message Dialog.
|
94 |
-
*
|
95 |
-
* Returns various dialogs and error messages.
|
96 |
-
*
|
97 |
-
* @since 1.8
|
98 |
-
* @since 3.3.0 Changed 'toggles' to 'tags'
|
99 |
-
*
|
100 |
-
* @global object $wpmem
|
101 |
-
* @param string $tag Error message tag to look for specific error messages.
|
102 |
-
* @param string $msg A message that has no tag that is passed directly to the function.
|
103 |
-
* @return string $str The final HTML for the message.
|
104 |
-
*/
|
105 |
-
function wpmem_inc_regmessage( $tag, $msg = '' ) {
|
106 |
-
|
107 |
-
global $wpmem;
|
108 |
-
|
109 |
-
// defaults
|
110 |
-
$defaults = array(
|
111 |
-
'div_before' => '<div class="wpmem_msg" align="center">',
|
112 |
-
'div_after' => '</div>',
|
113 |
-
'p_before' => '<p>',
|
114 |
-
'p_after' => '</p>',
|
115 |
-
'tags' => array(
|
116 |
-
'user',
|
117 |
-
'email',
|
118 |
-
'success',
|
119 |
-
'editsuccess',
|
120 |
-
'pwdchangerr',
|
121 |
-
'pwdchangesuccess',
|
122 |
-
'pwdreseterr',
|
123 |
-
'pwdresetsuccess',
|
124 |
-
),
|
125 |
-
);
|
126 |
-
|
127 |
-
/**
|
128 |
-
* Filter the message arguments.
|
129 |
-
*
|
130 |
-
* @since 2.9.0
|
131 |
-
* @deprecated 3.3.0 Use wpmem_msg_defaults instead.
|
132 |
-
*
|
133 |
-
* @param array An array of arguments to merge with defaults.
|
134 |
-
*/
|
135 |
-
$args = apply_filters( 'wpmem_msg_args', '' );
|
136 |
-
|
137 |
-
/** This filter is documented in /includes/class-wp-members-admin-api.php */
|
138 |
-
$dialogs = apply_filters( 'wpmem_dialogs', get_option( 'wpmembers_dialogs' ) );
|
139 |
-
|
140 |
-
// @todo Temporary(?) workaround for custom dialogs as an array (WP-Members Security).
|
141 |
-
if ( array_key_exists( $tag, $dialogs ) ) {
|
142 |
-
if ( is_array( $dialogs[ $tag ] ) ) {
|
143 |
-
$msg = stripslashes( $dialogs[ $tag ]['value'] );
|
144 |
-
} else {
|
145 |
-
$msg = $wpmem->get_text( $tag );
|
146 |
-
$msg = ( $dialogs[ $tag ] == $msg ) ? $msg : __( stripslashes( $dialogs[ $tag ] ), 'wp-members' );
|
147 |
-
}
|
148 |
-
}
|
149 |
-
$defaults['msg'] = $msg;
|
150 |
-
|
151 |
-
/**
|
152 |
-
* Filter the message array
|
153 |
-
*
|
154 |
-
* @since 2.9.2
|
155 |
-
* @since 3.1.1 added $dialogs parameter.
|
156 |
-
* @deprecated 3.3.0 Use wpmem_msg_defaults instead.
|
157 |
-
*
|
158 |
-
* @param array $defaults An array of the defaults.
|
159 |
-
* @param string $tag The tag that we are on, if any.
|
160 |
-
* @param array $dialogs
|
161 |
-
*/
|
162 |
-
$defaults = apply_filters( 'wpmem_msg_dialog_arr', $defaults, $tag, $dialogs );
|
163 |
-
|
164 |
-
// Merge $args with defaults.
|
165 |
-
$args = wp_parse_args( $args, $defaults );
|
166 |
-
|
167 |
-
// Backwards compatibility for 'toggles'.
|
168 |
-
if ( isset( $args['toggles'] ) ) {
|
169 |
-
$args['tags'] = $args['toggles'];
|
170 |
-
}
|
171 |
-
|
172 |
-
/**
|
173 |
-
* Filter the message settings.
|
174 |
-
*
|
175 |
-
* @since 3.3.0
|
176 |
-
*
|
177 |
-
* @param array $defaults An array of the defaults.
|
178 |
-
* @param string $tag The tag that we are on, if any.
|
179 |
-
* @param array $dialogs
|
180 |
-
*/
|
181 |
-
$args = apply_filters( 'wpmem_msg_defaults', $defaults, $tag, $dialogs );
|
182 |
-
|
183 |
-
// @todo Temporary(?) workaround for custom dialogs as an array (WP-Members Security).
|
184 |
-
$display_msg = ( is_array( $args['msg'] ) ) ? $args['msg']['value'] : $args['msg'];
|
185 |
-
|
186 |
-
$str = $args['div_before'] . $args['p_before'] . stripslashes( $display_msg ) . $args['p_after'] . $args['div_after'];
|
187 |
-
|
188 |
-
/**
|
189 |
-
* Filter the message.
|
190 |
-
*
|
191 |
-
* @since 2.7.4
|
192 |
-
* @since 3.1.0 Added tag.
|
193 |
-
*
|
194 |
-
* @param string $str The message.
|
195 |
-
* @param string $tag The tag of the message being displayed.
|
196 |
-
*/
|
197 |
-
return apply_filters( 'wpmem_msg_dialog', $str, $tag );
|
198 |
-
|
199 |
-
}
|
200 |
-
endif;
|
201 |
-
|
202 |
-
|
203 |
-
if ( ! function_exists( 'wpmem_inc_memberlinks' ) ):
|
204 |
-
/**
|
205 |
-
* Member Links Dialog.
|
206 |
-
*
|
207 |
-
* Outputs the links used on the members area.
|
208 |
-
*
|
209 |
-
* @since 2.0
|
210 |
-
*
|
211 |
-
* @gloabl $user_login
|
212 |
-
* @global object $wpmem
|
213 |
-
* @param string $page
|
214 |
-
* @return string $str
|
215 |
-
*/
|
216 |
-
function wpmem_inc_memberlinks( $page = 'member' ) {
|
217 |
-
|
218 |
-
global $user_login, $wpmem;
|
219 |
-
|
220 |
-
/**
|
221 |
-
* Filter the log out link.
|
222 |
-
*
|
223 |
-
* @since 2.8.3
|
224 |
-
*
|
225 |
-
* @param string The default logout link.
|
226 |
-
*/
|
227 |
-
$logout = apply_filters( 'wpmem_logout_link', add_query_arg( 'a', 'logout' ) );
|
228 |
-
|
229 |
-
switch ( $page ) {
|
230 |
-
|
231 |
-
case 'member':
|
232 |
-
|
233 |
-
$arr = array(
|
234 |
-
'before_wrapper' => '',
|
235 |
-
'wrapper_before' => '<ul>',
|
236 |
-
'wrapper_after' => '</ul>',
|
237 |
-
'rows' => array(
|
238 |
-
'<li><a href="' . esc_url( add_query_arg( 'a', 'edit' ) ) . '">' . $wpmem->get_text( 'profile_edit' ) . '</a></li>',
|
239 |
-
'<li><a href="' . esc_url( add_query_arg( 'a', 'pwdchange' ) ) . '">' . $wpmem->get_text( 'profile_password' ) . '</a></li>',
|
240 |
-
),
|
241 |
-
'after_wrapper' => '',
|
242 |
-
);
|
243 |
-
|
244 |
-
if ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 && function_exists( 'wpmem_user_page_detail' ) ) {
|
245 |
-
$arr['rows'][] = wpmem_user_page_detail();
|
246 |
-
}
|
247 |
-
|
248 |
-
/**
|
249 |
-
* Filter the member links array.
|
250 |
-
*
|
251 |
-
* @since 3.0.9
|
252 |
-
* @since 3.1.0 Added after_wrapper
|
253 |
-
*
|
254 |
-
* @param array $arr {
|
255 |
-
* The components of the links.
|
256 |
-
*
|
257 |
-
* @type string $before_wrapper Anything that comes before the wrapper.
|
258 |
-
* @type string $wrapper_before The wrapper opening tag (default: <ul>).
|
259 |
-
* @type string $wrapper_after The wrapper closing tag (default: </ul>).
|
260 |
-
* @type array $rows Row items HTML.
|
261 |
-
* @type string $after_wrapper Anything that comes after the wrapper.
|
262 |
-
* }
|
263 |
-
*/
|
264 |
-
$arr = apply_filters( "wpmem_{$page}_links_args", $arr );
|
265 |
-
|
266 |
-
$str = $arr['before_wrapper'];
|
267 |
-
$str.= $arr['wrapper_before'];
|
268 |
-
foreach ( $arr['rows'] as $row ) {
|
269 |
-
$str.= $row;
|
270 |
-
}
|
271 |
-
$str.= $arr['wrapper_after'];
|
272 |
-
$str.= $arr['after_wrapper'];
|
273 |
-
|
274 |
-
/**
|
275 |
-
* Filter the links displayed on the User Profile page (logged in state).
|
276 |
-
*
|
277 |
-
* @since 2.8.3
|
278 |
-
*
|
279 |
-
* @param string $str The default links.
|
280 |
-
*/
|
281 |
-
$str = apply_filters( "wpmem_{$page}_links", $str );
|
282 |
-
break;
|
283 |
-
|
284 |
-
case 'register':
|
285 |
-
|
286 |
-
$url = ( isset( $wpmem->user_pages['profile'] ) && '' != $wpmem->user_pages['profile'] ) ? $wpmem->user_pages['profile'] : get_option( 'home' );
|
287 |
-
|
288 |
-
$arr = array(
|
289 |
-
'before_wrapper' => '<p>' . sprintf( $wpmem->get_text( 'register_status' ), $user_login ) . '</p>',
|
290 |
-
'wrapper_before' => '<ul>',
|
291 |
-
'wrapper_after' => '</ul>',
|
292 |
-
'rows' => array(
|
293 |
-
'<li><a href="' . esc_url( $logout ) . '">' . $wpmem->get_text( 'register_logout' ) . '</a></li>',
|
294 |
-
'<li><a href="' . esc_url( $url ) . '">' . $wpmem->get_text( 'register_continue' ) . '</a></li>',
|
295 |
-
),
|
296 |
-
'after_wrapper' => '',
|
297 |
-
);
|
298 |
-
|
299 |
-
/**
|
300 |
-
* Filter the register links array.
|
301 |
-
*
|
302 |
-
* @since 3.0.9
|
303 |
-
* @since 3.1.0 Added after_wrapper
|
304 |
-
*
|
305 |
-
* @param array $arr {
|
306 |
-
* The components of the links.
|
307 |
-
*
|
308 |
-
* @type string $before_wrapper HTML before the wrapper (default: login status).
|
309 |
-
* @type string $wrapper_before The wrapper opening tag (default: <ul>).
|
310 |
-
* @type string $wrapper_after The wrapper closing tag (default: </ul>).
|
311 |
-
* @type array $rows Row items HTML.
|
312 |
-
* @type string $after_wrapper Anything that comes after the wrapper.
|
313 |
-
* }
|
314 |
-
*/
|
315 |
-
$arr = apply_filters( "wpmem_{$page}_links_args", $arr );
|
316 |
-
|
317 |
-
$str = $arr['before_wrapper'];
|
318 |
-
$str.= $arr['wrapper_before'];
|
319 |
-
foreach ( $arr['rows'] as $row ) {
|
320 |
-
$str.= $row;
|
321 |
-
}
|
322 |
-
$str.= $arr['wrapper_after'];
|
323 |
-
$str.= $arr['after_wrapper'];
|
324 |
-
|
325 |
-
/**
|
326 |
-
* Filter the links displayed on the Register page (logged in state).
|
327 |
-
*
|
328 |
-
* @since 2.8.3
|
329 |
-
*
|
330 |
-
* @param string $str The default links.
|
331 |
-
*/
|
332 |
-
$str = apply_filters( "wpmem_{$page}_links", $str );
|
333 |
-
break;
|
334 |
-
|
335 |
-
case 'login':
|
336 |
-
|
337 |
-
$logout = urldecode( $logout ); // @todo Resolves sprintf issue if url is encoded.
|
338 |
-
$args = array(
|
339 |
-
'wrapper_before' => '<p>',
|
340 |
-
'wrapper_after' => '</p>',
|
341 |
-
'user_login' => $user_login,
|
342 |
-
'welcome' => $wpmem->get_text( 'login_welcome' ),
|
343 |
-
'logout_text' => $wpmem->get_text( 'login_logout' ),
|
344 |
-
'logout_link' => '<a href="' . esc_url( $logout ) . '">%s</a>',
|
345 |
-
'separator' => '<br />',
|
346 |
-
);
|
347 |
-
/**
|
348 |
-
* Filter the status message parts.
|
349 |
-
*
|
350 |
-
* @since 2.9.9
|
351 |
-
*
|
352 |
-
* @param array $args {
|
353 |
-
* The components of the links.
|
354 |
-
*
|
355 |
-
* @type string $wrapper_before The wrapper opening tag (default: <p>).
|
356 |
-
* @type string $wrapper_after The wrapper closing tag (default: </p>).
|
357 |
-
* @type string $user_login
|
358 |
-
* @type string $welcome
|
359 |
-
* @type string $logout_text
|
360 |
-
* @type string $logout_link
|
361 |
-
* @type string $separator
|
362 |
-
* }
|
363 |
-
*/
|
364 |
-
$args = apply_filters( "wpmem_{$page}_links_args", $args );
|
365 |
-
|
366 |
-
// Assemble the message string.
|
367 |
-
$str = $args['wrapper_before']
|
368 |
-
. sprintf( $args['welcome'], $args['user_login'] )
|
369 |
-
. $args['separator']
|
370 |
-
. sprintf( $args['logout_link'], $args['logout_text'] )
|
371 |
-
. $args['wrapper_after'];
|
372 |
-
|
373 |
-
/**
|
374 |
-
* Filter the links displayed on the Log In page (logged in state).
|
375 |
-
*
|
376 |
-
* @since 2.8.3
|
377 |
-
*
|
378 |
-
* @param string $str The default links.
|
379 |
-
*/
|
380 |
-
$str = apply_filters( "wpmem_{$page}_links", $str );
|
381 |
-
break;
|
382 |
-
|
383 |
-
case 'status':
|
384 |
-
$args = array(
|
385 |
-
'wrapper_before' => '<p>',
|
386 |
-
'wrapper_after' => '</p>',
|
387 |
-
'user_login' => $user_login,
|
388 |
-
'welcome' => $wpmem->get_text( 'status_welcome' ),
|
389 |
-
'logout_text' => $wpmem->get_text( 'status_logout' ),
|
390 |
-
'logout_link' => '<a href="' . esc_url( $logout ) . '">%s</a>',
|
391 |
-
'separator' => ' | ',
|
392 |
-
);
|
393 |
-
/**
|
394 |
-
* Filter the status message parts.
|
395 |
-
*
|
396 |
-
* @since 2.9.9
|
397 |
-
*
|
398 |
-
* @param array $args {
|
399 |
-
* The components of the links.
|
400 |
-
*
|
401 |
-
* @type string $wrapper_before The wrapper opening tag (default: <p>).
|
402 |
-
* @type string $wrapper_after The wrapper closing tag (default: </p>).
|
403 |
-
* @type string $user_login
|
404 |
-
* @type string $welcome
|
405 |
-
* @type string $logout_text
|
406 |
-
* @type string $logout_link
|
407 |
-
* @type string $separator
|
408 |
-
* }
|
409 |
-
*/
|
410 |
-
$args = apply_filters( 'wpmem_status_msg_args', $args );
|
411 |
-
|
412 |
-
// Assemble the message string.
|
413 |
-
$str = $args['wrapper_before']
|
414 |
-
. sprintf( $args['welcome'], $args['user_login'] )
|
415 |
-
. $args['separator']
|
416 |
-
. sprintf( $args['logout_link'], $args['logout_text'] )
|
417 |
-
. $args['wrapper_after'];
|
418 |
-
break;
|
419 |
-
|
420 |
-
}
|
421 |
-
|
422 |
-
return $str;
|
423 |
-
}
|
424 |
-
endif;
|
425 |
-
|
426 |
-
|
427 |
-
if ( ! function_exists( 'wpmem_page_pwd_reset' ) ):
|
428 |
-
/**
|
429 |
-
* Password reset forms.
|
430 |
-
*
|
431 |
-
* This function creates both password reset and forgotten
|
432 |
-
* password forms for page=password shortcode.
|
433 |
-
*
|
434 |
-
* @since 2.7.6
|
435 |
-
* @since 3.2.6 Added nonce validation.
|
436 |
-
*
|
437 |
-
* @global object $wpmem
|
438 |
-
* @param string $wpmem_regchk
|
439 |
-
* @param string $content
|
440 |
-
* @return string $content
|
441 |
-
*/
|
442 |
-
function wpmem_page_pwd_reset( $wpmem_regchk, $content ) {
|
443 |
-
|
444 |
-
global $wpmem;
|
445 |
-
|
446 |
-
if ( is_user_logged_in() ) {
|
447 |
-
|
448 |
-
switch ( $wpmem_regchk ) {
|
449 |
-
|
450 |
-
case "pwdchangesuccess":
|
451 |
-
$content = $content . wpmem_inc_regmessage( $wpmem_regchk );
|
452 |
-
break;
|
453 |
-
|
454 |
-
default:
|
455 |
-
if ( isset( $wpmem_regchk ) && '' != $wpmem_regchk ) {
|
456 |
-
$content .= wpmem_inc_regmessage( $wpmem_regchk, $wpmem->get_text( $wpmem_regchk ) );
|
457 |
-
}
|
458 |
-
$content = $content . wpmem_change_password_form();
|
459 |
-
break;
|
460 |
-
}
|
461 |
-
|
462 |
-
} else {
|
463 |
-
|
464 |
-
// If the password shortcode page is set as User Profile page.
|
465 |
-
if ( 'getusername' == $wpmem->action ) {
|
466 |
-
|
467 |
-
return wpmem_page_forgot_username( $wpmem_regchk, $content );
|
468 |
-
|
469 |
-
} else {
|
470 |
-
|
471 |
-
switch( $wpmem_regchk ) {
|
472 |
-
|
473 |
-
case "pwdresetsuccess":
|
474 |
-
$content = $content . wpmem_inc_regmessage( $wpmem_regchk );
|
475 |
-
$wpmem_regchk = ''; // Clear regchk.
|
476 |
-
break;
|
477 |
-
|
478 |
-
default:
|
479 |
-
if ( isset( $wpmem_regchk ) && '' != $wpmem_regchk ) {
|
480 |
-
$content = wpmem_inc_regmessage( $wpmem_regchk, $wpmem->get_text( $wpmem_regchk ) );
|
481 |
-
}
|
482 |
-
$content = $content . wpmem_reset_password_form();
|
483 |
-
break;
|
484 |
-
}
|
485 |
-
|
486 |
-
}
|
487 |
-
|
488 |
-
}
|
489 |
-
|
490 |
-
return $content;
|
491 |
-
|
492 |
-
}
|
493 |
-
endif;
|
494 |
-
|
495 |
-
|
496 |
-
if ( ! function_exists( 'wpmem_page_user_edit' ) ):
|
497 |
-
/**
|
498 |
-
* Creates a user edit page.
|
499 |
-
*
|
500 |
-
* @since 2.7.6
|
501 |
-
*
|
502 |
-
* @global object $wpmem
|
503 |
-
* @global string $wpmem_a
|
504 |
-
* @global string $wpmem_themsg
|
505 |
-
* @param string $wpmem_regchk
|
506 |
-
* @param string $content
|
507 |
-
* @return string $content
|
508 |
-
*/
|
509 |
-
function wpmem_page_user_edit( $wpmem_regchk, $content ) {
|
510 |
-
|
511 |
-
global $wpmem, $wpmem_a, $wpmem_themsg;
|
512 |
-
/**
|
513 |
-
* Filter the default User Edit heading for shortcode.
|
514 |
-
*
|
515 |
-
* @since 2.7.6
|
516 |
-
*
|
517 |
-
* @param string The default edit mode heading.
|
518 |
-
*/
|
519 |
-
$heading = apply_filters( 'wpmem_user_edit_heading', $wpmem->get_text( 'profile_heading' ) );
|
520 |
-
|
521 |
-
if ( $wpmem_a == "update") {
|
522 |
-
$content.= wpmem_inc_regmessage( $wpmem_regchk, $wpmem_themsg );
|
523 |
-
}
|
524 |
-
$content = $content . wpmem_register_form( 'edit', $heading );
|
525 |
-
|
526 |
-
return $content;
|
527 |
-
}
|
528 |
-
endif;
|
529 |
-
|
530 |
-
|
531 |
-
/**
|
532 |
-
* Forgot username form.
|
533 |
-
*
|
534 |
-
* This function creates a form for retrieving a forgotten username.
|
535 |
-
*
|
536 |
-
* @since 3.0.8
|
537 |
-
*
|
538 |
-
* @param string $wpmem_regchk
|
539 |
-
* @param string $content
|
540 |
-
* @return string $content
|
541 |
-
*/
|
542 |
-
function wpmem_page_forgot_username( $wpmem_regchk, $content ) {
|
543 |
-
|
544 |
-
if ( ! is_user_logged_in() ) {
|
545 |
-
|
546 |
-
global $wpmem;
|
547 |
-
switch( $wpmem->regchk ) {
|
548 |
-
|
549 |
-
case "usernamefailed":
|
550 |
-
$msg = $wpmem->get_text( 'usernamefailed' );
|
551 |
-
$content = $content
|
552 |
-
. wpmem_inc_regmessage( 'usernamefailed', $msg )
|
553 |
-
. wpmem_forgot_username_form();
|
554 |
-
$wpmem->regchk = ''; // Clear regchk.
|
555 |
-
break;
|
556 |
-
|
557 |
-
case "usernamesuccess":
|
558 |
-
$email = ( isset( $_POST['user_email'] ) ) ? sanitize_email( $_POST['user_email'] ) : '';
|
559 |
-
$msg = sprintf( $wpmem->get_text( 'usernamesuccess' ), $email );
|
560 |
-
$content = $content . wpmem_inc_regmessage( 'usernamesuccess', $msg );
|
561 |
-
$wpmem->regchk = ''; // Clear regchk.
|
562 |
-
break;
|
563 |
-
|
564 |
-
default:
|
565 |
-
$content = $content . wpmem_forgot_username_form();
|
566 |
-
break;
|
567 |
-
}
|
568 |
-
|
569 |
-
}
|
570 |
-
|
571 |
-
return $content;
|
572 |
-
|
573 |
-
}
|
574 |
-
|
575 |
// End of file.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members Dialog Functions
|
4 |
+
*
|
5 |
+
* Handles functions that output front-end dialogs to end users.
|
6 |
+
*
|
7 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
+
* Copyright (c) 2006-2020 Chad Butler
|
10 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
+
*
|
12 |
+
* @package WP-Members
|
13 |
+
* @author Chad Butler
|
14 |
+
* @copyright 2006-2020
|
15 |
+
*
|
16 |
+
* Functions Included:
|
17 |
+
* - wpmem_inc_loginfailed
|
18 |
+
* - wpmem_inc_regmessage
|
19 |
+
* - wpmem_inc_memberlinks
|
20 |
+
* - wpmem_page_pwd_reset
|
21 |
+
* - wpmem_page_user_edit
|
22 |
+
* - wpmem_page_forgot_username
|
23 |
+
* - wpmem_inc_forgotusername
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Exit if accessed directly.
|
27 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
28 |
+
exit();
|
29 |
+
}
|
30 |
+
|
31 |
+
if ( ! function_exists( 'wpmem_inc_loginfailed' ) ):
|
32 |
+
/**
|
33 |
+
* Login Failed Dialog.
|
34 |
+
*
|
35 |
+
* Returns the login failed error message.
|
36 |
+
*
|
37 |
+
* @since 1.8
|
38 |
+
*
|
39 |
+
* @global object $wpmem The WP_Members object.
|
40 |
+
* @return string $str The generated html for the login failed message.
|
41 |
+
*/
|
42 |
+
function wpmem_inc_loginfailed() {
|
43 |
+
|
44 |
+
global $wpmem;
|
45 |
+
|
46 |
+
// Defaults.
|
47 |
+
$defaults = array(
|
48 |
+
'div_before' => '<div align="center" id="wpmem_msg">',
|
49 |
+
'div_after' => '</div>',
|
50 |
+
'heading_before' => '<h2>',
|
51 |
+
'heading' => $wpmem->get_text( 'login_failed_heading' ),
|
52 |
+
'heading_after' => '</h2>',
|
53 |
+
'p_before' => '<p>',
|
54 |
+
'message' => $wpmem->get_text( 'login_failed' ), // @todo $wpmem->error
|
55 |
+
'p_after' => '</p>',
|
56 |
+
'link' => '<a href="' . esc_url( $_SERVER['REQUEST_URI'] ) . '">' . $wpmem->get_text( 'login_failed_link' ) . '</a>',
|
57 |
+
);
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Filter the login failed dialog arguments.
|
61 |
+
*
|
62 |
+
* @since 2.9.0
|
63 |
+
*
|
64 |
+
* @param array An array of arguments to merge with defaults.
|
65 |
+
*/
|
66 |
+
$args = apply_filters( 'wpmem_login_failed_args', '' );
|
67 |
+
|
68 |
+
// Merge $args with defaults.
|
69 |
+
$args = wp_parse_args( $args, $defaults );
|
70 |
+
|
71 |
+
$str = $args['div_before']
|
72 |
+
. $args['heading_before'] . $args['heading'] . $args['heading_after']
|
73 |
+
. $args['p_before'] . $args['message'] . $args['p_after']
|
74 |
+
. $args['p_before'] . $args['link'] . $args['p_after']
|
75 |
+
. $args['div_after'];
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Filter the login failed dialog.
|
79 |
+
*
|
80 |
+
* @since 2.7.3
|
81 |
+
*
|
82 |
+
* @param string $str The login failed dialog.
|
83 |
+
*/
|
84 |
+
$str = apply_filters( 'wpmem_login_failed', $str );
|
85 |
+
|
86 |
+
return $str;
|
87 |
+
}
|
88 |
+
endif;
|
89 |
+
|
90 |
+
|
91 |
+
if ( ! function_exists( 'wpmem_inc_regmessage' ) ):
|
92 |
+
/**
|
93 |
+
* Message Dialog.
|
94 |
+
*
|
95 |
+
* Returns various dialogs and error messages.
|
96 |
+
*
|
97 |
+
* @since 1.8
|
98 |
+
* @since 3.3.0 Changed 'toggles' to 'tags'
|
99 |
+
*
|
100 |
+
* @global object $wpmem
|
101 |
+
* @param string $tag Error message tag to look for specific error messages.
|
102 |
+
* @param string $msg A message that has no tag that is passed directly to the function.
|
103 |
+
* @return string $str The final HTML for the message.
|
104 |
+
*/
|
105 |
+
function wpmem_inc_regmessage( $tag, $msg = '' ) {
|
106 |
+
|
107 |
+
global $wpmem;
|
108 |
+
|
109 |
+
// defaults
|
110 |
+
$defaults = array(
|
111 |
+
'div_before' => '<div class="wpmem_msg" align="center">',
|
112 |
+
'div_after' => '</div>',
|
113 |
+
'p_before' => '<p>',
|
114 |
+
'p_after' => '</p>',
|
115 |
+
'tags' => array(
|
116 |
+
'user',
|
117 |
+
'email',
|
118 |
+
'success',
|
119 |
+
'editsuccess',
|
120 |
+
'pwdchangerr',
|
121 |
+
'pwdchangesuccess',
|
122 |
+
'pwdreseterr',
|
123 |
+
'pwdresetsuccess',
|
124 |
+
),
|
125 |
+
);
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Filter the message arguments.
|
129 |
+
*
|
130 |
+
* @since 2.9.0
|
131 |
+
* @deprecated 3.3.0 Use wpmem_msg_defaults instead.
|
132 |
+
*
|
133 |
+
* @param array An array of arguments to merge with defaults.
|
134 |
+
*/
|
135 |
+
$args = apply_filters( 'wpmem_msg_args', '' );
|
136 |
+
|
137 |
+
/** This filter is documented in /includes/class-wp-members-admin-api.php */
|
138 |
+
$dialogs = apply_filters( 'wpmem_dialogs', get_option( 'wpmembers_dialogs' ) );
|
139 |
+
|
140 |
+
// @todo Temporary(?) workaround for custom dialogs as an array (WP-Members Security).
|
141 |
+
if ( array_key_exists( $tag, $dialogs ) ) {
|
142 |
+
if ( is_array( $dialogs[ $tag ] ) ) {
|
143 |
+
$msg = stripslashes( $dialogs[ $tag ]['value'] );
|
144 |
+
} else {
|
145 |
+
$msg = $wpmem->get_text( $tag );
|
146 |
+
$msg = ( $dialogs[ $tag ] == $msg ) ? $msg : __( stripslashes( $dialogs[ $tag ] ), 'wp-members' );
|
147 |
+
}
|
148 |
+
}
|
149 |
+
$defaults['msg'] = $msg;
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Filter the message array
|
153 |
+
*
|
154 |
+
* @since 2.9.2
|
155 |
+
* @since 3.1.1 added $dialogs parameter.
|
156 |
+
* @deprecated 3.3.0 Use wpmem_msg_defaults instead.
|
157 |
+
*
|
158 |
+
* @param array $defaults An array of the defaults.
|
159 |
+
* @param string $tag The tag that we are on, if any.
|
160 |
+
* @param array $dialogs
|
161 |
+
*/
|
162 |
+
$defaults = apply_filters( 'wpmem_msg_dialog_arr', $defaults, $tag, $dialogs );
|
163 |
+
|
164 |
+
// Merge $args with defaults.
|
165 |
+
$args = wp_parse_args( $args, $defaults );
|
166 |
+
|
167 |
+
// Backwards compatibility for 'toggles'.
|
168 |
+
if ( isset( $args['toggles'] ) ) {
|
169 |
+
$args['tags'] = $args['toggles'];
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* Filter the message settings.
|
174 |
+
*
|
175 |
+
* @since 3.3.0
|
176 |
+
*
|
177 |
+
* @param array $defaults An array of the defaults.
|
178 |
+
* @param string $tag The tag that we are on, if any.
|
179 |
+
* @param array $dialogs
|
180 |
+
*/
|
181 |
+
$args = apply_filters( 'wpmem_msg_defaults', $defaults, $tag, $dialogs );
|
182 |
+
|
183 |
+
// @todo Temporary(?) workaround for custom dialogs as an array (WP-Members Security).
|
184 |
+
$display_msg = ( is_array( $args['msg'] ) ) ? $args['msg']['value'] : $args['msg'];
|
185 |
+
|
186 |
+
$str = $args['div_before'] . $args['p_before'] . stripslashes( $display_msg ) . $args['p_after'] . $args['div_after'];
|
187 |
+
|
188 |
+
/**
|
189 |
+
* Filter the message.
|
190 |
+
*
|
191 |
+
* @since 2.7.4
|
192 |
+
* @since 3.1.0 Added tag.
|
193 |
+
*
|
194 |
+
* @param string $str The message.
|
195 |
+
* @param string $tag The tag of the message being displayed.
|
196 |
+
*/
|
197 |
+
return apply_filters( 'wpmem_msg_dialog', $str, $tag );
|
198 |
+
|
199 |
+
}
|
200 |
+
endif;
|
201 |
+
|
202 |
+
|
203 |
+
if ( ! function_exists( 'wpmem_inc_memberlinks' ) ):
|
204 |
+
/**
|
205 |
+
* Member Links Dialog.
|
206 |
+
*
|
207 |
+
* Outputs the links used on the members area.
|
208 |
+
*
|
209 |
+
* @since 2.0
|
210 |
+
*
|
211 |
+
* @gloabl $user_login
|
212 |
+
* @global object $wpmem
|
213 |
+
* @param string $page
|
214 |
+
* @return string $str
|
215 |
+
*/
|
216 |
+
function wpmem_inc_memberlinks( $page = 'member' ) {
|
217 |
+
|
218 |
+
global $user_login, $wpmem;
|
219 |
+
|
220 |
+
/**
|
221 |
+
* Filter the log out link.
|
222 |
+
*
|
223 |
+
* @since 2.8.3
|
224 |
+
*
|
225 |
+
* @param string The default logout link.
|
226 |
+
*/
|
227 |
+
$logout = apply_filters( 'wpmem_logout_link', add_query_arg( 'a', 'logout' ) );
|
228 |
+
|
229 |
+
switch ( $page ) {
|
230 |
+
|
231 |
+
case 'member':
|
232 |
+
|
233 |
+
$arr = array(
|
234 |
+
'before_wrapper' => '',
|
235 |
+
'wrapper_before' => '<ul>',
|
236 |
+
'wrapper_after' => '</ul>',
|
237 |
+
'rows' => array(
|
238 |
+
'<li><a href="' . esc_url( add_query_arg( 'a', 'edit' ) ) . '">' . $wpmem->get_text( 'profile_edit' ) . '</a></li>',
|
239 |
+
'<li><a href="' . esc_url( add_query_arg( 'a', 'pwdchange' ) ) . '">' . $wpmem->get_text( 'profile_password' ) . '</a></li>',
|
240 |
+
),
|
241 |
+
'after_wrapper' => '',
|
242 |
+
);
|
243 |
+
|
244 |
+
if ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 && function_exists( 'wpmem_user_page_detail' ) ) {
|
245 |
+
$arr['rows'][] = wpmem_user_page_detail();
|
246 |
+
}
|
247 |
+
|
248 |
+
/**
|
249 |
+
* Filter the member links array.
|
250 |
+
*
|
251 |
+
* @since 3.0.9
|
252 |
+
* @since 3.1.0 Added after_wrapper
|
253 |
+
*
|
254 |
+
* @param array $arr {
|
255 |
+
* The components of the links.
|
256 |
+
*
|
257 |
+
* @type string $before_wrapper Anything that comes before the wrapper.
|
258 |
+
* @type string $wrapper_before The wrapper opening tag (default: <ul>).
|
259 |
+
* @type string $wrapper_after The wrapper closing tag (default: </ul>).
|
260 |
+
* @type array $rows Row items HTML.
|
261 |
+
* @type string $after_wrapper Anything that comes after the wrapper.
|
262 |
+
* }
|
263 |
+
*/
|
264 |
+
$arr = apply_filters( "wpmem_{$page}_links_args", $arr );
|
265 |
+
|
266 |
+
$str = $arr['before_wrapper'];
|
267 |
+
$str.= $arr['wrapper_before'];
|
268 |
+
foreach ( $arr['rows'] as $row ) {
|
269 |
+
$str.= $row;
|
270 |
+
}
|
271 |
+
$str.= $arr['wrapper_after'];
|
272 |
+
$str.= $arr['after_wrapper'];
|
273 |
+
|
274 |
+
/**
|
275 |
+
* Filter the links displayed on the User Profile page (logged in state).
|
276 |
+
*
|
277 |
+
* @since 2.8.3
|
278 |
+
*
|
279 |
+
* @param string $str The default links.
|
280 |
+
*/
|
281 |
+
$str = apply_filters( "wpmem_{$page}_links", $str );
|
282 |
+
break;
|
283 |
+
|
284 |
+
case 'register':
|
285 |
+
|
286 |
+
$url = ( isset( $wpmem->user_pages['profile'] ) && '' != $wpmem->user_pages['profile'] ) ? $wpmem->user_pages['profile'] : get_option( 'home' );
|
287 |
+
|
288 |
+
$arr = array(
|
289 |
+
'before_wrapper' => '<p>' . sprintf( $wpmem->get_text( 'register_status' ), $user_login ) . '</p>',
|
290 |
+
'wrapper_before' => '<ul>',
|
291 |
+
'wrapper_after' => '</ul>',
|
292 |
+
'rows' => array(
|
293 |
+
'<li><a href="' . esc_url( $logout ) . '">' . $wpmem->get_text( 'register_logout' ) . '</a></li>',
|
294 |
+
'<li><a href="' . esc_url( $url ) . '">' . $wpmem->get_text( 'register_continue' ) . '</a></li>',
|
295 |
+
),
|
296 |
+
'after_wrapper' => '',
|
297 |
+
);
|
298 |
+
|
299 |
+
/**
|
300 |
+
* Filter the register links array.
|
301 |
+
*
|
302 |
+
* @since 3.0.9
|
303 |
+
* @since 3.1.0 Added after_wrapper
|
304 |
+
*
|
305 |
+
* @param array $arr {
|
306 |
+
* The components of the links.
|
307 |
+
*
|
308 |
+
* @type string $before_wrapper HTML before the wrapper (default: login status).
|
309 |
+
* @type string $wrapper_before The wrapper opening tag (default: <ul>).
|
310 |
+
* @type string $wrapper_after The wrapper closing tag (default: </ul>).
|
311 |
+
* @type array $rows Row items HTML.
|
312 |
+
* @type string $after_wrapper Anything that comes after the wrapper.
|
313 |
+
* }
|
314 |
+
*/
|
315 |
+
$arr = apply_filters( "wpmem_{$page}_links_args", $arr );
|
316 |
+
|
317 |
+
$str = $arr['before_wrapper'];
|
318 |
+
$str.= $arr['wrapper_before'];
|
319 |
+
foreach ( $arr['rows'] as $row ) {
|
320 |
+
$str.= $row;
|
321 |
+
}
|
322 |
+
$str.= $arr['wrapper_after'];
|
323 |
+
$str.= $arr['after_wrapper'];
|
324 |
+
|
325 |
+
/**
|
326 |
+
* Filter the links displayed on the Register page (logged in state).
|
327 |
+
*
|
328 |
+
* @since 2.8.3
|
329 |
+
*
|
330 |
+
* @param string $str The default links.
|
331 |
+
*/
|
332 |
+
$str = apply_filters( "wpmem_{$page}_links", $str );
|
333 |
+
break;
|
334 |
+
|
335 |
+
case 'login':
|
336 |
+
|
337 |
+
$logout = urldecode( $logout ); // @todo Resolves sprintf issue if url is encoded.
|
338 |
+
$args = array(
|
339 |
+
'wrapper_before' => '<p>',
|
340 |
+
'wrapper_after' => '</p>',
|
341 |
+
'user_login' => $user_login,
|
342 |
+
'welcome' => $wpmem->get_text( 'login_welcome' ),
|
343 |
+
'logout_text' => $wpmem->get_text( 'login_logout' ),
|
344 |
+
'logout_link' => '<a href="' . esc_url( $logout ) . '">%s</a>',
|
345 |
+
'separator' => '<br />',
|
346 |
+
);
|
347 |
+
/**
|
348 |
+
* Filter the status message parts.
|
349 |
+
*
|
350 |
+
* @since 2.9.9
|
351 |
+
*
|
352 |
+
* @param array $args {
|
353 |
+
* The components of the links.
|
354 |
+
*
|
355 |
+
* @type string $wrapper_before The wrapper opening tag (default: <p>).
|
356 |
+
* @type string $wrapper_after The wrapper closing tag (default: </p>).
|
357 |
+
* @type string $user_login
|
358 |
+
* @type string $welcome
|
359 |
+
* @type string $logout_text
|
360 |
+
* @type string $logout_link
|
361 |
+
* @type string $separator
|
362 |
+
* }
|
363 |
+
*/
|
364 |
+
$args = apply_filters( "wpmem_{$page}_links_args", $args );
|
365 |
+
|
366 |
+
// Assemble the message string.
|
367 |
+
$str = $args['wrapper_before']
|
368 |
+
. sprintf( $args['welcome'], $args['user_login'] )
|
369 |
+
. $args['separator']
|
370 |
+
. sprintf( $args['logout_link'], $args['logout_text'] )
|
371 |
+
. $args['wrapper_after'];
|
372 |
+
|
373 |
+
/**
|
374 |
+
* Filter the links displayed on the Log In page (logged in state).
|
375 |
+
*
|
376 |
+
* @since 2.8.3
|
377 |
+
*
|
378 |
+
* @param string $str The default links.
|
379 |
+
*/
|
380 |
+
$str = apply_filters( "wpmem_{$page}_links", $str );
|
381 |
+
break;
|
382 |
+
|
383 |
+
case 'status':
|
384 |
+
$args = array(
|
385 |
+
'wrapper_before' => '<p>',
|
386 |
+
'wrapper_after' => '</p>',
|
387 |
+
'user_login' => $user_login,
|
388 |
+
'welcome' => $wpmem->get_text( 'status_welcome' ),
|
389 |
+
'logout_text' => $wpmem->get_text( 'status_logout' ),
|
390 |
+
'logout_link' => '<a href="' . esc_url( $logout ) . '">%s</a>',
|
391 |
+
'separator' => ' | ',
|
392 |
+
);
|
393 |
+
/**
|
394 |
+
* Filter the status message parts.
|
395 |
+
*
|
396 |
+
* @since 2.9.9
|
397 |
+
*
|
398 |
+
* @param array $args {
|
399 |
+
* The components of the links.
|
400 |
+
*
|
401 |
+
* @type string $wrapper_before The wrapper opening tag (default: <p>).
|
402 |
+
* @type string $wrapper_after The wrapper closing tag (default: </p>).
|
403 |
+
* @type string $user_login
|
404 |
+
* @type string $welcome
|
405 |
+
* @type string $logout_text
|
406 |
+
* @type string $logout_link
|
407 |
+
* @type string $separator
|
408 |
+
* }
|
409 |
+
*/
|
410 |
+
$args = apply_filters( 'wpmem_status_msg_args', $args );
|
411 |
+
|
412 |
+
// Assemble the message string.
|
413 |
+
$str = $args['wrapper_before']
|
414 |
+
. sprintf( $args['welcome'], $args['user_login'] )
|
415 |
+
. $args['separator']
|
416 |
+
. sprintf( $args['logout_link'], $args['logout_text'] )
|
417 |
+
. $args['wrapper_after'];
|
418 |
+
break;
|
419 |
+
|
420 |
+
}
|
421 |
+
|
422 |
+
return $str;
|
423 |
+
}
|
424 |
+
endif;
|
425 |
+
|
426 |
+
|
427 |
+
if ( ! function_exists( 'wpmem_page_pwd_reset' ) ):
|
428 |
+
/**
|
429 |
+
* Password reset forms.
|
430 |
+
*
|
431 |
+
* This function creates both password reset and forgotten
|
432 |
+
* password forms for page=password shortcode.
|
433 |
+
*
|
434 |
+
* @since 2.7.6
|
435 |
+
* @since 3.2.6 Added nonce validation.
|
436 |
+
*
|
437 |
+
* @global object $wpmem
|
438 |
+
* @param string $wpmem_regchk
|
439 |
+
* @param string $content
|
440 |
+
* @return string $content
|
441 |
+
*/
|
442 |
+
function wpmem_page_pwd_reset( $wpmem_regchk, $content ) {
|
443 |
+
|
444 |
+
global $wpmem;
|
445 |
+
|
446 |
+
if ( is_user_logged_in() ) {
|
447 |
+
|
448 |
+
switch ( $wpmem_regchk ) {
|
449 |
+
|
450 |
+
case "pwdchangesuccess":
|
451 |
+
$content = $content . wpmem_inc_regmessage( $wpmem_regchk );
|
452 |
+
break;
|
453 |
+
|
454 |
+
default:
|
455 |
+
if ( isset( $wpmem_regchk ) && '' != $wpmem_regchk ) {
|
456 |
+
$content .= wpmem_inc_regmessage( $wpmem_regchk, $wpmem->get_text( $wpmem_regchk ) );
|
457 |
+
}
|
458 |
+
$content = $content . wpmem_change_password_form();
|
459 |
+
break;
|
460 |
+
}
|
461 |
+
|
462 |
+
} else {
|
463 |
+
|
464 |
+
// If the password shortcode page is set as User Profile page.
|
465 |
+
if ( 'getusername' == $wpmem->action ) {
|
466 |
+
|
467 |
+
return wpmem_page_forgot_username( $wpmem_regchk, $content );
|
468 |
+
|
469 |
+
} else {
|
470 |
+
|
471 |
+
switch( $wpmem_regchk ) {
|
472 |
+
|
473 |
+
case "pwdresetsuccess":
|
474 |
+
$content = $content . wpmem_inc_regmessage( $wpmem_regchk );
|
475 |
+
$wpmem_regchk = ''; // Clear regchk.
|
476 |
+
break;
|
477 |
+
|
478 |
+
default:
|
479 |
+
if ( isset( $wpmem_regchk ) && '' != $wpmem_regchk ) {
|
480 |
+
$content = wpmem_inc_regmessage( $wpmem_regchk, $wpmem->get_text( $wpmem_regchk ) );
|
481 |
+
}
|
482 |
+
$content = $content . wpmem_reset_password_form();
|
483 |
+
break;
|
484 |
+
}
|
485 |
+
|
486 |
+
}
|
487 |
+
|
488 |
+
}
|
489 |
+
|
490 |
+
return $content;
|
491 |
+
|
492 |
+
}
|
493 |
+
endif;
|
494 |
+
|
495 |
+
|
496 |
+
if ( ! function_exists( 'wpmem_page_user_edit' ) ):
|
497 |
+
/**
|
498 |
+
* Creates a user edit page.
|
499 |
+
*
|
500 |
+
* @since 2.7.6
|
501 |
+
*
|
502 |
+
* @global object $wpmem
|
503 |
+
* @global string $wpmem_a
|
504 |
+
* @global string $wpmem_themsg
|
505 |
+
* @param string $wpmem_regchk
|
506 |
+
* @param string $content
|
507 |
+
* @return string $content
|
508 |
+
*/
|
509 |
+
function wpmem_page_user_edit( $wpmem_regchk, $content ) {
|
510 |
+
|
511 |
+
global $wpmem, $wpmem_a, $wpmem_themsg;
|
512 |
+
/**
|
513 |
+
* Filter the default User Edit heading for shortcode.
|
514 |
+
*
|
515 |
+
* @since 2.7.6
|
516 |
+
*
|
517 |
+
* @param string The default edit mode heading.
|
518 |
+
*/
|
519 |
+
$heading = apply_filters( 'wpmem_user_edit_heading', $wpmem->get_text( 'profile_heading' ) );
|
520 |
+
|
521 |
+
if ( $wpmem_a == "update") {
|
522 |
+
$content.= wpmem_inc_regmessage( $wpmem_regchk, $wpmem_themsg );
|
523 |
+
}
|
524 |
+
$content = $content . wpmem_register_form( 'edit', $heading );
|
525 |
+
|
526 |
+
return $content;
|
527 |
+
}
|
528 |
+
endif;
|
529 |
+
|
530 |
+
|
531 |
+
/**
|
532 |
+
* Forgot username form.
|
533 |
+
*
|
534 |
+
* This function creates a form for retrieving a forgotten username.
|
535 |
+
*
|
536 |
+
* @since 3.0.8
|
537 |
+
*
|
538 |
+
* @param string $wpmem_regchk
|
539 |
+
* @param string $content
|
540 |
+
* @return string $content
|
541 |
+
*/
|
542 |
+
function wpmem_page_forgot_username( $wpmem_regchk, $content ) {
|
543 |
+
|
544 |
+
if ( ! is_user_logged_in() ) {
|
545 |
+
|
546 |
+
global $wpmem;
|
547 |
+
switch( $wpmem->regchk ) {
|
548 |
+
|
549 |
+
case "usernamefailed":
|
550 |
+
$msg = $wpmem->get_text( 'usernamefailed' );
|
551 |
+
$content = $content
|
552 |
+
. wpmem_inc_regmessage( 'usernamefailed', $msg )
|
553 |
+
. wpmem_forgot_username_form();
|
554 |
+
$wpmem->regchk = ''; // Clear regchk.
|
555 |
+
break;
|
556 |
+
|
557 |
+
case "usernamesuccess":
|
558 |
+
$email = ( isset( $_POST['user_email'] ) ) ? sanitize_email( $_POST['user_email'] ) : '';
|
559 |
+
$msg = sprintf( $wpmem->get_text( 'usernamesuccess' ), $email );
|
560 |
+
$content = $content . wpmem_inc_regmessage( 'usernamesuccess', $msg );
|
561 |
+
$wpmem->regchk = ''; // Clear regchk.
|
562 |
+
break;
|
563 |
+
|
564 |
+
default:
|
565 |
+
$content = $content . wpmem_forgot_username_form();
|
566 |
+
break;
|
567 |
+
}
|
568 |
+
|
569 |
+
}
|
570 |
+
|
571 |
+
return $content;
|
572 |
+
|
573 |
+
}
|
574 |
+
|
575 |
// End of file.
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: cbutlerjr
|
3 |
Tags: access, authentication, content, login, member, membership, password, protect, register, registration, restriction, subscriber
|
4 |
Requires at least: 4.0
|
5 |
-
Tested up to: 5.
|
6 |
-
Stable tag: 3.3.
|
7 |
License: GPLv2
|
8 |
|
9 |
== Description ==
|
@@ -100,7 +100,7 @@ The FAQs are maintained at https://rocketgeek.com/plugins/wp-members/docs/faqs/
|
|
100 |
|
101 |
== Upgrade Notice ==
|
102 |
|
103 |
-
WP-Members 3.3.0 is a major update. WP-Members 3.3.
|
104 |
|
105 |
|
106 |
== Screenshots ==
|
@@ -124,6 +124,32 @@ WP-Members 3.3.0 is a major update. WP-Members 3.3.1 is a bug fix release. See c
|
|
124 |
|
125 |
== Changelog ==
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
= 3.3.1 =
|
128 |
|
129 |
* Update membership product expiration to allow for a "no gap" expiration (i.e. renewal begins from expiration date, optional) or default (renewal begins from today or expiration date, whichever is later).
|
@@ -150,8 +176,6 @@ Including all 3.3.0.x patches:
|
|
150 |
|
151 |
= 3.3.0 =
|
152 |
|
153 |
-
* @todo Need to resolve duplicate wpmem_login_form_defaults. (maybe took care of itself with backing out of _args deprecation)
|
154 |
-
|
155 |
* REMOVED [wp-members] shortcode tag. THIS TAG IS OBSOLETE WILL NO LONGER FUNCTION. See: https://rocketgeek.com/shortcodes/list-of-replacement-shortcodes/
|
156 |
* REMOVED tinymce button for shortcodes as no longer necessary with gutenberg.
|
157 |
* Deprecated wpmem_inc_login_args filter, use wpmem_login_form_defaults instead.
|
2 |
Contributors: cbutlerjr
|
3 |
Tags: access, authentication, content, login, member, membership, password, protect, register, registration, restriction, subscriber
|
4 |
Requires at least: 4.0
|
5 |
+
Tested up to: 5.4
|
6 |
+
Stable tag: 3.3.2.2
|
7 |
License: GPLv2
|
8 |
|
9 |
== Description ==
|
100 |
|
101 |
== Upgrade Notice ==
|
102 |
|
103 |
+
WP-Members 3.3.0 is a major update. WP-Members 3.3.2 is a bug fix release. See changelog for important details. Minimum WP version is 4.0.
|
104 |
|
105 |
|
106 |
== Screenshots ==
|
124 |
|
125 |
== Changelog ==
|
126 |
|
127 |
+
= 3.3.2.2 =
|
128 |
+
|
129 |
+
* Fixed a bug from 3.3.2 that causes reCAPTCHA v2 to always believe the captcha is not checked.
|
130 |
+
* Fixed a bug from 3.3.2 that caused posts to not be able to be updated in the block editor.
|
131 |
+
|
132 |
+
= 3.3.2.1 =
|
133 |
+
|
134 |
+
* Fixed a bug that caused post excerpts to not be displayed if auto excerpt is not enabled.
|
135 |
+
|
136 |
+
= 3.3.2 =
|
137 |
+
|
138 |
+
* Added back shortcode menu item previously removed in 3.3.0.
|
139 |
+
* Added new handling in wpmem_is_blocked() for validating rest api requests.
|
140 |
+
* Added new wpmem_is_rest() function to the plugin's API, determines if the request is a rest request.
|
141 |
+
* Fixed issue with dropdown, mutliple select, and radio field types that allowed white space in resulting value.
|
142 |
+
* Fixed issue with register/profile update validation if email is removed via wpmem_fields filter hook.
|
143 |
+
* Fixed issue with prev/next post links to not show hidden posts if user is logged in but does not have a membership.
|
144 |
+
* Fixed issue with hidden posts when membership products are used. Hidden posts not assigned a membership remained hidden.
|
145 |
+
* Fixed issue with menus where logged in/logged out settings were not applied unless membership products were enabled.
|
146 |
+
* Moved wpmem_post_register_data action to fire hooked to user_register at priority 20. Changed email actions to fire at priority 25. See release announcement for more detail of implications.
|
147 |
+
* Code improvement to reCAPTCHA.
|
148 |
+
* Code improvement to excerpt generation.
|
149 |
+
* Code improvement to expiration date generation.
|
150 |
+
* Code improvement to hidden posts when using membership products.
|
151 |
+
* Code improvement changed user_register hook priority for post_register_data() to "9" to allow for custom meta fields to be available to any user_register function using the default priority (10) or later.
|
152 |
+
|
153 |
= 3.3.1 =
|
154 |
|
155 |
* Update membership product expiration to allow for a "no gap" expiration (i.e. renewal begins from expiration date, optional) or default (renewal begins from today or expiration date, whichever is later).
|
176 |
|
177 |
= 3.3.0 =
|
178 |
|
|
|
|
|
179 |
* REMOVED [wp-members] shortcode tag. THIS TAG IS OBSOLETE WILL NO LONGER FUNCTION. See: https://rocketgeek.com/shortcodes/list-of-replacement-shortcodes/
|
180 |
* REMOVED tinymce button for shortcodes as no longer necessary with gutenberg.
|
181 |
* Deprecated wpmem_inc_login_args filter, use wpmem_login_form_defaults instead.
|
templates/tos.php
CHANGED
@@ -1,39 +1,39 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members TOS Page
|
4 |
-
*
|
5 |
-
* Generates teh Terms of Service pop-up.
|
6 |
-
*
|
7 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
-
* Copyright (c) 2006-
|
10 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
-
*
|
12 |
-
* @package WP-Members
|
13 |
-
* @author Chad Butler
|
14 |
-
* @copyright 2006-
|
15 |
-
*/
|
16 |
-
?>
|
17 |
-
|
18 |
-
<html>
|
19 |
-
<head>
|
20 |
-
<title><?php _e( 'Terms of Service', 'wp-members' ); ?> | <?php bloginfo( 'name' ); ?></title>
|
21 |
-
</head>
|
22 |
-
|
23 |
-
<body>
|
24 |
-
|
25 |
-
<?php
|
26 |
-
|
27 |
-
$wpmem_tos = get_option( 'wpmembers_tos' );
|
28 |
-
|
29 |
-
echo stripslashes( $wpmem_tos );
|
30 |
-
|
31 |
-
print ( '<br /><br />' );
|
32 |
-
printf( __('%sclose%s', 'wp-members'), '[<a href="javascript:self.close()">', '</a>]' );
|
33 |
-
print ( ' ' );
|
34 |
-
printf( __('%sprint%s', 'wp-members'), '[<a href="javascript:window.print()">', '</a>]' );
|
35 |
-
|
36 |
-
?>
|
37 |
-
|
38 |
-
</body>
|
39 |
</html>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members TOS Page
|
4 |
+
*
|
5 |
+
* Generates teh Terms of Service pop-up.
|
6 |
+
*
|
7 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
+
* Copyright (c) 2006-2020 Chad Butler
|
10 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
+
*
|
12 |
+
* @package WP-Members
|
13 |
+
* @author Chad Butler
|
14 |
+
* @copyright 2006-2020
|
15 |
+
*/
|
16 |
+
?>
|
17 |
+
|
18 |
+
<html>
|
19 |
+
<head>
|
20 |
+
<title><?php _e( 'Terms of Service', 'wp-members' ); ?> | <?php bloginfo( 'name' ); ?></title>
|
21 |
+
</head>
|
22 |
+
|
23 |
+
<body>
|
24 |
+
|
25 |
+
<?php
|
26 |
+
|
27 |
+
$wpmem_tos = get_option( 'wpmembers_tos' );
|
28 |
+
|
29 |
+
echo stripslashes( $wpmem_tos );
|
30 |
+
|
31 |
+
print ( '<br /><br />' );
|
32 |
+
printf( __('%sclose%s', 'wp-members'), '[<a href="javascript:self.close()">', '</a>]' );
|
33 |
+
print ( ' ' );
|
34 |
+
printf( __('%sprint%s', 'wp-members'), '[<a href="javascript:window.print()">', '</a>]' );
|
35 |
+
|
36 |
+
?>
|
37 |
+
|
38 |
+
</body>
|
39 |
</html>
|
uninstall.php
CHANGED
@@ -1,91 +1,91 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP-Members Uninstall
|
4 |
-
*
|
5 |
-
* Removes all settings WP-Members added to the WP options table
|
6 |
-
*
|
7 |
-
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
-
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
-
* Copyright (c) 2006-
|
10 |
-
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
-
*
|
12 |
-
* @package WP-Members
|
13 |
-
* @author Chad Butler
|
14 |
-
* @copyright 2006-
|
15 |
-
*/
|
16 |
-
|
17 |
-
// Exit if accessed directly.
|
18 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
19 |
-
exit();
|
20 |
-
}
|
21 |
-
|
22 |
-
// If uninstall is not called from WordPress, kill the uninstall.
|
23 |
-
if( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
24 |
-
die( 'invalid uninstall' );
|
25 |
-
}
|
26 |
-
|
27 |
-
// Uninstall process removes WP-Members settings from the WordPress database (_options table).
|
28 |
-
if ( WP_UNINSTALL_PLUGIN ) {
|
29 |
-
|
30 |
-
if ( is_multisite() ) {
|
31 |
-
|
32 |
-
global $wpdb;
|
33 |
-
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
|
34 |
-
$original_blog_id = get_current_blog_id();
|
35 |
-
|
36 |
-
foreach ( $blog_ids as $blog_id ) {
|
37 |
-
switch_to_blog( $blog_id );
|
38 |
-
wpmem_uninstall_options();
|
39 |
-
}
|
40 |
-
switch_to_blog( $original_blog_id );
|
41 |
-
|
42 |
-
} else {
|
43 |
-
wpmem_uninstall_options();
|
44 |
-
}
|
45 |
-
}
|
46 |
-
|
47 |
-
|
48 |
-
/**
|
49 |
-
* Compartmentalizes uninstall
|
50 |
-
*
|
51 |
-
* @since 2.9.3
|
52 |
-
*/
|
53 |
-
function wpmem_uninstall_options() {
|
54 |
-
|
55 |
-
delete_option( 'wpmembers_settings' );
|
56 |
-
delete_option( 'wpmembers_fields' );
|
57 |
-
delete_option( 'wpmembers_dialogs' );
|
58 |
-
delete_option( 'wpmembers_captcha' );
|
59 |
-
delete_option( 'wpmembers_tos' );
|
60 |
-
delete_option( 'wpmembers_export' );
|
61 |
-
delete_option( 'wpmembers_utfields' );
|
62 |
-
delete_option( 'wpmembers_usfields' );
|
63 |
-
delete_option( 'wpmembers_dropins' );
|
64 |
-
|
65 |
-
delete_option( 'wpmembers_email_newreg' );
|
66 |
-
delete_option( 'wpmembers_email_newmod' );
|
67 |
-
delete_option( 'wpmembers_email_appmod' );
|
68 |
-
delete_option( 'wpmembers_email_repass' );
|
69 |
-
delete_option( 'wpmembers_email_footer' );
|
70 |
-
delete_option( 'wpmembers_email_notify' );
|
71 |
-
delete_option( 'wpmembers_email_wpfrom' );
|
72 |
-
delete_option( 'wpmembers_email_wpname' );
|
73 |
-
delete_option( 'wpmembers_email_getuser' );
|
74 |
-
|
75 |
-
delete_option( 'widget_wpmemwidget' );
|
76 |
-
|
77 |
-
// For pre-3.x settings that may remain.
|
78 |
-
delete_option( 'wpmembers_msurl' );
|
79 |
-
delete_option( 'wpmembers_regurl' );
|
80 |
-
delete_option( 'wpmembers_logurl' );
|
81 |
-
delete_option( 'wpmembers_cssurl' );
|
82 |
-
delete_option( 'wpmembers_style' );
|
83 |
-
delete_option( 'wpmembers_autoex' );
|
84 |
-
delete_option( 'wpmembers_attrib' );
|
85 |
-
|
86 |
-
// Drop user meta key search table.
|
87 |
-
global $wpdb;
|
88 |
-
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wpmembers_user_search_keys" );
|
89 |
-
}
|
90 |
-
|
91 |
// End of file.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Members Uninstall
|
4 |
+
*
|
5 |
+
* Removes all settings WP-Members added to the WP options table
|
6 |
+
*
|
7 |
+
* This file is part of the WP-Members plugin by Chad Butler
|
8 |
+
* You can find out more about this plugin at https://rocketgeek.com
|
9 |
+
* Copyright (c) 2006-2020 Chad Butler
|
10 |
+
* WP-Members(tm) is a trademark of butlerblog.com
|
11 |
+
*
|
12 |
+
* @package WP-Members
|
13 |
+
* @author Chad Butler
|
14 |
+
* @copyright 2006-2020
|
15 |
+
*/
|
16 |
+
|
17 |
+
// Exit if accessed directly.
|
18 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
19 |
+
exit();
|
20 |
+
}
|
21 |
+
|
22 |
+
// If uninstall is not called from WordPress, kill the uninstall.
|
23 |
+
if( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
24 |
+
die( 'invalid uninstall' );
|
25 |
+
}
|
26 |
+
|
27 |
+
// Uninstall process removes WP-Members settings from the WordPress database (_options table).
|
28 |
+
if ( WP_UNINSTALL_PLUGIN ) {
|
29 |
+
|
30 |
+
if ( is_multisite() ) {
|
31 |
+
|
32 |
+
global $wpdb;
|
33 |
+
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
|
34 |
+
$original_blog_id = get_current_blog_id();
|
35 |
+
|
36 |
+
foreach ( $blog_ids as $blog_id ) {
|
37 |
+
switch_to_blog( $blog_id );
|
38 |
+
wpmem_uninstall_options();
|
39 |
+
}
|
40 |
+
switch_to_blog( $original_blog_id );
|
41 |
+
|
42 |
+
} else {
|
43 |
+
wpmem_uninstall_options();
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Compartmentalizes uninstall
|
50 |
+
*
|
51 |
+
* @since 2.9.3
|
52 |
+
*/
|
53 |
+
function wpmem_uninstall_options() {
|
54 |
+
|
55 |
+
delete_option( 'wpmembers_settings' );
|
56 |
+
delete_option( 'wpmembers_fields' );
|
57 |
+
delete_option( 'wpmembers_dialogs' );
|
58 |
+
delete_option( 'wpmembers_captcha' );
|
59 |
+
delete_option( 'wpmembers_tos' );
|
60 |
+
delete_option( 'wpmembers_export' );
|
61 |
+
delete_option( 'wpmembers_utfields' );
|
62 |
+
delete_option( 'wpmembers_usfields' );
|
63 |
+
delete_option( 'wpmembers_dropins' );
|
64 |
+
|
65 |
+
delete_option( 'wpmembers_email_newreg' );
|
66 |
+
delete_option( 'wpmembers_email_newmod' );
|
67 |
+
delete_option( 'wpmembers_email_appmod' );
|
68 |
+
delete_option( 'wpmembers_email_repass' );
|
69 |
+
delete_option( 'wpmembers_email_footer' );
|
70 |
+
delete_option( 'wpmembers_email_notify' );
|
71 |
+
delete_option( 'wpmembers_email_wpfrom' );
|
72 |
+
delete_option( 'wpmembers_email_wpname' );
|
73 |
+
delete_option( 'wpmembers_email_getuser' );
|
74 |
+
|
75 |
+
delete_option( 'widget_wpmemwidget' );
|
76 |
+
|
77 |
+
// For pre-3.x settings that may remain.
|
78 |
+
delete_option( 'wpmembers_msurl' );
|
79 |
+
delete_option( 'wpmembers_regurl' );
|
80 |
+
delete_option( 'wpmembers_logurl' );
|
81 |
+
delete_option( 'wpmembers_cssurl' );
|
82 |
+
delete_option( 'wpmembers_style' );
|
83 |
+
delete_option( 'wpmembers_autoex' );
|
84 |
+
delete_option( 'wpmembers_attrib' );
|
85 |
+
|
86 |
+
// Drop user meta key search table.
|
87 |
+
global $wpdb;
|
88 |
+
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wpmembers_user_search_keys" );
|
89 |
+
}
|
90 |
+
|
91 |
// End of file.
|
wp-members.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: WP-Members
|
4 |
Plugin URI: https://rocketgeek.com
|
5 |
Description: WP access restriction and user registration. For more information on plugin features, refer to <a href="https://rocketgeek.com/plugins/wp-members/users-guide/">the online Users Guide</a>. A <a href="https://rocketgeek.com/plugins/wp-members/quick-start-guide/">Quick Start Guide</a> is also available. WP-Members(tm) is a trademark of butlerblog.com.
|
6 |
-
Version: 3.3.
|
7 |
Author: Chad Butler
|
8 |
Author URI: http://butlerblog.com/
|
9 |
Text Domain: wp-members
|
@@ -12,7 +12,7 @@ License: GPLv2
|
|
12 |
*/
|
13 |
|
14 |
/*
|
15 |
-
Copyright (c) 2006-
|
16 |
|
17 |
The name WP-Members(tm) is a trademark of butlerblog.com
|
18 |
|
@@ -64,7 +64,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
64 |
}
|
65 |
|
66 |
// Initialize constants.
|
67 |
-
define( 'WPMEM_VERSION', '3.3.
|
68 |
define( 'WPMEM_DB_VERSION', '2.2.0' );
|
69 |
define( 'WPMEM_PATH', plugin_dir_path( __FILE__ ) );
|
70 |
|
3 |
Plugin Name: WP-Members
|
4 |
Plugin URI: https://rocketgeek.com
|
5 |
Description: WP access restriction and user registration. For more information on plugin features, refer to <a href="https://rocketgeek.com/plugins/wp-members/users-guide/">the online Users Guide</a>. A <a href="https://rocketgeek.com/plugins/wp-members/quick-start-guide/">Quick Start Guide</a> is also available. WP-Members(tm) is a trademark of butlerblog.com.
|
6 |
+
Version: 3.3.2.2
|
7 |
Author: Chad Butler
|
8 |
Author URI: http://butlerblog.com/
|
9 |
Text Domain: wp-members
|
12 |
*/
|
13 |
|
14 |
/*
|
15 |
+
Copyright (c) 2006-2020 Chad Butler
|
16 |
|
17 |
The name WP-Members(tm) is a trademark of butlerblog.com
|
18 |
|
64 |
}
|
65 |
|
66 |
// Initialize constants.
|
67 |
+
define( 'WPMEM_VERSION', '3.3.2.2' );
|
68 |
define( 'WPMEM_DB_VERSION', '2.2.0' );
|
69 |
define( 'WPMEM_PATH', plugin_dir_path( __FILE__ ) );
|
70 |
|