WP-Members Membership Plugin - Version 3.4.0

Version Description

Here is a list of changes in 3.4.0, but for a more detailed look at the impact of some of these items, be sure to review https://rocketgeek.com/release-announcements/wp-members-3-4-0-wow/

  • Rebuilds the login widget functions so there are filter hooks that more closely mimic the main body login filters. Every attempt was made to provide an HTML result that is the same as previous versions, as well as providing support for legacy dialog tags.
  • Rebuilt and revised user export functionality. Now includes an api function that can be used to customize user exports for a variety of uses.

New Feature Settings: * The default password reset process is now the reset link. New installs will automatically have this setting. Existing installs can change to this by toggling the setting to use the legacy option in Settings > WP-Members > Options > New Features. * The default new registration process now uses the email confirmation link. A user must confirm their email address prior to their account being able to log in. New installs will automatically have this setting, but you may opt to use the legacy option by changing the setting in Settings > WP-Members > Options > New Features. * The default emails at install reflect the above changes. Existing installs as always will not have their email content altered by the upgrade script.

  • Post restricted message now completely separate from login form.
  • Post restricted message now has new wrapper id - #wpmem_restricted_msg

  • Improved redirect_to handling in login and register forms. Can now specify a page by slug alone in the shortcode param for portability.

  • Improved Google reCAPTCHA v3 ("invisible captcha") to optionally display on all pages (recommended by Google to improve user "score").

  • Improved forms display in Customizer, now can view forms on blocked content (not just shortcode pages).

  • Improved functionality of hidden posts. Now saved in WP settings (options) instead of as a transient.

  • Improved user count transient. Now expires in 5 minutes instead of 30 seconds (will result in fewer loads of the query).

  • Membership products now support hierarchy. This can be used for "levels" or for multiple expiration periods yet still only have to assign one membership to content for all child memberships.

  • HTML email for WP-Members emails can be enabled as an option in the Emails tab.

  • Login failed dialog now displays login form below the error. Removed "continue" (return) link from default message.

  • Login failed dialog (#wpmem_msg) text centered in stylesheet instead of applying in the div tag. Best way to customize is using the WP Customizer.

  • Updates to export function.

    • deprecated 'export_fields', use 'fields' instead.
  • Clone menus is deprecated. The setting remains in place for users who have it enabled. But if it is not enabled, the setting is no longer available.

  • Expands Customizer functionality so logged out forms show on blocked content (not just shortcodes).

  • Adds integration for WP's "registration_errors" filter hook, allowing for standarized custom validation and integration with other plugins.

New API functions: * wpmem_is_reg_form_showing()

Deprecated functions: * wpmem_inc_loginfailed() * wpmem_inc_regmessage() * wpmem_inc_login() * wpmem_page_pwd_reset() * wpmem_page_user_edit() * wpmem_page_forgot_username() * wpmem_inc_memberlinks() * wpmem_gettext() - use wpmem_get_text() instead. * $wpmem->texturize()

Bug fixes: * Fixes a bug in the signon process that causes the "rememberme" option to be ignored. * Fixes a bug in wpmem_is_blocked() that returns false when checking a specific post ID. * Fixes a bug in the autoexcerpt function that caused a double "read more" link when excerpt length was set to zero.

Download this release

Release Info

Developer cbutlerjr
Plugin Icon 128x128 WP-Members Membership Plugin
Version 3.4.0
Comparing to
See all releases

Code changes from version 3.3.8 to 3.4.0

Files changed (48) hide show
  1. README.md +24 -0
  2. assets/css/admin.css +140 -132
  3. assets/css/admin.min.css +1 -1
  4. assets/css/forms/generic-no-float.css +16 -16
  5. assets/css/forms/generic-no-float.min.css +1 -1
  6. assets/css/forms/generic-rigid.css +2 -2
  7. assets/css/forms/wp-members-styles.css +2 -2
  8. assets/js/admin.js +257 -227
  9. assets/js/admin.min.js +1 -1
  10. changelog.txt +181 -3
  11. includes/admin/admin.php +2 -17
  12. includes/admin/api.php +118 -118
  13. includes/admin/class-wp-members-admin-api.php +29 -73
  14. includes/admin/class-wp-members-admin-users.php +620 -600
  15. includes/admin/class-wp-members-export.php +0 -219
  16. includes/admin/class-wp-members-products-admin.php +176 -56
  17. includes/admin/class-wp-members-user-export.php +297 -0
  18. includes/admin/dialogs.php +5 -5
  19. includes/admin/tabs/class-wp-members-admin-tab-captcha.php +320 -319
  20. includes/admin/tabs/class-wp-members-admin-tab-dialogs.php +3 -3
  21. includes/admin/tabs/class-wp-members-admin-tab-dropins.php +2 -2
  22. includes/admin/tabs/class-wp-members-admin-tab-emails.php +74 -10
  23. includes/admin/tabs/class-wp-members-admin-tab-fields.php +773 -762
  24. includes/admin/tabs/class-wp-members-admin-tab-options.php +685 -690
  25. includes/admin/tabs/class-wp-members-dropins-table.php +2 -2
  26. includes/admin/tabs/class-wp-members-fields-table.php +167 -167
  27. includes/api/api-email.php +25 -6
  28. includes/api/api-forms.php +633 -581
  29. includes/api/api-products.php +64 -41
  30. includes/api/api-users.php +970 -942
  31. includes/api/api-utilities.php +56 -92
  32. includes/api/api.php +124 -51
  33. includes/class-wp-members-captcha.php +19 -10
  34. includes/class-wp-members-clone-menus.php +3 -23
  35. includes/class-wp-members-dialogs.php +398 -0
  36. includes/class-wp-members-email.php +66 -32
  37. includes/class-wp-members-forms.php +2180 -2128
  38. includes/class-wp-members-products.php +540 -526
  39. includes/class-wp-members-pwd-reset.php +301 -288
  40. includes/class-wp-members-shortcodes.php +486 -173
  41. includes/class-wp-members-user-profile.php +611 -609
  42. includes/class-wp-members-user.php +1228 -1176
  43. includes/class-wp-members-validation-link.php +385 -349
  44. includes/class-wp-members-widget.php +145 -31
  45. includes/class-wp-members.php +1790 -2128
  46. includes/cli/class-wp-members-cli-settings.php +309 -309
  47. includes/cli/class-wp-members-cli-user.php +16 -3
  48. includes/deprecated.php +110 -13
README.md ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # WP-Members #
2
+
3
+ WP-Members™ is a free membership management framework for WordPress® that restricts content to registered users.
4
+
5
+ ## Description ##
6
+
7
+ This is the development repository for the WP-Members plugin for WordPress.
8
+
9
+ ## Usage Information ##
10
+
11
+ Keep in mind that the branch here is a development branch, so it should be tested prior to loading to a production site. Although every effort is made to only load stable updates to this repo, this may not necessarily be production ready and some features may be subject to change prior to release.
12
+
13
+ If you need a production ready version of the plugin, use the version hosted here:
14
+ https://wordpress.org/plugins/wp-members/
15
+
16
+ ## Bug Reporting and Pull Requests ##
17
+
18
+ I do accept pull requests. However, I have a pretty strict standard on what goes into the production version of the plugin. So please make sure that your pull request actually makes sense and is a proper pull request. Also make sure that your code follows WP's code standards for both PHP and inline documentation.
19
+
20
+ Make sure any bug reports are actually bugs. A bug is *not* a feature that you wish to operate differently than it currently does in the plugin. A bug is something broken. Unfortunately, I get a lot of bug reports that are essentially feature requests or a user's inability to follow setup instructions. I wish I didn't have to say that, but I do.
21
+
22
+ ## Feature Requests ##
23
+
24
+ I am open to feature requests. However, I have a roadmap in place for the plugin so it ultimately needs to make sense for that. Consider Matt Mullenweg's vision for options in WordPress, which essentially boils down to the fact that too many options make the interface more confusing. Something that is better handled as a customization (through actions and filters) will likely be addressed that way (as it should be) rather than being incorporated into the plugin; but if your idea is a good one, don't hold it back just because you're not sure. All I'm saying is don't have hurt feelings if I see it differently.
assets/css/admin.css CHANGED
@@ -1,133 +1,141 @@
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
- }
119
-
120
- #wpmem_product_fixed_period_select label,
121
- #wpmem_product_fixed_period_select input,
122
- #wpmem_product_no_gap,
123
- #wpmem_product_fixed_period {
124
- margin-top: 10px;
125
- margin-left: 24px;
126
- }
127
-
128
- #updatesettings a {
129
- text-decoration:none;
130
- }
131
- updatesettings a:hover {
132
- color: black;
 
 
 
 
 
 
 
 
133
  }
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-2021 Chad Butler
9
+ * WP-Members(tm) is a trademark of butlerblog.com
10
+ *
11
+ * @package WP-Members
12
+ * @author Chad Butler
13
+ * @copyright 2006-2021
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
+ }
119
+
120
+ #wpmem_product_fixed_period_select label,
121
+ #wpmem_product_fixed_period_select input,
122
+ #wpmem_product_no_gap,
123
+ #wpmem_product_fixed_period {
124
+ margin-top: 10px;
125
+ margin-left: 24px;
126
+ }
127
+
128
+ #updatesettings a {
129
+ text-decoration:none;
130
+ }
131
+ updatesettings a:hover {
132
+ color: black;
133
+ }
134
+
135
+ #createuser .form-field input[type="checkbox"] {
136
+ width: initial;
137
+ }
138
+
139
+ .wpmem-user-table-membership {
140
+ border-bottom:1px solid #999;
141
  }
assets/css/admin.min.css CHANGED
@@ -1 +1 @@
1
- .wpmem_tbl_drag{background:#fffbcc;font-weight:700;border:1px solid #900}.column-wpmem_block{width:80px}#addfieldform li,#editfieldform li,#updatesettings li{padding:5px 0}#addfieldform label,#editfieldform label,#updatesettings label{float:left;width:166px;clear:both;display:block}#addfieldform .add-field-indent,#editfieldform .add-field-indent{margin-left:165px}#add_field_postbox,#fields_postbox{min-width:950px}.req{color:red}#the-list{cursor:move}#edit,#sort{width:30px}#wpmem_block input{vertical-align:-webkit-baseline-middle;margin:0 0 8px 0}#wpmem_block label{margin:0 0 0 8px}#wpmem_ok_block_status{margin:5px 0 0 0}#wpmem_post_block_status{font-weight:600}#wpmem_post_icon_0{color:red}#wpmem_post_icon_1{color:green}#wpmem_post_icon_2{color:#000}#wpmem_product_enabled{color:green}#_wpmem_products,#s2id__wpmem_products,.select2-search-field{width:100%}#wpmem_user_profile_tabs{padding:0;background:0 0;border-width:0}#wpmem_user_profile_tabs .ui-tabs-nav{padding-left:0;background:0 0;border-width:0 0 1px 0;-moz-border-radius:0;-webkit-border-radius:0;border-radius:0}#wpmem_user_profile_tabs .ui-tabs-panel{background:#fff;border-width:0 1px 1px 1px}#wpmem_user_profile_tabs .ui-state-active{border:1px solid #006799;background:#008ec2}#wpmem_user_profile_tabs .ui-state-active a{color:#fff}#wpmem_product_fixed_period,#wpmem_product_fixed_period_select input,#wpmem_product_fixed_period_select label,#wpmem_product_no_gap{margin-top:10px;margin-left:24px}#updatesettings a{text-decoration:none}updatesettings a:hover{color:#000}
1
+ .wpmem_tbl_drag{background:#fffbcc;font-weight:700;border:1px solid #900}.column-wpmem_block{width:80px}#addfieldform li,#editfieldform li,#updatesettings li{padding:5px 0}#addfieldform label,#editfieldform label,#updatesettings label{float:left;width:166px;clear:both;display:block}#addfieldform .add-field-indent,#editfieldform .add-field-indent{margin-left:165px}#add_field_postbox,#fields_postbox{min-width:950px}.req{color:red}#the-list{cursor:move}#edit,#sort{width:30px}#wpmem_block input{vertical-align:-webkit-baseline-middle;margin:0 0 8px 0}#wpmem_block label{margin:0 0 0 8px}#wpmem_ok_block_status{margin:5px 0 0 0}#wpmem_post_block_status{font-weight:600}#wpmem_post_icon_0{color:red}#wpmem_post_icon_1{color:green}#wpmem_post_icon_2{color:#000}#wpmem_product_enabled{color:green}#_wpmem_products,#s2id__wpmem_products,.select2-search-field{width:100%}#wpmem_user_profile_tabs{padding:0;background:0 0;border-width:0}#wpmem_user_profile_tabs .ui-tabs-nav{padding-left:0;background:0 0;border-width:0 0 1px 0;-moz-border-radius:0;-webkit-border-radius:0;border-radius:0}#wpmem_user_profile_tabs .ui-tabs-panel{background:#fff;border-width:0 1px 1px 1px}#wpmem_user_profile_tabs .ui-state-active{border:1px solid #006799;background:#008ec2}#wpmem_user_profile_tabs .ui-state-active a{color:#fff}#wpmem_product_fixed_period,#wpmem_product_fixed_period_select input,#wpmem_product_fixed_period_select label,#wpmem_product_no_gap{margin-top:10px;margin-left:24px}#updatesettings a{text-decoration:none}updatesettings a:hover{color:#000}#createuser .form-field input[type="checkbox"]{width: initial;}.wpmem-user-table-membership {border-bottom:1px solid #999;}
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-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
  /*
@@ -27,23 +27,25 @@ For information how to load custom stylesheets with wp_enqueue_style,
27
  see https://rocketgeek.com/tips-and-tricks/load-a-custom-stylesheet/
28
  */
29
 
30
-
31
  /* Error and Dialog Messages */
32
 
33
  #wpmem_msg,
34
  .wpmem_msg {
 
35
  background: #F9F9F9;
36
  border:1px solid lightGrey;
37
  border-radius: 3px;
38
- padding: 20px 0 0 0;
39
- }
40
- #wpmem_msg {
41
- width: 100%;
42
- }
43
- .wpmem_msg {
44
- width: 74%;
45
  }
46
 
 
 
 
 
 
 
 
47
 
48
  /* Sidebar Login Widget */
49
 
@@ -76,8 +78,8 @@ see https://rocketgeek.com/tips-and-tricks/load-a-custom-stylesheet/
76
  border-radius: 3px;
77
  }
78
 
79
-
80
  /* Login Form and Registration Form */
 
81
  #wpmem_reg,
82
  #wpmem_login {
83
  color: rgb(43, 43, 43);
@@ -135,6 +137,7 @@ see https://rocketgeek.com/tips-and-tricks/load-a-custom-stylesheet/
135
  border-radius: 2px;
136
  color: rgb(43, 43, 43);
137
  margin: 5px 0;
 
138
  }
139
 
140
  #wpmem_reg fieldset,
@@ -177,8 +180,8 @@ see https://rocketgeek.com/tips-and-tricks/load-a-custom-stylesheet/
177
  #wpmem_reg .div_file,
178
  #wpmem_reg .div_url,
179
  #wpmem_reg .div_number,
180
- #wpmem_reg .div_date {
181
- width:74%;
182
  margin:0 0 14px 0;
183
  }
184
  #wpmem_login input[type="checkbox"] {
@@ -220,7 +223,6 @@ see https://rocketgeek.com/tips-and-tricks/load-a-custom-stylesheet/
220
  }
221
 
222
  #wpmem_reg .captcha {
223
- width: 74%;
224
  margin: 5px 0px;
225
  }
226
  #wpmem_reg .captcha table{
@@ -228,7 +230,6 @@ see https://rocketgeek.com/tips-and-tricks/load-a-custom-stylesheet/
228
  }
229
  #wpmem_login .link-text {
230
  padding: 4px 0;
231
- width: 74%;
232
  text-align:right;
233
  }
234
 
@@ -240,7 +241,6 @@ see https://rocketgeek.com/tips-and-tricks/load-a-custom-stylesheet/
240
  /* Buttons */
241
 
242
  #wpmem_reg .button_div, #wpmem_login .button_div {
243
- width:74%;
244
  /* height:55px; */
245
  padding: 6px 0;
246
  text-align: right;
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-2021 Chad Butler
9
  * WP-Members(tm) is a trademark of butlerblog.com
10
  *
11
  * @package WP-Members
12
  * @author Chad Butler
13
+ * @copyright 2006-2021
14
  */
15
 
16
  /*
27
  see https://rocketgeek.com/tips-and-tricks/load-a-custom-stylesheet/
28
  */
29
 
 
30
  /* Error and Dialog Messages */
31
 
32
  #wpmem_msg,
33
  .wpmem_msg {
34
+ text-align: center;
35
  background: #F9F9F9;
36
  border:1px solid lightGrey;
37
  border-radius: 3px;
38
+ padding: 20px 0;
39
+ margin: 15px 0;
 
 
 
 
 
40
  }
41
 
42
+ /* Messages and forms should (ideally) be the same width */
43
+ #wpmem_msg,
44
+ .wpmem_msg,
45
+ #wpmem_reg,
46
+ #wpmem_login {
47
+ width: 75%;
48
+ }
49
 
50
  /* Sidebar Login Widget */
51
 
78
  border-radius: 3px;
79
  }
80
 
 
81
  /* Login Form and Registration Form */
82
+
83
  #wpmem_reg,
84
  #wpmem_login {
85
  color: rgb(43, 43, 43);
137
  border-radius: 2px;
138
  color: rgb(43, 43, 43);
139
  margin: 5px 0;
140
+ background: none repeat scroll 0% 0% #fff;
141
  }
142
 
143
  #wpmem_reg fieldset,
180
  #wpmem_reg .div_file,
181
  #wpmem_reg .div_url,
182
  #wpmem_reg .div_number,
183
+ #wpmem_reg .div_date,
184
+ #wpmem_reg .div_membership {
185
  margin:0 0 14px 0;
186
  }
187
  #wpmem_login input[type="checkbox"] {
223
  }
224
 
225
  #wpmem_reg .captcha {
 
226
  margin: 5px 0px;
227
  }
228
  #wpmem_reg .captcha table{
230
  }
231
  #wpmem_login .link-text {
232
  padding: 4px 0;
 
233
  text-align:right;
234
  }
235
 
241
  /* Buttons */
242
 
243
  #wpmem_reg .button_div, #wpmem_login .button_div {
 
244
  /* height:55px; */
245
  padding: 6px 0;
246
  text-align: right;
assets/css/forms/generic-no-float.min.css CHANGED
@@ -1 +1 @@
1
- #wpmem_msg,.wpmem_msg{background:#f9f9f9;border:1px solid #d3d3d3;border-radius:3px;padding:20px 0 0 0}#wpmem_msg{width:100%}.wpmem_msg{width:74%}#wp-members{width:100%}#wp-members fieldset{border:none;padding:0}#wp-members input{font-family:inherit}#wp-members input[type=password],#wp-members input[type=text]{margin:0 0 4px 0}#wp-members input[type=submit]{padding:5px 6px 4px;margin:0 4px 0 0}#wp-members .button_div{margin-top:4px}#wp-members .err{width:100%;padding:5px;font-family:inherit;border:1px solid #ccc;border-radius:3px}#wpmem_login,#wpmem_reg{color:#2b2b2b;font-family:Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.5}#wpmem_login label,#wpmem_reg label{display:initial}#wpmem_login input[type=password],#wpmem_login input[type=text],#wpmem_reg input[type=date],#wpmem_reg input[type=email],#wpmem_reg input[type=number],#wpmem_reg input[type=password],#wpmem_reg input[type=text],#wpmem_reg input[type=url],#wpmem_reg textarea{border:1px solid rgba(0,0,0,.1);border-radius:2px;color:#2b2b2b;padding:8px 10px 8px;background:none repeat scroll 0 0 #fff}#wpmem_login button,#wpmem_login input,#wpmem_reg button,#wpmem_reg input,#wpmem_reg select,#wpmem_reg textarea{-moz-box-sizing:border-box;font-size:100%;margin:0;max-width:100%;vertical-align:baseline}#wpmem_login input:focus,#wpmem_reg input:focus,#wpmem_reg textarea:focus{border:1px solid rgba(0,0,0,.3);outline:0 none}#wpmem_reg select{width:100%;padding:8px 10px 7px;border:1px solid rgba(0,0,0,.1);border-radius:2px;color:#2b2b2b;margin:5px 0}#wpmem_login fieldset,#wpmem_reg fieldset{border:none;padding:0;margin:40px 0}#wpmem_login legend,#wpmem_reg legend{font-size:24px;line-height:1;font-weight:700;margin-bottom:10px;width:100%}#wpmem_login .form,#wpmem_reg .form{margin:0;padding:0}#wpmem_login .clear,#wpmem_reg .clear{clear:both}#wpmem_login .holder,#wpmem_reg .holder{background-color:#fff}#wpmem_login .div_text,#wpmem_reg .div_checkbox,#wpmem_reg .div_date,#wpmem_reg .div_file,#wpmem_reg .div_image,#wpmem_reg .div_multicheckbox,#wpmem_reg .div_multiselect,#wpmem_reg .div_number,#wpmem_reg .div_radio,#wpmem_reg .div_select,#wpmem_reg .div_text,#wpmem_reg .div_textarea,#wpmem_reg .div_url{width:74%;margin:0 0 14px 0}#wpmem_login input[type=checkbox]{margin:12px 2px}#wpmem_login .password,#wpmem_login .textbox,#wpmem_login .username,#wpmem_reg .div_textarea textarea,#wpmem_reg .file,#wpmem_reg .image,#wpmem_reg .password,#wpmem_reg .textbox,#wpmem_reg .username{width:100%}#wpmem_reg textarea{height:185px}#wpmem_reg .req{color:#bd3500;font-size:22px;line-height:50%}#wpmem_reg .req-text{margin:20px 0 0 5px}#wpmem_reg .noinput{width:93%;padding:8px 10px 7px;border:1px solid rgba(0,0,0,.1);border-radius:2px;color:#2b2b2b;margin:5px 0}#wpmem_reg .captcha{width:74%;margin:5px 0}#wpmem_reg .captcha table{line-height:0}#wpmem_login .link-text{padding:4px 0;width:74%;text-align:right}#tos{margin-right:5px}#wpmem_login .button_div,#wpmem_reg .button_div{width:74%;padding:6px 0;text-align:right}@media screen and (max-width:720px){#wpmem_login .button_div,#wpmem_login .div_text,#wpmem_login label,#wpmem_reg .button_div,#wpmem_reg .div_checkbox,#wpmem_reg .div_select,#wpmem_reg .div_text,#wpmem_reg .div_textarea,#wpmem_reg label.checkbox,#wpmem_reg label.select,#wpmem_reg label.text,#wpmem_reg label.textarea{float:none}#wpmem_reg label.checkbox,#wpmem_reg label.select,#wpmem_reg label.text,#wpmem_reg label.textarea{width:90%;padding:5px 0 0 0}#wpmem_reg label.textarea{height:26px}#wpmem_login .div_text,#wpmem_reg .div_checkbox,#wpmem_reg .div_select,#wpmem_reg .div_text,#wpmem_reg .div_textarea{width:98%}#wpmem_msg,.wpmem_msg{width:100%}#wpmem_login .button_div,#wpmem_login .link-text,#wpmem_reg .button_div{width:98%}}
1
+ #wpmem_msg,.wpmem_msg{text-align:center;background:#f9f9f9;border:1px solid #d3d3d3;border-radius:3px;padding:20px 0;margin:15px 0;}#wpmem_login,#wpmem_msg,#wpmem_reg,.wpmem_msg{width:75%}#wp-members{width:100%}#wp-members fieldset{border:none;padding:0}#wp-members input{font-family:inherit}#wp-members input[type=password],#wp-members input[type=text]{margin:0 0 4px 0}#wp-members input[type=submit]{padding:5px 6px 4px;margin:0 4px 0 0}#wp-members .button_div{margin-top:4px}#wp-members .err{width:100%;padding:5px;font-family:inherit;border:1px solid #ccc;border-radius:3px}#wpmem_login,#wpmem_reg{color:#2b2b2b;font-family:Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.5}#wpmem_login label,#wpmem_reg label{display:initial}#wpmem_login input[type=password],#wpmem_login input[type=text],#wpmem_reg input[type=date],#wpmem_reg input[type=email],#wpmem_reg input[type=number],#wpmem_reg input[type=password],#wpmem_reg input[type=text],#wpmem_reg input[type=url],#wpmem_reg textarea{border:1px solid rgba(0,0,0,.1);border-radius:2px;color:#2b2b2b;padding:8px 10px 8px;background:none repeat scroll 0 0 #fff}#wpmem_login button,#wpmem_login input,#wpmem_reg button,#wpmem_reg input,#wpmem_reg select,#wpmem_reg textarea{-moz-box-sizing:border-box;font-size:100%;margin:0;max-width:100%;vertical-align:baseline}#wpmem_login input:focus,#wpmem_reg input:focus,#wpmem_reg textarea:focus{border:1px solid rgba(0,0,0,.3);outline:0 none}#wpmem_reg select{width:100%;padding:8px 10px 7px;border:1px solid rgba(0,0,0,.1);border-radius:2px;color:#2b2b2b;margin:5px 0;background:none repeat scroll 0 0 #fff}#wpmem_login fieldset,#wpmem_reg fieldset{border:none;padding:0;margin:40px 0}#wpmem_login legend,#wpmem_reg legend{font-size:24px;line-height:1;font-weight:700;margin-bottom:10px;width:100%}#wpmem_login .form,#wpmem_reg .form{margin:0;padding:0}#wpmem_login .clear,#wpmem_reg .clear{clear:both}#wpmem_login .holder,#wpmem_reg .holder{background-color:#fff}#wpmem_login .div_text,#wpmem_reg .div_checkbox,#wpmem_reg .div_date,#wpmem_reg .div_file,#wpmem_reg .div_image,#wpmem_reg .div_membership,#wpmem_reg .div_multicheckbox,#wpmem_reg .div_multiselect,#wpmem_reg .div_number,#wpmem_reg .div_radio,#wpmem_reg .div_select,#wpmem_reg .div_text,#wpmem_reg .div_textarea,#wpmem_reg .div_url{margin:0 0 14px 0}#wpmem_login input[type=checkbox]{margin:12px 2px}#wpmem_login .password,#wpmem_login .textbox,#wpmem_login .username,#wpmem_reg .div_textarea textarea,#wpmem_reg .file,#wpmem_reg .image,#wpmem_reg .password,#wpmem_reg .textbox,#wpmem_reg .username{width:100%}#wpmem_reg textarea{height:185px}#wpmem_reg .req{color:#bd3500;font-size:22px;line-height:50%}#wpmem_reg .req-text{margin:20px 0 0 5px}#wpmem_reg .noinput{width:93%;padding:8px 10px 7px;border:1px solid rgba(0,0,0,.1);border-radius:2px;color:#2b2b2b;margin:5px 0}#wpmem_reg .captcha{margin:5px 0}#wpmem_reg .captcha table{line-height:0}#wpmem_login .link-text{padding:4px 0;text-align:right}#tos{margin-right:5px}#wpmem_login .button_div,#wpmem_reg .button_div{padding:6px 0;text-align:right}@media screen and (max-width:720px){#wpmem_login .button_div,#wpmem_login .div_text,#wpmem_login label,#wpmem_reg .button_div,#wpmem_reg .div_checkbox,#wpmem_reg .div_select,#wpmem_reg .div_text,#wpmem_reg .div_textarea,#wpmem_reg label.checkbox,#wpmem_reg label.select,#wpmem_reg label.text,#wpmem_reg label.textarea{float:none}#wpmem_reg label.checkbox,#wpmem_reg label.select,#wpmem_reg label.text,#wpmem_reg label.textarea{width:90%;padding:5px 0 0 0}#wpmem_reg label.textarea{height:26px}#wpmem_login .div_text,#wpmem_reg .div_checkbox,#wpmem_reg .div_select,#wpmem_reg .div_text,#wpmem_reg .div_textarea{width:98%}#wpmem_msg,.wpmem_msg{width:100%}#wpmem_login .button_div,#wpmem_login .link-text,#wpmem_reg .button_div{width:98%}}
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-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
  /*
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-2021 Chad Butler
9
  * WP-Members(tm) is a trademark of butlerblog.com
10
  *
11
  * @package WP-Members
12
  * @author Chad Butler
13
+ * @copyright 2006-2021
14
  */
15
 
16
  /*
assets/css/forms/wp-members-styles.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-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
  /*
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-2021 Chad Butler
9
  * WP-Members(tm) is a trademark of butlerblog.com
10
  *
11
  * @package WP-Members
12
  * @author Chad Butler
13
+ * @copyright 2006-2021
14
  */
15
 
16
  /*
assets/js/admin.js CHANGED
@@ -1,227 +1,257 @@
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() == 'date' ) {
131
- $("#wpmem_pattern").show();
132
- $("#wpmem_title").show();
133
- } else {
134
- $("#wpmem_pattern").hide();
135
- $("#wpmem_title").hide();
136
- }
137
- if ($("#wpmem_field_type_select").val() == 'textarea' ) {
138
- $("#wpmem_allowhtml").show();
139
- $("#wpmem_rows_cols").show();
140
- } else {
141
- $("#wpmem_allowhtml").hide();
142
- $("#wpmem_rows_cols").hide();
143
- }
144
- if ($("#wpmem_field_type_select").val() == 'number' || $("#wpmem_field_type_select").val() == 'date' )
145
- $("#wpmem_min_max").show();
146
- else
147
- $("#wpmem_min_max").hide();
148
- if ($("#wpmem_field_type_select").val() == 'checkbox') {
149
- $("#wpmem_checkbox_info").show();
150
- $("#add_checked_value").prop('required',true);
151
- } else {
152
- $("#wpmem_checkbox_info").hide();
153
- $("#add_checked_value").prop('required',false);
154
- }
155
- if ( $("#wpmem_field_type_select").val() == 'select'
156
- || $("#wpmem_field_type_select").val() == 'multiselect'
157
- || $("#wpmem_field_type_select").val() == 'radio'
158
- || $("#wpmem_field_type_select").val() == 'multicheckbox'
159
- ) {
160
- $("#wpmem_dropdown_info").show();
161
- $("#add_dropdown_value").prop('required',true);
162
- } else {
163
- $("#wpmem_dropdown_info").hide();
164
- $("#add_dropdown_value").prop('required',false);
165
- }
166
- if ( $("#wpmem_field_type_select").val() == 'multiselect' || $("#wpmem_field_type_select").val() == 'multicheckbox'
167
- )
168
- $("#wpmem_delimiter_info").show();
169
- else
170
- $("#wpmem_delimiter_info").hide();
171
- if ($("#wpmem_field_type_select").val() == 'file' || $("#wpmem_field_type_select").val() == 'image' )
172
- $("#wpmem_file_info").show();
173
- else
174
- $("#wpmem_file_info").hide();
175
- if ($("#wpmem_field_type_select").val() == 'hidden') {
176
- $("#wpmem_hidden_info").show();
177
- $("#add_hidden_value").prop('required',true);
178
- } else {
179
- $("#wpmem_hidden_info").hide();
180
- $("#add_hidden_value").prop('required',false);
181
- }
182
- });
183
- });
184
- })(jQuery);
185
-
186
- /**
187
- * JS for post block status meta box
188
- *
189
- * @since 3.2.1
190
- */
191
- (function($) {
192
- $(document).ready(function() {
193
- $("#wpmem_block").hide();
194
- });
195
- $(document).ready(function() {
196
- $("#wpmem_edit_block_status").click(function() {
197
- $("#wpmem_block").show('normal');
198
- $("#wpmem_edit_block_status").hide();
199
- });
200
- $("#wpmem_cancel_block_status").click(function() {
201
- $("#wpmem_block").hide('normal');
202
- $("#wpmem_edit_block_status").show();
203
- $("#wpmem_post_block_status").text($("input[name=wpmem_block_original_label]").val());
204
- $('#wpmem_post_block_status_' + $('input[name=wpmem_block_original_value]')).val().prop("checked", true);
205
- });
206
- $("#wpmem_ok_block_status").click(function() {
207
- $("#wpmem_block").hide('normal');
208
- $("#wpmem_edit_block_status").show();
209
- $("#wpmem_post_block_status").text($("input[name=wpmem_block]:checked + label").text());
210
- if($('#wpmem_block_status_0').is(':checked')) {
211
- $("#wpmem_post_icon_0").show();
212
- $("#wpmem_post_icon_1").hide();
213
- $("#wpmem_post_icon_2").hide();
214
- }
215
- if($('#wpmem_block_status_1').is(':checked')) {
216
- $("#wpmem_post_icon_0").hide();
217
- $("#wpmem_post_icon_1").show();
218
- $("#wpmem_post_icon_2").hide();
219
- }
220
- if($('#wpmem_block_status_2').is(':checked')) {
221
- $("#wpmem_post_icon_0").hide();
222
- $("#wpmem_post_icon_1").hide();
223
- $("#wpmem_post_icon_2").show();
224
- }
225
- });
226
- });
227
- })(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-2021 Chad Butler
9
+ * WP-Members(tm) is a trademark of butlerblog.com
10
+ *
11
+ * @package WP-Members
12
+ * @author Chad Butler
13
+ * @copyright 2006-2021
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() == 'date' ) {
131
+ $("#wpmem_pattern").show();
132
+ $("#wpmem_title").show();
133
+ } else {
134
+ $("#wpmem_pattern").hide();
135
+ $("#wpmem_title").hide();
136
+ }
137
+ if ($("#wpmem_field_type_select").val() == 'textarea' ) {
138
+ $("#wpmem_allowhtml").show();
139
+ $("#wpmem_rows_cols").show();
140
+ } else {
141
+ $("#wpmem_allowhtml").hide();
142
+ $("#wpmem_rows_cols").hide();
143
+ }
144
+ if ($("#wpmem_field_type_select").val() == 'number' || $("#wpmem_field_type_select").val() == 'date' )
145
+ $("#wpmem_min_max").show();
146
+ else
147
+ $("#wpmem_min_max").hide();
148
+ if ($("#wpmem_field_type_select").val() == 'checkbox') {
149
+ $("#wpmem_checkbox_info").show();
150
+ $("#add_checked_value").prop('required',true);
151
+ } else {
152
+ $("#wpmem_checkbox_info").hide();
153
+ $("#add_checked_value").prop('required',false);
154
+ }
155
+ if ( $("#wpmem_field_type_select").val() == 'select'
156
+ || $("#wpmem_field_type_select").val() == 'multiselect'
157
+ || $("#wpmem_field_type_select").val() == 'radio'
158
+ || $("#wpmem_field_type_select").val() == 'multicheckbox'
159
+ ) {
160
+ $("#wpmem_dropdown_info").show();
161
+ $("#add_dropdown_value").prop('required',true);
162
+ } else {
163
+ $("#wpmem_dropdown_info").hide();
164
+ $("#add_dropdown_value").prop('required',false);
165
+ }
166
+ if ( $("#wpmem_field_type_select").val() == 'multiselect' || $("#wpmem_field_type_select").val() == 'multicheckbox'
167
+ )
168
+ $("#wpmem_delimiter_info").show();
169
+ else
170
+ $("#wpmem_delimiter_info").hide();
171
+ if ($("#wpmem_field_type_select").val() == 'file' || $("#wpmem_field_type_select").val() == 'image' )
172
+ $("#wpmem_file_info").show();
173
+ else
174
+ $("#wpmem_file_info").hide();
175
+ if ($("#wpmem_field_type_select").val() == 'hidden') {
176
+ $("#wpmem_hidden_info").show();
177
+ $("#add_hidden_value").prop('required',true);
178
+ } else {
179
+ $("#wpmem_hidden_info").hide();
180
+ $("#add_hidden_value").prop('required',false);
181
+ }
182
+ });
183
+ });
184
+ })(jQuery);
185
+
186
+ /**
187
+ * JS for post block status meta box
188
+ *
189
+ * @since 3.2.1
190
+ */
191
+ (function($) {
192
+ $(document).ready(function() {
193
+ $("#wpmem_block").hide();
194
+ });
195
+ $(document).ready(function() {
196
+ $("#wpmem_edit_block_status").click(function() {
197
+ $("#wpmem_block").show('normal');
198
+ $("#wpmem_edit_block_status").hide();
199
+ });
200
+ $("#wpmem_cancel_block_status").click(function() {
201
+ $("#wpmem_block").hide('normal');
202
+ $("#wpmem_edit_block_status").show();
203
+ $("#wpmem_post_block_status").text($("input[name=wpmem_block_original_label]").val());
204
+ $('#wpmem_post_block_status_' + $('input[name=wpmem_block_original_value]')).val().prop("checked", true);
205
+ });
206
+ $("#wpmem_ok_block_status").click(function() {
207
+ $("#wpmem_block").hide('normal');
208
+ $("#wpmem_edit_block_status").show();
209
+ $("#wpmem_post_block_status").text($("input[name=wpmem_block]:checked + label").text());
210
+ if($('#wpmem_block_status_0').is(':checked')) {
211
+ $("#wpmem_post_icon_0").show();
212
+ $("#wpmem_post_icon_1").hide();
213
+ $("#wpmem_post_icon_2").hide();
214
+ }
215
+ if($('#wpmem_block_status_1').is(':checked')) {
216
+ $("#wpmem_post_icon_0").hide();
217
+ $("#wpmem_post_icon_1").show();
218
+ $("#wpmem_post_icon_2").hide();
219
+ }
220
+ if($('#wpmem_block_status_2').is(':checked')) {
221
+ $("#wpmem_post_icon_0").hide();
222
+ $("#wpmem_post_icon_1").hide();
223
+ $("#wpmem_post_icon_2").show();
224
+ }
225
+ });
226
+ });
227
+ })(jQuery);
228
+
229
+ /**
230
+ * Shows the WP-Members settings.
231
+ */
232
+ (function($) {
233
+ $(document).ready(function($){
234
+ var close_button = wpmem_get_settings_vars.close_btn;
235
+ $("#dialog-message" ).dialog({
236
+ autoOpen: false,
237
+ modal: true,
238
+ height: "auto",
239
+ width: 600,
240
+ buttons: {
241
+ Close : function() {
242
+ $( this ).dialog( "close" );
243
+ }
244
+ }
245
+ });
246
+ $( "#opener" ).on( "click", function() {
247
+ $( "#dialog-message" ).dialog( "open" );
248
+ });
249
+ $("#select_all").click(function(){
250
+ $("textarea").select();
251
+ document.execCommand('copy');
252
+ });
253
+ $(window).resize(function() {
254
+ $("#dialog-message").dialog("option", "position", {my: "center", at: "center", of: window});
255
+ });
256
+ });
257
+ })(jQuery);
assets/js/admin.min.js CHANGED
@@ -1 +1 @@
1
- jQuery(document).ready(function(e){e("#the-list").sortable({items:".list_item",opacity:.6,cursor:"move",axis:"y",update:function(){var m=e(this).sortable("serialize")+"&action=wpmem_do_field_reorder";e.post(ajaxurl,m,function(e){alert(e)}),e(".list_item").each(function(m){e(this).data("id",m+1),e(this).attr("list_item",m+1)})}})}),function(e){e(document).ready(function(){"use_custom"==e("#wpmem_logpage_select").val()?e("#wpmem_logpage_custom").show():e("#wpmem_logpage_custom").hide(),"use_custom"==e("#wpmem_regpage_select").val()?e("#wpmem_regpage_custom").show():e("#wpmem_regpage_custom").hide(),"use_custom"==e("#wpmem_mspage_select").val()?e("#wpmem_mspage_custom").show():e("#wpmem_mspage_custom").hide(),"use_custom"==e("#wpmem_stylesheet_select").val()?e("#wpmem_stylesheet_custom").show():e("#wpmem_stylesheet_custom").hide(),e("#wpmem_logpage_select").change(function(){"use_custom"==e("#wpmem_logpage_select").val()?e("#wpmem_logpage_custom").show():e("#wpmem_logpage_custom").hide()}),e("#wpmem_regpage_select").change(function(){"use_custom"==e("#wpmem_regpage_select").val()?e("#wpmem_regpage_custom").show():e("#wpmem_regpage_custom").hide()}),e("#wpmem_mspage_select").change(function(){"use_custom"==e("#wpmem_mspage_select").val()?e("#wpmem_mspage_custom").show():e("#wpmem_mspage_custom").hide()}),e("#wpmem_stylesheet_select").change(function(){"use_custom"==e("#wpmem_stylesheet_select").val()?e("#wpmem_stylesheet_custom").show():e("#wpmem_stylesheet_custom").hide()})})}(jQuery),function(e){e(document).ready(function(){e("#wpmem_allowhtml").hide(),e("#wpmem_rows_cols").hide(),e("#wpmem_min_max").hide(),e("#wpmem_checkbox_info").hide(),e("#wpmem_dropdown_info").hide(),e("#wpmem_file_info").hide(),e("#wpmem_delimiter_info").hide(),e("#wpmem_hidden_info").hide()}),e(document).ready(function(){e("#wpmem_field_type_select").change(function(){"text"==e("#wpmem_field_type_select").val()||"password"==e("#wpmem_field_type_select").val()||"email"==e("#wpmem_field_type_select").val()||"url"==e("#wpmem_field_type_select").val()||"number"==e("#wpmem_field_type_select").val()||"date"==e("#wpmem_field_type_select").val()||"textarea"==e("#wpmem_field_type_select").val()?e("#wpmem_placeholder").show():e("#wpmem_placeholder").hide(),"text"==e("#wpmem_field_type_select").val()||"password"==e("#wpmem_field_type_select").val()||"email"==e("#wpmem_field_type_select").val()||"url"==e("#wpmem_field_type_select").val()||"date"==e("#wpmem_field_type_select").val()?(e("#wpmem_pattern").show(),e("#wpmem_title").show()):(e("#wpmem_pattern").hide(),e("#wpmem_title").hide()),"textarea"==e("#wpmem_field_type_select").val()?(e("#wpmem_allowhtml").show(),e("#wpmem_rows_cols").show()):(e("#wpmem_allowhtml").hide(),e("#wpmem_rows_cols").hide()),"number"==e("#wpmem_field_type_select").val()||"date"==e("#wpmem_field_type_select").val()?e("#wpmem_min_max").show():e("#wpmem_min_max").hide(),"checkbox"==e("#wpmem_field_type_select").val()?(e("#wpmem_checkbox_info").show(),e("#add_checked_value").prop("required",!0)):(e("#wpmem_checkbox_info").hide(),e("#add_checked_value").prop("required",!1)),"select"==e("#wpmem_field_type_select").val()||"multiselect"==e("#wpmem_field_type_select").val()||"radio"==e("#wpmem_field_type_select").val()||"multicheckbox"==e("#wpmem_field_type_select").val()?(e("#wpmem_dropdown_info").show(),e("#add_dropdown_value").prop("required",!0)):(e("#wpmem_dropdown_info").hide(),e("#add_dropdown_value").prop("required",!1)),"multiselect"==e("#wpmem_field_type_select").val()||"multicheckbox"==e("#wpmem_field_type_select").val()?e("#wpmem_delimiter_info").show():e("#wpmem_delimiter_info").hide(),"file"==e("#wpmem_field_type_select").val()||"image"==e("#wpmem_field_type_select").val()?e("#wpmem_file_info").show():e("#wpmem_file_info").hide(),"hidden"==e("#wpmem_field_type_select").val()?(e("#wpmem_hidden_info").show(),e("#add_hidden_value").prop("required",!0)):(e("#wpmem_hidden_info").hide(),e("#add_hidden_value").prop("required",!1))})})}(jQuery),function(e){e(document).ready(function(){e("#wpmem_block").hide()}),e(document).ready(function(){e("#wpmem_edit_block_status").click(function(){e("#wpmem_block").show("normal"),e("#wpmem_edit_block_status").hide()}),e("#wpmem_cancel_block_status").click(function(){e("#wpmem_block").hide("normal"),e("#wpmem_edit_block_status").show(),e("#wpmem_post_block_status").text(e("input[name=wpmem_block_original_label]").val()),e("#wpmem_post_block_status_"+e("input[name=wpmem_block_original_value]")).val().prop("checked",!0)}),e("#wpmem_ok_block_status").click(function(){e("#wpmem_block").hide("normal"),e("#wpmem_edit_block_status").show(),e("#wpmem_post_block_status").text(e("input[name=wpmem_block]:checked + label").text()),e("#wpmem_block_status_0").is(":checked")&&(e("#wpmem_post_icon_0").show(),e("#wpmem_post_icon_1").hide(),e("#wpmem_post_icon_2").hide()),e("#wpmem_block_status_1").is(":checked")&&(e("#wpmem_post_icon_0").hide(),e("#wpmem_post_icon_1").show(),e("#wpmem_post_icon_2").hide()),e("#wpmem_block_status_2").is(":checked")&&(e("#wpmem_post_icon_0").hide(),e("#wpmem_post_icon_1").hide(),e("#wpmem_post_icon_2").show())})})}(jQuery);
1
+ jQuery(document).ready(function(e){e("#the-list").sortable({items:".list_item",opacity:.6,cursor:"move",axis:"y",update:function(){var m=e(this).sortable("serialize")+"&action=wpmem_do_field_reorder";e.post(ajaxurl,m,function(e){alert(e)}),e(".list_item").each(function(m){e(this).data("id",m+1),e(this).attr("list_item",m+1)})}})}),function(e){e(document).ready(function(){"use_custom"==e("#wpmem_logpage_select").val()?e("#wpmem_logpage_custom").show():e("#wpmem_logpage_custom").hide(),"use_custom"==e("#wpmem_regpage_select").val()?e("#wpmem_regpage_custom").show():e("#wpmem_regpage_custom").hide(),"use_custom"==e("#wpmem_mspage_select").val()?e("#wpmem_mspage_custom").show():e("#wpmem_mspage_custom").hide(),"use_custom"==e("#wpmem_stylesheet_select").val()?e("#wpmem_stylesheet_custom").show():e("#wpmem_stylesheet_custom").hide(),e("#wpmem_logpage_select").change(function(){"use_custom"==e("#wpmem_logpage_select").val()?e("#wpmem_logpage_custom").show():e("#wpmem_logpage_custom").hide()}),e("#wpmem_regpage_select").change(function(){"use_custom"==e("#wpmem_regpage_select").val()?e("#wpmem_regpage_custom").show():e("#wpmem_regpage_custom").hide()}),e("#wpmem_mspage_select").change(function(){"use_custom"==e("#wpmem_mspage_select").val()?e("#wpmem_mspage_custom").show():e("#wpmem_mspage_custom").hide()}),e("#wpmem_stylesheet_select").change(function(){"use_custom"==e("#wpmem_stylesheet_select").val()?e("#wpmem_stylesheet_custom").show():e("#wpmem_stylesheet_custom").hide()})})}(jQuery),function(e){e(document).ready(function(){e("#wpmem_allowhtml").hide(),e("#wpmem_rows_cols").hide(),e("#wpmem_min_max").hide(),e("#wpmem_checkbox_info").hide(),e("#wpmem_dropdown_info").hide(),e("#wpmem_file_info").hide(),e("#wpmem_delimiter_info").hide(),e("#wpmem_hidden_info").hide()}),e(document).ready(function(){e("#wpmem_field_type_select").change(function(){"text"==e("#wpmem_field_type_select").val()||"password"==e("#wpmem_field_type_select").val()||"email"==e("#wpmem_field_type_select").val()||"url"==e("#wpmem_field_type_select").val()||"number"==e("#wpmem_field_type_select").val()||"date"==e("#wpmem_field_type_select").val()||"textarea"==e("#wpmem_field_type_select").val()?e("#wpmem_placeholder").show():e("#wpmem_placeholder").hide(),"text"==e("#wpmem_field_type_select").val()||"password"==e("#wpmem_field_type_select").val()||"email"==e("#wpmem_field_type_select").val()||"url"==e("#wpmem_field_type_select").val()||"date"==e("#wpmem_field_type_select").val()?(e("#wpmem_pattern").show(),e("#wpmem_title").show()):(e("#wpmem_pattern").hide(),e("#wpmem_title").hide()),"textarea"==e("#wpmem_field_type_select").val()?(e("#wpmem_allowhtml").show(),e("#wpmem_rows_cols").show()):(e("#wpmem_allowhtml").hide(),e("#wpmem_rows_cols").hide()),"number"==e("#wpmem_field_type_select").val()||"date"==e("#wpmem_field_type_select").val()?e("#wpmem_min_max").show():e("#wpmem_min_max").hide(),"checkbox"==e("#wpmem_field_type_select").val()?(e("#wpmem_checkbox_info").show(),e("#add_checked_value").prop("required",!0)):(e("#wpmem_checkbox_info").hide(),e("#add_checked_value").prop("required",!1)),"select"==e("#wpmem_field_type_select").val()||"multiselect"==e("#wpmem_field_type_select").val()||"radio"==e("#wpmem_field_type_select").val()||"multicheckbox"==e("#wpmem_field_type_select").val()?(e("#wpmem_dropdown_info").show(),e("#add_dropdown_value").prop("required",!0)):(e("#wpmem_dropdown_info").hide(),e("#add_dropdown_value").prop("required",!1)),"multiselect"==e("#wpmem_field_type_select").val()||"multicheckbox"==e("#wpmem_field_type_select").val()?e("#wpmem_delimiter_info").show():e("#wpmem_delimiter_info").hide(),"file"==e("#wpmem_field_type_select").val()||"image"==e("#wpmem_field_type_select").val()?e("#wpmem_file_info").show():e("#wpmem_file_info").hide(),"hidden"==e("#wpmem_field_type_select").val()?(e("#wpmem_hidden_info").show(),e("#add_hidden_value").prop("required",!0)):(e("#wpmem_hidden_info").hide(),e("#add_hidden_value").prop("required",!1))})})}(jQuery),function(e){e(document).ready(function(){e("#wpmem_block").hide()}),e(document).ready(function(){e("#wpmem_edit_block_status").click(function(){e("#wpmem_block").show("normal"),e("#wpmem_edit_block_status").hide()}),e("#wpmem_cancel_block_status").click(function(){e("#wpmem_block").hide("normal"),e("#wpmem_edit_block_status").show(),e("#wpmem_post_block_status").text(e("input[name=wpmem_block_original_label]").val()),e("#wpmem_post_block_status_"+e("input[name=wpmem_block_original_value]")).val().prop("checked",!0)}),e("#wpmem_ok_block_status").click(function(){e("#wpmem_block").hide("normal"),e("#wpmem_edit_block_status").show(),e("#wpmem_post_block_status").text(e("input[name=wpmem_block]:checked + label").text()),e("#wpmem_block_status_0").is(":checked")&&(e("#wpmem_post_icon_0").show(),e("#wpmem_post_icon_1").hide(),e("#wpmem_post_icon_2").hide()),e("#wpmem_block_status_1").is(":checked")&&(e("#wpmem_post_icon_0").hide(),e("#wpmem_post_icon_1").show(),e("#wpmem_post_icon_2").hide()),e("#wpmem_block_status_2").is(":checked")&&(e("#wpmem_post_icon_0").hide(),e("#wpmem_post_icon_1").hide(),e("#wpmem_post_icon_2").show())})})}(jQuery),jQuery(document).ready(function(e){wpmem_get_settings_vars.close_btn,e("#dialog-message").dialog({autoOpen:!1,modal:!0,height:"auto",width:600,buttons:{Close:function(){e(this).dialog("close")}}}),e("#opener").on("click",function(){e("#dialog-message").dialog("open")}),e("#select_all").click(function(){e("textarea").select(),document.execCommand("copy")}),e(window).resize(function(){e("#dialog-message").dialog("option","position",{my:"center",at:"center",of:window})})});
changelog.txt CHANGED
@@ -1,4 +1,182 @@
1
- = 3.1.9 =
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  * Security enhancements.
4
  * Improved user search in Users > All Users.
@@ -633,11 +811,11 @@ New Features:
633
 
634
  Bug Fix:
635
 
636
- * Fixed a bug where the reCAPTCHA error messages do not display on the [shortcode pages "register" and "members-area"](https://rocketgeek.com/plugins/wp-members/users-guide/shortcodes/page-shortcodes/).
637
 
638
  Code Improvement:
639
 
640
- * Completed a rebuild of the login function wpmem_login. Updated the cookie process to switch from [wp_setcookie](http://codex.wordpress.org/Function_Reference/wp_setcookie) (which is deprecated) to [wp_set_auth_cookie](http://codex.wordpress.org/Function_Reference/wp_set_auth_cookie). Also, the [wpmem_login_redirect hook](https://rocketgeek.com/plugins/wp-members/users-guide/filter-hooks/wpmem_login_redirect/) was moved to after the login credentials have been validated and the user is logged in. This allows the hook to access user data without the need to validate the user within the filter.
641
 
642
  = 2.7.6 =
643
 
1
+ = 3.2.9 =
2
+
3
+ * Load jQuery UI and Select2 libraries locally (if they have not already been enqueued).
4
+ * Use (local) template file for default tos field link (can be customized and saved in theme folder).
5
+ * Added new sanitization functions to API: wpmem_sanitize_class() and wpmem_sanitize_array().
6
+ * Review and cleanup of form data sanitization.
7
+ * Improved file/image field upload file type validation.
8
+ * Fixed issue with loading legacy translation files.
9
+ * Added "membership" attribute to [wpmem_logged_in] shortcode (same as "product" attribute, they are interchangeable).
10
+ * Added datepicker for setting user expiration (when membership products are used).
11
+
12
+ = 3.2.8 =
13
+
14
+ * Include jQuery UI CSS and Select2 library locally.
15
+ * Updated default TOS to a template file.
16
+ * Added additional data sanitization.
17
+ * Fixed potential security issues to prevent CSRF (Cross Site Request Forgery).
18
+
19
+ = 3.2.7 =
20
+
21
+ * Fix console error from nonce by implementing different nonce names.
22
+ * Updated packaged POT file for legacy lanaguage files. Updated legacy language files to use new POT.
23
+ * Full removal of legacy language files that are available as language packs from https://translate.wordpress.org/projects/wp-plugins/wp-members/
24
+ * Added jQuery UI stylesheet (fixes issue with main options tab settings modal).
25
+ * Added wpmem_default_text filter.
26
+ * Deprecated wpmem_default_text_strings filter, use wpmem_default_text instead.
27
+ * Added translation capability to field placeholders and title attributes.
28
+ * Updated Customizer setting slug to avoid namespace collisions (added "wpmem_" stem).
29
+ * Updated instances of wp_redirect() to use wp_safe_redirect().
30
+ * Updated install for multisite to use wp_insert_site (wpmu_new_blog deprecated in WP 5.1).
31
+ * Added user screen filter to show activated users.
32
+
33
+ = 3.2.6 =
34
+
35
+ * Update to evaluate required fields as not null (instead of false).
36
+ * Added wpmem_tos_link_tag filter.
37
+ * Added $button_html parameter to wpmem_register_form_buttons filter.
38
+ * Added wpmem_serve_menu filter.
39
+ * Added nonce to short form (long form was added in 3.2.5).
40
+ * Password change function only can be fired if user is logged in.
41
+ * Added "all" argument to wpmem_user_data() to retrieve either all user meta or WP-Members fields only.
42
+ * Added $date argument to wpmem_set_user_product(). Allows specific date to be set using API.
43
+ * Added wpmem_admin_after_profile_table and wpmem_user_after_profile_table actions.
44
+ * get_user_products() returns empty array if no products (previously boolean).
45
+ * Rebuild of [wpmem_field] logic for field type. Combined multiple conditions into a single switch.
46
+ * Update password reset form - password field should be "text" class.
47
+ * Added membership field type for allowing selection of a membership at registration.
48
+ * Login form updated from "Username" to "Username or Email".
49
+ * Added $arr parameter to wpmem_login_form_rows filter.
50
+ * Added file's post ID to post_data array.
51
+
52
+ = 3.2.5 =
53
+
54
+ * Fix user profile (admin/user) issue with tos field not displaying.
55
+ * Fix [wpmem_logged_in] shortcode to pass product attribute.
56
+ * Fix [wpmem_field] shortcode, checks if field is set to avoid undefined index error.
57
+ * Fix do_excerpt() if post object is not set as an object.
58
+ * Fix logic for displaying hidden posts based on product access.
59
+ * Added message dialog to display in Customizer.
60
+ * Added HTML5 "required" attribute to TOS checkbox.
61
+ * Added redirect_to attribute to logout link.
62
+ * Added $tag parameter to wpmem_{$tag}_link and wpmem_{$tag}_link_str filters.
63
+ * Added id parameter to wpmem_register_form_args filter.
64
+ * Added wpmem_email_send_args filter.
65
+ * Added wpmem_is_user() function to API.
66
+ * Added wpmem_do_shortcode() utility function in API.
67
+ * Added wpmem_export_fields filter to user export function.
68
+ * Added label attribute to field shortcode.
69
+ * Added user profile tabs (jquery ui tabs).
70
+ * Updated wpmem_form_date() API function.
71
+ * Updated check product access to handle product as an array.
72
+ * Updated to make a nonce a default for the registration form (reduces possibility of spam registrations).
73
+ * Updated form field creation, $value is now optional.
74
+ * Moved textdomain to load in main class file.
75
+ * Removed possibility of using reCAPTCHA v1 which is totally obsolete.
76
+ * Removed widget status message ("you are not logged in") for logged out state.
77
+
78
+ = 3.2.4 =
79
+
80
+ * Added deactivate users both bulk and single in Users > All Users.
81
+ * Added id attribute for form labels.
82
+ * Added wpmem_format_date() API function.
83
+ * Added label tags to multipe checkbox and radio group items.
84
+ * Added assigned product(s) column to users and posts screens.
85
+ * Updated membership product object structure.
86
+ * Updated load priority to run later for jquery loginout script.
87
+ * Removed query_vars filter.
88
+ * Deprecated wpmem_a_activate_user(), use wpmem_activate_user() instead.
89
+ * Deprecated wpmem_a_deactivate_user(), use wpmem_deactivate_user() instead.
90
+ * Relocated install file to /inc/ directory.
91
+ * Moved methods out of core.php, deprecated file.
92
+ * Fixed issue with default stylesheet setting caused by moving install file.
93
+
94
+ = 3.2.3 =
95
+
96
+ * Bug fix in user export that caused usernames to be dropped.
97
+ * Bug fix to allow admins to edit their own profile.
98
+ * Bug fix for jquery with regards to select2, only load if products are enabled.
99
+ * Added email API.
100
+ * Added product attribute to [wpmem_logged_in] shortcode.
101
+ * Added wpmem_force_ssl() API function.
102
+ * Added wpmem_set_as_logged_in() API function.
103
+ * Added filters to remove posts marked hidden from previous/next links.
104
+ * Updated user login function to use WP script, facilitates login with username OR email, removes wpmem_login_fields filter, changes to wp_safe_redirect().
105
+ * Updated password change for maintaining login state.
106
+ * Moved wpmem_fields(), wpmem_form_label(), and wpmem_form_field() to api-forms.php.
107
+ * Moved wpmem_user_has_role(), wpmem_user_has_meta(), wpmem_is_user_activated(), wpmem_user_data(), wpmem_update_user_role(), and wpmem_user_has_access() to api-users.php.
108
+ * Moved wpmem_do_excerpt(), wpmem_texturize(), wpmem_get_excluded_meta(), wpmem_use_ssl(), wpmem_write_log(), wpmem_load_dropins(), wpmem_array_insert(), and wpmem_get_sub_str() to api-utilities.php.
109
+ * Moved wpmem_wp_reserved_terms() to admin API.
110
+ * Deprecated wpmem_check_activated() and wpmem_use_ssl().
111
+ * Removed obsolete functions wpmem_enqueue_style(), wpmem_convert_tag(), wpmem_no_reset(), and wpmem_user_profile_multipart().
112
+ * Applied wpmem_force_ssl() to stylesheet in case it needs to load securely (even if the setting is saved as http://).
113
+ * Implemented change in the native WP registration form processing to allow values of "0" to be interpreted as string literals. Previously could be interpreted as boolean when being saved.
114
+
115
+ = 3.2.2 =
116
+
117
+ * Fixed bug in 3.2.1/3.2.2 for user activation when user creates password at registration and is activated from the user profile.
118
+ * Fixed a 3.2 upgrade issue, verifies username field is properly added to field settings array.
119
+ * Fixed issue with user product verification where only expiration products were validated.
120
+ * Fixed logic in form field builder so multiselect will accept a custom class.
121
+ * Added select2 support for setting product access in the post editor.
122
+ * Removed duplicate API function wpmem_current_postid() (use wpmem_current_post_id()).
123
+ * Replaced sanitize_html_class() with WP_Members_Forms::sanitize_class() so variables may contain multiple classes.
124
+
125
+ = 3.2.1 =
126
+
127
+ * Fixed duplicate ID in login form.
128
+ * Fixed user profile update for excluded fields.
129
+ * Fixed native WP registration, excluded WP-Members username field in form validation.
130
+ * Fixed update post when block status is not changed.
131
+ * Rebuilt user interface for post restriction metabox to make it more intuitive.
132
+ * Changed status column in All Posts to show all block statuses, not just those opposite the default.
133
+ * Changed "clickable" attribute for field shortcode default to false.
134
+ * Added wpmem_user_export_header and wpmem_user_export_row filter for export.
135
+
136
+ = 3.2.0 =
137
+
138
+ * Tested and compatible with Gutenberg.
139
+ * Changed default address meta fields to WooCommerce billing meta keys.
140
+ * Removed language packs that install from wordpress.org (de_DE, hu_HU, ja, nl_NL, pt_BR, ru_RU, and sv_SE).
141
+ * All remaining user facing strings in get_text() added wp-members textdomain.
142
+ * Added locale as a parameter for localization filters.
143
+ * Added wpmem_register_hidden_rows filter.
144
+ * Added "post_to" key for wpmem_register_form_args.
145
+ * Rebuild of user export function. User export now uses fputcsv.
146
+ * Updates/code improvement for enqueueing styles.
147
+ * Updated widget, added widget_title filter before wpmem_widget_title, documented wpmem_widget_id filter, added instance and id_base parameters.
148
+ * Updated empty $fields check to not rewrite fields.
149
+ * Deprecated wpmem_inc_status().
150
+ * Deprecated wpmem_do_sidebar().
151
+ * Deprecated wpmem_create_formfield(), use wpmem_form_field() instead.
152
+ * Deprecated a number of non-user callable functions.
153
+ * Eliminated capability-based load for admin files.
154
+ * Maintain user login state when password is changed.
155
+ * Added wpmem_get_sub_str() string manipulation utility.
156
+ * Updated login form redirect_to to account for query vars.
157
+ * Fixes issue with login status if logout url is encoded (sprintf() has too few arguments).
158
+ * Added Membership Products Custom Post Type.
159
+ * Added "Hide Post" option for blocking content (currently only by post meta _wpmem_block).
160
+ * Removed several outdated stylesheets from selection (still packaged with download for users who may use them).
161
+ * Added wpmem_update_user_role() API function.
162
+ * Added wpmem_display_message() API function.
163
+ * Added wpmem_user_has_access() API function.
164
+ * HTML5 update - form anchor tags changed from "name" to "id".
165
+ * HTML5 update - form id tags set default value (can still be filtered).
166
+ * HTML5 update - removed "align" attribute (captcha, link-text).
167
+ * HTML5 update - added placeholder, pattern, and title attribute support for password fields.
168
+ * Improved the add a field dialog to adjust required inputs depending on field type.
169
+ * Added placeholder, rows, and cols attribute support for textarea field settings.
170
+ * Moved remaining core functions to appropriate object classes, left wrappers for most.
171
+ * Added new email class and shortcode class to replace previous functions/files.
172
+ * Added link_span_before/link_span_after wrapper for login link text.
173
+ * Updated "TOS" text to accept a custom label (priority to filtered label with wpmem_tos_link_txt).
174
+ * Updated all processing involving "TOS" to better exclude the field on profile update (if saved value equals the field's checked value).
175
+ * Fixed a bug that caused WP native fields to be set as non-native when labels were updated in the fields tab.
176
+ * Added Customizer control to display login, register, and widget forms when using the Customizer (easier to work on custom CSS).
177
+ * Added login/out menu item.
178
+
179
+ = 3.1.9 =
180
 
181
  * Security enhancements.
182
  * Improved user search in Users > All Users.
811
 
812
  Bug Fix:
813
 
814
+ * Fixed a bug where the reCAPTCHA error messages do not display on the [shortcode pages "register" and "members-area"](https://rocketgeek.com/plugins/wp-members/docs/shortcodes/page-shortcodes/).
815
 
816
  Code Improvement:
817
 
818
+ * Completed a rebuild of the login function wpmem_login. Updated the cookie process to switch from [wp_setcookie](http://codex.wordpress.org/Function_Reference/wp_setcookie) (which is deprecated) to [wp_set_auth_cookie](http://codex.wordpress.org/Function_Reference/wp_set_auth_cookie). Also, the [wpmem_login_redirect hook](https://rocketgeek.com/plugins/wp-members/docs/filter-hooks/wpmem_login_redirect/) was moved to after the login credentials have been validated and the user is logged in. This allows the hook to access user data without the need to validate the user within the filter.
819
 
820
  = 2.7.6 =
821
 
includes/admin/admin.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-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
@@ -112,21 +112,6 @@ function wpmem_admin_action( $action ) {
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
  *
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-2021 Chad Butler
10
  * WP-Members(tm) is a trademark of butlerblog.com
11
  *
12
  * @package WP-Members
13
  * @author Chad Butler
14
+ * @copyright 2006-2021
15
  *
16
  * Functions included:
17
  * - wpmem_admin
112
  return $did_update;
113
  }
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  /**
116
  * Wrapper for WP_Members_Admin_Tab_Options::page_list()
117
  *
includes/admin/api.php CHANGED
@@ -1,119 +1,119 @@
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
- * Updates a single plugin option.
102
- *
103
- * @since 3.3.6
104
- *
105
- * @param string $option Name of the option to update.
106
- * @param string $key Which key to update. Update a subkey as primary_key/subkey.
107
- * @param string $value New value.
108
- * @return void
109
- */
110
- function wpmem_update_option( $option, $key, $value ) {
111
- $settings = get_option( $option );
112
- if ( strpos( $key, '/' ) ) {
113
- $keys = explode( '/', $key );
114
- $settings[ $keys[0] ][ $keys[1] ] = $value;
115
- } else {
116
- $settings[ $key ] = $value;
117
- }
118
- update_option( $option, $settings );
119
  }
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-2021 Chad Butler
8
+ * WP-Members(tm) is a trademark of butlerblog.com
9
+ *
10
+ * @package WP-Members
11
+ * @author Chad Butler
12
+ * @copyright 2006-2021
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
+ * Updates a single plugin option.
102
+ *
103
+ * @since 3.3.6
104
+ *
105
+ * @param string $option Name of the option to update.
106
+ * @param string $key Which key to update. Update a subkey as primary_key/subkey.
107
+ * @param string $value New value.
108
+ * @return bool True if the value was updated, otherwise false.
109
+ */
110
+ function wpmem_update_option( $option, $key, $value ) {
111
+ $settings = get_option( $option );
112
+ if ( strpos( $key, '/' ) ) {
113
+ $keys = explode( '/', $key );
114
+ $settings[ $keys[0] ][ $keys[1] ] = $value;
115
+ } else {
116
+ $settings[ $key ] = $value;
117
+ }
118
+ return update_option( $option, $settings );
119
  }
includes/admin/class-wp-members-admin-api.php CHANGED
@@ -116,8 +116,9 @@ class WP_Members_Admin_API {
116
  global $wpmem;
117
 
118
  add_action( 'admin_enqueue_scripts', array( $this, 'dashboard_enqueue_scripts' ) );
119
- add_action( 'user_new_form', 'wpmem_admin_add_new_user' );
120
  add_filter( 'plugin_action_links', array( $this, 'plugin_links' ), 10, 2 );
 
 
121
  // add_filter( 'wpmem_admin_tabs', 'wpmem_add_about_tab' );
122
 
123
  add_action( 'wp_ajax_wpmem_do_field_reorder', array( 'WP_Members_Admin_Tab_Fields', 'do_field_reorder' ) );
@@ -235,44 +236,6 @@ class WP_Members_Admin_API {
235
  echo '</h2>';
236
  }
237
 
238
- /**
239
- * Adds custom email dialog to the Emails tab.
240
- *
241
- * @since 3.1.0
242
- *
243
- * @param array $args Settings array for the email.
244
- */
245
- function do_email_input( $args ) { ?>
246
- <tr valign="top"><td colspan="2"><strong><?php echo esc_html( $args['heading'] ); ?></strong></td></tr>
247
- <tr valign="top">
248
- <th scope="row"><?php echo esc_html( $args['subject_label'] ); ?></th>
249
- <td><input type="text" name="<?php echo esc_attr( $args['subject_input'] ); ?>" size="80" value="<?php echo esc_attr( wp_unslash( $args['subject_value'] ) ); ?>"></td>
250
- </tr>
251
- <tr valign="top">
252
- <th scope="row"><?php echo esc_html( $args['body_label'] ); ?></th>
253
- <td><textarea name="<?php echo esc_attr( $args['body_input'] ); ?>" rows="12" cols="50" id="" class="large-text code"><?php echo esc_textarea( wp_unslash( $args['body_value'] ) ); ?></textarea></td>
254
- </tr>
255
- <tr><td colspan="2"><hr /></td></tr><?php
256
- }
257
-
258
- /**
259
- * Saves custom email settings.
260
- *
261
- * @since 3.1.0
262
- *
263
- * @param array $args Settings array for the email.
264
- */
265
- function email_update( $args ) {
266
- $settings = array(
267
- 'subj' => sanitize_text_field( wpmem_get( $args['subject_input'] ) ),
268
- 'body' => wp_kses( wpmem_get( $args['body_input'] ), 'post' ),
269
- );
270
- update_option( $args['name'], $settings, true );
271
- $this->emails[ $args['name'] ]['subject_value'] = $settings['subj'];
272
- $this->emails[ $args['name'] ]['body_value'] = $settings['body'];
273
- return;
274
- }
275
-
276
  /**
277
  * Handles custom email settings.
278
  *
@@ -353,7 +316,7 @@ class WP_Members_Admin_API {
353
  'label' => $args['label'],
354
  //'input' => $args['name'] . '_dialog',
355
  'value' => $args['value'],
356
- //'value' => ( $args['value'] ) ? $args['value'] : $wpmem->get_text( $key ),
357
  );
358
 
359
  // Merge args with settings.
@@ -569,11 +532,35 @@ class WP_Members_Admin_API {
569
  */
570
  function dashboard_enqueue_scripts( $hook ) {
571
  global $current_screen, $wpmem;
572
- if ( 'edit.php' == $hook || 'settings_page_wpmem-settings' == $hook || 'post.php' == $hook || 'post-new.php' == $hook || 'user-edit.php' == $hook || 'profile.php' == $hook ) {
 
 
 
 
 
 
573
  wp_enqueue_style( 'wpmem-admin', $wpmem->url . 'assets/css/admin' . wpmem_get_suffix() . '.css', '', $wpmem->version );
574
  }
575
  if ( 'settings_page_wpmem-settings' == $hook || 'post.php' == $hook || 'post-new.php' == $hook ) {
576
- wp_enqueue_script( 'wpmem-admin', $wpmem->url . 'assets/js/admin' . wpmem_get_suffix() . '.js', '', $wpmem->version );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
577
  }
578
  if ( ( 'post.php' == $hook || 'post-new.php' == $hook ) && 1 == $wpmem->enable_products ) {
579
  if ( ! wp_script_is( 'select2', 'enqueued' ) ) {
@@ -582,40 +569,9 @@ class WP_Members_Admin_API {
582
  wp_enqueue_style( 'select2-style' );
583
  wp_enqueue_script( 'select2' );
584
  }
585
-
586
- //if ( ( 'post-new.php' == $hook && isset( $_GET['post_type'] ) && 'wpmem_product' == $_GET['post_type'] ) || )
587
- if ( 'wpmem_product' == get_post_type() ) {
588
- wp_enqueue_script( 'jquery' );
589
- wp_enqueue_script( 'jquery-ui-core' );// enqueue jQuery UI Core
590
- wp_enqueue_script( 'jquery-ui-datepicker' ); // enqueue jQuery UI Datepicker
591
- if ( ! wp_style_is( 'jquery-ui-style', 'enqueued' ) ) {
592
- wp_register_style( 'jquery-ui-style', $wpmem->url . 'assets/css/jquery-ui' . wpmem_get_suffix() . '.css' );
593
- }
594
- wp_enqueue_style( 'jquery-ui-style' );
595
- }
596
  }
597
  if ( 'user-edit' == $current_screen->id || 'profile' == $current_screen->id ) {
598
- wp_enqueue_script( 'jquery' );
599
- wp_enqueue_script( 'jquery-ui-core' ); // enqueue jQuery UI Core
600
  wp_enqueue_script( 'jquery-ui-tabs' ); // enqueue jQuery UI Tabs
601
- wp_enqueue_script( 'jquery-ui-datepicker' ); // enqueue jQuery UI Datepicker
602
-
603
- if ( ! wp_style_is( 'jquery-ui-style', 'enqueued' ) ) {
604
- wp_register_style( 'jquery-ui-style', $wpmem->url . 'assets/css/jquery-ui' . wpmem_get_suffix() . '.css' );
605
- }
606
- wp_enqueue_style( 'jquery-ui-style' );
607
- }
608
- if ( 'settings_page_wpmem-settings' == $hook ) {
609
- wp_enqueue_script( 'jquery' );
610
- wp_enqueue_script( 'jquery-ui-core' );// enqueue jQuery UI Core
611
- wp_enqueue_script( 'jquery-ui-dialog' );
612
- wp_enqueue_script( 'jquery-ui-datepicker' ); // enqueue jQuery UI Datepicker
613
-
614
- if ( ! wp_style_is( 'jquery-ui-style', 'enqueued' ) ) {
615
- wp_register_style( 'jquery-ui-style', $wpmem->url . 'assets/css/jquery-ui' . wpmem_get_suffix() . '.css' );
616
- }
617
- wp_enqueue_style( 'jquery-ui-style' );
618
-
619
  }
620
  }
621
 
116
  global $wpmem;
117
 
118
  add_action( 'admin_enqueue_scripts', array( $this, 'dashboard_enqueue_scripts' ) );
 
119
  add_filter( 'plugin_action_links', array( $this, 'plugin_links' ), 10, 2 );
120
+
121
+ add_action( 'user_new_form', array( $wpmem->forms, 'wp_newuser_form' ) );
122
  // add_filter( 'wpmem_admin_tabs', 'wpmem_add_about_tab' );
123
 
124
  add_action( 'wp_ajax_wpmem_do_field_reorder', array( 'WP_Members_Admin_Tab_Fields', 'do_field_reorder' ) );
236
  echo '</h2>';
237
  }
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  /**
240
  * Handles custom email settings.
241
  *
316
  'label' => $args['label'],
317
  //'input' => $args['name'] . '_dialog',
318
  'value' => $args['value'],
319
+ //'value' => ( $args['value'] ) ? $args['value'] : wpmem_get_text( $key ),
320
  );
321
 
322
  // Merge args with settings.
532
  */
533
  function dashboard_enqueue_scripts( $hook ) {
534
  global $current_screen, $wpmem;
535
+ if ( 'edit.php' == $hook
536
+ || 'settings_page_wpmem-settings' == $hook
537
+ || 'post.php' == $hook
538
+ || 'post-new.php' == $hook
539
+ || 'user-edit.php' == $hook
540
+ || 'profile.php' == $hook
541
+ || 'users.php' ) {
542
  wp_enqueue_style( 'wpmem-admin', $wpmem->url . 'assets/css/admin' . wpmem_get_suffix() . '.css', '', $wpmem->version );
543
  }
544
  if ( 'settings_page_wpmem-settings' == $hook || 'post.php' == $hook || 'post-new.php' == $hook ) {
545
+ wp_enqueue_script( 'jquery-ui-dialog' ); // enqueue jQuery UI Dialog dependency
546
+ wp_register_script( 'wpmem-admin', $wpmem->url . 'assets/js/admin' . wpmem_get_suffix() . '.js', 'jquery', $wpmem->version, true );
547
+ $translation_array = array(
548
+ 'close_btn' => __( 'Close', 'wp-members' ),
549
+ );
550
+ wp_localize_script( 'wpmem-admin', 'wpmem_get_settings_vars', $translation_array );
551
+ wp_enqueue_script( 'wpmem-admin' );
552
+ }
553
+ if ( ( ( 'post.php' == $hook || 'post-new.php' == $hook ) && 1 == $wpmem->enable_products )
554
+ || ( 'wpmem_product' == get_post_type() )
555
+ || ( 'user-edit' == $current_screen->id || 'profile' == $current_screen->id )
556
+ || ( 'settings_page_wpmem-settings' == $hook ) ) {
557
+ wp_enqueue_script( 'jquery' );
558
+ wp_enqueue_script( 'jquery-ui-core' ); // enqueue jQuery UI Core
559
+ wp_enqueue_script( 'jquery-ui-datepicker' ); // enqueue jQuery UI Datepicker
560
+ if ( ! wp_style_is( 'jquery-ui-style', 'enqueued' ) ) {
561
+ wp_register_style( 'jquery-ui-style', $wpmem->url . 'assets/css/jquery-ui' . wpmem_get_suffix() . '.css' );
562
+ }
563
+ wp_enqueue_style( 'jquery-ui-style' );
564
  }
565
  if ( ( 'post.php' == $hook || 'post-new.php' == $hook ) && 1 == $wpmem->enable_products ) {
566
  if ( ! wp_script_is( 'select2', 'enqueued' ) ) {
569
  wp_enqueue_style( 'select2-style' );
570
  wp_enqueue_script( 'select2' );
571
  }
 
 
 
 
 
 
 
 
 
 
 
572
  }
573
  if ( 'user-edit' == $current_screen->id || 'profile' == $current_screen->id ) {
 
 
574
  wp_enqueue_script( 'jquery-ui-tabs' ); // enqueue jQuery UI Tabs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
575
  }
576
  }
577
 
includes/admin/class-wp-members-admin-users.php CHANGED
@@ -1,601 +1,621 @@
1
- <?php
2
- /**
3
- * The WP_Members Admin Users Class.
4
- *
5
- * @package WP-Members
6
- * @subpackage WP_Members Admin Users Object Class
7
- * @since 3.3.0
8
- */
9
-
10
- // Exit if accessed directly.
11
- if ( ! defined( 'ABSPATH' ) ) {
12
- exit();
13
- }
14
-
15
- class WP_Members_Admin_Users {
16
-
17
- /**
18
- * Function to add activate/export to the bulk dropdown list.
19
- *
20
- * @since 2.8.2
21
- */
22
- static function bulk_user_action() {
23
- global $wpmem; ?>
24
- <script type="text/javascript">
25
- var $j = jQuery.noConflict();
26
- $j(document).ready(function() {
27
- <?php if( $wpmem->mod_reg == 1 ) { ?>
28
- $j('<option>').val('activate').text('<?php _e( 'Activate', 'wp-members' )?>').appendTo("select[name='action']");
29
- $j('<option>').val('deactivate').text('<?php _e( 'Deactivate', 'wp-members' )?>').appendTo("select[name='action']");
30
- <?php } ?>
31
- $j('<option>').val('export').text('<?php _e( 'Export', 'wp-members' )?>').appendTo("select[name='action']");
32
- $j('<input id="export_all" name="export_all" class="button action" type="submit" value="<?php _e( 'Export All Users', 'wp-members' ); ?>" />').appendTo(".top .bulkactions");
33
- <?php if( $wpmem->mod_reg == 1 ) { ?>
34
- $j('<option>').val('activate').text('<?php _e( 'Activate', 'wp-members' )?>').appendTo("select[name='action2']");
35
- $j('<option>').val('deactivate').text('<?php _e( 'Deactivate', 'wp-members' )?>').appendTo("select[name='action2']");
36
- <?php } ?>
37
- $j('<option>').val('export').text('<?php _e( 'Export', 'wp-members' )?>').appendTo("select[name='action2']");
38
- $j('<input id="export_all" name="export_all" class="button action" type="submit" value="<?php _e( 'Export All Users', 'wp-members' ); ?>" />').appendTo(".bottom .bulkactions");
39
- });
40
- </script><?php
41
- }
42
-
43
- /**
44
- * Function to add activate link to the user row action.
45
- *
46
- * @since 2.8.2
47
- * @since 3.3.5 Updated to use wpmem_is_user_activated().
48
- * @since 3.3.8 Added confirmation link, changed from insert_activate_link().
49
- *
50
- * @param array $actions
51
- * @param $user_object
52
- * @return array $actions
53
- */
54
- static function insert_hover_links( $actions, $user_object ) {
55
- global $wpmem;
56
- if ( $user_object->ID != get_current_user_id() ) {
57
-
58
- if ( 1 == $wpmem->act_link ) {
59
- $is_user_confirmed = wpmem_is_user_confirmed( $user_object->ID );
60
- if ( false === $is_user_confirmed ) {
61
- $action = 'confirm';
62
- $term = __( 'Confirm', 'wp-members' );
63
- } else {
64
- $action = 'unconfirm';
65
- $term = __( 'Unconfirm', 'wp-members' );
66
- }
67
- $url = add_query_arg( array( 'action' => $action . '-single', 'user' => $user_object->ID ), "users.php" );
68
- $url = wp_nonce_url( $url, 'activate-user' );
69
- $actions[ $action ] = '<a href="' . $url . '">' . $term . '</a>';
70
- }
71
-
72
- if ( 1 == $wpmem->mod_reg ) {
73
- $is_active = wpmem_is_user_activated( $user_object->ID );
74
-
75
- if ( false === $is_active ) {
76
- $action = 'activate';
77
- $term = __( 'Activate', 'wp-members' );
78
- } else {
79
- $action = 'deactivate';
80
- $term = __( 'Deactivate', 'wp-members' );
81
- }
82
- $url = add_query_arg( array( 'action' => $action . '-single', 'user' => $user_object->ID ), "users.php" );
83
- $url = wp_nonce_url( $url, 'activate-user' );
84
- $actions[ $action ] = '<a href="' . $url . '">' . $term . '</a>';
85
- }
86
- }
87
- return $actions;
88
- }
89
-
90
- /**
91
- * Function to handle bulk actions at page load.
92
- *
93
- * @since 2.8.2
94
- *
95
- * @uses WP_Users_List_Table
96
- *
97
- * @global object $wpmem
98
- */
99
- static function page_load() {
100
-
101
- global $wpmem;
102
- if ( current_user_can( 'list_users' ) ) {
103
- $wpmem->admin->user_search = new WP_Members_Admin_User_Search();
104
- }
105
-
106
- // If exporting all users, do it, then exit.
107
- if ( wpmem_get( 'export_all', false, 'request' ) ) {
108
- $today = date( "Y-m-d" );
109
- wpmem_export_users( array( 'export'=>'all', 'filename'=>'user-export-' . $today . '.csv' ) );
110
- exit();
111
- }
112
-
113
- $wp_list_table = _get_list_table( 'WP_Users_List_Table' );
114
- $action = $wp_list_table->current_action();
115
- $sendback = '';
116
-
117
- switch ( $action ) {
118
-
119
- case 'activate':
120
- case 'deactivate':
121
-
122
- // Validate nonce.
123
- check_admin_referer( 'bulk-users' );
124
-
125
- // Get the users.
126
- if ( isset( $_REQUEST['users'] ) ) {
127
-
128
- $users = $_REQUEST['users'];
129
-
130
- // Update the users.
131
- $x = 0;
132
- foreach ( $users as $user ) {
133
- $user = filter_var( $user, FILTER_VALIDATE_INT );
134
- // Current user cannot activate or deactivate themselves.
135
- if ( $user != get_current_user_id() ) {
136
- // Check to see if the user is already activated, if not, activate.
137
- if ( 'activate' == $action && 1 != get_user_meta( $user, 'active', true ) ) {
138
- wpmem_activate_user( $user );
139
- } elseif( 'deactivate' == $action ) {
140
- wpmem_deactivate_user( $user );
141
- }
142
- $x++;
143
- }
144
- }
145
- $msg = ( 'activate' == $action ) ? urlencode( sprintf( __( '%s users activated', 'wp-members' ), $x ) ) : urlencode( sprintf( __( '%s users deactivated', 'wp-members' ), $x ) );
146
-
147
- } else {
148
- $msg = urlencode( __( 'No users selected', 'wp-members' ) );
149
- }
150
-
151
- // Set the return message.
152
- $sendback = add_query_arg( array( 'activated' => $msg ), $sendback );
153
- break;
154
-
155
- case 'activate-single':
156
- case 'deactivate-single':
157
-
158
- // Validate nonce.
159
- check_admin_referer( 'activate-user' );
160
-
161
- // Get the users.
162
- $user_id = filter_var( $_REQUEST['user'], FILTER_VALIDATE_INT );
163
-
164
- // Check to see if the user is already activated, if not, activate.
165
- if ( $user_id == get_current_user_id() ) {
166
- $msg = urlencode( sprintf( esc_html__( 'You cannot activate or deactivate yourself', 'wp-members' ) ) );
167
-
168
- } elseif ( 'activate-single' == $action && false === wpmem_is_user_activated( $user_id ) ) {
169
- wpmem_activate_user( $user_id );
170
- $user_info = get_userdata( $user_id );
171
- $msg = urlencode( sprintf( esc_html__( "%s activated", 'wp-members' ), $user_info->user_login ) );
172
-
173
- } elseif ( 'deactivate-single' == $action ) {
174
- wpmem_deactivate_user( $user_id );
175
- $user_info = get_userdata( $user_id );
176
- $msg = urlencode( sprintf( esc_html__( "%s deactivated", 'wp-members' ), $user_info->user_login ) );
177
-
178
- } else {
179
- // Set the return message.
180
- $msg = urlencode( __( "That user is already active", 'wp-members' ) );
181
- }
182
- $sendback = add_query_arg( array( 'activated' => $msg ), $sendback );
183
- break;
184
-
185
- case 'confirm-single':
186
- case 'unconfirm-single':
187
-
188
- // Validate nonce.
189
- check_admin_referer( 'activate-user' );
190
-
191
- // Get the users.
192
- $user_id = filter_var( $_REQUEST['user'], FILTER_VALIDATE_INT );
193
-
194
- // Check to see if the user is already activated, if not, activate.
195
- if ( $users == get_current_user_id() ) {
196
- $msg = urlencode( sprintf( esc_html__( 'You cannot confirm or unconfirm yourself', 'wp-members' ) ) );
197
-
198
- } elseif ( 'confirm-single' == $action && false === wpmem_is_user_confirmed( $user_id ) ) {
199
- wpmem_set_user_as_confirmed( $user_id );
200
- $user_info = get_userdata( $user_id );
201
- $msg = urlencode( sprintf( esc_html__( "%s confirmed", 'wp-members' ), $user_info->user_login ) );
202
-
203
- } elseif ( 'unconfirm-single' == $action ) {
204
- wpmem_set_user_as_unconfirmed( $user_id );
205
- $user_info = get_userdata( $user_id );
206
- $msg = urlencode( sprintf( esc_html__( "%s unconfirmed", 'wp-members' ), $user_info->user_login ) );
207
-
208
- } else {
209
- // Set the return message.
210
- $msg = urlencode( __( "That user is already confirmed", 'wp-members' ) );
211
- }
212
- $sendback = add_query_arg( array( 'activated' => $msg ), $sendback );
213
- break;
214
-
215
- case 'show':
216
-
217
- add_action( 'pre_user_query', array( 'WP_Members_Admin_Users', 'pre_user_query' ) );
218
- return;
219
- break;
220
-
221
- case 'export':
222
-
223
- $users = wpmem_get( 'users', array(), 'request' );
224
- wpmem_export_users( array( 'export'=>'selected' ), wpmem_sanitize_array( $users, 'integer' ) );
225
- return;
226
- break;
227
-
228
- default:
229
- return;
230
- break;
231
-
232
- }
233
-
234
- /**
235
- * Doing user action.
236
- *
237
- * @since 3.3.0
238
- */
239
- do_action( 'wpmem_user_action' );
240
-
241
- // If we did not return already, we need to wp_safe_redirect.
242
- wp_safe_redirect( $sendback );
243
- exit();
244
-
245
- }
246
-
247
- /**
248
- * Function to echo admin update message.
249
- *
250
- * @since 2.8.2
251
- */
252
- static function admin_notices() {
253
-
254
- global $pagenow, $user_action_msg;
255
- if( $pagenow == 'users.php' && isset( $_REQUEST['activated'] ) ) {
256
- $message = esc_html( $_REQUEST['activated'] );
257
- echo "<div class=\"updated\"><p>{$message}</p></div>";
258
- }
259
-
260
- if ( $user_action_msg ) {
261
- echo "<div class=\"updated\"><p>{$user_action_msg}</p></div>";
262
- }
263
- }
264
-
265
- /**
266
- * Function to add user views to the top list.
267
- *
268
- * @since 2.8.2
269
- * @since 3.1.2 Added user view counts as transient.
270
- *
271
- * @global object $wpdb
272
- * @global object $wpmem
273
- * @param array $views
274
- * @return array $views
275
- */
276
- static function views( $views ) {
277
-
278
- global $wpmem;
279
-
280
- // Get the cached user counts.
281
- $user_counts = get_transient( 'wpmem_user_counts' );
282
-
283
- // check to see if data was successfully retrieved from the cache
284
- if ( false === $user_counts ) {
285
-
286
- // @todo For now, 30 seconds. We'll see how things go.
287
- $transient_expires = 30; // Value in seconds, 1 day: ( 60 * 60 * 24 );
288
-
289
- global $wpdb;
290
-
291
- // We need a count of total users.
292
- // @todo - need a more elegant way of this entire process.
293
- $sql = "SELECT COUNT(*) FROM " . $wpdb->users;
294
- $users = $wpdb->get_var( $sql );
295
-
296
- // What needs to be counted?
297
- $count_metas = array(
298
- 'pending' => 'pending', // Used for PayPal Extension
299
- 'trial' => 'trial', // Used for PayPal Extension
300
- 'subscription' => 'subscription', // Used for PayPal Extension
301
- 'expired' => 'expired', // Used for PayPal Extension
302
- 'active' => 'active',
303
- 'notactive' => 'active',
304
- 'deactivated' => 'deactivated',
305
- 'notexported' => 'exported',
306
- );
307
-
308
- // Handle various counts.
309
- $user_counts = array();
310
- foreach ( $count_metas as $key => $meta_key ) {
311
- if ( 'active' == $key ) {
312
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM " . $wpdb->usermeta . " WHERE meta_key=%s AND meta_value=1", $meta_key ) );
313
- }
314
- if ( 'notactive' == $key || 'notexported' == $key ) {
315
- $users_with_meta = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM " . $wpdb->usermeta . " WHERE meta_key=%s AND meta_value=1", $meta_key ) );
316
- $count = $users - $users_with_meta;
317
- }
318
- if ( 'deactivated' == $key ) {
319
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM " . $wpdb->usermeta . " WHERE meta_key = 'active' AND meta_value = 0" );
320
- }
321
- if ( 'trial' == $key || 'subscription' == $key || 'pending' == $key ) {
322
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM " . $wpdb->usermeta . " WHERE meta_key = 'exp_type' AND meta_value = \"%s\"", $key ) );
323
- }
324
- if ( 'expired' == $key ) {
325
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM " . $wpdb->usermeta . " WHERE meta_key = 'expires' AND STR_TO_DATE( meta_value, '%m/%d/%Y' ) < CURDATE() AND meta_value != '01/01/1970'" );
326
- }
327
- $user_counts[ $key ] = $count;
328
- }
329
- set_transient( 'wpmem_user_counts', $user_counts, $transient_expires );
330
- }
331
-
332
- if ( defined( 'WPMEM_EXP_MODULE' ) && 1 == $wpmem->use_exp ) {
333
- $views['pending'] = __( 'Pending', 'wp-members' );
334
- $views['trial'] = __( 'Trial', 'wp-members' );
335
- $views['subscription'] = __( 'Subscription', 'wp-members' );
336
- $views['expired'] = __( 'Expired', 'wp-members' );
337
- }
338
- if ( 1 == $wpmem->mod_reg ) {
339
- $views['active'] = __( 'Activated', 'wp-members' );
340
- $views['notactive'] = __( 'Pending Activation', 'wp-members' );
341
- $views['deactivated'] = __( 'Deactivated', 'wp-members' );
342
- }
343
- $views['notexported'] = __( 'Not Exported', 'wp-members' );
344
- $show = sanitize_text_field( wpmem_get( 'show', false, 'get' ) );
345
-
346
- foreach ( $views as $key => $view ) {
347
- if ( isset( $user_counts[ $key ] ) ) {
348
- $link = "users.php?action=show&amp;show=" . $key;
349
- $current = ( $show == $key ) ? ' class="current"' : '';
350
- $views[ $key ] = sprintf(
351
- '<a href="%s" %s>%s <span class="count">(%d)</span></a>',
352
- esc_url( $link ),
353
- $current,
354
- $view,
355
- isset( $user_counts[ $key ] ) ? $user_counts[ $key ] : ''
356
- );
357
- }
358
- }
359
-
360
- /**
361
- * Filters all views before returning to the WP 'views_users' filter.
362
- *
363
- * @since 3.3.0
364
- *
365
- * @param array $views {
366
- *
367
- * @type string The HTML for the view.
368
- * }
369
- */
370
- $views = apply_filters( 'wpmem_views_users', $views, $show );
371
-
372
- return $views;
373
- }
374
-
375
- /**
376
- * Function to add custom user columns to the user table.
377
- *
378
- * @since 2.8.2
379
- *
380
- * @param array $columns
381
- * @return array $columns
382
- */
383
- static function add_user_column( $columns ) {
384
-
385
- global $wpmem_user_columns, $wpmem;
386
-
387
- // Get any columns to be added to the Users > All Users screen.
388
- $wpmem_user_columns = get_option( 'wpmembers_utfields' );
389
-
390
- if ( $wpmem_user_columns ) {
391
- $column_labels = array();
392
- if ( 1 != $wpmem->mod_reg ) {
393
- unset( $wpmem_user_columns['active'] );
394
- }
395
-
396
- // @todo This is a workaround so that wpmembers_utfields doesn't have to be updated.
397
- if ( isset( $wpmem_user_columns['active'] ) ) {
398
- $wpmem_user_columns['active'] = __( 'Activated', 'wp-members' );
399
- }
400
-
401
- if ( 1 != $wpmem->act_link ) {
402
- unset( $wpmem_user_columns['_wpmem_user_confirmed'] );
403
- }
404
-
405
- // @todo Need to eventually change the wpmembers_utfields setting so we don't have to do it this way.
406
- $fields = wpmem_fields();
407
- foreach ( $wpmem_user_columns as $key => $value ) {
408
- $column_labels[ $key ] = ( isset( $fields[ $key ] ) ) ? $fields[ $key ]['label'] : $value;
409
- }
410
-
411
- /**
412
- * Filter the User > All Users custom columns before they are merged.
413
- *
414
- * @since 3.3.8
415
- *
416
- * @param array
417
- */
418
- $column_labels = apply_filters( 'wpmem_user_columns', $column_labels );
419
-
420
- $columns = array_merge( $columns, $column_labels );
421
- }
422
-
423
- // Makes WP-Members columns sortable.
424
- // @todo - finish debugging class or add sortable functions to users.php.
425
- // require_once( $wpmem->path . 'admin/includes/class-wp-members-sortable-user-columns.php' );
426
- // new WP_Members_Sortable_User_Columns( $wpmem_user_columns );
427
-
428
- return $columns;
429
- }
430
-
431
- /**
432
- * Function to add the user content to the custom column.
433
- *
434
- * @since 2.8.2
435
- *
436
- * @param $value
437
- * @param $column_name
438
- * @param $user_id
439
- * @return The user value for the custom column.
440
- */
441
- static function add_user_column_content( $value, $column_name, $user_id ) {
442
-
443
- // Is the column a WP-Members column?
444
- global $wpmem_user_columns, $wpmem;
445
- $is_wpmem = ( is_array( $wpmem_user_columns ) && array_key_exists( $column_name, $wpmem_user_columns ) ) ? true : false;
446
-
447
- if ( $is_wpmem ) {
448
-
449
- switch ( $column_name ) {
450
-
451
- case 'active':
452
- if ( 1 == $wpmem->mod_reg ) {
453
- // If the column is "active", then return the value or empty. Returning in here keeps us from displaying another value.
454
- return ( get_user_meta( $user_id , 'active', 'true' ) != 1 ) ? '<span class="dashicons dashicons-dismiss" style="color:red;"></span>' : '<span class="dashicons dashicons-yes-alt" style="color:green;"></span>';
455
- } else {
456
- return;
457
- }
458
- break;
459
-
460
- case '_wpmem_user_confirmed':
461
- if ( 1 == $wpmem->act_link ) {
462
- $user_confirmed = get_user_meta( $user_id , '_wpmem_user_confirmed', 'true' );
463
- return ( $user_confirmed ) ? date_i18n( get_option( 'date_format' ), $user_confirmed ) : __( 'Not confirmed', 'wp-members' );
464
- } else {
465
- return;
466
- }
467
- break;
468
-
469
- case 'user_url':
470
- case 'user_registered':
471
- // Unlike other fields, website/url is not a meta field.
472
- $user_info = get_userdata( $user_id );
473
- return $user_info->$column_name;
474
- break;
475
-
476
- case 'user_id':
477
- return $user_id;
478
-
479
- default:
480
- return get_user_meta( $user_id, $column_name, true );
481
- break;
482
- }
483
-
484
- }
485
-
486
- /**
487
- * Filter user column content.
488
- *
489
- * @since 3.3.8
490
- *
491
- * @param string $value
492
- * @param string $column_name
493
- * @param int $user_id
494
- */
495
- $value = apply_filters( 'wpmem_user_column_content', $value, $column_name, $user_id );
496
- return $value;
497
- }
498
-
499
- /**
500
- * Adjusts user query based on custom views.
501
- *
502
- * @since 2.8.3
503
- *
504
- * @todo Currently, not activated query returns users who are deactivated. This
505
- * may be confusing for admins, so work on a query that displays only
506
- * users who have never been activated.
507
- *
508
- * @param $user_search
509
- */
510
- static function pre_user_query( $user_search ) {
511
-
512
- global $wpdb;
513
- $show = sanitize_text_field( wpmem_get( 'show', '', 'get' ) );
514
- switch ( $show ) {
515
-
516
- case 'trial':
517
- case 'subscription':
518
- case 'pending':
519
- $replace_query = "WHERE 1=1 AND {$wpdb->users}.ID IN (
520
- SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
521
- WHERE {$wpdb->usermeta}.meta_key = 'exp_type'
522
- AND {$wpdb->usermeta}.meta_value = \"" . esc_sql( $show ) . "\" )";
523
- break;
524
-
525
- case 'expired':
526
- $replace_query = "WHERE 1=1 AND {$wpdb->users}.ID IN (
527
- SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
528
- WHERE {$wpdb->usermeta}.meta_key = 'expires'
529
- AND STR_TO_DATE( {$wpdb->usermeta}.meta_value, '%m/%d/%Y' ) < CURDATE()
530
- AND {$wpdb->usermeta}.meta_value != '01/01/1970' )";
531
- break;
532
-
533
- case 'active':
534
- case 'notactive':
535
- case 'notexported':
536
- case 'deactivated':
537
- default:
538
- $key = ( 'notactive' == $show || 'deactivated' == $show ) ? 'active' : 'exported';
539
- $in = ( 'deactivated' == $show ) ? 'IN' : 'NOT IN';
540
- $val = ( 'deactivated' == $show ) ? '0' : '1';
541
- if ( 'active' == $show ) {
542
- $key = 'active'; $in = 'IN';
543
- }
544
- $replace_query = "WHERE 1=1 AND {$wpdb->users}.ID " . esc_sql( $in ) . " (
545
- SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
546
- WHERE {$wpdb->usermeta}.meta_key = \"" . esc_sql( $key ) . "\"
547
- AND {$wpdb->usermeta}.meta_value = \"" . esc_sql( $val ) . "\" )";
548
- break;
549
- }
550
-
551
- $query_where = str_replace( 'WHERE 1=1', $replace_query, $user_search->query_where );
552
-
553
- /**
554
- * Filters the pre_user_query being applied.
555
- *
556
- * @since 3.3.0
557
- *
558
- * @param string $query_where
559
- */
560
- $query_where = apply_filters( 'wpmem_query_where', $query_where, $show );
561
-
562
- $user_search->query_where = $query_where;
563
- }
564
-
565
- /**
566
- * Use wpmem_post_register_data to set the user_status field to 2 using wp_update_user.
567
- * http://codex.wordpress.org/Function_Reference/wp_update_user
568
- *
569
- * @deprecated 3.3.6 No longer used.
570
- *
571
- * @uses wpmem_set_user_status
572
- * @param $fields
573
- */
574
- static function set_new_user_non_active( $fields ) {
575
- wpmem_set_user_status( $fields['ID'], 2 );
576
- return;
577
- }
578
-
579
- /**
580
- * Use wpmem_user_activated to set the user_status field to 0 using wp_update_user.
581
- *
582
- * @uses wpmem_set_user_status
583
- * @param $user_id
584
- */
585
- static function set_activated_user( $user_id ) {
586
- wpmem_set_user_status( $user_id, 0 );
587
- return;
588
- }
589
-
590
- /**
591
- * Use wpmem_user_deactivated to set the user_status field to 2 using wp_update_user.
592
- *
593
- * @uses wpmem_set_user_status
594
- * @param $user_id
595
- */
596
- static function set_deactivated_user( $user_id ) {
597
- wpmem_set_user_status( $user_id, 2 );
598
- return;
599
- }
600
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
601
  }
1
+ <?php
2
+ /**
3
+ * The WP_Members Admin Users Class.
4
+ *
5
+ * @package WP-Members
6
+ * @subpackage WP_Members Admin Users Object Class
7
+ * @since 3.3.0
8
+ */
9
+
10
+ // Exit if accessed directly.
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit();
13
+ }
14
+
15
+ class WP_Members_Admin_Users {
16
+
17
+ /**
18
+ * Function to add activate/export to the bulk dropdown list.
19
+ *
20
+ * @since 2.8.2
21
+ */
22
+ static function bulk_user_action() {
23
+ global $wpmem; ?>
24
+ <script type="text/javascript">
25
+ var $j = jQuery.noConflict();
26
+ $j(document).ready(function() {
27
+ <?php if( $wpmem->mod_reg == 1 ) { ?>
28
+ $j('<option>').val('activate').text('<?php _e( 'Activate', 'wp-members' )?>').appendTo("select[name='action']");
29
+ $j('<option>').val('deactivate').text('<?php _e( 'Deactivate', 'wp-members' )?>').appendTo("select[name='action']");
30
+ <?php } ?>
31
+ $j('<option>').val('export').text('<?php _e( 'Export', 'wp-members' )?>').appendTo("select[name='action']");
32
+ $j('<input id="export_all" name="export_all" class="button action" type="submit" value="<?php _e( 'Export All Users', 'wp-members' ); ?>" />').appendTo(".top .bulkactions");
33
+ <?php if( $wpmem->mod_reg == 1 ) { ?>
34
+ $j('<option>').val('activate').text('<?php _e( 'Activate', 'wp-members' )?>').appendTo("select[name='action2']");
35
+ $j('<option>').val('deactivate').text('<?php _e( 'Deactivate', 'wp-members' )?>').appendTo("select[name='action2']");
36
+ <?php } ?>
37
+ $j('<option>').val('export').text('<?php _e( 'Export', 'wp-members' )?>').appendTo("select[name='action2']");
38
+ $j('<input id="export_all" name="export_all" class="button action" type="submit" value="<?php _e( 'Export All Users', 'wp-members' ); ?>" />').appendTo(".bottom .bulkactions");
39
+ });
40
+ </script><?php
41
+ }
42
+
43
+ /**
44
+ * Function to add activate link to the user row action.
45
+ *
46
+ * @since 2.8.2
47
+ * @since 3.3.5 Updated to use wpmem_is_user_activated().
48
+ * @since 3.3.8 Added confirmation link, changed from insert_activate_link().
49
+ *
50
+ * @param array $actions
51
+ * @param $user_object
52
+ * @return array $actions
53
+ */
54
+ static function insert_hover_links( $actions, $user_object ) {
55
+ global $wpmem;
56
+ if ( $user_object->ID != get_current_user_id() ) {
57
+
58
+ if ( 1 == $wpmem->act_link ) {
59
+ if ( false === wpmem_is_user_confirmed( $user_object->ID ) ) {
60
+ $action = 'confirm';
61
+ $term = __( 'Confirm', 'wp-members' );
62
+ } else {
63
+ $action = 'unconfirm';
64
+ $term = __( 'Unconfirm', 'wp-members' );
65
+ }
66
+ $url = add_query_arg( array( 'action' => $action . '-single', 'user' => $user_object->ID ), "users.php" );
67
+ $url = wp_nonce_url( $url, 'confirm-user' );
68
+ $actions[ $action ] = '<a href="' . $url . '">' . $term . '</a>';
69
+
70
+ // Resend welcome email (will contain confirmation link if enabled).
71
+ //$actions['resend_welcome'] = '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'resend_welcome', 'user' => $user_object->ID ), "users.php" ), 'resend-welcome' ) . '">' . __( 'Resend welcome email', 'wp-members' ) . '</a>';
72
+ }
73
+
74
+ if ( 1 == $wpmem->mod_reg ) {
75
+ $is_active = wpmem_is_user_activated( $user_object->ID );
76
+
77
+ if ( false === $is_active ) {
78
+ $action = 'activate';
79
+ $term = __( 'Activate', 'wp-members' );
80
+ } else {
81
+ $action = 'deactivate';
82
+ $term = __( 'Deactivate', 'wp-members' );
83
+ }
84
+ $url = add_query_arg( array( 'action' => $action . '-single', 'user' => $user_object->ID ), "users.php" );
85
+ $url = wp_nonce_url( $url, 'activate-user' );
86
+ $actions[ $action ] = '<a href="' . $url . '">' . $term . '</a>';
87
+ }
88
+ }
89
+ return $actions;
90
+ }
91
+
92
+ /**
93
+ * Function to handle bulk actions at page load.
94
+ *
95
+ * @since 2.8.2
96
+ *
97
+ * @uses WP_Users_List_Table
98
+ *
99
+ * @global object $wpmem
100
+ */
101
+ static function page_load() {
102
+
103
+ global $wpmem;
104
+ if ( current_user_can( 'list_users' ) ) {
105
+ $wpmem->admin->user_search = new WP_Members_Admin_User_Search();
106
+ }
107
+
108
+ // If exporting all users, do it, then exit.
109
+ if ( current_user_can( 'list_users' ) && wpmem_get( 'export_all', false, 'request' ) ) {
110
+ $today = date( "Y-m-d" );
111
+ wpmem_export_users();
112
+ exit();
113
+ }
114
+
115
+ $wp_list_table = _get_list_table( 'WP_Users_List_Table' );
116
+ $action = $wp_list_table->current_action();
117
+ $sendback = '';
118
+
119
+ switch ( $action ) {
120
+
121
+ case 'activate':
122
+ case 'deactivate':
123
+
124
+ // Validate nonce.
125
+ check_admin_referer( 'bulk-users' );
126
+
127
+ // Get the users.
128
+ if ( isset( $_REQUEST['users'] ) ) {
129
+
130
+ $users = $_REQUEST['users'];
131
+
132
+ // Update the users.
133
+ $x = 0;
134
+ foreach ( $users as $user ) {
135
+ $user = filter_var( $user, FILTER_VALIDATE_INT );
136
+ // Current user cannot activate or deactivate themselves.
137
+ if ( $user != get_current_user_id() ) {
138
+ // Check to see if the user is already activated, if not, activate.
139
+ if ( 'activate' == $action && 1 != get_user_meta( $user, 'active', true ) ) {
140
+ wpmem_activate_user( $user );
141
+ } elseif( 'deactivate' == $action ) {
142
+ wpmem_deactivate_user( $user );
143
+ }
144
+ $x++;
145
+ }
146
+ }
147
+ $msg = ( 'activate' == $action ) ? urlencode( sprintf( __( '%s users activated', 'wp-members' ), $x ) ) : urlencode( sprintf( __( '%s users deactivated', 'wp-members' ), $x ) );
148
+
149
+ } else {
150
+ $msg = urlencode( __( 'No users selected', 'wp-members' ) );
151
+ }
152
+
153
+ // Set the return message.
154
+ $sendback = add_query_arg( array( 'activated' => $msg ), $sendback );
155
+ break;
156
+
157
+ case 'activate-single':
158
+ case 'deactivate-single':
159
+
160
+ // Validate nonce.
161
+ check_admin_referer( 'activate-user' );
162
+
163
+ // Get the users.
164
+ $user_id = filter_var( $_REQUEST['user'], FILTER_VALIDATE_INT );
165
+
166
+ // Check to see if the user is already activated, if not, activate.
167
+ if ( $user_id == get_current_user_id() ) {
168
+ $msg = urlencode( sprintf( esc_html__( 'You cannot activate or deactivate yourself', 'wp-members' ) ) );
169
+
170
+ } elseif ( 'activate-single' == $action && false === wpmem_is_user_activated( $user_id ) ) {
171
+ wpmem_activate_user( $user_id );
172
+ $user_info = get_userdata( $user_id );
173
+ $msg = urlencode( sprintf( esc_html__( "%s activated", 'wp-members' ), $user_info->user_login ) );
174
+
175
+ } elseif ( 'deactivate-single' == $action ) {
176
+ wpmem_deactivate_user( $user_id );
177
+ $user_info = get_userdata( $user_id );
178
+ $msg = urlencode( sprintf( esc_html__( "%s deactivated", 'wp-members' ), $user_info->user_login ) );
179
+
180
+ } else {
181
+ // Set the return message.
182
+ $msg = urlencode( __( "That user is already active", 'wp-members' ) );
183
+ }
184
+ $sendback = add_query_arg( array( 'activated' => $msg ), $sendback );
185
+ break;
186
+
187
+ case 'confirm-single':
188
+ case 'unconfirm-single':
189
+
190
+ // Validate nonce.
191
+ check_admin_referer( 'confirm-user' );
192
+
193
+ // Get the users.
194
+ $user_id = filter_var( $_REQUEST['user'], FILTER_VALIDATE_INT );
195
+
196
+ // Check to see if the user is already activated, if not, activate.
197
+ if ( $users == get_current_user_id() ) {
198
+ $msg = urlencode( sprintf( esc_html__( 'You cannot confirm or unconfirm yourself', 'wp-members' ) ) );
199
+
200
+ } elseif ( 'confirm-single' == $action && false === wpmem_is_user_confirmed( $user_id ) ) {
201
+ wpmem_set_user_as_confirmed( $user_id );
202
+ $user_info = get_userdata( $user_id );
203
+ $msg = urlencode( sprintf( esc_html__( "%s confirmed", 'wp-members' ), $user_info->user_login ) );
204
+
205
+ } elseif ( 'unconfirm-single' == $action ) {
206
+ wpmem_set_user_as_unconfirmed( $user_id );
207
+ $user_info = get_userdata( $user_id );
208
+ $msg = urlencode( sprintf( esc_html__( "%s unconfirmed", 'wp-members' ), $user_info->user_login ) );
209
+
210
+ } else {
211
+ // Set the return message.
212
+ $msg = urlencode( __( "That user is already confirmed", 'wp-members' ) );
213
+ }
214
+ $sendback = add_query_arg( array( 'activated' => $msg ), $sendback );
215
+ break;
216
+
217
+ case 'show':
218
+
219
+ add_action( 'pre_user_query', array( 'WP_Members_Admin_Users', 'pre_user_query' ) );
220
+ return;
221
+ break;
222
+
223
+ case 'export':
224
+
225
+ $users = wpmem_get( 'users', array(), 'request' );
226
+ wpmem_export_users( array( 'export'=>'selected' ), wpmem_sanitize_array( $users, 'integer' ) );
227
+ return;
228
+ break;
229
+
230
+ default:
231
+ return;
232
+ break;
233
+
234
+ }
235
+
236
+ /**
237
+ * Doing user action.
238
+ *
239
+ * @since 3.3.0
240
+ */
241
+ do_action( 'wpmem_user_action' );
242
+
243
+ // If we did not return already, we need to wp_safe_redirect.
244
+ wp_safe_redirect( $sendback );
245
+ exit();
246
+
247
+ }
248
+
249
+ /**
250
+ * Function to echo admin update message.
251
+ *
252
+ * @since 2.8.2
253
+ */
254
+ static function admin_notices() {
255
+
256
+ global $pagenow, $user_action_msg;
257
+ if( $pagenow == 'users.php' && isset( $_REQUEST['activated'] ) ) {
258
+ $message = esc_html( $_REQUEST['activated'] );
259
+ echo "<div class=\"updated\"><p>{$message}</p></div>";
260
+ }
261
+
262
+ if ( $user_action_msg ) {
263
+ echo "<div class=\"updated\"><p>{$user_action_msg}</p></div>";
264
+ }
265
+ }
266
+
267
+ /**
268
+ * Function to add user views to the top list.
269
+ *
270
+ * @since 2.8.2
271
+ * @since 3.1.2 Added user view counts as transient.
272
+ *
273
+ * @global object $wpdb
274
+ * @global object $wpmem
275
+ * @param array $views
276
+ * @return array $views
277
+ */
278
+ static function views( $views ) {
279
+
280
+ global $wpmem;
281
+
282
+ // Get the cached user counts.
283
+ $user_counts = get_transient( 'wpmem_user_counts' );
284
+
285
+ // check to see if data was successfully retrieved from the cache
286
+ if ( false === $user_counts ) {
287
+
288
+ // @todo For now, 5 minutes. We'll see how things go.
289
+ $transient_expires = 300; // Value in seconds, 1 day: ( 60 * 60 * 24 );
290
+
291
+ global $wpdb;
292
+
293
+ // We need a count of total users.
294
+ // @todo - need a more elegant way of this entire process.
295
+ $sql = "SELECT COUNT(*) FROM " . $wpdb->users;
296
+ $users = $wpdb->get_var( $sql );
297
+
298
+ // What needs to be counted?
299
+ $count_metas = array(
300
+ 'pending' => 'pending', // Used for PayPal Extension
301
+ 'trial' => 'trial', // Used for PayPal Extension
302
+ 'subscription' => 'subscription', // Used for PayPal Extension
303
+ 'expired' => 'expired', // Used for PayPal Extension
304
+ 'active' => 'active',
305
+ 'notactive' => 'active',
306
+ 'deactivated' => 'deactivated',
307
+ 'notexported' => 'exported',
308
+ 'confirmed' => '_wpmem_user_confirmed',
309
+ 'notconfirmed' => '_wpmem_user_confirmed',
310
+ );
311
+
312
+ // Handle various counts.
313
+ $user_counts = array();
314
+ foreach ( $count_metas as $key => $meta_key ) {
315
+ if ( 'confirmed' == $key || 'notconfirmed' == $key ) {
316
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM " . $wpdb->usermeta . " WHERE meta_key=%s AND meta_value>0", $meta_key ) );
317
+ $count = ( 'notconfirmed' == $key ) ? $users - $count : $count;
318
+ }
319
+ if ( 'active' == $key ) {
320
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM " . $wpdb->usermeta . " WHERE meta_key=%s AND meta_value=1", $meta_key ) );
321
+ }
322
+ if ( 'notactive' == $key || 'notexported' == $key ) {
323
+ $users_with_meta = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM " . $wpdb->usermeta . " WHERE meta_key=%s AND meta_value=1", $meta_key ) );
324
+ $count = $users - $users_with_meta;
325
+ }
326
+ if ( 'deactivated' == $key ) {
327
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM " . $wpdb->usermeta . " WHERE meta_key = 'active' AND meta_value = 0" );
328
+ }
329
+ if ( 'trial' == $key || 'subscription' == $key || 'pending' == $key ) {
330
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM " . $wpdb->usermeta . " WHERE meta_key = 'exp_type' AND meta_value = \"%s\"", $key ) );
331
+ }
332
+ if ( 'expired' == $key ) {
333
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM " . $wpdb->usermeta . " WHERE meta_key = 'expires' AND STR_TO_DATE( meta_value, '%m/%d/%Y' ) < CURDATE() AND meta_value != '01/01/1970'" );
334
+ }
335
+ $user_counts[ $key ] = $count;
336
+ }
337
+ set_transient( 'wpmem_user_counts', $user_counts, $transient_expires );
338
+ }
339
+
340
+ if ( defined( 'WPMEM_EXP_MODULE' ) && 1 == $wpmem->use_exp ) {
341
+ $views['pending'] = __( 'Pending', 'wp-members' );
342
+ $views['trial'] = __( 'Trial', 'wp-members' );
343
+ $views['subscription'] = __( 'Subscription', 'wp-members' );
344
+ $views['expired'] = __( 'Expired', 'wp-members' );
345
+ }
346
+ if ( 1 == $wpmem->mod_reg ) {
347
+ $views['active'] = __( 'Activated', 'wp-members' );
348
+ $views['notactive'] = __( 'Pending Activation', 'wp-members' );
349
+ $views['deactivated'] = __( 'Deactivated', 'wp-members' );
350
+ }
351
+ if ( 1 == $wpmem->act_link ) {
352
+ $views['confirmed'] = __( 'Confirmed', 'wp-members' );
353
+ $views['notconfirmed'] = __( 'Not Confirmed', 'wp-members' );
354
+ }
355
+ $views['notexported'] = __( 'Not Exported', 'wp-members' );
356
+ $show = sanitize_text_field( wpmem_get( 'show', false, 'get' ) );
357
+
358
+ foreach ( $views as $key => $view ) {
359
+ if ( isset( $user_counts[ $key ] ) ) {
360
+ $link = "users.php?action=show&amp;show=" . $key;
361
+ $current = ( $show == $key ) ? ' class="current"' : '';
362
+ $views[ $key ] = sprintf(
363
+ '<a href="%s" %s>%s <span class="count">(%d)</span></a>',
364
+ esc_url( $link ),
365
+ $current,
366
+ $view,
367
+ isset( $user_counts[ $key ] ) ? $user_counts[ $key ] : ''
368
+ );
369
+ }
370
+ }
371
+
372
+ /**
373
+ * Filters all views before returning to the WP 'views_users' filter.
374
+ *
375
+ * @since 3.3.0
376
+ *
377
+ * @param array $views {
378
+ *
379
+ * @type string The HTML for the view.
380
+ * }
381
+ */
382
+ $views = apply_filters( 'wpmem_views_users', $views, $show );
383
+
384
+ return $views;
385
+ }
386
+
387
+ /**
388
+ * Function to add custom user columns to the user table.
389
+ *
390
+ * @since 2.8.2
391
+ *
392
+ * @param array $columns
393
+ * @return array $columns
394
+ */
395
+ static function add_user_column( $columns ) {
396
+
397
+ global $wpmem_user_columns, $wpmem;
398
+
399
+ // Get any columns to be added to the Users > All Users screen.
400
+ $wpmem_user_columns = get_option( 'wpmembers_utfields' );
401
+
402
+ if ( $wpmem_user_columns ) {
403
+ $column_labels = array();
404
+ if ( 1 != $wpmem->mod_reg ) {
405
+ unset( $wpmem_user_columns['active'] );
406
+ }
407
+
408
+ // @todo This is a workaround so that wpmembers_utfields doesn't have to be updated.
409
+ if ( isset( $wpmem_user_columns['active'] ) ) {
410
+ $wpmem_user_columns['active'] = __( 'Activated', 'wp-members' );
411
+ }
412
+
413
+ if ( 1 != $wpmem->act_link ) {
414
+ unset( $wpmem_user_columns['_wpmem_user_confirmed'] );
415
+ }
416
+
417
+ // @todo Need to eventually change the wpmembers_utfields setting so we don't have to do it this way.
418
+ $fields = wpmem_fields();
419
+ foreach ( $wpmem_user_columns as $key => $value ) {
420
+ $column_labels[ $key ] = ( isset( $fields[ $key ] ) ) ? $fields[ $key ]['label'] : $value;
421
+ }
422
+
423
+ /**
424
+ * Filter the User > All Users custom columns before they are merged.
425
+ *
426
+ * @since 3.3.8
427
+ *
428
+ * @param array
429
+ */
430
+ $column_labels = apply_filters( 'wpmem_user_columns', $column_labels );
431
+
432
+ $columns = array_merge( $columns, $column_labels );
433
+ }
434
+
435
+ // Makes WP-Members columns sortable.
436
+ // @todo - finish debugging class or add sortable functions to users.php.
437
+ // require_once( $wpmem->path . 'admin/includes/class-wp-members-sortable-user-columns.php' );
438
+ // new WP_Members_Sortable_User_Columns( $wpmem_user_columns );
439
+
440
+ return $columns;
441
+ }
442
+
443
+ /**
444
+ * Function to add the user content to the custom column.
445
+ *
446
+ * @since 2.8.2
447
+ *
448
+ * @param $value
449
+ * @param $column_name
450
+ * @param $user_id
451
+ * @return The user value for the custom column.
452
+ */
453
+ static function add_user_column_content( $value, $column_name, $user_id ) {
454
+
455
+ // Is the column a WP-Members column?
456
+ global $wpmem_user_columns, $wpmem;
457
+ $is_wpmem = ( is_array( $wpmem_user_columns ) && array_key_exists( $column_name, $wpmem_user_columns ) ) ? true : false;
458
+
459
+ if ( $is_wpmem ) {
460
+
461
+ switch ( $column_name ) {
462
+
463
+ case 'active':
464
+ if ( 1 == $wpmem->mod_reg ) {
465
+ // If the column is "active", then return the value or empty. Returning in here keeps us from displaying another value.
466
+ return ( get_user_meta( $user_id , 'active', 'true' ) != 1 ) ? '<span class="dashicons dashicons-dismiss" style="color:red;"></span>' : '<span class="dashicons dashicons-yes-alt" style="color:green;"></span>';
467
+ } else {
468
+ return;
469
+ }
470
+ break;
471
+
472
+ case '_wpmem_user_confirmed':
473
+ if ( 1 == $wpmem->act_link ) {
474
+ $user_confirmed = get_user_meta( $user_id , '_wpmem_user_confirmed', 'true' );
475
+ return ( $user_confirmed ) ? date_i18n( get_option( 'date_format' ), $user_confirmed ) : __( 'Not confirmed', 'wp-members' );
476
+ } else {
477
+ return;
478
+ }
479
+ break;
480
+
481
+ case 'user_url':
482
+ case 'user_registered':
483
+ // Unlike other fields, website/url is not a meta field.
484
+ $user_info = get_userdata( $user_id );
485
+ return $user_info->$column_name;
486
+ break;
487
+
488
+ case 'user_id':
489
+ return $user_id;
490
+
491
+ default:
492
+ return get_user_meta( $user_id, $column_name, true );
493
+ break;
494
+ }
495
+
496
+ }
497
+
498
+ /**
499
+ * Filter user column content.
500
+ *
501
+ * @since 3.3.8
502
+ *
503
+ * @param string $value
504
+ * @param string $column_name
505
+ * @param int $user_id
506
+ */
507
+ $value = apply_filters( 'wpmem_user_column_content', $value, $column_name, $user_id );
508
+ return $value;
509
+ }
510
+
511
+ /**
512
+ * Adjusts user query based on custom views.
513
+ *
514
+ * @since 2.8.3
515
+ *
516
+ * @todo Currently, not activated query returns users who are deactivated. This
517
+ * may be confusing for admins, so work on a query that displays only
518
+ * users who have never been activated.
519
+ *
520
+ * @param $user_search
521
+ */
522
+ static function pre_user_query( $user_search ) {
523
+
524
+ global $wpdb;
525
+ $show = sanitize_text_field( wpmem_get( 'show', '', 'get' ) );
526
+ switch ( $show ) {
527
+
528
+ case 'trial':
529
+ case 'subscription':
530
+ case 'pending':
531
+ $replace_query = "WHERE 1=1 AND {$wpdb->users}.ID IN (
532
+ SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
533
+ WHERE {$wpdb->usermeta}.meta_key = 'exp_type'
534
+ AND {$wpdb->usermeta}.meta_value = \"" . esc_sql( $show ) . "\" )";
535
+ break;
536
+
537
+ case 'expired':
538
+ $replace_query = "WHERE 1=1 AND {$wpdb->users}.ID IN (
539
+ SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
540
+ WHERE {$wpdb->usermeta}.meta_key = 'expires'
541
+ AND STR_TO_DATE( {$wpdb->usermeta}.meta_value, '%m/%d/%Y' ) < CURDATE()
542
+ AND {$wpdb->usermeta}.meta_value != '01/01/1970' )";
543
+ break;
544
+
545
+ case 'confirmed':
546
+ case 'notconfirmed':
547
+ $in = ( 'confirmed' == $show ) ? 'IN' : 'NOT IN';
548
+ $replace_query = "WHERE 1=1 AND {$wpdb->users}.ID " . esc_sql( $in ) . " (
549
+ SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
550
+ WHERE {$wpdb->usermeta}.meta_key = \"" . esc_sql( '_wpmem_user_confirmed' ) . "\" )";
551
+ break;
552
+
553
+ case 'active':
554
+ case 'notactive':
555
+ case 'notexported':
556
+ case 'deactivated':
557
+ default:
558
+ $key = ( 'notactive' == $show || 'deactivated' == $show ) ? 'active' : 'exported';
559
+ $in = ( 'deactivated' == $show ) ? 'IN' : 'NOT IN';
560
+ $val = ( 'deactivated' == $show ) ? '0' : '1';
561
+ if ( 'active' == $show ) {
562
+ $key = 'active'; $in = 'IN';
563
+ }
564
+ $replace_query = "WHERE 1=1 AND {$wpdb->users}.ID " . esc_sql( $in ) . " (
565
+ SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
566
+ WHERE {$wpdb->usermeta}.meta_key = \"" . esc_sql( $key ) . "\"
567
+ AND {$wpdb->usermeta}.meta_value = \"" . esc_sql( $val ) . "\" )";
568
+ break;
569
+ }
570
+
571
+ $query_where = str_replace( 'WHERE 1=1', $replace_query, $user_search->query_where );
572
+
573
+ /**
574
+ * Filters the pre_user_query being applied.
575
+ *
576
+ * @since 3.3.0
577
+ *
578
+ * @param string $query_where
579
+ */
580
+ $query_where = apply_filters( 'wpmem_query_where', $query_where, $show );
581
+
582
+ $user_search->query_where = $query_where;
583
+ }
584
+
585
+ /**
586
+ * Use wpmem_post_register_data to set the user_status field to 2 using wp_update_user.
587
+ * http://codex.wordpress.org/Function_Reference/wp_update_user
588
+ *
589
+ * @deprecated 3.3.6 No longer used.
590
+ *
591
+ * @uses wpmem_set_user_status
592
+ * @param $fields
593
+ */
594
+ static function set_new_user_non_active( $fields ) {
595
+ wpmem_set_user_status( $fields['ID'], 2 );
596
+ return;
597
+ }
598
+
599
+ /**
600
+ * Use wpmem_user_activated to set the user_status field to 0 using wp_update_user.
601
+ *
602
+ * @uses wpmem_set_user_status
603
+ * @param $user_id
604
+ */
605
+ static function set_activated_user( $user_id ) {
606
+ wpmem_set_user_status( $user_id, 0 );
607
+ return;
608
+ }
609
+
610
+ /**
611
+ * Use wpmem_user_deactivated to set the user_status field to 2 using wp_update_user.
612
+ *
613
+ * @uses wpmem_set_user_status
614
+ * @param $user_id
615
+ */
616
+ static function set_deactivated_user( $user_id ) {
617
+ wpmem_set_user_status( $user_id, 2 );
618
+ return;
619
+ }
620
+
621
  }
includes/admin/class-wp-members-export.php DELETED
@@ -1,219 +0,0 @@
1
- <?php
2
- /**
3
- * The WP_Members Export Class.
4
- *
5
- * @package WP-Members
6
- * @subpackage WP_Members Export Object Class
7
- * @since 3.3.0
8
- */
9
-
10
- // Exit if accessed directly.
11
- if ( ! defined( 'ABSPATH' ) ) {
12
- exit();
13
- }
14
-
15
- class WP_Members_Export {
16
-
17
- /**
18
- * New export function to export all or selected users
19
- *
20
- * @since 2.9.7
21
- * @since 3.2.0 Updated to use fputcsv.
22
- * @since 3.2.1 Added user data filters.
23
- * @since 3.3.0 Moved to new object class as static method.
24
- *
25
- * @param array $args
26
- * @param array $users
27
- */
28
- static function export_users( $args, $users = array() ) {
29
-
30
- global $wpmem;
31
-
32
- $wpmem_fields = wpmem_fields();
33
-
34
- // Prepare fields, add additional "special" fields.
35
- $export_fields = array(
36
- 'ID' => __( 'User ID', 'wp-members' ),
37
- 'username' => __( 'Username', 'wp-members' ),
38
- );
39
- foreach( $wpmem_fields as $meta_key => $value ) {
40
- $export_fields[ $meta_key ] = $value['label'];
41
- }
42
- if ( 1 == $wpmem->mod_reg ) {
43
- $export_fields['active'] = __( 'Activated?', 'wp-members' );
44
- }
45
- if ( defined( 'WPMEM_EXP_MODULE' ) && 1 == $wpmem->use_exp ) {
46
- $export_fields['exp_type'] = __( 'Subscription', 'wp-members' );
47
- $export_fields['expires'] = __( 'Expires', 'wp-members' );
48
- }
49
- $export_fields['user_registered'] = __( 'Registered', 'wp-members' );
50
- $export_fields['wpmem_reg_ip'] = __( 'IP', 'wp-members' );
51
- if ( 1 == $wpmem->enable_products ) {
52
- foreach( $wpmem->membership->products as $product_key => $product ) {
53
- $export_fields[ $wpmem->membership->post_stem . $product_key ] = $wpmem->membership->products[ $product_key ]['title'];
54
- }
55
- }
56
-
57
- /**
58
- * Filter the export fields.
59
- *
60
- * @since 3.2.5
61
- *
62
- * @param array $export_fields {
63
- * The array of export fields is keyed as 'heading value' => 'meta_key'.
64
- * The array will include all fields in the Fields tab, plus the following:
65
- *
66
- * @type int $ID ID from wp_users
67
- * @type string $username user_login from wp_users
68
- * @type string $user_nicename user_nicename
69
- * @type string $user_url user_url
70
- * @type string $display_name display_name
71
- * @type int $active Whether the user is active/deactivated.
72
- * @type string $exp_type If the PayPal extension is installed pending|subscrption (optional)
73
- * @type string $expires If the PayPal extension is installed MM/DD/YYYY (optional)
74
- * @type string $user_registered user_registered
75
- * @type string $user_ip The IP of the user when they registered.
76
- }
77
- */
78
- $export_fields = apply_filters( 'wpmem_export_fields', $export_fields );
79
-
80
- $today = date( "Y-m-d" );
81
-
82
- // Setup defaults.
83
- $defaults = array(
84
- 'export' => 'all',
85
- 'filename' => 'wp-members-user-export-' . $today . '.csv',
86
- 'export_fields' => $export_fields,
87
- 'exclude_fields' => array( 'password', 'confirm_password', 'confirm_email' ),
88
- 'entity_decode' => false,
89
- 'date_format' => 'Y-m-d',
90
- );
91
-
92
- /**
93
- * Filter the default export arguments.
94
- *
95
- * @since 2.9.7
96
- *
97
- * @param array $args {
98
- * Array of defaults for export.
99
- *
100
- * @type string $export
101
- * @type string $filename
102
- * @type array $export_fields
103
- * @type array $exclude_fields
104
- * @type boolean $entity_decode
105
- * @type string $date_format
106
- * }
107
- */
108
- $args = wp_parse_args( apply_filters( 'wpmem_export_args', $args ), $defaults );
109
-
110
- // Output needs to be buffered, start the buffer.
111
- ob_start();
112
-
113
- // If exporting all, get all of the users.
114
- $export_users = ( 'all' == $args['export'] ) ? get_users( array( 'fields' => 'ID' ) ) : $users;
115
-
116
- // Generate headers and a filename based on date of export.
117
- header( "Content-Description: File Transfer" );
118
- header( "Content-type: application/octet-stream" );
119
- header( "Content-Disposition: attachment; filename=" . $args['filename'] );
120
- header( "Content-Type: text/csv; charset=" . get_option( 'blog_charset' ), true );
121
-
122
- $handle = fopen( 'php://output', 'w' );
123
- fputs( $handle, "\xEF\xBB\xBF" ); // UTF-8 BOM
124
-
125
- // Remove excluded fields from $export_fields while setting up $header array.
126
- $header = array();
127
- foreach ( $export_fields as $meta => $field ) {
128
- if ( in_array( $meta, $args['exclude_fields'] ) ) {
129
- unset( $export_fields[ $meta ] );
130
- } else {
131
- $header[ $meta ] = $field;
132
- }
133
- }
134
-
135
- /**
136
- * Filters user export header row before assembly.
137
- *
138
- * @since 3.2.1
139
- *
140
- * @param array $header The header column values
141
- */
142
- $header = apply_filters( 'wpmem_user_export_header', $header );
143
-
144
- fputcsv( $handle, $header );
145
-
146
- // Loop through the array of users, assemble csv.
147
- // $export_fields only includes fields to be exported at this point.
148
- foreach ( $export_users as $user ) {
149
-
150
- $user_info = get_userdata( $user );
151
-
152
- $wp_user_fields = [ 'username', 'user_email', 'user_nicename', 'user_url', 'display_name' ];
153
- foreach ( $export_fields as $meta => $field ) {
154
- switch ( $meta ) {
155
- case 'ID':
156
- $row[ $meta ] = $user_info->ID;
157
- break;
158
- case 'username':
159
- $row[ $meta ] = $user_info->user_login;
160
- break;
161
- case 'active':
162
- $row[ $meta ] = get_user_meta( $user, 'active', 1 ) ? __( 'Yes' ) : __( 'No' );
163
- break;
164
- case 'exp_type':
165
- $row['exp_type'] = get_user_meta( $user, 'exp_type', true );
166
- break;
167
- case 'expires':
168
- $row['expires'] = get_user_meta( $user, 'expires', true );
169
- break;
170
- case 'user_registered':
171
- $row['user_registered'] = $user_info->user_registered;
172
- break;
173
- case 'wpmem_reg_ip':
174
- $row['wpmem_reg_ip'] = get_user_meta( $user, 'wpmem_reg_ip', true );
175
- break;
176
- case ( $wpmem->membership->post_stem === substr( $meta, 0, strlen( $wpmem->membership->post_stem ) ) ):
177
- $product = str_replace( $wpmem->membership->post_stem, '', $meta );
178
- $row[ $meta ] = get_user_meta( $user, $meta, true );
179
- // If value is a date and false is not the format_date option...
180
- if ( false !== $args['date_format'] && '' != $row[ $meta ] && $row[ $meta ] > 2 ) {
181
- $date_format = ( 'wp' == $args['date_format'] ) ? get_option('date_format') : $args['date_format'];
182
- $row[ $meta ] = date( $date_format, $row[ $meta ] );
183
- }
184
- break;
185
- default:
186
- if ( in_array( $meta, $wp_user_fields ) ) {
187
- $row[ $meta ] = ( 'username' == $meta ) ? $user_info->user_login : $user_info->{$meta};
188
- } else {
189
- $raw_data = get_user_meta( $user, $meta, true );
190
- $row[ $meta ] = ( $args['entity_decode'] ) ? html_entity_decode( $raw_data ) : $raw_data;
191
- }
192
- break;
193
- }
194
- }
195
-
196
- /**
197
- * Filter the user data before assembly.
198
- *
199
- * @since 3.2.1
200
- *
201
- * @param array $row The user data row
202
- */
203
- $row = apply_filters( 'wpmem_user_export_row', $row );
204
-
205
- fputcsv( $handle, $row );
206
-
207
- // Update the user record as being exported.
208
- if ( 'all' != $args['export'] ) {
209
- update_user_meta( $user, 'exported', 1 );
210
- }
211
- }
212
-
213
- fclose( $handle );
214
- print( ob_get_clean() );
215
-
216
- exit();
217
- }
218
-
219
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/admin/class-wp-members-products-admin.php CHANGED
@@ -33,6 +33,7 @@ class WP_Members_Products_Admin {
33
  add_action( 'admin_footer', array( $this, 'enqueue_select2' ) );
34
  add_filter( 'manage_users_columns', array( $this, 'user_columns' ) );
35
  add_filter( 'manage_users_custom_column', array( $this, 'user_columns_content' ), 10, 3 );
 
36
  add_filter( 'manage_posts_columns', array( $this, 'post_columns' ) );
37
  add_action( 'manage_posts_custom_column', array( $this, 'post_columns_content' ), 10, 2 );
38
  add_filter( 'manage_pages_columns', array( $this, 'post_columns' ) );
@@ -44,6 +45,9 @@ class WP_Members_Products_Admin {
44
 
45
  add_filter( 'wpmem_user_profile_tabs', array( $this, 'user_profile_tabs' ), 1 );
46
  add_action( 'wpmem_user_profile_tabs_content', array( $this, 'user_profile_tab_content' ), 10 );
 
 
 
47
  }
48
 
49
  $this->default_products = $wpmem->membership->get_default_products();
@@ -352,8 +356,16 @@ class WP_Members_Products_Admin {
352
  * @since 3.3.5
353
  */
354
  do_action( 'wpmem_membership_product_message_meta_before' );
355
- echo '<label for="product_message">' . __( 'Restricted Message (displays when a user does not have access to a membership)', 'wp-members' ) . '</label>';
356
- echo '<textarea name="product_message" id="product_message" rows="3" cols="50" id="" class="large-text code">' . $message . '</textarea>';
 
 
 
 
 
 
 
 
357
  /**
358
  * Fires after membership product messate meta box.
359
  *
@@ -488,7 +500,7 @@ class WP_Members_Products_Admin {
488
  'type' => 'multiselect',
489
  'value' => $values,
490
  'compare' => $product,
491
- 'class' => 'wpmem-product-select2',
492
  ) );
493
  }
494
 
@@ -529,13 +541,24 @@ class WP_Members_Products_Admin {
529
  <script language="javascript">
530
  (function($) {
531
  $(document).ready(function() {
532
- $('.wpmem-product-select2').select2();
533
  });
534
  })(jQuery);
535
  </script><?php
536
  }
537
  }
538
 
 
 
 
 
 
 
 
 
 
 
 
539
  /**
540
  * Add membership product column to post table.
541
  *
@@ -610,6 +633,20 @@ class WP_Members_Products_Admin {
610
  * @return array $display
611
  */
612
  function user_columns_content( $val, $column_name, $user_id ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
613
  if ( 'wpmem_product' == $column_name ) {
614
  global $wpmem;
615
  $display = array();
@@ -617,8 +654,8 @@ class WP_Members_Products_Admin {
617
  if ( $user_products ) {
618
  foreach ( $user_products as $meta => $value ) {
619
  if ( isset( $wpmem->membership->products[ $meta ]['title'] ) ) {
620
- $expires = ( $user_products[ $meta ] > 1 ) ? ' expires: ' . date_i18n( get_option( 'date_format' ), $user_products[ $meta ] ) : '';
621
- $display[] = $wpmem->membership->products[ $meta ]['title'] . $expires;
622
  }
623
  }
624
  }
@@ -632,7 +669,7 @@ class WP_Members_Products_Admin {
632
  * @param int $user_id
633
  * @param array $user_products
634
  */
635
- return apply_filters( 'wpmem_user_columns_membership_value', implode( "<br />", $display ), $display, $user_id, $user_products );
636
  }
637
  return $val;
638
  }
@@ -672,58 +709,141 @@ class WP_Members_Products_Admin {
672
  * logged in when checking profiles.
673
  */
674
  $user_id = ( 'profile' == $pagenow && current_user_can( 'edit_users' ) ) ? get_current_user_id() : sanitize_text_field( wpmem_get( 'user_id', false, 'get' ) );
675
- $user_products = $wpmem->user->get_user_products( $user_id );
676
- echo '<h3>' . __( 'Product Access', 'wp-members' ) . '</h3>';
677
- echo '<table>
678
- <tr>
679
- <th>' . __( 'Status', 'wp-members' ) . '</th>
680
- <th>' . __( 'Membership', 'wp-members' ) . '</th>
681
- <th>' . __( 'Enabled?', 'wp-members' ) . '</th>
682
- <th>' . __( 'Expires', 'wp-members' ) . '</th>
683
- </tr>'; ?>
684
- <?php
685
- foreach ( $wpmem->membership->products as $key => $value ) {
686
- $checked = ( $user_products && array_key_exists( $key, $user_products ) ) ? "checked" : "";
687
- echo "<tr>";
688
- echo '<td style="padding:5px 5px;">
689
- <select name="_wpmem_membership_product[' . $key . ']">
690
- <option value="">----</option>
691
- <option value="enable">' . __( 'Enable', 'wp-members' ) . '</option>
692
- <option value="disable">' . __( 'Disable', 'wp-members' ) . '</option>
693
- </select></td><td style="padding:0px 0px;">' . $value['title'] . '</td>';
694
-
695
- // If user has date, display that; otherwise placeholder
696
- $date_value = ( isset( $user_products[ $key ] ) && 1 != $user_products[ $key ] && 0 != $user_products[ $key ] && '' != $user_products[ $key ] ) ? date( 'Y-m-d', $user_products[ $key ] ) : "";
697
- $placeholder = ( ! isset( $user_products[ $key ] ) ) ? 'placeholder="' . __( 'Expiration date (optional)', 'wp-members' ) . '" ' : '';
698
- $product_date_field = ' <input type="text" name="_wpmem_membership_expiration_' . $key . '" value="' . $date_value . '" class="wpmem_datepicker" ' . $placeholder . ' />';
699
-
700
- if ( isset( $user_products[ $key ] ) ) {
701
- echo '<td align="center"><span id="wpmem_product_enabled" class="dashicons dashicons-yes"></span></td>';
702
- if ( $user_products[ $key ] != 1 ) {
703
- echo '<td>' . $product_date_field . '</td>';
704
- } else {
705
- echo '<td>&nbsp;</td>';
706
- }
707
- } else {
708
- if ( isset( $value['expires'] ) && ! empty( $value['expires'] ) ) {
709
- echo '<td><span id="wpmem_product_enabled" class="dashicons"></span></td>';
710
- echo '<td>' . $product_date_field . '</td>';
 
 
 
711
  } else {
712
- echo '<td>&nbsp;</td>';
713
- }
714
- }
715
- echo '</tr>';
716
- }
 
 
 
 
717
 
718
- ?></table>
719
- <script>
720
- jQuery(function() {
721
- jQuery( ".wpmem_datepicker" ).datepicker({
722
- dateFormat : "yy-mm-dd"
 
723
  });
724
- });
725
- </script>
726
- <?php
 
 
727
  }
728
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
729
  }
33
  add_action( 'admin_footer', array( $this, 'enqueue_select2' ) );
34
  add_filter( 'manage_users_columns', array( $this, 'user_columns' ) );
35
  add_filter( 'manage_users_custom_column', array( $this, 'user_columns_content' ), 10, 3 );
36
+ add_action( 'admin_head', array( $this, 'post_columns_width' ) );
37
  add_filter( 'manage_posts_columns', array( $this, 'post_columns' ) );
38
  add_action( 'manage_posts_custom_column', array( $this, 'post_columns_content' ), 10, 2 );
39
  add_filter( 'manage_pages_columns', array( $this, 'post_columns' ) );
45
 
46
  add_filter( 'wpmem_user_profile_tabs', array( $this, 'user_profile_tabs' ), 1 );
47
  add_action( 'wpmem_user_profile_tabs_content', array( $this, 'user_profile_tab_content' ), 10 );
48
+
49
+ add_filter( 'wpmem_views_users', array( $this, 'user_views' ), 10, 2 );
50
+ add_filter( 'wpmem_query_where', array( $this, 'query_where' ), 10, 2 );
51
  }
52
 
53
  $this->default_products = $wpmem->membership->get_default_products();
356
  * @since 3.3.5
357
  */
358
  do_action( 'wpmem_membership_product_message_meta_before' );
359
+
360
+ echo '<p>' . __( 'Restricted Message (displays when a user does not have access to a membership)', 'wp-members' ) . '</p>';
361
+
362
+ $args = array(
363
+ 'media_buttons' => false,
364
+ 'textarea_rows' => 10,
365
+ );
366
+
367
+ wp_editor( $message, 'product_message', $args );
368
+
369
  /**
370
  * Fires after membership product messate meta box.
371
  *
500
  'type' => 'multiselect',
501
  'value' => $values,
502
  'compare' => $product,
503
+ 'class' => 'wpmem-product-select2 populate placeholder',
504
  ) );
505
  }
506
 
541
  <script language="javascript">
542
  (function($) {
543
  $(document).ready(function() {
544
+ $('.wpmem-product-select2').select2({width:"100%"});
545
  });
546
  })(jQuery);
547
  </script><?php
548
  }
549
  }
550
 
551
+ /**
552
+ * Styles the width for membership post column.
553
+ *
554
+ * @since 3.4.0
555
+ */
556
+ function post_columns_width() {
557
+ if ( isset( $_REQUEST['post_type'] ) ) {
558
+ echo '<style>.column-wpmem_product{ min-width:140px; width: 12%;}</style>';
559
+ }
560
+ }
561
+
562
  /**
563
  * Add membership product column to post table.
564
  *
633
  * @return array $display
634
  */
635
  function user_columns_content( $val, $column_name, $user_id ) {
636
+ /**
637
+ * Filter the users > all users screen membership column default html.
638
+ *
639
+ * @since 3.4.0
640
+ *
641
+ * @param array $defaults
642
+ * @param array $val
643
+ * @param array $column_name
644
+ * @param array $user_id
645
+ */
646
+ $defaults = apply_filters( 'wpmem_user_columns_membership_defaults', array(
647
+ 'item_wrap_before' => '<div class="wpmem-user-table-membership">',
648
+ 'item_wrap_after' => '</div>',
649
+ ), $val, $column_name, $user_id );
650
  if ( 'wpmem_product' == $column_name ) {
651
  global $wpmem;
652
  $display = array();
654
  if ( $user_products ) {
655
  foreach ( $user_products as $meta => $value ) {
656
  if ( isset( $wpmem->membership->products[ $meta ]['title'] ) ) {
657
+ $expires = ( $user_products[ $meta ] > 1 ) ? '<br />' . __( 'expires:', 'wp-members' ) . ' ' . date_i18n( get_option( 'date_format' ), $user_products[ $meta ] ) : '';
658
+ $display[] = $defaults['item_wrap_before'] . $wpmem->membership->products[ $meta ]['title'] . $expires . $defaults['item_wrap_after'];
659
  }
660
  }
661
  }
669
  * @param int $user_id
670
  * @param array $user_products
671
  */
672
+ return apply_filters( 'wpmem_user_columns_membership_value', implode( " ", $display ), $display, $user_id, $user_products );
673
  }
674
  return $val;
675
  }
709
  * logged in when checking profiles.
710
  */
711
  $user_id = ( 'profile' == $pagenow && current_user_can( 'edit_users' ) ) ? get_current_user_id() : sanitize_text_field( wpmem_get( 'user_id', false, 'get' ) );
712
+ $user_products = wpmem_get_user_products( $user_id );
713
+ echo '<h3>' . __( 'Membership Access', 'wp-members' ) . '</h3>';
714
+ if ( ! empty( $wpmem->membership->products ) ) {
715
+ $expires_heading = "&nbsp;";
716
+ foreach( $wpmem->membership->products as $key => $value ) {
717
+ $expires_heading = ( ! empty( $value['expires'] ) ) ? __( 'Expires', 'wp-members' ) : $expires_heading;
718
+ }
719
+ echo '<table>
720
+ <tr>
721
+ <th>' . __( 'Action', 'wp-members' ) . '</th>
722
+ <th>' . __( 'Membership', 'wp-members' ) . '</th>
723
+ <th>' . __( 'Enabled?', 'wp-members' ) . '</th>
724
+ <th>' . $expires_heading . '</th>
725
+ </tr>'; ?>
726
+ <?php
727
+
728
+ foreach ( $wpmem->membership->products as $key => $value ) {
729
+ $checked = ( $user_products && array_key_exists( $key, $user_products ) ) ? "checked" : "";
730
+ echo "<tr>";
731
+ echo '<td style="padding:5px 5px;">
732
+ <select name="_wpmem_membership_product[' . $key . ']">
733
+ <option value="">----</option>
734
+ <option value="enable">' . __( 'Enable', 'wp-members' ) . '</option>
735
+ <option value="disable">' . __( 'Disable', 'wp-members' ) . '</option>
736
+ <option value="enable">' . __( 'Update', 'wp-members' ) . '</option>
737
+ </select></td><td style="padding:0px 0px;">' . $value['title'] . '</td>';
738
+
739
+ // If user has date, display that; otherwise placeholder
740
+ $date_value = ( isset( $user_products[ $key ] ) && 1 != $user_products[ $key ] && 0 != $user_products[ $key ] && '' != $user_products[ $key ] ) ? date( 'Y-m-d', $user_products[ $key ] ) : "";
741
+ $placeholder = ( ! isset( $user_products[ $key ] ) ) ? 'placeholder="' . __( 'Expiration date (optional)', 'wp-members' ) . '" ' : '';
742
+ $product_date_field = ' <input type="text" name="_wpmem_membership_expiration_' . $key . '" value="' . $date_value . '" class="wpmem_datepicker" ' . $placeholder . ' />';
743
+
744
+ if ( isset( $user_products[ $key ] ) ) {
745
+ echo '<td align="center"><span id="wpmem_product_enabled" class="dashicons dashicons-yes"></span></td>';
746
+ if ( $user_products[ $key ] != 1 ) {
747
+ echo '<td>' . $product_date_field . '</td>';
748
+ } else {
749
+ echo '<td>&nbsp;</td>';
750
+ }
751
  } else {
752
+ if ( isset( $value['expires'] ) && ! empty( $value['expires'] ) ) {
753
+ echo '<td><span id="wpmem_product_enabled" class="dashicons"></span></td>';
754
+ echo '<td>' . $product_date_field . '</td>';
755
+ } else {
756
+ echo '<td>&nbsp;</td>';
757
+ }
758
+ }
759
+ echo '</tr>';
760
+ }
761
 
762
+ ?></table>
763
+ <script>
764
+ jQuery(function() {
765
+ jQuery( ".wpmem_datepicker" ).datepicker({
766
+ dateFormat : "yy-mm-dd"
767
+ });
768
  });
769
+ </script>
770
+ <?php
771
+ } else {
772
+ echo '<p>' . sprintf( __( 'No memberships have been created. %sCreate new memberships here%s', 'wp-members' ), '<a href="' . admin_url() . 'edit.php?post_type=wpmem_product">', '</a>' );
773
+ }
774
  }
775
  }
776
+
777
+ /**
778
+ * Adds user view links to Users > All Users for each membership.
779
+ *
780
+ * @since 3.3.9
781
+ *
782
+ * @param array $views
783
+ * @param string $show The slug of the current view.
784
+ * @return array $views
785
+ */
786
+ function user_views( $views, $show ) {
787
+
788
+ global $wpdb, $wpmem;
789
+
790
+ // Add a view for each membership
791
+ foreach ( $wpmem->membership->product_by_id as $product_slug ) {
792
+
793
+ // Count is stored in a transient (see "if" condition below).
794
+ $count = get_transient( 'wpmem_user_counts_' . $product_slug );
795
+ // If the transient is not already set.
796
+ if ( false === $count ) {
797
+
798
+ // Get the count
799
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM " . $wpdb->usermeta . " WHERE meta_key=%s AND meta_value>0", "_wpmem_products_" . $product_slug ) );
800
+
801
+ // Save it in a transient
802
+ $transient_expires = 60; // Value in seconds, 1 day: ( 60 * 60 * 24 );
803
+ set_transient( 'wpmem_user_counts_' . $product_slug, $count, $transient_expires );
804
+ }
805
+
806
+ // Build the link for the filter view
807
+ $link = "users.php?action=show&amp;show=" . $product_slug;
808
+ $current = ( $show == $product_slug ) ? ' class="current"' : '';
809
+ $views[ $product_slug ] = sprintf(
810
+ '<a href="%s" %s>%s <span class="count">(%d)</span></a>',
811
+ esc_url( $link ),
812
+ $current,
813
+ $wpmem->membership->products[ $product_slug ]['title'],
814
+ $count
815
+ );
816
+ }
817
+
818
+ // Return the $views array with the added membership views.
819
+ return $views;
820
+ }
821
+
822
+ /**
823
+ * Filters the "where" query for user view links in Users > All Users for each membership.
824
+ *
825
+ * @since 3.3.9
826
+ *
827
+ * @param string $query_where
828
+ * @param string $show The slug of the current view.
829
+ * @return string $query_where
830
+ */
831
+ function query_where( $query_where, $show ) {
832
+
833
+ global $wpdb, $wpmem;
834
+
835
+ // Check for membership views.
836
+ foreach ( $wpmem->membership->product_by_id as $product_slug ) {
837
+ // Check if we are viewing ($show) a membership ($prduct_slug).
838
+ if ( $product_slug == $show ) {
839
+ // Set appropriate $query_where to filter the view.
840
+ $query_where = "WHERE 1=1 AND {$wpdb->users}.ID IN (
841
+ SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
842
+ WHERE {$wpdb->usermeta}.meta_key = \"" . esc_sql( "_wpmem_products_" . $product_slug ) . "\"
843
+ AND {$wpdb->usermeta}.meta_value > 0 )";
844
+ }
845
+ }
846
+
847
+ return $query_where;
848
+ }
849
  }
includes/admin/class-wp-members-user-export.php ADDED
@@ -0,0 +1,297 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The WP_Members Export Class.
4
+ *
5
+ * @package WP-Members
6
+ * @subpackage WP_Members Export Object Class
7
+ * @since 3.3.0
8
+ */
9
+
10
+ // Exit if accessed directly.
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit();
13
+ }
14
+
15
+ class WP_Members_User_Export {
16
+
17
+ /**
18
+ * New export function to export all or selected users
19
+ *
20
+ * @since 2.9.7
21
+ * @since 3.2.0 Updated to use fputcsv.
22
+ * @since 3.2.1 Added user data filters.
23
+ * @since 3.3.0 Moved to new object class as static method.
24
+ * @since 3.4.0 Added $tag to identify what export process is being run.
25
+ *
26
+ * @param array $args array {
27
+ * Array of defaults for export.
28
+ *
29
+ * @type string $export The type of export (all|selected)
30
+ * @type string $filename
31
+ * @type array $fields {
32
+ * The array of export fields is keyed as 'meta_key' => 'heading value'.
33
+ * The array can include fields in the Fields tab, plus the following:
34
+ *
35
+ * @type int $ID ID from wp_users
36
+ * @type string $username user_login from wp_users
37
+ * @type string $user_nicename user_nicename
38
+ * @type string $user_url user_url
39
+ * @type string $display_name display_name
40
+ * @type int $active Whether the user is active/deactivated.
41
+ * @type string $exp_type If the PayPal extension is installed pending|subscrption (optional)
42
+ * @type string $expires If the PayPal extension is installed MM/DD/YYYY (optional)
43
+ * @type string $user_registered user_registered
44
+ * @type string $user_ip The IP of the user when they registered.
45
+ * @type string $role The user's role (or roles, if multiple).
46
+ * }
47
+ * @type array $exclude_fields @deprecated 3.4.0
48
+ * @type boolean $entity_decode
49
+ * @type string $date_format
50
+ * }
51
+ * @param array $users Array of user IDs to export.
52
+ * @param string $tag
53
+ */
54
+ static function export_users( $args = array(), $users = array(), $tag = 'default' ) {
55
+
56
+ global $wpmem;
57
+
58
+ $export_fields = ( ! isset( $args['fields'] ) ) ? self::get_export_fields() : $args['fields'];
59
+
60
+ /**
61
+ * Filter the export fields.
62
+ *
63
+ * @since 3.2.5
64
+ * @since 3.4.0 Added $tag.
65
+ *
66
+ * @param array $export_fields {
67
+ * The array of export fields is keyed as 'meta_key' => 'heading value'.
68
+ * The array will include all fields in the Fields tab, plus the following:
69
+ *
70
+ * @type int $ID ID from wp_users
71
+ * @type string $username user_login from wp_users
72
+ * @type string $user_nicename user_nicename
73
+ * @type string $user_url user_url
74
+ * @type string $display_name display_name
75
+ * @type int $active Whether the user is active/deactivated.
76
+ * @type string $exp_type If the PayPal extension is installed pending|subscrption (optional)
77
+ * @type string $expires If the PayPal extension is installed MM/DD/YYYY (optional)
78
+ * @type string $user_registered user_registered
79
+ * @type string $user_ip The IP of the user when they registered.
80
+ * @type string $role The user's role (or roles, if multiple).
81
+ * }
82
+ * @param string $tag
83
+ */
84
+ $export_fields = apply_filters( 'wpmem_export_fields', $export_fields, $tag );
85
+
86
+ $today = date( "Y-m-d" );
87
+
88
+ // Setup defaults.
89
+ $defaults = array(
90
+ 'export' => 'all',
91
+ 'filename' => 'wp-members-user-export-' . $today . '.csv',
92
+ 'fields' => $export_fields,
93
+ 'entity_decode' => false,
94
+ 'date_format' => 'Y-m-d',
95
+ 'required_caps' => 'list_users',
96
+ );
97
+ // Merge args with default (in case any were missing).
98
+ $args = wp_parse_args( $args, $defaults );
99
+
100
+ /**
101
+ * Filter the default export arguments.
102
+ *
103
+ * @since 2.9.7
104
+ * @since 3.4.0 Filter all defaults (like other _args changes), then wp_parse_args() in case any are missing.
105
+ * @since 3.4.0 Added $tag.
106
+ * @since 3.4.0 Deprecated 'exclude_fields' (unset using wpmem_export_fields instead).
107
+ * @since 3.4.0 Deprecated 'export_fields' use "fields" instead.
108
+ *
109
+ * @param array $args {
110
+ * Array of defaults for export.
111
+ *
112
+ * @type string $export
113
+ * @type string $filename
114
+ * @type array $fields
115
+ * @type array $exclude_fields @deprecated 3.4.0
116
+ * @type boolean $entity_decode
117
+ * @type string $date_format
118
+ * }
119
+ * @param string $tag
120
+ */
121
+ $args = apply_filters( 'wpmem_export_args', $args, $tag );
122
+
123
+ // Merge args with default (in case any were missing).
124
+ $args = wp_parse_args( $args, $defaults );
125
+
126
+ if ( current_user_can( $args['required_caps'] ) ) {
127
+ // Output needs to be buffered, start the buffer.
128
+ ob_start();
129
+
130
+ // If exporting all, get all of the users.
131
+ $export_users = ( 'all' == $args['export'] ) ? get_users( array( 'fields' => 'ID' ) ) : $users;
132
+
133
+ // Generate headers and a filename based on date of export.
134
+ header( "Content-Description: File Transfer" );
135
+ header( "Content-type: application/octet-stream" );
136
+ header( "Content-Disposition: attachment; filename=" . $args['filename'] );
137
+ header( "Content-Type: text/csv; charset=" . get_option( 'blog_charset' ), true );
138
+
139
+ $handle = fopen( 'php://output', 'w' );
140
+ fputs( $handle, "\xEF\xBB\xBF" ); // UTF-8 BOM
141
+
142
+ // Remove excluded fields from $export_fields while setting up $header array.
143
+ $header = array();
144
+ foreach ( $args['fields'] as $meta => $field ) {
145
+ $header[ $meta ] = $field;
146
+ }
147
+
148
+ /**
149
+ * Filters user export header row before assembly.
150
+ *
151
+ * As of 3.4.0, this really isn't a necessary filter. You can specify the header
152
+ * value in wpmem_export_fields instead and just use one filter.
153
+ *
154
+ * @since 3.2.1
155
+ * @since 3.4.0 Added $tag.
156
+ *
157
+ * @param array $header The header column values
158
+ * @param string $tag
159
+ */
160
+ $header = apply_filters( 'wpmem_user_export_header', $header, $tag );
161
+
162
+ fputcsv( $handle, $header );
163
+
164
+ // Loop through the array of users, assemble csv.
165
+ // $fields only includes fields to be exported at this point.
166
+ foreach ( $export_users as $user ) {
167
+
168
+ $user_info = get_userdata( $user );
169
+
170
+ $wp_user_fields = array( 'ID', 'user_login', 'user_pass', 'user_nicename', 'user_email', 'user_url', 'user_registered', 'user_activation_key', 'user_status', 'display_name' );
171
+ foreach ( $args['fields'] as $meta => $field ) {
172
+
173
+ switch ( $meta ) {
174
+ case 'ID':
175
+ case 'user_login':
176
+ case 'user_pass':
177
+ case 'user_nicename':
178
+ case 'user_email':
179
+ case 'user_url':
180
+ case 'user_registered':
181
+ case 'user_activation_key':
182
+ case 'user_status':
183
+ case 'display_name':
184
+ $row[ $meta ] = $user_info->{$meta};
185
+ break;
186
+ case 'username':
187
+ $row['username'] = $user_info->user_login;
188
+ break;
189
+ case 'password':
190
+ $row['password'] = $user_info->user_pass;
191
+ break;
192
+ case 'active':
193
+ $row['active'] = wpmem_get_user_meta( $user, 'active' ) ? __( 'Yes' ) : __( 'No' );
194
+ break;
195
+ case 'exp_type':
196
+ $exp_type = wpmem_get_user_meta( $user, 'exp_type' );
197
+ $row['exp_type'] = ( false !== $exp_type ) ? $exp_type : '';
198
+ break;
199
+ case 'expires':
200
+ $expires = wpmem_get_user_meta( $user, 'expires' );
201
+ $row['expires'] = ( false !== $expires ) ? $expires : '';
202
+ break;
203
+ case 'wpmem_reg_ip':
204
+ $reg_ip = wpmem_get_user_meta( $user, 'wpmem_reg_ip' );
205
+ $row['wpmem_reg_ip'] = ( false !== $reg_ip ) ? $reg_ip : '';
206
+ break;
207
+ case 'role':
208
+ $role = wpmem_get_user_role( $user, true ); // As of 3.4, wpmem_get_user_role() can get all roles.
209
+ $row['role'] = ( is_array( $role ) ) ? implode( ",", $role ) : $role;
210
+ break;
211
+ case ( $wpmem->membership->post_stem === substr( $meta, 0, strlen( $wpmem->membership->post_stem ) ) ):
212
+ $product = str_replace( $wpmem->membership->post_stem, '', $meta );
213
+ $row[ $meta ] = wpmem_get_user_meta( $user, $meta );
214
+ // If value is a date and false is not the format_date option...
215
+ if ( false !== $args['date_format'] && '' != $row[ $meta ] && $row[ $meta ] > 2 ) {
216
+ $date_format = ( 'wp' == $args['date_format'] ) ? get_option('date_format') : $args['date_format'];
217
+ $row[ $meta ] = date( $date_format, $row[ $meta ] );
218
+ }
219
+ break;
220
+ default:
221
+ if ( in_array( $meta, $wp_user_fields ) ) {
222
+ $row[ $meta ] = ( 'username' == $meta ) ? $user_info->user_login : $user_info->{$meta};
223
+ } else {
224
+ $raw_data = wpmem_get_user_meta( $user, $meta );
225
+ $raw_data = ( $raw_data ) ? $raw_data : '';
226
+ $row[ $meta ] = ( $args['entity_decode'] ) ? html_entity_decode( $raw_data ) : $raw_data;
227
+ }
228
+ break;
229
+ }
230
+ }
231
+
232
+ /**
233
+ * Filter the user data before assembly.
234
+ *
235
+ * @since 3.2.1
236
+ * @since 3.4.0 Added user ID (it may not be included in the $row array if the field were filtered out).
237
+ * @since 3.4.0 Added $tag.
238
+ *
239
+ * @param array $row The user data row.
240
+ * @param int $user_id The user ID.
241
+ * @param string $tag
242
+ */
243
+ $row = apply_filters( 'wpmem_user_export_row', $row, $user_info->ID, $tag );
244
+
245
+ fputcsv( $handle, $row );
246
+
247
+ // Update the user record as being exported.
248
+ if ( 'all' != $args['export'] ) {
249
+ update_user_meta( $user, 'exported', 1 );
250
+ }
251
+ }
252
+
253
+ fclose( $handle );
254
+ print( ob_get_clean() );
255
+
256
+ exit();
257
+ } else {
258
+ wp_die( __( 'You do not have the required user capabilities to export users.', 'wp-members' ) );
259
+ }
260
+ }
261
+
262
+ private static function get_export_fields() {
263
+
264
+ $wpmem_fields = wpmem_fields();
265
+
266
+ // Fields to exclude.
267
+ $exclude_fields = array( 'user_pass', 'password', 'confirm_password', 'confirm_email' );
268
+
269
+ // Prepare fields, add additional "special" fields.
270
+ $export_fields = array(
271
+ 'ID' => __( 'User ID', 'wp-members' ),
272
+ );
273
+ foreach( $wpmem_fields as $meta_key => $value ) {
274
+ if ( ! in_array( $meta_key, $exclude_fields ) ) {
275
+ $export_fields[ $meta_key ] = $value['label'];
276
+ }
277
+ }
278
+ $export_fields['username'] = __( 'Username', 'wp-members' );
279
+ if ( 1 == $wpmem->mod_reg ) {
280
+ $export_fields['active'] = __( 'Activated?', 'wp-members' );
281
+ }
282
+ if ( defined( 'WPMEM_EXP_MODULE' ) && 1 == $wpmem->use_exp ) {
283
+ $export_fields['exp_type'] = __( 'Subscription', 'wp-members' );
284
+ $export_fields['expires'] = __( 'Expires', 'wp-members' );
285
+ }
286
+ $export_fields['user_registered'] = __( 'Registered', 'wp-members' );
287
+ $export_fields['wpmem_reg_ip'] = __( 'IP', 'wp-members' );
288
+ $export_fields['role'] = __( 'Role', 'wp-members' );
289
+ if ( 1 == $wpmem->enable_products ) {
290
+ foreach( $wpmem->membership->products as $product_key => $product ) {
291
+ $export_fields[ $wpmem->membership->post_stem . $product_key ] = $wpmem->membership->products[ $product_key ]['title'];
292
+ }
293
+ }
294
+
295
+ return $export_fields;
296
+ }
297
+ }
includes/admin/dialogs.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-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
@@ -75,7 +75,7 @@ function wpmem_a_do_warnings( $did_update ) {
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
  }
@@ -173,8 +173,8 @@ function wpmem_a_meta_box() {
173
 
174
  <p><strong><?php _e( 'Version:', 'wp-members' ); echo "&nbsp;" . $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 } ?>
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-2021 Chad Butler
10
  * WP-Members(tm) is a trademark of butlerblog.com
11
  *
12
  * @package WP-Members
13
  * @author Chad Butler
14
+ * @copyright 2006-2021
15
  *
16
  * Functions included:
17
  * - wpmem_a_do_warnings
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
  }
173
 
174
  <p><strong><?php _e( 'Version:', 'wp-members' ); echo "&nbsp;" . $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/docs/"><?php _e( 'Online User Guide', 'wp-members' ); ?></a><br />
177
+ <a href="https://rocketgeek.com/plugins/wp-members/docs/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 } ?>
includes/admin/tabs/class-wp-members-admin-tab-captcha.php CHANGED
@@ -1,320 +1,321 @@
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, $updated_captcha_type;
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 CAPTCHA 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
- <tr valign="top">
91
- <th><?php _e( 'CAPTCHA Type', 'wp-members' ); ?></th>
92
- <td><?php
93
- if ( 1 == $wpmem->captcha ) {
94
- $wpmem->captcha = 3; // reCAPTCHA v1 is fully obsolete. Change it to v2.
95
- }
96
- $captcha[] = __( 'reCAPTCHA v2', 'wp-members' ) . '|3';
97
- $captcha[] = __( 'reCAPTCHA v3', 'wp-members' ) . '|4';
98
- $captcha[] = __( 'Really Simple CAPTCHA', 'wp-members' ) . '|2';
99
- $captcha[] = __( 'hCaptcha', 'wp-members' ) . '|5';
100
- echo wpmem_create_formfield( 'wpmem_settings_captcha', 'select', $captcha, $wpmem->captcha ); ?>
101
- </td>
102
- </tr>
103
- <?php if ( isset( $updated_captcha_type ) ) { ?>
104
- <tr>
105
- <td colspan="2">
106
- <p><?php _e( 'CAPTCHA type was changed. Please verify and update the settings below for the new CAPTCHA type.', 'wp-members' ); ?></p>
107
- </td>
108
- </tr>
109
- <?php } ?>
110
- <?php // if reCAPTCHA is enabled...
111
- if ( 3 == $wpmem->captcha || 4 == $wpmem->captcha ) {
112
- $show_update_button = true;
113
- $private_key = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['private'] : '';
114
- $public_key = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['public'] : '';
115
- ?>
116
- <tr valign="top">
117
- <th scope="row"><?php _e( 'reCAPTCHA Keys', 'wp-members' ); ?></th>
118
- <td>
119
- <p><?php if ( '' == $wpmem_captcha['recaptcha']['private'] || '' == $wpmem_captcha['recaptcha']['public'] ) {
120
- 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>' );
121
- } ?></p>
122
- <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>
123
- <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>
124
- </td>
125
- </tr>
126
- <?php
127
- } elseif ( 5 == $wpmem->captcha ) {
128
- $show_update_button = true;
129
- $private_key = ( isset( $wpmem_captcha['hcaptcha'] ) ) ? $wpmem_captcha['hcaptcha']['secret'] : '';
130
- $public_key = ( isset( $wpmem_captcha['hcaptcha'] ) ) ? $wpmem_captcha['hcaptcha']['api_key'] : '';
131
- ?>
132
- <tr valign="top">
133
- <th scope="row"><?php _e( 'hCaptcha Keys', 'wp-members' ); ?></th>
134
- <td>
135
- <p><?php if ( '' == $private_key || '' == $public_key ) {
136
- printf( __( 'hCaptcha requires an API key. You can sign up for %s an hCaptcha API key here %s', 'wp-members' ), "<a href=\"https://hcaptcha.com/\" target=\"_blank\">", '</a>' );
137
- } ?></p>
138
- <p><label><?php _e( 'API Key', 'wp-members' ); ?>:</label><br /><input type="text" name="wpmem_captcha_publickey" size="60" value="<?php echo $public_key; ?>" /></p>
139
- <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>
140
- </td>
141
- </tr>
142
- <?php
143
- // If Really Simple CAPTCHA is enabled.
144
- } elseif ( $wpmem->captcha == 2 ) {
145
-
146
- // Setup defaults.
147
- $defaults = array(
148
- 'characters' => 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789',
149
- 'num_char' => '4',
150
- 'dim_w' => '72',
151
- 'dim_h' => '30',
152
- 'font_color' => '0,0,0',
153
- 'bg_color' => '255,255,255',
154
- 'font_size' => '12',
155
- 'kerning' => '14',
156
- 'img_type' => 'png',
157
- );
158
-
159
- $args = ( isset( $wpmem_captcha['really_simple'] ) && is_array( $wpmem_captcha['really_simple'] ) ) ? $wpmem_captcha['really_simple'] : array();
160
-
161
- $args = wp_parse_args( $args, $defaults );
162
-
163
- // Explode colors.
164
- $font_color = explode( ',', $args['font_color'] );
165
- $bg_color = explode( ',', $args['bg_color'] );
166
-
167
- $show_update_button = true;
168
- if ( is_plugin_active( 'really-simple-captcha/really-simple-captcha.php' ) ) { ?>
169
- <tr>
170
- <th scope="row"><?php _e( 'Characters for image', 'wp-members' ); ?></th>
171
- <td><input name="characters" type="text" size="34" value="<?php echo $args['characters']; ?>" /></td>
172
- </tr>
173
- <tr>
174
- <th scope="row"><?php _e( 'Number of characters', 'wp-members' ); ?></th>
175
- <td><input name="num_char" type="text" size="2" value="<?php echo $args['num_char']; ?>" /></td>
176
- </tr>
177
- <tr>
178
- <th scope="row"><?php _e( 'Image dimensions', 'wp-members' ); ?></th>
179
- <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>
180
- </tr>
181
- <tr>
182
- <th scope="row"><?php _e( 'Font color of characters', 'wp-members' ); ?></th>
183
- <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>
184
- </tr>
185
- <tr>
186
- <th scope="row"><?php _e( 'Background color of image', 'wp-members' ); ?></th>
187
- <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>
188
- </tr>
189
- <tr>
190
- <th scope="row"><?php _e( 'Font size', 'wp-members' ); ?></th>
191
- <td><input name="font_size" type="text" value="<?php echo $args['font_size']; ?>" /></td>
192
- </tr>
193
- <tr>
194
- <th scope="row"><?php _e( 'Width between characters', 'wp-members' ); ?></th>
195
- <td><input name="kerning" type="text" value="<?php echo $args['kerning']; ?>" /></td>
196
- </tr>
197
- <tr>
198
- <th scope="row"><?php _e( 'Image type', 'wp-members' ); ?></th>
199
- <td><select name="img_type">
200
- <option<?php echo ( $args['img_type'] == 'png' ) ? ' selected' : ''; ?>>png</option>
201
- <option<?php echo ( $args['img_type'] == 'gif' ) ? ' selected' : ''; ?>>gif</option>
202
- <option<?php echo ( $args['img_type'] == 'jpg' ) ? ' selected' : ''; ?>>jpg</option>
203
- </select>
204
- </td>
205
- </tr><?php
206
-
207
- } else {
208
-
209
- $show_update_button = false; ?>
210
- <tr>
211
- <td colspan="2">
212
- <p><?php _e( 'To use Really Simple CAPTCHA, you must have the Really Simple CAPTCHA plugin installed and activated.', 'wp-members' ); ?></p>
213
- <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>
214
- </td>
215
- </tr><?php
216
- }
217
- } // End if RSC is selected.
218
- if ( $show_update_button ) {
219
-
220
- switch ( $wpmem->captcha ) {
221
- case 1:
222
- $captcha_type = 'recaptcha';
223
- break;
224
- case 2:
225
- $captcha_type = 'really_simple';
226
- break;
227
- case 3:
228
- case 4:
229
- $captcha_type = 'recaptcha2';
230
- break;
231
- case 5:
232
- $captcha_type = 'hcaptcha';
233
- break;
234
- } ?>
235
- <tr valign="top">
236
- <th scope="row">&nbsp;</th>
237
- <td>
238
- <input type="hidden" name="wpmem_recaptcha_type" value="<?php echo $captcha_type ?>" />
239
- <input type="hidden" name="wpmem_admin_a" value="update_captcha" />
240
- <?php submit_button( __( 'Update CAPTCHA Settings', 'wp-members' ) ); ?>
241
- </td>
242
- </tr>
243
- <?php } ?>
244
- </table>
245
- </form>
246
- </div><!-- .inside -->
247
- </div>
248
- </div><!-- #post-body-content -->
249
- </div><!-- #post-body -->
250
- </div><!-- .metabox-holder -->
251
- <?php
252
- }
253
-
254
- /**
255
- * Updates the captcha options.
256
- *
257
- * @since 2.8
258
- * @since 3.3.0 Ported wpmem_update_captcha() to update().
259
- *
260
- * @return string The captcha option update message.
261
- */
262
- public static function update() {
263
-
264
- global $wpmem;
265
-
266
- // Check nonce.
267
- check_admin_referer( 'wpmem-update-captcha' );
268
-
269
- $settings = get_option( 'wpmembers_captcha' );
270
- $update_type = sanitize_text_field( $_POST['wpmem_recaptcha_type'] );
271
- $which = intval( wpmem_get( 'wpmem_settings_captcha', 0 ) );
272
-
273
- // If there are no current settings.
274
- if ( ! $settings ) {
275
- $settings = array();
276
- }
277
-
278
- if ( 0 != $which && $wpmem->captcha != $which ) {
279
- // Changing captcha type.
280
- global $updated_captcha_type;
281
- $updated_captcha_type = true;
282
- $wpmem->captcha = $which;
283
- wpmem_update_option( 'wpmembers_settings', 'captcha', $which );
284
- }
285
-
286
- if ( $update_type == 'recaptcha' || $update_type == 'recaptcha2' ) {
287
- $settings['recaptcha'] = array(
288
- 'public' => sanitize_text_field( $_POST['wpmem_captcha_publickey'] ),
289
- 'private' => sanitize_text_field( $_POST['wpmem_captcha_privatekey'] ),
290
- );
291
- if ( $update_type == 'recaptcha' && isset( $_POST['wpmem_captcha_theme'] ) ) {
292
- $settings['recaptcha']['theme'] = sanitize_text_field( $_POST['wpmem_captcha_theme'] );
293
- }
294
- }
295
-
296
- if ( 'hcaptcha' == $update_type ) {
297
- $settings['hcaptcha']['api_key'] = sanitize_text_field( $_POST['wpmem_captcha_publickey'] );
298
- $settings['hcaptcha']['secret'] = sanitize_text_field( $_POST['wpmem_captcha_privatekey'] );
299
- }
300
-
301
- if ( $update_type == 'really_simple' ) {
302
- $font_color = sanitize_text_field( $_POST['font_color_r'] ) . ',' . sanitize_text_field( $_POST['font_color_g'] ) . ',' . sanitize_text_field( $_POST['font_color_b'] );
303
- $bg_color = sanitize_text_field( $_POST['bg_color_r'] ) . ',' . sanitize_text_field( $_POST['bg_color_g'] ) . ',' . sanitize_text_field( $_POST['bg_color_b'] );
304
- $settings['really_simple'] = array(
305
- 'characters' => sanitize_text_field( $_POST['characters'] ),
306
- 'num_char' => sanitize_text_field( $_POST['num_char'] ),
307
- 'dim_w' => sanitize_text_field( $_POST['dim_w'] ),
308
- 'dim_h' => sanitize_text_field( $_POST['dim_h'] ),
309
- 'font_color' => $font_color,
310
- 'bg_color' => $bg_color,
311
- 'font_size' => sanitize_text_field( $_POST['font_size'] ),
312
- 'kerning' => sanitize_text_field( $_POST['kerning'] ),
313
- 'img_type' => sanitize_text_field( $_POST['img_type'] ),
314
- );
315
- }
316
-
317
- update_option( 'wpmembers_captcha', $settings );
318
- return __( 'CAPTCHA was updated for WP-Members', 'wp-members' );
319
- }
 
320
  }
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-2021 Chad Butler
10
+ * WP-Members(tm) is a trademark of butlerblog.com
11
+ *
12
+ * @package WP-Members
13
+ * @author Chad Butler
14
+ * @copyright 2006-2021
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, $updated_captcha_type;
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/docs/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 CAPTCHA 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
+ <tr valign="top">
91
+ <th><?php _e( 'CAPTCHA Type', 'wp-members' ); ?></th>
92
+ <td><?php
93
+ if ( 1 == $wpmem->captcha ) {
94
+ $wpmem->captcha = 3; // reCAPTCHA v1 is fully obsolete. Change it to v2.
95
+ }
96
+ $captcha[] = __( 'reCAPTCHA v2', 'wp-members' ) . '|3';
97
+ $captcha[] = __( 'reCAPTCHA v3', 'wp-members' ) . '|4';
98
+ $captcha[] = __( 'Really Simple CAPTCHA', 'wp-members' ) . '|2';
99
+ $captcha[] = __( 'hCaptcha', 'wp-members' ) . '|5';
100
+ echo wpmem_form_field( 'wpmem_settings_captcha', 'select', $captcha, $wpmem->captcha ); ?>
101
+ </td>
102
+ </tr>
103
+ <?php if ( isset( $updated_captcha_type ) ) { ?>
104
+ <tr>
105
+ <td colspan="2">
106
+ <p><?php _e( 'CAPTCHA type was changed. Please verify and update the settings below for the new CAPTCHA type.', 'wp-members' ); ?></p>
107
+ </td>
108
+ </tr>
109
+ <?php } ?>
110
+ <?php // if reCAPTCHA is enabled...
111
+ if ( 3 == $wpmem->captcha || 4 == $wpmem->captcha ) {
112
+ $show_update_button = true;
113
+ $private_key = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['private'] : '';
114
+ $public_key = ( isset( $wpmem_captcha['recaptcha'] ) ) ? $wpmem_captcha['recaptcha']['public'] : '';
115
+ ?>
116
+ <tr valign="top">
117
+ <th scope="row"><?php _e( 'reCAPTCHA Keys', 'wp-members' ); ?></th>
118
+ <td>
119
+ <p><?php if ( '' == $wpmem_captcha['recaptcha']['private'] || '' == $wpmem_captcha['recaptcha']['public'] ) {
120
+ 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>' );
121
+ } ?></p>
122
+ <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>
123
+ <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>
124
+ </td>
125
+ </tr>
126
+ <?php
127
+ } elseif ( 5 == $wpmem->captcha ) {
128
+ $show_update_button = true;
129
+ $private_key = ( isset( $wpmem_captcha['hcaptcha'] ) ) ? $wpmem_captcha['hcaptcha']['secret'] : '';
130
+ $public_key = ( isset( $wpmem_captcha['hcaptcha'] ) ) ? $wpmem_captcha['hcaptcha']['api_key'] : '';
131
+ ?>
132
+ <tr valign="top">
133
+ <th scope="row"><?php _e( 'hCaptcha Keys', 'wp-members' ); ?></th>
134
+ <td>
135
+ <p><?php if ( '' == $private_key || '' == $public_key ) {
136
+ printf( __( 'hCaptcha requires an API key. You can sign up for %s an hCaptcha API key here %s', 'wp-members' ), "<a href=\"https://hcaptcha.com/\" target=\"_blank\">", '</a>' );
137
+ } ?></p>
138
+ <p><label><?php _e( 'API Key', 'wp-members' ); ?>:</label><br /><input type="text" name="wpmem_captcha_publickey" size="60" value="<?php echo $public_key; ?>" /></p>
139
+ <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>
140
+ </td>
141
+ </tr>
142
+ <?php
143
+ // If Really Simple CAPTCHA is enabled.
144
+ } elseif ( $wpmem->captcha == 2 ) {
145
+
146
+ // Setup defaults.
147
+ $defaults = array(
148
+ 'characters' => 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789',
149
+ 'num_char' => '4',
150
+ 'dim_w' => '72',
151
+ 'dim_h' => '30',
152
+ 'font_color' => '0,0,0',
153
+ 'bg_color' => '255,255,255',
154
+ 'font_size' => '12',
155
+ 'kerning' => '14',
156
+ 'img_type' => 'png',
157
+ );
158
+
159
+ $args = ( isset( $wpmem_captcha['really_simple'] ) && is_array( $wpmem_captcha['really_simple'] ) ) ? $wpmem_captcha['really_simple'] : array();
160
+
161
+ $args = wp_parse_args( $args, $defaults );
162
+
163
+ // Explode colors.
164
+ $font_color = explode( ',', $args['font_color'] );
165
+ $bg_color = explode( ',', $args['bg_color'] );
166
+
167
+ $show_update_button = true;
168
+ if ( is_plugin_active( 'really-simple-captcha/really-simple-captcha.php' ) ) { ?>
169
+ <tr>
170
+ <th scope="row"><?php _e( 'Characters for image', 'wp-members' ); ?></th>
171
+ <td><input name="characters" type="text" size="34" value="<?php echo $args['characters']; ?>" /></td>
172
+ </tr>
173
+ <tr>
174
+ <th scope="row"><?php _e( 'Number of characters', 'wp-members' ); ?></th>
175
+ <td><input name="num_char" type="text" size="2" value="<?php echo $args['num_char']; ?>" /></td>
176
+ </tr>
177
+ <tr>
178
+ <th scope="row"><?php _e( 'Image dimensions', 'wp-members' ); ?></th>
179
+ <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>
180
+ </tr>
181
+ <tr>
182
+ <th scope="row"><?php _e( 'Font color of characters', 'wp-members' ); ?></th>
183
+ <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>
184
+ </tr>
185
+ <tr>
186
+ <th scope="row"><?php _e( 'Background color of image', 'wp-members' ); ?></th>
187
+ <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>
188
+ </tr>
189
+ <tr>
190
+ <th scope="row"><?php _e( 'Font size', 'wp-members' ); ?></th>
191
+ <td><input name="font_size" type="text" value="<?php echo $args['font_size']; ?>" /></td>
192
+ </tr>
193
+ <tr>
194
+ <th scope="row"><?php _e( 'Width between characters', 'wp-members' ); ?></th>
195
+ <td><input name="kerning" type="text" value="<?php echo $args['kerning']; ?>" /></td>
196
+ </tr>
197
+ <tr>
198
+ <th scope="row"><?php _e( 'Image type', 'wp-members' ); ?></th>
199
+ <td><select name="img_type">
200
+ <option<?php echo ( $args['img_type'] == 'png' ) ? ' selected' : ''; ?>>png</option>
201
+ <option<?php echo ( $args['img_type'] == 'gif' ) ? ' selected' : ''; ?>>gif</option>
202
+ <option<?php echo ( $args['img_type'] == 'jpg' ) ? ' selected' : ''; ?>>jpg</option>
203
+ </select>
204
+ </td>
205
+ </tr><?php
206
+
207
+ } else {
208
+
209
+ $show_update_button = true; // @todo Fixes whether the update button shows or not.
210
+ // Could remove that logic altogether? ?>
211
+ <tr>
212
+ <td colspan="2">
213
+ <p><?php _e( 'To use Really Simple CAPTCHA, you must have the Really Simple CAPTCHA plugin installed and activated.', 'wp-members' ); ?></p>
214
+ <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>
215
+ </td>
216
+ </tr><?php
217
+ }
218
+ } // End if RSC is selected.
219
+ if ( $show_update_button ) {
220
+
221
+ switch ( $wpmem->captcha ) {
222
+ case 1:
223
+ $captcha_type = 'recaptcha';
224
+ break;
225
+ case 2:
226
+ $captcha_type = 'really_simple';
227
+ break;
228
+ case 3:
229
+ case 4:
230
+ $captcha_type = 'recaptcha2';
231
+ break;
232
+ case 5:
233
+ $captcha_type = 'hcaptcha';
234
+ break;
235
+ } ?>
236
+ <tr valign="top">
237
+ <th scope="row">&nbsp;</th>
238
+ <td>
239
+ <input type="hidden" name="wpmem_recaptcha_type" value="<?php echo $captcha_type ?>" />
240
+ <input type="hidden" name="wpmem_admin_a" value="update_captcha" />
241
+ <?php submit_button( __( 'Update CAPTCHA Settings', 'wp-members' ) ); ?>
242
+ </td>
243
+ </tr>
244
+ <?php } ?>
245
+ </table>
246
+ </form>
247
+ </div><!-- .inside -->
248
+ </div>
249
+ </div><!-- #post-body-content -->
250
+ </div><!-- #post-body -->
251
+ </div><!-- .metabox-holder -->
252
+ <?php
253
+ }
254
+
255
+ /**
256
+ * Updates the captcha options.
257
+ *
258
+ * @since 2.8
259
+ * @since 3.3.0 Ported wpmem_update_captcha() to update().
260
+ *
261
+ * @return string The captcha option update message.
262
+ */
263
+ public static function update() {
264
+
265
+ global $wpmem;
266
+
267
+ // Check nonce.
268
+ check_admin_referer( 'wpmem-update-captcha' );
269
+
270
+ $settings = get_option( 'wpmembers_captcha' );
271
+ $update_type = sanitize_text_field( wpmem_get( 'wpmem_recaptcha_type', '' ) );
272
+ $which = intval( wpmem_get( 'wpmem_settings_captcha', 0 ) );
273
+
274
+ // If there are no current settings.
275
+ if ( ! $settings ) {
276
+ $settings = array();
277
+ }
278
+
279
+ if ( 0 != $which && $wpmem->captcha != $which ) {
280
+ // Changing captcha type.
281
+ global $updated_captcha_type;
282
+ $updated_captcha_type = true;
283
+ $wpmem->captcha = $which;
284
+ wpmem_update_option( 'wpmembers_settings', 'captcha', $which );
285
+ }
286
+
287
+ if ( $update_type == 'recaptcha' || $update_type == 'recaptcha2' ) {
288
+ $settings['recaptcha'] = array(
289
+ 'public' => sanitize_text_field( wpmem_get( 'wpmem_captcha_publickey', '' ) ),
290
+ 'private' => sanitize_text_field( wpmem_get( 'wpmem_captcha_privatekey', '' ) ),
291
+ );
292
+ if ( 'recaptcha' == wpmem_get( 'wpmem_captcha_theme', false ) ) {
293
+ $settings['recaptcha']['theme'] = sanitize_text_field( wpmem_get( 'wpmem_captcha_theme', '' ) );
294
+ }
295
+ }
296
+
297
+ if ( 'hcaptcha' == $update_type ) {
298
+ $settings['hcaptcha']['api_key'] = sanitize_text_field( wpmem_get( 'wpmem_captcha_publickey', '' ) );
299
+ $settings['hcaptcha']['secret'] = sanitize_text_field( wpmem_get( 'wpmem_captcha_privatekey', '' ) );
300
+ }
301
+
302
+ if ( $update_type == 'really_simple' ) {
303
+ $font_color = sanitize_text_field( wpmem_get( 'font_color_r', '' ) ) . ',' . sanitize_text_field( wpmem_get( 'font_color_g', '' ) ) . ',' . sanitize_text_field( wpmem_get( 'font_color_b', '' ) );
304
+ $bg_color = sanitize_text_field( wpmem_get( 'bg_color_r', '' ) ) . ',' . sanitize_text_field( wpmem_get( 'bg_color_g', '' ) ) . ',' . sanitize_text_field( wpmem_get( 'bg_color_b', '' ) );
305
+ $settings['really_simple'] = array(
306
+ 'characters' => sanitize_text_field( wpmem_get( 'characters', '' ) ),
307
+ 'num_char' => sanitize_text_field( wpmem_get( 'num_char', '' ) ),
308
+ 'dim_w' => sanitize_text_field( wpmem_get( 'dim_w', '' ) ),
309
+ 'dim_h' => sanitize_text_field( wpmem_get( 'dim_h', '' ) ),
310
+ 'font_color' => $font_color,
311
+ 'bg_color' => $bg_color,
312
+ 'font_size' => sanitize_text_field( wpmem_get( 'font_size', '' ) ),
313
+ 'kerning' => sanitize_text_field( wpmem_get( 'kerning', '' ) ),
314
+ 'img_type' => sanitize_text_field( wpmem_get( 'img_type', '' ) ),
315
+ );
316
+ }
317
+
318
+ update_option( 'wpmembers_captcha', $settings );
319
+ return __( 'CAPTCHA was updated for WP-Members', 'wp-members' );
320
+ }
321
  }
includes/admin/tabs/class-wp-members-admin-tab-dialogs.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-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.
@@ -56,7 +56,7 @@ class WP_Members_Admin_Tab_Dialogs {
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 -->
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-2021 Chad Butler
10
  * WP-Members(tm) is a trademark of butlerblog.com
11
  *
12
  * @package WP-Members
13
  * @author Chad Butler
14
+ * @copyright 2006-2021
15
  */
16
 
17
  // Exit if accessed directly.
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/docs/plugin-settings/dialogs/" target="_blank">Users Guide on dialogs</a>.</i></strong>
60
  </div>
61
  </div>
62
  </div> <!-- .inner-sidebar -->
includes/admin/tabs/class-wp-members-admin-tab-dropins.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-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.
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-2021 Chad Butler
10
  * WP-Members(tm) is a trademark of butlerblog.com
11
  *
12
  * @package WP-Members
13
  * @author Chad Butler
14
+ * @copyright 2006-2021
15
  */
16
 
17
  // Exit if accessed directly.
includes/admin/tabs/class-wp-members-admin-tab-emails.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-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.
@@ -58,7 +58,7 @@ class WP_Members_Admin_Tab_Emails {
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 />
@@ -73,16 +73,25 @@ class WP_Members_Admin_Tab_Emails {
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 ) ); ?>" />&nbsp;<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">
@@ -99,7 +108,7 @@ class WP_Members_Admin_Tab_Emails {
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 -->
@@ -126,11 +135,13 @@ class WP_Members_Admin_Tab_Emails {
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.
@@ -154,7 +165,7 @@ class WP_Members_Admin_Tab_Emails {
154
 
155
  if ( ! empty ( $wpmem->admin->emails ) ) {
156
  foreach( $wpmem->admin->emails as $email ) {
157
- $wpmem->admin->email_update( $email );
158
  }
159
  }
160
 
@@ -162,4 +173,57 @@ class WP_Members_Admin_Tab_Emails {
162
 
163
  }
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  } // End of file.
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-2021 Chad Butler
10
  * WP-Members(tm) is a trademark of butlerblog.com
11
  *
12
  * @package WP-Members
13
  * @author Chad Butler
14
+ * @copyright 2006-2021
15
  */
16
 
17
  // Exit if accessed directly.
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/docs/customizing-emails/" target="_blank">
62
  <?php _e( 'A list of shortcodes is available here.', 'wp-members' ); ?></a>
63
  </p>
64
  <hr />
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 ) ); ?>" />&nbsp;<span class="description"><?php _e( '(optional)', 'wp-members' ); ?> John Smith</span></td>
75
  </tr>
76
+ <tr valign="top">
77
+ <th scope="row"><?php _e( 'Send HTML email', 'wp-members' ); ?></th>
78
+ <td><input type="checkbox" name="wpmem_email_html" value="1" <?php checked( $wpmem->email->html, 1, true ); ?> /></td>
79
+ </tr>
80
  <tr><td colspan="2"><hr /></td></tr>
81
+ <?php // Here is where we handle all emails, both standard and custom.
82
+ if ( ! empty ( $wpmem->admin->emails ) ) {
83
  foreach( $wpmem->admin->emails as $email ) {
84
+ self::do_email_input( $email );
85
  }
86
  }
87
+ $arr = get_option( 'wpmembers_email_footer' );
88
+ $footer_args = array(
89
+ 'body_input' => 'wpmembers_email_footer_body',
90
+ 'body_value' => $arr,
91
+ ); ?>
92
  <tr valign="top">
93
  <th scope="row"><strong><?php echo __( "Email Signature", 'wp-members' ); ?></strong> <span class="description"><?php _e( '(optional)', 'wp-members' ); ?></span></th>
94
+ <td><?php self::do_email_editor( $footer_args ); ?></td>
95
  </tr>
96
  <tr><td colspan="2"><hr /></td></tr>
97
  <tr valign="top">
108
  <div class="postbox">
109
  <h3><span><?php _e( 'Need help?', 'wp-members' ); ?></span></h3>
110
  <div class="inside">
111
+ <strong><i>See the <a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/emails/" target="_blank">Users Guide on email options</a>.</i></strong>
112
  </div>
113
  </div>
114
  </div> <!-- #post-body-content -->
135
  check_admin_referer( 'wpmem-update-emails' );
136
 
137
  // Update the email address (if applicable).
138
+ if ( $wpmem->email->from != $_POST['wp_mail_from'] || $wpmem->email->from_name != $_POST['wp_mail_from_name'] || $wpmem->email->html != wpmem_get( 'wpmem_email_html', 0 ) ) {
139
  $wpmem->email->from = sanitize_email( $_POST['wp_mail_from'] );
140
  $wpmem->email->from_name = sanitize_text_field( $_POST['wp_mail_from_name'] );
141
+ $wpmem->email->html = intval( wpmem_get( 'wpmem_email_html', 0 ) );
142
  update_option( 'wpmembers_email_wpfrom', $wpmem->email->from );
143
  update_option( 'wpmembers_email_wpname', $wpmem->email->from_name );
144
+ update_option( 'wpmembers_email_html', $wpmem->email->html );
145
  }
146
 
147
  // Update the various emails being used.
165
 
166
  if ( ! empty ( $wpmem->admin->emails ) ) {
167
  foreach( $wpmem->admin->emails as $email ) {
168
+ self::email_update( $email );
169
  }
170
  }
171
 
173
 
174
  }
175
 
176
+ /**
177
+ * Adds custom email dialog to the Emails tab.
178
+ *
179
+ * @since 3.1.0
180
+ * @since 3.4.0 Moved to emails tab class.
181
+ *
182
+ * @param array $args Settings array for the email.
183
+ */
184
+ static private function do_email_input( $args ) { ?>
185
+ <tr valign="top"><td colspan="2"><strong><?php echo esc_html( $args['heading'] ); ?></strong></td></tr>
186
+ <tr valign="top">
187
+ <th scope="row"><?php echo esc_html( $args['subject_label'] ); ?></th>
188
+ <td><input type="text" name="<?php echo esc_attr( $args['subject_input'] ); ?>" size="80" value="<?php echo esc_attr( wp_unslash( $args['subject_value'] ) ); ?>"></td>
189
+ </tr>
190
+ <tr valign="top">
191
+ <th scope="row"><?php echo esc_html( $args['body_label'] ); ?></th>
192
+ <td><?php self::do_email_editor( $args ); ?></td>
193
+ </tr>
194
+ <tr><td colspan="2"><hr /></td></tr><?php
195
+ }
196
+
197
+ static private function do_email_editor( $args ) {
198
+ global $wpmem;
199
+ if ( 1 == $wpmem->email->html ) {
200
+ $editor_args = array(
201
+ 'media_buttons' => false,
202
+ 'textarea_rows' => 10,
203
+ );
204
+ wp_editor( $args['body_value'], esc_attr( $args['body_input'] ), $editor_args );
205
+ } else { ?>
206
+ <textarea name="<?php echo esc_attr( $args['body_input'] ); ?>" rows="12" cols="50" id="" class="large-text code"><?php echo esc_textarea( wp_unslash( $args['body_value'] ) ); ?></textarea>
207
+ <?php }
208
+ }
209
+
210
+ /**
211
+ * Saves custom email settings.
212
+ *
213
+ * @since 3.1.0
214
+ * @since 3.4.0 Moved to emails tab class.
215
+ *
216
+ * @param array $args Settings array for the email.
217
+ */
218
+ static private function email_update( $args ) {
219
+ global $wpmem;
220
+ $settings = array(
221
+ 'subj' => sanitize_text_field( wpmem_get( $args['subject_input'] ) ),
222
+ 'body' => wp_kses( wpmem_get( $args['body_input'] ), 'post' ),
223
+ );
224
+ update_option( $args['name'], $settings, true );
225
+ $wpmem->admin->emails[ $args['name'] ]['subject_value'] = $settings['subj'];
226
+ $wpmem->admin->emails[ $args['name'] ]['body_value'] = $settings['body'];
227
+ return;
228
+ }
229
  } // End of file.
includes/admin/tabs/class-wp-members-admin-tab-fields.php CHANGED
@@ -1,763 +1,774 @@
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', '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 } ?>
254
- <?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'text', 'password', 'email', 'url', 'number', 'date' ) ) ) ) ) { ?>
255
- <?php echo ( $mode == 'add' ) ? '<div id="wpmem_title">' : ''; ?>
256
- <li>
257
- <label><?php _e( 'Title', 'wp-members' ); ?></label>
258
- <input type="text" name="add_title" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['title'] ) ? $field['title'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
259
- </li>
260
- <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
261
- <?php } ?>
262
-
263
- <?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'number', 'date' ) ) ) ) ) { ?>
264
- <?php echo ( $mode == 'add' ) ? '<div id="wpmem_min_max">' : ''; ?>
265
- <li>
266
- <label><?php _e( 'Minimum Value', 'wp-members' ); ?></label>
267
- <input type="text" name="add_min" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['min'] ) ? $field['min'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
268
- </li>
269
- <li>
270
- <label><?php _e( 'Maximum Value', 'wp-members' ); ?></label>
271
- <input type="text" name="add_max" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['max'] ) ? $field['max'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
272
- </li>
273
- <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
274
- <?php } ?>
275
- <?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'textarea' ) ) ) ) ) { ?>
276
- <?php echo ( $mode == 'add' ) ? '<div id="wpmem_rows_cols">' : ''; ?>
277
- <li>
278
- <label><?php _e( 'Rows', 'wp-members' ); ?></label>
279
- <input type="number" name="add_rows" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['rows'] ) ? $field['rows'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
280
- </li>
281
- <li>
282
- <label><?php _e( 'Columns', 'wp-members' ); ?></label>
283
- <input type="number" name="add_cols" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['cols'] ) ? $field['cols'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
284
- </li>
285
- <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
286
- <?php } ?>
287
- <?php if ( $mode == 'add' || ( $mode == 'edit' && ( $field['type'] == 'file' || $field['type'] == 'image' ) ) ) { ?>
288
- <?php echo ( $mode == 'add' ) ? '<div id="wpmem_file_info">' : ''; ?>
289
- <li>
290
- <label><?php _e( 'Accepted file types:', 'wp-members' ); ?></label>
291
- <input type="text" name="add_file_value" value="<?php echo ( $mode == 'edit' && ( $field['type'] == 'file' || $field['type'] == 'image' ) ) ? $field['file_types'] : false; ?>" />
292
- </li>
293
- <li>
294
- <label>&nbsp;</label>
295
- <span class="description"><?php _e( 'Accepted file types should be set like this: jpg|jpeg|png|gif', 'wp-members' ); ?></span>
296
- </li>
297
- <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
298
- <?php } ?>
299
- <?php if ( $mode == 'add' || ( $mode == 'edit' && $field['type'] == 'checkbox' ) ) { ?>
300
- <?php echo ( $mode == 'add' ) ? '<div id="wpmem_checkbox_info">' : ''; ?>
301
- <li>
302
- <label><?php _e( 'Checked by default?', 'wp-members' ); ?></label>
303
- <input type="checkbox" name="add_checked_default" value="y" <?php echo ( $mode == 'edit' && $field['type'] == 'checkbox' ) ? checked( true, $field['checked_default'] ) : false; ?> />
304
- </li>
305
- <li>
306
- <label><?php _e( 'Stored value if checked:', 'wp-members' ); ?> <span class="req"><?php _e( '(required)', 'wp-members' ); ?></span></label>
307
- <input type="text" name="add_checked_value" id="add_checked_value" value="<?php echo ( $mode == 'edit' && $field['type'] == 'checkbox' ) ? $field['checked_value'] : false; ?>" />
308
- </li>
309
- <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
310
- <?php }
311
-
312
- if ( isset( $field['type'] ) ) {
313
- $additional_settings = ( $field['type'] == 'select' || $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' || $field['type'] == 'radio' ) ? true : false;
314
- $delimiter_settings = ( $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' ) ? true : false;
315
- }
316
- if ( $mode == 'add' || ( $mode == 'edit' && $additional_settings ) ) { ?>
317
- <?php echo ( $mode == 'add' ) ? '<div id="wpmem_dropdown_info">' : ''; ?>
318
- <?php if ( $mode == 'add' || ( $mode == 'edit' && $delimiter_settings ) ) {
319
- echo ( $mode == 'add' ) ? '<div id="wpmem_delimiter_info">' : '';
320
- if ( isset( $field['delimiter'] ) && ( "|" == $field['delimiter'] || "," == $field['delimiter'] ) ) {
321
- $delimiter = $field['delimiter'];
322
- } else {
323
- $delimiter = "|";
324
- }
325
- ?>
326
- <li>
327
- <label><?php _e( 'Stored values delimiter:', 'wp-members' ); ?></label>
328
- <select name = "add_delimiter_value">
329
- <option value="|" <?php selected( '|', $delimiter ); ?>>pipe "|"</option>
330
- <option value="," <?php selected( ',', $delimiter ); ?>>comma ","</option>
331
- </select>
332
- </li>
333
- <?php echo ( $mode == 'add' ) ? '</div>' : '';
334
- } ?>
335
- <li>
336
- <label style="vertical-align:top"><?php _e( 'Values (Displayed|Stored):', 'wp-members' ); ?> <?php echo $span_required; ?></label>
337
- <textarea name="add_dropdown_value" id="add_dropdown_value" rows="5" cols="40"><?php
338
- // Accomodate editing the current dropdown values or create dropdown value example.
339
- if ( $mode == 'edit' ) {
340
- for ( $row = 0; $row < count( $field['values'] ); $row++ ) {
341
- // If the row contains commas (i.e. 1,000-10,000), wrap in double quotes.
342
- if ( strstr( $field['values'][ $row ], ',' ) ) {
343
- echo '"' . $field['values'][ $row ]; echo ( $row == count( $field['values'] )- 1 ) ? '"' : "\",\n";
344
- } else {
345
- echo $field['values'][ $row ]; echo ( $row == count( $field['values'] )- 1 ) ? "" : ",\n";
346
- } }
347
- } else {
348
- if (version_compare(PHP_VERSION, '5.3.0') >= 0) { ?>
349
- ---- Select One ----|,
350
- Choice One|choice_one,
351
- "1,000|one_thousand",
352
- "1,000-10,000|1,000-10,000",
353
- Last Row|last_row<?php } else { ?>
354
- ---- Select One ----|,
355
- Choice One|choice_one,
356
- Choice 2|choice_two,
357
- Last Row|last_row<?php } } ?></textarea>
358
- </li>
359
- <li>
360
- <label>&nbsp;</label>
361
- <span class="description"><?php _e( 'Options should be Option Name|option_value,', 'wp-members' ); ?></span>
362
- </li>
363
- <li>
364
- <label>&nbsp;</label>
365
- <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>
366
- </li>
367
- <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
368
- <?php } ?>
369
- <?php if ( $mode == 'add' || ( $mode == 'edit' && $field['type'] == 'hidden' ) ) { ?>
370
- <?php echo ( $mode == 'add' ) ? '<div id="wpmem_hidden_info">' : ''; ?>
371
- <li>
372
- <label><?php _e( 'Value', 'wp-members' ); ?> <?php echo $span_required; ?></label>
373
- <input type="text" name="add_hidden_value" id="add_hidden_value" value="<?php echo ( $mode == 'edit' && $field['type'] == 'hidden' ) ? $field['value'] : ''; ?>" />
374
- </li>
375
- <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
376
- <?php } ?>
377
- </ul><br />
378
- <?php if ( $mode == 'edit' ) { ?><input type="hidden" name="field_arr" value="<?php echo $meta_key; ?>" /><?php } ?>
379
- <?php if ( 'add' == $mode ) {
380
- $ids = array();
381
- foreach ( $fields as $f ) {
382
- $ids[] = $f[0];
383
- }
384
- sort( $ids );
385
- $field_order_id = end( $ids ) + 1;
386
- } else {
387
- $field_order_id = $field[0];
388
- } ?>
389
- <input type="hidden" name="add_order_id" value="<?php echo $field_order_id; ?>" />
390
- <input type="hidden" name="wpmem_admin_a" value="<?php echo ( $mode == 'edit' ) ? 'edit_field' : 'add_field'; ?>" />
391
- <?php $text = ( $mode == 'edit' ) ? __( 'Edit Field', 'wp-members' ) : __( 'Add Field', 'wp-members' ); ?>
392
- <?php submit_button( $text ); ?>
393
- <p><a href="<?php echo add_query_arg( array( 'page' => 'wpmem-settings', 'tab' => 'fields' ), get_admin_url() . 'options-general.php' ); ?>">&laquo; <?php _e( 'Return to Fields Table', 'wp-members' ); ?></a></p>
394
- </form><?php
395
- }
396
-
397
- /**
398
- * Function to display the table of fields in the field manager tab.
399
- *
400
- * @since 2.8.0
401
- * @since 3.1.8 Changed name from wpmem_a_field_table().
402
- * @since 3.3.0 Changed namme from wpmem_a_render_fields_tab_field_table() to build_field_table().
403
- *
404
- * @global object $wpmem
405
- */
406
- public static function build_field_table() {
407
- global $wpmem;
408
-
409
- $wpmem_ut_fields_skip = array( 'username', 'user_email', 'confirm_email', 'password', 'confirm_password' );
410
- $wpmem_ut_fields = get_option( 'wpmembers_utfields' );
411
- $wpmem_us_fields_skip = array( 'username', 'user_email', 'confirm_email', 'password', 'confirm_password' );
412
- $wpmem_us_fields = get_option( 'wpmembers_usfields' );
413
-
414
- $wpmem_fields = get_option( 'wpmembers_fields', array() );
415
- foreach ( $wpmem_fields as $key => $field ) {
416
-
417
- // @todo - transitional until new array keys
418
- if ( is_numeric( $key ) ) {
419
- // Adjust for profile @todo - temporary until new array keys.
420
- if ( isset( $field['profile'] ) ) {
421
- $profile = ( true === $field['profile'] ) ? 'y' : 'n';
422
- } else {
423
- $profile = $field[4];
424
- }
425
-
426
- $meta = $field[2];
427
- $ut_checked = ( ( $wpmem_ut_fields ) && ( in_array( $field[1], $wpmem_ut_fields ) ) ) ? $field[1] : '';
428
- $us_checked = ( ( $wpmem_us_fields ) && ( in_array( $field[1], $wpmem_us_fields ) ) ) ? $field[1] : '';
429
- $field_items[] = array(
430
- 'order' => $field[0],
431
- 'label' => $field[1],
432
- 'meta' => $meta,
433
- 'type' => $field[3],
434
- 'display' => ( 'user_email' != $meta && 'username' != $meta ) ? wpmem_create_formfield( $meta . "_display", 'checkbox', 'y', $field[4] ) : '',
435
- 'req' => ( 'user_email' != $meta && 'username' != $meta ) ? wpmem_create_formfield( $meta . "_required", 'checkbox', 'y', $field[5] ) : '',
436
- 'profile' => ( 'user_email' != $meta && 'username' != $meta ) ? wpmem_create_formfield( $meta . "_profile", 'checkbox', 'y', $profile ) : '',
437
- 'userscrn' => ( ! in_array( $meta, $wpmem_ut_fields_skip ) ) ? wpmem_create_formfield( 'ut_fields[' . $meta . ']', 'checkbox', $field[1], $ut_checked ) : '',
438
- 'usearch' => ( ! in_array( $meta, $wpmem_us_fields_skip ) ) ? wpmem_create_formfield( 'us_fields[' . $meta . ']', 'checkbox', $field[1], $us_checked ) : '',
439
- 'edit' => self::do_edit_link( $meta ),
440
- 'sort' => '<span class="dashicons dashicons-sort" title="' . __( 'Drag and drop to reorder fields', 'wp-members' ) . '"></span>',
441
- );
442
- }
443
- }
444
-
445
- $extra_user_screen_items = array(
446
- 'user_registered' => __( 'Registration Date', 'wp-members' ),
447
- '_wpmem_user_confirmed' => __( 'Confirmed', 'wp-members' ),
448
- 'active' => __( 'Activated', 'wp-members' ),
449
- 'wpmem_reg_ip' => __( 'Registration IP', 'wp-members' ),
450
- 'exp_type' => __( 'Subscription Type', 'wp-members' ),
451
- 'expires' => __( 'Expires', 'wp-members' ),
452
- 'user_id' => __( 'User ID', 'wp-members' ),
453
- );
454
-
455
- foreach ( $extra_user_screen_items as $key => $item ) {
456
- $ut_checked = ( ( $wpmem_ut_fields ) && ( in_array( $item, $wpmem_ut_fields ) ) ) ? $item : '';
457
- if ( 'user_id' == $key
458
- || 'user_registered' == $key
459
- || 'wpmem_reg_ip' == $key
460
- || ( '_wpmem_user_confirmed' == $key && 1 == $wpmem->act_link )
461
- || ( 'active' == $key && 1 == $wpmem->mod_reg )
462
- || defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 && ( 'exp_type' == $key || 'expires' == $key ) ) {
463
- $user_screen_items[ $key ] = array( 'label' => __( $item, 'wp-members' ), 'meta' => $key,
464
- 'userscrn' => wpmem_create_formfield( "ut_fields[{$key}]", 'checkbox', $item, $ut_checked ),
465
- );
466
- }
467
- }
468
-
469
- foreach ( $user_screen_items as $screen_item ) {
470
- $field_items[] = array(
471
- 'label' => $screen_item['label'],
472
- 'meta' => $screen_item['meta'],
473
- 'type' => '',
474
- 'display' => '',
475
- 'req' => '',
476
- 'profile' => '',
477
- 'userscrn' => $screen_item['userscrn'],
478
- 'usearch' => '',
479
- 'edit' => '',
480
- 'sort' => '',
481
- );
482
- }
483
-
484
- $table = new WP_Members_Fields_Table();
485
-
486
- $heading = __( 'Manage Fields', 'wp-members' );
487
- //$description = __( 'Displaying fields for:', 'wp-members' );
488
- //$which_form = $wpmem->form_tags[ $wpmem->admin->current_form ];
489
-
490
- echo '<div class="wrap">';
491
- printf( '<h3 class="title">%s</h3>', $heading );
492
- //printf( '<p>%s <strong>%s</strong></p>', $description, $which_form );
493
- printf( '<form name="updatefieldform" id="updatefieldform" method="post" action="%s">', wpmem_admin_form_post_url() );
494
-
495
- $table->items = $field_items;
496
- $table->prepare_items();
497
- $table->display();
498
- echo '</form>';
499
- echo '</div>';
500
- }
501
-
502
- /**
503
- * Javascript to ID the fields table and add curser style to rows.
504
- *
505
- * @since 3.1.8
506
- * @since 3.3.0 Changed from wpmem_bulk_fields_actions() to bulk_actions().
507
- */
508
-
509
- public static function bulk_actions() {
510
- if ( 'wpmem-settings' == wpmem_get( 'page', false, 'get' ) && 'fields' == wpmem_get( 'tab', false, 'get' ) ) {
511
- ?><script type="text/javascript">
512
- (function($) {
513
- $(document).ready(function() {
514
- $("table").attr("id", "wpmem-fields");
515
- /**$("tr").attr('style', 'cursor:move;');**/
516
- });
517
- })(jQuery);
518
- jQuery('<input id="add_field" name="add_field" class="button action" type="submit" value="<?php _e( 'Add Field', 'wp-members' ); ?>" />').appendTo(".top .bulkactions");
519
- jQuery('<input id="add_field" name="add_field" class="button action" type="submit" value="<?php _e( 'Add Field', 'wp-members' ); ?>" />').appendTo(".bottom .bulkactions");
520
- </script><?php
521
- }
522
- }
523
-
524
- /**
525
- * Updates fields.
526
- *
527
- * Derived from wpmem_update_fields()
528
- *
529
- * @since 3.1.8
530
- * @since 3.3.0 Changed from wpmem_admin_fields_update() to update().
531
- *
532
- * @global object $wpmem
533
- * @global string $did_update
534
- * @global string $add_field_err_msg The add field error message
535
- */
536
- public static function update() {
537
-
538
- global $wpmem, $did_update, $delete_action;
539
-
540
- if ( 'wpmem-settings' == wpmem_get( 'page', false, 'get' ) && 'fields' == wpmem_get( 'tab', false, 'get' ) ) {
541
- // Get the current fields.
542
- $wpmem_fields = get_option( 'wpmembers_fields' );
543
-
544
- $action = sanitize_text_field( wpmem_get( 'action', false ) );
545
- $action = ( -1 == $action ) ? sanitize_text_field( wpmem_get( 'action2' ) ) : $action;
546
-
547
- $delete_action = false;
548
-
549
- if ( 'save' == $action ) {
550
-
551
- // Check nonce.
552
- check_admin_referer( 'bulk-settings_page_wpmem-settings' );
553
-
554
- // Update user table fields.
555
- $arr = ( isset( $_POST['ut_fields'] ) ) ? $_POST['ut_fields'] : array();
556
- $ut_fields_arr = array();
557
- foreach ( $arr as $key => $item ) {
558
- $ut_fields_arr[ sanitize_text_field( $key ) ] = sanitize_text_field( $item );
559
- }
560
- update_option( 'wpmembers_utfields', $ut_fields_arr );
561
-
562
- // Update user search fields.
563
- $arr = ( isset( $_POST['us_fields'] ) ) ? $_POST['us_fields'] : array();
564
- $us_fields_arr = array();
565
- foreach ( $arr as $key => $item ) {
566
- $us_fields_arr[ sanitize_text_field( $key ) ] = sanitize_text_field( $item );
567
- }
568
- update_option( 'wpmembers_usfields', $us_fields_arr );
569
-
570
- // Update display/required settings
571
- foreach ( $wpmem_fields as $key => $field ) {
572
- $meta_key = $field[2];
573
- if ( 'username' == $meta_key || 'user_email' == $meta_key ) {
574
- $wpmem_fields[ $key ][4] = 'y';
575
- $wpmem_fields[ $key ][5] = 'y';
576
- $wpmem_fields[ $key ]['profile'] = ( 'username' == $meta_key ) ? false : true;
577
- } else {
578
- $wpmem_fields[ $key ][4] = ( wpmem_get( $meta_key . "_display" ) ) ? 'y' : '';
579
- $wpmem_fields[ $key ][5] = ( wpmem_get( $meta_key . "_required" ) ) ? 'y' : '';
580
- $wpmem_fields[ $key ]['profile'] = ( wpmem_get( $meta_key . '_profile' ) ) ? true : false;
581
- }
582
- }
583
- update_option( 'wpmembers_fields', $wpmem_fields );
584
- $wpmem->load_fields();
585
- $did_update = __( 'WP-Members fields were updated', 'wp-members' );
586
- return $did_update;
587
-
588
- } elseif ( 'delete' == $action ) {
589
-
590
- // Check nonce.
591
- check_admin_referer( 'bulk-settings_page_wpmem-settings' );
592
-
593
- $delete_action = 'delete';
594
-
595
- } elseif ( ( 'add_field' == wpmem_get( 'wpmem_admin_a' ) || 'edit_field' == wpmem_get( 'wpmem_admin_a' ) ) && check_admin_referer( 'wpmem_add_field' ) ) {
596
-
597
- // Set action.
598
- $action = sanitize_text_field( wpmem_get( 'wpmem_admin_a' ) );
599
-
600
- global $add_field_err_msg;
601
-
602
- $add_field_err_msg = false;
603
- $add_name = sanitize_text_field( wpmem_get( 'add_name' ) );
604
- $add_option = sanitize_text_field( wpmem_get( 'add_option' ) );
605
-
606
- // Error check that field label and option name are included and unique.
607
- $add_field_err_msg = ( ! $add_name ) ? __( 'Field Label is required. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
608
- $add_field_err_msg = ( ! $add_option ) ? __( 'Meta Key is required. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
609
-
610
- $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;
611
-
612
- // Check for duplicate field names.
613
- $chk_fields = array();
614
- foreach ( $wpmem_fields as $field ) {
615
- $chk_fields[] = $field[2];
616
- }
617
- $add_field_err_msg = ( in_array( $add_option, $chk_fields ) ) ? __( 'A field with that meta key already exists', 'wp-members' ) : $add_field_err_msg;
618
-
619
- // Error check for reserved terms.
620
- $reserved_terms = wpmem_wp_reserved_terms();
621
- if ( in_array( strtolower( $add_option ), $reserved_terms ) ) {
622
- $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 );
623
- }
624
-
625
- // Error check option name for spaces and replace with underscores.
626
- $us_option = preg_replace( "/ /", '_', $add_option );
627
-
628
- $arr = array();
629
-
630
- $type = sanitize_text_field( wpmem_get( 'add_type' ) );
631
-
632
- $arr[0] = filter_var( wpmem_get( 'add_order_id' ), FILTER_SANITIZE_NUMBER_INT );
633
- $arr[1] = sanitize_text_field( stripslashes( wpmem_get( 'add_name' ) ) );
634
- $arr[2] = $us_option;
635
- $arr[3] = $type;
636
- $arr[4] = ( 'y' == wpmem_get( 'add_display', 'n' ) ) ? 'y' : 'n';
637
- $arr[5] = ( 'y' == wpmem_get( 'add_required', 'n' ) ) ? 'y' : 'n';
638
-
639
- // Mark native fields:
640
- $native_fields = array( 'user_login', 'user_pass', 'user_nicename', 'user_email', 'user_url', 'user_registered', 'display_name', 'first_name', 'last_name', 'nickname', 'description' );
641
- $arr[6] = ( in_array( $us_option, $native_fields ) ) ? 'y' : 'n';
642
-
643
- if ( 'text' == $type || 'email' == $type || 'textarea' == $type || 'password' == $type || 'url' == $type || 'number' == $type || 'date' == $type ) {
644
- $arr['placeholder'] = sanitize_text_field( stripslashes( wpmem_get( 'add_placeholder' ) ) );
645
- }
646
-
647
- if ( 'text' == $type || 'email' == $type || 'password' == $type || 'url' == $type || 'number' == $type || 'date' == $type ) {
648
- $arr['pattern'] = sanitize_text_field( stripslashes( wpmem_get( 'add_pattern' ) ) );
649
- $arr['title'] = sanitize_text_field( stripslashes( wpmem_get( 'add_title' ) ) );
650
- }
651
-
652
- if ( 'number' == $type || 'date' == $type ) {
653
- $arr['min'] = filter_var( wpmem_get( 'add_min' ), FILTER_SANITIZE_NUMBER_INT );
654
- $arr['max'] = filter_var( wpmem_get( 'add_max' ), FILTER_SANITIZE_NUMBER_INT );
655
- }
656
-
657
- if ( 'textarea' == $type ) {
658
- $arr['rows'] = filter_var( wpmem_get( 'add_rows' ), FILTER_SANITIZE_NUMBER_INT );
659
- $arr['cols'] = filter_var( wpmem_get( 'add_cols' ), FILTER_SANITIZE_NUMBER_INT );
660
- }
661
-
662
- if ( $type == 'checkbox' ) {
663
- $add_field_err_msg = ( ! $_POST['add_checked_value'] ) ? __( 'Checked value is required for checkboxes. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
664
- $arr[7] = sanitize_text_field( wpmem_get( 'add_checked_value', false ) );
665
- $arr[8] = ( 'y' == wpmem_get( 'add_checked_default', 'n' ) ) ? 'y' : 'n';
666
- }
667
-
668
- if ( $type == 'select'
669
- || $type == 'multiselect'
670
- || $type == 'radio'
671
- || $type == 'multicheckbox'
672
- ) {
673
- // Get the values.
674
- $str = stripslashes( sanitize_textarea_field( $_POST['add_dropdown_value'] ) );
675
- // Remove linebreaks.
676
- $str = trim( str_replace( array("\r", "\r\n", "\n"), '', $str ) );
677
- // Create array.
678
- if ( ! function_exists( 'str_getcsv' ) ) {
679
- $arr[7] = explode( ',', $str );
680
- } else {
681
- $arr[7] = str_getcsv( $str, ',', '"' );
682
- }
683
- // If multiselect or multicheckbox, set delimiter.
684
- if ( 'multiselect' == $type || 'multicheckbox' == $type ) {
685
- $arr[8] = ( ',' === wpmem_get( 'add_delimiter_value', '|' ) ) ? ',' : '|';
686
- }
687
- }
688
-
689
- if ( $type == 'file' || $type == 'image' ) {
690
- $arr[7] = sanitize_text_field( stripslashes( $_POST['add_file_value'] ) );
691
- }
692
-
693
- if ( wpmem_get( 'add_type' ) == 'hidden' ) {
694
- $add_field_err_msg = ( ! $_POST['add_hidden_value'] ) ? __( 'A value is required for hidden fields. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
695
- $arr[7] = ( isset( $_POST['add_hidden_value'] ) ) ? sanitize_text_field( stripslashes( $_POST['add_hidden_value'] ) ) : '';
696
- }
697
-
698
- if ( $action == 'add_field' ) {
699
- if ( ! $add_field_err_msg ) {
700
- array_push( $wpmem_fields, $arr );
701
- $did_update = sprintf( __( '%s was added', 'wp-members' ), esc_html( $_POST['add_name'] ) );
702
- } else {
703
- $did_update = $add_field_err_msg;
704
- }
705
- } else {
706
- for ( $row = 0; $row < count( $wpmem_fields ); $row++ ) {
707
- if ( $wpmem_fields[ $row ][2] == wpmem_get( 'field', false, 'get' ) ) {
708
- $arr[0] = $wpmem_fields[ $row ][0];
709
- foreach ( $arr as $key => $value ) {
710
- $wpmem_fields[ $row ][ $key ] = $arr[ $key ];
711
- }
712
- }
713
- }
714
- $did_update = sprintf( __( '%s was updated', 'wp-members' ), esc_html( stripslashes( $add_name ) ) );
715
- $did_update.= '<p><a href="' . esc_url( add_query_arg( array( 'page' => 'wpmem-settings', 'tab' => 'fields' ), get_admin_url() . 'options-general.php' ) ) . '">&laquo; ' . __( 'Return to Fields Table', 'wp-members' ) . '</a></p>';
716
- }
717
-
718
- $wpmem_newfields = $wpmem_fields;
719
-
720
- update_option( 'wpmembers_fields', $wpmem_newfields );
721
- $wpmem->load_fields();
722
- return $did_update;
723
- }
724
- }
725
- }
726
-
727
- /**
728
- * Reorders form fields.
729
- *
730
- * @since 2.5.1
731
- * @since 3.1.8 Rebuilt for new List Table.
732
- * @since 3.3.0 Merged do_field_reorder() and field_reorder().
733
- */
734
- public static function do_field_reorder() {
735
-
736
- // Start fresh.
737
- $new_order = $wpmem_fields = $field = $key = $wpmem_new_fields = $id = $k = '';
738
- $wpmem_fields = get_option( 'wpmembers_fields' );
739
-
740
- // Get the list items
741
- $new_order = $_POST;
742
-
743
- // Put fields in the proper order for the current form.
744
- $wpmem_new_fields = array();
745
- foreach ( $new_order['list_items'] as $id ) {
746
- foreach( $wpmem_fields as $val ) {
747
- if ( $val[0] == $id ) {
748
- $wpmem_new_fields[] = $val;
749
- }
750
- }
751
- }
752
-
753
- // Save fields array with new current form field order.
754
- update_option( 'wpmembers_fields', $wpmem_new_fields );
755
-
756
- // Indicate successful transaction.
757
- _e( 'Form field order updated.', 'wp-members' );
758
-
759
- die(); // This is required to return a proper result.
760
-
761
- }
762
- }
 
 
 
 
 
 
 
 
 
 
 
763
  // 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-2021 Chad Butler
10
+ * WP-Members(tm) is a trademark of butlerblog.com
11
+ *
12
+ * @package WP-Members
13
+ * @author Chad Butler
14
+ * @copyright 2006-2021
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_sanitize_array( 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
+ } else {
160
+ $field['checkbox_label'] = ''; // fixes unset variable at 308/309 since $field would not be set.
161
+ }
162
+ $form_action = ( $mode == 'edit' ) ? 'editfieldform' : 'addfieldform';
163
+ $span_optional = '<span class="description">' . __( '(optional)', 'wp-members' ) . '</span>';
164
+ $span_required = '<span class="req">' . __( '(required)', 'wp-members' ) . '</span>';
165
+ $form_submit = array( 'mode' => $mode );
166
+ if ( isset( $_GET['field'] ) ) {
167
+ $form_submit['field'] = $meta_key;
168
+ } ?>
169
+ <h3 class="title"><?php ( $mode == 'edit' ) ? _e( 'Edit Field', 'wp-members' ) : _e( 'Add a Field', 'wp-members' ); ?></h3>
170
+ <form name="<?php echo $form_action; ?>" id="<?php echo $form_action; ?>" method="post" action="<?php echo wpmem_admin_form_post_url( $form_submit ); ?>">
171
+ <?php wp_nonce_field( 'wpmem_add_field' ); ?>
172
+ <ul>
173
+ <li>
174
+ <label><?php _e( 'Field Label', 'wp-members' ); ?> <?php echo $span_required; ?></label>
175
+ <input type="text" name="add_name" value="<?php echo ( $mode == 'edit' ) ? $field['label'] : false; ?>" required />
176
+ <?php _e( 'The name of the field as it will be displayed to the user.', 'wp-members' ); ?>
177
+ </li>
178
+ <li>
179
+ <label><?php _e( 'Meta Key', 'wp-members' ); ?> <?php echo $span_required; ?></label>
180
+ <?php if ( $mode == 'edit' ) {
181
+ echo "<span>$meta_key</span>"; ?>
182
+ <input type="hidden" name="add_option" value="<?php echo $meta_key; ?>" required />
183
+ <?php } else { ?>
184
+ <input type="text" name="add_option" value="" />
185
+ <?php _e( 'The database meta value for the field. It must be unique and contain no spaces (underscores are ok).', 'wp-members' ); ?>
186
+ <?php } ?>
187
+ </li>
188
+ <li>
189
+ <label><?php _e( 'Field Type', 'wp-members' ); ?></label>
190
+ <?php if ( $mode == 'edit' ) {
191
+ echo '<span>' . $field['type'] . '</span>'; ?>
192
+ <input type="hidden" name="add_type" value="<?php echo $field['type']; ?>" />
193
+ <?php } else { ?>
194
+ <select name="add_type" id="wpmem_field_type_select">
195
+ <option value="text"><?php _e( 'text', 'wp-members' ); ?></option>
196
+ <option value="email"><?php _e( 'email', 'wp-members' ); ?></option>
197
+ <option value="textarea"><?php _e( 'textarea', 'wp-members' ); ?></option>
198
+ <option value="checkbox"><?php _e( 'checkbox', 'wp-members' ); ?></option>
199
+ <option value="multicheckbox"><?php _e( 'multiple checkbox', 'wp-members' ); ?></option>
200
+ <option value="select"><?php _e( 'select (dropdown)', 'wp-members' ); ?></option>
201
+ <option value="multiselect"><?php _e( 'multiple select', 'wp-members' ); ?></option>
202
+ <option value="radio"><?php _e( 'radio group', 'wp-members' ); ?></option>
203
+ <option value="password"><?php _e( 'password', 'wp-members' ); ?></option>
204
+ <option value="image"><?php _e( 'image', 'wp-members' ); ?></option>
205
+ <option value="file"><?php _e( 'file', 'wp-members' ); ?></option>
206
+ <option value="url"><?php _e( 'url', 'wp-members' ); ?></option>
207
+ <option value="number"><?php _e( 'number', 'wp-members' ); ?></option>
208
+ <option value="date"><?php _e( 'date', 'wp-members' ); ?></option>
209
+ <option value="hidden"><?php _e( 'hidden', 'wp-members' ); ?></option>
210
+ <?php if ( $wpmem->enable_products ) { ?>
211
+ <option value="membership"><?php _e( 'membership', 'wp-members' ); ?></option>
212
+ <?php } ?>
213
+ </select>
214
+ <?php } ?>
215
+ </li>
216
+ <li>
217
+ <label><?php _e( 'Display?', 'wp-members' ); ?></label>
218
+ <?php if ( 'username' != $meta_key && 'user_email' != $meta_key ) { ?>
219
+ <input type="checkbox" name="add_display" value="y" <?php echo ( $mode == 'edit' ) ? checked( true, $field['register'] ) : false; ?> />
220
+ <?php } else { ?>
221
+ <span><?php _e( 'This field is always displayed', 'wp-members' ); ?></span>
222
+ <input type="hidden" name="add_display" value="y" />
223
+ <?php } ?>
224
+ </li>
225
+ <li>
226
+ <label><?php _e( 'Required?', 'wp-members' ); ?></label>
227
+ <?php if ( 'username' != $meta_key && 'user_email' != $meta_key ) { ?>
228
+ <input type="checkbox" name="add_required" value="y" <?php echo ( $mode == 'edit' ) ? checked( true, $field['required'] ) : false; ?> />
229
+ <?php } else { ?>
230
+ <span><?php _e( 'This field is always required', 'wp-members' ); ?></span>
231
+ <input type="hidden" name="add_required" value="y" />
232
+ <?php } ?>
233
+ </li>
234
+ <!--<div id="wpmem_allowhtml">
235
+ <li>
236
+ <label><?php _e( 'Allow HTML?', 'wp-members' ); ?></label>
237
+ <input type="checkbox" name="add_html" value="y" <?php echo ( $mode == 'edit' ) ? checked( true, $field['html'] ) : false; ?> />
238
+ </li>
239
+ </div>-->
240
+ <?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'text', 'password', 'email', 'url', 'number', 'date', 'textarea' ) ) ) ) ) { ?>
241
+ <?php echo ( $mode == 'add' ) ? '<div id="wpmem_placeholder">' : ''; ?>
242
+ <li>
243
+ <label><?php _e( 'Placeholder', 'wp-members' ); ?></label>
244
+ <input type="text" name="add_placeholder" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['placeholder'] ) ? $field['placeholder'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
245
+ </li>
246
+ <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
247
+ <?php } ?>
248
+ <?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'text', 'password', 'email', 'url', 'date' ) ) ) ) ) { ?>
249
+ <?php echo ( $mode == 'add' ) ? '<div id="wpmem_pattern">' : ''; ?>
250
+ <li>
251
+ <label><?php _e( 'Pattern', 'wp-members' ); ?></label>
252
+ <input type="text" name="add_pattern" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['pattern'] ) ? $field['pattern'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
253
+ </li>
254
+ <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
255
+ <?php } ?>
256
+ <?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'text', 'password', 'email', 'url', 'number', 'date' ) ) ) ) ) { ?>
257
+ <?php echo ( $mode == 'add' ) ? '<div id="wpmem_title">' : ''; ?>
258
+ <li>
259
+ <label><?php _e( 'Title', 'wp-members' ); ?></label>
260
+ <input type="text" name="add_title" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['title'] ) ? $field['title'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
261
+ </li>
262
+ <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
263
+ <?php } ?>
264
+
265
+ <?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'number', 'date' ) ) ) ) ) { ?>
266
+ <?php echo ( $mode == 'add' ) ? '<div id="wpmem_min_max">' : ''; ?>
267
+ <li>
268
+ <label><?php _e( 'Minimum Value', 'wp-members' ); ?></label>
269
+ <input type="text" name="add_min" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['min'] ) ? $field['min'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
270
+ </li>
271
+ <li>
272
+ <label><?php _e( 'Maximum Value', 'wp-members' ); ?></label>
273
+ <input type="text" name="add_max" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['max'] ) ? $field['max'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
274
+ </li>
275
+ <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
276
+ <?php } ?>
277
+ <?php if ( $mode == 'add' || ( $mode == 'edit' && ( in_array( $field['type'], array( 'textarea' ) ) ) ) ) { ?>
278
+ <?php echo ( $mode == 'add' ) ? '<div id="wpmem_rows_cols">' : ''; ?>
279
+ <li>
280
+ <label><?php _e( 'Rows', 'wp-members' ); ?></label>
281
+ <input type="number" name="add_rows" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['rows'] ) ? $field['rows'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
282
+ </li>
283
+ <li>
284
+ <label><?php _e( 'Columns', 'wp-members' ); ?></label>
285
+ <input type="number" name="add_cols" value="<?php echo ( $mode == 'edit' ) ? ( isset( $field['cols'] ) ? $field['cols'] : false ) : false; ?>" /> <?php echo $span_optional; ?>
286
+ </li>
287
+ <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
288
+ <?php } ?>
289
+ <?php if ( $mode == 'add' || ( $mode == 'edit' && ( $field['type'] == 'file' || $field['type'] == 'image' ) ) ) { ?>
290
+ <?php echo ( $mode == 'add' ) ? '<div id="wpmem_file_info">' : ''; ?>
291
+ <li>
292
+ <label><?php _e( 'Accepted file types:', 'wp-members' ); ?></label>
293
+ <input type="text" name="add_file_value" value="<?php echo ( $mode == 'edit' && ( $field['type'] == 'file' || $field['type'] == 'image' ) ) ? $field['file_types'] : false; ?>" />
294
+ </li>
295
+ <li>
296
+ <label>&nbsp;</label>
297
+ <span class="description"><?php _e( 'Accepted file types should be set like this: jpg|jpeg|png|gif', 'wp-members' ); ?></span>
298
+ </li>
299
+ <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
300
+ <?php } ?>
301
+ <?php if ( $mode == 'add' || ( $mode == 'edit' && $field['type'] == 'checkbox' ) ) { ?>
302
+ <?php echo ( $mode == 'add' ) ? '<div id="wpmem_checkbox_info">' : ''; ?>
303
+ <li>
304
+ <label><?php _e( 'Checked by default?', 'wp-members' ); ?></label>
305
+ <input type="checkbox" name="add_checked_default" value="y" <?php echo ( $mode == 'edit' && $field['type'] == 'checkbox' ) ? checked( true, $field['checked_default'] ) : false; ?> />
306
+ </li>
307
+ <li>
308
+ <label><?php _e( 'HTML label position', 'wp-members' ); ?></label>
309
+ <select name="add_checkbox_label">
310
+ <option value="0" <?php selected( $field['checkbox_label'], 0 ); ?>><?php _e( 'Before the input tag', 'wp-members' ); ?></option>
311
+ <option value="1" <?php selected( $field['checkbox_label'], 1 ); ?>><?php _e( 'After the input tag', 'wp-members' ); ?></option>
312
+ </select> <span class="description"><?php _e( 'Selecting "after" will generally display the label to the right of the checkbox', 'wp-members' ); ?></span>
313
+ </li>
314
+ <li>
315
+ <label><?php _e( 'Stored value if checked:', 'wp-members' ); ?> <span class="req"><?php _e( '(required)', 'wp-members' ); ?></span></label>
316
+ <input type="text" name="add_checked_value" id="add_checked_value" value="<?php echo ( $mode == 'edit' && $field['type'] == 'checkbox' ) ? $field['checked_value'] : false; ?>" />
317
+ </li>
318
+ <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
319
+ <?php }
320
+
321
+ if ( isset( $field['type'] ) ) {
322
+ $additional_settings = ( $field['type'] == 'select' || $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' || $field['type'] == 'radio' ) ? true : false;
323
+ $delimiter_settings = ( $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' ) ? true : false;
324
+ }
325
+ if ( $mode == 'add' || ( $mode == 'edit' && $additional_settings ) ) { ?>
326
+ <?php echo ( $mode == 'add' ) ? '<div id="wpmem_dropdown_info">' : ''; ?>
327
+ <?php if ( $mode == 'add' || ( $mode == 'edit' && $delimiter_settings ) ) {
328
+ echo ( $mode == 'add' ) ? '<div id="wpmem_delimiter_info">' : '';
329
+ if ( isset( $field['delimiter'] ) && ( "|" == $field['delimiter'] || "," == $field['delimiter'] ) ) {
330
+ $delimiter = $field['delimiter'];
331
+ } else {
332
+ $delimiter = "|";
333
+ }
334
+ ?>
335
+ <li>
336
+ <label><?php _e( 'Stored values delimiter:', 'wp-members' ); ?></label>
337
+ <select name = "add_delimiter_value">
338
+ <option value="|" <?php selected( '|', $delimiter ); ?>>pipe "|"</option>
339
+ <option value="," <?php selected( ',', $delimiter ); ?>>comma ","</option>
340
+ </select>
341
+ </li>
342
+ <?php echo ( $mode == 'add' ) ? '</div>' : '';
343
+ } ?>
344
+ <li>
345
+ <label style="vertical-align:top"><?php _e( 'Values (Displayed|Stored):', 'wp-members' ); ?> <?php echo $span_required; ?></label>
346
+ <textarea name="add_dropdown_value" id="add_dropdown_value" rows="5" cols="40"><?php
347
+ // Accomodate editing the current dropdown values or create dropdown value example.
348
+ if ( $mode == 'edit' ) {
349
+ for ( $row = 0; $row < count( $field['values'] ); $row++ ) {
350
+ // If the row contains commas (i.e. 1,000-10,000), wrap in double quotes.
351
+ if ( strstr( $field['values'][ $row ], ',' ) ) {
352
+ echo '"' . $field['values'][ $row ]; echo ( $row == count( $field['values'] )- 1 ) ? '"' : "\",\n";
353
+ } else {
354
+ echo $field['values'][ $row ]; echo ( $row == count( $field['values'] )- 1 ) ? "" : ",\n";
355
+ } }
356
+ } else {
357
+ if (version_compare(PHP_VERSION, '5.3.0') >= 0) { ?>
358
+ ---- Select One ----|,
359
+ Choice One|choice_one,
360
+ "1,000|one_thousand",
361
+ "1,000-10,000|1,000-10,000",
362
+ Last Row|last_row<?php } else { ?>
363
+ ---- Select One ----|,
364
+ Choice One|choice_one,
365
+ Choice 2|choice_two,
366
+ Last Row|last_row<?php } } ?></textarea>
367
+ </li>
368
+ <li>
369
+ <label>&nbsp;</label>
370
+ <span class="description"><?php _e( 'Options should be Option Name|option_value,', 'wp-members' ); ?></span>
371
+ </li>
372
+ <li>
373
+ <label>&nbsp;</label>
374
+ <span class="description"><a href="https://rocketgeek.com/plugins/wp-members/docs/registration/choosing-fields/" target="_blank"><?php _e( 'Visit plugin site for more information', 'wp-members' ); ?></a></span>
375
+ </li>
376
+ <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
377
+ <?php } ?>
378
+ <?php if ( $mode == 'add' || ( $mode == 'edit' && $field['type'] == 'hidden' ) ) { ?>
379
+ <?php echo ( $mode == 'add' ) ? '<div id="wpmem_hidden_info">' : ''; ?>
380
+ <li>
381
+ <label><?php _e( 'Value', 'wp-members' ); ?> <?php echo $span_required; ?></label>
382
+ <input type="text" name="add_hidden_value" id="add_hidden_value" value="<?php echo ( $mode == 'edit' && $field['type'] == 'hidden' ) ? $field['value'] : ''; ?>" />
383
+ </li>
384
+ <?php echo ( $mode == 'add' ) ? '</div>' : ''; ?>
385
+ <?php } ?>
386
+ </ul><br />
387
+ <?php if ( $mode == 'edit' ) { ?><input type="hidden" name="field_arr" value="<?php echo $meta_key; ?>" /><?php } ?>
388
+ <?php if ( 'add' == $mode ) {
389
+ $ids = array();
390
+ foreach ( $fields as $f ) {
391
+ $ids[] = $f[0];
392
+ }
393
+ sort( $ids );
394
+ $field_order_id = end( $ids ) + 1;
395
+ } else {
396
+ $field_order_id = $field[0];
397
+ } ?>
398
+ <input type="hidden" name="add_order_id" value="<?php echo $field_order_id; ?>" />
399
+ <input type="hidden" name="wpmem_admin_a" value="<?php echo ( $mode == 'edit' ) ? 'edit_field' : 'add_field'; ?>" />
400
+ <?php $text = ( $mode == 'edit' ) ? __( 'Save Changes', 'wp-members' ) : __( 'Add Field', 'wp-members' ); ?>
401
+ <?php submit_button( $text ); ?>
402
+ <p><a href="<?php echo add_query_arg( array( 'page' => 'wpmem-settings', 'tab' => 'fields' ), get_admin_url() . 'options-general.php' ); ?>">&laquo; <?php _e( 'Return to Fields Table', 'wp-members' ); ?></a></p>
403
+ </form><?php
404
+ }
405
+
406
+ /**
407
+ * Function to display the table of fields in the field manager tab.
408
+ *
409
+ * @since 2.8.0
410
+ * @since 3.1.8 Changed name from wpmem_a_field_table().
411
+ * @since 3.3.0 Changed namme from wpmem_a_render_fields_tab_field_table() to build_field_table().
412
+ *
413
+ * @global object $wpmem
414
+ */
415
+ public static function build_field_table() {
416
+ global $wpmem;
417
+
418
+ $wpmem_ut_fields_skip = array( 'username', 'user_email', 'confirm_email', 'password', 'confirm_password' );
419
+ $wpmem_ut_fields = get_option( 'wpmembers_utfields' );
420
+ $wpmem_us_fields_skip = array( 'username', 'user_email', 'confirm_email', 'password', 'confirm_password' );
421
+ $wpmem_us_fields = get_option( 'wpmembers_usfields' );
422
+
423
+ $wpmem_fields = get_option( 'wpmembers_fields', array() );
424
+ foreach ( $wpmem_fields as $key => $field ) {
425
+
426
+ // @todo - transitional until new array keys
427
+ if ( is_numeric( $key ) ) {
428
+ // Adjust for profile @todo - temporary until new array keys.
429
+ if ( isset( $field['profile'] ) ) {
430
+ $profile = ( true === $field['profile'] ) ? 'y' : 'n';
431
+ } else {
432
+ $profile = $field[4];
433
+ }
434
+
435
+ $meta = $field[2];
436
+ $ut_checked = ( ( $wpmem_ut_fields ) && ( in_array( $field[1], $wpmem_ut_fields ) ) ) ? $field[1] : '';
437
+ $us_checked = ( ( $wpmem_us_fields ) && ( in_array( $field[1], $wpmem_us_fields ) ) ) ? $field[1] : '';
438
+ $field_items[] = array(
439
+ 'order' => $field[0],
440
+ 'label' => $field[1],
441
+ 'meta' => $meta,
442
+ 'type' => $field[3],
443
+ 'display' => ( 'user_email' != $meta && 'username' != $meta ) ? wpmem_form_field( $meta . "_display", 'checkbox', 'y', $field[4] ) : '',
444
+ 'req' => ( 'user_email' != $meta && 'username' != $meta ) ? wpmem_form_field( $meta . "_required", 'checkbox', 'y', $field[5] ) : '',
445
+ 'profile' => ( 'user_email' != $meta && 'username' != $meta ) ? wpmem_form_field( $meta . "_profile", 'checkbox', 'y', $profile ) : '',
446
+ 'userscrn' => ( ! in_array( $meta, $wpmem_ut_fields_skip ) ) ? wpmem_form_field( 'ut_fields[' . $meta . ']', 'checkbox', $field[1], $ut_checked ) : '',
447
+ 'usearch' => ( ! in_array( $meta, $wpmem_us_fields_skip ) ) ? wpmem_form_field( 'us_fields[' . $meta . ']', 'checkbox', $field[1], $us_checked ) : '',
448
+ 'edit' => self::do_edit_link( $meta ),
449
+ 'sort' => '<span class="dashicons dashicons-sort" title="' . __( 'Drag and drop to reorder fields', 'wp-members' ) . '"></span>',
450
+ );
451
+ }
452
+ }
453
+
454
+ $extra_user_screen_items = array(
455
+ 'user_registered' => __( 'Registration Date', 'wp-members' ),
456
+ '_wpmem_user_confirmed' => __( 'Confirmed', 'wp-members' ),
457
+ 'active' => __( 'Activated', 'wp-members' ),
458
+ 'wpmem_reg_ip' => __( 'Registration IP', 'wp-members' ),
459
+ 'exp_type' => __( 'Subscription Type', 'wp-members' ),
460
+ 'expires' => __( 'Expires', 'wp-members' ),
461
+ 'user_id' => __( 'User ID', 'wp-members' ),
462
+ );
463
+
464
+ foreach ( $extra_user_screen_items as $key => $item ) {
465
+ $ut_checked = ( ( $wpmem_ut_fields ) && ( in_array( $item, $wpmem_ut_fields ) ) ) ? $item : '';
466
+ if ( 'user_id' == $key
467
+ || 'user_registered' == $key
468
+ || 'wpmem_reg_ip' == $key
469
+ || ( '_wpmem_user_confirmed' == $key && 1 == $wpmem->act_link )
470
+ || ( 'active' == $key && 1 == $wpmem->mod_reg )
471
+ || defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 && ( 'exp_type' == $key || 'expires' == $key ) ) {
472
+ $user_screen_items[ $key ] = array( 'label' => __( $item, 'wp-members' ), 'meta' => $key,
473
+ 'userscrn' => wpmem_form_field( "ut_fields[{$key}]", 'checkbox', $item, $ut_checked ),
474
+ );
475
+ }
476
+ }
477
+
478
+ foreach ( $user_screen_items as $screen_item ) {
479
+ $field_items[] = array(
480
+ 'label' => $screen_item['label'],
481
+ 'meta' => $screen_item['meta'],
482
+ 'type' => '',
483
+ 'display' => '',
484
+ 'req' => '',
485
+ 'profile' => '',
486
+ 'userscrn' => $screen_item['userscrn'],
487
+ 'usearch' => '',
488
+ 'edit' => '',
489
+ 'sort' => '',
490
+ );
491
+ }
492
+
493
+ $table = new WP_Members_Fields_Table();
494
+
495
+ $heading = __( 'Manage Fields', 'wp-members' );
496
+ //$description = __( 'Displaying fields for:', 'wp-members' );
497
+ //$which_form = $wpmem->form_tags[ $wpmem->admin->current_form ];
498
+
499
+ echo '<div class="wrap">';
500
+ printf( '<h3 class="title">%s</h3>', $heading );
501
+ //printf( '<p>%s <strong>%s</strong></p>', $description, $which_form );
502
+ printf( '<form name="updatefieldform" id="updatefieldform" method="post" action="%s">', wpmem_admin_form_post_url() );
503
+
504
+ $table->items = $field_items;
505
+ $table->prepare_items();
506
+ $table->display();
507
+ echo '</form>';
508
+ echo '</div>';
509
+ }
510
+
511
+ /**
512
+ * Javascript to ID the fields table and add curser style to rows.
513
+ *
514
+ * @since 3.1.8
515
+ * @since 3.3.0 Changed from wpmem_bulk_fields_actions() to bulk_actions().
516
+ */
517
+
518
+ public static function bulk_actions() {
519
+ if ( 'wpmem-settings' == wpmem_get( 'page', false, 'get' ) && 'fields' == wpmem_get( 'tab', false, 'get' ) ) {
520
+ ?><script type="text/javascript">
521
+ (function($) {
522
+ $(document).ready(function() {
523
+ $("table").attr("id", "wpmem-fields");
524
+ /**$("tr").attr('style', 'cursor:move;');**/
525
+ });
526
+ })(jQuery);
527
+ jQuery('<input id="add_field" name="add_field" class="button action" type="submit" value="<?php _e( 'Add Field', 'wp-members' ); ?>" />').appendTo(".top .bulkactions");
528
+ jQuery('<input id="add_field2" name="add_field" class="button action" type="submit" value="<?php _e( 'Add Field', 'wp-members' ); ?>" />').appendTo(".bottom .bulkactions");
529
+ </script><?php
530
+ }
531
+ }
532
+
533
+ /**
534
+ * Updates fields.
535
+ *
536
+ * Derived from wpmem_update_fields()
537
+ *
538
+ * @since 3.1.8
539
+ * @since 3.3.0 Changed from wpmem_admin_fields_update() to update().
540
+ * @since 3.3.9 load_fields() moved to forms object class.
541
+ *
542
+ * @global object $wpmem
543
+ * @global string $did_update
544
+ * @global string $add_field_err_msg The add field error message
545
+ */
546
+ public static function update() {
547
+
548
+ global $wpmem, $did_update, $delete_action;
549
+
550
+ if ( 'wpmem-settings' == wpmem_get( 'page', false, 'get' ) && 'fields' == wpmem_get( 'tab', false, 'get' ) ) {
551
+ // Get the current fields.
552
+ $wpmem_fields = get_option( 'wpmembers_fields' );
553
+
554
+ $action = sanitize_text_field( wpmem_get( 'action', false ) );
555
+ $action = ( -1 == $action ) ? sanitize_text_field( wpmem_get( 'action2' ) ) : $action;
556
+
557
+ $delete_action = false;
558
+
559
+ if ( 'save' == $action ) {
560
+
561
+ // Check nonce.
562
+ check_admin_referer( 'bulk-settings_page_wpmem-settings' );
563
+
564
+ // Update user table fields.
565
+ $arr = ( isset( $_POST['ut_fields'] ) ) ? $_POST['ut_fields'] : array();
566
+ $ut_fields_arr = array();
567
+ foreach ( $arr as $key => $item ) {
568
+ $ut_fields_arr[ sanitize_text_field( $key ) ] = sanitize_text_field( $item );
569
+ }
570
+ update_option( 'wpmembers_utfields', $ut_fields_arr );
571
+
572
+ // Update user search fields.
573
+ $arr = ( isset( $_POST['us_fields'] ) ) ? $_POST['us_fields'] : array();
574
+ $us_fields_arr = array();
575
+ foreach ( $arr as $key => $item ) {
576
+ $us_fields_arr[ sanitize_text_field( $key ) ] = sanitize_text_field( $item );
577
+ }
578
+ update_option( 'wpmembers_usfields', $us_fields_arr );
579
+
580
+ // Update display/required settings
581
+ foreach ( $wpmem_fields as $key => $field ) {
582
+ $meta_key = $field[2];
583
+ if ( 'username' == $meta_key || 'user_email' == $meta_key ) {
584
+ $wpmem_fields[ $key ][4] = 'y';
585
+ $wpmem_fields[ $key ][5] = 'y';
586
+ $wpmem_fields[ $key ]['profile'] = ( 'username' == $meta_key ) ? false : true;
587
+ } else {
588
+ $wpmem_fields[ $key ][4] = ( wpmem_get( $meta_key . "_display" ) ) ? 'y' : '';
589
+ $wpmem_fields[ $key ][5] = ( wpmem_get( $meta_key . "_required" ) ) ? 'y' : '';
590
+ $wpmem_fields[ $key ]['profile'] = ( wpmem_get( $meta_key . '_profile' ) ) ? true : false;
591
+ }
592
+ }
593
+ update_option( 'wpmembers_fields', $wpmem_fields );
594
+ $wpmem->forms->load_fields();
595
+ $did_update = __( 'WP-Members fields were updated', 'wp-members' );
596
+ return $did_update;
597
+
598
+ } elseif ( 'delete' == $action ) {
599
+
600
+ // Check nonce.
601
+ check_admin_referer( 'bulk-settings_page_wpmem-settings' );
602
+
603
+ $delete_action = 'delete';
604
+
605
+ } elseif ( ( 'add_field' == wpmem_get( 'wpmem_admin_a' ) || 'edit_field' == wpmem_get( 'wpmem_admin_a' ) ) && check_admin_referer( 'wpmem_add_field' ) ) {
606
+
607
+ // Set action.
608
+ $action = sanitize_text_field( wpmem_get( 'wpmem_admin_a' ) );
609
+
610
+ global $add_field_err_msg;
611
+
612
+ $add_field_err_msg = false;
613
+ $add_name = sanitize_text_field( wpmem_get( 'add_name' ) );
614
+ $add_option = sanitize_text_field( wpmem_get( 'add_option' ) );
615
+
616
+ // Error check that field label and option name are included and unique.
617
+ $add_field_err_msg = ( ! $add_name ) ? __( 'Field Label is required. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
618
+ $add_field_err_msg = ( ! $add_option ) ? __( 'Meta Key is required. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
619
+
620
+ $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;
621
+
622
+ // Check for duplicate field names.
623
+ $chk_fields = array();
624
+ foreach ( $wpmem_fields as $field ) {
625
+ $chk_fields[] = $field[2];
626
+ }
627
+ $add_field_err_msg = ( in_array( $add_option, $chk_fields ) ) ? __( 'A field with that meta key already exists', 'wp-members' ) : $add_field_err_msg;
628
+
629
+ // Error check for reserved terms.
630
+ $reserved_terms = wpmem_wp_reserved_terms();
631
+ if ( in_array( strtolower( $add_option ), $reserved_terms ) ) {
632
+ $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 );
633
+ }
634
+
635
+ // Error check option name for spaces and replace with underscores.
636
+ $us_option = preg_replace( "/ /", '_', $add_option );
637
+
638
+ $arr = array();
639
+
640
+ $type = sanitize_text_field( wpmem_get( 'add_type' ) );
641
+
642
+ $arr[0] = filter_var( wpmem_get( 'add_order_id' ), FILTER_SANITIZE_NUMBER_INT );
643
+ $arr[1] = sanitize_text_field( stripslashes( wpmem_get( 'add_name' ) ) );
644
+ $arr[2] = $us_option;
645
+ $arr[3] = $type;
646
+ $arr[4] = ( 'y' == wpmem_get( 'add_display', 'n' ) ) ? 'y' : 'n';
647
+ $arr[5] = ( 'y' == wpmem_get( 'add_required', 'n' ) ) ? 'y' : 'n';
648
+
649
+ // Mark native fields:
650
+ $native_fields = array( 'user_login', 'user_pass', 'user_nicename', 'user_email', 'user_url', 'user_registered', 'display_name', 'first_name', 'last_name', 'nickname', 'description' );
651
+ $arr[6] = ( in_array( $us_option, $native_fields ) ) ? 'y' : 'n';
652
+
653
+ if ( 'text' == $type || 'email' == $type || 'textarea' == $type || 'password' == $type || 'url' == $type || 'number' == $type || 'date' == $type ) {
654
+ $arr['placeholder'] = sanitize_text_field( stripslashes( wpmem_get( 'add_placeholder' ) ) );
655
+ }
656
+
657
+ if ( 'text' == $type || 'email' == $type || 'password' == $type || 'url' == $type || 'number' == $type || 'date' == $type ) {
658
+ $arr['pattern'] = sanitize_text_field( stripslashes( wpmem_get( 'add_pattern' ) ) );
659
+ $arr['title'] = sanitize_text_field( stripslashes( wpmem_get( 'add_title' ) ) );
660
+ }
661
+
662
+ if ( 'number' == $type || 'date' == $type ) {
663
+ $arr['min'] = filter_var( wpmem_get( 'add_min' ), FILTER_SANITIZE_NUMBER_INT );
664
+ $arr['max'] = filter_var( wpmem_get( 'add_max' ), FILTER_SANITIZE_NUMBER_INT );
665
+ }
666
+
667
+ if ( 'textarea' == $type ) {
668
+ $arr['rows'] = filter_var( wpmem_get( 'add_rows' ), FILTER_SANITIZE_NUMBER_INT );
669
+ $arr['cols'] = filter_var( wpmem_get( 'add_cols' ), FILTER_SANITIZE_NUMBER_INT );
670
+ }
671
+
672
+ if ( $type == 'checkbox' ) {
673
+ $add_field_err_msg = ( ! $_POST['add_checked_value'] ) ? __( 'Checked value is required for checkboxes. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
674
+ $arr[7] = sanitize_text_field( wpmem_get( 'add_checked_value', false ) );
675
+ $arr[8] = ( 'y' == wpmem_get( 'add_checked_default', 'n' ) ) ? 'y' : 'n';
676
+ $arr['checkbox_label'] = intval( wpmem_get( 'add_checkbox_label', 0 ) );
677
+ }
678
+
679
+ if ( $type == 'select'
680
+ || $type == 'multiselect'
681
+ || $type == 'radio'
682
+ || $type == 'multicheckbox'
683
+ ) {
684
+ // Get the values.
685
+ $str = stripslashes( sanitize_textarea_field( $_POST['add_dropdown_value'] ) );
686
+ // Remove linebreaks.
687
+ $str = trim( str_replace( array("\r", "\r\n", "\n"), '', $str ) );
688
+ // Create array.
689
+ if ( ! function_exists( 'str_getcsv' ) ) {
690
+ $arr[7] = explode( ',', $str );
691
+ } else {
692
+ $arr[7] = str_getcsv( $str, ',', '"' );
693
+ }
694
+ // If multiselect or multicheckbox, set delimiter.
695
+ if ( 'multiselect' == $type || 'multicheckbox' == $type ) {
696
+ $arr[8] = ( ',' === wpmem_get( 'add_delimiter_value', '|' ) ) ? ',' : '|';
697
+ }
698
+ }
699
+
700
+ if ( $type == 'file' || $type == 'image' ) {
701
+ $arr[7] = sanitize_text_field( stripslashes( $_POST['add_file_value'] ) );
702
+ }
703
+
704
+ if ( wpmem_get( 'add_type' ) == 'hidden' ) {
705
+ $add_field_err_msg = ( ! $_POST['add_hidden_value'] ) ? __( 'A value is required for hidden fields. Nothing was updated.', 'wp-members' ) : $add_field_err_msg;
706
+ $arr[7] = ( isset( $_POST['add_hidden_value'] ) ) ? sanitize_text_field( stripslashes( $_POST['add_hidden_value'] ) ) : '';
707
+ }
708
+
709
+ if ( $action == 'add_field' ) {
710
+ if ( ! $add_field_err_msg ) {
711
+ array_push( $wpmem_fields, $arr );
712
+ $did_update = sprintf( __( '%s was added', 'wp-members' ), esc_html( $_POST['add_name'] ) );
713
+ } else {
714
+ $did_update = $add_field_err_msg;
715
+ }
716
+ } else {
717
+ for ( $row = 0; $row < count( $wpmem_fields ); $row++ ) {
718
+ if ( $wpmem_fields[ $row ][2] == wpmem_get( 'field', false, 'get' ) ) {
719
+ $arr[0] = $wpmem_fields[ $row ][0];
720
+ foreach ( $arr as $key => $value ) {
721
+ $wpmem_fields[ $row ][ $key ] = $arr[ $key ];
722
+ }
723
+ }
724
+ }
725
+ $did_update = sprintf( __( '%s was updated', 'wp-members' ), esc_html( stripslashes( $add_name ) ) );
726
+ $did_update.= '<p><a href="' . esc_url( add_query_arg( array( 'page' => 'wpmem-settings', 'tab' => 'fields' ), get_admin_url() . 'options-general.php' ) ) . '">&laquo; ' . __( 'Return to Fields Table', 'wp-members' ) . '</a></p>';
727
+ }
728
+
729
+ $wpmem_newfields = $wpmem_fields;
730
+
731
+ update_option( 'wpmembers_fields', $wpmem_newfields );
732
+ $wpmem->forms->load_fields();
733
+ return $did_update;
734
+ }
735
+ }
736
+ }
737
+
738
+ /**
739
+ * Reorders form fields.
740
+ *
741
+ * @since 2.5.1
742
+ * @since 3.1.8 Rebuilt for new List Table.
743
+ * @since 3.3.0 Merged do_field_reorder() and field_reorder().
744
+ */
745
+ public static function do_field_reorder() {
746
+
747
+ // Start fresh.
748
+ $new_order = $wpmem_fields = $field = $key = $wpmem_new_fields = $id = $k = '';
749
+ $wpmem_fields = get_option( 'wpmembers_fields' );
750
+
751
+ // Get the list items
752
+ $new_order = $_POST;
753
+
754
+ // Put fields in the proper order for the current form.
755
+ $wpmem_new_fields = array();
756
+ foreach ( $new_order['list_items'] as $id ) {
757
+ foreach( $wpmem_fields as $val ) {
758
+ if ( $val[0] == $id ) {
759
+ $wpmem_new_fields[] = $val;
760
+ }
761
+ }
762
+ }
763
+
764
+ // Save fields array with new current form field order.
765
+ update_option( 'wpmembers_fields', $wpmem_new_fields );
766
+
767
+ // Indicate successful transaction.
768
+ _e( 'Form field order updated.', 'wp-members' );
769
+
770
+ die(); // This is required to return a proper result.
771
+
772
+ }
773
+ }
774
  // End of file.
includes/admin/tabs/class-wp-members-admin-tab-options.php CHANGED
@@ -1,691 +1,686 @@
1
- <?php
2
- /**
3
- * WP-Members Admin functions
4
- *
5
- * Static functions to manage the plugin options 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_Options {
23
-
24
- /**
25
- * Creates the tab.
26
- *
27
- * @since 3.2.0
28
- * @since 3.3.0 Ported from wpmem_a_options_tab().
29
- *
30
- * @param string $tab The admin tab being displayed.
31
- * @return string|bool The about tab, otherwise false.
32
- */
33
- static function do_tab( $tab ) {
34
- if ( $tab == 'options' || ! $tab ) {
35
- // Render the about tab.
36
- return self::build_settings();
37
- } else {
38
- return false;
39
- }
40
- }
41
-
42
- /**
43
- * Builds the settings panel.
44
- *
45
- * @since 2.2.2
46
- * @since 3.3.0 Ported from wpmem_a_build_options().
47
- *
48
- * @global object $wpmem The WP_Members Object.
49
- */
50
- static function build_settings() {
51
-
52
- global $wpmem;
53
-
54
- /** This filter is documented in wp-members/includes/class-wp-members-email.php */
55
- $admin_email = apply_filters( 'wpmem_notify_addr', get_option( 'admin_email' ) );
56
- $chg_email = sprintf( __( '%sChange%s or %sFilter%s this address', 'wp-members' ), '<a href="' . site_url( 'wp-admin/options-general.php', 'admin' ) . '">', '</a>', '<a href="https://rocketgeek.com/plugins/wp-members/users-guide/filter-hooks/wpmem_notify_addr/">', '</a>' );
57
- $help_link = sprintf( __( 'See the %sUsers Guide on plugin options%s.', 'wp-members' ), '<a href="https://rocketgeek.com/plugins/wp-members/users-guide/plugin-settings/options/" target="_blank">', '</a>' );
58
-
59
- // Build an array of post types
60
- $post_types = $wpmem->admin->post_types();
61
- $post_arr = array(
62
- 'post' => __( 'Posts' ),
63
- 'page' => __( 'Pages' ),
64
- );
65
- if ( $post_types ) {
66
- foreach ( $post_types as $post_type ) {
67
- $cpt_obj = get_post_type_object( $post_type );
68
- $post_arr[ $cpt_obj->name ] = $cpt_obj->labels->name;
69
- }
70
- } ?>
71
-
72
- <div class="metabox-holder has-right-sidebar">
73
-
74
- <div class="inner-sidebar">
75
- <?php wpmem_a_meta_box(); ?>
76
- <?php wpmem_a_rating_box(); ?>
77
- <div class="postbox">
78
- <h3><span><?php _e( 'Need help?', 'wp-members' ); ?></span></h3>
79
- <div class="inside">
80
- <p><strong><i><?php echo $help_link; ?></i></strong></p>
81
- <p><button id="opener">Get Settings Information</button></p>
82
- </div>
83
- </div>
84
- <?php wpmem_a_rss_box(); ?>
85
- </div> <!-- .inner-sidebar -->
86
-
87
- <div id="post-body">
88
- <div id="post-body-content">
89
- <div class="postbox">
90
- <h3><span><?php _e( 'Manage Options', 'wp-members' ); ?></span></h3>
91
- <div class="inside">
92
- <form name="updatesettings" id="updatesettings" method="post" action="<?php echo wpmem_admin_form_post_url(); ?>">
93
- <?php wp_nonce_field( 'wpmem-update-settings' ); ?>
94
- <h3><?php _e( 'Content', 'wp-members' ); ?> <a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/options/#content" target="_blank" title="info"><span class="dashicons dashicons-info"></span></a></h3>
95
- <ul>
96
- <?php
97
-
98
- // Content Blocking option group.
99
- $i = 0;
100
- $len = count( $post_arr );
101
- foreach ( $post_arr as $key => $val ) {
102
- if ( $key == 'post' || $key == 'page' || ( isset( $wpmem->post_types ) && array_key_exists( $key, $wpmem->post_types ) ) ) {
103
- ?>
104
- <li<?php echo ( $i == $len - 1 ) ? ' style="border-bottom:1px solid #eee;"' : ''; ?>>
105
- <label><?php echo ( $i == 0 ) ? __( 'Content Blocking', 'wp-members' ) : '&nbsp;'; ?></label>
106
- <?php
107
- $block = ( isset( $wpmem->block[ $key ] ) ) ? $wpmem->block[ $key ] : '';
108
- $values = array(
109
- __( 'Do not block', 'wp-members' ) . '|0',
110
- __( 'Block', 'wp-members' ) . '|1',
111
- // @todo Future development. __( 'Hide', 'wp-members' ) . '|2',
112
- );
113
- echo wpmem_create_formfield( 'wpmem_block_' . $key, 'select', $values, $block ); ?>
114
- <span><?php echo $val; ?></span><?php // @todo - this needs to be translatable. ?>
115
- </li>
116
- <?php $i++;
117
- }
118
- }
119
-
120
- // Show Excerpts, Login Form, and Registration Form option groups.
121
-
122
- $option_group_array = array(
123
- 'show_excerpt' => __( 'Show Excerpts', 'wp-members' ),
124
- 'show_login' => __( 'Show Login Form', 'wp-members' ),
125
- 'show_reg' => __( 'Show Registration Form', 'wp-members' ),
126
- 'autoex' => __( 'Auto Excerpt:', 'wp-members' ),
127
- );
128
-
129
- foreach ( $option_group_array as $item_key => $item_val ) {
130
- $i = 0;
131
- $len = count( $post_arr );
132
- foreach ( $post_arr as $key => $val ) {
133
- if ( $key == 'post' || $key == 'page' || ( isset( $wpmem->post_types ) && array_key_exists( $key, $wpmem->post_types ) ) ) {
134
- ?>
135
- <li<?php echo ( $i == $len - 1 ) ? ' style="border-bottom:1px solid #eee;"' : ''; ?>>
136
- <label><?php echo ( $i == 0 ) ? $item_val : '&nbsp;'; ?></label>
137
- <?php if ( 'autoex' == $item_key ) {
138
- if ( isset( $wpmem->{$item_key}[ $key ] ) && $wpmem->{$item_key}[ $key ]['enabled'] == 1 ) {
139
- $setting = 1;
140
- $ex_len = $wpmem->{$item_key}[ $key ]['length'];
141
- $ex_text = ( isset( $wpmem->{$item_key}[ $key ]['text'] ) ) ? $wpmem->{$item_key}[ $key ]['text'] : '';
142
- } else {
143
- $setting = 0;
144
- $ex_len = '';
145
- $ex_text = '';
146
- }
147
- echo wpmem_create_formfield( 'wpmem_' . $item_key . '_' . $key, 'checkbox', '1', $setting ); ?> <span><?php echo $val; ?></span>&nbsp;&nbsp;&nbsp;&nbsp;
148
- <span><?php _e( 'Number of words in excerpt:', 'wp-members' ); ?> </span><input name="wpmem_autoex_<?php echo $key; ?>_len" type="text" size="5" value="<?php echo $ex_len; ?>" />&nbsp;&nbsp;&nbsp;&nbsp;
149
- <span><?php _e( 'Custom read more link (optional):', 'wp-members' ); ?> </span><input name="wpmem_autoex_<?php echo $key; ?>_text" type="text" size="5" value="<?php echo $ex_text; ?>" />
150
- <?php } else {
151
- $setting = ( isset( $wpmem->{$item_key}[ $key ] ) ) ? $wpmem->{$item_key}[ $key ] : 0;
152
- echo wpmem_create_formfield( 'wpmem_' . $item_key . '_' . $key, 'checkbox', '1', $setting ); ?> <span><?php echo $val; ?></span>
153
- <?php } ?>
154
- </li>
155
- <?php $i++;
156
- }
157
- }
158
- } ?>
159
- </ul>
160
- <?php
161
- if ( WPMEM_EXP_MODULE == true ) {
162
- $rows = array(
163
- array(__('Time-based expiration','wp-members'),'wpmem_settings_time_exp',__('Allows for access to expire','wp-members'),'use_exp'),
164
- array(__('Trial period','wp-members'),'wpmem_settings_trial',__('Allows for a trial period','wp-members'),'use_trial'),
165
- ); ?>
166
- <h3><?php _e( 'Subscription Settings', 'wp-members' ); ?></h3>
167
- <ul><?php
168
- foreach ( $rows as $row ) { ?>
169
- <li>
170
- <label><?php echo $row[0]; ?></label>
171
- <?php echo wpmem_create_formfield( $row[1], 'checkbox', '1', $wpmem->{$row[3]} ); ?>&nbsp;&nbsp;
172
- <?php if ( $row[2] ) { ?><span class="description"><?php echo $row[2]; ?></span><?php } ?>
173
- </li>
174
- <?php }
175
- }?></ul>
176
- <h3><?php _e( 'Feature Settings', 'wp-members' ); ?> <a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/new-feature-settings/" target="_blank" title="info"><span class="dashicons dashicons-info"></span></a></h3>
177
- <?php
178
- $rows = array(
179
- array(__('Confirmation Link', 'wp-members'),'wpmem_settings_act_link',__('Send email confirmation link on new registration. (Requires additional configuration)','wp-members'),'act_link'),
180
- array(__('Password Reset Link', 'wp-members'),'wpmem_settings_pwd_link',__('Send password reset link instead of new password. (Requires additional configuration)','wp-members'),'pwd_link'),
181
- array(__('Enable WP Login Error', 'wp-members' ),'wpmem_settings_login_error',__('Use WP login error object instead of WP-Members default login error','wp-members'),'login_error'),
182
- );
183
- if ( wpmem_is_woo_active() ) {
184
- $rows[] = array(__('WooCommerce My Account', 'wp-members' ),'wpmem_settings_add_my_account_fields',__('Add WP-Members fields to WooCommerce My Account registration','wp-members'),'add_my_account_fields');
185
- $rows[] = array(__('WooCommerce Checkout', 'wp-members' ),'wpmem_settings_add_checkout_fields',__('Add WP-Members fields to WooCommerce registration during checkout','wp-members'),'add_checkout_fields');
186
- }
187
- ?><ul><?php
188
- foreach ( $rows as $key => $row ) { ?>
189
- <li>
190
- <label><?php echo $row[0]; ?></label>
191
- <?php $checkbox_value = ( 3 == $key || 4 == $key ) ? $wpmem->woo[ $row[3] ] : $wpmem->{$row[3]}; ?>
192
- <?php echo wpmem_create_formfield( $row[1], 'checkbox', '1', $checkbox_value ); ?>&nbsp;&nbsp;
193
- <?php if ( $row[2] ) { ?><span class="description"><?php echo $row[2]; ?></span><?php } ?>
194
- </li>
195
- <?php } ?>
196
- </ul>
197
- <h3><?php _e( 'Other Settings', 'wp-members' ); ?> <a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/options/#other" target="_blank" title="info"><span class="dashicons dashicons-info"></span></a></h3>
198
- <ul>
199
- <?php
200
- /** This filter is defined in class-wp-members.php */
201
- $dropin_dir = apply_filters( 'wpmem_dropin_dir', $wpmem->dropin_dir );
202
- $rows = array(
203
- array(__('Enable Products', 'wp-members'),'wpmem_settings_products',__('Enables creation of different membership products','wp-members'),'enable_products'),
204
- array(__('Clone menus','wp-members'),'wpmem_settings_menus',__('Enables logged in menus','wp-members'),'clone_menus'),
205
- array(__('Notify admin','wp-members'),'wpmem_settings_notify',sprintf(__('Notify %s for each new registration? %s','wp-members'),$admin_email,$chg_email),'notify'),
206
- array(__('Moderate registration','wp-members'),'wpmem_settings_moderate',__('Holds new registrations for admin approval','wp-members'),'mod_reg'),
207
- array(__('Ignore warning messages','wp-members'),'wpmem_settings_ignore_warnings',__('Ignores WP-Members warning messages in the admin panel','wp-members'),'warnings'),
208
- //array(__('Enable dropins', 'wp-members'),'wpmem_settings_enable_dropins',sprintf(__('Enables dropins in %s', 'wp-members'), $dropin_dir),'dropins'),
209
- );
210
- foreach ( $rows as $row ) { ?>
211
- <li>
212
- <label><?php echo $row[0]; ?></label>
213
- <?php echo wpmem_create_formfield( $row[1], 'checkbox', '1', $wpmem->{$row[3]} ); ?>&nbsp;&nbsp;
214
- <?php if ( $row[2] ) { ?><span class="description"><?php echo $row[2]; ?></span><?php } ?>
215
- </li>
216
- <?php } ?>
217
- <li>
218
- <label><?php _e( 'Attribution', 'wp-members' ); ?></label>
219
- <?php echo wpmem_create_formfield( 'attribution', 'checkbox', '1', $wpmem->attrib ); ?>&nbsp;&nbsp;
220
- <span class="description"><?php _e( 'Attribution is appreciated! Display "powered by" link on register form?', 'wp-members' ); ?></span>
221
- </li>
222
- <li>
223
- <label><?php _e( 'Enable CAPTCHA for Registration', 'wp-members' ); ?></label>
224
- <?php $captcha = array( __( 'None', 'wp-members' ) . '|0' );
225
- if ( 1 == $wpmem->captcha ) {
226
- $wpmem->captcha = 3; // reCAPTCHA v1 is fully obsolete. Change it to v2.
227
- }
228
- $captcha[] = __( 'reCAPTCHA v2', 'wp-members' ) . '|3';
229
- $captcha[] = __( 'reCAPTCHA v3', 'wp-members' ) . '|4';
230
- $captcha[] = __( 'Really Simple CAPTCHA', 'wp-members' ) . '|2';
231
- $captcha[] = __( 'hCaptcha', 'wp-members' ) . '|5';
232
- echo wpmem_create_formfield( 'wpmem_settings_captcha', 'select', $captcha, $wpmem->captcha ); ?>
233
- </li>
234
- <h3><?php _e( 'Pages' ); ?> <a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/options/#pages" target="_blank" title="info"><span class="dashicons dashicons-info"></span></a></h3>
235
- <?php $wpmem_logurl = $wpmem->user_pages['login'];
236
- if ( ! $wpmem_logurl ) { $wpmem_logurl = wpmem_use_ssl(); } ?>
237
- <li>
238
- <label><?php _e( 'Login Page:', 'wp-members' ); ?></label>
239
- <select name="wpmem_settings_logpage" id="wpmem_logpage_select">
240
- <?php WP_Members_Admin_Tab_Options::page_list( $wpmem_logurl ); ?>
241
- </select>&nbsp;<span class="description"><?php _e( 'Specify a login page (optional)', 'wp-members' ); ?></span><br />
242
- <div id="wpmem_logpage_custom">
243
- <label>&nbsp;</label>
244
- <input class="regular-text code" type="text" name="wpmem_settings_logurl" value="<?php echo $wpmem_logurl; ?>" size="50" />
245
- </div>
246
- </li>
247
- <?php $wpmem_regurl = $wpmem->user_pages['register'];
248
- if ( ! $wpmem_regurl ) { $wpmem_regurl = wpmem_use_ssl(); } ?>
249
- <li>
250
- <label><?php _e( 'Register Page:', 'wp-members' ); ?></label>
251
- <select name="wpmem_settings_regpage" id="wpmem_regpage_select">
252
- <?php WP_Members_Admin_Tab_Options::page_list( $wpmem_regurl ); ?>
253
- </select>&nbsp;<span class="description"><?php _e( 'For creating a register link in the login form', 'wp-members' ); ?></span><br />
254
- <div id="wpmem_regpage_custom">
255
- <label>&nbsp;</label>
256
- <input class="regular-text code" type="text" name="wpmem_settings_regurl" value="<?php echo $wpmem_regurl; ?>" size="50" />
257
- </div>
258
- </li>
259
- <?php $wpmem_msurl = $wpmem->user_pages['profile'];
260
- if ( ! $wpmem_msurl ) { $wpmem_msurl = wpmem_use_ssl(); } ?>
261
- <li>
262
- <label><?php _e( 'User Profile Page:', 'wp-members' ); ?></label>
263
- <select name="wpmem_settings_mspage" id="wpmem_mspage_select">
264
- <?php WP_Members_Admin_Tab_Options::page_list( $wpmem_msurl ); ?>
265
- </select>&nbsp;<span class="description"><?php _e( 'For creating a forgot password link in the login form', 'wp-members' ); ?></span><br />
266
- <div id="wpmem_mspage_custom">
267
- <label>&nbsp;</label>
268
- <input class="regular-text code" type="text" name="wpmem_settings_msurl" value="<?php echo $wpmem_msurl; ?>" size="50" />
269
- </div>
270
- </li>
271
- <h3><?php _e( 'Stylesheet' ); ?> <a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/options/#styles" target="_blank" title="info"><span class="dashicons dashicons-info"></span></a></h3>
272
- <li>
273
- <label><?php _e( 'Stylesheet' ); ?>:</label>
274
- <select name="wpmem_settings_style" id="wpmem_stylesheet_select">
275
- <?php WP_Members_Admin_Tab_Options::style_list( $wpmem->select_style ); ?>
276
- </select>
277
- </li>
278
- <?php $wpmem_cssurl = $wpmem->cssurl;
279
- if ( ! $wpmem_cssurl ) { $wpmem_cssurl = wpmem_use_ssl(); } ?>
280
- <div id="wpmem_stylesheet_custom">
281
- <li>
282
- <label><?php _e( 'Custom Stylesheet:', 'wp-members' ); ?></label>
283
- <input class="regular-text code" type="text" name="wpmem_settings_cssurl" value="<?php echo $wpmem_cssurl; ?>" size="50" />
284
- </li>
285
- </div>
286
- <input type="hidden" name="wpmem_admin_a" value="update_settings">
287
- <?php submit_button( __( 'Update Settings', 'wp-members' ) ); ?>
288
- </ul>
289
- </form>
290
- <p>If you like <strong>WP-Members</strong> please give it a <a href="https://wordpress.org/support/plugin/wp-members/reviews?rate=5#new-post">&#9733;&#9733;&#9733;&#9733;&#9733;</a> rating. Thanks!!</p>
291
- </div><!-- .inside -->
292
- </div>
293
- <?php if ( $post_types ) { ?>
294
- <div class="postbox">
295
- <h3><span><?php _e( 'Custom Post Types', 'wp-members' ); ?></span></h3>
296
- <div class="inside">
297
- <form name="updatecpts" id="updatecpts" method="post" action="<?php echo wpmem_admin_form_post_url(); ?>">
298
- <?php wp_nonce_field( 'wpmem-update-cpts' ); ?>
299
- <table class="form-table">
300
- <tr>
301
- <th scope="row"><?php _e( 'Add to WP-Members Settings', 'wp-members' ); ?></th>
302
- <td><fieldset><?php
303
- foreach ( $post_arr as $key => $val ) {
304
- if ( 'post' != $key && 'page' != $key && 'wpmem_product' != $key ) {
305
- $checked = ( isset( $wpmem->post_types ) && array_key_exists( $key, $wpmem->post_types ) ) ? ' checked' : '';
306
- echo '<label for="' . $key . '"><input type="checkbox" name="wpmembers_handle_cpts[]" value="' . $key . '"' . $checked . ' />' . $val . '</label><br />';
307
- }
308
- }
309
- ?></fieldset>
310
- </td>
311
- </tr>
312
- <tr>
313
- <input type="hidden" name="wpmem_admin_a" value="update_cpts" />
314
- <td colspan="2"><?php submit_button( __( 'Update Settings', 'wp-members' ) ); ?></td>
315
- </tr>
316
- <tr>
317
- <td colspan="2"><?php _e( 'Please keep in mind that Custom Post Types are "custom" and therefore, not all of them will function exactly the same way. WP-Members will certainly work with any post type that operate like a post or a page; but you will need to review any custom post type added to determine that it functions the way you expect.', 'wp-members' ); ?></td>
318
- </tr>
319
- </table>
320
- </form>
321
- </div>
322
- </div>
323
- <?php } ?>
324
- </div><!-- #post-body-content -->
325
- </div><!-- #post-body -->
326
- </div><!-- .metabox-holder -->
327
- <script>
328
- jQuery(document).ready(function($){
329
- $(function() {
330
- $("#dialog-message" ).dialog({
331
- autoOpen: false,
332
- modal: true,
333
- height: "auto",
334
- width: 600,
335
- buttons: {
336
- "<?php _e( 'Close', 'wp-members' ); ?>": function() {
337
- $( this ).dialog( "close" );
338
- }
339
- }
340
- });
341
- $( "#opener" ).on( "click", function() {
342
- $( "#dialog-message" ).dialog( "open" );
343
- });
344
- } );
345
- $("#select_all").click(function(){
346
- $("textarea").select();
347
- document.execCommand('copy');
348
- });
349
- $(window).resize(function() {
350
- $("#dialog-message").dialog("option", "position", {my: "center", at: "center", of: window});
351
- });
352
- });
353
- </script>
354
- <div id="dialog-message" title="<?php _e( 'WP-Members Settings', 'wp-members' ); ?>">
355
- <h3><span><?php _e( 'WP-Members Settings', 'wp-members' ); ?></span></h3>
356
- <p><?php _e( 'The following is your WP-Members settings information if needed for support.', 'wp-members' ); ?></p>
357
- <pre>
358
- <textarea cols=80 rows=10 align=left wrap=soft style="width:80%;" id="supportinfo" wrap="soft"><?php
359
- global $wp_version, $wpdb, $wpmem;
360
- echo "WP Version: " . $wp_version . "\r\n";
361
- echo "PHP Version: " . phpversion() . "\r\n";
362
- echo "MySQL Version: " . $wpdb->db_version() . "\r\n";
363
- wpmem_fields();
364
- print_r( $wpmem );
365
-
366
- echo '***************** Plugin Info *******************' . "\r\n";
367
- $all_plugins = get_plugins();
368
- $active_plugins = get_option( 'active_plugins' );
369
- $active_display = ''; $inactive_display = '';
370
- foreach ( $all_plugins as $key => $value ) {
371
- if ( in_array( $key, $active_plugins ) ) {
372
- $active_display.= $key . " | " . $value['Name'] . " | Version: " . $value['Version'] . "\r\n";
373
- } else {
374
- $inactive_display.= $key . " | " . $value['Name'] . " | Version: " . $value['Version'] . "\r\n";
375
- }
376
- }
377
- echo "*************** Active Plugins **************** \r\n";
378
- echo $active_display;
379
- echo "*************** Inactive Plugins **************** \r\n";
380
- echo $inactive_display;
381
- ?></textarea>
382
- </pre>
383
- <button id="select_all" class="ui-button-text"><?php _e( 'Click to Copy', 'wp-members' ); ?></button>
384
- </div>
385
- <?php
386
- }
387
-
388
- /**
389
- * Updates the plugin options.
390
- *
391
- * @since 2.8.0
392
- * @since 3.3.0 Ported from wpmem_update_options() and wpmem_update_cpts().
393
- *
394
- * @global object $wpmem The WP_Members object.
395
- * @param string $action
396
- * @return string The options updated message.
397
- */
398
- static function update( $action ) {
399
-
400
- if ( 'update_cpts' == $action ) {
401
-
402
- // Check nonce.
403
- check_admin_referer( 'wpmem-update-cpts' );
404
-
405
- // Get the main settings array as it stands.
406
- $wpmem_newsettings = get_option( 'wpmembers_settings' );
407
-
408
- // Assemble CPT settings.
409
- $cpts = array();
410
-
411
- $post_arr = array();
412
- $post_types = get_post_types( array( 'public' => true, '_builtin' => false ), 'names', 'and' );
413
- if ( $post_types ) {
414
- foreach ( $post_types as $post_type ) {
415
- $cpt_obj = get_post_type_object( $post_type );
416
- if ( $cpt_obj->labels->name != 'wpmem_product' ) {
417
- $post_arr[ $cpt_obj->name ] = $cpt_obj->labels->name;
418
- }
419
- }
420
- }
421
-
422
- $post_vals = ( isset( $_POST['wpmembers_handle_cpts'] ) ) ? $_POST['wpmembers_handle_cpts'] : false;
423
- if ( $post_vals ) {
424
- foreach ( $post_vals as $val ) {
425
- $cpts[ $val ] = sanitize_text_field( $post_arr[ $val ] );
426
- }
427
- } else {
428
- $cpts = array();
429
- }
430
- $wpmem_newsettings['post_types'] = $cpts;
431
-
432
- // Update settings, remove or add CPTs.
433
- $chk_settings = array( 'block', 'show_excerpt', 'show_login', 'show_reg', 'autoex' );
434
- foreach ( $chk_settings as $chk ) {
435
- // Handle removing unmanaged CPTs.
436
- foreach ( $wpmem_newsettings[ $chk ] as $key => $val ) {
437
- if ( 'post' != $key && 'page' != $key ) {
438
- // If the $key is not in managed CPTs, remove it.
439
- if ( ! array_key_exists( $key, $cpts ) ) {
440
- unset( $wpmem_newsettings[ $chk ][ $key ] );
441
- }
442
- }
443
- }
444
- // Handle adding managed CPTs.
445
- foreach ( $cpts as $key => $val ) {
446
- if ( ! array_key_exists( $key, $wpmem_newsettings[ $chk ] ) ) {
447
- if ( 'autoex' == $chk ) {
448
- // Auto excerpt is an array.
449
- $wpmem_newsettings[ $chk ][ $key ] = array(
450
- 'enabled' => 0,
451
- 'length' => '',
452
- );
453
- } else {
454
- // All other settings are 0|1.
455
- $wpmem_newsettings[ $chk ][ $key ] = 0;
456
- }
457
- }
458
- }
459
- }
460
-
461
- WP_Members_Admin_Tab_Options::save_settings( $wpmem_newsettings );
462
-
463
- return __( 'Custom Post Type settings were updated', 'wp-members' );
464
-
465
- } else {
466
-
467
- global $wpmem;
468
-
469
- // Check nonce.
470
- check_admin_referer( 'wpmem-update-settings' );
471
-
472
- $wpmem_settings_msurl = ( $_POST['wpmem_settings_mspage'] == 'use_custom' ) ? esc_url( $_POST['wpmem_settings_msurl'] ) : '';
473
- $wpmem_settings_mspage = ( $_POST['wpmem_settings_mspage'] == 'use_custom' ) ? '' : filter_var( $_POST['wpmem_settings_mspage'], FILTER_SANITIZE_NUMBER_INT );
474
- if ( $wpmem_settings_msurl != wpmem_use_ssl() && $wpmem_settings_msurl != 'use_custom' && ! $wpmem_settings_mspage ) {
475
- $msurl = trim( $wpmem_settings_msurl );
476
- } else {
477
- $msurl = $wpmem_settings_mspage;
478
- }
479
-
480
- $wpmem_settings_regurl = ( $_POST['wpmem_settings_regpage'] == 'use_custom' ) ? esc_url( $_POST['wpmem_settings_regurl'] ) : '';
481
- $wpmem_settings_regpage = ( $_POST['wpmem_settings_regpage'] == 'use_custom' ) ? '' : filter_var( $_POST['wpmem_settings_regpage'], FILTER_SANITIZE_NUMBER_INT );
482
- if ( $wpmem_settings_regurl != wpmem_use_ssl() && $wpmem_settings_regurl != 'use_custom' && ! $wpmem_settings_regpage ) {
483
- $regurl = trim( $wpmem_settings_regurl );
484
- } else {
485
- $regurl = $wpmem_settings_regpage;
486
- }
487
-
488
- $wpmem_settings_logurl = ( $_POST['wpmem_settings_logpage'] == 'use_custom' ) ? esc_url( $_POST['wpmem_settings_logurl'] ) : '';
489
- $wpmem_settings_logpage = ( $_POST['wpmem_settings_logpage'] == 'use_custom' ) ? '' : filter_var( $_POST['wpmem_settings_logpage'], FILTER_SANITIZE_NUMBER_INT );
490
- if ( $wpmem_settings_logurl != wpmem_use_ssl() && $wpmem_settings_logurl != 'use_custom' && ! $wpmem_settings_logpage ) {
491
- $logurl = trim( $wpmem_settings_logurl );
492
- } else {
493
- $logurl = $wpmem_settings_logpage;
494
- }
495
-
496
- $wpmem_settings_cssurl = esc_url( $_POST['wpmem_settings_cssurl'] );
497
- $cssurl = ( $wpmem_settings_cssurl != wpmem_use_ssl() ) ? trim( $wpmem_settings_cssurl ) : '';
498
-
499
- $wpmem_settings_style = ( isset( $_POST['wpmem_settings_style'] ) ) ? sanitize_text_field( $_POST['wpmem_settings_style'] ) : false;
500
-
501
- $wpmem_newsettings = array(
502
- 'version' => $wpmem->version,
503
- 'db_version' => $wpmem->db_version,
504
- 'act_link' => filter_var( wpmem_get( 'wpmem_settings_act_link', 0 ), FILTER_SANITIZE_NUMBER_INT ),
505
- 'pwd_link' => filter_var( wpmem_get( 'wpmem_settings_pwd_link', 0 ), FILTER_SANITIZE_NUMBER_INT ),
506
- 'login_error' => filter_var( wpmem_get( 'wpmem_settings_login_error', 0 ), FILTER_SANITIZE_NUMBER_INT ),
507
- 'enable_products' => filter_var( wpmem_get( 'wpmem_settings_products', 0 ), FILTER_SANITIZE_NUMBER_INT ),
508
- 'clone_menus' => filter_var( wpmem_get( 'wpmem_settings_menus', 0 ), FILTER_SANITIZE_NUMBER_INT ),
509
- 'notify' => filter_var( wpmem_get( 'wpmem_settings_notify', 0 ), FILTER_SANITIZE_NUMBER_INT ),
510
- 'mod_reg' => filter_var( wpmem_get( 'wpmem_settings_moderate', 0 ), FILTER_SANITIZE_NUMBER_INT ),
511
- 'captcha' => filter_var( wpmem_get( 'wpmem_settings_captcha', 0 ), FILTER_SANITIZE_NUMBER_INT ),
512
- 'use_exp' => filter_var( wpmem_get( 'wpmem_settings_time_exp', 0 ), FILTER_SANITIZE_NUMBER_INT ),
513
- 'use_trial' => filter_var( wpmem_get( 'wpmem_settings_trial', 0 ), FILTER_SANITIZE_NUMBER_INT ),
514
- 'warnings' => filter_var( wpmem_get( 'wpmem_settings_ignore_warnings', 0 ), FILTER_SANITIZE_NUMBER_INT ),
515
- 'dropins' => filter_var( wpmem_get( 'wpmem_settings_enable_dropins', 0 ), FILTER_SANITIZE_NUMBER_INT ),
516
- 'user_pages' => array(
517
- 'profile' => ( $msurl ) ? $msurl : '',
518
- 'register' => ( $regurl ) ? $regurl : '',
519
- 'login' => ( $logurl ) ? $logurl : '',
520
- ),
521
- 'woo' => array(
522
- 'add_my_account_fields' => filter_var( wpmem_get( 'wpmem_settings_add_my_account_fields', 0 ), FILTER_SANITIZE_NUMBER_INT ),
523
- 'add_checkout_fields' => filter_var( wpmem_get( 'wpmem_settings_add_checkout_fields', 0 ), FILTER_SANITIZE_NUMBER_INT ),
524
- ),
525
- 'cssurl' => ( $cssurl ) ? $cssurl : '',
526
- 'select_style' => $wpmem_settings_style,
527
- 'attrib' => filter_var( wpmem_get( 'attribution', 0 ), FILTER_SANITIZE_NUMBER_INT ),
528
- );
529
-
530
- // Build an array of post types
531
- $post_arr = array( 'post', 'page' );
532
- if ( isset( $wpmem->post_types ) ) {
533
- $wpmem_newsettings['post_types'] = $wpmem->post_types;
534
- foreach ( $wpmem_newsettings['post_types'] as $key => $val ) {
535
- $post_arr[] = $key;
536
- }
537
- }
538
-
539
- // If activation link is being enabled, make sure current admin is marked as activated.
540
- if ( 1 == $wpmem_newsettings['act_link'] && 0 == $wpmem->act_link ) {
541
- update_user_meta( get_current_user_id(), '_wpmem_user_confirmed', time() );
542
- }
543
-
544
- // Leave form tag settings alone.
545
- if ( isset( $wpmem->form_tags ) ) {
546
- $wpmem_newsettings['form_tags'] = $wpmem->form_tags;
547
- }
548
-
549
- // Get settings for blocking, excerpts, show login, and show registration for posts, pages, and custom post types.
550
- $option_group_array = array( 'block', 'show_excerpt', 'show_login', 'show_reg', 'autoex' );
551
- foreach ( $option_group_array as $option_group_item ) {
552
- $arr = array();
553
- foreach ( $post_arr as $post_type ) {
554
- $post_var = 'wpmem_' . $option_group_item . '_' . $post_type;
555
- if ( $option_group_item == 'autoex' ) {
556
- // Auto excerpt is an array.
557
- $arr[ $post_type ]['enabled'] = ( isset( $_POST[ $post_var ] ) ) ? filter_var( $_POST[ $post_var ], FILTER_SANITIZE_NUMBER_INT ) : 0;
558
- $arr[ $post_type ]['length'] = ( isset( $_POST[ $post_var . '_len' ] ) ) ? ( ( $_POST[ $post_var . '_len' ] == '' ) ? 0 : filter_var( $_POST[ $post_var . '_len' ], FILTER_SANITIZE_NUMBER_INT ) ) : '';
559
- $arr[ $post_type ]['text'] = ( isset( $_POST[ $post_var . '_text' ] ) ) ? sanitize_text_field( $_POST[ $post_var . '_text' ] ) : '';
560
- } else {
561
- // All other settings are 0|1.
562
- $arr[ $post_type ] = ( isset( $_POST[ $post_var ] ) ) ? filter_var( $_POST[ $post_var ], FILTER_SANITIZE_NUMBER_INT ) : 0;
563
- }
564
- }
565
- $wpmem_newsettings[ $option_group_item ] = $arr;
566
- }
567
-
568
- /*
569
- * If we are setting registration to be moderated,
570
- * check to see if the current admin has been
571
- * activated so they don't accidentally lock themselves
572
- * out later.
573
- */
574
- if ( isset( $_POST['wpmem_settings_moderate'] ) == 1 ) {
575
- update_user_meta( get_current_user_id(), 'active', 1 );
576
- }
577
-
578
- if ( isset( $_POST['wpmem_settings_act_link'] ) == 1 ) {
579
- update_user_meta( get_current_user_id(), '_wpmem_activation_confirm', time() );
580
- }
581
-
582
- WP_Members_Admin_Tab_Options::save_settings( $wpmem_newsettings );
583
-
584
- return __( 'WP-Members settings were updated', 'wp-members' );
585
- }
586
- }
587
-
588
- /**
589
- * Puts new settings into the current object.
590
- *
591
- * @since 3.0.9
592
- * @since 3.3.0 Ported from wpmem_admin_new_settings().
593
- *
594
- * @global $wpmem
595
- * @param $new
596
- * @return $settings
597
- */
598
- static function save_settings( $new ) {
599
-
600
- // Update saved settings.
601
- update_option( 'wpmembers_settings', $new );
602
-
603
- // Update the current WP_Members object with the new settings.
604
- global $wpmem;
605
- foreach ( $new as $key => $val ) {
606
- if ( 'user_pages' == $key ) {
607
- foreach ( $val as $subkey => $subval ) {
608
- $val[ $subkey ] = ( is_numeric( $subval ) ) ? get_page_link( $subval ) : $subval;
609
- }
610
- }
611
- $wpmem->{$key} = $val;
612
- }
613
- }
614
-
615
- /**
616
- * Create the stylesheet dropdown selection.
617
- *
618
- * @since 2.8.0
619
- * @since 3.3.0 Ported from wpmem_admin_style_list().
620
- *
621
- * @param $style string The stored stylesheet setting.
622
- */
623
- static function style_list( $style ) {
624
-
625
- $list = array(
626
- 'No Float' => 'generic-no-float',
627
- 'Rigid' => 'generic-rigid',
628
- 'Twenty Sixteen - no float' => 'wp-members-2016-no-float',
629
- 'Twenty Fifteen' => 'wp-members-2015',
630
- 'Twenty Fifteen - no float' => 'wp-members-2015-no-float',
631
- 'Twenty Fourteen' => 'wp-members-2014',
632
- 'Twenty Fourteen - no float' => 'wp-members-2014-no-float',
633
- //'Twenty Thirteen' => WPMEM_DIR . 'css/wp-members-2013.css',
634
- //'Twenty Twelve' => WPMEM_DIR . 'css/wp-members-2012.css',
635
- //'Twenty Eleven' => WPMEM_DIR . 'css/wp-members-2011.css',
636
- //'Twenty Ten' => WPMEM_DIR . 'css/wp-members.css',
637
- //'Kubrick' => WPMEM_DIR . 'css/wp-members-kubrick.css',
638
- );
639
-
640
- /**
641
- * Filters the list of stylesheets in the plugin options dropdown.
642
- *
643
- * @since 2.8.0
644
- * @deprecated 3.3.0 There is no way to manage custom values in the dropdown with the new setting rules.
645
- *
646
- * @param array $list An array of stylesheets that can be applied to the plugin's forms.
647
- */
648
- //$list = apply_filters( 'wpmem_admin_style_list', $list );
649
-
650
- $selected = false;
651
- foreach ( $list as $name => $location ) {
652
- $selected = ( $location == $style ) ? true : $selected;
653
- echo '<option value="' . $location . '" ' . selected( $location, $style ) . '>' . $name . "</option>\n";
654
- }
655
- $selected = ( ! $selected ) ? ' selected' : '';
656
- echo '<option value="use_custom"' . $selected . '>' . __( 'USE CUSTOM URL BELOW', 'wp-members' ) . '</option>';
657
-
658
- return;
659
- }
660
-
661
- /**
662
- * Create a dropdown selection of pages.
663
- *
664
- * @since 2.8.1
665
- * @since 3.3.0 Ported from wpmem_admin_page_list().
666
- *
667
- * @todo Consider wp_dropdown_pages. Can be retrieved as HTML (echo=false) and str_replaced to add custom values.
668
- *
669
- * @param string $val
670
- */
671
- static function page_list( $val, $show_custom_url = true ) {
672
-
673
- $selected = ( $val == 'http://' || $val == 'https://' ) ? 'select a page' : false;
674
- $pages = get_pages();
675
-
676
- echo '<option value=""'; echo ( $selected == 'select a page' ) ? ' selected' : ''; echo '>'; echo esc_attr( __( 'Select a page', 'wp-members' ) ); echo '</option>';
677
-
678
- foreach ( $pages as $page ) {
679
- $selected = ( get_page_link( $page->ID ) == $val ) ? true : $selected; //echo "VAL: " . $val . ' PAGE LINK: ' . get_page_link( $page->ID );
680
- $option = '<option value="' . $page->ID . '"' . selected( get_page_link( $page->ID ), $val, 'select' ) . '>';
681
- $option .= $page->post_title;
682
- $option .= '</option>';
683
- echo $option;
684
- }
685
- if ( $show_custom_url ) {
686
- $selected = ( ! $selected ) ? ' selected' : '';
687
- echo '<option value="use_custom"' . $selected . '>' . __( 'USE CUSTOM URL BELOW', 'wp-members' ) . '</option>';
688
- }
689
- }
690
-
691
  } // End of file.
1
+ <?php
2
+ /**
3
+ * WP-Members Admin functions
4
+ *
5
+ * Static functions to manage the plugin options 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-2021 Chad Butler
10
+ * WP-Members(tm) is a trademark of butlerblog.com
11
+ *
12
+ * @package WP-Members
13
+ * @author Chad Butler
14
+ * @copyright 2006-2021
15
+ */
16
+
17
+ // Exit if accessed directly.
18
+ if ( ! defined( 'ABSPATH' ) ) {
19
+ exit();
20
+ }
21
+
22
+ class WP_Members_Admin_Tab_Options {
23
+
24
+ /**
25
+ * Creates the tab.
26
+ *
27
+ * @since 3.2.0
28
+ * @since 3.3.0 Ported from wpmem_a_options_tab().
29
+ *
30
+ * @param string $tab The admin tab being displayed.
31
+ * @return string|bool The about tab, otherwise false.
32
+ */
33
+ static function do_tab( $tab ) {
34
+ if ( $tab == 'options' || ! $tab ) {
35
+ // Render the about tab.
36
+ return self::build_settings();
37
+ } else {
38
+ return false;
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Builds the settings panel.
44
+ *
45
+ * @since 2.2.2
46
+ * @since 3.3.0 Ported from wpmem_a_build_options().
47
+ *
48
+ * @global object $wpmem The WP_Members Object.
49
+ */
50
+ static function build_settings() {
51
+
52
+ global $wpmem;
53
+
54
+ /** This filter is documented in wp-members/includes/class-wp-members-email.php */
55
+ $admin_email = apply_filters( 'wpmem_notify_addr', get_option( 'admin_email' ) );
56
+ $chg_email = sprintf( __( '%sChange%s or %sFilter%s this address', 'wp-members' ), '<a href="' . site_url( 'wp-admin/options-general.php', 'admin' ) . '">', '</a>', '<a href="https://rocketgeek.com/plugins/wp-members/docs/filter-hooks/wpmem_notify_addr/">', '</a>' );
57
+ $help_link = sprintf( __( 'See the %sUsers Guide on plugin options%s.', 'wp-members' ), '<a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/options/" target="_blank">', '</a>' );
58
+
59
+ // Build an array of post types
60
+ $post_types = $wpmem->admin->post_types();
61
+ $post_arr = array(
62
+ 'post' => __( 'Posts' ),
63
+ 'page' => __( 'Pages' ),
64
+ );
65
+ if ( $post_types ) {
66
+ foreach ( $post_types as $post_type ) {
67
+ $cpt_obj = get_post_type_object( $post_type );
68
+ $post_arr[ $cpt_obj->name ] = $cpt_obj->labels->name;
69
+ }
70
+ } ?>
71
+
72
+ <div class="metabox-holder has-right-sidebar">
73
+
74
+ <div class="inner-sidebar">
75
+ <?php wpmem_a_meta_box(); ?>
76
+ <?php wpmem_a_rating_box(); ?>
77
+ <div class="postbox">
78
+ <h3><span><?php _e( 'Need help?', 'wp-members' ); ?></span></h3>
79
+ <div class="inside">
80
+ <p><strong><i><?php echo $help_link; ?></i></strong></p>
81
+ <p><button id="opener">Get Settings Information</button></p>
82
+ </div>
83
+ </div>
84
+ <?php wpmem_a_rss_box(); ?>
85
+ </div> <!-- .inner-sidebar -->
86
+
87
+ <div id="post-body">
88
+ <div id="post-body-content">
89
+ <div class="postbox">
90
+ <h3><span><?php _e( 'Manage Options', 'wp-members' ); ?></span></h3>
91
+ <div class="inside">
92
+ <form name="updatesettings" id="updatesettings" method="post" action="<?php echo wpmem_admin_form_post_url(); ?>">
93
+ <?php wp_nonce_field( 'wpmem-update-settings' ); ?>
94
+ <h3><?php _e( 'Content', 'wp-members' ); ?> <a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/options/#content" target="_blank" title="info"><span class="dashicons dashicons-info"></span></a></h3>
95
+ <ul>
96
+ <?php
97
+
98
+ // Content Blocking option group.
99
+ $i = 0;
100
+ $len = count( $post_arr );
101
+ foreach ( $post_arr as $key => $val ) {
102
+ if ( $key == 'post' || $key == 'page' || ( isset( $wpmem->post_types ) && array_key_exists( $key, $wpmem->post_types ) ) ) {
103
+ ?>
104
+ <li<?php echo ( $i == $len - 1 ) ? ' style="border-bottom:1px solid #eee;"' : ''; ?>>
105
+ <label><?php echo ( $i == 0 ) ? __( 'Content Blocking', 'wp-members' ) : '&nbsp;'; ?></label>
106
+ <?php
107
+ $block = ( isset( $wpmem->block[ $key ] ) ) ? $wpmem->block[ $key ] : '';
108
+ $values = array(
109
+ __( 'Do not block', 'wp-members' ) . '|0',
110
+ __( 'Block', 'wp-members' ) . '|1',
111
+ // @todo Future development. __( 'Hide', 'wp-members' ) . '|2',
112
+ );
113
+ echo wpmem_form_field( 'wpmem_block_' . $key, 'select', $values, $block ); ?>
114
+ <span><?php echo $val; ?></span><?php // @todo - this needs to be translatable. ?>
115
+ </li>
116
+ <?php $i++;
117
+ }
118
+ }
119
+
120
+ // Show Excerpts, Login Form, and Registration Form option groups.
121
+
122
+ $option_group_array = array(
123
+ 'show_excerpt' => __( 'Show Excerpts', 'wp-members' ),
124
+ 'show_login' => __( 'Show Login Form', 'wp-members' ),
125
+ 'show_reg' => __( 'Show Registration Form', 'wp-members' ),
126
+ 'autoex' => __( 'Auto Excerpt:', 'wp-members' ),
127
+ );
128
+
129
+ foreach ( $option_group_array as $item_key => $item_val ) {
130
+ $i = 0;
131
+ $len = count( $post_arr );
132
+ foreach ( $post_arr as $key => $val ) {
133
+ if ( $key == 'post' || $key == 'page' || ( isset( $wpmem->post_types ) && array_key_exists( $key, $wpmem->post_types ) ) ) {
134
+ ?>
135
+ <li<?php echo ( $i == $len - 1 ) ? ' style="border-bottom:1px solid #eee;"' : ''; ?>>
136
+ <label><?php echo ( $i == 0 ) ? $item_val : '&nbsp;'; ?></label>
137
+ <?php if ( 'autoex' == $item_key ) {
138
+ if ( isset( $wpmem->{$item_key}[ $key ] ) && $wpmem->{$item_key}[ $key ]['enabled'] == 1 ) {
139
+ $setting = 1;
140
+ $ex_len = $wpmem->{$item_key}[ $key ]['length'];
141
+ $ex_text = ( isset( $wpmem->{$item_key}[ $key ]['text'] ) ) ? $wpmem->{$item_key}[ $key ]['text'] : '';
142
+ } else {
143
+ $setting = 0;
144
+ $ex_len = '';
145
+ $ex_text = '';
146
+ }
147
+ echo wpmem_form_field( 'wpmem_' . $item_key . '_' . $key, 'checkbox', '1', $setting ); ?> <span><?php echo $val; ?></span>&nbsp;&nbsp;&nbsp;&nbsp;
148
+ <span><?php _e( 'Number of words in excerpt:', 'wp-members' ); ?> </span><input name="wpmem_autoex_<?php echo $key; ?>_len" type="text" size="5" value="<?php echo $ex_len; ?>" />&nbsp;&nbsp;&nbsp;&nbsp;
149
+ <span><?php _e( 'Custom read more link (optional):', 'wp-members' ); ?> </span><input name="wpmem_autoex_<?php echo $key; ?>_text" type="text" size="5" value="<?php echo $ex_text; ?>" />
150
+ <?php } else {
151
+ $setting = ( isset( $wpmem->{$item_key}[ $key ] ) ) ? $wpmem->{$item_key}[ $key ] : 0;
152
+ echo wpmem_form_field( 'wpmem_' . $item_key . '_' . $key, 'checkbox', '1', $setting ); ?> <span><?php echo $val; ?></span>
153
+ <?php } ?>
154
+ </li>
155
+ <?php $i++;
156
+ }
157
+ }
158
+ } ?>
159
+ </ul>
160
+ <?php
161
+ if ( WPMEM_EXP_MODULE == true ) {
162
+ $rows = array(
163
+ array(__('Time-based expiration','wp-members'),'wpmem_settings_time_exp',__('Allows for access to expire','wp-members'),'use_exp'),
164
+ array(__('Trial period','wp-members'),'wpmem_settings_trial',__('Allows for a trial period','wp-members'),'use_trial'),
165
+ ); ?>
166
+ <h3><?php _e( 'Subscription Settings', 'wp-members' ); ?></h3>
167
+ <ul><?php
168
+ foreach ( $rows as $row ) { ?>
169
+ <li>
170
+ <label><?php echo $row[0]; ?></label>
171
+ <?php echo wpmem_form_field( $row[1], 'checkbox', '1', $wpmem->{$row[3]} ); ?>&nbsp;&nbsp;
172
+ <?php if ( $row[2] ) { ?><span class="description"><?php echo $row[2]; ?></span><?php } ?>
173
+ </li>
174
+ <?php }
175
+ }?></ul>
176
+ <h3><?php _e( 'New Feature Settings', 'wp-members' ); ?> <a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/new-feature-settings/" target="_blank" title="info"><span class="dashicons dashicons-info"></span></a></h3>
177
+ <?php
178
+ $reset_link_start = '<a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/new-feature-settings/" target="_blank">';
179
+ $reset_link_end = '</a>';
180
+ $rows = array(
181
+ //array(__('Password Reset Link', 'wp-members'),'wpmem_settings_pwd_link',__('Send password reset link instead of new password. (Requires additional configuration)','wp-members'),'pwd_link'),
182
+ array(__('Legacy Password Reset', 'wp-members'),'wpmem_settings_pwd_link',sprintf(__('Use legacy password reset. %s(Requires additional configuration)%s','wp-members'),$reset_link_start,$reset_link_end),'pwd_link'),
183
+ //array(__('Enable WP Login Error', 'wp-members' ),'wpmem_settings_login_error',__('Use WP login error object instead of WP-Members default login error','wp-members'),'login_error'),
184
+ array(__('Legacy Login Error', 'wp-members' ),'wpmem_settings_login_error',__('Use legacy WP-Members login error instead of WP error object.','wp-members'),'login_error'),
185
+ );
186
+ if ( wpmem_is_woo_active() ) {
187
+ $rows[] = array(__('WooCommerce My Account', 'wp-members' ),'wpmem_settings_add_my_account_fields',__('Add WP-Members fields to WooCommerce My Account registration','wp-members'),'add_my_account_fields');
188
+ $rows[] = array(__('WooCommerce Checkout', 'wp-members' ),'wpmem_settings_add_checkout_fields',__('Add WP-Members fields to WooCommerce registration during checkout','wp-members'),'add_checkout_fields');
189
+ }
190
+ ?><ul><?php
191
+ foreach ( $rows as $key => $row ) { ?>
192
+ <li>
193
+ <label><?php echo $row[0]; ?></label>
194
+ <?php $checkbox_value = ( 2 == $key || 3 == $key ) ? $wpmem->woo[ $row[3] ] : $wpmem->{$row[3]}; ?>
195
+ <?php if ( 1 == $key || 0 == $key ) {
196
+ echo wpmem_form_field( $row[1], 'checkbox', '0', $checkbox_value ); ?>&nbsp;&nbsp;
197
+ <?php } else {
198
+ echo wpmem_form_field( $row[1], 'checkbox', '1', $checkbox_value ); ?>&nbsp;&nbsp;
199
+ <?php } ?>
200
+ <?php if ( $row[2] ) { ?><span class="description"><?php echo $row[2]; ?></span><?php } ?>
201
+ </li>
202
+ <?php } ?>
203
+ </ul>
204
+ <h3><?php _e( 'Other Settings', 'wp-members' ); ?> <a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/options/#other" target="_blank" title="info"><span class="dashicons dashicons-info"></span></a></h3>
205
+ <ul>
206
+ <?php
207
+ /** This filter is defined in includes/class-wp-members.php */
208
+ $dropin_dir = apply_filters( 'wpmem_dropin_dir', $wpmem->dropin_dir );
209
+ $mem_link_start = '<a href="https://rocketgeek.com/plugins/wp-members/docs/membership-products/" target="_blank">';
210
+ $mem_link_end = '</a>';
211
+ $conf_link_start = '<a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/options/#confirm" target="_blank">';
212
+ $conf_link_end = '</a>';
213
+ $rows = array(
214
+ array(__('Enable Products', 'wp-members'),'wpmem_settings_products',sprintf(__('Enables creation of different %s membership products %s','wp-members'),$mem_link_start,$mem_link_end),'enable_products'),
215
+ array(__('Clone menus','wp-members'),'wpmem_settings_menus',__('Enables logged in menus','wp-members'),'clone_menus'),
216
+ array(__('Notify admin','wp-members'),'wpmem_settings_notify',sprintf(__('Notify %s for each new registration? %s','wp-members'),$admin_email,$chg_email),'notify'),
217
+ array(__('Moderate registration','wp-members'),'wpmem_settings_moderate',__('Holds new registrations for admin approval','wp-members'),'mod_reg'),
218
+ array(__('Confirmation Link', 'wp-members'),'wpmem_settings_act_link',sprintf(__('Send email confirmation link on new registration. %s(Requires additional configuration)%s','wp-members'),$conf_link_start,$conf_link_end),'act_link'),
219
+ array(__('Ignore warning messages','wp-members'),'wpmem_settings_ignore_warnings',__('Ignores WP-Members warning messages in the admin panel','wp-members'),'warnings'),
220
+ //array(__('Enable dropins', 'wp-members'),'wpmem_settings_enable_dropins',sprintf(__('Enables dropins in %s', 'wp-members'), $dropin_dir),'dropins'),
221
+ );
222
+ foreach ( $rows as $row ) {
223
+ if ( $row[0] == __('Clone menus','wp-members') && 1 != $wpmem->clone_menus ) {
224
+ continue;
225
+ }?>
226
+ <li>
227
+ <label><?php echo $row[0]; ?></label>
228
+ <?php echo wpmem_form_field( $row[1], 'checkbox', '1', $wpmem->{$row[3]} ); ?>&nbsp;&nbsp;
229
+ <?php if ( $row[2] ) { ?><span class="description"><?php echo $row[2]; ?></span><?php } ?>
230
+ </li>
231
+ <?php } ?>
232
+ <li>
233
+ <label><?php _e( 'Attribution', 'wp-members' ); ?></label>
234
+ <?php echo wpmem_form_field( 'attribution', 'checkbox', '1', $wpmem->attrib ); ?>&nbsp;&nbsp;
235
+ <span class="description"><?php _e( 'Attribution is appreciated! Display "powered by" link on register form?', 'wp-members' ); ?></span>
236
+ </li>
237
+ <li>
238
+ <label><?php _e( 'Enable CAPTCHA for Registration', 'wp-members' ); ?></label>
239
+ <?php $captcha = array( __( 'None', 'wp-members' ) . '|0' );
240
+ if ( 1 == $wpmem->captcha ) {
241
+ $wpmem->captcha = 3; // reCAPTCHA v1 is fully obsolete. Change it to v2.
242
+ }
243
+ $captcha[] = __( 'reCAPTCHA v2', 'wp-members' ) . '|3';
244
+ $captcha[] = __( 'reCAPTCHA v3', 'wp-members' ) . '|4';
245
+ $captcha[] = __( 'Really Simple CAPTCHA', 'wp-members' ) . '|2';
246
+ $captcha[] = __( 'hCaptcha', 'wp-members' ) . '|5';
247
+ echo wpmem_form_field( 'wpmem_settings_captcha', 'select', $captcha, $wpmem->captcha ); ?>
248
+ </li>
249
+ <h3><?php _e( 'Pages' ); ?> <a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/options/#pages" target="_blank" title="info"><span class="dashicons dashicons-info"></span></a></h3>
250
+ <?php $wpmem_logurl = $wpmem->user_pages['login'];
251
+ if ( ! $wpmem_logurl ) { $wpmem_logurl = wpmem_use_ssl(); } ?>
252
+ <li>
253
+ <label><?php _e( 'Login Page:', 'wp-members' ); ?></label>
254
+ <select name="wpmem_settings_logpage" id="wpmem_logpage_select">
255
+ <?php WP_Members_Admin_Tab_Options::page_list( $wpmem_logurl ); ?>
256
+ </select>&nbsp;<span class="description"><?php _e( 'Specify a login page (optional)', 'wp-members' ); ?></span><br />
257
+ <div id="wpmem_logpage_custom">
258
+ <label>&nbsp;</label>
259
+ <input class="regular-text code" type="text" name="wpmem_settings_logurl" value="<?php echo $wpmem_logurl; ?>" size="50" />
260
+ </div>
261
+ </li>
262
+ <?php $wpmem_regurl = $wpmem->user_pages['register'];
263
+ if ( ! $wpmem_regurl ) { $wpmem_regurl = wpmem_use_ssl(); } ?>
264
+ <li>
265
+ <label><?php _e( 'Register Page:', 'wp-members' ); ?></label>
266
+ <select name="wpmem_settings_regpage" id="wpmem_regpage_select">
267
+ <?php WP_Members_Admin_Tab_Options::page_list( $wpmem_regurl ); ?>
268
+ </select>&nbsp;<span class="description"><?php _e( 'For creating a register link in the login form', 'wp-members' ); ?></span><br />
269
+ <div id="wpmem_regpage_custom">
270
+ <label>&nbsp;</label>
271
+ <input class="regular-text code" type="text" name="wpmem_settings_regurl" value="<?php echo $wpmem_regurl; ?>" size="50" />
272
+ </div>
273
+ </li>
274
+ <?php $wpmem_msurl = $wpmem->user_pages['profile'];
275
+ if ( ! $wpmem_msurl ) { $wpmem_msurl = wpmem_use_ssl(); } ?>
276
+ <li>
277
+ <label><?php _e( 'User Profile Page:', 'wp-members' ); ?></label>
278
+ <select name="wpmem_settings_mspage" id="wpmem_mspage_select">
279
+ <?php WP_Members_Admin_Tab_Options::page_list( $wpmem_msurl ); ?>
280
+ </select>&nbsp;<span class="description"><?php _e( 'For creating a forgot password link in the login form', 'wp-members' ); ?></span><br />
281
+ <div id="wpmem_mspage_custom">
282
+ <label>&nbsp;</label>
283
+ <input class="regular-text code" type="text" name="wpmem_settings_msurl" value="<?php echo $wpmem_msurl; ?>" size="50" />
284
+ </div>
285
+ </li>
286
+ <h3><?php _e( 'Stylesheet' ); ?> <a href="https://rocketgeek.com/plugins/wp-members/docs/plugin-settings/options/#styles" target="_blank" title="info"><span class="dashicons dashicons-info"></span></a></h3>
287
+ <li>
288
+ <label><?php _e( 'Stylesheet' ); ?>:</label>
289
+ <select name="wpmem_settings_style" id="wpmem_stylesheet_select">
290
+ <?php WP_Members_Admin_Tab_Options::style_list( $wpmem->select_style ); ?>
291
+ </select>
292
+ </li>
293
+ <?php $wpmem_cssurl = $wpmem->cssurl;
294
+ if ( ! $wpmem_cssurl ) { $wpmem_cssurl = wpmem_use_ssl(); } ?>
295
+ <div id="wpmem_stylesheet_custom">
296
+ <li>
297
+ <label><?php _e( 'Custom Stylesheet:', 'wp-members' ); ?></label>
298
+ <input class="regular-text code" type="text" name="wpmem_settings_cssurl" value="<?php echo $wpmem_cssurl; ?>" size="50" />
299
+ </li>
300
+ </div>
301
+ <input type="hidden" name="wpmem_admin_a" value="update_settings">
302
+ <?php submit_button( __( 'Update Settings', 'wp-members' ) ); ?>
303
+ </ul>
304
+ </form>
305
+ <p>If you like <strong>WP-Members</strong> please give it a <a href="https://wordpress.org/support/plugin/wp-members/reviews?rate=5#new-post">&#9733;&#9733;&#9733;&#9733;&#9733;</a> rating. Thanks!!</p>
306
+ </div><!-- .inside -->
307
+ </div>
308
+ <?php if ( $post_types ) { ?>
309
+ <div class="postbox">
310
+ <h3><span><?php _e( 'Custom Post Types', 'wp-members' ); ?></span></h3>
311
+ <div class="inside">
312
+ <form name="updatecpts" id="updatecpts" method="post" action="<?php echo wpmem_admin_form_post_url(); ?>">
313
+ <?php wp_nonce_field( 'wpmem-update-cpts' ); ?>
314
+ <table class="form-table">
315
+ <tr>
316
+ <th scope="row"><?php _e( 'Add to WP-Members Settings', 'wp-members' ); ?></th>
317
+ <td><fieldset><?php
318
+ foreach ( $post_arr as $key => $val ) {
319
+ if ( 'post' != $key && 'page' != $key && 'wpmem_product' != $key ) {
320
+ $checked = ( isset( $wpmem->post_types ) && array_key_exists( $key, $wpmem->post_types ) ) ? ' checked' : '';
321
+ echo '<label for="' . $key . '"><input type="checkbox" name="wpmembers_handle_cpts[]" value="' . $key . '"' . $checked . ' />' . $val . '</label><br />';
322
+ }
323
+ }
324
+ ?></fieldset>
325
+ </td>
326
+ </tr>
327
+ <tr>
328
+ <input type="hidden" name="wpmem_admin_a" value="update_cpts" />
329
+ <td colspan="2"><?php submit_button( __( 'Update Settings', 'wp-members' ) ); ?></td>
330
+ </tr>
331
+ <tr>
332
+ <td colspan="2"><?php _e( 'Please keep in mind that Custom Post Types are "custom" and therefore, not all of them will function exactly the same way. WP-Members will certainly work with any post type that operate like a post or a page; but you will need to review any custom post type added to determine that it functions the way you expect.', 'wp-members' ); ?></td>
333
+ </tr>
334
+ </table>
335
+ </form>
336
+ </div>
337
+ </div>
338
+ <?php } ?>
339
+ </div><!-- #post-body-content -->
340
+ </div><!-- #post-body -->
341
+ </div><!-- .metabox-holder -->
342
+ <div id="dialog-message" title="<?php _e( 'WP-Members Settings', 'wp-members' ); ?>">
343
+ <h3><span><?php _e( 'WP-Members Settings', 'wp-members' ); ?></span></h3>
344
+ <p><?php _e( 'The following is your WP-Members settings information if needed for support.', 'wp-members' ); ?></p>
345
+ <pre>
346
+ <textarea cols=80 rows=10 align=left wrap=soft style="width:80%;" id="supportinfo" wrap="soft"><?php
347
+ global $wp_version, $wpdb, $wpmem;
348
+ echo "WP Version: " . $wp_version . "\r\n";
349
+ echo "PHP Version: " . phpversion() . "\r\n";
350
+ echo "MySQL Version: " . $wpdb->db_version() . "\r\n";
351
+ wpmem_fields();
352
+ print_r( $wpmem );
353
+
354
+ /**
355
+ * Action to add before other plugin info.
356
+ *
357
+ * @since 3.4.0
358
+ */
359
+ do_action( 'wpmem_settings_for_support' );
360
+
361
+ echo '***************** Plugin Info *******************' . "\r\n";
362
+ $all_plugins = get_plugins();
363
+ $active_plugins = get_option( 'active_plugins' );
364
+ $active_display = ''; $inactive_display = '';
365
+ foreach ( $all_plugins as $key => $value ) {
366
+ if ( in_array( $key, $active_plugins ) ) {
367
+ $active_display.= $key . " | " . $value['Name'] . " | Version: " . $value['Version'] . "\r\n";
368
+ } else {
369
+ $inactive_display.= $key . " | " . $value['Name'] . " | Version: " . $value['Version'] . "\r\n";
370
+ }
371
+ }
372
+ echo "*************** Active Plugins **************** \r\n";
373
+ echo $active_display;
374
+ echo "*************** Inactive Plugins **************** \r\n";
375
+ echo $inactive_display;
376
+ ?></textarea>
377
+ </pre>
378
+ <button id="select_all" class="ui-button-text"><?php _e( 'Click to Copy', 'wp-members' ); ?></button>
379
+ </div>
380
+ <?php
381
+ }
382
+
383
+ /**
384
+ * Updates the plugin options.
385
+ *
386
+ * @since 2.8.0
387
+ * @since 3.3.0 Ported from wpmem_update_options() and wpmem_update_cpts().
388
+ *
389
+ * @global object $wpmem The WP_Members object.
390
+ * @param string $action
391
+ * @return string The options updated message.
392
+ */
393
+ static function update( $action ) {
394
+
395
+ if ( 'update_cpts' == $action ) {
396
+
397
+ // Check nonce.
398
+ check_admin_referer( 'wpmem-update-cpts' );
399
+
400
+ // Get the main settings array as it stands.
401
+ $wpmem_newsettings = get_option( 'wpmembers_settings' );
402
+
403
+ // Assemble CPT settings.
404
+ $cpts = array();
405
+
406
+ $post_arr = array();
407
+ $post_types = get_post_types( array( 'public' => true, '_builtin' => false ), 'names', 'and' );
408
+ if ( $post_types ) {
409
+ foreach ( $post_types as $post_type ) {
410
+ $cpt_obj = get_post_type_object( $post_type );
411
+ if ( $cpt_obj->labels->name != 'wpmem_product' ) {
412
+ $post_arr[ $cpt_obj->name ] = $cpt_obj->labels->name;
413
+ }
414
+ }
415
+ }
416
+
417
+ $post_vals = ( isset( $_POST['wpmembers_handle_cpts'] ) ) ? $_POST['wpmembers_handle_cpts'] : false;
418
+ if ( $post_vals ) {
419
+ foreach ( $post_vals as $val ) {
420
+ $cpts[ $val ] = sanitize_text_field( $post_arr[ $val ] );
421
+ }
422
+ } else {
423
+ $cpts = array();
424
+ }
425
+ $wpmem_newsettings['post_types'] = $cpts;
426
+
427
+ // Update settings, remove or add CPTs.
428
+ $chk_settings = array( 'block', 'show_excerpt', 'show_login', 'show_reg', 'autoex' );
429
+ foreach ( $chk_settings as $chk ) {
430
+ // Handle removing unmanaged CPTs.
431
+ foreach ( $wpmem_newsettings[ $chk ] as $key => $val ) {
432
+ if ( 'post' != $key && 'page' != $key ) {
433
+ // If the $key is not in managed CPTs, remove it.
434
+ if ( ! array_key_exists( $key, $cpts ) ) {
435
+ unset( $wpmem_newsettings[ $chk ][ $key ] );
436
+ }
437
+ }
438
+ }
439
+ // Handle adding managed CPTs.
440
+ foreach ( $cpts as $key => $val ) {
441
+ if ( ! array_key_exists( $key, $wpmem_newsettings[ $chk ] ) ) {
442
+ if ( 'autoex' == $chk ) {
443
+ // Auto excerpt is an array.
444
+ $wpmem_newsettings[ $chk ][ $key ] = array(
445
+ 'enabled' => 0,
446
+ 'length' => '',
447
+ );
448
+ } else {
449
+ // All other settings are 0|1.
450
+ $wpmem_newsettings[ $chk ][ $key ] = 0;
451
+ }
452
+ }
453
+ }
454
+ }
455
+
456
+ WP_Members_Admin_Tab_Options::save_settings( $wpmem_newsettings );
457
+
458
+ return __( 'Custom Post Type settings were updated', 'wp-members' );
459
+
460
+ } else {
461
+
462
+ global $wpmem;
463
+
464
+ // Check nonce.
465
+ check_admin_referer( 'wpmem-update-settings' );
466
+
467
+ $wpmem_settings_msurl = ( $_POST['wpmem_settings_mspage'] == 'use_custom' ) ? esc_url( $_POST['wpmem_settings_msurl'] ) : '';
468
+ $wpmem_settings_mspage = ( $_POST['wpmem_settings_mspage'] == 'use_custom' ) ? '' : wpmem_sanitize_field( $_POST['wpmem_settings_mspage'], 'int' );
469
+ if ( $wpmem_settings_msurl != wpmem_use_ssl() && $wpmem_settings_msurl != 'use_custom' && ! $wpmem_settings_mspage ) {
470
+ $msurl = trim( $wpmem_settings_msurl );
471
+ } else {
472
+ $msurl = $wpmem_settings_mspage;
473
+ }
474
+
475
+ $wpmem_settings_regurl = ( $_POST['wpmem_settings_regpage'] == 'use_custom' ) ? esc_url( $_POST['wpmem_settings_regurl'] ) : '';
476
+ $wpmem_settings_regpage = ( $_POST['wpmem_settings_regpage'] == 'use_custom' ) ? '' : wpmem_sanitize_field( $_POST['wpmem_settings_regpage'], 'int' );
477
+ if ( $wpmem_settings_regurl != wpmem_use_ssl() && $wpmem_settings_regurl != 'use_custom' && ! $wpmem_settings_regpage ) {
478
+ $regurl = trim( $wpmem_settings_regurl );
479
+ } else {
480
+ $regurl = $wpmem_settings_regpage;
481
+ }
482
+
483
+ $wpmem_settings_logurl = ( $_POST['wpmem_settings_logpage'] == 'use_custom' ) ? esc_url( $_POST['wpmem_settings_logurl'] ) : '';
484
+ $wpmem_settings_logpage = ( $_POST['wpmem_settings_logpage'] == 'use_custom' ) ? '' : wpmem_sanitize_field( $_POST['wpmem_settings_logpage'], 'int' );
485
+ if ( $wpmem_settings_logurl != wpmem_use_ssl() && $wpmem_settings_logurl != 'use_custom' && ! $wpmem_settings_logpage ) {
486
+ $logurl = trim( $wpmem_settings_logurl );
487
+ } else {
488
+ $logurl = $wpmem_settings_logpage;
489
+ }
490
+
491
+ $wpmem_settings_cssurl = esc_url( $_POST['wpmem_settings_cssurl'] );
492
+ $cssurl = ( $wpmem_settings_cssurl != wpmem_use_ssl() ) ? trim( $wpmem_settings_cssurl ) : '';
493
+
494
+ $wpmem_settings_style = ( isset( $_POST['wpmem_settings_style'] ) ) ? sanitize_text_field( $_POST['wpmem_settings_style'] ) : false;
495
+
496
+ $wpmem_newsettings = array(
497
+ 'version' => $wpmem->version,
498
+ 'db_version' => $wpmem->db_version,
499
+ 'act_link' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_act_link', 0 ), 'int' ),
500
+ 'pwd_link' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_pwd_link', 1 ), 'int' ),
501
+ 'login_error' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_login_error', 1 ), 'int' ),
502
+ 'enable_products' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_products', 0 ), 'int' ),
503
+ 'clone_menus' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_menus', 0 ), 'int' ),
504
+ 'notify' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_notify', 0 ), 'int' ),
505
+ 'mod_reg' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_moderate', 0 ), 'int' ),
506
+ 'captcha' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_captcha', 0 ), 'int' ),
507
+ 'use_exp' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_time_exp', 0 ), 'int' ),
508
+ 'use_trial' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_trial', 0 ), 'int' ),
509
+ 'warnings' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_ignore_warnings', 0 ), 'int' ),
510
+ 'dropins' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_enable_dropins', 0 ), 'int' ),
511
+ 'user_pages' => array(
512
+ 'profile' => ( $msurl ) ? $msurl : '',
513
+ 'register' => ( $regurl ) ? $regurl : '',
514
+ 'login' => ( $logurl ) ? $logurl : '',
515
+ ),
516
+ 'woo' => array(
517
+ 'add_my_account_fields' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_add_my_account_fields', 0 ), 'int' ),
518
+ 'add_checkout_fields' => wpmem_sanitize_field( wpmem_get( 'wpmem_settings_add_checkout_fields', 0 ), 'int' ),
519
+ ),
520
+ 'cssurl' => ( $cssurl ) ? $cssurl : '',
521
+ 'select_style' => $wpmem_settings_style,
522
+ 'attrib' => wpmem_sanitize_field( wpmem_get( 'attribution', 0 ), 'int' ),
523
+ );
524
+
525
+ // Build an array of post types
526
+ $post_arr = array( 'post', 'page' );
527
+ if ( isset( $wpmem->post_types ) ) {
528
+ $wpmem_newsettings['post_types'] = $wpmem->post_types;
529
+ foreach ( $wpmem_newsettings['post_types'] as $key => $val ) {
530
+ $post_arr[] = $key;
531
+ }
532
+ }
533
+
534
+ // If activation link is being enabled, make sure current admin is marked as activated.
535
+ if ( 1 == $wpmem_newsettings['act_link'] && 0 == $wpmem->act_link ) {
536
+ update_user_meta( get_current_user_id(), '_wpmem_user_confirmed', time() );
537
+ }
538
+
539
+ // Leave form tag settings alone.
540
+ if ( isset( $wpmem->form_tags ) ) {
541
+ $wpmem_newsettings['form_tags'] = $wpmem->form_tags;
542
+ }
543
+
544
+ // Get settings for blocking, excerpts, show login, and show registration for posts, pages, and custom post types.
545
+ $option_group_array = array( 'block', 'show_excerpt', 'show_login', 'show_reg', 'autoex' );
546
+ foreach ( $option_group_array as $option_group_item ) {
547
+ $arr = array();
548
+ foreach ( $post_arr as $post_type ) {
549
+ $post_var = 'wpmem_' . $option_group_item . '_' . $post_type;
550
+ if ( $option_group_item == 'autoex' ) {
551
+ // Auto excerpt is an array.
552
+ $arr[ $post_type ]['enabled'] = ( isset( $_POST[ $post_var ] ) ) ? wpmem_sanitize_field( $_POST[ $post_var ], 'int' ) : 0;
553
+ $arr[ $post_type ]['length'] = ( isset( $_POST[ $post_var . '_len' ] ) ) ? ( ( $_POST[ $post_var . '_len' ] == '' ) ? 0 : wpmem_sanitize_field( $_POST[ $post_var . '_len' ], 'int' ) ) : '';
554
+ $arr[ $post_type ]['text'] = ( isset( $_POST[ $post_var . '_text' ] ) ) ? sanitize_text_field( $_POST[ $post_var . '_text' ] ) : '';
555
+ } else {
556
+ // All other settings are 0|1.
557
+ $arr[ $post_type ] = ( isset( $_POST[ $post_var ] ) ) ? wpmem_sanitize_field( $_POST[ $post_var ], 'int' ) : 0;
558
+ }
559
+ }
560
+ $wpmem_newsettings[ $option_group_item ] = $arr;
561
+ }
562
+
563
+ /*
564
+ * If we are setting registration to be moderated,
565
+ * check to see if the current admin has been
566
+ * activated so they don't accidentally lock themselves
567
+ * out later.
568
+ */
569
+ if ( isset( $_POST['wpmem_settings_moderate'] ) == 1 ) {
570
+ update_user_meta( get_current_user_id(), 'active', 1 );
571
+ }
572
+
573
+ if ( isset( $_POST['wpmem_settings_act_link'] ) == 1 ) {
574
+ update_user_meta( get_current_user_id(), '_wpmem_activation_confirm', time() );
575
+ }
576
+
577
+ WP_Members_Admin_Tab_Options::save_settings( $wpmem_newsettings );
578
+
579
+ return __( 'WP-Members settings were updated', 'wp-members' );
580
+ }
581
+ }
582
+
583
+ /**
584
+ * Puts new settings into the current object.
585
+ *
586
+ * @since 3.0.9
587
+ * @since 3.3.0 Ported from wpmem_admin_new_settings().
588
+ *
589
+ * @global $wpmem
590
+ * @param $new
591
+ * @return $settings
592
+ */
593
+ static function save_settings( $new ) {
594
+
595
+ // Update saved settings.
596
+ update_option( 'wpmembers_settings', $new );
597
+
598
+ // Update the current WP_Members object with the new settings.
599
+ global $wpmem;
600
+ foreach ( $new as $key => $val ) {
601
+ if ( 'user_pages' == $key ) {
602
+ foreach ( $val as $subkey => $subval ) {
603
+ $val[ $subkey ] = ( is_numeric( $subval ) ) ? get_page_link( $subval ) : $subval;
604
+ }
605
+ }
606
+ $wpmem->{$key} = $val;
607
+ }
608
+ }
609
+
610
+ /**
611
+ * Create the stylesheet dropdown selection.
612
+ *
613
+ * @since 2.8.0
614
+ * @since 3.3.0 Ported from wpmem_admin_style_list().
615
+ *
616
+ * @param $style string The stored stylesheet setting.
617
+ */
618
+ static function style_list( $style ) {
619
+
620
+ $list = array(
621
+ 'No Float' => 'generic-no-float',
622
+ 'Rigid' => 'generic-rigid',
623
+ 'Twenty Sixteen - no float' => 'wp-members-2016-no-float',
624
+ 'Twenty Fifteen' => 'wp-members-2015',
625
+ 'Twenty Fifteen - no float' => 'wp-members-2015-no-float',
626
+ 'Twenty Fourteen' => 'wp-members-2014',
627
+ 'Twenty Fourteen - no float' => 'wp-members-2014-no-float',
628
+ //'Twenty Thirteen' => WPMEM_DIR . 'css/wp-members-2013.css',
629
+ //'Twenty Twelve' => WPMEM_DIR . 'css/wp-members-2012.css',
630
+ //'Twenty Eleven' => WPMEM_DIR . 'css/wp-members-2011.css',
631
+ //'Twenty Ten' => WPMEM_DIR . 'css/wp-members.css',
632
+ //'Kubrick' => WPMEM_DIR . 'css/wp-members-kubrick.css',
633
+ );
634
+
635
+ /**
636
+ * Filters the list of stylesheets in the plugin options dropdown.
637
+ *
638
+ * @since 2.8.0
639
+ * @deprecated 3.3.0 There is no way to manage custom values in the dropdown with the new setting rules.
640
+ *
641
+ * @param array $list An array of stylesheets that can be applied to the plugin's forms.
642
+ */
643
+ //$list = apply_filters( 'wpmem_admin_style_list', $list );
644
+
645
+ $selected = false;
646
+ foreach ( $list as $name => $location ) {
647
+ $selected = ( $location == $style ) ? true : $selected;
648
+ echo '<option value="' . $location . '" ' . selected( $location, $style ) . '>' . $name . "</option>\n";
649
+ }
650
+ $selected = ( ! $selected ) ? ' selected' : '';
651
+ echo '<option value="use_custom"' . $selected . '>' . __( 'USE CUSTOM URL BELOW', 'wp-members' ) . '</option>';
652
+
653
+ return;
654
+ }
655
+
656
+ /**
657
+ * Create a dropdown selection of pages.
658
+ *
659
+ * @since 2.8.1
660
+ * @since 3.3.0 Ported from wpmem_admin_page_list().
661
+ *
662
+ * @todo Consider wp_dropdown_pages. Can be retrieved as HTML (echo=false) and str_replaced to add custom values.
663
+ *
664
+ * @param string $val
665
+ */
666
+ static function page_list( $val, $show_custom_url = true ) {
667
+
668
+ $selected = ( $val == 'http://' || $val == 'https://' ) ? 'select a page' : false;
669
+ $pages = get_pages();
670
+
671
+ echo '<option value=""'; echo ( $selected == 'select a page' ) ? ' selected' : ''; echo '>'; echo esc_attr( __( 'Select a page', 'wp-members' ) ); echo '</option>';
672
+
673
+ foreach ( $pages as $page ) {
674
+ $selected = ( get_page_link( $page->ID ) == $val ) ? true : $selected; //echo "VAL: " . $val . ' PAGE LINK: ' . get_page_link( $page->ID );
675
+ $option = '<option value="' . $page->ID . '"' . selected( get_page_link( $page->ID ), $val, 'select' ) . '>';
676
+ $option .= $page->post_title;
677
+ $option .= '</option>';
678
+ echo $option;
679
+ }
680
+ if ( $show_custom_url ) {
681
+ $selected = ( ! $selected ) ? ' selected' : '';
682
+ echo '<option value="use_custom"' . $selected . '>' . __( 'USE CUSTOM URL BELOW', 'wp-members' ) . '</option>';
683
+ }
684
+ }
685
+
 
 
 
 
 
686
  } // End of file.
includes/admin/tabs/class-wp-members-dropins-table.php CHANGED
@@ -4,12 +4,12 @@
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.
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-2021 Chad Butler
8
  * WP-Members(tm) is a trademark of butlerblog.com
9
  *
10
  * @package WP-Members
11
  * @author Chad Butler
12
+ * @copyright 2006-2021
13
  */
14
 
15
  // Exit if accessed directly.
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-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', '_wpmem_user_confirmed', '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-2021 Chad Butler
8
+ * WP-Members(tm) is a trademark of butlerblog.com
9
+ *
10
+ * @package WP-Members
11
+ * @author Chad Butler
12
+ * @copyright 2006-2021
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', '_wpmem_user_confirmed', '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
@@ -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-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
  /**
@@ -41,6 +41,25 @@ function wpmem_mail_from_name() {
41
  return $wpmem->email->from_name;
42
  }
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  /**
45
  * Builds emails for the user.
46
  *
@@ -81,11 +100,11 @@ function wpmem_email_to_user( $args, $password = null, $tag = null, $wpmem_field
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
  }
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-2021 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-2021
14
  */
15
 
16
  /**
41
  return $wpmem->email->from_name;
42
  }
43
 
44
+ /**
45
+ * Returns the wp_mail content type (if set).
46
+ *
47
+ * @since 3.4.0
48
+ *
49
+ * @global object $wpmem
50
+ * @return string $wpmem_mail_content_type
51
+ *
52
+ * @note Currently checks for existing function. Advanced Options set up for
53
+ * backward compatibility could potentially load first if wp-members directory
54
+ * is named something other than "wp-members".
55
+ */
56
+ if ( ! function_exists( 'wpmem_mail_content_type' ) ):
57
+ function wpmem_mail_content_type() {
58
+ global $wpmem;
59
+ return $wpmem->email->content_type();
60
+ }
61
+ endif;
62
+
63
  /**
64
  * Builds emails for the user.
65
  *
100
  global $wpmem;
101
  if ( is_array( $args ) ) {
102
  $user_id = $args['user_id'];
 
103
  $tag = $args['tag'];
104
+ $password = ( isset( $args['password'] ) ) ? $args['password'] : '';
105
+ $wpmem_fields = ( isset( $args['wpmem_fields'] ) ) ? $args['wpmem_fields'] : '';
106
+ $field_data = ( isset( $args['field_data'] ) ) ? $args['field_data'] : '';
107
+ $custom = ( isset( $args['custom'] ) ) ? $args['custom'] : '';
108
  } else {
109
  $user_id = $args;
110
  }
includes/api/api-forms.php CHANGED
@@ -1,582 +1,634 @@
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
- if ( ! function_exists( 'wpmem_login_form' ) ):
17
- /**
18
- * Invokes a login form.
19
- *
20
- * Note: The original pluggable version of this function used a $page param
21
- * and an array. This function should (1) no longer be considered pluggable
22
- * and (2) should pass all arguments in the form if a single array. The previous
23
- * methods are maintained for legacy reasons, but should be updated to apply
24
- * to the current function documentation.
25
- *
26
- * @since 2.5.1
27
- * @since 3.1.7 Now a wrapper for $wpmem->forms->login_form()
28
- * @since 3.3.0 Added to API.
29
- *
30
- * @global object $wpmem
31
- * @param array $args {
32
- * Possible arguments for creating the form.
33
- *
34
- * @type string $id
35
- * @type string $tag
36
- * @type string $form
37
- * @type string $redirect_to
38
- * }
39
- * @param array $arr {
40
- * Maintained only for legacy reasons.
41
- * The elements needed to generate the form (login|reset password|forgotten password).
42
- *
43
- * @type string $heading Form heading text.
44
- * @type string $action The form action (login|pwdchange|pwdreset).
45
- * @type string $button_text Form submit button text.
46
- * @type array $inputs {
47
- * The form input values.
48
- *
49
- * @type array {
50
- *
51
- * @type string $name The field label.
52
- * @type string $type Input type.
53
- * @type string $tag Input tag name.
54
- * @type string $class Input tag class.
55
- * @type string $div Div wrapper class.
56
- * }
57
- * }
58
- * @type string $redirect_to Optional. URL to redirect to.
59
- * }
60
- * @return string $form The HTML for the form as a string.
61
- */
62
- function wpmem_login_form( $args, $arr = false ) {
63
- global $wpmem;
64
- // Convert legacy values.
65
- if ( ! is_array( $args ) && is_array( $arr ) ) {
66
- $page = $args;
67
- $args = $arr;
68
- $args['page'] = $page;
69
- }
70
- // @todo Work on making this $wpmem->forms->do_login_form( $args );
71
- return $wpmem->forms->login_form( $args );
72
- }
73
- endif;
74
-
75
- /**
76
- * Use the WP login form.
77
- *
78
- * @since 3.3.2
79
- *
80
- * @global stdClass $wpmem
81
- * @param array $args
82
- */
83
- function wpmem_wp_login_form( $args ) {
84
- global $wpmem;
85
- return $wpmem->forms->wp_login_form( $args );
86
- }
87
-
88
- /**
89
- * Invokes a registration or user profile update form.
90
- *
91
- * @since 3.2.0
92
- *
93
- * @global object $wpmem
94
- * @param array $args {
95
- * Possible arguments for creating the form.
96
- *
97
- * @type string id
98
- * @type string tag
99
- * @type string form
100
- * @type string product
101
- * @type string include_fields
102
- * @type string exclude_fields
103
- * @type string redirect_to
104
- * @type string heading
105
- * }
106
- * @return string $html
107
- */
108
- function wpmem_register_form( $args = 'new' ) {
109
- global $wpmem;
110
- return $wpmem->forms->register_form( $args );
111
- }
112
-
113
- /**
114
- * Change Password Form.
115
- *
116
- * @since 3.3.0 Replaces wpmem_inc_changepassword().
117
- * @since 3.3.0 Added $action argument.
118
- *
119
- * @global stdClass $wpmem The WP_Members object.
120
- *
121
- * @param string $action Determine if it is password change or reset.
122
- * @return string $str The generated html for the change password form.
123
- */
124
- function wpmem_change_password_form() {
125
- global $wpmem;
126
- return $wpmem->forms->do_shortform( 'changepassword' );
127
- }
128
-
129
- /**
130
- * Reset Password Form.
131
- *
132
- * @since 3.3.0 Replaced wpmem_inc_resetpassword().
133
- *
134
- * @global object $wpmem The WP_Members object.
135
- * @return string $str The generated html fo the reset password form.
136
- */
137
- function wpmem_reset_password_form() {
138
- global $wpmem;
139
- return $wpmem->forms->do_shortform( 'resetpassword' );
140
- }
141
-
142
- /**
143
- * Forgot Username Form.
144
- *
145
- * @since 3.3.0 Replaced wpmem_inc_forgotusername().
146
- *
147
- * @global object $wpmem The WP_Members object class.
148
- * @return string $str The generated html for the forgot username form.
149
- */
150
- function wpmem_forgot_username_form() {
151
- global $wpmem;
152
- return $wpmem->forms->do_shortform( 'forgotusername' );
153
- }
154
-
155
- /**
156
- * Add registration fields to the native WP registration.
157
- *
158
- * @since 2.8.3
159
- * @since 3.1.8 Added $process argument.
160
- * @since 3.3.0 Moved to forms API.
161
- *
162
- * @global stdClass $wpmem
163
- * @param string $process
164
- */
165
- function wpmem_wp_register_form( $process = 'register_wp' ) {
166
- global $wpmem;
167
- $wpmem->forms->wp_register_form( $process );
168
- }
169
-
170
- /**
171
- * Add registration fields to WooCommerce registration.
172
- *
173
- * As of WooCommerce 3.0, the WC registration process no longer includes the
174
- * WP register_form action hook. It only includes woocommerce_register_form.
175
- * In previous versions, WP-Members hooked to register_form for both WP and
176
- * WC registration. To provide backward compatibility with users who may
177
- * continue to use updated WP-Members with pre-3.0 WooCommerce, this function
178
- * checks for WC version and if it is older than 3.0 it will ignore adding
179
- * the WP-Members form fields as they would have already been added when the
180
- * register_form action hook fired.
181
- *
182
- * @since 3.1.8
183
- * @since 3.3.0 Moved to forms API.
184
- *
185
- * @global stdClass $woocommerce
186
- */
187
- function wpmem_woo_register_form() {
188
- if ( class_exists( 'WooCommerce' ) ) {
189
- global $woocommerce;
190
- if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
191
- wpmem_wp_register_form( 'woo' );
192
- }
193
- }
194
- }
195
-
196
- /**
197
- * Wrapper for $wpmem->create_form_field().
198
- *
199
- * @since 3.1.2
200
- * @since 3.2.0 Accepts wpmem_create_formfield() arguments.
201
- *
202
- * @global object $wpmem The WP_Members object class.
203
- * @param string|array $args {
204
- * @type string $name (required) The field meta key.
205
- * @type string $type (required) The field HTML type (url, email, image, file, checkbox, text, textarea, password, hidden, select, multiselect, multicheckbox, radio).
206
- * @type string $value (optional) The field's value (can be a null value).
207
- * @type string $compare (optional) Compare value.
208
- * @type string $class (optional) Class identifier for the field.
209
- * @type boolean $required (optional) If a value is required default: true).
210
- * @type string $delimiter (optional) The field delimiter (pipe or comma, default: | ).
211
- * @type string $placeholder (optional) Defines the placeholder attribute.
212
- * @type string $pattern (optional) Adds a regex pattern to the field (HTML5).
213
- * @type string $title (optional) Defines the title attribute.
214
- * @type string $min (optional) Adds a min attribute (HTML5).
215
- * @type string $max (optional) Adds a max attribute (HTML5).
216
- * @type string $rows (optional) Adds rows attribute to textarea.
217
- * @type string $cols (optional) Adds cols attribute to textarea.
218
- * }
219
- * @param string $type The field type.
220
- * @param string $value The default value for the field.
221
- * @param string $valtochk Optional for comparing the default value of the field.
222
- * @param string $class Optional for setting a specific CSS class for the field.
223
- * @return string The HTML of the form field.
224
- */
225
- //function wpmem_form_field( $args ) {
226
- function wpmem_form_field( $name, $type=null, $value=null, $valtochk=null, $class='textbox' ) {
227
- global $wpmem;
228
- if ( is_array( $name ) ) {
229
- $args = $name;
230
- } else {
231
- $args = array(
232
- 'name' => $name,
233
- 'type' => $type,
234
- 'value' => $value,
235
- 'compare' => $valtochk,
236
- 'class' => $class,
237
- );
238
- }
239
- return $wpmem->forms->create_form_field( $args );
240
- }
241
-
242
- /**
243
- * Wrapper for $wpmem->create_form_label().
244
- *
245
- * @since 3.1.7
246
- *
247
- * @global object $wpmem
248
- * @param array $args {
249
- * @type string $meta_key
250
- * @type string $label
251
- * @type string $type
252
- * @type string $id (optional)
253
- * @type string $class (optional)
254
- * @type string $required (optional)
255
- * @type string $req_mark (optional)
256
- * }
257
- * @return string The HTML of the form label.
258
- */
259
- function wpmem_form_label( $args ) {
260
- global $wpmem;
261
- return $wpmem->forms->create_form_label( $args );
262
- }
263
-
264
- /**
265
- * Wrapper to get form fields.
266
- *
267
- * @since 3.1.1
268
- * @since 3.1.5 Checks if fields array is set or empty before returning.
269
- * @since 3.1.7 Added wpmem_form_fields filter.
270
- *
271
- * @global object $wpmem The WP_Members object.
272
- * @param string $tag The action being used (default: null).
273
- * @param string $form The form being generated.
274
- * @return array $fields The form fields.
275
- */
276
- function wpmem_fields( $tag = '', $form = 'default' ) {
277
- global $wpmem;
278
- // Load fields if none are loaded.
279
- if ( ! isset( $wpmem->fields ) || empty( $wpmem->fields ) ) {
280
- $wpmem->load_fields( $form );
281
- }
282
-
283
- // @todo Review for removal.
284
- $tag = $wpmem->convert_tag( $tag );
285
-
286
- /**
287
- * Filters the fields array.
288
- *
289
- * @since 3.1.7
290
- * @since 3.3.2 Change object var and return.
291
- *
292
- * @param array $wpmem->fields
293
- * @param string $tag (optional)
294
- */
295
- $wpmem->fields = apply_filters( 'wpmem_fields', $wpmem->fields, $tag );
296
-
297
- return $wpmem->fields;
298
- }
299
-
300
- /**
301
- * Sanitizes classes passed to the WP-Members form building functions.
302
- *
303
- * This generally uses just sanitize_html_class() but allows for
304
- * whitespace so multiple classes can be passed (such as "regular-text code").
305
- * This is an API wrapper for WP_Members_Forms::sanitize_class().
306
- *
307
- * @since 3.2.9
308
- *
309
- * @global object $wpmem
310
- *
311
- * @param string $class
312
- * @return string sanitized_class
313
- */
314
- function wpmem_sanitize_class( $class ) {
315
- global $wpmem;
316
- return $wpmem->forms->sanitize_class( $class );
317
- }
318
-
319
- /**
320
- * Sanitizes the text in an array.
321
- *
322
- * This is an API wrapper for WP_Members_Forms::sanitize_array().
323
- *
324
- * @since 3.2.9
325
- * @since 3.3.7 Added optional $type
326
- *
327
- * @global object $wpmem
328
- *
329
- * @param array $data
330
- * @param string $type The data type integer|int (default: false)
331
- * @return array $data
332
- */
333
- function wpmem_sanitize_array( $data, $type = false ) {
334
- global $wpmem;
335
- return $wpmem->forms->sanitize_array( $data, $type );
336
- }
337
-
338
- /**
339
- * A multi use sanitization function.
340
- *
341
- * @since 3.3.0
342
- *
343
- * @global object $wpmem
344
- *
345
- * @param string $data
346
- * @param string $type (multiselect|multicheckbox|textarea|email|file|image|int|integer|number)
347
- * @return string $sanitized_data
348
- */
349
- function wpmem_sanitize_field( $data, $type = 'text' ) {
350
- global $wpmem;
351
- return $wpmem->forms->sanitize_field( $data, $type );
352
- }
353
-
354
- /**
355
- * Generate a form nonce.
356
- *
357
- * @since 3.3.0
358
- *
359
- * @param string $nonce
360
- * @param boolean $echo
361
- * @return string The nonce.
362
- */
363
- function wpmem_form_nonce( $nonce, $echo = false ) {
364
- $form = ( 'update' == $nonce || 'register' == $nonce ) ? 'longform' : 'shortform';
365
- return wp_nonce_field( 'wpmem_' . $form . '_nonce', '_wpmem_' . $nonce . '_nonce', true, $echo );
366
- }
367
-
368
- // @todo Experimental
369
- /**
370
- * Create WP-Members fields set for woo checkout.
371
- *
372
- * @since 3.3.4
373
- *
374
- * @param array $checkout_fields
375
- */
376
- function wpmem_woo_checkout_fields( $checkout_fields = false ) {
377
- $woo_checkout = array(
378
- 'billing_first_name',
379
- 'billing_last_name',
380
- 'billing_company',
381
- 'billing_country',
382
- 'billing_address_1',
383
- 'billing_address_2',
384
- 'billing_city',
385
- 'billing_state',
386
- 'billing_postcode',
387
- 'billing_phone',
388
- 'billing_email',
389
- 'account_username',
390
- 'account_password',
391
- );
392
- $fields = wpmem_fields();
393
-
394
- if ( ! $checkout_fields ) {
395
- $checkout_fields = WC()->checkout()->checkout_fields;
396
- }
397
-
398
- foreach ( $fields as $meta_key => $field ) {
399
-
400
- if ( 1 != $fields[ $meta_key ]['register'] ) {
401
- unset( $fields[ $meta_key ] );
402
- } else {
403
- if ( isset( $checkout_fields['billing'][ $meta_key ] ) ) {
404
- unset( $fields[ $meta_key ] );
405
- }
406
- if ( isset( $checkout_fields['shipping'][ $meta_key ] ) ) {
407
- unset( $fields[ $meta_key ] );
408
- }
409
- if ( isset( $checkout_fields['account'][ $meta_key ] ) ) {
410
- unset( $fields[ $meta_key ] );
411
- }
412
- if ( isset( $checkout_fields['order'][ $meta_key ] ) ) {
413
- unset( $fields[ $meta_key ] );
414
- }
415
- }
416
-
417
- // @todo For now, remove any unsupported field types.
418
- if ( 'hidden' == $field['type'] || 'image' == $field['type'] || 'file' == $field['type'] || 'membership' == $field['type'] ) {
419
- unset( $fields[ $meta_key ] );
420
- }
421
- }
422
- unset( $fields['username'] );
423
- unset( $fields['password'] );
424
- unset( $fields['confirm_password'] );
425
- unset( $fields['confirm_email'] );
426
- unset( $fields['user_email'] );
427
- unset( $fields['first_name'] );
428
- unset( $fields['last_name'] );
429
-
430
- return $fields;
431
- }
432
-
433
- /**
434
- * Adds WP-Members custom fields to woo checkout.
435
- *
436
- * @since 3.3.4
437
- *
438
- * @param array $checkout_fields
439
- */
440
- function wpmem_woo_checkout_form( $checkout_fields ) {
441
- global $wpmem;
442
- $fields = wpmem_woo_checkout_fields( $checkout_fields );
443
-
444
- /**
445
- * Filters the initial WC priority of the WP-members added fields.
446
- *
447
- * @since 3.3.7
448
- *
449
- * @param int
450
- */
451
- $priority = apply_filters( 'wpmem_wc_checkout_field_priority_seed', 10 );
452
-
453
- foreach ( $fields as $meta_key => $field ) {
454
- $checkout_fields['order'][ $meta_key ] = array(
455
- 'type' => $fields[ $meta_key ]['type'],
456
- 'label' => ( 'tos' == $meta_key ) ? $wpmem->forms->get_tos_link( $field, 'woo' ) : $fields[ $meta_key ]['label'],
457
- 'required' => $fields[ $meta_key ]['required'],
458
- 'priority' => $priority,
459
- );
460
- if ( isset( $fields[ $meta_key ]['placeholder'] ) ) {
461
- $checkout_fields['order'][ $meta_key ]['placeholder'] = $fields[ $meta_key ]['placeholder'];
462
- }
463
- $priority = $priority + 10;
464
- }
465
- return $checkout_fields;
466
- }
467
-
468
- /**
469
- * Saves WP-Members custom fields for woo checkout.
470
- *
471
- * @since 3.3.4
472
- *
473
- * @param int $order_id
474
- */
475
- function wpmem_woo_checkout_update_meta( $order_id ) {
476
-
477
- // Get user id from order.
478
- $order = wc_get_order( $order_id );
479
- $user_id = $order->get_user_id();
480
-
481
- $checkout_fields = WC()->checkout()->checkout_fields;
482
- $fields = wpmem_fields();
483
- foreach ( $fields as $meta_key => $field ) {
484
- if ( isset( $checkout_fields['order'][ $meta_key ] ) && isset( $_POST[ $meta_key ] ) ) {
485
- switch ( $fields[ $meta_key ]['type'] ) {
486
- case 'checkbox':
487
- update_user_meta( $user_id, $meta_key, $field['checked_value'] );
488
- break;
489
- case 'textarea':
490
- update_user_meta( $user_id, $meta_key, sanitize_textarea_field( $_POST[ $meta_key ] ) );
491
- break;
492
- case 'multicheckbox':
493
- case 'multiselect':
494
- update_user_meta( $user_id, $meta_key, wpmem_sanitize_array( $_POST[ $meta_key ] ) );
495
- break;
496
- case 'membership':
497
- wpmem_set_user_product( wpmem_sanitize_array( $_POST[ $meta_key ] ), $user_id );
498
- break;
499
- default:
500
- if ( 'user_url' == $meta_key ) {
501
- wp_update_user( array( 'ID' => $user_id, 'user_url' => sanitize_text_field( $_POST[ $meta_key ] ) ) );
502
- } else {
503
- update_user_meta( $user_id, $meta_key, sanitize_text_field( $_POST[ $meta_key ] ) );
504
- }
505
- break;
506
- }
507
- }
508
- }
509
- }
510
-
511
- function wpmem_form_field_wc_custom_field_types( $field, $key, $args, $value ) {
512
-
513
- $wpmem_fields = wpmem_fields();
514
- /**
515
- * @type string $name (required) The field meta key.
516
- * @type string $type (required) The field HTML type (url, email, image, file, checkbox, text, textarea, password, hidden, select, multiselect, multicheckbox, radio).
517
- * @type string $value (optional) The field's value (can be a null value).
518
- * @type string $compare (optional) Compare value.
519
- * @type string $class (optional) Class identifier for the field.
520
- * @type boolean $required (optional) If a value is required default: true).
521
- * @type string $delimiter (optional) The field delimiter (pipe or comma, default: | ).
522
- * @type string $placeholder (optional) Defines the placeholder attribute.
523
- * @type string $pattern (optional) Adds a regex pattern to the field (HTML5).
524
- * @type string $title (optional) Defines the title attribute.
525
- * @type string $min (optional) Adds a min attribute (HTML5).
526
- * @type string $max (optional) Adds a max attribute (HTML5).
527
- * @type string $rows (optional) Adds rows attribute to textarea.
528
- * @type string $cols (optional) Adds cols attribute to textarea.
529
- */
530
-
531
- // Let's only mess with WP-Members fields (in case another checkout fields plugin is used).
532
- if ( array_key_exists( $key, $wpmem_fields ) ) {
533
-
534
- // If it is a checkbox.
535
- if ( 'checkbox' == $wpmem_fields[ $key ]['type'] ) {
536
-
537
- if ( ! $_POST && $wpmem_fields[ $key ]['checked_default'] ) {
538
- $field = str_replace( '<input type="checkbox"', '<input type="checkbox" checked ', $field );
539
- }
540
-
541
- } else {
542
-
543
- $field_args = array(
544
- 'name' => $key,
545
- 'type' => $wpmem_fields[ $key ]['type'],
546
- 'required' => $wpmem_fields[ $key ]['required'],
547
- 'delimiter' => $wpmem_fields[ $key ]['delimiter'],
548
- 'value' => $wpmem_fields[ $key ]['values'],
549
- );
550
-
551
- $field_html = wpmem_form_field( $field_args );
552
- $field_html = str_replace( 'class="' . $wpmem_fields[ $key ]['type'] . '"', 'class="' . $wpmem_fields[ $key ]['type'] . '" style="display:initial;"', $field_html );
553
- $field = '<p class="form-row ' . implode( ' ', $args['class'] ) .'" id="' . $key . '_field">
554
- <label for="' . $key . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label'] . ( ( 1 == $wpmem_fields[ $key ]['required'] ) ? '&nbsp;<abbr class="required" title="required">*</abbr>' : '' ) . '</label>';
555
- $field .= $field_html;
556
- $field .= '</p>';
557
- }
558
-
559
- }
560
-
561
- return $field;
562
- }
563
-
564
- function wpmem_woo_reg_validate( $username, $email, $errors ) {
565
-
566
- $fields = wpmem_woo_checkout_fields();
567
-
568
- unset( $fields['username'] );
569
- unset( $fields['password'] );
570
- unset( $fields['confirm_password'] );
571
- unset( $fields['user_email'] );
572
- unset( $fields['first_name'] );
573
- unset( $fields['last_name'] );
574
-
575
- foreach ( $fields as $key => $field_args ) {
576
- if ( 1 == $field_args['required'] && empty( $_POST[ $key ] ) ) {
577
- $message = sprintf( __( '%s is a required field.', 'wp-members' ), '<strong>' . $field_args['label'] . '</strong>' );
578
- $errors->add( $key, $message );
579
- }
580
- }
581
- return $errors;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
582
  }
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-2021 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-2021
14
+ */
15
+
16
+ if ( ! function_exists( 'wpmem_login_form' ) ):
17
+ /**
18
+ * Invokes a login form.
19
+ *
20
+ * Note: The original pluggable version of this function used a $page param
21
+ * and an array. This function should (1) no longer be considered pluggable
22
+ * and (2) should pass all arguments in the form if a single array. The previous
23
+ * methods are maintained for legacy reasons, but should be updated to apply
24
+ * to the current function documentation.
25
+ *
26
+ * @since 2.5.1
27
+ * @since 3.1.7 Now an alias for $wpmem->forms->login_form()
28
+ * @since 3.3.0 Added to API.
29
+ * @since 3.4.0 Main API function for displaying login form.
30
+ *
31
+ * @global object $wpmem
32
+ * @param array $args {
33
+ * Possible arguments for creating the form.
34
+ *
35
+ * @type string $id
36
+ * @type string $tag
37
+ * @type string $form
38
+ * @type string $redirect_to
39
+ * }
40
+ * @param array $arr {
41
+ * Maintained only for legacy reasons.
42
+ * The elements needed to generate the form (login|reset password|forgotten password).
43
+ *
44
+ * @type string $heading Form heading text.
45
+ * @type string $action The form action (login|pwdchange|pwdreset).
46
+ * @type string $button_text Form submit button text.
47
+ * @type array $inputs {
48
+ * The form input values.
49
+ *
50
+ * @type array {
51
+ *
52
+ * @type string $name The field label.
53
+ * @type string $type Input type.
54
+ * @type string $tag Input tag name.
55
+ * @type string $class Input tag class.
56
+ * @type string $div Div wrapper class.
57
+ * }
58
+ * }
59
+ * @type string $redirect_to Optional. URL to redirect to.
60
+ * }
61
+ * @return string $form The HTML for the form as a string.
62
+ */
63
+ function wpmem_login_form( $args = array(), $arr = false ) {
64
+ global $wpmem;
65
+
66
+ /*
67
+ // Convert legacy values.
68
+ if ( ( ! is_array( $args ) && is_array( $arr ) ) || ( is_array( $args ) && empty( $args ) ) ) {
69
+ $page = $args;
70
+ $args = $arr;
71
+ $args['page'] = $page;
72
+ }
73
+ $args['form'] = ( isset( $args['form'] ) ) ? $args['form'] : 'login';
74
+ // @todo Work on making this $wpmem->forms->do_login_form( $args );
75
+ return $wpmem->forms->login_form( $args );
76
+ */
77
+
78
+ return $wpmem->forms->do_shortform( 'login', $args );
79
+ }
80
+ endif;
81
+
82
+ /**
83
+ * Use the WP login form.
84
+ *
85
+ * @since 3.3.2
86
+ *
87
+ * @global stdClass $wpmem
88
+ * @param array $args
89
+ */
90
+ function wpmem_wp_login_form( $args ) {
91
+ global $wpmem;
92
+ return $wpmem->forms->wp_login_form( $args );
93
+ }
94
+
95
+ /**
96
+ * Invokes a registration or user profile update form.
97
+ *
98
+ * @since 3.2.0
99
+ *
100
+ * @global object $wpmem
101
+ * @param array $args {
102
+ * Possible arguments for creating the form.
103
+ *
104
+ * @type string id
105
+ * @type string tag
106
+ * @type string form
107
+ * @type string product
108
+ * @type string include_fields
109
+ * @type string exclude_fields
110
+ * @type string redirect_to
111
+ * @type string heading
112
+ * }
113
+ * @return string $html
114
+ */
115
+ function wpmem_register_form( $args = 'new' ) {
116
+ global $wpmem;
117
+ return $wpmem->forms->register_form( $args );
118
+ }
119
+
120
+ /**
121
+ * Change Password Form.
122
+ *
123
+ * @since 3.3.0 Replaces wpmem_inc_changepassword().
124
+ * @since 3.3.0 Added $action argument.
125
+ *
126
+ * @global stdClass $wpmem The WP_Members object.
127
+ *
128
+ * @param string $action Determine if it is password change or reset.
129
+ * @return string $str The generated html for the change password form.
130
+ */
131
+ function wpmem_change_password_form() {
132
+ global $wpmem;
133
+ return $wpmem->forms->do_shortform( 'changepassword' );
134
+ }
135
+
136
+ /**
137
+ * Reset Password Form.
138
+ *
139
+ * @since 3.3.0 Replaced wpmem_inc_resetpassword().
140
+ *
141
+ * @global object $wpmem The WP_Members object.
142
+ * @return string $str The generated html fo the reset password form.
143
+ */
144
+ function wpmem_reset_password_form() {
145
+ global $wpmem;
146
+ return $wpmem->forms->do_shortform( 'resetpassword' );
147
+ }
148
+
149
+ /**
150
+ * Forgot Username Form.
151
+ *
152
+ * @since 3.3.0 Replaced wpmem_inc_forgotusername().
153
+ *
154
+ * @global object $wpmem The WP_Members object class.
155
+ * @return string $str The generated html for the forgot username form.
156
+ */
157
+ function wpmem_forgot_username_form() {
158
+ global $wpmem;
159
+ return $wpmem->forms->do_shortform( 'forgotusername' );
160
+ }
161
+
162
+ /**
163
+ * Add registration fields to the native WP registration.
164
+ *
165
+ * @since 2.8.3
166
+ * @since 3.1.8 Added $process argument.
167
+ * @since 3.3.0 Moved to forms API.
168
+ *
169
+ * @global stdClass $wpmem
170
+ * @param string $process
171
+ */
172
+ function wpmem_wp_register_form( $process = 'register_wp' ) {
173
+ global $wpmem;
174
+ $wpmem->forms->wp_register_form( $process );
175
+ }
176
+
177
+ /**
178
+ * Add registration fields to WooCommerce registration.
179
+ *
180
+ * As of WooCommerce 3.0, the WC registration process no longer includes the
181
+ * WP register_form action hook. It only includes woocommerce_register_form.
182
+ * In previous versions, WP-Members hooked to register_form for both WP and
183
+ * WC registration. To provide backward compatibility with users who may
184
+ * continue to use updated WP-Members with pre-3.0 WooCommerce, this function
185
+ * checks for WC version and if it is older than 3.0 it will ignore adding
186
+ * the WP-Members form fields as they would have already been added when the
187
+ * register_form action hook fired.
188
+ *
189
+ * @since 3.1.8
190
+ * @since 3.3.0 Moved to forms API.
191
+ *
192
+ * @global stdClass $woocommerce
193
+ */
194
+ function wpmem_woo_register_form() {
195
+ if ( class_exists( 'WooCommerce' ) ) {
196
+ global $woocommerce;
197
+ if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
198
+ wpmem_wp_register_form( 'woo' );
199
+ }
200
+ }
201
+ }
202
+
203
+ /**
204
+ * Alias for $wpmem->create_form_field().
205
+ *
206
+ * @since 3.1.2
207
+ * @since 3.2.0 Accepts wpmem_create_formfield() arguments.
208
+ *
209
+ * @global object $wpmem The WP_Members object class.
210
+ * @param string|array $args {
211
+ * @type string $name (required) The field meta key.
212
+ * @type string $type (required) The field HTML type (url, email, image, file, checkbox, text, textarea, password, hidden, select, multiselect, multicheckbox, radio).
213
+ * @type string $value (optional) The field's value (can be a null value).
214
+ * @type string $compare (optional) Compare value.
215
+ * @type string $class (optional) Class identifier for the field.
216
+ * @type boolean $required (optional) If a value is required default: true).
217
+ * @type string $delimiter (optional) The field delimiter (pipe or comma, default: | ).
218
+ * @type string $placeholder (optional) Defines the placeholder attribute.
219
+ * @type string $pattern (optional) Adds a regex pattern to the field (HTML5).
220
+ * @type string $title (optional) Defines the title attribute.
221
+ * @type string $min (optional) Adds a min attribute (HTML5).
222
+ * @type string $max (optional) Adds a max attribute (HTML5).
223
+ * @type string $rows (optional) Adds rows attribute to textarea.
224
+ * @type string $cols (optional) Adds cols attribute to textarea.
225
+ * }
226
+ * @param string $type The field type.
227
+ * @param string $value The default value for the field.
228
+ * @param string $valtochk Optional for comparing the default value of the field.
229
+ * @param string $class Optional for setting a specific CSS class for the field.
230
+ * @return string The HTML of the form field.
231
+ */
232
+ //function wpmem_form_field( $args ) {
233
+ function wpmem_form_field( $name, $type=null, $value=null, $valtochk=null, $class='textbox' ) {
234
+ global $wpmem;
235
+ if ( is_array( $name ) ) {
236
+ $args = $name;
237
+ } else {
238
+ $args = array(
239
+ 'name' => $name,
240
+ 'type' => $type,
241
+ 'value' => $value,
242
+ 'compare' => $valtochk,
243
+ 'class' => $class,
244
+ );
245
+ }
246
+ return $wpmem->forms->create_form_field( $args );
247
+ }
248
+
249
+ /**
250
+ * Wrapper for $wpmem->create_form_label().
251
+ *
252
+ * @since 3.1.7
253
+ *
254
+ * @global object $wpmem
255
+ * @param array $args {
256
+ * @type string $meta_key
257
+ * @type string $label
258
+ * @type string $type
259
+ * @type string $id (optional)
260
+ * @type string $class (optional)
261
+ * @type string $required (optional)
262
+ * @type string $req_mark (optional)
263
+ * }
264
+ * @return string The HTML of the form label.
265
+ */
266
+ function wpmem_form_label( $args ) {
267
+ global $wpmem;
268
+ return $wpmem->forms->create_form_label( $args );
269
+ }
270
+
271
+ /**
272
+ * Wrapper to get form fields.
273
+ *
274
+ * @since 3.1.1
275
+ * @since 3.1.5 Checks if fields array is set or empty before returning.
276
+ * @since 3.1.7 Added wpmem_form_fields filter.
277
+ * @since 3.3.9 load_fields() moved to forms object class.
278
+ *
279
+ * @global object $wpmem The WP_Members object.
280
+ * @param string $tag The action being used (default: null).
281
+ * @param string $form The form being generated.
282
+ * @return array $fields The form fields.
283
+ */
284
+ function wpmem_fields( $tag = '', $form = 'default' ) {
285
+ global $wpmem;
286
+ // Load fields if none are loaded.
287
+ if ( ! isset( $wpmem->fields ) || empty( $wpmem->fields ) ) {
288
+ $wpmem->forms->load_fields( $form );
289
+ }
290
+
291
+ // @todo Review for removal.
292
+ $tag = $wpmem->convert_tag( $tag );
293
+
294
+ /**
295
+ * Filters the fields array.
296
+ *
297
+ * @since 3.1.7
298
+ * @since 3.3.2 Change object var and return.
299
+ *
300
+ * @param array $wpmem->fields
301
+ * @param string $tag (optional)
302
+ */
303
+ $wpmem->fields = apply_filters( 'wpmem_fields', $wpmem->fields, $tag );
304
+
305
+ return $wpmem->fields;
306
+ }
307
+
308
+ /**
309
+ * Sanitizes classes passed to the WP-Members form building functions.
310
+ *
311
+ * This generally uses just sanitize_html_class() but allows for
312
+ * whitespace so multiple classes can be passed (such as "regular-text code").
313
+ * This is an API wrapper for WP_Members_Forms::sanitize_class().
314
+ *
315
+ * @since 3.2.9
316
+ * @since 3.4.0 Now an alias for rktgk_sanitize_class().
317
+ *
318
+ * @global object $wpmem
319
+ *
320
+ * @param string $class
321
+ * @return string sanitized_class
322
+ */
323
+ function wpmem_sanitize_class( $class ) {
324
+ return rktgk_sanitize_class( $class );
325
+ }
326
+
327
+ /**
328
+ * Sanitizes the text in an array.
329
+ *
330
+ * This is an API wrapper for WP_Members_Forms::sanitize_array().
331
+ *
332
+ * @since 3.2.9
333
+ * @since 3.3.7 Added optional $type
334
+ * @since 3.4.0 Now an alias for rktgk_sanitize_array().
335
+ *
336
+ * @global object $wpmem
337
+ *
338
+ * @param array $data
339
+ * @param string $type The data type integer|int (default: false)
340
+ * @return array $data
341
+ */
342
+ function wpmem_sanitize_array( $data, $type = false ) {
343
+ return rktgk_sanitize_array( $data, $type );
344
+ }
345
+
346
+ /**
347
+ * A multi use sanitization function.
348
+ *
349
+ * @since 3.3.0
350
+ *
351
+ * @global object $wpmem
352
+ *
353
+ * @param string $data
354
+ * @param string $type (multiselect|multicheckbox|textarea|email|file|image|int|integer|number)
355
+ * @return string $sanitized_data
356
+ */
357
+ function wpmem_sanitize_field( $data, $type = 'text' ) {
358
+ return rktgk_sanitize_field( $data, $type );
359
+ }
360
+
361
+ /**
362
+ * Generate a form nonce.
363
+ *
364
+ * @since 3.3.0
365
+ *
366
+ * @param string $nonce
367
+ * @param boolean $echo
368
+ * @return string The nonce.
369
+ */
370
+ function wpmem_form_nonce( $nonce, $echo = false ) {
371
+ $form = ( 'update' == $nonce || 'register' == $nonce ) ? 'longform' : 'shortform';
372
+ return wp_nonce_field( 'wpmem_' . $form . '_nonce', '_wpmem_' . $nonce . '_nonce', true, $echo );
373
+ }
374
+
375
+ // @todo Experimental
376
+ /**
377
+ * Create WP-Members fields set for woo checkout.
378
+ *
379
+ * @since 3.3.4
380
+ *
381
+ * @param array $checkout_fields
382
+ */
383
+ function wpmem_woo_checkout_fields( $checkout_fields = false ) {
384
+ $woo_checkout = array(
385
+ 'billing_first_name',
386
+ 'billing_last_name',
387
+ 'billing_company',
388
+ 'billing_country',
389
+ 'billing_address_1',
390
+ 'billing_address_2',
391
+ 'billing_city',
392
+ 'billing_state',
393
+ 'billing_postcode',
394
+ 'billing_phone',
395
+ 'billing_email',
396
+ 'account_username',
397
+ 'account_password',
398
+ );
399
+ $fields = wpmem_fields();
400
+
401
+ if ( ! $checkout_fields ) {
402
+ $checkout_fields = WC()->checkout()->checkout_fields;
403
+ }
404
+
405
+ foreach ( $fields as $meta_key => $field ) {
406
+
407
+ if ( 1 != $fields[ $meta_key ]['register'] ) {
408
+ unset( $fields[ $meta_key ] );
409
+ } else {
410
+ if ( isset( $checkout_fields['billing'][ $meta_key ] ) ) {
411
+ unset( $fields[ $meta_key ] );
412
+ }
413
+ if ( isset( $checkout_fields['shipping'][ $meta_key ] ) ) {
414
+ unset( $fields[ $meta_key ] );
415
+ }
416
+ if ( isset( $checkout_fields['account'][ $meta_key ] ) ) {
417
+ unset( $fields[ $meta_key ] );
418
+ }
419
+ if ( isset( $checkout_fields['order'][ $meta_key ] ) ) {
420
+ unset( $fields[ $meta_key ] );
421
+ }
422
+ }
423
+
424
+ // @todo For now, remove any unsupported field types.
425
+ if ( 'hidden' == $field['type'] || 'image' == $field['type'] || 'file' == $field['type'] || 'membership' == $field['type'] ) {
426
+ unset( $fields[ $meta_key ] );
427
+ }
428
+ }
429
+ unset( $fields['username'] );
430
+ unset( $fields['password'] );
431
+ unset( $fields['confirm_password'] );
432
+ unset( $fields['confirm_email'] );
433
+ unset( $fields['user_email'] );
434
+ unset( $fields['first_name'] );
435
+ unset( $fields['last_name'] );
436
+
437
+ return $fields;
438
+ }
439
+
440
+ /**
441
+ * Adds WP-Members custom fields to woo checkout.
442
+ *
443
+ * @since 3.3.4
444
+ *
445
+ * @param array $checkout_fields
446
+ */
447
+ function wpmem_woo_checkout_form( $checkout_fields ) {
448
+ global $wpmem;
449
+ $fields = wpmem_woo_checkout_fields( $checkout_fields );
450
+
451
+ /**
452
+ * Filters the initial WC priority of the WP-members added fields.
453
+ *
454
+ * @since 3.3.7
455
+ *
456
+ * @param int
457
+ */
458
+ $priority = apply_filters( 'wpmem_wc_checkout_field_priority_seed', 10 );
459
+
460
+ foreach ( $fields as $meta_key => $field ) {
461
+ $checkout_fields['order'][ $meta_key ] = array(
462
+ 'type' => $fields[ $meta_key ]['type'],
463
+ 'label' => ( 'tos' == $meta_key ) ? $wpmem->forms->get_tos_link( $field, 'woo' ) : $fields[ $meta_key ]['label'],
464
+ 'required' => $fields[ $meta_key ]['required'],
465
+ 'priority' => $priority,
466
+ );
467
+ if ( isset( $fields[ $meta_key ]['placeholder'] ) ) {
468
+ $checkout_fields['order'][ $meta_key ]['placeholder'] = $fields[ $meta_key ]['placeholder'];
469
+ }
470
+ $priority = $priority + 10;
471
+ }
472
+ return $checkout_fields;
473
+ }
474
+
475
+ /**
476
+ * Saves WP-Members custom fields for woo checkout.
477
+ *
478
+ * @since 3.3.4
479
+ *
480
+ * @param int $order_id
481
+ */
482
+ function wpmem_woo_checkout_update_meta( $order_id ) {
483
+
484
+ // Get user id from order.
485
+ $order = wc_get_order( $order_id );
486
+ $user_id = $order->get_user_id();
487
+
488
+ $checkout_fields = WC()->checkout()->checkout_fields;
489
+ $fields = wpmem_fields();
490
+ foreach ( $fields as $meta_key => $field ) {
491
+ if ( isset( $checkout_fields['order'][ $meta_key ] ) && isset( $_POST[ $meta_key ] ) ) {
492
+ switch ( $fields[ $meta_key ]['type'] ) {
493
+ case 'checkbox':
494
+ update_user_meta( $user_id, $meta_key, $field['checked_value'] );
495
+ break;
496
+ case 'textarea':
497
+ update_user_meta( $user_id, $meta_key, sanitize_textarea_field( $_POST[ $meta_key ] ) );
498
+ break;
499
+ case 'multicheckbox':
500
+ case 'multiselect':
501
+ update_user_meta( $user_id, $meta_key, wpmem_sanitize_array( $_POST[ $meta_key ] ) );
502
+ break;
503
+ case 'membership':
504
+ wpmem_set_user_product( wpmem_sanitize_array( $_POST[ $meta_key ] ), $user_id );
505
+ break;
506
+ default:
507
+ if ( 'user_url' == $meta_key ) {
508
+ wp_update_user( array( 'ID' => $user_id, 'user_url' => sanitize_text_field( $_POST[ $meta_key ] ) ) );
509
+ } else {
510
+ update_user_meta( $user_id, $meta_key, sanitize_text_field( $_POST[ $meta_key ] ) );
511
+ }
512
+ break;
513
+ }
514
+ }
515
+ }
516
+ }
517
+
518
+ function wpmem_form_field_wc_custom_field_types( $field, $key, $args, $value ) {
519
+
520
+ $wpmem_fields = wpmem_fields();
521
+ /**
522
+ * @type string $name (required) The field meta key.
523
+ * @type string $type (required) The field HTML type (url, email, image, file, checkbox, text, textarea, password, hidden, select, multiselect, multicheckbox, radio).
524
+ * @type string $value (optional) The field's value (can be a null value).
525
+ * @type string $compare (optional) Compare value.
526
+ * @type string $class (optional) Class identifier for the field.
527
+ * @type boolean $required (optional) If a value is required default: true).
528
+ * @type string $delimiter (optional) The field delimiter (pipe or comma, default: | ).
529
+ * @type string $placeholder (optional) Defines the placeholder attribute.
530
+ * @type string $pattern (optional) Adds a regex pattern to the field (HTML5).
531
+ * @type string $title (optional) Defines the title attribute.
532
+ * @type string $min (optional) Adds a min attribute (HTML5).
533
+ * @type string $max (optional) Adds a max attribute (HTML5).
534
+ * @type string $rows (optional) Adds rows attribute to textarea.
535
+ * @type string $cols (optional) Adds cols attribute to textarea.
536
+ */
537
+
538
+ // Let's only mess with WP-Members fields (in case another checkout fields plugin is used).
539
+ if ( array_key_exists( $key, $wpmem_fields ) ) {
540
+
541
+ // If it is a checkbox.
542
+ if ( 'checkbox' == $wpmem_fields[ $key ]['type'] ) {
543
+
544
+ if ( ! $_POST && $wpmem_fields[ $key ]['checked_default'] ) {
545
+ $field = str_replace( '<input type="checkbox"', '<input type="checkbox" checked ', $field );
546
+ }
547
+
548
+ } else {
549
+
550
+ $field_args = array(
551
+ 'name' => $key,
552
+ 'type' => $wpmem_fields[ $key ]['type'],
553
+ 'required' => $wpmem_fields[ $key ]['required'],
554
+ 'delimiter' => $wpmem_fields[ $key ]['delimiter'],
555
+ 'value' => $wpmem_fields[ $key ]['values'],
556
+ );
557
+
558
+ $field_html = wpmem_form_field( $field_args );
559
+ $field_html = str_replace( 'class="' . $wpmem_fields[ $key ]['type'] . '"', 'class="' . $wpmem_fields[ $key ]['type'] . '" style="display:initial;"', $field_html );
560
+ $field = '<p class="form-row ' . implode( ' ', $args['class'] ) .'" id="' . $key . '_field">
561
+ <label for="' . $key . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label'] . ( ( 1 == $wpmem_fields[ $key ]['required'] ) ? '&nbsp;<abbr class="required" title="required">*</abbr>' : '' ) . '</label>';
562
+ $field .= $field_html;
563
+ $field .= '</p>';
564
+ }
565
+
566
+ }
567
+
568
+ return $field;
569
+ }
570
+
571
+ function wpmem_woo_reg_validate( $username, $email, $errors ) {
572
+
573
+ $fields = wpmem_woo_checkout_fields();
574
+
575
+ unset( $fields['username'] );
576
+ unset( $fields['password'] );
577
+ unset( $fields['confirm_password'] );
578
+ unset( $fields['user_email'] );
579
+ unset( $fields['first_name'] );
580
+ unset( $fields['last_name'] );
581
+
582
+ foreach ( $fields as $key => $field_args ) {
583
+ if ( 1 == $field_args['required'] && empty( $_POST[ $key ] ) ) {
584
+ $message = sprintf( __( '%s is a required field.', 'wp-members' ), '<strong>' . $field_args['label'] . '</strong>' );
585
+ $errors->add( $key, $message );
586
+ }
587
+ }
588
+ return $errors;
589
+ }
590
+
591
+ function wpmem_is_reg_form_showing() {
592
+ global $wpmem;
593
+ return ( true === $wpmem->reg_form_showing ) ? true : false;
594
+ }
595
+
596
+ function wpmem_field_display_value( $field, $type, $value, $echo = false ) {
597
+ $fields = wpmem_fields();
598
+ /**
599
+ * Filter the value.
600
+ *
601
+ * @since 3.4.0
602
+ *
603
+ * @param string $display_value
604
+ * @param string $field
605
+ * @param string $type
606
+ */
607
+ $display_value = apply_filters( 'wpmem_' . $type . '_field_display', $fields[ $field ]['options'][ $value ], $field, $type );
608
+ if ( $echo ) {
609
+ echo $display_value;
610
+ } else {
611
+ return $display_value;
612
+ }
613
+ }
614
+
615
+ function wpmem_checkbox_field_display( $field, $value, $echo = false ) {
616
+ wpmem_field_display_value( $field, 'checkbox', $value, $echo );
617
+ }
618
+
619
+ function wpmem_select_field_display( $field, $value, $echo = false ) {
620
+ wpmem_field_display_value( $field, 'select', $value, $echo );
621
+ }
622
+
623
+ function wpmem_get_user_meta_select( $user_id, $field ) {
624
+ $value = wpmem_get_user_meta( $user_id, $field );
625
+ return wpmem_select_field_display( $field, $value );
626
+ }
627
+
628
+ function wpmem_get_user_meta_radio( $user_id, $field ) {
629
+ return wpmem_get_user_meta_select( $user_id, $field );
630
+ }
631
+
632
+ function wpmem_get_user_meta_multi( $user_id, $field ) {
633
+
634
  }
includes/api/api-products.php CHANGED
@@ -1,42 +1,65 @@
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
- /**
17
- * Gets all posts by product key.
18
- *
19
- * @since Unknown
20
- *
21
- * @global stdClass $wpmem
22
- * @param string $product_key
23
- * @return array
24
- */
25
- function wpmem_get_product_post_list( $product_key ) {
26
- global $wpmem;
27
- return $wpmem->membership->get_all_posts( $product_key );
28
- }
29
-
30
- /**
31
- * Gets the membership products for a given post.
32
- *
33
- * @since 3.3.7
34
- *
35
- * @global stdClass $wpmem
36
- * @param integer $post_id
37
- * @return array
38
- */
39
- function wpmem_get_post_products( $post_id ) {
40
- global $wpmem;
41
- return $wpmem->membership->get_post_products( $post_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  }
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-2021 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-2021
14
+ */
15
+
16
+ /**
17
+ * Gets all posts by product key.
18
+ *
19
+ * @since Unknown
20
+ *
21
+ * @global stdClass $wpmem
22
+ * @param string $product_key
23
+ * @return array
24
+ */
25
+ function wpmem_get_product_post_list( $product_key ) {
26
+ global $wpmem;
27
+ return $wpmem->membership->get_all_posts( $product_key );
28
+ }
29
+
30
+ /**
31
+ * Gets the membership products for a given post.
32
+ *
33
+ * @since 3.3.7
34
+ *
35
+ * @global stdClass $wpmem
36
+ * @param integer $post_id
37
+ * @return array
38
+ */
39
+ function wpmem_get_post_products( $post_id ) {
40
+ global $wpmem;
41
+ return $wpmem->membership->get_post_products( $post_id );
42
+ }
43
+
44
+ /**
45
+ * Gets access message if user does not have required membership.
46
+ *
47
+ * @since 3.4.0
48
+ *
49
+ * @global stdClass $wpmem
50
+ * @param array $post_products
51
+ * @return string $message
52
+ */
53
+ function wpmem_get_access_message( $post_products ) {
54
+ global $wpmem;
55
+ return $wpmem->membership->get_access_message( $post_products );
56
+ }
57
+
58
+ function wpmem_get_products() {
59
+ return wpmem_get_memberships();
60
+ }
61
+
62
+ function wpmem_get_memberships() {
63
+ global $wpmem;
64
+ return ( ! empty( $wpmem->membership->products ) ) ? $wpmem->membership->products : false;
65
  }
includes/api/api-users.php CHANGED
@@ -1,943 +1,971 @@
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
- * @since 3.3.5 Added $notify argument.
420
- *
421
- * @param int $user_id
422
- * @param bool $notify Send notification to user (optional, default: true).
423
- */
424
- function wpmem_activate_user( $user_id, $notify = true ) {
425
-
426
- global $wpmem;
427
-
428
- // Define new_pass.
429
- $new_pass = '';
430
-
431
- // If passwords are user defined skip this.
432
- if ( ! wpmem_user_sets_password() ) {
433
- $new_pass = wp_generate_password();
434
- wp_set_password( $new_pass, $user_id );
435
- }
436
-
437
- // @todo this should be taken out, use the wpmem_user_activated hook instead.
438
- // If subscriptions can expire, and the user has no expiration date, set one.
439
- if ( $wpmem->use_exp == 1 && ! get_user_meta( $user_id, 'expires', true ) ) {
440
- if ( function_exists( 'wpmem_set_exp' ) ) {
441
- wpmem_set_exp( $user_id );
442
- }
443
- }
444
-
445
- // Generate and send user approved email to user.
446
- if ( true === $notify ) {
447
- wpmem_email_to_user( $user_id, $new_pass, 2 );
448
- }
449
-
450
- // Set the active flag in usermeta.
451
- update_user_meta( $user_id, 'active', 1 );
452
-
453
- /**
454
- * Fires after the user activation process is complete.
455
- *
456
- * @since 2.8.2
457
- *
458
- * @param int $user_id The user's ID.
459
- */
460
- do_action( 'wpmem_user_activated', $user_id );
461
-
462
- return;
463
- }
464
-
465
- /**
466
- * Deactivates a user.
467
- *
468
- * Reverses the active flag from the activation process
469
- * preventing login when registration is moderated.
470
- *
471
- * @since 2.7.1
472
- * @since 3.2.4 Renamed from wpmem_a_deactivate_user().
473
- * @since 3.3.0 Moved to user API.
474
- *
475
- * @param int $user_id
476
- */
477
- function wpmem_deactivate_user( $user_id ) {
478
- update_user_meta( $user_id, 'active', 0 );
479
-
480
- /**
481
- * Fires after the user deactivation process is complete.
482
- *
483
- * @since 2.9.9
484
- *
485
- * @param int $user_id The user's ID.
486
- */
487
- do_action( 'wpmem_user_deactivated', $user_id );
488
- }
489
-
490
- /**
491
- * Updates the user_status value in the wp_users table.
492
- *
493
- * @since Unknown
494
- * @since 3.3.0 Moved to User API.
495
- *
496
- * @global object $wpdb
497
- *
498
- * @param int $user_id
499
- * @param string $status
500
- */
501
- function wpmem_set_user_status( $user_id, $status ) {
502
- global $wpdb;
503
- $wpdb->update( $wpdb->users, array( 'user_status' => $status ), array( 'ID' => $user_id ) );
504
- return;
505
- }
506
-
507
- /**
508
- * Register function.
509
- *
510
- * Handles registering new users and updating existing users.
511
- *
512
- * @since 2.2.1
513
- * @since 2.7.2 Added pre/post process actions.
514
- * @since 2.8.2 Added validation and data filters.
515
- * @since 2.9.3 Added validation for multisite.
516
- * @since 3.0.0 Moved from wp-members-register.php to /inc/register.php.
517
- * @since 3.3.0 Ported from wpmem_registration in /inc/register.php (now deprecated).
518
- *
519
- * @todo Review what should be in the API function and what should be moved to object classes.
520
- *
521
- * @global int $user_ID
522
- * @global object $wpmem
523
- * @global string $wpmem_themsg
524
- * @global array $userdata
525
- *
526
- * @param string $tag Identifies 'register' or 'update'.
527
- * @return string $wpmem_themsg|success|editsuccess
528
- */
529
- function wpmem_user_register( $tag ) {
530
-
531
- // Get the globals.
532
- global $user_ID, $wpmem, $wpmem_themsg, $userdata;
533
-
534
- $wpmem->user->register_validate( $tag );
535
-
536
- // @todo Added as a fix for legacy versions of security extension and any wpmem_pre_register_data action that might null $wpmem_themsg.
537
- if ( $wpmem_themsg ) {
538
- return $wpmem_themsg;
539
- }
540
-
541
- switch ( $tag ) {
542
-
543
- case "register":
544
-
545
- /**
546
- * Filter registration data after validation before data insertion.
547
- *
548
- * @since 2.8.2
549
- *
550
- * @param array $wpmem->user->post_data An array of the registration field data.
551
- * @param string $tag A switch to indicate the action (new|edit).
552
- */
553
- $wpmem->user->post_data = apply_filters( 'wpmem_register_data', $wpmem->user->post_data, 'new' );
554
-
555
- /**
556
- * Fires before any insertion/emails.
557
- *
558
- * This action is the final step in pre registering a user. This
559
- * can be used for attaching custom validation to the registration
560
- * process. It cannot be used for changing any user registration
561
- * data. Use the wpmem_register_data filter for that.
562
- *
563
- * @since 2.7.2
564
- *
565
- * @param array $wpmem->user->post_data The user's submitted registration data.
566
- */
567
- do_action( 'wpmem_pre_register_data', $wpmem->user->post_data );
568
-
569
- // If the _pre_register_data hook sends back an error message.
570
- if ( $wpmem_themsg ) {
571
- return $wpmem_themsg;
572
- }
573
-
574
- // Main new user fields are ready.
575
- $new_user_fields = array (
576
- 'user_pass' => $wpmem->user->post_data['password'],
577
- 'user_login' => $wpmem->user->post_data['username'],
578
- 'user_nicename' => $wpmem->user->post_data['user_nicename'],
579
- 'user_email' => $wpmem->user->post_data['user_email'],
580
- 'display_name' => $wpmem->user->post_data['display_name'],
581
- 'nickname' => $wpmem->user->post_data['nickname'],
582
- 'user_registered' => $wpmem->user->post_data['user_registered'],
583
- 'role' => $wpmem->user->post_data['user_role']
584
- );
585
-
586
- // Get any excluded meta fields.
587
- $wpmem->excluded_meta = wpmem_get_excluded_meta( 'register' );
588
-
589
- // Fields for wp_insert_user: user_url, first_name, last_name, description, jabber, aim, yim.
590
- $new_user_fields_meta = array( 'user_url', 'first_name', 'last_name', 'description', 'jabber', 'aim', 'yim' );
591
- foreach ( $wpmem->fields as $meta_key => $field ) {
592
- if ( in_array( $meta_key, $new_user_fields_meta ) ) {
593
- if ( $field['register'] && ! in_array( $meta_key, $wpmem->excluded_meta ) ) {
594
- $new_user_fields[ $meta_key ] = $wpmem->user->post_data[ $meta_key ];
595
- }
596
- }
597
- }
598
-
599
- // Inserts to wp_users table.
600
- $user = wp_insert_user( $new_user_fields );
601
-
602
- /**
603
- * Fires after registration is complete.
604
- *
605
- * @since 2.7.1
606
- * @since 3.1.0 Added $fields
607
- * @since 3.1.7 Changed $fields to $this->post_data
608
- * @since 3.3.0 Moved to registration function.
609
- * @since 3.3.8 Added $user parameter.
610
- *
611
- * @param array $wpmem->user->post_data The user's submitted registration data.
612
- */
613
- do_action( 'wpmem_register_redirect', $wpmem->user->post_data, $user );
614
-
615
- // successful registration message
616
- return "success";
617
- break;
618
-
619
- case "update":
620
-
621
- if ( $wpmem_themsg ) {
622
- return "updaterr";
623
- exit();
624
- }
625
-
626
- /*
627
- * Doing a check for existing email is not the same as a new reg. check first to
628
- * see if it's different, then check if it is a valid address and it exists.
629
- */
630
- global $current_user; wp_get_current_user();
631
- if ( isset( $wpmem->user->post_data['user_email'] ) ) {
632
- if ( $wpmem->user->post_data['user_email'] != $current_user->user_email ) {
633
- if ( email_exists( $wpmem->user->post_data['user_email'] ) ) {
634
- return "email";
635
- exit();
636
- }
637
- if ( in_array( 'user_email', $wpmem->fields ) && ! is_email( $wpmem->user->post_data['user_email']) ) {
638
- $wpmem_themsg = $wpmem->get_text( 'reg_valid_email' );
639
- return "updaterr";
640
- exit();
641
- }
642
- }
643
- }
644
-
645
- // If form includes email confirmation, validate that they match.
646
- if ( array_key_exists( 'confirm_email', $wpmem->user->post_data ) && $wpmem->user->post_data['confirm_email'] != $wpmem->user->post_data ['user_email'] ) {
647
- $wpmem_themsg = $wpmem->get_text( 'reg_email_match' );
648
- return "updaterr";
649
- exit();
650
- }
651
-
652
- // Add the user_ID to the fields array.
653
- $wpmem->user->post_data['ID'] = $user_ID;
654
-
655
- /** This filter is documented in register.php */
656
- $wpmem->user->post_data = apply_filters( 'wpmem_register_data', $wpmem->user->post_data, 'edit' );
657
-
658
- /**
659
- * Fires before data insertion.
660
- *
661
- * This action is the final step in pre updating a user. This
662
- * can be used for attaching custom validation to the update
663
- * process. It cannot be used for changing any user update
664
- * data. Use the wpmem_register_data filter for that.
665
- *
666
- * @since 2.7.2
667
- *
668
- * @param array $wpmem->user->post_data The user's submitted update data.
669
- */
670
- do_action( 'wpmem_pre_update_data', $wpmem->user->post_data );
671
-
672
- // If the _pre_update_data hook sends back an error message.
673
- if ( $wpmem_themsg ){
674
- return "updaterr";
675
- }
676
-
677
- // A list of fields that can be updated by wp_update_user.
678
- $native_fields = array(
679
- 'user_nicename',
680
- 'user_url',
681
- 'user_email',
682
- 'display_name',
683
- 'nickname',
684
- 'first_name',
685
- 'last_name',
686
- 'description',
687
- 'role',
688
- 'jabber',
689
- 'aim',
690
- 'yim'
691
- );
692
- $native_update = array( 'ID' => $wpmem->user->post_data['ID'] );
693
-
694
- foreach ( $wpmem->fields as $meta_key => $field ) {
695
- // If the field is not excluded, update accordingly.
696
- if ( ! in_array( $meta_key, wpmem_get_excluded_meta( 'update' ) ) ) {
697
- if ( 'file' != $field['type'] && 'image' != $field['type'] ) {
698
- switch ( $meta_key ) {
699
-
700
- // If the field can be updated by wp_update_user.
701
- case( in_array( $meta_key, $native_fields ) ):
702
- $wpmem->user->post_data[ $meta_key ] = ( isset( $wpmem->user->post_data[ $meta_key ] ) ) ? $wpmem->user->post_data[ $meta_key ] : '';
703
- $native_update[ $meta_key ] = $wpmem->user->post_data[ $meta_key ];
704
- break;
705
-
706
- // If the field is password.
707
- case( 'password' ):
708
- // Do nothing.
709
- break;
710
-
711
- // Everything else goes into wp_usermeta.
712
- default:
713
- if ( ( 'register' == $tag && true == $field['register'] ) || ( 'update' == $tag && true == $field['profile'] ) ) {
714
- update_user_meta( $wpmem->user->post_data['ID'], $meta_key, $wpmem->user->post_data[ $meta_key ] );
715
- }
716
- break;
717
- }
718
- }
719
- }
720
- }
721
-
722
- // Handle file uploads, if any.
723
- if ( ! empty( $_FILES ) ) {
724
- $wpmem->user->upload_user_files( $wpmem->user->post_data['ID'], $wpmem->fields );
725
- }
726
-
727
- // Update wp_update_user fields.
728
- wp_update_user( $native_update );
729
-
730
- /**
731
- * Fires at the end of user update data insertion.
732
- *
733
- * @since 2.7.2
734
- *
735
- * @param array $wpmem->user->post_data The user's submitted registration data.
736
- */
737
- do_action( 'wpmem_post_update_data', $wpmem->user->post_data );
738
-
739
- return "editsuccess"; exit();
740
- break;
741
- }
742
- } // End registration function.
743
-
744
- /**
745
- * Get user IP address.
746
- *
747
- * From Pippin.
748
- * @link https://gist.github.com/pippinsplugins/9641841
749
- *
750
- * @since 3.3.0
751
- *
752
- * @return string $ip.
753
- */
754
- function wpmem_get_user_ip() {
755
- if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
756
- //check ip from share internet
757
- $ip = $_SERVER['HTTP_CLIENT_IP'];
758
- } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
759
- //to check ip is pass from proxy
760
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
761
- } else {
762
- $ip = $_SERVER['REMOTE_ADDR'];
763
- }
764
- /**
765
- * Filter the IP result.
766
- *
767
- * @since 3.3.0
768
- *
769
- * @param string $ip
770
- */
771
- return apply_filters( 'wpmem_get_ip', $ip );
772
- }
773
-
774
- /**
775
- * Export all or selected users
776
- *
777
- * @since 2.9.7
778
- * @since 3.2.0 Updated to use fputcsv.
779
- * @since 3.2.1 Added user data filters.
780
- * @since 3.3.0 Call object class static method.
781
- * @since 3.3.4 Moved into general API.
782
- *
783
- * @todo Move object class file to main /includes/
784
- *
785
- * @global object $wpmem
786
- *
787
- * @param array $args
788
- * @param array $users
789
- */
790
- function wpmem_export_users( $args, $users = array() ) {
791
- global $wpmem;
792
- include_once( $wpmem->path . 'includes/admin/class-wp-members-export.php' );
793
- WP_Members_Export::export_users( $args, $users );
794
- }
795
-
796
- /**
797
- * Gets user ID based on request.
798
- *
799
- * @since 3.3.5
800
- *
801
- * @param mixed $user
802
- * @return mixed
803
- */
804
- function wpmem_get_user_id( $user ) {
805
- $user_obj = wpmem_get_user_obj( $user );
806
- return ( is_object( $user_obj ) ) ? $user_obj->ID : false;
807
- }
808
-
809
- /**
810
- * Gets user object based on request.
811
- *
812
- * @since 3.3.5
813
- *
814
- * @param mixed $user
815
- * @return mixed
816
- */
817
- function wpmem_get_user_obj( $user ) {
818
- if ( is_numeric( $user ) ) {
819
- $user_obj = get_userdata( $user );
820
- if ( $user_obj ) {
821
- return $user_obj;
822
- }
823
- }
824
- if ( strpos( $user, '@' ) ) {
825
- $user_obj = get_user_by( 'email', $user );
826
- if ( $user_obj ) {
827
- return $user_obj;
828
- }
829
- }
830
- if ( is_string( $user ) ) {
831
- $user_obj = get_user_by( 'login', $user );
832
- if ( $user_obj ) {
833
- return $user_obj;
834
- }
835
- }
836
- return false;
837
- }
838
-
839
- /**
840
- * Get all users by a meta value.
841
- *
842
- * @since 3.3.5
843
- *
844
- * @param string $meta The meta key to search fo.
845
- * @param string $value The meta value to search for (defaul:false).
846
- * @return array $users An array of user IDs who have the requested meta.
847
- */
848
- function wpmem_get_users_by_meta( $meta, $value = "EXISTS" ) {
849
- $args = array( 'fields' => array( 'ID' ), 'meta_key' => $meta );
850
- if ( false === $value ) {
851
- $args['meta_value'] = '';
852
- $args['meta_compare'] = 'NOT EXISTS';
853
- } elseif ( "EXISTS" === $value ) {
854
- $args['meta_value'] = '';
855
- $args['meta_compare'] = '>';
856
- } else {
857
- $args['meta_value'] = $value;
858
- }
859
- $results = get_users( $args );
860
- if ( $results ) {
861
- foreach( $results as $result ) {
862
- $users[] = $result->ID;
863
- }
864
- return $users;
865
- } else {
866
- return array();
867
- }
868
- }
869
-
870
- /**
871
- * Gets a list of all pending users.
872
- *
873
- * @since 3.3.5
874
- *
875
- * @return array $users An array of user IDs where meta key "active" does not exist.
876
- */
877
- function wpmem_get_pending_users() {
878
- return wpmem_get_users_by_meta( 'active', false );
879
- }
880
-
881
- /**
882
- * Gets a list of all activated users.
883
- *
884
- * @since 3.3.5
885
- *
886
- * @return array $users An array of user IDs who have the meta key active=1
887
- */
888
- function wpmem_get_activated_users() {
889
- return wpmem_get_users_by_meta( 'active', 1 );
890
- }
891
-
892
- /**
893
- * Gets a list of all deactivated users.
894
- *
895
- * @since 3.3.5
896
- *
897
- * @return array $users An array of users IDs who have the meta key active=0
898
- */
899
- function wpmem_get_deactivated_users() {
900
- return wpmem_get_users_by_meta( 'active', 0 );
901
- }
902
-
903
- /**
904
- * Sets a user as validated.
905
- *
906
- * @since 3.3.5
907
- *
908
- * @param int $user_id
909
- * @return void
910
- */
911
- function wpmem_set_user_as_confirmed( $user_id ) {
912
- global $wpmem;
913
- $wpmem->act_newreg->set_as_confirmed( $user_id );
914
- }
915
-
916
- /**
917
- * Sets user as unconfirmed (not validated).
918
- *
919
- * @since 3.3.8
920
- *
921
- * @param int $user_id
922
- * @return void
923
- */
924
- function wpmem_set_user_as_unconfirmed( $user_id ) {
925
- global $wpmem;
926
- $wpmem->act_newreg->set_as_unconfirmed( $user_id );
927
- }
928
-
929
- /**
930
- * Checks if a user is confirmed.
931
- *
932
- * @since 3.3.8
933
- *
934
- * @global object $wpmem
935
- * @param int $user_id
936
- * @return bool
937
- */
938
- function wpmem_is_user_confirmed( $user_id = false ) {
939
- global $wpmem;
940
- $user_id = ( false === $user_id ) ? get_current_user_id() : $user_id;
941
- return ( get_user_meta( $user_id, $wpmem->act_newreg->validation_confirm, true ) ) ? true : false;
942
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
943
  // 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-2021 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-2021
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
+ * @param boolean $all If true, all roles as an array; if false, just the current role.
41
+ * @return mixed If the user is set and has roles, the current user role, otherwise false.
42
+ */
43
+ function wpmem_get_user_role( $user_id = false, $all = false ) {
44
+ $user = ( $user_id ) ? get_userdata( $user_id ) : wp_get_current_user();
45
+ $role = ( ! $all ) ? current( $user->roles ) : $user->roles;
46
+ return ( $user ) ? $role : false;
47
+ }
48
+
49
+ /**
50
+ * Checks if user has a particular role.
51
+ *
52
+ * Utility function to check if a given user has a specific role. Users can
53
+ * have multiple roles assigned, so it checks the role array rather than using
54
+ * the incorrect method of current_user_can( 'role_name' ). The function can
55
+ * check the role of the current user (default) or a specific user (if $user_id
56
+ * is passed).
57
+ *
58
+ * @since 3.1.1
59
+ * @since 3.1.6 Include accepting an array of roles to check.
60
+ * @since 3.1.9 Return false if user is not logged in.
61
+ * @since 3.2.0 Change return false to not logged in AND no user id.
62
+ *
63
+ * @global object $current_user Current user object.
64
+ * @global object $wpmem WP_Members object.
65
+ * @param string|array $role Slug or array of slugs of the role being checked.
66
+ * @param int $user_id ID of the user being checked (optional).
67
+ * @return boolean $has_role True if user has the role, otherwise false.
68
+ */
69
+ function wpmem_user_has_role( $role, $user_id = false ) {
70
+ if ( ! is_user_logged_in() && ! $user_id ) {
71
+ return false;
72
+ }
73
+ global $current_user, $wpmem;
74
+ $has_role = false;
75
+ if ( $user_id ) {
76
+ $user = get_userdata( $user_id );
77
+ } else {
78
+ $user = ( isset( $current_user ) ) ? $current_user : wp_get_current_user();
79
+ }
80
+ if ( is_array( $role ) ) {
81
+ foreach ( $role as $r ) {
82
+ if ( in_array( $r, $user->roles ) ) {
83
+ return true;
84
+ }
85
+ }
86
+ } else {
87
+ return ( in_array( $role, $user->roles ) ) ? true : $has_role;
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Gets user meta.
93
+ *
94
+ * It may seem like WP already has this feature. And it does. But most user meta
95
+ * are single, and WP's get_user_meta() defaults to "false" for the $single
96
+ * argument. This function provides a shorthand that assumes a string value for
97
+ * the meta result and drops the $single argument.
98
+ *
99
+ * @since 3.3.0
100
+ *
101
+ * @param int $user_id
102
+ * @param string $meta_key
103
+ * @return string $result
104
+ */
105
+ function wpmem_get_user_meta( $user_id, $meta_key ) {
106
+ return get_user_meta( $user_id, $meta_key, true );
107
+ }
108
+
109
+ /**
110
+ * Checks if a user has a given meta value.
111
+ *
112
+ * @since 3.1.8
113
+ * @since 3.3.0 Added wpmem_user_has_meta filter.
114
+ * @since 3.3.0 Added array check for multi-value fields (multicheckbox and multiselect).
115
+ *
116
+ * @global object $wpmem WP_Members object.
117
+ *
118
+ * @param string $meta Meta key being checked.
119
+ * @param string $value Value the meta key should have (optional).
120
+ * @param int $user_id ID of the user being checked (optional).
121
+ * @return boolean $has_meta True if user has the meta value, otherwise false.
122
+ */
123
+ function wpmem_user_has_meta( $meta, $value = false, $user_id = false ) {
124
+
125
+ global $wpmem;
126
+
127
+ // Get the user ID.
128
+ $user_id = ( $user_id ) ? $user_id : get_current_user_id();
129
+
130
+ // Get field type.
131
+ $fields = wpmem_fields();
132
+ $multi = ( ( isset( $fields[ $meta ] ) ) && ( 'multicheckbox' == $fields[ $meta ]['type'] || 'multiselect' == $fields[ $meta ]['type'] ) ) ? true : false;
133
+
134
+ // Get meta.
135
+ $has_meta = false;
136
+ $user_value = get_user_meta( $user_id, $meta, true );
137
+
138
+ // Check meta.
139
+ if ( $value ) {
140
+ if ( $multi ) {
141
+ // Check array of values.
142
+ $user_value = explode( $fields[ $meta ]['delimiter'], $user_value );
143
+ $has_meta = ( in_array( $value, $user_value ) ) ? true : $has_meta;
144
+ } else {
145
+ // Straight comparison.
146
+ $has_meta = ( $user_value == $value ) ? true : $has_meta;
147
+ }
148
+ } else {
149
+ // Check if the user has any meta value (regardless of actual value).
150
+ $has_meta = ( $user_value ) ? true : $has_meta;
151
+ }
152
+
153
+ /**
154
+ * Filter the user has meta result.
155
+ *
156
+ * @since 3.3.0
157
+ *
158
+ * @param bool $has_meta True if the user has the value, otherwise false.
159
+ * @param int $user_id The user ID being checked.
160
+ * @param string $user_value The user's stored meta value (false if none).
161
+ */
162
+ return apply_filters( 'wpmem_user_has_meta', $has_meta, $user_id, $user_value );
163
+ }
164
+
165
+ /**
166
+ * Checks if a user is activated.
167
+ *
168
+ * @since 3.1.7
169
+ * @since 3.2.3 Now an alias for WP_Members_Users::is_user_activated().
170
+ *
171
+ * @global object $wpmem
172
+ * @param int $user_id
173
+ * @return bool
174
+ */
175
+ function wpmem_is_user_activated( $user_id = false ) {
176
+ global $wpmem;
177
+ return $wpmem->user->is_user_activated( $user_id );
178
+ }
179
+
180
+ /**
181
+ * Gets an array of the user's registration data.
182
+ *
183
+ * Returns an array keyed by meta keys of the user's registration data for
184
+ * all fields in the WP-Members Fields. Returns the current user unless
185
+ * a user ID is specified.
186
+ *
187
+ * @since 3.2.0
188
+ *
189
+ * @global object $wpmem
190
+ * @param integer $user_id
191
+ * @param bool $all
192
+ * @return array $user_fields
193
+ */
194
+ function wpmem_user_data( $user_id = false, $all = false ) {
195
+ global $wpmem;
196
+ return $wpmem->user->user_data( $user_id, $all );
197
+ }
198
+
199
+ /**
200
+ * Updates a user's role.
201
+ *
202
+ * This is an alias for $wpmem->update_user_role(). It can add a role to a
203
+ * user, change or remove the user's role. If no action is specified it will
204
+ * change the role.
205
+ *
206
+ * @since 3.2.0
207
+ *
208
+ * @global object $wpmem
209
+ * @param integer $user_id (required)
210
+ * @param string $role (required)
211
+ * @param string $action (optional add|remove|set default:set)
212
+ */
213
+ function wpmem_update_user_role( $user_id, $role, $action = 'set' ) {
214
+ global $wpmem;
215
+ $wpmem->user->update_user_role( $user_id, $role, $action );
216
+ }
217
+
218
+ /**
219
+ * A function for checking user access criteria.
220
+ *
221
+ * @since 3.2.0
222
+ * @since 3.2.3 Reversed order of arguments.
223
+ *
224
+ * @param mixed $product Accepts a single membership slug/meta, or an array of multiple memberships.
225
+ * @param integer $user_id User ID (optional|default: false).
226
+ * @return boolean $access True if user has access, otherwise false.
227
+ */
228
+ function wpmem_user_has_access( $product, $user_id = false ) {
229
+ global $wpmem;
230
+ return $wpmem->user->has_access( $product, $user_id );
231
+ }
232
+
233
+ /**
234
+ * Checks if user expiration is current.
235
+ *
236
+ * Similar to wpmem_user_has_access(), but specifically checks the
237
+ * expiration date for a specified product (must be expiration product).
238
+ *
239
+ * @since 3.3.9
240
+ *
241
+ * @param mixed $product
242
+ * @param integer $user_id
243
+ * @return boolean
244
+ */
245
+ function wpmem_user_is_current( $product, $user_id = false ) {
246
+ global $wpmem;
247
+ // @todo Finish this.
248
+ return;
249
+ }
250
+
251
+ /**
252
+ * Sets product access for a user.
253
+ *
254
+ * @since 3.2.3
255
+ * @since 3.2.6 Added $date to set a specific expiration date.
256
+ *
257
+ * @global object $wpmem
258
+ * @param string $product The meta key of the product.
259
+ * @param int $user_id
260
+ * @param string $date Expiration date (optional) format: MySQL timestamp
261
+ * @return bool $result
262
+ */
263
+ function wpmem_set_user_product( $product, $user_id = false, $date = false ) {
264
+ global $wpmem;
265
+ return $wpmem->user->set_user_product( $product, $user_id, $date );
266
+ }
267
+
268
+ /**
269
+ * Removes product access for a user.
270
+ *
271
+ * @since 3.2.3
272
+ *
273
+ * @global object $wpmem
274
+ * @param string $product
275
+ * @param int $user_id
276
+ */
277
+ function wpmem_remove_user_product( $product, $user_id = false ) {
278
+ global $wpmem;
279
+ $wpmem->user->remove_user_product( $product, $user_id );
280
+ return;
281
+ }
282
+
283
+ /**
284
+ * Gets memberships a user has.
285
+ *
286
+ * @since 3.3.0
287
+ *
288
+ * @global stdClass $wpmem
289
+ * @param int $user_id
290
+ * @return array
291
+ */
292
+ function wpmem_get_user_products( $user_id = false ) {
293
+ global $wpmem;
294
+ return ( $user_id ) ? $wpmem->user->get_user_products( $user_id ) : $wpmem->user->access;
295
+ }
296
+
297
+ /**
298
+ * Sets a user as logged in.
299
+ *
300
+ * @since 3.2.3
301
+ *
302
+ * @global object $wpmem
303
+ * @param int $user_id
304
+ */
305
+ function wpmem_set_as_logged_in( $user_id ) {
306
+ global $wpmem;
307
+ $wpmem->user->set_as_logged_in( $user_id );
308
+ }
309
+
310
+ if ( ! function_exists( 'wpmem_login' ) ):
311
+ /**
312
+ * Logs in the user.
313
+ *
314
+ * Logs in the the user using wp_signon (since 2.5.2). If login is
315
+ * successful, it will set a cookie using wp_set_auth_cookie (since 2.7.7),
316
+ * then it redirects and exits; otherwise "loginfailed" is returned.
317
+ *
318
+ * @since 0.1.0
319
+ * @since 2.5.2 Now uses wp_signon().
320
+ * @since 2.7.7 Sets cookie using wp_set_auth_cookie().
321
+ * @since 3.0.0 Removed wp_set_auth_cookie(), this already happens in wp_signon().
322
+ * @since 3.1.7 Now an alias for login() in WP_Members_Users Class.
323
+ * @since 3.2.4 Moved to user API (could be deprecated).
324
+ *
325
+ * @global object $wpmem
326
+ * @return string Returns "loginfailed" if the login fails.
327
+ */
328
+ function wpmem_login() {
329
+ global $wpmem;
330
+ return $wpmem->user->login();
331
+ } // End of login function.
332
+ endif;
333
+
334
+ if ( ! function_exists( 'wpmem_logout' ) ):
335
+ /**
336
+ * Logs the user out then redirects.
337
+ *
338
+ * @since 2.0.0
339
+ * @since 3.1.6 Added wp_destroy_current_session(), removed nocache_headers().
340
+ * @since 3.1.7 Now an alias for logout() in WP_Members_Users Class.
341
+ * @since 3.2.4 Moved to user API (could be deprecated).
342
+ *
343
+ * @global object $wpmem
344
+ * @param string $redirect_to The URL to redirect to at logout.
345
+ */
346
+ function wpmem_logout( $redirect_to = false ) {
347
+ global $wpmem;
348
+ $wpmem->user->logout( $redirect_to );
349
+ }
350
+ endif;
351
+
352
+ if ( ! function_exists( 'wpmem_change_password' ) ):
353
+ /**
354
+ * Handles user password change (not reset).
355
+ *
356
+ * @since 2.1.0
357
+ * @since 3.1.7 Now an alias for password_update() in WP_Members_Users Class.
358
+ * @since 3.2.4 Moved to user API (could be deprecated).
359
+ *
360
+ * @global int $user_ID The WordPress user ID.
361
+ *
362
+ * @return string The value for $wpmem->regchk
363
+ */
364
+ function wpmem_change_password() {
365
+ global $wpmem;
366
+ return $wpmem->user->password_update( 'change' );
367
+ }
368
+ endif;
369
+
370
+ if ( ! function_exists( 'wpmem_reset_password' ) ):
371
+ /**
372
+ * Resets a forgotten password.
373
+ *
374
+ * @since 2.1.0
375
+ * @since 3.1.7 Now an alias for password_update() in WP_Members_Users Class.
376
+ * @since 3.2.4 Moved to user API (could be deprecated).
377
+ *
378
+ * @global object $wpmem The WP-Members object class.
379
+ *
380
+ * @return string The value for $wpmem->regchk
381
+ */
382
+ function wpmem_reset_password() {
383
+ global $wpmem;
384
+ return $wpmem->user->password_update( 'reset' );
385
+ }
386
+ endif;
387
+
388
+ /**
389
+ * Handles retrieving a forgotten username.
390
+ *
391
+ * @since 3.0.8
392
+ * @since 3.1.6 Dependencies now loaded by object.
393
+ * @since 3.1.8 Now an alias for $wpmem->retrieve_username() in WP_Members_Users Class.
394
+ * @since 3.2.4 Moved to user API (could be deprecated).
395
+ *
396
+ * @global object $wpmem The WP-Members object class.
397
+ *
398
+ * @return string $regchk The regchk value.
399
+ */
400
+ function wpmem_retrieve_username() {
401
+ global $wpmem;
402
+ return $wpmem->user->retrieve_username();
403
+ }
404
+
405
+ /**
406
+ * Creates a membership number.
407
+ *
408
+ * @since 3.1.1
409
+ * @since 3.2.0 Changed "lead" to "pad".
410
+ *
411
+ * @param array $args {
412
+ * @type string $option The wp_options name for the counter setting (required).
413
+ * @type string $meta_key The field's meta key (required).
414
+ * @type int $start Number to start with (optional, default 0).
415
+ * @type int $increment Number to increment by (optional, default 1).
416
+ * @type int $digits Number of digits for the number (optional).
417
+ * @type boolen $pad Pad leading zeros (optional, default true).
418
+ * }
419
+ * @return string $membersip_number
420
+ */
421
+ function wpmem_create_membership_number( $args ) {
422
+ global $wpmem;
423
+ return $wpmem->api->generate_membership_number( $args );
424
+ }
425
+
426
+ /**
427
+ * Activates a user.
428
+ *
429
+ * If registration is moderated, sets the activated flag
430
+ * in the usermeta. Flag prevents login when $wpmem->mod_reg
431
+ * is true (1). Function is fired from bulk user edit or
432
+ * user profile update.
433
+ *
434
+ * @uses $wpdb WordPress Database object.
435
+ *
436
+ * @since 2.4
437
+ * @since 3.1.6 Dependencies now loaded by object.
438
+ * @since 3.2.4 Renamed from wpmem_a_activate_user().
439
+ * @since 3.3.0 Moved to user API.
440
+ * @since 3.3.5 Added $notify argument.
441
+ * @since 3.4.0 Added $set_pwd argument.
442
+ *
443
+ * @param int $user_id
444
+ * @param bool $notify Send notification to user (optional, default: true).
445
+ */
446
+ function wpmem_activate_user( $user_id, $notify = true, $set_pwd = false ) {
447
+
448
+ global $wpmem;
449
+
450
+ // Define new_pass.
451
+ $new_pass = '';
452
+
453
+ // If passwords are user defined skip this.
454
+ if ( true == $set_pwd || ! wpmem_user_sets_password() ) {
455
+ $new_pass = wp_generate_password();
456
+ wp_set_password( $new_pass, $user_id );
457
+ }
458
+
459
+ // @todo this should be taken out, use the wpmem_user_activated hook instead.
460
+ // If subscriptions can expire, and the user has no expiration date, set one.
461
+ if ( $wpmem->use_exp == 1 && ! get_user_meta( $user_id, 'expires', true ) ) {
462
+ if ( function_exists( 'wpmem_set_exp' ) ) {
463
+ wpmem_set_exp( $user_id );
464
+ }
465
+ }
466
+
467
+ // Generate and send user approved email to user.
468
+ if ( true === $notify ) {
469
+ wpmem_email_to_user( $user_id, $new_pass, 2 );
470
+ }
471
+
472
+ // Set the active flag in usermeta.
473
+ update_user_meta( $user_id, 'active', 1 );
474
+
475
+ /**
476
+ * Fires after the user activation process is complete.
477
+ *
478
+ * @since 2.8.2
479
+ *
480
+ * @param int $user_id The user's ID.
481
+ */
482
+ do_action( 'wpmem_user_activated', $user_id );
483
+
484
+ return;
485
+ }
486
+
487
+ /**
488
+ * Deactivates a user.
489
+ *
490
+ * Reverses the active flag from the activation process
491
+ * preventing login when registration is moderated.
492
+ *
493
+ * @since 2.7.1
494
+ * @since 3.2.4 Renamed from wpmem_a_deactivate_user().
495
+ * @since 3.3.0 Moved to user API.
496
+ *
497
+ * @param int $user_id
498
+ */
499
+ function wpmem_deactivate_user( $user_id ) {
500
+ update_user_meta( $user_id, 'active', 0 );
501
+
502
+ /**
503
+ * Fires after the user deactivation process is complete.
504
+ *
505
+ * @since 2.9.9
506
+ *
507
+ * @param int $user_id The user's ID.
508
+ */
509
+ do_action( 'wpmem_user_deactivated', $user_id );
510
+ }
511
+
512
+ /**
513
+ * Updates the user_status value in the wp_users table.
514
+ *
515
+ * @since Unknown
516
+ * @since 3.3.0 Moved to User API.
517
+ *
518
+ * @global object $wpdb
519
+ *
520
+ * @param int $user_id
521
+ * @param string $status
522
+ */
523
+ function wpmem_set_user_status( $user_id, $status ) {
524
+ global $wpdb;
525
+ $wpdb->update( $wpdb->users, array( 'user_status' => $status ), array( 'ID' => $user_id ) );
526
+ return;
527
+ }
528
+
529
+ /**
530
+ * Register function.
531
+ *
532
+ * Handles registering new users and updating existing users.
533
+ *
534
+ * @since 2.2.1
535
+ * @since 2.7.2 Added pre/post process actions.
536
+ * @since 2.8.2 Added validation and data filters.
537
+ * @since 2.9.3 Added validation for multisite.
538
+ * @since 3.0.0 Moved from wp-members-register.php to /inc/register.php.
539
+ * @since 3.3.0 Ported from wpmem_registration in /inc/register.php (now deprecated).
540
+ *
541
+ * @todo Review what should be in the API function and what should be moved to object classes.
542
+ *
543
+ * @global int $user_ID
544
+ * @global object $wpmem
545
+ * @global string $wpmem_themsg
546
+ * @global array $userdata
547
+ *
548
+ * @param string $tag Identifies 'register' or 'update'.
549
+ * @return string $wpmem_themsg|success|editsuccess
550
+ */
551
+ function wpmem_user_register( $tag ) {
552
+
553
+ // Get the globals.
554
+ global $user_ID, $wpmem, $wpmem_themsg, $userdata;
555
+
556
+ $wpmem->user->register_validate( $tag );
557
+
558
+ // @todo Added as a fix for legacy versions of security extension and any wpmem_pre_register_data action that might null $wpmem_themsg.
559
+ if ( $wpmem_themsg ) {
560
+ return $wpmem_themsg;
561
+ }
562
+
563
+ switch ( $tag ) {
564
+
565
+ case "register":
566
+
567
+ /**
568
+ * Filter registration data after validation before data insertion.
569
+ *
570
+ * @since 2.8.2
571
+ *
572
+ * @param array $wpmem->user->post_data An array of the registration field data.
573
+ * @param string $tag A switch to indicate the action (new|edit).
574
+ */
575
+ $wpmem->user->post_data = apply_filters( 'wpmem_register_data', $wpmem->user->post_data, 'new' );
576
+
577
+ /**
578
+ * Fires before any insertion/emails.
579
+ *
580
+ * This action is the final step in pre registering a user. This
581
+ * can be used for attaching custom validation to the registration
582
+ * process. It cannot be used for changing any user registration
583
+ * data. Use the wpmem_register_data filter for that.
584
+ *
585
+ * @since 2.7.2
586
+ *
587
+ * @param array $wpmem->user->post_data The user's submitted registration data.
588
+ */
589
+ do_action( 'wpmem_pre_register_data', $wpmem->user->post_data );
590
+
591
+ // If the _pre_register_data hook sends back an error message.
592
+ if ( $wpmem_themsg ) {
593
+ return $wpmem_themsg;
594
+ }
595
+
596
+ // Main new user fields are ready.
597
+ $new_user_fields = array (
598
+ 'user_pass' => $wpmem->user->post_data['password'],
599
+ 'user_login' => $wpmem->user->post_data['username'],
600
+ 'user_nicename' => $wpmem->user->post_data['user_nicename'],
601
+ 'user_email' => $wpmem->user->post_data['user_email'],
602
+ 'display_name' => $wpmem->user->post_data['display_name'],
603
+ 'nickname' => $wpmem->user->post_data['nickname'],
604
+ 'user_registered' => $wpmem->user->post_data['user_registered'],
605
+ 'role' => $wpmem->user->post_data['user_role']
606
+ );
607
+
608
+ // Get any excluded meta fields.
609
+ $wpmem->excluded_meta = wpmem_get_excluded_meta( 'register' );
610
+
611
+ // Fields for wp_insert_user: user_url, first_name, last_name, description.
612
+ $new_user_fields_meta = array( 'user_url', 'first_name', 'last_name', 'description' );
613
+ foreach ( $wpmem->fields as $meta_key => $field ) {
614
+ if ( in_array( $meta_key, $new_user_fields_meta ) ) {
615
+ if ( $field['register'] && ! in_array( $meta_key, $wpmem->excluded_meta ) ) {
616
+ $new_user_fields[ $meta_key ] = $wpmem->user->post_data[ $meta_key ];
617
+ }
618
+ }
619
+ }
620
+
621
+ // Inserts to wp_users table.
622
+ $user = wp_insert_user( $new_user_fields );
623
+
624
+ /**
625
+ * Fires after registration is complete.
626
+ *
627
+ * @since 2.7.1
628
+ * @since 3.1.0 Added $fields
629
+ * @since 3.1.7 Changed $fields to $this->post_data
630
+ * @since 3.3.0 Moved to registration function.
631
+ * @since 3.3.8 Added $user parameter.
632
+ *
633
+ * @param array $wpmem->user->post_data The user's submitted registration data.
634
+ */
635
+ do_action( 'wpmem_register_redirect', $wpmem->user->post_data, $user );
636
+
637
+ // successful registration message
638
+ return "success";
639
+ break;
640
+
641
+ case "update":
642
+
643
+ if ( $wpmem_themsg ) {
644
+ return "updaterr";
645
+ exit();
646
+ }
647
+
648
+ /*
649
+ * Doing a check for existing email is not the same as a new reg. check first to
650
+ * see if it's different, then check if it is a valid address and it exists.
651
+ */
652
+ global $current_user; wp_get_current_user();
653
+ if ( isset( $wpmem->user->post_data['user_email'] ) ) {
654
+ if ( $wpmem->user->post_data['user_email'] != $current_user->user_email ) {
655
+ if ( email_exists( $wpmem->user->post_data['user_email'] ) ) {
656
+ return "email";
657
+ exit();
658
+ }
659
+ if ( in_array( 'user_email', $wpmem->fields ) && ! is_email( $wpmem->user->post_data['user_email']) ) {
660
+ $wpmem_themsg = wpmem_get_text( 'reg_valid_email' );
661
+ return "updaterr";
662
+ exit();
663
+ }
664
+ }
665
+ }
666
+
667
+ // If form includes email confirmation, validate that they match.
668
+ if ( array_key_exists( 'confirm_email', $wpmem->user->post_data ) && $wpmem->user->post_data['confirm_email'] != $wpmem->user->post_data ['user_email'] ) {
669
+ $wpmem_themsg = wpmem_get_text( 'reg_email_match' );
670
+ return "updaterr";
671
+ exit();
672
+ }
673
+
674
+ // Add the user_ID to the fields array.
675
+ $wpmem->user->post_data['ID'] = $user_ID;
676
+
677
+ /** This filter is documented in register.php */
678
+ $wpmem->user->post_data = apply_filters( 'wpmem_register_data', $wpmem->user->post_data, 'edit' );
679
+
680
+ /**
681
+ * Fires before data insertion.
682
+ *
683
+ * This action is the final step in pre updating a user. This
684
+ * can be used for attaching custom validation to the update
685
+ * process. It cannot be used for changing any user update
686
+ * data. Use the wpmem_register_data filter for that.
687
+ *
688
+ * @since 2.7.2
689
+ *
690
+ * @param array $wpmem->user->post_data The user's submitted update data.
691
+ */
692
+ do_action( 'wpmem_pre_update_data', $wpmem->user->post_data );
693
+
694
+ // If the _pre_update_data hook sends back an error message.
695
+ if ( $wpmem_themsg ){
696
+ return "updaterr";
697
+ }
698
+
699
+ // A list of fields that can be updated by wp_update_user.
700
+ $native_fields = array(
701
+ 'user_nicename',
702
+ 'user_url',
703
+ 'user_email',
704
+ 'display_name',
705
+ 'nickname',
706
+ 'first_name',
707
+ 'last_name',
708
+ 'description',
709
+ 'role',
710
+ );
711
+ $native_update = array( 'ID' => $wpmem->user->post_data['ID'] );
712
+
713
+ foreach ( $wpmem->fields as $meta_key => $field ) {
714
+ // If the field is not excluded, update accordingly.
715
+ if ( ! in_array( $meta_key, wpmem_get_excluded_meta( 'update' ) ) ) {
716
+ if ( 'file' != $field['type'] && 'image' != $field['type'] ) {
717
+ switch ( $meta_key ) {
718
+
719
+ // If the field can be updated by wp_update_user.
720
+ case( in_array( $meta_key, $native_fields ) ):
721
+ if ( 1 == $field['profile'] ) {
722
+ $wpmem->user->post_data[ $meta_key ] = ( isset( $wpmem->user->post_data[ $meta_key ] ) ) ? $wpmem->user->post_data[ $meta_key ] : '';
723
+ $native_update[ $meta_key ] = $wpmem->user->post_data[ $meta_key ];
724
+ }
725
+ break;
726
+
727
+ // If the field is password.
728
+ case( 'password' ):
729
+ // Do nothing.
730
+ break;
731
+
732
+ // Everything else goes into wp_usermeta.
733
+ default:
734
+ if ( ( 'register' == $tag && true == $field['register'] ) || ( 'update' == $tag && true == $field['profile'] ) ) {
735
+ update_user_meta( $wpmem->user->post_data['ID'], $meta_key, $wpmem->user->post_data[ $meta_key ] );
736
+ }
737
+ break;
738
+ }
739
+ }
740
+ }
741
+ }
742
+
743
+ // Handle file uploads, if any.
744
+ if ( ! empty( $_FILES ) ) {
745
+ $wpmem->user->upload_user_files( $wpmem->user->post_data['ID'], $wpmem->fields );
746
+ }
747
+
748
+ // Update wp_update_user fields.
749
+ wp_update_user( $native_update );
750
+
751
+ /**
752
+ * Fires at the end of user update data insertion.
753
+ *
754
+ * @since 2.7.2
755
+ *
756
+ * @param array $wpmem->user->post_data The user's submitted registration data.
757
+ */
758
+ do_action( 'wpmem_post_update_data', $wpmem->user->post_data );
759
+
760
+ return "editsuccess"; exit();
761
+ break;
762
+ }
763
+ } // End registration function.
764
+
765
+ /**
766
+ * Get user IP address.
767
+ *
768
+ * From Pippin.
769
+ * @link https://gist.github.com/pippinsplugins/9641841
770
+ *
771
+ * @since 3.3.0
772
+ * @since 3.4.0 Now an alias for rktgk_get_user_ip();
773
+ *
774
+ * @return string $ip.
775
+ */
776
+ function wpmem_get_user_ip() {
777
+ /**
778
+ * Filter the IP result.
779
+ *
780
+ * @since 3.3.0
781
+ *
782
+ * @param string $ip
783
+ */
784
+ return apply_filters( 'wpmem_get_ip', rktgk_get_user_ip( $ip ) );
785
+ }
786
+
787
+ /**
788
+ * Export all or selected users
789
+ *
790
+ * @since 2.9.7
791
+ * @since 3.2.0 Updated to use fputcsv.
792
+ * @since 3.2.1 Added user data filters.
793
+ * @since 3.3.0 Call object class static method.
794
+ * @since 3.3.4 Moved into general API.
795
+ *
796
+ * @todo Move object class file to main /includes/
797
+ *
798
+ * @global object $wpmem
799
+ *
800
+ * @param array $args
801
+ * @param array $users
802
+ */
803
+ function wpmem_export_users( $args = array(), $users = array() ) {
804
+ global $wpmem;
805
+ include_once( $wpmem->path . 'includes/admin/class-wp-members-user-export.php' );
806
+ WP_Members_User_Export::export_users( $args, $users );
807
+ }
808
+
809
+ /**
810
+ * Gets user ID based on request.
811
+ *
812
+ * @since 3.3.5
813
+ *
814
+ * @param mixed $user
815
+ * @return mixed
816
+ */
817
+ function wpmem_get_user_id( $user ) {
818
+ $user_obj = wpmem_get_user_obj( $user );
819
+ return ( is_object( $user_obj ) ) ? $user_obj->ID : false;
820
+ }
821
+
822
+ /**
823
+ * Gets user object based on request.
824
+ *
825
+ * @since 3.3.5
826
+ *
827
+ * @param mixed $user
828
+ * @return mixed
829
+ */
830
+ function wpmem_get_user_obj( $user ) {
831
+ if ( is_numeric( $user ) ) {
832
+ $user_obj = get_userdata( $user );
833
+ if ( $user_obj ) {
834
+ return $user_obj;
835
+ }
836
+ }
837
+ if ( strpos( $user, '@' ) ) {
838
+ $user_obj = get_user_by( 'email', $user );
839
+ if ( $user_obj ) {
840
+ return $user_obj;
841
+ }
842
+ }
843
+ if ( is_string( $user ) ) {
844
+ $user_obj = get_user_by( 'login', $user );
845
+ if ( $user_obj ) {
846
+ return $user_obj;
847
+ }
848
+ }
849
+ return false;
850
+ }
851
+
852
+ /**
853
+ * Get all users by a meta value.
854
+ *
855
+ * @since 3.3.5
856
+ *
857
+ * @param string $meta The meta key to search fo.
858
+ * @param string $value The meta value to search for (defaul:false).
859
+ * @return array $users An array of user IDs who have the requested meta.
860
+ */
861
+ function wpmem_get_users_by_meta( $meta, $value = "EXISTS" ) {
862
+ $args = array( 'fields' => array( 'ID' ), 'meta_key' => $meta );
863
+ if ( false === $value ) {
864
+ $args['meta_value'] = '';
865
+ $args['meta_compare'] = 'NOT EXISTS';
866
+ } elseif ( "EXISTS" === $value ) {
867
+ $args['meta_value'] = '';
868
+ $args['meta_compare'] = '>';
869
+ } else {
870
+ $args['meta_value'] = $value;
871
+ }
872
+ $results = get_users( $args );
873
+ if ( $results ) {
874
+ foreach( $results as $result ) {
875
+ $users[] = $result->ID;
876
+ }
877
+ return $users;
878
+ } else {
879
+ return array();
880
+ }
881
+ }
882
+
883
+ /**
884
+ * Gets a list of all pending users.
885
+ *
886
+ * @since 3.3.5
887
+ *
888
+ * @return array $users An array of user IDs where meta key "active" does not exist.
889
+ */
890
+ function wpmem_get_pending_users() {
891
+ return wpmem_get_users_by_meta( 'active', false );
892
+ }
893
+
894
+ /**
895
+ * Gets a list of all activated users.
896
+ *
897
+ * @since 3.3.5
898
+ *
899
+ * @return array $users An array of user IDs who have the meta key active=1
900
+ */
901
+ function wpmem_get_activated_users() {
902
+ return wpmem_get_users_by_meta( 'active', 1 );
903
+ }
904
+
905
+ /**
906
+ * Gets a list of all deactivated users.
907
+ *
908
+ * @since 3.3.5
909
+ *
910
+ * @return array $users An array of users IDs who have the meta key active=0
911
+ */
912
+ function wpmem_get_deactivated_users() {
913
+ return wpmem_get_users_by_meta( 'active', 0 );
914
+ }
915
+
916
+ /**
917
+ * Sets a user as validated.
918
+ *
919
+ * @since 3.3.5
920
+ *
921
+ * @param int $user_id
922
+ * @return void
923
+ */
924
+ function wpmem_set_user_as_confirmed( $user_id ) {
925
+ global $wpmem;
926
+ $wpmem->act_newreg->set_as_confirmed( $user_id );
927
+ }
928
+
929
+ /**
930
+ * Sets user as unconfirmed (not validated).
931
+ *
932
+ * @since 3.3.8
933
+ *
934
+ * @param int $user_id
935
+ * @return void
936
+ */
937
+ function wpmem_set_user_as_unconfirmed( $user_id ) {
938
+ global $wpmem;
939
+ $wpmem->act_newreg->set_as_unconfirmed( $user_id );
940
+ }
941
+
942
+ /**
943
+ * Checks if a user is confirmed.
944
+ *
945
+ * @since 3.3.8
946
+ *
947
+ * @global object $wpmem
948
+ * @param int $user_id
949
+ * @return bool
950
+ */
951
+ function wpmem_is_user_confirmed( $user_id = false ) {
952
+ global $wpmem;
953
+ $user_id = ( false === $user_id ) ? get_current_user_id() : $user_id;
954
+ return ( get_user_meta( $user_id, $wpmem->act_newreg->validation_confirm, true ) ) ? true : false;
955
+ }
956
+
957
+ /**
958
+ * Adds WP-Members custom fields to the WP Add New User form.
959
+ *
960
+ * @since 2.9.1
961
+ * @since 3.4.0 Moved from admin.php
962
+ *
963
+ * @global stdClass $wpmem
964
+ */
965
+ function wpmem_admin_add_new_user() {
966
+ global $wpmem;
967
+ // Output the custom registration fields.
968
+ echo $wpmem->forms->wp_newuser_form();
969
+ return;
970
+ }
971
  // End of file.
includes/api/api-utilities.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-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' ) ):
@@ -22,10 +22,10 @@ if ( ! function_exists( 'wpmem_securify' ) ):
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.
@@ -43,53 +43,40 @@ endif;
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
  /**
@@ -102,6 +89,7 @@ function wpmem_write_log ( $log ) {
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
@@ -116,27 +104,7 @@ function wpmem_write_log ( $log ) {
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' ) ):
@@ -144,7 +112,7 @@ if ( ! function_exists( 'wpmem_do_excerpt' ) ):
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
  *
@@ -165,7 +133,8 @@ if ( ! function_exists( 'wpmem_texturize' ) ):
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
  *
@@ -175,7 +144,8 @@ if ( ! function_exists( 'wpmem_texturize' ) ):
175
  */
176
  function wpmem_texturize( $content ) {
177
  global $wpmem;
178
- return $wpmem->texturize( $content );
 
179
  }
180
  endif;
181
 
@@ -184,6 +154,7 @@ endif;
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.
@@ -192,14 +163,7 @@ endif;
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
  /**
@@ -219,34 +183,22 @@ function wpmem_load_dropins() {
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
  /**
@@ -265,6 +217,7 @@ function wpmem_format_date( $args ) {
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.
@@ -273,14 +226,7 @@ function wpmem_format_date( $args ) {
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
  /**
@@ -312,41 +258,59 @@ function wpmem_user_sets_password() {
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
  }
342
 
343
  /**
344
  * Checks if WooCommerce is active.
345
  *
346
  * @since 3.3.7
 
347
  *
348
  * @return boolean
349
  */
350
  function wpmem_is_woo_active() {
351
- return ( class_exists( 'woocommerce' ) ) ? true : false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  }
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-2021 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-2021
17
  */
18
 
19
  if ( ! function_exists( 'wpmem_securify' ) ):
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 an alias for $wpmem->do_securify().
26
  *
27
  * @since 2.0.0
28
+ * @since 3.0.0 Now an alias 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.
43
  * Sets an array of user meta fields to be excluded from update/insert.
44
  *
45
  * @since 2.9.3
46
+ * @since Unknown Now an alias for get_excluded_fields().
47
+ * @since 3.3.9 excluded_fields() moved to forms object class.
48
  *
49
  * @param string $tag A tag so we know where the function is being used.
50
  * @return array Array of fields to be excluded from the registration form.
51
  */
52
  function wpmem_get_excluded_meta( $tag ) {
53
  global $wpmem;
54
+ return $wpmem->forms->excluded_fields( $tag );
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
56
 
57
  /**
58
  * Forces a URL to be secure (ssl).
59
  *
60
  * @since 3.2.3
61
+ * @since 3.4.0 Now an alias for rktgk_force_ssl()
62
  *
63
  * @param string $url URL to be make secure.
64
  * @return string The secure URL.
65
  */
66
  function wpmem_force_ssl( $url ) {
67
+ return rktgk_force_ssl( $url );
68
  }
69
 
70
  /**
71
  * Log debugging errors.
72
  *
73
  * @since 3.1.2
74
+ * @since 3.4.0 Now an alias for rktgk_write_log().
75
  *
76
  * @param mixed (string|array|object) $log Information to write in the WP debug file.
77
  */
78
+ function wpmem_write_log( $log ) {
79
+ rktgk_write_log( $log );
 
 
 
 
80
  }
81
 
82
  /**
89
  * the parts before, after, and the "needle" are returned.
90
  *
91
  * @since 3.2.0
92
+ * @since 3.4.0 Now an alias for rktgk_get_sub_str().
93
  *
94
  * @param string $needle
95
  * @param string $haystack
104
  * }
105
  */
106
  function wpmem_get_sub_str( $needle, $haystack, $position = 'after', $keep_needle = true ) {
107
+ return rktgk_get_sub_str( $needle, $haystack, $position, $keep_needle );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  }
109
 
110
  if ( ! function_exists( 'wpmem_do_excerpt' ) ):
112
  * Creates an excerpt on the fly if there is no 'more' tag.
113
  *
114
  * @since 2.6
115
+ * @since 3.2.3 Now an alias for WP_Members::do_excerpt().
116
  *
117
  * @global object $wpmem The WP_Members object.
118
  *
133
  * Currently only used for the login form to remove the <br> tag that WP puts in after the "Remember Me".
134
  *
135
  * @since 2.6.4
136
+ * @since 3.2.3 Now an alias for WP_Members::texturize().
137
+ * @deprecated 3.4.0. No replacement available.
138
  *
139
  * @todo Possibly deprecate or severely alter this process as its need may be obsolete.
140
  *
144
  */
145
  function wpmem_texturize( $content ) {
146
  global $wpmem;
147
+ //return $wpmem->texturize( $content );
148
+ return $content;
149
  }
150
  endif;
151
 
154
  *
155
  * @since 3.1.6
156
  * @since 3.2.3 Moved to utilities api.
157
+ * @since 3.4.0 Now an alias for rktgk_array_insert()
158
  *
159
  * @param array $array Original array.
160
  * @param array $new Array of new items to insert into $array.
163
  * @return array Original array with new items inserted.
164
  */
165
  function wpmem_array_insert( array $array, array $new, $key, $loc = 'after' ) {
166
+ return rktgk_array_insert( $array, $new, $key, $loc );
 
 
 
 
 
 
 
167
  }
168
 
169
  /**
183
  * Display a localized date based on the WP date format setting.
184
  *
185
  * @since 3.2.4
186
+ * @since 3.4.0 Now an alias for rktgk_format_date().
187
  *
188
  * @param mixed $args
189
  * @return date $date
190
  */
191
  function wpmem_format_date( $args ) {
 
 
 
 
 
 
 
 
 
 
 
 
192
  /**
193
  * Filter the date display and format settings.
194
  *
195
  * @since 3.2.4
196
+ * @deprecated 3.4.0 Use rktgk_format_date instead.
197
  *
198
  * @param arrag $args
199
  */
200
  $args = apply_filters( 'wpmem_format_date_args', $args );
201
+ return rktgk_format_date( $args );
 
 
202
  }
203
 
204
  /**
217
  * @link https://codesymphony.co/dont-do_shortcode/
218
  *
219
  * @since 3.2.5
220
+ * @since 3.4.0 Now an alias for rktgk_do_shortcode().
221
  *
222
  * @param string $tag The shortcode whose function to call.
223
  * @param array $atts The attributes to pass to the shortcode function. Optional.
226
  * @return string|bool False on failure, the result of the shortcode on success.
227
  */
228
  function wpmem_do_shortcode( $tag, array $atts = array(), $content = null ) {
229
+ return rktgk_do_shortcode( $tag, $atts, $content );
 
 
 
 
 
 
 
230
  }
231
 
232
  /**
258
  * sanitizes each individual array element.
259
  *
260
  * @since 3.3.0
261
+ * @since 3.4.0 Now an alias for rktgk_maybe_unserialize().
262
  *
263
  * @param mixed $original
264
  * @return mixed $original
265
  */
266
  function wpmem_maybe_unserialize( $original ) {
267
+ return rktgk_maybe_unserialize( $original );
 
 
 
268
  }
269
 
270
  /**
271
  * Determines whether to use a .min suffix for a script/style file.
272
  *
273
  * @since 3.3.0
274
+ * @since 3.4.0 Now an alias for rktgk_get_suffix().
275
  *
276
  * @param boolean $echo
277
  */
278
  function wpmem_get_suffix( $echo = false ) {
279
+ return rktgk_get_suffix( $echo );
 
 
 
 
 
 
280
  }
281
 
282
  /**
283
  * Checks if WooCommerce is active.
284
  *
285
  * @since 3.3.7
286
+ * @since 3.4.0 Now an alias for rktgk_is_woo_active().
287
  *
288
  * @return boolean
289
  */
290
  function wpmem_is_woo_active() {
291
+ return rktgk_is_woo_active();
292
+ }
293
+
294
+ /**
295
+ * A utility to determine a redirect_to param.
296
+ *
297
+ * @since 3.4.0
298
+ *
299
+ * @param array $args
300
+ * @return string $redirect_to
301
+ */
302
+ function wpmem_get_redirect_to( $args = array() ) {
303
+ // redirect_to in the form or URL will override a redirect set in the form args.
304
+ if ( isset( $_REQUEST['redirect_to'] ) ) {
305
+ $redirect_to = $_REQUEST['redirect_to'];
306
+ } else {
307
+ if ( isset( $args['redirect_to'] ) ) {
308
+ $raw_redirect_to = $args['redirect_to'];
309
+ // Is it a URL?
310
+ $redirect_to = ( false == filter_var( $raw_redirect_to, FILTER_VALIDATE_URL ) ) ? home_url( $raw_redirect_to ) : $raw_redirect_to;
311
+ } else {
312
+ $redirect_to = ( isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : get_permalink();
313
+ }
314
+ }
315
+ return $redirect_to;
316
  }
includes/api/api.php CHANGED
@@ -4,29 +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-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.
@@ -101,6 +85,7 @@ function wpmem_get_block_setting( $post_id ) {
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).
@@ -108,10 +93,12 @@ function wpmem_get_block_setting( $post_id ) {
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
  }
@@ -200,20 +187,19 @@ function wpmem_current_post_id() {
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
 
@@ -238,17 +224,58 @@ function wpmem_use_custom_dialog( $defaults, $tag, $dialogs ) {
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
  }
@@ -260,6 +287,7 @@ function wpmem_login_status( $echo = true ) {
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).
@@ -267,17 +295,7 @@ function wpmem_login_status( $echo = true ) {
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
  /**
@@ -326,19 +344,62 @@ function wpmem_loginout( $args = array(), $echo = false ) {
326
  return $wpmem->loginout_args( $args );
327
  }
328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
  /**
330
  * Dispalays requested dialog.
 
 
 
331
  *
332
  * @since 3.2.0
 
333
  *
334
- * @todo Needs testing and finalization before release.
 
 
 
 
 
335
  */
336
- function wpmem_display_message( $tag, $echo = true ) {
337
- if ( $echo ) {
338
- echo wpmem_inc_regmessage( $tag );
339
- } else {
340
- return wpmem_inc_regmessage( $tag );
341
- }
342
  }
343
 
344
  /**
@@ -415,4 +476,16 @@ function wpmem_is_reg_type( $type ) {
415
  return $wpmem->reg_type[ 'is_' . $type ];
416
  }
417
 
 
 
 
 
 
 
 
 
 
 
 
 
418
  // End of file.
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-2021 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-2021
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  */
15
 
16
  // Exit if accessed directly.
85
  *
86
  * @since 3.1.1
87
  * @since 3.1.2 Added redirect_to parameter.
88
+ * @since 3.4.0 If no login page is set, return the wp_login_url().
89
  *
90
  * @global object $wpmem The WP_Members object.
91
  * @param string $redirect_to URL to return to (optional).
93
  */
94
  function wpmem_login_url( $redirect_to = false ) {
95
  global $wpmem;
96
+ // If no login page is set, get WP login url.
97
+ $login_url = ( isset( $wpmem->user_pages['login'] ) ) ? $wpmem->user_pages['login'] : wp_login_url();
98
  if ( $redirect_to ) {
99
+ $url = add_query_arg( 'redirect_to', urlencode( $redirect_to ), $login_url );
100
  } else {
101
+ $url = $login_url;
102
  }
103
  return $url;
104
  }
187
  /**
188
  * Wrapper to return a string from the get_text function.
189
  *
190
+ * @since 3.4.0
 
191
  *
192
  * @global object $wpmem The WP_Members object.
193
  * @param string $str The string to retrieve.
194
  * @param bool $echo Print the string (default: false).
195
  * @return string $str The localized string.
196
  */
197
+ function wpmem_get_text( $str, $echo = false ) {
198
  global $wpmem;
199
  if ( $echo ) {
200
+ echo $wpmem->dialogs->get_text( $str );
201
  } else {
202
+ return $wpmem->dialogs->get_text( $str );
203
  }
204
  }
205
 
224
  * @since 2.0.0
225
  * @since 3.1.2 Moved to api.php, no longer pluggable.
226
  * @since 3.1.6 Dependencies now loaded by object.
227
+ * @since 3.4.0 Added $tag for id'ing useage, to be passed through filter.
228
  *
229
+ * @global string $user_login
230
+ * @param boolean $echo Determines whether function should print result or not (default: true).
231
+ * @return string $status The user status string produced by wpmem_inc_memberlinks().
232
  */
233
+ function wpmem_login_status( $echo = true, $tag = false ) {
234
+ if ( is_user_logged_in() ) {
235
+
236
+ global $user_login;
237
+
238
+ $args = array(
239
+ 'wrapper_before' => '<p>',
240
+ 'wrapper_after' => '</p>',
241
+ 'user_login' => $user_login,
242
+ 'welcome' => wpmem_gettext( 'status_welcome' ),
243
+ 'logout_text' => wpmem_gettext( 'status_logout' ),
244
+ 'logout_link' => '<a href="' . esc_url( wpmem_logout_link() ) . '">%s</a>',
245
+ 'separator' => ' | ',
246
+ );
247
+ /**
248
+ * Filter the status message parts.
249
+ *
250
+ * @since 2.9.9
251
+ * @since 3.4.0 Added $tag as a parameter (most often will be false).
252
+ *
253
+ * @param array $args {
254
+ * The components of the links.
255
+ *
256
+ * @type string $wrapper_before The wrapper opening tag (default: <p>).
257
+ * @type string $wrapper_after The wrapper closing tag (default: </p>).
258
+ * @type string $user_login
259
+ * @type string $welcome
260
+ * @type string $logout_text
261
+ * @type string $logout_link
262
+ * @type string $separator
263
+ * }
264
+ * @param string $tag
265
+ */
266
+ $args = apply_filters( 'wpmem_status_msg_args', $args, $tag );
267
 
268
+ // Assemble the message string.
269
+ $status = $args['wrapper_before']
270
+ . sprintf( $args['welcome'], $args['user_login'] )
271
+ . $args['separator']
272
+ . sprintf( $args['logout_link'], $args['logout_text'] )
273
+ . $args['wrapper_after'];
274
+ }
275
+
276
+ if ( $echo ) {
277
+ echo $status;
278
+ } else {
279
  return $status;
280
  }
281
  }
287
  * sanitized or escaped depending on how it is used.
288
  *
289
  * @since 3.1.3
290
+ * @since 3.4.0 Now an alias for rktgk_get().
291
  *
292
  * @param string $tag The form field or query string.
293
  * @param string $default The default value (optional).
295
  * @return string
296
  */
297
  function wpmem_get( $tag, $default = '', $type = 'post' ) {
298
+ return rktgk_get( $tag, $default, $type );
 
 
 
 
 
 
 
 
 
 
299
  }
300
 
301
  /**
344
  return $wpmem->loginout_args( $args );
345
  }
346
 
347
+ /**
348
+ * Gets a logout link.
349
+ *
350
+ * @since 3.4.0
351
+ *
352
+ * @return string Logout link.
353
+ */
354
+ function wpmem_logout_link() {
355
+ /**
356
+ * Filter the log out link.
357
+ *
358
+ * @since 2.8.3
359
+ *
360
+ * @param string The default logout link.
361
+ */
362
+ return apply_filters( 'wpmem_logout_link', add_query_arg( 'a', 'logout' ) );
363
+ }
364
+
365
+ /**
366
+ * Gets requested dialog.
367
+ *
368
+ * @since 3.4.0
369
+ *
370
+ * @note It is being relased now as tentative.
371
+ * There may be some changes to how this is applied.
372
+ *
373
+ * @todo What about wpmem_use_custom_dialog()?
374
+ *
375
+ * @global stdClass $wpmem
376
+ * @param string $tag
377
+ * @param string $custom
378
+ * @return
379
+ */
380
+ function wpmem_get_display_message( $tag, $custom = false ) {
381
+ global $wpmem;
382
+ return $wpmem->dialogs->get_message( $tag, $custom );
383
+ }
384
+
385
  /**
386
  * Dispalays requested dialog.
387
+ *
388
+ * @note It is being relased now as tentative.
389
+ * There may be some changes to how this is applied.
390
  *
391
  * @since 3.2.0
392
+ * @since 3.4.0 Now echos the message. Added $custom argument
393
  *
394
+ * @todo What about wpmem_use_custom_dialog()?
395
+ *
396
+ * @global stdClass $wpmem
397
+ * @param string $tag
398
+ * @param string $custom
399
+ * @return
400
  */
401
+ function wpmem_display_message( $tag, $custom = false ) {
402
+ echo wpmem_get_display_message( $tag, $custom );
 
 
 
 
403
  }
404
 
405
  /**
476
  return $wpmem->reg_type[ 'is_' . $type ];
477
  }
478
 
479
+ /**
480
+ * Displays the post restricted message.
481
+ *
482
+ * @since 3.4.0
483
+ *
484
+ * @return string
485
+ */
486
+ function wpmem_restricted_message() {
487
+ global $wpmem;
488
+ return $wpmem->forms->add_restricted_msg();
489
+ }
490
+
491
  // End of file.
includes/class-wp-members-captcha.php CHANGED
@@ -216,13 +216,13 @@ class WP_Members_Captcha {
216
  * @param array
217
  */
218
  $rows = apply_filters( 'wpmem_rs_captcha_rows', array(
219
- 'label_text' => $wpmem->get_text( 'register_rscaptcha' ),
220
  'code_size' => esc_attr( $size ),
221
  'prefix' => $pre,
222
  'img_src' => esc_url( $src ),
223
  'img_w' => esc_attr( $img_w ),
224
  'img_h' => esc_attr( $img_h ),
225
- 'label' => '<label class="text" for="captcha">' . $wpmem->get_text( 'register_rscaptcha' ) . '</label>',
226
  'field' => '<input id="captcha_code" name="captcha_code" size="' . esc_attr( $size ) . '" type="text" class="textbox" required />',
227
  'hidden' => '<input id="captcha_prefix" name="captcha_prefix" type="hidden" value="' . esc_attr( $pre ) . '" />',
228
  'img' => '<img src="' . esc_url( $src ) . '" alt="captcha" width="' . esc_attr( $img_w ) . '" height="' . esc_attr( $img_h ) . '" />',
@@ -290,7 +290,7 @@ class WP_Members_Captcha {
290
 
291
  // If there is no captcha value, return error.
292
  if ( false === $captcha ) {
293
- $wpmem_themsg = $wpmem->get_text( 'reg_empty_captcha' );
294
  return false;
295
  }
296
 
@@ -307,7 +307,7 @@ class WP_Members_Captcha {
307
  if ( $response->success ) {
308
  // your success code goes here
309
  } else {
310
- $wpmem_themsg = $wpmem->get_text( 'reg_invalid_captcha' );
311
  return false;
312
  }
313
 
@@ -328,7 +328,7 @@ class WP_Members_Captcha {
328
 
329
  // If there is no captcha value, return error.
330
  if ( false === $captcha ) {
331
- $wpmem_themsg = $wpmem->get_text( 'reg_empty_captcha' );
332
  return false;
333
  }
334
 
@@ -347,7 +347,7 @@ class WP_Members_Captcha {
347
 
348
  // If captcha validation was unsuccessful.
349
  if ( false == $response['success'] ) {
350
- $wpmem_themsg = $wpmem->get_text( 'reg_invalid_captcha' );
351
  if ( WP_DEBUG && isset( $response['error-codes'] ) ) {
352
  $wpmem_themsg.= '<br /><br />';
353
  foreach( $response['error-codes'] as $code ) {
@@ -360,7 +360,7 @@ class WP_Members_Captcha {
360
  $captcha = wpmem_get( 'recaptcha_response', false );
361
 
362
  if ( false === $captcha ) {
363
- $wpmem_themsg = $wpmem->get_text( 'reg_empty_captcha' );
364
  return false;
365
  }
366
 
@@ -374,11 +374,20 @@ class WP_Members_Captcha {
374
  $recaptcha = file_get_contents( $url );
375
  $recaptcha = json_decode( $recaptcha );
376
 
 
 
 
 
 
 
 
 
 
377
  // Take action based on the score returned:
378
- if ( $recaptcha->score >= 0.5 ) {
379
- // Verified - send email
380
  } else {
381
- $wpmem_themsg = $wpmem->get_text( 'reg_invalid_captcha' );
382
  return false;
383
  }
384
  } else {
216
  * @param array
217
  */
218
  $rows = apply_filters( 'wpmem_rs_captcha_rows', array(
219
+ 'label_text' => wpmem_get_text( 'register_rscaptcha' ),
220
  'code_size' => esc_attr( $size ),
221
  'prefix' => $pre,
222
  'img_src' => esc_url( $src ),
223
  'img_w' => esc_attr( $img_w ),
224
  'img_h' => esc_attr( $img_h ),
225
+ 'label' => '<label class="text" for="captcha">' . wpmem_get_text( 'register_rscaptcha' ) . '</label>',
226
  'field' => '<input id="captcha_code" name="captcha_code" size="' . esc_attr( $size ) . '" type="text" class="textbox" required />',
227
  'hidden' => '<input id="captcha_prefix" name="captcha_prefix" type="hidden" value="' . esc_attr( $pre ) . '" />',
228
  'img' => '<img src="' . esc_url( $src ) . '" alt="captcha" width="' . esc_attr( $img_w ) . '" height="' . esc_attr( $img_h ) . '" />',
290
 
291
  // If there is no captcha value, return error.
292
  if ( false === $captcha ) {
293
+ $wpmem_themsg = wpmem_get_text( 'reg_empty_captcha' );
294
  return false;
295
  }
296
 
307
  if ( $response->success ) {
308
  // your success code goes here
309
  } else {
310
+ $wpmem_themsg = wpmem_get_text( 'reg_invalid_captcha' );
311
  return false;
312
  }
313
 
328
 
329
  // If there is no captcha value, return error.
330
  if ( false === $captcha ) {
331
+ $wpmem_themsg = wpmem_get_text( 'reg_empty_captcha' );
332
  return false;
333
  }
334
 
347
 
348
  // If captcha validation was unsuccessful.
349
  if ( false == $response['success'] ) {
350
+ $wpmem_themsg = wpmem_get_text( 'reg_invalid_captcha' );
351
  if ( WP_DEBUG && isset( $response['error-codes'] ) ) {
352
  $wpmem_themsg.= '<br /><br />';
353
  foreach( $response['error-codes'] as $code ) {
360
  $captcha = wpmem_get( 'recaptcha_response', false );
361
 
362
  if ( false === $captcha ) {
363
+ $wpmem_themsg = wpmem_get_text( 'reg_empty_captcha' );
364
  return false;
365
  }
366
 
374
  $recaptcha = file_get_contents( $url );
375
  $recaptcha = json_decode( $recaptcha );
376
 
377
+ /**
378
+ * Filters the reCAPTCHA v3 score.
379
+ * @link https://developers.google.com/recaptcha/docs/v3
380
+ *
381
+ * @since 3.3.9
382
+ *
383
+ * @param int $score
384
+ */
385
+ $score = apply_filters( 'wpmem_recaptcha_score', 0.5 );
386
  // Take action based on the score returned:
387
+ if ( $recaptcha->score >= $score ) {
388
+ return true;
389
  } else {
390
+ $wpmem_themsg = wpmem_get_text( 'reg_invalid_captcha' );
391
  return false;
392
  }
393
  } else {
includes/class-wp-members-clone-menus.php CHANGED
@@ -6,6 +6,7 @@
6
  * @subpackage WP_Members Clone Menus Object Class
7
  * @since 3.2.0
8
  * @since 3.3.0 Renamed WP_Members_Clone_Menus
 
9
  */
10
 
11
  // Exit if accessed directly.
@@ -16,9 +17,8 @@ if ( ! defined( 'ABSPATH' ) ) {
16
  class WP_Members_Clone_Menus {
17
 
18
  function __construct() {
19
- add_action( 'init', array( $this, 'register_menus' ), 99 );
20
- add_filter( 'wp_nav_menu_args', array( $this, 'serve_menu' ) );
21
- add_filter( 'jetpack_mobile_theme_menu', array( $this, 'jetpack_mobile_theme_menu' ) );
22
  }
23
 
24
  /**
@@ -95,24 +95,4 @@ class WP_Members_Clone_Menus {
95
  return $args;
96
  }
97
 
98
- /**
99
- * Handles Jetpack mobile theme, if enabled.
100
- *
101
- * Jetpack mobile theme uses a custom mobile theme called Minileven. This theme uses
102
- * the default primary menu for the main menu. If this is enabled, the Logged-in
103
- * Menus extension uses the jetpack_mobile_theme_menu filter hook to apply the default
104
- * primary menu if the user is not logged in or the logged in primary menu if they are.
105
- *
106
- * @since 3.2.0
107
- */
108
- function jetpack_mobile_theme_menu() {
109
- // Get menus
110
- $menu_locs = get_nav_menu_locations();
111
- if ( is_user_logged_in() ) {
112
- return $menu_locs['primary_wpmem_loggedin'];
113
- } else {
114
- return $menu_locs['primary'];
115
- }
116
- }
117
-
118
  }
6
  * @subpackage WP_Members Clone Menus Object Class
7
  * @since 3.2.0
8
  * @since 3.3.0 Renamed WP_Members_Clone_Menus
9
+ * @deprecated 3.4.0 No longer supported.
10
  */
11
 
12
  // Exit if accessed directly.
17
  class WP_Members_Clone_Menus {
18
 
19
  function __construct() {
20
+ add_action( 'init', array( $this, 'register_menus' ), 99 );
21
+ add_filter( 'wp_nav_menu_args', array( $this, 'serve_menu' ) );
 
22
  }
23
 
24
  /**
95
  return $args;
96
  }
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  }
includes/class-wp-members-dialogs.php ADDED
@@ -0,0 +1,398 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The WP_Members_Dialogs Class.
4
+ *
5
+ * This class contains functions for handling dialongs and messaging..
6
+ *
7
+ * @package WP-Members
8
+ * @subpackage WP_Members_Dialogs Object Class
9
+ * @since 3.0.0
10
+ */
11
+
12
+ // Exit if accessed directly.
13
+ if ( ! defined( 'ABSPATH' ) ) {
14
+ exit();
15
+ }
16
+
17
+ class WP_Members_Dialogs {
18
+
19
+ function __construct() {
20
+
21
+ }
22
+
23
+ /**
24
+ * Returns a requested text string.
25
+ *
26
+ * This function manages all of the front-end facing text.
27
+ * All defaults can be filtered using wpmem_default_text_strings.
28
+ *
29
+ * @since 3.1.0
30
+ *
31
+ * @global object $wpmem
32
+ *
33
+ * @param string $str
34
+ * @return string $text
35
+ */
36
+ function get_text( $str ) {
37
+ global $wpmem;
38
+
39
+ // Default Form Fields.
40
+ $default_form_fields = array(
41
+ 'first_name' => __( 'First Name', 'wp-members' ),
42
+ 'last_name' => __( 'Last Name', 'wp-members' ),
43
+ 'addr1' => __( 'Address 1', 'wp-members' ),
44
+ 'addr2' => __( 'Address 2', 'wp-members' ),
45
+ 'city' => __( 'City', 'wp-members' ),
46
+ 'thestate' => __( 'State', 'wp-members' ),
47
+ 'zip' => __( 'Zip', 'wp-members' ),
48
+ 'country' => __( 'Country', 'wp-members' ),
49
+ 'phone1' => __( 'Day Phone', 'wp-members' ),
50
+ 'user_email' => __( 'Email', 'wp-members' ),
51
+ 'confirm_email' => __( 'Confirm Email', 'wp-members' ),
52
+ 'user_url' => __( 'Website', 'wp-members' ),
53
+ 'description' => __( 'Biographical Info', 'wp-members' ),
54
+ 'password' => __( 'Password', 'wp-members' ),
55
+ 'confirm_password' => __( 'Confirm Password', 'wp-members' ),
56
+ 'tos' => __( 'TOS', 'wp-members' ),
57
+ );
58
+
59
+ /*
60
+ * Strings to be added or removed in future versions, included so they will
61
+ * be in the translation template.
62
+ * @todo Check whether any of these should be removed.
63
+ */
64
+ $benign_strings = array(
65
+ __( 'No fields selected for deletion', 'wp-members' ),
66
+ __( 'You are not logged in.', 'wp-members' ), // Technically removed 3.5
67
+ );
68
+
69
+ $defaults = array(
70
+
71
+ // Login form.
72
+ 'login_heading' => __( 'Existing Users Log In', 'wp-members' ),
73
+ 'login_username' => __( 'Username or Email', 'wp-members' ),
74
+ 'login_password' => __( 'Password', 'wp-members' ),
75
+ 'login_button' => __( 'Log In', 'wp-members' ),
76
+ 'remember_me' => __( 'Remember Me', 'wp-members' ),
77
+ 'forgot_link_before' => __( 'Forgot password?', 'wp-members' ) . '&nbsp;',
78
+ 'forgot_link' => __( 'Click here to reset', 'wp-members' ),
79
+ 'register_link_before' => __( 'New User?', 'wp-members' ) . '&nbsp;',
80
+ 'register_link' => __( 'Click here to register', 'wp-members' ),
81
+
82
+ // Password change form.
83
+ 'pwdchg_heading' => __( 'Change Password', 'wp-members' ),
84
+ 'pwdchg_password1' => __( 'New password', 'wp-members' ),
85
+ 'pwdchg_password2' => __( 'Confirm new password', 'wp-members' ),
86
+ 'pwdchg_button' => __( 'Update Password', 'wp-members' ),
87
+ 'pwdchg_update' => __( 'Password successfully changed!', 'wp-members' ),
88
+
89
+ // Password reset form.
90
+ 'pwdreset_heading' => __( 'Reset Forgotten Password', 'wp-members' ),
91
+ 'pwdreset_username' => __( 'Username', 'wp-members' ),
92
+ 'pwdreset_email' => __( 'Email', 'wp-members' ),
93
+ 'pwdreset_button' => __( 'Reset Password' ),
94
+ 'username_link_before' => __( 'Forgot username?', 'wp-members' ) . '&nbsp;',
95
+ 'username_link' => __( 'Click here', 'wp-members' ),
96
+
97
+ // Retrieve username form.
98
+ 'username_heading' => __( 'Retrieve username', 'wp-members' ),
99
+ 'username_email' => __( 'Email Address', 'wp-members' ),
100
+ 'username_button' => __( 'Retrieve username', 'wp-members' ),
101
+
102
+ // Register form.
103
+ 'register_heading' => __( 'New User Registration', 'wp-members' ),
104
+ 'register_username' => __( 'Choose a Username', 'wp-members' ),
105
+ 'register_rscaptcha' => __( 'Input the code:', 'wp-members' ),
106
+ 'register_tos' => __( 'Please indicate that you agree to the %s Terms of Service %s', 'wp-members' ), // @note: if default changes, default check after wpmem_tos_link_txt must change.
107
+ 'register_clear' => __( 'Reset Form', 'wp-members' ),
108
+ 'register_submit' => __( 'Register', 'wp-members' ),
109
+ 'register_req_mark' => '<span class="req">*</span>',
110
+ 'register_required' => '<span class="req">*</span>' . __( 'Required field', 'wp-members' ),
111
+
112
+ // User profile update form.
113
+ 'profile_heading' => __( 'Edit Your Information', 'wp-members' ),
114
+ 'profile_username' => __( 'Username', 'wp-members' ),
115
+ 'profile_submit' => __( 'Update Profile', 'wp-members' ),
116
+ 'profile_upload' => __( 'Update this file', 'wp-members' ),
117
+
118
+ // Error messages and dialogs.
119
+ 'login_failed_heading' => __( 'Login Failed!', 'wp-members' ), // @deprecated 3.4.0
120
+ 'login_failed' => __( 'You entered an invalid username or password.', 'wp-members' ),
121
+ 'login_failed_link' => __( 'Click here to continue.', 'wp-members' ), // @deprecated 3.4.0
122
+ 'pwdchangempty' => __( 'Password fields cannot be empty', 'wp-members' ),
123
+ 'usernamefailed' => __( 'Sorry, that email address was not found.', 'wp-members' ),
124
+ 'usernamesuccess' => __( 'An email was sent to %s with your username.', 'wp-members' ),
125
+ 'reg_empty_field' => __( 'Sorry, %s is a required field.', 'wp-members' ),
126
+ 'reg_valid_email' => __( 'You must enter a valid email address.', 'wp-members' ),
127
+ 'reg_non_alphanumeric' => __( 'The username cannot include non-alphanumeric characters.', 'wp-members' ),
128
+ 'reg_empty_username' => __( 'Sorry, username is a required field', 'wp-members' ),
129
+ 'reg_username_taken' => __( 'Sorry, that username is taken, Please try another.', 'wp-members' ),
130
+ 'reg_email_taken' => __( 'Sorry, that email address already has an account. Please try another.', 'wp-members' ),
131
+ 'reg_password_match' => __( 'Passwords did not match.', 'wp-members' ),
132
+ 'reg_email_match' => __( 'Emails did not match.', 'wp-members' ),
133
+ 'reg_empty_captcha' => __( 'You must complete the CAPTCHA form.', 'wp-members' ),
134
+ 'reg_invalid_captcha' => __( 'CAPTCHA was not valid.', 'wp-members' ),
135
+ 'reg_generic' => __( 'There was an error processing the form.', 'wp-members' ),
136
+ 'reg_captcha_err' => __( 'There was an error with the CAPTCHA form.', 'wp-members' ),
137
+ 'reg_file_type' => __( 'Sorry, you can only upload the following file types for the %s field: %s.', 'wp-members' ),
138
+ 'profile_update' => __( 'Your information was updated!', 'wp-members' ),
139
+
140
+ // Links.
141
+ 'profile_edit' => __( 'Edit My Information', 'wp-members' ),
142
+ 'profile_password' => __( 'Change Password', 'wp-members' ),
143
+ 'register_status' => __( 'You are logged in as %s', 'wp-members' ),
144
+ 'register_logout' => __( 'Log out', 'wp-members' ),
145
+ 'register_continue' => ( isset( $wpmem->user_pages['profile'] ) && '' != $wpmem->user_pages['profile'] ) ? __( 'Edit profile', 'wp-members' ) : __( 'Begin using the site.', 'wp-members' ),
146
+ 'login_welcome' => __( 'You are logged in as %s', 'wp-members' ),
147
+ 'login_logout' => __( 'Click to log out', 'wp-members' ),
148
+ 'status_welcome' => __( 'You are logged in as %s', 'wp-members' ),
149
+ 'status_logout' => __( 'click to log out', 'wp-members' ),
150
+ 'menu_logout' => __( 'Log Out', 'wp-members' ),
151
+
152
+ // Widget.
153
+ 'widget_status' => __( 'You are logged in as %s', 'wp-members' ),
154
+ 'widget_logout' => __( 'click here to log out', 'wp-members' ),
155
+ 'widget_login_failed' => __( 'Login Failed!<br />You entered an invalid username or password.', 'wp-members' ),
156
+ 'widget_login_failed_new' => __( 'Invalid username or password.', 'wp-members' ), // @todo New string replacement. Replace widget_login_failed when translated.
157
+ 'widget_not_logged_in' => '',
158
+ 'widget_login_username' => __( 'Username or Email', 'wp-members' ),
159
+ 'widget_login_password' => __( 'Password', 'wp-members' ),
160
+ 'widget_login_button' => __( 'log in', 'wp-members' ),
161
+ 'widget_login_forgot' => __( 'Forgot?', 'wp-members' ),
162
+ 'widget_login_register' => __( 'Register', 'wp-members' ),
163
+
164
+ // Default Dialogs.
165
+ 'restricted_msg' => __( "This content is restricted to site members. If you are an existing user, please log in. New users may register below.", 'wp-members' ),
166
+ 'success' => __( "Congratulations! Your registration was successful.<br /><br />You may now log in using the password that was emailed to you.", 'wp-members' ),
167
+
168
+ // @todo Under consideration for removal from the Dialogs tab.
169
+ 'user' => __( "Sorry, that username is taken, please try another.", 'wp-members' ),
170
+ 'email' => __( "Sorry, that email address already has an account.<br />Please try another.", 'wp-members' ),
171
+ 'editsuccess' => __( "Your information was updated!", 'wp-members' ),
172
+
173
+ // @todo These are defaults and are under consideration for removal from the dialogs tab, possibly as we change the password reset to a link based process.
174
+ 'pwdchangerr' => __( "Passwords did not match.", 'wp-members' ),
175
+ 'pwdchangesuccess' => __( "Password successfully changed.", 'wp-members' ),
176
+ 'pwdreseterr' => __( "Invalid username or email address.", 'wp-members' ),
177
+ 'pwdresetsuccess' => __( "Password successfully reset! An email containing a new password has been sent to the email address on file for your account.", 'wp-members' ),
178
+ 'pwdresetsuccess_alt' => __( "Reset request received. An email with instructions to complete the password reset has been sent.", 'wp-members' ),
179
+
180
+ 'product_restricted_single' => __( "This content requires the following membership: ", 'wp-members' ),
181
+ 'product_restricted_multiple' => __( "This content requires one of the following memberships: ", 'wp-members' ),
182
+
183
+ ); // End of $defaults array.
184
+
185
+ /**
186
+ * Filter default terms.
187
+ *
188
+ * @since 3.1.0
189
+ * @deprecated 3.2.7 Use wpmem_default_text instead.
190
+ */
191
+ $text = apply_filters( 'wpmem_default_text_strings', '' );
192
+
193
+ // Merge filtered $terms with $defaults.
194
+ $text = wp_parse_args( $text, $defaults );
195
+
196
+ /**
197
+ * Filter the default terms.
198
+ *
199
+ * Replaces 'wpmem_default_text_strings' so that multiple filters could
200
+ * be run. This allows for custom filters when also running the Text
201
+ * String Editor extension.
202
+ *
203
+ * @since 3.2.7
204
+ */
205
+ $text = apply_filters( 'wpmem_default_text', $text );
206
+
207
+ // Manage legacy keys (i.e. sb_ to widget_ ).
208
+ // @todo Legacy keys to be obsolete by 3.5.0
209
+ $str = ( false !== strpos( $str, 'sb_' ) ) ? str_replace( 'sb_', 'widget_', $str ) : $str;
210
+ foreach ( $text as $key => $value ) {
211
+ if ( false !== strpos( $key, 'sb_' ) ) {
212
+ $new_key = str_replace( 'sb_', 'widget_', $key );
213
+ $text[ $new_key ] = $text[ $key ];
214
+ }
215
+ }
216
+
217
+ // Return the requested text string.
218
+ return $text[ $str ];
219
+ }
220
+
221
+ /**
222
+ * Login Failed Dialog.
223
+ *
224
+ * Returns the login failed error message.
225
+ *
226
+ * @since 1.8
227
+ * @since 3.4.0 Removed "continue" (return) link (login form now displays by default under the error message).
228
+ *
229
+ * @todo 3.5.0 will fold this into the main message function and this functions associated filters will be obsolete.
230
+ *
231
+ * @global object $wpmem The WP_Members object.
232
+ * @return string $str The generated html for the login failed message.
233
+ */
234
+ function login_failed() {
235
+
236
+ global $wpmem;
237
+
238
+ // Defaults.
239
+ $defaults = array(
240
+ 'div_before' => '',
241
+ 'div_after' => '',
242
+ 'heading_before' => '',
243
+ 'heading' => '', //wpmem_get_text( 'login_failed_heading' ),
244
+ 'heading_after' => '',
245
+ 'p_before' => '',
246
+ 'message' => ( $wpmem->error && 1 == $wpmem->login_error ) ? $wpmem->error : wpmem_get_text( 'login_failed' ), // @todo $this->error
247
+ 'p_after' => '',
248
+ //'link' => '<a href="' . esc_url( $_SERVER['REQUEST_URI'] ) . '">' . wpmem_get_text( 'login_failed_link' ) . '</a>',
249
+ );
250
+
251
+ /**
252
+ * Filter the login failed dialog arguments.
253
+ *
254
+ * @since 2.9.0
255
+ * @since 3.3.3 Should pass defaults to filter.
256
+ * @deprecated 3.4.0
257
+ *
258
+ * @param array An array of arguments to merge with defaults.
259
+ */
260
+ $args = apply_filters( 'wpmem_login_failed_args', $defaults );
261
+
262
+ // Merge $args with defaults.
263
+ $args = wp_parse_args( $args, $defaults );
264
+
265
+ $str = $args['div_before']
266
+ . $args['heading_before'] . $args['heading'] . $args['heading_after']
267
+ . $args['p_before'] . $args['message'] . $args['p_after']
268
+ //. $args['p_before'] . $args['link'] . $args['p_after']
269
+ . $args['div_after'];
270
+
271
+ /**
272
+ * Filter the login failed dialog.
273
+ *
274
+ * @since 2.7.3
275
+ *
276
+ * @param string $str The login failed dialog.
277
+ */
278
+ $str = apply_filters( 'wpmem_login_failed', $str );
279
+
280
+ return $str;
281
+ }
282
+
283
+ /**
284
+ * Gets the message to display.
285
+ *
286
+ * @since 3.4.0
287
+ *
288
+ * @todo This replaces some other functions and usage seems to be inconsistent.
289
+ * Review and replace useage as needed.
290
+ *
291
+ * @param $tag string
292
+ * @param $custom string
293
+ * @return $message string
294
+ */
295
+ function get_message( $tag, $custom = false ) {
296
+
297
+ // defaults
298
+ $defaults = array(
299
+ 'div_before' => '<div class="wpmem_msg">',
300
+ 'div_after' => '</div>',
301
+ 'p_before' => '', // @deprecated 3.4.0
302
+ 'p_after' => '', // @deprecated 3.4.0
303
+ 'tags' => array(
304
+ 'user',
305
+ 'email',
306
+ 'success',
307
+ 'editsuccess',
308
+ 'pwdchangerr',
309
+ 'pwdchangesuccess',
310
+ 'pwdreseterr',
311
+ 'pwdresetsuccess',
312
+ 'loginfailed',
313
+ ),
314
+ );
315
+
316
+ /**
317
+ * Filter the message arguments.
318
+ *
319
+ * @since 2.9.0
320
+ * @deprecated 3.3.0 Use wpmem_msg_defaults instead.
321
+ * @todo Obsolete in 3.5.0
322
+ *
323
+ * @param array An array of arguments to merge with defaults.
324
+ */
325
+ $args = apply_filters( 'wpmem_msg_args', '' );
326
+
327
+ /** This filter is documented in /includes/class-wp-members-admin-api.php */
328
+ $dialogs = apply_filters( 'wpmem_dialogs', get_option( 'wpmembers_dialogs' ) );
329
+
330
+ // @todo Temporary(?) workaround for custom dialogs as an array (WP-Members Security).
331
+ if ( array_key_exists( $tag, $dialogs ) ) {
332
+ if ( is_array( $dialogs[ $tag ] ) ) {
333
+ $msg = stripslashes( $dialogs[ $tag ]['value'] );
334
+ } else {
335
+ $msg = wpmem_get_text( $tag );
336
+ $msg = ( $dialogs[ $tag ] == $msg ) ? $msg : __( stripslashes( $dialogs[ $tag ] ), 'wp-members' );
337
+ }
338
+ } elseif ( 'loginfailed' == $tag ) {
339
+ $msg = $this->login_failed();
340
+ } elseif ( $custom ) {
341
+ $msg = $custom;
342
+ } else {
343
+ // It must be a custom message ("custom" in that it is not included in the dialogs array).
344
+ $msg = $tag;
345
+ }
346
+
347
+ $defaults['msg'] = $msg;
348
+
349
+ /**
350
+ * Filter the message array
351
+ *
352
+ * @since 2.9.2
353
+ * @since 3.1.1 added $dialogs parameter.
354
+ * @deprecated 3.3.0 Use wpmem_msg_defaults instead.
355
+ * @todo Obsolete in 3.5.0
356
+ *
357
+ * @param array $defaults An array of the defaults.
358
+ * @param string $tag The tag that we are on, if any.
359
+ * @param array $dialogs
360
+ */
361
+ $defaults = apply_filters( 'wpmem_msg_dialog_arr', $defaults, $tag, $dialogs );
362
+
363
+ // Merge $args with defaults.
364
+ $args = wp_parse_args( $args, $defaults );
365
+
366
+ // Backwards compatibility for 'toggles'.
367
+ if ( isset( $args['toggles'] ) ) {
368
+ $args['tags'] = $args['toggles'];
369
+ }
370
+
371
+ /**
372
+ * Filter the message settings.
373
+ *
374
+ * @since 3.3.0
375
+ *
376
+ * @param array $defaults An array of the defaults.
377
+ * @param string $tag The tag that we are on, if any.
378
+ * @param array $dialogs
379
+ */
380
+ $args = apply_filters( 'wpmem_msg_defaults', $defaults, $tag, $dialogs );
381
+
382
+ // @todo Temporary(?) workaround for custom dialogs as an array (WP-Members Security).
383
+ $display_msg = ( is_array( $args['msg'] ) ) ? $args['msg']['value'] : $args['msg'];
384
+
385
+ $str = $args['div_before'] . stripslashes( $display_msg ) . $args['div_after'];
386
+
387
+ /**
388
+ * Filter the message.
389
+ *
390
+ * @since 2.7.4
391
+ * @since 3.1.0 Added tag.
392
+ *
393
+ * @param string $str The message.
394
+ * @param string $tag The tag of the message being displayed.
395
+ */
396
+ return apply_filters( 'wpmem_msg_dialog', $str, $tag );
397
+ }
398
+ }
includes/class-wp-members-email.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-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.
@@ -50,14 +50,33 @@ class WP_Members_Email {
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
  /**
@@ -83,12 +102,13 @@ class WP_Members_Email {
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();
@@ -116,6 +136,11 @@ class WP_Members_Email {
116
  $this->settings['tag'] = ( isset( $custom['tag'] ) ) ? $custom['tag'] : '';
117
  break;
118
  }
 
 
 
 
 
119
 
120
  // Get the user ID.
121
  $user = new WP_User( $user_id );
@@ -133,7 +158,7 @@ class WP_Members_Email {
133
  $this->settings['reg_link'] = esc_url( get_user_meta( $user_id, 'wpmem_reg_url', true ) );
134
  $this->settings['do_shortcodes'] = true;
135
  $this->settings['add_footer'] = true;
136
- $this->settings['footer'] = get_option( 'wpmembers_email_footer' );
137
  $this->settings['disable'] = false;
138
  $this->settings['toggle'] = $this->settings['tag']; // Deprecated since 3.2.0, but remains in the array for legacy reasons.
139
  $this->settings['reset_link'] = esc_url_raw( add_query_arg( array( 'a' => 'pwdreset', 'key' => $password, 'id' => $user_id ), wpmem_profile_url() ) );
@@ -283,7 +308,7 @@ class WP_Members_Email {
283
  * @param array $wpmem_fields Array of the WP-Members fields (defaults to null).
284
  * @param array $field_data Array of the registration data (defaults to null).
285
  */
286
- function notify_admin( $user_id, $wpmem_fields = null, $field_data = null ) {
287
 
288
  global $wpmem;
289
 
@@ -342,7 +367,6 @@ class WP_Members_Email {
342
  } else {
343
  $val = ( is_array( $field_data ) ) ? esc_html( $field_data[ $meta_key ] ) : esc_html( get_user_meta( $user_id, $meta_key, true ) );
344
  }
345
- // $field_arr[ $field['label'] ] = $val; // @todo Consider (1) if this should be implemented, and (2) if it should be done here or location "B".
346
  $field_arr[ __( $field['label'], 'wp-members' ) ] = $val;
347
  }
348
  }
@@ -375,6 +399,7 @@ class WP_Members_Email {
375
  * data from the register function.
376
  *
377
  * @since 2.9.8
 
378
  *
379
  * @param array $this->settings P
380
  * An array containing email body, subject, user id, and additional settings.
@@ -398,10 +423,11 @@ class WP_Members_Email {
398
  * @type string $headers
399
  * @type string $admin_email
400
  * }
401
- * @param array $wpmem_fields An array of the WP-Members fields.
402
- * @param array $field_data An array of the posted registration data.
 
403
  */
404
- $this->settings = apply_filters( 'wpmem_notify_filter', $this->settings, $wpmem_fields, $field_data );
405
 
406
  // If emails are not disabled, continue the email process.
407
  if ( ! $this->settings['disable'] ) {
@@ -410,8 +436,6 @@ class WP_Members_Email {
410
  $field_str = '';
411
  foreach ( $this->settings['field_arr'] as $key => $val ) {
412
  $field_str.= $key . ': ' . $val . "\r\n";
413
- // @todo Location "B" to to label translation. Could be as follows:
414
- // $field_str.= __( $key, 'wp-members' ) . ": " . $val . "\r\n";
415
  }
416
 
417
  // Get the email footer if needed.
@@ -476,12 +500,6 @@ class WP_Members_Email {
476
  /**
477
  * Filters the admin notification email.
478
  *
479
- * This is the last chance to filter the message body. At this point
480
- * it is just the text that will be in the message.
481
- * @todo Consider deprecating this filter as it could be accomplished
482
- * by the wp_mail filter, or a universal filter could be added
483
- * to the new email send function.
484
- *
485
  * @since 2.8.2
486
  *
487
  * @param string $this->settings['body'] The admin notification email body.
@@ -500,13 +518,10 @@ class WP_Members_Email {
500
  * @since 3.1.0 Converted to use email var in object.
501
  * @since 3.2.0 Moved to WP_Members_Email::from().
502
  *
503
- * @global object $wpmem
504
- *
505
  * @param string $email
506
  * @return string $wpmem_mail_from|$email
507
  */
508
- function from( $email ) {
509
- global $wpmem;
510
  return ( $this->from ) ? $this->from : $email;
511
  }
512
 
@@ -517,15 +532,23 @@ class WP_Members_Email {
517
  * @since 3.1.0 Converted to use email var in object.
518
  * @since 3.2.0 Moved to WP_Members_Email::from_name().
519
  *
520
- * @global object $wpmem
521
- *
522
  * @param string $name
523
  * @return string $wpmem_mail_from_name|$name
524
  */
525
- function from_name( $name ) {
526
- global $wpmem;
527
  return ( $this->from_name ) ? stripslashes( $this->from_name ) : stripslashes( $name );
528
  }
 
 
 
 
 
 
 
 
 
 
 
529
 
530
  /**
531
  * Sends email.
@@ -535,7 +558,7 @@ class WP_Members_Email {
535
  * @param string $to
536
  * @return bool $result
537
  */
538
- function send( $to ) {
539
  $args['to'] = ( 'user' == $to ) ? $this->settings['user_email'] : $this->settings['admin_email'];
540
  $args['subject'] = $this->settings['subj'];
541
  $args['message'] = $this->settings['body'];
@@ -551,10 +574,21 @@ class WP_Members_Email {
551
  * @param array $this->settings
552
  */
553
  $args = apply_filters( 'wpmem_email_send_args', $args, $to, $this->settings );
554
- // Apply WP's "from" and "from name" email filters.
555
- add_filter( 'wp_mail_from', array( $this, 'from' ) );
556
- add_filter( 'wp_mail_from_name', array( $this, 'from_name' ) );
557
- $result = wp_mail( $args['to'], stripslashes( $args['subject'] ), stripslashes( $args['message'] ), $args['headers'] );
 
 
 
 
 
 
 
 
 
 
 
558
  return $result;
559
  }
560
  }
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-2021 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-2021
17
  */
18
 
19
  // Exit if accessed directly.
50
  */
51
  public $settings;
52
 
53
+ /**
54
+ * Setting for HTML email.
55
+ *
56
+ * @since 3.4.0
57
+ * @access public
58
+ * @var string
59
+ */
60
+ public $html = 0;
61
+
62
  /**
63
  * Load custom from address.
64
  *
65
  * @since 3.3.0
66
  */
67
+ public function load_from() {
68
  $this->from = get_option( 'wpmembers_email_wpfrom', '' );
69
  $this->from_name = get_option( 'wpmembers_email_wpname', '' );
70
+ $this->html = get_option( 'wpmembers_email_html', '' );
71
+ }
72
+
73
+ /**
74
+ * Load plugin HTML email setting.
75
+ *
76
+ * @since 3.4.0
77
+ */
78
+ private function load_format() {
79
+ $this->html = get_option( 'wpmembers_email_html', 0 );
80
  }
81
 
82
  /**
102
  * @param array $fields Array of the registration data (defaults to null).
103
  * @param array $custom Array of custom email information (defaults to null).
104
  */
105
+ public function to_user( $user_id, $password, $tag, $wpmem_fields = null, $field_data = null, $custom = null ) {
106
 
107
  global $wpmem;
108
 
109
+ // Load settings.
110
  $this->load_from();
111
+ $this->load_format();
112
 
113
  // Handle backward compatibility for customizations that may call the email function directly.
114
  $wpmem_fields = wpmem_fields();
136
  $this->settings['tag'] = ( isset( $custom['tag'] ) ) ? $custom['tag'] : '';
137
  break;
138
  }
139
+
140
+ // wpautop() the content if we are doing HTML email.
141
+ if ( 1 == $this->html ) {
142
+ $this->settings['body'] = wpautop( $this->settings['body'] );
143
+ }
144
 
145
  // Get the user ID.
146
  $user = new WP_User( $user_id );
158
  $this->settings['reg_link'] = esc_url( get_user_meta( $user_id, 'wpmem_reg_url', true ) );
159
  $this->settings['do_shortcodes'] = true;
160
  $this->settings['add_footer'] = true;
161
+ $this->settings['footer'] = ( 1 == $this->html ) ? wpautop( get_option( 'wpmembers_email_footer' ) ) : get_option( 'wpmembers_email_footer' );
162
  $this->settings['disable'] = false;
163
  $this->settings['toggle'] = $this->settings['tag']; // Deprecated since 3.2.0, but remains in the array for legacy reasons.
164
  $this->settings['reset_link'] = esc_url_raw( add_query_arg( array( 'a' => 'pwdreset', 'key' => $password, 'id' => $user_id ), wpmem_profile_url() ) );
308
  * @param array $wpmem_fields Array of the WP-Members fields (defaults to null).
309
  * @param array $field_data Array of the registration data (defaults to null).
310
  */
311
+ public function notify_admin( $user_id, $wpmem_fields = null, $field_data = null ) {
312
 
313
  global $wpmem;
314
 
367
  } else {
368
  $val = ( is_array( $field_data ) ) ? esc_html( $field_data[ $meta_key ] ) : esc_html( get_user_meta( $user_id, $meta_key, true ) );
369
  }
 
370
  $field_arr[ __( $field['label'], 'wp-members' ) ] = $val;
371
  }
372
  }
399
  * data from the register function.
400
  *
401
  * @since 2.9.8
402
+ * @since 3.3.9 Added $user param.
403
  *
404
  * @param array $this->settings P
405
  * An array containing email body, subject, user id, and additional settings.
423
  * @type string $headers
424
  * @type string $admin_email
425
  * }
426
+ * @param array $wpmem_fields An array of the WP-Members fields.
427
+ * @param array $field_data An array of the posted registration data.
428
+ * @param stdClass $user WP user object for the specific user.
429
  */
430
+ $this->settings = apply_filters( 'wpmem_notify_filter', $this->settings, $wpmem_fields, $field_data, $user );
431
 
432
  // If emails are not disabled, continue the email process.
433
  if ( ! $this->settings['disable'] ) {
436
  $field_str = '';
437
  foreach ( $this->settings['field_arr'] as $key => $val ) {
438
  $field_str.= $key . ': ' . $val . "\r\n";
 
 
439
  }
440
 
441
  // Get the email footer if needed.
500
  /**
501
  * Filters the admin notification email.
502
  *
 
 
 
 
 
 
503
  * @since 2.8.2
504
  *
505
  * @param string $this->settings['body'] The admin notification email body.
518
  * @since 3.1.0 Converted to use email var in object.
519
  * @since 3.2.0 Moved to WP_Members_Email::from().
520
  *
 
 
521
  * @param string $email
522
  * @return string $wpmem_mail_from|$email
523
  */
524
+ public function from( $email ) {
 
525
  return ( $this->from ) ? $this->from : $email;
526
  }
527
 
532
  * @since 3.1.0 Converted to use email var in object.
533
  * @since 3.2.0 Moved to WP_Members_Email::from_name().
534
  *
 
 
535
  * @param string $name
536
  * @return string $wpmem_mail_from_name|$name
537
  */
538
+ public function from_name( $name ) {
 
539
  return ( $this->from_name ) ? stripslashes( $this->from_name ) : stripslashes( $name );
540
  }
541
+
542
+ /**
543
+ * Returns HTML content type for email.
544
+ *
545
+ * @since 3.4.0
546
+ *
547
+ * @return string Always returns "text/html"
548
+ */
549
+ public function content_type( $content_type ) {
550
+ return ( 1 == $this->html ) ? 'text/html' : $content_type;
551
+ }
552
 
553
  /**
554
  * Sends email.
558
  * @param string $to
559
  * @return bool $result
560
  */
561
+ private function send( $to ) {
562
  $args['to'] = ( 'user' == $to ) ? $this->settings['user_email'] : $this->settings['admin_email'];
563
  $args['subject'] = $this->settings['subj'];
564
  $args['message'] = $this->settings['body'];
574
  * @param array $this->settings
575
  */
576
  $args = apply_filters( 'wpmem_email_send_args', $args, $to, $this->settings );
577
+
578
+ // Apply filters.
579
+ add_filter( 'wp_mail_from', array( $this, 'from' ) );
580
+ add_filter( 'wp_mail_from_name', array( $this, 'from_name' ) );
581
+ add_filter( 'wp_mail_content_type', array( $this, 'content_type' ) );
582
+
583
+ // Send message.
584
+ $result = wp_mail( $args['to'], stripslashes( $args['subject'] ), stripslashes( $args['message'] ) );
585
+
586
+ // Remove customizations.
587
+ remove_filter( 'wp_mail_from', array( $this, 'from' ) );
588
+ remove_filter( 'wp_mail_from_name', array( $this, 'from_name' ) );
589
+ remove_filter( 'wp_mail_content_type', array( $this, 'content_type' ) );
590
+
591
+ // Return result (does not necessarily indicate message was sent).
592
  return $result;
593
  }
594
  }
includes/class-wp-members-forms.php CHANGED
@@ -1,2129 +1,2181 @@
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
- $title = ( $title ) ? ' title="' . esc_attr( __( $title, 'wp-members' ) ) . '"' : '';
106
- $pattern = ( $pattern && 'number' != $type ) ? ' pattern="' . esc_attr( $pattern ) . '"' : '';
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 " : "" ) . ( ( 'image' == $type ) ? ' onchange="loadFile(event, this.id)"' : '' ) . ' />';
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', 'wp-members' ) . '|' );
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'=>'multicheckbox', '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
- ) ) . "&nbsp;" . $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
- * @since 3.3.7 Added optional $type
312
- *
313
- * @param array $data
314
- * @param string $type The data type integer|int (default: false)
315
- * @return array $data
316
- */
317
- function sanitize_array( $data, $type = false ) {
318
- if ( is_array( $data ) ) {
319
- foreach( $data as $key => $val ) {
320
- $data[ $key ] = ( 'integer' == $type || 'int' == $type ) ? intval( $val ) : sanitize_text_field( $val );
321
- }
322
- }
323
- return $data;
324
- }
325
-
326
- /**
327
- * Sanitizes field based on field type.
328
- *
329
- * Obviously, this isn't an all inclusive function of every WordPress
330
- * sanitization function. It is intended to handle sanitization of
331
- * WP-Members form input and therefore includes the necessary methods
332
- * that would relate to the WP-Members custom field types and can thus
333
- * be used by looping through form data when the WP-Members fields are
334
- * handled and validated.
335
- *
336
- * @since 3.2.9
337
- * @since 3.3.0 Added email, file, and image.
338
- *
339
- * @param string $data
340
- * @param string $type
341
- * @return string $sanitized_data
342
- */
343
- function sanitize_field( $data, $type ) {
344
-
345
- switch ( $type ) {
346
-
347
- case 'multiselect':
348
- case 'multicheckbox':
349
- $sanitized_data = $this->sanitize_array( $data );
350
- break;
351
-
352
- case 'textarea':
353
- $sanitized_data = sanitize_textarea_field( $data );
354
- break;
355
-
356
- case 'email':
357
- $sanitized_data = sanitize_email( $data );
358
- break;
359
-
360
- case 'file':
361
- case 'image':
362
- $sanitized_data = sanitize_file_name( $data );
363
- break;
364
-
365
- case 'int':
366
- case 'integer':
367
- case 'number':
368
- $sanitized_data = intval( $data );
369
- break;
370
-
371
- default:
372
- $sanitized_data = sanitize_text_field( $data );
373
- break;
374
- }
375
-
376
- return $sanitized_data;
377
- }
378
-
379
- /**
380
- * Uploads file from the user.
381
- *
382
- * @since 3.1.0
383
- *
384
- * @param array $file
385
- * @param int $user_id
386
- * @return int|bool
387
- */
388
- function do_file_upload( $file = array(), $user_id = false ) {
389
-
390
- // Filter the upload directory.
391
- add_filter( 'upload_dir', array( &$this, 'file_upload_dir' ) );
392
-
393
- // Set up user ID for use in upload process.
394
- $this->file_user_id = ( $user_id ) ? $user_id : 0;
395
-
396
- // Get WordPress file upload processing scripts.
397
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
398
- require_once( ABSPATH . 'wp-admin/includes/media.php' );
399
-
400
- $file_return = wp_handle_upload( $file, array( 'test_form' => false ) );
401
-
402
- if ( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
403
- return false;
404
- } else {
405
-
406
- $attachment = array(
407
- 'post_mime_type' => $file_return['type'],
408
- 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $file_return['file'] ) ),
409
- 'post_content' => '',
410
- 'post_status' => 'inherit',
411
- 'guid' => $file_return['url'],
412
- 'post_author' => ( $user_id ) ? $user_id : '',
413
- );
414
-
415
- $attachment_id = wp_insert_attachment( $attachment, $file_return['url'] );
416
-
417
- require_once( ABSPATH . 'wp-admin/includes/image.php' );
418
- $attachment_data = wp_generate_attachment_metadata( $attachment_id, $file_return['file'] );
419
- wp_update_attachment_metadata( $attachment_id, $attachment_data );
420
-
421
- if ( 0 < intval( $attachment_id ) ) {
422
- // Returns an array with file information.
423
- return $attachment_id;
424
- }
425
- }
426
-
427
- return false;
428
- } // End upload_file()
429
-
430
- /**
431
- * Sets the file upload directory.
432
- *
433
- * This is a filter function for upload_dir.
434
- *
435
- * @link https://codex.wordpress.org/Plugin_API/Filter_Reference/upload_dir
436
- *
437
- * @since 3.1.0
438
- *
439
- * @param array $param {
440
- * The directory information for upload.
441
- *
442
- * @type string $path
443
- * @type string $url
444
- * @type string $subdir
445
- * @type string $basedir
446
- * @type string $baseurl
447
- * @type string $error
448
- * }
449
- * @return array $param
450
- */
451
- function file_upload_dir( $param ) {
452
-
453
- global $wpmem;
454
-
455
- $user_id = ( isset( $this->file_user_id ) ) ? $this->file_user_id : null;
456
-
457
- $args = array(
458
- 'user_id' => $user_id,
459
- 'wpmem_dir' => $wpmem->upload_base,
460
- 'user_dir' => 'user_files/' . $user_id,
461
- );
462
-
463
- /**
464
- * Filter the user directory elements.
465
- *
466
- * @since 3.1.0
467
- *
468
- * @param array $args
469
- */
470
- $args = apply_filters( 'wpmem_user_upload_dir', $args );
471
-
472
- $param['subdir'] = '/' . $args['wpmem_dir'] . '/' . $args['user_dir'];
473
- $param['path'] = $param['basedir'] . '/' . $args['wpmem_dir'] . '/' . $args['user_dir'];
474
- $param['url'] = $param['baseurl'] . '/' . $args['wpmem_dir'] . '/' . $args['user_dir'];
475
-
476
- return $param;
477
- }
478
-
479
- /**
480
- * Login Form Builder.
481
- *
482
- * Builds the form used for login, change password, and reset password.
483
- *
484
- * @since 2.5.1
485
- * @since 3.1.7 Moved to forms object class as login_form().
486
- * @since 3.1.7 Added WP action login_form.
487
- * @since 3.2.6 Added nonce to the short form.
488
- *
489
- * @param string $page
490
- * @param array $arr {
491
- * The elements needed to generate the form (login|reset password|forgotten password).
492
- *
493
- * @type string $heading Form heading text.
494
- * @type string $action The form action (login|pwdchange|pwdreset|getusername).
495
- * @type string $button_text Form submit button text.
496
- * @type array $inputs {
497
- * The form input values.
498
- *
499
- * @type array {
500
- *
501
- * @type string $name The field label.
502
- * @type string $type Input type.
503
- * @type string $tag Input tag name.
504
- * @type string $class Input tag class.
505
- * @type string $div Div wrapper class.
506
- * }
507
- * }
508
- * @type string $redirect_to Optional. URL to redirect to.
509
- * }
510
- * @return string $form The HTML for the form as a string.
511
- */
512
- function login_form( $mixed, $arr = array() ) {
513
-
514
- // Handle legacy use.
515
- if ( is_array( $mixed ) ) {
516
- $page = $mixed['page'];
517
- $arr = $mixed;
518
- } else {
519
- $page = $mixed;
520
- }
521
-
522
-
523
- // Set up redirect_to @todo This could be done in a separate method usable by both login & reg.
524
- if ( isset( $_REQUEST['redirect_to'] ) ) {
525
- $redirect_to = $_REQUEST['redirect_to'];
526
- } else {
527
- if ( isset( $arr['redirect_to'] ) ) {
528
- $redirect_to = $arr['redirect_to'];
529
- } else {
530
- $redirect_to = ( isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : get_permalink();
531
- }
532
- }
533
-
534
- global $wpmem;
535
-
536
- // set up default wrappers
537
- $defaults = array(
538
-
539
- // wrappers
540
- 'heading_before' => '<legend>',
541
- 'heading_after' => '</legend>',
542
- 'fieldset_before' => '<fieldset>',
543
- 'fieldset_after' => '</fieldset>',
544
- 'main_div_before' => '<div id="wpmem_login">',
545
- 'main_div_after' => '</div>',
546
- 'txt_before' => '',
547
- 'txt_after' => '',
548
- 'row_before' => '',
549
- 'row_after' => '',
550
- 'buttons_before' => '<div class="button_div">',
551
- 'buttons_after' => '</div>',
552
- 'link_before' => '<div class="link-text">',
553
- 'link_after' => '</div>',
554
- 'link_span_before' => '<span class="link-text-%s">',
555
- 'link_span_after' => '</span>',
556
-
557
- // classes & ids
558
- 'form_id' => 'wpmem_' . $arr['action'] . '_form',
559
- 'form_class' => 'form',
560
- 'button_id' => '',
561
- 'button_class' => 'buttons',
562
-
563
- // other
564
- 'strip_breaks' => true,
565
- 'wrap_inputs' => true,
566
- 'remember_check' => true,
567
- 'n' => "\n",
568
- 't' => "\t",
569
- 'redirect_to' => $redirect_to,
570
- 'login_form_action' => true,
571
-
572
- );
573
-
574
- /**
575
- * Filter the default form arguments.
576
- *
577
- * This filter accepts an array of various elements to replace the form defaults. This
578
- * includes default tags, labels, text, and small items including various booleans.
579
- *
580
- * @since 2.9.0
581
- * @since 3.3.0 Passes $defaults as an argument.
582
- *
583
- * @param array $args An array of arguments to merge with defaults.
584
- * @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
585
- */
586
- $args = apply_filters( 'wpmem_login_form_args', $defaults, $arr['action'] );
587
-
588
- // Merge $args with defaults.
589
- $args = wp_parse_args( $args, $defaults );
590
-
591
- // Build the input rows.
592
- foreach ( $arr['inputs'] as $input ) {
593
- $label = '<label for="' . esc_attr( $input['tag'] ) . '">' . $input['name'] . '</label>';
594
- $field = wpmem_form_field( array(
595
- 'name' => $input['tag'],
596
- 'type' => $input['type'],
597
- 'class' => $input['class'],
598
- 'required' => true,
599
- ) );
600
- $field_before = ( $args['wrap_inputs'] ) ? '<div class="' . $this->sanitize_class( $input['div'] ) . '">' : '';
601
- $field_after = ( $args['wrap_inputs'] ) ? '</div>' : '';
602
- $rows[] = array(
603
- 'row_before' => $args['row_before'],
604
- 'label' => $label,
605
- 'field_before' => $field_before,
606
- 'field' => $field,
607
- 'field_after' => $field_after,
608
- 'row_after' => $args['row_after'],
609
- );
610
- }
611
-
612
- /**
613
- * Filter the array of form rows.
614
- *
615
- * This filter receives an array of the main rows in the form, each array element being
616
- * an array of that particular row's pieces. This allows making changes to individual
617
- * parts of a row without needing to parse through a string of HTML.
618
- *
619
- * @since 2.9.0
620
- * @since 3.2.6 Added $arr parameter so all settings are passed.
621
- *
622
- * @param array $rows An array containing the form rows.
623
- * @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
624
- * @param array $arr An array containing all of the form settings.
625
- */
626
- $rows = apply_filters( 'wpmem_login_form_rows', $rows, $arr['action'], $arr );
627
-
628
- // Put the rows from the array into $form.
629
- $form = '';
630
- foreach ( $rows as $row_item ) {
631
- $row = ( $row_item['row_before'] != '' ) ? $row_item['row_before'] . $args['n'] . $row_item['label'] . $args['n'] : $row_item['label'] . $args['n'];
632
- $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'];
633
- $row .= ( $row_item['row_after'] != '' ) ? $row_item['row_after'] . $args['n'] : '';
634
- $form.= $row;
635
- }
636
-
637
- // Handle outside elements added to the login form (currently ONLY for login).
638
- if ( 'login' == $arr['action'] && $args['login_form_action'] ) {
639
- ob_start();
640
- /** This action is documented in wp-login.php */
641
- do_action( 'login_form' );
642
- $add_to_form = ob_get_contents();
643
- ob_end_clean();
644
- $form.= $add_to_form;
645
- }
646
-
647
- // Build hidden fields, filter, and add to the form.
648
- $hidden = wpmem_create_formfield( 'redirect_to', 'hidden', esc_url( $args['redirect_to'] ) ) . $args['n'];
649
- $hidden = $hidden . wpmem_create_formfield( 'a', 'hidden', $arr['action'] ) . $args['n'];
650
- $hidden = ( $arr['action'] != 'login' ) ? $hidden . wpmem_create_formfield( 'formsubmit', 'hidden', '1' ) : $hidden;
651
-
652
- /**
653
- * Filter the hidden field HTML.
654
- *
655
- * @since 2.9.0
656
- *
657
- * @param string $hidden The generated HTML of hidden fields.
658
- * @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
659
- */
660
- $form = $form . apply_filters( 'wpmem_login_hidden_fields', $hidden, $arr['action'] );
661
-
662
- // Build the buttons, filter, and add to the form.
663
- if ( $arr['action'] == 'login' ) {
664
- $args['remember_check'] = ( $args['remember_check'] ) ? $args['t'] . wpmem_create_formfield( 'rememberme', 'checkbox', 'forever' ) . '&nbsp;' . '<label for="rememberme">' . $wpmem->get_text( 'remember_me' ) . '</label>&nbsp;&nbsp;' . $args['n'] : '';
665
- $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'];
666
- } else {
667
- $buttons = '<input type="submit" name="Submit" value="' . esc_attr( $arr['button_text'] ) . '" class="' . $this->sanitize_class( $args['button_class'] ) . '" />' . $args['n'];
668
- }
669
-
670
- /**
671
- * Filter the HTML for form buttons.
672
- *
673
- * The string includes the buttons, as well as the before/after wrapper elements.
674
- *
675
- * @since 2.9.0
676
- *
677
- * @param string $buttons The generated HTML of the form buttons.
678
- * @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
679
- */
680
- $form = $form . apply_filters( 'wpmem_login_form_buttons', $args['buttons_before'] . $args['n'] . $buttons . $args['buttons_after'] . $args['n'], $arr['action'] );
681
-
682
- $links_array = array(
683
- 'forgot' => array(
684
- 'tag' => 'forgot',
685
- 'link' => add_query_arg( 'a', 'pwdreset', $wpmem->user_pages['profile'] ),
686
- 'page' => 'profile',
687
- 'action' => 'login',
688
- ),
689
- 'register' => array(
690
- 'tag' => 'reg',
691
- 'link' => $wpmem->user_pages['register'],
692
- 'page' => 'register',
693
- 'action' => 'login',
694
- ),
695
- 'username' => array(
696
- 'tag' => 'username',
697
- 'link' => add_query_arg( 'a', 'getusername', $wpmem->user_pages['profile'] ),
698
- 'page' => 'profile',
699
- 'action' => 'pwdreset',
700
- ),
701
- );
702
- foreach ( $links_array as $key => $value ) {
703
- $tag = $value['tag'];
704
- if ( ( $wpmem->user_pages[ $value['page'] ] || 'members' == $page ) && $value['action'] == $arr['action'] ) {
705
- /**
706
- * Filters register, forgot password, and forgot username links.
707
- *
708
- * @since 2.8.0
709
- * @since 3.1.7 Combined all to a single process.
710
- * @since 3.2.5 Added $tag parameter.
711
- *
712
- * @param string The raw link.
713
- * @param string $tag forgot|reg|pwdreset|username.
714
- */
715
- $link = apply_filters( "wpmem_{$tag}_link", $value['link'], $tag );
716
- $str = $wpmem->get_text( "{$key}_link_before" ) . '<a href="' . esc_url( $link ) . '">' . $wpmem->get_text( "{$key}_link" ) . '</a>';
717
- $link_str = $args['link_before'];
718
- $link_str.= ( '' != $args['link_span_before'] ) ? sprintf( $args['link_span_before'], $key ) : '';
719
- /**
720
- * Filters the register, forgot password, and forgot username links HTML.
721
- *
722
- * @since 2.9.0
723
- * @since 3.0.9 Added $link parameter.
724
- * @since 3.1.7 Combined all to a single process.
725
- * @since 3.2.5 Added $tag parameter.
726
- *
727
- * @param string $str The link HTML.
728
- * @param string $link The link.
729
- * @param string $tag forgot|reg|pwdreset.
730
- */
731
- $link_str.= apply_filters( "wpmem_{$tag}_link_str", $str, $link, $tag );
732
- $link_str.= ( '' != $args['link_span_after'] ) ? $args['link_span_after'] : '';
733
- $link_str.= $args['link_after'] . $args['n'];
734
- /*
735
- * If this is the register link, and the current post type is set to
736
- * display the register form, and the current page is not the login
737
- * page, then do not add the register link, otherwise add the link.
738
- */
739
- if ( 'register' == $key ) {
740
- if ( ! isset( $wpmem->user_pages['register'] ) || '' == $wpmem->user_pages['register'] ) {
741
- $form = $form;
742
- } else {
743
- if ( isset( $wpmem->user_pages['login'] ) && '' != $wpmem->user_pages['login'] ) {
744
- $form = ( 1 == $wpmem->show_reg[ get_post_type( get_the_ID() ) ] && wpmem_current_url( true, false ) != wpmem_login_url() ) ? $form : $form . $link_str;
745
- } else {
746
- global $post;
747
- if ( has_shortcode( $post->post_content, 'wpmem_profile' ) ) {
748
- $form = $form;
749
- } else {
750
- $form = ( 1 == $wpmem->show_reg[ get_post_type( get_the_ID() ) ] && ! has_shortcode( $post->post_content, 'wpmem_form' ) ) ? $form : $form . $link_str;
751
- }
752
- }
753
- }
754
- } else {
755
- $form = $form . $link_str;
756
- }
757
- }
758
- }
759
-
760
- // Apply the heading.
761
- $form = $args['heading_before'] . $arr['heading'] . $args['heading_after'] . $args['n'] . $form;
762
-
763
- // Apply fieldset wrapper.
764
- $form = $args['fieldset_before'] . $args['n'] . $form . $args['fieldset_after'] . $args['n'];
765
-
766
- // Apply nonce.
767
- $form = wp_nonce_field( 'wpmem_shortform_nonce', '_wpmem_' . $arr['action'] . '_nonce', true, false ) . $args['n'] . $form;
768
-
769
- // Apply form wrapper.
770
- $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>';
771
-
772
- // Apply anchor.
773
- $form = '<a id="' . esc_attr( $arr['action'] ) . '"></a>' . $args['n'] . $form;
774
-
775
- // Apply main wrapper.
776
- $form = $args['main_div_before'] . $args['n'] . $form . $args['n'] . $args['main_div_after'];
777
-
778
- // Apply wpmem_txt wrapper.
779
- $form = $args['txt_before'] . $form . $args['txt_after'];
780
-
781
- // Remove line breaks.
782
- $form = ( $args['strip_breaks'] ) ? str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form ) : $form;
783
-
784
- /**
785
- * Filter the generated HTML of the entire form.
786
- *
787
- * @since 2.7.4
788
- *
789
- * @param string $form The HTML of the final generated form.
790
- * @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
791
- */
792
- $form = apply_filters( 'wpmem_login_form', $form, $arr['action'] );
793
-
794
- /**
795
- * Filter before the form.
796
- *
797
- * This rarely used filter allows you to stick any string onto the front of
798
- * the generated form.
799
- *
800
- * @since 2.7.4
801
- *
802
- * @param string $str The HTML to add before the form. Default null.
803
- * @param string $arr['action'] The action being performed by the form. login|pwdreset|pwdchange|getusername.
804
- */
805
- $form = apply_filters( 'wpmem_login_form_before', '', $arr['action'] ) . $form;
806
-
807
- return $form;
808
- } // End login_form.
809
-
810
- /**
811
- * Registration Form Builder.
812
- *
813
- * Outputs the form for new user registration and existing user edits.
814
- *
815
- * @since 2.5.1
816
- * @since 3.1.7 Moved to forms object class as register_form().
817
- * @since 3.2.5 use_nonce now obsolete (nonce is added automatically).
818
- * @since 3.3.0 $heading argument obsolete.
819
- * @since 3.3.3 Image field type now shows the preview image when "choose file" is clicked.
820
- *
821
- * @global object $wpmem The WP_Members object.
822
- * @global string $wpmem_regchk Used to determine if the form is in an error state.
823
- * @global array $userdata Used to get the user's registration data if they are logged in (user profile edit).
824
- * @param mixed $mixed (optional) String toggles between new registration ('new') and user profile edit ('edit'), or array containing settings arguments.
825
- * @return string $form The HTML for the entire form as a string.
826
- */
827
- function register_form( $mixed = 'new', $redirect_to = null ) {
828
-
829
- // Handle legacy use.
830
- if ( is_array( $mixed ) ) {
831
- $id = ( isset( $mixed['id'] ) ) ? $mixed['id'] : '';
832
- $tag = ( isset( $mixed['tag'] ) ) ? $mixed['tag'] : 'new';
833
- $heading = ( isset( $mixed['heading'] ) ) ? $mixed['heading'] : '';
834
- $redirect_to = ( isset( $mixed['redirect_to'] ) ) ? $mixed['redirect_to'] : '';
835
- } else {
836
- $id = 'default';
837
- $tag = $mixed;
838
- }
839
-
840
- global $wpmem, $wpmem_regchk, $userdata;
841
-
842
- // Set up default wrappers.
843
- $defaults = array(
844
-
845
- // Wrappers.
846
- 'heading_before' => '<legend>',
847
- 'heading_after' => '</legend>',
848
- 'fieldset_before' => '<fieldset>',
849
- 'fieldset_after' => '</fieldset>',
850
- 'main_div_before' => '<div id="wpmem_reg">',
851
- 'main_div_after' => '</div>',
852
- 'txt_before' => '',
853
- 'txt_after' => '',
854
- 'row_before' => '',
855
- 'row_after' => '',
856
- 'buttons_before' => '<div class="button_div">',
857
- 'buttons_after' => '</div>',
858
-
859
- // Classes & ids.
860
- 'form_id' => ( 'new' == $tag ) ? 'wpmem_register_form' : 'wpmem_profile_form',
861
- 'form_class' => 'form',
862
- 'button_id' => '',
863
- 'button_class' => 'buttons',
864
-
865
- // Required field tags and text.
866
- 'req_mark' => $wpmem->get_text( 'register_req_mark' ),
867
- 'req_label' => $wpmem->get_text( 'register_required' ),
868
- 'req_label_before' => '<div class="req-text">',
869
- 'req_label_after' => '</div>',
870
-
871
- // Buttons.
872
- 'show_clear_form' => false,
873
- 'clear_form' => $wpmem->get_text( 'register_clear' ),
874
- 'submit_register' => $wpmem->get_text( 'register_submit' ),
875
- 'submit_update' => $wpmem->get_text( 'profile_submit' ),
876
-
877
- // Other.
878
- 'post_to' => get_permalink(),
879
- 'strip_breaks' => true,
880
- 'wrap_inputs' => true,
881
- 'n' => "\n",
882
- 't' => "\t",
883
-
884
- );
885
-
886
- /**
887
- * Filter the default form arguments.
888
- *
889
- * This filter accepts an array of various elements to replace the form defaults. This
890
- * includes default tags, labels, text, and small items including various booleans.
891
- *
892
- * @since 2.9.0
893
- * @since 3.2.5 Added $id
894
- * @since 3.3.0 Passes $defaults as an argument.
895
- *
896
- * @param array An array of arguments to merge with defaults. Default null.
897
- * @param string $tag Toggle new registration or profile update. new|edit.
898
- * @param string $id An id for the form (optional).
899
- */
900
- $args = apply_filters( 'wpmem_register_form_args', $defaults, $tag, $id );
901
-
902
- // Merge $args with defaults.
903
- $args = wp_parse_args( $args, $defaults );
904
-
905
- // Get fields.
906
- $wpmem_fields = wpmem_fields( $tag );
907
-
908
- // Fields to skip for user profile update.
909
-
910
- if ( 'edit' == $tag ) {
911
- $pass_arr = array( 'username', 'password', 'confirm_password', 'password_confirm' );
912
- // Skips tos on user edit page, unless they haven't got a value for tos.
913
- if ( isset( $wpmem_fields['tos'] ) && ( $wpmem_fields['tos']['checked_value'] == get_user_meta( $userdata->ID, 'tos', true ) ) ) {
914
- $pass_arr[] = 'tos';
915
- }
916
- foreach ( $pass_arr as $pass ) {
917
- unset( $wpmem_fields[ $pass ] );
918
- }
919
- }
920
-
921
- /**
922
- * Filter the array of form fields.
923
- *
924
- * The form fields are stored in the WP options table as wpmembers_fields. This
925
- * filter can filter that array after the option is retreived before the fields
926
- * are parsed. This allows you to change the fields that may be used in the form
927
- * on the fly.
928
- *
929
- * @since 2.9.0
930
- * @deprecated 3.1.7 Use wpmem_fields instead.
931
- *
932
- * @param array The array of form fields.
933
- * @param string $tag Toggle new registration or profile update. new|edit.
934
- */
935
- $wpmem_fields = apply_filters( 'wpmem_register_fields_arr', $wpmem_fields, $tag );
936
-
937
- $hidden_rows = array();
938
- $form_has_file = false;
939
-
940
- // Loop through the remaining fields.
941
- foreach ( $wpmem_fields as $meta_key => $field ) {
942
-
943
- // Start with a clean row.
944
- $val = ''; $label = ''; $input = ''; $field_before = ''; $field_after = '';
945
-
946
- // If the field is set to display and we aren't skipping, construct the row.
947
- // if ( ( 'new' == $tag && $field['register'] ) || ( 'edit' == $tag && $field['profile'] ) ) { // @todo Wait for profile fix
948
- if ( $field['register'] ) {
949
-
950
- // Handle hidden fields
951
- if ( 'hidden' == $field['type'] ) {
952
- $do_row = false;
953
- $hidden_rows[ $meta_key ] = wpmem_form_field( array(
954
- 'name' => $meta_key,
955
- 'type' => $field['type'],
956
- 'value' => $field['value'],
957
- 'compare' => $valtochk,
958
- 'required' => $field['required'],
959
- ) );
960
- }
961
-
962
- // Label for all but TOS and hidden fields.
963
- if ( 'tos' != $meta_key && 'hidden' != $field['type'] ) {
964
-
965
- $class = ( $field['type'] == 'password' || $field['type'] == 'email' || $field['type'] == 'url' ) ? 'text' : $field['type'];
966
-
967
- $label = wpmem_form_label( array(
968
- 'meta_key' => $meta_key, //( 'username' == $meta_key ) ? 'user_login' : $meta_key,
969
- 'label' => __( $field['label'], 'wp-members' ),
970
- 'type' => $field['type'],
971
- 'class' => $class,
972
- 'required' => $field['required'],
973
- 'req_mark' => $args['req_mark']
974
- ) );
975
-
976
- }
977
-
978
- // Gets the field value for edit profile.
979
- if ( ( 'edit' == $tag ) && ( '' == $wpmem->regchk ) ) {
980
- switch ( $meta_key ) {
981
- case( 'description' ):
982
- case( 'textarea' == $field['type'] ):
983
- $val = get_user_meta( $userdata->ID, $meta_key, 'true' ); // esc_textarea() is run when field is created.
984
- break;
985
-
986
- case 'user_email':
987
- case 'confirm_email':
988
- $val = sanitize_email( $userdata->user_email );
989
- break;
990
-
991
- case 'user_url':
992
- $val = $userdata->user_url; // esc_url() is run when the field is created.
993
- break;
994
-
995
- case 'display_name':
996
- $val = sanitize_text_field( $userdata->display_name );
997
- break;
998
-
999
- default:
1000
- $val = sanitize_text_field( get_user_meta( $userdata->ID, $meta_key, 'true' ) );
1001
- break;
1002
- }
1003
-
1004
- } else {
1005
- if ( 'file' == $field['type'] ) {
1006
- $val = ( isset( $_FILES[ $meta_key ]['name'] ) ) ? sanitize_file_name( $_FILES[ $meta_key ]['name'] ) : '' ;
1007
- } else {
1008
- $val = ( isset( $_POST[ $meta_key ] ) ) ? $this->sanitize_field( $_POST[ $meta_key ], $field['type'] ) : '';
1009
- }
1010
- }
1011
-
1012
- // Does the tos field.
1013
- if ( 'tos' == $meta_key ) {
1014
-
1015
- // $val = sanitize_text_field( wpmem_get( $meta_key, '' ) );
1016
-
1017
- // Should be checked by default? and only if form hasn't been submitted.
1018
- $val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val;
1019
- $input = wpmem_form_field( array(
1020
- 'name' => $meta_key,
1021
- 'type' => $field['type'],
1022
- 'value' => $field['checked_value'],
1023
- 'compare' => $val,
1024
- 'required' => $field['required'],
1025
- ) );
1026
- $input = ( $field['required'] ) ? $input . $args['req_mark'] : $input;
1027
-
1028
- $input .= ' ' . $this->get_tos_link( $field, $tag );
1029
-
1030
- // In previous versions, the div class would end up being the same as the row before.
1031
- $field_before = ( $args['wrap_inputs'] ) ? '<div class="div_text">' : '';
1032
- $field_after = ( $args['wrap_inputs'] ) ? '</div>' : '';
1033
-
1034
- } elseif ( 'hidden' != $field['type'] ) {
1035
-
1036
- // For checkboxes.
1037
- if ( 'checkbox' == $field['type'] ) {
1038
- $valtochk = $val;
1039
- $val = $field['checked_value'];
1040
- // if it should it be checked by default (& only if form not submitted), then override above...
1041
- if ( $field['checked_default'] && ( ! $_POST && $tag != 'edit' ) ) {
1042
- $val = $valtochk = $field['checked_value'];
1043
- }
1044
- }
1045
-
1046
- // For dropdown select.
1047
- if ( 'select' == $field['type'] || 'radio' == $field['type'] || 'multiselect' == $field['type'] || 'multicheckbox' == $field['type'] || 'membership' == $field['type'] ) {
1048
- $valtochk = $val;
1049
- $val = $field['values'];
1050
- }
1051
-
1052
- if ( ! isset( $valtochk ) ) {
1053
- $valtochk = '';
1054
- }
1055
-
1056
- if ( ( 'file' == $field['type'] || 'image' == $field['type'] ) ) {
1057
-
1058
- $form_has_file = true;
1059
-
1060
- // Handle files differently for multisite vs. single install.
1061
- // @see: https://core.trac.wordpress.org/ticket/32145
1062
- if ( is_multisite() ) {
1063
- $attachment = get_post( $val );
1064
- $attachment_url = $attachment->guid;
1065
- } else {
1066
- $attachment_url = wp_get_attachment_url( $val );
1067
- }
1068
-
1069
- $empty_file = '<span class="description">' . __( 'None' ) . '</span>';
1070
- if ( 'edit' == $tag ) {
1071
- if ( 'file' == $field['type'] ) {
1072
- $input = ( $attachment_url ) ? '<a href="' . esc_url( $attachment_url ) . '" id="' . $meta_key . '_file">' . get_the_title( $val ) . '</a>' : $empty_file;
1073
- } else {
1074
- $input = ( $attachment_url ) ? '<img src="' . esc_url( $attachment_url ) . '" id="' . $meta_key . '_img" />' : $empty_file;
1075
- }
1076
- $input.= '<br />' . $wpmem->get_text( 'profile_upload' ) . '<br />';
1077
- } else {
1078
- if ( 'image' == $field['type'] ) {
1079
- $input = '<img src="" id="' . $meta_key . '_img" />';
1080
- }
1081
- }
1082
- $input.= wpmem_form_field( array(
1083
- 'name' => $meta_key,
1084
- 'type' => $field['type'],
1085
- 'value' => $val,
1086
- 'compare' => $valtochk,
1087
- 'file_types' => $field['file_types'],
1088
- ) );
1089
-
1090
- } else {
1091
-
1092
- // For all other input types.
1093
- $formfield_args = array(
1094
- 'name' => $meta_key, // ( 'username' == $meta_key ) ? 'user_login' : $meta_key,
1095
- 'type' => $field['type'],
1096
- 'value' => $val,
1097
- 'compare' => $valtochk,
1098
- //'class' => ( $class ) ? $class : 'textbox',
1099
- 'required' => $field['required'],
1100
- 'placeholder' => ( isset( $field['placeholder'] ) ) ? $field['placeholder'] : '',
1101
- 'pattern' => ( isset( $field['pattern'] ) ) ? $field['pattern'] : false,
1102
- 'title' => ( isset( $field['title'] ) ) ? $field['title'] : false,
1103
- 'min' => ( isset( $field['min'] ) ) ? $field['min'] : false,
1104
- 'max' => ( isset( $field['max'] ) ) ? $field['max'] : false,
1105
- 'rows' => ( isset( $field['rows'] ) ) ? $field['rows'] : false,
1106
- 'cols' => ( isset( $field['cols'] ) ) ? $field['cols'] : false,
1107
- 'file_types' => ( isset( $field['file_types'] ) ) ? $field['file_types'] : false,
1108
- );
1109
- if ( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
1110
- $formfield_args['delimiter'] = $field['delimiter'];
1111
- }
1112
- $input = wpmem_form_field( $formfield_args );
1113
-
1114
- }
1115
-
1116
- // Determine input wrappers.
1117
- $field_before = ( $args['wrap_inputs'] ) ? '<div class="div_' . $class . '">' : '';
1118
- $field_after = ( $args['wrap_inputs'] ) ? '</div>' : '';
1119
- }
1120
-
1121
- }
1122
-
1123
- // If the row is set to display, add the row to the form array.
1124
- if ( ( 'new' == $tag && $field['register'] ) || ( 'edit' == $tag && $field['profile'] ) ) {
1125
- //if ( $field['register'] && 'hidden' != $field['type'] ) {
1126
- if ( 'hidden' != $field['type'] ) {
1127
-
1128
- $values = '';
1129
- if ( 'multicheckbox' == $field['type'] || 'select' == $field['type'] || 'multiselect' == $field['type'] || 'radio' == $field['type'] ) {
1130
- $values = $val;
1131
- $val = $valtochk;
1132
- }
1133
-
1134
- $rows[ $meta_key ] = array(
1135
- 'meta' => $meta_key,
1136
- 'type' => $field['type'],
1137
- 'value' => $val,
1138
- 'values' => $values,
1139
- 'label_text' => __( $field['label'], 'wp-members' ),
1140
- 'row_before' => $args['row_before'],
1141
- 'label' => $label,
1142
- 'field_before' => $field_before,
1143
- 'field' => $input,
1144
- 'field_after' => $field_after,
1145
- 'row_after' => $args['row_after'],
1146
- );
1147
- }
1148
- }
1149
- }
1150
-
1151
- // If captcha is Really Simple CAPTCHA.
1152
- if ( 2 == $wpmem->captcha && 'edit' != $tag ) {
1153
- // Build the captcha.
1154
- $row = WP_Members_Captcha::rs_captcha( 'array' );
1155
- $rows['captcha'] = array(
1156
- 'meta' => '',
1157
- 'type' => 'text',
1158
- 'value' => '',
1159
- 'values' => '',
1160
- 'label_text' => $row['label_text'],
1161
- 'row_before' => $args['row_before'],
1162
- 'label' => $row['label'],
1163
- 'field_before' => ( $args['wrap_inputs'] ) ? '<div class="div_text">' : '',
1164
- 'field' => $row['img'] . $row['hidden'] . $row['field'],
1165
- 'field_after' => ( $args['wrap_inputs'] ) ? '</div>' : '',
1166
- 'row_after' => $args['row_after'],
1167
- );
1168
- }
1169
-
1170
- /**
1171
- * Filter the array of form rows.
1172
- *
1173
- * This filter receives an array of the main rows in the form, each array element being
1174
- * an array of that particular row's pieces. This allows making changes to individual
1175
- * parts of a row without needing to parse through a string of HTML.
1176
- *
1177
- * @since 2.9.0
1178
- * @since 3.0.9 Added $rows['label_text'].
1179
- * @since 3.1.0 Added $rows['key'].
1180
- * @since 3.1.6 Deprecated $rows['order'].
1181
- *
1182
- * @param array $rows {
1183
- * An array containing the form rows.
1184
- *
1185
- * @type string order Field display order. (deprecated as of 3.1.6)
1186
- * @type string meta Field meta tag (not used for display).
1187
- * @type string type Input field type (not used for display).
1188
- * @type string value Input field value (not used for display).
1189
- * @type string values Possible field values (dropdown, multiple select/check, radio).
1190
- * @type string label_text Raw text for the label (not used for display).
1191
- * @type string row_before Opening wrapper tag around the row.
1192
- * @type string label Label tag.
1193
- * @type string field_before Opening wrapper tag before the input tag.
1194
- * @type string field The field input tag.
1195
- * @type string field_after Closing wrapper tag around the input tag.
1196
- * @type string row_after Closing wrapper tag around the row.
1197
- * }
1198
- * @param string $tag Toggle new registration or profile update. new|edit.
1199
- */
1200
- $rows = apply_filters( 'wpmem_register_form_rows', $rows, $tag );
1201
-
1202
- // Make sure all keys are set just in case someone didn't return a proper array through the filter.
1203
- // @todo Merge this with the next foreach loop so we only have to foreach one time.
1204
- $row_keys = array( 'meta', 'type', 'value', 'values', 'label_text', 'row_before', 'label', 'field_before', 'field', 'field_after', 'row_after' );
1205
- foreach ( $rows as $meta_key => $row ) {
1206
- foreach ( $row_keys as $check_key ) {
1207
- $rows[ $meta_key ][ $check_key ] = ( isset( $rows[ $meta_key ][ $check_key ] ) ) ? $rows[ $meta_key ][ $check_key ] : '';
1208
- }
1209
- }
1210
-
1211
- // Put the rows from the array into $form.
1212
- $form = ''; $enctype = '';
1213
- foreach ( $rows as $row_item ) {
1214
- // Check form to see if we need multipart enctype.
1215
- $enctype = ( $row_item['type'] == 'file' || $row_item['type'] == 'image' ) ? "multipart/form-data" : $enctype;
1216
- // Assemble row pieces.
1217
- $row = ( $row_item['row_before'] != '' ) ? $row_item['row_before'] . $args['n'] . $row_item['label'] . $args['n'] : $row_item['label'] . $args['n'];
1218
- $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'];
1219
- $row .= ( $row_item['row_after'] != '' ) ? $row_item['row_after'] . $args['n'] : '';
1220
- $form.= $row;
1221
- }
1222
-
1223
- // Do recaptcha if enabled.
1224
- if ( ( 1 == $wpmem->captcha || 3 == $wpmem->captcha || 4 == $wpmem->captcha ) && $tag != 'edit' ) { // don't show on edit page!
1225
-
1226
- $row = WP_Members_Captcha::recaptcha();
1227
-
1228
- if ( 4 != $wpmem->captcha ) {
1229
- $row = '<div class="clear"></div><div class="captcha">' . $row . '</div>';
1230
- }
1231
-
1232
- // Add the captcha row to the form.
1233
- /**
1234
- * Filter the HTML for the CAPTCHA row.
1235
- *
1236
- * @since 2.9.0
1237
- *
1238
- * @param string The HTML for the entire row (includes HTML tags plus reCAPTCHA).
1239
- * @param string $tag Toggle new registration or profile update. new|edit.
1240
- */
1241
- $form.= apply_filters( 'wpmem_register_captcha_row', $args['row_before'] . $row . $args['row_after'], $tag );
1242
- }
1243
-
1244
- if ( 5 == $wpmem->captcha && 'edit' != $tag ) {
1245
- $row = WP_Members_Captcha::hcaptcha();
1246
- /** This filter is documented in /includes/class-wp-members-forms.php */
1247
- $form.= apply_filters( 'wpmem_register_captcha_row', $args['row_before'] . $row . $args['row_after'], $tag );
1248
- }
1249
-
1250
- // Create hidden fields.
1251
- $var = ( $tag == 'edit' ) ? 'update' : 'register';
1252
- $redirect_to = ( isset( $_REQUEST['redirect_to'] ) ) ? $_REQUEST['redirect_to'] : ( ( $redirect_to ) ? $redirect_to : get_permalink() );
1253
- $hidden_rows['_wpmem_a'] = '<input name="a" type="hidden" value="' . esc_attr( $var ) . '" />';
1254
- $hidden_rows['_wpmem_reg_page'] = '<input name="wpmem_reg_page" type="hidden" value="' . esc_url( get_permalink() ) . '" />';
1255
- if ( $redirect_to != get_permalink() ) {
1256
- $hidden_rows['_wpmem_redirect_to'] = '<input name="redirect_to" type="hidden" value="' . esc_url( $redirect_to ) . '" />';
1257
- }
1258
-
1259
- /**
1260
- * Filter the hidden form rows.
1261
- *
1262
- * @since 3.2.0
1263
- *
1264
- * @param array $hidden_rows
1265
- * @param string $tag
1266
- */
1267
- $hidden_rows = apply_filters( 'wpmem_register_hidden_rows', $hidden_rows, $tag );
1268
-
1269
- // Assemble hidden fields HTML.
1270
- $hidden = '';
1271
- foreach ( $hidden_rows as $hidden_row ) {
1272
- $hidden .= $hidden_row . $args['n'];
1273
- }
1274
-
1275
- /**
1276
- * Filter the hidden field HTML.
1277
- *
1278
- * @since 2.9.0
1279
- *
1280
- * @param string $hidden The generated HTML of hidden fields.
1281
- * @param string $tag Toggle new registration or profile update. new|edit.
1282
- */
1283
- $hidden = apply_filters( 'wpmem_register_hidden_fields', $hidden, $tag );
1284
-
1285
- // Add the hidden fields to the form.
1286
- $form.= $hidden;
1287
-
1288
- // Create buttons and wrapper.
1289
- $button_text = ( $tag == 'edit' ) ? $args['submit_update'] : $args['submit_register'];
1290
- $button_html = array(
1291
- 'reset' => ( $args['show_clear_form'] ) ? '<input name="reset" type="reset" value="' . esc_attr( $args['clear_form'] ) . '" class="' . $this->sanitize_class( $args['button_class'] ) . '" /> ' : '',
1292
- 'submit' => '<input name="submit" type="submit" value="' . esc_attr( $button_text ) . '" class="' . $this->sanitize_class( $args['button_class'] ) . '" />',
1293
- );
1294
- $buttons = $button_html['reset'] . $args['n'] . $button_html['submit'] . $args['n'];
1295
-
1296
- /**
1297
- * Filter the HTML for form buttons.
1298
- *
1299
- * The string passed through the filter includes the buttons, as well as the HTML wrapper elements.
1300
- *
1301
- * @since 2.9.0
1302
- * @since 3.2.6 Added $button_html parameter
1303
- *
1304
- * @param string $buttons The generated HTML of the form buttons.
1305
- * @param string $tag Toggle new registration or profile update. new|edit.
1306
- * @param array $button_html The individual button html.
1307
- */
1308
- $buttons = apply_filters( 'wpmem_register_form_buttons', $buttons, $tag, $button_html );
1309
-
1310
- // Add the buttons to the form.
1311
- $form.= $args['buttons_before'] . $args['n'] . $buttons . $args['buttons_after'] . $args['n'];
1312
-
1313
- // Add the required field notation to the bottom of the form.
1314
- $form.= $args['req_label_before'] . $args['req_label'] . $args['req_label_after'];
1315
-
1316
- // Apply the heading.
1317
- if ( 'edit' == $tag ) {
1318
- /**
1319
- * Filter the default heading in User Profile edit mode.
1320
- *
1321
- * @since 2.7.5
1322
- * @since 3.3.0 Moved into main registration function (from profile shortcode).
1323
- *
1324
- * @param string The default edit mode heading.
1325
- */
1326
- $heading = ( isset( $heading ) && '' != $heading ) ? $heading : apply_filters( 'wpmem_user_edit_heading', $wpmem->get_text( 'profile_heading' ) );
1327
- } else {
1328
- /**
1329
- * Filter the registration form heading.
1330
- *
1331
- * @since 2.8.2
1332
- *
1333
- * @param string $str
1334
- * @param string $tag Toggle new registration or profile update. new|edit.
1335
- */
1336
- $heading = ( isset( $heading ) && '' != $heading ) ? $heading : apply_filters( 'wpmem_register_heading', $wpmem->get_text( 'register_heading' ), $tag );
1337
- }
1338
- $form = $args['heading_before'] . $heading . $args['heading_after'] . $args['n'] . $form;
1339
-
1340
- // Apply fieldset wrapper.
1341
- $form = $args['fieldset_before'] . $args['n'] . $form . $args['n'] . $args['fieldset_after'];
1342
-
1343
- // Apply attribution if enabled.
1344
- $form = $form . $this->attribution();
1345
-
1346
- // Apply nonce. Nonce uses $tag value of the form processor, NOT the form builder.
1347
- $nonce = ( $tag == 'edit' ) ? 'update' : 'register';
1348
- $form = wp_nonce_field( 'wpmem_longform_nonce', '_wpmem_' . $nonce . '_nonce', true, false ) . $args['n'] . $form;
1349
-
1350
- // Apply form wrapper.
1351
- $enctype = ( $enctype == 'multipart/form-data' ) ? ' enctype="multipart/form-data"' : '';
1352
- $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>';
1353
-
1354
- // Apply anchor.
1355
- $form = '<a id="register"></a>' . $args['n'] . $form;
1356
-
1357
- // Apply main div wrapper.
1358
- $form = $args['main_div_before'] . $args['n'] . $form . $args['n'] . $args['main_div_after'] . $args['n'];
1359
-
1360
- // Apply wpmem_txt wrapper.
1361
- $form = $args['txt_before'] . $form . $args['txt_after'];
1362
-
1363
- // Remove line breaks if enabled for easier filtering later.
1364
- $form = ( $args['strip_breaks'] ) ? $this->strip_breaks( $form, $rows ) : $form; //str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form ) : $form;
1365
-
1366
- // If there is an image input type, include the following script.
1367
- $form = ( $form_has_file ) ? $form . '
1368
- <script>
1369
- var loadFile = function(event, clicked_id) {
1370
- var reader = new FileReader();
1371
- var the_id = clicked_id + "_img";
1372
- reader.onload = function() {
1373
- var output = document.getElementById(the_id);
1374
- output.src = reader.result;
1375
- };
1376
- reader.readAsDataURL(event.target.files[0]);
1377
- };
1378
- </script>' : $form;
1379
-
1380
- /**
1381
- * Filter the generated HTML of the entire form.
1382
- *
1383
- * @since 2.7.4
1384
- *
1385
- * @param string $form The HTML of the final generated form.
1386
- * @param string $tag Toggle new registration or profile update. new|edit.
1387
- * @param array $rows {
1388
- * An array containing the form rows.
1389
- *
1390
- * @type string order Field display order.
1391
- * @type string meta Field meta tag (not used for display).
1392
- * @type string type Input field type (not used for display).
1393
- * @type string value Input field value (not used for display).
1394
- * @type string values The possible values for the field (dropdown, multiple select/checkbox, radio group).
1395
- * @type string label_text Raw text for the label (not used for display).
1396
- * @type string row_before Opening wrapper tag around the row.
1397
- * @type string label Label tag.
1398
- * @type string field_before Opening wrapper tag before the input tag.
1399
- * @type string field The field input tag.
1400
- * @type string field_after Closing wrapper tag around the input tag.
1401
- * @type string row_after Closing wrapper tag around the row.
1402
- * }
1403
- * @param string $hidden The HTML string of hidden fields
1404
- */
1405
- $form = apply_filters( 'wpmem_register_form', $form, $tag, $rows, $hidden );
1406
-
1407
- /**
1408
- * Filter before the form.
1409
- *
1410
- * This rarely used filter allows you to stick any string onto the front of
1411
- * the generated form.
1412
- *
1413
- * @since 2.7.4
1414
- *
1415
- * @param string $str The HTML to add before the form. Default null.
1416
- * @param string $tag Toggle new registration or profile update. new|edit.
1417
- */
1418
- $form = apply_filters( 'wpmem_register_form_before', '', $tag ) . $form;
1419
-
1420
- // Return the generated form.
1421
- return $form;
1422
- } // End register_form().
1423
-
1424
- /**
1425
- * Strip line breaks from form.
1426
- *
1427
- * Function removes line breaks and tabs. Checks for textarea fields
1428
- * before stripping line breaks.
1429
- *
1430
- * @since 3.1.8
1431
- *
1432
- * @param string $form
1433
- * @param array $rows
1434
- * @return string $form
1435
- */
1436
- function strip_breaks( $form, $rows ) {
1437
- foreach( $rows as $key => $row ) {
1438
- if ( 'textarea' == $row['type'] ) {
1439
- $textareas[ $key ] = $row['field'];
1440
- }
1441
- }
1442
- $form = str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form );
1443
- if ( ! empty ( $textareas ) ) {
1444
- foreach ( $textareas as $textarea ) {
1445
- $stripped = str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $textarea );
1446
- $form = str_replace( $stripped, $textarea, $form );
1447
- }
1448
- }
1449
- return $form;
1450
- }
1451
-
1452
- /**
1453
- * Login Dialog.
1454
- *
1455
- * Loads the login form for user login.
1456
- *
1457
- * @since 1.8
1458
- * @since 3.1.4 Global $wpmem_regchk no longer needed.
1459
- * @since 3.2.0 Moved to forms class, renamed do_login_form().
1460
- * @todo $show is deprecated, post restricted message ($msg) handled externally.
1461
- *
1462
- * @global object $post The WordPress Post object.
1463
- * @global object $wpmem The WP_Members object.
1464
- * @param string $page If the form is being displayed in place of blocked content. Default: page.
1465
- * @param string $redirect_to Redirect URL. Default: null.
1466
- * @param string $show If the form is being displayed in place of blocked content. Default: show.
1467
- * @return string $str The generated html for the login form.
1468
- */
1469
- function do_login_form( $page = "page", $redirect_to = null, $show = 'show' ) {
1470
-
1471
- global $post, $wpmem;
1472
-
1473
- $msg = '';
1474
-
1475
- if ( 'page' == $page ) {
1476
- $msg = $this->add_restricted_msg();
1477
- }
1478
-
1479
- // Create the default inputs.
1480
- $default_inputs = array(
1481
- array(
1482
- 'name' => $wpmem->get_text( 'login_username' ),
1483
- 'type' => 'text',
1484
- 'tag' => 'log',
1485
- 'class' => 'username',
1486
- 'div' => 'div_text',
1487
- ),
1488
- array(
1489
- 'name' => $wpmem->get_text( 'login_password' ),
1490
- 'type' => 'password',
1491
- 'tag' => 'pwd',
1492
- 'class' => 'password',
1493
- 'div' => 'div_text',
1494
- ),
1495
- );
1496
-
1497
- /**
1498
- * Filter the array of login form fields.
1499
- *
1500
- * @since 2.9.0
1501
- * @deprecated 3.3.0 Use wpmem_login_form_defaults instead.
1502
- *
1503
- * @param array $default_inputs An array matching the elements used by default.
1504
- */
1505
- $default_inputs = apply_filters( 'wpmem_inc_login_inputs', $default_inputs );
1506
-
1507
- $defaults = array(
1508
- 'heading' => $wpmem->get_text( 'login_heading' ),
1509
- 'action' => 'login',
1510
- 'button_text' => $wpmem->get_text( 'login_button' ),
1511
- 'inputs' => $default_inputs,
1512
- 'redirect_to' => $redirect_to,
1513
- );
1514
-
1515
- /**
1516
- * Filter the arguments to override login form defaults.
1517
- *
1518
- * @since 2.9.0
1519
- * @deprecated 3.3.0 Use wpmem_login_form_defaults instead.
1520
- *
1521
- * @param array $args An array of arguments to use. Default null.
1522
- */
1523
- $args = apply_filters( 'wpmem_inc_login_args', '' );
1524
- $arr = wp_parse_args( $args, $defaults );
1525
-
1526
- /**
1527
- * Filter the arguments to override login form defaults.
1528
- *
1529
- * @since 3.3.0
1530
- *
1531
- * @param array $args {
1532
- * @type string $heading
1533
- * @type string $action
1534
- * @type string $button_text
1535
- * @type string $redirect_to
1536
- * @type array $inputs {
1537
- * @type string $name
1538
- * @type string $type
1539
- * @type string $tag
1540
- * @type string $class
1541
- * @type string $div
1542
- * }
1543
- * }
1544
- */
1545
- $arr = apply_filters( 'wpmem_login_form_defaults', $arr );
1546
-
1547
- return ( $show == 'show' ) ? $msg . wpmem_login_form( $page, $arr ) : $msg;
1548
- }
1549
-
1550
- /**
1551
- * Appends WP-Members registration fields to wp-login.php registration form.
1552
- *
1553
- * @since 2.8.7
1554
- * @since 3.1.1 Updated to support new (3.1.0) field types.
1555
- * @since 3.1.6 Updated to support new fields array. Added WC classes.
1556
- * @since 3.1.8 Added $process parameter.
1557
- * @since 3.3.0 Ported from wpmem_do_wp_register_form() in wp-registration.php.
1558
- *
1559
- * @global stdClass $wpmem
1560
- * @param string $process
1561
- */
1562
- function wp_register_form( $process = 'wp' ) {
1563
-
1564
- global $wpmem;
1565
- $wpmem_fields = wpmem_fields( $process );
1566
-
1567
- // Check if this is WooCommerce account page.
1568
- $is_woo = false;
1569
- if ( 'woo' == $process ) {
1570
- $is_woo = true;
1571
- } else {
1572
- if ( function_exists( 'is_account_page' ) ) {
1573
- $is_woo = ( is_account_page() ) ? true : $is_woo;
1574
- }
1575
- }
1576
-
1577
- if ( isset( $wpmem_fields ) && is_array( $wpmem_fields ) ) {
1578
-
1579
- unset( $wpmem_fields['username'] );
1580
-
1581
- if ( $is_woo ) {
1582
- // Woo has its own setting for password fields.
1583
- unset( $wpmem_fields['password'] );
1584
- unset( $wpmem_fields['confirm_password'] );
1585
- }
1586
-
1587
- foreach ( $wpmem_fields as $meta_key => $field ) {
1588
-
1589
- $req = ( $field['required'] ) ? ( ( $is_woo ) ? ' <span class="required">*</span>' : ' <span class="req">' . __( '(required)' ) . '</span>' ) : '';
1590
-
1591
- // File fields not yet supported for this form.
1592
- if ( $field['register'] && $meta_key != 'user_email' && $field['type'] != 'file' && $field['type'] != 'image' ) {
1593
-
1594
- if ( 'checkbox' == $field['type'] ) {
1595
-
1596
- if ( 'tos' == $meta_key ) {
1597
- $tos_link_text = $this->get_tos_link( $field, 'woo' );
1598
- }
1599
-
1600
- $label = ( 'tos' == $meta_key ) ? $tos_link_text : __( $field['label'], 'wp-members' );
1601
-
1602
- $val = ( isset( $_POST[ $meta_key ] ) ) ? esc_attr( $_POST[ $meta_key ] ) : '';
1603
- $val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val;
1604
-
1605
- $row_before = '<p class="wpmem-checkbox">';
1606
- $label = '<label for="' . $meta_key . '">' . $label . $req;
1607
- $input = wpmem_form_field( $meta_key, $field['type'], $field['checked_value'], $val );
1608
- $row_after = '</label></p>';
1609
-
1610
- } elseif ( 'hidden' == $field['type'] ) {
1611
-
1612
- // Handle hidden fields
1613
- $row_before = '';
1614
- $label = '';
1615
- $input = wpmem_form_field( array(
1616
- 'name' => $meta_key,
1617
- 'type' => $field['type'],
1618
- 'value' => $field['value'],
1619
- 'compare' => $valtochk,
1620
- 'required' => $field['required'],
1621
- ) );
1622
- $row_after = '';
1623
-
1624
- } else {
1625
-
1626
- $row_before = ( $is_woo ) ? '<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">' : '<p>';
1627
- $label = '<label for="' . $meta_key . '">' . __( $field['label'], 'wp-members' ) . $req . '<br />';
1628
-
1629
- // determine the field type and generate accordingly...
1630
-
1631
- switch ( $field['type'] ) {
1632
-
1633
- case( 'textarea' ):
1634
- $input = '<textarea name="' . $meta_key . '" id="' . $meta_key . '" class="textarea">';
1635
- $input.= ( isset( $_POST[ $meta_key ] ) ) ? esc_textarea( $_POST[ $meta_key ] ) : '';
1636
- $input.= '</textarea>';
1637
- break;
1638
-
1639
- case( 'select' ):
1640
- case( 'multiselect' ):
1641
- case( 'multicheckbox' ):
1642
- case( 'radio' ):
1643
- case( 'membership' ):
1644
- $row_before = ( $is_woo && ( 'select' == $field['type'] || 'multiselect' == $field['type'] || 'membership' == $field['type'] ) ) ? $row_before : '<p class="' . $field['type'] . '">';
1645
- $valtochk = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
1646
- $formfield_args = array(
1647
- 'name' => $meta_key,
1648
- 'type' => $field['type'],
1649
- 'value' => $field['values'],
1650
- 'compare' => $valtochk,
1651
- 'required' => $field['required'],
1652
- 'class' => ( $is_woo && ( 'select' == $field['type'] || 'multiselect' == $field['type'] || 'membership' == $field['type'] ) ) ? 'woocommerce-Input woocommerce-Input--text input-text' : $field['type'],
1653
- );
1654
- if ( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
1655
- $formfield_args['delimiter'] = $field['delimiter'];
1656
- }
1657
- $input = wpmem_form_field( $formfield_args );
1658
- break;
1659
-
1660
- case( 'file' ):
1661
- case( 'image' ):
1662
- // Field type not supported for this yet.
1663
- break;
1664
-
1665
- default:
1666
- $class = ( $is_woo ) ? 'woocommerce-Input woocommerce-Input--text input-text' : 'input';
1667
- //$input = '<input type="' . $field['type'] . '" name="' . $meta_key . '" id="' . $meta_key . '" class="' . $class . '" value="';
1668
- $formfield_args = array(
1669
- 'name' => $meta_key,
1670
- 'type' => $field['type'],
1671
- 'value' => $this->sanitize_field( wpmem_get( $meta_key, '' ), $field['type'] ),
1672
- 'compare' => ( isset( $field['compare'] ) ) ? $field['compare'] : '',
1673
- 'required' => $field['required'],
1674
- 'class' => $class,
1675
- 'placeholder' => ( isset( $field['placeholder'] ) ) ? $field['placeholder'] : '',
1676
- 'pattern' => ( isset( $field['pattern'] ) ) ? $field['pattern'] : false,
1677
- 'title' => ( isset( $field['title'] ) ) ? $field['title'] : false,
1678
- 'min' => ( isset( $field['min'] ) ) ? $field['min'] : false,
1679
- 'max' => ( isset( $field['max'] ) ) ? $field['max'] : false,
1680
- 'rows' => ( isset( $field['rows'] ) ) ? $field['rows'] : false,
1681
- 'cols' => ( isset( $field['cols'] ) ) ? $field['cols'] : false,
1682
- );
1683
- $input = wpmem_form_field( $formfield_args );
1684
- //$input.= ( isset( $_POST[ $meta_key ] ) ) ? esc_attr( $_POST[ $meta_key ] ) : '';
1685
- //$input.= '" size="25" />';
1686
- break;
1687
- }
1688
-
1689
- $row_after = '</label></p>';
1690
-
1691
- }
1692
-
1693
- // if the row is set to display, add the row to the form array
1694
- $rows[ $meta_key ] = array(
1695
- 'type' => $field['type'],
1696
- 'row_before' => $row_before,
1697
- 'label' => $label,
1698
- 'field' => $input,
1699
- 'row_after' => $row_after,
1700
- );
1701
- }
1702
- }
1703
-
1704
- // Do recaptcha if enabled.
1705
- if ( ! $is_woo && isset( $wpmem->captcha ) && $wpmem->captcha > 0 ) {
1706
-
1707
- $row_before = '<p>';
1708
- $row_after = '</p>';
1709
- $label = '';
1710
-
1711
- if ( in_array( $wpmem->captcha, array( 1, 3, 4 ) ) ) {
1712
- $captcha = WP_Members_Captcha::recaptcha();
1713
- } elseif ( 5 == $wpmem->captcha ) {
1714
- $captcha = WP_Members_Captcha::hcaptcha();
1715
- } elseif ( 2 == $wpmem->captcha ) {
1716
- $row = WP_Members_Captcha::rs_captcha( 'array' );
1717
- $label = $row['label']; //$row['label_text'];
1718
- $captcha = $row['img'] . $row['hidden'] . $row['field'];
1719
- }
1720
- if ( 4 == $wpmem->captcha ) {
1721
- $row_before = '';
1722
- $row_after = '';
1723
- }
1724
- }
1725
-
1726
- $rows['captcha'] = array(
1727
- 'type' => '',
1728
- 'row_before' => $row_before,
1729
- 'row_after' => $row_after,
1730
- 'label' => $label,
1731
- 'field' => $captcha,
1732
- );
1733
-
1734
- if ( isset( $rows ) && is_array( $rows ) ) {
1735
-
1736
- /**
1737
- * Filter the native registration form rows.
1738
- *
1739
- * @since 2.9.3.
1740
- *
1741
- * @param array $rows The custom rows added to the form.
1742
- */
1743
- $rows = apply_filters( 'wpmem_native_form_rows', $rows );
1744
-
1745
- foreach ( $rows as $row_item ) {
1746
- if ( $row_item['type'] == 'checkbox' ) {
1747
- echo $row_item['row_before'] . $row_item['field'] . $row_item['label'] . $row_item['row_after'];
1748
- } else {
1749
- echo $row_item['row_before'] . $row_item['label'] . $row_item['field'] . $row_item['row_after'];
1750
- }
1751
- }
1752
- }
1753
- }
1754
- }
1755
-
1756
-
1757
- /**
1758
- * Appends WP-Members registration fields to Users > Add New User screen.
1759
- *
1760
- * @since 2.9.0
1761
- * @since 3.1.1 Updated to support new (3.1.0) field types and user activation.
1762
- * @since 3.1.6 Updated to support new fields array.
1763
- * @since 3.3.0 Ported from wpmem_do_wp_newuser_form() in wp-registration.php.
1764
- *
1765
- * @global stdClass $wpmem
1766
- */
1767
- function wp_newuser_form() {
1768
-
1769
- global $wpmem;
1770
- echo '<table class="form-table"><tbody>';
1771
-
1772
- $wpmem_fields = wpmem_fields( 'add_new' );
1773
- $exclude = wpmem_get_excluded_meta( 'wp-register' );
1774
-
1775
- foreach ( $wpmem_fields as $meta_key => $field ) {
1776
-
1777
- if ( ! $field['native'] && ! in_array( $meta_key, $exclude ) ) {
1778
-
1779
- $req = ( $field['required'] ) ? ' <span class="description">' . __( '(required)' ) . '</span>' : '';
1780
-
1781
- echo '<tr>
1782
- <th scope="row">
1783
- <label for="' . $meta_key . '">' . __( $field['label'], 'wp-members' ) . $req . '</label>
1784
- </th>
1785
- <td>';
1786
-
1787
- // determine the field type and generate accordingly.
1788
-
1789
- switch ( $field['type'] ) {
1790
-
1791
- case( 'select' ):
1792
- $val = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
1793
- echo wpmem_create_formfield( $meta_key, $field['type'], $field['values'], $val );
1794
- break;
1795
-
1796
- case( 'textarea' ):
1797
- echo '<textarea name="' . $meta_key . '" id="' . $meta_key . '" class="textarea">';
1798
- echo ( isset( $_POST[ $meta_key ] ) ) ? esc_textarea( $_POST[ $meta_key ] ) : '';
1799
- echo '</textarea>';
1800
- break;
1801
-
1802
- case( 'checkbox' ):
1803
- $val = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
1804
- $val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val;
1805
- echo wpmem_create_formfield( $meta_key, $field['type'], $field['checked_value'], $val );
1806
- break;
1807
-
1808
- case( 'multiselect' ):
1809
- case( 'multicheckbox' ):
1810
- case( 'radio' ):
1811
- case( 'membership' );
1812
- $valtochk = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
1813
- $formfield_args = array(
1814
- 'name' => $meta_key,
1815
- 'type' => $field['type'],
1816
- 'value' => $field['values'],
1817
- 'compare' => $valtochk,
1818
- 'required' => $field['required'],
1819
- );
1820
- if ( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
1821
- $formfield_args['delimiter'] = $field['delimiter'];
1822
- }
1823
- echo $this->create_form_field( $formfield_args );
1824
- break;
1825
-
1826
- case( 'file' ):
1827
- case( 'image' ):
1828
- break;
1829
-
1830
- default:
1831
- $value = ( isset( $_POST[ $meta_key ] ) ) ? esc_attr( $_POST[ $meta_key ] ) : '';
1832
- echo '<input type="' . $field['type'] . '" name="' . $meta_key . '" id="' . $meta_key . '" class="input" value="' . $value . '" size="25" />';
1833
- break;
1834
- }
1835
-
1836
- echo '</td>
1837
- </tr>';
1838
-
1839
- }
1840
- }
1841
-
1842
- // If moderated registration is enabled, add checkbox to set user as active.
1843
- if ( 1 == $wpmem->mod_reg ) {
1844
- echo '<tr>
1845
- <th scope="row">
1846
- <label for="activate_user">' . __( 'Activate this user?', 'wp-members' ) . '</label>
1847
- </th>
1848
- <td>' . $this->create_form_field( array( 'name' => 'activate_user', 'type' => 'checkbox', 'value' => 1, 'compare' => '' ) ) . '</td>
1849
- </tr>';
1850
- }
1851
-
1852
- echo '</tbody></table>';
1853
-
1854
- }
1855
-
1856
- /**
1857
- * Create an attribution link in the form.
1858
- *
1859
- * @since 2.6.0
1860
- * @since 3.1.1 Updated to use new object setting.
1861
- * @since 3.3.0 Ported from wpmem_inc_attribution() in forms.php.
1862
- *
1863
- * @global object $wpmem
1864
- * @return string $str
1865
- */
1866
- function attribution() {
1867
-
1868
- global $wpmem;
1869
- $str = '
1870
- <div align="center">
1871
- <small>Powered by <a href="https://rocketgeek.com" target="_blank">WP-Members</a></small>
1872
- </div>';
1873
-
1874
- return ( 1 == $wpmem->attrib ) ? $str : '';
1875
- }
1876
-
1877
- /**
1878
- * Settings for building Short Form (login).
1879
- *
1880
- * Replaces individual legacy functions and filters for
1881
- * the short forms, combined into a single method.
1882
- *
1883
- * @since 3.3.0
1884
- *
1885
- * @global stdClass $post
1886
- * @global stdClass $wpmem
1887
- *
1888
- * @param string $form login|changepassword|resetpassword|forgotusername
1889
- * @return string $form
1890
- */
1891
- function do_shortform( $form, $page = "page", $redirect_to = null, $show = 'show' ) {
1892
-
1893
- global $post, $wpmem;
1894
-
1895
- $msg = '';
1896
-
1897
- if ( "login" == $form && "page" == $page ) {
1898
- $msg = $this->add_restricted_msg();
1899
- }
1900
-
1901
- $input_arrays = array(
1902
- 'login' => array(
1903
- array(
1904
- 'name' => $wpmem->get_text( 'login_username' ),
1905
- 'type' => 'text',
1906
- 'tag' => 'log',
1907
- 'class' => 'username',
1908
- 'div' => 'div_text',
1909
- ),
1910
- array(
1911
- 'name' => $wpmem->get_text( 'login_password' ),
1912
- 'type' => 'password',
1913
- 'tag' => 'pwd',
1914
- 'class' => 'password',
1915
- 'div' => 'div_text',
1916
- ),
1917
- ),
1918
- 'changepassword' => array(
1919
- array(
1920
- 'name' => $wpmem->get_text( 'pwdchg_password1' ),
1921
- 'type' => 'password',
1922
- 'tag' => 'pass1',
1923
- 'class' => 'password',
1924
- 'div' => 'div_text',
1925
- ),
1926
- array(
1927
- 'name' => $wpmem->get_text( 'pwdchg_password2' ),
1928
- 'type' => 'password',
1929
- 'tag' => 'pass2',
1930
- 'class' => 'password',
1931
- 'div' => 'div_text',
1932
- ),
1933
- ),
1934
- 'resetpassword' => array(
1935
- array(
1936
- 'name' => $wpmem->get_text( 'pwdreset_username' ),
1937
- 'type' => 'text',
1938
- 'tag' => 'user',
1939
- 'class' => 'username',
1940
- 'div' => 'div_text',
1941
- ),
1942
- array(
1943
- 'name' => $wpmem->get_text( 'pwdreset_email' ),
1944
- 'type' => 'text',
1945
- 'tag' => 'email',
1946
- 'class' => 'textbox',
1947
- 'div' => 'div_text',
1948
- ),
1949
- ),
1950
- 'forgotusername' => array(
1951
- array(
1952
- 'name' => $wpmem->get_text( 'username_email' ),
1953
- 'type' => 'text',
1954
- 'tag' => 'user_email',
1955
- 'class' => 'username',
1956
- 'div' => 'div_text',
1957
- ),
1958
- ),
1959
- );
1960
-
1961
- /**
1962
- * Filter the array of change password form fields.
1963
- *
1964
- * @since 2.9.0
1965
- * @deprecated 3.3.0 Use wpmem_{$form}_form_defaults instead.
1966
- *
1967
- * @param array $default_inputs An array matching the elements used by default.
1968
- */
1969
- $default_inputs = apply_filters( 'wpmem_inc_' . $form . '_inputs', $input_arrays[ $form ] );
1970
-
1971
- $form_arrays = array(
1972
- 'login' => array(
1973
- 'heading' => $wpmem->get_text( 'login_heading' ),
1974
- 'action' => 'login',
1975
- 'button_text' => $wpmem->get_text( 'login_button' ),
1976
- 'inputs' => $default_inputs,
1977
- 'redirect_to' => $redirect_to,
1978
- ),
1979
- 'changepassword' => array(
1980
- 'heading' => $wpmem->get_text( 'pwdchg_heading' ),
1981
- 'action' => 'pwdchange',
1982
- 'button_text' => $wpmem->get_text( 'pwdchg_button' ),
1983
- 'inputs' => $default_inputs,
1984
- ),
1985
- 'resetpassword' => array(
1986
- 'heading' => $wpmem->get_text( 'pwdreset_heading' ),
1987
- 'action' => 'pwdreset',
1988
- 'button_text' => $wpmem->get_text( 'pwdreset_button' ),
1989
- 'inputs' => $default_inputs,
1990
- ),
1991
- 'forgotusername' => array(
1992
- 'heading' => $wpmem->get_text( 'username_heading' ),
1993
- 'action' => 'getusername',
1994
- 'button_text' => $wpmem->get_text( 'username_button' ),
1995
- 'inputs' => $default_inputs,
1996
- ),
1997
- );
1998
-
1999
- /**
2000
- * Filter the arguments to override form defaults.
2001
- *
2002
- * @since 2.9.0
2003
- * @deprecated 3.3.0 Use wpmem_inc_{$form}_defaults instead.
2004
- *
2005
- * @param array $args An array of arguments to use. Default null. (login|changepassword|resetpassword|forgotusername)
2006
- */
2007
- $args = apply_filters( 'wpmem_inc_' . $form . '_args', '' );
2008
- $arr = wp_parse_args( $args, $form_arrays[ $form ] );
2009
-
2010
- /**
2011
- * Filter the arguments to override change password form defaults.
2012
- *
2013
- * @since 3.3.0
2014
- *
2015
- * @param array $args An array of arguments to use. Default null. (login|changepassword|resetpassword|forgotusername)
2016
- */
2017
- $arr = apply_filters( 'wpmem_' . $form . '_form_defaults', $arr );
2018
-
2019
- return ( $show == 'show' ) ? $msg . $this->login_form( $page, $arr ) : $msg;
2020
- }
2021
-
2022
- /**
2023
- * Applies the post restricted message above the short form.
2024
- *
2025
- * @since 3.3.0
2026
- *
2027
- * @global stdClass $wpmem
2028
- *
2029
- * @return string $str The generated message.
2030
- */
2031
- private function add_restricted_msg() {
2032
-
2033
- global $wpmem;
2034
-
2035
- $str = '';
2036
-
2037
- if ( $wpmem->regchk != "success" ) {
2038
-
2039
- $dialogs = get_option( 'wpmembers_dialogs' );
2040
-
2041
- // This shown above blocked content.
2042
- $msg = $wpmem->get_text( 'restricted_msg' );
2043
- $msg = ( $dialogs['restricted_msg'] == $msg ) ? $msg : __( stripslashes( $dialogs['restricted_msg'] ), 'wp-members' );
2044
- $str = '<div id="wpmem_restricted_msg"><p>' . $msg . '</p></div>';
2045
-
2046
- /**
2047
- * Filter the post restricted message.
2048
- *
2049
- * @since 2.7.3
2050
- * @since 3.2.0 Added raw message string and HTML as separate params.
2051
- *
2052
- * @param string $str The post restricted message with HTML.
2053
- * @param string $msg The raw message string.
2054
- * @param string The 'before' HTML wrapper.
2055
- * @param string The 'after' HTML wrapper.
2056
- */
2057
- $str = apply_filters( 'wpmem_restricted_msg', $str, $msg, '<div id="wpmem_restricted_msg"><p>', '</p></div>' );
2058
- }
2059
-
2060
- return $str;
2061
- }
2062
-
2063
- /**
2064
- * Wrapper for handing the default WP login form.
2065
- *
2066
- * @since 3.3.2
2067
- */
2068
- function wp_login_form( $args ) {
2069
-
2070
- return wp_login_form( $args );
2071
- }
2072
-
2073
- /**
2074
- * Generate TOS field with link.
2075
- *
2076
- * @since 3.3.5
2077
- *
2078
- * @param array $field
2079
- * @param string $tag
2080
- * @return string
2081
- */
2082
- function get_tos_link( $field, $tag = 'new' ) {
2083
- global $wpmem;
2084
- // Determine if TOS is a WP page or not.
2085
- $tos_content = stripslashes( get_option( 'wpmembers_tos' ) );
2086
- if ( has_shortcode( $tos_content, 'wpmem_tos' ) || has_shortcode( $tos_content, 'wp-members' ) ) {
2087
- $tos_link_url = do_shortcode( $tos_content );
2088
- $tos_link_tag = '<a href="' . esc_url( $tos_link_url ) . '" target="_blank">';
2089
- } else {
2090
- $tos_link_url = add_query_arg( 'tos', 'display' );
2091
- $tos_link_tag = "<a href=\"#\" onClick=\"window.open('" . $tos_link_url . "','tos');\">";
2092
- }
2093
-
2094
- /**
2095
- * Filter the TOS link.
2096
- *
2097
- * @since 3.2.6
2098
- *
2099
- * @param string $tos_link_tag
2100
- * @param string $tos_link_url
2101
- */
2102
- $tos_link_tag = apply_filters( 'wpmem_tos_link_tag', $tos_link_tag, $tos_link_url );
2103
-
2104
- /**
2105
- * Filter the TOS link text.
2106
- *
2107
- * @since 2.7.5
2108
- *
2109
- * @param string The link text.
2110
- * @param string $tag Toggle new registration or profile update. new|edit.
2111
- */
2112
- $tos_link_text = apply_filters( 'wpmem_tos_link_txt', $wpmem->get_text( 'register_tos' ), $tag );
2113
-
2114
- // If filtered value is not the default label, use that, otherwise use label.
2115
- // @note: if default changes, this check must change.
2116
- if ( __( 'Please indicate that you agree to the %s Terms of Service %s', 'wp-members' ) == $tos_link_text ) {
2117
- if ( __( 'TOS', 'wp-members' ) != $field['label'] && __( 'Terms of Service', 'wp-members' ) != $field['label'] ) {
2118
- $tos_link_text = $field['label'];
2119
- }
2120
- }
2121
-
2122
- // If tos string does not contain link identifiers (%s), wrap the whole string.
2123
- if ( ! strpos( $tos_link_text, '%s' ) ) {
2124
- $tos_link_text = '%s' . $tos_link_text . '%s';
2125
- }
2126
-
2127
- return sprintf( $tos_link_text, $tos_link_tag, '</a>' );
2128
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2129
  } // 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
+ * Sets the registration fields.
28
+ *
29
+ * @since 3.0.0
30
+ * @since 3.1.5 Added $form argument.
31
+ * @since 3.3.0 Added $tag argument.
32
+ *
33
+ * @global stdClass $wpmem
34
+ * @param string $tag
35
+ * @param string $form The form being generated.
36
+ */
37
+ function load_fields( $tag = 'new', $form = 'default' ) {
38
+
39
+ global $wpmem;
40
+
41
+ // Get stored fields settings.
42
+ $fields = get_option( 'wpmembers_fields' );
43
+
44
+ // Validate fields settings.
45
+ if ( ! isset( $fields ) || empty( $fields ) ) {
46
+ // Update settings.
47
+ $fields = array( array( 10, 'Email', 'user_email', 'email', 'y', 'y', 'y', 'profile'=>true ) );
48
+ }
49
+
50
+ // Add new field array keys
51
+ foreach ( $fields as $key => $val ) {
52
+
53
+ // Key fields with meta key.
54
+ $meta_key = $val[2];
55
+
56
+ // Old format, new key.
57
+ foreach ( $val as $subkey => $subval ) {
58
+ $wpmem->fields[ $meta_key ][ $subkey ] = $subval;
59
+ }
60
+
61
+ // Setup field properties.
62
+ $wpmem->fields[ $meta_key ]['label'] = $val[1];
63
+ $wpmem->fields[ $meta_key ]['type'] = $val[3];
64
+ $wpmem->fields[ $meta_key ]['register'] = ( 'y' == $val[4] ) ? true : false;
65
+ $wpmem->fields[ $meta_key ]['required'] = ( 'y' == $val[5] ) ? true : false;
66
+ $wpmem->fields[ $meta_key ]['profile'] = ( 'y' == $val[4] ) ? true : false;// ( isset( $val['profile'] ) ) ? $val['profile'] : true ; // // @todo Wait for profile fix
67
+ $wpmem->fields[ $meta_key ]['native'] = ( 'y' == $val[6] ) ? true : false;
68
+
69
+ // Certain field types have additional properties.
70
+ switch ( $val[3] ) {
71
+
72
+ case 'checkbox':
73
+ $wpmem->fields[ $meta_key ]['checked_value'] = $val[7];
74
+ $wpmem->fields[ $meta_key ]['checked_default'] = ( 'y' == $val[8] ) ? true : false;
75
+ $wpmem->fields[ $meta_key ]['checkbox_label'] = ( isset( $val['checkbox_label'] ) ) ? $val['checkbox_label'] : 0;
76
+ break;
77
+
78
+ case 'select':
79
+ case 'multiselect':
80
+ case 'multicheckbox':
81
+ case 'radio':
82
+ case 'membership':
83
+ if ( 'membership' == $val[3] ) {
84
+ $val[7] = array( __( 'Choose membership', 'wp-members' ) . '|' );
85
+ foreach( $wpmem->membership->products as $membership_key => $membership_value ) {
86
+ $val[7][] = $membership_value['title'] . '|' . $membership_key;
87
+ }
88
+ }
89
+ // Correct a malformed value (if last value is empty due to a trailing comma).
90
+ if ( '' == end( $val[7] ) ) {
91
+ array_pop( $val[7] );
92
+ $wpmem->fields[ $meta_key ][7] = $val[7];
93
+ }
94
+ $wpmem->fields[ $meta_key ]['values'] = $val[7];
95
+ $wpmem->fields[ $meta_key ]['delimiter'] = ( isset( $val[8] ) ) ? $val[8] : '|';
96
+ $wpmem->fields[ $meta_key ]['options'] = array();
97
+ foreach ( $val[7] as $value ) {
98
+ $pieces = explode( '|', trim( $value ) );
99
+ if ( isset( $pieces[1] ) && $pieces[1] != '' ) {
100
+ $wpmem->fields[ $meta_key ]['options'][ $pieces[1] ] = $pieces[0];
101
+ }
102
+ }
103
+ break;
104
+
105
+ case 'file':
106
+ case 'image':
107
+ $wpmem->fields[ $meta_key ]['file_types'] = $val[7];
108
+ break;
109
+
110
+ case 'hidden':
111
+ $wpmem->fields[ $meta_key ]['value'] = $val[7];
112
+ break;
113
+
114
+ }
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Filter custom fields for localization.
120
+ *
121
+ * @since 3.3.9
122
+ *
123
+ * @param array $fields
124
+ */
125
+ function localize_fields( $fields ) {
126
+ if ( function_exists( 'wpmem_custom_translation_strings' ) ) {
127
+ $string_map = wpmem_custom_translation_strings( get_locale() );
128
+ foreach ( $string_map as $meta_key => $value ) {
129
+ if ( is_array( $value ) ) {
130
+ if ( isset( $fields[ $meta_key ]['placeholder'] ) && isset( $value['placeholder'] ) ) {
131
+ $fields[ $meta_key ]['placeholder'] = $string_map[ $meta_key ]['placeholder'];
132
+ }
133
+ if ( isset( $fields[ $meta_key ]['title'] ) && isset( $value['title'] ) ) {
134
+ $fields[ $meta_key ]['title'] = $string_map[ $meta_key ]['title'];
135
+ }
136
+ if ( isset( $fields[ $meta_key ]['label'] ) && isset( $value['label'] ) ) {
137
+ $fields[ $meta_key ]['label'] = $string_map[ $meta_key ]['label'];
138
+ }
139
+ } else {
140
+ $fields[ $meta_key ]['label'] = $string_map[ $meta_key ];
141
+ }
142
+ }
143
+ }
144
+ return $fields;
145
+ }
146
+
147
+ /**
148
+ * Get excluded meta fields.
149
+ *
150
+ * @since 3.0.0
151
+ * @since 3.3.3 Update $tag to match wpmem_fields() tags.
152
+ *
153
+ * @param string $tag A tag so we know where the function is being used.
154
+ * @return array The excluded fields.
155
+ */
156
+ function excluded_fields( $tag ) {
157
+
158
+ // Default excluded fields.
159
+ $excluded_fields = array( 'password', 'confirm_password', 'confirm_email', 'password_confirm', 'email_confirm' );
160
+
161
+ if ( 'update' == $tag || 'admin-profile' == $tag || 'user-profile' == $tag || 'wp-register' == $tag ) {
162
+ $excluded_fields[] = 'username';
163
+ }
164
+
165
+ if ( 'admin-profile' == $tag || 'user-profile' == $tag ) {
166
+ array_push( $excluded_fields, 'first_name', 'last_name', 'nickname', 'display_name', 'user_email', 'description', 'user_url' );
167
+
168
+ // If WooCommerce is used, remove these meta - WC already adds them in their own section.
169
+ if ( class_exists( 'woocommerce' ) ) {
170
+ array_push( $excluded_fields,
171
+ 'billing_first_name',
172
+ 'billing_last_name',
173
+ 'billing_company',
174
+ 'billing_address_1',
175
+ 'billing_address_2',
176
+ 'billing_city',
177
+ 'billing_postcode',
178
+ 'billing_country',
179
+ 'billing_state',
180
+ 'billing_email',
181
+ 'billing_phone',
182
+ 'shipping_first_name',
183
+ 'shipping_last_name',
184
+ 'shipping_company',
185
+ 'shipping_address_1',
186
+ 'shipping_address_2',
187
+ 'shipping_city',
188
+ 'shipping_postcode',
189
+ 'shipping_country',
190
+ 'shipping_state'
191
+ );
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Filter excluded meta fields.
197
+ *
198
+ * @since 2.9.3
199
+ * @since 3.0.0 Moved to new method in WP_Members Class.
200
+ * @since 3.3.3 Update $tag to match wpmem_fields() tags.
201
+ *
202
+ * @param array An array of the field meta names to exclude.
203
+ * @param string $tag A tag so we know where the function is being used.
204
+ */
205
+ $excluded_fields = apply_filters( 'wpmem_exclude_fields', $excluded_fields, $tag );
206
+
207
+ // Return excluded fields.
208
+ return $excluded_fields;
209
+ }
210
+
211
+ /**
212
+ * Creates form fields
213
+ *
214
+ * Creates various form fields and returns them as a string.
215
+ *
216
+ * @since 3.1.0
217
+ * @since 3.1.1 Added $delimiter.
218
+ * @since 3.1.2 Changed $valtochk to $compare.
219
+ * @since 3.1.6 Added $placeholder.
220
+ * @since 3.1.7 Added number type & $min, $max, $title and $pattern attributes.
221
+ * @since 3.2.0 Added $id argument.
222
+ * @since 3.2.4 Added radio group and multiple checkbox individual item labels.
223
+ *
224
+ * @global object $wpmem The WP_Members object class.
225
+ * @param array $args {
226
+ * @type string $id
227
+ * @type string $name
228
+ * @type string $type
229
+ * @type string $value
230
+ * @type string $compare
231
+ * @type string $class
232
+ * @type boolean $required
233
+ * @type string $delimiter
234
+ * @type string $placeholder
235
+ * @type string $pattern
236
+ * @type string $title
237
+ * @type string $min
238
+ * @type string $max
239
+ * @type string $rows Number of rows for a textarea (default:5).
240
+ * @type string $cols Number of columns for a textarea (default:20).
241
+ * }
242
+ * @return string $str The field returned as a string.
243
+ */
244
+ function create_form_field( $args ) {
245
+
246
+ global $wpmem;
247
+
248
+ // Set defaults for most possible $args.
249
+ $id = ( isset( $args['id'] ) ) ? esc_attr( $args['id'] ) : esc_attr( $args['name'] );
250
+ $name = esc_attr( $args['name'] );
251
+ $type = esc_attr( $args['type'] );
252
+ $value = ( isset( $args['value'] ) ) ? $args['value'] : '';
253
+ $compare = ( isset( $args['compare'] ) ) ? $args['compare'] : '';
254
+ $class = ( isset( $args['class'] ) ) ? $args['class'] : 'textbox';
255
+ $required = ( isset( $args['required'] ) ) ? $args['required'] : false;
256
+ $delimiter = ( isset( $args['delimiter'] ) ) ? $args['delimiter'] : '|';
257
+ $placeholder = ( isset( $args['placeholder'] ) ) ? $args['placeholder'] : false;
258
+ $pattern = ( isset( $args['pattern'] ) ) ? $args['pattern'] : false;
259
+ $title = ( isset( $args['title'] ) ) ? $args['title'] : false;
260
+ $file_types = ( isset( $args['file_types'] ) ) ? $args['file_types'] : false;
261
+
262
+ // Handle field creation by type.
263
+ switch ( $type ) {
264
+
265
+ /*
266
+ * Field types text|url|email|number|date are all handled essentially the
267
+ * same. The primary differences are CSS class (with a default fallback
268
+ * of 'textbox'), how values are escaped, and the application of min|max
269
+ * values for number fields.
270
+ */
271
+ case "text":
272
+ case "url":
273
+ case "email":
274
+ case "number":
275
+ case "date":
276
+ $class = ( 'textbox' == $class ) ? "textbox" : wpmem_sanitize_class( $class );
277
+ switch ( $type ) {
278
+ case 'url':
279
+ $value = esc_url( $value );
280
+ break;
281
+ case 'email':
282
+ $value = esc_attr( wp_unslash( $value ) );
283
+ break;
284
+ default:
285
+ $value = stripslashes( esc_attr( $value ) ); // @todo Could email and default be combined? Both seem to unslash and esc_attr().
286
+ break;
287
+ }
288
+ $required = ( $required ) ? ' required' : '';
289
+ $placeholder = ( $placeholder ) ? ' placeholder="' . esc_attr( __( $placeholder, 'wp-members' ) ) . '"' : '';
290
+ $title = ( $title ) ? ' title="' . esc_attr( __( $title, 'wp-members' ) ) . '"' : '';
291
+ $pattern = ( $pattern && 'number' != $type ) ? ' pattern="' . esc_attr( $pattern ) . '"' : '';
292
+ $min = ( isset( $args['min'] ) && $args['min'] != '' ) ? ' min="' . esc_attr( $args['min'] ) . '"' : '';
293
+ $max = ( isset( $args['max'] ) && $args['max'] != '' ) ? ' max="' . esc_attr( $args['max'] ). '"' : '';
294
+ $str = "<input name=\"$name\" type=\"$type\" id=\"$id\" value=\"$value\" class=\"$class\"$placeholder$title$pattern$min$max" . ( ( $required ) ? " required " : "" ) . " />";
295
+ break;
296
+
297
+ case "password":
298
+ $class = wpmem_sanitize_class( $class );
299
+ $placeholder = ( $placeholder ) ? ' placeholder="' . esc_attr( __( $placeholder, 'wp-members' ) ) . '"' : '';
300
+ $pattern = ( $pattern ) ? ' pattern="' . esc_attr( $pattern ) . '"' : '';
301
+ $title = ( $title ) ? ' title="' . esc_attr( __( $title, 'wp-members' ) ) . '"' : '';
302
+ $str = "<input name=\"$name\" type=\"$type\" id=\"$id\" class=\"$class\"$placeholder$title$pattern" . ( ( $required ) ? " required " : "" ) . " />";
303
+ break;
304
+
305
+ case "image":
306
+ case "file":
307
+ if ( $file_types ) {
308
+ $file_types = explode( '|', $file_types );
309
+ foreach( $file_types as $file_type ) {
310
+ $array[] = "." . $file_type;
311
+ }
312
+ $accept = ' accept="' . implode( ",", $array ) . '"';
313
+ } else {
314
+ $accept = '';
315
+ }
316
+ $class = ( 'textbox' == $class ) ? "file" : wpmem_sanitize_class( $class );
317
+ $str = "<input name=\"$name\" type=\"file\" id=\"$id\" value=\"" . esc_attr( $value ) . "\" class=\"$class\"$accept" . ( ( $required ) ? " required " : "" ) . ( ( 'image' == $type ) ? ' onchange="loadFile(event, this.id)"' : '' ) . ' />';
318
+ break;
319
+
320
+ case "checkbox":
321
+ $class = ( 'textbox' == $class ) ? "checkbox" : wpmem_sanitize_class( $class );
322
+ $str = "<input name=\"$name\" type=\"$type\" id=\"$id\" value=\"" . esc_attr( $value ) . "\"" . checked( $value, $compare, false ) . ( ( $required ) ? " required " : "" ) . " />";
323
+ break;
324
+
325
+ case "textarea":
326
+ $value = esc_textarea( stripslashes( $value ) ); // stripslashes( esc_textarea( $value ) );
327
+ $class = ( 'textbox' == $class ) ? "textarea" : wpmem_sanitize_class( $class );
328
+ $placeholder = ( $placeholder ) ? ' placeholder="' . esc_attr( __( $placeholder, 'wp-members' ) ) . '"' : '';
329
+ $rows = ( isset( $args['rows'] ) && $args['rows'] ) ? esc_attr( $args['rows'] ) : '5';
330
+ $cols = ( isset( $args['cols'] ) && $args['cols'] ) ? esc_attr( $args['cols'] ) : '20';
331
+ $str = "<textarea cols=\"$cols\" rows=\"$rows\" name=\"$name\" id=\"$id\" class=\"$class\"$placeholder" . ( ( $required ) ? " required " : "" ) . ">$value</textarea>";
332
+ break;
333
+
334
+ case "hidden":
335
+ $str = "<input name=\"$name\" type=\"$type\" value=\"" . esc_attr( $value ) . "\" />";
336
+ break;
337
+
338
+ case "option":
339
+ $str = "<option value=\"" . esc_attr( $value ) . "\" " . selected( $value, $compare, false ) . " >" . __( $name, 'wp-members' ) . "</option>";
340
+ break;
341
+
342
+ case "select":
343
+ case "multiselect":
344
+ case "membership":
345
+ $class = ( 'textbox' == $class && 'multiselect' != $type ) ? "dropdown" : $class;
346
+ $class = ( 'textbox' == $class && 'multiselect' == $type ) ? "multiselect" : $class;
347
+ $pname = ( 'multiselect' == $type ) ? $name . "[]" : $name;
348
+ $str = "<select name=\"$pname\" id=\"$id\" class=\"$class\"" . ( ( 'multiselect' == $type ) ? " multiple " : "" ) . ( ( $required ) ? " required " : "" ) . ">\n";
349
+ if ( 'membership' == $type ) {
350
+ $value = array( __( 'Choose membership', 'wp-members' ) . '|' );
351
+ foreach( $wpmem->membership->products as $membership_key => $membership_value ) {
352
+ $value[] = $membership_value['title'] . '|' . $membership_key;
353
+ }
354
+ }
355
+ foreach ( $value as $option ) {
356
+ $pieces = array_map( 'trim', explode( '|', $option ) );
357
+ if ( 'multiselect' == $type ) {
358
+ $chk = '';
359
+ $values = ( empty( $compare ) ) ? array() : ( is_array( $compare ) ? $compare : explode( $delimiter, $compare ) );
360
+ } else {
361
+ $chk = $compare;
362
+ $values = array();
363
+ }
364
+ if ( isset( $pieces[1] ) && '' != $pieces[1] ) {
365
+ $chk = ( ( isset( $pieces[2] ) && '' == $compare ) || in_array( $pieces[1], $values ) ) ? $pieces[1] : $chk;
366
+ } else {
367
+ $chk = 'not selected';
368
+ }
369
+ $pieces[1] = ( isset( $pieces[1] ) ) ? $pieces[1] : ''; // If someone skipped a pipe, treat it as empty.
370
+ $str = $str . "<option value=\"$pieces[1]\"" . selected( $pieces[1], $chk, false ) . ">" . esc_attr( __( $pieces[0], 'wp-members' ) ) . "</option>\n";
371
+ }
372
+ $str = $str . "</select>";
373
+ break;
374
+
375
+ case "multicheckbox":
376
+ $class = ( 'textbox' == $class ) ? "checkbox" : $class;
377
+ $str = '';
378
+ $num = 1;
379
+ foreach ( $value as $option ) {
380
+ $pieces = explode( '|', $option );
381
+ $values = ( empty( $compare ) ) ? array() : ( is_array( $compare ) ? $compare : explode( $delimiter, $compare ) );
382
+ $chk = ( isset( $pieces[2] ) && '' == $compare ) ? $pieces[1] : '';
383
+ if ( isset( $pieces[1] ) && '' != $pieces[1] ) {
384
+ $id_value = esc_attr( $id . '[' . $pieces[1] . ']' );
385
+ $label = wpmem_form_label( array( 'meta_key'=>$id_value, 'label'=>esc_html( __( $pieces[0], 'wp-members' ) ), 'type'=>'multicheckbox', 'id'=>$id_value ) );
386
+ $str = $str . wpmem_form_field( array(
387
+ 'id' => $id_value,
388
+ 'name' => $name . '[]',
389
+ 'type' => 'checkbox',
390
+ 'value' => $pieces[1],
391
+ 'compare' => ( in_array( $pieces[1], $values ) ) ? $pieces[1] : $chk,
392
+ ) ) . "&nbsp;" . $label . "<br />\n";
393
+ } else {
394
+ $str = $str . '<span class="div_multicheckbox_separator">' . esc_html( __( $pieces[0], 'wp-members' ) ) . "</span><br />\n";
395
+ }
396
+ }
397
+ break;
398
+
399
+ case "radio":
400
+ $class = ( 'textbox' == $class ) ? "radio" : wpmem_sanitize_class( $class );
401
+ $str = '';
402
+ $num = 1;
403
+ foreach ( $value as $option ) {
404
+ $pieces = explode( '|', $option );
405
+ $id_num = $id . '_' . $num;
406
+ if ( isset( $pieces[1] ) && '' != $pieces[1] ) {
407
+ $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 ) ) );
408
+ $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";
409
+ $num++;
410
+ } else {
411
+ $str = $str . '<span class="div_radio_separator">' . esc_html( __( $pieces[0], 'wp-members' ) ) . "</span><br />\n";
412
+ }
413
+ }
414
+ break;
415
+
416
+ }
417
+
418
+ return $str;
419
+ } // End create_form_field()
420
+
421
+ /**
422
+ * Create form label.
423
+ *
424
+ * @since 3.1.7
425
+ * @since 3.2.4 Added $id
426
+ *
427
+ * @param array $args {
428
+ * @type string $meta_key
429
+ * @type string $label
430
+ * @type string $type
431
+ * @type string $id (optional)
432
+ * @type string $class (optional)
433
+ * @type string $required (optional)
434
+ * @type string $req_mark (optional)
435
+ * }
436
+ * @return string $label
437
+ */
438
+ function create_form_label( $args ) {
439
+ global $wpmem;
440
+
441
+ $meta_key = $args['meta_key'];
442
+ $label = $args['label'];
443
+ $type = $args['type'];
444
+ $class = ( isset( $args['class'] ) ) ? $args['class'] : false;
445
+ $id = ( isset( $args['id'] ) ) ? $args['id'] : false;
446
+ $required = ( isset( $args['required'] ) ) ? $args['required'] : false;
447
+ $req_mark = ( isset( $args['req_mark'] ) ) ? $args['req_mark'] : false;
448
+
449
+ //$req_mark = ( ! $req_mark ) ? wpmem_get_text( 'register_req_mark' ) : '*';
450
+
451
+ if ( ! $class ) {
452
+ $class = ( $type == 'password' || $type == 'email' || $type == 'url' ) ? 'text' : $type;
453
+ }
454
+
455
+ $id = ( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
456
+
457
+ $label = '<label for="' . esc_attr( $meta_key ) . '"' . $id . ' class="' . wpmem_sanitize_class( $class ) . '">' . __( $label, 'wp-members' );
458
+ $label = ( $required ) ? $label . $req_mark : $label;
459
+ $label = $label . '</label>';
460
+
461
+ return $label;
462
+ }
463
+
464
+ /**
465
+ * Uploads file from the user.
466
+ *
467
+ * @since 3.1.0
468
+ *
469
+ * @param array $file
470
+ * @param int $user_id
471
+ * @return int|bool
472
+ */
473
+ function do_file_upload( $file = array(), $user_id = false ) {
474
+
475
+ // Filter the upload directory.
476
+ add_filter( 'upload_dir', array( &$this, 'file_upload_dir' ) );
477
+
478
+ // Set up user ID for use in upload process.
479
+ $this->file_user_id = ( $user_id ) ? $user_id : 0;
480
+
481
+ // Get WordPress file upload processing scripts.
482
+ require_once( ABSPATH . 'wp-admin/includes/file.php' );
483
+ require_once( ABSPATH . 'wp-admin/includes/media.php' );
484
+
485
+ $file_return = wp_handle_upload( $file, array( 'test_form' => false ) );
486
+
487
+ if ( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
488
+ return false;
489
+ } else {
490
+
491
+ $attachment = array(
492
+ 'post_mime_type' => $file_return['type'],
493
+ 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $file_return['file'] ) ),
494
+ 'post_content' => '',
495
+ 'post_status' => 'inherit',
496
+ 'guid' => $file_return['url'],
497
+ 'post_author' => ( $user_id ) ? $user_id : '',
498
+ );
499
+
500
+ $attachment_id = wp_insert_attachment( $attachment, $file_return['url'] );
501
+
502
+ require_once( ABSPATH . 'wp-admin/includes/image.php' );
503
+ $attachment_data = wp_generate_attachment_metadata( $attachment_id, $file_return['file'] );
504
+ wp_update_attachment_metadata( $attachment_id, $attachment_data );
505
+
506
+ if ( 0 < intval( $attachment_id ) ) {
507
+ // Returns an array with file information.
508
+ return $attachment_id;
509
+ }
510
+ }
511
+
512
+ return false;
513
+ } // End upload_file()
514
+
515
+ /**
516
+ * Sets the file upload directory.
517
+ *
518
+ * This is a filter function for upload_dir.
519
+ *
520
+ * @link https://codex.wordpress.org/Plugin_API/Filter_Reference/upload_dir
521
+ *
522
+ * @since 3.1.0
523
+ *
524
+ * @param array $param {
525
+ * The directory information for upload.
526
+ *
527
+ * @type string $path
528
+ * @type string $url
529
+ * @type string $subdir
530
+ * @type string $basedir
531
+ * @type string $baseurl
532
+ * @type string $error
533
+ * }
534
+ * @return array $param
535
+ */
536
+ function file_upload_dir( $param ) {
537
+
538
+ global $wpmem;
539
+
540
+ $user_id = ( isset( $this->file_user_id ) ) ? $this->file_user_id : null;
541
+
542
+ $args = array(
543
+ 'user_id' => $user_id,
544
+ 'wpmem_dir' => $wpmem->upload_base,
545
+ 'user_dir' => 'user_files/' . $user_id,
546
+ );
547
+
548
+ /**
549
+ * Filter the user directory elements.
550
+ *
551
+ * @since 3.1.0
552
+ *
553
+ * @param array $args
554
+ */
555
+ $args = apply_filters( 'wpmem_user_upload_dir', $args );
556
+
557
+ $param['subdir'] = '/' . $args['wpmem_dir'] . '/' . $args['user_dir'];
558
+ $param['path'] = $param['basedir'] . '/' . $args['wpmem_dir'] . '/' . $args['user_dir'];
559
+ $param['url'] = $param['baseurl'] . '/' . $args['wpmem_dir'] . '/' . $args['user_dir'];
560
+
561
+ return $param;
562
+ }
563
+
564
+ /**
565
+ * Login Form Builder.
566
+ *
567
+ * Builds the form used for login, change password, and reset password.
568
+ *
569
+ * @since 2.5.1
570
+ * @since 3.1.7 Moved to forms object class as login_form().
571
+ * @since 3.1.7 Added WP action login_form.
572
+ * @since 3.2.6 Added nonce to the short form.
573
+ *
574
+ * @param string $page
575
+ * @param array $arr {
576
+ * The elements needed to generate the form (login|reset password|forgotten password).
577
+ *
578
+ * @type string $heading Form heading text.
579
+ * @type string $action The form action (login|pwdchange|pwdreset|getusername).
580
+ * @type string $button_text Form submit button text.
581
+ * @type array $inputs {
582
+ * The form input values.
583
+ *
584
+ * @type array {
585
+ *
586
+ * @type string $name The field label.
587
+ * @type string $type Input type.
588
+ * @type string $tag Input tag name.
589
+ * @type string $class Input tag class.
590
+ * @type string $div Div wrapper class.
591
+ * }
592
+ * }
593
+ * @type string $redirect_to Optional. URL to redirect to.
594
+ * }
595
+ * @return string $form The HTML for the form as a string.
596
+ */
597
+ function login_form( $mixed, $arr = array() ) {
598
+
599
+ global $wpmem;
600
+
601
+ // Handle legacy use.
602
+ if ( is_array( $mixed ) ) {
603
+ $page = ( isset( $mixed['page'] ) ) ? $mixed['page'] : 'login';
604
+ $arr = $mixed;
605
+ } else {
606
+ $page = $mixed;
607
+ }
608
+
609
+ $action = ( ! isset( $arr['action'] ) ) ? 'login' : $arr['action'];
610
+
611
+ // Set up redirect_to @todo This could be done in a separate method usable by both login & reg.
612
+ $redirect_to = wpmem_get_redirect_to( $arr );
613
+
614
+ // Set up default wrappers.
615
+ // NOTE: DO NOT EDIT! There is a filter hook for this -> wpmem_login_form_args.
616
+ $defaults = array(
617
+
618
+ // wrappers
619
+ 'heading_before' => '<legend>',
620
+ 'heading_after' => '</legend>',
621
+ 'fieldset_before' => '<fieldset>',
622
+ 'fieldset_after' => '</fieldset>',
623
+ 'main_div_before' => '<div id="wpmem_login">',
624
+ 'main_div_after' => '</div>',
625
+ 'row_before' => '',
626
+ 'row_after' => '',
627
+ 'buttons_before' => '<div class="button_div">',
628
+ 'buttons_after' => '</div>',
629
+ 'link_before' => '<div class="link-text">',
630
+ 'link_after' => '</div>',
631
+ 'link_span_before' => '<span class="link-text-%s">',
632
+ 'link_span_after' => '</span>',
633
+
634
+ // classes & ids
635
+ 'form_id' => 'wpmem_' . $action . '_form',
636
+ 'form_class' => 'form',
637
+ 'button_id' => '',
638
+ 'button_class' => 'buttons',
639
+
640
+ // other
641
+ 'strip_breaks' => true,
642
+ 'wrap_inputs' => true,
643
+ 'remember_check' => true,
644
+ 'n' => "\n",
645
+ 't' => "\t",
646
+ 'redirect_to' => $redirect_to,
647
+ 'login_form_action' => true,
648
+
649
+ );
650
+
651
+ /**
652
+ * Filter the default form arguments.
653
+ *
654
+ * This filter accepts an array of various elements to replace the form defaults. This
655
+ * includes default tags, labels, text, and small items including various booleans.
656
+ *
657
+ * @since 2.9.0
658
+ * @since 3.3.0 Passes $defaults as an argument.
659
+ *
660
+ * @param array $args {
661
+ * An array of arguments to merge with defaults.
662
+ *
663
+ * @type string $heading_before Default: '<legend>'
664
+ * @type string $heading_after Default: '</legend>'
665
+ * @type string $fieldset_before Default: '<fieldset>'
666
+ * @type string $fieldset_after Default: '</fieldset>'
667
+ * @type string $main_div_before Default: '<div id="wpmem_login">'
668
+ * @type string $main_div_after Default: '</div>'
669
+ * @type string $row_before Default: ''
670
+ * @type string $row_after Default: ''
671
+ * @type string $buttons_before Default: '<div class="button_div">'
672
+ * @type string $buttons_after Default: '</div>'
673
+ * @type string $link_before Default: '<div class="link-text">'
674
+ * @type string $link_after Default: '</div>'
675
+ * @type string $link_span_before Default: '<span class="link-text-%s">'
676
+ * @type string $link_span_after Default: '</span>'
677
+ * @type string $form_id Default: 'wpmem_' . $action . '_form' (for example, wpmem_login_form or wpmem_pwdreset_form)
678
+ * @type string $form_class Default: 'form'
679
+ * @type string $button_id Default: ''
680
+ * @type string $button_class Default: buttons'
681
+ * @type boolean $strip_breaks Default: true (if true, strips all line breaks from the generated HTML)
682
+ * @type boolean $wrap_inputs Default: true (if true, includes main_div_before/after wrappers around input tags)
683
+ * @type boolean $remember_check Default: true
684
+ * @type string $n Default: "\n" (the new line character if breaks are not stripped (see $strip_breaks))
685
+ * @type string $t Default: "\t" (the line indent character if breaks are not stripped (see $strip_breaks))
686
+ * @type string $redirect_to Default: (the $redirec_to argument passed to the function)
687
+ * @type boolean $login_form_action Default: true (if true, adds the WP login_form action)
688
+ * }
689
+ * @param string $action The action being performed by the form. login|pwdreset|pwdchange|getusername.
690
+ */
691
+ $args = apply_filters( 'wpmem_login_form_args', $defaults, $action );
692
+
693
+ // Merge $args with defaults.
694
+ $args = wp_parse_args( $args, $defaults );
695
+
696
+ // Build the input rows.
697
+ foreach ( $arr['inputs'] as $input ) {
698
+ $label = '<label for="' . esc_attr( $input['tag'] ) . '">' . $input['name'] . '</label>';
699
+ $field = wpmem_form_field( array(
700
+ 'name' => $input['tag'],
701
+ 'type' => $input['type'],
702
+ 'class' => $input['class'],
703
+ 'required' => true,
704
+ ) );
705
+ $field_before = ( $args['wrap_inputs'] ) ? '<div class="' . wpmem_sanitize_class( $input['div'] ) . '">' : '';
706
+ $field_after = ( $args['wrap_inputs'] ) ? '</div>' : '';
707
+ $rows[] = array(
708
+ 'row_before' => $args['row_before'],
709
+ 'label' => $label,
710
+ 'field_before' => $field_before,
711
+ 'field' => $field,
712
+ 'field_after' => $field_after,
713
+ 'row_after' => $args['row_after'],
714
+ );
715
+ }
716
+
717
+ /**
718
+ * Filter the array of form rows.
719
+ *
720
+ * This filter receives an array of the main rows in the form, each array element being
721
+ * an array of that particular row's pieces. This allows making changes to individual
722
+ * parts of a row without needing to parse through a string of HTML.
723
+ *
724
+ * @since 2.9.0
725
+ * @since 3.2.6 Added $arr parameter so all settings are passed.
726
+ *
727
+ * @param array $rows An array containing the form rows.
728
+ * @param string $action The action being performed by the form. login|pwdreset|pwdchange|getusername.
729
+ * @param array $arr An array containing all of the form settings.
730
+ */
731
+ $rows = apply_filters( 'wpmem_login_form_rows', $rows, $action, $arr );
732
+
733
+ // Put the rows from the array into $form.
734
+ $form = '';
735
+ foreach ( $rows as $row_item ) {
736
+ $row = ( $row_item['row_before'] != '' ) ? $row_item['row_before'] . $args['n'] . $row_item['label'] . $args['n'] : $row_item['label'] . $args['n'];
737
+ $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'];
738
+ $row .= ( $row_item['row_after'] != '' ) ? $row_item['row_after'] . $args['n'] : '';
739
+ $form.= $row;
740
+ }
741
+
742
+ // Handle outside elements added to the login form (currently ONLY for login).
743
+ if ( 'login' == $action && $args['login_form_action'] ) {
744
+ ob_start();
745
+ /** This action is documented in wp-login.php */
746
+ do_action( 'login_form' );
747
+ $add_to_form = ob_get_contents();
748
+ ob_end_clean();
749
+ $form.= $add_to_form;
750
+ }
751
+
752
+ // Build hidden fields, filter, and add to the form.
753
+ $hidden[] = wpmem_form_field( array( 'name' => 'redirect_to', 'type' => 'hidden', 'value' => esc_url( $args['redirect_to'] ) ) ) . $args['n'];
754
+ $hidden[] = wpmem_form_field( array( 'name' => 'a', 'type' => 'hidden', 'value' => $action ) ) . $args['n'];
755
+ if ( $action != 'login' ) {
756
+ $hidden[] = wpmem_form_field( array( 'name' => 'formsubmit', 'type' => 'hidden', 'value' => '1' ) );
757
+ }
758
+
759
+ /**
760
+ * Filter hidden fields array.
761
+ *
762
+ * @since 3.4.0
763
+ *
764
+ * @param array $hidden
765
+ * @param string $action The action being performed by the form. login|pwdreset|pwdchange|getusername.
766
+ */
767
+ $hidden = apply_filters( 'wpmem_login_hidden_field_rows', $hidden, $action );
768
+
769
+ $hidden_field_string = '';
770
+ foreach ( $hidden as $field ) {
771
+ $hidden_field_string .= $field;
772
+ }
773
+
774
+ /**
775
+ * Filter the hidden field HTML.
776
+ *
777
+ * @since 2.9.0
778
+ *
779
+ * @param string $hidden The generated HTML of hidden fields.
780
+ * @param string $action The action being performed by the form. login|pwdreset|pwdchange|getusername.
781
+ */
782
+ $form = $form . apply_filters( 'wpmem_login_hidden_fields', $hidden_field_string, $action );
783
+
784
+ // Build the buttons, filter, and add to the form.
785
+ if ( $action == 'login' ) {
786
+ $args['remember_check'] = ( $args['remember_check'] ) ? $args['t'] . wpmem_form_field( array( 'name' => 'rememberme', 'type' => 'checkbox', 'value' => 'forever' ) ) . '&nbsp;' . '<label for="rememberme">' . wpmem_get_text( 'remember_me' ) . '</label>&nbsp;&nbsp;' . $args['n'] : '';
787
+ $buttons = $args['remember_check'] . $args['t'] . '<input type="submit" name="Submit" value="' . esc_attr( $arr['button_text'] ) . '" class="' . wpmem_sanitize_class( $args['button_class'] ) . '" />' . $args['n'];
788
+ } else {
789
+ $buttons = '<input type="submit" name="Submit" value="' . esc_attr( $arr['button_text'] ) . '" class="' . wpmem_sanitize_class( $args['button_class'] ) . '" />' . $args['n'];
790
+ }
791
+
792
+ /**
793
+ * Filter the HTML for form buttons.
794
+ *
795
+ * The string includes the buttons, as well as the before/after wrapper elements.
796
+ *
797
+ * @since 2.9.0
798
+ *
799
+ * @param string $buttons The generated HTML of the form buttons.
800
+ * @param string $action The action being performed by the form. login|pwdreset|pwdchange|getusername.
801
+ */
802
+ $form = $form . apply_filters( 'wpmem_login_form_buttons', $args['buttons_before'] . $args['n'] . $buttons . $args['buttons_after'] . $args['n'], $action );
803
+
804
+ $links_array = array(
805
+ 'forgot' => array(
806
+ 'tag' => 'forgot',
807
+ 'link' => add_query_arg( 'a', 'pwdreset', $wpmem->user_pages['profile'] ),
808
+ 'page' => 'profile',
809
+ 'action' => 'login',
810
+ ),
811
+ 'register' => array(
812
+ 'tag' => 'reg',
813
+ 'link' => $wpmem->user_pages['register'],
814
+ 'page' => 'register',
815
+ 'action' => 'login',
816
+ ),
817
+ 'username' => array(
818
+ 'tag' => 'username',
819
+ 'link' => add_query_arg( 'a', 'getusername', $wpmem->user_pages['profile'] ),
820
+ 'page' => 'profile',
821
+ 'action' => 'pwdreset',
822
+ ),
823
+ );
824
+ foreach ( $links_array as $key => $value ) {
825
+ $tag = $value['tag'];
826
+ if ( ( $wpmem->user_pages[ $value['page'] ] || 'profile' == $page ) && $value['action'] == $action ) {
827
+ /**
828
+ * Filters register, forgot password, and forgot username links.
829
+ *
830
+ * @since 2.8.0
831
+ * @since 3.1.7 Combined all to a single process.
832
+ * @since 3.2.5 Added $tag parameter.
833
+ *
834
+ * @param string The raw link.
835
+ * @param string $tag forgot|reg|pwdreset|username.
836
+ */
837
+ $link = apply_filters( "wpmem_{$tag}_link", $value['link'], $tag );
838
+ $str = wpmem_get_text( "{$key}_link_before" ) . '<a href="' . esc_url( $link ) . '">' . wpmem_get_text( "{$key}_link" ) . '</a>';
839
+ $link_str = $args['link_before'];
840
+ $link_str.= ( '' != $args['link_span_before'] ) ? sprintf( $args['link_span_before'], $key ) : '';
841
+ /**
842
+ * Filters the register, forgot password, and forgot username links HTML.
843
+ *
844
+ * @since 2.9.0
845
+ * @since 3.0.9 Added $link parameter.
846
+ * @since 3.1.7 Combined all to a single process.
847
+ * @since 3.2.5 Added $tag parameter.
848
+ *
849
+ * @param string $str The link HTML.
850
+ * @param string $link The link.
851
+ * @param string $tag forgot|reg|pwdreset.
852
+ */
853
+ $link_str.= apply_filters( "wpmem_{$tag}_link_str", $str, $link, $tag );
854
+ $link_str.= ( '' != $args['link_span_after'] ) ? $args['link_span_after'] : '';
855
+ $link_str.= $args['link_after'] . $args['n'];
856
+ /*
857
+ * If this is the register link, and the current post type is set to
858
+ * display the register form, and the current page is not the login
859
+ * page, then do not add the register link, otherwise add the link.
860
+ */
861
+ if ( 'register' == $key ) {
862
+ if ( ! isset( $wpmem->user_pages['register'] ) || '' == $wpmem->user_pages['register'] ) {
863
+ $form = $form;
864
+ } else {
865
+ if ( isset( $wpmem->user_pages['login'] ) && '' != $wpmem->user_pages['login'] ) {
866
+ $form = ( 1 == $wpmem->show_reg[ get_post_type( get_the_ID() ) ] && wpmem_current_url( true, false ) != wpmem_login_url() ) ? $form : $form . $link_str;
867
+ } else {
868
+ global $post;
869
+ if ( has_shortcode( $post->post_content, 'wpmem_profile' ) ) {
870
+ $form = $form;
871
+ } else {
872
+ $form = ( 1 == $wpmem->show_reg[ get_post_type( get_the_ID() ) ] && ! has_shortcode( $post->post_content, 'wpmem_form' ) ) ? $form : $form . $link_str;
873
+ }
874
+ }
875
+ }
876
+ } else {
877
+ $form = $form . $link_str;
878
+ }
879
+ }
880
+ }
881
+
882
+ // Apply the heading.
883
+ $form = $args['heading_before'] . $arr['heading'] . $args['heading_after'] . $args['n'] . $form;
884
+
885
+ // Apply fieldset wrapper.
886
+ $form = $args['fieldset_before'] . $args['n'] . $form . $args['fieldset_after'] . $args['n'];
887
+
888
+ // Apply nonce.
889
+ $form = wp_nonce_field( 'wpmem_shortform_nonce', '_wpmem_' . $action . '_nonce', true, false ) . $args['n'] . $form;
890
+
891
+ // Apply form wrapper.
892
+ $form = '<form action="' . esc_url( get_permalink() ) . '" method="POST" id="' . wpmem_sanitize_class( $args['form_id'] ) . '" class="' . wpmem_sanitize_class( $args['form_class'] ) . '">' . $args['n'] . $form . '</form>';
893
+
894
+ // Apply anchor.
895
+ $form = '<a id="' . esc_attr( $action ) . '"></a>' . $args['n'] . $form;
896
+
897
+ // Apply main wrapper.
898
+ $form = $args['main_div_before'] . $args['n'] . $form . $args['n'] . $args['main_div_after'];
899
+
900
+ // Remove line breaks.
901
+ $form = ( $args['strip_breaks'] ) ? str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form ) : $form;
902
+
903
+ /**
904
+ * Filter the generated HTML of the entire form.
905
+ *
906
+ * @since 2.7.4
907
+ *
908
+ * @param string $form The HTML of the final generated form.
909
+ * @param string $action The action being performed by the form. login|pwdreset|pwdchange|getusername.
910
+ */
911
+ $form = apply_filters( 'wpmem_login_form', $form, $action );
912
+
913
+ /**
914
+ * Filter before the form.
915
+ *
916
+ * This rarely used filter allows you to stick any string onto the front of
917
+ * the generated form.
918
+ *
919
+ * @since 2.7.4
920
+ *
921
+ * @param string $str The HTML to add before the form. Default null.
922
+ * @param string $action The action being performed by the form. login|pwdreset|pwdchange|getusername.
923
+ */
924
+ $form = apply_filters( 'wpmem_login_form_before', '', $action ) . $form;
925
+
926
+ return $form;
927
+ } // End login_form.
928
+
929
+ /**
930
+ * Registration Form Builder.
931
+ *
932
+ * Outputs the form for new user registration and existing user edits.
933
+ *
934
+ * @since 2.5.1
935
+ * @since 3.1.7 Moved to forms object class as register_form().
936
+ * @since 3.2.5 use_nonce now obsolete (nonce is added automatically).
937
+ * @since 3.3.0 $heading argument obsolete.
938
+ * @since 3.3.3 Image field type now shows the preview image when "choose file" is clicked.
939
+ *
940
+ * @global object $wpmem The WP_Members object.
941
+ * @global array $userdata Used to get the user's registration data if they are logged in (user profile edit).
942
+ * @param mixed $mixed (optional) String toggles between new registration ('new') and user profile edit ('edit'), or array containing settings arguments.
943
+ * @return string $form The HTML for the entire form as a string.
944
+ */
945
+ function register_form( $mixed = 'new', $redirect_to = null ) {
946
+
947
+ /*
948
+ * Removes the action to load form elements for the WP registration
949
+ * form. Otherwise, when the register_form action is fired in this
950
+ * form, we'd get a duplication of all custom fields.
951
+ */
952
+ remove_action( 'register_form', 'wpmem_wp_register_form' );
953
+
954
+ // Handle legacy use.
955
+ if ( is_array( $mixed ) ) {
956
+ $id = ( isset( $mixed['id'] ) ) ? $mixed['id'] : '';
957
+ $tag = ( isset( $mixed['tag'] ) ) ? $mixed['tag'] : 'new';
958
+ $heading = ( isset( $mixed['heading'] ) ) ? $mixed['heading'] : '';
959
+ $redirect_to = ( isset( $mixed['redirect_to'] ) ) ? $mixed['redirect_to'] : '';
960
+ $fields = ( isset( $mixed['fields'] ) ) ? $mixed['fields'] : false;
961
+ } else {
962
+ $id = 'default';
963
+ $tag = $mixed;
964
+ }
965
+
966
+ global $wpmem, $userdata;
967
+
968
+ // Set up default wrappers.
969
+ $defaults = array(
970
+
971
+ // Wrappers.
972
+ 'heading_before' => '<legend>',
973
+ 'heading_after' => '</legend>',
974
+ 'fieldset_before' => '<fieldset>',
975
+ 'fieldset_after' => '</fieldset>',
976
+ 'main_div_before' => '<div id="wpmem_reg">',
977
+ 'main_div_after' => '</div>',
978
+ 'row_before' => '',
979
+ 'row_after' => '',
980
+ 'buttons_before' => '<div class="button_div">',
981
+ 'buttons_after' => '</div>',
982
+
983
+ // Classes & ids.
984
+ 'form_id' => ( 'new' == $tag ) ? 'wpmem_register_form' : 'wpmem_profile_form',
985
+ 'form_class' => 'form',
986
+ 'button_id' => '',
987
+ 'button_class' => 'buttons',
988
+
989
+ // Required field tags and text.
990
+ 'req_mark' => wpmem_get_text( 'register_req_mark' ),
991
+ 'req_label' => wpmem_get_text( 'register_required' ),
992
+ 'req_label_before' => '<div class="req-text">',
993
+ 'req_label_after' => '</div>',
994
+
995
+ // Buttons.
996
+ 'show_clear_form' => false,
997
+ 'clear_form' => wpmem_get_text( 'register_clear' ),
998
+ 'submit_register' => wpmem_get_text( 'register_submit' ),
999
+ 'submit_update' => wpmem_get_text( 'profile_submit' ),
1000
+
1001
+ // Other.
1002
+ 'post_to' => get_permalink(),
1003
+ 'strip_breaks' => true,
1004
+ 'wrap_inputs' => true,
1005
+ 'n' => "\n",
1006
+ 't' => "\t",
1007
+
1008
+ 'register_form_action' => true,
1009
+
1010
+ );
1011
+
1012
+ /**
1013
+ * Filter the default form arguments.
1014
+ *
1015
+ * This filter accepts an array of various elements to replace the form defaults. This
1016
+ * includes default tags, labels, text, and small items including various booleans.
1017
+ *
1018
+ * @since 2.9.0
1019
+ * @since 3.2.5 Added $id
1020
+ * @since 3.3.0 Passes $defaults as an argument.
1021
+ *
1022
+ * @param array An array of arguments to merge with defaults. Default null.
1023
+ * @param string $tag Toggle new registration or profile update. new|edit.
1024
+ * @param string $id An id for the form (optional).
1025
+ */
1026
+ $args = apply_filters( 'wpmem_register_form_args', $defaults, $tag, $id );
1027
+
1028
+ // Merge $args with defaults.
1029
+ $args = wp_parse_args( $args, $defaults );
1030
+
1031
+ // Get fields.
1032
+ $wpmem_fields = wpmem_fields( $tag );
1033
+
1034
+ // Fields to skip for user profile update.
1035
+
1036
+ if ( 'edit' == $tag ) {
1037
+ $pass_arr = array( 'username', 'password', 'confirm_password', 'password_confirm' );
1038
+ // Skips tos on user edit page, unless they haven't got a value for tos.
1039
+ if ( isset( $wpmem_fields['tos'] ) && ( $wpmem_fields['tos']['checked_value'] == get_user_meta( $userdata->ID, 'tos', true ) ) ) {
1040
+ $pass_arr[] = 'tos';
1041
+ }
1042
+ foreach ( $pass_arr as $pass ) {
1043
+ unset( $wpmem_fields[ $pass ] );
1044
+ }
1045
+ }
1046
+
1047
+ /**
1048
+ * Filter the array of form fields.
1049
+ *
1050
+ * The form fields are stored in the WP options table as wpmembers_fields. This
1051
+ * filter can filter that array after the option is retreived before the fields
1052
+ * are parsed. This allows you to change the fields that may be used in the form
1053
+ * on the fly.
1054
+ *
1055
+ * @since 2.9.0
1056
+ * @deprecated 3.1.7 Use wpmem_fields instead.
1057
+ *
1058
+ * @param array The array of form fields.
1059
+ * @param string $tag Toggle new registration or profile update. new|edit.
1060
+ */
1061
+ $wpmem_fields = apply_filters( 'wpmem_register_fields_arr', $wpmem_fields, $tag );
1062
+
1063
+ $hidden_rows = array();
1064
+ $form_has_file = false;
1065
+
1066
+ // Loop through the remaining fields.
1067
+ foreach ( $wpmem_fields as $meta_key => $field ) {
1068
+
1069
+ // Start with a clean row.
1070
+ $val = ''; $label = ''; $input = ''; $field_before = ''; $field_after = '';
1071
+
1072
+ // If the field is set to display and we aren't skipping, construct the row.
1073
+ // if ( ( 'new' == $tag && $field['register'] ) || ( 'edit' == $tag && $field['profile'] ) ) { // @todo Wait for profile fix
1074
+ if ( $field['register'] ) {
1075
+
1076
+ // Handle hidden fields
1077
+ if ( 'hidden' == $field['type'] ) {
1078
+ $do_row = false;
1079
+ $hidden_rows[ $meta_key ] = wpmem_form_field( array(
1080
+ 'name' => $meta_key,
1081
+ 'type' => $field['type'],
1082
+ 'value' => $field['value'],
1083
+ 'compare' => $valtochk,
1084
+ 'required' => $field['required'],
1085
+ ) );
1086
+ }
1087
+
1088
+ // Label for all but TOS and hidden fields.
1089
+ if ( 'tos' != $meta_key && 'hidden' != $field['type'] ) {
1090
+
1091
+ $class = ( $field['type'] == 'password' || $field['type'] == 'email' || $field['type'] == 'url' ) ? 'text' : $field['type'];
1092
+
1093
+ $label = wpmem_form_label( array(
1094
+ 'meta_key' => $meta_key, //( 'username' == $meta_key ) ? 'user_login' : $meta_key,
1095
+ 'label' => __( $field['label'], 'wp-members' ),
1096
+ 'type' => $field['type'],
1097
+ 'class' => $class,
1098
+ 'required' => $field['required'],
1099
+ 'req_mark' => $args['req_mark']
1100
+ ) );
1101
+
1102
+ }
1103
+
1104
+ // Gets the field value for edit profile.
1105
+ if ( ( 'edit' == $tag ) && ( '' == $wpmem->regchk ) ) {
1106
+ switch ( $meta_key ) {
1107
+ case( 'description' ):
1108
+ case( 'textarea' == $field['type'] ):
1109
+ $val = get_user_meta( $userdata->ID, $meta_key, 'true' ); // esc_textarea() is run when field is created.
1110
+ break;
1111
+
1112
+ case 'user_email':
1113
+ case 'confirm_email':
1114
+ $val = sanitize_email( $userdata->user_email );
1115
+ break;
1116
+
1117
+ case 'user_url':
1118
+ $val = $userdata->user_url; // esc_url() is run when the field is created.
1119
+ break;
1120
+
1121
+ case 'display_name':
1122
+ $val = sanitize_text_field( $userdata->display_name );
1123
+ break;
1124
+
1125
+ default:
1126
+ $val = sanitize_text_field( get_user_meta( $userdata->ID, $meta_key, 'true' ) );
1127
+ break;
1128
+ }
1129
+
1130
+ } else {
1131
+ if ( 'file' == $field['type'] ) {
1132
+ $val = ( isset( $_FILES[ $meta_key ]['name'] ) ) ? sanitize_file_name( $_FILES[ $meta_key ]['name'] ) : '' ;
1133
+ } else {
1134
+ $val = ( isset( $_POST[ $meta_key ] ) ) ? wpmem_sanitize_field( $_POST[ $meta_key ], $field['type'] ) : '';
1135
+ }
1136
+ }
1137
+
1138
+ // Does the tos field.
1139
+ if ( 'tos' == $meta_key ) {
1140
+
1141
+ // $val = sanitize_text_field( wpmem_get( $meta_key, '' ) );
1142
+
1143
+ // Should be checked by default? and only if form hasn't been submitted.
1144
+ $val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val;
1145
+ $input = wpmem_form_field( array(
1146
+ 'name' => $meta_key,
1147
+ 'type' => $field['type'],
1148
+ 'value' => $field['checked_value'],
1149
+ 'compare' => $val,
1150
+ 'required' => $field['required'],
1151
+ ) );
1152
+
1153
+ $input .= ' ' . $this->get_tos_link( $field, $tag );
1154
+
1155
+ $input = ( $field['required'] ) ? $input . $args['req_mark'] : $input;
1156
+
1157
+ // In previous versions, the div class would end up being the same as the row before.
1158
+ $field_before = ( $args['wrap_inputs'] ) ? '<div class="div_text">' : '';
1159
+ $field_after = ( $args['wrap_inputs'] ) ? '</div>' : '';
1160
+
1161
+ } elseif ( 'hidden' != $field['type'] ) {
1162
+
1163
+ // For checkboxes.
1164
+ if ( 'checkbox' == $field['type'] ) {
1165
+ $valtochk = $val;
1166
+ $val = $field['checked_value'];
1167
+ // if it should it be checked by default (& only if form not submitted), then override above...
1168
+ if ( $field['checked_default'] && ( ! $_POST && $tag != 'edit' ) ) {
1169
+ $val = $valtochk = $field['checked_value'];
1170
+ }
1171
+ }
1172
+
1173
+ // For dropdown select.
1174
+ if ( 'select' == $field['type'] || 'radio' == $field['type'] || 'multiselect' == $field['type'] || 'multicheckbox' == $field['type'] || 'membership' == $field['type'] ) {
1175
+ $valtochk = $val;
1176
+ $val = $field['values'];
1177
+ }
1178
+
1179
+ if ( ! isset( $valtochk ) ) {
1180
+ $valtochk = '';
1181
+ }
1182
+
1183
+ if ( ( 'file' == $field['type'] || 'image' == $field['type'] ) ) {
1184
+
1185
+ $form_has_file = true;
1186
+
1187
+ // Handle files differently for multisite vs. single install.
1188
+ // @see: https://core.trac.wordpress.org/ticket/32145
1189
+ if ( is_multisite() ) {
1190
+ $attachment = get_post( $val );
1191
+ $attachment_url = $attachment->guid;
1192
+ } else {
1193
+ $attachment_url = wp_get_attachment_url( $val );
1194
+ }
1195
+
1196
+ $empty_file = '<span class="description">' . __( 'None' ) . '</span>';
1197
+ if ( 'edit' == $tag ) {
1198
+ if ( 'file' == $field['type'] ) {
1199
+ $input = ( $attachment_url ) ? '<a href="' . esc_url( $attachment_url ) . '" id="' . $meta_key . '_file">' . get_the_title( $val ) . '</a>' : $empty_file;
1200
+ } else {
1201
+ $input = ( $attachment_url ) ? '<img src="' . esc_url( $attachment_url ) . '" id="' . $meta_key . '_img" />' : $empty_file;
1202
+ }
1203
+ $input.= '<br />' . wpmem_get_text( 'profile_upload' ) . '<br />';
1204
+ } else {
1205
+ if ( 'image' == $field['type'] ) {
1206
+ $input = '<img src="" id="' . $meta_key . '_img" />';
1207
+ }
1208
+ }
1209
+ $input.= wpmem_form_field( array(
1210
+ 'name' => $meta_key,
1211
+ 'type' => $field['type'],
1212
+ 'value' => $val,
1213
+ 'compare' => $valtochk,
1214
+ 'file_types' => $field['file_types'],
1215
+ ) );
1216
+
1217
+ } else {
1218
+
1219
+ // For all other input types.
1220
+ $formfield_args = array(
1221
+ 'name' => $meta_key, // ( 'username' == $meta_key ) ? 'user_login' : $meta_key,
1222
+ 'type' => $field['type'],
1223
+ 'value' => $val,
1224
+ 'compare' => $valtochk,
1225
+ //'class' => ( $class ) ? $class : 'textbox',
1226
+ 'required' => $field['required'],
1227
+ 'placeholder' => ( isset( $field['placeholder'] ) ) ? $field['placeholder'] : '',
1228
+ 'pattern' => ( isset( $field['pattern'] ) ) ? $field['pattern'] : false,
1229
+ 'title' => ( isset( $field['title'] ) ) ? $field['title'] : false,
1230
+ 'min' => ( isset( $field['min'] ) ) ? $field['min'] : false,
1231
+ 'max' => ( isset( $field['max'] ) ) ? $field['max'] : false,
1232
+ 'rows' => ( isset( $field['rows'] ) ) ? $field['rows'] : false,
1233
+ 'cols' => ( isset( $field['cols'] ) ) ? $field['cols'] : false,
1234
+ 'file_types' => ( isset( $field['file_types'] ) ) ? $field['file_types'] : false,
1235
+ );
1236
+ if ( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
1237
+ $formfield_args['delimiter'] = $field['delimiter'];
1238
+ }
1239
+ $input = wpmem_form_field( $formfield_args );
1240
+
1241
+ // If checkbox label option is enabled.
1242
+ if ( 'checkbox' == $field['type'] && 1 == $field['checkbox_label'] ) {
1243
+ $input = $input . ' <label for="' . $meta_key . '">' . $label . '</label>';
1244
+ $fields[ $meta_key ]['label'] = $field['label'] = $label = '';
1245
+ }
1246
+ }
1247
+
1248
+ // Determine input wrappers.
1249
+ $field_before = ( $args['wrap_inputs'] ) ? '<div class="div_' . $class . '">' : '';
1250
+ $field_after = ( $args['wrap_inputs'] ) ? '</div>' : '';
1251
+ }
1252
+
1253
+ }
1254
+
1255
+ // If the row is set to display, add the row to the form array.
1256
+ if ( ( 'new' == $tag && $field['register'] ) || ( 'edit' == $tag && $field['profile'] ) ) {
1257
+ //if ( $field['register'] && 'hidden' != $field['type'] ) {
1258
+ if ( 'hidden' != $field['type'] ) {
1259
+
1260
+ $values = '';
1261
+ if ( 'multicheckbox' == $field['type'] || 'select' == $field['type'] || 'multiselect' == $field['type'] || 'radio' == $field['type'] ) {
1262
+ $values = $val;
1263
+ $val = $valtochk;
1264
+ }
1265
+
1266
+ $rows[ $meta_key ] = array(
1267
+ 'meta' => $meta_key,
1268
+ 'type' => $field['type'],
1269
+ 'value' => $val,
1270
+ 'values' => $values,
1271
+ 'label_text' => __( $field['label'], 'wp-members' ),
1272
+ 'row_before' => $args['row_before'],
1273
+ 'label' => $label,
1274
+ 'field_before' => $field_before,
1275
+ 'field' => $input,
1276
+ 'field_after' => $field_after,
1277
+ 'row_after' => $args['row_after'],
1278
+ );
1279
+ }
1280
+ }
1281
+ }
1282
+
1283
+ // If captcha is Really Simple CAPTCHA.
1284
+ if ( 2 == $wpmem->captcha && 'edit' != $tag ) {
1285
+ // Build the captcha.
1286
+ $row = WP_Members_Captcha::rs_captcha( 'array' );
1287
+ $rows['captcha'] = array(
1288
+ 'meta' => '',
1289
+ 'type' => 'text',
1290
+ 'value' => '',
1291
+ 'values' => '',
1292
+ 'label_text' => $row['label_text'],
1293
+ 'row_before' => $args['row_before'],
1294
+ 'label' => $row['label'],
1295
+ 'field_before' => ( $args['wrap_inputs'] ) ? '<div class="div_text">' : '',
1296
+ 'field' => $row['img'] . $row['hidden'] . $row['field'],
1297
+ 'field_after' => ( $args['wrap_inputs'] ) ? '</div>' : '',
1298
+ 'row_after' => $args['row_after'],
1299
+ );
1300
+ }
1301
+
1302
+ /**
1303
+ * Filter the array of form rows.
1304
+ *
1305
+ * This filter receives an array of the main rows in the form, each array element being
1306
+ * an array of that particular row's pieces. This allows making changes to individual
1307
+ * parts of a row without needing to parse through a string of HTML.
1308
+ *
1309
+ * @since 2.9.0
1310
+ * @since 3.0.9 Added $rows['label_text'].
1311
+ * @since 3.1.0 Added $rows['key'].
1312
+ * @since 3.1.6 Deprecated $rows['order'].
1313
+ *
1314
+ * @param array $rows {
1315
+ * An array containing the form rows.
1316
+ *
1317
+ * @type string order Field display order. (deprecated as of 3.1.6)
1318
+ * @type string meta Field meta tag (not used for display).
1319
+ * @type string type Input field type (not used for display).
1320
+ * @type string value Input field value (not used for display).
1321
+ * @type string values Possible field values (dropdown, multiple select/check, radio).
1322
+ * @type string label_text Raw text for the label (not used for display).
1323
+ * @type string row_before Opening wrapper tag around the row.
1324
+ * @type string label Label tag.
1325
+ * @type string field_before Opening wrapper tag before the input tag.
1326
+ * @type string field The field input tag.
1327
+ * @type string field_after Closing wrapper tag around the input tag.
1328
+ * @type string row_after Closing wrapper tag around the row.
1329
+ * }
1330
+ * @param string $tag Toggle new registration or profile update. new|edit.
1331
+ */
1332
+ $rows = apply_filters( 'wpmem_register_form_rows', $rows, $tag );
1333
+
1334
+ // Put the rows from the array into $form.
1335
+ $form = ''; $enctype = '';
1336
+ foreach ( $rows as $meta_key => $row_item ) {
1337
+ // Make sure all keys are set just in case someone didn't return a proper array through the filter.
1338
+ foreach ( $this->get_reg_row_keys() as $check_key ) {
1339
+ if ( ! isset( $rows[ $meta_key ][ $check_key ] ) ) {
1340
+ $rows[ $meta_key ][ $check_key ] = '';
1341
+ }
1342
+ }
1343
+ // Check form to see if we need multipart enctype.
1344
+ $enctype = ( $row_item['type'] == 'file' || $row_item['type'] == 'image' ) ? "multipart/form-data" : $enctype;
1345
+ // Assemble row pieces.
1346
+ $row = ( $row_item['row_before'] != '' ) ? $row_item['row_before'] . $args['n'] . $row_item['label'] . $args['n'] : $row_item['label'] . $args['n'];
1347
+ $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'];
1348
+ $row .= ( $row_item['row_after'] != '' ) ? $row_item['row_after'] . $args['n'] : '';
1349
+ $form.= $row;
1350
+ }
1351
+
1352
+ // Handle outside elements added to the register form with register_form.
1353
+ if ( 'new' == $tag && $args['register_form_action'] ) {
1354
+ ob_start();
1355
+ /** This action is documented in wp-login.php */
1356
+ do_action( 'register_form' );
1357
+ $add_to_form = ob_get_contents();
1358
+ ob_end_clean();
1359
+ $form.= $add_to_form;
1360
+ }
1361
+
1362
+ // Do recaptcha if enabled.
1363
+ if ( ( 1 == $wpmem->captcha || 3 == $wpmem->captcha || 4 == $wpmem->captcha ) && $tag != 'edit' ) { // don't show on edit page!
1364
+
1365
+ $row = WP_Members_Captcha::recaptcha();
1366
+
1367
+ if ( 4 != $wpmem->captcha ) {
1368
+ $row = '<div class="clear"></div><div class="captcha">' . $row . '</div>';
1369
+ }
1370
+
1371
+ // Add the captcha row to the form.
1372
+ /**
1373
+ * Filter the HTML for the CAPTCHA row.
1374
+ *
1375
+ * @since 2.9.0
1376
+ *
1377
+ * @param string The HTML for the entire row (includes HTML tags plus reCAPTCHA).
1378
+ * @param string $tag Toggle new registration or profile update. new|edit.
1379
+ */
1380
+ $form.= apply_filters( 'wpmem_register_captcha_row', $args['row_before'] . $row . $args['row_after'], $tag );
1381
+ }
1382
+
1383
+ if ( 5 == $wpmem->captcha && 'edit' != $tag ) {
1384
+ $row = WP_Members_Captcha::hcaptcha();
1385
+ /** This filter is documented in /includes/class-wp-members-forms.php */
1386
+ $form.= apply_filters( 'wpmem_register_captcha_row', $args['row_before'] . $row . $args['row_after'], $tag );
1387
+ }
1388
+
1389
+ // Create hidden fields.
1390
+ $var = ( $tag == 'edit' ) ? 'update' : 'register';
1391
+ $redirect_to = ( isset( $_REQUEST['redirect_to'] ) ) ? $_REQUEST['redirect_to'] : ( ( $redirect_to ) ? $redirect_to : get_permalink() );
1392
+ $hidden_rows['_wpmem_a'] = '<input name="a" type="hidden" value="' . esc_attr( $var ) . '" />';
1393
+ $hidden_rows['_wpmem_reg_page'] = '<input name="wpmem_reg_page" type="hidden" value="' . esc_url( get_permalink() ) . '" />';
1394
+ if ( $redirect_to != get_permalink() ) {
1395
+ $hidden_rows['_wpmem_redirect_to'] = '<input name="redirect_to" type="hidden" value="' . esc_url( $redirect_to ) . '" />';
1396
+ }
1397
+
1398
+ /**
1399
+ * Filter the hidden form rows.
1400
+ *
1401
+ * @since 3.2.0
1402
+ *
1403
+ * @param array $hidden_rows
1404
+ * @param string $tag
1405
+ */
1406
+ $hidden_rows = apply_filters( 'wpmem_register_hidden_rows', $hidden_rows, $tag );
1407
+
1408
+ // Assemble hidden fields HTML.
1409
+ $hidden = '';
1410
+ foreach ( $hidden_rows as $hidden_row ) {
1411
+ $hidden .= $hidden_row . $args['n'];
1412
+ }
1413
+
1414
+ /**
1415
+ * Filter the hidden field HTML.
1416
+ *
1417
+ * @since 2.9.0
1418
+ *
1419
+ * @param string $hidden The generated HTML of hidden fields.
1420
+ * @param string $tag Toggle new registration or profile update. new|edit.
1421
+ */
1422
+ $hidden = apply_filters( 'wpmem_register_hidden_fields', $hidden, $tag );
1423
+
1424
+ // Add the hidden fields to the form.
1425
+ $form.= $hidden;
1426
+
1427
+ // Create buttons and wrapper.
1428
+ $button_text = ( $tag == 'edit' ) ? $args['submit_update'] : $args['submit_register'];
1429
+ $button_html = array(
1430
+ 'reset' => ( $args['show_clear_form'] ) ? '<input name="reset" type="reset" value="' . esc_attr( $args['clear_form'] ) . '" class="' . wpmem_sanitize_class( $args['button_class'] ) . '" /> ' : '',
1431
+ 'submit' => '<input name="submit" type="submit" value="' . esc_attr( $button_text ) . '" class="' . wpmem_sanitize_class( $args['button_class'] ) . '" />',
1432
+ );
1433
+ $buttons = $button_html['reset'] . $args['n'] . $button_html['submit'] . $args['n'];
1434
+
1435
+ /**
1436
+ * Filter the HTML for form buttons.
1437
+ *
1438
+ * The string passed through the filter includes the buttons, as well as the HTML wrapper elements.
1439
+ *
1440
+ * @since 2.9.0
1441
+ * @since 3.2.6 Added $button_html parameter
1442
+ *
1443
+ * @param string $buttons The generated HTML of the form buttons.
1444
+ * @param string $tag Toggle new registration or profile update. new|edit.
1445
+ * @param array $button_html The individual button html.
1446
+ */
1447
+ $buttons = apply_filters( 'wpmem_register_form_buttons', $buttons, $tag, $button_html );
1448
+
1449
+ // Add the buttons to the form.
1450
+ $form.= $args['buttons_before'] . $args['n'] . $buttons . $args['buttons_after'] . $args['n'];
1451
+
1452
+ // Add the required field notation to the bottom of the form.
1453
+ $form.= $args['req_label_before'] . $args['req_label'] . $args['req_label_after'];
1454
+
1455
+ // Apply the heading.
1456
+ if ( 'edit' == $tag ) {
1457
+ /**
1458
+ * Filter the default heading in User Profile edit mode.
1459
+ *
1460
+ * @since 2.7.5
1461
+ * @since 3.3.0 Moved into main registration function (from profile shortcode).
1462
+ *
1463
+ * @param string The default edit mode heading.
1464
+ */
1465
+ $heading = ( isset( $heading ) && '' != $heading ) ? $heading : apply_filters( 'wpmem_user_edit_heading', wpmem_get_text( 'profile_heading' ) );
1466
+ } else {
1467
+ /**
1468
+ * Filter the registration form heading.
1469
+ *
1470
+ * @since 2.8.2
1471
+ *
1472
+ * @param string $str
1473
+ * @param string $tag Toggle new registration or profile update. new|edit.
1474
+ */
1475
+ $heading = ( isset( $heading ) && '' != $heading ) ? $heading : apply_filters( 'wpmem_register_heading', wpmem_get_text( 'register_heading' ), $tag );
1476
+ }
1477
+ $form = $args['heading_before'] . $heading . $args['heading_after'] . $args['n'] . $form;
1478
+
1479
+ // Apply fieldset wrapper.
1480
+ $form = $args['fieldset_before'] . $args['n'] . $form . $args['n'] . $args['fieldset_after'];
1481
+
1482
+ // Apply attribution if enabled.
1483
+ $form = $form . $this->attribution();
1484
+
1485
+ // Apply nonce. Nonce uses $tag value of the form processor, NOT the form builder.
1486
+ $nonce = ( $tag == 'edit' ) ? 'update' : 'register';
1487
+ $form = wp_nonce_field( 'wpmem_longform_nonce', '_wpmem_' . $nonce . '_nonce', true, false ) . $args['n'] . $form;
1488
+
1489
+ // Apply form wrapper.
1490
+ $enctype = ( $enctype == 'multipart/form-data' ) ? ' enctype="multipart/form-data"' : '';
1491
+ $form = '<form name="form" method="post"' . $enctype . ' action="' . esc_attr( $args['post_to'] ) . '" id="' . wpmem_sanitize_class( $args['form_id'] ) . '" class="' . wpmem_sanitize_class( $args['form_class'] ) . '">' . $args['n'] . $form . $args['n'] . '</form>';
1492
+
1493
+ // Apply anchor.
1494
+ $form = '<a id="register"></a>' . $args['n'] . $form;
1495
+
1496
+ // Apply main div wrapper.
1497
+ $form = $args['main_div_before'] . $args['n'] . $form . $args['n'] . $args['main_div_after'] . $args['n'];
1498
+
1499
+ // Remove line breaks if enabled for easier filtering later.
1500
+ $form = ( $args['strip_breaks'] ) ? $this->strip_breaks( $form, $rows ) : $form; //str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form ) : $form;
1501
+
1502
+ // If there is an image input type, include the following script.
1503
+ $form = ( $form_has_file ) ? $form . '
1504
+ <script>
1505
+ var loadFile = function(event, clicked_id) {
1506
+ var reader = new FileReader();
1507
+ var the_id = clicked_id + "_img";
1508
+ reader.onload = function() {
1509
+ var output = document.getElementById(the_id);
1510
+ output.src = reader.result;
1511
+ };
1512
+ reader.readAsDataURL(event.target.files[0]);
1513
+ };
1514
+ </script>' : $form;
1515
+
1516
+ /**
1517
+ * Filter the generated HTML of the entire form.
1518
+ *
1519
+ * @since 2.7.4
1520
+ *
1521
+ * @param string $form The HTML of the final generated form.
1522
+ * @param string $tag Toggle new registration or profile update. new|edit.
1523
+ * @param array $rows {
1524
+ * An array containing the form rows.
1525
+ *
1526
+ * @type string order Field display order.
1527
+ * @type string meta Field meta tag (not used for display).
1528
+ * @type string type Input field type (not used for display).
1529
+ * @type string value Input field value (not used for display).
1530
+ * @type string values The possible values for the field (dropdown, multiple select/checkbox, radio group).
1531
+ * @type string label_text Raw text for the label (not used for display).
1532
+ * @type string row_before Opening wrapper tag around the row.
1533
+ * @type string label Label tag.
1534
+ * @type string field_before Opening wrapper tag before the input tag.
1535
+ * @type string field The field input tag.
1536
+ * @type string field_after Closing wrapper tag around the input tag.
1537
+ * @type string row_after Closing wrapper tag around the row.
1538
+ * }
1539
+ * @param string $hidden The HTML string of hidden fields
1540
+ */
1541
+ $form = apply_filters( 'wpmem_register_form', $form, $tag, $rows, $hidden );
1542
+
1543
+ /**
1544
+ * Filter before the form.
1545
+ *
1546
+ * This rarely used filter allows you to stick any string onto the front of
1547
+ * the generated form.
1548
+ *
1549
+ * @since 2.7.4
1550
+ *
1551
+ * @param string $str The HTML to add before the form. Default null.
1552
+ * @param string $tag Toggle new registration or profile update. new|edit.
1553
+ */
1554
+ $form = apply_filters( 'wpmem_register_form_before', '', $tag ) . $form;
1555
+
1556
+ $wpmem->reg_form_showing = true;
1557
+
1558
+ // Return the generated form.
1559
+ return $form;
1560
+ } // End register_form().
1561
+
1562
+ /**
1563
+ * Strip line breaks from form.
1564
+ *
1565
+ * Function removes line breaks and tabs. Checks for textarea fields
1566
+ * before stripping line breaks.
1567
+ *
1568
+ * @since 3.1.8
1569
+ *
1570
+ * @param string $form
1571
+ * @param array $rows
1572
+ * @return string $form
1573
+ */
1574
+ function strip_breaks( $form, $rows ) {
1575
+ foreach( $rows as $key => $row ) {
1576
+ if ( 'textarea' == $row['type'] ) {
1577
+ $textareas[ $key ] = $row['field'];
1578
+ }
1579
+ }
1580
+ $form = str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form );
1581
+ if ( ! empty ( $textareas ) ) {
1582
+ foreach ( $textareas as $textarea ) {
1583
+ $stripped = str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $textarea );
1584
+ $form = str_replace( $stripped, $textarea, $form );
1585
+ }
1586
+ }
1587
+ return $form;
1588
+ }
1589
+
1590
+ /**
1591
+ * Appends WP-Members registration fields to wp-login.php registration form.
1592
+ *
1593
+ * @since 2.8.7
1594
+ * @since 3.1.1 Updated to support new (3.1.0) field types.
1595
+ * @since 3.1.6 Updated to support new fields array. Added WC classes.
1596
+ * @since 3.1.8 Added $process parameter.
1597
+ * @since 3.3.0 Ported from wpmem_do_wp_register_form() in wp-registration.php.
1598
+ *
1599
+ * @global stdClass $wpmem
1600
+ * @param string $process
1601
+ */
1602
+ function wp_register_form( $process = 'wp' ) {
1603
+
1604
+ global $wpmem;
1605
+ $wpmem_fields = wpmem_fields( $process );
1606
+
1607
+ // Check if this is WooCommerce account page.
1608
+ $is_woo = false;
1609
+ if ( 'woo' == $process ) {
1610
+ $is_woo = true;
1611
+ } else {
1612
+ if ( function_exists( 'is_account_page' ) ) {
1613
+ $is_woo = ( is_account_page() ) ? true : $is_woo;
1614
+ }
1615
+ }
1616
+
1617
+ if ( isset( $wpmem_fields ) && is_array( $wpmem_fields ) ) {
1618
+
1619
+ unset( $wpmem_fields['username'] );
1620
+
1621
+ if ( $is_woo ) {
1622
+ // Woo has its own setting for password fields.
1623
+ unset( $wpmem_fields['password'] );
1624
+ unset( $wpmem_fields['confirm_password'] );
1625
+ }
1626
+
1627
+ foreach ( $wpmem_fields as $meta_key => $field ) {
1628
+
1629
+ $req = ( $field['required'] ) ? ( ( $is_woo ) ? ' <span class="required">*</span>' : ' <span class="req">' . __( '(required)' ) . '</span>' ) : '';
1630
+
1631
+ // File fields not yet supported for this form.
1632
+ if ( $field['register'] && $meta_key != 'user_email' && $field['type'] != 'file' && $field['type'] != 'image' ) {
1633
+
1634
+ if ( 'checkbox' == $field['type'] ) {
1635
+
1636
+ if ( 'tos' == $meta_key ) {
1637
+ $tos_link_text = $this->get_tos_link( $field, 'woo' );
1638
+ }
1639
+
1640
+ $label = ( 'tos' == $meta_key ) ? $tos_link_text : __( $field['label'], 'wp-members' );
1641
+
1642
+ $val = ( isset( $_POST[ $meta_key ] ) ) ? esc_attr( $_POST[ $meta_key ] ) : '';
1643
+ $val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val;
1644
+
1645
+ $row_before = '<p class="wpmem-checkbox">';
1646
+ $label = '<label for="' . $meta_key . '">' . $label . $req . '</label>';
1647
+ $input = wpmem_form_field( $meta_key, $field['type'], $field['checked_value'], $val );
1648
+ $row_after = '</p>';
1649
+
1650
+ } elseif ( 'hidden' == $field['type'] ) {
1651
+
1652
+ // Handle hidden fields
1653
+ $row_before = '';
1654
+ $label = '';
1655
+ $input = wpmem_form_field( array(
1656
+ 'name' => $meta_key,
1657
+ 'type' => $field['type'],
1658
+ 'value' => $field['value'],
1659
+ 'compare' => $valtochk,
1660
+ 'required' => $field['required'],
1661
+ ) );
1662
+ $row_after = '';
1663
+
1664
+ } else {
1665
+
1666
+ $row_before = ( $is_woo ) ? '<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">' : '<p>';
1667
+ $label = '<label for="' . $meta_key . '">' . __( $field['label'], 'wp-members' ) . $req . '</label>';
1668
+ $label .= ( 'multicheckbox' == $field['type'] ) ? '<br />' : '';
1669
+
1670
+ // determine the field type and generate accordingly...
1671
+
1672
+ switch ( $field['type'] ) {
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( 'select' ):
1681
+ case( 'multiselect' ):
1682
+ case( 'multicheckbox' ):
1683
+ case( 'radio' ):
1684
+ case( 'membership' ):
1685
+ $row_before = ( $is_woo && ( 'select' == $field['type'] || 'multiselect' == $field['type'] || 'membership' == $field['type'] ) ) ? $row_before : '<p class="' . $field['type'] . '">';
1686
+ $valtochk = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
1687
+ $formfield_args = array(
1688
+ 'name' => $meta_key,
1689
+ 'type' => $field['type'],
1690
+ 'value' => $field['values'],
1691
+ 'compare' => $valtochk,
1692
+ 'required' => $field['required'],
1693
+ 'class' => ( $is_woo && ( 'select' == $field['type'] || 'multiselect' == $field['type'] || 'membership' == $field['type'] ) ) ? 'woocommerce-Input woocommerce-Input--text input-text' : $field['type'],
1694
+ );
1695
+ if ( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
1696
+ $formfield_args['delimiter'] = $field['delimiter'];
1697
+ }
1698
+ $input = wpmem_form_field( $formfield_args );
1699
+ break;
1700
+
1701
+ case( 'file' ):
1702
+ case( 'image' ):
1703
+ // Field type not supported for this yet.
1704
+ break;
1705
+
1706
+ default:
1707
+ $class = ( $is_woo ) ? 'woocommerce-Input woocommerce-Input--text input-text' : 'input';
1708
+ //$input = '<input type="' . $field['type'] . '" name="' . $meta_key . '" id="' . $meta_key . '" class="' . $class . '" value="';
1709
+ $formfield_args = array(
1710
+ 'name' => $meta_key,
1711
+ 'type' => $field['type'],
1712
+ 'value' => wpmem_sanitize_field( wpmem_get( $meta_key, '' ), $field['type'] ),
1713
+ 'compare' => ( isset( $field['compare'] ) ) ? $field['compare'] : '',
1714
+ 'required' => $field['required'],
1715
+ 'class' => $class,
1716
+ 'placeholder' => ( isset( $field['placeholder'] ) ) ? $field['placeholder'] : '',
1717
+ 'pattern' => ( isset( $field['pattern'] ) ) ? $field['pattern'] : false,
1718
+ 'title' => ( isset( $field['title'] ) ) ? $field['title'] : false,
1719
+ 'min' => ( isset( $field['min'] ) ) ? $field['min'] : false,
1720
+ 'max' => ( isset( $field['max'] ) ) ? $field['max'] : false,
1721
+ 'rows' => ( isset( $field['rows'] ) ) ? $field['rows'] : false,
1722
+ 'cols' => ( isset( $field['cols'] ) ) ? $field['cols'] : false,
1723
+ );
1724
+ $input = wpmem_form_field( $formfield_args );
1725
+ //$input.= ( isset( $_POST[ $meta_key ] ) ) ? esc_attr( $_POST[ $meta_key ] ) : '';
1726
+ //$input.= '" size="25" />';
1727
+ break;
1728
+ }
1729
+
1730
+ $row_after = '</p>';
1731
+
1732
+ }
1733
+
1734
+ // if the row is set to display, add the row to the form array
1735
+ $rows[ $meta_key ] = array(
1736
+ 'type' => $field['type'],
1737
+ 'row_before' => $row_before,
1738
+ 'label' => $label,
1739
+ 'field' => $input,
1740
+ 'row_after' => $row_after,
1741
+ );
1742
+ }
1743
+ }
1744
+
1745
+ // Do recaptcha if enabled.
1746
+ if ( ! $is_woo && isset( $wpmem->captcha ) && $wpmem->captcha != 0 ) {
1747
+
1748
+ $row_before = '<p>';
1749
+ $row_after = '</p>';
1750
+ $label = '';
1751
+ $captcha = '';
1752
+
1753
+ if ( in_array( $wpmem->captcha, array( 1, 3, 4 ) ) ) {
1754
+ $captcha = WP_Members_Captcha::recaptcha();
1755
+ } elseif ( 5 == $wpmem->captcha ) {
1756
+ $captcha = WP_Members_Captcha::hcaptcha();
1757
+ } elseif ( 2 == $wpmem->captcha ) {
1758
+ $row = WP_Members_Captcha::rs_captcha( 'array' );
1759
+ $label = $row['label']; //$row['label_text'];
1760
+ $captcha = $row['img'] . $row['hidden'] . $row['field'];
1761
+ }
1762
+ if ( 4 == $wpmem->captcha ) {
1763
+ $row_before = '';
1764
+ $row_after = '';
1765
+ }
1766
+
1767
+ $rows['captcha'] = array(
1768
+ 'type' => '',
1769
+ 'row_before' => $row_before,
1770
+ 'row_after' => $row_after,
1771
+ 'label' => $label,
1772
+ 'field' => $captcha,
1773
+ );
1774
+ }
1775
+
1776
+ if ( isset( $rows ) && is_array( $rows ) ) {
1777
+
1778
+ /**
1779
+ * Filter the native registration form rows.
1780
+ *
1781
+ * @since 2.9.3.
1782
+ *
1783
+ * @param array $rows The custom rows added to the form.
1784
+ */
1785
+ $rows = apply_filters( 'wpmem_native_form_rows', $rows );
1786
+
1787
+ foreach ( $rows as $row_item ) {
1788
+ if ( $row_item['type'] == 'checkbox' ) {
1789
+ echo $row_item['row_before'] . $row_item['field'] . $row_item['label'] . $row_item['row_after'];
1790
+ } else {
1791
+ echo $row_item['row_before'] . $row_item['label'] . $row_item['field'] . $row_item['row_after'];
1792
+ }
1793
+ }
1794
+ }
1795
+ }
1796
+ }
1797
+
1798
+
1799
+ /**
1800
+ * Appends WP-Members registration fields to Users > Add New User screen.
1801
+ *
1802
+ * @since 2.9.0
1803
+ * @since 3.1.1 Updated to support new (3.1.0) field types and user activation.
1804
+ * @since 3.1.6 Updated to support new fields array.
1805
+ * @since 3.3.0 Ported from wpmem_do_wp_newuser_form() in wp-registration.php.
1806
+ *
1807
+ * @global stdClass $wpmem
1808
+ */
1809
+ function wp_newuser_form() {
1810
+
1811
+ global $wpmem;
1812
+ echo '<table class="form-table"><tbody>';
1813
+
1814
+ $wpmem_fields = wpmem_fields( 'add_new' );
1815
+ $exclude = wpmem_get_excluded_meta( 'wp-register' );
1816
+
1817
+ foreach ( $wpmem_fields as $meta_key => $field ) {
1818
+
1819
+ if ( ! $field['native'] && ! in_array( $meta_key, $exclude ) ) {
1820
+
1821
+ $req = ( $field['required'] ) ? ' <span class="description">' . __( '(required)' ) . '</span>' : '';
1822
+
1823
+ $class = ( 'radio' == $field['type']
1824
+ || 'checkbox' == $field['type']
1825
+ || 'date' == $field['type'] ) ? '' : ' class="form-field" ';
1826
+ echo '<tr' . $class . '>
1827
+ <th scope="row">
1828
+ <label for="' . $meta_key . '">' . __( $field['label'], 'wp-members' ) . $req . '</label>
1829
+ </th>
1830
+ <td>';
1831
+
1832
+ // determine the field type and generate accordingly.
1833
+
1834
+ // All fields use the following:
1835
+ $args['name'] = $meta_key;
1836
+ $args['type'] = $field['type'];
1837
+ $args['required'] = $field['required'];
1838
+
1839
+ $args['placeholder'] = ( isset( $field['placeholder'] ) ) ? $field['placeholder'] : '';
1840
+ $args['pattern'] = ( isset( $field['pattern'] ) ) ? $field['pattern'] : '';
1841
+ $args['title'] = ( isset( $field['title'] ) ) ? $field['title'] : '';
1842
+
1843
+ switch ( $field['type'] ) {
1844
+
1845
+ case( 'select' ):
1846
+ $val = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
1847
+ $args['value'] = $field['values'];
1848
+ $args['compare'] = $val;
1849
+ echo wpmem_form_field( $args );
1850
+ break;
1851
+
1852
+ case( 'textarea' ):
1853
+ $args['value'] = ( isset( $_POST[ $meta_key ] ) ) ? esc_textarea( $_POST[ $meta_key ] ) : '';
1854
+ echo wpmem_form_field( $args );
1855
+ break;
1856
+
1857
+ case( 'checkbox' ):
1858
+ $val = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
1859
+ $val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val;
1860
+ $args['value'] = $field['checked_value'];
1861
+ $args['compare'] = $val;
1862
+ echo wpmem_form_field( $args );
1863
+ break;
1864
+
1865
+ case( 'multiselect' ):
1866
+ case( 'multicheckbox' ):
1867
+ case( 'radio' ):
1868
+ case( 'membership' );
1869
+ $args['value'] = $field['values'];
1870
+ $args['compare'] = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
1871
+ if ( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
1872
+ $args['delimiter'] = $field['delimiter'];
1873
+ }
1874
+ echo wpmem_form_field( $args );
1875
+ break;
1876
+
1877
+ case( 'file' ):
1878
+ case( 'image' ):
1879
+ echo 'Not currently supported for this form';
1880
+ break;
1881
+
1882
+ default:
1883
+ $args['value'] = ( isset( $_POST[ $meta_key ] ) ) ? esc_attr( $_POST[ $meta_key ] ) : '';
1884
+ echo wpmem_form_field( $args );
1885
+ break;
1886
+ }
1887
+
1888
+ echo '</td>
1889
+ </tr>';
1890
+
1891
+ }
1892
+ }
1893
+
1894
+ // If moderated registration is enabled, add checkbox to set user as active.
1895
+ if ( 1 == $wpmem->mod_reg ) {
1896
+ echo '<tr>
1897
+ <th scope="row">
1898
+ <label for="activate_user">' . __( 'Activate this user?', 'wp-members' ) . '</label>
1899
+ </th>
1900
+ <td>' . wpmem_form_field( array( 'name' => 'activate_user', 'type' => 'checkbox', 'value' => 1, 'compare' => '' ) ) . '</td>
1901
+ </tr>';
1902
+ }
1903
+
1904
+ echo '</tbody></table>';
1905
+
1906
+ }
1907
+
1908
+ /**
1909
+ * Create an attribution link in the form.
1910
+ *
1911
+ * @since 2.6.0
1912
+ * @since 3.1.1 Updated to use new object setting.
1913
+ * @since 3.3.0 Ported from wpmem_inc_attribution() in forms.php.
1914
+ *
1915
+ * @global object $wpmem
1916
+ * @return string $str
1917
+ */
1918
+ function attribution() {
1919
+
1920
+ global $wpmem;
1921
+ $str = '
1922
+ <div align="center">
1923
+ <small>Powered by <a href="https://rocketgeek.com" target="_blank">WP-Members</a></small>
1924
+ </div>';
1925
+
1926
+ return ( 1 == $wpmem->attrib ) ? $str : '';
1927
+ }
1928
+
1929
+ /**
1930
+ * Settings for building Short Form (login).
1931
+ *
1932
+ * Replaces individual legacy functions and filters for
1933
+ * the short forms, combined into a single method.
1934
+ *
1935
+ * @since 3.3.0
1936
+ * @since 3.4.0 Change inputs.
1937
+ *
1938
+ * @global stdClass $post
1939
+ * @global stdClass $wpmem
1940
+ *
1941
+ * @param string $form login|changepassword|resetpassword|forgotusername
1942
+ * @param array $args
1943
+ * @return string $form
1944
+ */
1945
+ function do_shortform( $form, $args = array() ) {
1946
+
1947
+ global $post, $wpmem;
1948
+
1949
+ $input_arrays = array(
1950
+ 'login' => array(
1951
+ array(
1952
+ 'name' => wpmem_get_text( 'login_username' ),
1953
+ 'type' => 'text',
1954
+ 'tag' => 'log',
1955
+ 'class' => 'username',
1956
+ 'div' => 'div_text',
1957
+ ),
1958
+ array(
1959
+ 'name' => wpmem_get_text( 'login_password' ),
1960
+ 'type' => 'password',
1961
+ 'tag' => 'pwd',
1962
+ 'class' => 'password',
1963
+ 'div' => 'div_text',
1964
+ ),
1965
+ ),
1966
+ 'changepassword' => array(
1967
+ array(
1968
+ 'name' => wpmem_get_text( 'pwdchg_password1' ),
1969
+ 'type' => 'password',
1970
+ 'tag' => 'pass1',
1971
+ 'class' => 'password',
1972
+ 'div' => 'div_text',
1973
+ ),
1974
+ array(
1975
+ 'name' => wpmem_get_text( 'pwdchg_password2' ),
1976
+ 'type' => 'password',
1977
+ 'tag' => 'pass2',
1978
+ 'class' => 'password',
1979
+ 'div' => 'div_text',
1980
+ ),
1981
+ ),
1982
+ 'resetpassword' => array(
1983
+ array(
1984
+ 'name' => wpmem_get_text( 'pwdreset_username' ),
1985
+ 'type' => 'text',
1986
+ 'tag' => 'user',
1987
+ 'class' => 'username',
1988
+ 'div' => 'div_text',
1989
+ ),
1990
+ array(
1991
+ 'name' => wpmem_get_text( 'pwdreset_email' ),
1992
+ 'type' => 'text',
1993
+ 'tag' => 'email',
1994
+ 'class' => 'textbox',
1995
+ 'div' => 'div_text',
1996
+ ),
1997
+ ),
1998
+ 'forgotusername' => array(
1999
+ array(
2000
+ 'name' => wpmem_get_text( 'username_email' ),
2001
+ 'type' => 'text',
2002
+ 'tag' => 'user_email',
2003
+ 'class' => 'username',
2004
+ 'div' => 'div_text',
2005
+ ),
2006
+ ),
2007
+ );
2008
+
2009
+ /**
2010
+ * Filter the array of change password form fields.
2011
+ *
2012
+ * @since 2.9.0
2013
+ * @deprecated 3.3.0 Use wpmem_{$form}_form_defaults instead.
2014
+ *
2015
+ * @param array $default_inputs An array matching the elements used by default.
2016
+ */
2017
+ $default_inputs = apply_filters( 'wpmem_inc_' . $form . '_inputs', $input_arrays[ $form ] );
2018
+
2019
+ $form_arrays = array(
2020
+ 'login' => array(
2021
+ 'heading' => wpmem_get_text( 'login_heading' ),
2022
+ 'action' => 'login',
2023
+ 'button_text' => wpmem_get_text( 'login_button' ),
2024
+ 'inputs' => $default_inputs,
2025
+ 'redirect_to' => ( isset( $args['redirect_to'] ) ) ? $args['redirect_to'] : get_permalink(),
2026
+ ),
2027
+ 'changepassword' => array(
2028
+ 'heading' => wpmem_get_text( 'pwdchg_heading' ),
2029
+ 'action' => 'pwdchange',
2030
+ 'button_text' => wpmem_get_text( 'pwdchg_button' ),
2031
+ 'inputs' => $default_inputs,
2032
+ ),
2033
+ 'resetpassword' => array(
2034
+ 'heading' => wpmem_get_text( 'pwdreset_heading' ),
2035
+ 'action' => 'pwdreset',
2036
+ 'button_text' => wpmem_get_text( 'pwdreset_button' ),
2037
+ 'inputs' => $default_inputs,
2038
+ ),
2039
+ 'forgotusername' => array(
2040
+ 'heading' => wpmem_get_text( 'username_heading' ),
2041
+ 'action' => 'getusername',
2042
+ 'button_text' => wpmem_get_text( 'username_button' ),
2043
+ 'inputs' => $default_inputs,
2044
+ ),
2045
+ );
2046
+
2047
+ /**
2048
+ * Filter the arguments to override form defaults.
2049
+ *
2050
+ * @since 2.9.0
2051
+ * @deprecated 3.3.0 Use wpmem_inc_{$form}_defaults instead.
2052
+ *
2053
+ * @param array $args An array of arguments to use. Default null. (login|changepassword|resetpassword|forgotusername)
2054
+ */
2055
+ $args = apply_filters( 'wpmem_inc_' . $form . '_args', '' );
2056
+ $arr = wp_parse_args( $args, $form_arrays[ $form ] );
2057
+
2058
+ /**
2059
+ * Filter the arguments to override change password form defaults.
2060
+ *
2061
+ * @since 3.3.0
2062
+ *
2063
+ * @param array $args An array of arguments to use. Default null. (login|changepassword|resetpassword|forgotusername)
2064
+ */
2065
+ $arr = apply_filters( 'wpmem_' . $form . '_form_defaults', $arr );
2066
+
2067
+ return $this->login_form( '', $arr );
2068
+ }
2069
+
2070
+ /**
2071
+ * Applies the post restricted message above the short form.
2072
+ *
2073
+ * @since 3.3.0
2074
+ *
2075
+ * @global stdClass $wpmem
2076
+ *
2077
+ * @return string $str The generated message.
2078
+ */
2079
+ public function add_restricted_msg() {
2080
+
2081
+ global $wpmem;
2082
+
2083
+ $str = '';
2084
+
2085
+ if ( $wpmem->regchk != "success" ) {
2086
+
2087
+ $dialogs = get_option( 'wpmembers_dialogs' );
2088
+
2089
+ // This shown above blocked content.
2090
+ $msg = wpmem_get_text( 'restricted_msg' );
2091
+ $msg = ( $dialogs['restricted_msg'] == $msg ) ? $msg : __( stripslashes( $dialogs['restricted_msg'] ), 'wp-members' );
2092
+ $str = '<div id="wpmem_restricted_msg"><p>' . $msg . '</p></div>';
2093
+
2094
+ /**
2095
+ * Filter the post restricted message.
2096
+ *
2097
+ * @since 2.7.3
2098
+ * @since 3.2.0 Added raw message string and HTML as separate params.
2099
+ *
2100
+ * @param string $str The post restricted message with HTML.
2101
+ * @param string $msg The raw message string.
2102
+ * @param string The 'before' HTML wrapper.
2103
+ * @param string The 'after' HTML wrapper.
2104
+ */
2105
+ $str = apply_filters( 'wpmem_restricted_msg', $str, $msg, '<div id="wpmem_restricted_msg"><p>', '</p></div>' );
2106
+ }
2107
+
2108
+ return $str;
2109
+ }
2110
+
2111
+ /**
2112
+ * Wrapper for handing the default WP login form.
2113
+ *
2114
+ * @since 3.3.2
2115
+ */
2116
+ function wp_login_form( $args ) {
2117
+
2118
+ return wp_login_form( $args );
2119
+ }
2120
+
2121
+ /**
2122
+ * Generate TOS field with link.
2123
+ *
2124
+ * @since 3.3.5
2125
+ *
2126
+ * @param array $field
2127
+ * @param string $tag
2128
+ * @return string
2129
+ */
2130
+ function get_tos_link( $field, $tag = 'new' ) {
2131
+ global $wpmem;
2132
+ // Determine if TOS is a WP page or not.
2133
+ $tos_content = stripslashes( get_option( 'wpmembers_tos' ) );
2134
+ if ( has_shortcode( $tos_content, 'wpmem_tos' ) || has_shortcode( $tos_content, 'wp-members' ) ) {
2135
+ $tos_link_url = do_shortcode( $tos_content );
2136
+ $tos_link_tag = '<a href="' . esc_url( $tos_link_url ) . '" target="_blank">';
2137
+ } else {
2138
+ $tos_link_url = add_query_arg( 'tos', 'display' );
2139
+ $tos_link_tag = "<a href=\"#\" onClick=\"window.open('" . $tos_link_url . "','tos');\">";
2140
+ }
2141
+
2142
+ /**
2143
+ * Filter the TOS link.
2144
+ *
2145
+ * @since 3.2.6
2146
+ *
2147
+ * @param string $tos_link_tag
2148
+ * @param string $tos_link_url
2149
+ */
2150
+ $tos_link_tag = apply_filters( 'wpmem_tos_link_tag', $tos_link_tag, $tos_link_url );
2151
+
2152
+ /**
2153
+ * Filter the TOS link text.
2154
+ *
2155
+ * @since 2.7.5
2156
+ *
2157
+ * @param string The link text.
2158
+ * @param string $tag Toggle new registration or profile update. new|edit.
2159
+ */
2160
+ $tos_link_text = apply_filters( 'wpmem_tos_link_txt', wpmem_get_text( 'register_tos' ), $tag );
2161
+
2162
+ // If filtered value is not the default label, use that, otherwise use label.
2163
+ // @note: if default changes, this check must change.
2164
+ if ( __( 'Please indicate that you agree to the %s Terms of Service %s', 'wp-members' ) == $tos_link_text ) {
2165
+ if ( __( 'TOS', 'wp-members' ) != $field['label'] && __( 'Terms of Service', 'wp-members' ) != $field['label'] ) {
2166
+ $tos_link_text = $field['label'];
2167
+ }
2168
+ }
2169
+
2170
+ // If tos string does not contain link identifiers (%s), wrap the whole string.
2171
+ if ( ! strpos( $tos_link_text, '%s' ) ) {
2172
+ $tos_link_text = '%s' . $tos_link_text . '%s';
2173
+ }
2174
+
2175
+ return sprintf( $tos_link_text, $tos_link_tag, '</a>' );
2176
+ }
2177
+
2178
+ function get_reg_row_keys() {
2179
+ return array( 'meta', 'type', 'value', 'values', 'label_text', 'row_before', 'label', 'field_before', 'field', 'field_after', 'row_after' );
2180
+ }
2181
  } // End of WP_Members_Forms class.
includes/class-wp-members-products.php CHANGED
@@ -1,527 +1,541 @@
1
- <?php
2
- /**
3
- * The WP_Members Membership Products Class.
4
- *
5
- * This is the main WP_Members object class. This class contains functions
6
- * for loading settings, shortcodes, hooks to WP, plugin dropins, constants,
7
- * and registration fields. It also manages whether content should be blocked.
8
- *
9
- * @package WP-Members
10
- * @subpackage WP_Members Membership Products Object Class
11
- * @since 3.0.0
12
- */
13
-
14
- // Exit if accessed directly.
15
- if ( ! defined( 'ABSPATH' ) ) {
16
- exit();
17
- }
18
-
19
- class WP_Members_Products {
20
-
21
- /**
22
- * Product post type.
23
- *
24
- * @since 3.4.0
25
- * @access public
26
- * @var string
27
- */
28
- public $post_type = 'wpmem_product';
29
-
30
- /**
31
- * Product meta key.
32
- *
33
- * @since 3.2.0
34
- * @access public
35
- * @var string
36
- */
37
- public $post_meta = '_wpmem_products';
38
-
39
- /**
40
- * Product meta key stem.
41
- *
42
- * @since 3.2.0
43
- * @access public
44
- * @var string
45
- */
46
- public $post_stem = '_wpmem_products_';
47
-
48
- /**
49
- * Product details.
50
- *
51
- * @since 3.2.0
52
- * @access public
53
- * @var array {
54
- * Array of membership product information.
55
- *
56
- * @type array $product_slug {
57
- * Array of membership product settings.
58
- *
59
- * @type string $title The product title (user view).
60
- * @type string $role User role, if a role is required.
61
- * @type string $name The product slug.
62
- * @type string $default
63
- * @type array $expires {
64
- * If the membership has expiration periods.
65
- *
66
- * $type string number|period Number of periods|Period (year/month/week/day).
67
- * }
68
- * }
69
- * }
70
- */
71
- public $products = array();
72
-
73
- /**
74
- * Product meta keyed by ID.
75
- *
76
- * @since 3.2.4
77
- * @access public
78
- * @var array {
79
- * Array of membership products keyed by CPT ID.
80
- *
81
- * @type string $ID The membership product slug.
82
- * }
83
- */
84
- public $product_by_id = array();
85
-
86
- /**
87
- * Class constructor.
88
- *
89
- * @since 3.2.0
90
- *
91
- * @global object $wpmem The WP_Members object class.
92
- */
93
- function __construct() {
94
-
95
- $this->load_products();
96
-
97
- add_filter( 'wpmem_securify', array( $this, 'product_access' ) );
98
- add_filter( 'wpmem_product_restricted_msg', array( $this, 'access_message' ) );
99
- add_filter( 'wpmem_restricted_msg', array( $this, 'access_message' ) );
100
- }
101
-
102
- /**
103
- * Loads product settings.
104
- *
105
- * @since 3.2.0
106
- *
107
- * @global object $wpdb The WPDB object class.
108
- */
109
- function load_products() {
110
- global $wpdb;
111
- $sql = "SELECT ID, post_title, post_name FROM "
112
- . $wpdb->prefix
113
- . "posts WHERE post_type = 'wpmem_product' AND post_status = 'publish';";
114
- $result = $wpdb->get_results( $sql );
115
- foreach ( $result as $plan ) {
116
- $this->product_by_id[ $plan->ID ] = $plan->post_name;
117
- $this->products[ $plan->post_name ]['title'] = $plan->post_title;
118
- $post_meta = get_post_meta( $plan->ID );
119
- foreach ( $post_meta as $key => $meta ) {
120
- if ( false !== strpos( $key, 'wpmem_product' ) ) {
121
- if ( 'wpmem_product_expires' == $key ) {
122
- $meta[0] = unserialize( $meta[0] );
123
- }
124
- if ( 'wpmem_product_fixed_period' == $key ) {
125
- $meta[0] = $this->explode_fixed_period( $meta[0] );
126
- }
127
- $this->products[ $plan->post_name ][ str_replace( 'wpmem_product_', '', $key ) ] = $meta[0];
128
- }
129
- }
130
- }
131
- }
132
-
133
- /**
134
- * Gets products assigned to a post.
135
- *
136
- * @since 3.2.4
137
- *
138
- * @param integer $post_id
139
- * @return array $products {
140
- * Membership product slugs the post is restricted to.
141
- *
142
- * @type string $slug
143
- * }
144
- */
145
- function get_post_products( $post_id ) {
146
- $products = get_post_meta( $post_id, $this->post_meta, true );
147
- /**
148
- * Filter product access by post ID.
149
- *
150
- * @since 3.3.5
151
- *
152
- * @param array $post_products
153
- * @param int $post_id
154
- */
155
- $products = apply_filters( 'wpmem_post_products', $products, $post_id );
156
- return $products;
157
- }
158
-
159
- /**
160
- * Gets default membership products.
161
- *
162
- * @since 3.3.0
163
- *
164
- * @return array $defaults
165
- */
166
- function get_default_products() {
167
- // Get any default membership products.
168
- $args = array(
169
- 'numberposts' => -1,
170
- 'post_type' => $this->post_type,
171
- 'meta_key' => 'wpmem_product_default',
172
- 'meta_value' => 1,
173
- 'fields' => array( 'post_name' ),
174
- );
175
- $default_products = get_posts( $args );
176
- $defaults = array();
177
- if ( $default_products ) {
178
- foreach ( $default_products as $product ) {
179
- $defaults[] = $product->post_name;
180
- }
181
- }
182
- return $defaults;
183
- }
184
-
185
- /**
186
- * Sets up custom access restriction by product.
187
- *
188
- * @since 3.2.0
189
- * @since 3.2.2 Merged check_product_access() logic for better messaging.
190
- *
191
- * @global object $post The WordPress Post object.
192
- * @global object $wpmem The WP_Members object class.
193
- * @param string $content
194
- * @return string $content
195
- */
196
- function product_access( $content ) {
197
-
198
- global $post, $wpmem;
199
- // Is the user logged in and is this blocked content?
200
- if ( ! is_admin() && is_user_logged_in() && wpmem_is_blocked() && 1 == $wpmem->enable_products ) { // @todo Should is_admin() check be run on securify in general?
201
-
202
- // Get the post access products.
203
- $post_products = $this->get_post_products( $post->ID );
204
- // If the post is restricted to a product.
205
- if ( is_array( $post_products ) && ! empty( $post_products ) ) {
206
- $access = ( wpmem_user_has_access( $post_products ) ) ? true : false;
207
- } else {
208
- $access = true;
209
- }
210
-
211
- // Only produce the product restricted message if access is false.
212
- if ( false === $access ) {
213
-
214
- // Singular message if post only has one membership, otherwise multiple.
215
- if ( 1 == count( $post_products ) ) {
216
- $message = $wpmem->get_text( 'product_restricted_single' )
217
- . "<br />" . $this->products[ $post_products[0] ]['title'];
218
- } else {
219
- $message = $wpmem->get_text( 'product_restricted_multiple' ) . "<br />";
220
- foreach ( $post_products as $post_product ) {
221
- $message .= $this->products[ $post_product ]['title'] . "<br />";
222
- }
223
- }
224
- /**
225
- * Filter the product restricted message.
226
- *
227
- * @since 3.2.3
228
- *
229
- * @param string The message.
230
- * @param array $post_products {
231
- * Membership product slugs the post is restricted to.
232
- *
233
- * @type string $slug
234
- * }
235
- */
236
- $message = apply_filters( 'wpmem_product_restricted_msg', $message, $post_products );
237
-
238
- /**
239
- * Filter the product restricted message HTML.
240
- *
241
- * @since 3.3.3
242
- * @since 3.3.4 Added $post_products
243
- *
244
- * @param array $product_restricted {
245
- * $type string $wrapper_before
246
- * $type string $message
247
- * $type string $wrapper_after
248
- * }
249
- * @param array $post_products {
250
- * Membership product slugs the post is restricted to.
251
- *
252
- * @type string $slug
253
- * }
254
- */
255
- $product_restricted = apply_filters( 'wpmem_product_restricted_args', array(
256
- 'wrapper_before' => '<div class="wpmem_msg" align="center">',
257
- 'message' => '<p>' . $message . '</p>',
258
- 'wrapper_after' => '</div>',
259
- ), $post_products );
260
-
261
- $content = $product_restricted['wrapper_before'] . $product_restricted['message'] . $product_restricted['wrapper_after'];
262
-
263
- // Handle comments.
264
- add_filter( 'wpmem_securify_comments', '__return_false' );
265
- }
266
-
267
- }
268
-
269
- return $content;
270
- }
271
-
272
- /**
273
- * Filters the access message if the user does not have
274
- * access to this membership.
275
- *
276
- * @since 3.3.4
277
- *
278
- * @global stdClass $post
279
- * @param string $msg
280
- * @return string $msg
281
- */
282
- function access_message( $msg ) {
283
- global $post;
284
- $post_products = $this->get_post_products( $post->ID );
285
- if ( $post_products ) {
286
- foreach( $post_products as $post_product ) {
287
- $membership_id = array_search( $post_product, $this->product_by_id );
288
- $message = get_post_meta( $membership_id, 'wpmem_product_message', true );
289
- if ( $message ) {
290
- $product_message = ( isset( $product_message ) ) ? $product_message . '<p>' . $message . '</p>' : '<p>' . $message . '</p>';
291
- }
292
- }
293
- if ( isset( $product_message ) ) {
294
- $msg = $product_message;
295
- }
296
- }
297
- return $msg;
298
- }
299
-
300
- /**
301
- * Register Membership Plans Custom Post Type
302
- *
303
- * @since 3.2.0
304
- *
305
- * @global object $wpmem The WP_Members object class.
306
- */
307
- function add_cpt() {
308
-
309
- global $wpmem;
310
-
311
- $args = array( 'capabilities' => 'manage_options', );
312
- /**
313
- * Filter customizable elements of the membership custom post type.
314
- *
315
- * @since 3.3.5
316
- *
317
- * @param array
318
- */
319
- $args = apply_filters( 'wpmem_membership_cpt_args', $args );
320
-
321
- $singular = __( 'Product', 'wp-members' );
322
- $plural = __( 'Products', 'wp-members' );
323
-
324
- $labels = array(
325
- 'name' => $plural,
326
- 'singular_name' => $singular,
327
- 'menu_name' => __( 'Memberships', 'wp-members' ),
328
- 'all_items' => sprintf( __( 'All %s', 'wp-members' ), $plural ),
329
- 'add_new_item' => sprintf( __( 'Add New %s', 'wp-members' ), $singular ),
330
- 'add_new' => __( 'Add New', 'wp-members' ),
331
- 'new_item' => sprintf( __( 'New %s', 'wp-members' ), $singular ),
332
- 'edit_item' => sprintf( __( 'Edit %s', 'wp-members' ), $singular ),
333
- 'update_item' => sprintf( __( 'Update %s', 'wp-members' ), $singular ),
334
- 'view_item' => sprintf( __( 'View %s', 'wp-members' ), $singular ),
335
- 'view_items' => sprintf( __( 'View %s', 'wp-members' ), $plural ),
336
- 'search_items' => sprintf( __( 'Search %s', 'wp-members' ), $plural ),
337
- 'not_found' => __( 'Not found', 'wp-members' ),
338
- 'not_found_in_trash' => __( 'Not found in Trash', 'wp-members' ),
339
- 'insert_into_item' => __( 'Insert into item', 'wp-members' ),
340
- 'publish' => sprintf( __( 'Save %s Details', 'wp-members' ), $singular ),
341
- );
342
- $args = array(
343
- 'label' => __( 'Membership Product', 'wp-members' ),
344
- 'description' => __( 'WP-Members Membership Products', 'wp-members' ),
345
- 'labels' => $labels,
346
- 'supports' => array( 'title', 'page-attributes' ),
347
- 'hierarchical' => true,
348
- 'public' => false,
349
- 'show_ui' => ( $wpmem->enable_products ) ? true : false,
350
- 'show_in_menu' => ( $wpmem->enable_products ) ? true : false,
351
- 'menu_position' => 58,
352
- 'menu_icon' => 'dashicons-groups',
353
- 'show_in_admin_bar' => false,
354
- 'show_in_nav_menus' => false,
355
- 'can_export' => true,
356
- 'has_archive' => false,
357
- 'exclude_from_search' => true,
358
- 'publicly_queryable' => false,
359
- 'query_var' => 'membership_product',
360
- 'rewrite' => false,
361
- 'capability_type' => 'page',
362
- 'capabilities' => array(
363
- 'publish_posts' => $args['capabilities'],
364
- 'edit_posts' => $args['capabilities'],
365
- 'delete_posts' => $args['capabilities'],
366
- 'edit_post' => $args['capabilities'],
367
- 'delete_post' => $args['capabilities'],
368
- 'read_post' => $args['capabilities'],
369
- ),
370
- 'show_in_rest' => false,
371
- //'register_meta_box_cb' => '', // callback for meta box
372
- );
373
- register_post_type( $this->post_type, $args );
374
- }
375
-
376
- /**
377
- * Get all posts tagged to a specified product.
378
- *
379
- * @since 3.3.0
380
- *
381
- * @global stdClass $wpdb
382
- *
383
- * @param string $product_meta
384
- * @return array $post_ids
385
- */
386
- function get_all_posts( $product_meta ) {
387
- global $wpdb;
388
- $results = $wpdb->get_results( $wpdb->prepare( "
389
- SELECT post_id
390
- FROM {$wpdb->postmeta}
391
- WHERE meta_key = %s
392
- ", $this->post_stem . $product_meta ), ARRAY_N );
393
- foreach ( $results as $result ) {
394
- $post_ids[] = $result[0];
395
- }
396
- return $post_ids;
397
- }
398
-
399
- /**
400
- * Utility to explode fixed period.
401
- *
402
- * @since 3.3.5
403
- */
404
- function explode_fixed_period( $array ) {
405
- $period_parts = explode( "-", $array );
406
- $period['start'] = ( $period_parts ) ? $period_parts[0] . '-' . $period_parts[1] : '';
407
- $period['end'] = ( $period_parts ) ? $period_parts[2] . '-' . $period_parts[3] : '';
408
- $period['grace']['num'] = ( $period_parts && isset( $period_parts[4] ) ) ? $period_parts[4] : '';
409
- $period['grace']['per'] = ( $period_parts && isset( $period_parts[5] ) ) ? $period_parts[5] : '';
410
- return $period;
411
- }
412
-
413
- /**
414
- * Set an expiration date.
415
- *
416
- * @since 3.3.5
417
- *
418
- * @param string $product
419
- * @param int $user_id
420
- * @param mixed $set_date
421
- * @param mixed $pre_value
422
- * @param boolean $renew
423
- * @return mixed $new_value
424
- */
425
- function set_product_expiration( $product, $user_id, $set_date, $prev_value, $renew ) {
426
- // If this is setting a specific date.
427
- if ( $set_date ) {
428
- $new_value = strtotime( $set_date );
429
- } else {
430
- // Either setting initial expiration based on set time period, or adding to the existing date (renewal/extending).
431
- $raw_add = explode( "|", $this->products[ $product ]['expires'][0] );
432
- $add_period = ( 1 < $raw_add[0] ) ? $raw_add[0] . " " . $raw_add[1] . "s" : $raw_add[0] . " " . $raw_add[1];
433
-
434
- if ( $prev_value ) {
435
- if ( isset( $this->products[ $product ]['no_gap'] ) && 1 == $this->products[ $product ]['no_gap'] ) {
436
- // Add to the user's existing date (no gap).
437
- $new_value = strtotime( $add_period, $prev_value );
438
- } else {
439
- // Add to the user either from end or now (whichever is later; i.e. allow gaps (default)).
440
- if ( wpmem_user_has_access( $product, $user_id ) ) {
441
- // if not expired, set from when they expire.
442
- $new_value = strtotime( $add_period, $prev_value );
443
- } else {
444
- // if expired, set from today.
445
- $new_value = strtotime( $add_period );
446
- }
447
- }
448
- } else {
449
- // User doesn't have this membershp. Go ahead and add it.
450
-
451
- // If we are using fixed period expiration, calculate the expiration date
452
- if ( isset( $this->products[ $product ] ) && isset( $this->products[ $product ]['fixed_period'] ) ) {
453
- // Calculate the fixed period expiration.
454
- $new_value = $this->calculate_fixed_period ( $product );
455
- } else {
456
- // Just add to the existing expiration.
457
- $new_value = strtotime( $add_period );
458
- }
459
- }
460
- }
461
-
462
- /**
463
- * Filter the expiration date.
464
- *
465
- * @since 3.3.2
466
- *
467
- * @param int|boolean $new_value Unix timestamp of new expiration, true|false if not an expiry product.
468
- * @param int|boolean $prev_value The user's current value (prior to updating).
469
- * @param boolean $renew Is this a renewal transaction?
470
- */
471
- $new_value = apply_filters( 'wpmem_user_product_set_expiration', $new_value, $prev_value, $renew );
472
-
473
- return $new_value;
474
- }
475
-
476
- /**
477
- * Calculate a fixed period expiration.
478
- *
479
- * @since 3.3.5
480
- *
481
- * @param string $product
482
- * @return string $timestamp
483
- */
484
- function calculate_fixed_period( $product ) {
485
- // Use fixed period expiration.
486
- $end = $this->products[ $product ]['fixed_period']['end'];
487
-
488
- // Get the current year.
489
- $current_year = date( 'Y' );
490
-
491
- // Format period end date for current year.
492
- $cur_date = DateTime::createFromFormat( 'd-m-Y', $end . '-' . $current_year ); //DateTime( $start_date );
493
-
494
- // Where are we now?
495
- $now = new DateTime();
496
-
497
- // If date is past, set next period.
498
- if ( $cur_date < $now ) {
499
- // Date is past.
500
- $next_year = date( 'Y', strtotime( '+1 year' ) );
501
- $next_date = DateTime::createFromFormat( 'd-m-Y', $end . '-' . $next_year );
502
- $new_value = $next_date->format( 'U' );
503
- } else {
504
- // Date is not past.
505
- // Are we using a grace period?
506
- if ( isset( $this->products[ $product ]['fixed_period']['grace'] ) && $this->products[ $product ]['fixed_period']['grace']['num'] > 0 ) {
507
- // Are we in the grace period?
508
- $grace_period = "-" . $this->products[ $product ]['fixed_period']['grace']['num'] . " " . $this->products[ $product ]['fixed_period']['grace']['per'];
509
- $grace_date = DateTime::createFromFormat( 'U', strtotime( $grace_period, strtotime( $cur_date->format( 'd-m-Y' ) ) ) );
510
- if ( $grace_date < $now ) {
511
- // We are in grace period, set expiration as next year.
512
- $next_year = date( 'Y', strtotime( '+1 year' ) );
513
- $next_date = DateTime::createFromFormat( 'd-m-Y', $end . '-' . $next_year );
514
- $new_value = $next_date->format( 'U' );
515
- } else {
516
- // Not in grace period, set the current year.
517
- $new_value = $cur_date->format( 'U' );
518
- }
519
- } else {
520
- // No grace period, and date is not past. Use current year.
521
- $new_value = $cur_date->format( 'U' );
522
- }
523
- }
524
-
525
- return $new_value;
526
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
527
  }
1
+ <?php
2
+ /**
3
+ * The WP_Members Membership Products Class.
4
+ *
5
+ * This is the main WP_Members object class. This class contains functions
6
+ * for loading settings, shortcodes, hooks to WP, plugin dropins, constants,
7
+ * and registration fields. It also manages whether content should be blocked.
8
+ *
9
+ * @package WP-Members
10
+ * @subpackage WP_Members Membership Products Object Class
11
+ * @since 3.0.0
12
+ */
13
+
14
+ // Exit if accessed directly.
15
+ if ( ! defined( 'ABSPATH' ) ) {
16
+ exit();
17
+ }
18
+
19
+ class WP_Members_Products {
20
+
21
+ /**
22
+ * Product post type.
23
+ *
24
+ * @since 3.4.0
25
+ * @access public
26
+ * @var string
27
+ */
28
+ public $post_type = 'wpmem_product';
29
+
30
+ /**
31
+ * Product meta key.
32
+ *
33
+ * @since 3.2.0
34
+ * @access public
35
+ * @var string
36
+ */
37
+ public $post_meta = '_wpmem_products';
38
+
39
+ /**
40
+ * Product meta key stem.
41
+ *
42
+ * @since 3.2.0
43
+ * @access public
44
+ * @var string
45
+ */
46
+ public $post_stem = '_wpmem_products_';
47
+
48
+ /**
49
+ * Product details.
50
+ *
51
+ * @since 3.2.0
52
+ * @access public
53
+ * @var array {
54
+ * Array of membership product information.
55
+ *
56
+ * @type array $product_slug {
57
+ * Array of membership product settings.
58
+ *
59
+ * @type string $title The product title (user view).
60
+ * @type string $role User role, if a role is required.
61
+ * @type string $name The product slug.
62
+ * @type string $default
63
+ * @type array $expires {
64
+ * If the membership has expiration periods.
65
+ *
66
+ * $type string number|period Number of periods|Period (year/month/week/day).
67
+ * }
68
+ * }
69
+ * }
70
+ */
71
+ public $products = array();
72
+
73
+ /**
74
+ * Product meta keyed by ID.
75
+ *
76
+ * @since 3.2.4
77
+ * @access public
78
+ * @var array {
79
+ * Array of membership products keyed by CPT ID.
80
+ *
81
+ * @type string $ID The membership product slug.
82
+ * }
83
+ */
84
+ public $product_by_id = array();
85
+
86
+ /**
87
+ * Class constructor.
88
+ *
89
+ * @since 3.2.0
90
+ *
91
+ * @global object $wpmem The WP_Members object class.
92
+ */
93
+ function __construct() {
94
+
95
+ $this->load_products();
96
+
97
+ add_filter( 'wpmem_securify', array( $this, 'product_access' ) );
98
+ add_filter( 'wpmem_product_restricted_msg', array( $this, 'apply_custom_access_message' ) );
99
+ add_filter( 'wpmem_restricted_msg', array( $this, 'apply_custom_access_message' ) );
100
+ }
101
+
102
+ /**
103
+ * Loads product settings.
104
+ *
105
+ * @since 3.2.0
106
+ *
107
+ * @global object $wpdb The WPDB object class.
108
+ */
109
+ function load_products() {
110
+ global $wpdb;
111
+ $sql = "SELECT ID, post_title, post_name FROM "
112
+ . $wpdb->prefix
113
+ . "posts WHERE post_type = 'wpmem_product' AND post_status = 'publish';";
114
+ $result = $wpdb->get_results( $sql );
115
+ foreach ( $result as $plan ) {
116
+ $this->product_by_id[ $plan->ID ] = $plan->post_name;
117
+ $this->products[ $plan->post_name ]['title'] = $plan->post_title;
118
+ $post_meta = get_post_meta( $plan->ID );
119
+ foreach ( $post_meta as $key => $meta ) {
120
+ if ( false !== strpos( $key, 'wpmem_product' ) ) {
121
+ if ( 'wpmem_product_expires' == $key ) {
122
+ $meta[0] = unserialize( $meta[0] );
123
+ }
124
+ if ( 'wpmem_product_fixed_period' == $key ) {
125
+ $meta[0] = $this->explode_fixed_period( $meta[0] );
126
+ }
127
+ $this->products[ $plan->post_name ][ str_replace( 'wpmem_product_', '', $key ) ] = $meta[0];
128
+ }
129
+ }
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Gets products assigned to a post.
135
+ *
136
+ * @since 3.2.4
137
+ *
138
+ * @param integer $post_id
139
+ * @return array $products {
140
+ * Membership product slugs the post is restricted to.
141
+ *
142
+ * @type string $slug
143
+ * }
144
+ */
145
+ function get_post_products( $post_id ) {
146
+ $products = get_post_meta( $post_id, $this->post_meta, true );
147
+ /**
148
+ * Filter product access by post ID.
149
+ *
150
+ * @since 3.3.5
151
+ *
152
+ * @param array $post_products
153
+ * @param int $post_id
154
+ */
155
+ $products = apply_filters( 'wpmem_post_products', $products, $post_id );
156
+ return $products;
157
+ }
158
+
159
+ /**
160
+ * Gets default membership products.
161
+ *
162
+ * @since 3.3.0
163
+ *
164
+ * @return array $defaults
165
+ */
166
+ function get_default_products() {
167
+ // Get any default membership products.
168
+ $args = array(
169
+ 'numberposts' => -1,
170
+ 'post_type' => $this->post_type,
171
+ 'meta_key' => 'wpmem_product_default',
172
+ 'meta_value' => 1,
173
+ 'fields' => array( 'post_name' ),
174
+ );
175
+ $default_products = get_posts( $args );
176
+ $defaults = array();
177
+ if ( $default_products ) {
178
+ foreach ( $default_products as $product ) {
179
+ $defaults[] = $product->post_name;
180
+ }
181
+ }
182
+ return $defaults;
183
+ }
184
+
185
+ /**
186
+ * Sets up custom access restriction by product.
187
+ *
188
+ * @since 3.2.0
189
+ * @since 3.2.2 Merged check_product_access() logic for better messaging.
190
+ *
191
+ * @global object $post The WordPress Post object.
192
+ * @global object $wpmem The WP_Members object class.
193
+ * @param string $content
194
+ * @return string $content
195
+ */
196
+ function product_access( $content ) {
197
+
198
+ global $post, $wpmem;
199
+ // Is the user logged in and is this blocked content?
200
+ if ( ! is_admin() && is_user_logged_in() && wpmem_is_blocked() && 1 == $wpmem->enable_products ) { // @todo Should is_admin() check be run on securify in general?
201
+
202
+ // Get the post access products.
203
+ $post_products = $this->get_post_products( $post->ID );
204
+ // If the post is restricted to a product.
205
+ if ( is_array( $post_products ) && ! empty( $post_products ) ) {
206
+ $access = ( wpmem_user_has_access( $post_products ) ) ? true : false;
207
+ } else {
208
+ $access = true;
209
+ }
210
+
211
+ // Only produce the product restricted message if access is false.
212
+ if ( false === $access ) {
213
+
214
+ $message = wpmem_get_access_message( $post_products );
215
+
216
+ /**
217
+ * Filter the product restricted message HTML.
218
+ *
219
+ * @since 3.3.3
220
+ * @since 3.3.4 Added $post_products
221
+ *
222
+ * @param array $product_restricted {
223
+ * $type string $wrapper_before
224
+ * $type string $message
225
+ * $type string $wrapper_after
226
+ * }
227
+ * @param array $post_products {
228
+ * Membership product slugs the post is restricted to.
229
+ *
230
+ * @type string $slug
231
+ * }
232
+ */
233
+ $product_restricted = apply_filters( 'wpmem_product_restricted_args', array(
234
+ 'wrapper_before' => '<div class="wpmem_msg">',
235
+ 'message' => $message,
236
+ 'wrapper_after' => '</div>',
237
+ ), $post_products );
238
+
239
+ $content = $product_restricted['wrapper_before'] . $product_restricted['message'] . $product_restricted['wrapper_after'];
240
+
241
+ // Handle comments.
242
+ add_filter( 'wpmem_securify_comments', '__return_false' );
243
+ }
244
+
245
+ }
246
+
247
+ return $content;
248
+ }
249
+
250
+ /**
251
+ * Gets the access message if user does not have required membership.
252
+ *
253
+ * @since 3.4.0
254
+ *
255
+ * @param array $post_products
256
+ * @return string $message
257
+ */
258
+ function get_access_message( $post_products ) {
259
+ // Singular message if post only has one membership, otherwise multiple.
260
+ if ( 1 == count( $post_products ) ) {
261
+ $message = wpmem_get_text( 'product_restricted_single' )
262
+ . "<br />" . $this->products[ $post_products[0] ]['title'];
263
+ } else {
264
+ $message = wpmem_get_text( 'product_restricted_multiple' ) . "<br />";
265
+ foreach ( $post_products as $post_product ) {
266
+ $message .= $this->products[ $post_product ]['title'] . "<br />";
267
+ }
268
+ }
269
+ /**
270
+ * Filter the product restricted message.
271
+ *
272
+ * @since 3.2.3
273
+ *
274
+ * @param string The message.
275
+ * @param array $post_products {
276
+ * Membership product slugs the post is restricted to.
277
+ *
278
+ * @type string $slug
279
+ * }
280
+ */
281
+ $message = apply_filters( 'wpmem_product_restricted_msg', $message, $post_products );
282
+ return $message;
283
+ }
284
+
285
+ /**
286
+ * Filters the access message if the user does not have
287
+ * access to this membership.
288
+ *
289
+ * @since 3.3.4
290
+ * @since 3.4.0 Renamed from access_message().
291
+ *
292
+ * @global stdClass $post
293
+ * @param string $msg
294
+ * @return string $msg
295
+ */
296
+ function apply_custom_access_message( $msg ) {
297
+ global $post;
298
+ $post_products = $this->get_post_products( $post->ID );
299
+ if ( $post_products ) {
300
+ foreach( $post_products as $post_product ) {
301
+ $membership_id = array_search( $post_product, $this->product_by_id );
302
+ $message = wpautop( get_post_meta( $membership_id, 'wpmem_product_message', true ) );
303
+ if ( $message ) {
304
+ $product_message = ( isset( $product_message ) ) ? $product_message . $message : $message;
305
+ }
306
+ }
307
+ if ( isset( $product_message ) ) {
308
+ $msg = $product_message;
309
+ }
310
+ }
311
+ return $msg;
312
+ }
313
+
314
+ /**
315
+ * Register Membership Plans Custom Post Type
316
+ *
317
+ * @since 3.2.0
318
+ *
319
+ * @global object $wpmem The WP_Members object class.
320
+ */
321
+ function add_cpt() {
322
+
323
+ global $wpmem;
324
+
325
+ $args = array( 'capabilities' => 'manage_options', );
326
+ /**
327
+ * Filter customizable elements of the membership custom post type.
328
+ *
329
+ * @since 3.3.5
330
+ *
331
+ * @param array
332
+ */
333
+ $args = apply_filters( 'wpmem_membership_cpt_args', $args );
334
+
335
+ $singular = __( 'Product', 'wp-members' );
336
+ $plural = __( 'Products', 'wp-members' );
337
+
338
+ $labels = array(
339
+ 'name' => $plural,
340
+ 'singular_name' => $singular,
341
+ 'menu_name' => __( 'Memberships', 'wp-members' ),
342
+ 'all_items' => sprintf( __( 'All %s', 'wp-members' ), $plural ),
343
+ 'add_new_item' => sprintf( __( 'Add New %s', 'wp-members' ), $singular ),
344
+ 'add_new' => __( 'Add New', 'wp-members' ),
345
+ 'new_item' => sprintf( __( 'New %s', 'wp-members' ), $singular ),
346
+ 'edit_item' => sprintf( __( 'Edit %s', 'wp-members' ), $singular ),
347
+ 'update_item' => sprintf( __( 'Update %s', 'wp-members' ), $singular ),
348
+ 'view_item' => sprintf( __( 'View %s', 'wp-members' ), $singular ),
349
+ 'view_items' => sprintf( __( 'View %s', 'wp-members' ), $plural ),
350
+ 'search_items' => sprintf( __( 'Search %s', 'wp-members' ), $plural ),
351
+ 'not_found' => __( 'Not found', 'wp-members' ),
352
+ 'not_found_in_trash' => __( 'Not found in Trash', 'wp-members' ),
353
+ 'insert_into_item' => __( 'Insert into item', 'wp-members' ),
354
+ 'publish' => sprintf( __( 'Save %s Details', 'wp-members' ), $singular ),
355
+ );
356
+ $args = array(
357
+ 'label' => __( 'Membership Product', 'wp-members' ),
358
+ 'description' => __( 'WP-Members Membership Products', 'wp-members' ),
359
+ 'labels' => $labels,
360
+ 'supports' => array( 'title', 'page-attributes' ),
361
+ 'hierarchical' => true,
362
+ 'public' => false,
363
+ 'show_ui' => ( $wpmem->enable_products ) ? true : false,
364
+ 'show_in_menu' => ( $wpmem->enable_products ) ? true : false,
365
+ 'menu_position' => 58,
366
+ 'menu_icon' => 'dashicons-groups',
367
+ 'show_in_admin_bar' => false,
368
+ 'show_in_nav_menus' => false,
369
+ 'can_export' => true,
370
+ 'has_archive' => false,
371
+ 'exclude_from_search' => true,
372
+ 'publicly_queryable' => false,
373
+ 'query_var' => 'membership_product',
374
+ 'rewrite' => false,
375
+ 'capability_type' => 'page',
376
+ 'capabilities' => array(
377
+ 'publish_posts' => $args['capabilities'],
378
+ 'edit_posts' => $args['capabilities'],
379
+ 'delete_posts' => $args['capabilities'],
380
+ 'edit_post' => $args['capabilities'],
381
+ 'delete_post' => $args['capabilities'],
382
+ 'read_post' => $args['capabilities'],
383
+ ),
384
+ 'show_in_rest' => false,
385
+ //'register_meta_box_cb' => '', // callback for meta box
386
+ );
387
+ register_post_type( $this->post_type, $args );
388
+ }
389
+
390
+ /**
391
+ * Get all posts tagged to a specified product.
392
+ *
393
+ * @since 3.3.0
394
+ *
395
+ * @global stdClass $wpdb
396
+ *
397
+ * @param string $product_meta
398
+ * @return array $post_ids
399
+ */
400
+ function get_all_posts( $product_meta ) {
401
+ global $wpdb;
402
+ $results = $wpdb->get_results( $wpdb->prepare( "
403
+ SELECT post_id
404
+ FROM {$wpdb->postmeta}
405
+ WHERE meta_key = %s
406
+ ", $this->post_stem . $product_meta ), ARRAY_N );
407
+ foreach ( $results as $result ) {
408
+ $post_ids[] = $result[0];
409
+ }
410
+ return $post_ids;
411
+ }
412
+
413
+ /**
414
+ * Utility to explode fixed period.
415
+ *
416
+ * @since 3.3.5
417
+ */
418
+ function explode_fixed_period( $array ) {
419
+ $period_parts = explode( "-", $array );
420
+ $period['start'] = ( $period_parts ) ? $period_parts[0] . '-' . $period_parts[1] : '';
421
+ $period['end'] = ( $period_parts ) ? $period_parts[2] . '-' . $period_parts[3] : '';
422
+ $period['grace']['num'] = ( $period_parts && isset( $period_parts[4] ) ) ? $period_parts[4] : '';
423
+ $period['grace']['per'] = ( $period_parts && isset( $period_parts[5] ) ) ? $period_parts[5] : '';
424
+ return $period;
425
+ }
426
+
427
+ /**
428
+ * Set an expiration date.
429
+ *
430
+ * @since 3.3.5
431
+ *
432
+ * @param string $product
433
+ * @param int $user_id
434
+ * @param mixed $set_date
435
+ * @param mixed $pre_value
436
+ * @param boolean $renew
437
+ * @return mixed $new_value
438
+ */
439
+ function set_product_expiration( $product, $user_id, $set_date, $prev_value, $renew ) {
440
+ // If this is setting a specific date.
441
+ if ( $set_date ) {
442
+ $new_value = strtotime( $set_date );
443
+ } else {
444
+ // Either setting initial expiration based on set time period, or adding to the existing date (renewal/extending).
445
+ $raw_add = explode( "|", $this->products[ $product ]['expires'][0] );
446
+ $add_period = ( 1 < $raw_add[0] ) ? $raw_add[0] . " " . $raw_add[1] . "s" : $raw_add[0] . " " . $raw_add[1];
447
+
448
+ if ( $prev_value ) {
449
+ if ( isset( $this->products[ $product ]['no_gap'] ) && 1 == $this->products[ $product ]['no_gap'] ) {
450
+ // Add to the user's existing date (no gap).
451
+ $new_value = strtotime( $add_period, $prev_value );
452
+ } else {
453
+ // Add to the user either from end or now (whichever is later; i.e. allow gaps (default)).
454
+ if ( wpmem_user_has_access( $product, $user_id ) ) {
455
+ // if not expired, set from when they expire.
456
+ $new_value = strtotime( $add_period, $prev_value );
457
+ } else {
458
+ // if expired, set from today.
459
+ $new_value = strtotime( $add_period );
460
+ }
461
+ }
462
+ } else {
463
+ // User doesn't have this membershp. Go ahead and add it.
464
+
465
+ // If we are using fixed period expiration, calculate the expiration date
466
+ if ( isset( $this->products[ $product ] ) && isset( $this->products[ $product ]['fixed_period'] ) ) {
467
+ // Calculate the fixed period expiration.
468
+ $new_value = $this->calculate_fixed_period ( $product );
469
+ } else {
470
+ // Just add to the existing expiration.
471
+ $new_value = strtotime( $add_period );
472
+ }
473
+ }
474
+ }
475
+
476
+ /**
477
+ * Filter the expiration date.
478
+ *
479
+ * @since 3.3.2
480
+ *
481
+ * @param int|boolean $new_value Unix timestamp of new expiration, true|false if not an expiry product.
482
+ * @param int|boolean $prev_value The user's current value (prior to updating).
483
+ * @param boolean $renew Is this a renewal transaction?
484
+ */
485
+ $new_value = apply_filters( 'wpmem_user_product_set_expiration', $new_value, $prev_value, $renew );
486
+
487
+ return $new_value;
488
+ }
489
+
490
+ /**
491
+ * Calculate a fixed period expiration.
492
+ *
493
+ * @since 3.3.5
494
+ *
495
+ * @param string $product
496
+ * @return string $timestamp
497
+ */
498
+ function calculate_fixed_period( $product ) {
499
+ // Use fixed period expiration.
500
+ $end = $this->products[ $product ]['fixed_period']['end'];
501
+
502
+ // Get the current year.
503
+ $current_year = date( 'Y' );
504
+
505
+ // Format period end date for current year.
506
+ $cur_date = DateTime::createFromFormat( 'd-m-Y', $end . '-' . $current_year ); //DateTime( $start_date );
507
+
508
+ // Where are we now?
509
+ $now = new DateTime();
510
+
511
+ // If date is past, set next period.
512
+ if ( $cur_date < $now ) {
513
+ // Date is past.
514
+ $next_year = date( 'Y', strtotime( '+1 year' ) );
515
+ $next_date = DateTime::createFromFormat( 'd-m-Y', $end . '-' . $next_year );
516
+ $new_value = $next_date->format( 'U' );
517
+ } else {
518
+ // Date is not past.
519
+ // Are we using a grace period?
520
+ if ( isset( $this->products[ $product ]['fixed_period']['grace'] ) && $this->products[ $product ]['fixed_period']['grace']['num'] > 0 ) {
521
+ // Are we in the grace period?
522
+ $grace_period = "-" . $this->products[ $product ]['fixed_period']['grace']['num'] . " " . $this->products[ $product ]['fixed_period']['grace']['per'];
523
+ $grace_date = DateTime::createFromFormat( 'U', strtotime( $grace_period, strtotime( $cur_date->format( 'd-m-Y' ) ) ) );
524
+ if ( $grace_date < $now ) {
525
+ // We are in grace period, set expiration as next year.
526
+ $next_year = date( 'Y', strtotime( '+1 year' ) );
527
+ $next_date = DateTime::createFromFormat( 'd-m-Y', $end . '-' . $next_year );
528
+ $new_value = $next_date->format( 'U' );
529
+ } else {
530
+ // Not in grace period, set the current year.
531
+ $new_value = $cur_date->format( 'U' );
532
+ }
533
+ } else {
534
+ // No grace period, and date is not past. Use current year.
535
+ $new_value = $cur_date->format( 'U' );
536
+ }
537
+ }
538
+
539
+ return $new_value;
540
+ }
541
  }
includes/class-wp-members-pwd-reset.php CHANGED
@@ -1,289 +1,302 @@
1
- <?php
2
- /**
3
- * An object class for WP-Members Password Reset.
4
- *
5
- * @since 3.3.5
6
- * @since 3.3.8 Rebuild processing to utilize WP native functions and user_activation_key.
7
- */
8
- class WP_Members_Pwd_Reset {
9
-
10
- /**
11
- * Message containers.
12
- *
13
- * @since 3.3.5
14
- */
15
- public $form_submitted_key_not_found;
16
- public $form_load_key_not_found;
17
- public $key_is_expired;
18
-
19
- /**
20
- * Meta containers
21
- *
22
- * @since 3.3.5
23
- */
24
- public $reset_key_nonce = "_wpmem_pwd_reset";
25
- public $form_action = 'set_password_from_key';
26
-
27
- /**
28
- * Initialize the class.
29
- *
30
- * @since 3.3.5
31
- */
32
- function __construct() {
33
-
34
- $defaults = array(
35
- 'form_submitted_key_not_found' => __( "Sorry, no password reset key was found. Please check your email and try again.", 'wp-members' ),
36
- 'form_load_key_not_found' => __( "Sorry, no password reset key was found. Please check your email and try again.", 'wp-members' ),
37
- 'key_is_expired' => __( "Sorry, the password reset key is expired.", 'wp-members' ),
38
- );
39
-
40
- /**
41
- * Filter default dialogs.
42
- *
43
- * @since 3.3.8
44
- *
45
- * @param array $defaults
46
- */
47
- $defaults = apply_filters( 'wpmem_pwd_reset_default_dialogs', $defaults );
48
-
49
- foreach ( $defaults as $key => $value ) {
50
- $this->{$key} = $value;
51
- }
52
-
53
- add_filter( 'wpmem_email_filter', array( $this, 'add_reset_key_to_email' ), 10, 3 );
54
- add_filter( 'the_content', array( $this, 'display_content' ), 100 );
55
- add_filter( 'wpmem_login_hidden_fields', array( $this, 'add_hidden_form_field' ), 10, 2 );
56
- add_action( 'wpmem_get_action', array( $this, 'get_wpmem_action' ) );
57
- add_filter( 'wpmem_regchk', array( $this, 'change_regchk' ), 10, 2 );
58
- add_filter( 'wpmem_resetpassword_form_defaults', array( $this, 'reset_password_form' ) );
59
- }
60
-
61
- /**
62
- * Add reset key to the email.
63
- *
64
- * @since 3.3.5
65
- *
66
- * @param array $arr
67
- * @param array $wpmem_fields
68
- * @param array $field_data
69
- * @return array $arr
70
- */
71
- function add_reset_key_to_email( $arr, $wpmem_fields, $field_data ) {
72
-
73
- if ( $arr['toggle'] == 'repass' ) {
74
-
75
- $user = get_user_by( 'ID', $arr['user_id'] );
76
-
77
- // Get the stored key.
78
- $key = $this->get_password_reset_key( $user );
79
- $query_args = array(
80
- 'a' => $this->form_action,
81
- 'key' => $key,
82
- 'login' => $user->user_login,
83
- );
84
-
85
- // Generate reset link.
86
- $link = add_query_arg( $query_args, trailingslashit( wpmem_profile_url() ) );
87
-
88
- // Does email body have the [reset_link] shortcode?
89
- if ( strpos( $arr['body'], '[reset_link]' ) ) {
90
- $arr['body'] = str_replace( '[reset_link]', $link, $arr['body'] );
91
- } else {
92
- // Add text and link to the email body.
93
- $arr['body'] = $arr['body'] . "\r\n"
94
- . $link;
95
- }
96
- }
97
- return $arr;
98
- }
99
-
100
- /**
101
- * Display page content to user.
102
- *
103
- * @since 3.3.5
104
- *
105
- * @param string $content
106
- * @return string $content
107
- */
108
- function display_content( $content ) {
109
-
110
- global $wpmem;
111
-
112
- if ( ! is_user_logged_in() && in_the_loop() && $this->form_action == wpmem_get( 'a', false, 'request' ) ) {
113
- // Define variables
114
- $result = '';
115
- $user_id = false;
116
- $msg = '';
117
- $form = '';
118
-
119
- // Check for key.
120
- $key = sanitize_text_field( wpmem_get( 'key', false, 'request' ) );
121
- $user_login = sanitize_text_field( wpmem_get( 'login', false, 'request' ) );
122
- $pass1 = wpmem_get( 'pass1', false );
123
- $pass2 = wpmem_get( 'pass2', false );
124
-
125
- // Set an error container.
126
- $errors = new WP_Error();
127
-
128
- /**
129
- * Validate the key.
130
- *
131
- * WP_Error will be invalid_key or expired_key. Process triggers password_reset_expiration filter
132
- * filtering DAY_IN_SECONDS default. Filter password_reset_key_expired is also triggered filtering
133
- * the return value (which can be used to override the expired/invalid check based on user_id).
134
- *
135
- * WP filter/actions triggered:
136
- * - password_reset_expiration
137
- * - password_reset_key_expired
138
- *
139
- * @see https://developer.wordpress.org/reference/functions/check_password_reset_key/
140
- * @param string Hash to validate sending user's password.
141
- * @param string The user login.
142
- * @return WP_User|WP_Error WP_User object on success, WP_Error object for invalid or expired keys (invalid_key|expired_key).
143
- */
144
- $user = check_password_reset_key( $key, $user_login );
145
-
146
- // Validate
147
- if ( 1 == wpmem_get( 'formsubmit' ) && false !== wpmem_get( 'a', false, $this->form_action ) ) {
148
-
149
- // Verify nonce.
150
- if ( ! wp_verify_nonce( $_REQUEST['_wpmem_pwdchange_nonce'], 'wpmem_shortform_nonce' ) ) {
151
- $errors->add( 'reg_generic', $wpmem->get_text( 'reg_generic' ) );
152
- }
153
-
154
- // Make sure submitted passwords match.
155
- if ( $pass1 !== $pass2 ) {
156
- // Legacy WP-Members error.
157
- $result = 'pwdchangerr';
158
- $msg = wpmem_inc_regmessage( 'pwdchangerr' );
159
- // WP Error.
160
- $errors->add( 'password_reset_mismatch', __( 'The passwords do not match.' ) );
161
- }
162
-
163
- /** This action is documented in wp-login.php */
164
- // do_action( 'validate_password_reset', $errors, $user );
165
-
166
- if ( ( ! $errors->has_errors() ) && isset( $pass1 ) && ! empty( $pass1 ) ) {
167
- reset_password( $user, $pass1 );
168
- $msg = wpmem_inc_regmessage( 'pwdchangesuccess' ) . $wpmem->forms->do_login_form( 'pwdreset' );
169
- $result = 'pwdchangesuccess';
170
- }
171
- }
172
-
173
- if ( $result != 'pwdchangesuccess' ) {
174
-
175
- if ( 'invalid_key' == $user->get_error_code() ) {
176
- // If somehow the form was submitted but the key not found.
177
- $msg = wpmem_inc_regmessage( 'invalid_key', $this->form_submitted_key_not_found );
178
- }
179
-
180
- $form = wpmem_change_password_form();
181
-
182
- }
183
-
184
- $content = $msg . $form;
185
- }
186
-
187
- return $content;
188
- }
189
-
190
- /**
191
- * Add hidden form field for form action.
192
- *
193
- * @since 3.3.5
194
- *
195
- * @param string $hidden_fields
196
- * @return string $hidden_fields
197
- */
198
- function add_hidden_form_field( $hidden_fields, $action ) {
199
- if ( $this->form_action == wpmem_get( 'a', false, 'request' ) ) {
200
- $hidden_fields = str_replace( 'pwdchange', $this->form_action, $hidden_fields );
201
- $hidden_fields.= wpmem_create_formfield( 'key', 'hidden', wpmem_get( 'key', null, 'request' ) );
202
- $hidden_fields.= wpmem_create_formfield( 'login', 'hidden', wpmem_get( 'login', null, 'request' ) );
203
- }
204
- return $hidden_fields;
205
- }
206
-
207
- /**
208
- * Get the wpmem action variable.
209
- *
210
- * @since 3.3.5
211
- */
212
- function get_wpmem_action() {
213
- global $wpmem;
214
- if ( 'pwdreset' == $wpmem->action && isset( $_POST['formsubmit'] ) ) {
215
-
216
- $user_to_check = wpmem_get( 'user', false );
217
- $user_to_check = ( strpos( $user_to_check, '@' ) ) ? sanitize_email( $user_to_check ) : sanitize_user( $user_to_check );
218
-
219
- if ( username_exists( $user_to_check ) ) {
220
- $user = get_user_by( 'login', $user_to_check );
221
- if ( ( 1 == $wpmem->mod_reg ) && ( 1 != get_user_meta( $user->ID, 'active', true ) ) ) {
222
- $user = false;
223
- }
224
- } elseif ( email_exists( $user_to_check ) ) {
225
- $user = get_user_by( 'email', $user_to_check );
226
- } else {
227
- $user = false;
228
- }
229
-
230
- if ( false === $user ) {
231
- return "pwdreseterr";
232
- }
233
-
234
- $new_pass = '';
235
- wpmem_email_to_user( $user->ID, $new_pass, 3 );
236
- do_action( 'wpmem_pwd_reset', $user->ID, $new_pass );
237
- $wpmem->action = 'pwdreset_link';
238
- global $wpmem_regchk;
239
- $wpmem->regchk = 'pwdresetsuccess';
240
- return "pwdresetsuccess";
241
- }
242
- return;
243
- }
244
-
245
- /**
246
- * Changes the wpmem_regchk value.
247
- *
248
- * @since 3.3.5
249
- *
250
- * @param string $regchk
251
- */
252
- function change_regchk( $regchk, $action ) {
253
- global $wpmem;
254
- if ( 'pwdreset_link' == $action && 'pwdresetsuccess' == $wpmem->regchk ) {
255
- global $wpmem;
256
- $wpmem->action = 'pwdreset';
257
- return 'pwdresetsuccess';
258
- }
259
- return $regchk;
260
- }
261
-
262
- /**
263
- * Filter the reset password form.
264
- *
265
- * @since 3.3.5
266
- *
267
- * @param array $args
268
- */
269
- function reset_password_form( $args ) {
270
- global $wpmem;
271
- $args['inputs'][0]['name'] = $wpmem->get_text( 'login_username' );
272
- unset( $args['inputs'][1] );
273
- return $args;
274
- }
275
-
276
- /**
277
- * Sets and gets the password reset key.
278
- *
279
- * This function is a wrapper for the WP function get_password_reset_key().
280
- *
281
- * @since 3.3.8
282
- *
283
- * @param object $user
284
- * @return string The reset key.
285
- */
286
- private function get_password_reset_key( $user ) {
287
- return get_password_reset_key( $user );
288
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  }
1
+ <?php
2
+ /**
3
+ * An object class for WP-Members Password Reset.
4
+ *
5
+ * @since 3.3.5
6
+ * @since 3.3.8 Rebuild processing to utilize WP native functions and user_activation_key.
7
+ */
8
+ class WP_Members_Pwd_Reset {
9
+
10
+ /**
11
+ * Message containers.
12
+ *
13
+ * @since 3.3.5
14
+ */
15
+ public $form_submitted_key_not_found;
16
+ public $form_load_key_not_found;
17
+ public $key_is_expired;
18
+
19
+ /**
20
+ * Meta containers
21
+ *
22
+ * @since 3.3.5
23
+ */
24
+ public $reset_key_nonce = "_wpmem_pwd_reset";
25
+ public $form_action = 'set_password_from_key';
26
+
27
+ /**
28
+ * Initialize the class.
29
+ *
30
+ * @since 3.3.5
31
+ */
32
+ function __construct() {
33
+
34
+ $defaults = array(
35
+ 'form_submitted_key_not_found' => __( "Sorry, no password reset key was found. Please check your email and try again.", 'wp-members' ),
36
+ 'form_load_key_not_found' => __( "Sorry, no password reset key was found. Please check your email and try again.", 'wp-members' ),
37
+ 'key_is_expired' => __( "Sorry, the password reset key is expired.", 'wp-members' ),
38
+ );
39
+
40
+ /**
41
+ * Filter default dialogs.
42
+ *
43
+ * @since 3.3.8
44
+ *
45
+ * @param array $defaults
46
+ */
47
+ $defaults = apply_filters( 'wpmem_pwd_reset_default_dialogs', $defaults );
48
+
49
+ foreach ( $defaults as $key => $value ) {
50
+ $this->{$key} = $value;
51
+ }
52
+
53
+ add_filter( 'wpmem_email_filter', array( $this, 'add_reset_key_to_email' ), 10, 3 );
54
+ add_filter( 'the_content', array( $this, 'display_content' ), 100 );
55
+ add_filter( 'wpmem_login_hidden_fields', array( $this, 'add_hidden_form_field' ), 10, 2 );
56
+ add_action( 'wpmem_get_action', array( $this, 'get_wpmem_action' ) );
57
+ add_filter( 'wpmem_regchk', array( $this, 'change_regchk' ), 10, 2 );
58
+ add_filter( 'wpmem_resetpassword_form_defaults', array( $this, 'reset_password_form' ) );
59
+ }
60
+
61
+ /**
62
+ * Add reset key to the email.
63
+ *
64
+ * @since 3.3.5
65
+ *
66
+ * @param array $arr
67
+ * @param array $wpmem_fields
68
+ * @param array $field_data
69
+ * @return array $arr
70
+ */
71
+ function add_reset_key_to_email( $arr, $wpmem_fields, $field_data ) {
72
+
73
+ if ( $arr['toggle'] == 'repass' ) {
74
+
75
+ $user = get_user_by( 'ID', $arr['user_id'] );
76
+
77
+ // Get the stored key.
78
+ $key = $this->get_password_reset_key( $user );
79
+ $query_args = array(
80
+ 'a' => $this->form_action,
81
+ 'key' => $key,
82
+ 'login' => $user->user_login,
83
+ );
84
+
85
+ // urlencode, primarily for user_login with a space.
86
+ $query_args = array_map( 'rawurlencode', $query_args );
87
+
88
+ // Generate reset link.
89
+ $link = add_query_arg( $query_args, trailingslashit( wpmem_profile_url() ) );
90
+
91
+ // Does email body have the [reset_link] shortcode?
92
+ if ( strpos( $arr['body'], '[reset_link]' ) ) {
93
+ $arr['body'] = str_replace( '[reset_link]', $link, $arr['body'] );
94
+ } else {
95
+ // Add text and link to the email body.
96
+ $arr['body'] = $arr['body'] . "\r\n"
97
+ . $link;
98
+ }
99
+ }
100
+ return $arr;
101
+ }
102
+
103
+ /**
104
+ * Display page content to user.
105
+ *
106
+ * @since 3.3.5
107
+ *
108
+ * @param string $content
109
+ * @return string $content
110
+ */
111
+ function display_content( $content ) {
112
+
113
+ global $wpmem;
114
+
115
+ if ( ! is_user_logged_in() && in_the_loop() && $this->form_action == wpmem_get( 'a', false, 'request' ) ) {
116
+ // Define variables
117
+ $result = '';
118
+ $user_id = false;
119
+ $msg = '';
120
+ $form = '';
121
+
122
+ // Check for key.
123
+ $key = sanitize_text_field( wpmem_get( 'key', false, 'request' ) );
124
+ $user_login = sanitize_text_field( wpmem_get( 'login', false, 'request' ) );
125
+ $pass1 = wpmem_get( 'pass1', false );
126
+ $pass2 = wpmem_get( 'pass2', false );
127
+
128
+ // Set an error container.
129
+ $errors = new WP_Error();
130
+
131
+ /**
132
+ * Validate the key.
133
+ *
134
+ * WP_Error will be invalid_key or expired_key. Process triggers password_reset_expiration filter
135
+ * filtering DAY_IN_SECONDS default. Filter password_reset_key_expired is also triggered filtering
136
+ * the return value (which can be used to override the expired/invalid check based on user_id).
137
+ *
138
+ * WP filter/actions triggered:
139
+ * - password_reset_expiration
140
+ * - password_reset_key_expired
141
+ *
142
+ * @see https://developer.wordpress.org/reference/functions/check_password_reset_key/
143
+ * @param string Hash to validate sending user's password.
144
+ * @param string The user login.
145
+ * @return WP_User|WP_Error WP_User object on success, WP_Error object for invalid or expired keys (invalid_key|expired_key).
146
+ */
147
+ $user = check_password_reset_key( $key, $user_login );
148
+
149
+ if ( $user->has_errors() ) {
150
+ $errors->add( 'user_not_found', $this->form_load_key_not_found );
151
+ }
152
+
153
+ // Validate
154
+ if ( 1 == wpmem_get( 'formsubmit' ) && false !== wpmem_get( 'a', false, $this->form_action ) ) {
155
+
156
+ // Verify nonce.
157
+ if ( ! wp_verify_nonce( $_REQUEST['_wpmem_pwdchange_nonce'], 'wpmem_shortform_nonce' ) ) {
158
+ $errors->add( 'reg_generic', wpmem_get_text( 'reg_generic' ) );
159
+ }
160
+
161
+ // Make sure submitted passwords match.
162
+ if ( $pass1 !== $pass2 ) {
163
+ // Legacy WP-Members error.
164
+ $result = 'pwdchangerr';
165
+ $msg = wpmem_get_display_message( 'pwdchangerr' );
166
+ // WP Error.
167
+ $errors->add( 'password_reset_mismatch', __( 'The passwords do not match.' ) );
168
+ }
169
+
170
+ /** This action is documented in wp-login.php */
171
+ // do_action( 'validate_password_reset', $errors, $user );
172
+
173
+ if ( ( ! $errors->has_errors() ) && isset( $pass1 ) && ! empty( $pass1 ) ) {
174
+ reset_password( $user, $pass1 );
175
+ $msg = wpmem_get_display_message( 'pwdchangesuccess' ) . wpmem_login_form( 'pwdreset' );
176
+ $result = 'pwdchangesuccess';
177
+ }
178
+ }
179
+
180
+ if ( $result != 'pwdchangesuccess' ) {
181
+
182
+ if ( 'invalid_key' == $user->get_error_code() ) {
183
+ // If somehow the form was submitted but the key not found.
184
+ $pwd_reset_link = wpmem_profile_url( 'pwdreset' );
185
+ $msg = wpmem_get_display_message( 'invalid_key', $this->form_submitted_key_not_found . '<br /><a href="' . $pwd_reset_link . '">Request a new reset key.</a>' );
186
+ $form = '';
187
+ } else {
188
+ $form = wpmem_change_password_form();
189
+ }
190
+
191
+ }
192
+
193
+ $content = $msg . $form;
194
+ }
195
+
196
+ return $content;
197
+ }
198
+
199
+ /**
200
+ * Add hidden form field for form action.
201
+ *
202
+ * @since 3.3.5
203
+ *
204
+ * @param string $hidden_fields
205
+ * @return string $hidden_fields
206
+ */
207
+ function add_hidden_form_field( $hidden_fields, $action ) {
208
+ if ( $this->form_action == wpmem_get( 'a', false, 'request' ) ) {
209
+ $hidden_fields = str_replace( 'pwdchange', $this->form_action, $hidden_fields );
210
+ $hidden_fields.= wpmem_form_field( array( 'name' => 'key', 'type' => 'hidden', 'value' => sanitize_text_field( wpmem_get( 'key', null, 'request' ) ) ) );
211
+ $hidden_fields.= wpmem_form_field( array( 'name' => 'login', 'type' => 'hidden', 'value' => sanitize_user( wpmem_get( 'login', null, 'request' ) ) ) );
212
+ }
213
+ return $hidden_fields;
214
+ }
215
+
216
+ /**
217
+ * Get the wpmem action variable.
218
+ *
219
+ * @since 3.3.5
220
+ */
221
+ function get_wpmem_action() {
222
+ global $wpmem;
223
+ if ( 'pwdreset' == $wpmem->action && isset( $_POST['formsubmit'] ) ) {
224
+
225
+ if ( ! wp_verify_nonce( $_REQUEST['_wpmem_pwdreset_nonce'], 'wpmem_shortform_nonce' ) ) {
226
+ return "reg_generic";
227
+ }
228
+
229
+ $user_to_check = wpmem_get( 'user', false );
230
+ $user_to_check = ( strpos( $user_to_check, '@' ) ) ? sanitize_email( $user_to_check ) : sanitize_user( $user_to_check );
231
+
232
+ if ( username_exists( $user_to_check ) ) {
233
+ $user = get_user_by( 'login', $user_to_check );
234
+ if ( ( 1 == $wpmem->mod_reg ) && ( 1 != get_user_meta( $user->ID, 'active', true ) ) ) {
235
+ $user = false;
236
+ }
237
+ } elseif ( email_exists( $user_to_check ) ) {
238
+ $user = get_user_by( 'email', $user_to_check );
239
+ } else {
240
+ $user = false;
241
+ }
242
+
243
+ if ( false === $user ) {
244
+ return "pwdreseterr";
245
+ }
246
+
247
+ $new_pass = '';
248
+ wpmem_email_to_user( $user->ID, $new_pass, 3 );
249
+ /** This action is documented in /includes/class-wp-members-user.php */
250
+ do_action( 'wpmem_pwd_reset', $user->ID, $new_pass );
251
+ $wpmem->action = 'pwdreset_link';
252
+ $wpmem->regchk = 'pwdresetsuccess';
253
+ return "pwdresetsuccess";
254
+ }
255
+ return;
256
+ }
257
+
258
+ /**
259
+ * Changes the wpmem_regchk value.
260
+ *
261
+ * @since 3.3.5
262
+ *
263
+ * @param string $regchk
264
+ */
265
+ function change_regchk( $regchk, $action ) {
266
+ global $wpmem;
267
+ if ( 'pwdreset_link' == $action && 'pwdresetsuccess' == $wpmem->regchk ) {
268
+ global $wpmem;
269
+ $wpmem->action = 'pwdreset';
270
+ return 'pwdresetsuccess';
271
+ }
272
+ return $regchk;
273
+ }
274
+
275
+ /**
276
+ * Filter the reset password form.
277
+ *
278
+ * @since 3.3.5
279
+ *
280
+ * @param array $args
281
+ */
282
+ function reset_password_form( $args ) {
283
+ global $wpmem;
284
+ $args['inputs'][0]['name'] = wpmem_get_text( 'login_username' );
285
+ unset( $args['inputs'][1] );
286
+ return $args;
287
+ }
288
+
289
+ /**
290
+ * Sets and gets the password reset key.
291
+ *
292
+ * This function is an alias for the WP function get_password_reset_key().
293
+ *
294
+ * @since 3.3.8
295
+ *
296
+ * @param object $user
297
+ * @return string The reset key.
298
+ */
299
+ private function get_password_reset_key( $user ) {
300
+ return get_password_reset_key( $user );
301
+ }
302
  }
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-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.
@@ -57,7 +57,7 @@ class WP_Members_Shortcodes {
57
  }
58
 
59
  /**
60
- * Function for forms called by shortcode.
61
  *
62
  * @since 3.0.0
63
  * @since 3.1.3 Added forgot_username shortcode.
@@ -75,138 +75,124 @@ class WP_Members_Shortcodes {
75
  * Possible shortcode attributes (some vary by form).
76
  *
77
  * @type string $id An ID for the form.
78
- * @type string $login Idenifies login form.
79
- * @type string $password Idenifies reset/change password form (login state dependent).
80
- * @type string $user_edit Idenifies user profile edit form.
81
- * @type string $forgot_username Idenifies forgot username form.
82
- * @type string $register Idenifies register form.
83
- * @type string $redirect_to URL to redirect to on form submit.
84
- * @type string $texturize Add/fix texturization for the from HTML.
85
- * @type string $exclude_fields Fields to exclude (register/user_edit forms only).
86
- * @type string $include_fields Fields to include (register/user_edit forms only).
 
87
  * @type string $product Register for specific product (if products are enabled).
88
  * }
89
- * @param string $content
90
- * @param string $tag
91
- * @return string $content
92
  */
93
- function forms( $atts, $content = null, $tag = 'wpmem_form' ) {
94
 
95
  global $wpmem, $wpmem_themsg;
96
 
97
  // Defaults.
98
- $redirect_to = ( isset( $atts['redirect_to'] ) ) ? $atts['redirect_to'] : null;
99
- $texturize = ( isset( $atts['texturize'] ) ) ? $atts['texturize'] : false;
 
 
 
 
 
100
 
101
- $customizer = ( is_customize_preview() ) ? get_theme_mod( 'wpmem_show_logged_out_state', false ) : false;
 
102
 
103
- /*
104
- * The [wpmem_form] shortcode requires additional tags (login, register, etc) that
105
- * will be in the $atts array. If $atts is not an array, no additional tags were
106
- * given, so there is nothing to render.
107
- */
108
- if ( is_array( $atts ) ) {
109
 
110
- // If $atts is an array, get the tag from the array so we know what form to render.
111
- switch ( $atts ) {
112
 
113
- case in_array( 'wp_login', $atts ):
114
- $content = wpmem_wp_login_form( $atts );
115
- break;
116
-
117
- case in_array( 'login', $atts ):
118
- if ( is_user_logged_in() && '1' != $customizer ) {
119
- /*
120
- * If the user is logged in, return any nested content (if any)
121
- * or the default bullet links if no nested content.
122
- */
123
- $content = ( $content ) ? $content : wpmem_inc_memberlinks( 'login' );
124
- } else {
125
- /*
126
- * If the user is not logged in, return an error message if a login
127
- * error state exists, or return the login form.
128
- */
129
- $content = ( $wpmem->regchk == 'loginfailed' || ( is_customize_preview() && get_theme_mod( 'wpmem_show_form_message_dialog', false ) ) ) ? wpmem_inc_loginfailed() : wpmem_inc_login( 'login', $redirect_to );
130
- }
131
- break;
132
 
133
- case in_array( 'register', $atts ):
134
-
135
- // Set up register form args.
136
- $reg_form_args = array( 'tag' => 'new' );
137
- if ( isset( $redirect_to ) ) {
138
- $reg_form_args['redirect_to'] = $redirect_to;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  }
140
-
141
- if ( is_user_logged_in() && '1' != $customizer ) {
142
- /*
143
- * If the user is logged in, return any nested content (if any)
144
- * or the default bullet links if no nested content.
145
- */
146
- $content = ( $content ) ? $content : wpmem_inc_memberlinks( 'register' );
147
- } elseif ( is_user_logged_in() && is_customize_preview() && get_theme_mod( 'wpmem_show_form_message_dialog', false ) ) {
148
- $wpmem_themsg = __( "This is a generic message to display the form message dialog in the Customizer.", 'wp-members' );
149
- $content = wpmem_inc_regmessage( $wpmem->regchk, $wpmem_themsg );
150
- $content .= wpmem_register_form( $reg_form_args );
151
- } else {
152
- if ( $wpmem->regchk == 'loginfailed' ) {
153
- $content = wpmem_inc_loginfailed() . wpmem_inc_login( 'login', $redirect_to );
154
- break;
155
- }
156
- // @todo Can this be moved into another function? Should $wpmem get an error message handler?
157
- if ( $wpmem->regchk == 'captcha' ) {
158
- global $wpmem_captcha_err;
159
- $wpmem_themsg = __( 'There was an error with the CAPTCHA form.' ) . '<br /><br />' . $wpmem_captcha_err;
160
- }
161
- $content = ( $wpmem_themsg || $wpmem->regchk == 'success' ) ? wpmem_inc_regmessage( $wpmem->regchk, $wpmem_themsg ) : '';
162
- $content .= ( $wpmem->regchk == 'success' ) ? wpmem_inc_login( 'login', $redirect_to ) : wpmem_register_form( $reg_form_args );
163
  }
164
- break;
 
 
 
165
 
166
- case in_array( 'password', $atts ):
167
- $content = wpmem_page_pwd_reset( $wpmem->regchk, $content );
168
- break;
169
 
170
- case in_array( 'user_edit', $atts ):
171
- $content = wpmem_page_user_edit( $wpmem->regchk, $content );
172
- break;
173
 
174
- case in_array( 'forgot_username', $atts ):
175
- $content = wpmem_page_forgot_username( $wpmem->regchk, $content );
176
- break;
177
-
178
- case in_array( 'customizer_login', $atts ):
179
- $content = wpmem_inc_login( 'login', $redirect_to );
180
- break;
181
-
182
- case in_array( 'customizer_register', $atts ):
183
- $content = wpmem_register_form( 'new', $redirect_to );
184
- break;
185
 
186
- }
 
 
 
187
 
188
- /*
189
- * This is for texturizing. Need to work it into an argument in the function call as to whether the
190
- * [wpmem_txt] shortcode is even included. @todo - Is this a temporary solution or is there something
191
- * cleaner that can be worked out?
192
- */
193
- if ( 1 == $wpmem->texturize ) {
194
- if ( array_key_exists( 'texturize', $atts ) && $atts['texturize'] == 'false' ) {
195
- $content = str_replace( array( '[wpmem_txt]', '[/wpmem_txt]' ), array( '', '' ), $content );
196
- }
197
- if ( strstr( $content, '[wpmem_txt]' ) ) {
198
- // Fixes the wptexturize.
199
- remove_filter( 'the_content', 'wpautop' );
200
- remove_filter( 'the_content', 'wptexturize' );
201
- add_filter( 'the_content', array( 'WP_Members', 'texturize' ), 999 );
 
 
 
202
  }
203
- } // End texturize functions
 
204
  }
 
205
  return do_shortcode( $content );
206
  }
207
 
208
  /**
209
- * Handles the logged in status shortcodes [wpmem_logged_in].
210
  *
211
  * There are several attributes that can be used with the shortcode:
212
  * in|out, sub for subscription only info, id, and role. IDs and roles
@@ -221,22 +207,23 @@ class WP_Members_Shortcodes {
221
  * @global object $wpmem The WP_Members object.
222
  *
223
  * @param array $atts {
224
- * The shortcode attributes.
225
  *
226
- * @type string $status
227
- * @type int $id
228
- * @type string $role
229
- * @type string $sub
230
- * @type string $meta_key
231
- * @type string $meta_value
232
- * @type string $product
233
- * @type string $membership
 
234
  * }
235
- * @param string $content
236
- * @param string $tag
237
- * @return string $content
238
  */
239
- function logged_in( $atts, $content = null, $tag = 'wpmem_logged_in' ) {
240
 
241
  global $wpmem;
242
 
@@ -320,7 +307,7 @@ class WP_Members_Shortcodes {
320
  $do_return = true;
321
  $settings = array(
322
  'wrapper_before' => '<div class="product_restricted_msg">',
323
- 'msg' => sprintf( $wpmem->get_text( 'product_restricted' ), $wpmem->membership->products[ $membership ]['title'] ),
324
  'wrapper_after' => '</div>',
325
  );
326
  /**
@@ -350,22 +337,22 @@ class WP_Members_Shortcodes {
350
  }
351
 
352
  /**
353
- * Handles the [wpmem_logged_out] shortcode.
354
  *
355
  * @since 3.0.0
356
  * @since 3.2.0 Moved to WP_Members_Shortcodes::logged_out().
357
  *
358
- * @param array $atts
359
- * @param string $content
360
- * @param string $tag
361
- * @return string $content
362
  */
363
- function logged_out( $atts, $content = null, $tag ) {
364
  return ( ! is_user_logged_in() ) ? do_shortcode( $content ) : '';
365
  }
366
 
367
  /**
368
- * User count shortcode [wpmem_show_count].
369
  *
370
  * User count displays a total user count or a count of users by specific
371
  * role (role="some_role"). It also accepts attributes for counting users
@@ -380,15 +367,16 @@ class WP_Members_Shortcodes {
380
  * @param array $atts {
381
  * The shortcode attributes.
382
  *
383
- * @type string $key
384
- * @type string $value
385
- * @type string $role
386
- * @type string $label
387
  * }
388
- * @param string $content The shortcode content.
389
- * @return string $content
 
390
  */
391
- function user_count( $atts, $content = null ) {
392
  if ( isset( $atts['key'] ) && isset( $atts['value'] ) ) {
393
  // If by meta key.
394
  global $wpdb;
@@ -439,11 +427,7 @@ class WP_Members_Shortcodes {
439
 
440
  if ( $wpmem->regchk == "captcha" ) {
441
  global $wpmem_captcha_err;
442
- $wpmem_themsg = $wpmem->get_text( 'reg_captcha_err' ) . '<br /><br />' . $wpmem_captcha_err;
443
- }
444
-
445
- if ( $wpmem->regchk == "loginfailed" ) {
446
- return wpmem_inc_loginfailed();
447
  }
448
 
449
  if ( is_user_logged_in() ) {
@@ -457,18 +441,18 @@ class WP_Members_Shortcodes {
457
  case "update":
458
  // Determine if there are any errors/empty fields.
459
  if ( $wpmem->regchk == "updaterr" || $wpmem->regchk == "email" ) {
460
- $content = $content . wpmem_inc_regmessage( $wpmem->regchk, $wpmem_themsg );
461
  $content = $content . wpmem_register_form( 'edit' );
462
  } else {
463
  //Case "editsuccess".
464
- $content = $content . wpmem_inc_regmessage( $wpmem->regchk, $wpmem_themsg );
465
- $content = $content . wpmem_inc_memberlinks();
466
  }
467
  break;
468
 
469
  case "pwdchange":
470
  $content = wpmem_page_pwd_reset( $wpmem->regchk, $content );
471
- $content = ( 'pwdchangesuccess' == $wpmem->regchk ) ? $content . wpmem_inc_memberlinks() : $content;
472
  break;
473
 
474
  case "renew":
@@ -480,38 +464,28 @@ class WP_Members_Shortcodes {
480
  break;
481
 
482
  default:
483
- $content = wpmem_inc_memberlinks();
484
  break;
485
  }
486
 
487
  } else {
488
 
489
- if ( $wpmem->action == 'register' && ! $hide_register ) {
490
-
491
- switch( $wpmem->regchk ) {
492
-
493
- case "success":
494
- $content = wpmem_inc_regmessage( $wpmem->regchk, $wpmem_themsg );
495
- $content = $content . wpmem_inc_login();
496
- break;
497
-
498
- default:
499
- $content = wpmem_inc_regmessage( $wpmem->regchk, $wpmem_themsg );
500
- $content = $content . wpmem_register_form();
501
- break;
502
- }
503
-
504
  } elseif ( $wpmem->action == 'pwdreset' ) {
505
 
506
- $content = wpmem_page_pwd_reset( $wpmem->regchk, $content );
507
 
508
  } elseif( $wpmem->action == 'getusername' ) {
509
 
510
- $content = wpmem_page_forgot_username( $wpmem->regchk, $content );
511
 
512
  } else {
513
 
514
- $content = $content . wpmem_inc_login( 'members' );
515
  $content = ( ! $hide_register ) ? $content . wpmem_register_form() : $content;
516
  }
517
  }
@@ -587,7 +561,7 @@ class WP_Members_Shortcodes {
587
  * @param string $tag The shortcode tag (wpmem_form).
588
  * @return string $content Content to return.
589
  */
590
- function fields( $atts, $content = null, $tag ) {
591
 
592
  // What field?
593
  $field = ( isset( $atts[0] ) ) ? $atts[0] : $atts['field'];
@@ -605,18 +579,19 @@ class WP_Members_Shortcodes {
605
 
606
  global $wpmem;
607
  $fields = wpmem_fields();
608
- $field_type = ( isset( $fields[ $field ]['type'] ) ) ? $fields[ $field ]['type'] : 'native'; // @todo Is this needed? It seems to set the type to "native" if not set.
609
-
610
  $user_info_field = ( isset( $field ) && is_object( $user_info ) ) ? $user_info->{$field} : '';
611
  $result = false;
612
-
613
  // Handle each field type.
614
  switch ( $field_type ) {
615
 
616
  // Select and radio groups have single selections.
617
  case 'select':
618
  case 'radio':
619
- $result = ( isset( $atts['display'] ) && 'raw' == $atts['display'] ) ? $user_info_field : $fields[ $field ]['options'][ $user_info_field ];
 
620
  break;
621
 
622
  // Multiple select and multiple checkbox have multiple selections.
@@ -629,7 +604,7 @@ class WP_Members_Shortcodes {
629
  $result = ''; $x = 1;
630
  foreach ( $saved_vals as $value ) {
631
  $result.= ( $x > 1 ) ? ', ' : ''; $x++;
632
- $result.= $fields[ $field ]['options'][ $value ];
633
  }
634
  }
635
  break;
@@ -743,7 +718,7 @@ class WP_Members_Shortcodes {
743
  * @retrun string $content
744
  */
745
  function tos( $atts, $content, $tag ) {
746
- $url = ( strpos( $atts['url'], 'http' ) ) ? $atts['url'] : home_url( $atts['url'] );
747
  return esc_url( $url );
748
  }
749
 
@@ -841,6 +816,344 @@ class WP_Members_Shortcodes {
841
  $content = wpmem_form_nonce( $nonce, false );
842
  return do_shortcode( $content );
843
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
844
  }
845
 
846
  // End of file.
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-2021 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-2021
17
  */
18
 
19
  // Exit if accessed directly.
57
  }
58
 
59
  /**
60
+ * Renders forms called by [wpmem_form] shortcode.
61
  *
62
  * @since 3.0.0
63
  * @since 3.1.3 Added forgot_username shortcode.
75
  * Possible shortcode attributes (some vary by form).
76
  *
77
  * @type string $id An ID for the form.
78
+ * @type string $login Renders a login form.
79
+ * @type string $password Renders a reset/change password form (login state dependent).
80
+ * @type string $user_edit Renders a user profile edit form.
81
+ * @type string $forgot_username Renders a forgot username form.
82
+ * @type string $register Renders a register form.
83
+ * @type string $wp_login Renders the WP login form.
84
+ * @type string $redirect_to URL to redirect to on form submit (used for login and register forms).
85
+ * @type string $texturize Add/fix texturization for the from HTML (usually not necessary).
86
+ * @type string $exclude_fields Fields to exclude as comma separated meta keys (register/user_edit forms only).
87
+ * @type string $include_fields Fields to include as comma separated meta keys (register/user_edit forms only).
88
  * @type string $product Register for specific product (if products are enabled).
89
  * }
90
+ * @param string $content Nested content displayed if the shortcode is in the logged in state (optional).
91
+ * @param string $tag The shortcode's tag (wpmem_form).
92
+ * @return string The form HTML (or nested content, if used and the user is logged in).
93
  */
94
+ function forms( $atts, $content, $tag ) {
95
 
96
  global $wpmem, $wpmem_themsg;
97
 
98
  // Defaults.
99
+ $defaults = array(
100
+ 'form' => '',
101
+ 'redirect_to' => null,
102
+ 'texturize' => false,
103
+ 'form_id' => false,
104
+ );
105
+ $atts = wp_parse_args( $atts, $defaults );
106
 
107
+ $atts['form'] = ( isset( $atts[0] ) ) ? $atts[0] : 'login';
108
+ unset( $atts[0] );
109
 
110
+ $customizer = ( is_customize_preview() ) ? get_theme_mod( 'wpmem_show_logged_out_state', false ) : false;
 
 
 
 
 
111
 
112
+ // If $atts is an array, get the tag from the array so we know what form to render.
113
+ switch ( $atts['form'] ) {
114
 
115
+ case 'wp_login':
116
+ $content = wpmem_wp_login_form( $atts );
117
+ break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
+ case 'register':
120
+
121
+ // Set up register form args.
122
+ $reg_form_args = array( 'tag' => 'new' );
123
+ if ( isset( $redirect_to ) ) {
124
+ $reg_form_args['redirect_to'] = $redirect_to;
125
+ }
126
+
127
+ if ( is_user_logged_in() && '1' != $customizer ) {
128
+ /*
129
+ * If the user is logged in, return any nested content (if any)
130
+ * or the default bullet links if no nested content.
131
+ */
132
+ $content = ( $content ) ? $content : $this->render_links( 'register' );
133
+ } elseif ( is_user_logged_in() && is_customize_preview() && get_theme_mod( 'wpmem_show_form_message_dialog', false ) ) {
134
+ $wpmem_themsg = __( "This is a generic message to display the form message dialog in the Customizer.", 'wp-members' );
135
+ $content = wpmem_get_display_message( $wpmem->regchk, $wpmem_themsg );
136
+ $content .= wpmem_register_form( $reg_form_args );
137
+ } else {
138
+ if ( $wpmem->regchk == 'loginfailed' ) {
139
+ $content = $wpmem->dialogs->login_failed() . wpmem_login_form();
140
+ break;
141
  }
142
+ // @todo Can this be moved into another function? Should $wpmem get an error message handler?
143
+ if ( $wpmem->regchk == 'captcha' ) {
144
+ global $wpmem_captcha_err;
145
+ $wpmem_themsg = wpmem_get_text( 'reg_captcha_err' ) . '<br /><br />' . $wpmem_captcha_err;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  }
147
+ $content = ( $wpmem_themsg || $wpmem->regchk == 'success' ) ? wpmem_get_display_message( $wpmem->regchk, $wpmem_themsg ) : '';
148
+ $content .= ( $wpmem->regchk == 'success' ) ? wpmem_login_form() : wpmem_register_form( $reg_form_args );
149
+ }
150
+ break;
151
 
152
+ case 'password':
153
+ $content = $this->render_pwd_reset( $wpmem->regchk, $content );
154
+ break;
155
 
156
+ case 'user_edit':
157
+ $content = $this->render_user_edit( $wpmem->regchk, $content, $atts );
158
+ break;
159
 
160
+ case 'forgot_username':
161
+ $content = $this->render_forgot_username( $wpmem->regchk, $content );
162
+ break;
 
 
 
 
 
 
 
 
163
 
164
+ // @todo Review - is this actually ever triggered?
165
+ case 'customizer_login':
166
+ $content = wpmem_login_form();
167
+ break;
168
 
169
+ // @todo Review - is this actually ever triggered?
170
+ case 'customizer_register':
171
+ $content = wpmem_register_form( 'new' );
172
+ break;
173
+
174
+ case 'login':
175
+ default:
176
+ if ( is_user_logged_in() && '1' != $customizer ) {
177
+ // If the user is logged in, return any nested content (if any) or the default bullet links if no nested content.
178
+ $content = ( $content ) ? $content : $this->render_links( 'login' );
179
+ } else {
180
+ $content = '';
181
+ if ( $wpmem->regchk == 'loginfailed' || ( is_customize_preview() && get_theme_mod( 'wpmem_show_form_message_dialog', false ) ) ) {
182
+ $content = wpmem_get_display_message( 'loginfailed' );
183
+ }
184
+ $form_id = ( $atts['form_id'] ) ? $atts['form_id'] : 'wpmem_login_form';
185
+ $content .= wpmem_login_form( array( 'redirect_to'=>$atts['redirect_to'], 'form_id'=>$form_id ) );
186
  }
187
+ break;
188
+
189
  }
190
+
191
  return do_shortcode( $content );
192
  }
193
 
194
  /**
195
+ * Restricts content to logged in users using the shortcode [wpmem_logged_in].
196
  *
197
  * There are several attributes that can be used with the shortcode:
198
  * in|out, sub for subscription only info, id, and role. IDs and roles
207
  * @global object $wpmem The WP_Members object.
208
  *
209
  * @param array $atts {
210
+ * Attributes of the wpmem_logged_in shortcode.
211
  *
212
+ * @type string $status User status to check (in|out) (optional).
213
+ * @type int $id The user's ID. Restricts to a specified user by ID (optional).
214
+ * @type string $role The user's role. Restrictes to a specific role (optional).
215
+ * @type string $sub If the user is a current subscriber (for use with the PayPal extension) (optional).
216
+ * @type string $meta_key If the user has a specified meta key (use with meta_value) (optional).
217
+ * @type string $meta_value If the user has a specific meta key value (use with meta_key) (optional).
218
+ * @tryp string $compare Can specify a comparison operator when using meta_key/meta_value (optional).
219
+ * @type string $product If the user has a specific product/membership (optional).
220
+ * @type string $membership If the user has a specific product/membership (optional).
221
  * }
222
+ * @param string $content Shortcode content.
223
+ * @param string $tag The shortcode's tag (wpmem_logged_in).
224
+ * @return string|void The restricted content to display if the user meets the criteria.
225
  */
226
+ function logged_in( $atts, $content, $tag ) {
227
 
228
  global $wpmem;
229
 
307
  $do_return = true;
308
  $settings = array(
309
  'wrapper_before' => '<div class="product_restricted_msg">',
310
+ 'msg' => sprintf( wpmem_get_text( 'product_restricted' ), $wpmem->membership->products[ $membership ]['title'] ),
311
  'wrapper_after' => '</div>',
312
  );
313
  /**
337
  }
338
 
339
  /**
340
+ * Renders the [wpmem_logged_out] shortcode.
341
  *
342
  * @since 3.0.0
343
  * @since 3.2.0 Moved to WP_Members_Shortcodes::logged_out().
344
  *
345
+ * @param array $atts There are no attributes for this shortcode.
346
+ * @param string $content Conent to display if user is logged out.
347
+ * @param string $tag The shortcode tab (wpmem_logged_out).
348
+ * @return string $content The content, if the user is logged out, otherwise an empty string.
349
  */
350
+ function logged_out( $atts, $content, $tag ) {
351
  return ( ! is_user_logged_in() ) ? do_shortcode( $content ) : '';
352
  }
353
 
354
  /**
355
+ * Displays the user count shortcode [wpmem_show_count].
356
  *
357
  * User count displays a total user count or a count of users by specific
358
  * role (role="some_role"). It also accepts attributes for counting users
367
  * @param array $atts {
368
  * The shortcode attributes.
369
  *
370
+ * @type string $key The user meta key, if displaying count by meta key.
371
+ * @type string $value The user meta value, if displaying count by meta key.
372
+ * @type string $role The user role, if displaying count by role.
373
+ * @type string $label Label to display with the count (optional).
374
  * }
375
+ * @param string $content Does not accept nested content.
376
+ * @param string $tag The shortcode's tag (wpmem_show_count).
377
+ * @return string $content The user count.
378
  */
379
+ function user_count( $atts, $content, $tag ) {
380
  if ( isset( $atts['key'] ) && isset( $atts['value'] ) ) {
381
  // If by meta key.
382
  global $wpdb;
427
 
428
  if ( $wpmem->regchk == "captcha" ) {
429
  global $wpmem_captcha_err;
430
+ $wpmem_themsg = wpmem_get_text( 'reg_captcha_err' ) . '<br /><br />' . $wpmem_captcha_err;
 
 
 
 
431
  }
432
 
433
  if ( is_user_logged_in() ) {
441
  case "update":
442
  // Determine if there are any errors/empty fields.
443
  if ( $wpmem->regchk == "updaterr" || $wpmem->regchk == "email" ) {
444
+ $content = $content . wpmem_get_display_message( $wpmem->regchk, $wpmem_themsg );
445
  $content = $content . wpmem_register_form( 'edit' );
446
  } else {
447
  //Case "editsuccess".
448
+ $content = $content . wpmem_get_display_message( $wpmem->regchk, $wpmem_themsg );
449
+ $content = $content . $this->render_links();
450
  }
451
  break;
452
 
453
  case "pwdchange":
454
  $content = wpmem_page_pwd_reset( $wpmem->regchk, $content );
455
+ $content = ( 'pwdchangesuccess' == $wpmem->regchk ) ? $content . $this->render_links() : $content;
456
  break;
457
 
458
  case "renew":
464
  break;
465
 
466
  default:
467
+ $content = $this->render_links();
468
  break;
469
  }
470
 
471
  } else {
472
 
473
+ if ( ( 'login' == $wpmem->action ) || ( 'register' == $wpmem->action && ! $hide_register ) ) {
474
+
475
+ $content = wpmem_get_display_message( $wpmem->regchk, $wpmem_themsg );
476
+ $content.= ( 'loginfailed' == $wpmem->regchk || 'success' == $wpmem->regchk ) ? wpmem_login_form() : wpmem_register_form();
477
+
 
 
 
 
 
 
 
 
 
 
478
  } elseif ( $wpmem->action == 'pwdreset' ) {
479
 
480
+ $content = $this->render_pwd_reset( $wpmem->regchk, $content );
481
 
482
  } elseif( $wpmem->action == 'getusername' ) {
483
 
484
+ $content = $this->render_forgot_username( $wpmem->regchk, $content );
485
 
486
  } else {
487
 
488
+ $content = $content . wpmem_login_form( 'profile' );
489
  $content = ( ! $hide_register ) ? $content . wpmem_register_form() : $content;
490
  }
491
  }
561
  * @param string $tag The shortcode tag (wpmem_form).
562
  * @return string $content Content to return.
563
  */
564
+ function fields( $atts, $content, $tag ) {
565
 
566
  // What field?
567
  $field = ( isset( $atts[0] ) ) ? $atts[0] : $atts['field'];
579
 
580
  global $wpmem;
581
  $fields = wpmem_fields();
582
+
583
+ $field_type = ( 'user_login' == $field ) ? 'text' : $fields[ $field ]['type'];
584
  $user_info_field = ( isset( $field ) && is_object( $user_info ) ) ? $user_info->{$field} : '';
585
  $result = false;
586
+
587
  // Handle each field type.
588
  switch ( $field_type ) {
589
 
590
  // Select and radio groups have single selections.
591
  case 'select':
592
  case 'radio':
593
+ case 'membership':
594
+ $result = ( isset( $atts['display'] ) && 'raw' == $atts['display'] ) ? $user_info_field : wpmem_select_field_display( $field, $user_info_field );
595
  break;
596
 
597
  // Multiple select and multiple checkbox have multiple selections.
604
  $result = ''; $x = 1;
605
  foreach ( $saved_vals as $value ) {
606
  $result.= ( $x > 1 ) ? ', ' : ''; $x++;
607
+ $result.= wpmem_select_field_display( $field, $value );;
608
  }
609
  }
610
  break;
718
  * @retrun string $content
719
  */
720
  function tos( $atts, $content, $tag ) {
721
+ $url = ( strpos( $atts['url'], 'http://' ) || strpos( $atts['url'], 'https://' ) ) ? $atts['url'] : home_url( $atts['url'] );
722
  return esc_url( $url );
723
  }
724
 
816
  $content = wpmem_form_nonce( $nonce, false );
817
  return do_shortcode( $content );
818
  }
819
+
820
+ /**
821
+ * Password reset forms.
822
+ *
823
+ * This function creates both password reset and forgotten
824
+ * password forms for page=password shortcode.
825
+ *
826
+ * @since 2.7.6
827
+ * @since 3.2.6 Added nonce validation.
828
+ * @since 3.4.0 Moved to shortcodes as private function, renamed from wpmem_page_pwd_reset().
829
+ *
830
+ * @global object $wpmem
831
+ * @param string $wpmem_regchk
832
+ * @param string $content
833
+ * @return string $content
834
+ */
835
+ function render_pwd_reset( $wpmem_regchk, $content ) {
836
+
837
+ global $wpmem;
838
+
839
+ if ( is_user_logged_in() ) {
840
+
841
+ switch ( $wpmem_regchk ) {
842
+
843
+ case "pwdchangesuccess":
844
+ $content = $content . wpmem_get_display_message( $wpmem_regchk );
845
+ break;
846
+
847
+ default:
848
+ if ( isset( $wpmem_regchk ) && '' != $wpmem_regchk ) {
849
+ $content .= wpmem_get_display_message( $wpmem_regchk, wpmem_get_text( $wpmem_regchk ) );
850
+ }
851
+ $content = $content . wpmem_change_password_form();
852
+ break;
853
+ }
854
+
855
+ } else {
856
+
857
+ // If the password shortcode page is set as User Profile page.
858
+ if ( 'getusername' == $wpmem->action ) {
859
+
860
+ return wpmem_page_forgot_username( $wpmem_regchk, $content );
861
+
862
+ } else {
863
+
864
+ switch( $wpmem_regchk ) {
865
+
866
+ case "pwdresetsuccess":
867
+ $content = $content . wpmem_get_display_message( $wpmem_regchk );
868
+ $wpmem_regchk = ''; // Clear regchk.
869
+ break;
870
+
871
+ default:
872
+ if ( isset( $wpmem_regchk ) && '' != $wpmem_regchk ) {
873
+ $content = wpmem_get_display_message( $wpmem_regchk, wpmem_get_text( $wpmem_regchk ) );
874
+ }
875
+ $content = $content . wpmem_reset_password_form();
876
+ break;
877
+ }
878
+
879
+ }
880
+
881
+ }
882
+
883
+ return $content;
884
+
885
+ }
886
+
887
+ /**
888
+ * Creates a user edit page.
889
+ *
890
+ * @since 2.7.6
891
+ * @since 3.3.9 Added $atts
892
+ * @since 3.4.0 Moved to shortcodes as private function, renamed from wpmem_page_user_edit
893
+ *
894
+ * @global object $wpmem
895
+ * @global string $wpmem_a
896
+ * @global string $wpmem_themsg
897
+ * @param string $wpmem_regchk
898
+ * @param string $content
899
+ * @return string $content
900
+ */
901
+ function render_user_edit( $wpmem_regchk, $content, $atts = false ) {
902
+
903
+ global $wpmem, $wpmem_a, $wpmem_themsg;
904
+ /**
905
+ * Filter the default User Edit heading for shortcode.
906
+ *
907
+ * @since 2.7.6
908
+ *
909
+ * @param string The default edit mode heading.
910
+ */
911
+ $heading = apply_filters( 'wpmem_user_edit_heading', wpmem_get_text( 'profile_heading' ) );
912
+
913
+ if ( $wpmem_a == "update") {
914
+ $content.= wpmem_get_display_message( $wpmem_regchk, $wpmem_themsg );
915
+ }
916
+
917
+ $args['tag'] = 'edit';
918
+ $args['heading'] = $heading;
919
+ if ( false !== $atts && isset( $atts['fields'] ) ) {
920
+ $args['fields'] = $atts['fields'];
921
+ }
922
+
923
+ $content = $content . wpmem_register_form( $args );
924
+
925
+ return $content;
926
+ }
927
+
928
+ /**
929
+ * Forgot username form.
930
+ *
931
+ * This function creates a form for retrieving a forgotten username.
932
+ *
933
+ * @since 3.0.8
934
+ * @since 3.4.0 Moved to shortcodes as private function, renamed from wpmem_page_forgot_username().
935
+ *
936
+ * @param string $wpmem_regchk
937
+ * @param string $content
938
+ * @return string $content
939
+ */
940
+ function render_forgot_username( $wpmem_regchk, $content ) {
941
+
942
+ if ( ! is_user_logged_in() ) {
943
+
944
+ global $wpmem;
945
+ switch( $wpmem->regchk ) {
946
+
947
+ case "usernamefailed":
948
+ $msg = wpmem_get_text( 'usernamefailed' );
949
+ $content = $content
950
+ . wpmem_get_display_message( 'usernamefailed', $msg )
951
+ . wpmem_forgot_username_form();
952
+ $wpmem->regchk = ''; // Clear regchk.
953
+ break;
954
+
955
+ case "usernamesuccess":
956
+ $email = ( isset( $_POST['user_email'] ) ) ? sanitize_email( $_POST['user_email'] ) : '';
957
+ $msg = sprintf( wpmem_get_text( 'usernamesuccess' ), $email );
958
+ $content = $content . wpmem_get_display_message( 'usernamesuccess', $msg );
959
+ $wpmem->regchk = ''; // Clear regchk.
960
+ break;
961
+
962
+ default:
963
+ $content = $content . wpmem_forgot_username_form();
964
+ break;
965
+ }
966
+
967
+ }
968
+
969
+ return $content;
970
+
971
+ }
972
+
973
+ /**
974
+ * Member Links Dialog.
975
+ *
976
+ * Outputs the links used on the members area.
977
+ *
978
+ * @since 2.0
979
+ * @since 3.4.0 Replaces wpmem_inc_memberlinks().
980
+ *
981
+ * @gloabl $user_login
982
+ * @global object $wpmem
983
+ * @param string $page
984
+ * @return string $str
985
+ */
986
+ function render_links( $page = 'member' ) {
987
+
988
+ global $user_login, $wpmem;
989
+
990
+ $logout = wpmem_logout_link();
991
+
992
+ switch ( $page ) {
993
+
994
+ case 'register':
995
+
996
+ $url = ( isset( $wpmem->user_pages['profile'] ) && '' != $wpmem->user_pages['profile'] ) ? $wpmem->user_pages['profile'] : get_option( 'home' );
997
+
998
+ // NOTE: DO NOT EDIT THESE. Use the filter below.
999
+ $arr = array(
1000
+ 'before_wrapper' => '<p class="register_status">' . sprintf( wpmem_get_text( 'register_status' ), $user_login ) . '</p>',
1001
+ 'wrapper_before' => '<ul class="register_links">',
1002
+ 'wrapper_after' => '</ul>',
1003
+ 'rows' => array(
1004
+ '<li><a href="' . esc_url( $logout ) . '">' . wpmem_get_text( 'register_logout' ) . '</a></li>',
1005
+ '<li><a href="' . esc_url( $url ) . '">' . wpmem_get_text( 'register_continue' ) . '</a></li>',
1006
+ ),
1007
+ 'after_wrapper' => '',
1008
+ );
1009
+
1010
+ /**
1011
+ * Filter the register links array.
1012
+ *
1013
+ * @since 3.0.9
1014
+ * @since 3.1.0 Added after_wrapper
1015
+ *
1016
+ * @param array $arr {
1017
+ * The components of the links.
1018
+ *
1019
+ * @type string $before_wrapper HTML before the wrapper (default: login status).
1020
+ * @type string $wrapper_before The wrapper opening tag (default: <ul>).
1021
+ * @type string $wrapper_after The wrapper closing tag (default: </ul>).
1022
+ * @type array $rows Row items HTML.
1023
+ * @type string $after_wrapper Anything that comes after the wrapper.
1024
+ * }
1025
+ */
1026
+ $arr = apply_filters( "wpmem_{$page}_links_args", $arr );
1027
+
1028
+ $str = $arr['before_wrapper'];
1029
+ $str.= $arr['wrapper_before'];
1030
+ foreach ( $arr['rows'] as $row ) {
1031
+ $str.= $row;
1032
+ }
1033
+ $str.= $arr['wrapper_after'];
1034
+ $str.= $arr['after_wrapper'];
1035
+
1036
+ /**
1037
+ * Filter the links displayed on the Register page (logged in state).
1038
+ *
1039
+ * @since 2.8.3
1040
+ *
1041
+ * @param string $str The default links.
1042
+ */
1043
+ $str = apply_filters( "wpmem_{$page}_links", $str );
1044
+ break;
1045
+
1046
+ case 'login':
1047
+
1048
+ $logout = urldecode( $logout );
1049
+ // NOTE: DO NOT EDIT THESE. Use the filter hook below.
1050
+ $args = array(
1051
+ 'wrapper_before' => '<p class="login_status">',
1052
+ 'wrapper_after' => '</p>',
1053
+ 'user_login' => $user_login,
1054
+ 'welcome' => wpmem_get_text( 'login_welcome' ),
1055
+ 'logout_text' => wpmem_get_text( 'login_logout' ),
1056
+ 'logout_link' => '<a href="' . esc_url( $logout ) . '">%s</a>',
1057
+ 'separator' => '<br />',
1058
+ );
1059
+ /**
1060
+ * Filter the status message parts.
1061
+ *
1062
+ * @since 2.9.9
1063
+ *
1064
+ * @param array $args {
1065
+ * The components of the links.
1066
+ *
1067
+ * @type string $wrapper_before The wrapper opening tag (default: <p>).
1068
+ * @type string $wrapper_after The wrapper closing tag (default: </p>).
1069
+ * @type string $user_login
1070
+ * @type string $welcome
1071
+ * @type string $logout_text
1072
+ * @type string $logout_link
1073
+ * @type string $separator
1074
+ * }
1075
+ */
1076
+ $args = apply_filters( "wpmem_{$page}_links_args", $args );
1077
+
1078
+ // Assemble the message string.
1079
+ $str = $args['wrapper_before']
1080
+ . sprintf( $args['welcome'], $args['user_login'] )
1081
+ . $args['separator']
1082
+ . sprintf( $args['logout_link'], $args['logout_text'] )
1083
+ . $args['wrapper_after'];
1084
+
1085
+ /**
1086
+ * Filter the links displayed on the Log In page (logged in state).
1087
+ *
1088
+ * @since 2.8.3
1089
+ *
1090
+ * @param string $str The default links.
1091
+ */
1092
+ $str = apply_filters( "wpmem_{$page}_links", $str );
1093
+ break;
1094
+
1095
+ case 'member':
1096
+ default:
1097
+
1098
+ // NOTE: DO NOT EDIT. Use the filter below.
1099
+ $arr = array(
1100
+ 'before_wrapper' => '',
1101
+ 'wrapper_before' => '<ul>',
1102
+ 'wrapper_after' => '</ul>',
1103
+ 'rows' => array(
1104
+ '<li><a href="' . esc_url( add_query_arg( 'a', 'edit', remove_query_arg( 'key' ) ) ) . '">' . wpmem_get_text( 'profile_edit' ) . '</a></li>',
1105
+ '<li><a href="' . esc_url( add_query_arg( 'a', 'pwdchange', remove_query_arg( 'key' ) ) ) . '">' . wpmem_get_text( 'profile_password' ) . '</a></li>',
1106
+ ),
1107
+ 'after_wrapper' => '',
1108
+ );
1109
+
1110
+ if ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 && function_exists( 'wpmem_user_page_detail' ) ) {
1111
+ $arr['rows'][] = wpmem_user_page_detail();
1112
+ }
1113
+
1114
+ /**
1115
+ * Filter the member links array.
1116
+ *
1117
+ * @since 3.0.9
1118
+ * @since 3.1.0 Added after_wrapper
1119
+ *
1120
+ * @param array $arr {
1121
+ * The components of the links.
1122
+ *
1123
+ * @type string $before_wrapper Anything that comes before the wrapper.
1124
+ * @type string $wrapper_before The wrapper opening tag (default: <ul>).
1125
+ * @type string $wrapper_after The wrapper closing tag (default: </ul>).
1126
+ * @type array $rows Row items HTML.
1127
+ * @type string $after_wrapper Anything that comes after the wrapper.
1128
+ * }
1129
+ */
1130
+ $arr = apply_filters( "wpmem_{$page}_links_args", $arr );
1131
+
1132
+ $str = $arr['before_wrapper'];
1133
+ $str.= $arr['wrapper_before'];
1134
+ foreach ( $arr['rows'] as $row ) {
1135
+ $str.= $row;
1136
+ }
1137
+ $str.= $arr['wrapper_after'];
1138
+ $str.= $arr['after_wrapper'];
1139
+
1140
+ /**
1141
+ * Filter the links displayed on the User Profile page (logged in state).
1142
+ *
1143
+ * @since 2.8.3
1144
+ *
1145
+ * @param string $str The default links.
1146
+ */
1147
+ $str = apply_filters( "wpmem_{$page}_links", $str );
1148
+ break;
1149
+ }
1150
+
1151
+ return $str;
1152
+ }
1153
+
1154
+ function render_links_filter_args( $page, $args ) {
1155
+
1156
+ }
1157
  }
1158
 
1159
  // End of file.
includes/class-wp-members-user-profile.php CHANGED
@@ -1,610 +1,612 @@
1
- <?php
2
- /**
3
- * The WP_Members User Profile Class.
4
- *
5
- * @package WP-Members
6
- * @subpackage WP_Members Admin User Profile Object Class
7
- * @since 3.1.8
8
- */
9
-
10
- // Exit if accessed directly.
11
- if ( ! defined( 'ABSPATH' ) ) {
12
- exit();
13
- }
14
-
15
- class WP_Members_User_Profile {
16
-
17
- /**
18
- * Remove "admin only" fields if dashboard user profile.
19
- *
20
- * @since 3.3.6
21
- *
22
- * @param string $tag
23
- * @return array $fields
24
- */
25
- static function get_fields( $tag ) {
26
- $fields = wpmem_fields( $tag );
27
- if ( 'profile_dashboard' == $tag && false === current_user_can( 'edit_users' ) ) {
28
- foreach( $fields as $key => $field ) {
29
- if ( false == $field['profile'] ) {
30
- unset( $fields[ $key ] );
31
- }
32
- }
33
- }
34
- return $fields;
35
- }
36
-
37
- /**
38
- * Static function to display WP-Members fields on the admin/dashboard user profile.
39
- *
40
- * Function was created in 3.1.9 as a merge of wpmem_admin_fields()
41
- * and wpmem_user_profile().
42
- *
43
- * @since 3.1.9
44
- *
45
- * @global object $current_screen
46
- * @global string $user_ID
47
- * @global object $wpmem
48
- * @param object $user_obj
49
- */
50
- static function profile( $user_obj ) {
51
-
52
- global $current_screen, $user_ID, $wpmem;
53
- $user_id = ( 'profile' == $current_screen->id ) ? $user_ID : filter_var( $_REQUEST['user_id'], FILTER_SANITIZE_NUMBER_INT );
54
- $display = ( 'profile' == $current_screen->base ) ? 'user' : 'admin';
55
- $display = ( current_user_can( 'edit_users' ) ) ? 'admin' : $display; ?>
56
-
57
- <h3><?php
58
- $heading = ( 'admin' == $display ) ? __( 'WP-Members Additional Fields', 'wp-members' ) : __( 'Additional Information', 'wp-members' );
59
- /**
60
- * Filter the heading for additional profile fields.
61
- *
62
- * Filter is applied for the admin user edit ("wpmem_admin_profile_heading")
63
- * and the user profile edit ("wpmem_user_profile_heading").
64
- *
65
- * @since 2.8.2 Admin Profile
66
- * @since 2.9.1 Dashboard Profile
67
- * @since 3.1.9 Merged admin/dashboard profile
68
- *
69
- * @param string The default additional fields heading.
70
- */
71
- echo apply_filters( 'wpmem_' . $display . '_profile_heading', $heading ); ?></h3>
72
- <table class="form-table">
73
- <?php
74
- // Get fields.
75
- $wpmem_fields = ( 'admin' == $display ) ? self::get_fields( 'profile_admin' ) : self::get_fields( 'profile_dashboard' );
76
- // Get excluded meta.
77
- $exclude = wpmem_get_excluded_meta( $display . '-profile' );
78
-
79
- // If tos is an active field.
80
- if ( isset( $wpmem_fields['tos'] ) ) {
81
- if ( 1 != $wpmem_fields['tos']['register'] ) {
82
- unset( $wpmem_fields['tos'] );
83
- }
84
- // This is the dashboard profile, and user has current field value.
85
- if ( 'user' == $display
86
- && isset( $wpmem_fields['tos'] )
87
- && ( get_user_meta( $user_ID, 'tos', true ) == $wpmem_fields['tos']['checked_value'] ) ) {
88
- unset( $wpmem_fields['tos'] );
89
- }
90
- }
91
-
92
- /**
93
- * Fires at the beginning of generating the WP-Members fields in the user profile.
94
- *
95
- * Action fires for the admin user edit ("wpmem_admin_before_profile")
96
- * and the user profile edit ("wpmem_user_before_profile").
97
- *
98
- * @since 2.9.3 Created for admin profile.
99
- * @since 3.1.9 Added to dashboard profile.
100
- *
101
- * @param int $user_id The user's ID.
102
- * @param array $wpmem_fields The WP-Members fields.
103
- */
104
- do_action( 'wpmem_' . $display . '_before_profile', $user_id, $wpmem_fields );
105
-
106
- // Assemble form rows array.
107
- $rows = array();
108
- foreach ( $wpmem_fields as $meta => $field ) {
109
-
110
- $valtochk = ''; $values = '';
111
-
112
- // Determine which fields to show in the additional fields area.
113
- $show = ( ! $field['native'] && ! in_array( $meta, $exclude ) ) ? true : false;
114
- //$show = ( 'tos' == $meta && $field['register'] ) ? null : $show;
115
-
116
- if ( $show ) {
117
-
118
- $val = get_user_meta( $user_id, $meta, true );
119
- $val = ( $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' ) ? $val : htmlspecialchars( $val );
120
- if ( $field['type'] == 'checkbox' ) {
121
- $valtochk = $val;
122
- $val = $field['checked_value'];
123
- }
124
-
125
- if ( 'multicheckbox' == $field['type'] || 'select' == $field['type'] || 'multiselect' == $field['type'] || 'radio' == $field['type'] ) {
126
- $values = $field['values'];
127
- $valtochk = $val;
128
- }
129
-
130
- // Is this an image or a file?
131
- if ( 'file' == $field['type'] || 'image' == $field['type'] ) {
132
- $empty_file = '<span class="description">' . __( 'None' ) . '</span>';
133
- if ( 'file' == $field['type'] ) {
134
- $attachment_url = wp_get_attachment_url( $val );
135
- $input = ( $attachment_url ) ? '<a href="' . $attachment_url . '">' . $attachment_url . '</a>' : $empty_file;
136
- } else {
137
- $attachment_url = wp_get_attachment_image( $val, 'medium' );
138
- if ( 'admin' == $display ) {
139
- $edit_url = admin_url( 'upload.php?item=' . $val );
140
- $input = ( $attachment_url ) ? '<a href="' . $edit_url . '">' . $attachment_url . '</a>' : $empty_file;
141
- } else {
142
- $input = ( $attachment_url ) ? $attachment_url : $empty_file;
143
- }
144
- }
145
- $input.= '<br />' . $wpmem->get_text( 'profile_upload' ) . '<br />';
146
- $input.= wpmem_form_field( array(
147
- 'name' => $meta,
148
- 'type' => $field['type'],
149
- 'value' => $val,
150
- 'compare' => $valtochk,
151
- ) );
152
- } else {
153
- if ( 'select' == $field['type'] || 'radio' == $field['type'] ) {
154
- $input = wpmem_form_field( $meta, $field['type'], $values, $valtochk );
155
- } elseif( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
156
- $input = wpmem_form_field( array( 'name'=>$meta, 'type'=>$field['type'], 'value'=>$values, 'compare'=>$valtochk, 'delimiter'=>$field['delimiter'] ) );
157
- } else {
158
- $field['type'] = ( 'hidden' == $field['type'] ) ? 'text' : $field['type'];
159
-
160
- $formfield_args = array(
161
- 'name' => $meta,
162
- 'type' => $field['type'],
163
- 'value' => $val,
164
- 'compare' => $valtochk,
165
- 'required' => $field['required'],
166
- 'placeholder' => ( isset( $field['placeholder'] ) ) ? $field['placeholder'] : '',
167
- 'pattern' => ( isset( $field['pattern'] ) ) ? $field['pattern'] : false,
168
- 'title' => ( isset( $field['title'] ) ) ? $field['title'] : false,
169
- 'min' => ( isset( $field['min'] ) ) ? $field['min'] : false,
170
- 'max' => ( isset( $field['max'] ) ) ? $field['max'] : false,
171
- 'rows' => ( isset( $field['rows'] ) ) ? $field['rows'] : false,
172
- 'cols' => ( isset( $field['cols'] ) ) ? $field['cols'] : false,
173
- );
174
-
175
- $input = wpmem_form_field( $formfield_args );
176
- }
177
- }
178
-
179
- // Is the field required?
180
- $req = ( $field['required'] ) ? ' <span class="description">' . __( '(required)' ) . '</span>' : '';
181
- $label = '<label>' . __( $field['label'], 'wp-members' ) . $req . '</label>';
182
-
183
- // Build the form rows for filtering.
184
- $rows[ $meta ] = array(
185
- 'meta' => $meta,
186
- 'type' => $field['type'],
187
- 'value' => $val,
188
- 'values' => $values,
189
- 'label_text' => __( $field['label'], 'wp-members' ),
190
- 'row_before' => '<tr>',
191
- 'label' => '<th>' . $label . '</th>',
192
- 'field_before' => '<td>',
193
- 'field' => $input,
194
- 'field_after' => '</td>',
195
- 'row_after' => '</tr>',
196
- );
197
- }
198
- }
199
-
200
- /**
201
- * Filter for rows.
202
- *
203
- * Filter is applied for the admin user edit ("wpmem_register_form_rows_admin")
204
- * and the user profile edit ("wpmem_register_form_rows_user").
205
- *
206
- * @since 3.1.0
207
- * @since 3.1.6 Deprecated $order.
208
- *
209
- * @param array $rows {
210
- * An array of the profile rows.
211
- *
212
- * @type string $meta The meta key.
213
- * @type string $type The field type.
214
- * @type string $value Value if set.
215
- * @type string $values Possible values (select, multiselect, multicheckbox, radio).
216
- * @type string $label_text Raw label text (no HTML).
217
- * @type string $row_before HTML before the row.
218
- * @type string $label HTML label.
219
- * @type string $field_before HTML before the field input tag.
220
- * @type string $field HTML for field input.
221
- * @type string $field_after HTML after the field.
222
- * @type string $row_after HTML after the row.
223
- * }
224
- * @param string $tag adminprofile|userprofile
225
- */
226
- $rows = apply_filters( 'wpmem_register_form_rows_' . $display, $rows, $display . 'profile' );
227
-
228
- // Handle form rows display from array.
229
- foreach ( $rows as $row ) {
230
- $show_field =
231
- $row['row_before'] .
232
- $row['label'] .
233
- $row['field_before'] . $row['field'] . $row['field_after'] .
234
- $row['field_after'];
235
-
236
- /**
237
- * Filter the profile field.
238
- *
239
- * Filter is applied for the admin user edit ("wpmem_admin_profile_field")
240
- * and the user profile edit ("wpmem_user_profile_field").
241
- *
242
- * @since 2.8.2
243
- * @since 3.1.1 Added $user_id and $row
244
- *
245
- * @param string $show_field The HTML string for the additional profile field.
246
- * @param string $user_id
247
- * @param array $row
248
- */
249
- echo apply_filters( 'wpmem_' . $display . '_profile_field', $show_field, $user_id, $row );
250
- }
251
-
252
- /**
253
- * Fires after generating the WP-Members fields in the user profile.
254
- *
255
- * Action fires for the admin user edit ("wpmem_admin_after_profile")
256
- * and the user profile edit ("wpmem_user_after_profile").
257
- *
258
- * @since 2.9.3
259
- *
260
- * @param int $user_id The user's ID.
261
- * @param array $wpmem_fields The WP-Members fields.
262
- */
263
- do_action( 'wpmem_' . $display . '_after_profile', $user_id, $wpmem_fields ); ?>
264
-
265
- </table><?php
266
-
267
- /**
268
- * Fires after the user profile table.
269
- *
270
- * Action fires for the admin user edit ("wpmem_admin_after_profile_table")
271
- * and the user profile edit ("wpmem_user_after_profile_table").
272
- *
273
- * @since 3.2.6
274
- *
275
- * @param int $user_id The user's ID.
276
- * @param array $wpmem_fields The WP-Members fields.
277
- */
278
- do_action( 'wpmem_' . $display . '_after_profile_table', $user_id, $wpmem_fields );
279
-
280
- }
281
-
282
- /**
283
- * Static function to update admin/dashboard user profile.
284
- *
285
- * Function was created in 3.1.9 as a merge of wpmem_admin_update()
286
- * and wpmem_profile_update().
287
- *
288
- * @since 3.1.9
289
- *
290
- * @global object $current_screen
291
- * @global string $user_id
292
- * @global object $wpmem
293
- * @param string $user_id
294
- * @return
295
- */
296
- static function update( $user_id ) {
297
-
298
- global $current_screen, $user_id, $wpmem;
299
- $display = ( 'profile' == $current_screen->base ) ? 'user' : 'admin';
300
-
301
- if ( ! $user_id ) {
302
- $user_id = filter_var( wpmem_get( 'user_id', -1, 'request' ), FILTER_SANITIZE_NUMBER_INT );
303
- if ( 1 > $user_id ) {
304
- // Still no user id? User cannot be updated.
305
- return;
306
- }
307
- }
308
-
309
- $wpmem_fields = ( 'admin' == $display ) ? self::get_fields( 'profile_admin' ) : self::get_fields( 'profile_dashboard' );
310
-
311
- // Check for password field before exclusions, just in case we are activating a user (otherwise password is removed on user/admin profiles).
312
- $chk_pass = ( array_key_exists( 'password', $wpmem_fields ) && true === $wpmem_fields['password']['register'] ) ? true : false;
313
-
314
- $exclude = wpmem_get_excluded_meta( $display . '-profile' );
315
-
316
- foreach ( $exclude as $excluded ) {
317
- unset( $wpmem_fields[ $excluded ] );
318
- }
319
-
320
- // If tos is an active field, this is the dashboard profile, and user has current field value.
321
- if ( isset( $wpmem_fields['tos'] )
322
- && 'user' == $display
323
- && get_user_meta( $user_id, 'tos', true ) == $wpmem_fields['tos']['checked_value'] ) {
324
- unset( $wpmem_fields['tos'] );
325
- }
326
-
327
- /**
328
- * Fires before the user profile is updated.
329
- *
330
- * Action fires for the admin user edit ("wpmem_admin_pre_user_update")
331
- * and the user profile edit ("wpmem_user_pre_user_update").
332
- *
333
- * @since 2.9.2 Added for admin profile update.
334
- * @since 3.1.9 Added for user profile update.
335
- *
336
- * @param int $user_id The user ID.
337
- * @param array $wpmem_fields Array of the custom fields.
338
- */
339
- do_action( 'wpmem_' . $display . '_pre_user_update', $user_id, $wpmem_fields );
340
-
341
- $fields = array();
342
- foreach ( $wpmem_fields as $meta => $field ) {
343
- if ( ! $field['native']
344
- && $field['type'] != 'password'
345
- && $field['type'] != 'checkbox'
346
- && $field['type'] != 'multiselect'
347
- && $field['type'] != 'multicheckbox'
348
- && $field['type'] != 'file'
349
- && $field['type'] != 'image'
350
- && $field['type'] != 'textarea' ) {
351
- ( isset( $_POST[ $meta ] ) && 'password' != $field['type'] ) ? $fields[ $meta ] = sanitize_text_field( $_POST[ $meta ] ) : false;
352
-
353
- // For user profile (not admin).
354
- $chk = false;
355
- if ( 'admin' != $display ) {
356
- // Check for required fields.
357
- if ( ! $field['required'] ) {
358
- $chk = 'ok';
359
- }
360
- if ( $field['required'] && $_POST[ $meta ] != '' ) {
361
- $chk = 'ok';
362
- }
363
- }
364
- } elseif ( $field['type'] == 'checkbox' ) {
365
- $fields[ $meta ] = ( isset( $_POST[ $meta ] ) ) ? sanitize_text_field( $_POST[ $meta ] ) : '';
366
- } elseif ( $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' ) {
367
- $fields[ $meta ] = ( isset( $_POST[ $meta ] ) ) ? implode( $field['delimiter'], wp_unslash( $_POST[ $meta ] ) ) : '';
368
- } elseif ( $field['type'] == 'textarea' ) {
369
- $fields[ $meta ] = ( isset( $_POST[ $meta ] ) ) ? sanitize_textarea_field( $_POST[ $meta ] ) : '';
370
- }
371
- }
372
-
373
- /**
374
- * Filter the submitted field values for backend profile update.
375
- *
376
- * Filters is applied for the admin user edit ("wpmem_admin_profile_update")
377
- * and the user profile edit ("wpmem_user_profile_update").
378
- *
379
- * @since 2.8.2 Added for Admin profile update.
380
- * @since 3.1.9 Added for User profile update.
381
- *
382
- * @param array $fields An array of the posted form values.
383
- * @param int $user_id The ID of the user being updated.
384
- */
385
- $fields = apply_filters( 'wpmem_' . $display . '_profile_update', $fields, $user_id );
386
-
387
- // Handle meta update, skip excluded fields.
388
- foreach ( $fields as $key => $val ) {
389
- if ( ! in_array( $key, $exclude ) ) {
390
- if ( ( 'admin' != $display && 'ok' == $chk ) || 'admin' == $display ) {
391
- update_user_meta( $user_id, $key, $val );
392
- }
393
- }
394
- }
395
-
396
- if ( ! empty( $_FILES ) ) {
397
- $wpmem->user->upload_user_files( $user_id, $wpmem->fields );
398
- }
399
-
400
- if ( 'admin' == $display || current_user_can( 'edit_users' ) ) {
401
- if ( $wpmem->mod_reg == 1 ) {
402
-
403
- $wpmem_activate_user = ( isset( $_POST['activate_user'] ) == '' ) ? -1 : filter_var( $_POST['activate_user'], FILTER_SANITIZE_NUMBER_INT );
404
-
405
- if ( $wpmem_activate_user == 1 ) {
406
- wpmem_activate_user( $user_id );
407
- } elseif ( $wpmem_activate_user == 0 ) {
408
- wpmem_deactivate_user( $user_id );
409
- }
410
- }
411
-
412
- if ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) {
413
- if ( function_exists( 'wpmem_a_extenduser' ) ) {
414
- wpmem_a_extenduser( $user_id );
415
- }
416
- }
417
-
418
- if ( 1 == $wpmem->enable_products ) {
419
- // Update products.
420
- if ( isset( $_POST['_wpmem_membership_product'] ) ) {
421
- foreach ( $_POST['_wpmem_membership_product'] as $product_key => $product_value ) {
422
- // Sanitize.
423
- $product_key = sanitize_text_field( $product_key );
424
- // Enable or Disable?
425
- if ( 'enable' == $product_value ) {
426
- // Does product require a role?
427
- if ( false !== $wpmem->membership->products[ $product_key ]['role'] ) {
428
- wpmem_update_user_role( $user_id, $wpmem->membership->products[ $product_key ]['role'], 'add' );
429
- }
430
- // Do we need to set a specific date?
431
- if ( isset( $_POST[ '_wpmem_membership_expiration_' . $product_key ] ) ) {
432
- wpmem_set_user_product( $product_key, $user_id, sanitize_text_field( $_POST[ '_wpmem_membership_expiration_' . $product_key ] ) );
433
- } else {
434
- wpmem_set_user_product( $product_key, $user_id );
435
- }
436
- }
437
- if ( 'disable' == $product_value ) {
438
- $wpmem->user->remove_user_product( $product_key, $user_id );
439
- }
440
- }
441
- }
442
- }
443
- }
444
-
445
- /**
446
- * Fires after the user profile is updated.
447
- *
448
- * Action fires for the admin user edit ("wpmem_admin_after_user_update")
449
- * and the user profile edit ("wpmem_user_after_user_update").
450
- *
451
- * @since 2.9.2
452
- *
453
- * @param int $user_id The user ID.
454
- */
455
- do_action( 'wpmem_' . $display . '_after_user_update', $user_id );
456
-
457
- return;
458
- }
459
-
460
- /**
461
- * Sets user profile update to multipart form data.
462
- *
463
- * If the fields array has a file or image field, this will echo the
464
- * necessary "multipart/form-data" enctype for the form tag.
465
- *
466
- * @since 3.1.8 (as wpmem_profile_multipart()).
467
- * @since 3.1.9 Moved to User Profile object.
468
- */
469
- public static function add_multipart() {
470
- $has_file = false;
471
- foreach ( wpmem_fields() as $field ) {
472
- if ( $field['type'] == 'file' || $field['type'] == 'image' ) {
473
- $has_file = true;
474
- break;
475
- }
476
- }
477
- echo ( $has_file ) ? " enctype=\"multipart/form-data\"" : '';
478
- }
479
-
480
- /**
481
- * Adds user activation to the user profile.
482
- *
483
- * @since 3.1.1
484
- * @since 3.2.0 Moved to WP_Members_User_Profile object
485
- *
486
- * @global object $wpmem
487
- * @param int $user_id
488
- */
489
- public static function _show_activate( $user_id ) {
490
- global $wpmem;
491
- // See if reg is moderated, and if the user has been activated.
492
- if ( $wpmem->mod_reg == 1 ) {
493
- // Make sure this isn't an admin looking at their own profile.
494
- if ( current_user_can( 'edit_users' ) && $user_id != get_current_user_id() ) {
495
- $user_active_flag = get_user_meta( $user_id, 'active', true );
496
- switch( $user_active_flag ) {
497
-
498
- case "0":
499
- $label = __( 'Reactivate this user?', 'wp-members' );
500
- $action = 1;
501
- break;
502
-
503
- case "1":
504
- $label = __( 'Deactivate this user?', 'wp-members' );
505
- $action = 0;
506
- break;
507
-
508
- default:
509
- $label = __( 'Activate this user?', 'wp-members' );
510
- $action = 1;
511
- break;
512
- } ?>
513
- <tr>
514
- <th><label><?php echo $label; ?></label></th>
515
- <td><input id="activate_user" type="checkbox" class="input" name="activate_user" value="<?php echo $action; ?>" /></td>
516
- </tr>
517
- <?php }
518
- }
519
- }
520
-
521
- /**
522
- * Adds user expiration to the user profile.
523
- *
524
- * @since 3.1.1
525
- * @since 3.2.0 Moved to WP_Members_User_Profile object
526
- *
527
- * @global object $wpmem
528
- * @param int $user_id
529
- */
530
- public static function _show_expiration( $user_id ) {
531
-
532
- global $wpmem;
533
- /*
534
- * If using subscription model, show expiration.
535
- * If registration is moderated, this doesn't show
536
- * if user is not active yet.
537
- */
538
- if ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) {
539
- if ( ( $wpmem->mod_reg == 1 && get_user_meta( $user_id, 'active', true ) == 1 ) || ( $wpmem->mod_reg != 1 ) ) {
540
- if ( function_exists( 'wpmem_a_extend_user' ) ) {
541
- wpmem_a_extend_user( $user_id );
542
- }
543
- }
544
- }
545
- }
546
-
547
-
548
- /**
549
- * Adds user registration IP to the user profile.
550
- *
551
- * @since 3.1.1
552
- * @since 3.2.0 Moved to WP_Members_User_Profile object
553
- *
554
- * @param int $user_id
555
- */
556
- public static function _show_ip( $user_id ) { ?>
557
- <tr>
558
- <th><label><?php _e( 'IP @ registration', 'wp-members' ); ?></label></th>
559
- <td><?php echo get_user_meta( $user_id, 'wpmem_reg_ip', true ); ?></td>
560
- </tr>
561
- <?php
562
- }
563
-
564
- /**
565
- * Add jquery ui tabs to user profile.
566
- *
567
- * @since 3.2.5
568
- *
569
- * @param int $user_id
570
- */
571
- static function _profile_tabs( $user_id ) {
572
-
573
- if ( current_user_can( 'edit_users' ) ) {
574
-
575
- /**
576
- * Add tabs to user profile tabs.
577
- *
578
- * @since 3.2.5
579
- *
580
- * @param array {
581
- * @type string $tab (required)
582
- * @type string $content (optional)
583
- * }
584
- */
585
- $tabs = apply_filters( 'wpmem_user_profile_tabs', array() );
586
-
587
- if ( ! empty( $tabs ) ) { ?>
588
- <script>
589
- jQuery(document).ready(function($){
590
- $("#wpmem_user_profile_tabs").tabs();
591
- });
592
- </script>
593
- <?php
594
- echo '<div id="wpmem_user_profile_tabs">';
595
- echo '<ul>';
596
- foreach ( $tabs as $key => $value ) {
597
- echo '<li><a href="#wpmem_user_profile_tabs-' . ( $key ) . '">' . $value['tab'] . '</a></li>';
598
- }
599
- echo '</ul>';
600
- foreach ( $tabs as $key => $value ) {
601
- echo '<div id="wpmem_user_profile_tabs-' . ( $key ) . '">';
602
- echo ( isset( $value['content'] ) ) ? $value['content'] : '';
603
- do_action( 'wpmem_user_profile_tabs_content', $key );
604
- echo '</div>';
605
- }
606
- echo '</div>';
607
- }
608
- }
609
- }
 
 
610
  }
1
+ <?php
2
+ /**
3
+ * The WP_Members User Profile Class.
4
+ *
5
+ * @package WP-Members
6
+ * @subpackage WP_Members Admin User Profile Object Class
7
+ * @since 3.1.8
8
+ */
9
+
10
+ // Exit if accessed directly.
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit();
13
+ }
14
+
15
+ class WP_Members_User_Profile {
16
+
17
+ /**
18
+ * Remove "admin only" fields if dashboard user profile.
19
+ *
20
+ * @since 3.3.6
21
+ *
22
+ * @param string $tag
23
+ * @return array $fields
24
+ */
25
+ static function get_fields( $tag ) {
26
+ $fields = wpmem_fields( $tag );
27
+ if ( 'profile_dashboard' == $tag && false === current_user_can( 'edit_users' ) ) {
28
+ foreach( $fields as $key => $field ) {
29
+ if ( false == $field['profile'] ) {
30
+ unset( $fields[ $key ] );
31
+ }
32
+ }
33
+ }
34
+ return $fields;
35
+ }
36
+
37
+ /**
38
+ * Static function to display WP-Members fields on the admin/dashboard user profile.
39
+ *
40
+ * Function was created in 3.1.9 as a merge of wpmem_admin_fields()
41
+ * and wpmem_user_profile().
42
+ *
43
+ * @since 3.1.9
44
+ *
45
+ * @global object $current_screen
46
+ * @global string $user_ID
47
+ * @global object $wpmem
48
+ * @param object $user_obj
49
+ */
50
+ static function profile( $user_obj ) {
51
+
52
+ global $current_screen, $user_ID, $wpmem;
53
+ $user_id = ( 'profile' == $current_screen->id ) ? $user_ID : filter_var( $_REQUEST['user_id'], FILTER_SANITIZE_NUMBER_INT );
54
+ $display = ( 'profile' == $current_screen->base ) ? 'user' : 'admin';
55
+ $display = ( current_user_can( 'edit_users' ) ) ? 'admin' : $display; ?>
56
+
57
+ <h3><?php
58
+ $heading = ( 'admin' == $display ) ? __( 'WP-Members Additional Fields', 'wp-members' ) : __( 'Additional Information', 'wp-members' );
59
+ /**
60
+ * Filter the heading for additional profile fields.
61
+ *
62
+ * Filter is applied for the admin user edit ("wpmem_admin_profile_heading")
63
+ * and the user profile edit ("wpmem_user_profile_heading").
64
+ *
65
+ * @since 2.8.2 Admin Profile
66
+ * @since 2.9.1 Dashboard Profile
67
+ * @since 3.1.9 Merged admin/dashboard profile
68
+ *
69
+ * @param string The default additional fields heading.
70
+ */
71
+ echo apply_filters( 'wpmem_' . $display . '_profile_heading', $heading ); ?></h3>
72
+ <table class="form-table">
73
+ <?php
74
+ // Get fields.
75
+ $wpmem_fields = ( 'admin' == $display ) ? self::get_fields( 'profile_admin' ) : self::get_fields( 'profile_dashboard' );
76
+ // Get excluded meta.
77
+ $exclude = wpmem_get_excluded_meta( $display . '-profile' );
78
+
79
+ // If tos is an active field.
80
+ if ( isset( $wpmem_fields['tos'] ) ) {
81
+ if ( 1 != $wpmem_fields['tos']['register'] ) {
82
+ unset( $wpmem_fields['tos'] );
83
+ }
84
+ // This is the dashboard profile, and user has current field value.
85
+ if ( 'user' == $display
86
+ && isset( $wpmem_fields['tos'] )
87
+ && ( get_user_meta( $user_ID, 'tos', true ) == $wpmem_fields['tos']['checked_value'] ) ) {
88
+ unset( $wpmem_fields['tos'] );
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Fires at the beginning of generating the WP-Members fields in the user profile.
94
+ *
95
+ * Action fires for the admin user edit ("wpmem_admin_before_profile")
96
+ * and the user profile edit ("wpmem_user_before_profile").
97
+ *
98
+ * @since 2.9.3 Created for admin profile.
99
+ * @since 3.1.9 Added to dashboard profile.
100
+ *
101
+ * @param int $user_id The user's ID.
102
+ * @param array $wpmem_fields The WP-Members fields.
103
+ */
104
+ do_action( 'wpmem_' . $display . '_before_profile', $user_id, $wpmem_fields );
105
+
106
+ // Assemble form rows array.
107
+ $rows = array();
108
+ foreach ( $wpmem_fields as $meta => $field ) {
109
+
110
+ $valtochk = ''; $values = '';
111
+
112
+ // Determine which fields to show in the additional fields area.
113
+ $show = ( ! $field['native'] && ! in_array( $meta, $exclude ) ) ? true : false;
114
+ //$show = ( 'tos' == $meta && $field['register'] ) ? null : $show;
115
+
116
+ if ( $show ) {
117
+
118
+ $val = get_user_meta( $user_id, $meta, true );
119
+ $val = ( $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' ) ? $val : htmlspecialchars( $val );
120
+ if ( $field['type'] == 'checkbox' ) {
121
+ $valtochk = $val;
122
+ $val = $field['checked_value'];
123
+ }
124
+
125
+ if ( 'multicheckbox' == $field['type'] || 'select' == $field['type'] || 'multiselect' == $field['type'] || 'radio' == $field['type'] ) {
126
+ $values = $field['values'];
127
+ $valtochk = $val;
128
+ }
129
+
130
+ // Is this an image or a file?
131
+ if ( 'file' == $field['type'] || 'image' == $field['type'] ) {
132
+ $empty_file = '<span class="description">' . __( 'None' ) . '</span>';
133
+ if ( 'file' == $field['type'] ) {
134
+ $attachment_url = wp_get_attachment_url( $val );
135
+ $input = ( $attachment_url ) ? '<a href="' . $attachment_url . '">' . $attachment_url . '</a>' : $empty_file;
136
+ } else {
137
+ $attachment_url = wp_get_attachment_image( $val, 'medium' );
138
+ if ( 'admin' == $display ) {
139
+ $edit_url = admin_url( 'upload.php?item=' . $val );
140
+ $input = ( $attachment_url ) ? '<a href="' . $edit_url . '">' . $attachment_url . '</a>' : $empty_file;
141
+ } else {
142
+ $input = ( $attachment_url ) ? $attachment_url : $empty_file;
143
+ }
144
+ }
145
+ $input.= '<br />' . wpmem_get_text( 'profile_upload' ) . '<br />';
146
+ $input.= wpmem_form_field( array(
147
+ 'name' => $meta,
148
+ 'type' => $field['type'],
149
+ 'value' => $val,
150
+ 'compare' => $valtochk,
151
+ ) );
152
+ } else {
153
+ if ( 'select' == $field['type'] || 'radio' == $field['type'] ) {
154
+ $input = wpmem_form_field( $meta, $field['type'], $values, $valtochk );
155
+ } elseif( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) {
156
+ $input = wpmem_form_field( array( 'name'=>$meta, 'type'=>$field['type'], 'value'=>$values, 'compare'=>$valtochk, 'delimiter'=>$field['delimiter'] ) );
157
+ } else {
158
+ $field['type'] = ( 'hidden' == $field['type'] ) ? 'text' : $field['type'];
159
+
160
+ $formfield_args = array(
161
+ 'name' => $meta,
162
+ 'type' => $field['type'],
163
+ 'value' => $val,
164
+ 'compare' => $valtochk,
165
+ 'required' => $field['required'],
166
+ 'class' => 'regular-text',
167
+ 'placeholder' => ( isset( $field['placeholder'] ) ) ? $field['placeholder'] : '',
168
+ 'pattern' => ( isset( $field['pattern'] ) ) ? $field['pattern'] : false,
169
+ 'title' => ( isset( $field['title'] ) ) ? $field['title'] : false,
170
+ 'min' => ( isset( $field['min'] ) ) ? $field['min'] : false,
171
+ 'max' => ( isset( $field['max'] ) ) ? $field['max'] : false,
172
+ 'rows' => ( isset( $field['rows'] ) ) ? $field['rows'] : false,
173
+ 'cols' => ( isset( $field['cols'] ) ) ? $field['cols'] : false,
174
+ );
175
+
176
+ $input = wpmem_form_field( $formfield_args );
177
+ }
178
+ }
179
+
180
+ // Is the field required?
181
+ $req = ( $field['required'] ) ? ' <span class="description">' . __( '(required)' ) . '</span>' : '';
182
+ $label = '<label>' . __( $field['label'], 'wp-members' ) . $req . '</label>';
183
+
184
+ // Build the form rows for filtering.
185
+ $rows[ $meta ] = array(
186
+ 'meta' => $meta,
187
+ 'type' => $field['type'],
188
+ 'value' => $val,
189
+ 'values' => $values,
190
+ 'label_text' => __( $field['label'], 'wp-members' ),
191
+ 'row_before' => '<tr>',
192
+ 'label' => '<th>' . $label . '</th>',
193
+ 'field_before' => '<td>',
194
+ 'field' => $input,
195
+ 'field_after' => '</td>',
196
+ 'row_after' => '</tr>',
197
+ );
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Filter for rows.
203
+ *
204
+ * Filter is applied for the admin user edit ("wpmem_register_form_rows_admin")
205
+ * and the user profile edit ("wpmem_register_form_rows_user").
206
+ *
207
+ * @since 3.1.0
208
+ * @since 3.1.6 Deprecated $order.
209
+ *
210
+ * @param array $rows {
211
+ * An array of the profile rows.
212
+ *
213
+ * @type string $meta The meta key.
214
+ * @type string $type The field type.
215
+ * @type string $value Value if set.
216
+ * @type string $values Possible values (select, multiselect, multicheckbox, radio).
217
+ * @type string $label_text Raw label text (no HTML).
218
+ * @type string $row_before HTML before the row.
219
+ * @type string $label HTML label.
220
+ * @type string $field_before HTML before the field input tag.
221
+ * @type string $field HTML for field input.
222
+ * @type string $field_after HTML after the field.
223
+ * @type string $row_after HTML after the row.
224
+ * }
225
+ * @param string $tag adminprofile|userprofile
226
+ */
227
+ $rows = apply_filters( 'wpmem_register_form_rows_' . $display, $rows, $display . 'profile' );
228
+
229
+ // Handle form rows display from array.
230
+ foreach ( $rows as $row ) {
231
+ $show_field =
232
+ $row['row_before'] .
233
+ $row['label'] .
234
+ $row['field_before'] . $row['field'] . $row['field_after'] .
235
+ $row['field_after'];
236
+
237
+ /**
238
+ * Filter the profile field.
239
+ *
240
+ * Filter is applied for the admin user edit ("wpmem_admin_profile_field")
241
+ * and the user profile edit ("wpmem_user_profile_field").
242
+ *
243
+ * @since 2.8.2
244
+ * @since 3.1.1 Added $user_id and $row
245
+ *
246
+ * @param string $show_field The HTML string for the additional profile field.
247
+ * @param string $user_id
248
+ * @param array $row
249
+ */
250
+ echo apply_filters( 'wpmem_' . $display . '_profile_field', $show_field, $user_id, $row );
251
+ }
252
+
253
+ /**
254
+ * Fires after generating the WP-Members fields in the user profile.
255
+ *
256
+ * Action fires for the admin user edit ("wpmem_admin_after_profile")
257
+ * and the user profile edit ("wpmem_user_after_profile").
258
+ *
259
+ * @since 2.9.3
260
+ *
261
+ * @param int $user_id The user's ID.
262
+ * @param array $wpmem_fields The WP-Members fields.
263
+ */
264
+ do_action( 'wpmem_' . $display . '_after_profile', $user_id, $wpmem_fields ); ?>
265
+
266
+ </table><?php
267
+
268
+ /**
269
+ * Fires after the user profile table.
270
+ *
271
+ * Action fires for the admin user edit ("wpmem_admin_after_profile_table")
272
+ * and the user profile edit ("wpmem_user_after_profile_table").
273
+ *
274
+ * @since 3.2.6
275
+ *
276
+ * @param int $user_id The user's ID.
277
+ * @param array $wpmem_fields The WP-Members fields.
278
+ */
279
+ do_action( 'wpmem_' . $display . '_after_profile_table', $user_id, $wpmem_fields );
280
+
281
+ }
282
+
283
+ /**
284
+ * Static function to update admin/dashboard user profile.
285
+ *
286
+ * Function was created in 3.1.9 as a merge of wpmem_admin_update()
287
+ * and wpmem_profile_update().
288
+ *
289
+ * @since 3.1.9
290
+ *
291
+ * @global object $current_screen
292
+ * @global string $user_id
293
+ * @global object $wpmem
294
+ * @param string $user_id
295
+ * @return
296
+ */
297
+ static function update( $user_id ) {
298
+
299
+ global $current_screen, $user_id, $wpmem;
300
+ $display = ( 'profile' == $current_screen->base ) ? 'user' : 'admin';
301
+
302
+ if ( ! $user_id ) {
303
+ $user_id = filter_var( wpmem_get( 'user_id', -1, 'request' ), FILTER_SANITIZE_NUMBER_INT );
304
+ if ( 1 > $user_id ) {
305
+ // Still no user id? User cannot be updated.
306
+ return;
307
+ }
308
+ }
309
+
310
+ $wpmem_fields = ( 'admin' == $display ) ? self::get_fields( 'profile_admin' ) : self::get_fields( 'profile_dashboard' );
311
+
312
+ // Check for password field before exclusions, just in case we are activating a user (otherwise password is removed on user/admin profiles).
313
+ $chk_pass = ( array_key_exists( 'password', $wpmem_fields ) && true === $wpmem_fields['password']['register'] ) ? true : false;
314
+
315
+ $exclude = wpmem_get_excluded_meta( $display . '-profile' );
316
+
317
+ foreach ( $exclude as $excluded ) {
318
+ unset( $wpmem_fields[ $excluded ] );
319
+ }
320
+
321
+ // If tos is an active field, this is the dashboard profile, and user has current field value.
322
+ if ( isset( $wpmem_fields['tos'] )
323
+ && 'user' == $display
324
+ && get_user_meta( $user_id, 'tos', true ) == $wpmem_fields['tos']['checked_value'] ) {
325
+ unset( $wpmem_fields['tos'] );
326
+ }
327
+
328
+ /**
329
+ * Fires before the user profile is updated.
330
+ *
331
+ * Action fires for the admin user edit ("wpmem_admin_pre_user_update")
332
+ * and the user profile edit ("wpmem_user_pre_user_update").
333
+ *
334
+ * @since 2.9.2 Added for admin profile update.
335
+ * @since 3.1.9 Added for user profile update.
336
+ *
337
+ * @param int $user_id The user ID.
338
+ * @param array $wpmem_fields Array of the custom fields.
339
+ */
340
+ do_action( 'wpmem_' . $display . '_pre_user_update', $user_id, $wpmem_fields );
341
+
342
+ $fields = array();
343
+ foreach ( $wpmem_fields as $meta => $field ) {
344
+ if ( ! $field['native']
345
+ && $field['type'] != 'password'
346
+ && $field['type'] != 'checkbox'
347
+ && $field['type'] != 'multiselect'
348
+ && $field['type'] != 'multicheckbox'
349
+ && $field['type'] != 'file'
350
+ && $field['type'] != 'image'
351
+ && $field['type'] != 'textarea' ) {
352
+ ( isset( $_POST[ $meta ] ) && 'password' != $field['type'] ) ? $fields[ $meta ] = sanitize_text_field( $_POST[ $meta ] ) : false;
353
+
354
+ // For user profile (not admin).
355
+ $chk = false;
356
+ if ( 'admin' != $display ) {
357
+ // Check for required fields.
358
+ if ( ! $field['required'] ) {
359
+ $chk = 'ok';
360
+ }
361
+ if ( $field['required'] && $_POST[ $meta ] != '' ) {
362
+ $chk = 'ok';
363
+ }
364
+ }
365
+ } elseif ( $field['type'] == 'checkbox' ) {
366
+ $fields[ $meta ] = ( isset( $_POST[ $meta ] ) ) ? sanitize_text_field( $_POST[ $meta ] ) : '';
367
+ } elseif ( $field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' ) {
368
+ $fields[ $meta ] = ( isset( $_POST[ $meta ] ) ) ? implode( $field['delimiter'], wp_unslash( $_POST[ $meta ] ) ) : '';
369
+ } elseif ( $field['type'] == 'textarea' ) {
370
+ $fields[ $meta ] = ( isset( $_POST[ $meta ] ) ) ? sanitize_textarea_field( $_POST[ $meta ] ) : '';
371
+ }
372
+ }
373
+
374
+ /**
375
+ * Filter the submitted field values for backend profile update.
376
+ *
377
+ * Filters is applied for the admin user edit ("wpmem_admin_profile_update")
378
+ * and the user profile edit ("wpmem_user_profile_update").
379
+ *
380
+ * @since 2.8.2 Added for Admin profile update.
381
+ * @since 3.1.9 Added for User profile update.
382
+ *
383
+ * @param array $fields An array of the posted form values.
384
+ * @param int $user_id The ID of the user being updated.
385
+ */
386
+ $fields = apply_filters( 'wpmem_' . $display . '_profile_update', $fields, $user_id );
387
+
388
+ // Handle meta update, skip excluded fields.
389
+ foreach ( $fields as $key => $val ) {
390
+ if ( ! in_array( $key, $exclude ) ) {
391
+ if ( ( 'admin' != $display && 'ok' == $chk ) || 'admin' == $display ) {
392
+ update_user_meta( $user_id, $key, $val );
393
+ }
394
+ }
395
+ }
396
+
397
+ if ( ! empty( $_FILES ) ) {
398
+ $wpmem->user->upload_user_files( $user_id, $wpmem->fields );
399
+ }
400
+
401
+ if ( 'admin' == $display || current_user_can( 'edit_users' ) ) {
402
+ if ( $wpmem->mod_reg == 1 ) {
403
+
404
+ $wpmem_activate_user = ( isset( $_POST['activate_user'] ) == '' ) ? -1 : filter_var( $_POST['activate_user'], FILTER_SANITIZE_NUMBER_INT );
405
+
406
+ if ( $wpmem_activate_user == 1 ) {
407
+ wpmem_activate_user( $user_id );
408
+ } elseif ( $wpmem_activate_user == 0 ) {
409
+ wpmem_deactivate_user( $user_id );
410
+ }
411
+ }
412
+
413
+ if ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) {
414
+ if ( function_exists( 'wpmem_a_extenduser' ) ) {
415
+ wpmem_a_extenduser( $user_id );
416
+ }
417
+ }
418
+
419
+ if ( 1 == $wpmem->enable_products ) {
420
+ // Update products.
421
+ if ( isset( $_POST['_wpmem_membership_product'] ) ) {
422
+ foreach ( $_POST['_wpmem_membership_product'] as $product_key => $product_value ) {
423
+ // Sanitize.
424
+ $product_key = sanitize_text_field( $product_key );
425
+ // Enable or Disable?
426
+ if ( 'enable' == $product_value ) {
427
+ // Does product require a role?
428
+ if ( false !== $wpmem->membership->products[ $product_key ]['role'] ) {
429
+ wpmem_update_user_role( $user_id, $wpmem->membership->products[ $product_key ]['role'], 'add' );
430
+ }
431
+ // Do we need to set a specific date?
432
+ if ( isset( $_POST[ '_wpmem_membership_expiration_' . $product_key ] ) ) {
433
+ wpmem_set_user_product( $product_key, $user_id, sanitize_text_field( $_POST[ '_wpmem_membership_expiration_' . $product_key ] ) );
434
+ } else {
435
+ wpmem_set_user_product( $product_key, $user_id );
436
+ }
437
+ }
438
+ if ( 'disable' == $product_value ) {
439
+ $wpmem->user->remove_user_product( $product_key, $user_id );
440
+ }
441
+ }
442
+ }
443
+ }
444
+ }
445
+
446
+ /**
447
+ * Fires after the user profile is updated.
448
+ *
449
+ * Action fires for the admin user edit ("wpmem_admin_after_user_update")
450
+ * and the user profile edit ("wpmem_user_after_user_update").
451
+ *
452
+ * @since 2.9.2
453
+ *
454
+ * @param int $user_id The user ID.
455
+ */
456
+ do_action( 'wpmem_' . $display . '_after_user_update', $user_id );
457
+
458
+ return;
459
+ }
460
+
461
+ /**
462
+ * Sets user profile update to multipart form data.
463
+ *
464
+ * If the fields array has a file or image field, this will echo the
465
+ * necessary "multipart/form-data" enctype for the form tag.
466
+ *
467
+ * @since 3.1.8 (as wpmem_profile_multipart()).
468
+ * @since 3.1.9 Moved to User Profile object.
469
+ */
470
+ public static function add_multipart() {
471
+ $has_file = false;
472
+ foreach ( wpmem_fields() as $field ) {
473
+ if ( $field['type'] == 'file' || $field['type'] == 'image' ) {
474
+ $has_file = true;
475
+ break;
476
+ }
477
+ }
478
+ echo ( $has_file ) ? " enctype=\"multipart/form-data\"" : '';
479
+ }
480
+
481
+ /**
482
+ * Adds user activation to the user profile.
483
+ *
484
+ * @since 3.1.1
485
+ * @since 3.2.0 Moved to WP_Members_User_Profile object
486
+ *
487
+ * @global object $wpmem
488
+ * @param int $user_id
489
+ */
490
+ public static function _show_activate( $user_id ) {
491
+ global $wpmem;
492
+ // See if reg is moderated, and if the user has been activated.
493
+ if ( $wpmem->mod_reg == 1 ) {
494
+ // Make sure this isn't an admin looking at their own profile.
495
+ if ( current_user_can( 'edit_users' ) && $user_id != get_current_user_id() ) {
496
+ $user_active_flag = get_user_meta( $user_id, 'active', true );
497
+ switch( $user_active_flag ) {
498
+
499
+ case "0":
500
+ $label = __( 'Reactivate this user?', 'wp-members' );
501
+ $action = 1;
502
+ break;
503
+
504
+ case "1":
505
+ $label = __( 'Deactivate this user?', 'wp-members' );
506
+ $action = 0;
507
+ break;
508
+
509
+ default:
510
+ $label = __( 'Activate this user?', 'wp-members' );
511
+ $action = 1;
512
+ break;
513
+ } ?>
514
+ <tr>
515
+ <th><label><?php echo $label; ?></label></th>
516
+ <td><input id="activate_user" type="checkbox" class="input" name="activate_user" value="<?php echo $action; ?>" /></td>
517
+ </tr>
518
+ <?php }
519
+ }
520
+ }
521
+
522
+ /**
523
+ * Adds user expiration to the user profile.
524
+ *
525
+ * @since 3.1.1
526
+ * @since 3.2.0 Moved to WP_Members_User_Profile object
527
+ *
528
+ * @global object $wpmem
529
+ * @param int $user_id
530
+ */
531
+ public static function _show_expiration( $user_id ) {
532
+
533
+ global $wpmem;
534
+ /*
535
+ * If using subscription model, show expiration.
536
+ * If registration is moderated, this doesn't show
537
+ * if user is not active yet.
538
+ */
539
+ if ( defined( 'WPMEM_EXP_MODULE' ) && $wpmem->use_exp == 1 ) {
540
+ if ( ( $wpmem->mod_reg == 1 && get_user_meta( $user_id, 'active', true ) == 1 ) || ( $wpmem->mod_reg != 1 ) ) {
541
+ if ( function_exists( 'wpmem_a_extend_user' ) ) {
542
+ wpmem_a_extend_user( $user_id );
543
+ }
544
+ }
545
+ }
546
+ }
547
+
548
+
549
+ /**
550
+ * Adds user registration IP to the user profile.
551
+ *
552
+ * @since 3.1.1
553
+ * @since 3.2.0 Moved to WP_Members_User_Profile object
554
+ *
555
+ * @param int $user_id
556
+ */
557
+ public static function _show_ip( $user_id ) { ?>
558
+ <tr>
559
+ <th><label><?php _e( 'IP @ registration', 'wp-members' ); ?></label></th>
560
+ <td><?php echo get_user_meta( $user_id, 'wpmem_reg_ip', true ); ?></td>
561
+ </tr>
562
+ <?php
563
+ }
564
+
565
+ /**
566
+ * Add jquery ui tabs to user profile.
567
+ *
568
+ * @since 3.2.5
569
+ *
570
+ * @param int $user_id
571
+ */
572
+ static function _profile_tabs( $user_id ) {
573
+
574
+ if ( current_user_can( 'edit_users' ) ) {
575
+
576
+ /**
577
+ * Add tabs to user profile tabs.
578
+ *
579
+ * @since 3.2.5
580
+ *
581
+ * @param array {
582
+ * @type string $tab (required)
583
+ * @type string $content (optional)
584
+ * }
585
+ */
586
+ $tabs = apply_filters( 'wpmem_user_profile_tabs', array() );
587
+
588
+ if ( ! empty( $tabs ) ) {
589
+ ?>
590
+ <script>
591
+ jQuery(document).ready(function($){
592
+ $("#wpmem_user_profile_tabs").tabs();
593
+ });
594
+ </script>
595
+ <?php
596
+ echo '<div id="wpmem_user_profile_tabs">';
597
+ echo '<ul>';
598
+ foreach ( $tabs as $key => $value ) {
599
+ echo '<li><a href="#wpmem_user_profile_tabs-' . ( $key ) . '">' . $value['tab'] . '</a></li>';
600
+ }
601
+ echo '</ul>';
602
+ foreach ( $tabs as $key => $value ) {
603
+ echo '<div id="wpmem_user_profile_tabs-' . ( $key ) . '">';
604
+ echo ( isset( $value['content'] ) ) ? $value['content'] : '';
605
+ do_action( 'wpmem_user_profile_tabs_content', $key );
606
+ echo '</div>';
607
+ }
608
+ echo '</div>';
609
+ }
610
+ }
611
+ }
612
  }
includes/class-wp-members-user.php CHANGED
@@ -1,1177 +1,1229 @@
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_User {
19
-
20
- /**
21
- * Container for reg form data.
22
- *
23
- * @since 3.1.7
24
- * @access public
25
- * @var array
26
- */
27
- public $post_data = array();
28
-
29
- /**
30
- * Container for user access information.
31
- *
32
- * @since 3.2.0
33
- * @access public
34
- * @var array
35
- */
36
- public $access = array();
37
-
38
- /**
39
- * Initilize the User object.
40
- *
41
- * @since 3.1.7
42
- *
43
- * @param object $settings The WP_Members Object
44
- */
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
-
53
- add_action( 'wpmem_register_redirect', array( $this, 'register_redirect' ), 20 ); // Adds a nonce to the redirect if there is a "redirect_to" attribute in the reg form.
54
-
55
- add_filter( 'registration_errors', array( $this, 'wp_register_validate' ), 10, 3 ); // native registration validation
56
-
57
- // Load anything the user as access to.
58
- if ( 1 == $settings->enable_products ) {
59
- add_action( 'user_register', array( $this, 'set_default_product' ), 6 );
60
-
61
- if ( is_user_logged_in() ) {
62
- $this->access = $this->get_user_products( false, $settings );
63
- }
64
- }
65
- }
66
-
67
- /**
68
- * Handle user login.
69
- *
70
- * Built from, but replaces, the original wpmem_login() function
71
- * from core.php. wpmem_login() is currently maintained as a
72
- * wrapper and is the direct function called for login.
73
- *
74
- * @since 3.1.7
75
- * @since 3.2.3 Removed wpmem_login_fields filter.
76
- * @since 3.2.3 Replaced form collection with WP script to facilitate login with username OR email.
77
- * @since 3.2.3 Changed to wp_safe_redirect().
78
- *
79
- * @return string Returns "loginfailed" if failed login.
80
- */
81
- function login() {
82
-
83
- global $wpmem;
84
-
85
- if ( ! empty( $_POST['log'] ) && ! force_ssl_admin() ) {
86
- $user_name = sanitize_user( $_POST['log'] );
87
- $user = get_user_by( 'login', $user_name );
88
-
89
- if ( ! $user && strpos( $user_name, '@' ) ) {
90
- $user = get_user_by( 'email', $user_name );
91
- }
92
- }
93
-
94
- $user = wp_signon( array(), is_ssl() );
95
-
96
- if ( is_wp_error( $user ) ) {
97
- $wpmem->error = $user->get_error_message();
98
- return "loginfailed";
99
- } else {
100
- $redirect_to = wpmem_get( 'redirect_to', false );
101
- $redirect_to = ( $redirect_to ) ? esc_url_raw( trim( $redirect_to ) ) : esc_url_raw( wpmem_current_url() );
102
- /** This filter defined in wp-login.php */
103
- $redirect_to = apply_filters( 'login_redirect', $redirect_to, '', $user );
104
- /**
105
- * Filter the redirect url.
106
- *
107
- * This is the plugin's original redirect filter. In 3.1.7,
108
- * WP's login_redirect filter hook was added to provide better
109
- * integration support for other plugins and also for users
110
- * who may already be using WP's filter(s). login_redirect
111
- * comes first, then wpmem_login_redirect. So wpmem_login_redirect
112
- * can be used to override a default in login_redirect.
113
- *
114
- * @since 2.7.7
115
- * @since 2.9.2 Added $user_id
116
- *
117
- * @param string $redirect_to The url to direct to.
118
- * @param int $user->ID The user's primary key ID.
119
- */
120
- $redirect_to = apply_filters( 'wpmem_login_redirect', $redirect_to, $user->ID );
121
- wp_safe_redirect( $redirect_to );
122
- exit();
123
- }
124
- }
125
-
126
- /**
127
- * Handle user logout.
128
- *
129
- * Built from, but replaces, the original wpmem_logout() function
130
- * from core.php. wpmem_logout() is currently maintained as a
131
- * wrapper and is the direct function called for logout.
132
- *
133
- * @since 3.1.7
134
- * @since 3.2.0 Added logout_redirect filter
135
- *
136
- * @param string $redirect_to URL to redirect the user to (default: false).
137
- */
138
- function logout( $redirect_to = false ) {
139
- // Default redirect URL.
140
- $redirect_to = ( $redirect_to ) ? $redirect_to : home_url();
141
-
142
- /** This filter is documented in /wp-login.php */
143
- $redirect_to = apply_filters( 'logout_redirect', $redirect_to, $redirect_to, wp_get_current_user() );
144
- /**
145
- * Filter where the user goes when logged out.
146
- *
147
- * @since 2.7.1
148
- * @since 3.1.7 Moved to WP_Members_Users Class.
149
- *
150
- * @param string The blog home page.
151
- */
152
- $redirect_to = apply_filters( 'wpmem_logout_redirect', $redirect_to );
153
-
154
- wp_destroy_current_session();
155
- wp_clear_auth_cookie();
156
-
157
- /** This action is defined in /wp-includes/pluggable.php. */
158
- do_action( 'wp_logout' );
159
-
160
- wp_safe_redirect( $redirect_to );
161
- exit();
162
- }
163
-
164
- /**
165
- * Sets the registration type.
166
- *
167
- * @since 3.3.0
168
- */
169
- function set_reg_type() {
170
- // Is this a WP-Members registration?
171
- $this->reg_type['is_wpmem'] = ( 'register' == wpmem_get( 'a' ) ) ? true : false;
172
- // Is this WP's native registration? Checks the native submit button.
173
- $this->reg_type['is_native'] = ( __( 'Register' ) == wpmem_get( 'wp-submit' ) ) ? true : false;
174
- // Is this a Users > Add New process? Checks the post action.
175
- $this->reg_type['is_add_new'] = ( 'createuser' == wpmem_get( 'action' ) ) ? true : false;
176
- // Is this a WooCommerce my account registration? Checks for WC fields.
177
- $this->reg_type['is_woo'] = ( wpmem_get( 'woocommerce-register-nonce' ) ) ? true : false;
178
- // Is this a WooCommerce checkout?
179
- $this->reg_type['is_woo_checkout'] = ( wpmem_get( 'woocommerce_checkout_place_order' ) ) ? true : false;
180
- }
181
-
182
- /**
183
- * Validate user registration.
184
- *
185
- * @since 3.3.0
186
- *
187
- * @global int $user_ID
188
- * @global string $wpmem_themsg
189
- * @global array $userdata
190
- *
191
- * @param string $tag
192
- */
193
- function register_validate( $tag ) {
194
-
195
- // Get the globals.
196
- global $user_ID, $wpmem, $wpmem_themsg, $userdata;
197
-
198
- // Check the nonce.
199
- if ( empty( $_POST ) || ! wp_verify_nonce( $_REQUEST[ '_wpmem_' . $tag . '_nonce' ], 'wpmem_longform_nonce' ) ) {
200
- $wpmem_themsg = __( 'There was an error processing the form.', 'wp-members' );
201
- return;
202
- }
203
-
204
- // Make sure fields are loaded.
205
- wpmem_fields( $tag );
206
-
207
- // Is this a registration or a user profile update?
208
- if ( 'register' == $tag ) {
209
- $this->post_data['username'] = sanitize_user( wpmem_get( 'username' ) );
210
- }
211
-
212
- // Add the user email to the $this->post_data array for _data hooks.
213
- if ( isset( $wpmem->fields['user_email'] ) ) {
214
- $this->post_data['user_email'] = sanitize_email( wpmem_get( 'user_email' ) );
215
- }
216
-
217
- // If this is an update, and tos is a field, and the user has the correct saved value, remove tos.
218
- if ( 'update' == $tag && isset( $wpmem->fields['tos'] ) ) {
219
- if ( get_user_meta( $user_ID, 'tos', true ) == $wpmem->fields['tos']['checked_value'] ) {
220
- unset( $wpmem->fields['tos'] );
221
- }
222
- }
223
-
224
- // Build the $this->post_data array from $_POST data.
225
- foreach ( $wpmem->fields as $meta_key => $field ) {
226
- if ( ( 'register' == $tag && true == $field['register'] ) || ( 'update' == $tag && true == $field['profile'] ) ) {
227
- if ( 'password' != $meta_key && 'confirm_password' != $meta_key && 'username' != $meta_key ) {
228
- if ( isset( $_POST[ $meta_key ] ) ) {
229
- switch ( $field['type'] ) {
230
- case 'checkbox':
231
- $this->post_data[ $meta_key ] = sanitize_text_field( $_POST[ $meta_key ] );
232
- break;
233
- case 'multiselect':
234
- case 'multicheckbox':
235
- $delimiter = ( isset( $field['delimiter'] ) ) ? $field['delimiter'] : '|';
236
- $this->post_data[ $meta_key ] = ( isset( $_POST[ $meta_key ] ) ) ? implode( $delimiter, wpmem_sanitize_array( $_POST[ $meta_key ] ) ) : '';
237
- break;
238
- case 'textarea':
239
- $this->post_data[ $meta_key ] = sanitize_textarea_field( $_POST[ $meta_key ] );
240
- break;
241
- default:
242
- $this->post_data[ $meta_key ] = sanitize_text_field( $_POST[ $meta_key ] );
243
- break;
244
- }
245
- } else {
246
- $this->post_data[ $meta_key ] = '';
247
- }
248
- } else {
249
- // We do have password as part of the registration form.
250
- if ( isset( $_POST['password'] ) ) {
251
- $this->post_data['password'] = $_POST['password'];
252
- }
253
- if ( isset( $_POST['confirm_password'] ) ) {
254
- $this->post_data['confirm_password'] = $_POST['confirm_password'];
255
- }
256
- }
257
- }
258
- }
259
-
260
- /**
261
- * Filter the submitted form fields prior to validation.
262
- *
263
- * @since 2.8.2
264
- * @since 3.1.7 Added $tag
265
- * @since 3.2.0 Moved to regiser_validate() method in user object class.
266
- *
267
- * @param array $this->post_data An array of the posted form field data.
268
- * @param string $tag
269
- */
270
- $this->post_data = apply_filters( 'wpmem_pre_validate_form', $this->post_data, $tag );
271
-
272
- if ( 'update' == $tag ) {
273
- $pass_arr = array( 'username', 'password', 'confirm_password', 'password_confirm' );
274
- foreach ( $pass_arr as $pass ) {
275
- unset( $wpmem->fields[ $pass ] );
276
- }
277
- }
278
-
279
- // Check for required fields, reverse the array for logical error message order.
280
- foreach ( array_reverse( $wpmem->fields ) as $meta_key => $field ) {
281
- // Validation if the field is required.
282
- if ( true == $field['required'] ) {
283
- if ( 'file' == $field['type'] || 'image' == $field['type'] ) {
284
- // If this is a new registration.
285
- if ( 'register' == $tag ) {
286
- // If the required field is a file type.
287
- if ( empty( $_FILES[ $meta_key ]['name'] ) ) {
288
- $wpmem_themsg = sprintf( $wpmem->get_text( 'reg_empty_field' ), __( $field['label'], 'wp-members' ) );
289
- }
290
- }
291
- } else {
292
- // If the required field is any other field type.
293
- if ( ( 'register' == $tag && true == $field['register'] ) || ( 'update' == $tag && true == $field['profile'] ) ) {
294
- if ( null == $this->post_data[ $meta_key ] ) {
295
- $wpmem_themsg = sprintf( $wpmem->get_text( 'reg_empty_field' ), __( $field['label'], 'wp-members' ) );
296
- }
297
- }
298
- }
299
- }
300
-
301
- // Validate file field type.
302
- if ( 'file' == $field['type'] || 'image' == $field['type'] ) {
303
- if ( '' == $field['file_types'] ) {
304
- $field['file_types'] = ( 'image' == $field['type'] ) ? 'gif|png|jpg|jpeg|bmp' : 'doc|docx|pdf|zip';
305
- }
306
- $allowed_file_types = explode( '|', $field['file_types'] );
307
- $msg_types = implode( ', ', $allowed_file_types );
308
- if ( ! empty( $_FILES[ $meta_key ]['name'] ) ) {
309
- $extension = pathinfo( $_FILES[ $meta_key ]['name'], PATHINFO_EXTENSION );
310
- if ( ! in_array( $extension, $allowed_file_types ) ) {
311
- $wpmem_themsg = sprintf( $wpmem->get_text( 'reg_file_type' ), __( $field['label'], 'wp-members' ), str_replace( '|', ',', $msg_types ) );
312
- }
313
- }
314
- }
315
- }
316
-
317
- if ( 'register' == $tag ) {
318
- if ( is_multisite() ) {
319
- // Multisite has different requirements.
320
- $result = wpmu_validate_user_signup( $this->post_data['username'], $this->post_data['user_email'] );
321
- $errors = $result['errors'];
322
- if ( $errors->errors ) {
323
- $wpmem_themsg = $errors->get_error_message();
324
- return $wpmem_themsg;
325
- exit();
326
- }
327
-
328
- } else {
329
- // Validate username and email fields.
330
- $wpmem_themsg = ( email_exists( $this->post_data['user_email'] ) ) ? "email" : $wpmem_themsg;
331
- $wpmem_themsg = ( username_exists( $this->post_data['username'] ) ) ? "user" : $wpmem_themsg;
332
- $wpmem_themsg = ( ! is_email( $this->post_data['user_email']) ) ? $wpmem->get_text( 'reg_valid_email' ) : $wpmem_themsg;
333
- $wpmem_themsg = ( ! validate_username( $this->post_data['username'] ) ) ? $wpmem->get_text( 'reg_non_alphanumeric' ) : $wpmem_themsg;
334
- $wpmem_themsg = ( ! $this->post_data['username'] ) ? $wpmem->get_text( 'reg_empty_username' ) : $wpmem_themsg;
335
-
336
- // If there is an error from username, email, or required field validation, stop registration and return the error.
337
- if ( $wpmem_themsg ) {
338
- return $wpmem_themsg;
339
- exit();
340
- }
341
- }
342
-
343
- // If form contains password and email confirmation, validate that they match.
344
- if ( array_key_exists( 'confirm_password', $this->post_data ) && $this->post_data['confirm_password'] != $this->post_data ['password'] ) {
345
- $wpmem_themsg = $wpmem->get_text( 'reg_password_match' );
346
- }
347
- if ( array_key_exists( 'confirm_email', $this->post_data ) && $this->post_data['confirm_email'] != $this->post_data ['user_email'] ) {
348
- $wpmem_themsg = $wpmem->get_text( 'reg_email_match' );
349
- }
350
-
351
- // Process CAPTCHA.
352
- if ( 0 != $wpmem->captcha ) {
353
- $check_captcha = WP_Members_Captcha::validate();
354
- if ( false === $check_captcha ) {
355
- return "empty"; // @todo Return and/or set error object. For now changed to return original value.
356
- }
357
- }
358
-
359
- // Check for user defined password.
360
- $this->post_data['password'] = wpmem_get( 'password', wp_generate_password() );
361
-
362
- // Add for _data hooks
363
- $this->post_data['user_registered'] = current_time( 'mysql', 1 );
364
- $this->post_data['user_role'] = get_option( 'default_role' );
365
- $this->post_data['wpmem_reg_ip'] = wpmem_get_user_ip();
366
- $this->post_data['wpmem_reg_url'] = esc_url_raw( wpmem_get( 'wpmem_reg_page', wpmem_get( 'redirect_to', false, 'request' ), 'request' ) );
367
-
368
- /*
369
- * These native fields are not installed by default, but if they
370
- * are added, use the $_POST value - otherwise, default to username.
371
- * Value can be filtered with wpmem_register_data.
372
- */
373
- foreach( array( 'user_nicename', 'display_name', 'nickname' ) as $user_names ) {
374
- $this->post_data[ $user_names ] = sanitize_text_field( wpmem_get( $user_names, $this->post_data['username'] ) );
375
- }
376
- }
377
- }
378
-
379
- /**
380
- * Validates registration fields in the native WP registration.
381
- *
382
- * @since 2.8.3
383
- * @since 3.3.0 Ported from wpmem_wp_reg_validate() in wp-registration.php.
384
- *
385
- * @global object $wpmem The WP-Members object class.
386
- *
387
- * @param array $errors A WP_Error object containing any errors encountered during registration.
388
- * @param string $sanitized_user_login User's username after it has been sanitized.
389
- * @param string $user_email User's email.
390
- * @return array $errors A WP_Error object containing any errors encountered during registration.
391
- */
392
- function wp_register_validate( $errors, $sanitized_user_login, $user_email ) {
393
-
394
- global $wpmem;
395
-
396
- // Get any meta fields that should be excluded.
397
- $exclude = wpmem_get_excluded_meta( 'wp-register' );
398
-
399
- foreach ( wpmem_fields( 'register_wp' ) as $meta_key => $field ) {
400
- $is_error = false;
401
- if ( true == $field['required'] && true == $field['register'] && $meta_key != 'user_email' && ! in_array( $meta_key, $exclude ) ) {
402
- if ( ( $field['type'] == 'checkbox' || $field['type'] == 'multicheckbox' || $field['type'] == 'multiselect' || $field['type'] == 'radio' ) && ( ! isset( $_POST[ $meta_key ] ) ) ) {
403
- $is_error = true;
404
- }
405
- if ( ( $field['type'] != 'checkbox' && $field['type'] != 'multicheckbox' && $field['type'] != 'multiselect' && $field['type'] != 'radio' ) && ( ! $_POST[ $meta_key ] ) ) {
406
- $is_error = true;
407
- }
408
- if ( $is_error ) {
409
- $errors->add( 'wpmem_error', sprintf( $wpmem->get_text( 'reg_empty_field' ), __( $field['label'], 'wp-members' ) ) );
410
- }
411
- }
412
- }
413
-
414
- // Process CAPTCHA.
415
- if ( $wpmem->captcha > 0 ) {
416
- $check_captcha = WP_Members_Captcha::validate();
417
- if ( false === $check_captcha ) {
418
- $errors->add( 'wpmem_captcha_error', sprintf( $wpmem->get_text( 'reg_captcha_err' ), __( $field['label'], 'wp-members' ) ) );
419
- }
420
- }
421
-
422
- return $errors;
423
- }
424
-
425
- /**
426
- * User registration functions.
427
- *
428
- * @since 3.1.7
429
- * @since 3.2.6 Added handler for membership field type.
430
- * @since 3.3.0 Changed from register() to register_finalize().
431
- *
432
- * @global object $wpmem
433
- * @param int $user_id
434
- */
435
- function register_finalize( $user_id ) {
436
-
437
- global $wpmem;
438
-
439
- // If this is WP-Members registration.
440
- if ( $this->reg_type['is_wpmem'] ) {
441
- // Put user ID into post_data array.
442
- $this->post_data['ID'] = $user_id;
443
-
444
- // Set remaining fields to wp_usermeta table.
445
- $new_user_fields_meta = array( 'user_url', 'first_name', 'last_name', 'description', 'jabber', 'aim', 'yim' );
446
- foreach ( $wpmem->fields as $meta_key => $field ) {
447
- // If the field is not excluded, update accordingly.
448
- if ( ! in_array( $meta_key, wpmem_get_excluded_meta( 'register' ) ) && ! in_array( $meta_key, $new_user_fields_meta ) ) {
449
- if ( $field['register'] && 'user_email' != $meta_key ) {
450
- // Assign memberships, if applicable.
451
- if ( 'membership' == $field['type'] && 1 == $wpmem->enable_products ) {
452
- wpmem_set_user_product( $this->post_data[ $meta_key ], $user_id );
453
- } else {
454
- update_user_meta( $user_id, $meta_key, $this->post_data[ $meta_key ] );
455
- }
456
- }
457
- }
458
- }
459
-
460
- // Store the registration url.
461
- update_user_meta( $user_id, 'wpmem_reg_url', $this->post_data['wpmem_reg_url'] );
462
-
463
- // Handle file uploads, if any.
464
- if ( ! empty( $_FILES ) ) {
465
- $this->upload_user_files( $user_id, $wpmem->fields );
466
- }
467
- }
468
-
469
- // If this is native WP (wp-login.php), Users > Add New, or WooCommerce registration.
470
- if ( $this->reg_type['is_native'] || $this->reg_type['is_add_new'] || $this->reg_type['is_woo'] ) {
471
- // Get any excluded meta fields.
472
- $exclude = wpmem_get_excluded_meta( 'wp-register' );
473
- foreach ( wpmem_fields( 'register_wp' ) as $meta_key => $field ) {
474
- $value = wpmem_get( $meta_key, false );
475
- if ( false !== $value && ! in_array( $meta_key, $exclude ) && 'file' != $field['type'] && 'image' != $field['type'] ) {
476
- if ( 'multiselect' == $field['type'] || 'multicheckbox' == $field['type'] ) {
477
- $value = implode( $field['delimiter'], $value );
478
- }
479
- $sanitized_value = sanitize_text_field( $value );
480
- update_user_meta( $user_id, $meta_key, $sanitized_value );
481
- }
482
- }
483
- }
484
-
485
- // If this is Users > Add New.
486
- if ( is_admin() && $this->reg_type['is_add_new'] ) {
487
- // If moderated registration and activate is checked, set active flags.
488
- if ( 1 == $wpmem->mod_reg && isset( $_POST['activate_user'] ) ) {
489
- update_user_meta( $user_id, 'active', 1 );
490
- wpmem_set_user_status( $user_id, 0 );
491
- }
492
- }
493
-
494
- // Capture IP address of all users at registration.
495
- $user_ip = ( $this->reg_type['is_wpmem'] ) ? $this->post_data['wpmem_reg_ip'] : wpmem_get_user_ip();
496
- update_user_meta( $user_id, 'wpmem_reg_ip', $user_ip );
497
-
498
- }
499
-
500
- /**
501
- * Fires wpmem_post_register_data action.
502
- *
503
- * @since 3.3.2
504
- *
505
- * @global stdClass $wpmem
506
- * @param int $user_id
507
- */
508
- function post_register_data( $user_id ) {
509
- global $wpmem;
510
- $wpmem->user->post_data['ID'] = $user_id;
511
- /**
512
- * Fires after user insertion but before email.
513
- *
514
- * @since 2.7.2
515
- * @since 3.3.2 Hooked to user_register.
516
- *
517
- * @param array $wpmem->user->post_data The user's submitted registration data.
518
- */
519
- do_action( 'wpmem_post_register_data', $wpmem->user->post_data );
520
- }
521
-
522
- /**
523
- * Sends emails on registration.
524
- *
525
- * @since 3.3.0
526
- *
527
- * @global object $wpmem
528
- *
529
- * @param int $user_id
530
- */
531
- function register_email_to_user( $user_id ) {
532
- global $wpmem;
533
- if ( $this->reg_type['is_wpmem'] ) {
534
- // @todo Work out a better method for this so that it is optional and can be turned on/off for native reg
535
- // Send a notification email to the user.
536
- wpmem_email_to_user( $user_id, $this->post_data['password'], $wpmem->mod_reg, $wpmem->fields, $this->post_data );
537
- }
538
- }
539
-
540
- /**
541
- * Sends admin notifiction on registration.
542
- *
543
- * @since 3.3.0
544
- *
545
- * @global object $wpmem
546
- *
547
- * @param int $user_id
548
- */
549
- function register_email_to_admin( $user_id ) {
550
- global $wpmem;
551
- if ( $this->reg_type['is_wpmem'] ) {
552
- // @todo Work out a better method for this so that it is optional and can be turned on/off for native reg
553
- // Notify admin of new reg, if needed.
554
- if ( 1 == $wpmem->notify ) {
555
- $wpmem->email->notify_admin( $user_id, $wpmem->fields, $this->post_data );
556
- }
557
- }
558
- }
559
-
560
- /**
561
- * Redirects user on registration.
562
- *
563
- * @since 3.1.7
564
- */
565
- function register_redirect() {
566
- $redirect_to = wpmem_get( 'redirect_to', false );
567
- if ( $redirect_to ) {
568
- $nonce_url = wp_nonce_url( $redirect_to, 'register_redirect', 'reg_nonce' );
569
- wp_safe_redirect( $nonce_url );
570
- exit();
571
- }
572
- }
573
-
574
- /**
575
- * Password change or reset.
576
- *
577
- * @since 3.1.7
578
- *
579
- * @param string $action
580
- * @return string $result
581
- */
582
- function password_update( $action ) {
583
- if ( isset( $_POST['formsubmit'] ) ) {
584
- if ( 'reset' == $action ) {
585
- $args = array(
586
- 'user' => sanitize_user( wpmem_get( 'user', false ) ),
587
- 'email' => sanitize_email( wpmem_get( 'email', false ) ),
588
- );
589
- } else {
590
- $args = array(
591
- 'pass1' => wpmem_get( 'pass1', false ),
592
- 'pass2' => wpmem_get( 'pass2', false ),
593
- );
594
- }
595
- return ( 'reset' == $action ) ? $this->password_reset( $args ) : $this->password_change( $args );
596
- }
597
- return;
598
- }
599
-
600
- /**
601
- * Change a user's password()
602
- *
603
- * @since 3.1.7
604
- *
605
- * @return
606
- */
607
- function password_change( $args ) {
608
- global $user_ID;
609
- $is_error = false;
610
- // Check for both fields being empty.
611
- $is_error = ( ! $args['pass1'] && ! $args['pass2'] ) ? "pwdchangempty" : $is_error;
612
- // Make sure the fields match.
613
- $is_error = ( $args['pass1'] != $args['pass2'] ) ? "pwdchangerr" : $is_error;
614
- /**
615
- * Filters the password change error.
616
- *
617
- * @since 3.1.5
618
- * @since 3.1.7 Moved to user object.
619
- *
620
- * @param string $is_error
621
- * @param int $user_ID The user's numeric ID.
622
- * @param string $args['pass1'] The user's new plain text password.
623
- */
624
- $is_error = apply_filters( 'wpmem_pwd_change_error', $is_error, $user_ID, $args['pass1'] );
625
- // User must be logged in.
626
- $is_error = ( ! is_user_logged_in() ) ? "loggedin" : $is_error;
627
- // Verify nonce.
628
- $is_error = ( ! wp_verify_nonce( $_REQUEST['_wpmem_pwdchange_nonce'], 'wpmem_shortform_nonce' ) ) ? "reg_generic" : $is_error;
629
- if ( $is_error ) {
630
- return $is_error;
631
- }
632
- /**
633
- * Fires after password change.
634
- *
635
- * @since 2.9.0
636
- * @since 3.0.5 Added $args['pass1'] to arguments passed.
637
- * @since 3.1.7 Moved to user object.
638
- *
639
- * @param int $user_ID The user's numeric ID.
640
- * @param string $args['pass1'] The user's new plain text password.
641
- */
642
- do_action( 'wpmem_pwd_change', $user_ID, $args['pass1'] );
643
- return "pwdchangesuccess";
644
- }
645
-
646
- /**
647
- * Reset a user's password.
648
- *
649
- * @since 3.1.7
650
- *
651
- */
652
- function password_reset( $args ) {
653
- global $wpmem;
654
- /**
655
- * Filter the password reset arguments.
656
- *
657
- * @since 2.7.1
658
- * @since 3.1.7 Moved to user object.
659
- *
660
- * @param array The username and email.
661
- */
662
- $arr = apply_filters( 'wpmem_pwdreset_args', $args );
663
- if ( ! $arr['user'] || ! $arr['email'] ) {
664
- // There was an empty field.
665
- return "pwdreseterr";
666
-
667
- } else {
668
-
669
- if ( ! wp_verify_nonce( $_REQUEST['_wpmem_pwdreset_nonce'], 'wpmem_shortform_nonce' ) ) {
670
- return "reg_generic";
671
- }
672
- if ( username_exists( $arr['user'] ) ) {
673
- $user = get_user_by( 'login', $arr['user'] );
674
- if ( strtolower( $user->user_email ) !== strtolower( $arr['email'] ) || ( ( $wpmem->mod_reg == 1 ) && ( get_user_meta( $user->ID, 'active', true ) != 1 ) ) ) {
675
- // The username was there, but the email did not match OR the user hasn't been activated.
676
- return "pwdreseterr";
677
- } else {
678
- // Generate a new password.
679
- $new_pass = wp_generate_password();
680
- // Update the users password.
681
- wp_set_password( $new_pass, $user->ID );
682
- // Send it in an email.
683
- wpmem_email_to_user( $user->ID, $new_pass, 3 );
684
- /**
685
- * Fires after password reset.
686
- *
687
- * @since 2.9.0
688
- * @since 3.0.5 Added $new_pass to arguments passed.
689
- * @since 3.1.7 Moved to user object.
690
- *
691
- * @param int $user_ID The user's numeric ID.
692
- * @param string $new_pass The new plain text password.
693
- */
694
- do_action( 'wpmem_pwd_reset', $user->ID, $new_pass );
695
- return "pwdresetsuccess";
696
- }
697
- } else {
698
- // Username did not exist.
699
- return "pwdreseterr";
700
- }
701
- }
702
- return;
703
- }
704
-
705
- /**
706
- * Handles retrieving a forgotten username.
707
- *
708
- * @since 3.0.8
709
- * @since 3.1.6 Dependencies now loaded by object.
710
- * @since 3.1.8 Moved to user object.
711
- *
712
- * @global object $wpmem
713
- * @return string $regchk The regchk value.
714
- */
715
- function retrieve_username() {
716
- global $wpmem;
717
- if ( isset( $_POST['formsubmit'] ) ) {
718
-
719
- if ( ! wp_verify_nonce( $_REQUEST['_wpmem_getusername_nonce'], 'wpmem_shortform_nonce' ) ) {
720
- return "reg_generic";
721
- }
722
-
723
- $email = sanitize_email( $_POST['user_email'] );
724
- $user = ( isset( $_POST['user_email'] ) ) ? get_user_by( 'email', $email ) : false;
725
- if ( $user ) {
726
- // Send it in an email.
727
- wpmem_email_to_user( $user->ID, '', 4 );
728
- /**
729
- * Fires after retrieving username.
730
- *
731
- * @since 3.0.8
732
- *
733
- * @param int $user_ID The user's numeric ID.
734
- */
735
- do_action( 'wpmem_get_username', $user->ID );
736
- return 'usernamesuccess';
737
- } else {
738
- return 'usernamefailed';
739
- }
740
- }
741
- return;
742
- }
743
-
744
- /**
745
- * Handle user file uploads for registration and profile update.
746
- *
747
- * @since 3.1.8
748
- * @since 3.2.6 Add file's post ID to $this->post_data.
749
- *
750
- * @param string $user_id
751
- * @param array $fields
752
- */
753
- function upload_user_files( $user_id, $fields ) {
754
- global $wpmem;
755
- foreach ( $fields as $meta_key => $field ) {
756
- if ( ( 'file' == $field['type'] || 'image' == $field['type'] ) && isset( $_FILES[ $meta_key ] ) && is_array( $_FILES[ $meta_key ] ) ) {
757
- if ( ! empty( $_FILES[ $meta_key ]['name'] ) ) {
758
- // Upload the file and save it as an attachment.
759
- $file_post_id = $wpmem->forms->do_file_upload( $_FILES[ $meta_key ], $user_id );
760
- // Save the attachment ID as user meta.
761
- update_user_meta( $user_id, $meta_key, $file_post_id );
762
- // Add attachement ID to post data array.
763
- $this->post_data[ $meta_key ] = $file_post_id;
764
- }
765
- }
766
- }
767
- }
768
-
769
- /**
770
- * Get user data for all fields in WP-Members.
771
- *
772
- * Retrieves user data for all WP-Members fields (and WP default fields)
773
- * in an array keyed by WP-Members field meta keys.
774
- *
775
- * @since 3.2.0
776
- * @since 3.2.6 Added option for "all" fields (default:false).
777
- *
778
- * @param string $user_id optional (defaults to current user)
779
- * @param string $all optional (default to false)
780
- * @return array $user_fields
781
- */
782
- function user_data( $user_id = false, $all = false ) {
783
- $user_id = ( $user_id ) ? $user_id : get_current_user_id();
784
- if ( true == $all ) {
785
- $user_info = get_user_meta( $user_id );
786
- foreach( $user_info as $key => $value ) {
787
- $formatted = maybe_unserialize( $value[0] );
788
- $user_fields[ $key ] = $formatted;
789
- }
790
- } else {
791
- $fields = wpmem_fields();
792
- $user_data = get_userdata( $user_id );
793
- $excludes = array( 'first_name', 'last_name', 'description', 'nickname' );
794
- foreach ( $fields as $meta => $field ) {
795
- $meta = ( 'username' == $meta ) ? 'user_login' : $meta;
796
- if ( $field['native'] == 1 && ! in_array( $meta, $excludes ) ) {
797
- $user_fields[ $meta ] = $user_data->data->{$meta};
798
- } else {
799
- $user_fields[ $meta ] = get_user_meta( $user_id, $meta, true );
800
- }
801
- }
802
- }
803
- return $user_fields;
804
- }
805
-
806
- /**
807
- * Sets the role for the specified user.
808
- *
809
- * @since 3.2.0
810
- *
811
- * @param integer $user_id
812
- * @param string $role
813
- * @param string $action (set|add|remove)
814
- */
815
- public function update_user_role( $user_id, $role, $action = 'set' ) {
816
- $user = new WP_User( $user_id );
817
- switch ( $action ) {
818
- case 'add':
819
- $user->add_role( $role );
820
- break;
821
- case 'remove':
822
- $user->remove_role( $role );
823
- break;
824
- default:
825
- $user->set_role( $role );
826
- break;
827
- }
828
- }
829
-
830
- /**
831
- * Sets a user's password.
832
- *
833
- * @since 3.2.3
834
- *
835
- * @param int $user_id
836
- * @param string $password
837
- */
838
- function set_password( $user_id, $password ) {
839
- wp_set_password( $password, $user_id );
840
- }
841
-
842
- /**
843
- * Sets user as logged on password change.
844
- *
845
- * (Hooked to wpmem_pwd_change)
846
- *
847
- * @since 3.2.0
848
- *
849
- * @param int $user_id
850
- * @param string $password
851
- */
852
- function set_as_logged_in( $user_id ) {
853
- $user = get_user_by( 'id', $user_id );
854
- wp_set_current_user( $user_id, $user->user_login );
855
- wp_set_auth_cookie( $user_id );
856
- }
857
-
858
- /**
859
- * Validates user access to content.
860
- *
861
- * @since 3.2.0
862
- * @todo Currently checks in this order: expiration, role, "other". If expiration product,
863
- * and the user is current, then access is granted. This doesn't consider if the
864
- * user is current but does not have a required role (if BOTH an expiration and role
865
- * product). Maybe add role checking to the expiration block if both exist.
866
- *
867
- * @global object $wpmem
868
- * @param mixed $product
869
- * @param int $user_id (optional)
870
- * @return bool $access
871
- */
872
- function has_access( $product, $user_id = false ) {
873
- global $wpmem;
874
- if ( false === $user_id && ! is_user_logged_in() ) {
875
- return false;
876
- }
877
-
878
- // Product must be an array.
879
- $product_array = ( ! is_array( $product ) ) ? array( $product ) : $product;
880
-
881
- // Load user memberships array.
882
- $memberships = ( false == $user_id ) ? $this->access : wpmem_get_user_products( $user_id );
883
-
884
- // Current user or requested user.
885
- $user_id = ( ! $user_id ) ? get_current_user_id() : $user_id;
886
-
887
- // Start by assuming no access.
888
- $access = false;
889
-
890
- foreach ( $product_array as $prod ) {
891
- $expiration_product = false;
892
- $role_product = false;
893
- if ( isset( $memberships[ $prod ] ) ) {
894
- // Is this an expiration product?
895
- if ( isset( $wpmem->membership->products[ $prod ]['expires'][0] ) && ! is_bool( $memberships[ $prod ] ) ) {
896
- $expiration_product = true;
897
- if ( $this->is_current( $memberships[ $prod ] ) ) {
898
- $access = true;
899
- break;
900
- }
901
- }
902
- // Is this a role product?
903
- if ( '' != $wpmem->membership->products[ $prod ]['role'] ) {
904
- $role_product = true;
905
- if ( $memberships[ $prod ] && wpmem_user_has_role( $wpmem->membership->products[ $prod ]['role'] ) ) {
906
- if ( $expiration_product && ! $this->is_current( $memberships[ $prod ] ) ) {
907
- $access = false;
908
- break;
909
- }
910
- $access = true;
911
- break;
912
- }
913
- }
914
- if ( ! $expiration_product && ! $role_product && $memberships[ $prod ] ) {
915
- $access = true;
916
- break;
917
- }
918
- }
919
- }
920
-
921
- /**
922
- * Filter the access result.
923
- *
924
- * @since 3.2.0
925
- * @since 3.2.3 Added $product argument.
926
- *
927
- * @param boolean $access
928
- * @param array $product
929
- * @param integer $user_id
930
- * @param array $args
931
- */
932
- return apply_filters( 'wpmem_user_has_access', $access, $product_array, $user_id );
933
-
934
- }
935
-
936
- /**
937
- * Loads anything the user has access to.
938
- *
939
- * @since 3.2.0
940
- * @since 3.2.6 Updated to return empty array if no products exist for this user.
941
- * @since 3.3.0 Updated to use individual meta for product access.
942
- *
943
- * @global object $wpmem
944
- *
945
- * @param int $user_id
946
- * @return array $products
947
- */
948
- function get_user_products( $user_id = false, $obj = false ) {
949
- global $wpmem;
950
- $product_array = ( $obj ) ? $obj->membership->products : $wpmem->membership->products;
951
- $user_id = ( ! $user_id ) ? get_current_user_id() : $user_id;
952
- foreach ( $product_array as $product_meta => $product ) {
953
- $user_product = get_user_meta( $user_id, '_wpmem_products_' . $product_meta, true );
954
- if ( $user_product ) {
955
- $products[ $product_meta ] = $user_product;
956
- }
957
- $user_product = '';
958
- }
959
- return ( isset( $products ) ) ? $products : array();
960
- }
961
-
962
- /**
963
- * Sets a product as active for a user.
964
- *
965
- * If the product expires, it sets an expiration date
966
- * based on the time period. Otherwise the value is
967
- * set to "true" (which does not expire).
968
- *
969
- * @since 3.2.0
970
- * @since 3.2.6 Added $date to set a specific expiration date.
971
- * @since 3.3.0 Updated to new single meta, keeps legacy array for rollback.
972
- * @since 3.3.1 Added no gap renewal option, @todo Needs some possible condensing.
973
- *
974
- * @param string $product
975
- * @param int $user_id
976
- * @param string $set_date Formatted date should be MySQL timestamp, or simply YYYY-MM-DD.
977
- */
978
- function set_user_product( $product, $user_id = false, $set_date = false ) {
979
-
980
- global $wpmem;
981
-
982
- $user_id = ( ! $user_id ) ? get_current_user_id() : $user_id;
983
-
984
- // New single meta format. @todo This remains when legacy array is removed.
985
- $prev_value = get_user_meta( $user_id, '_wpmem_products_' . $product, true );
986
-
987
- // Convert date to add.
988
- $expiration_period = ( isset( $wpmem->membership->products[ $product ]['expires'] ) ) ? $wpmem->membership->products[ $product ]['expires'] : false;
989
-
990
- $renew = ( $prev_value ) ? true : false;
991
-
992
- // If membership is an expiration product.
993
- if ( is_array( $expiration_period ) ) {
994
- $new_value = $wpmem->membership->set_product_expiration( $product, $user_id, $set_date, $prev_value, $renew );
995
- } else {
996
- $new_value = true;
997
- }
998
-
999
- // Update product setting.
1000
- update_user_meta( $user_id, '_wpmem_products_' . $product, $new_value );
1001
-
1002
- // Update the legacy setting.
1003
- $user_products = get_user_meta( $user_id, '_wpmem_products', true );
1004
- $user_products = ( $user_products ) ? $user_products : array();
1005
- $user_products[ $product ] = ( true === $new_value ) ? true : date( 'Y-m-d H:i:s', $new_value );
1006
- update_user_meta( $user_id, '_wpmem_products', $user_products );
1007
-
1008
- /**
1009
- * Fires when a user product has been set.
1010
- *
1011
- * @since 3.3.0
1012
- *
1013
- * @param int $user_id
1014
- * @param string $product
1015
- */
1016
- do_action( 'wpmem_user_product_set', $user_id, $product, $new_value, $prev_value, $renew );
1017
-
1018
- }
1019
-
1020
- /**
1021
- * Removes a product from a user.
1022
- *
1023
- * @since 3.2.0
1024
- * @since 3.3.0 Updated for new single meta, keeps legacy array for rollback.
1025
- *
1026
- * @param string $product
1027
- * @param int $user_id
1028
- */
1029
- function remove_user_product( $product, $user_id = false ) {
1030
- global $wpmem;
1031
- $user_id = ( ! $user_id ) ? get_current_user_id() : $user_id;
1032
-
1033
- // @todo Legacy version.
1034
- $user_products = get_user_meta( $user_id, '_wpmem_products', true );
1035
- $user_products = ( $user_products ) ? $user_products : array();
1036
- if ( $user_products ) {
1037
- unset( $user_products[ $product ] );
1038
- update_user_meta( $user_id, '_wpmem_products', $user_products );
1039
- }
1040
-
1041
- // @todo New version.
1042
- return delete_user_meta( $user_id, '_wpmem_products_' . $product );
1043
- }
1044
-
1045
- /**
1046
- * Utility for expiration validation.
1047
- *
1048
- * @since 3.2.0
1049
- * @since 3.3.0 Validates date or epoch time.
1050
- *
1051
- * @param date $date
1052
- */
1053
- function is_current( $date ) {
1054
- $date = ( is_numeric( $date ) ) ? $date : strtotime( $date );
1055
- return ( time() < $date ) ? true : false;
1056
- }
1057
-
1058
- /**
1059
- * Check if a user is activated.
1060
- *
1061
- * @since 3.2.2
1062
- *
1063
- * @param int $user_id
1064
- * @return bool $active
1065
- */
1066
- function is_user_activated( $user_id = false ) {
1067
- $user_id = ( ! $user_id ) ? get_current_user_id() : $user_id;
1068
- $active = get_user_meta( $user_id, 'active', true );
1069
- $is_activated = ( 1 == $active ) ? true : false;
1070
- /**
1071
- * Filter whether the user is active or not.
1072
- *
1073
- * @since 3.3.5
1074
- *
1075
- * @param bool $is_activated
1076
- * @param int $user_id
1077
- */
1078
- return apply_filters( 'wpmem_is_user_activated', $is_activated, $user_id );
1079
- }
1080
-
1081
- /**
1082
- * Checks if a user is activated during user authentication.
1083
- *
1084
- * @since 2.7.1
1085
- * @since 3.2.0 Moved from core to user object.
1086
- *
1087
- * @param object $user The WordPress User object.
1088
- * @param string $username The user's username (user_login).
1089
- * @param string $password The user's password.
1090
- * @return object $user The WordPress User object.
1091
- */
1092
- function check_activated( $user, $username, $password ) {
1093
- // Password must be validated.
1094
- $pass = ( ( ! is_wp_error( $user ) ) && $password ) ? wp_check_password( $password, $user->user_pass, $user->ID ) : false;
1095
-
1096
- if ( ! $pass ) {
1097
- return $user;
1098
- }
1099
-
1100
- // Activation flag must be validated.
1101
- if ( ! $this->is_user_activated( $user->ID ) ) {
1102
- return new WP_Error( 'authentication_failed', __( '<strong>ERROR</strong>: User has not been activated.', 'wp-members' ) );
1103
- }
1104
-
1105
- // If the user is validated, return the $user object.
1106
- return $user;
1107
- }
1108
-
1109
- /**
1110
- * Prevents users not activated from resetting their password.
1111
- *
1112
- * @since 2.5.1
1113
- * @since 3.2.0 Moved to user object, renamed no_reset().
1114
- *
1115
- * @return bool Returns false if the user is not activated, otherwise true.
1116
- */
1117
- function no_reset() {
1118
- global $wpmem;
1119
- $raw_val = wpmem_get( 'user_login', false );
1120
- if ( $raw_val ) {
1121
- if ( strpos( $raw_val, '@' ) ) {
1122
- $user = get_user_by( 'email', sanitize_email( $raw_val ) );
1123
- } else {
1124
- $username = sanitize_user( $raw_val );
1125
- $user = get_user_by( 'login', $username );
1126
- }
1127
- if ( $wpmem->mod_reg == 1 ) {
1128
- if ( get_user_meta( $user->ID, 'active', true ) != 1 ) {
1129
- return false;
1130
- }
1131
- }
1132
- }
1133
-
1134
- return true;
1135
- }
1136
-
1137
- /**
1138
- * Set expiration for PayPal Subscriptions extension.
1139
- *
1140
- * @since 3.3.0
1141
- *
1142
- * @global object $wpmem
1143
- *
1144
- * @param int $user_id
1145
- */
1146
- function set_user_exp( $user_id ) {
1147
- global $wpmem;
1148
- // Set user expiration, if used.
1149
- if ( 1 == $wpmem->use_exp && 1 != $wpmem->mod_reg ) {
1150
- if ( function_exists( 'wpmem_set_exp' ) ) {
1151
- wpmem_set_exp( $user_id );
1152
- }
1153
- }
1154
- }
1155
-
1156
- /**
1157
- * Sets default membership product access (if applicable).
1158
- *
1159
- * @since 3.3.0
1160
- *
1161
- * @global object $wpmem
1162
- *
1163
- * @param int $user_id
1164
- */
1165
- function set_default_product( $user_id ) {
1166
- global $wpmem;
1167
-
1168
- // Get default memberships.
1169
- $default_products = $wpmem->membership->get_default_products();
1170
-
1171
- // Assign any default memberships to user.
1172
- foreach ( $default_products as $product ) {
1173
- wpmem_set_user_product( $product, $user_id );
1174
- }
1175
- }
1176
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1177
  }
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_User {
19
+
20
+ /**
21
+ * Container for reg form data.
22
+ *
23
+ * @since 3.1.7
24
+ * @access public
25
+ * @var array
26
+ */
27
+ public $post_data = array();
28
+
29
+ /**
30
+ * Container for user access information.
31
+ *
32
+ * @since 3.2.0
33
+ * @access public
34
+ * @var array
35
+ */
36
+ public $access = array();
37
+
38
+ /**
39
+ * Initilize the User object.
40
+ *
41
+ * @since 3.1.7
42
+ *
43
+ * @param object $settings The WP_Members Object
44
+ */
45
+ function __construct( $settings ) {
46
+
47
+ add_action( 'wpmem_after_init', array( $this, 'load_user_products' ) );
48
+
49
+ add_action( 'user_register', array( $this, 'set_reg_type' ), 1 );
50
+ add_action( 'user_register', array( $this, 'register_finalize' ), 5 );
51
+ 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.
52
+ add_action( 'user_register', array( $this, 'set_user_exp' ), 25 );
53
+ add_action( 'user_register', array( $this, 'register_email_to_user' ), 25 );
54
+ add_action( 'user_register', array( $this, 'register_email_to_admin' ), 25 );
55
+
56
+ add_action( 'wpmem_register_redirect', array( $this, 'register_redirect' ), 20 ); // Adds a nonce to the redirect if there is a "redirect_to" attribute in the reg form.
57
+
58
+ add_filter( 'registration_errors', array( $this, 'wp_register_validate' ), 10, 3 ); // native registration validation
59
+
60
+ // Load anything the user as access to.
61
+ if ( 1 == $settings->enable_products ) {
62
+ add_action( 'user_register', array( $this, 'set_default_product' ), 6 );
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Loads the current user's membership products on init.
68
+ *
69
+ * @since 3.4.0
70
+ */
71
+ function load_user_products() {
72
+ if ( is_user_logged_in() ) {
73
+ $this->access = wpmem_get_user_products( get_current_user_id() );
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Handle user login.
79
+ *
80
+ * Built from, but replaces, the original wpmem_login() function
81
+ * from core.php. wpmem_login() is currently maintained as a
82
+ * wrapper and is the direct function called for login.
83
+ *
84
+ * @since 3.1.7
85
+ * @since 3.2.3 Removed wpmem_login_fields filter.
86
+ * @since 3.2.3 Replaced form collection with WP script to facilitate login with username OR email.
87
+ * @since 3.2.3 Changed to wp_safe_redirect().
88
+ * @since 3.3.9 Added wpmem_set_as_logged_in() to make sure user is set.
89
+ *
90
+ * @return string Returns "loginfailed" if failed login.
91
+ */
92
+ function login() {
93
+
94
+ global $wpmem;
95
+
96
+ $user = wp_signon( array(), is_ssl() );
97
+
98
+ if ( is_wp_error( $user ) ) {
99
+ $wpmem->error = $user->get_error_message();
100
+ return "loginfailed";
101
+ } else {
102
+
103
+ // Make sure current user is set.
104
+ wpmem_set_as_logged_in( $user->ID );
105
+
106
+ $redirect_to = wpmem_get( 'redirect_to', false );
107
+ $redirect_to = ( $redirect_to ) ? esc_url_raw( trim( $redirect_to ) ) : esc_url_raw( wpmem_current_url() );
108
+ /** This filter defined in wp-login.php */
109
+ $redirect_to = apply_filters( 'login_redirect', $redirect_to, '', $user );
110
+ /**
111
+ * Filter the redirect url.
112
+ *
113
+ * This is the plugin's original redirect filter. In 3.1.7,
114
+ * WP's login_redirect filter hook was added to provide better
115
+ * integration support for other plugins and also for users
116
+ * who may already be using WP's filter(s). login_redirect
117
+ * comes first, then wpmem_login_redirect. So wpmem_login_redirect
118
+ * can be used to override a default in login_redirect.
119
+ *
120
+ * @since 2.7.7
121
+ * @since 2.9.2 Added $user_id
122
+ *
123
+ * @param string $redirect_to The url to direct to.
124
+ * @param int $user->ID The user's primary key ID.
125
+ */
126
+ $redirect_to = apply_filters( 'wpmem_login_redirect', $redirect_to, $user->ID );
127
+ wp_safe_redirect( $redirect_to );
128
+ exit();
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Handle user logout.
134
+ *
135
+ * Built from, but replaces, the original wpmem_logout() function
136
+ * from core.php. wpmem_logout() is currently maintained as a
137
+ * wrapper and is the direct function called for logout.
138
+ *
139
+ * @since 3.1.7
140
+ * @since 3.2.0 Added logout_redirect filter
141
+ * @since 3.4.0 Added $user_id for wp_logout action (to match WP, which added this in 5.5.0).
142
+ *
143
+ * @param string $redirect_to URL to redirect the user to (default: false).
144
+ */
145
+ function logout( $redirect_to = false ) {
146
+
147
+ // Get the user ID for when the action is fired.
148
+ $user_id = get_current_user_id();
149
+
150
+ // Default redirect URL.
151
+ $redirect_to = ( $redirect_to ) ? $redirect_to : home_url();
152
+
153
+ /** This filter is documented in /wp-login.php */
154
+ $redirect_to = apply_filters( 'logout_redirect', $redirect_to, $redirect_to, wp_get_current_user() );
155
+ /**
156
+ * Filter where the user goes when logged out.
157
+ *
158
+ * @since 2.7.1
159
+ * @since 3.1.7 Moved to WP_Members_Users Class.
160
+ * @since 3.4.0 Added $user_id param.
161
+ *
162
+ * @param string The blog home page.
163
+ */
164
+ $redirect_to = apply_filters( 'wpmem_logout_redirect', $redirect_to, $user_id );
165
+
166
+ wp_destroy_current_session();
167
+ wp_clear_auth_cookie();
168
+ wp_set_current_user( 0 );
169
+
170
+ /** This action is defined in /wp-includes/pluggable.php. */
171
+ do_action( 'wp_logout', $user_id );
172
+
173
+ wp_safe_redirect( $redirect_to );
174
+ exit();
175
+ }
176
+
177
+ /**
178
+ * Sets the registration type.
179
+ *
180
+ * @since 3.3.0
181
+ */
182
+ function set_reg_type() {
183
+ // Is this a WP-Members registration?
184
+ $this->reg_type['is_wpmem'] = ( 'register' == wpmem_get( 'a' ) ) ? true : false;
185
+ // Is this WP's native registration? Checks the native submit button.
186
+ $this->reg_type['is_native'] = ( __( 'Register' ) == wpmem_get( 'wp-submit' ) ) ? true : false;
187
+ // Is this a Users > Add New process? Checks the post action.
188
+ $this->reg_type['is_add_new'] = ( 'createuser' == wpmem_get( 'action' ) ) ? true : false;
189
+ // Is this a WooCommerce my account registration? Checks for WC fields.
190
+ $this->reg_type['is_woo'] = ( wpmem_get( 'woocommerce-register-nonce' ) ) ? true : false;
191
+ // Is this a WooCommerce checkout?
192
+ $this->reg_type['is_woo_checkout'] = ( wpmem_get( 'woocommerce_checkout_place_order' ) ) ? true : false;
193
+ }
194
+
195
+ /**
196
+ * Validate user registration.
197
+ *
198
+ * @since 3.3.0
199
+ *
200
+ * @global int $user_ID
201
+ * @global string $wpmem_themsg
202
+ * @global array $userdata
203
+ *
204
+ * @param string $tag
205
+ */
206
+ function register_validate( $tag ) {
207
+
208
+ // Get the globals.
209
+ global $user_ID, $wpmem, $wpmem_themsg, $userdata;
210
+
211
+ // Check the nonce.
212
+ if ( empty( $_POST ) || ! wp_verify_nonce( $_REQUEST[ '_wpmem_' . $tag . '_nonce' ], 'wpmem_longform_nonce' ) ) {
213
+ $wpmem_themsg = wpmem_get_text( 'reg_generic' );
214
+ return;
215
+ }
216
+
217
+ // Make sure fields are loaded.
218
+ wpmem_fields( $tag );
219
+
220
+ // Is this a registration or a user profile update?
221
+ if ( 'register' == $tag ) {
222
+ $this->post_data['username'] = sanitize_user( wpmem_get( 'username' ) );
223
+ }
224
+
225
+ // Add the user email to the $this->post_data array for _data hooks.
226
+ if ( isset( $wpmem->fields['user_email'] ) ) {
227
+ $this->post_data['user_email'] = sanitize_email( wpmem_get( 'user_email' ) );
228
+ }
229
+
230
+ // If this is an update, and tos is a field, and the user has the correct saved value, remove tos.
231
+ if ( 'update' == $tag && isset( $wpmem->fields['tos'] ) ) {
232
+ if ( get_user_meta( $user_ID, 'tos', true ) == $wpmem->fields['tos']['checked_value'] ) {
233
+ unset( $wpmem->fields['tos'] );
234
+ }
235
+ }
236
+
237
+ // Build the $this->post_data array from $_POST data.
238
+ foreach ( $wpmem->fields as $meta_key => $field ) {
239
+ if ( ( 'register' == $tag && true == $field['register'] ) || ( 'update' == $tag && true == $field['profile'] ) ) {
240
+ if ( 'password' != $meta_key && 'confirm_password' != $meta_key && 'username' != $meta_key ) {
241
+ if ( isset( $_POST[ $meta_key ] ) ) {
242
+ switch ( $field['type'] ) {
243
+ case 'checkbox':
244
+ $this->post_data[ $meta_key ] = sanitize_text_field( $_POST[ $meta_key ] );
245
+ break;
246
+ case 'multiselect':
247
+ case 'multicheckbox':
248
+ $delimiter = ( isset( $field['delimiter'] ) ) ? $field['delimiter'] : '|';
249
+ $this->post_data[ $meta_key ] = ( isset( $_POST[ $meta_key ] ) ) ? implode( $delimiter, wpmem_sanitize_array( $_POST[ $meta_key ] ) ) : '';
250
+ break;
251
+ case 'textarea':
252
+ $this->post_data[ $meta_key ] = sanitize_textarea_field( $_POST[ $meta_key ] );
253
+ break;
254
+ default:
255
+ $this->post_data[ $meta_key ] = sanitize_text_field( $_POST[ $meta_key ] );
256
+ break;
257
+ }
258
+ } else {
259
+ $this->post_data[ $meta_key ] = '';
260
+ }
261
+ } else {
262
+ // We do have password as part of the registration form.
263
+ if ( isset( $_POST['password'] ) ) {
264
+ $this->post_data['password'] = $_POST['password'];
265
+ }
266
+ if ( isset( $_POST['confirm_password'] ) ) {
267
+ $this->post_data['confirm_password'] = $_POST['confirm_password'];
268
+ }
269
+ }
270
+ }
271
+ }
272
+
273
+ /**
274
+ * Filter the submitted form fields prior to validation.
275
+ *
276
+ * @since 2.8.2
277
+ * @since 3.1.7 Added $tag
278
+ * @since 3.2.0 Moved to regiser_validate() method in user object class.
279
+ *
280
+ * @param array $this->post_data An array of the posted form field data.
281
+ * @param string $tag
282
+ */
283
+ $this->post_data = apply_filters( 'wpmem_pre_validate_form', $this->post_data, $tag );
284
+
285
+ // Adds integration for custom error codes triggered by "register_post" or contained in "registration_errors"
286
+ // @todo This will move towards integrating all WP-Members registration errors into the "registration_errors" filter
287
+ // and allow for more standardized custom validation.
288
+ $errors = new WP_Error();
289
+ do_action( 'register_post', $sanitized_user_login, $user_email, $errors );
290
+ $errors = apply_filters( 'registration_errors', $errors, $this->post_data['username'], $this->post_data['user_email'] );
291
+ if ( count( $errors->get_error_messages() ) > 0 ) {
292
+ $wpmem_themsg = $errors->get_error_message();
293
+ return;
294
+ }
295
+
296
+ if ( 'update' == $tag ) {
297
+ $pass_arr = array( 'username', 'password', 'confirm_password', 'password_confirm' );
298
+ foreach ( $pass_arr as $pass ) {
299
+ unset( $wpmem->fields[ $pass ] );
300
+ }
301
+ }
302
+
303
+ // Check for required fields, reverse the array for logical error message order.
304
+ foreach ( array_reverse( $wpmem->fields ) as $meta_key => $field ) {
305
+ // Validation if the field is required.
306
+ if ( true == $field['required'] ) {
307
+ if ( 'file' == $field['type'] || 'image' == $field['type'] ) {
308
+ // If this is a new registration.
309
+ if ( 'register' == $tag ) {
310
+ // If the required field is a file type.
311
+ if ( empty( $_FILES[ $meta_key ]['name'] ) ) {
312
+ $wpmem_themsg = sprintf( wpmem_get_text( 'reg_empty_field' ), __( $field['label'], 'wp-members' ) );
313
+ }
314
+ }
315
+ } else {
316
+ // If the required field is any other field type.
317
+ if ( ( 'register' == $tag && true == $field['register'] ) || ( 'update' == $tag && true == $field['profile'] ) ) {
318
+ if ( null == $this->post_data[ $meta_key ] ) {
319
+ $wpmem_themsg = sprintf( wpmem_get_text( 'reg_empty_field' ), __( $field['label'], 'wp-members' ) );
320
+ }
321
+ }
322
+ }
323
+ }
324
+
325
+ // Validate file field type.
326
+ if ( 'file' == $field['type'] || 'image' == $field['type'] ) {
327
+ if ( '' == $field['file_types'] ) {
328
+ $field['file_types'] = ( 'image' == $field['type'] ) ? 'gif|png|jpg|jpeg|bmp' : 'doc|docx|pdf|zip';
329
+ }
330
+ $allowed_file_types = explode( '|', $field['file_types'] );
331
+ $msg_types = implode( ', ', $allowed_file_types );
332
+ if ( ! empty( $_FILES[ $meta_key ]['name'] ) ) {
333
+ $extension = pathinfo( $_FILES[ $meta_key ]['name'], PATHINFO_EXTENSION );
334
+ if ( ! in_array( $extension, $allowed_file_types ) ) {
335
+ $wpmem_themsg = sprintf( wpmem_get_text( 'reg_file_type' ), __( $field['label'], 'wp-members' ), str_replace( '|', ',', $msg_types ) );
336
+ }
337
+ }
338
+ }
339
+ }
340
+
341
+ if ( 'register' == $tag ) {
342
+ if ( is_multisite() ) {
343
+ // Multisite has different requirements.
344
+ $result = wpmu_validate_user_signup( $this->post_data['username'], $this->post_data['user_email'] );
345
+ $errors = $result['errors'];
346
+ if ( $errors->errors ) {
347
+ $wpmem_themsg = $errors->get_error_message();
348
+ return $wpmem_themsg;
349
+ exit();
350
+ }
351
+
352
+ } else {
353
+ // Validate username and email fields.
354
+ $wpmem_themsg = ( email_exists( $this->post_data['user_email'] ) ) ? "email" : $wpmem_themsg;
355
+ $wpmem_themsg = ( username_exists( $this->post_data['username'] ) ) ? "user" : $wpmem_themsg;
356
+ $wpmem_themsg = ( ! is_email( $this->post_data['user_email']) ) ? wpmem_get_text( 'reg_valid_email' ) : $wpmem_themsg;
357
+ $wpmem_themsg = ( ! validate_username( $this->post_data['username'] ) ) ? wpmem_get_text( 'reg_non_alphanumeric' ) : $wpmem_themsg;
358
+ $wpmem_themsg = ( ! $this->post_data['username'] ) ? wpmem_get_text( 'reg_empty_username' ) : $wpmem_themsg;
359
+
360
+ // If there is an error from username, email, or required field validation, stop registration and return the error.
361
+ if ( $wpmem_themsg ) {
362
+ return $wpmem_themsg;
363
+ exit();
364
+ }
365
+ }
366
+
367
+ // If form contains password and email confirmation, validate that they match.
368
+ if ( array_key_exists( 'confirm_password', $this->post_data ) && $this->post_data['confirm_password'] != $this->post_data ['password'] ) {
369
+ $wpmem_themsg = wpmem_get_text( 'reg_password_match' );
370
+ }
371
+ if ( array_key_exists( 'confirm_email', $this->post_data ) && $this->post_data['confirm_email'] != $this->post_data ['user_email'] ) {
372
+ $wpmem_themsg = wpmem_get_text( 'reg_email_match' );
373
+ }
374
+
375
+ // Process CAPTCHA.
376
+ if ( 0 != $wpmem->captcha ) {
377
+ $check_captcha = WP_Members_Captcha::validate();
378
+ if ( false === $check_captcha ) {
379
+ return "empty"; // @todo Return and/or set error object. For now changed to return original value.
380
+ }
381
+ }
382
+
383
+ // Check for user defined password.
384
+ $this->post_data['password'] = wpmem_get( 'password', wp_generate_password() );
385
+
386
+ // Add for _data hooks
387
+ $this->post_data['user_registered'] = current_time( 'mysql', 1 );
388
+ $this->post_data['user_role'] = get_option( 'default_role' );
389
+ $this->post_data['wpmem_reg_ip'] = wpmem_get_user_ip();
390
+ $this->post_data['wpmem_reg_url'] = esc_url_raw( wpmem_get( 'wpmem_reg_page', wpmem_get( 'redirect_to', false, 'request' ), 'request' ) );
391
+
392
+ /*
393
+ * These native fields are not installed by default, but if they
394
+ * are added, use the $_POST value - otherwise, default to username.
395
+ * Value can be filtered with wpmem_register_data.
396
+ */
397
+ $this->post_data['user_nicename'] = sanitize_title( wpmem_get( 'user_nicename', $this->post_data['username'] ) );
398
+ $this->post_data['display_name'] = sanitize_text_field( wpmem_get( 'display_name', $this->post_data['username'] ) );
399
+ $this->post_data['nickname'] = sanitize_text_field( wpmem_get( 'nickname', $this->post_data['username'] ) );
400
+ }
401
+ }
402
+
403
+ /**
404
+ * Validates registration fields in the native WP registration.
405
+ *
406
+ * @since 2.8.3
407
+ * @since 3.3.0 Ported from wpmem_wp_reg_validate() in wp-registration.php.
408
+ *
409
+ * @global object $wpmem The WP-Members object class.
410
+ *
411
+ * @param array $errors A WP_Error object containing any errors encountered during registration.
412
+ * @param string $sanitized_user_login User's username after it has been sanitized.
413
+ * @param string $user_email User's email.
414
+ * @return array $errors A WP_Error object containing any errors encountered during registration.
415
+ */
416
+ function wp_register_validate( $errors, $sanitized_user_login, $user_email ) {
417
+
418
+ global $wpmem;
419
+
420
+ // Get any meta fields that should be excluded.
421
+ $exclude = wpmem_get_excluded_meta( 'wp-register' );
422
+
423
+ foreach ( wpmem_fields( 'register_wp' ) as $meta_key => $field ) {
424
+ $is_error = false;
425
+ if ( true == $field['required'] && true == $field['register'] && $meta_key != 'user_email' && ! in_array( $meta_key, $exclude ) ) {
426
+ if ( ( $field['type'] == 'checkbox' || $field['type'] == 'multicheckbox' || $field['type'] == 'multiselect' || $field['type'] == 'radio' ) && ( ! isset( $_POST[ $meta_key ] ) ) ) {
427
+ $is_error = true;
428
+ }
429
+ if ( ( $field['type'] != 'checkbox' && $field['type'] != 'multicheckbox' && $field['type'] != 'multiselect' && $field['type'] != 'radio' ) && ( ! $_POST[ $meta_key ] ) ) {
430
+ $is_error = true;
431
+ }
432
+ if ( $is_error ) {
433
+ $errors->add( 'wpmem_error', sprintf( wpmem_get_text( 'reg_empty_field' ), __( $field['label'], 'wp-members' ) ) );
434
+ }
435
+ }
436
+ }
437
+
438
+ // Process CAPTCHA.
439
+ if ( $wpmem->captcha > 0 ) {
440
+ $check_captcha = WP_Members_Captcha::validate();
441
+ if ( false === $check_captcha ) {
442
+ $errors->add( 'wpmem_captcha_error', sprintf( wpmem_get_text( 'reg_captcha_err' ), __( $field['label'], 'wp-members' ) ) );
443
+ }
444
+ }
445
+
446
+ return $errors;
447
+ }
448
+
449
+ /**
450
+ * User registration functions.
451
+ *
452
+ * @since 3.1.7
453
+ * @since 3.2.6 Added handler for membership field type.
454
+ * @since 3.3.0 Changed from register() to register_finalize().
455
+ *
456
+ * @global object $wpmem
457
+ * @param int $user_id
458
+ */
459
+ function register_finalize( $user_id ) {
460
+
461
+ global $wpmem;
462
+
463
+ // If this is WP-Members registration.
464
+ if ( $this->reg_type['is_wpmem'] ) {
465
+ // Put user ID into post_data array.
466
+ $this->post_data['ID'] = $user_id;
467
+
468
+ // Set remaining fields to wp_usermeta table.
469
+ $new_user_fields_meta = array( 'user_url', 'first_name', 'last_name', 'description' );
470
+ foreach ( $wpmem->fields as $meta_key => $field ) {
471
+ // If the field is not excluded, update accordingly.
472
+ if ( ! in_array( $meta_key, wpmem_get_excluded_meta( 'register' ) ) && ! in_array( $meta_key, $new_user_fields_meta ) ) {
473
+ if ( $field['register'] && 'user_email' != $meta_key ) {
474
+ // Assign memberships, if applicable.
475
+ if ( 'membership' == $field['type'] && 1 == $wpmem->enable_products ) {
476
+ wpmem_set_user_product( $this->post_data[ $meta_key ], $user_id );
477
+ } else {
478
+ update_user_meta( $user_id, $meta_key, $this->post_data[ $meta_key ] );
479
+ }
480
+ }
481
+ }
482
+ }
483
+
484
+ // Store the registration url.
485
+ update_user_meta( $user_id, 'wpmem_reg_url', $this->post_data['wpmem_reg_url'] );
486
+
487
+ // Handle file uploads, if any.
488
+ if ( ! empty( $_FILES ) ) {
489
+ $this->upload_user_files( $user_id, $wpmem->fields );
490
+ }
491
+ }
492
+
493
+ // If this is native WP (wp-login.php), Users > Add New, or WooCommerce registration.
494
+ if ( $this->reg_type['is_native'] || $this->reg_type['is_add_new'] || $this->reg_type['is_woo'] ) {
495
+ // Get any excluded meta fields.
496
+ $exclude = wpmem_get_excluded_meta( 'wp-register' );
497
+ foreach ( wpmem_fields( 'register_wp' ) as $meta_key => $field ) {
498
+ $value = wpmem_get( $meta_key, false );
499
+ if ( false !== $value && ! in_array( $meta_key, $exclude ) && 'file' != $field['type'] && 'image' != $field['type'] ) {
500
+ if ( 'multiselect' == $field['type'] || 'multicheckbox' == $field['type'] ) {
501
+ $value = implode( $field['delimiter'], $value );
502
+ }
503
+ $sanitized_value = sanitize_text_field( $value );
504
+ update_user_meta( $user_id, $meta_key, $sanitized_value );
505
+ }
506
+ }
507
+ }
508
+
509
+ // If this is Users > Add New.
510
+ if ( is_admin() && $this->reg_type['is_add_new'] ) {
511
+ // If moderated registration and activate is checked, set active flags.
512
+ if ( 1 == $wpmem->mod_reg && isset( $_POST['activate_user'] ) ) {
513
+ update_user_meta( $user_id, 'active', 1 );
514
+ wpmem_set_user_status( $user_id, 0 );
515
+ }
516
+ }
517
+
518
+ // Capture IP address of all users at registration.
519
+ $user_ip = ( $this->reg_type['is_wpmem'] ) ? $this->post_data['wpmem_reg_ip'] : wpmem_get_user_ip();
520
+ update_user_meta( $user_id, 'wpmem_reg_ip', $user_ip );
521
+
522
+ }
523
+
524
+ /**
525
+ * Fires wpmem_post_register_data action.
526
+ *
527
+ * @since 3.3.2
528
+ *
529
+ * @param int $user_id
530
+ */
531
+ function post_register_data( $user_id ) {
532
+ $this->post_data['ID'] = $user_id;
533
+ /**
534
+ * Fires after user insertion but before email.
535
+ *
536
+ * @since 2.7.2
537
+ * @since 3.3.2 Hooked to user_register.
538
+ *
539
+ * @param array $this->post_data The user's submitted registration data.
540
+ */
541
+ do_action( 'wpmem_post_register_data', $this->post_data );
542
+ }
543
+
544
+ /**
545
+ * Sends emails on registration.
546
+ *
547
+ * @since 3.3.0
548
+ *
549
+ * @global object $wpmem
550
+ *
551
+ * @param int $user_id
552
+ */
553
+ function register_email_to_user( $user_id ) {
554
+ global $wpmem;
555
+ if ( $this->reg_type['is_wpmem'] ) {
556
+ // @todo Work out a better method for this so that it is optional and can be turned on/off for native reg
557
+ // Send a notification email to the user.
558
+ wpmem_email_to_user( $user_id, $this->post_data['password'], $wpmem->mod_reg, $wpmem->fields, $this->post_data );
559
+ }
560
+ }
561
+
562
+ /**
563
+ * Sends admin notifiction on registration.
564
+ *
565
+ * @since 3.3.0
566
+ *
567
+ * @global object $wpmem
568
+ *
569
+ * @param int $user_id
570
+ */
571
+ function register_email_to_admin( $user_id ) {
572
+ global $wpmem;
573
+ if ( $this->reg_type['is_wpmem'] ) {
574
+ // @todo Work out a better method for this so that it is optional and can be turned on/off for native reg
575
+ // Notify admin of new reg, if needed.
576
+ if ( 1 == $wpmem->notify ) {
577
+ $wpmem->email->notify_admin( $user_id, $wpmem->fields, $this->post_data );
578
+ }
579
+ }
580
+ }
581
+
582
+ /**
583
+ * Redirects user on registration.
584
+ *
585
+ * @since 3.1.7
586
+ */
587
+ function register_redirect() {
588
+ $redirect_to = wpmem_get( 'redirect_to', false );
589
+ if ( $redirect_to ) {
590
+ $nonce_url = wp_nonce_url( $redirect_to, 'register_redirect', 'reg_nonce' );
591
+ wp_safe_redirect( $nonce_url );
592
+ exit();
593
+ }
594
+ }
595
+
596
+ /**
597
+ * Password change or reset.
598
+ *
599
+ * @since 3.1.7
600
+ *
601
+ * @param string $action
602
+ * @return string $result
603
+ */
604
+ function password_update( $action ) {
605
+ if ( isset( $_POST['formsubmit'] ) ) {
606
+ if ( 'reset' == $action ) {
607
+ $args = array(
608
+ 'user' => sanitize_user( wpmem_get( 'user', false ) ),
609
+ 'email' => sanitize_email( wpmem_get( 'email', false ) ),
610
+ );
611
+ } else {
612
+ $args = array(
613
+ 'pass1' => wpmem_get( 'pass1', false ),
614
+ 'pass2' => wpmem_get( 'pass2', false ),
615
+ );
616
+ }
617
+ return ( 'reset' == $action ) ? $this->password_reset( $args ) : $this->password_change( $args );
618
+ }
619
+ return;
620
+ }
621
+
622
+ /**
623
+ * Change a user's password()
624
+ *
625
+ * @since 3.1.7
626
+ *
627
+ * @return
628
+ */
629
+ function password_change( $args ) {
630
+ global $user_ID;
631
+ $is_error = false;
632
+ // Check for both fields being empty.
633
+ $is_error = ( ! $args['pass1'] && ! $args['pass2'] ) ? "pwdchangempty" : $is_error;
634
+ // Make sure the fields match.
635
+ $is_error = ( $args['pass1'] != $args['pass2'] ) ? "pwdchangerr" : $is_error;
636
+ /**
637
+ * Filters the password change error.
638
+ *
639
+ * @since 3.1.5
640
+ * @since 3.1.7 Moved to user object.
641
+ *
642
+ * @param string $is_error
643
+ * @param int $user_ID The user's numeric ID.
644
+ * @param string $args['pass1'] The user's new plain text password.
645
+ */
646
+ $is_error = apply_filters( 'wpmem_pwd_change_error', $is_error, $user_ID, $args['pass1'] );
647
+ // User must be logged in.
648
+ $is_error = ( ! is_user_logged_in() ) ? "loggedin" : $is_error;
649
+ // Verify nonce.
650
+ $is_error = ( ! wp_verify_nonce( $_REQUEST['_wpmem_pwdchange_nonce'], 'wpmem_shortform_nonce' ) ) ? "reg_generic" : $is_error;
651
+ if ( $is_error ) {
652
+ return $is_error;
653
+ }
654
+ /**
655
+ * Fires after password change.
656
+ *
657
+ * @since 2.9.0
658
+ * @since 3.0.5 Added $args['pass1'] to arguments passed.
659
+ * @since 3.1.7 Moved to user object.
660
+ *
661
+ * @param int $user_ID The user's numeric ID.
662
+ * @param string $args['pass1'] The user's new plain text password.
663
+ */
664
+ do_action( 'wpmem_pwd_change', $user_ID, $args['pass1'] );
665
+ return "pwdchangesuccess";
666
+ }
667
+
668
+ /**
669
+ * Reset a user's password.
670
+ *
671
+ * @since 3.1.7
672
+ *
673
+ */
674
+ function password_reset( $args ) {
675
+ global $wpmem;
676
+ /**
677
+ * Filter the password reset arguments.
678
+ *
679
+ * @since 2.7.1
680
+ * @since 3.1.7 Moved to user object.
681
+ *
682
+ * @param array The username and email.
683
+ */
684
+ $arr = apply_filters( 'wpmem_pwdreset_args', $args );
685
+ if ( ! $arr['user'] || ! $arr['email'] ) {
686
+ // There was an empty field.
687
+ return "pwdreseterr";
688
+
689
+ } else {
690
+
691
+ if ( ! wp_verify_nonce( $_REQUEST['_wpmem_pwdreset_nonce'], 'wpmem_shortform_nonce' ) ) {
692
+ return "reg_generic";
693
+ }
694
+ if ( username_exists( $arr['user'] ) ) {
695
+ $user = get_user_by( 'login', $arr['user'] );
696
+ if ( strtolower( $user->user_email ) !== strtolower( $arr['email'] ) || ( ( $wpmem->mod_reg == 1 ) && ( get_user_meta( $user->ID, 'active', true ) != 1 ) ) ) {
697
+ // The username was there, but the email did not match OR the user hasn't been activated.
698
+ return "pwdreseterr";
699
+ } else {
700
+ // Generate a new password.
701
+ $new_pass = wp_generate_password();
702
+ // Update the users password.
703
+ wp_set_password( $new_pass, $user->ID );
704
+ // Send it in an email.
705
+ wpmem_email_to_user( $user->ID, $new_pass, 3 );
706
+ /**
707
+ * Fires after password reset.
708
+ *
709
+ * @since 2.9.0
710
+ * @since 3.0.5 Added $new_pass to arguments passed.
711
+ * @since 3.1.7 Moved to user object.
712
+ *
713
+ * @param int $user_ID The user's numeric ID.
714
+ * @param string $new_pass The new plain text password.
715
+ */
716
+ do_action( 'wpmem_pwd_reset', $user->ID, $new_pass );
717
+ return "pwdresetsuccess";
718
+ }
719
+ } else {
720
+ // Username did not exist.
721
+ return "pwdreseterr";
722
+ }
723
+ }
724
+ return;
725
+ }
726
+
727
+ /**
728
+ * Handles retrieving a forgotten username.
729
+ *
730
+ * @since 3.0.8
731
+ * @since 3.1.6 Dependencies now loaded by object.
732
+ * @since 3.1.8 Moved to user object.
733
+ *
734
+ * @global object $wpmem
735
+ * @return string $regchk The regchk value.
736
+ */
737
+ function retrieve_username() {
738
+ global $wpmem;
739
+ if ( isset( $_POST['formsubmit'] ) ) {
740
+
741
+ if ( ! wp_verify_nonce( $_REQUEST['_wpmem_getusername_nonce'], 'wpmem_shortform_nonce' ) ) {
742
+ return "reg_generic";
743
+ }
744
+
745
+ $email = sanitize_email( $_POST['user_email'] );
746
+ $user = ( isset( $_POST['user_email'] ) ) ? get_user_by( 'email', $email ) : false;
747
+ if ( $user ) {
748
+ // Send it in an email.
749
+ wpmem_email_to_user( $user->ID, '', 4 );
750
+ /**
751
+ * Fires after retrieving username.
752
+ *
753
+ * @since 3.0.8
754
+ *
755
+ * @param int $user_ID The user's numeric ID.
756
+ */
757
+ do_action( 'wpmem_get_username', $user->ID );
758
+ return 'usernamesuccess';
759
+ } else {
760
+ return 'usernamefailed';
761
+ }
762
+ }
763
+ return;
764
+ }
765
+
766
+ /**
767
+ * Handle user file uploads for registration and profile update.
768
+ *
769
+ * @since 3.1.8
770
+ * @since 3.2.6 Add file's post ID to $this->post_data.
771
+ *
772
+ * @param string $user_id
773
+ * @param array $fields
774
+ */
775
+ function upload_user_files( $user_id, $fields ) {
776
+ global $wpmem;
777
+ foreach ( $fields as $meta_key => $field ) {
778
+ if ( ( 'file' == $field['type'] || 'image' == $field['type'] ) && isset( $_FILES[ $meta_key ] ) && is_array( $_FILES[ $meta_key ] ) ) {
779
+ if ( ! empty( $_FILES[ $meta_key ]['name'] ) ) {
780
+ // Upload the file and save it as an attachment.
781
+ $file_post_id = $wpmem->forms->do_file_upload( $_FILES[ $meta_key ], $user_id );
782
+ // Save the attachment ID as user meta.
783
+ update_user_meta( $user_id, $meta_key, $file_post_id );
784
+ // Add attachement ID to post data array.
785
+ $this->post_data[ $meta_key ] = $file_post_id;
786
+ }
787
+ }
788
+ }
789
+ }
790
+
791
+ /**
792
+ * Get user data for all fields in WP-Members.
793
+ *
794
+ * Retrieves user data for all WP-Members fields (and WP default fields)
795
+ * in an array keyed by WP-Members field meta keys.
796
+ *
797
+ * @since 3.2.0
798
+ * @since 3.2.6 Added option for "all" fields (default:false).
799
+ *
800
+ * @param string $user_id optional (defaults to current user)
801
+ * @param string $all optional (default to false)
802
+ * @return array $user_fields
803
+ */
804
+ function user_data( $user_id = false, $all = false ) {
805
+ $user_id = ( $user_id ) ? $user_id : get_current_user_id();
806
+ if ( true == $all ) {
807
+ $user_info = get_user_meta( $user_id );
808
+ foreach( $user_info as $key => $value ) {
809
+ $formatted = maybe_unserialize( $value[0] );
810
+ $user_fields[ $key ] = $formatted;
811
+ }
812
+ } else {
813
+ $fields = wpmem_fields();
814
+ $user_data = get_userdata( $user_id );
815
+ $excludes = array( 'first_name', 'last_name', 'description', 'nickname' );
816
+ foreach ( $fields as $meta => $field ) {
817
+ $meta = ( 'username' == $meta ) ? 'user_login' : $meta;
818
+ if ( $field['native'] == 1 && ! in_array( $meta, $excludes ) ) {
819
+ $user_fields[ $meta ] = $user_data->data->{$meta};
820
+ } else {
821
+ $user_fields[ $meta ] = get_user_meta( $user_id, $meta, true );
822
+ }
823
+ }
824
+ }
825
+ return $user_fields;
826
+ }
827
+
828
+ /**
829
+ * Sets the role for the specified user.
830
+ *
831
+ * @since 3.2.0
832
+ *
833
+ * @param integer $user_id
834
+ * @param string $role
835
+ * @param string $action (set|add|remove)
836
+ */
837
+ public function update_user_role( $user_id, $role, $action = 'set' ) {
838
+ $user = new WP_User( $user_id );
839
+ switch ( $action ) {
840
+ case 'add':
841
+ $user->add_role( $role );
842
+ break;
843
+ case 'remove':
844
+ $user->remove_role( $role );
845
+ break;
846
+ default:
847
+ $user->set_role( $role );
848
+ break;
849
+ }
850
+ }
851
+
852
+ /**
853
+ * Sets a user's password.
854
+ *
855
+ * @since 3.2.3
856
+ *
857
+ * @param int $user_id
858
+ * @param string $password
859
+ */
860
+ function set_password( $user_id, $password ) {
861
+ wp_set_password( $password, $user_id );
862
+ }
863
+
864
+ /**
865
+ * Sets user as logged on password change.
866
+ *
867
+ * (Hooked to wpmem_pwd_change)
868
+ *
869
+ * @since 3.2.0
870
+ *
871
+ * @param int $user_id
872
+ * @param string $password
873
+ */
874
+ function set_as_logged_in( $user_id ) {
875
+ $user = get_user_by( 'id', $user_id );
876
+ wp_set_current_user( $user_id, $user->user_login );
877
+ wp_set_auth_cookie( $user_id, wpmem_get( 'rememberme', false, 'request' ) );
878
+ }
879
+
880
+ /**
881
+ * Validates user access to content.
882
+ *
883
+ * @since 3.2.0
884
+ * @todo Currently checks in this order: expiration, role, "other". If expiration product,
885
+ * and the user is current, then access is granted. This doesn't consider if the
886
+ * user is current but does not have a required role (if BOTH an expiration and role
887
+ * product). Maybe add role checking to the expiration block if both exist.
888
+ *
889
+ * @global object $wpmem
890
+ * @param mixed $product Accepts a single membership slug/meta, or an array of multiple memberships.
891
+ * @param int $user_id (optional)
892
+ * @return bool $access
893
+ */
894
+ function has_access( $product, $user_id = false ) {
895
+ global $wpmem;
896
+ if ( false === $user_id && ! is_user_logged_in() ) {
897
+ return false;
898
+ }
899
+
900
+ // Product must be an array.
901
+ $product_array = ( ! is_array( $product ) ) ? array( $product ) : $product;
902
+
903
+ $product_array = $this->get_product_children( $product_array );
904
+
905
+ // Current user or requested user.
906
+ $user_id = ( ! $user_id ) ? get_current_user_id() : $user_id;
907
+
908
+ // Load user memberships array.
909
+ $memberships = ( false == $user_id ) ? $this->access : wpmem_get_user_products( $user_id );
910
+
911
+ // Start by assuming no access.
912
+ $access = false;
913
+
914
+ foreach ( $product_array as $prod ) {
915
+ $expiration_product = false;
916
+ $role_product = false;
917
+ if ( isset( $memberships[ $prod ] ) ) {
918
+ // Is this an expiration product?
919
+ if ( isset( $wpmem->membership->products[ $prod ]['expires'][0] ) && ! is_bool( $memberships[ $prod ] ) ) {
920
+ $expiration_product = true;
921
+ if ( $this->is_current( $memberships[ $prod ] ) ) {
922
+ $access = true;
923
+ break;
924
+ }
925
+ }
926
+ // Is this a role product?
927
+ if ( '' != $wpmem->membership->products[ $prod ]['role'] ) {
928
+ $role_product = true;
929
+ if ( $memberships[ $prod ] && wpmem_user_has_role( $wpmem->membership->products[ $prod ]['role'] ) ) {
930
+ if ( $expiration_product && ! $this->is_current( $memberships[ $prod ] ) ) {
931
+ $access = false;
932
+ break;
933
+ }
934
+ $access = true;
935
+ break;
936
+ }
937
+ }
938
+ if ( ! $expiration_product && ! $role_product && $memberships[ $prod ] ) {
939
+ $access = true;
940
+ break;
941
+ }
942
+ }
943
+ }
944
+
945
+ /**
946
+ * Filter the access result.
947
+ *
948
+ * @since 3.2.0
949
+ * @since 3.2.3 Added $product argument.
950
+ *
951
+ * @param boolean $access
952
+ * @param array $product
953
+ * @param integer $user_id
954
+ * @param array $args
955
+ */
956
+ return apply_filters( 'wpmem_user_has_access', $access, $product_array, $user_id );
957
+
958
+ }
959
+
960
+ /**
961
+ * Gets product children (if any).
962
+ *
963
+ * @since 3.4.0
964
+ *
965
+ * @global stdClass $wpmem
966
+ * @param array $product_array
967
+ * $return array $product_array Product array with child products added.
968
+ */
969
+ function get_product_children( $product_array ) {
970
+
971
+ global $wpmem;
972
+ $membership_ids = array_flip( $wpmem->membership->product_by_id );
973
+ foreach ( $product_array as $product ) {
974
+ $args = array(
975
+ 'post_type' => $wpmem->membership->post_type,
976
+ 'post_parent' => $membership_ids[ $product ], // Current post's ID
977
+ );
978
+ $children = get_children( $args );
979
+ if ( ! empty( $children ) ) {
980
+ foreach ( $children as $child ) {
981
+ $product_array[] = $child->post_name;
982
+ }
983
+ }
984
+ }
985
+
986
+ return $product_array;
987
+ }
988
+
989
+ /**
990
+ * Loads anything the user has access to.
991
+ *
992
+ * @since 3.2.0
993
+ * @since 3.2.6 Updated to return empty array if no products exist for this user.
994
+ * @since 3.3.0 Updated to use individual meta for product access.
995
+ *
996
+ * @global object $wpmem
997
+ *
998
+ * @param int $user_id
999
+ * @return array $products
1000
+ */
1001
+ function get_user_products( $user_id = false, $obj = false ) {
1002
+ global $wpmem;
1003
+ $product_array = ( $obj ) ? $obj->membership->products : $wpmem->membership->products;
1004
+ $user_id = ( ! $user_id ) ? get_current_user_id() : $user_id;
1005
+ foreach ( $product_array as $product_meta => $product ) {
1006
+ $user_product = get_user_meta( $user_id, '_wpmem_products_' . $product_meta, true );
1007
+ if ( $user_product ) {
1008
+ $products[ $product_meta ] = $user_product;
1009
+ }
1010
+ $user_product = '';
1011
+ }
1012
+ return ( isset( $products ) ) ? $products : array();
1013
+ }
1014
+
1015
+ /**
1016
+ * Sets a product as active for a user.
1017
+ *
1018
+ * If the product expires, it sets an expiration date
1019
+ * based on the time period. Otherwise the value is
1020
+ * set to "true" (which does not expire).
1021
+ *
1022
+ * @since 3.2.0
1023
+ * @since 3.2.6 Added $date to set a specific expiration date.
1024
+ * @since 3.3.0 Updated to new single meta, keeps legacy array for rollback.
1025
+ * @since 3.3.1 Added no gap renewal option, @todo Needs some possible condensing.
1026
+ *
1027
+ * @param string $product
1028
+ * @param int $user_id
1029
+ * @param string $set_date Formatted date should be MySQL timestamp, or simply YYYY-MM-DD.
1030
+ */
1031
+ function set_user_product( $product, $user_id = false, $set_date = false ) {
1032
+
1033
+ global $wpmem;
1034
+
1035
+ $user_id = ( ! $user_id ) ? get_current_user_id() : $user_id;
1036
+
1037
+ // New single meta format. @todo This remains when legacy array is removed.
1038
+ $prev_value = get_user_meta( $user_id, '_wpmem_products_' . $product, true );
1039
+
1040
+ // Convert date to add.
1041
+ $expiration_period = ( isset( $wpmem->membership->products[ $product ]['expires'] ) ) ? $wpmem->membership->products[ $product ]['expires'] : false;
1042
+
1043
+ $renew = ( $prev_value ) ? true : false;
1044
+
1045
+ // If membership is an expiration product.
1046
+ if ( is_array( $expiration_period ) ) {
1047
+ $new_value = $wpmem->membership->set_product_expiration( $product, $user_id, $set_date, $prev_value, $renew );
1048
+ } else {
1049
+ $new_value = true;
1050
+ }
1051
+
1052
+ // Update product setting.
1053
+ update_user_meta( $user_id, '_wpmem_products_' . $product, $new_value );
1054
+
1055
+ // Update the legacy setting.
1056
+ $user_products = get_user_meta( $user_id, '_wpmem_products', true );
1057
+ $user_products = ( $user_products ) ? $user_products : array();
1058
+ $user_products[ $product ] = ( true === $new_value ) ? true : date( 'Y-m-d H:i:s', $new_value );
1059
+ update_user_meta( $user_id, '_wpmem_products', $user_products );
1060
+
1061
+ /**
1062
+ * Fires when a user product has been set.
1063
+ *
1064
+ * @since 3.3.0
1065
+ *
1066
+ * @param int $user_id
1067
+ * @param string $product
1068
+ */
1069
+ do_action( 'wpmem_user_product_set', $user_id, $product, $new_value, $prev_value, $renew );
1070
+
1071
+ }
1072
+
1073
+ /**
1074
+ * Removes a product from a user.
1075
+ *
1076
+ * @since 3.2.0
1077
+ * @since 3.3.0 Updated for new single meta, keeps legacy array for rollback.
1078
+ *
1079
+ * @param string $product
1080
+ * @param int $user_id
1081
+ */
1082
+ function remove_user_product( $product, $user_id = false ) {
1083
+ global $wpmem;
1084
+ $user_id = ( ! $user_id ) ? get_current_user_id() : $user_id;
1085
+
1086
+ // @todo Legacy version.
1087
+ $user_products = get_user_meta( $user_id, '_wpmem_products', true );
1088
+ $user_products = ( $user_products ) ? $user_products : array();
1089
+ if ( $user_products ) {
1090
+ unset( $user_products[ $product ] );
1091
+ update_user_meta( $user_id, '_wpmem_products', $user_products );
1092
+ }
1093
+
1094
+ // @todo New version.
1095
+ return delete_user_meta( $user_id, '_wpmem_products_' . $product );
1096
+ }
1097
+
1098
+ /**
1099
+ * Utility for expiration validation.
1100
+ *
1101
+ * @since 3.2.0
1102
+ * @since 3.3.0 Validates date or epoch time.
1103
+ *
1104
+ * @param date $date
1105
+ */
1106
+ function is_current( $date ) {
1107
+ $date = ( is_numeric( $date ) ) ? $date : strtotime( $date );
1108
+ return ( time() < $date ) ? true : false;
1109
+ }
1110
+
1111
+ /**
1112
+ * Check if a user is activated.
1113
+ *
1114
+ * @since 3.2.2
1115
+ *
1116
+ * @param int $user_id
1117
+ * @return bool $active
1118
+ */
1119
+ function is_user_activated( $user_id = false ) {
1120
+ $user_id = ( ! $user_id ) ? get_current_user_id() : $user_id;
1121
+ $active = get_user_meta( $user_id, 'active', true );
1122
+ $is_activated = ( 1 == $active ) ? true : false;
1123
+ /**
1124
+ * Filter whether the user is active or not.
1125
+ *
1126
+ * @since 3.3.5
1127
+ *
1128
+ * @param bool $is_activated
1129
+ * @param int $user_id
1130
+ */
1131
+ return apply_filters( 'wpmem_is_user_activated', $is_activated, $user_id );
1132
+ }
1133
+
1134
+ /**
1135
+ * Checks if a user is activated during user authentication.
1136
+ *
1137
+ * @since 2.7.1
1138
+ * @since 3.2.0 Moved from core to user object.
1139
+ *
1140
+ * @param object $user The WordPress User object.
1141
+ * @param string $username The user's username (user_login).
1142
+ * @param string $password The user's password.
1143
+ * @return object $user The WordPress User object.
1144
+ */
1145
+ function check_activated( $user, $username, $password ) {
1146
+ // Password must be validated.
1147
+ $pass = ( ( ! is_wp_error( $user ) ) && $password ) ? wp_check_password( $password, $user->user_pass, $user->ID ) : false;
1148
+
1149
+ if ( ! $pass ) {
1150
+ return $user;
1151
+ }
1152
+
1153
+ // Activation flag must be validated.
1154
+ if ( ! $this->is_user_activated( $user->ID ) ) {
1155
+ return new WP_Error( 'authentication_failed', __( '<strong>ERROR</strong>: User has not been activated.', 'wp-members' ) );
1156
+ }
1157
+
1158
+ // If the user is validated, return the $user object.
1159
+ return $user;
1160
+ }
1161
+
1162
+ /**
1163
+ * Prevents users not activated from resetting their password.
1164
+ *
1165
+ * @since 2.5.1
1166
+ * @since 3.2.0 Moved to user object, renamed no_reset().
1167
+ *
1168
+ * @return bool Returns false if the user is not activated, otherwise true.
1169
+ */
1170
+ function no_reset() {
1171
+ global $wpmem;
1172
+ $raw_val = wpmem_get( 'user_login', false );
1173
+ if ( $raw_val ) {
1174
+ if ( strpos( $raw_val, '@' ) ) {
1175
+ $user = get_user_by( 'email', sanitize_email( $raw_val ) );
1176
+ } else {
1177
+ $username = sanitize_user( $raw_val );
1178
+ $user = get_user_by( 'login', $username );
1179
+ }
1180
+ if ( $wpmem->mod_reg == 1 ) {
1181
+ if ( get_user_meta( $user->ID, 'active', true ) != 1 ) {
1182
+ return false;
1183
+ }
1184
+ }
1185
+ }
1186
+
1187
+ return true;
1188
+ }
1189
+
1190
+ /**
1191
+ * Set expiration for PayPal Subscriptions extension.
1192
+ *
1193
+ * @since 3.3.0
1194
+ *
1195
+ * @global object $wpmem
1196
+ *
1197
+ * @param int $user_id
1198
+ */
1199
+ function set_user_exp( $user_id ) {
1200
+ global $wpmem;
1201
+ // Set user expiration, if used.
1202
+ if ( 1 == $wpmem->use_exp && 1 != $wpmem->mod_reg ) {
1203
+ if ( function_exists( 'wpmem_set_exp' ) ) {
1204
+ wpmem_set_exp( $user_id );
1205
+ }
1206
+ }
1207
+ }
1208
+
1209
+ /**
1210
+ * Sets default membership product access (if applicable).
1211
+ *
1212
+ * @since 3.3.0
1213
+ *
1214
+ * @global object $wpmem
1215
+ *
1216
+ * @param int $user_id
1217
+ */
1218
+ function set_default_product( $user_id ) {
1219
+ global $wpmem;
1220
+
1221
+ // Get default memberships.
1222
+ $default_products = $wpmem->membership->get_default_products();
1223
+
1224
+ // Assign any default memberships to user.
1225
+ foreach ( $default_products as $product ) {
1226
+ wpmem_set_user_product( $product, $user_id );
1227
+ }
1228
+ }
1229
  }
includes/class-wp-members-validation-link.php CHANGED
@@ -1,350 +1,386 @@
1
- <?php
2
- /**
3
- *
4
- *
5
- */
6
- class WP_Members_Validation_Link {
7
-
8
- /**
9
- * Meta containers
10
- *
11
- * @since 3.3.5
12
- */
13
- public $validation_confirm = '_wpmem_user_confirmed';
14
-
15
- /**
16
- * Options.
17
- *
18
- * @since 3.3.5
19
- */
20
- public $send_welcome = true;
21
- public $show_success = true;
22
- public $send_notify = true;
23
-
24
- /**
25
- * Initialize validation link feature.
26
- *
27
- * @since 3.3.5
28
- */
29
- public function __construct() {
30
-
31
- $defaults = array(
32
- 'email_text' => __( 'Click to validate your account: ', 'wp-members' ),
33
- 'success_message' => __( 'Thank you for validating your account.', 'wp-members' ),
34
- 'invalid_message' => __( 'Validation key was expired or invalid', 'wp-members' ),
35
- 'moderated_message' => __( 'Your account is now pending approval', 'wp-members' ),
36
- );
37
-
38
- /**
39
- * Filter default dialogs.
40
- *
41
- * @since 3.3.8
42
- *
43
- * @param array $defaults
44
- */
45
- $defaults = apply_filters( 'wpmem_validation_link_default_dialogs', $defaults );
46
-
47
- foreach ( $defaults as $key => $value ) {
48
- $this->{$key} = $value;
49
- }
50
-
51
- add_action( 'template_redirect', array( $this, 'validate_key' ) );
52
- add_filter( 'authenticate', array( $this, 'check_validated' ), 99, 3 );
53
- add_filter( 'wpmem_email_filter', array( $this, 'add_key_to_email' ), 10, 3 );
54
- add_filter( 'the_content', array( $this, 'validation_success' ), 100 );
55
-
56
- add_action( 'wpmem_account_validation_success', array( $this, 'send_welcome' ) );
57
- add_action( 'wpmem_account_validation_success', array( $this, 'notify_admin' ) );
58
- }
59
-
60
- /**
61
- * Include the validation key in the new user registration email as a validation link.
62
- *
63
- * @since 3.3.5
64
- *
65
- * @global stdClass $wpmem
66
- * @param array $arr
67
- * @param array $wpmem_fields
68
- * @param array $field_data
69
- * @return array
70
- */
71
- public function add_key_to_email( $arr, $wpmem_fields, $field_data ) {
72
-
73
- global $wpmem;
74
-
75
- // Only do this for new registrations.
76
- $email_type = ( 1 == $wpmem->mod_reg ) ? 'newmod' : 'newreg';
77
- if ( $arr['toggle'] == $email_type ) {
78
-
79
- $user = get_user_by( 'ID', $arr['user_id'] );
80
-
81
- /**
82
- * Gets the user based on the password key.
83
- *
84
- * WP filters/actions triggered:
85
- * - retrieve_password
86
- * - allow_password_reset
87
- * - retrieve_password_key
88
- *
89
- * @see: https://developer.wordpress.org/reference/functions/get_password_reset_key/
90
- * @param WP_User User to retrieve password reset key for.
91
- * @return string|WP_Error Password reset key on success. WP_Error on error.
92
- */
93
- $key = $this->set_validation_key( $user );
94
-
95
- // Generate confirm link.
96
- /**
97
- * Filter the return url
98
- *
99
- * @since 3.3.5
100
- */
101
- $url = apply_filters( 'wpmem_validation_link_return_url', trailingslashit( wpmem_profile_url() ) );
102
- $query_args = array(
103
- 'a' => 'confirm',
104
- 'key' => $key,
105
- 'login' => $user->user_login,
106
- );
107
- $link = add_query_arg( $query_args, trailingslashit( $url ) );
108
-
109
- // Does email body have the [confirm_link] shortcode?
110
- if ( strpos( $arr['body'], '[confirm_link]' ) ) {
111
- $arr['body'] = str_replace( '[confirm_link]', $link, $arr['body'] );
112
- } else {
113
- // Add text and link to the email body.
114
- $arr['body'] = $arr['body'] . "\r\n"
115
- . $this->email_text
116
- . $link;
117
- }
118
- }
119
-
120
- return $arr;
121
- }
122
-
123
- /**
124
- * Check for a validation key and if one exists, validate and log in user.
125
- *
126
- * @since 3.3.5
127
- */
128
- public function validate_key() {
129
-
130
- global $wpmem;
131
-
132
- // Check for validation key.
133
- $key = ( 'confirm' == wpmem_get( 'a', false, 'get' ) ) ? wpmem_get( 'key', false, 'get' ) : false;
134
- $login = ( 'confirm' == wpmem_get( 'a', false, 'get' ) ) ? wpmem_get( 'login', false, 'get' ) : false;
135
-
136
- if ( false !== $key ) {
137
-
138
- // Set an error container.
139
- $errors = new WP_Error();
140
-
141
- /**
142
- * Validate the key.
143
- *
144
- * WP_Error will be invalid_key or expired_key. Process triggers password_reset_expiration filter
145
- * filtering DAY_IN_SECONDS default. Filter password_reset_key_expired is also triggered filtering
146
- * the return value (which can be used to override the expired/invalid check based on user_id).
147
- *
148
- * WP filter/actions triggered:
149
- * - password_reset_expiration
150
- * - password_reset_key_expired
151
- *
152
- * @see https://developer.wordpress.org/reference/functions/check_password_reset_key/
153
- * @param string Hash to validate sending user's password.
154
- * @param string The user login.
155
- * @return WP_User|WP_Error WP_User object on success, WP_Error object for invalid or expired keys (invalid_key|expired_key).
156
- */
157
- $user = check_password_reset_key( $key, $login );
158
-
159
- if ( ! is_wp_error( $user ) ) {
160
-
161
- $this->validated = true;
162
-
163
- // If registration is not moderated, set the user as logged in.
164
- if ( 1 != $wpmem->mod_reg ) {
165
- /**
166
- * Sets the WP auth cookie.
167
- *
168
- * May trigger the following WP filter/actions:
169
- * - auth_cookie_expiration
170
- * - secure_auth_cookie
171
- * - secure_logged_in_cookie
172
- * - set_auth_cookie
173
- * - set_logged_in_cookie
174
- * - send_auth_cookies
175
- *
176
- * @see https://developer.wordpress.org/reference/functions/wp_set_auth_cookie/
177
- */
178
- wp_set_auth_cookie( $user->ID, true );
179
-
180
- /**
181
- * Sets the user as logged in.
182
- *
183
- * May trigger the folloiwng WP filter/actions:
184
- * - set_current_user
185
- *
186
- * @see https://developer.wordpress.org/reference/functions/wp_set_current_user/
187
- */
188
- wp_set_current_user( $user->ID );
189
- }
190
-
191
- // Delete validation_key meta and set active.
192
- $this->clear_activation_key( $user->ID );
193
- $this->set_as_confirmed( $user->ID );
194
-
195
- /**
196
- * Fires when a user has successfully validated their account.
197
- *
198
- * @since 3.3.5
199
- *
200
- * @param int $user_id
201
- */
202
- do_action( 'wpmem_account_validation_success', $user->ID );
203
-
204
- } else {
205
- $this->validated = false;
206
- }
207
- }
208
- }
209
-
210
- /**
211
- * Display messaging.
212
- *
213
- * Shows success if key validates, expired if it does not.
214
- *
215
- * @since 3.3.5
216
- *
217
- * @param string $content
218
- * @return string $content
219
- */
220
- public function validation_success( $content ) {
221
-
222
- global $wpmem;
223
-
224
- if ( $this->show_success && 'confirm' == wpmem_get( 'a', false, 'get' ) && isset( $this->validated ) ) {
225
-
226
- if ( true === $this->validated ) {
227
- $msg = $this->success_message;
228
-
229
- if ( 1 == $wpmem->mod_reg ) {
230
- $msg = $msg . $this->moderated_message;
231
- }
232
- } elseif ( false === $this->validated ) {
233
- $msg = $this->invalid_message;
234
- } else {
235
- $msg = '';
236
- }
237
-
238
- $content = wpmem_inc_regmessage( '', $msg ) . $content;
239
- }
240
-
241
- return $content;
242
- }
243
-
244
- /**
245
- * Checks if a user is activated during user authentication.
246
- *
247
- * This prevents access via login if the user has not confirmed their email.
248
- *
249
- * @since 3.3.5 Moved from core to user object.
250
- *
251
- * @param object $user The WordPress User object.
252
- * @param string $username The user's username (user_login).
253
- * @param string $password The user's password.
254
- * @return object $user The WordPress User object.
255
- */
256
- function check_validated( $user, $username, $password ) {
257
- // Password must be validated.
258
- $pass = ( ( ! is_wp_error( $user ) ) && $password ) ? wp_check_password( $password, $user->user_pass, $user->ID ) : false;
259
-
260
- if ( ! $pass ) {
261
- return $user;
262
- }
263
-
264
- // Validation flag must be confirmed.
265
- $validated = get_user_meta( $user->ID, $this->validation_confirm, true ); // @todo Update to use wpmem_is_user_confirmed().
266
- if ( false == $validated ) {
267
- return new WP_Error( 'authentication_failed', __( '<strong>ERROR</strong>: User has not confirmed their account.', 'wp-members' ) );
268
- }
269
-
270
- // If the user is validated, return the $user object.
271
- return $user;
272
- }
273
-
274
- /**
275
- * Sends the welcome email to the user upon validation of their email.
276
- *
277
- * @since 3.3.5
278
- * @since 3.3.8 Sends email specific to email validation (previously was moderated approved email).
279
- *
280
- * @param int $user_id
281
- */
282
- public function send_welcome( $user_id ) {
283
- if ( $this->send_welcome ) {
284
- $email_to_send = ( get_option( 'wpmembers_email_validated' ) ) ? 6 : 2;
285
- wpmem_email_to_user( $user_id, '', $email_to_send );
286
- }
287
- }
288
-
289
- /**
290
- * Sends notification email to the admin upon validation of the user's email.
291
- *
292
- * @since 3.3.5
293
- *
294
- * @param int $user_id
295
- */
296
- public function notify_admin( $user_id ) {
297
- if ( $this->send_notify ) {
298
- // global $wpmem;
299
- wpmem_notify_admin( $user_id ); //, $wpmem->fields );
300
- }
301
- }
302
-
303
- /**
304
- * Clears user_activation_key.
305
- *
306
- * @since 3.3.8
307
- *
308
- * @param int $user_id
309
- */
310
- public function clear_activation_key( $user_id ) {
311
- global $wpdb;
312
- $result = $wpdb->update( $wpdb->users, array( 'user_activation_key' => '', ), array( 'ID' => $user_id ) );
313
- //clean_user_cache( $user_id );
314
- }
315
-
316
- /**
317
- * Sets a user activation key.
318
- *
319
- * @since 3.3.8
320
- *
321
- * @param mixed $user user ID (int)|WP_User (object).
322
- */
323
- public function set_validation_key( $user ) {
324
- $user = ( is_object( $user ) ) ? $user : get_user_by( 'ID', $user );
325
- return get_password_reset_key( $user );
326
- }
327
-
328
- /**
329
- * Sets user as having validated their email.
330
- *
331
- * @since 3.3.8
332
- *
333
- * @param int $user_id
334
- */
335
- public function set_as_confirmed( $user_id ) {
336
- update_user_meta( $user_id, $this->validation_confirm, time() );
337
- }
338
-
339
- /**
340
- * Sets user as NOT having validated their email.
341
- *
342
- * @since 3.3.8
343
- *
344
- * @param int $user_id
345
- */
346
- public function set_as_unconfirmed( $user_id ) {
347
- delete_user_meta( $user_id, $this->validation_confirm );
348
- $this->set_validation_key( $user_id );
349
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  }
1
+ <?php
2
+ /**
3
+ *
4
+ *
5
+ */
6
+ class WP_Members_Validation_Link {
7
+
8
+ /**
9
+ * Meta containers
10
+ *
11
+ * @since 3.3.5
12
+ */
13
+ public $validation_confirm = '_wpmem_user_confirmed';
14
+
15
+ /**
16
+ * Options.
17
+ *
18
+ * @since 3.3.5
19
+ */
20
+ public $send_welcome = true;
21
+ public $show_success = true;
22
+ public $send_notify = true;
23
+
24
+ /**
25
+ * Initialize validation link feature.
26
+ *
27
+ * @since 3.3.5
28
+ */
29
+ public function __construct() {
30
+
31
+ $defaults = array(
32
+ 'email_text' => __( 'Click to validate your account: ', 'wp-members' ),
33
+ 'success_message' => __( 'Thank you for validating your account.', 'wp-members' ),
34
+ 'invalid_message' => __( 'Validation key was expired or invalid', 'wp-members' ),
35
+ 'moderated_message' => __( 'Your account is now pending approval', 'wp-members' ),
36
+ );
37
+
38
+ /**
39
+ * Filter default dialogs.
40
+ *
41
+ * @since 3.3.8
42
+ *
43
+ * @param array $defaults
44
+ */
45
+ $defaults = apply_filters( 'wpmem_validation_link_default_dialogs', $defaults );
46
+
47
+ foreach ( $defaults as $key => $value ) {
48
+ $this->{$key} = $value;
49
+ }
50
+
51
+ add_action( 'template_redirect', array( $this, 'validate_key' ) );
52
+ add_filter( 'authenticate', array( $this, 'check_validated' ), 99, 3 );
53
+ add_filter( 'wpmem_email_filter', array( $this, 'add_key_to_email' ), 10, 3 );
54
+ add_filter( 'the_content', array( $this, 'validation_success' ), 100 );
55
+
56
+ add_action( 'wpmem_account_validation_success', array( $this, 'send_welcome' ) );
57
+ add_action( 'wpmem_account_validation_success', array( $this, 'notify_admin' ) );
58
+ }
59
+
60
+ /**
61
+ * Include the validation key in the new user registration email as a validation link.
62
+ *
63
+ * @since 3.3.5
64
+ *
65
+ * @global stdClass $wpmem
66
+ * @param array $arr
67
+ * @param array $wpmem_fields
68
+ * @param array $field_data
69
+ * @return array
70
+ */
71
+ public function add_key_to_email( $arr, $wpmem_fields, $field_data ) {
72
+
73
+ global $wpmem;
74
+
75
+ // Only do this for new registrations.
76
+ $email_type = ( 1 == $wpmem->mod_reg ) ? 'newmod' : 'newreg';
77
+ if ( $arr['toggle'] == $email_type ) {
78
+
79
+ $user = get_user_by( 'ID', $arr['user_id'] );
80
+
81
+ /**
82
+ * Gets the user based on the password key.
83
+ *
84
+ * WP filters/actions triggered:
85
+ * - retrieve_password
86
+ * - allow_password_reset
87
+ * - retrieve_password_key
88
+ *
89
+ * @see: https://developer.wordpress.org/reference/functions/get_password_reset_key/
90
+ * @param WP_User User to retrieve password reset key for.
91
+ * @return string|WP_Error Password reset key on success. WP_Error on error.
92
+ */
93
+ $key = $this->set_validation_key( $user );
94
+
95
+ // Generate confirm link.
96
+ /**
97
+ * Filter the return url
98
+ *
99
+ * @since 3.3.5
100
+ * @since 3.3.9 Added $user object
101
+ *
102
+ * @param string The link URL (trailing slash recommended).
103
+ * @param object $user
104
+ */
105
+ $url = apply_filters( 'wpmem_validation_link_return_url', trailingslashit( wpmem_profile_url() ), $user );
106
+ $query_args = array(
107
+ 'a' => 'confirm',
108
+ 'key' => $key,
109
+ 'login' => $user->user_login,
110
+ );
111
+
112
+ // urlencode, primarily for user_login with a space.
113
+ $query_args = array_map( 'rawurlencode', $query_args );
114
+
115
+ $link = add_query_arg( $query_args, trailingslashit( $url ) );
116
+
117
+ /**
118
+ * Filter the confirmation link.
119
+ *
120
+ * @since 3.3.9
121
+ *
122
+ * @param string $link
123
+ * @param string $url
124
+ * @param array $query_args
125
+ */
126
+ $link = apply_filters( 'wpmem_validation_link', $link, $url, $query_args );
127
+
128
+ // Does email body have the [confirm_link] shortcode?
129
+ if ( strpos( $arr['body'], '[confirm_link]' ) ) {
130
+ $arr['body'] = str_replace( '[confirm_link]', $link, $arr['body'] );
131
+ } else {
132
+ // Add text and link to the email body.
133
+ $arr['body'] = $arr['body'] . "\r\n"
134
+ . $this->email_text . ' ' . $link;
135
+ }
136
+ }
137
+
138
+ return $arr;
139
+ }
140
+
141
+ /**
142
+ * Check for a validation key and if one exists, validate and log in user.
143
+ *
144
+ * @since 3.3.5
145
+ */
146
+ public function validate_key() {
147
+
148
+ global $wpmem;
149
+
150
+ // Check for validation key.
151
+ $key = ( 'confirm' == wpmem_get( 'a', false, 'get' ) ) ? wpmem_get( 'key', false, 'get' ) : false;
152
+ $login = ( 'confirm' == wpmem_get( 'a', false, 'get' ) ) ? wpmem_get( 'login', false, 'get' ) : false;
153
+
154
+ if ( false !== $key ) {
155
+
156
+ // Set an error container.
157
+ $errors = new WP_Error();
158
+
159
+ /**
160
+ * Validate the key.
161
+ *
162
+ * WP_Error will be invalid_key or expired_key. Process triggers password_reset_expiration filter
163
+ * filtering DAY_IN_SECONDS default. Filter password_reset_key_expired is also triggered filtering
164
+ * the return value (which can be used to override the expired/invalid check based on user_id).
165
+ *
166
+ * WP filter/actions triggered:
167
+ * - password_reset_expiration
168
+ * - password_reset_key_expired
169
+ *
170
+ * @see https://developer.wordpress.org/reference/functions/check_password_reset_key/
171
+ * @param string Hash to validate sending user's password.
172
+ * @param string The user login.
173
+ * @return WP_User|WP_Error WP_User object on success, WP_Error object for invalid or expired keys (invalid_key|expired_key).
174
+ */
175
+ $user = check_password_reset_key( $key, $login );
176
+
177
+ if ( ! is_wp_error( $user ) ) {
178
+
179
+ $this->validated = true;
180
+
181
+ // If registration is not moderated, set the user as logged in.
182
+ if ( 1 != $wpmem->mod_reg ) {
183
+ /**
184
+ * Sets the WP auth cookie.
185
+ *
186
+ * May trigger the following WP filter/actions:
187
+ * - auth_cookie_expiration
188
+ * - secure_auth_cookie
189
+ * - secure_logged_in_cookie
190
+ * - set_auth_cookie
191
+ * - set_logged_in_cookie
192
+ * - send_auth_cookies
193
+ *
194
+ * @see https://developer.wordpress.org/reference/functions/wp_set_auth_cookie/
195
+ */
196
+ wp_set_auth_cookie( $user->ID, true );
197
+
198
+ /**
199
+ * Sets the user as logged in.
200
+ *
201
+ * May trigger the folloiwng WP filter/actions:
202
+ * - set_current_user
203
+ *
204
+ * @see https://developer.wordpress.org/reference/functions/wp_set_current_user/
205
+ */
206
+ wp_set_current_user( $user->ID );
207
+ }
208
+
209
+ // Delete validation_key meta and set active.
210
+ $this->clear_activation_key( $user->ID );
211
+ $this->set_as_confirmed( $user->ID );
212
+
213
+ /**
214
+ * Fires when a user has successfully validated their account.
215
+ *
216
+ * @since 3.3.5
217
+ *
218
+ * @param int $user_id
219
+ */
220
+ do_action( 'wpmem_account_validation_success', $user->ID );
221
+
222
+ } else {
223
+ $this->validated = false;
224
+ }
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Display messaging.
230
+ *
231
+ * Shows success if key validates, expired if it does not.
232
+ *
233
+ * @since 3.3.5
234
+ *
235
+ * @param string $content
236
+ * @return string $content
237
+ */
238
+ public function validation_success( $content ) {
239
+
240
+ global $wpmem;
241
+
242
+ if ( $this->show_success && 'confirm' == wpmem_get( 'a', false, 'get' ) && isset( $this->validated ) ) {
243
+
244
+ if ( true === $this->validated ) {
245
+ $msg = $this->success_message;
246
+
247
+ if ( 1 == $wpmem->mod_reg ) {
248
+ $msg = $msg . $this->moderated_message;
249
+ }
250
+ } elseif ( false === $this->validated ) {
251
+ $msg = $this->invalid_message;
252
+ } else {
253
+ $msg = '';
254
+ }
255
+
256
+ $content = wpmem_get_display_message( 'custom', $msg ) . $content;
257
+ }
258
+
259
+ return $content;
260
+ }
261
+
262
+ /**
263
+ * Checks if a user is activated during user authentication.
264
+ *
265
+ * This prevents access via login if the user has not confirmed their email.
266
+ *
267
+ * @since 3.3.5 Moved from core to user object.
268
+ *
269
+ * @param object $user The WordPress User object.
270
+ * @param string $username The user's username (user_login).
271
+ * @param string $password The user's password.
272
+ * @return object $user The WordPress User object.
273
+ */
274
+ function check_validated( $user, $username, $password ) {
275
+ // Password must be validated.
276
+ $pass = ( ( ! is_wp_error( $user ) ) && $password ) ? wp_check_password( $password, $user->user_pass, $user->ID ) : false;
277
+
278
+ if ( ! $pass ) {
279
+ return $user;
280
+ }
281
+
282
+ // Validation flag must be confirmed.
283
+ if ( false == wpmem_is_user_confirmed( $user->ID ) ) {
284
+ return new WP_Error( 'authentication_failed', __( '<strong>ERROR</strong>: User has not confirmed their account.', 'wp-members' ) );
285
+ }
286
+
287
+ // If the user is validated, return the $user object.
288
+ return $user;
289
+ }
290
+
291
+ /**
292
+ * Sends the welcome email to the user upon validation of their email.
293
+ *
294
+ * @since 3.3.5
295
+ * @since 3.3.8 Sends email specific to email validation (previously was moderated approved email).
296
+ *
297
+ * @param int $user_id
298
+ */
299
+ public function send_welcome( $user_id ) {
300
+ if ( $this->send_welcome ) {
301
+ $email_to_send = ( get_option( 'wpmembers_email_validated' ) ) ? 6 : 2;
302
+ wpmem_email_to_user( $user_id, '', $email_to_send );
303
+ }
304
+ }
305
+
306
+ /**
307
+ * Sends notification email to the admin upon validation of the user's email.
308
+ *
309
+ * @since 3.3.5
310
+ *
311
+ * @param int $user_id
312
+ */
313
+ public function notify_admin( $user_id ) {
314
+ if ( $this->send_notify ) {
315
+ // global $wpmem;
316
+ wpmem_notify_admin( $user_id ); //, $wpmem->fields );
317
+ }
318
+ }
319
+
320
+ /**
321
+ * Clears user_activation_key.
322
+ *
323
+ * @since 3.3.8
324
+ *
325
+ * @param int $user_id
326
+ */
327
+ public function clear_activation_key( $user_id ) {
328
+ global $wpdb;
329
+ $result = $wpdb->update( $wpdb->users, array( 'user_activation_key' => '', ), array( 'ID' => $user_id ) );
330
+ //clean_user_cache( $user_id );
331
+ }
332
+
333
+ /**
334
+ * Sets a user activation key.
335
+ *
336
+ * @since 3.3.8
337
+ *
338
+ * @param mixed $user user ID (int)|WP_User (object).
339
+ */
340
+ public function set_validation_key( $user ) {
341
+ $user = ( is_object( $user ) ) ? $user : get_user_by( 'ID', $user );
342
+ return get_password_reset_key( $user );
343
+ }
344
+
345
+ /**
346
+ * Sets user as having validated their email.
347
+ *
348
+ * @since 3.3.8
349
+ *
350
+ * @param int $user_id
351
+ */
352
+ public function set_as_confirmed( $user_id ) {
353
+ update_user_meta( $user_id, $this->validation_confirm, time() );
354
+ /**
355
+ * Fires when user is set as confirmed (either manually or by user).
356
+ *
357
+ * @since 3.3.9
358
+ *
359
+ * @param int $user_id
360
+ * @param string time()
361
+ */
362
+ do_action( 'wpmem_user_set_as_confirmed', $user_id, time() );
363
+ }
364
+
365
+ /**
366
+ * Sets user as NOT having validated their email.
367
+ *
368
+ * @since 3.3.8
369
+ *
370
+ * @param int $user_id
371
+ */
372
+ public function set_as_unconfirmed( $user_id ) {
373
+ delete_user_meta( $user_id, $this->validation_confirm );
374
+ $validation_key = $this->set_validation_key( $user_id );
375
+ /**
376
+ * Fires when user is set as confirmed (either manually or by user).
377
+ *
378
+ * @since 3.3.9
379
+ *
380
+ * @param int $user_id
381
+ * @param string time()
382
+ * @param string $key
383
+ */
384
+ do_action( 'wpmem_user_set_as_unconfirmed', $user_id, time(), $key );
385
+ }
386
  }
includes/class-wp-members-widget.php CHANGED
@@ -34,14 +34,14 @@ class widget_wpmemwidget extends WP_Widget {
34
  */
35
  function form( $instance ) {
36
 
37
- /* Default widget settings. */
38
  $defaults = array(
39
  'title' => __( 'Login Status', 'wp-members' ),
40
  'redirect_to' => '',
41
  );
42
  $instance = wp_parse_args( ( array ) $instance, $defaults );
43
 
44
- /* Title input */ ?>
45
  <p>
46
  <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'wp-members' ); ?></label>
47
  <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:95%;" />
@@ -124,13 +124,14 @@ class widget_wpmemwidget extends WP_Widget {
124
  * @since 3.0.0 Added $post_to argument.
125
  * @since 3.1.0 Changed $post_to to $redirect_to.
126
  * @since 3.2.0 Moved to widget_wpmemwidget class as do_sidebar().
 
127
  *
128
  * @param string $redirect_to A URL to redirect to upon login, default null.
129
  * @param bool $customizer Whether to show the form for the customizer.
130
  * @global string $wpmem_regchk
131
  * @global string $user_login
132
  */
133
- static function do_sidebar( $redirect_to = null, $customizer = false ) {
134
 
135
  global $wpmem, $wpmem_regchk;
136
 
@@ -167,15 +168,22 @@ class widget_wpmemwidget extends WP_Widget {
167
  'error_after' => '</p>',
168
  'fieldset_before' => '<fieldset>',
169
  'fieldset_after' => '</fieldset>',
 
 
170
  'inputs_before' => '<div class="div_texbox">',
171
  'inputs_after' => '</div>',
172
  'buttons_before' => '<div class="button_div">',
173
  'buttons_after' => '</div>',
174
 
175
  // Messages.
176
- 'error_msg' => $wpmem->get_text( 'sb_login_failed' ),
177
- 'status_msg' => $wpmem->get_text( 'sb_not_logged_in' ) . '<br />',
178
-
 
 
 
 
 
179
  // Other.
180
  'strip_breaks' => true,
181
  'wrap_inputs' => true,
@@ -206,21 +214,61 @@ class widget_wpmemwidget extends WP_Widget {
206
  */
207
  $args = apply_filters( 'wpmem_login_widget_args', $args );
208
 
209
- $form = '';
210
-
211
- $label = '<label for="username">' . $wpmem->get_text( 'sb_login_username' ) . '</label>';
212
- $input = '<input type="text" name="log" class="username" id="username" />';
213
-
214
- $input = ( $args['wrap_inputs'] ) ? $args['inputs_before'] . $input . $args['inputs_after'] : $input;
215
- $row1 = $label . $args['n'] . $input . $args['n'];
216
-
217
- $label = '<label for="password">' . $wpmem->get_text( 'sb_login_password' ) . '</label>';
218
- $input = '<input type="password" name="pwd" class="password" id="password" />';
219
-
220
- $input = ( $args['wrap_inputs'] ) ? $args['inputs_before'] . $input . $args['inputs_after'] : $input;
221
- $row2 = $label . $args['n'] . $input . $args['n'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
 
223
- $form = $row1 . $row2;
 
 
 
 
 
 
 
224
 
225
  // Handle outside elements added to the login form (currently ONLY for login).
226
  if ( $args['login_form_action'] ) {
@@ -239,42 +287,71 @@ class widget_wpmemwidget extends WP_Widget {
239
  * Filter sidebar login form hidden fields.
240
  *
241
  * @since 2.9.0
 
242
  *
243
  * @param string $hidden The HTML for the hidden fields.
244
  */
245
- $form = $form . apply_filters( 'wpmem_sb_hidden_fields', $hidden );
 
 
 
 
 
 
 
 
246
 
247
- $buttons = '<input type="submit" name="Submit" class="buttons" value="' . $wpmem->get_text( 'sb_login_button' ) . '" />';
248
 
249
  if ( $wpmem->user_pages['profile'] != null ) {
250
- /** This filter is documented in wp-members/inc/forms.php */
251
  $link = apply_filters( 'wpmem_forgot_link', add_query_arg( 'a', 'pwdreset', $wpmem->user_pages['profile'] ) );
252
- $link_html = ' <a href="' . $link . '">' . $wpmem->get_text( 'sb_login_forgot' ) . '</a>&nbsp;';
253
  /**
254
  * Filter the sidebar forgot password.
255
  *
256
  * @since 3.0.9
 
257
  *
258
  * @param string $link_html
259
  * @param string $link
260
  */
261
  $link_html = apply_filters( 'wpmem_sb_forgot_link_str', $link_html, $link );
 
 
 
 
 
 
 
 
 
262
  $buttons.= $link_html;
263
  }
264
 
265
  if ( $wpmem->user_pages['register'] != null ) {
266
- /** This filter is documented in wp-members/inc/forms.php */
267
  $link = apply_filters( 'wpmem_reg_link', $wpmem->user_pages['register'] );
268
- $link_html = ' <a href="' . $link . '">' . $wpmem->get_text( 'sb_login_register' ) . '</a>';
269
  /**
270
  * Filter the sidebar register link.
271
  *
272
  * @since 3.0.9
 
273
  *
274
  * @param string $link_html
275
  * @param string $link
276
  */
277
  $link_html = apply_filters( 'wpmem_sb_reg_link_str', $link_html, $link );
 
 
 
 
 
 
 
 
 
278
  $buttons.= $link_html;
279
  }
280
 
@@ -282,7 +359,7 @@ class widget_wpmemwidget extends WP_Widget {
282
 
283
  $form = $args['fieldset_before'] . $args['n'] . $form . $args['n'] . $args['fieldset_after'];
284
 
285
- $form = '<form name="form" method="post" action="' . $post_to . '">' . $args['n'] . $form . $args['n'] . '</form>';
286
 
287
  // Add status message, if one exists.
288
  if ( '' == $args['status_msg'] ) {
@@ -296,10 +373,19 @@ class widget_wpmemwidget extends WP_Widget {
296
  * Filter the sidebar form.
297
  *
298
  * @since unknown
 
299
  *
300
  * @param string $form The HTML for the sidebar login form.
301
  */
302
  $form = apply_filters( 'wpmem_sidebar_form', $form );
 
 
 
 
 
 
 
 
303
 
304
  $do_error_msg = '';
305
  $error_msg = $args['error_before'] . $args['error_msg'] . $args['error_after'];
@@ -315,10 +401,19 @@ class widget_wpmemwidget extends WP_Widget {
315
  * Filter the sidebar login failed message.
316
  *
317
  * @since unknown
 
318
  *
319
  * @param string $error_msg The error message.
320
  */
321
  $error_msg = apply_filters( 'wpmem_login_failed_sb', $error_msg );
 
 
 
 
 
 
 
 
322
  $form = $error_msg . $form;
323
  }
324
 
@@ -328,15 +423,15 @@ class widget_wpmemwidget extends WP_Widget {
328
 
329
  global $user_login;
330
 
331
- /** This filter is documented in wp-members/inc/dialogs.php */
332
  $logout = apply_filters( 'wpmem_logout_link', add_query_arg( 'a', 'logout', $url ) );
333
 
334
  // Defaults.
335
  $defaults = array(
336
  'user_login' => $user_login,
337
- 'wrapper_before' => '<p>',
338
- 'status_text' => sprintf( $wpmem->get_text( 'sb_status' ), $user_login ) . '<br />',
339
- 'link_text' => $wpmem->get_text( 'sb_logout' ),
340
  'wrapper_after' => '</p>',
341
  );
342
 
@@ -345,11 +440,21 @@ class widget_wpmemwidget extends WP_Widget {
345
  *
346
  * @since 3.1.0
347
  * @since 3.1.2 Pass default args.
 
348
  *
349
  * @param array $defaults
350
  * @return array
351
  */
352
  $args = apply_filters( 'wpmem_sidebar_status_args', $defaults );
 
 
 
 
 
 
 
 
 
353
 
354
  // Merge $args with $defaults.
355
  $args = wp_parse_args( $args, $defaults );
@@ -361,10 +466,19 @@ class widget_wpmemwidget extends WP_Widget {
361
  * Filter the sidebar user login status.
362
  *
363
  * @since unknown
 
364
  *
365
  * @param string $str The login status for the user.
366
  */
367
  $str = apply_filters( 'wpmem_sidebar_status', $str );
 
 
 
 
 
 
 
 
368
 
369
  echo $str;
370
  }
34
  */
35
  function form( $instance ) {
36
 
37
+ // Default widget settings.
38
  $defaults = array(
39
  'title' => __( 'Login Status', 'wp-members' ),
40
  'redirect_to' => '',
41
  );
42
  $instance = wp_parse_args( ( array ) $instance, $defaults );
43
 
44
+ // Title input. ?>
45
  <p>
46
  <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'wp-members' ); ?></label>
47
  <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:95%;" />
124
  * @since 3.0.0 Added $post_to argument.
125
  * @since 3.1.0 Changed $post_to to $redirect_to.
126
  * @since 3.2.0 Moved to widget_wpmemwidget class as do_sidebar().
127
+ * @since 3.4.0 Revise form for consitency with main body form.
128
  *
129
  * @param string $redirect_to A URL to redirect to upon login, default null.
130
  * @param bool $customizer Whether to show the form for the customizer.
131
  * @global string $wpmem_regchk
132
  * @global string $user_login
133
  */
134
+ function do_sidebar( $redirect_to = null, $customizer = false ) {
135
 
136
  global $wpmem, $wpmem_regchk;
137
 
168
  'error_after' => '</p>',
169
  'fieldset_before' => '<fieldset>',
170
  'fieldset_after' => '</fieldset>',
171
+ 'row_before' => '',
172
+ 'row_after' => '',
173
  'inputs_before' => '<div class="div_texbox">',
174
  'inputs_after' => '</div>',
175
  'buttons_before' => '<div class="button_div">',
176
  'buttons_after' => '</div>',
177
 
178
  // Messages.
179
+ 'error_msg' => wpmem_get_text( 'widget_login_failed' ),
180
+ 'status_msg' => wpmem_get_text( 'widget_not_logged_in' ) . '<br />',
181
+
182
+ 'form_id' => 'wpmem_login_widget_form',
183
+ 'form_class' => 'widget_form',
184
+ 'button_id' => '',
185
+ 'button_class' => 'buttons',
186
+
187
  // Other.
188
  'strip_breaks' => true,
189
  'wrap_inputs' => true,
214
  */
215
  $args = apply_filters( 'wpmem_login_widget_args', $args );
216
 
217
+ $inputs = array(
218
+ array(
219
+ 'name' => wpmem_get_text( 'widget_login_username' ),
220
+ 'type' => 'text',
221
+ 'tag' => 'log',
222
+ 'class' => 'username',
223
+ 'div' => 'div_text'
224
+ ),
225
+ array(
226
+ 'name' => wpmem_get_text( 'widget_login_password' ),
227
+ 'type' => 'password',
228
+ 'tag' => 'pwd',
229
+ 'class' => 'password',
230
+ 'div' => 'div_text',
231
+ ),
232
+ );
233
+
234
+ // Build the input rows.
235
+ foreach ( $inputs as $input ) {
236
+ $label = '<label for="' . esc_attr( $input['tag'] ) . '">' . $input['name'] . '</label>';
237
+ $field = wpmem_form_field( array(
238
+ 'name' => $input['tag'],
239
+ 'type' => $input['type'],
240
+ 'class' => $input['class'],
241
+ 'required' => true,
242
+ ) );
243
+ $field_before = ( $args['wrap_inputs'] ) ? '<div class="' . wpmem_sanitize_class( $input['div'] ) . '">' : '';
244
+ $field_after = ( $args['wrap_inputs'] ) ? '</div>' : '';
245
+ $rows[] = array(
246
+ 'row_before' => $args['row_before'],
247
+ 'label' => $label,
248
+ 'field_before' => $field_before,
249
+ 'field' => $field,
250
+ 'field_after' => $field_after,
251
+ 'row_after' => $args['row_after'],
252
+ );
253
+ }
254
+
255
+ /**
256
+ * Filter the array of form rows. Works like wpmem_login_form_rows.
257
+ *
258
+ * @since 3.4.0
259
+ *
260
+ * @param array $rows An array containing the form rows.
261
+ */
262
+ $rows = apply_filters( 'wpmem_login_widget_form_rows', $rows );
263
 
264
+ // Put the rows from the array into $form.
265
+ $form = '';
266
+ foreach ( $rows as $row_item ) {
267
+ $row = ( $row_item['row_before'] != '' ) ? $row_item['row_before'] . $args['n'] . $row_item['label'] . $args['n'] : $row_item['label'] . $args['n'];
268
+ $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'];
269
+ $row .= ( $row_item['row_after'] != '' ) ? $row_item['row_after'] . $args['n'] : '';
270
+ $form.= $row;
271
+ }
272
 
273
  // Handle outside elements added to the login form (currently ONLY for login).
274
  if ( $args['login_form_action'] ) {
287
  * Filter sidebar login form hidden fields.
288
  *
289
  * @since 2.9.0
290
+ * @deprecated 3.4.0 Use wpmem_login_widget_hidden_fields instead.
291
  *
292
  * @param string $hidden The HTML for the hidden fields.
293
  */
294
+ $hidden = apply_filters( 'wpmem_sb_hidden_fields', $hidden );
295
+ /**
296
+ * Filter sidebar login form hidden fields.
297
+ *
298
+ * @since 3.4.0
299
+ *
300
+ * @param string $hidden The HTML for the hidden fields.
301
+ */
302
+ $form = $form . apply_filters( 'wpmem_login_widget_hidden_fields', $hidden );
303
 
304
+ $buttons = '<input type="submit" name="Submit" class="' . wpmem_sanitize_class( $args['button_class'] ) . '" value="' . wpmem_get_text( 'widget_login_button' ) . '" />';
305
 
306
  if ( $wpmem->user_pages['profile'] != null ) {
307
+ /** This filter is documented in wp-members/includes/class-wp-members-forms.php */
308
  $link = apply_filters( 'wpmem_forgot_link', add_query_arg( 'a', 'pwdreset', $wpmem->user_pages['profile'] ) );
309
+ $link_html = ' <a href="' . $link . '">' . wpmem_get_text( 'widget_login_forgot' ) . '</a>&nbsp;';
310
  /**
311
  * Filter the sidebar forgot password.
312
  *
313
  * @since 3.0.9
314
+ * @deprecated 3.4.0 Use wpmem_login_widget_forgot_link_str instead.
315
  *
316
  * @param string $link_html
317
  * @param string $link
318
  */
319
  $link_html = apply_filters( 'wpmem_sb_forgot_link_str', $link_html, $link );
320
+ /**
321
+ * Filter the sidebar forgot password.
322
+ *
323
+ * @since 3.4.0
324
+ *
325
+ * @param string $link_html
326
+ * @param string $link
327
+ */
328
+ $link_html = apply_filters( 'wpmem_login_widget_forgot_link_str', $link_html, $link );
329
  $buttons.= $link_html;
330
  }
331
 
332
  if ( $wpmem->user_pages['register'] != null ) {
333
+ /** This filter is documented in wp-members/includes/class-wp-members-forms.php */
334
  $link = apply_filters( 'wpmem_reg_link', $wpmem->user_pages['register'] );
335
+ $link_html = ' <a href="' . $link . '">' . wpmem_get_text( 'widget_login_register' ) . '</a>';
336
  /**
337
  * Filter the sidebar register link.
338
  *
339
  * @since 3.0.9
340
+ * @deprecated 3.4.0 Use wpmem_login_widget_reg_link_str instead.
341
  *
342
  * @param string $link_html
343
  * @param string $link
344
  */
345
  $link_html = apply_filters( 'wpmem_sb_reg_link_str', $link_html, $link );
346
+ /**
347
+ * Filter the sidebar register link.
348
+ *
349
+ * @since 3.4.0
350
+ *
351
+ * @param string $link_html
352
+ * @param string $link
353
+ */
354
+ $link_html = apply_filters( 'wpmem_login_widget_reg_link_str', $link_html, $link );
355
  $buttons.= $link_html;
356
  }
357
 
359
 
360
  $form = $args['fieldset_before'] . $args['n'] . $form . $args['n'] . $args['fieldset_after'];
361
 
362
+ $form = '<form name="form" method="post" action="' . $post_to . '" id="' . wpmem_sanitize_class( $args['form_id'] ) . '" class="' . wpmem_sanitize_class( $args['form_class'] ) . '">' . $args['n'] . $form . $args['n'] . '</form>';
363
 
364
  // Add status message, if one exists.
365
  if ( '' == $args['status_msg'] ) {
373
  * Filter the sidebar form.
374
  *
375
  * @since unknown
376
+ * @deprecated 3.3.9 Use wpmem_login_widget_form instead.
377
  *
378
  * @param string $form The HTML for the sidebar login form.
379
  */
380
  $form = apply_filters( 'wpmem_sidebar_form', $form );
381
+ /**
382
+ * Filter the sidebar form.
383
+ *
384
+ * @since 3.3.9
385
+ *
386
+ * @param string $form The HTML for the sidebar login form.
387
+ */
388
+ $form = apply_filters( 'wpmem_login_widget_form', $form );
389
 
390
  $do_error_msg = '';
391
  $error_msg = $args['error_before'] . $args['error_msg'] . $args['error_after'];
401
  * Filter the sidebar login failed message.
402
  *
403
  * @since unknown
404
+ * @deprecated 3.4.0 Use wpmem_login_widget_login_failed instead.
405
  *
406
  * @param string $error_msg The error message.
407
  */
408
  $error_msg = apply_filters( 'wpmem_login_failed_sb', $error_msg );
409
+ /**
410
+ * Filter the sidebar login failed message.
411
+ *
412
+ * @since 3.4.0
413
+ *
414
+ * @param string $error_msg The error message.
415
+ */
416
+ $error_msg = apply_filters( 'wpmem_login_widget_login_failed', $error_msg );
417
  $form = $error_msg . $form;
418
  }
419
 
423
 
424
  global $user_login;
425
 
426
+ /** This filter is defined in /includes/api/api.php */
427
  $logout = apply_filters( 'wpmem_logout_link', add_query_arg( 'a', 'logout', $url ) );
428
 
429
  // Defaults.
430
  $defaults = array(
431
  'user_login' => $user_login,
432
+ 'wrapper_before' => '<p class="login_widget_status">',
433
+ 'status_text' => sprintf( wpmem_get_text( 'widget_status' ), $user_login ) . '<br />',
434
+ 'link_text' => wpmem_get_text( 'widget_logout' ),
435
  'wrapper_after' => '</p>',
436
  );
437
 
440
  *
441
  * @since 3.1.0
442
  * @since 3.1.2 Pass default args.
443
+ * @deprecated 3.4.0 Use wpmem_login_widget_status_args instead.
444
  *
445
  * @param array $defaults
446
  * @return array
447
  */
448
  $args = apply_filters( 'wpmem_sidebar_status_args', $defaults );
449
+ /**
450
+ * Filter sidebar login status arguments.
451
+ *
452
+ * @since 3.4.0
453
+ *
454
+ * @param array $defaults
455
+ * @return array
456
+ */
457
+ $args = apply_filters( 'wpmem_login_widget_status_args', $defaults );
458
 
459
  // Merge $args with $defaults.
460
  $args = wp_parse_args( $args, $defaults );
466
  * Filter the sidebar user login status.
467
  *
468
  * @since unknown
469
+ * @deprecated 3.4.0 Use wpmem_login_widget_status instead.
470
  *
471
  * @param string $str The login status for the user.
472
  */
473
  $str = apply_filters( 'wpmem_sidebar_status', $str );
474
+ /**
475
+ * Filter the sidebar user login status.
476
+ *
477
+ * @since 3.4.0
478
+ *
479
+ * @param string $str The login status for the user.
480
+ */
481
+ $str = apply_filters( 'wpmem_login_widget_status', $str );
482
 
483
  echo $str;
484
  }
includes/class-wp-members.php CHANGED
@@ -1,2129 +1,1791 @@
1
- <?php
2
- /**
3
- * The WP_Members Class.
4
- *
5
- * This is the main WP_Members object class. This class contains functions
6
- * for loading settings, shortcodes, hooks to WP, plugin dropins, constants,
7
- * and registration fields. It also manages whether content should be blocked.
8
- *
9
- * @package WP-Members
10
- * @subpackage WP_Members Object Class
11
- * @since 3.0.0
12
- */
13
-
14
- // Exit if accessed directly.
15
- if ( ! defined( 'ABSPATH' ) ) {
16
- exit();
17
- }
18
-
19
- class WP_Members {
20
-
21
- /**
22
- * Plugin version.
23
- *
24
- * @since 3.0.0
25
- * @access public
26
- * @var string
27
- */
28
- public $version = WPMEM_VERSION;
29
-
30
- /**
31
- * Database version
32
- *
33
- * @since 3.2.2
34
- * @access public
35
- * @var string
36
- */
37
- public $db_version = WPMEM_DB_VERSION;
38
-
39
- /**
40
- * Plugin path.
41
- *
42
- * @since 3.3.0
43
- * @access public
44
- * @var string
45
- */
46
- public $path;
47
-
48
- /**
49
- * Plugin __FILE__.
50
- *
51
- * @since 3.3.0
52
- * @access public
53
- * @var string
54
- */
55
- public $name;
56
-
57
- /**
58
- * Plugin slug.
59
- *
60
- * @since 3.3.0
61
- * @access public
62
- * @var string
63
- */
64
- public $slug;
65
-
66
- /**
67
- * Plugin URL.
68
- *
69
- * @since 3.3.0
70
- * @access public
71
- * @var string
72
- */
73
- public $url;
74
-
75
-
76
- /**
77
- * Content block settings.
78
- *
79
- * @since 3.0.0
80
- * @access public
81
- * @var array
82
- */
83
- public $block;
84
-
85
- /**
86
- * Excerpt settings.
87
- *
88
- * @since 3.0.0
89
- * @access public
90
- * @var array
91
- */
92
- public $show_excerpt;
93
-
94
- /**
95
- * Show login form settings.
96
- *
97
- * @since 3.0.0
98
- * @access public
99
- * @var array
100
- */
101
- public $show_login;
102
-
103
- /**
104
- * Show registration form settings.
105
- *
106
- * @since 3.0.0
107
- * @access public
108
- * @var array
109
- */
110
- public $show_reg;
111
-
112
- /**
113
- * Auto-excerpt settings.
114
- *
115
- * @since 3.0.0
116
- * @access public
117
- * @var array
118
- */
119
- public $autoex;
120
-
121
- /**
122
- * Notify admin settings.
123
- *
124
- * @since 3.0.0
125
- * @access public
126
- * @var string
127
- */
128
- public $notify;
129
-
130
- /**
131
- * Moderated registration settings.
132
- *
133
- * @since 3.0.0
134
- * @access public
135
- * @var string
136
- */
137
- public $mod_reg;
138
-
139
- /**
140
- * Captcha settings.
141
- *
142
- * @since 3.0.0
143
- * @access public
144
- * @var array
145
- */
146
- public $captcha;
147
-
148
- /**
149
- * Enable expiration extension settings.
150
- *
151
- * @since 3.0.0
152
- * @access public
153
- * @var string
154
- */
155
- public $use_exp;
156
-
157
- /**
158
- * Expiration extension enable trial period.
159
- *
160
- * @since 3.0.0
161
- * @access public
162
- * @var string
163
- */
164
- public $use_trial;
165
-
166
- /**
167
- *
168
- *
169
- * @since 3.0.0
170
- * @access public
171
- * @var array
172
- */
173
- public $warnings;
174
-
175
- /**
176
- * Enable drop-ins setting.
177
- *
178
- * @since 3.1.9
179
- * @access public
180
- * @var string
181
- */
182
- public $dropins = 0;
183
-
184
- /**
185
- * Container for enabled dropins.
186
- *
187
- * @since 3.1.9
188
- * @access public
189
- * @var array
190
- */
191
- public $dropins_enabled = array();
192
-
193
- /**
194
- * Current plugin action container.
195
- *
196
- * @since 3.0.0
197
- * @access public
198
- * @var string
199
- */
200
- public $action;
201
-
202
- /**
203
- * Regchk container.
204
- *
205
- * @since 3.0.0
206
- * @access public
207
- * @var string
208
- */
209
- public $regchk;
210
-
211
- /**
212
- * User page settings.
213
- *
214
- * @since 3.0.0
215
- * @access public
216
- * @var array
217
- */
218
- public $user_pages;
219
-
220
- /**
221
- * Custom Post Type settings.
222
- *
223
- * @since 3.0.0
224
- * @access public
225
- * @var array
226
- */
227
- public $post_types;
228
-
229
- /**
230
- * Setting for applying texturization.
231
- *
232
- * @since 3.1.7
233
- * @access public
234
- * @var boolean
235
- */
236
- public $texturize;
237
-
238
- /**
239
- * Enable product creation.
240
- *
241
- * @since 3.2.0
242
- * @access public
243
- * @var boolean
244
- */
245
- public $enable_products;
246
-
247
- /**
248
- * Enable logged-in menu clones.
249
- *
250
- * @since 3.2.0
251
- * @access public
252
- * @var string
253
- */
254
- public $clone_menus;
255
-
256
- /**
257
- * Container for error messages.
258
- *
259
- * @since 3.2.0
260
- * @access public
261
- * @var string
262
- */
263
- public $error;
264
-
265
- /**
266
- * Container for admin notices.
267
- *
268
- * @since 3.3.0
269
- * @access public
270
- * @var array
271
- */
272
- public $admin_notices;
273
-
274
- /**
275
- * Container for stylesheet setting.
276
- *
277
- * @since 3.2.7
278
- * @access public
279
- * @var string
280
- */
281
- public $select_style;
282
-
283
- /**
284
- * Container for dropin folder location.
285
- *
286
- * @since 3.3.0
287
- * @access public
288
- * @var string
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
- * Temporary setting for activation link.
303
- * Will default to 0 until 3.4.0, then 1 until 3.5.0
304
- * at which point we'll remove the old process.
305
- *
306
- * @since 3.3.5
307
- * @access public
308
- * @var string
309
- */
310
- public $act_link = 0;
311
-
312
- /**
313
- * Temporary setting for password reset.
314
- * Will default to 0 until 3.4.0, then 1 until 3.5.0
315
- * at which point we'll remove the old process.
316
- *
317
- * @since 3.3.5
318
- * @access public
319
- * @var string
320
- */
321
- public $pwd_link = 0;
322
-
323
- /**
324
- * Temporary settings for login errors.
325
- * Will default to 0 until 3.4.0.
326
- *
327
- * @since 3.3.5
328
- * @access public
329
- * @var string
330
- */
331
- public $login_error = 0;
332
-
333
- /**
334
- * Default file upload directory.
335
- *
336
- * @since 3.3.8
337
- * @access public
338
- * @var string
339
- */
340
- public $upload_base = 'wpmembers';
341
-
342
- /**
343
- * Plugin initialization function.
344
- *
345
- * @since 3.0.0
346
- * @since 3.1.6 Dependencies now loaded by object.
347
- */
348
- function __construct() {
349
-
350
- // Constants.
351
- $this->path = plugin_dir_path( __DIR__ );
352
- $this->name = $this->path . 'wp-members.php';
353
- $this->slug = substr( basename( $this->name ), 0, -4 );
354
- $this->url = plugin_dir_url ( __DIR__ );
355
-
356
- // Load dependent files.
357
- $this->load_dependencies();
358
-
359
- /**
360
- * Filter the options before they are loaded into constants.
361
- *
362
- * @since 2.9.0
363
- * @since 3.0.0 Moved to the WP_Members class.
364
- *
365
- * @param array $this->settings An array of the WP-Members settings.
366
- */
367
- $settings = apply_filters( 'wpmem_settings', get_option( 'wpmembers_settings' ) );
368
-
369
- // Validate that v3 settings are loaded.
370
- if ( ! isset( $settings['version'] )
371
- || $settings['version'] != $this->version
372
- || ! isset( $settings['db_version'] )
373
- || $settings['db_version'] != $this->db_version ) {
374
- /**
375
- * Load installation routine.
376
- */
377
- require_once( $this->path . 'includes/install.php' );
378
- // Update settings.
379
- /** This filter is documented in /inc/class-wp-members.php */
380
- $settings = apply_filters( 'wpmem_settings', wpmem_do_install() );
381
- }
382
-
383
- // Assemble settings.
384
- foreach ( $settings as $key => $val ) {
385
- $this->$key = $val;
386
- }
387
-
388
- $this->load_user_pages();
389
- $this->set_style();
390
-
391
- $this->forms = new WP_Members_Forms; // Load forms.
392
- $this->api = new WP_Members_API; // Load api.
393
- $this->shortcodes = new WP_Members_Shortcodes(); // Load shortcodes.
394
- $this->membership = new WP_Members_Products(); // Load membership plans
395
- $this->email = new WP_Members_Email; // Load email functions
396
- $this->user = new WP_Members_User( $this ); // Load user functions.
397
- $this->menus = new WP_Members_Menus();
398
- if ( $this->clone_menus ) {
399
- $this->menus_clone = new WP_Members_Clone_Menus(); // Load clone menus.
400
- }
401
- if ( 1 == $this->pwd_link ) {
402
- $this->pwd_reset = new WP_Members_Pwd_Reset;
403
- }
404
- if ( 1 == $this->act_link ) {
405
- $this->act_newreg = new WP_Members_Validation_Link;
406
- }
407
-
408
- // @todo Is this a temporary fix?
409
- $this->email->load_from();
410
-
411
- /**
412
- * Fires after main settings are loaded.
413
- *
414
- * @since 3.0
415
- * @deprecated 3.2.0 Use wpmem_after_init instead.
416
- */
417
- do_action( 'wpmem_settings_loaded' );
418
-
419
- // Preload the expiration module, if available.
420
- $exp_active = ( function_exists( 'wpmem_exp_init' ) || function_exists( 'wpmem_set_exp' ) ) ? true : false;
421
- define( 'WPMEM_EXP_MODULE', $exp_active );
422
-
423
- // Load actions and filters.
424
- $this->load_hooks();
425
-
426
- // Load contants.
427
- $this->load_constants();
428
-
429
- // Load dropins.
430
- if ( $this->dropins ) {
431
- $this->load_dropins();
432
- }
433
-
434
- // Check for anything that we should stop execution for (currently just the default tos).
435
- if ( 'display' == wpmem_get( 'tos', false, 'get' ) ) {
436
- // If themes are not loaded, we don't need them.
437
- $user_themes = ( ! defined( 'WP_USE_THEMES' ) ) ? define( 'WP_USE_THEMES', false ) : '';
438
- $this->load_default_tos();
439
- die();
440
- }
441
- }
442
-
443
- /**
444
- * Plugin initialization function to load hooks.
445
- *
446
- * @since 3.0.0
447
- */
448
- function load_hooks() {
449
-
450
- /**
451
- * Fires before action and filter hooks load.
452
- *
453
- * @since 3.0.0
454
- * @since 3.1.6 Fires before hooks load.
455
- */
456
- do_action( 'wpmem_load_hooks' );
457
-
458
- // Add actions.
459
-
460
- add_action( 'init', array( $this, 'load_textdomain' ) ); //add_action( 'plugins_loaded', 'wpmem_load_textdomain' );
461
- add_action( 'init', array( $this->membership, 'add_cpt' ), 0 ); // Adds membership plans custom post type.
462
- add_action( 'widgets_init', array( $this, 'widget_init' ) ); // initializes the widget
463
- add_action( 'admin_init', array( $this, 'load_admin' ) ); // check user role to load correct dashboard
464
- add_action( 'rest_api_init', array( $this, 'rest_init' ) );
465
- add_action( 'template_redirect', array( $this, 'get_action' ) );
466
- add_action( 'login_enqueue_scripts', array( $this, 'enqueue_style_wp_login' ) ); // styles the native registration
467
- add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) ); // Enqueues the stylesheet.
468
- add_action( 'wp_enqueue_scripts', array( $this, 'loginout_script' ) );
469
- add_action( 'pre_get_posts', array( $this, 'do_hide_posts' ), 20 );
470
- add_action( 'customize_register', array( $this, 'customizer_settings' ) );
471
- add_action( 'admin_menu', 'wpmem_admin_options' ); // adds admin menu
472
-
473
- if ( is_user_logged_in() ) {
474
- add_action( 'wpmem_pwd_change', array( $this->user, 'set_password' ), 9, 2 );
475
- add_action( 'wpmem_pwd_change', array( $this->user, 'set_as_logged_in' ), 10 );
476
- }
477
-
478
- add_filter( 'register_form', 'wpmem_wp_register_form' ); // adds fields to the default wp registration
479
-
480
- if ( wpmem_is_woo_active() ) {
481
-
482
- // Handle "My Account" page registration.
483
- if ( 1 == $this->woo['add_my_account_fields'] ) {
484
- add_action( 'woocommerce_register_form', 'wpmem_woo_register_form' );
485
- add_action( 'woocommerce_register_post', 'wpmem_woo_reg_validate', 10, 3 );
486
- }
487
- // Handle Registration checkout
488
- if ( 1 == $this->woo['add_checkout_fields'] && ! is_user_logged_in() ) {
489
- add_filter( 'woocommerce_checkout_fields', 'wpmem_woo_checkout_form' );
490
- add_action( 'woocommerce_checkout_update_order_meta', 'wpmem_woo_checkout_update_meta' );
491
- //add_action( 'woocommerce_save_account_details_errors', 'wpmem_woo_reg_validate' );
492
- add_action( 'woocommerce_form_field_multicheckbox', 'wpmem_form_field_wc_custom_field_types', 10, 4 );
493
- add_action( 'woocommerce_form_field_multiselect', 'wpmem_form_field_wc_custom_field_types', 10, 4 );
494
- add_action( 'woocommerce_form_field_radio', 'wpmem_form_field_wc_custom_field_types', 10, 4 );
495
- add_action( 'woocommerce_form_field_select', 'wpmem_form_field_wc_custom_field_types', 10, 4 );
496
- add_action( 'woocommerce_form_field_checkbox', 'wpmem_form_field_wc_custom_field_types', 10, 4 );
497
- }
498
- }
499
-
500
- // Add filters.
501
- add_filter( 'the_content', array( $this, 'do_securify' ), 99 );
502
- add_filter( 'comments_open', array( $this, 'do_securify_comments' ), 99, 2 ); // securifies the comments
503
- add_filter( 'wpmem_securify', array( $this, 'reg_securify' ) ); // adds success message on login form if redirected
504
- add_filter( 'rest_prepare_post', array( $this, 'do_securify_rest' ), 10, 3 );
505
- add_filter( 'rest_prepare_page', array( $this, 'do_securify_rest' ), 10, 3 );
506
- foreach( $this->post_types as $post_type ) {
507
- add_filter( "rest_prepare_{$post_type}", array( $this, 'do_securify_rest' ), 10, 3 );
508
- }
509
-
510
- //add_filter( 'query_vars', array( $this, 'add_query_vars' ), 10, 2 ); // adds custom query vars
511
- add_filter( 'get_pages', array( $this, 'filter_get_pages' ) );
512
- add_filter( 'wp_get_nav_menu_items', array( $this, 'filter_nav_menu_items' ), null, 3 );
513
- add_filter( 'get_previous_post_where', array( $this, 'filter_get_adjacent_post_where' ) );
514
- add_filter( 'get_next_post_where', array( $this, 'filter_get_adjacent_post_where' ) );
515
- add_filter( 'allow_password_reset', array( $this->user, 'no_reset' ) ); // no password reset for non-activated users
516
-
517
- // If registration is moderated, check for activation (blocks backend login by non-activated users).
518
- if ( $this->mod_reg == 1 ) {
519
- add_filter( 'authenticate', array( $this->user, 'check_activated' ), 99, 3 );
520
- }
521
-
522
- // Replace login error object.
523
- if ( 1 == $this->login_error ) {
524
- add_filter( 'wpmem_login_failed_args', array( $this, 'login_error' ) );
525
- add_filter( 'lostpassword_url', array( $this, 'lost_pwd_url' ), 10, 2 );
526
- }
527
- /**
528
- * Fires after action and filter hooks load.
529
- *
530
- * @since 3.0.0
531
- * @since 3.1.6 Was wpmem_load_hooks, now wpmem_hooks_loaded.
532
- */
533
- do_action( 'wpmem_hooks_loaded' );
534
- }
535
-
536
- /**
537
- * Load drop-ins.
538
- *
539
- * @since 3.0.0
540
- *
541
- * @todo This is experimental. The function and its operation is subject to change.
542
- */
543
- function load_dropins() {
544
-
545
- /**
546
- * Fires before dropins load (for adding additional drop-ins).
547
- *
548
- * @since 3.0.0
549
- * @since 3.1.6 Fires before dropins.
550
- */
551
- do_action( 'wpmem_load_dropins' );
552
-
553
- /**
554
- * Filters the drop-in file directory.
555
- *
556
- * @since 3.0.0
557
- * @since 3.3.0 Filter previously unpublished, changed hook name.
558
- *
559
- * @param string $wpmem->dropin_dir The drop-in file directory.
560
- */
561
- $dir = apply_filters( 'wpmem_dropin_dir', $this->dropin_dir );
562
-
563
- // Load any drop-ins.
564
- $settings = get_option( 'wpmembers_dropins' );
565
- $this->dropins_enabled = ( $settings ) ? $settings : array();
566
- if ( ! empty( $this->dropins_enabled ) ) {
567
- foreach ( $this->dropins_enabled as $filename ) {
568
- $dropin = $dir . $filename;
569
- if ( file_exists( $dropin ) ) {
570
- include_once( $dropin );
571
- }
572
- }
573
- }
574
-
575
- /**
576
- * Fires before dropins load (for adding additional drop-ins).
577
- *
578
- * @since 3.0.0
579
- * @since 3.1.6 Was wpmem_load_dropins, now wpmem_dropins_loaded.
580
- */
581
- do_action( 'wpmem_dropins_loaded' );
582
- }
583
-
584
- /**
585
- * Loads pre-3.0 constants (included primarily for add-on compatibility).
586
- *
587
- * @since 3.0.0
588
- * @since 3.3.0 Deprecated all but exp and trl constants.
589
- */
590
- function load_constants() {
591
- ( ! defined( 'WPMEM_MOD_REG' ) ) ? define( 'WPMEM_MOD_REG', $this->mod_reg ) : '';
592
- ( ! defined( 'WPMEM_USE_EXP' ) ) ? define( 'WPMEM_USE_EXP', $this->use_exp ) : '';
593
- ( ! defined( 'WPMEM_USE_TRL' ) ) ? define( 'WPMEM_USE_TRL', $this->use_trial ) : '';
594
- }
595
-
596
- /**
597
- * Load dependent files.
598
- *
599
- * @since 3.1.6
600
- */
601
- function load_dependencies() {
602
-
603
- /**
604
- * Filter the location and name of the pluggable file.
605
- *
606
- * @since 2.9.0
607
- * @since 3.1.6 Moved in load order to come before dependencies.
608
- *
609
- * @param string The path to WP-Members plugin functions file.
610
- */
611
- $wpmem_pluggable = apply_filters( 'wpmem_plugins_file', WP_PLUGIN_DIR . '/wp-members-pluggable.php' );
612
-
613
- // Preload any custom functions, if available.
614
- if ( file_exists( $wpmem_pluggable ) ) {
615
- include( $wpmem_pluggable );
616
- }
617
-
618
- require_once( $this->path . 'includes/class-wp-members-api.php' );
619
- require_once( $this->path . 'includes/class-wp-members-clone-menus.php' );
620
- require_once( $this->path . 'includes/class-wp-members-captcha.php' );
621
- require_once( $this->path . 'includes/class-wp-members-email.php' );
622
- require_once( $this->path . 'includes/class-wp-members-forms.php' );
623
- require_once( $this->path . 'includes/class-wp-members-menus.php' );
624
- require_once( $this->path . 'includes/class-wp-members-products.php' );
625
- require_once( $this->path . 'includes/class-wp-members-pwd-reset.php' );
626
- require_once( $this->path . 'includes/class-wp-members-shortcodes.php' );
627
- require_once( $this->path . 'includes/class-wp-members-user.php' );
628
- require_once( $this->path . 'includes/class-wp-members-user-profile.php' );
629
- require_once( $this->path . 'includes/class-wp-members-validation-link.php' );
630
- require_once( $this->path . 'includes/class-wp-members-widget.php' );
631
- require_once( $this->path . 'includes/api/api.php' );
632
- require_once( $this->path . 'includes/api/api-email.php' );
633
- require_once( $this->path . 'includes/api/api-forms.php' );
634
- require_once( $this->path . 'includes/api/api-products.php' );
635
- require_once( $this->path . 'includes/api/api-users.php' );
636
- require_once( $this->path . 'includes/api/api-utilities.php' );
637
- require_once( $this->path . 'includes/legacy/dialogs.php' );
638
- require_once( $this->path . 'includes/deprecated.php' );
639
-
640
- if ( defined( 'WP_CLI' ) && WP_CLI ) {
641
- require_once( $this->path . 'includes/cli/class-wp-members-cli.php' );
642
- require_once( $this->path . 'includes/cli/class-wp-members-cli-user.php' );
643
- require_once( $this->path . 'includes/cli/class-wp-members-cli-settings.php' );
644
- }
645
- }
646
-
647
- /**
648
- * Load admin API and dependencies.
649
- *
650
- * Determines which scripts to load and actions to use based on the
651
- * current users capabilities.
652
- *
653
- * @since 2.5.2
654
- * @since 3.1.0 Added admin api object.
655
- * @since 3.1.7 Moved from main plugin file as wpmem_chk_admin() to main object.
656
- */
657
- function load_admin() {
658
-
659
- /**
660
- * Fires before initialization of admin options.
661
- *
662
- * @since 2.9.0
663
- */
664
- do_action( 'wpmem_pre_admin_init' );
665
-
666
- /**
667
- * Load the admin api class.
668
- *
669
- * @since 3.1.0
670
- */
671
- include_once( $this->path . 'includes/admin/class-wp-members-admin-api.php' );
672
- $this->admin = new WP_Members_Admin_API;
673
-
674
- /**
675
- * Fires after initialization of admin options.
676
- *
677
- * @since 2.9.0
678
- */
679
- do_action( 'wpmem_after_admin_init' );
680
- }
681
-
682
- /**
683
- * Gets the requested action.
684
- *
685
- * @since 3.0.0
686
- *
687
- * @global string $wpmem_a The WP-Members action variable.
688
- */
689
- function get_action() {
690
-
691
- // Get the action being done (if any).
692
- $this->action = sanitize_text_field( wpmem_get( 'a', '', 'request' ) );
693
-
694
- // For backward compatibility with processes that check $wpmem_a.
695
- global $wpmem_a;
696
- $wpmem_a = $this->action;
697
-
698
- /**
699
- * Fires when the wpmem action is retrieved.
700
- *
701
- * @since 3.1.7
702
- */
703
- do_action( 'wpmem_get_action' );
704
-
705
- // Get the regchk value (if any).
706
- $this->regchk = $this->get_regchk( $this->action );
707
- }
708
-
709
- /**
710
- * Gets the regchk value.
711
- *
712
- * regchk is a legacy variable that contains information about the current
713
- * action being performed. Login, logout, password, registration, profile
714
- * update functions all return a specific value that is stored in regchk.
715
- * This value and information about the current action can then be used to
716
- * determine what content is to be displayed by the securify function.
717
- *
718
- * @since 3.0.0
719
- *
720
- * @global string $wpmem_a The WP-Members action variable.
721
- *
722
- * @param string $action The current action.
723
- * @return string The regchk value.
724
- */
725
- function get_regchk( $action ) {
726
-
727
- switch ( $action ) {
728
-
729
- case 'login':
730
- $regchk = $this->user->login();
731
- break;
732
-
733
- case 'logout':
734
- $regchk = $this->user->logout();
735
- break;
736
-
737
- case 'pwdchange':
738
- $regchk = $this->user->password_update( 'change' );
739
- break;
740
-
741
- case 'pwdreset':
742
- $regchk = $this->user->password_update( 'reset' );
743
- break;
744
-
745
- case 'getusername':
746
- $regchk = $this->user->retrieve_username();
747
- break;
748
-
749
- case 'register':
750
- case 'update':
751
- $regchk = wpmem_user_register( $action );
752
- break;
753
-
754
- default:
755
- $regchk = ( isset( $regchk ) ) ? $regchk : '';
756
- break;
757
- }
758
-
759
- /**
760
- * Filter wpmem_regchk.
761
- *
762
- * The value of regchk is determined by functions that may be run in the get_regchk function.
763
- * This value determines what happens in the wpmem_securify() function.
764
- *
765
- * @since 2.9.0
766
- * @since 3.0.0 Moved to get_regchk() in WP_Members object.
767
- *
768
- * @param string $this->regchk The value of wpmem_regchk.
769
- * @param string $this->action The $wpmem_a action.
770
- */
771
- $regchk = apply_filters( 'wpmem_regchk', $regchk, $action );
772
-
773
- // Legacy global variable for use with older extensions.
774
- global $wpmem_regchk;
775
- $wpmem_regchk = $regchk;
776
-
777
- return $regchk;
778
- }
779
-
780
- /**
781
- * Determines if content should be blocked.
782
- *
783
- * This function was originally stand alone in the core file and
784
- * was moved to the WP_Members class in 3.0.
785
- *
786
- * @since 3.0.0
787
- * @since 3.3.0 Added $post_id
788
- *
789
- * @global object $post The WordPress Post object.
790
- *
791
- * @param int $post_id
792
- * @return bool $block true|false
793
- */
794
- function is_blocked( $post_id = false ) {
795
-
796
- global $post;
797
-
798
- if ( $post || $post_id ) {
799
-
800
- $the_post = ( false === $post_id ) ? $post : get_post( $post_id );
801
-
802
- $meta = wpmem_get_block_setting( $the_post->ID );
803
-
804
- // Backward compatibility for old block/unblock meta.
805
- if ( ! $meta ) {
806
- // Check for old meta.
807
- $old_block = get_post_meta( $the_post->ID, 'block', true );
808
- $old_unblock = get_post_meta( $the_post->ID, 'unblock', true );
809
- $meta = ( $old_block ) ? 1 : ( ( $old_unblock ) ? 0 : $meta );
810
- }
811
-
812
- // Setup defaults.
813
- $defaults = array(
814
- 'post_id' => $the_post->ID,
815
- 'post_type' => $the_post->post_type,
816
- 'block' => ( isset( $this->block[ $the_post->post_type ] ) && $this->block[ $the_post->post_type ] == 1 ) ? true : false,
817
- 'block_meta' => $meta,
818
- 'block_type' => ( isset( $this->block[ $the_post->post_type ] ) ) ? $this->block[ $the_post->post_type ] : 0,
819
- );
820
-
821
- /**
822
- * Filter the block arguments.
823
- *
824
- * @since 2.9.8
825
- * @since 3.0.0 Moved to is_blocked() in WP_Members object.
826
- * @since 3.3.0 Passes $defaults, second argument deprecated.
827
- *
828
- * @param array $args $defaults.
829
- * @param array $defaults Deprecated 3.3.0.
830
- */
831
- $args = apply_filters( 'wpmem_block_args', $defaults, $defaults );
832
-
833
- // Merge $args with defaults.
834
- $args = ( wp_parse_args( $args, $defaults ) );
835
-
836
- if ( is_single() || is_page() || wpmem_is_rest() ) {
837
- switch( $args['block_type'] ) {
838
- case 1: // If content is blocked by default.
839
- $args['block'] = ( $args['block_meta'] == '0' ) ? false : $args['block'];
840
- break;
841
- case 0 : // If content is unblocked by default.
842
- $args['block'] = ( $args['block_meta'] == '1' ) ? true : $args['block'];
843
- break;
844
- }
845
-
846
- } else {
847
- $args['block'] = false;
848
- }
849
-
850
- } else {
851
- $args = array( 'block' => false );
852
- }
853
-
854
- // Don't block user pages.
855
- $args['block'] = ( in_array( get_permalink(), $this->user_pages ) ) ? false : $args['block'];
856
-
857
- /**
858
- * Filter the block boolean.
859
- *
860
- * @since 2.7.5
861
- *
862
- * @param bool $args['block']
863
- * @param array $args {
864
- * An array of arguments used in the function.
865
- *
866
- * @type string $post_id
867
- * @type string $post_type
868
- * @type string $block
869
- * @type string $block_meta
870
- * @tyep string $block_type
871
- * }
872
- */
873
- return apply_filters( 'wpmem_block', $args['block'], $args );
874
- }
875
-
876
- /**
877
- * The Securify Content Filter.
878
- *
879
- * This is the primary function that picks up where get_action() leaves off.
880
- * Determines whether content is shown or hidden for both post and pages. This
881
- * is a filter function for the_content.
882
- *
883
- * @link https://developer.wordpress.org/reference/functions/the_content/
884
- * @link https://developer.wordpress.org/reference/hooks/the_content/
885
- *
886
- * @since 3.0.0
887
- *
888
- * @global object $post The WordPress Post object.
889
- * @global object $wpmem The WP_Members object.
890
- * @global string $wpmem_themsg Contains messages to be output.
891
- * @param string $content
892
- * @return string $content
893
- */
894
- function do_securify( $content = null ) {
895
-
896
- global $post, $wpmem, $wpmem_themsg;
897
-
898
- $content = ( is_single() || is_page() ) ? $content : wpmem_do_excerpt( $content );
899
-
900
- if ( $this->regchk == "captcha" ) {
901
- global $wpmem_captcha_err;
902
- $wpmem_themsg = $wpmem->get_text( 'reg_captcha_err' ) . '<br /><br />' . $wpmem_captcha_err;
903
- }
904
-
905
- // Block/unblock Posts.
906
- if ( ! is_user_logged_in() && $this->is_blocked() == true ) {
907
-
908
- //Show the login and registration forms.
909
- if ( $this->regchk ) {
910
-
911
- // Empty content in any of these scenarios.
912
- $content = '';
913
-
914
- switch ( $this->regchk ) {
915
-
916
- case "loginfailed":
917
- $content = wpmem_inc_loginfailed();
918
- break;
919
-
920
- case "success":
921
- $content = wpmem_inc_regmessage( $this->regchk, $wpmem_themsg );
922
- $content = $content . wpmem_inc_login();
923
- break;
924
-
925
- default:
926
- $content = wpmem_inc_regmessage( $this->regchk, $wpmem_themsg );
927
- $content = $content . wpmem_register_form();
928
- break;
929
- }
930
-
931
- } else {
932
-
933
- // Toggle shows excerpt above login/reg on posts/pages.
934
- global $wp_query;
935
- if ( isset( $wp_query->query_vars['page'] ) && $wp_query->query_vars['page'] > 1 ) {
936
-
937
- // Shuts down excerpts on multipage posts if not on first page.
938
- $content = '';
939
-
940
- } elseif ( isset( $this->show_excerpt[ $post->post_type ] ) && $this->show_excerpt[ $post->post_type ] == 1 ) {
941
-
942
- $len = strpos( $content, '<span id="more' );
943
- if ( false === $len ) {
944
- $content = wpmem_do_excerpt( $content );
945
- } else {
946
- $content = substr( $content, 0, $len );
947
- }
948
-
949
- } else {
950
-
951
- // Empty all content.
952
- $content = '';
953
-
954
- }
955
-
956
- $content = ( isset( $this->show_login[ $post->post_type ] ) && $this->show_login[ $post->post_type ] == 1 ) ? $content . wpmem_inc_login() : $content . wpmem_inc_login( 'page', '', 'hide' );
957
-
958
- $content = ( isset( $this->show_reg[ $post->post_type ] ) && $this->show_reg[ $post->post_type ] == 1 ) ? $content . wpmem_register_form() : $content;
959
- }
960
-
961
- // Protects comments if expiration module is used and user is expired.
962
- } elseif ( is_user_logged_in() && $this->is_blocked() == true ){
963
-
964
- if ( $this->use_exp == 1 && function_exists( 'wpmem_do_expmessage' ) ) {
965
- /**
966
- * Filters the user expired message used by the PayPal extension.
967
- *
968
- * @since 3.2.0
969
- *
970
- * @param string $message
971
- * @param string $content
972
- */
973
- $content = apply_filters( 'wpmem_do_expmessage', wpmem_do_expmessage( $content ), $content );
974
- }
975
- }
976
-
977
- /**
978
- * Filter the value of $content after wpmem_securify has run.
979
- *
980
- * @since 2.7.7
981
- * @since 3.0.0 Moved to new method in WP_Members Class.
982
- *
983
- * @param string $content The content after securify has run.
984
- */
985
- $content = apply_filters( 'wpmem_securify', $content );
986
-
987
- if ( 1 == $this->texturize && strstr( $content, '[wpmem_txt]' ) ) {
988
- // Fix the wptexturize.
989
- remove_filter( 'the_content', 'wpautop' );
990
- remove_filter( 'the_content', 'wptexturize' );
991
- add_filter( 'the_content', array( $this, 'texturize' ), 999 );
992
- }
993
-
994
- return $content;
995
-
996
- }
997
-
998
- /**
999
- * Securifies the comments.
1000
- *
1001
- * If the user is not logged in and the content is blocked
1002
- * (i.e. wpmem->is_blocked() returns true), function loads a
1003
- * dummy/empty comments template.
1004
- *
1005
- * @since 2.9.9
1006
- * @since 3.2.0 Moved wpmem_securify_comments() to main class, renamed.
1007
- * @since 3.3.2 Added $post_id.
1008
- *
1009
- * @param bool $open Whether the current post is open for comments.
1010
- * @param int $post_id The post ID.
1011
- * @return bool $open True if current post is open for comments, otherwise false.
1012
- */
1013
- function do_securify_comments( $open, $post_id ) {
1014
-
1015
- $open = ( ! is_user_logged_in() && wpmem_is_blocked( $post_id ) ) ? false : $open;
1016
-
1017
- /**
1018
- * Filters whether comments are open or not.
1019
- *
1020
- * @since 3.0.0
1021
- * @since 3.2.0 Moved to main class.
1022
- * @since 3.3.2 Added $post_id.
1023
- *
1024
- * @param bool $open true if current post is open for comments, otherwise false.
1025
- */
1026
- $open = apply_filters( 'wpmem_securify_comments', $open, $post_id );
1027
-
1028
- if ( ! $open ) {
1029
- /** This filter is documented in wp-includes/comment-template.php */
1030
- add_filter( 'comments_array', array( $this, 'do_securify_comments_array' ), 10, 2 );
1031
- }
1032
-
1033
- return $open;
1034
- }
1035
-
1036
- /**
1037
- * Empties the comments array if content is blocked.
1038
- *
1039
- * @since 3.0.1
1040
- * @since 3.2.0 Moved wpmem_securify_comments_array() to main class, renamed.
1041
- *
1042
- * @param array $comments
1043
- * @param int $post_id
1044
- * @return array $comments The comments array.
1045
- */
1046
- function do_securify_comments_array( $comments , $post_id ) {
1047
- $comments = ( ! is_user_logged_in() && wpmem_is_blocked( $post_id ) ) ? array() : $comments;
1048
- return $comments;
1049
- }
1050
-
1051
- /**
1052
- * Handles REST request.
1053
- *
1054
- * @since 3.3.2
1055
- *
1056
- * @param WP_REST_Response $response The response object.
1057
- * @param WP_Post $post Post object.
1058
- * @param WP_REST_Request $request Request object.
1059
- * @return
1060
- */
1061
- function do_securify_rest( $response, $post, $request ) {
1062
-
1063
- if ( ! is_user_logged_in() ) { // @todo This needs to be changed to check for whether the user has access (for internal requests).
1064
- // Response for restricted content
1065
- $block_value = wpmem_is_blocked( $response->data['id'] );
1066
- if ( $block_value ) {
1067
- if ( isset( $response->data['content']['rendered'] ) ) {
1068
- /**
1069
- * Filters restricted content message.
1070
- *
1071
- * @since 3.3.2
1072
- *
1073
- * @param string $message
1074
- */
1075
- $response->data['content']['rendered'] = apply_filters( "wpmem_securify_rest_{$post->post_type}_content", __( "You must be logged in to view this content.", 'wp-members' ) );
1076
- }
1077
- if ( isset( $response->data['excerpt']['rendered'] ) ) {
1078
- /**
1079
- * Filters restricted excerpt message.
1080
- *
1081
- * @since 3.3.2
1082
- *
1083
- * @param string $message
1084
- */
1085
- $response->data['excerpt']['rendered'] = apply_filters( "wpmem_securify_rest_{$post->post_type}_excerpt", __( "You must be logged in to view this content.", 'wp-members' ) );
1086
- }
1087
- }
1088
-
1089
- // Response for hidden content. @todo This needs to be changed to check for whether the user has access (for internal requests).
1090
- if ( ! is_admin() && in_array( $post->ID, $this->hidden_posts() ) ) {
1091
- return new WP_REST_Response( __( 'The page you are looking for does not exist', 'wp-members' ), 404 );
1092
- }
1093
- }
1094
- return $response;
1095
- }
1096
-
1097
- /**
1098
- * Adds the successful registration message on the login page if reg_nonce validates.
1099
- *
1100
- * @since 3.1.7
1101
- * @since 3.2.0 Moved to wpmem object, renamed reg_securify()
1102
- *
1103
- * @param string $content
1104
- * @return string $content
1105
- */
1106
- function reg_securify( $content ) {
1107
- global $wpmem, $wpmem_themsg;
1108
- $nonce = wpmem_get( 'reg_nonce', false, 'get' );
1109
- if ( $nonce && wp_verify_nonce( $nonce, 'register_redirect' ) ) {
1110
- $content = wpmem_inc_regmessage( 'success', $wpmem_themsg );
1111
- $content = $content . wpmem_inc_login();
1112
- }
1113
- return $content;
1114
- }
1115
-
1116
- /**
1117
- * Runs if the REST API is initialized.
1118
- *
1119
- * @since 3.3.2
1120
- */
1121
- function rest_init() {
1122
- $this->is_rest = true;
1123
- }
1124
-
1125
- /**
1126
- * Gets an array of hidden post IDs.
1127
- *
1128
- * @since 3.2.0
1129
- *
1130
- * @global object $wpdb
1131
- * @return array $hidden
1132
- */
1133
- function hidden_posts() {
1134
- global $wpdb;
1135
- $hidden = get_transient( '_wpmem_hidden_posts' );
1136
- if ( false === $hidden ) {
1137
- $hidden = $this->update_hidden_posts();
1138
- }
1139
- return $hidden;
1140
- }
1141
-
1142
- /**
1143
- * Updates the hidden post array transient.
1144
- *
1145
- * @since 3.2.0
1146
- * @since 3.3.3 Don't include posts from post types not set as handled by WP-Members.
1147
- *
1148
- * @global object $wpdb
1149
- * @return array $hidden
1150
- */
1151
- function update_hidden_posts() {
1152
- global $wpdb;
1153
- $hidden = array();
1154
- $default_post_types = array( 'post'=>'Posts', 'page'=>'Page' );
1155
- $post_types = array_merge( $this->post_types, $default_post_types );
1156
- // $results = $wpdb->get_results( "SELECT post_id FROM " . $wpdb->prefix . "postmeta WHERE meta_key = '_wpmem_block' AND meta_value = 2" );
1157
- $results = $wpdb->get_results(
1158
- "SELECT
1159
- p1.id,
1160
- p1.post_type,
1161
- m1.meta_key AS _wpmem_block
1162
- FROM " . $wpdb->prefix . "posts p1
1163
- JOIN " . $wpdb->prefix . "postmeta m1 ON (m1.post_id = p1.id AND m1.meta_key = '_wpmem_block')
1164
- WHERE m1.meta_value = '2';"
1165
- );
1166
- foreach( $results as $result ) {
1167
- if ( array_key_exists( $result->post_type, $post_types ) ) {
1168
- $hidden[] = $result->id;
1169
- }
1170
- }
1171
- set_transient( '_wpmem_hidden_posts', $hidden, 60*5 );
1172
- return $hidden;
1173
- }
1174
-
1175
- /**
1176
- * Gets an array of hidden post IDs.
1177
- *
1178
- * @since 3.2.0
1179
- *
1180
- * @global stdClass $wpdb
1181
- * @return array $hidden
1182
- */
1183
- function get_hidden_posts() {
1184
- $hidden = array();
1185
-
1186
- // Return empty array if this is the admin and user can edit posts.
1187
- if ( is_admin() && current_user_can( 'edit_posts' ) ) {
1188
- return $hidden;
1189
- }
1190
-
1191
- // If the user is not logged in, return all hidden posts.
1192
- if ( ! is_user_logged_in() ) {
1193
- $hidden = $this->hidden_posts();
1194
- } else {
1195
- // If the user is logged in.
1196
- if ( 1 == $this->enable_products ) {
1197
- // Get user product access.
1198
- $hidden = $this->hidden_posts();
1199
- $hidden = ( is_array( $hidden ) ) ? $hidden : array();
1200
-
1201
- // Remove posts with a product the user has access to.
1202
- foreach ( $this->membership->products as $key => $value ) {
1203
- if ( isset( $this->user->access[ $key ] ) && ( true == $this->user->access[ $key ] || $this->user->is_current( $this->user->access[ $key ] ) ) ) {
1204
- foreach ( $hidden as $post_id ) {
1205
- if ( 1 == get_post_meta( $post_id, $this->membership->post_stem . $key, true ) ) {
1206
- $hidden_key = array_search( $post_id, $hidden );
1207
- unset( $hidden[ $hidden_key ] );
1208
- }
1209
- }
1210
- }
1211
- }
1212
-
1213
- // Remove posts that don't have a product assignment (general login).
1214
- foreach( $hidden as $hidden_key ) {
1215
- $unattached = get_post_meta( $hidden_key, '_wpmem_products', true );
1216
- if ( false == $unattached ) {
1217
- $hidden_key = array_search( $hidden_key, $hidden );
1218
- unset( $hidden[ $hidden_key ] );
1219
- }
1220
- }
1221
- }
1222
- }
1223
- /**
1224
- * Filter the hidden posts array.
1225
- *
1226
- * @since 3.3.4
1227
- *
1228
- * @param array $hidden
1229
- */
1230
- return apply_filters( 'wpmem_hidden_posts', $hidden );
1231
- }
1232
-
1233
- /**
1234
- * Hides posts based on settings and meta.
1235
- *
1236
- * @since 3.2.0
1237
- *
1238
- * @param array $query
1239
- * @return array $query
1240
- */
1241
- function do_hide_posts( $query ) {
1242
- $hidden_posts = $this->get_hidden_posts();
1243
- if ( ! empty( $hidden_posts ) ) {
1244
- // Add hidden posts to post__not_in while maintaining any existing exclusions.
1245
- $post__not_in = array_merge( $query->query_vars['post__not_in'], $hidden_posts );
1246
- /**
1247
- * Filter post__not_in.
1248
- *
1249
- * @since 3.3.4
1250
- *
1251
- * @param array $post__not_in
1252
- */
1253
- $post__not_in = apply_filters( 'wpmem_post__not_in', $post__not_in );
1254
- $query->set( 'post__not_in', $post__not_in );
1255
- }
1256
- return $query;
1257
- }
1258
-
1259
- /**
1260
- * Filter to hide pages for get_pages().
1261
- *
1262
- * @since 3.2.0
1263
- *
1264
- * @global object $wpdb
1265
- * @param array $pages
1266
- * @return array $pages
1267
- */
1268
- function filter_get_pages( $pages ) {
1269
- $hidden_posts = $this->get_hidden_posts();
1270
- if ( ! empty ( $hidden_posts ) ) {
1271
- $new_pages = array();
1272
- foreach ( $pages as $key => $page ) {
1273
- if ( ! in_array( $page->ID, $hidden_posts ) ) {
1274
- $new_pages[ $key ] = $page;
1275
- }
1276
- }
1277
- $pages = $new_pages;
1278
- }
1279
- return $pages;
1280
- }
1281
-
1282
- /**
1283
- * Filter to hide menu items.
1284
- *
1285
- * @since 3.2.0
1286
- *
1287
- * @param array $items
1288
- * @param $menu
1289
- * @param array $args
1290
- * @return array $items
1291
- */
1292
- function filter_nav_menu_items( $items, $menu, $args ) {
1293
- $hidden_posts = $this->get_hidden_posts();
1294
- if ( ! empty( $hidden_posts ) ) {
1295
- foreach ( $items as $key => $item ) {
1296
- if ( in_array( $item->object_id, $hidden_posts ) ) {
1297
- unset( $items[ $key ] );
1298
- }
1299
- }
1300
- }
1301
- return $items;
1302
- }
1303
-
1304
- /**
1305
- * Filter to remove hidden posts from prev/next links.
1306
- *
1307
- * @since 3.2.4
1308
- *
1309
- * @global object $wpmem
1310
- * @param string $where
1311
- * @return string $where
1312
- */
1313
- function filter_get_adjacent_post_where( $where ) {
1314
- global $wpmem;
1315
- if ( ! is_user_logged_in() ) {
1316
- $hidden_posts = $this->get_hidden_posts();
1317
- if ( ! empty( $hidden_posts ) ) {
1318
- $hidden = implode( ",", $hidden_posts );
1319
- $where = $where . " AND p.ID NOT IN ( $hidden )";
1320
- }
1321
- }
1322
- return $where;
1323
- }
1324
-
1325
- /**
1326
- * Sets the registration fields.
1327
- *
1328
- * @since 3.0.0
1329
- * @since 3.1.5 Added $form argument.
1330
- * @since 3.3.0 Added $tag argument.
1331
- *
1332
- * @param string $form The form being generated.
1333
- */
1334
- function load_fields( $tag = 'new', $form = 'default' ) {
1335
-
1336
- // Get stored fields settings.
1337
- $fields = get_option( 'wpmembers_fields' );
1338
-
1339
- // Validate fields settings.
1340
- if ( ! isset( $fields ) || empty( $fields ) ) {
1341
- // Update settings.
1342
- $fields = array( array( 10, 'Email', 'user_email', 'email', 'y', 'y', 'y', 'profile'=>true ) );
1343
- }
1344
-
1345
- // Add new field array keys
1346
- foreach ( $fields as $key => $val ) {
1347
-
1348
- // Key fields with meta key.
1349
- $meta_key = $val[2];
1350
-
1351
- // Old format, new key.
1352
- foreach ( $val as $subkey => $subval ) {
1353
- $this->fields[ $meta_key ][ $subkey ] = $subval;
1354
- }
1355
-
1356
- // Setup field properties.
1357
- $this->fields[ $meta_key ]['label'] = $val[1];
1358
- $this->fields[ $meta_key ]['type'] = $val[3];
1359
- $this->fields[ $meta_key ]['register'] = ( 'y' == $val[4] ) ? true : false;
1360
- $this->fields[ $meta_key ]['required'] = ( 'y' == $val[5] ) ? true : false;
1361
- $this->fields[ $meta_key ]['profile'] = ( 'y' == $val[4] ) ? true : false;// ( isset( $val['profile'] ) ) ? $val['profile'] : true ; // // @todo Wait for profile fix
1362
- $this->fields[ $meta_key ]['native'] = ( 'y' == $val[6] ) ? true : false;
1363
-
1364
- // Certain field types have additional properties.
1365
- switch ( $val[3] ) {
1366
-
1367
- case 'checkbox':
1368
- $this->fields[ $meta_key ]['checked_value'] = $val[7];
1369
- $this->fields[ $meta_key ]['checked_default'] = ( 'y' == $val[8] ) ? true : false;
1370
- break;
1371
-
1372
- case 'select':
1373
- case 'multiselect':
1374
- case 'multicheckbox':
1375
- case 'radio':
1376
- case 'membership':
1377
- if ( 'membership' == $val[3] ) {
1378
- $val[7] = array( __( 'Choose membership', 'wp-members' ) . '|' );
1379
- foreach( $this->membership->products as $membership_key => $membership_value ) {
1380
- $val[7][] = $membership_value['title'] . '|' . $membership_key;
1381
- }
1382
- }
1383
- // Correct a malformed value (if last value is empty due to a trailing comma).
1384
- if ( '' == end( $val[7] ) ) {
1385
- array_pop( $val[7] );
1386
- $this->fields[ $meta_key ][7] = $val[7];
1387
- }
1388
- $this->fields[ $meta_key ]['values'] = $val[7];
1389
- $this->fields[ $meta_key ]['delimiter'] = ( isset( $val[8] ) ) ? $val[8] : '|';
1390
- $this->fields[ $meta_key ]['options'] = array();
1391
- foreach ( $val[7] as $value ) {
1392
- $pieces = explode( '|', trim( $value ) );
1393
- if ( isset( $pieces[1] ) && $pieces[1] != '' ) {
1394
- $this->fields[ $meta_key ]['options'][ $pieces[1] ] = $pieces[0];
1395
- }
1396
- }
1397
- break;
1398
-
1399
- case 'file':
1400
- case 'image':
1401
- $this->fields[ $meta_key ]['file_types'] = $val[7];
1402
- break;
1403
-
1404
- case 'hidden':
1405
- $this->fields[ $meta_key ]['value'] = $val[7];
1406
- break;
1407
-
1408
- }
1409
- }
1410
- }
1411
-
1412
- /**
1413
- * Get excluded meta fields.
1414
- *
1415
- * @since 3.0.0
1416
- * @since 3.3.3 Update $tag to match wpmem_fields() tags.
1417
- *
1418
- * @param string $tag A tag so we know where the function is being used.
1419
- * @return array The excluded fields.
1420
- */
1421
- function excluded_fields( $tag ) {
1422
-
1423
- // Default excluded fields.
1424
- $excluded_fields = array( 'password', 'confirm_password', 'confirm_email', 'password_confirm', 'email_confirm' );
1425
-
1426
- if ( 'update' == $tag || 'admin-profile' == $tag || 'user-profile' == $tag || 'wp-register' == $tag ) {
1427
- $excluded_fields[] = 'username';
1428
- }
1429
-
1430
- if ( 'admin-profile' == $tag || 'user-profile' == $tag ) {
1431
- array_push( $excluded_fields, 'first_name', 'last_name', 'nickname', 'display_name', 'user_email', 'description', 'user_url' );
1432
-
1433
- // If WooCommerce is used, remove these meta - WC already adds them in their own section.
1434
- if ( class_exists( 'woocommerce' ) ) {
1435
- array_push( $excluded_fields,
1436
- 'billing_first_name',
1437
- 'billing_last_name',
1438
- 'billing_company',
1439
- 'billing_address_1',
1440
- 'billing_address_2',
1441
- 'billing_city',
1442
- 'billing_postcode',
1443
- 'billing_country',
1444
- 'billing_state',
1445
- 'billing_email',
1446
- 'billing_phone',
1447
- 'shipping_first_name',
1448
- 'shipping_last_name',
1449
- 'shipping_company',
1450
- 'shipping_address_1',
1451
- 'shipping_address_2',
1452
- 'shipping_city',
1453
- 'shipping_postcode',
1454
- 'shipping_country',
1455
- 'shipping_state'
1456
- );
1457
- }
1458
- }
1459
-
1460
- /**
1461
- * Filter excluded meta fields.
1462
- *
1463
- * @since 2.9.3
1464
- * @since 3.0.0 Moved to new method in WP_Members Class.
1465
- * @since 3.3.3 Update $tag to match wpmem_fields() tags.
1466
- *
1467
- * @param array An array of the field meta names to exclude.
1468
- * @param string $tag A tag so we know where the function is being used.
1469
- */
1470
- $excluded_fields = apply_filters( 'wpmem_exclude_fields', $excluded_fields, $tag );
1471
-
1472
- // Return excluded fields.
1473
- return $excluded_fields;
1474
- }
1475
-
1476
- /**
1477
- * Set page locations.
1478
- *
1479
- * Handles numeric page IDs while maintaining
1480
- * compatibility with old full url settings.
1481
- *
1482
- * @since 3.0.8
1483
- */
1484
- function load_user_pages() {
1485
- foreach ( $this->user_pages as $key => $val ) {
1486
- if ( is_numeric( $val ) ) {
1487
- if ( false !== get_post_status( $val ) ) {
1488
- $this->user_pages[ $key ] = get_page_link( $val );
1489
- } else {
1490
- $notice = sprintf( __( 'You have a linked page in the WP-Members page settings that corresponds to a post ID that no longer exists. Please %s review and update the %s page settings %s.', 'wp-members' ), '<a href="' . esc_url( get_admin_url() . '/options-general.php?page=wpmem-settings&tab=options' ) . '">', $key, '</a>' );
1491
- $this->admin_notices[] = array(
1492
- 'type'=>'error',
1493
- 'notice'=>$notice
1494
- );
1495
- }
1496
- }
1497
- }
1498
- }
1499
-
1500
- /**
1501
- * Sets the stylesheet URL.
1502
- *
1503
- * @since 3.3.0
1504
- */
1505
- function set_style() {
1506
- $this->cssurl = ( 'use_custom' == $this->select_style ) ? $this->cssurl : $this->url . 'assets/css/forms/' . $this->select_style . wpmem_get_suffix() . '.css'; // Set the stylesheet.
1507
- }
1508
-
1509
- /**
1510
- * Returns a requested text string.
1511
- *
1512
- * This function manages all of the front-end facing text.
1513
- * All defaults can be filtered using wpmem_default_text_strings.
1514
- *
1515
- * @since 3.1.0
1516
- *
1517
- * @global object $wpmem
1518
- *
1519
- * @param string $str
1520
- * @return string $text
1521
- */
1522
- function get_text( $str ) {
1523
-
1524
- global $wpmem;
1525
-
1526
- // Default Form Fields.
1527
- $default_form_fields = array(
1528
- 'first_name' => __( 'First Name', 'wp-members' ),
1529
- 'last_name' => __( 'Last Name', 'wp-members' ),
1530
- 'addr1' => __( 'Address 1', 'wp-members' ),
1531
- 'addr2' => __( 'Address 2', 'wp-members' ),
1532
- 'city' => __( 'City', 'wp-members' ),
1533
- 'thestate' => __( 'State', 'wp-members' ),
1534
- 'zip' => __( 'Zip', 'wp-members' ),
1535
- 'country' => __( 'Country', 'wp-members' ),
1536
- 'phone1' => __( 'Day Phone', 'wp-members' ),
1537
- 'user_email' => __( 'Email', 'wp-members' ),
1538
- 'confirm_email' => __( 'Confirm Email', 'wp-members' ),
1539
- 'user_url' => __( 'Website', 'wp-members' ),
1540
- 'description' => __( 'Biographical Info', 'wp-members' ),
1541
- 'password' => __( 'Password', 'wp-members' ),
1542
- 'confirm_password' => __( 'Confirm Password', 'wp-members' ),
1543
- 'tos' => __( 'TOS', 'wp-members' ),
1544
- );
1545
-
1546
- /*
1547
- * Strings to be added or removed in future versions, included so they will
1548
- * be in the translation template.
1549
- * @todo Check whether any of these should be removed.
1550
- */
1551
- $benign_strings = array(
1552
- __( 'No fields selected for deletion', 'wp-members' ),
1553
- __( 'You are not logged in.', 'wp-members' ), // Technically removed 3.5
1554
- );
1555
-
1556
- $defaults = array(
1557
-
1558
- // Login form.
1559
- 'login_heading' => __( 'Existing Users Log In', 'wp-members' ),
1560
- 'login_username' => __( 'Username or Email', 'wp-members' ),
1561
- 'login_password' => __( 'Password', 'wp-members' ),
1562
- 'login_button' => __( 'Log In', 'wp-members' ),
1563
- 'remember_me' => __( 'Remember Me', 'wp-members' ),
1564
- 'forgot_link_before' => __( 'Forgot password?', 'wp-members' ) . '&nbsp;',
1565
- 'forgot_link' => __( 'Click here to reset', 'wp-members' ),
1566
- 'register_link_before' => __( 'New User?', 'wp-members' ) . '&nbsp;',
1567
- 'register_link' => __( 'Click here to register', 'wp-members' ),
1568
-
1569
- // Password change form.
1570
- 'pwdchg_heading' => __( 'Change Password', 'wp-members' ),
1571
- 'pwdchg_password1' => __( 'New password', 'wp-members' ),
1572
- 'pwdchg_password2' => __( 'Confirm new password', 'wp-members' ),
1573
- 'pwdchg_button' => __( 'Update Password', 'wp-members' ),
1574
-
1575
- // Password reset form.
1576
- 'pwdreset_heading' => __( 'Reset Forgotten Password', 'wp-members' ),
1577
- 'pwdreset_username' => __( 'Username', 'wp-members' ),
1578
- 'pwdreset_email' => __( 'Email', 'wp-members' ),
1579
- 'pwdreset_button' => __( 'Reset Password' ),
1580
- 'username_link_before' => __( 'Forgot username?', 'wp-members' ) . '&nbsp;',
1581
- 'username_link' => __( 'Click here', 'wp-members' ),
1582
-
1583
- // Retrieve username form.
1584
- 'username_heading' => __( 'Retrieve username', 'wp-members' ),
1585
- 'username_email' => __( 'Email Address', 'wp-members' ),
1586
- 'username_button' => __( 'Retrieve username', 'wp-members' ),
1587
-
1588
- // Register form.
1589
- 'register_heading' => __( 'New User Registration', 'wp-members' ),
1590
- 'register_username' => __( 'Choose a Username', 'wp-members' ),
1591
- 'register_rscaptcha' => __( 'Input the code:', 'wp-members' ),
1592
- 'register_tos' => __( 'Please indicate that you agree to the %s Terms of Service %s', 'wp-members' ), // @note: if default changes, default check after wpmem_tos_link_txt must change.
1593
- 'register_clear' => __( 'Reset Form', 'wp-members' ),
1594
- 'register_submit' => __( 'Register', 'wp-members' ),
1595
- 'register_req_mark' => '<span class="req">*</span>',
1596
- 'register_required' => '<span class="req">*</span>' . __( 'Required field', 'wp-members' ),
1597
-
1598
- // User profile update form.
1599
- 'profile_heading' => __( 'Edit Your Information', 'wp-members' ),
1600
- 'profile_username' => __( 'Username', 'wp-members' ),
1601
- 'profile_submit' => __( 'Update Profile', 'wp-members' ),
1602
- 'profile_upload' => __( 'Update this file', 'wp-members' ),
1603
-
1604
- // Error messages and dialogs.
1605
- 'login_failed_heading' => __( 'Login Failed!', 'wp-members' ),
1606
- 'login_failed' => __( 'You entered an invalid username or password.', 'wp-members' ),
1607
- 'login_failed_link' => __( 'Click here to continue.', 'wp-members' ),
1608
- 'pwdchangempty' => __( 'Password fields cannot be empty', 'wp-members' ),
1609
- 'usernamefailed' => __( 'Sorry, that email address was not found.', 'wp-members' ),
1610
- 'usernamesuccess' => __( 'An email was sent to %s with your username.', 'wp-members' ),
1611
- 'reg_empty_field' => __( 'Sorry, %s is a required field.', 'wp-members' ),
1612
- 'reg_valid_email' => __( 'You must enter a valid email address.', 'wp-members' ),
1613
- 'reg_non_alphanumeric' => __( 'The username cannot include non-alphanumeric characters.', 'wp-members' ),
1614
- 'reg_empty_username' => __( 'Sorry, username is a required field', 'wp-members' ),
1615
- 'reg_password_match' => __( 'Passwords did not match.', 'wp-members' ),
1616
- 'reg_email_match' => __( 'Emails did not match.', 'wp-members' ),
1617
- 'reg_empty_captcha' => __( 'You must complete the CAPTCHA form.', 'wp-members' ),
1618
- 'reg_invalid_captcha' => __( 'CAPTCHA was not valid.', 'wp-members' ),
1619
- 'reg_generic' => __( 'There was an error processing the form.', 'wp-members' ),
1620
- 'reg_captcha_err' => __( 'There was an error with the CAPTCHA form.', 'wp-members' ),
1621
- 'reg_file_type' => __( 'Sorry, you can only upload the following file types for the %s field: %s.', 'wp-members' ),
1622
-
1623
- // Links.
1624
- 'profile_edit' => __( 'Edit My Information', 'wp-members' ),
1625
- 'profile_password' => __( 'Change Password', 'wp-members' ),
1626
- 'register_status' => __( 'You are logged in as %s', 'wp-members' ),
1627
- 'register_logout' => __( 'Log out', 'wp-members' ),
1628
- 'register_continue' => ( isset( $wpmem->user_pages['profile'] ) && '' != $wpmem->user_pages['profile'] ) ? __( 'Edit profile', 'wp-members' ) : __( 'Begin using the site.', 'wp-members' ),
1629
- 'login_welcome' => __( 'You are logged in as %s', 'wp-members' ),
1630
- 'login_logout' => __( 'Click to log out', 'wp-members' ),
1631
- 'status_welcome' => __( 'You are logged in as %s', 'wp-members' ),
1632
- 'status_logout' => __( 'click to log out', 'wp-members' ),
1633
- 'menu_logout' => __( 'Log Out', 'wp-members' ),
1634
-
1635
- // Widget.
1636
- 'sb_status' => __( 'You are logged in as %s', 'wp-members' ),
1637
- 'sb_logout' => __( 'click here to log out', 'wp-members' ),
1638
- 'sb_login_failed' => __( 'Login Failed!<br />You entered an invalid username or password.', 'wp-members' ),
1639
- 'sb_not_logged_in' => '',
1640
- 'sb_login_username' => __( 'Username or Email', 'wp-members' ),
1641
- 'sb_login_password' => __( 'Password', 'wp-members' ),
1642
- 'sb_login_button' => __( 'log in', 'wp-members' ),
1643
- 'sb_login_forgot' => __( 'Forgot?', 'wp-members' ),
1644
- 'sb_login_register' => __( 'Register', 'wp-members' ),
1645
-
1646
- // Default Dialogs.
1647
- 'restricted_msg' => __( "This content is restricted to site members. If you are an existing user, please log in. New users may register below.", 'wp-members' ),
1648
- 'success' => __( "Congratulations! Your registration was successful.<br /><br />You may now log in using the password that was emailed to you.", 'wp-members' ),
1649
-
1650
- // @todo Under consideration for removal from the Dialogs tab.
1651
- 'user' => __( "Sorry, that username is taken, please try another.", 'wp-members' ),
1652
- 'email' => __( "Sorry, that email address already has an account.<br />Please try another.", 'wp-members' ),
1653
- 'editsuccess' => __( "Your information was updated!", 'wp-members' ),
1654
-
1655
- // @todo These are defaults and are under consideration for removal from the dialogs tab, possibly as we change the password reset to a link based process.
1656
- 'pwdchangerr' => __( "Passwords did not match.<br /><br />Please try again.", 'wp-members' ),
1657
- 'pwdchangesuccess' => __( "Password successfully changed!", 'wp-members' ),
1658
- 'pwdreseterr' => __( "Either the username or email address do not exist in our records.", 'wp-members' ),
1659
- 'pwdresetsuccess' => __( "Password successfully reset!<br /><br />An email containing a new password has been sent to the email address on file for your account.", 'wp-members' ),
1660
-
1661
- 'product_restricted_single' => __( "This content requires the following membership: ", 'wp-members' ),
1662
- 'product_restricted_multiple' => __( "This content requires one of the following memberships: ", 'wp-members' ),
1663
-
1664
- ); // End of $defaults array.
1665
-
1666
- /**
1667
- * Filter default terms.
1668
- *
1669
- * @since 3.1.0
1670
- * @deprecated 3.2.7 Use wpmem_default_text instead.
1671
- */
1672
- $text = apply_filters( 'wpmem_default_text_strings', '' );
1673
-
1674
- // Merge filtered $terms with $defaults.
1675
- $text = wp_parse_args( $text, $defaults );
1676
-
1677
- /**
1678
- * Filter the default terms.
1679
- *
1680
- * Replaces 'wpmem_default_text_strings' so that multiple filters could
1681
- * be run. This allows for custom filters when also running the Text
1682
- * String Editor extension.
1683
- *
1684
- * @since 3.2.7
1685
- */
1686
- $text = apply_filters( 'wpmem_default_text', $text );
1687
-
1688
- // Return the requested text string.
1689
- return $text[ $str ];
1690
-
1691
- } // End of get_text().
1692
-
1693
- /**
1694
- * Initializes the WP-Members widget.
1695
- *
1696
- * @since 3.2.0 Replaces widget_wpmemwidget_init
1697
- */
1698
- public function widget_init() {
1699
- // Register the WP-Members widget.
1700
- register_widget( 'widget_wpmemwidget' );
1701
- }
1702
-
1703
- /**
1704
- * Adds WP-Members query vars to WP's public query vars.
1705
- *
1706
- * @since 3.2.0
1707
- *
1708
- * @see https://codex.wordpress.org/Plugin_API/Filter_Reference/query_vars
1709
- *
1710
- * @param array $qvars
1711
- */
1712
- public function add_query_vars ( $qvars ) {
1713
- $qvars[] = 'a'; // The WP-Members action variable.
1714
- return $qvars;
1715
- }
1716
-
1717
- /**
1718
- * Enqueues login/out script for the footer.
1719
- *
1720
- * @since 3.2.0
1721
- */
1722
- public function loginout_script() {
1723
- if ( is_user_logged_in() ) {
1724
- wp_enqueue_script( 'jquery' );
1725
- add_action( 'wp_footer', array( $this, 'do_loginout_script' ), 50 );
1726
- }
1727
- }
1728
-
1729
- /**
1730
- * Outputs login/out script for the footer.
1731
- *
1732
- * @since 3.2.0
1733
- *
1734
- * @global object $wpmem
1735
- */
1736
- public function do_loginout_script() {
1737
- global $wpmem;
1738
- $logout = apply_filters( 'wpmem_logout_link', add_query_arg( 'a', 'logout' ) );
1739
- ?><script type="text/javascript">
1740
- jQuery('.wpmem_loginout').html('<a class="login_button" href="<?php echo esc_url( $logout ); ?>"><?php echo $this->get_text( 'menu_logout' ); ?></a>');
1741
- </script><?php
1742
- }
1743
-
1744
- /**
1745
- * Adds WP-Members controls to the Customizer
1746
- *
1747
- * @since 3.2.0
1748
- *
1749
- * @param object $wp_customize The Customizer object.
1750
- */
1751
- function customizer_settings( $wp_customize ) {
1752
- $wp_customize->add_section( 'wp_members' , array(
1753
- 'title' => 'WP-Members',
1754
- 'priority' => 190,
1755
- ) );
1756
-
1757
- // Add settings for output description
1758
- $wp_customize->add_setting( 'wpmem_show_logged_out_state', array(
1759
- 'default' => '1',
1760
- 'type' => 'theme_mod', //'option'
1761
- 'capability' => 'edit_theme_options',
1762
- 'transport' => 'refresh',
1763
- ) );
1764
-
1765
- // Add settings for output description
1766
- $wp_customize->add_setting( 'wpmem_show_form_message_dialog', array(
1767
- 'default' => '1',
1768
- 'type' => 'theme_mod', //'option'
1769
- 'capability' => 'edit_theme_options',
1770
- 'transport' => 'refresh',
1771
- ) );
1772
-
1773
- // Add control and output for select field
1774
- $wp_customize->add_control( 'wpmem_show_form_logged_out', array(
1775
- 'label' => __( 'Show forms as logged out', 'wp-members' ),
1776
- 'section' => 'wp_members',
1777
- 'settings' => 'wpmem_show_logged_out_state',
1778
- 'type' => 'checkbox',
1779
- 'std' => '1'
1780
- ) );
1781
-
1782
- // Add control for showing dialog
1783
- $wp_customize->add_control( 'wpmem_show_form_dialog', array(
1784
- 'label' => __( 'Show form message dialog', 'wp-members' ),
1785
- 'section' => 'wp_members',
1786
- 'settings' => 'wpmem_show_form_message_dialog',
1787
- 'type' => 'checkbox',
1788
- 'std' => '0'
1789
- ) );
1790
- }
1791
-
1792
- /**
1793
- * Overrides the wptexturize filter.
1794
- *
1795
- * Currently only used for the login form to remove the <br> tag that WP puts in after the "Remember Me".
1796
- *
1797
- * @since 2.6.4
1798
- * @since 3.2.3 Moved to WP_Members class.
1799
- *
1800
- * @todo Possibly deprecate or severely alter this process as its need may be obsolete.
1801
- *
1802
- * @param string $content
1803
- * @return string $new_content
1804
- */
1805
- function texturize( $content ) {
1806
-
1807
- $new_content = '';
1808
- $pattern_full = '{(\[wpmem_txt\].*?\[/wpmem_txt\])}is';
1809
- $pattern_contents = '{\[wpmem_txt\](.*?)\[/wpmem_txt\]}is';
1810
- $pieces = preg_split( $pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE );
1811
-
1812
- foreach ( $pieces as $piece ) {
1813
- if ( preg_match( $pattern_contents, $piece, $matches ) ) {
1814
- $new_content .= $matches[1];
1815
- } else {
1816
- $new_content .= wptexturize( wpautop( $piece ) );
1817
- }
1818
- }
1819
-
1820
- return $new_content;
1821
- }
1822
-
1823
- /**
1824
- * Loads the stylesheet for tableless forms.
1825
- *
1826
- * @since 2.6
1827
- * @since 3.2.3 Moved to WP_Members class.
1828
- *
1829
- * @global object $wpmem The WP_Members object.
1830
- */
1831
- function enqueue_style() {
1832
- global $wpmem;
1833
- wp_enqueue_style ( 'wp-members', wpmem_force_ssl( $wpmem->cssurl ), false, $wpmem->version );
1834
- }
1835
-
1836
- /**
1837
- * Loads the wp-login.php stylesheet.
1838
- *
1839
- * @since 3.3.0
1840
- *
1841
- * @global stdClass $wpmem
1842
- */
1843
- function enqueue_style_wp_login() {
1844
- global $wpmem;
1845
- wp_enqueue_style( 'wp-members', $wpmem->url . 'assets/css/wp-login' . wpmem_get_suffix() . '.css', false, $wpmem->version );
1846
- }
1847
-
1848
- /**
1849
- * Creates an excerpt on the fly if there is no 'more' tag.
1850
- *
1851
- * @since 2.6
1852
- * @since 3.2.3 Moved to WP_Members class.
1853
- * @since 3.2.5 Check if post object exists.
1854
- *
1855
- * @global object $post The post object.
1856
- * @global object $wpmem The WP_Members object.
1857
- *
1858
- * @param string $content
1859
- * @return string $content
1860
- */
1861
- function do_excerpt( $content ) {
1862
-
1863
- global $post, $more, $wpmem;
1864
-
1865
- if ( is_object( $post ) ) {
1866
-
1867
- $post_id = $post->ID;
1868
- $post_type = $post->post_type;
1869
-
1870
- $autoex = ( isset( $wpmem->autoex[ $post->post_type ] ) && 1 == $wpmem->autoex[ $post->post_type ]['enabled'] ) ? $wpmem->autoex[ $post->post_type ] : false;
1871
-
1872
- // Is there already a 'more' link in the content?
1873
- $has_more_link = ( stristr( $content, 'class="more-link"' ) ) ? true : false;
1874
-
1875
- // If auto_ex is on.
1876
- if ( $autoex ) {
1877
-
1878
- // Build an excerpt if one does not exist.
1879
- if ( ! $has_more_link ) {
1880
-
1881
- $is_singular = ( is_singular( $post->post_type ) ) ? true : false;
1882
-
1883
- if ( $is_singular ) {
1884
- // If it's a single post, we don't need the 'more' link.
1885
- $more_link_text = '';
1886
- $more_link = '';
1887
- } else {
1888
- // The default $more_link_text.
1889
- if ( isset( $wpmem->autoex[ $post->post_type ]['text'] ) && '' != $wpmem->autoex[ $post->post_type ]['text'] ) {
1890
- $more_link_text = __( $wpmem->autoex[ $post->post_type ]['text'], 'wp-members' );
1891
- } else {
1892
- $more_link_text = __( '(more&hellip;)' );
1893
- }
1894
- // The default $more_link.
1895
- $more_link = ' <a href="'. get_permalink( $post->ID ) . '" class="more-link">' . $more_link_text . '</a>';
1896
- }
1897
-
1898
- // Apply the_content_more_link filter if one exists (will match up all 'more' link text).
1899
- /** This filter is documented in /wp-includes/post-template.php */
1900
- $more_link = apply_filters( 'the_content_more_link', $more_link, $more_link_text );
1901
-
1902
- $defaults = array(
1903
- 'length' => $autoex['length'],
1904
- 'more_link' => $more_link,
1905
- 'blocked_only' => false,
1906
- );
1907
- /**
1908
- * Filter auto excerpt defaults.
1909
- *
1910
- * @since 3.0.9
1911
- * @since 3.1.5 Deprecated add_ellipsis, strip_tags, close_tags, parse_shortcodes, strip_shortcodes.
1912
- *
1913
- * @param array {
1914
- * An array of settings to override the function defaults.
1915
- *
1916
- * @type int $length The default length of the excerpt.
1917
- * @type string $more_link The more link HTML.
1918
- * @type boolean $blocked_only Run autoexcerpt only on blocked content. default: false.
1919
- * }
1920
- * @param string $post->ID The post ID.
1921
- * @param string $post->post_type The content's post type.
1922
- */
1923
- $args = apply_filters( 'wpmem_auto_excerpt_args', '', $post->ID, $post->post_type );
1924
-
1925
- // Merge settings.
1926
- $args = wp_parse_args( $args, $defaults );
1927
-
1928
- // Are we only excerpting blocked content?
1929
- if ( $args['blocked_only'] ) {
1930
- $post_meta = get_post_meta( $post->ID, '_wpmem_block', true );
1931
- if ( 1 == $wpmem->block[ $post->post_type ] ) {
1932
- // Post type is blocked, if post meta unblocks it, don't do excerpt.
1933
- $do_excerpt = ( "0" == $post_meta ) ? false : true;
1934
- } else {
1935
- // Post type is unblocked, if post meta blocks it, do excerpt.
1936
- $do_excerpt = ( "1" == $post_meta ) ? true : false;
1937
- }
1938
- } else {
1939
- $do_excerpt = true;
1940
- }
1941
-
1942
- if ( true === $do_excerpt ) {
1943
- $content = wp_trim_words( $content, $args['length'], $args['more_link'] );
1944
- // Check if the more link was added (note: singular has no more_link):
1945
- if ( ! $is_singular && ! strpos( $content, $args['more_link'] ) ) {
1946
- $content = $content . $args['more_link'];
1947
- }
1948
- }
1949
- }
1950
- }
1951
- } else {
1952
- $post_id = false;
1953
- $post_type = false;
1954
- }
1955
-
1956
- /**
1957
- * Filter the auto excerpt.
1958
- *
1959
- * @since 2.8.1
1960
- * @since 3.0.9 Added post ID and post type parameters.
1961
- * @since 3.2.5 Post ID and post type may be false if there is no post object.
1962
- *
1963
- * @param string $content The content excerpt.
1964
- * @param string $post_id The post ID.
1965
- * @param string $post_type The content's post type.
1966
- */
1967
- $content = apply_filters( 'wpmem_auto_excerpt', $content, $post_id, $post_type );
1968
-
1969
- // Return the excerpt.
1970
- return $content;
1971
- }
1972
-
1973
- /**
1974
- * Convert form tag.
1975
- *
1976
- * @todo This is temporary to handle form tag conversion.
1977
- *
1978
- * @since 3.1.7
1979
- * @since 3.2.3 Moved to WP_Members class.
1980
- * @since 3.3.0 Removed unnecessary tags.
1981
- *
1982
- * @param string $tag
1983
- * @return string $tag
1984
- */
1985
- function convert_tag( $tag ) {
1986
- switch ( $tag ) {
1987
- case 'new':
1988
- return 'register';
1989
- break;
1990
- case 'edit':
1991
- case 'update':
1992
- return 'profile';
1993
- break;
1994
- default:
1995
- return $tag;
1996
- break;
1997
- }
1998
- return $tag;
1999
- }
2000
-
2001
- /**
2002
- * Loads translation files.
2003
- *
2004
- * @since 3.0.0
2005
- * @since 3.2.5 Moved to main object, dropped wpmem_ stem.
2006
- */
2007
- function load_textdomain() {
2008
-
2009
- // @see: https://ulrich.pogson.ch/load-theme-plugin-translations for notes on changes.
2010
-
2011
- // Plugin textdomain.
2012
- $domain = 'wp-members';
2013
-
2014
- // Wordpress locale.
2015
- /** This filter is documented in wp-includes/l10n.php */
2016
- $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
2017
-
2018
- /**
2019
- * Filter translation file.
2020
- *
2021
- * If the translate.wordpress.org language pack is available, it will
2022
- * be /wp-content/languages/plugins/wp-members-{locale}.mo by default.
2023
- * You can filter this if you want to load a language pack from a
2024
- * different location (or different file name).
2025
- *
2026
- * @since 3.0.0
2027
- * @since 3.2.0 Added locale as a parameter.
2028
- *
2029
- * @param string $file The translation file to load.
2030
- * @param string $locale The current locale.
2031
- */
2032
- $file = apply_filters( 'wpmem_localization_file', trailingslashit( WP_LANG_DIR ) . 'plugins/' . $domain . '-' . $locale . '.mo', $locale );
2033
-
2034
- $loaded = load_textdomain( $domain, $file );
2035
- if ( $loaded ) {
2036
- return $loaded;
2037
- } else {
2038
- /**
2039
- * Filter translation directory.
2040
- *
2041
- * @since 3.0.3
2042
- * @since 3.2.0 Added locale as a parameter.
2043
- *
2044
- * @param string $dir The translation directory.
2045
- * @param string $locale The current locale.
2046
- */
2047
- $dir = apply_filters( 'wpmem_localization_dir', basename( $this->path ) . '/i18n/languages/', $locale );
2048
- load_plugin_textdomain( $domain, FALSE, $dir );
2049
- }
2050
- return;
2051
- }
2052
-
2053
- /**
2054
- * Load default tos template.
2055
- *
2056
- * @since 3.2.8
2057
- */
2058
- function load_default_tos() {
2059
- // Check for custom template or load default.
2060
- $custom_template = get_stylesheet_directory() . '/wp-members/templates/tos.php';
2061
- if ( file_exists( $custom_template ) ) {
2062
- require_once( $custom_template );
2063
- } else {
2064
- require_once( $this->path . 'templates/tos.php' );
2065
- }
2066
- }
2067
-
2068
- /**
2069
- * Builds defaults for login/out links/buttons.
2070
- *
2071
- * @since 3.3.5
2072
- *
2073
- * @param array $args
2074
- * @return string $html
2075
- */
2076
- function loginout_args( $args = array() ) {
2077
- $defaults = array(
2078
- 'format' => ( isset( $args['format'] ) ) ? $args['format'] : 'link',
2079
- 'login_redirect_to' => ( isset( $args['login_redirect_to'] ) ) ? $args['login_redirect_to'] : wpmem_current_url(),
2080
- 'logout_redirect_to' => ( isset( $args['logout_redirect_to'] ) ) ? $args['logout_redirect_to'] : wpmem_current_url(), // @todo - This is not currently active.
2081
- 'login_text' => ( isset( $args['login_text'] ) ) ? $args['login_text'] : __( 'log in', 'wp-members' ),
2082
- 'logout_text' => ( isset( $args['logout_text'] ) ) ? $args['logout_text'] : __( 'log out', 'wp-members' ),
2083
- 'class' => ( isset( $args['class'] ) ) ? $args['class'] : 'wpmem_loginout_link',
2084
- 'id' => ( isset( $args['id'] ) ) ? $args['id'] : 'wpmem_loginout_link',
2085
- );
2086
- $args = wp_parse_args( $args, $defaults );
2087
- $redirect = ( is_user_logged_in() ) ? $args['logout_redirect_to'] : $args['login_redirect_to'];
2088
- $text = ( is_user_logged_in() ) ? $args['logout_text'] : $args['login_text'];
2089
- if ( is_user_logged_in() ) {
2090
- /** This filter is defined in /inc/dialogs.php */
2091
- $link = apply_filters( 'wpmem_logout_link', add_query_arg( 'a', 'logout' ) );
2092
- } else {
2093
- $link = wpmem_login_url( $redirect );
2094
- }
2095
-
2096
- if ( 'button' == $args['format'] ) {
2097
- $html = '<form action="' . $link . '" id="' . $args['id'] . '" class="' . $args['class'] . '">';
2098
- $html.= ( is_user_logged_in() ) ? '<input type="hidden" name="a" value="logout" />' : '';
2099
- $html.= '<input type="submit" value="' . $text . '" /></form>';
2100
- } else {
2101
- $html = sprintf( '<a href="%s" id="%" class="%s">%s</a>', $link, $args['id'], $args['class'], $text );
2102
- }
2103
- return $html;
2104
- }
2105
-
2106
- /**
2107
- * Filters the password URL to point to the WP-Members process.
2108
- *
2109
- * @since 3.3.5
2110
- */
2111
- function lost_pwd_url( $lostpwd_url, $redirect ) {
2112
- return wpmem_profile_url( 'pwdreset' );
2113
- }
2114
-
2115
- /**
2116
- * Filters the login error message to display the WP login error.
2117
- *
2118
- * @since 3.3.5
2119
- */
2120
- function login_error( $args = array() ) {
2121
- if ( $this->error ) {
2122
- $args['heading_before'] = '';
2123
- $args['heading'] = '';
2124
- $args['heading_after'] = '';
2125
- $args['message'] = $this->error;
2126
- }
2127
- return $args;
2128
- }
2129
  } // End of WP_Members class.
1
+ <?php
2
+ /**
3
+ * The WP_Members Class.
4
+ *
5
+ * This is the main WP_Members object class. This class contains functions
6
+ * for loading settings, shortcodes, hooks to WP, plugin dropins, constants,
7
+ * and registration fields. It also manages whether content should be blocked.
8
+ *
9
+ * @package WP-Members
10
+ * @subpackage WP_Members Object Class
11
+ * @since 3.0.0
12
+ */
13
+
14
+ // Exit if accessed directly.
15
+ if ( ! defined( 'ABSPATH' ) ) {
16
+ exit();
17
+ }
18
+
19
+ class WP_Members {
20
+
21
+ /**
22
+ * Plugin version.
23
+ *
24
+ * @since 3.0.0
25
+ * @access public
26
+ * @var string
27
+ */
28
+ public $version = WPMEM_VERSION;
29
+
30
+ /**
31
+ * Database version
32
+ *
33
+ * @since 3.2.2
34
+ * @access public
35
+ * @var string
36
+ */
37
+ public $db_version = WPMEM_DB_VERSION;
38
+
39
+ /**
40
+ * Plugin path.
41
+ *
42
+ * @since 3.3.0
43
+ * @access public
44
+ * @var string
45
+ */
46
+ public $path;
47
+
48
+ /**
49
+ * Plugin __FILE__.
50
+ *
51
+ * @since 3.3.0
52
+ * @access public
53
+ * @var string
54
+ */
55
+ public $name;
56
+
57
+ /**
58
+ * Plugin slug.
59
+ *
60
+ * @since 3.3.0
61
+ * @access public
62
+ * @var string
63
+ */
64
+ public $slug;
65
+
66
+ /**
67
+ * Plugin URL.
68
+ *
69
+ * @since 3.3.0
70
+ * @access public
71
+ * @var string
72
+ */
73
+ public $url;
74
+
75
+
76
+ /**
77
+ * Content block settings.
78
+ *
79
+ * @since 3.0.0
80
+ * @access public
81
+ * @var array
82
+ */
83
+ public $block;
84
+
85
+ /**
86
+ * Excerpt settings.
87
+ *
88
+ * @since 3.0.0
89
+ * @access public
90
+ * @var array
91
+ */
92
+ public $show_excerpt;
93
+
94
+ /**
95
+ * Show login form settings.
96
+ *
97
+ * @since 3.0.0
98
+ * @access public
99
+ * @var array
100
+ */
101
+ public $show_login;
102
+
103
+ /**
104
+ * Show registration form settings.
105
+ *
106
+ * @since 3.0.0
107
+ * @access public
108
+ * @var array
109
+ */
110
+ public $show_reg;
111
+
112
+ /**
113
+ * Auto-excerpt settings.
114
+ *
115
+ * @since 3.0.0
116
+ * @access public
117
+ * @var array
118
+ */
119
+ public $autoex;
120
+
121
+ /**
122
+ * Notify admin settings.
123
+ *
124
+ * @since 3.0.0
125
+ * @access public
126
+ * @var string
127
+ */
128
+ public $notify;
129
+
130
+ /**
131
+ * Moderated registration settings.
132
+ *
133
+ * @since 3.0.0
134
+ * @access public
135
+ * @var string
136
+ */
137
+ public $mod_reg;
138
+
139
+ /**
140
+ * Captcha settings.
141
+ *
142
+ * @since 3.0.0
143
+ * @access public
144
+ * @var array
145
+ */
146
+ public $captcha;
147
+
148
+ /**
149
+ * Enable expiration extension settings.
150
+ *
151
+ * @since 3.0.0
152
+ * @access public
153
+ * @var string
154
+ */
155
+ public $use_exp;
156
+
157
+ /**
158
+ * Expiration extension enable trial period.
159
+ *
160
+ * @since 3.0.0
161
+ * @access public
162
+ * @var string
163
+ */
164
+ public $use_trial;
165
+
166
+ /**
167
+ *
168
+ *
169
+ * @since 3.0.0
170
+ * @access public
171
+ * @var array
172
+ */
173
+ public $warnings;
174
+
175
+ /**
176
+ * Enable drop-ins setting.
177
+ *
178
+ * @since 3.1.9
179
+ * @access public
180
+ * @var string
181
+ */
182
+ public $dropins = 0;
183
+
184
+ /**
185
+ * Container for enabled dropins.
186
+ *
187
+ * @since 3.1.9
188
+ * @access public
189
+ * @var array
190
+ */
191
+ public $dropins_enabled = array();
192
+
193
+ /**
194
+ * Current plugin action container.
195
+ *
196
+ * @since 3.0.0
197
+ * @access public
198
+ * @var string
199
+ */
200
+ public $action;
201
+
202
+ /**
203
+ * Regchk container.
204
+ *
205
+ * @since 3.0.0
206
+ * @access public
207
+ * @var string
208
+ */
209
+ public $regchk;
210
+
211
+ /**
212
+ * User page settings.
213
+ *
214
+ * @since 3.0.0
215
+ * @access public
216
+ * @var array
217
+ */
218
+ public $user_pages;
219
+
220
+ /**
221
+ * Custom Post Type settings.
222
+ *
223
+ * @since 3.0.0
224
+ * @access public
225
+ * @var array
226
+ */
227
+ public $post_types;
228
+
229
+ /**
230
+ * Setting for applying texturization.
231
+ *
232
+ * @since 3.1.7
233
+ * @access public
234
+ * @var boolean
235
+ */
236
+ public $texturize;
237
+
238
+ /**
239
+ * Enable product creation.
240
+ *
241
+ * @since 3.2.0
242
+ * @access public
243
+ * @var boolean
244
+ */
245
+ public $enable_products;
246
+
247
+ /**
248
+ * Enable logged-in menu clones.
249
+ *
250
+ * @since 3.2.0
251
+ * @access public
252
+ * @var string
253
+ */
254
+ public $clone_menus;
255
+
256
+ /**
257
+ * Container for error messages.
258
+ *
259
+ * @since 3.2.0
260
+ * @access public
261
+ * @var string
262
+ */
263
+ public $error;
264
+
265
+ /**
266
+ * Container for admin notices.
267
+ *
268
+ * @since 3.3.0
269
+ * @access public
270
+ * @var array
271
+ */
272
+ public $admin_notices;
273
+
274
+ /**
275
+ * Container for stylesheet setting.
276
+ *
277
+ * @since 3.2.7
278
+ * @access public
279
+ * @var string
280
+ */
281
+ public $select_style;
282
+
283
+ /**
284
+ * Container for dropin folder location.
285
+ *
286
+ * @since 3.3.0
287
+ * @access public
288
+ * @var string
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
+ * Temporary setting for activation link.
303
+ * Will default to 0 until 3.4.0, then 1 until 3.5.0
304
+ * at which point we'll remove the old process.
305
+ *
306
+ * @since 3.3.5
307
+ * @access public
308
+ * @var string
309
+ */
310
+ public $act_link = 0;
311
+
312
+ /**
313
+ * Temporary setting for password reset.
314
+ * Will default to 0 until 3.4.0, then 1 until 3.5.0
315
+ * at which point we'll remove the old process.
316
+ *
317
+ * @since 3.3.5
318
+ * @access public
319
+ * @var string
320
+ */
321
+ public $pwd_link = 1;
322
+
323
+ /**
324
+ * Temporary settings for login errors.
325
+ * Will default to 0 until 3.4.0.
326
+ *
327
+ * @since 3.3.5
328
+ * @access public
329
+ * @var string
330
+ */
331
+ public $login_error = 1;
332
+
333
+ /**
334
+ * Default file upload directory.
335
+ *
336
+ * @since 3.3.8
337
+ * @access public
338
+ * @var string
339
+ */
340
+ public $upload_base = 'wpmembers';
341
+
342
+ /**
343
+ * Plugin initialization function.
344
+ *
345
+ * @since 3.0.0
346
+ * @since 3.1.6 Dependencies now loaded by object.
347
+ */
348
+ function __construct() {
349
+
350
+ // Constants.
351
+ $this->path = plugin_dir_path( __DIR__ );
352
+ $this->name = $this->path . 'wp-members.php';
353
+ $this->slug = substr( basename( $this->name ), 0, -4 );
354
+ $this->url = plugin_dir_url ( __DIR__ );
355
+
356
+ // Load dependent files.
357
+ $this->load_dependencies();
358
+
359
+ /**
360
+ * Filter the options before they are loaded into constants.
361
+ *
362
+ * @since 2.9.0
363
+ * @since 3.0.0 Moved to the WP_Members class.
364
+ *
365
+ * @param array $this->settings An array of the WP-Members settings.
366
+ */
367
+ $settings = apply_filters( 'wpmem_settings', get_option( 'wpmembers_settings' ) );
368
+
369
+ // Validate that v3 settings are loaded.
370
+ if ( ! isset( $settings['version'] )
371
+ || $settings['version'] != $this->version
372
+ || ! isset( $settings['db_version'] )
373
+ || $settings['db_version'] != $this->db_version ) {
374
+ /**
375
+ * Load installation routine.
376
+ */
377
+ require_once( $this->path . 'includes/install.php' );
378
+ // Update settings.
379
+ /** This filter is documented in /inc/class-wp-members.php */
380
+ $settings = apply_filters( 'wpmem_settings', wpmem_do_install() );
381
+ }
382
+
383
+ // Assemble settings.
384
+ foreach ( $settings as $key => $val ) {
385
+ $this->$key = $val;
386
+ }
387
+
388
+ $this->load_user_pages();
389
+ $this->set_style();
390
+
391
+ $this->forms = new WP_Members_Forms; // Load forms.
392
+ $this->api = new WP_Members_API; // Load api.
393
+ $this->shortcodes = new WP_Members_Shortcodes(); // Load shortcodes.
394
+ $this->membership = new WP_Members_Products(); // Load membership plans
395
+ $this->email = new WP_Members_Email; // Load email functions
396
+ $this->user = new WP_Members_User( $this ); // Load user functions.
397
+ $this->menus = new WP_Members_Menus();
398
+ $this->dialogs = new WP_Members_Dialogs();
399
+ if ( $this->clone_menus ) {
400
+ $this->menus_clone = new WP_Members_Clone_Menus(); // Load clone menus.
401
+ }
402
+ if ( 1 == $this->pwd_link ) {
403
+ $this->pwd_reset = new WP_Members_Pwd_Reset;
404
+ }
405
+ if ( 1 == $this->act_link ) {
406
+ $this->act_newreg = new WP_Members_Validation_Link;
407
+ }
408
+
409
+ // @todo Is this a temporary fix?
410
+ $this->email->load_from();
411
+
412
+ /**
413
+ * Fires after main settings are loaded.
414
+ *
415
+ * @since 3.0
416
+ * @deprecated 3.2.0 Use wpmem_after_init instead.
417
+ */
418
+ do_action( 'wpmem_settings_loaded' );
419
+
420
+ // Preload the expiration module, if available.
421
+ $exp_active = ( function_exists( 'wpmem_exp_init' ) || function_exists( 'wpmem_set_exp' ) ) ? true : false;
422
+ define( 'WPMEM_EXP_MODULE', $exp_active );
423
+
424
+ // Load actions and filters.
425
+ $this->load_hooks();
426
+
427
+ // Load contants.
428
+ $this->load_constants();
429
+
430
+ // Load dropins.
431
+ if ( $this->dropins ) {
432
+ $this->load_dropins();
433
+ }
434
+
435
+ // Check for anything that we should stop execution for (currently just the default tos).
436
+ if ( 'display' == wpmem_get( 'tos', false, 'get' ) ) {
437
+ // If themes are not loaded, we don't need them.
438
+ $user_themes = ( ! defined( 'WP_USE_THEMES' ) ) ? define( 'WP_USE_THEMES', false ) : '';
439
+ $this->load_default_tos();
440
+ die();
441
+ }
442
+ }
443
+
444
+ /**
445
+ * Plugin initialization function to load hooks.
446
+ *
447
+ * @since 3.0.0
448
+ */
449
+ function load_hooks() {
450
+
451
+ /**
452
+ * Fires before action and filter hooks load.
453
+ *
454
+ * @since 3.0.0
455
+ * @since 3.1.6 Fires before hooks load.
456
+ */
457
+ do_action( 'wpmem_load_hooks' );
458
+
459
+ // Add actions.
460
+
461
+ add_action( 'init', array( $this, 'load_textdomain' ) ); //add_action( 'plugins_loaded', 'wpmem_load_textdomain' );
462
+ add_action( 'init', array( $this->membership, 'add_cpt' ), 0 ); // Adds membership plans custom post type.
463
+ add_action( 'widgets_init', array( $this, 'widget_init' ) ); // initializes the widget
464
+ add_action( 'admin_init', array( $this, 'load_admin' ) ); // check user role to load correct dashboard
465
+ add_action( 'rest_api_init', array( $this, 'rest_init' ) );
466
+ add_action( 'template_redirect', array( $this, 'get_action' ) );
467
+ add_action( 'login_enqueue_scripts', array( $this, 'enqueue_style_wp_login' ) ); // styles the native registration
468
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) ); // Enqueues the stylesheet.
469
+ add_action( 'wp_enqueue_scripts', array( $this, 'loginout_script' ) );
470
+ add_action( 'pre_get_posts', array( $this, 'do_hide_posts' ), 20 );
471
+ add_action( 'customize_register', array( $this, 'customizer_settings' ) );
472
+ add_action( 'admin_menu', 'wpmem_admin_options' ); // adds admin menu
473
+ add_action( 'wp_footer', array( $this, 'invisible_captcha' ) );
474
+
475
+ if ( is_user_logged_in() ) {
476
+ add_action( 'wpmem_pwd_change', array( $this->user, 'set_password' ), 9, 2 );
477
+ add_action( 'wpmem_pwd_change', array( $this->user, 'set_as_logged_in' ), 10 );
478
+ }
479
+
480
+ add_action( 'register_form', 'wpmem_wp_register_form' ); // adds fields to the default wp registration
481
+
482
+ if ( wpmem_is_woo_active() ) {
483
+
484
+ // Handle "My Account" page registration.
485
+ if ( isset( $this->woo['add_my_account_fields'] ) && 1 == $this->woo['add_my_account_fields'] ) {
486
+ add_action( 'woocommerce_register_form', 'wpmem_woo_register_form' );
487
+ add_action( 'woocommerce_register_post', 'wpmem_woo_reg_validate', 10, 3 );
488
+ }
489
+ // Handle Registration checkout
490
+ if ( isset( $this->woo['add_checkout_fields'] ) && 1 == $this->woo['add_checkout_fields'] && ! is_user_logged_in() ) {
491
+ add_filter( 'woocommerce_checkout_fields', 'wpmem_woo_checkout_form' );
492
+ add_action( 'woocommerce_checkout_update_order_meta', 'wpmem_woo_checkout_update_meta' );
493
+ //add_action( 'woocommerce_save_account_details_errors', 'wpmem_woo_reg_validate' );
494
+ add_action( 'woocommerce_form_field_multicheckbox', 'wpmem_form_field_wc_custom_field_types', 10, 4 );
495
+ add_action( 'woocommerce_form_field_multiselect', 'wpmem_form_field_wc_custom_field_types', 10, 4 );
496
+ add_action( 'woocommerce_form_field_radio', 'wpmem_form_field_wc_custom_field_types', 10, 4 );
497
+ add_action( 'woocommerce_form_field_select', 'wpmem_form_field_wc_custom_field_types', 10, 4 );
498
+ add_action( 'woocommerce_form_field_checkbox', 'wpmem_form_field_wc_custom_field_types', 10, 4 );
499
+ }
500
+ }
501
+
502
+ // Add filters.
503
+ add_filter( 'the_content', array( $this, 'do_securify' ), 99 );
504
+ add_filter( 'comments_open', array( $this, 'do_securify_comments' ), 99, 2 ); // securifies the comments
505
+ add_filter( 'wpmem_securify', array( $this, 'reg_securify' ) ); // adds success message on login form if redirected
506
+ add_filter( 'rest_prepare_post', array( $this, 'do_securify_rest' ), 10, 3 );
507
+ add_filter( 'rest_prepare_page', array( $this, 'do_securify_rest' ), 10, 3 );
508
+ foreach( $this->post_types as $post_type ) {
509
+ add_filter( "rest_prepare_{$post_type}", array( $this, 'do_securify_rest' ), 10, 3 );
510
+ }
511
+
512
+ //add_filter( 'query_vars', array( $this, 'add_query_vars' ), 10, 2 ); // adds custom query vars
513
+ add_filter( 'get_pages', array( $this, 'filter_get_pages' ) );
514
+ add_filter( 'wp_get_nav_menu_items', array( $this, 'filter_nav_menu_items' ), null, 3 );
515
+ add_filter( 'get_previous_post_where', array( $this, 'filter_get_adjacent_post_where' ) );
516
+ add_filter( 'get_next_post_where', array( $this, 'filter_get_adjacent_post_where' ) );
517
+ add_filter( 'allow_password_reset', array( $this->user, 'no_reset' ) ); // no password reset for non-activated users
518
+
519
+ // If registration is moderated, check for activation (blocks backend login by non-activated users).
520
+ if ( $this->mod_reg == 1 ) {
521
+ add_filter( 'authenticate', array( $this->user, 'check_activated' ), 99, 3 );
522
+ }
523
+
524
+ // Replace login error object.
525
+ if ( 1 == $this->login_error ) {
526
+ // @todo I think we can do this without the filter now that
527
+ // the main messaging function has been updated.
528
+ // add_filter( 'wpmem_login_failed_args', array( $this->dialogs, 'login_error' ) );
529
+ add_filter( 'lostpassword_url', array( $this, 'lost_pwd_url' ), 10, 2 );
530
+ }
531
+
532
+ if ( function_exists( 'wpmem_custom_translation_strings' ) ) {
533
+ add_filter( 'wpmem_fields', array( $this->forms, 'localize_fields' ), 9 );
534
+ }
535
+ /**
536
+ * Fires after action and filter hooks load.
537
+ *
538
+ * @since 3.0.0
539
+ * @since 3.1.6 Was wpmem_load_hooks, now wpmem_hooks_loaded.
540
+ */
541
+ do_action( 'wpmem_hooks_loaded' );
542
+ }
543
+
544
+ /**
545
+ * Load drop-ins.
546
+ *
547
+ * @since 3.0.0
548
+ *
549
+ * @todo This is experimental. The function and its operation is subject to change.
550
+ */
551
+ function load_dropins() {
552
+
553
+ /**
554
+ * Fires before dropins load (for adding additional drop-ins).
555
+ *
556
+ * @since 3.0.0
557
+ * @since 3.1.6 Fires before dropins.
558
+ */
559
+ do_action( 'wpmem_load_dropins' );
560
+
561
+ /**
562
+ * Filters the drop-in file directory.
563
+ *
564
+ * @since 3.0.0
565
+ * @since 3.3.0 Filter previously unpublished, changed hook name.
566
+ *
567
+ * @param string $wpmem->dropin_dir The drop-in file directory.
568
+ */
569
+ $dir = apply_filters( 'wpmem_dropin_dir', $this->dropin_dir );
570
+
571
+ // Load any drop-ins.
572
+ $settings = get_option( 'wpmembers_dropins' );
573
+ $this->dropins_enabled = ( $settings ) ? $settings : array();
574
+ if ( ! empty( $this->dropins_enabled ) ) {
575
+ foreach ( $this->dropins_enabled as $filename ) {
576
+ $dropin = $dir . $filename;
577
+ if ( file_exists( $dropin ) ) {
578
+ include_once( $dropin );
579
+ }
580
+ }
581
+ }
582
+
583
+ /**
584
+ * Fires before dropins load (for adding additional drop-ins).
585
+ *
586
+ * @since 3.0.0
587
+ * @since 3.1.6 Was wpmem_load_dropins, now wpmem_dropins_loaded.
588
+ */
589
+ do_action( 'wpmem_dropins_loaded' );
590
+ }
591
+
592
+ /**
593
+ * Loads pre-3.0 constants (included primarily for add-on compatibility).
594
+ *
595
+ * @since 3.0.0
596
+ * @since 3.3.0 Deprecated all but exp and trl constants.
597
+ */
598
+ function load_constants() {
599
+ ( ! defined( 'WPMEM_MOD_REG' ) ) ? define( 'WPMEM_MOD_REG', $this->mod_reg ) : '';
600
+ ( ! defined( 'WPMEM_USE_EXP' ) ) ? define( 'WPMEM_USE_EXP', $this->use_exp ) : '';
601
+ ( ! defined( 'WPMEM_USE_TRL' ) ) ? define( 'WPMEM_USE_TRL', $this->use_trial ) : '';
602
+ }
603
+
604
+ /**
605
+ * Load dependent files.
606
+ *
607
+ * @since 3.1.6
608
+ */
609
+ function load_dependencies() {
610
+
611
+ /**
612
+ * Filter the location and name of the pluggable file.
613
+ *
614
+ * @since 2.9.0
615
+ * @since 3.1.6 Moved in load order to come before dependencies.
616
+ *
617
+ * @param string The path to WP-Members plugin functions file.
618
+ */
619
+ $wpmem_pluggable = apply_filters( 'wpmem_plugins_file', WP_PLUGIN_DIR . '/wp-members-pluggable.php' );
620
+
621
+ // Preload any custom functions, if available.
622
+ if ( file_exists( $wpmem_pluggable ) ) {
623
+ include( $wpmem_pluggable );
624
+ }
625
+
626
+ require_once( $this->path . 'includes/libraries/rocketgeek-utilities/loader.php' );
627
+ require_once( $this->path . 'includes/class-wp-members-api.php' );
628
+ require_once( $this->path . 'includes/class-wp-members-clone-menus.php' );
629
+ require_once( $this->path . 'includes/class-wp-members-captcha.php' );
630
+ require_once( $this->path . 'includes/class-wp-members-dialogs.php' );
631
+ require_once( $this->path . 'includes/class-wp-members-email.php' );
632
+ require_once( $this->path . 'includes/class-wp-members-forms.php' );
633
+ require_once( $this->path . 'includes/class-wp-members-menus.php' );
634
+ require_once( $this->path . 'includes/class-wp-members-products.php' );
635
+ require_once( $this->path . 'includes/class-wp-members-pwd-reset.php' );
636
+ require_once( $this->path . 'includes/class-wp-members-shortcodes.php' );
637
+ require_once( $this->path . 'includes/class-wp-members-user.php' );
638
+ require_once( $this->path . 'includes/class-wp-members-user-profile.php' );
639
+ require_once( $this->path . 'includes/class-wp-members-validation-link.php' );
640
+ require_once( $this->path . 'includes/class-wp-members-widget.php' );
641
+ require_once( $this->path . 'includes/api/api.php' );
642
+ require_once( $this->path . 'includes/api/api-email.php' );
643
+ require_once( $this->path . 'includes/api/api-forms.php' );
644
+ require_once( $this->path . 'includes/api/api-products.php' );
645
+ require_once( $this->path . 'includes/api/api-users.php' );
646
+ require_once( $this->path . 'includes/api/api-utilities.php' );
647
+ require_once( $this->path . 'includes/deprecated.php' );
648
+
649
+ require_once( $this->path . 'includes/legacy/dialogs.php' ); // File is totally deprecated at this point; eval for removal.
650
+
651
+ if ( defined( 'WP_CLI' ) && WP_CLI ) {
652
+ require_once( $this->path . 'includes/cli/class-wp-members-cli.php' );
653
+ require_once( $this->path . 'includes/cli/class-wp-members-cli-user.php' );
654
+ require_once( $this->path . 'includes/cli/class-wp-members-cli-settings.php' );
655
+ }
656
+ }
657
+
658
+ /**
659
+ * Load admin API and dependencies.
660
+ *
661
+ * Determines which scripts to load and actions to use based on the
662
+ * current users capabilities.
663
+ *
664
+ * @since 2.5.2
665
+ * @since 3.1.0 Added admin api object.
666
+ * @since 3.1.7 Moved from main plugin file as wpmem_chk_admin() to main object.
667
+ */
668
+ function load_admin() {
669
+
670
+ /**
671
+ * Fires before initialization of admin options.
672
+ *
673
+ * @since 2.9.0
674
+ */
675
+ do_action( 'wpmem_pre_admin_init' );
676
+
677
+ /**
678
+ * Load the admin api class.
679
+ *
680
+ * @since 3.1.0
681
+ */
682
+ include_once( $this->path . 'includes/admin/class-wp-members-admin-api.php' );
683
+ $this->admin = new WP_Members_Admin_API;
684
+
685
+ /**
686
+ * Fires after initialization of admin options.
687
+ *
688
+ * @since 2.9.0
689
+ */
690
+ do_action( 'wpmem_after_admin_init' );
691
+ }
692
+
693
+ /**
694
+ * Gets the requested action.
695
+ *
696
+ * @since 3.0.0
697
+ *
698
+ * @global string $wpmem_a The WP-Members action variable.
699
+ */
700
+ function get_action() {
701
+
702
+ // Get the action being done (if any).
703
+ $this->action = sanitize_text_field( wpmem_get( 'a', '', 'request' ) );
704
+
705
+ // For backward compatibility with processes that check $wpmem_a.
706
+ global $wpmem_a;
707
+ $wpmem_a = $this->action;
708
+
709
+ /**
710
+ * Fires when the wpmem action is retrieved.
711
+ *
712
+ * @since 3.1.7
713
+ */
714
+ do_action( 'wpmem_get_action' );
715
+
716
+ // Get the regchk value (if any).
717
+ $this->regchk = $this->get_regchk( $this->action );
718
+ }
719
+
720
+ /**
721
+ * Gets the regchk value.
722
+ *
723
+ * regchk is a legacy variable that contains information about the current
724
+ * action being performed. Login, logout, password, registration, profile
725
+ * update functions all return a specific value that is stored in regchk.
726
+ * This value and information about the current action can then be used to
727
+ * determine what content is to be displayed by the securify function.
728
+ *
729
+ * @since 3.0.0
730
+ *
731
+ * @global string $wpmem_a The WP-Members action variable.
732
+ *
733
+ * @param string $action The current action.
734
+ * @return string The regchk value.
735
+ */
736
+ function get_regchk( $action ) {
737
+
738
+ switch ( $action ) {
739
+
740
+ case 'login':
741
+ $regchk = $this->user->login();
742
+ break;
743
+
744
+ case 'logout':
745
+ $regchk = $this->user->logout();
746
+ break;
747
+
748
+ case 'pwdchange':
749
+ $regchk = $this->user->password_update( 'change' );
750
+ break;
751
+
752
+ case 'pwdreset':
753
+ $regchk = $this->user->password_update( 'reset' );
754
+ break;
755
+
756
+ case 'getusername':
757
+ $regchk = $this->user->retrieve_username();
758
+ break;
759
+
760
+ case 'register':
761
+ case 'update':
762
+ $regchk = wpmem_user_register( $action );
763
+ break;
764
+
765
+ default:
766
+ $regchk = ( isset( $regchk ) ) ? $regchk : '';
767
+ break;
768
+ }
769
+
770
+ /**
771
+ * Filter wpmem_regchk.
772
+ *
773
+ * The value of regchk is determined by functions that may be run in the get_regchk function.
774
+ * This value determines what happens in the wpmem_securify() function.
775
+ *
776
+ * @since 2.9.0
777
+ * @since 3.0.0 Moved to get_regchk() in WP_Members object.
778
+ *
779
+ * @param string $this->regchk The value of wpmem_regchk.
780
+ * @param string $this->action The $wpmem_a action.
781
+ */
782
+ $regchk = apply_filters( 'wpmem_regchk', $regchk, $action );
783
+
784
+ // Legacy global variable for use with older extensions.
785
+ global $wpmem_regchk;
786
+ $wpmem_regchk = $regchk;
787
+
788
+ return $regchk;
789
+ }
790
+
791
+ /**
792
+ * Determines if content should be blocked.
793
+ *
794
+ * This function was originally stand alone in the core file and
795
+ * was moved to the WP_Members class in 3.0.
796
+ *
797
+ * @since 3.0.0
798
+ * @since 3.3.0 Added $post_id
799
+ * @since 3.4.0 Added $is_post_check to allow for individual post checking.
800
+ *
801
+ * @global object $post The WordPress Post object.
802
+ *
803
+ * @param int $post_id
804
+ * @return bool $block true|false
805
+ */
806
+ function is_blocked( $post_id = false ) {
807
+
808
+ global $post;
809
+
810
+ $is_post_check = ( false === $post_id ) ? false : true;
811
+
812
+ if ( $post || $post_id ) {
813
+
814
+ $the_post = ( false === $post_id ) ? $post : get_post( $post_id );
815
+
816
+ $meta = wpmem_get_block_setting( $the_post->ID );
817
+
818
+ // Backward compatibility for old block/unblock meta.
819
+ if ( ! $meta ) {
820
+ // Check for old meta.
821
+ $old_block = get_post_meta( $the_post->ID, 'block', true );
822
+ $old_unblock = get_post_meta( $the_post->ID, 'unblock', true );
823
+ $meta = ( $old_block ) ? 1 : ( ( $old_unblock ) ? 0 : $meta );
824
+ }
825
+
826
+ // Setup defaults.
827
+ $defaults = array(
828
+ 'post_id' => $the_post->ID,
829
+ 'post_type' => $the_post->post_type,
830
+ 'block' => ( isset( $this->block[ $the_post->post_type ] ) && $this->block[ $the_post->post_type ] == 1 ) ? true : false,
831
+ 'block_meta' => $meta,
832
+ 'block_type' => ( isset( $this->block[ $the_post->post_type ] ) ) ? $this->block[ $the_post->post_type ] : 0,
833
+ );
834
+
835
+ /**
836
+ * Filter the block arguments.
837
+ *
838
+ * @since 2.9.8
839
+ * @since 3.0.0 Moved to is_blocked() in WP_Members object.
840
+ * @since 3.3.0 Passes $defaults, second argument deprecated.
841
+ *
842
+ * @param array $args $defaults.
843
+ * @param array $defaults Deprecated 3.3.0.
844
+ */
845
+ $args = apply_filters( 'wpmem_block_args', $defaults, $defaults );
846
+
847
+ // Merge $args with defaults.
848
+ $args = ( wp_parse_args( $args, $defaults ) );
849
+
850
+ if ( $is_post_check || is_single() || is_page() || wpmem_is_rest() ) {
851
+ switch( $args['block_type'] ) {
852
+ case 1: // If content is blocked by default.
853
+ $args['block'] = ( $args['block_meta'] == '0' ) ? false : $args['block'];
854
+ break;
855
+ case 0 : // If content is unblocked by default.
856
+ $args['block'] = ( $args['block_meta'] == '1' ) ? true : $args['block'];
857
+ break;
858
+ }
859
+
860
+ } else {
861
+ $args['block'] = false;
862
+ }
863
+
864
+ } else {
865
+ $args = array( 'block' => false );
866
+ }
867
+
868
+ // Don't block user pages.
869
+ $args['block'] = ( in_array( get_permalink(), $this->user_pages ) ) ? false : $args['block'];
870
+
871
+ /**
872
+ * Filter the block boolean.
873
+ *
874
+ * @since 2.7.5
875
+ *
876
+ * @param bool $args['block']
877
+ * @param array $args {
878
+ * An array of arguments used in the function.
879
+ *
880
+ * @type string $post_id
881
+ * @type string $post_type
882
+ * @type string $block
883
+ * @type string $block_meta
884
+ * @tyep string $block_type
885
+ * }
886
+ */
887
+ return apply_filters( 'wpmem_block', $args['block'], $args );
888
+ }
889
+
890
+ /**
891
+ * The Securify Content Filter.
892
+ *
893
+ * This is the primary function that picks up where get_action() leaves off.
894
+ * Determines whether content is shown or hidden for both post and pages. This
895
+ * is a filter function for the_content.
896
+ *
897
+ * @link https://developer.wordpress.org/reference/functions/the_content/
898
+ * @link https://developer.wordpress.org/reference/hooks/the_content/
899
+ *
900
+ * @since 3.0.0
901
+ *
902
+ * @global object $post The WordPress Post object.
903
+ * @global object $wpmem The WP_Members object.
904
+ * @global string $wpmem_themsg Contains messages to be output.
905
+ * @param string $content
906
+ * @return string $content
907
+ */
908
+ function do_securify( $content = null ) {
909
+
910
+ global $post, $wpmem, $wpmem_themsg;
911
+
912
+ $orig_content = $content;
913
+
914
+ $content = ( is_single() || is_page() ) ? $content : wpmem_do_excerpt( $content );
915
+
916
+ if ( $this->regchk == "captcha" ) {
917
+ global $wpmem_captcha_err;
918
+ $wpmem_themsg = wpmem_get_text( 'reg_captcha_err' ) . '<br /><br />' . $wpmem_captcha_err;
919
+ }
920
+
921
+ // Block/unblock Posts.
922
+ if ( ! is_user_logged_in() && true == $this->is_blocked() ) {
923
+
924
+ // If there is a regchk action, show the login and/or registration forms.
925
+ if ( $this->regchk ) {
926
+
927
+ $content = wpmem_get_display_message( $this->regchk, $wpmem_themsg );
928
+ $content .= ( 'loginfailed' == $this->regchk || 'success' == $this->regchk ) ? wpmem_login_form() : wpmem_register_form();
929
+
930
+ } else {
931
+
932
+ // Toggle shows excerpt above login/reg on posts/pages.
933
+ global $wp_query;
934
+ if ( isset( $wp_query->query_vars['page'] ) && $wp_query->query_vars['page'] > 1 ) {
935
+
936
+ // Shuts down excerpts on multipage posts if not on first page.
937
+ $content = '';
938
+
939
+ } elseif ( isset( $this->show_excerpt[ $post->post_type ] ) && 1 == $this->show_excerpt[ $post->post_type ] ) {
940
+
941
+ // @todo Can this be condensed or eliminated?
942
+ $len = strpos( $content, '<span id="more' );
943
+ if ( false === $len ) {
944
+ $content = wpmem_do_excerpt( $content );
945
+ } else {
946
+ $content = substr( $content, 0, $len );
947
+ }
948
+
949
+ } else {
950
+
951
+ // Empty all content.
952
+ $content = '';
953
+
954
+ }
955
+
956
+ // Build up default view based on settings.
957
+ $content = $content . wpmem_restricted_message();
958
+ $content = ( isset( $this->show_login[ $post->post_type ] ) && 1 == $this->show_login[ $post->post_type ] ) ? $content . wpmem_login_form() : $content;
959
+ $content = ( isset( $this->show_reg[ $post->post_type ] ) && 1 == $this->show_reg[ $post->post_type ] ) ? $content . wpmem_register_form() : $content;
960
+ }
961
+
962
+ // Protects comments if expiration module is used and user is expired.
963
+ } elseif ( is_user_logged_in() && true == $this->is_blocked() ) {
964
+
965
+ // Allows for a view of the forms in the Customizer.
966
+ if ( is_customize_preview() ) {
967
+
968
+ if ( get_theme_mod( 'wpmem_show_logged_out_state', false ) ) {
969
+ $content = '';
970
+ if ( get_theme_mod( 'wpmem_show_form_message_dialog', false ) ) {
971
+ $content = $this->dialogs->login_failed();
972
+ } else {
973
+ $content = wpmem_restricted_message();
974
+ }
975
+ $content = ( isset( $this->show_login[ $post->post_type ] ) && 1 == $this->show_login[ $post->post_type ] ) ? $content . wpmem_login_form() : $content;
976
+ $content = ( isset( $this->show_reg[ $post->post_type ] ) && 1 == $this->show_reg[ $post->post_type ] ) ? $content . wpmem_register_form() : $content;
977
+ }
978
+ } else {
979
+
980
+ // @todo Test with expired membership.
981
+ if ( 1 == $this->use_exp && function_exists( 'wpmem_do_expmessage' ) ) {
982
+ /**
983
+ * Filters the user expired message used by the PayPal extension.
984
+ *
985
+ * @since 3.2.0
986
+ *
987
+ * @param string $message
988
+ * @param string $content
989
+ */
990
+ $content = apply_filters( 'wpmem_do_expmessage', wpmem_do_expmessage( $content ), $content );
991
+ }
992
+ }
993
+ }
994
+
995
+ /**
996
+ * Filter the value of $content after wpmem_securify has run.
997
+ *
998
+ * @since 2.7.7
999
+ * @since 3.0.0 Moved to new method in WP_Members Class.
1000
+ * @since 3.4.0 Added $orig_content param.
1001
+ *
1002
+ * @param string $content The content after securify has run.
1003
+ */
1004
+ $content = apply_filters( 'wpmem_securify', $content, $orig_content );
1005
+
1006
+ return $content;
1007
+
1008
+ }
1009
+
1010
+ /**
1011
+ * Securifies the comments.
1012
+ *
1013
+ * If the user is not logged in and the content is blocked
1014
+ * (i.e. wpmem->is_blocked() returns true), function loads a
1015
+ * dummy/empty comments template.
1016
+ *
1017
+ * @since 2.9.9
1018
+ * @since 3.2.0 Moved wpmem_securify_comments() to main class, renamed.
1019
+ * @since 3.3.2 Added $post_id.
1020
+ *
1021
+ * @param bool $open Whether the current post is open for comments.
1022
+ * @param int $post_id The post ID.
1023
+ * @return bool $open True if current post is open for comments, otherwise false.
1024
+ */
1025
+ function do_securify_comments( $open, $post_id ) {
1026
+
1027
+ $open = ( ! is_user_logged_in() && wpmem_is_blocked( $post_id ) ) ? false : $open;
1028
+
1029
+ /**
1030
+ * Filters whether comments are open or not.
1031
+ *
1032
+ * @since 3.0.0
1033
+ * @since 3.2.0 Moved to main class.
1034
+ * @since 3.3.2 Added $post_id.
1035
+ *
1036
+ * @param bool $open true if current post is open for comments, otherwise false.
1037
+ */
1038
+ $open = apply_filters( 'wpmem_securify_comments', $open, $post_id );
1039
+
1040
+ if ( ! $open ) {
1041
+ /** This filter is documented in wp-includes/comment-template.php */
1042
+ add_filter( 'comments_array', array( $this, 'do_securify_comments_array' ), 10, 2 );
1043
+ }
1044
+
1045
+ return $open;
1046
+ }
1047
+
1048
+ /**
1049
+ * Empties the comments array if content is blocked.
1050
+ *
1051
+ * @since 3.0.1
1052
+ * @since 3.2.0 Moved wpmem_securify_comments_array() to main class, renamed.
1053
+ *
1054
+ * @param array $comments
1055
+ * @param int $post_id
1056
+ * @return array $comments The comments array.
1057
+ */
1058
+ function do_securify_comments_array( $comments , $post_id ) {
1059
+ $comments = ( ! is_user_logged_in() && wpmem_is_blocked( $post_id ) ) ? array() : $comments;
1060
+ return $comments;
1061
+ }
1062
+
1063
+ /**
1064
+ * Handles REST request.
1065
+ *
1066
+ * @since 3.3.2
1067
+ *
1068
+ * @param WP_REST_Response $response The response object.
1069
+ * @param WP_Post $post Post object.
1070
+ * @param WP_REST_Request $request Request object.
1071
+ * @return
1072
+ */
1073
+ function do_securify_rest( $response, $post, $request ) {
1074
+
1075
+ if ( ! is_user_logged_in() ) { // @todo This needs to be changed to check for whether the user has access (for internal requests).
1076
+ // Response for restricted content
1077
+ $block_value = wpmem_is_blocked( $response->data['id'] );
1078
+ if ( $block_value ) {
1079
+ if ( isset( $response->data['content']['rendered'] ) ) {
1080
+ /**
1081
+ * Filters restricted content message.
1082
+ *
1083
+ * @since 3.3.2
1084
+ * @since 3.3.4 Added $response, $post, and $request
1085
+ *
1086
+ * @param string $message
1087
+ */
1088
+ $response->data['content']['rendered'] = apply_filters( "wpmem_securify_rest_{$post->post_type}_content", __( "You must be logged in to view this content.", 'wp-members' ), $response, $post, $request );
1089
+ }
1090
+ if ( isset( $response->data['excerpt']['rendered'] ) ) {
1091
+ /**
1092
+ * Filters restricted excerpt message.
1093
+ *
1094
+ * @since 3.3.2
1095
+ * @since 3.3.4 Added $response, $post, and $request
1096
+ *
1097
+ * @param string $message
1098
+ */
1099
+ $response->data['excerpt']['rendered'] = apply_filters( "wpmem_securify_rest_{$post->post_type}_excerpt", __( "You must be logged in to view this content.", 'wp-members' ), $response, $post, $request );
1100
+ }
1101
+ }
1102
+
1103
+ // Response for hidden content. @todo This needs to be changed to check for whether the user has access (for internal requests).
1104
+ if ( ! is_admin() && in_array( $post->ID, $this->hidden_posts() ) ) {
1105
+ return new WP_REST_Response( __( 'The page you are looking for does not exist', 'wp-members' ), 404 );
1106
+ }
1107
+ }
1108
+ return $response;
1109
+ }
1110
+
1111
+ /**
1112
+ * Adds the successful registration message on the login page if reg_nonce validates.
1113
+ *
1114
+ * @since 3.1.7
1115
+ * @since 3.2.0 Moved to wpmem object, renamed reg_securify()
1116
+ *
1117
+ * @param string $content
1118
+ * @return string $content
1119
+ */
1120
+ function reg_securify( $content ) {
1121
+ global $wpmem, $wpmem_themsg;
1122
+ $nonce = wpmem_get( 'reg_nonce', false, 'get' );
1123
+ if ( $nonce && wp_verify_nonce( $nonce, 'register_redirect' ) ) {
1124
+ $content = wpmem_get_display_message( 'success', $wpmem_themsg );
1125
+ $content = $content . wpmem_login_form();
1126
+ }
1127
+ return $content;
1128
+ }
1129
+
1130
+ /**
1131
+ * Runs if the REST API is initialized.
1132
+ *
1133
+ * @since 3.3.2
1134
+ */
1135
+ function rest_init() {
1136
+ $this->is_rest = true;
1137
+ }
1138
+
1139
+ /**
1140
+ * Gets an array of hidden post IDs.
1141
+ *
1142
+ * @since 3.2.0
1143
+ *
1144
+ * @global object $wpdb
1145
+ * @return array $hidden
1146
+ */
1147
+ function hidden_posts() {
1148
+ global $wpdb;
1149
+ $hidden = get_option( 'wpmem_hidden_posts' );
1150
+ if ( false === $hidden ) {
1151
+ $hidden = $this->update_hidden_posts();
1152
+ }
1153
+ return $hidden;
1154
+ }
1155
+
1156
+ /**
1157
+ * Updates the hidden post array transient.
1158
+ *
1159
+ * @since 3.2.0
1160
+ * @since 3.3.3 Don't include posts from post types not set as handled by WP-Members.
1161
+ *
1162
+ * @global object $wpdb
1163
+ * @return array $hidden
1164
+ */
1165
+ function update_hidden_posts() {
1166
+ global $wpdb;
1167
+ $hidden = array();
1168
+ $default_post_types = array( 'post'=>'Posts', 'page'=>'Page' );
1169
+ $post_types = array_merge( $this->post_types, $default_post_types );
1170
+ // $results = $wpdb->get_results( "SELECT post_id FROM " . $wpdb->prefix . "postmeta WHERE meta_key = '_wpmem_block' AND meta_value = 2" );
1171
+ $results = $wpdb->get_results(
1172
+ "SELECT
1173
+ p1.id,
1174
+ p1.post_type,
1175
+ m1.meta_key AS _wpmem_block
1176
+ FROM " . $wpdb->prefix . "posts p1
1177
+ JOIN " . $wpdb->prefix . "postmeta m1 ON (m1.post_id = p1.id AND m1.meta_key = '_wpmem_block')
1178
+ WHERE m1.meta_value = '2';"
1179
+ );
1180
+ foreach( $results as $result ) {
1181
+ if ( array_key_exists( $result->post_type, $post_types ) ) {
1182
+ $hidden[] = $result->id;
1183
+ }
1184
+ }
1185
+ update_option( 'wpmem_hidden_posts', $hidden );
1186
+ return $hidden;
1187
+ }
1188
+
1189
+ /**
1190
+ * Gets an array of hidden post IDs.
1191
+ *
1192
+ * @since 3.2.0
1193
+ *
1194
+ * @global stdClass $wpdb
1195
+ * @return array $hidden
1196
+ */
1197
+ function get_hidden_posts() {
1198
+ $hidden = array();
1199
+
1200
+ // Return empty array if this is the admin and user can edit posts.
1201
+ if ( is_admin() && current_user_can( 'edit_posts' ) ) {
1202
+ return $hidden;
1203
+ }
1204
+
1205
+ // If the user is not logged in, return all hidden posts.
1206
+ if ( ! is_user_logged_in() ) {
1207
+ $hidden = $this->hidden_posts();
1208
+ } else {
1209
+ // If the user is logged in.
1210
+ if ( 1 == $this->enable_products ) {
1211
+ // Get user product access.
1212
+ $hidden = $this->hidden_posts();
1213
+ $hidden = ( is_array( $hidden ) ) ? $hidden : array();
1214
+
1215
+ // Remove posts with a product the user has access to.
1216
+ foreach ( $this->membership->products as $key => $value ) {
1217
+ if ( isset( $this->user->access[ $key ] ) && ( true == $this->user->access[ $key ] || $this->user->is_current( $this->user->access[ $key ] ) ) ) {
1218
+ foreach ( $hidden as $post_id ) {
1219
+ if ( 1 == get_post_meta( $post_id, $this->membership->post_stem . $key, true ) ) {
1220
+ $hidden_key = array_search( $post_id, $hidden );
1221
+ unset( $hidden[ $hidden_key ] );
1222
+ }
1223
+ }
1224
+ }
1225
+ }
1226
+
1227
+ // Remove posts that don't have a product assignment (general login).
1228
+ foreach( $hidden as $hidden_key ) {
1229
+ $unattached = get_post_meta( $hidden_key, '_wpmem_products', true );
1230
+ if ( false == $unattached ) {
1231
+ $hidden_key = array_search( $hidden_key, $hidden );
1232
+ unset( $hidden[ $hidden_key ] );
1233
+ }
1234
+ }
1235
+ }
1236
+ }
1237
+ /**
1238
+ * Filter the hidden posts array.
1239
+ *
1240
+ * @since 3.3.4
1241
+ *
1242
+ * @param array $hidden
1243
+ */
1244
+ return apply_filters( 'wpmem_hidden_posts', $hidden );
1245
+ }
1246
+
1247
+ /**
1248
+ * Hides posts based on settings and meta.
1249
+ *
1250
+ * @since 3.2.0
1251
+ *
1252
+ * @param array $query
1253
+ * @return array $query
1254
+ */
1255
+ function do_hide_posts( $query ) {
1256
+ $hidden_posts = $this->get_hidden_posts();
1257
+ if ( ! empty( $hidden_posts ) ) {
1258
+ // Add hidden posts to post__not_in while maintaining any existing exclusions.
1259
+ $post__not_in = array_merge( $query->query_vars['post__not_in'], $hidden_posts );
1260
+ /**
1261
+ * Filter post__not_in.
1262
+ *
1263
+ * @since 3.3.4
1264
+ *
1265
+ * @param array $post__not_in
1266
+ */
1267
+ $post__not_in = apply_filters( 'wpmem_post__not_in', $post__not_in );
1268
+ $query->set( 'post__not_in', $post__not_in );
1269
+ }
1270
+ return $query;
1271
+ }
1272
+
1273
+ /**
1274
+ * Filter to hide pages for get_pages().
1275
+ *
1276
+ * @since 3.2.0
1277
+ *
1278
+ * @global object $wpdb
1279
+ * @param array $pages
1280
+ * @return array $pages
1281
+ */
1282
+ function filter_get_pages( $pages ) {
1283
+ $hidden_posts = $this->get_hidden_posts();
1284
+ if ( ! empty ( $hidden_posts ) ) {
1285
+ $new_pages = array();
1286
+ foreach ( $pages as $key => $page ) {
1287
+ if ( ! in_array( $page->ID, $hidden_posts ) ) {
1288
+ $new_pages[ $key ] = $page;
1289
+ }
1290
+ }
1291
+ $pages = $new_pages;
1292
+ }
1293
+ return $pages;
1294
+ }
1295
+
1296
+ /**
1297
+ * Filter to hide menu items.
1298
+ *
1299
+ * @since 3.2.0
1300
+ *
1301
+ * @param array $items
1302
+ * @param $menu
1303
+ * @param array $args
1304
+ * @return array $items
1305
+ */
1306
+ function filter_nav_menu_items( $items, $menu, $args ) {
1307
+ $hidden_posts = $this->get_hidden_posts();
1308
+ if ( ! empty( $hidden_posts ) ) {
1309
+ foreach ( $items as $key => $item ) {
1310
+ if ( in_array( $item->object_id, $hidden_posts ) ) {
1311
+ unset( $items[ $key ] );
1312
+ }
1313
+ }
1314
+ }
1315
+ return $items;
1316
+ }
1317
+
1318
+ /**
1319
+ * Filter to remove hidden posts from prev/next links.
1320
+ *
1321
+ * @since 3.2.4
1322
+ *
1323
+ * @global object $wpmem
1324
+ * @param string $where
1325
+ * @return string $where
1326
+ */
1327
+ function filter_get_adjacent_post_where( $where ) {
1328
+ global $wpmem;
1329
+ if ( ! is_user_logged_in() ) {
1330
+ $hidden_posts = $this->get_hidden_posts();
1331
+ if ( ! empty( $hidden_posts ) ) {
1332
+ $hidden = implode( ",", $hidden_posts );
1333
+ $where = $where . " AND p.ID NOT IN ( $hidden )";
1334
+ }
1335
+ }
1336
+ return $where;
1337
+ }
1338
+
1339
+ /**
1340
+ * Set page locations.
1341
+ *
1342
+ * Handles numeric page IDs while maintaining
1343
+ * compatibility with old full url settings.
1344
+ *
1345
+ * @since 3.0.8
1346
+ */
1347
+ function load_user_pages() {
1348
+ foreach ( $this->user_pages as $key => $val ) {
1349
+ if ( is_numeric( $val ) ) {
1350
+ if ( false !== get_post_status( $val ) ) {
1351
+ $this->user_pages[ $key ] = get_page_link( $val );
1352
+ } else {
1353
+ $notice = sprintf( __( 'You have a linked page in the WP-Members page settings that corresponds to a post ID that no longer exists. Please %s review and update the %s page settings %s.', 'wp-members' ), '<a href="' . esc_url( get_admin_url() . '/options-general.php?page=wpmem-settings&tab=options' ) . '">', $key, '</a>' );
1354
+ $this->admin_notices[] = array(
1355
+ 'type'=>'error',
1356
+ 'notice'=>$notice
1357
+ );
1358
+ }
1359
+ }
1360
+ }
1361
+ }
1362
+
1363
+ /**
1364
+ * Sets the stylesheet URL.
1365
+ *
1366
+ * @since 3.3.0
1367
+ */
1368
+ function set_style() {
1369
+ $this->cssurl = ( 'use_custom' == $this->select_style ) ? $this->cssurl : $this->url . 'assets/css/forms/' . $this->select_style . wpmem_get_suffix() . '.css'; // Set the stylesheet.
1370
+ }
1371
+
1372
+ /**
1373
+ * Returns a requested text string.
1374
+ *
1375
+ * This function manages all of the front-end facing text.
1376
+ * All defaults can be filtered using wpmem_default_text_strings.
1377
+ *
1378
+ * @since 3.1.0
1379
+ *
1380
+ * @global object $wpmem
1381
+ *
1382
+ * @param string $str
1383
+ * @return string $text
1384
+ */
1385
+ function get_text( $str ) {
1386
+ global $wpmem;
1387
+ return $wpmem->dialogs->get_text( $str );
1388
+ } // End of get_text().
1389
+
1390
+ /**
1391
+ * Initializes the WP-Members widget.
1392
+ *
1393
+ * @since 3.2.0 Replaces widget_wpmemwidget_init
1394
+ */
1395
+ public function widget_init() {
1396
+ // Register the WP-Members widget.
1397
+ register_widget( 'widget_wpmemwidget' );
1398
+ }
1399
+
1400
+ /**
1401
+ * Adds WP-Members query vars to WP's public query vars.
1402
+ *
1403
+ * @since 3.2.0
1404
+ *
1405
+ * @see https://codex.wordpress.org/Plugin_API/Filter_Reference/query_vars
1406
+ *
1407
+ * @param array $qvars
1408
+ */
1409
+ public function add_query_vars ( $qvars ) {
1410
+ $qvars[] = 'a'; // The WP-Members action variable.
1411
+ return $qvars;
1412
+ }
1413
+
1414
+ /**
1415
+ * Enqueues login/out script for the footer.
1416
+ *
1417
+ * @since 3.2.0
1418
+ */
1419
+ public function loginout_script() {
1420
+ if ( is_user_logged_in() ) {
1421
+ wp_enqueue_script( 'jquery' );
1422
+ add_action( 'wp_footer', array( $this, 'do_loginout_script' ), 50 );
1423
+ }
1424
+ }
1425
+
1426
+ /**
1427
+ * Outputs login/out script for the footer.
1428
+ *
1429
+ * @since 3.2.0
1430
+ *
1431
+ * @global object $wpmem
1432
+ */
1433
+ public function do_loginout_script() {
1434
+ global $wpmem;
1435
+ /** This filter is defined in /includes/api/api.php */
1436
+ $logout = apply_filters( 'wpmem_logout_link', add_query_arg( 'a', 'logout' ) );
1437
+ ?><script type="text/javascript">
1438
+ jQuery('.wpmem_loginout').html('<a class="login_button" href="<?php echo esc_url( $logout ); ?>"><?php echo $this->get_text( 'menu_logout' ); ?></a>');
1439
+ </script><?php
1440
+ }
1441
+
1442
+ /**
1443
+ * Adds WP-Members controls to the Customizer
1444
+ *
1445
+ * @since 3.2.0
1446
+ *
1447
+ * @param object $wp_customize The Customizer object.
1448
+ */
1449
+ function customizer_settings( $wp_customize ) {
1450
+ $wp_customize->add_section( 'wp_members' , array(
1451
+ 'title' => 'WP-Members',
1452
+ 'priority' => 190,
1453
+ ) );
1454
+
1455
+ // Add settings for output description
1456
+ $wp_customize->add_setting( 'wpmem_show_logged_out_state', array(
1457
+ 'default' => '1',
1458
+ 'type' => 'theme_mod', //'option'
1459
+ 'capability' => 'edit_theme_options',
1460
+ 'transport' => 'refresh',
1461
+ ) );
1462
+
1463
+ // Add settings for output description
1464
+ $wp_customize->add_setting( 'wpmem_show_form_message_dialog', array(
1465
+ 'default' => '1',
1466
+ 'type' => 'theme_mod', //'option'
1467
+ 'capability' => 'edit_theme_options',
1468
+ 'transport' => 'refresh',
1469
+ ) );
1470
+
1471
+ // Add control and output for select field
1472
+ $wp_customize->add_control( 'wpmem_show_form_logged_out', array(
1473
+ 'label' => __( 'Show forms as logged out', 'wp-members' ),
1474
+ 'section' => 'wp_members',
1475
+ 'settings' => 'wpmem_show_logged_out_state',
1476
+ 'type' => 'checkbox',
1477
+ 'std' => '1'
1478
+ ) );
1479
+
1480
+ // Add control for showing dialog
1481
+ $wp_customize->add_control( 'wpmem_show_form_dialog', array(
1482
+ 'label' => __( 'Show form message dialog', 'wp-members' ),
1483
+ 'section' => 'wp_members',
1484
+ 'settings' => 'wpmem_show_form_message_dialog',
1485
+ 'type' => 'checkbox',
1486
+ 'std' => '0'
1487
+ ) );
1488
+ }
1489
+
1490
+ /**
1491
+ * Loads the stylesheet for tableless forms.
1492
+ *
1493
+ * @since 2.6
1494
+ * @since 3.2.3 Moved to WP_Members class.
1495
+ *
1496
+ * @global object $wpmem The WP_Members object.
1497
+ */
1498
+ function enqueue_style() {
1499
+ global $wpmem;
1500
+ wp_enqueue_style ( 'wp-members', wpmem_force_ssl( $wpmem->cssurl ), false, $wpmem->version );
1501
+ }
1502
+
1503
+ /**
1504
+ * Loads the wp-login.php stylesheet.
1505
+ *
1506
+ * @since 3.3.0
1507
+ *
1508
+ * @global stdClass $wpmem
1509
+ */
1510
+ function enqueue_style_wp_login() {
1511
+ global $wpmem;
1512
+ wp_enqueue_style( 'wp-members', $wpmem->url . 'assets/css/wp-login' . wpmem_get_suffix() . '.css', false, $wpmem->version );
1513
+ }
1514
+
1515
+ /**
1516
+ * Creates an excerpt on the fly if there is no 'more' tag.
1517
+ *
1518
+ * @since 2.6
1519
+ * @since 3.2.3 Moved to WP_Members class.
1520
+ * @since 3.2.5 Check if post object exists.
1521
+ *
1522
+ * @global object $post The post object.
1523
+ * @global object $wpmem The WP_Members object.
1524
+ *
1525
+ * @param string $content
1526
+ * @return string $content
1527
+ */
1528
+ function do_excerpt( $content ) {
1529
+
1530
+ global $post, $more, $wpmem;
1531
+
1532
+ if ( is_object( $post ) ) {
1533
+
1534
+ $post_id = $post->ID;
1535
+ $post_type = $post->post_type;
1536
+
1537
+ $autoex = ( isset( $wpmem->autoex[ $post->post_type ] ) && 1 == $wpmem->autoex[ $post->post_type ]['enabled'] ) ? $wpmem->autoex[ $post->post_type ] : false;
1538
+
1539
+ // Is there already a 'more' link in the content?
1540
+ $has_more_link = ( stristr( $content, 'class="more-link"' ) ) ? true : false;
1541
+
1542
+ // If auto_ex is on.
1543
+ if ( $autoex ) {
1544
+
1545
+ // Build an excerpt if one does not exist.
1546
+ if ( ! $has_more_link ) {
1547
+
1548
+ $is_singular = ( is_singular( $post->post_type ) ) ? true : false;
1549
+
1550
+ if ( $is_singular ) {
1551
+ // If it's a single post, we don't need the 'more' link.
1552
+ $more_link_text = '';
1553
+ $more_link = '';
1554
+ } else {
1555
+ // The default $more_link_text.
1556
+ if ( isset( $wpmem->autoex[ $post->post_type ]['text'] ) && '' != $wpmem->autoex[ $post->post_type ]['text'] ) {
1557
+ $more_link_text = __( $wpmem->autoex[ $post->post_type ]['text'], 'wp-members' );
1558
+ } else {
1559
+ $more_link_text = __( '(more&hellip;)' );
1560
+ }
1561
+ // The default $more_link.
1562
+ $more_link = ' <a href="'. get_permalink( $post->ID ) . '" class="more-link">' . $more_link_text . '</a>';
1563
+ }
1564
+
1565
+ // Apply the_content_more_link filter if one exists (will match up all 'more' link text).
1566
+ /** This filter is documented in /wp-includes/post-template.php */
1567
+ $more_link = apply_filters( 'the_content_more_link', $more_link, $more_link_text );
1568
+
1569
+ $defaults = array(
1570
+ 'length' => $autoex['length'],
1571
+ 'more_link' => $more_link,
1572
+ 'blocked_only' => false,
1573
+ );
1574
+ /**
1575
+ * Filter auto excerpt defaults.
1576
+ *
1577
+ * @since 3.0.9
1578
+ * @since 3.1.5 Deprecated add_ellipsis, strip_tags, close_tags, parse_shortcodes, strip_shortcodes.
1579
+ *
1580
+ * @param array {
1581
+ * An array of settings to override the function defaults.
1582
+ *
1583
+ * @type int $length The default length of the excerpt.
1584
+ * @type string $more_link The more link HTML.
1585
+ * @type boolean $blocked_only Run autoexcerpt only on blocked content. default: false.
1586
+ * }
1587
+ * @param string $post->ID The post ID.
1588
+ * @param string $post->post_type The content's post type.
1589
+ */
1590
+ $args = apply_filters( 'wpmem_auto_excerpt_args', $defaults, $post->ID, $post->post_type );
1591
+
1592
+ // Merge settings.
1593
+ $args = wp_parse_args( $args, $defaults );
1594
+
1595
+ // Are we only excerpting blocked content?
1596
+ if ( $args['blocked_only'] ) {
1597
+ $post_meta = get_post_meta( $post->ID, '_wpmem_block', true );
1598
+ if ( 1 == $wpmem->block[ $post->post_type ] ) {
1599
+ // Post type is blocked, if post meta unblocks it, don't do excerpt.
1600
+ $do_excerpt = ( "0" == $post_meta ) ? false : true;
1601
+ } else {
1602
+ // Post type is unblocked, if post meta blocks it, do excerpt.
1603
+ $do_excerpt = ( "1" == $post_meta ) ? true : false;
1604
+ }
1605
+ } else {
1606
+ $do_excerpt = true;
1607
+ }
1608
+
1609
+ if ( true === $do_excerpt ) {
1610
+ $content = ( $args['length'] > 0 ) ? wp_trim_words( $content, $args['length'], $args['more_link'] ) : '';
1611
+ // Check if the more link was added (note: singular has no more_link):
1612
+ if ( ! $is_singular && ! strpos( $content, $args['more_link'] ) ) {
1613
+ $content = $content . $args['more_link'];
1614
+ }
1615
+ }
1616
+ }
1617
+ }
1618
+ } else {
1619
+ $post_id = false;
1620
+ $post_type = false;
1621
+ }
1622
+
1623
+ /**
1624
+ * Filter the auto excerpt.
1625
+ *
1626
+ * @since 2.8.1
1627
+ * @since 3.0.9 Added post ID and post type parameters.
1628
+ * @since 3.2.5 Post ID and post type may be false if there is no post object.
1629
+ *
1630
+ * @param string $content The content excerpt.
1631
+ * @param string $post_id The post ID.
1632
+ * @param string $post_type The content's post type.
1633
+ */
1634
+ $content = apply_filters( 'wpmem_auto_excerpt', $content, $post_id, $post_type );
1635
+
1636
+ // Return the excerpt.
1637
+ return $content;
1638
+ }
1639
+
1640
+ /**
1641
+ * Convert form tag.
1642
+ *
1643
+ * @todo This is temporary to handle form tag conversion.
1644
+ *
1645
+ * @since 3.1.7
1646
+ * @since 3.2.3 Moved to WP_Members class.
1647
+ * @since 3.3.0 Removed unnecessary tags.
1648
+ *
1649
+ * @param string $tag
1650
+ * @return string $tag
1651
+ */
1652
+ function convert_tag( $tag ) {
1653
+ switch ( $tag ) {
1654
+ case 'new':
1655
+ return 'register';
1656
+ break;
1657
+ case 'edit':
1658
+ case 'update':
1659
+ return 'profile';
1660
+ break;
1661
+ default:
1662
+ return $tag;
1663
+ break;
1664
+ }
1665
+ return $tag;
1666
+ }
1667
+
1668
+ /**
1669
+ * Loads translation files.
1670
+ *
1671
+ * @since 3.0.0
1672
+ * @since 3.2.5 Moved to main object, dropped wpmem_ stem.
1673
+ */
1674
+ function load_textdomain() {
1675
+
1676
+ // Plugin textdomain.
1677
+ $domain = 'wp-members';
1678
+
1679
+ // Wordpress locale.
1680
+ /** This filter is documented in wp-includes/l10n.php */
1681
+ $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
1682
+
1683
+ /**
1684
+ * Filter translation file.
1685
+ *
1686
+ * If the translate.wordpress.org language pack is available, it will
1687
+ * be /wp-content/languages/plugins/wp-members-{locale}.mo by default.
1688
+ * You can filter this if you want to load a language pack from a
1689
+ * different location (or different file name).
1690
+ *
1691
+ * @since 3.0.0
1692
+ * @since 3.2.0 Added locale as a parameter.
1693
+ *
1694
+ * @param string $file The translation file to load.
1695
+ * @param string $locale The current locale.
1696
+ */
1697
+ $file = apply_filters( 'wpmem_localization_file', trailingslashit( WP_LANG_DIR ) . 'plugins/' . $domain . '-' . $locale . '.mo', $locale );
1698
+
1699
+ $loaded = load_textdomain( $domain, $file );
1700
+ if ( $loaded ) {
1701
+ return $loaded;
1702
+ } else {
1703
+ /**
1704
+ * Filter translation directory.
1705
+ *
1706
+ * @since 3.0.3
1707
+ * @since 3.2.0 Added locale as a parameter.
1708
+ *
1709
+ * @param string $dir The translation directory.
1710
+ * @param string $locale The current locale.
1711
+ */
1712
+ $dir = apply_filters( 'wpmem_localization_dir', basename( $this->path ) . '/i18n/languages/', $locale );
1713
+ load_plugin_textdomain( $domain, FALSE, $dir );
1714
+ }
1715
+ return;
1716
+ }
1717
+
1718
+ /**
1719
+ * Load default tos template.
1720
+ *
1721
+ * @since 3.2.8
1722
+ */
1723
+ function load_default_tos() {
1724
+ // Check for custom template or load default.
1725
+ $custom_template = get_stylesheet_directory() . '/wp-members/templates/tos.php';
1726
+ if ( file_exists( $custom_template ) ) {
1727
+ require_once( $custom_template );
1728
+ } else {
1729
+ require_once( $this->path . 'templates/tos.php' );
1730
+ }
1731
+ }
1732
+
1733
+ /**
1734
+ * Builds defaults for login/out links/buttons.
1735
+ *
1736
+ * @since 3.3.5
1737
+ *
1738
+ * @param array $args
1739
+ * @return string $html
1740
+ */
1741
+ function loginout_args( $args = array() ) {
1742
+ $defaults = array(
1743
+ 'format' => ( isset( $args['format'] ) ) ? $args['format'] : 'link',
1744
+ 'login_redirect_to' => ( isset( $args['login_redirect_to'] ) ) ? $args['login_redirect_to'] : wpmem_current_url(),
1745
+ 'logout_redirect_to' => ( isset( $args['logout_redirect_to'] ) ) ? $args['logout_redirect_to'] : wpmem_current_url(), // @todo - This is not currently active.
1746
+ 'login_text' => ( isset( $args['login_text'] ) ) ? $args['login_text'] : __( 'log in', 'wp-members' ),
1747
+ 'logout_text' => ( isset( $args['logout_text'] ) ) ? $args['logout_text'] : __( 'log out', 'wp-members' ),
1748
+ 'class' => ( isset( $args['class'] ) ) ? $args['class'] : 'wpmem_loginout_link',
1749
+ 'id' => ( isset( $args['id'] ) ) ? $args['id'] : 'wpmem_loginout_link',
1750
+ );
1751
+ $args = wp_parse_args( $args, $defaults );
1752
+ $redirect = ( is_user_logged_in() ) ? $args['logout_redirect_to'] : $args['login_redirect_to'];
1753
+ $text = ( is_user_logged_in() ) ? $args['logout_text'] : $args['login_text'];
1754
+ if ( is_user_logged_in() ) {
1755
+ /** This filter is defined in /includes/api/api.php */
1756
+ $link = apply_filters( 'wpmem_logout_link', add_query_arg( 'a', 'logout' ) );
1757
+ } else {
1758
+ $link = wpmem_login_url( $redirect );
1759
+ }
1760
+
1761
+ if ( 'button' == $args['format'] ) {
1762
+ $html = '<form action="' . $link . '" id="' . $args['id'] . '" class="' . $args['class'] . '">';
1763
+ $html.= ( is_user_logged_in() ) ? '<input type="hidden" name="a" value="logout" />' : '';
1764
+ $html.= '<input type="submit" value="' . $text . '" /></form>';
1765
+ } else {
1766
+ $html = sprintf( '<a href="%s" id="%" class="%s">%s</a>', $link, $args['id'], $args['class'], $text );
1767
+ }
1768
+ return $html;
1769
+ }
1770
+
1771
+ /**
1772
+ * Filters the password URL to point to the WP-Members process.
1773
+ *
1774
+ * @since 3.3.5
1775
+ */
1776
+ function lost_pwd_url( $lostpwd_url, $redirect ) {
1777
+ return wpmem_profile_url( 'pwdreset' );
1778
+ }
1779
+
1780
+ /**
1781
+ * Google recaptcha v3 (invisible) gives more accurate user scores
1782
+ * if it is loaded on all pages.
1783
+ *
1784
+ * @since 3.4.0
1785
+ */
1786
+ function invisible_captcha() {
1787
+ if ( 4 == $this->captcha && true !== wpmem_is_reg_form_showing() ) {
1788
+ echo WP_Members_Captcha::show();
1789
+ }
1790
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1791
  } // End of WP_Members class.
includes/cli/class-wp-members-cli-settings.php CHANGED
@@ -1,310 +1,310 @@
1
- <?php
2
- /**
3
- * A WP_CLI set of subcommands to list and update WP-Members plugin settings.
4
- *
5
- * @since 3.3.5
6
- */
7
- class WP_Members_CLI_Settings {
8
-
9
- /**
10
- * Initialize any required elements.
11
- *
12
- * @since 3.3.5
13
- *
14
- * @global object $wpmem
15
- */
16
- public function __construct() {
17
- // WP-Members admin needs to be loaded manually.
18
- global $wpmem;
19
- if ( ! isset( $wpmem->admin ) ) {
20
- $wpmem->load_admin();
21
- }
22
- }
23
-
24
- /**
25
- * List the WP-Members content settings.
26
- *
27
- * @since 3.3.5
28
- */
29
- public function content() {
30
- $this->list_settings( array( 'content' ), array() );
31
- }
32
-
33
- /**
34
- * List the WP-Members option settings.
35
- *
36
- * @since 3.3.5
37
- */
38
- public function options() {
39
- $this->list_settings( array( 'options' ), array() );
40
- }
41
-
42
- /**
43
- * Lists WP-Members settings.
44
- *
45
- * @since 3.3.5
46
- *
47
- * @param array $args
48
- * @param array $assoc_args
49
- */
50
- private function list_settings( $args, $assoc_args ) {
51
-
52
- global $wpmem;
53
-
54
- if ( 'content' == $args[0] ) {
55
- $settings = $wpmem->admin->settings( 'content' );
56
- } else {
57
- $settings = $wpmem->admin->settings( 'options' );
58
- }
59
- if ( 'content' == $args[0] ) {
60
-
61
- // @todo Add custom post types, and look for admin where all possible post types are assembled.
62
- $post_types = array_merge( array( 'post', 'page' ), $wpmem->post_types );
63
-
64
- foreach( $post_types as $post_type ) {
65
- foreach ( $settings as $setting => $description ) {
66
- if ( 'autoex' != $setting ) {
67
- $list[] = array(
68
- 'Setting' => $setting . ' ' . $post_type,
69
- 'Description' => $description . ' ' . $post_type,
70
- 'Value' => $wpmem->{$setting}[ $post_type ],
71
- 'Option' => ( 0 == $wpmem->{$setting}[ $post_type ] ) ? 'Disabled' : 'Enabled',
72
- );
73
- } else {
74
- $list[] = array(
75
- 'Setting' => $setting . ' ' . $post_type,
76
- 'Description' => $description . ' ' . $post_type,
77
- 'Value' => $wpmem->{$setting}[ $post_type ]['enabled'],
78
- 'Option' => ( 0 == $wpmem->{$setting}[ $post_type ]['enabled'] ) ? 'Disabled' : 'Enabled',
79
- );
80
- $list[] = array(
81
- 'Setting' => '',
82
- 'Description' => $post_type . ' excerpt word length:',
83
- 'Value' => $wpmem->{$setting}[ $post_type ]['length'],
84
- 'Option' => '',
85
- );
86
-
87
- }
88
- }
89
-
90
- $list[] = array( 'Setting' => '', 'Description' => '', 'Value' => '', 'Option' => '' );
91
- }
92
-
93
- } else {
94
- foreach ( $settings as $setting => $description ) {
95
- if ( 'captcha' == $setting ) {
96
- $option = WP_Members_Captcha::type( $wpmem->{$setting} );
97
- } else {
98
- $option = ( 0 == $wpmem->{$setting} ) ? 'Disabled' : 'Enabled';
99
- }
100
- $list[] = array(
101
- 'Setting' => $setting,
102
- 'Description' => $description,
103
- 'Value' => $wpmem->{$setting},
104
- 'Option' => $option,
105
- );
106
-
107
- }
108
- }
109
-
110
- $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'Description', 'Setting', 'Value', 'Option' ) );
111
- $formatter->display_items( $list );
112
- }
113
-
114
- /**
115
- * List custom post types for WP-Members management.
116
- *
117
- * @since 3.3.5
118
- */
119
- public function post_types() {
120
- global $wpmem;
121
- $post_types = $wpmem->admin->post_types();
122
- foreach ( $post_types as $post_type ) {
123
- $enabled = ( array_key_exists( $post_type, $wpmem->post_types ) ) ? "Enabled" : "Disabled";
124
- $list[] = array(
125
- 'Post Type' => $post_type,
126
- 'Value' => $enabled,
127
- );
128
- }
129
- WP_CLI::line( 'Custom post type settings for WP-Members:' );
130
- $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'Post Type', 'Value' ) );
131
- $formatter->display_items( $list );
132
- }
133
-
134
- /**
135
- * Manage post type.
136
- *
137
- * ## OPTIONS
138
- *
139
- * [--enable=<post_type>]
140
- * : enable the specified post type.
141
- *
142
- * [--disable=<post_type>]
143
- * : disable the specified post type.
144
- *
145
- * @since 3.3.5
146
- */
147
- public function post_type( $args, $assoc_args ) {
148
- global $wpmem;
149
- if ( isset( $assoc_args['enable'] ) || isset( $assoc_args['disable'] ) ) {
150
- $post_types = $wpmem->admin->post_types();
151
- if ( ( isset( $assoc_args['enable'] ) && ! array_key_exists( $assoc_args['enable'], $post_types ) ) || ( isset( $assoc_args['disable'] ) && ! array_key_exists( $assoc_args['disable'], $post_types ) ) ) {
152
- WP_CLI::error( 'Not an available post type. Try wp mem settings post_types' );
153
- }
154
- // Handle disable.
155
- if ( isset( $assoc_args['disable'] ) ) {
156
- unset( $wpmem->post_types[ $assoc_args['disable'] ] );
157
- wpmem_update_option( 'wpmembers_settings', 'post_types', $wpmem->post_types );
158
- WP_CLI::success( 'Disabled ' . $assoc_args['disable'] . ' post type.' );
159
- }
160
- if ( isset( $assoc_args['enable'] ) ) {
161
- $cpt_obj = get_post_type_object( $assoc_args['enable'] );
162
- $new_post_types = array_merge($wpmem->post_types, array( $cpt_obj->name => $cpt_obj->labels->name ) );
163
- wpmem_update_option( 'wpmembers_settings', 'post_types', $new_post_types );
164
- WP_CLI::success( 'Enabled ' . $assoc_args['enable'] . ' post type.' );
165
- }
166
- } else {
167
- WP_CLI::error( 'Must specify an option: --enable=<post_type> or --disable=<post_type>' );
168
- }
169
- }
170
-
171
- /**
172
- * Enable a WP-Members setting.
173
- *
174
- * ## OPTIONS
175
- *
176
- * <option>
177
- * : The WP-Members option setting to enable.
178
- *
179
- * ## EXAMPLES
180
- *
181
- * wp mem settings enable mod_reg
182
- */
183
- public function enable( $args, $assoc_args ) {
184
- global $wpmem;
185
- $settings = $wpmem->admin->settings( 'options' );
186
- if ( array_key_exists( $args[0], $settings ) && 'captcha' !== $args[0] ) {
187
- wpmem_update_option( 'wpmembers_settings', $args[0], 1 );
188
- WP_CLI::success( $settings[ $args[0] ] . ' enabled' );
189
- }
190
- if ( array_key_exists( $args[0], $settings ) && 'captcha' === $args[0] ) {
191
- switch( $args[1] ) {
192
- case 'rs_captcha':
193
- $which = 2;
194
- break;
195
- case 'recaptcha_v2':
196
- $which = 3;
197
- break;
198
- case 'recaptcha_v3':
199
- $which = 4;
200
- break;
201
- }
202
- wpmem_update_option( 'wpmembers_settings', $args[0], $which );
203
- WP_CLI::success( $settings[ $args[0] ] . ' ' . $args[1] . ' enabled' );
204
- }
205
- }
206
-
207
- /**
208
- * Disables a WP-Members setting.
209
- *
210
- * ## OPTIONS
211
- *
212
- * <option>
213
- * : The WP-Members option setting to disable.
214
- *
215
- * ## EXAMPLES
216
- *
217
- * wp mem settings enable mod_reg
218
- */
219
- public function disable( $args ) {
220
- global $wpmem;
221
- $settings = $wpmem->admin->settings( 'options' );
222
- if ( array_key_exists( $args[0], $settings ) ) {
223
- wpmem_update_option( 'wpmembers_settings', $args[0], 0 );
224
- WP_CLI::success( $settings[ $args[0] ] . ' disabled' );
225
- }
226
- }
227
-
228
- /**
229
- * Set, clear, or list the WP-Members page settings.
230
- *
231
- * ## OPTIONS
232
- *
233
- * [<list>]
234
- * : Lists all page settings.
235
- *
236
- * [<clear>]
237
- * : Clears page or pages specified.
238
- *
239
- * [<set>]
240
- * : Set a page ID for the user page.
241
- *
242
- * [--all]
243
- * : used with <clear> option, clears all pages.
244
- *
245
- * [--login[=<ID>]]
246
- * : Leave empty (--login) to clear, or set a page ID for the login page.
247
- *
248
- * [--register[=<ID>]]
249
- * : Leave empty (--register) to clear, or set a page ID for the registration page.
250
- *
251
- * [--profile[=<ID>]]
252
- * : Leave empty (--profile) to clear, or set a page ID for the profile page.
253
- *
254
- * ## EXAMPLES
255
- *
256
- * wp mem settings pages clear --all
257
- * wp mem settings pages clear --register
258
- * wp mem settings pages set --login=123
259
- * wp mem settings pages list
260
- */
261
- public function pages( $args, $assoc_args ) {
262
- if ( empty( $args ) ) {
263
- WP_CLI::error( 'You must specify clear|set|list', true );
264
- }
265
- if ( 'clear' == $args[0] ) {
266
- if ( empty( $assoc_args ) ) {
267
- WP_CLI::error( 'You must specify --all or --login|register|profile', true );
268
- }
269
- if ( isset( $assoc_args['all'] ) ) {
270
- unset( $assoc_args['all'] );
271
- $assoc_args = array( 'login'=>'', 'register'=>'', 'profile'=>'' );
272
- }
273
- foreach ( $assoc_args as $page => $value ) {
274
- if ( isset( $assoc_args[ $page ] ) ) {
275
- wpmem_update_option( 'wpmembers_settings', 'user_pages/' . $page, '' );
276
- WP_CLI::success( ucfirst( $page ) . ' page cleared' );
277
- }
278
- }
279
- return;
280
- }
281
- if ( 'set' == $args[0] ) {
282
- if ( empty( $assoc_args ) ) {
283
- WP_CLI::error( 'You must specify which page(s) to set: --login=<ID>, --register=<ID>, --profile=<ID>', true );
284
- }
285
- foreach ( $assoc_args as $page => $value ) {
286
- if ( isset( $assoc_args[ $page ] ) ) {
287
- wpmem_update_option( 'wpmembers_settings', 'user_pages/' . $page, $assoc_args[ $page ] );
288
- WP_CLI::success( ucfirst( $page ) . ' page set to ID ' . $assoc_args[ $page ] );
289
- }
290
- }
291
- return;
292
- }
293
- if ( 'list' == $args[0] ) {
294
- global $wpmem;
295
- $raw_settings = get_option( 'wpmembers_settings' );
296
- foreach ( $wpmem->user_pages as $key => $page ) {
297
- $list[] = array(
298
- 'Page' => ucfirst( $key ),
299
- 'ID' => $raw_settings['user_pages'][ $key ],
300
- 'URL' => $wpmem->user_pages[ $key ],
301
- );
302
- }
303
-
304
- $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'Page', 'ID', 'URL' ) );
305
- $formatter->display_items( $list );
306
- }
307
- }
308
- }
309
-
310
  WP_CLI::add_command( 'mem settings', 'WP_Members_CLI_Settings' );
1
+ <?php
2
+ /**
3
+ * A WP_CLI set of subcommands to list and update WP-Members plugin settings.
4
+ *
5
+ * @since 3.3.5
6
+ */
7
+ class WP_Members_CLI_Settings {
8
+
9
+ /**
10
+ * Initialize any required elements.
11
+ *
12
+ * @since 3.3.5
13
+ *
14
+ * @global object $wpmem
15
+ */
16
+ public function __construct() {
17
+ // WP-Members admin needs to be loaded manually.
18
+ global $wpmem;
19
+ if ( ! isset( $wpmem->admin ) ) {
20
+ $wpmem->load_admin();
21
+ }
22
+ }
23
+
24
+ /**
25
+ * List the WP-Members content settings.
26
+ *
27
+ * @since 3.3.5
28
+ */
29
+ public function content() {
30
+ $this->list_settings( array( 'content' ), array() );
31
+ }
32
+
33
+ /**
34
+ * List the WP-Members option settings.
35
+ *
36
+ * @since 3.3.5
37
+ */
38
+ public function options() {
39
+ $this->list_settings( array( 'options' ), array() );
40
+ }
41
+
42
+ /**
43
+ * Lists WP-Members settings.
44
+ *
45
+ * @since 3.3.5
46
+ *
47
+ * @param array $args
48
+ * @param array $assoc_args
49
+ */
50
+ private function list_settings( $args, $assoc_args ) {
51
+
52
+ global $wpmem;
53
+
54
+ if ( 'content' == $args[0] ) {
55
+ $settings = $wpmem->admin->settings( 'content' );
56
+ } else {
57
+ $settings = $wpmem->admin->settings( 'options' );
58
+ }
59
+ if ( 'content' == $args[0] ) {
60
+
61
+ // @todo Add custom post types, and look for admin where all possible post types are assembled.
62
+ $post_types = array_merge( array( 'post', 'page' ), $wpmem->post_types );
63
+
64
+ foreach( $post_types as $post_type ) {
65
+ foreach ( $settings as $setting => $description ) {
66
+ if ( 'autoex' != $setting ) {
67
+ $list[] = array(
68
+ 'Setting' => $setting . ' ' . $post_type,
69
+ 'Description' => $description . ' ' . $post_type,
70
+ 'Value' => $wpmem->{$setting}[ $post_type ],
71
+ 'Option' => ( 0 == $wpmem->{$setting}[ $post_type ] ) ? 'Disabled' : 'Enabled',
72
+ );
73
+ } else {
74
+ $list[] = array(
75
+ 'Setting' => $setting . ' ' . $post_type,
76
+ 'Description' => $description . ' ' . $post_type,
77
+ 'Value' => $wpmem->{$setting}[ $post_type ]['enabled'],
78
+ 'Option' => ( 0 == $wpmem->{$setting}[ $post_type ]['enabled'] ) ? 'Disabled' : 'Enabled',
79
+ );
80
+ $list[] = array(
81
+ 'Setting' => '',
82
+ 'Description' => $post_type . ' excerpt word length:',
83
+ 'Value' => $wpmem->{$setting}[ $post_type ]['length'],
84
+ 'Option' => '',
85
+ );
86
+
87
+ }
88
+ }
89
+
90
+ $list[] = array( 'Setting' => '', 'Description' => '', 'Value' => '', 'Option' => '' );
91
+ }
92
+
93
+ } else {
94
+ foreach ( $settings as $setting => $description ) {
95
+ if ( 'captcha' == $setting ) {
96
+ $option = WP_Members_Captcha::type( $wpmem->{$setting} );
97
+ } else {
98
+ $option = ( 0 == $wpmem->{$setting} ) ? 'Disabled' : 'Enabled';
99
+ }
100
+ $list[] = array(
101
+ 'Setting' => $setting,
102
+ 'Description' => $description,
103
+ 'Value' => $wpmem->{$setting},
104
+ 'Option' => $option,
105
+ );
106
+
107
+ }
108
+ }
109
+
110
+ $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'Description', 'Setting', 'Value', 'Option' ) );
111
+ $formatter->display_items( $list );
112
+ }
113
+
114
+ /**
115
+ * List custom post types for WP-Members management.
116
+ *
117
+ * @since 3.3.5
118
+ */
119
+ public function post_types() {
120
+ global $wpmem;
121
+ $post_types = $wpmem->admin->post_types();
122
+ foreach ( $post_types as $post_type ) {
123
+ $enabled = ( array_key_exists( $post_type, $wpmem->post_types ) ) ? "Enabled" : "Disabled";
124
+ $list[] = array(
125
+ 'Post Type' => $post_type,
126
+ 'Value' => $enabled,
127
+ );
128
+ }
129
+ WP_CLI::line( 'Custom post type settings for WP-Members:' );
130
+ $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'Post Type', 'Value' ) );
131
+ $formatter->display_items( $list );
132
+ }
133
+
134
+ /**
135
+ * Manage post type.
136
+ *
137
+ * ## OPTIONS
138
+ *
139
+ * [--enable=<post_type>]
140
+ * : enable the specified post type.
141
+ *
142
+ * [--disable=<post_type>]
143
+ * : disable the specified post type.
144
+ *
145
+ * @since 3.3.5
146
+ */
147
+ public function post_type( $args, $assoc_args ) {
148
+ global $wpmem;
149
+ if ( isset( $assoc_args['enable'] ) || isset( $assoc_args['disable'] ) ) {
150
+ $post_types = $wpmem->admin->post_types();
151
+ if ( ( isset( $assoc_args['enable'] ) && ! array_key_exists( $assoc_args['enable'], $post_types ) ) || ( isset( $assoc_args['disable'] ) && ! array_key_exists( $assoc_args['disable'], $post_types ) ) ) {
152
+ WP_CLI::error( 'Not an available post type. Try wp mem settings post_types' );
153
+ }
154
+ // Handle disable.
155
+ if ( isset( $assoc_args['disable'] ) ) {
156
+ unset( $wpmem->post_types[ $assoc_args['disable'] ] );
157
+ wpmem_update_option( 'wpmembers_settings', 'post_types', $wpmem->post_types );
158
+ WP_CLI::success( 'Disabled ' . $assoc_args['disable'] . ' post type.' );
159
+ }
160
+ if ( isset( $assoc_args['enable'] ) ) {
161
+ $cpt_obj = get_post_type_object( $assoc_args['enable'] );
162
+ $new_post_types = array_merge($wpmem->post_types, array( $cpt_obj->name => $cpt_obj->labels->name ) );
163
+ wpmem_update_option( 'wpmembers_settings', 'post_types', $new_post_types );
164
+ WP_CLI::success( 'Enabled ' . $assoc_args['enable'] . ' post type.' );
165
+ }
166
+ } else {
167
+ WP_CLI::error( 'Must specify an option: --enable=<post_type> or --disable=<post_type>' );
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Enable a WP-Members setting.
173
+ *
174
+ * ## OPTIONS
175
+ *
176
+ * <option>
177
+ * : The WP-Members option setting to enable.
178
+ *
179
+ * ## EXAMPLES
180
+ *
181
+ * wp mem settings enable mod_reg
182
+ */
183
+ public function enable( $args, $assoc_args ) {
184
+ global $wpmem;
185
+ $settings = $wpmem->admin->settings( 'options' );
186
+ if ( array_key_exists( $args[0], $settings ) && 'captcha' !== $args[0] ) {
187
+ wpmem_update_option( 'wpmembers_settings', $args[0], 1 );
188
+ WP_CLI::success( $settings[ $args[0] ] . ' enabled' );
189
+ }
190
+ if ( array_key_exists( $args[0], $settings ) && 'captcha' === $args[0] ) {
191
+ switch( $args[1] ) {
192
+ case 'rs_captcha':
193
+ $which = 2;
194
+ break;
195
+ case 'recaptcha_v2':
196
+ $which = 3;
197
+ break;
198
+ case 'recaptcha_v3':
199
+ $which = 4;
200
+ break;
201
+ }
202
+ wpmem_update_option( 'wpmembers_settings', $args[0], $which );
203
+ WP_CLI::success( $settings[ $args[0] ] . ' ' . $args[1] . ' enabled' );
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Disables a WP-Members setting.
209
+ *
210
+ * ## OPTIONS
211
+ *
212
+ * <option>
213
+ * : The WP-Members option setting to disable.
214
+ *
215
+ * ## EXAMPLES
216
+ *
217
+ * wp mem settings enable mod_reg
218
+ */
219
+ public function disable( $args ) {
220
+ global $wpmem;
221
+ $settings = $wpmem->admin->settings( 'options' );
222
+ if ( array_key_exists( $args[0], $settings ) ) {
223
+ wpmem_update_option( 'wpmembers_settings', $args[0], 0 );
224
+ WP_CLI::success( $settings[ $args[0] ] . ' disabled' );
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Set, clear, or list the WP-Members page settings.
230
+ *
231
+ * ## OPTIONS
232
+ *
233
+ * [<list>]
234
+ * : Lists all page settings.
235
+ *
236
+ * [<clear>]
237
+ * : Clears page or pages specified.
238
+ *
239
+ * [<set>]
240
+ * : Set a page ID for the user page.
241
+ *
242
+ * [--all]
243
+ * : used with <clear> option, clears all pages.
244
+ *
245
+ * [--login[=<ID>]]
246
+ * : Leave empty (--login) to clear, or set a page ID for the login page.
247
+ *
248
+ * [--register[=<ID>]]
249
+ * : Leave empty (--register) to clear, or set a page ID for the registration page.
250
+ *
251
+ * [--profile[=<ID>]]
252
+ * : Leave empty (--profile) to clear, or set a page ID for the profile page.
253
+ *
254
+ * ## EXAMPLES
255
+ *
256
+ * wp mem settings pages clear --all
257
+ * wp mem settings pages clear --register
258
+ * wp mem settings pages set --login=123
259
+ * wp mem settings pages list
260
+ */
261
+ public function pages( $args, $assoc_args ) {
262
+ if ( empty( $args ) ) {
263
+ WP_CLI::error( 'You must specify clear|set|list', true );
264
+ }
265
+ if ( 'clear' == $args[0] ) {
266
+ if ( empty( $assoc_args ) ) {
267
+ WP_CLI::error( 'You must specify --all or --login|register|profile', true );
268
+ }
269
+ if ( isset( $assoc_args['all'] ) ) {
270
+ unset( $assoc_args['all'] );
271
+ $assoc_args = array( 'login'=>'', 'register'=>'', 'profile'=>'' );
272
+ }
273
+ foreach ( $assoc_args as $page => $value ) {
274
+ if ( isset( $assoc_args[ $page ] ) ) {
275
+ wpmem_update_option( 'wpmembers_settings', 'user_pages/' . $page, '' );
276
+ WP_CLI::success( ucfirst( $page ) . ' page cleared' );
277
+ }
278
+ }
279
+ return;
280
+ }
281
+ if ( 'set' == $args[0] ) {
282
+ if ( empty( $assoc_args ) ) {
283
+ WP_CLI::error( 'You must specify which page(s) to set: --login=<ID>, --register=<ID>, --profile=<ID>', true );
284
+ }
285
+ foreach ( $assoc_args as $page => $value ) {
286
+ if ( isset( $assoc_args[ $page ] ) ) {
287
+ wpmem_update_option( 'wpmembers_settings', 'user_pages/' . $page, $assoc_args[ $page ] );
288
+ WP_CLI::success( ucfirst( $page ) . ' page set to ID ' . $assoc_args[ $page ] );
289
+ }
290
+ }
291
+ return;
292
+ }
293
+ if ( 'list' == $args[0] ) {
294
+ global $wpmem;
295
+ $raw_settings = get_option( 'wpmembers_settings' );
296
+ foreach ( $wpmem->user_pages as $key => $page ) {
297
+ $list[] = array(
298
+ 'Page' => ucfirst( $key ),
299
+ 'ID' => $raw_settings['user_pages'][ $key ],
300
+ 'URL' => $wpmem->user_pages[ $key ],
301
+ );
302
+ }
303
+
304
+ $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'Page', 'ID', 'URL' ) );
305
+ $formatter->display_items( $list );
306
+ }
307
+ }
308
+ }
309
+
310
  WP_CLI::add_command( 'mem settings', 'WP_Members_CLI_Settings' );
includes/cli/class-wp-members-cli-user.php CHANGED
@@ -193,16 +193,19 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) {
193
  WP_CLI::error( 'User does not exist. Try wp user list' );
194
  }
195
  $all = ( $assoc_args['all'] ) ? true : false;
196
- $this->display_user_detail( $user->ID, $all );
197
  }
198
 
199
  /**
200
  * Handles user detail display.
201
  *
202
  * @since 3.3.5
 
 
 
203
  */
204
- private function display_user_detail( $user_id, $all ) {
205
- WP_CLI::line( __( 'User: %s', 'wp-members' ) );
206
 
207
  $values = wpmem_user_data( $user_id, $all );
208
  foreach ( $values as $key => $meta ) {
@@ -235,6 +238,16 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) {
235
  WP_CLI::success( 'User confirmed' );
236
  }
237
  }
 
 
 
 
 
 
 
 
 
 
238
  }
239
  }
240
  WP_CLI::add_command( 'mem user', 'WP_Members_CLI_User' );
193
  WP_CLI::error( 'User does not exist. Try wp user list' );
194
  }
195
  $all = ( $assoc_args['all'] ) ? true : false;
196
+ $this->display_user_detail( $user, $all );
197
  }
198
 
199
  /**
200
  * Handles user detail display.
201
  *
202
  * @since 3.3.5
203
+ *
204
+ * @param object $user
205
+ * @param $all
206
  */
207
+ private function display_user_detail( $user, $all ) {
208
+ WP_CLI::line( sprintf( __( 'User: %s', 'wp-members' ), $user->user_login ) );
209
 
210
  $values = wpmem_user_data( $user_id, $all );
211
  foreach ( $values as $key => $meta ) {
238
  WP_CLI::success( 'User confirmed' );
239
  }
240
  }
241
+
242
+ public function get_role( $args, $assoc_args ) {
243
+ $all = ( isset( $assoc_args['all'] ) ) ? true : false;
244
+ $role = wpmem_get_user_role( $assoc_args['id'], $all );
245
+ if ( is_array( $role ) ) {
246
+
247
+ } else {
248
+ WP_CLI::line( __( 'User role: %s', 'wp-members' ), $role );
249
+ }
250
+ }
251
  }
252
  }
253
  WP_CLI::add_command( 'mem user', 'WP_Members_CLI_User' );
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-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.
@@ -57,11 +57,11 @@ function wpmem_inc_status() {
57
 
58
  global $user_login, $wpmem;
59
 
60
- /** This filter is documented in wp-members/inc/dialogs.php */
61
  $logout = apply_filters( 'wpmem_logout_link', $url . '/?a=logout' );
62
 
63
- $status = '<p>' . sprintf( $wpmem->get_text( 'sb_login_status' ), $user_login )
64
- . ' | <a href="' . $logout . '">' . $wpmem->get_text( 'sb_logout_link' ) . '</a></p>';
65
 
66
  return $status;
67
  }
@@ -134,8 +134,8 @@ function wpmem_reg_securify( $content ) {
134
  global $wpmem, $wpmem_themsg;
135
  $nonce = wpmem_get( 'reg_nonce', false, 'get' );
136
  if ( $nonce && wp_verify_nonce( $nonce, 'register_redirect' ) ) {
137
- $content = wpmem_inc_regmessage( 'success', $wpmem_themsg );
138
- $content = $content . wpmem_inc_login();
139
  }
140
  return $content;
141
  }
@@ -233,7 +233,7 @@ if ( ! function_exists( 'wpmem_inc_changepassword' ) ):
233
  * Loads the form for changing password.
234
  *
235
  * @since 2.0.0
236
- * @since 3.2.0 Now a wrapper for $wpmem->forms->do_changepassword_form()
237
  * @deprecated 3.3.0 Use wpmem_change_password_form() instead.
238
  *
239
  * @global object $wpmem The WP_Members object.
@@ -253,7 +253,7 @@ if ( ! function_exists( 'wpmem_inc_resetpassword' ) ):
253
  * Loads the form for resetting password.
254
  *
255
  * @since 2.1.0
256
- * @since 3.2.0 Now a wrapper for $wpmem->forms->do_resetpassword_form()
257
  * @deprecated 3.3.0 Use wpmem_reset_password_form() instead.
258
  *
259
  * @global object $wpmem The WP_Members object.
@@ -426,7 +426,7 @@ if ( ! function_exists( 'wpmem_inc_login' ) ):
426
  *
427
  * @since 1.8
428
  * @since 3.1.4 Global $wpmem_regchk no longer needed.
429
- * @since 3.2.0 Now a wrapper for $wpmem->forms->do_login_form().
430
  * @deprecated 3.3.0 Use wpmem_login_form() instead.
431
  *
432
  * @global object $post The WordPress Post object.
@@ -437,8 +437,9 @@ if ( ! function_exists( 'wpmem_inc_login' ) ):
437
  * @return string $str The generated html for the login form.
438
  */
439
  function wpmem_inc_login( $page = "page", $redirect_to = null, $show = 'show' ) {
 
440
  global $wpmem;
441
- return $wpmem->forms->do_login_form( $page, $redirect_to, $show );
442
  }
443
  endif;
444
 
@@ -449,7 +450,7 @@ if ( ! function_exists( 'wpmem_inc_registration' ) ):
449
  * Outputs the form for new user registration and existing user edits.
450
  *
451
  * @since 2.5.1
452
- * @since 3.1.7 Now a wrapper for $wpmem->forms->register_form()
453
  * @since 3.2.0 Preparing for deprecation, use wpmem_register_form() instead.
454
  * @deprecated 3.3.0 Use wpmem_register_form() instead.
455
  *
@@ -459,8 +460,184 @@ if ( ! function_exists( 'wpmem_inc_registration' ) ):
459
  * @return string $form The HTML for the entire form as a string.
460
  */
461
  function wpmem_inc_registration( $tag = 'new', $heading = '', $redirect_to = null ) {
 
462
  global $wpmem;
463
  $args = array( 'tag' => $tag, 'heading' => $heading, 'redirect_to' => $redirect_to );
464
  return $wpmem->forms->register_form( $args );
465
  } // End wpmem_inc_registration.
466
- 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-2021 Chad Butler
12
  * WP-Members(tm) is a trademark of butlerblog.com
13
  *
14
  * @package WP-Members
15
  * @author Chad Butler
16
+ * @copyright 2006-2021
17
  */
18
 
19
  // Exit if accessed directly.
57
 
58
  global $user_login, $wpmem;
59
 
60
+ /** This filter is defined in /includes/api/api.php */
61
  $logout = apply_filters( 'wpmem_logout_link', $url . '/?a=logout' );
62
 
63
+ $status = '<p>' . sprintf( wpmem_get_text( 'sb_login_status' ), $user_login )
64
+ . ' | <a href="' . $logout . '">' . wpmem_get_text( 'sb_logout_link' ) . '</a></p>';
65
 
66
  return $status;
67
  }
134
  global $wpmem, $wpmem_themsg;
135
  $nonce = wpmem_get( 'reg_nonce', false, 'get' );
136
  if ( $nonce && wp_verify_nonce( $nonce, 'register_redirect' ) ) {
137
+ $content = wpmem_get_display_message( 'success', $wpmem_themsg );
138
+ $content = $content . wpmem_login_form();
139
  }
140
  return $content;
141
  }
233
  * Loads the form for changing password.
234
  *
235
  * @since 2.0.0
236
+ * @since 3.2.0 Now an alias for $wpmem->forms->do_changepassword_form()
237
  * @deprecated 3.3.0 Use wpmem_change_password_form() instead.
238
  *
239
  * @global object $wpmem The WP_Members object.
253
  * Loads the form for resetting password.
254
  *
255
  * @since 2.1.0
256
+ * @since 3.2.0 Now an alias for $wpmem->forms->do_resetpassword_form()
257
  * @deprecated 3.3.0 Use wpmem_reset_password_form() instead.
258
  *
259
  * @global object $wpmem The WP_Members object.
426
  *
427
  * @since 1.8
428
  * @since 3.1.4 Global $wpmem_regchk no longer needed.
429
+ * @since 3.2.0 Now an alias for $wpmem->forms->do_login_form().
430
  * @deprecated 3.3.0 Use wpmem_login_form() instead.
431
  *
432
  * @global object $post The WordPress Post object.
437
  * @return string $str The generated html for the login form.
438
  */
439
  function wpmem_inc_login( $page = "page", $redirect_to = null, $show = 'show' ) {
440
+ wpmem_write_log( 'wpmem_inc_login() is deprecated as of WP-Members 3.3.0. Use wpmem_login_form() instead.' );
441
  global $wpmem;
442
+ return wpmem_login_form( 'login', array( 'redirect_to'=>$redirect_to ) ); //$wpmem->forms->do_login_form( $page, $redirect_to, $show );
443
  }
444
  endif;
445
 
450
  * Outputs the form for new user registration and existing user edits.
451
  *
452
  * @since 2.5.1
453
+ * @since 3.1.7 Now an alias for $wpmem->forms->register_form()
454
  * @since 3.2.0 Preparing for deprecation, use wpmem_register_form() instead.
455
  * @deprecated 3.3.0 Use wpmem_register_form() instead.
456
  *
460
  * @return string $form The HTML for the entire form as a string.
461
  */
462
  function wpmem_inc_registration( $tag = 'new', $heading = '', $redirect_to = null ) {
463
+ wpmem_write_log( 'wpmem_inc_registration() is deprecated as of WP-Members 3.3.0. Use wpmem_register_form() instead.' );
464
  global $wpmem;
465
  $args = array( 'tag' => $tag, 'heading' => $heading, 'redirect_to' => $redirect_to );
466
  return $wpmem->forms->register_form( $args );
467
  } // End wpmem_inc_registration.
468
+ endif;
469
+
470
+ if ( ! function_exists( 'wpmem_inc_loginfailed' ) ):
471
+ /**
472
+ * Login Failed Dialog.
473
+ *
474
+ * Returns the login failed error message.
475
+ *
476
+ * @since 1.8
477
+ * @deprecated 3.4.0 Use $wpmem->dialogs->login_failed().
478
+ *
479
+ * @global object $wpmem The WP_Members object.
480
+ * @return string $str The generated html for the login failed message.
481
+ */
482
+ function wpmem_inc_loginfailed() {
483
+ wpmem_write_log( 'wpmem_inc_loginfailed() is deprecated as of WP-Members 3.4.0. Use $wpmem->dialogs->login_failed() instead.' );
484
+ global $wpmem;
485
+ return $wpmem->dialogs->login_failed();
486
+ }
487
+ endif;
488
+
489
+
490
+ if ( ! function_exists( 'wpmem_inc_regmessage' ) ):
491
+ /**
492
+ * Message Dialog.
493
+ *
494
+ * Returns various dialogs and error messages.
495
+ *
496
+ * @since 1.8
497
+ * @since 3.3.0 Changed 'toggles' to 'tags'
498
+ * @deprecated 3.4.0 Use wpmem_get_display_message() instead.
499
+ *
500
+ * @global object $wpmem
501
+ * @param string $tag Error message tag to look for specific error messages.
502
+ * @param string $msg A message that has no tag that is passed directly to the function.
503
+ * @return string $str The final HTML for the message.
504
+ */
505
+ function wpmem_inc_regmessage( $tag, $msg = '' ) {
506
+ wpmem_write_log( "wpmem_inc_regmessage() is deprecated as of WP-Members 3.4.0. Use wpmem_get_display_message() instead." );
507
+ global $wpmem;
508
+ return $wpmem->dialogs->get_message( $tag, $msg );
509
+ }
510
+ endif;
511
+
512
+
513
+ if ( ! function_exists( 'wpmem_page_pwd_reset' ) ):
514
+ /**
515
+ * Password reset forms.
516
+ *
517
+ * This function creates both password reset and forgotten
518
+ * password forms for page=password shortcode.
519
+ *
520
+ * @since 2.7.6
521
+ * @since 3.2.6 Added nonce validation.
522
+ * @deprecated 3.4.0 Use $wpmem->shortcodes->render_pwd_reset() instead.
523
+ *
524
+ * @global object $wpmem
525
+ * @param string $wpmem_regchk
526
+ * @param string $content
527
+ * @return string $content
528
+ */
529
+ function wpmem_page_pwd_reset( $wpmem_regchk, $content ) {
530
+ wpmem_write_log( "wpmem_page_pwd_reset() is deprecated as of WP-Members 3.4.0." );
531
+ global $wpmem;
532
+ $content = $wpmem->shortcodes->render_pwd_reset( $wpmem_regchk, $content );
533
+ return $content;
534
+
535
+ }
536
+ endif;
537
+
538
+
539
+ if ( ! function_exists( 'wpmem_page_user_edit' ) ):
540
+ /**
541
+ * Creates a user edit page.
542
+ *
543
+ * @since 2.7.6
544
+ * @since 3.3.9 Added $atts
545
+ * @deprecated 3.4.0 Use $wpmem->shortcodes->render_user_edit() instead.
546
+ *
547
+ * @global object $wpmem
548
+ * @global string $wpmem_a
549
+ * @global string $wpmem_themsg
550
+ * @param string $wpmem_regchk
551
+ * @param string $content
552
+ * @return string $content
553
+ */
554
+ function wpmem_page_user_edit( $wpmem_regchk, $content, $atts = false ) {
555
+ wpmem_write_log( "wpmem_page_user_edit() is deprecated as of WP-Members 3.4.0." );
556
+ global $wpmem, $wpmem_a, $wpmem_themsg;
557
+ $content = $wpmem->shortcodes->render_user_edit( $wpmem_regchk, $content );
558
+ return $content;
559
+ }
560
+ endif;
561
+
562
+
563
+ /