s2Member Framework (Member Roles, Capabilities, Membership, PayPal Members) - Version 3.0.4

Version Description

  • Over 100 new Hooks/Filters have been added to the s2Member framework. Many of these Hooks/Filters now pass variables by reference.
  • All of s2Member's function calls have been wrapped inside if(!function_exists()){}. This gives developers the ability to override built-in functions - as needed. We suggest using Hooks/Filters, but when all else fails, you can now override built-in functions.
  • IMPORTANT: ( Attention Developers ) All of s2Member's internal Hooks/Filters have been prefixed with ws_plugin__ starting with v3.0.4. Given the number of Hooks/Filters spread throughout the s2Member framework ( now over 200 ); it was important to establish a standard for prefixing all Hooks/Filters. This will prevent future namespace clashes. If you've hooked into s2Member using your own custom programming routines, please update all of your Hooks/Filters by prefixing them with ws_plugin__.
  • Security fix. It was possible for a Customer to use a Registration Access Link generated by s2Member; coming from a previously canceled purchased, to re-register under certain circumstances. This has been resolved in v3.0.4.
Download this release

Release Info

Developer PriMoThemes
Plugin Icon 128x128 s2Member Framework (Member Roles, Capabilities, Membership, PayPal Members)
Version 3.0.4
Comparing to
See all releases

Code changes from version 3.0.2 to 3.0.4

Files changed (59) hide show
  1. images/brand-donations.fla +0 -0
  2. images/brand-donations.jpg +0 -0
  3. includes/codes.inc.php +21 -0
  4. includes/funcs.inc.php +6 -6
  5. includes/functions/activate-deactivate.inc.php +165 -159
  6. includes/functions/admin-lockout.inc.php +15 -12
  7. includes/functions/admin-notices.inc.php +68 -45
  8. includes/functions/auto-eots.inc.php +130 -104
  9. includes/functions/catg-level-access.inc.php +84 -81
  10. includes/functions/constants.inc.php +178 -159
  11. includes/functions/email-configs.inc.php +26 -17
  12. includes/functions/file-download-access.inc.php +184 -170
  13. includes/functions/hide-some-systematics.inc.php +18 -9
  14. includes/functions/ip-restrictions.inc.php +44 -34
  15. includes/functions/is-systematic.inc.php +44 -43
  16. includes/functions/js-globals.inc.php +122 -106
  17. includes/functions/list-servers.inc.php +46 -34
  18. includes/functions/login-customizations.inc.php +63 -46
  19. includes/functions/login-redirection.inc.php +42 -28
  20. includes/functions/menu-pages.inc.php +333 -253
  21. includes/functions/nocache.inc.php +44 -33
  22. includes/functions/page-level-access.inc.php +46 -43
  23. includes/functions/paypal-notify.inc.php +588 -517
  24. includes/functions/paypal-return.inc.php +312 -261
  25. includes/functions/paypal-utilities.inc.php +166 -132
  26. includes/functions/post-level-access.inc.php +46 -43
  27. includes/functions/profile-modifications.inc.php +56 -46
  28. includes/functions/ptag-level-access.inc.php +68 -65
  29. includes/functions/readme-parsing.inc.php +85 -66
  30. includes/functions/register-access.inc.php +394 -293
  31. includes/functions/ruri-level-access.inc.php +47 -39
  32. includes/functions/shortcodes.inc.php +97 -87
  33. includes/functions/sp-access.inc.php +83 -62
  34. includes/functions/tracking-codes.inc.php +72 -56
  35. includes/functions/translations.inc.php +31 -34
  36. includes/functions/user-access-level.inc.php +32 -31
  37. includes/functions/user-deletions.inc.php +31 -22
  38. includes/functions/user-has-wp-role.inc.php +21 -16
  39. includes/functions/user-notes.inc.php +41 -22
  40. includes/functions/users-list.inc.php +225 -141
  41. includes/functions/utilities.inc.php +273 -222
  42. includes/hooks.inc.php +2 -3
  43. includes/menu-pages/api-ops.inc.php +370 -317
  44. includes/menu-pages/buttons.inc.php +596 -518
  45. includes/menu-pages/down-ops.inc.php +198 -167
  46. includes/menu-pages/els-ops.inc.php +327 -288
  47. includes/menu-pages/info.inc.php +26 -11
  48. includes/menu-pages/menu-pages-s.js +261 -0
  49. includes/menu-pages/menu-pages.css +27 -45
  50. includes/menu-pages/menu-pages.js +3 -248
  51. includes/menu-pages/options.inc.php +1257 -1119
  52. includes/menu-pages/paypal-ops.inc.php +373 -316
  53. includes/menu-pages/scripting.inc.php +462 -389
  54. includes/menu-pages/start.inc.php +160 -95
  55. includes/menu-pages/trk-ops.inc.php +201 -152
  56. includes/profile.inc.php +108 -54
  57. includes/syscon.inc.php +9 -10
  58. readme.txt +31 -11
  59. s2member.php +19 -10
