-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmemberpress.php
More file actions
327 lines (281 loc) · 12.3 KB
/
memberpress.php
File metadata and controls
327 lines (281 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?php
/*
Plugin Name: MemberPress Pro 30 (Legacy)
Plugin URI: https://memberpress.com/
Description: The membership plugin that makes it easy to accept payments for access to your content and digital products.
Version: 1.12.15
Requires at least: 6.5
Tested up to: 6.9
Requires PHP: 7.4
License: GPL v2+
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Author: Caseproof, LLC
Author URI: https://caseproof.com/
Text Domain: memberpress
*/
/**
* * * * * * * * * * * * * * * * * * * * * * *
* *
* Reporting a Security Vulnerability *
* *
* Please disclose any security issues or *
* vulnerabilities to security@caseproof.com *
* *
* * * * * * * * * * * * * * * * * * * * * * *
*/
if (!defined('ABSPATH')) {
die('You are not allowed to call this page directly.');
}
require_once __DIR__ . '/vendor-prefixed/autoload.php';
define('MEPR_PLUGIN_SLUG', 'memberpress/memberpress.php');
define('MEPR_PLUGIN_NAME', 'memberpress');
define('MEPR_PATH', __DIR__);
define('MEPR_IMAGES_PATH', MEPR_PATH . '/images');
define('MEPR_BRAND_PATH', MEPR_PATH . '/brand');
define('MEPR_BRAND_CTRLS_PATH', MEPR_BRAND_PATH . '/controllers');
define('MEPR_BRAND_ADDONS_PATH', MEPR_BRAND_PATH . '/add-ons');
define('MEPR_CSS_PATH', MEPR_PATH . '/css');
define('MEPR_JS_PATH', MEPR_PATH . '/js');
define('MEPR_I18N_PATH', MEPR_PATH . '/i18n');
define('MEPR_LIB_PATH', MEPR_PATH . '/app/lib');
define('MEPR_INTEGRATIONS_PATH', MEPR_PATH . '/app/integrations');
define('MEPR_INTERFACES_PATH', MEPR_PATH . '/app/lib/interfaces');
define('MEPR_DATA_PATH', MEPR_PATH . '/app/data');
define('MEPR_BRAND_DATA_PATH', MEPR_BRAND_PATH . '/data');
define('MEPR_FONTS_PATH', MEPR_PATH . '/fonts');
define('MEPR_APIS_PATH', MEPR_PATH . '/app/apis');
define('MEPR_MODELS_PATH', MEPR_PATH . '/app/models');
define('MEPR_BRAND_MODELS_PATH', MEPR_BRAND_PATH . '/models');
define('MEPR_CTRLS_PATH', MEPR_PATH . '/app/controllers');
define('MEPR_GATEWAYS_PATH', MEPR_PATH . '/app/gateways');
define('MEPR_EMAILS_PATH', MEPR_PATH . '/app/emails');
define('MEPR_JOBS_PATH', MEPR_PATH . '/app/jobs');
define('MEPR_VIEWS_PATH', MEPR_PATH . '/app/views');
define('MEPR_BRAND_VIEWS_PATH', MEPR_BRAND_PATH . '/views');
define('MEPR_WIDGETS_PATH', MEPR_PATH . '/app/widgets');
define('MEPR_HELPERS_PATH', MEPR_PATH . '/app/helpers');
define('MEPR_BRAND_HELPERS_PATH', MEPR_BRAND_PATH . '/helpers');
define('MEPR_EXCEPTIONS_PATH', MEPR_PATH . '/app/lib/exceptions');
define('MEPR_URL', plugins_url('/' . MEPR_PLUGIN_NAME));
define('MEPR_BRAND_URL', MEPR_URL . '/brand');
define('MEPR_VIEWS_URL', MEPR_URL . '/app/views');
define('MEPR_IMAGES_URL', MEPR_URL . '/images');
define('MEPR_BRAND_IMAGES_URL', MEPR_BRAND_URL . '/images');
define('MEPR_CSS_URL', MEPR_URL . '/css');
define('MEPR_BRAND_CSS_URL', MEPR_BRAND_URL . '/css');
define('MEPR_JS_URL', MEPR_URL . '/js');
define('MEPR_BRAND_JS_URL', MEPR_BRAND_URL . '/js');
define('MEPR_GATEWAYS_URL', MEPR_URL . '/app/gateways');
define('MEPR_FONTS_URL', MEPR_URL . '/fonts');
define('MEPR_SCRIPT_URL', site_url('/index.php?plugin=mepr'));
define('MEPR_OPTIONS_SLUG', 'mepr_options');
define('MEPR_EDITION', 'memberpress-pro');
/**
* Returns current plugin version.
*
* @param string $field The field.
* @return string Plugin version
*/
function mepr_plugin_info($field)
{
static $curr_plugins;
if (!isset($curr_plugins)) {
if (!function_exists('get_plugins')) {
require_once(ABSPATH . '/wp-admin/includes/plugin.php');
}
$curr_plugins = get_plugins();
wp_cache_delete('plugins', 'plugins');
}
if (isset($curr_plugins[MEPR_PLUGIN_SLUG][$field])) {
return $curr_plugins[MEPR_PLUGIN_SLUG][$field];
}
return '';
}
// Plugin Information from the plugin header declaration.
define('MEPR_VERSION', mepr_plugin_info('Version'));
define('MEPR_DISPLAY_NAME', mepr_plugin_info('Name'));
define('MEPR_AUTHOR', mepr_plugin_info('Author'));
define('MEPR_AUTHOR_URI', mepr_plugin_info('AuthorURI'));
define('MEPR_DESCRIPTION', mepr_plugin_info('Description'));
/**
* Autoloads MemberPress plugin classes based on naming conventions.
*
* @param string $class_name The name of the class to load.
* @return void
*/
function mepr_autoloader($class_name)
{
// Only load classes belonging to this plugin.
if (preg_match('/^Mepr.+$/', $class_name)) {
// Ensure DB tables are defined before any Mepr class runs (fixes third-party integrations in REST/early contexts).
if (!class_exists('MeprDb', false)) {
require_once MEPR_LIB_PATH . '/MeprDb.php';
}
MeprDb::define_tables();
if (preg_match('/^.+Interface$/', $class_name)) { // Load interfaces first.
$filepath = MEPR_INTERFACES_PATH . "/{$class_name}.php";
} elseif (preg_match('/^Mepr(Base|Cpt).+$/', $class_name)) { // Base classes are in lib.
$filepath = MEPR_LIB_PATH . "/{$class_name}.php";
} elseif (preg_match('/^.+BrandCtrl$/', $class_name)) {
$filepath = MEPR_BRAND_CTRLS_PATH . "/{$class_name}.php";
} elseif (preg_match('/^.+Ctrl$/', $class_name)) {
$filepath = MEPR_CTRLS_PATH . "/{$class_name}.php";
// Try the brand controllers dir if file doesn't exist.
if (!file_exists($filepath)) {
$filepath = MEPR_BRAND_CTRLS_PATH . "/{$class_name}.php";
}
} elseif (preg_match('/^.+Helper$/', $class_name)) {
$filepath = MEPR_HELPERS_PATH . "/{$class_name}.php";
// Try the brand helpers dir if file doesn't exist.
if (!file_exists($filepath)) {
$filepath = MEPR_BRAND_HELPERS_PATH . "/{$class_name}.php";
}
} elseif (preg_match('/^.+Exception$/', $class_name)) {
$filepath = MEPR_EXCEPTIONS_PATH . "/{$class_name}.php";
} elseif (preg_match('/^.+Jobs$/', $class_name)) {
$filepath = MEPR_LIB_PATH . '/MeprJobs.php';
} elseif (preg_match('/^MeprMigrator.+$/', $class_name)) {
$filepath = MEPR_LIB_PATH . "/migrators/{$class_name}.php";
} elseif (preg_match('/^.+Gateway$/', $class_name)) {
foreach (MeprGatewayFactory::paths() as $path) {
$filepath = $path . "/{$class_name}.php";
if (file_exists($filepath)) {
require_once($filepath);
return;
}
}
return;
} elseif (preg_match('/^.+Email$/', $class_name)) {
foreach (MeprEmailFactory::paths() as $path) {
$filepath = $path . "/{$class_name}.php";
if (file_exists($filepath)) {
require_once($filepath);
return;
}
}
return;
} elseif (preg_match('/^.+Job$/', $class_name)) {
foreach (MeprJobFactory::paths() as $path) {
$filepath = $path . "/{$class_name}.php";
if (file_exists($filepath)) {
require_once($filepath);
return;
}
}
return;
} else {
$filepath = MEPR_MODELS_PATH . "/{$class_name}.php";
// Try the brand models dir if file doesn't exist.
if (!file_exists($filepath)) {
$filepath = MEPR_BRAND_MODELS_PATH . "/{$class_name}.php";
}
// Now let's try the lib dir if its not a model.
if (!file_exists($filepath)) {
$filepath = MEPR_LIB_PATH . "/{$class_name}.php";
}
}
if (file_exists($filepath)) {
require_once($filepath);
}
}
}
// If __autoload is active, put it on the spl_autoload stack.
if (is_array(spl_autoload_functions()) and in_array('__autoload', spl_autoload_functions(), true)) {
spl_autoload_register('__autoload');
}
// Add the autoloader.
spl_autoload_register('mepr_autoloader');
// Load integration files.
foreach ((array) glob(MEPR_INTEGRATIONS_PATH . '/*/Integration.php') as $mepr_file) {
include_once $mepr_file;
}
// Load brand add-ons.
if (file_exists(MEPR_BRAND_PATH . '/add-ons.php')) {
require_once MEPR_BRAND_PATH . '/add-ons.php';
}
// Include other files.
require_once MEPR_LIB_PATH . '/core-functions.php';
// Define database tables immediately (before controllers load).
MeprDb::define_tables();
// Add any tables from mepr_db_tables filter once MeprHooks is available.
add_action('init', [MeprDb::class, 'define_extra_tables_from_filter'], 0);
// Re-define tables when switching blogs in multisite to ensure correct prefix.
if (is_multisite()) {
add_action('switch_blog', [MeprDb::class, 'define_tables'], 1);
add_action('switch_blog', [MeprDb::class, 'define_extra_tables_from_filter'], 1);
}
// Load our controllers.
MeprCtrlFactory::all();
// Setup screens.
MeprAppCtrl::setup_menus();
// Start Job Processor / Scheduler.
new MeprJobs();
/**
* Activation hook.
*/
function mepr_on_activate(): void
{
$mepr_options = MeprOptions::fetch();
if (!$mepr_options->setup_complete) {
if (!is_numeric($mepr_options->thankyou_page_id) || $mepr_options->thankyou_page_id === 0) {
$mepr_options->thankyou_page_id = MeprAppHelper::auto_add_page(__('Thank You', 'memberpress'), esc_html__('Your subscription has been set up successfully.', 'memberpress'));
}
if (!is_numeric($mepr_options->account_page_id) || $mepr_options->account_page_id === 0) {
$mepr_options->account_page_id = MeprAppHelper::auto_add_page(__('Account', 'memberpress'));
}
if (!is_numeric($mepr_options->login_page_id) || $mepr_options->login_page_id === 0) {
$mepr_options->login_page_id = MeprAppHelper::auto_add_page(__('Login', 'memberpress'));
}
// Enable Pro Mode Templates.
if (! filter_var($mepr_options->design_enable_checkout_template, FILTER_VALIDATE_BOOLEAN)) {
$mepr_options->design_enable_checkout_template = true;
}
if (! filter_var($mepr_options->design_enable_login_template, FILTER_VALIDATE_BOOLEAN)) {
$mepr_options->design_enable_login_template = true;
}
if (! filter_var($mepr_options->design_enable_courses_template, FILTER_VALIDATE_BOOLEAN)) {
$mepr_options->design_enable_courses_template = true;
}
if (! filter_var($mepr_options->design_enable_thankyou_template, FILTER_VALIDATE_BOOLEAN)) {
$mepr_options->design_enable_thankyou_template = true;
}
if (! filter_var($mepr_options->design_enable_pricing_template, FILTER_VALIDATE_BOOLEAN)) {
$mepr_options->design_enable_pricing_template = true;
}
if (! filter_var($mepr_options->design_enable_account_template, FILTER_VALIDATE_BOOLEAN)) {
$mepr_options->design_enable_account_template = true;
}
$mepr_options->setup_complete = 1;
$mepr_options->activated_timestamp = time();
$mepr_options->proactive_support_fresh_install = true;
$mepr_options->store(false);
} else {
// Re-activation or edition switch: restart the proactive support delay clock
// so the failed-onboarding trigger 3-day window begins from this activation.
$mepr_options->activated_timestamp = time();
$mepr_options->store(false);
}
update_option('mepr_flush_rewrite_rules', true);
}
/**
* Deactivation hook.
*/
function mepr_on_deactivate(): void
{
remove_action('mod_rewrite_rules', 'MeprRulesCtrl::mod_rewrite_rules');
MeprUtils::flush_rewrite_rules();
// Remove wp-cron general purpose jobs.
$jobs = new MeprJobs();
$jobs->unschedule_events();
// Remove wp-cron transaction jobs.
MeprTransactionsCtrl::unschedule_events();
$reminders_controller = new MeprRemindersCtrl();
$reminders_controller->unschedule_reminders();
// Remove wp-cron proactive support event.
wp_clear_scheduled_hook(MeprProactiveSupportCronCtrl::CRON_HOOK);
// Remove wp-cron DRM app fee events.
wp_clear_scheduled_hook('mepr_drm_app_fee_mapper', [false]);
wp_clear_scheduled_hook('mepr_drm_app_fee_revision', [false]);
}
register_activation_hook(MEPR_PLUGIN_SLUG, 'mepr_on_activate');
register_deactivation_hook(MEPR_PLUGIN_SLUG, 'mepr_on_deactivate');