images/brand-donations.fla CHANGED
Binary file
images/brand-donations.jpg CHANGED
Binary file
includes/codes.inc.php ADDED
@@ -0,0 +1,21 @@
1
+ <?php
2
+ /*
3
+ Copyright: © 2009 WebSharks, Inc. ( coded in the USA )
4
+ <mailto:support@websharks-inc.com> <http://www.websharks-inc.com/>
5
+
6
+ Released under the terms of the GNU General Public License.
7
+ You should have received a copy of the GNU General Public License,
8
+ along with this software. In the main directory, see: /licensing/
9
+ If not, see: <http://www.gnu.org/licenses/>.
10
+ */
11
+ /*
12
+ Direct access denial.
13
+ */
14
+ if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
15
+ exit;
16
+ /*
17
+ Add WordPress® Editor Shortcodes.
18
+ http://codex.wordpress.org/Shortcode_API
19
+ */
20
+ add_shortcode ("s2Member-PayPal-Button", "ws_plugin__s2member_paypal_button");
21
+ ?>
includes/funcs.inc.php CHANGED
@@ -11,14 +11,14 @@ If not, see: <http://www.gnu.org/licenses/>.
11
/*
12
Direct access denial.
13
*/
14
- if (realpath(__FILE__) === realpath($_SERVER["SCRIPT_FILENAME"]))
15
exit;
16
/*
17
Include all of the functions that came with this plugin.
18
*/
19
- if (is_dir(dirname(__FILE__) . "/functions"))
20
- if ($ws_plugin__s2member_temp_r = opendir(dirname(__FILE__) . "/functions"))
21
- while (($ws_plugin__s2member_temp_s = readdir($ws_plugin__s2member_temp_r)) !== false)
22
- if (preg_match("/\.php#x2F;", $ws_plugin__s2member_temp_s) && !preg_match("/^index\.php#x2F;i", $ws_plugin__s2member_temp_s))
23
- include_once dirname(__FILE__) . "/functions/" . $ws_plugin__s2member_temp_s;
24
?>
11
/*
12
Direct access denial.
13
*/
14
+ if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
15
exit;
16
/*
17
Include all of the functions that came with this plugin.
18
*/
19
+ if (is_dir (dirname (__FILE__) . "/functions"))
20
+ if ($ws_plugin__s2member_temp_r = opendir (dirname (__FILE__) . "/functions"))
21
+ while (($ws_plugin__s2member_temp_s = readdir ($ws_plugin__s2member_temp_r)) !== false)
22
+ if (preg_match ("/\.php#x2F;", $ws_plugin__s2member_temp_s) && !preg_match ("/^index\.php#x2F;i", $ws_plugin__s2member_temp_s))
23
+ include_once dirname (__FILE__) . "/functions/" . $ws_plugin__s2member_temp_s;
24
?>
includes/functions/activate-deactivate.inc.php CHANGED
@@ -23,186 +23,192 @@ Initializing these options will force them to be
23
autoloaded into WordPress® instead of generating
24
extra queries before they are set.
25
*/
26
- function ws_plugin__s2member_activate ()
27
{
28
- do_action ("s2member_before_activation", get_defined_vars ());
29
- /**/
30
- add_role ("s2member_level1", "s2Member Level 1");
31
- add_role ("s2member_level2", "s2Member Level 2");
32
- add_role ("s2member_level3", "s2Member Level 3");
33
- add_role ("s2member_level4", "s2Member Level 4");
34
- /**/
35
- $role = &get_role ("s2member_level1");
36
- $role->add_cap ("read");
37
- $role->add_cap ("level_0");
38
- $role->add_cap ("access_s2member_level1");
39
- /**/
40
- $role = &get_role ("s2member_level2");
41
- $role->add_cap ("read");
42
- $role->add_cap ("level_0");
43
- $role->add_cap ("access_s2member_level2");
44
- $role->add_cap ("access_s2member_level1");
45
- /**/
46
- $role = &get_role ("s2member_level3");
47
- $role->add_cap ("read");
48
- $role->add_cap ("level_0");
49
- $role->add_cap ("access_s2member_level3");
50
- $role->add_cap ("access_s2member_level2");
51
- $role->add_cap ("access_s2member_level1");
52
- /**/
53
- $role = &get_role ("s2member_level4");
54
- $role->add_cap ("read");
55
- $role->add_cap ("level_0");
56
- $role->add_cap ("access_s2member_level4");
57
- $role->add_cap ("access_s2member_level3");
58
- $role->add_cap ("access_s2member_level2");
59
- $role->add_cap ("access_s2member_level1");
60
- /**/
61
- $role = &get_role ("administrator");
62
- $role->add_cap ("access_s2member_level1");
63
- $role->add_cap ("access_s2member_level2");
64
- $role->add_cap ("access_s2member_level3");
65
- $role->add_cap ("access_s2member_level4");
66
- /**/
67
- $role = &get_role ("editor");
68
- $role->add_cap ("access_s2member_level1");
69
- $role->add_cap ("access_s2member_level2");
70
- $role->add_cap ("access_s2member_level3");
71
- $role->add_cap ("access_s2member_level4");
72
- /**/
73
- $role = &get_role ("author");
74
- $role->add_cap ("access_s2member_level1");
75
- $role->add_cap ("access_s2member_level2");
76
- $role->add_cap ("access_s2member_level3");
77
- $role->add_cap ("access_s2member_level4");
78
- /**/
79
- $role = &get_role ("contributor");
80
- $role->add_cap ("access_s2member_level1");
81
- $role->add_cap ("access_s2member_level2");
82
- $role->add_cap ("access_s2member_level3");
83
- $role->add_cap ("access_s2member_level4");
84
- /**/
85
- if (!is_dir ($files_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"]))
86
- if (is_writable (dirname ($files_dir)))
87
- mkdir ($files_dir, 0777);
88
- /**/
89
- if (is_dir ($files_dir) && is_writable ($files_dir))
90
- if (!file_exists ($htaccess = $files_dir . "/.htaccess"))
91
- file_put_contents ($htaccess, "deny from all");
92
- /**/
93
- if (!is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
94
- if (is_writable (dirname ($logs_dir)))
95
- mkdir ($logs_dir, 0777);
96
- /**/
97
- if (is_dir ($logs_dir) && is_writable ($logs_dir))
98
- if (!file_exists ($htaccess = $logs_dir . "/.htaccess"))
99
- file_put_contents ($htaccess, "deny from all");
100
- /**/
101
- if (!is_numeric (get_option ("ws_plugin__s2member_configured")))
102
- update_option ("ws_plugin__s2member_configured", "0");
103
- /**/
104
- if (!is_array (get_option ("ws_plugin__s2member_cache")))
105
- update_option ("ws_plugin__s2member_cache", array ());
106
- /**/
107
- if (!is_array (get_option ("ws_plugin__s2member_notices")))
108
- update_option ("ws_plugin__s2member_notices", array ());
109
- /**/
110
- if (!is_array (get_option ("ws_plugin__s2member_options")))
111
- update_option ("ws_plugin__s2member_options", array ());
112
- /**/
113
- if (get_option ("ws_plugin__s2member_configured")) /* If they already have s2Member configured, read the Changelog. */
114
{
115
- $notice = '<strong>s2Member</strong> has been <strong>re-activated</strong>, with the latest version. Your existing configuration remains intact.<br />';
116
- $notice .= 'Have fun, <a href="admin.php?page=ws-plugin--s2member-info">read the Changelog</a>, and make some money! :-)';
117
- ws_plugin__s2member_enqueue_admin_notice ($notice, array ("plugins.php", "ws-plugin--s2member-options"));
118
- }
119
- else /* Otherwise, we'll help the site owner out by giving them a link to the Quick Start Guide. */
120
- {
121
- $notice = '<strong>s2Member</strong> has been <strong>activated</strong>, with the latest version. Nice work!<br />';
122
- $notice .= 'Have fun, <a href="admin.php?page=ws-plugin--s2member-start">read the Quick Start Guide</a>, and make some money! :-)';
123
- ws_plugin__s2member_enqueue_admin_notice ($notice, array ("plugins.php", "ws-plugin--s2member-options"));
124
- }
125
- /**/
126
- do_action ("s2member_after_activation", get_defined_vars ());
127
- /**/
128
- return;
129
- }
130
- /*
131
- Function for handling de-activation cleanup routines.
132
- This function should match the array key for this plugin:
133
- ws_plugin__$plugin_key_deactivate() is called by our themes.
134
- */
135
- function ws_plugin__s2member_deactivate ()
136
- {
137
- do_action ("s2member_before_deactivation", get_defined_vars ());
138
- /**/
139
- if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["run_deactivation_routines"])
140
- {
141
- remove_role ("s2member_level1");
142
- remove_role ("s2member_level2");
143
- remove_role ("s2member_level3");
144
- remove_role ("s2member_level4");
145
/**/
146
$role = &get_role ("administrator");
147
- $role->remove_cap ("access_s2member_level1");
148
- $role->remove_cap ("access_s2member_level2");
149
- $role->remove_cap ("access_s2member_level3");
150
- $role->remove_cap ("access_s2member_level4");
151
/**/
152
$role = &get_role ("editor");
153
- $role->remove_cap ("access_s2member_level1");
154
- $role->remove_cap ("access_s2member_level2");
155
- $role->remove_cap ("access_s2member_level3");
156
- $role->remove_cap ("access_s2member_level4");
157
/**/
158
$role = &get_role ("author");
159
- $role->remove_cap ("access_s2member_level1");
160
- $role->remove_cap ("access_s2member_level2");
161
- $role->remove_cap ("access_s2member_level3");
162
- $role->remove_cap ("access_s2member_level4");
163
/**/
164
$role = &get_role ("contributor");
165
- $role->remove_cap ("access_s2member_level1");
166
- $role->remove_cap ("access_s2member_level2");
167
- $role->remove_cap ("access_s2member_level3");
168
- $role->remove_cap ("access_s2member_level4");
169
/**/
170
- if (is_dir ($files_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"]))
171
{
172
- if (file_exists ($htaccess = $files_dir . "/.htaccess"))
173
- if (is_writable ($htaccess))
174
- unlink ($htaccess);
175
- /**/
176
- @rmdir ($files_dir);
177
}
178
/**/
179
- if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
180
{
181
- if (file_exists ($htaccess = $logs_dir . "/.htaccess"))
182
- if (is_writable ($htaccess))
183
- unlink ($htaccess);
184
/**/
185
- if (file_exists ($log = $logs_dir . "/paypal-ipn.log"))
186
- if (is_writable ($log))
187
- unlink ($log);
188
/**/
189
- if (file_exists ($log = $logs_dir . "/paypal-rtn.log"))
190
- if (is_writable ($log))
191
- unlink ($log);
192
/**/
193
- @rmdir ($logs_dir);
194
}
195
/**/
196
- delete_option ("ws_plugin__s2member_configured");
197
- delete_option ("ws_plugin__s2member_cache");
198
- delete_option ("ws_plugin__s2member_notices");
199
- delete_option ("ws_plugin__s2member_options");
200
/**/
201
- do_action ("s2member_during_deactivation", get_defined_vars ());
202
}
203
- /**/
204
- do_action ("s2member_after_deactivation", get_defined_vars ());
205
- /**/
206
- return;
207
}
208
?>
23
autoloaded into WordPress® instead of generating
24
extra queries before they are set.
25
*/
26
+ if (!function_exists ("ws_plugin__s2member_activate"))
27
{
28
+ function ws_plugin__s2member_activate ()
29
{
30
+ do_action ("ws_plugin__s2member_before_activation", get_defined_vars ());
31
+ /**/
32
+ add_role ("s2member_level1", "s2Member Level 1");
33
+ add_role ("s2member_level2", "s2Member Level 2");
34
+ add_role ("s2member_level3", "s2Member Level 3");
35
+ add_role ("s2member_level4", "s2Member Level 4");
36
+ /**/
37
+ $role = &get_role ("s2member_level1");
38
+ $role->add_cap ("read");
39
+ $role->add_cap ("level_0");
40
+ $role->add_cap ("access_s2member_level1");
41
+ /**/
42
+ $role = &get_role ("s2member_level2");
43
+ $role->add_cap ("read");
44
+ $role->add_cap ("level_0");
45
+ $role->add_cap ("access_s2member_level2");
46
+ $role->add_cap ("access_s2member_level1");
47
+ /**/
48
+ $role = &get_role ("s2member_level3");
49
+ $role->add_cap ("read");
50
+ $role->add_cap ("level_0");
51
+ $role->add_cap ("access_s2member_level3");
52
+ $role->add_cap ("access_s2member_level2");
53
+ $role->add_cap ("access_s2member_level1");
54
+ /**/
55
+ $role = &get_role ("s2member_level4");
56
+ $role->add_cap ("read");
57
+ $role->add_cap ("level_0");
58
+ $role->add_cap ("access_s2member_level4");
59
+ $role->add_cap ("access_s2member_level3");
60
+ $role->add_cap ("access_s2member_level2");
61
+ $role->add_cap ("access_s2member_level1");
62
/**/
63
$role = &get_role ("administrator");
64
+ $role->add_cap ("access_s2member_level1");
65
+ $role->add_cap ("access_s2member_level2");
66
+ $role->add_cap ("access_s2member_level3");
67
+ $role->add_cap ("access_s2member_level4");
68
/**/
69
$role = &get_role ("editor");
70
+ $role->add_cap ("access_s2member_level1");
71
+ $role->add_cap ("access_s2member_level2");
72
+ $role->add_cap ("access_s2member_level3");
73
+ $role->add_cap ("access_s2member_level4");
74
/**/
75
$role = &get_role ("author");
76
+ $role->add_cap ("access_s2member_level1");
77
+ $role->add_cap ("access_s2member_level2");
78
+ $role->add_cap ("access_s2member_level3");
79
+ $role->add_cap ("access_s2member_level4");
80
/**/
81
$role = &get_role ("contributor");
82
+ $role->add_cap ("access_s2member_level1");
83
+ $role->add_cap ("access_s2member_level2");
84
+ $role->add_cap ("access_s2member_level3");
85
+ $role->add_cap ("access_s2member_level4");
86
+ /**/
87
+ if (!is_dir ($files_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"]))
88
+ if (is_writable (dirname ($files_dir)))
89
+ mkdir ($files_dir, 0777);
90
+ /**/
91
+ if (is_dir ($files_dir) && is_writable ($files_dir))
92
+ if (!file_exists ($htaccess = $files_dir . "/.htaccess"))
93
+ file_put_contents ($htaccess, "deny from all");
94
+ /**/
95
+ if (!is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
96
+ if (is_writable (dirname ($logs_dir)))
97
+ mkdir ($logs_dir, 0777);
98
+ /**/
99
+ if (is_dir ($logs_dir) && is_writable ($logs_dir))
100
+ if (!file_exists ($htaccess = $logs_dir . "/.htaccess"))
101
+ file_put_contents ($htaccess, "deny from all");
102
+ /**/
103
+ if (!is_numeric (get_option ("ws_plugin__s2member_configured")))
104
+ update_option ("ws_plugin__s2member_configured", "0");
105
+ /**/
106
+ if (!is_array (get_option ("ws_plugin__s2member_cache")))
107
+ update_option ("ws_plugin__s2member_cache", array ());
108
/**/
109
+ if (!is_array (get_option ("ws_plugin__s2member_notices")))
110
+ update_option ("ws_plugin__s2member_notices", array ());
111
+ /**/
112
+ if (!is_array (get_option ("ws_plugin__s2member_options")))
113
+ update_option ("ws_plugin__s2member_options", array ());
114
+ /**/
115
+ if (get_option ("ws_plugin__s2member_configured")) /* If they already have s2Member configured, read the Changelog. */
116
{
117
+ $notice = '<strong>s2Member</strong> has been <strong>re-activated</strong>, with the latest version. Your existing configuration remains intact.<br />';
118
+ $notice .= 'Have fun, <a href="admin.php?page=ws-plugin--s2member-info">read the Changelog</a>, and make some money! :-)';
119
+ ws_plugin__s2member_enqueue_admin_notice ($notice, array ("plugins.php", "ws-plugin--s2member-options"));
120
}
121
+ else /* Otherwise, we'll help the site owner out by giving them a link to the Quick Start Guide. */
122
+ {
123
+ $notice = '<strong>s2Member</strong> has been <strong>activated</strong>, with the latest version. Nice work!<br />';
124
+ $notice .= 'Have fun, <a href="admin.php?page=ws-plugin--s2member-start">read the Quick Start Guide</a>, and make some money! :-)';
125
+ ws_plugin__s2member_enqueue_admin_notice ($notice, array ("plugins.php", "ws-plugin--s2member-options"));
126
+ }
127
+ /**/
128
+ do_action ("ws_plugin__s2member_after_activation", get_defined_vars ());
129
/**/
130
+ return;
131
+ }
132
+ }
133
+ /*
134
+ Function for handling de-activation cleanup routines.
135
+ This function should match the array key for this plugin:
136
+ ws_plugin__$plugin_key_deactivate() is called by our themes.
137
+ */
138
+ if (!function_exists ("ws_plugin__s2member_deactivate"))
139
+ {
140
+ function ws_plugin__s2member_deactivate ()
141
+ {
142
+ do_action ("ws_plugin__s2member_before_deactivation", get_defined_vars ());
143
+ /**/
144
+ if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["run_deactivation_routines"])
145
{
146
+ remove_role ("s2member_level1");
147
+ remove_role ("s2member_level2");
148
+ remove_role ("s2member_level3");
149
+ remove_role ("s2member_level4");
150
+ /**/
151
+ $role = &get_role ("administrator");
152
+ $role->remove_cap ("access_s2member_level1");
153
+ $role->remove_cap ("access_s2member_level2");
154
+ $role->remove_cap ("access_s2member_level3");
155
+ $role->remove_cap ("access_s2member_level4");
156
+ /**/
157
+ $role = &get_role ("editor");
158
+ $role->remove_cap ("access_s2member_level1");
159
+ $role->remove_cap ("access_s2member_level2");
160
+ $role->remove_cap ("access_s2member_level3");
161
+ $role->remove_cap ("access_s2member_level4");
162
+ /**/
163
+ $role = &get_role ("author");
164
+ $role->remove_cap ("access_s2member_level1");
165
+ $role->remove_cap ("access_s2member_level2");
166
+ $role->remove_cap ("access_s2member_level3");
167
+ $role->remove_cap ("access_s2member_level4");
168
+ /**/
169
+ $role = &get_role ("contributor");
170
+ $role->remove_cap ("access_s2member_level1");
171
+ $role->remove_cap ("access_s2member_level2");
172
+ $role->remove_cap ("access_s2member_level3");
173
+ $role->remove_cap ("access_s2member_level4");
174
+ /**/
175
+ if (is_dir ($files_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"]))
176
+ {
177
+ if (file_exists ($htaccess = $files_dir . "/.htaccess"))
178
+ if (is_writable ($htaccess))
179
+ unlink ($htaccess);
180
+ /**/
181
+ @rmdir ($files_dir);
182
+ }
183
/**/
184
+ if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
185
+ {
186
+ if (file_exists ($htaccess = $logs_dir . "/.htaccess"))
187
+ if (is_writable ($htaccess))
188
+ unlink ($htaccess);
189
+ /**/
190
+ if (file_exists ($log = $logs_dir . "/paypal-ipn.log"))
191
+ if (is_writable ($log))
192
+ unlink ($log);
193
+ /**/
194
+ if (file_exists ($log = $logs_dir . "/paypal-rtn.log"))
195
+ if (is_writable ($log))
196
+ unlink ($log);
197
+ /**/
198
+ @rmdir ($logs_dir);
199
+ }
200
/**/
201
+ delete_option ("ws_plugin__s2member_configured");
202
+ delete_option ("ws_plugin__s2member_cache");
203
+ delete_option ("ws_plugin__s2member_notices");
204
+ delete_option ("ws_plugin__s2member_options");
205
/**/
206
+ do_action ("ws_plugin__s2member_during_deactivation", get_defined_vars ());
207
}
208
/**/
209
+ do_action ("ws_plugin__s2member_after_deactivation", get_defined_vars ());
210
/**/
211
+ return;
212
}
213
}
214
?>
includes/functions/admin-lockout.inc.php CHANGED
@@ -17,18 +17,21 @@ if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
17
Function for handling admin lockouts.
18
Attach to: add_action("admin_init");
19
*/
20
- function ws_plugin__s2member_admin_lockout ()
21
{
22
- do_action ("s2member_before_admin_lockouts", get_defined_vars ());
23
- /**/
24
- if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["force_admin_lockouts"]/**/
25
- && !current_user_can ("edit_posts") /* In other words: Subscribers and Members. */
26
- && apply_filters ("s2member_admin_lockout", true, get_defined_vars ()) && /* Give filters a chance. */
27
- wp_redirect (get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"])) !== "nill")
28
- exit;
29
- /**/
30
- do_action ("s2member_after_admin_lockouts", get_defined_vars ());
31
- /**/
32
- return;
33
}
34
?>
17
Function for handling admin lockouts.
18
Attach to: add_action("admin_init");
19
*/
20
+ if (!function_exists ("ws_plugin__s2member_admin_lockout"))
21
{
22
+ function ws_plugin__s2member_admin_lockout ()
23
+ {
24
+ do_action ("ws_plugin__s2member_before_admin_lockouts", get_defined_vars ());
25
+ /**/
26
+ if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["force_admin_lockouts"]/**/
27
+ && !current_user_can ("edit_posts") /* In other words: Subscribers and Members. */
28
+ && apply_filters ("ws_plugin__s2member_admin_lockout", true, get_defined_vars ()) && /* Give filters a chance. */
29
+ wp_redirect (get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"])) !== "nill")
30
+ exit;
31
+ /**/
32
+ do_action ("ws_plugin__s2member_after_admin_lockouts", get_defined_vars ());
33
+ /**/
34
+ return;
35
+ }
36
}
37
?>
includes/functions/admin-notices.inc.php CHANGED
@@ -16,79 +16,102 @@ if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
16
/*
17
Function displays an admin notice immediately.
18
*/
19
- function ws_plugin__s2member_display_admin_notice ($notice = FALSE, $error = FALSE)
20
{
21
- do_action ("s2member_before_display_admin_notice", get_defined_vars ());
22
- /**/
23
- if ($notice && $error) /* Special format for errors. */
24
{
25
- echo '<div class="error fade"><p>' . $notice . '</p></div>';
26
- }
27
- else if ($notice) /* Otherwise, we just send it as an update notice. */
28
- {
29
- echo '<div class="updated fade"><p>' . $notice . '</p></div>';
30
}
31
- /**/
32
- do_action ("s2member_after_display_admin_notice", get_defined_vars ());
33
- /**/
34
- return;
35
}
36
/*
37
Function that enqueues admin notices.
38
*/
39
- function ws_plugin__s2member_enqueue_admin_notice ($notice = FALSE, $on_pages = FALSE, $error = FALSE, $time = FALSE)
40
{
41
- do_action ("s2member_before_enqueue_admin_notice", get_defined_vars ());
42
- /**/
43
- if ($notice && is_string ($notice)) /* If we have a valid string. */
44
{
45
- $notices = (array)get_option ("ws_plugin__s2member_notices");
46
/**/
47
- array_push ($notices, array ("notice" => $notice, "on_pages" => $on_pages, "error" => $error, "time" => $time));
48
/**/
49
- do_action ("s2member_during_enqueue_admin_notice", get_defined_vars ()); /* Give plugins a chance. */
50
/**/
51
- update_option ("ws_plugin__s2member_notices", ws_plugin__s2member_array_unique ($notices));
52
}
53
- /**/
54
- do_action ("s2member_after_enqueue_admin_notice", get_defined_vars ());
55
- /**/
56
- return;
57
}
58
/*
59
Function that displays admin notices.
60
Attach to: add_action("admin_notices");
61
*/
62
- function ws_plugin__s2member_admin_notices ()
63
{
64
- global $pagenow; /* This holds the current page filename. */
65
- /**/
66
- do_action ("s2member_before_admin_notices", get_defined_vars ());
67
- /**/
68
- if (is_array ($notices = get_option ("ws_plugin__s2member_notices")) && !empty ($notices))
69
{
70
- foreach ($notices as $key => $notice) /* Check time on each notice. */
71
{
72
- if (empty ($notice["on_pages"]) || $pagenow === $notice["on_pages"] || in_array ($pagenow, (array)$notice["on_pages"]) || $_GET["page"] === $notice["on_pages"] || in_array ($_GET["page"], (array)$notice["on_pages"]))
73
{
74
- if (strtotime ("now") >= $notice["time"]) /* Time to show it? */
75
{
76
- unset ($notices[$key]); /* Clear this notice & display it. */
77
- /**/
78
- ws_plugin__s2member_display_admin_notice ($notice["notice"], $notice["error"]);
79
}
80
}
81
}
82
/**/
83
- do_action ("s2member_during_admin_notices", get_defined_vars ());
84
- /**/
85
- $notices = array_merge ($notices); /* Re-index. */
86
/**/
87
- update_option ("ws_plugin__s2member_notices", $notices);
88
}
89
- /**/
90
- do_action ("s2member_after_admin_notices", get_defined_vars ());
91
- /**/
92
- return;
93
}
94
?>
16
/*
17
Function displays an admin notice immediately.
18
*/
19
+ if (!function_exists ("ws_plugin__s2member_display_admin_notice"))
20
{
21
+ function ws_plugin__s2member_display_admin_notice ($notice = FALSE, $error = FALSE)
22
{
23
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
24
+ do_action ("ws_plugin__s2member_before_display_admin_notice", get_defined_vars ());
25
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
26
+ /**/
27
+ if ($notice && $error) /* Special format for errors. */
28
+ {
29
+ echo '<div class="error fade"><p>' . $notice . '</p></div>';
30
+ }
31
+ else if ($notice) /* Otherwise, we just send it as an update notice. */
32
+ {
33
+ echo '<div class="updated fade"><p>' . $notice . '</p></div>';
34
+ }
35
+ /**/
36
+ do_action ("ws_plugin__s2member_after_display_admin_notice", get_defined_vars ());
37
+ /**/
38
+ return;
39
}
40
}
41
/*
42
Function that enqueues admin notices.
43
*/
44
+ if (!function_exists ("ws_plugin__s2member_enqueue_admin_notice"))
45
{
46
+ function ws_plugin__s2member_enqueue_admin_notice ($notice = FALSE, $on_pages = FALSE, $error = FALSE, $time = FALSE)
47
{
48
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
49
+ do_action ("ws_plugin__s2member_before_enqueue_admin_notice", get_defined_vars ());
50
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
51
/**/
52
+ if ($notice && is_string ($notice)) /* If we have a valid string. */
53
+ {
54
+ $notices = (array)get_option ("ws_plugin__s2member_notices");
55
+ /**/
56
+ array_push ($notices, array ("notice" => $notice, "on_pages" => $on_pages, "error" => $error, "time" => $time));
57
+ /**/
58
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
59
+ do_action ("ws_plugin__s2member_during_enqueue_admin_notice", get_defined_vars ());
60
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
61
+ /**/
62
+ update_option ("ws_plugin__s2member_notices", ws_plugin__s2member_array_unique ($notices));
63
+ }
64
/**/
65
+ do_action ("ws_plugin__s2member_after_enqueue_admin_notice", get_defined_vars ());
66
/**/
67
+ return;
68
}
69
}
70
/*
71
Function that displays admin notices.
72
Attach to: add_action("admin_notices");
73
*/
74
+ if (!function_exists ("ws_plugin__s2member_admin_notices"))
75
{
76
+ function ws_plugin__s2member_admin_notices ()
77
{
78
+ global $pagenow; /* This holds the current page filename. */
79
+ /**/
80
+ do_action ("ws_plugin__s2member_before_admin_notices", get_defined_vars ());
81
+ /**/
82
+ if (is_array ($notices = get_option ("ws_plugin__s2member_notices")) && !empty ($notices))
83
{
84
+ foreach ($notices as $key => $notice) /* Check time on each notice. */
85
{
86
+ if (empty ($notice["on_pages"]) || $pagenow === $notice["on_pages"] || in_array ($pagenow, (array)$notice["on_pages"]) || $_GET["page"] === $notice["on_pages"] || in_array ($_GET["page"], (array)$notice["on_pages"]))
87
{
88
+ if (strtotime ("now") >= $notice["time"]) /* Time to show it? */
89
+ {
90
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
91
+ do_action ("ws_plugin__s2member_during_admin_notices_before_display", get_defined_vars ());
92
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
93
+ /**/
94
+ unset ($notices[$key]); /* Clear this notice & display it. */
95
+ /**/
96
+ ws_plugin__s2member_display_admin_notice ($notice["notice"], $notice["error"]);
97
+ /**/
98
+ do_action ("ws_plugin__s2member_during_admin_notices_after_display", get_defined_vars ());
99
+ }
100
}
101
}
102
+ /**/
103
+ $notices = array_merge ($notices); /* Re-index. */
104
+ /**/
105
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
106
+ do_action ("ws_plugin__s2member_during_admin_notices", get_defined_vars ());
107
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
108
+ /**/
109
+ update_option ("ws_plugin__s2member_notices", $notices);
110
}
111
/**/
112
+ do_action ("ws_plugin__s2member_after_admin_notices", get_defined_vars ());
113
/**/
114
+ return;
115
}
116
}
117
?>
includes/functions/auto-eots.inc.php CHANGED
@@ -16,160 +16,186 @@ if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
16
/*
17
Function processed by WP-Cron. This handles Auto-EOTs.
18
If you have a HUGE user-base, increase the max eots per process.
19
- To increase, use: add_filter("s2member_auto_eots_per_process");
20
*/
21
- function ws_plugin__s2member_auto_eot_system ($per_process = 10)
22
{
23
- global $wpdb; /* Need global DB obj. */
24
- /**/
25
- do_action ("s2member_before_auto_eot_system", get_defined_vars ());
26
- /**/
27
- include_once ABSPATH . "wp-admin/includes/admin.php"; /* Get Admin APIs. */
28
- /**/
29
- if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["auto_eot_system_enabled"]) /* Enabled? */
30
{
31
- $per_process = apply_filters ("s2member_auto_eot_system_per_process", $per_process, get_defined_vars ());
32
/**/
33
- if ($eots = $wpdb->get_results ("SELECT `user_id` FROM `" . $wpdb->usermeta . "` WHERE `meta_key` = 's2member_auto_eot_time' AND `meta_value` <= '" . $wpdb->escape (strtotime ("now")) . "' LIMIT " . $per_process))
34
{
35
- foreach ($eots as $eot) /* Go through the array of eots. We need to (demote|delete) each of them. */
36
{
37
- $user_id = $eot->user_id; /* Grab the user ID value from the query. */
38
- /**/
39
- $user = new WP_User ($user_id); /* Acquire user object. */
40
- /**/
41
- delete_usermeta ($user_id, "s2member_auto_eot_time"); /* Always delete this. */
42
- /* Removing this prevents re-runs on non WP Roles. Which are scanned for next. */
43
- /**/
44
- if (!ws_plugin__s2member_user_has_wp_role ($user)) /* Non WP Roles. */
45
{
46
- if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_eot_behavior"] === "demote")
47
{
48
- $user->set_role ("subscriber");
49
- /**/
50
- $subscr_id = get_usermeta ($user_id, "s2member_subscr_id");
51
- $custom = get_usermeta ($user_id, "s2member_custom");
52
- /**/
53
- delete_usermeta ($user_id, "s2member_custom");
54
- delete_usermeta ($user_id, "s2member_subscr_id");
55
- delete_usermeta ($user_id, "s2member_last_payment_time");
56
- delete_usermeta ($user_id, "s2member_auto_eot_time");
57
- /**/
58
- foreach ($user->allcaps as $cap => $cap_enabled)
59
- if (preg_match ("/^access_s2member_ccap_/", $cap))
60
- $user->remove_cap ($ccap = $cap);
61
- /**/
62
- delete_usermeta ($user_id, "s2member_file_download_access_arc");
63
- delete_usermeta ($user_id, "s2member_file_download_access_log");
64
- /**/
65
- ws_plugin__s2member_append_user_notes ($user_id, "Demoted by s2Member: " . date ("D M j, Y g:i a T"));
66
- /**/
67
- if ($subscr_id && $custom && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_del_notification_urls"] && is_array ($cv = preg_split ("/\|/", $custom)))
68
{
69
- foreach (preg_split ("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_del_notification_urls"]) as $url) /* Handle EOT Notifications. */
70
- /**/
71
- if (($url = preg_replace ("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace ("/%%subscr_id%%/i", urlencode ($subscr_id), $url)))
72
- if (($url = preg_replace ("/%%user_first_name%%/i", urlencode ($user->first_name), $url)) && ($url = preg_replace ("/%%user_last_name%%/i", urlencode ($user->last_name), $url)))
73
- if (($url = preg_replace ("/%%user_full_name%%/i", urlencode (trim ($user->first_name . " " . $user->last_name)), $url)))
74
- if (($url = preg_replace ("/%%user_email%%/i", urlencode ($user->user_email), $url)))
75
- /**/
76
- if (($url = trim ($url))) /* Empty? */
77
- ws_plugin__s2member_remote ($url);
78
}
79
/**/
80
- do_action ("s2member_during_auto_eot_system_during_demote", get_defined_vars ());
81
- }
82
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_eot_behavior"] === "delete")
83
- {
84
- wp_delete_user ($user_id); /* Triggers: `ws_plugin__s2member_handle_user_deletions()` */
85
- /* `ws_plugin__s2member_handle_user_deletions()` triggers `eot_del_notification_urls` */
86
- /**/
87
- do_action ("s2member_during_auto_eot_system_during_delete", get_defined_vars ());
88
}
89
- /**/
90
- do_action ("s2member_during_auto_eot_system", get_defined_vars ());
91
}
92
}
93
}
94
}
95
- /**/
96
- do_action ("s2member_after_auto_eot_system", get_defined_vars ());
97
- /**/
98
- return;
99
}
100
/*
101
This function allows the Auto-EOT Sytem to be
102
processed through a server-side Cron Job.
103
Attach to: add_action("init");
104
*/
105
- function ws_plugin__s2member_auto_eot_system_via_cron ()
106
{
107
- do_action ("s2member_before_auto_eot_system_via_cron", get_defined_vars ());
108
- /**/
109
- if ($_GET["s2member_auto_eot_system_via_cron"]) /* Being called through HTTP? */
110
{
111
- if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["auto_eot_system_enabled"]) /* Enabled? */
112
{
113
- ws_plugin__s2member_auto_eot_system ();
114
/**/
115
- do_action ("s2member_during_auto_eot_system_via_cron", get_defined_vars ());
116
}
117
/**/
118
- exit; /* Exit. */
119
}
120
- /**/
121
- do_action ("s2member_after_auto_eot_system_via_cron", get_defined_vars ());
122
}
123
/*
124
Extends the WP-Cron schedules to support 10 minute intervals.
125
Attach to: add_filter("cron_schedules");
126
*/
127
- function ws_plugin__s2member_extend_cron_schedules ($schedules = array ())
128
{
129
- do_action ("s2member_before_extend_cron_schedules", get_defined_vars ());
130
- /**/
131
- $array = array ("every10m" => array ("interval" => 600, "display" => "Every 10 Minutes"));
132
- /**/
133
- return apply_filters ("s2member_extend_cron_schedules", array_merge ($array, $schedules), get_defined_vars ());
134
}
135
/*
136
Adds a scheduled task for s2Member's Auto-EOT System.
137
*/
138
- function ws_plugin__s2member_add_auto_eot_system ()
139
{
140
- do_action ("s2member_before_add_auto_eot_system", get_defined_vars ());
141
- /**/
142
- if (!ws_plugin__s2member_delete_auto_eot_system ())
143
{
144
- return apply_filters ("s2member_add_auto_eot_system", false, get_defined_vars ());
145
- }
146
- else if (function_exists ("wp_cron")) /* Otherwise, we can schedule. */
147
- {
148
- wp_schedule_event (time (), "every10m", "s2member_auto_eot_system");
149
/**/
150
- return apply_filters ("s2member_add_auto_eot_system", true, get_defined_vars ());
151
- }
152
- else /* Otherwise, it would appear that WP-Cron is not available. */
153
- {
154
- return apply_filters ("s2member_add_auto_eot_system", false, get_defined_vars ());
155
}
156
}
157
/*
158
Delete scheduled tasks for s2Member's Auto-EOT System.
159
*/
160
- function ws_plugin__s2member_delete_auto_eot_system ()
161
{
162
- do_action ("s2member_before_delete_auto_eot_system", get_defined_vars ());
163
- /**/
164
- if (function_exists ("wp_cron"))
165
{
166
- wp_clear_scheduled_hook ("s2member_auto_eot_system");
167
/**/
168
- return apply_filters ("s2member_delete_auto_eot_system", true, get_defined_vars ());
169
- }
170
- else /* Otherwise, it would appear that WP-Cron is not available. */
171
- {
172
- return apply_filters ("s2member_delete_auto_eot_system", false, get_defined_vars ());
173
}
174
}
175
?>
16
/*
17
Function processed by WP-Cron. This handles Auto-EOTs.
18
If you have a HUGE user-base, increase the max eots per process.
19
+ To increase, use: add_filter ("ws_plugin__s2member_auto_eot_system_per_process");
20
*/
21
+ if (!function_exists ("ws_plugin__s2member_auto_eot_system"))
22
{
23
+ function ws_plugin__s2member_auto_eot_system ($per_process = 10)
24
{
25
+ global $wpdb; /* Need global DB obj. */
26
/**/
27
+ include_once ABSPATH . "wp-admin/includes/admin.php";
28
+ /**/
29
+ do_action ("ws_plugin__s2member_before_auto_eot_system", get_defined_vars ());
30
+ /**/
31
+ if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["auto_eot_system_enabled"]) /* Enabled? */
32
{
33
+ $per_process = apply_filters ("ws_plugin__s2member_auto_eot_system_per_process", $per_process, get_defined_vars ());
34
+ /**/
35
+ if ($eots = $wpdb->get_results ("SELECT `user_id` FROM `" . $wpdb->usermeta . "` WHERE `meta_key` = 's2member_auto_eot_time' AND `meta_value` <= '" . $wpdb->escape (strtotime ("now")) . "' LIMIT " . $per_process))
36
{
37
+ foreach ($eots as $eot) /* Go through the array of eots. We need to (demote|delete) each of them. */
38
{
39
+ $user_id = $eot->user_id; /* Grab the user ID value from the query. */
40
+ /**/
41
+ $user = new WP_User ($user_id); /* Acquire user object. */
42
+ /**/
43
+ delete_usermeta ($user_id, "s2member_auto_eot_time"); /* Always delete this. */
44
+ /* Removing this prevents re-runs on non WP Roles. Which are scanned for next. */
45
+ /**/
46
+ if (!ws_plugin__s2member_user_has_wp_role ($user)) /* Non WP Roles. */
47
{
48
+ if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_eot_behavior"] === "demote")
49
{
50
+ $user->set_role ("subscriber");
51
+ /**/
52
+ $subscr_id = get_usermeta ($user_id, "s2member_subscr_id");
53
+ $custom = get_usermeta ($user_id, "s2member_custom");
54
+ /**/
55
+ delete_usermeta ($user_id, "s2member_custom");
56
+ delete_usermeta ($user_id, "s2member_subscr_id");
57
+ delete_usermeta ($user_id, "s2member_last_payment_time");
58
+ delete_usermeta ($user_id, "s2member_auto_eot_time");
59
+ /**/
60
+ foreach ($user->allcaps as $cap => $cap_enabled)
61
+ if (preg_match ("/^access_s2member_ccap_/", $cap))
62
+ $user->remove_cap ($ccap = $cap);
63
+ /**/
64
+ delete_usermeta ($user_id, "s2member_file_download_access_arc");
65
+ delete_usermeta ($user_id, "s2member_file_download_access_log");
66
+ /**/
67
+ ws_plugin__s2member_append_user_notes ($user_id, "Demoted by s2Member: " . date ("D M j, Y g:i a T"));
68
+ /**/
69
+ if ($subscr_id && $custom && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_del_notification_urls"] && is_array ($cv = preg_split ("/\|/", $custom)))
70
+ {
71
+ foreach (preg_split ("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_del_notification_urls"]) as $url) /* Handle EOT Notifications. */
72
+ /**/
73
+ if (($url = preg_replace ("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace ("/%%subscr_id%%/i", urlencode ($subscr_id), $url)))
74
+ if (($url = preg_replace ("/%%user_first_name%%/i", urlencode ($user->first_name), $url)) && ($url = preg_replace ("/%%user_last_name%%/i", urlencode ($user->last_name), $url)))
75
+ if (($url = preg_replace ("/%%user_full_name%%/i", urlencode (trim ($user->first_name . " " . $user->last_name)), $url)))
76
+ if (($url = preg_replace ("/%%user_email%%/i", urlencode ($user->user_email), $url)))
77
+ /**/
78
+ if (($url = trim ($url))) /* Empty? */
79
+ ws_plugin__s2member_remote ($url);
80
+ }
81
+ /**/
82
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
83
+ do_action ("ws_plugin__s2member_during_auto_eot_system_during_demote", get_defined_vars ());
84
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
85
+ }
86
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_eot_behavior"] === "delete")
87
+ {
88
+ wp_delete_user ($user_id); /* Triggers: `ws_plugin__s2member_handle_user_deletions()` */
89
+ /* `ws_plugin__s2member_handle_user_deletions()` triggers `eot_del_notification_urls` */
90
+ /**/
91
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
92
+ do_action ("ws_plugin__s2member_during_auto_eot_system_during_delete", get_defined_vars ());
93
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
94
}
95
/**/
96
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
97
+ do_action ("ws_plugin__s2member_during_auto_eot_system", get_defined_vars ());
98
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
99
}
100
}
101
}
102
}
103
+ /**/
104
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
105
+ do_action ("ws_plugin__s2member_after_auto_eot_system", get_defined_vars ());
106
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
107
+ /**/
108
+ return;
109
}
110
}
111
/*
112
This function allows the Auto-EOT Sytem to be
113
processed through a server-side Cron Job.
114
Attach to: add_action("init");
115
*/
116
+ if (!function_exists ("ws_plugin__s2member_auto_eot_system_via_cron"))
117
{
118
+ function ws_plugin__s2member_auto_eot_system_via_cron ()
119
{
120
+ do_action ("ws_plugin__s2member_before_auto_eot_system_via_cron", get_defined_vars ());
121
+ /**/
122
+ if ($_GET["s2member_auto_eot_system_via_cron"]) /* Being called through HTTP? */
123
{
124
+ if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["auto_eot_system_enabled"])
125
+ {
126
+ ws_plugin__s2member_auto_eot_system ();
127
+ /**/
128
+ do_action ("ws_plugin__s2member_during_auto_eot_system_via_cron", get_defined_vars ());
129
+ }
130
/**/
131
+ exit; /* Exit. */
132
}
133
/**/
134
+ do_action ("ws_plugin__s2member_after_auto_eot_system_via_cron", get_defined_vars ());
135
}
136
}
137
/*
138
Extends the WP-Cron schedules to support 10 minute intervals.
139
Attach to: add_filter("cron_schedules");
140
*/
141
+ if (!function_exists ("ws_plugin__s2member_extend_cron_schedules"))
142
{
143
+ function ws_plugin__s2member_extend_cron_schedules ($schedules = array ())
144
+ {
145
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
146
+ do_action ("ws_plugin__s2member_before_extend_cron_schedules", get_defined_vars ());
147
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
148
+ /**/
149
+ $array = array ("every10m" => array ("interval" => 600, "display" => "Every 10 Minutes"));
150
+ /**/
151
+ return apply_filters ("ws_plugin__s2member_extend_cron_schedules", array_merge ($array, $schedules), get_defined_vars ());
152
+ }
153
}
154
/*
155
Adds a scheduled task for s2Member's Auto-EOT System.
156
*/
157
+ if (!function_exists ("ws_plugin__s2member_add_auto_eot_system"))
158
{
159
+ function ws_plugin__s2member_add_auto_eot_system ()
160
{
161
+ do_action ("ws_plugin__s2member_before_add_auto_eot_system", get_defined_vars ());
162
/**/
163
+ if (!ws_plugin__s2member_delete_auto_eot_system ())
164
+ {
165
+ return apply_filters ("ws_plugin__s2member_add_auto_eot_system", false, get_defined_vars ());
166
+ }
167
+ else if (function_exists ("wp_cron")) /* Otherwise, we can schedule. */
168
+ {
169
+ wp_schedule_event (time (), "every10m", "ws_plugin__s2member_auto_eot_system__schedule");
170
+ /**/
171
+ return apply_filters ("ws_plugin__s2member_add_auto_eot_system", true, get_defined_vars ());
172
+ }
173
+ else /* Otherwise, it would appear that WP-Cron is not available. */
174
+ {
175
+ return apply_filters ("ws_plugin__s2member_add_auto_eot_system", false, get_defined_vars ());
176
+ }
177
}
178
}
179
/*
180
Delete scheduled tasks for s2Member's Auto-EOT System.
181
*/
182
+ if (!function_exists ("ws_plugin__s2member_delete_auto_eot_system"))
183
{
184
+ function ws_plugin__s2member_delete_auto_eot_system ()
185
{
186
+ do_action ("ws_plugin__s2member_before_delete_auto_eot_system", get_defined_vars ());
187
/**/
188
+ if (function_exists ("wp_cron"))
189
+ {
190
+ wp_clear_scheduled_hook ("s2member_auto_eot_system"); /* This is for backward compatibility. */
191
+ wp_clear_scheduled_hook ("ws_plugin__s2member_auto_eot_system__schedule"); /* Since v3.0.3. */
192
+ /**/
193
+ return apply_filters ("ws_plugin__s2member_delete_auto_eot_system", true, get_defined_vars ());
194
+ }
195
+ else /* Otherwise, it would appear that WP-Cron is not available. */
196
+ {
197
+ return apply_filters ("ws_plugin__s2member_delete_auto_eot_system", false, get_defined_vars ());
198
+ }
199
}
200
}
201
?>
includes/functions/catg-level-access.inc.php CHANGED
@@ -17,99 +17,102 @@ if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
17
Function for handling category level access permissions.
18
Attach to: add_action("template_redirect");
19
*/
20
- function ws_plugin__s2member_check_catg_level_access ()
21
{
22
- global $post; /* get_the_ID() not yet available here. */
23
- /**/
24
- do_action ("s2member_before_check_catg_level_access", get_defined_vars ());
25
- /**/
26
- $excluded = apply_filters ("s2member_check_catg_level_access_excluded", false, get_defined_vars ());
27
- /**/
28
- if (!$excluded && ((is_category () && ($cat_ID = get_query_var ("cat"))) || (is_single () && !is_page () && is_object ($post) && ($post_ID = $post->ID))))
29
{
30
- if (!ws_plugin__s2member_is_systematic_use_page ()) /* Never restrict systematic use pages. */
31
{
32
- $current_user = (is_user_logged_in ()) ? wp_get_current_user () : false;
33
- /**/
34
- if (is_category () && $cat_ID) /* We also check if this is a child category of a restricted category. */
35
{
36
- if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level1")) && wp_redirect (add_query_arg ("s2member_level_req", "1", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
37
- exit;
38
/**/
39
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_catgs"] && in_array ($cat_ID, ($level1_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_catgs"]))) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level1")) && wp_redirect (add_query_arg ("s2member_level_req", "1", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
40
- exit;
41
- /**/
42
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level2")) && wp_redirect (add_query_arg ("s2member_level_req", "2", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
43
- exit;
44
- /**/
45
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_catgs"] && in_array ($cat_ID, ($level2_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_catgs"]))) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level2")) && wp_redirect (add_query_arg ("s2member_level_req", "2", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
46
- exit;
47
- /**/
48
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level3")) && wp_redirect (add_query_arg ("s2member_level_req", "3", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
49
- exit;
50
- /**/
51
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_catgs"] && in_array ($cat_ID, ($level3_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_catgs"]))) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level3")) && wp_redirect (add_query_arg ("s2member_level_req", "3", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
52
- exit;
53
- /**/
54
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level4")) && wp_redirect (add_query_arg ("s2member_level_req", "4", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
55
- exit;
56
- /**/
57
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_catgs"] && in_array ($cat_ID, ($level4_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_catgs"]))) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level4")) && wp_redirect (add_query_arg ("s2member_level_req", "4", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
58
- exit;
59
- /**/
60
- if ($level1_catgs)
61
- foreach ($level1_catgs as $catg)
62
- if ($catg && cat_is_ancestor_of ($catg, $cat_ID) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level1")) && wp_redirect (add_query_arg ("s2member_level_req", "1", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
63
exit;
64
- /**/
65
- if ($level2_catgs)
66
- foreach ($level2_catgs as $catg)
67
- if ($catg && cat_is_ancestor_of ($catg, $cat_ID) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level2")) && wp_redirect (add_query_arg ("s2member_level_req", "2", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
68
exit;
69
- /**/
70
- if ($level3_catgs)
71
- foreach ($level3_catgs as $catg)
72
- if ($catg && cat_is_ancestor_of ($catg, $cat_ID) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level3")) && wp_redirect (add_query_arg ("s2member_level_req", "3", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
73
exit;
74
- /**/
75
- if ($level4_catgs)
76
- foreach ($level4_catgs as $catg)
77
- if ($catg && cat_is_ancestor_of ($catg, $cat_ID) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level4")) && wp_redirect (add_query_arg ("s2member_level_req", "4", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
78
exit;
79
- }
80
- else if (is_single () && !is_page () && $post_ID)
81
- {
82
- if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level1")) && wp_redirect (add_query_arg ("s2member_level_req", "1", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
83
- exit;
84
- /**/
85
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_catgs"] && (in_category (($level1_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_catgs"])), $post_ID) || ws_plugin__s2member_in_descendant_category ($level1_catgs, $post_ID)) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level1")) && wp_redirect (add_query_arg ("s2member_level_req", "1", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
86
- exit;
87
- /**/
88
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level2")) && wp_redirect (add_query_arg ("s2member_level_req", "2", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
89
- exit;
90
- /**/
91
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_catgs"] && (in_category (($level2_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_catgs"])), $post_ID) || ws_plugin__s2member_in_descendant_category ($level2_catgs, $post_ID)) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level2")) && wp_redirect (add_query_arg ("s2member_level_req", "2", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
92
- exit;
93
- /**/
94
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level3")) && wp_redirect (add_query_arg ("s2member_level_req", "3", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
95
- exit;
96
- /**/
97
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_catgs"] && (in_category (($level3_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_catgs"])), $post_ID) || ws_plugin__s2member_in_descendant_category ($level3_catgs, $post_ID)) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level3")) && wp_redirect (add_query_arg ("s2member_level_req", "3", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
98
- exit;
99
- /**/
100
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level4")) && wp_redirect (add_query_arg ("s2member_level_req", "4", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
101
- exit;
102
/**/
103
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_catgs"] && (in_category (($level4_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_catgs"])), $post_ID) || ws_plugin__s2member_in_descendant_category ($level4_catgs, $post_ID)) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level4")) && wp_redirect (add_query_arg ("s2member_level_req", "4", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
104
- exit;
105
}
106
- /**/
107
- do_action ("s2member_during_check_catg_level_access", get_defined_vars ());
108
}
109
}
110
- /**/
111
- do_action ("s2member_after_check_catg_level_access", get_defined_vars ());
112
- /**/
113
- return;
114
}
115
?>
17
Function for handling category level access permissions.
18
Attach to: add_action("template_redirect");
19
*/
20
+ if (!function_exists ("ws_plugin__s2member_check_catg_level_access"))
21
{
22
+ function ws_plugin__s2member_check_catg_level_access ()
23
{
24
+ global $post; /* get_the_ID() not yet available here. */
25
+ /**/
26
+ do_action ("ws_plugin__s2member_before_check_catg_level_access", get_defined_vars ());
27
+ /**/
28
+ $excluded = apply_filters ("ws_plugin__s2member_check_catg_level_access_excluded", false, get_defined_vars ());
29
+ /**/
30
+ if (!$excluded && ((is_category () && ($cat_ID = get_query_var ("cat"))) || (is_single () && !is_page () && is_object ($post) && ($post_ID = $post->ID))))
31
{
32
+ if (!ws_plugin__s2member_is_systematic_use_page ()) /* Never restrict systematic use pages. */
33
{
34
+ $current_user = (is_user_logged_in ()) ? wp_get_current_user () : false;
35
/**/
36
+ if (is_category () && $cat_ID) /* We also check if this is a child category of a restricted category. */
37
+ {
38
+ if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level1")) && wp_redirect (add_query_arg ("s2member_level_req", "1", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
39
exit;
40
+ /**/
41
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_catgs"] && in_array ($cat_ID, ($level1_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_catgs"]))) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level1")) && wp_redirect (add_query_arg ("s2member_level_req", "1", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
42
exit;
43
+ /**/
44
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level2")) && wp_redirect (add_query_arg ("s2member_level_req", "2", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
45
exit;
46
+ /**/
47
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_catgs"] && in_array ($cat_ID, ($level2_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_catgs"]))) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level2")) && wp_redirect (add_query_arg ("s2member_level_req", "2", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
48
exit;
49
+ /**/
50
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level3")) && wp_redirect (add_query_arg ("s2member_level_req", "3", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
51
+ exit;
52
+ /**/
53
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_catgs"] && in_array ($cat_ID, ($level3_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_catgs"]))) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level3")) && wp_redirect (add_query_arg ("s2member_level_req", "3", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
54
+ exit;
55
+ /**/
56
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level4")) && wp_redirect (add_query_arg ("s2member_level_req", "4", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
57
+ exit;
58
+ /**/
59
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_catgs"] && in_array ($cat_ID, ($level4_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_catgs"]))) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level4")) && wp_redirect (add_query_arg ("s2member_level_req", "4", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
60
+ exit;
61
+ /**/
62
+ if ($level1_catgs)
63
+ foreach ($level1_catgs as $catg)
64
+ if ($catg && cat_is_ancestor_of ($catg, $cat_ID) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level1")) && wp_redirect (add_query_arg ("s2member_level_req", "1", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
65
+ exit;
66
+ /**/
67
+ if ($level2_catgs)
68
+ foreach ($level2_catgs as $catg)
69
+ if ($catg && cat_is_ancestor_of ($catg, $cat_ID) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level2")) && wp_redirect (add_query_arg ("s2member_level_req", "2", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
70
+ exit;
71
+ /**/
72
+ if ($level3_catgs)
73
+ foreach ($level3_catgs as $catg)
74
+ if ($catg && cat_is_ancestor_of ($catg, $cat_ID) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level3")) && wp_redirect (add_query_arg ("s2member_level_req", "3", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
75
+ exit;
76
+ /**/
77
+ if ($level4_catgs)
78
+ foreach ($level4_catgs as $catg)
79
+ if ($catg && cat_is_ancestor_of ($catg, $cat_ID) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level4")) && wp_redirect (add_query_arg ("s2member_level_req", "4", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
80
+ exit;
81
+ }
82
+ else if (is_single () && !is_page () && $post_ID)
83
+ {
84
+ if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level1")) && wp_redirect (add_query_arg ("s2member_level_req", "1", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
85
+ exit;
86
+ /**/
87
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_catgs"] && (in_category (($level1_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_catgs"])), $post_ID) || ws_plugin__s2member_in_descendant_category ($level1_catgs, $post_ID)) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level1")) && wp_redirect (add_query_arg ("s2member_level_req", "1", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
88
+ exit;
89
+ /**/
90
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level2")) && wp_redirect (add_query_arg ("s2member_level_req", "2", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
91
+ exit;
92
+ /**/
93
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_catgs"] && (in_category (($level2_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_catgs"])), $post_ID) || ws_plugin__s2member_in_descendant_category ($level2_catgs, $post_ID)) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level2")) && wp_redirect (add_query_arg ("s2member_level_req", "2", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
94
+ exit;
95
+ /**/
96
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level3")) && wp_redirect (add_query_arg ("s2member_level_req", "3", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
97
+ exit;
98
+ /**/
99
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_catgs"] && (in_category (($level3_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_catgs"])), $post_ID) || ws_plugin__s2member_in_descendant_category ($level3_catgs, $post_ID)) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level3")) && wp_redirect (add_query_arg ("s2member_level_req", "3", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
100
+ exit;
101
+ /**/
102
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_catgs"] === "all" && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level4")) && wp_redirect (add_query_arg ("s2member_level_req", "4", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
103
+ exit;
104
+ /**/
105
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_catgs"] && (in_category (($level4_catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_catgs"])), $post_ID) || ws_plugin__s2member_in_descendant_category ($level4_catgs, $post_ID)) && ws_plugin__s2member_nocache_constants () !== "nill" && (!$current_user || !current_user_can ("access_s2member_level4")) && wp_redirect (add_query_arg ("s2member_level_req", "4", get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
106
+ exit;
107
+ }
108
/**/
109
+ do_action ("ws_plugin__s2member_during_check_catg_level_access", get_defined_vars ());
110
}
111
}
112
+ /**/
113
+ do_action ("ws_plugin__s2member_after_check_catg_level_access", get_defined_vars ());
114
+ /**/
115
+ return;
116
}
117
}
118
?>
includes/functions/constants.inc.php CHANGED
@@ -18,86 +18,95 @@ Define several API Constants for s2Member.
18
Note that these are duplicated into the JavaScript API as well.
19
Attach to: add_action("init");
20
*/
21
- function ws_plugin__s2member_constants ()
22
{
23
- do_action ("s2member_before_constants", get_defined_vars ());
24
- /**/
25
- $links = ws_plugin__s2member_constant_links ();
26
- $metas = ws_plugin__s2member_constant_metas ();
27
- $level = ws_plugin__s2member_user_access_level ();
28
- $current_user = (is_user_logged_in ()) ? wp_get_current_user () : false;
29
- $file_downloads = ws_plugin__s2member_user_downloads ("", $metas["s2member_file_download_access_log"]);
30
- $login_redirection_override = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_redirection_override"];
31
- /**/
32
- define ("S2MEMBER_VERSION", $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["version"]); /* Always a (string) containing the version. Available since 3.0. */
33
- /**/
34
- define ("S2MEMBER_CURRENT_USER_IS_LOGGED_IN", (($current_user) ? true : false)); /* This will always be (bool) true or false. False if they are NOT currently logged in. */
35
- define ("S2MEMBER_CURRENT_USER_IS_LOGGED_IN_AS_MEMBER", (($current_user && $level >= 1) ? true : false)); /* This will always be (bool) true or false. Level >= 1 for Members. */
36
- define ("S2MEMBER_CURRENT_USER_ACCESS_LEVEL", (int)$level); /* This will always be (int) negative 1 thru positive 4. -1 if user is not logged in. 0 if logged in as a Subscriber. */
37
- define ("S2MEMBER_CURRENT_USER_ACCESS_LABEL", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $level . "_label"]); /* This will always be a (string). Empty if not logged in. */
38
- define ("S2MEMBER_CURRENT_USER_SUBSCR_ID", (($current_user) ? (($metas["s2member_subscr_id"]) ? $metas["s2member_subscr_id"] : $current_user->ID) : "")); /* Empty if not logged in. */
39
- define ("S2MEMBER_CURRENT_USER_CUSTOM", (($current_user) ? $metas["s2member_custom"] : "")); /* This will always a (string). However, it will be empty if not logged in. */
40
- define ("S2MEMBER_CURRENT_USER_REGISTRATION_TIME", (($current_user) ? strtotime ($current_user->user_registered) : 0)); /* Always an (int). Or 0 if they're not logged in. */
41
- define ("S2MEMBER_CURRENT_USER_REGISTRATION_DAYS", (($current_user) ? floor ((strtotime ("now") - strtotime ($current_user->user_registered)) / 86400) : 0)); /* (int). */
42
- define ("S2MEMBER_CURRENT_USER_DISPLAY_NAME", (($current_user) ? $current_user->display_name : "")); /* This will always be a (string). Empty if not logged in. */
43
- define ("S2MEMBER_CURRENT_USER_FIRST_NAME", (($current_user) ? $current_user->user_firstname : "")); /* This will always be a (string). Empty if not logged in. */
44
- define ("S2MEMBER_CURRENT_USER_LAST_NAME", (($current_user) ? $current_user->user_lastname : "")); /* This will always be a (string). Empty if not logged in. */
45
- define ("S2MEMBER_CURRENT_USER_LOGIN", (($current_user) ? $current_user->user_login : "")); /* This will always be a (string). Empty if not logged in. */
46
- define ("S2MEMBER_CURRENT_USER_EMAIL", (($current_user) ? $current_user->user_email : "")); /* This will always be a (string). Empty if not logged in. */
47
- define ("S2MEMBER_CURRENT_USER_IP", $_SERVER["REMOTE_ADDR"]); /* This will always be a (string). It may be empty if the user is browsing anonymously. */
48
- define ("S2MEMBER_CURRENT_USER_ID", (($current_user) ? (int)$current_user->ID : 0)); /* This will always be an (int). Zero if not logged in. */
49
- define ("S2MEMBER_CURRENT_USER_FIELDS", (($current_user) ? json_encode (array_merge /* Always a json_encode (array). This includes custom fields. */
50
- (array ("id" => S2MEMBER_CURRENT_USER_ID, "ip" => S2MEMBER_CURRENT_USER_IP, "email" => S2MEMBER_CURRENT_USER_EMAIL, "login" => S2MEMBER_CURRENT_USER_LOGIN,/**/
51
- "first_name" => S2MEMBER_CURRENT_USER_FIRST_NAME, "last_name" => S2MEMBER_CURRENT_USER_LAST_NAME, "display_name" => S2MEMBER_CURRENT_USER_DISPLAY_NAME,/**/
52
- "subscr_id" => S2MEMBER_CURRENT_USER_SUBSCR_ID, "custom" => S2MEMBER_CURRENT_USER_CUSTOM), $metas["s2member_custom_fields"])) : json_encode (array ())));
53
- /**/
54
- define ("S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED", (int)$file_downloads["allowed"]); /* This will always be an integer value (int) >= 0 where 0 means no access. */
55
- define ("S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_IS_UNLIMITED", (($file_downloads["allowed"] >= 999999999) ? true : false)); /* This will always be (bool). */
56
- define ("S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY", (int)$file_downloads["currently"]); /* This will always be an integer value (int) >= 0 where 0 means none currently. */
57
- define ("S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS", (int)$file_downloads["allowed_days"]); /* This will always be an integer value (int) >= 0 where 0 means no access. */
58
- /**/
59
- define ("S2MEMBER_FILE_DOWNLOAD_LIMIT_EXCEEDED_PAGE_ID", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"]); /* The exceeded page id (int). */
60
- define ("S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_ID", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]); /* Options page id, always an (int). */
61
- define ("S2MEMBER_LOGIN_WELCOME_PAGE_ID", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"]); /* The welcome page id, always an (int). */
62
- /**/
63
- define ("S2MEMBER_CURRENT_USER_PROFILE_MODIFICATION_PAGE_URL", get_bloginfo ("url") . "/?s2member_profile=1"); /* Where a user modifies their profile. */
64
- define ("S2MEMBER_FILE_DOWNLOAD_LIMIT_EXCEEDED_PAGE_URL", $links["file_download_limit_exceeded_page"]); /* Always a string. URL to limit exceeded page. */
65
- define ("S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL", $links["membership_options_page"]); /* Always a string. This is the URL to the membership options page. */
66
- define ("S2MEMBER_LOGIN_WELCOME_PAGE_URL", (($login_redirection_override) ? $login_redirection_override : $links["login_welcome_page"])); /* Always a string. */
67
- define ("S2MEMBER_LOGOUT_PAGE_URL", wp_logout_url ()); /* This is always the same, it is the default wordpress action=logout url generated by wp_logout_url(). */
68
- define ("S2MEMBER_LOGIN_PAGE_URL", wp_login_url ()); /* This is always the same, it is the default wordpress login url that is generated by wp_login_url(). */
69
- /**/
70
- define ("S2MEMBER_LEVEL1_LABEL", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_label"]); /* This is the (string) label that you created for membership level number 1. */
71
- define ("S2MEMBER_LEVEL2_LABEL", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_label"]); /* This is the (string) label that you created for membership level number 2. */
72
- define ("S2MEMBER_LEVEL3_LABEL", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_label"]); /* This is the (string) label that you created for membership level number 3. */
73
- define ("S2MEMBER_LEVEL4_LABEL", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_label"]); /* This is the (string) label that you created for membership level number 4. */
74
- /**/
75
- define ("S2MEMBER_LEVEL1_FILE_DOWNLOADS_ALLOWED", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed"]); /* This is the (int) allowed downloads. */
76
- define ("S2MEMBER_LEVEL2_FILE_DOWNLOADS_ALLOWED", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed"]); /* This is the (int) allowed downloads. */
77
- define ("S2MEMBER_LEVEL3_FILE_DOWNLOADS_ALLOWED", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed"]); /* This is the (int) allowed downloads. */
78
- define ("S2MEMBER_LEVEL4_FILE_DOWNLOADS_ALLOWED", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed"]); /* This is the (int) allowed downloads. */
79
- /**/
80
- define ("S2MEMBER_LEVEL1_FILE_DOWNLOADS_ALLOWED_DAYS", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed_days"]); /* This is (int) allowed days. */
81
- define ("S2MEMBER_LEVEL2_FILE_DOWNLOADS_ALLOWED_DAYS", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed_days"]); /* This is (int) allowed days. */
82
- define ("S2MEMBER_LEVEL3_FILE_DOWNLOADS_ALLOWED_DAYS", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed_days"]); /* This is (int) allowed days. */
83
- define ("S2MEMBER_LEVEL4_FILE_DOWNLOADS_ALLOWED_DAYS", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed_days"]); /* This is (int) allowed days. */
84
- /**/
85
- define ("S2MEMBER_FILE_DOWNLOAD_INLINE_EXTENSIONS", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_inline_extensions"]); /* This is the (string) list of extensions. */
86
- /**/
87
- define ("S2MEMBER_REG_EMAIL_FROM_NAME", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_name"]); /* This is the name that outgoing email messages are sent by. */
88
- define ("S2MEMBER_REG_EMAIL_FROM_EMAIL", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_email"]); /* This is the email that outgoing messages are sent by. */
89
- /**/
90
- define ("S2MEMBER_PAYPAL_NOTIFY_URL", get_bloginfo ("url") . "/?s2member_paypal_notify=1"); /* This will always be a (string), and it will never be an empty value. */
91
- define ("S2MEMBER_PAYPAL_RETURN_URL", get_bloginfo ("url") . "/?s2member_paypal_return=1"); /* This will always be a (string), and it will never be an empty value. */
92
- define ("S2MEMBER_PAYPAL_ENDPOINT", (($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_sandbox"]) ? "www.sandbox.paypal.com" : "www.paypal.com")); /* Using sandbox? */
93
- define ("S2MEMBER_PAYPAL_BUSINESS", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_business"]); /* This is the email address that identifies your paypal business. */
94
- /**/
95
- define ("S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON0", ((S2MEMBER_CURRENT_USER_SUBSCR_ID && !ws_plugin__s2member_user_has_wp_role ($current_user)) ? "Updating Subscr. ID" : ""));
96
- define ("S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS0", ((S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON0) ? S2MEMBER_CURRENT_USER_SUBSCR_ID : "")); /* ^ Not for built-in WP Roles. */
97
- /**/
98
- do_action ("s2member_after_constants", get_defined_vars ());
99
- /**/
100
- return;
101
}
102
/*
103
This function pulls all of the page links needed for Constants.
@@ -105,101 +114,111 @@ Page links are cached into the s2member options on 15 min intervals.
105
This allows the API Constants to provide quick access to them without being
106
forced to execute get_page_link() all the time, which piles up DB queries.
107
*/
108
- function ws_plugin__s2member_constant_links ()
109
{
110
- do_action ("s2member_before_constant_links", get_defined_vars ());
111
- /**/
112
- $cache_minutes = 15; /* Could be higher? */
113
- /**/
114
- $l["login_welcome_page"] = (string)"";
115
- $l["membership_options_page"] = (string)"";
116
- $l["file_download_limit_exceeded_page"] = (string)"";
117
- /**/
118
- $login_welcome_page = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"];
119
- $membership_options_page = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"];
120
- $file_download_limit_exceeded_page = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"];
121
- /**/
122
- $login_welcome_page_cache = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"];
123
- $membership_options_page_cache = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"];
124
- $file_download_limit_exceeded_page_cache = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"];
125
- /**/
126
- if ($login_welcome_page && $login_welcome_page_cache["page"] === $login_welcome_page && $login_welcome_page_cache["link"] && $login_welcome_page_cache["time"] >= strtotime ("-" . $cache_minutes . " minutes"))
127
{
128
- $l["login_welcome_page"] = $login_welcome_page_cache["link"];
129
- }
130
- else /* Otherwise, we need to query the database using get_page_link() and update the cache. */
131
- {
132
- $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["time"] = strtotime ("now");
133
- $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["page"] = $login_welcome_page;
134
- $l["login_welcome_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["link"] = get_page_link ($login_welcome_page);
135
/**/
136
- $cache_needs_updating = true;
137
- }
138
- /**/
139
- if ($membership_options_page && $membership_options_page_cache["page"] === $membership_options_page && $membership_options_page_cache["link"] && $membership_options_page_cache["time"] >= strtotime ("-" . $cache_minutes . " minutes"))
140
- {
141
- $l["membership_options_page"] = $membership_options_page_cache["link"];
142
- }
143
- else /* Otherwise, we need to query the database using get_page_link() and update the cache. */
144
- {
145
- $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["time"] = strtotime ("now");
146
- $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["page"] = $membership_options_page;
147
- $l["membership_options_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["link"] = get_page_link ($membership_options_page);
148
/**/
149
- $cache_needs_updating = true;
150
- }
151
- /**/
152
- if ($file_download_limit_exceeded_page && $file_download_limit_exceeded_page_cache["page"] === $file_download_limit_exceeded_page && $file_download_limit_exceeded_page_cache["link"] && $file_download_limit_exceeded_page_cache["time"] >= strtotime ("-" . $cache_minutes . " minutes"))
153
- {
154
- $l["file_download_limit_exceeded_page"] = $file_download_limit_exceeded_page_cache["link"];
155
- }
156
- else /* Otherwise, we need to query the database using get_page_link() and update the cache. */
157
- {
158
- $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["time"] = strtotime ("now");
159
- $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["page"] = $file_download_limit_exceeded_page;
160
- $l["file_download_limit_exceeded_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["link"] = get_page_link ($file_download_limit_exceeded_page);
161
/**/
162
- $cache_needs_updating = true;
163
- }
164
- /**/
165
- if ($cache_needs_updating) /* The cache is also reset when options are updated from a menu page. */
166
- {
167
- update_option ("ws_plugin__s2member_cache", $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]);
168
}
169
- /**/
170
- return apply_filters ("s2member_constant_links", $l, get_defined_vars ());
171
}
172
/*
173
This function pulls all of the usermeta details needed for Constants.
174
Pulling them all at once helps to prevent repeated database queries.
175
*/
176
- function ws_plugin__s2member_constant_metas ()
177
{
178
- global $wpdb; /* The global database object. */
179
- /**/
180
- do_action ("s2member_before_constant_metas", get_defined_vars ());
181
- /**/
182
- $m["s2member_file_download_access_log"] = array ();
183
- $m["s2member_custom_fields"] = array ();
184
- $m["s2member_subscr_id"] = (string)"";
185
- $m["s2member_custom"] = (string)"";
186
- /**/
187
- if (($current_user = (is_user_logged_in ()) ? wp_get_current_user () : false))
188
{
189
- if (is_array ($results = $wpdb->get_results ("SELECT `meta_key`, `meta_value` FROM `" . $wpdb->usermeta . "` WHERE `user_id` = '" . $current_user->ID . "' AND (meta_key = 's2member_file_download_access_log' OR meta_key = 's2member_subscr_id' OR meta_key = 's2member_custom') LIMIT 3")))
190
{
191
- foreach ($results as $r) /* Fill in the array we need. */
192
- if ($r->meta_key === "s2member_file_download_access_log")
193
- $m["s2member_file_download_access_log"] = (array)maybe_unserialize ($r->meta_value);
194
- else if ($result->meta_key === "s2member_custom_fields")
195
- $m["s2member_custom_fields"] = (array)maybe_unserialize ($r->meta_value);
196
- else if ($r->meta_key === "s2member_subscr_id")
197
- $m["s2member_subscr_id"] = (string)$r->meta_value;
198
- else if ($result->meta_key === "s2member_custom")
199
- $m["s2member_custom"] = (string)$r->meta_value;
200
}
201
}
202
- /**/
203
- return apply_filters ("s2member_constant_metas", $m, get_defined_vars ());
204
}
205
?>
18
Note that these are duplicated into the JavaScript API as well.
19
Attach to: add_action("init");
20
*/
21
+ if (!function_exists ("ws_plugin__s2member_constants"))
22
{
23
+ function ws_plugin__s2member_constants ()
24
+ {
25
+ do_action ("ws_plugin__s2member_before_constants", get_defined_vars ());
26
+ /**/
27
+ $links = ws_plugin__s2member_constant_links ();
28
+ $metas = ws_plugin__s2member_constant_metas ();
29
+ $level = ws_plugin__s2member_user_access_level ();
30
+ $current_user = (is_user_logged_in ()) ? wp_get_current_user () : false;
31
+ $file_downloads = ws_plugin__s2member_user_downloads ("", $metas["s2member_file_download_access_log"]);
32
+ $login_redirection_override = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_redirection_override"];
33
+ /**/
34
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
35
+ do_action ("ws_plugin__s2member_during_constants", get_defined_vars ());
36
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
37
+ /**/
38
+ define ("S2MEMBER_VERSION", WS_PLUGIN__S2MEMBER_VERSION); /* Always a (string) containing the version. Available since 3.0. */
39
+ /**/
40
+ define ("S2MEMBER_CURRENT_USER_IS_LOGGED_IN", (($current_user) ? true : false)); /* This will always be (bool) true or false. False if they are NOT currently logged in. */
41
+ define ("S2MEMBER_CURRENT_USER_IS_LOGGED_IN_AS_MEMBER", (($current_user && $level >= 1) ? true : false)); /* This will always be (bool) true or false. Level >= 1 for Members. */
42
+ define ("S2MEMBER_CURRENT_USER_ACCESS_LEVEL", (int)$level); /* This will always be (int) negative 1 thru positive 4. -1 if user is not logged in. 0 if logged in as a Subscriber. */
43
+ define ("S2MEMBER_CURRENT_USER_ACCESS_LABEL", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $level . "_label"]); /* This will always be a (string). Empty if not logged in. */
44
+ define ("S2MEMBER_CURRENT_USER_SUBSCR_ID", (($current_user) ? (($metas["s2member_subscr_id"]) ? $metas["s2member_subscr_id"] : $current_user->ID) : "")); /* Empty if not logged in. */
45
+ define ("S2MEMBER_CURRENT_USER_CUSTOM", (($current_user) ? $metas["s2member_custom"] : "")); /* This will always a (string). However, it will be empty if not logged in. */
46
+ define ("S2MEMBER_CURRENT_USER_REGISTRATION_TIME", (($current_user) ? strtotime ($current_user->user_registered) : 0)); /* Always an (int). Or 0 if they're not logged in. */
47
+ define ("S2MEMBER_CURRENT_USER_REGISTRATION_DAYS", (($current_user) ? floor ((strtotime ("now") - strtotime ($current_user->user_registered)) / 86400) : 0)); /* (int). */
48
+ define ("S2MEMBER_CURRENT_USER_DISPLAY_NAME", (($current_user) ? $current_user->display_name : "")); /* This will always be a (string). Empty if not logged in. */
49
+ define ("S2MEMBER_CURRENT_USER_FIRST_NAME", (($current_user) ? $current_user->user_firstname : "")); /* This will always be a (string). Empty if not logged in. */
50
+ define ("S2MEMBER_CURRENT_USER_LAST_NAME", (($current_user) ? $current_user->user_lastname : "")); /* This will always be a (string). Empty if not logged in. */
51
+ define ("S2MEMBER_CURRENT_USER_LOGIN", (($current_user) ? $current_user->user_login : "")); /* This will always be a (string). Empty if not logged in. */
52
+ define ("S2MEMBER_CURRENT_USER_EMAIL", (($current_user) ? $current_user->user_email : "")); /* This will always be a (string). Empty if not logged in. */
53
+ define ("S2MEMBER_CURRENT_USER_IP", $_SERVER["REMOTE_ADDR"]); /* This will always be a (string). It may be empty if the user is browsing anonymously. */
54
+ define ("S2MEMBER_CURRENT_USER_ID", (($current_user) ? (int)$current_user->ID : 0)); /* This will always be an (int). Zero if not logged in. */
55
+ define ("S2MEMBER_CURRENT_USER_FIELDS", (($current_user) ? json_encode (array_merge /* Always a json_encode (array). This includes custom fields. */
56
+ (array ("id" => S2MEMBER_CURRENT_USER_ID, "ip" => S2MEMBER_CURRENT_USER_IP, "email" => S2MEMBER_CURRENT_USER_EMAIL, "login" => S2MEMBER_CURRENT_USER_LOGIN,/**/
57
+ "first_name" => S2MEMBER_CURRENT_USER_FIRST_NAME, "last_name" => S2MEMBER_CURRENT_USER_LAST_NAME, "display_name" => S2MEMBER_CURRENT_USER_DISPLAY_NAME,/**/
58
+ "subscr_id" => S2MEMBER_CURRENT_USER_SUBSCR_ID, "custom" => S2MEMBER_CURRENT_USER_CUSTOM), $metas["s2member_custom_fields"])) : json_encode (array ())));
59
+ /**/
60
+ define ("S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED", (int)$file_downloads["allowed"]); /* This will always be an integer value (int) >= 0 where 0 means no access. */
61
+ define ("S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_IS_UNLIMITED", (($file_downloads["allowed"] >= 999999999) ? true : false)); /* This will always be (bool). */
62
+ define ("S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY", (int)$file_downloads["currently"]); /* This will always be an integer value (int) >= 0 where 0 means none currently. */
63
+ define ("S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS", (int)$file_downloads["allowed_days"]); /* This will always be an integer value (int) >= 0 where 0 means no access. */
64
+ /**/
65
+ define ("S2MEMBER_FILE_DOWNLOAD_LIMIT_EXCEEDED_PAGE_ID", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"]); /* The exceeded page id (int). */
66
+ define ("S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_ID", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]); /* Options page id, always an (int). */
67
+ define ("S2MEMBER_LOGIN_WELCOME_PAGE_ID", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"]); /* The welcome page id, always an (int). */
68
+ /**/
69
+ define ("S2MEMBER_CURRENT_USER_PROFILE_MODIFICATION_PAGE_URL", get_bloginfo ("url") . "/?s2member_profile=1"); /* Where a user modifies their profile. */
70
+ define ("S2MEMBER_FILE_DOWNLOAD_LIMIT_EXCEEDED_PAGE_URL", $links["file_download_limit_exceeded_page"]); /* Always a string. URL to limit exceeded page. */
71
+ define ("S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL", $links["membership_options_page"]); /* Always a string. This is the URL to the membership options page. */
72
+ define ("S2MEMBER_LOGIN_WELCOME_PAGE_URL", (($login_redirection_override) ? $login_redirection_override : $links["login_welcome_page"])); /* Always a string. */
73
+ define ("S2MEMBER_LOGOUT_PAGE_URL", wp_logout_url ()); /* This is always the same, it is the default wordpress action=logout url generated by wp_logout_url(). */
74
+ define ("S2MEMBER_LOGIN_PAGE_URL", wp_login_url ()); /* This is always the same, it is the default wordpress login url that is generated by wp_login_url(). */
75
+ /**/
76
+ define ("S2MEMBER_LEVEL1_LABEL", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_label"]); /* This is the (string) label that you created for membership level number 1. */
77
+ define ("S2MEMBER_LEVEL2_LABEL", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_label"]); /* This is the (string) label that you created for membership level number 2. */
78
+ define ("S2MEMBER_LEVEL3_LABEL", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_label"]); /* This is the (string) label that you created for membership level number 3. */
79
+ define ("S2MEMBER_LEVEL4_LABEL", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_label"]); /* This is the (string) label that you created for membership level number 4. */
80
+ /**/
81
+ define ("S2MEMBER_LEVEL1_FILE_DOWNLOADS_ALLOWED", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed"]); /* This is the (int) allowed downloads. */
82
+ define ("S2MEMBER_LEVEL2_FILE_DOWNLOADS_ALLOWED", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed"]); /* This is the (int) allowed downloads. */
83
+ define ("S2MEMBER_LEVEL3_FILE_DOWNLOADS_ALLOWED", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed"]); /* This is the (int) allowed downloads. */
84
+ define ("S2MEMBER_LEVEL4_FILE_DOWNLOADS_ALLOWED", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed"]); /* This is the (int) allowed downloads. */
85
+ /**/
86
+ define ("S2MEMBER_LEVEL1_FILE_DOWNLOADS_ALLOWED_DAYS", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed_days"]); /* This is (int) allowed days. */
87
+ define ("S2MEMBER_LEVEL2_FILE_DOWNLOADS_ALLOWED_DAYS", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed_days"]); /* This is (int) allowed days. */
88
+ define ("S2MEMBER_LEVEL3_FILE_DOWNLOADS_ALLOWED_DAYS", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed_days"]); /* This is (int) allowed days. */
89
+ define ("S2MEMBER_LEVEL4_FILE_DOWNLOADS_ALLOWED_DAYS", (int)$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed_days"]); /* This is (int) allowed days. */
90
+ /**/
91
+ define ("S2MEMBER_FILE_DOWNLOAD_INLINE_EXTENSIONS", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_inline_extensions"]); /* This is the (string) list of extensions. */
92
+ /**/
93
+ define ("S2MEMBER_REG_EMAIL_FROM_NAME", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_name"]); /* This is the name that outgoing email messages are sent by. */
94
+ define ("S2MEMBER_REG_EMAIL_FROM_EMAIL", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_email"]); /* This is the email that outgoing messages are sent by. */
95
+ /**/
96
+ define ("S2MEMBER_PAYPAL_NOTIFY_URL", get_bloginfo ("url") . "/?s2member_paypal_notify=1"); /* This will always be a (string), and it will never be an empty value. */
97
+ define ("S2MEMBER_PAYPAL_RETURN_URL", get_bloginfo ("url") . "/?s2member_paypal_return=1"); /* This will always be a (string), and it will never be an empty value. */
98
+ define ("S2MEMBER_PAYPAL_ENDPOINT", (($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_sandbox"]) ? "www.sandbox.paypal.com" : "www.paypal.com")); /* Using sandbox? */
99
+ define ("S2MEMBER_PAYPAL_BUSINESS", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_business"]); /* This is the email address that identifies your paypal business. */
100
+ /**/
101
+ define ("S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON0", ((S2MEMBER_CURRENT_USER_SUBSCR_ID && !ws_plugin__s2member_user_has_wp_role ($current_user)) ? "Updating Subscr. ID" : ""));
102
+ define ("S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS0", ((S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON0) ? S2MEMBER_CURRENT_USER_SUBSCR_ID : "")); /* ^ Not for built-in WP Roles. */
103
+ /**/
104
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
105
+ do_action ("ws_plugin__s2member_after_constants", get_defined_vars ());
106
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
107
+ /**/
108
+ return;
109
+ }
110
}
111
/*
112
This function pulls all of the page links needed for Constants.
114
This allows the API Constants to provide quick access to them without being
115
forced to execute get_page_link() all the time, which piles up DB queries.
116
*/
117
+ if (!function_exists ("ws_plugin__s2member_constant_links"))
118
{
119
+ function ws_plugin__s2member_constant_links ()
120
{
121
+ do_action ("ws_plugin__s2member_before_constant_links", get_defined_vars ());
122
/**/
123
+ $cache_minutes = 15; /* Could be higher? */
124
/**/
125
+ $l["login_welcome_page"] = (string)"";
126
+ $l["membership_options_page"] = (string)"";
127
+ $l["file_download_limit_exceeded_page"] = (string)"";
128
/**/
129
+ $login_welcome_page = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"];
130
+ $membership_options_page = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"];
131
+ $file_download_limit_exceeded_page = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"];
132
+ /**/
133
+ $login_welcome_page_cache = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"];
134
+ $membership_options_page_cache = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"];
135
+ $file_download_limit_exceeded_page_cache = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"];
136
+ /**/
137
+ if ($login_welcome_page && $login_welcome_page_cache["page"] === $login_welcome_page && $login_welcome_page_cache["link"] && $login_welcome_page_cache["time"] >= strtotime ("-" . $cache_minutes . " minutes"))
138
+ {
139
+ $l["login_welcome_page"] = $login_welcome_page_cache["link"];
140
+ }
141
+ else /* Otherwise, we need to query the database using get_page_link() and update the cache. */
142
+ {
143
+ $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["time"] = strtotime ("now");
144
+ $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["page"] = $login_welcome_page;
145
+ $l["login_welcome_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["link"] = get_page_link ($login_welcome_page);
146
+ /**/
147
+ $cache_needs_updating = true;
148
+ }
149
+ /**/
150
+ if ($membership_options_page && $membership_options_page_cache["page"] === $membership_options_page && $membership_options_page_cache["link"] && $membership_options_page_cache["time"] >= strtotime ("-" . $cache_minutes . " minutes"))
151
+ {
152
+ $l["membership_options_page"] = $membership_options_page_cache["link"];
153
+ }
154
+ else /* Otherwise, we need to query the database using get_page_link() and update the cache. */
155
+ {
156
+ $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["time"] = strtotime ("now");
157
+ $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["page"] = $membership_options_page;
158
+ $l["membership_options_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["link"] = get_page_link ($membership_options_page);
159
+ /**/
160
+ $cache_needs_updating = true;
161
+ }
162
+ /**/
163
+ if ($file_download_limit_exceeded_page && $file_download_limit_exceeded_page_cache["page"] === $file_download_limit_exceeded_page && $file_download_limit_exceeded_page_cache["link"] && $file_download_limit_exceeded_page_cache["time"] >= strtotime ("-" . $cache_minutes . " minutes"))
164
+ {
165
+ $l["file_download_limit_exceeded_page"] = $file_download_limit_exceeded_page_cache["link"];
166
+ }
167
+ else /* Otherwise, we need to query the database using get_page_link() and update the cache. */
168
+ {
169
+ $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["time"] = strtotime ("now");
170
+ $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["page"] = $file_download_limit_exceeded_page;
171
+ $l["file_download_limit_exceeded_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["link"] = get_page_link ($file_download_limit_exceeded_page);
172
+ /**/
173
+ $cache_needs_updating = true;
174
+ }
175
+ /**/
176
+ if ($cache_needs_updating) /* The cache is also reset when options are updated from a menu page. */
177
+ {
178
+ update_option ("ws_plugin__s2member_cache", $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]);
179
+ }
180
+ /**/
181
+ return apply_filters ("ws_plugin__s2member_constant_links", $l, get_defined_vars ());
182
}
183
}
184
/*
185
This function pulls all of the usermeta details needed for Constants.
186
Pulling them all at once helps to prevent repeated database queries.
187
*/
188
+ if (!function_exists ("ws_plugin__s2member_constant_metas"))
189
{
190
+ function ws_plugin__s2member_constant_metas ()
191
{
192
+ global $wpdb; /* The global database object. */
193
+ /**/
194
+ do_action ("ws_plugin__s2member_before_constant_metas", get_defined_vars ());
195
+ /**/
196
+ $m["s2member_file_download_access_log"] = array ();
197
+ $m["s2member_custom_fields"] = array ();
198
+ $m["s2member_subscr_id"] = (string)"";
199
+ $m["s2member_custom"] = (string)"";
200
+ /**/
201
+ if (($current_user = (is_user_logged_in ()) ? wp_get_current_user () : false))
202
{
203
+ if (is_array ($results = $wpdb->get_results ("SELECT `meta_key`, `meta_value` FROM `" . $wpdb->usermeta . "` WHERE `user_id` = '" . $current_user->ID . "' AND (meta_key = 's2member_file_download_access_log' OR meta_key = 's2member_subscr_id' OR meta_key = 's2member_custom') LIMIT 3")))
204
+ {
205
+ foreach ($results as $r) /* Fill in the array we need. */
206
+ if ($r->meta_key === "s2member_file_download_access_log")
207
+ $m["s2member_file_download_access_log"] = (array)maybe_unserialize ($r->meta_value);
208
+ else if ($result->meta_key === "s2member_custom_fields")
209
+ $m["s2member_custom_fields"] = (array)maybe_unserialize ($r->meta_value);
210
+ else if ($r->meta_key === "s2member_subscr_id")
211
+ $m["s2member_subscr_id"] = (string)$r->meta_value;
212
+ else if ($result->meta_key === "s2member_custom")
213
+ $m["s2member_custom"] = (string)$r->meta_value;
214
+ /**/
215
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
216
+ do_action ("ws_plugin__s2member_during_constant_metas", get_defined_vars ());
217
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
218
+ }
219
}
220
+ /**/
221
+ return apply_filters ("ws_plugin__s2member_constant_metas", $m, get_defined_vars ());
222
}
223
}
224
?>
includes/functions/email-configs.inc.php CHANGED
@@ -16,29 +16,38 @@ if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
16
/*
17
Functions that modify the email From: name/address.
18
*/
19
- function ws_plugin__s2member_email_config ()
20
{
21
- do_action ("s2member_before_email_config", get_defined_vars ());
22
- /**/
23
- add_filter ("wp_mail_from", "_ws_plugin__s2member_email_config_email");
24
- add_filter ("wp_mail_from_name", "_ws_plugin__s2member_email_config_name");
25
- /**/
26
- do_action ("s2member_after_email_config", get_defined_vars ());
27
- /**/
28
- return;
29
}
30
/**/
31
- function _ws_plugin__s2member_email_config_email ($email = FALSE)
32
{
33
- do_action ("s2member_before_email_config_email", get_defined_vars ());
34
- /**/
35
- return apply_filters ("s2member_email_config_email", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_email"], get_defined_vars ());
36
}
37
/**/
38
- function _ws_plugin__s2member_email_config_name ($name = FALSE)
39
{
40
- do_action ("s2member_before_email_config_name", get_defined_vars ());
41
- /**/
42
- return apply_filters ("s2member_email_config_name", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_name"], get_defined_vars ());
43
}
44
?>
16
/*
17
Functions that modify the email From: name/address.
18
*/
19
+ if (!function_exists ("ws_plugin__s2member_email_config"))
20
{
21
+ function ws_plugin__s2member_email_config ()
22
+ {
23
+ do_action ("ws_plugin__s2member_before_email_config", get_defined_vars ());
24
+ /**/
25
+ add_filter ("wp_mail_from", "_ws_plugin__s2member_email_config_email");
26
+ add_filter ("wp_mail_from_name", "_ws_plugin__s2member_email_config_name");
27
+ /**/
28
+ do_action ("ws_plugin__s2member_after_email_config", get_defined_vars ());
29
+ /**/
30
+ return;
31
+ }
32
}
33
/**/
34
+ if (!function_exists ("_ws_plugin__s2member_email_config_email"))
35
{
36
+ function _ws_plugin__s2member_email_config_email ($email = FALSE)
37
+ {
38
+ do_action ("_ws_plugin__s2member_before_email_config_email", get_defined_vars ());
39
+ /**/
40
+ return apply_filters ("_ws_plugin__s2member_email_config_email", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_email"], get_defined_vars ());
41
+ }
42
}
43
/**/
44
+ if (!function_exists ("_ws_plugin__s2member_email_config_name"))
45
{
46
+ function _ws_plugin__s2member_email_config_name ($name = FALSE)
47
+ {
48
+ do_action ("_ws_plugin__s2member_before_email_config_name", get_defined_vars ());
49
+ /**/
50
+ return apply_filters ("_ws_plugin__s2member_email_config_name", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_name"], get_defined_vars ());
51
+ }
52
}
53
?>
includes/functions/file-download-access.inc.php CHANGED
@@ -17,222 +17,236 @@ if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
17
Function determines the max period in days for download access.
18
Returns number of days, where 0 means no access to files has been allowed.
19
*/
20
- function ws_plugin__s2member_max_download_period ()
21
{
22
- do_action ("s2member_before_max_download_period", get_defined_vars ());
23
- /**/
24
- if ($days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed_days"])
25
{
26
- $max = ($max < $days) ? $days : $max;
27
- }
28
- /**/
29
- if ($days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed_days"])
30
- {
31
- $max = ($max < $days) ? $days : $max;
32
- }
33
- /**/
34
- if ($days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed_days"])
35
- {
36
- $max = ($max < $days) ? $days : $max;
37
- }
38
- /**/
39
- if ($days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed_days"])
40
- {
41
- $max = ($max < $days) ? $days : $max;
42
}
43
- /**/
44
- return apply_filters ("s2member_max_download_period", (($max > 365) ? 365 : (int)$max), get_defined_vars ());
45
}
46
/*
47
Function determines how many downloads allowed - etc, etc.
48
Returns an array with 3 elements: allowed, allowed_days, currently.
49
The 2nd parameter can be used to prevent another database connection.
50
*/
51
- function ws_plugin__s2member_user_downloads ($not_counting_this_particular_file = false, $log = null)
52
{
53
- do_action ("s2member_before_user_downloads", get_defined_vars ());
54
- /**/
55
- if (($current_user = (is_user_logged_in ()) ? wp_get_current_user () : false))
56
{
57
- if (current_user_can ("access_s2member_level1") && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed"])
58
- {
59
- $allowed = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed"];
60
- $allowed_days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed_days"];
61
- }
62
/**/
63
- if (current_user_can ("access_s2member_level2") && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed"])
64
{
65
- $allowed = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed"];
66
- $allowed_days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed_days"];
67
- }
68
- /**/
69
- if (current_user_can ("access_s2member_level3") && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed"])
70
- {
71
- $allowed = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed"];
72
- $allowed_days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed_days"];
73
- }
74
- /**/
75
- if (current_user_can ("access_s2member_level4") && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed"])
76
- {
77
- $allowed = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed"];
78
- $allowed_days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed_days"];
79
}
80
/**/
81
- $file_download_access_log = (isset ($log)) ? (array)$log : (array)get_usermeta ($current_user->ID, "s2member_file_download_access_log");
82
- foreach ($file_download_access_log as $file_download_access_log_entry_key => $file_download_access_log_entry)
83
- if (strtotime ($file_download_access_log_entry["date"]) >= strtotime ("-" . (int)$allowed_days . " days"))
84
- if ($file_download_access_log_entry["file"] !== $not_counting_this_particular_file)
85
- $currently = ($currently) ? $currently + 1 : 1;
86
}
87
- /**/
88
- return apply_filters ("s2member_user_downloads", array ("allowed" => (int)$allowed, "allowed_days" => (int)$allowed_days, "currently" => (int)$currently), get_defined_vars ());
89
}
90
/*
91
Function determines the minimum level required for file download access.
92
Returns 0-4, where 0 means no access to file downloads has been allowed.
93
*/
94
- function ws_plugin__s2member_min_level_4_downloads ()
95
{
96
- do_action ("s2member_before_min_level_4_downloads", get_defined_vars ());
97
- /**/
98
- if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed"] && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed_days"])
99
- {
100
- $file_download_access_is_allowed = $min_level_4_downloads = 1;
101
- }
102
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed"] && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed_days"])
103
{
104
- $file_download_access_is_allowed = $min_level_4_downloads = 2;
105
- }
106
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed"] && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed_days"])
107
- {
108
- $file_download_access_is_allowed = $min_level_4_downloads = 3;
109
- }
110
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed"] && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed_days"])
111
- {
112
- $file_download_access_is_allowed = $min_level_4_downloads = 4;
113
}
114
- /**/
115
- return apply_filters ("s2member_min_level_4_downloads", (int)$min_level_4_downloads, get_defined_vars ());
116
}
117
/*
118
Function for handling download access permissions.
119
Attach to: add_action("init");
120
*/
121
- function ws_plugin__s2member_check_file_download_access ()
122
{
123
- do_action ("s2member_before_file_download_access", get_defined_vars ());
124
- /**/
125
- if ($_GET["s2member_file_download"]) /* Filter $excluded to force free downloads. */
126
{
127
- $excluded = apply_filters ("s2member_check_file_download_access_excluded", false, get_defined_vars ()); /* Or use $_GET["s2member_free_file_download_key"] with a hash of the xencrypted version. */
128
/**/
129
- if (!$excluded && (!$_GET["s2member_free_file_download_key"] || ($_GET["s2member_free_file_download_key"] !== md5 (ws_plugin__s2member_xencrypt ($_GET["s2member_file_download"]))/**/
130
- /* For backward compatiblity, we also check the xencrypted value, without the hash. This is decprecated as of v2.9. It will be removed completely in a future version. */
131
- && $_GET["s2member_free_file_download_key"] !== ws_plugin__s2member_xencrypt ($_GET["s2member_file_download"]))))
132
{
133
- $_GET["s2member_file_download"] = trim ($_GET["s2member_file_download"], "/");
134
- /**/
135
- $file_download_access_is_allowed = $minimum_level_required_to_download_files = ws_plugin__s2member_min_level_4_downloads ();
136
- /**/
137
- if (!($current_user = (is_user_logged_in ()) ? wp_get_current_user () : false) /* Redirect Users who are not logged in. */
138
- && wp_redirect (add_query_arg (array ("s2member_level_req" => $minimum_level_required_to_download_files, "s2member_file_download_req" => $_GET["s2member_file_download"]), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
139
- exit;
140
- /**/
141
- else if (!$file_download_access_is_allowed) /* Have file downloads even been enabled? */
142
- {
143
- header ("HTTP/1.0 503 Service Temporarily Unavailable");
144
- echo '503: File Downloads Are Not Enabled.';
145
- exit;
146
- }
147
- /**/
148
- else if (!file_exists ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"] . "/" . $_GET["s2member_file_download"]))
149
- {
150
- header ("HTTP/1.0 404 Not Found"); /* The file does not even exist. */
151
- echo '404: File Download Not Found.';
152
- exit;
153
- }
154
- /**/
155
- else if ((!is_array ($file_downloads = ws_plugin__s2member_user_downloads ()) || !$file_downloads["allowed"] || !$file_downloads["allowed_days"])/**/
156
- && wp_redirect (add_query_arg (array ("s2member_file_download_req" => $_GET["s2member_file_download"]), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"]))) !== "nill")
157
- exit;
158
- /**/
159
- $previous_file_downloads = 0; /* Here we're going to count how many downloads they've performed. */
160
- $max_days_logged = ws_plugin__s2member_max_download_period (); /* The longest period in days. */
161
- $file_download_access_log = (array)get_usermeta ($current_user->ID, "s2member_file_download_access_log");
162
- $file_download_access_arc = (array)get_usermeta ($current_user->ID, "s2member_file_download_access_arc");
163
/**/
164
- foreach ($file_download_access_log as $file_download_access_log_entry_key => $file_download_access_log_entry)
165
{
166
- if (strtotime ($file_download_access_log_entry["date"]) < strtotime ("-" . $max_days_logged . " days"))
167
{
168
- unset ($file_download_access_log[$file_download_access_log_entry_key]);
169
- $file_download_access_arc[] = $file_download_access_log_entry;
170
}
171
- else if (strtotime ($file_download_access_log_entry["date"]) >= strtotime ("-" . $file_downloads["allowed_days"] . " days"))
172
{
173
- $previous_file_downloads++;
174
- /* Here we check if this file has already been downloaded. */
175
- if ($file_download_access_log_entry["file"] === $_GET["s2member_file_download"])
176
- $already_downloaded = true;
177
}
178
}
179
/**/
180
- if (!$already_downloaded && $previous_file_downloads >= $file_downloads["allowed"] /* They have NOT already downloaded this file, and they're over their limit. */
181
- && wp_redirect (add_query_arg (array ("s2member_file_download_req" => $_GET["s2member_file_download"]), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"]))) !== "nill")
182
- exit;
183
/**/
184
- if (!$already_downloaded) /* Only add this file to the log if they have not already downloaded it. */
185
- $file_download_access_log[] = array ("date" => date ("Y-m-d"), "file" => $_GET["s2member_file_download"]);
186
/**/
187
- update_usermeta ($current_user->ID, "s2member_file_download_access_arc", ws_plugin__s2member_array_unique ($file_download_access_arc));
188
- update_usermeta ($current_user->ID, "s2member_file_download_access_log", ws_plugin__s2member_array_unique ($file_download_access_log));
189
- }
190
- else /* This is a free download that we just need to check on the existence of. */
191
- {
192
- $_GET["s2member_file_download"] = trim ($_GET["s2member_file_download"], "/");
193
/**/
194
- if (!file_exists ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"] . "/" . $_GET["s2member_file_download"]))
195
- {
196
- header ("HTTP/1.0 404 Not Found"); /* The file does not exist. */
197
- echo '404: File Download Not Found.';
198
- exit;
199
- }
200
}
201
- /*
202
- Here we are going to put together all of the file download information.
203
- */
204
- $mimetypes = parse_ini_file (dirname (dirname (dirname (__FILE__))) . "/includes/mime-types.ini");
205
- $pathinfo = pathinfo ($file = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"] . "/" . $_GET["s2member_file_download"]);
206
- $extension = strtolower ($pathinfo["extension"]); /* Convert file extension to lowercase format for MIME type lookup. */
207
- $inline = (in_array ($extension, preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_inline_extensions"]))) ? true : false;
208
- $mimetype = ($mimetypes[$extension]) ? $mimetypes[$extension] : "application/octet-stream"; /* Lookup MIME type. */
209
- $basename = $pathinfo["basename"]; /* The actual file name, including its extension. */
210
- $length = filesize ($file); /* The overall file size, in bytes. */
211
- /**/
212
- do_action ("s2member_during_file_download_access", get_defined_vars ());
213
- /*
214
- Now send the file to the browser. Be sure to turn off output compression.
215
- */
216
- ini_set ("zlib.output_compression", 0); /* Must be turned off. */
217
- /**/
218
- header ("Content-Encoding: none");
219
- header ("Content-Type: " . $mimetype);
220
- header ("Content-Length: " . $length);
221
- /**/
222
- if (!$inline) /* If not inline, we default to serving the file as an attachment. */
223
- header ('Content-Disposition: attachment; filename="' . $basename . '"');
224
- /**/
225
- header ("Expires: " . gmdate ("D, d M Y H:i:s", strtotime ("-1 week")) . " GMT");
226
- header ("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT");
227
- header ("Cache-Control: no-cache, must-revalidate, max-age=0");
228
- header ("Cache-Control: post-check=0, pre-check=0", false);
229
- header ("Pragma: no-cache");
230
- /**/
231
- readfile ($file);
232
/**/
233
- exit;
234
}
235
- /**/
236
- do_action ("s2member_after_file_download_access", get_defined_vars ());
237
}
238
?>
17
Function determines the max period in days for download access.
18
Returns number of days, where 0 means no access to files has been allowed.
19
*/
20
+ if (!function_exists ("ws_plugin__s2member_max_download_period"))
21
{
22
+ function ws_plugin__s2member_max_download_period ()
23
{
24
+ do_action ("ws_plugin__s2member_before_max_download_period", get_defined_vars ());
25
+ /**/
26
+ if ($days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed_days"])
27
+ {
28
+ $max = ($max < $days) ? $days : $max;
29
+ }
30
+ /**/
31
+ if ($days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed_days"])
32
+ {
33
+ $max = ($max < $days) ? $days : $max;
34
+ }
35
+ /**/
36
+ if ($days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed_days"])
37
+ {
38
+ $max = ($max < $days) ? $days : $max;
39
+ }
40
+ /**/
41
+ if ($days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed_days"])
42
+ {
43
+ $max = ($max < $days) ? $days : $max;
44
+ }
45
+ /**/
46
+ return apply_filters ("ws_plugin__s2member_max_download_period", (($max > 365) ? 365 : (int)$max), get_defined_vars ());
47
}
48
}
49
/*
50
Function determines how many downloads allowed - etc, etc.
51
Returns an array with 3 elements: allowed, allowed_days, currently.
52
The 2nd parameter can be used to prevent another database connection.
53
*/
54
+ if (!function_exists ("ws_plugin__s2member_user_downloads"))
55
{
56
+ function ws_plugin__s2member_user_downloads ($not_counting_this_particular_file = false, $log = null)
57
{
58
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
59
+ do_action ("ws_plugin__s2member_before_user_downloads", get_defined_vars ());
60
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
61
/**/
62
+ if (($current_user = (is_user_logged_in ()) ? wp_get_current_user () : false))
63
{
64
+ if (current_user_can ("access_s2member_level1") && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed"])
65
+ {
66
+ $allowed = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed"];
67
+ $allowed_days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed_days"];
68
+ }
69
+ /**/
70
+ if (current_user_can ("access_s2member_level2") && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed"])
71
+ {
72
+ $allowed = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed"];
73
+ $allowed_days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed_days"];
74
+ }
75
+ /**/
76
+ if (current_user_can ("access_s2member_level3") && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed"])
77
+ {
78
+ $allowed = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed"];
79
+ $allowed_days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed_days"];
80
+ }
81
+ /**/
82
+ if (current_user_can ("access_s2member_level4") && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed"])
83
+ {
84
+ $allowed = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed"];
85
+ $allowed_days = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed_days"];
86
+ }
87
+ /**/
88
+ $file_download_access_log = (isset ($log)) ? (array)$log : (array)get_usermeta ($current_user->ID, "s2member_file_download_access_log");
89
+ foreach ($file_download_access_log as $file_download_access_log_entry_key => $file_download_access_log_entry)
90
+ if (strtotime ($file_download_access_log_entry["date"]) >= strtotime ("-" . (int)$allowed_days . " days"))
91
+ if ($file_download_access_log_entry["file"] !== $not_counting_this_particular_file)
92
+ $currently = ($currently) ? $currently + 1 : 1;
93
}
94
/**/
95
+ return apply_filters ("ws_plugin__s2member_user_downloads", array ("allowed" => (int)$allowed, "allowed_days" => (int)$allowed_days, "currently" => (int)$currently), get_defined_vars ());
96
}
97
}
98
/*
99
Function determines the minimum level required for file download access.
100
Returns 0-4, where 0 means no access to file downloads has been allowed.
101
*/
102
+ if (!function_exists ("ws_plugin__s2member_min_level_4_downloads"))
103
{
104
+ function ws_plugin__s2member_min_level_4_downloads ()
105
{
106
+ do_action ("ws_plugin__s2member_before_min_level_4_downloads", get_defined_vars ());
107
+ /**/
108
+ if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed"] && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_file_downloads_allowed_days"])
109
+ {
110
+ $file_download_access_is_allowed = $min_level_4_downloads = 1;
111
+ }
112
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed"] && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level2_file_downloads_allowed_days"])
113
+ {
114
+ $file_download_access_is_allowed = $min_level_4_downloads = 2;
115
+ }
116
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed"] && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level3_file_downloads_allowed_days"])
117
+ {
118
+ $file_download_access_is_allowed = $min_level_4_downloads = 3;
119
+ }
120
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed"] && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level4_file_downloads_allowed_days"])
121
+ {
122
+ $file_download_access_is_allowed = $min_level_4_downloads = 4;
123
+ }
124
+ /**/
125
+ return apply_filters ("ws_plugin__s2member_min_level_4_downloads", (int)$min_level_4_downloads, get_defined_vars ());
126
}
127
}
128
/*
129
Function for handling download access permissions.
130
Attach to: add_action("init");
131
*/
132
+ if (!function_exists ("ws_plugin__s2member_check_file_download_access"))
133
{
134
+ function ws_plugin__s2member_check_file_download_access ()
135
{
136
+ do_action ("ws_plugin__s2member_before_file_download_access", get_defined_vars ());
137
/**/
138
+ if ($_GET["s2member_file_download"]) /* Filter $excluded to force free downloads. */
139
{
140
+ $excluded = apply_filters ("ws_plugin__s2member_check_file_download_access_excluded", false, get_defined_vars ()); /* Or use $_GET["s2member_free_file_download_key"]. */
141
/**/
142
+ if (!$excluded && (!$_GET["s2member_free_file_download_key"] || ($_GET["s2member_free_file_download_key"] !== md5 (ws_plugin__s2member_xencrypt ($_GET["s2member_file_download"])))))
143
{
144
+ $_GET["s2member_file_download"] = trim ($_GET["s2member_file_download"], "/");
145
+ /**/
146
+ $file_download_access_is_allowed = $minimum_level_required_to_download_files = ws_plugin__s2member_min_level_4_downloads ();
147
+ /**/
148
+ if (!($current_user = (is_user_logged_in ()) ? wp_get_current_user () : false) /* Redirect Users who are not logged in. */
149
+ && wp_redirect (add_query_arg (array ("s2member_level_req" => $minimum_level_required_to_download_files, "s2member_file_download_req" => $_GET["s2member_file_download"]), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]))) !== "nill")
150
+ exit;
151
+ /**/
152
+ else if (!$file_download_access_is_allowed) /* Have file downloads even been enabled? */
153
+ {
154
+ header ("HTTP/1.0 503 Service Temporarily Unavailable");
155
+ echo '503: File Downloads Are Not Enabled.';
156
+ exit;
157
+ }
158
+ /**/
159
+ else if (!file_exists ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"] . "/" . $_GET["s2member_file_download"]))
160
{
161
+ header ("HTTP/1.0 404 Not Found"); /* The file does not even exist. */
162
+ echo '404: File Download Not Found.';
163
+ exit;
164
}
165
+ /**/
166
+ else if ((!is_array ($file_downloads = ws_plugin__s2member_user_downloads ()) || !$file_downloads["allowed"] || !$file_downloads["allowed_days"])/**/
167
+ && wp_redirect (add_query_arg (array ("s2member_file_download_req" => $_GET["s2member_file_download"]), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"]))) !== "nill")
168
+ exit;
169
+ /**/
170
+ $previous_file_downloads = 0; /* Here we're going to count how many downloads they've performed. */
171
+ $max_days_logged = ws_plugin__s2member_max_download_period (); /* The longest period in days. */
172
+ $file_download_access_log = (array)get_usermeta ($current_user->ID, "s2member_file_download_access_log");
173
+ $file_download_access_arc = (array)get_usermeta ($current_user->ID, "s2member_file_download_access_arc");
174
+ /**/
175
+ foreach ($file_download_access_log as $file_download_access_log_entry_key => $file_download_access_log_entry)
176
{
177
+ if (strtotime ($file_download_access_log_entry["date"]) < strtotime ("-" . $max_days_logged . " days"))
178
+ {
179
+ unset ($file_download_access_log[$file_download_access_log_entry_key]);
180
+ $file_download_access_arc[] = $file_download_access_log_entry;
181
+ }
182
+ else if (strtotime ($file_download_access_log_entry["date"]) >= strtotime ("-" . $file_downloads["allowed_days"] . " days"))
183
+ {
184
+ $previous_file_downloads++;
185
+ /* Here we check if this file has already been downloaded. */
186
+ if ($file_download_access_log_entry["file"] === $_GET["s2member_file_download"])
187
+ $already_downloaded = true;
188
+ }
189
}
190
+ /**/
191
+ if (!$already_downloaded && $previous_file_downloads >= $file_downloads["allowed"] /* They have NOT already downloaded this file, and they're over their limit. */
192
+ && wp_redirect (add_query_arg (array ("s2member_file_download_req" => $_GET["s2member_file_download"]), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"]))) !== "nill")
193
+ exit;
194
+ /**/
195
+ if (!$already_downloaded) /* Only add this file to the log if they have not already downloaded it. */
196
+ $file_download_access_log[] = array ("date" => date ("Y-m-d"), "file" => $_GET["s2member_file_download"]);
197
+ /**/
198
+ update_usermeta ($current_user->ID, "s2member_file_download_access_arc", ws_plugin__s2member_array_unique ($file_download_access_arc));
199
+ update_usermeta ($current_user->ID, "s2member_file_download_access_log", ws_plugin__s2member_array_unique ($file_download_access_log));
200
}
201
+ else /* This is a free download that we just need to check on the existence of. */
202
+ {
203
+ $_GET["s2member_file_download"] = trim ($_GET["s2member_file_download"], "/");
204
+ /**/
205
+ if (!file_exists ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"] . "/" . $_GET["s2member_file_download"]))
206
+ {
207
+ header ("HTTP/1.0 404 Not Found"); /* The file does not exist. */
208
+ echo '404: File Download Not Found.';
209
+ exit;
210
+ }
211
+ }
212
+ /*
213
+ Here we are going to put together all of the file download information.
214
+ */
215
+ $mimetypes = parse_ini_file (dirname (dirname (dirname (__FILE__))) . "/includes/mime-types.ini");
216
+ $pathinfo = pathinfo ($file = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"] . "/" . $_GET["s2member_file_download"]);
217
+ $extension = strtolower ($pathinfo["extension"]); /* Convert file extension to lowercase format for MIME type lookup. */
218
+ $inline = (in_array ($extension, preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_inline_extensions"]))) ? true : false;
219
+ $mimetype = ($mimetypes[$extension]) ? $mimetypes[$extension] : "application/octet-stream"; /* Lookup MIME type. */
220
+ $basename = $pathinfo["basename"]; /* The actual file name, including its extension. */
221
+ $length = filesize ($file); /* The overall file size, in bytes. */
222
/**/
223
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
224
+ do_action ("ws_plugin__s2member_during_file_download_access", get_defined_vars ());
225
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
226
+ /*
227
+ Now send the file to the browser. Be sure to turn off output compression.
228
+ */
229
+ ini_set ("zlib.output_compression", 0); /* Must be turned off. */
230
/**/
231
+ header ("Content-Encoding: none");
232
+ header ("Content-Type: " . $mimetype);
233
+ header ("Content-Length: " . $length);
234
/**/
235
+ if (!$inline) /* If not inline, we default to serving the file as an attachment. */
236
+ header ('Content-Disposition: attachment; filename="' . $basename . '"');
237
/**/
238
+ header ("Expires: " . gmdate ("D, d M Y H:i:s", strtotime ("-1 week")) . " GMT");
239
+ header ("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT");
240
+ header ("Cache-Control: no-cache, must-revalidate, max-age=0");
241
+ header ("Cache-Control: post-check=0, pre-check=0", false);
242
+ header ("Pragma: no-cache");
243
+ /**/
244
+ readfile ($file);
245
+ /**/
246
+ exit;
247
}
<