forked from cliffordp/Restrict-Content-Pro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestrict-content-pro.php
executable file
·368 lines (302 loc) · 12.6 KB
/
restrict-content-pro.php
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<?php
/**
* Plugin Name: Restrict Content Pro
* Plugin URL: https://restrictcontentpro.com
* Description: Set up a complete subscription system for your WordPress site and deliver premium content to your subscribers. Unlimited subscription packages, membership management, discount codes, registration / login forms, and more.
* Version: 2.8.6
* Author: Restrict Content Pro Team
* Author URI: https://restrictcontentpro.com
* Contributors: mordauk
* Text Domain: rcp
* Domain Path: languages
*/
if ( !defined( 'RCP_PLUGIN_DIR' ) ) {
define( 'RCP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
if ( !defined( 'RCP_PLUGIN_URL' ) ) {
define( 'RCP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
if ( !defined( 'RCP_PLUGIN_FILE' ) ) {
define( 'RCP_PLUGIN_FILE', __FILE__ );
}
if ( !defined( 'RCP_PLUGIN_VERSION' ) ) {
define( 'RCP_PLUGIN_VERSION', '2.8.6' );
}
if ( ! defined( 'CAL_GREGORIAN' ) ) {
define( 'CAL_GREGORIAN', 1 );
}
/*******************************************
* setup DB names
*******************************************/
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
/**
* Get the name of the subscription levels database table.
*
* @return string
*/
function rcp_get_levels_db_name() {
global $wpdb;
$prefix = is_plugin_active_for_network( plugin_basename( RCP_PLUGIN_FILE ) ) ? '' : $wpdb->prefix;
if ( defined( 'RCP_NETWORK_SEPARATE_SITES' ) && RCP_NETWORK_SEPARATE_SITES ) {
$prefix = $wpdb->prefix;
}
return apply_filters( 'rcp_levels_db_name', $prefix . 'restrict_content_pro' );
}
/**
* Get the name of the subscription level meta database table.
*
* @return string
*/
function rcp_get_level_meta_db_name() {
global $wpdb;
$prefix = is_plugin_active_for_network( plugin_basename( RCP_PLUGIN_FILE ) ) ? '' : $wpdb->prefix;
if ( defined( 'RCP_NETWORK_SEPARATE_SITES' ) && RCP_NETWORK_SEPARATE_SITES ) {
$prefix = $wpdb->prefix;
}
return apply_filters( 'rcp_level_meta_db_name', $prefix . 'rcp_subscription_level_meta' );
}
/**
* Get the name of the discount codes database table.
*
* @return string
*/
function rcp_get_discounts_db_name() {
global $wpdb;
$prefix = is_plugin_active_for_network( plugin_basename( RCP_PLUGIN_FILE ) ) ? '' : $wpdb->prefix;
if ( defined( 'RCP_NETWORK_SEPARATE_SITES' ) && RCP_NETWORK_SEPARATE_SITES ) {
$prefix = $wpdb->prefix;
}
return apply_filters( 'rcp_discounts_db_name', $prefix . 'rcp_discounts' );
}
/**
* Get the name of the payments database table.
*
* @return string
*/
function rcp_get_payments_db_name() {
global $wpdb;
$prefix = is_plugin_active_for_network( plugin_basename( RCP_PLUGIN_FILE ) ) ? '' : $wpdb->prefix;
if ( defined( 'RCP_NETWORK_SEPARATE_SITES' ) && RCP_NETWORK_SEPARATE_SITES ) {
$prefix = $wpdb->prefix;
}
return apply_filters( 'rcp_payments_db_name', $prefix . 'rcp_payments' );
}
/**
* Get the name of the payment meta database table.
*
* @return string
*/
function rcp_get_payment_meta_db_name() {
global $wpdb;
$prefix = is_plugin_active_for_network( plugin_basename( RCP_PLUGIN_FILE ) ) ? '' : $wpdb->prefix;
if ( defined( 'RCP_NETWORK_SEPARATE_SITES' ) && RCP_NETWORK_SEPARATE_SITES ) {
$prefix = $wpdb->prefix;
}
return apply_filters( 'rcp_payment_meta_db_name', $prefix . 'rcp_payment_meta' );
}
/*******************************************
* global variables
*******************************************/
global $wpdb, $rcp_payments_db, $rcp_levels_db, $rcp_discounts_db;
// the plugin base directory
global $rcp_base_dir; // not used any more, but just in case someone else is
$rcp_base_dir = dirname( __FILE__ );
// load the plugin options
$rcp_options = get_option( 'rcp_settings' );
global $rcp_db_name;
$rcp_db_name = rcp_get_levels_db_name();
global $rcp_db_version;
$rcp_db_version = '1.6';
global $rcp_discounts_db_name;
$rcp_discounts_db_name = rcp_get_discounts_db_name();
global $rcp_discounts_db_version;
$rcp_discounts_db_version = '1.2';
global $rcp_payments_db_name;
$rcp_payments_db_name = rcp_get_payments_db_name();
global $rcp_payments_db_version;
$rcp_payments_db_version = '1.5';
/* settings page globals */
global $rcp_members_page;
global $rcp_subscriptions_page;
global $rcp_discounts_page;
global $rcp_payments_page;
global $rcp_settings_page;
global $rcp_reports_page;
global $rcp_export_page;
global $rcp_help_page;
/**
* Check WordPress version is at least $version.
*
* @param string $version WP version string to compare.
*
* @return bool Result of comparison check.
*/
function rcp_compare_wp_version( $version ) {
return version_compare( get_bloginfo( 'version' ), $version, '>=' );
}
/**
* Load plugin text domain for translations.
*
* @return void
*/
function rcp_load_textdomain() {
// Set filter for plugin's languages directory
$rcp_lang_dir = dirname( plugin_basename( RCP_PLUGIN_FILE ) ) . '/languages/';
$rcp_lang_dir = apply_filters( 'rcp_languages_directory', $rcp_lang_dir );
// Traditional WordPress plugin locale filter
$get_locale = get_locale();
if ( rcp_compare_wp_version( 4.7 ) ) {
$get_locale = get_user_locale();
}
/**
* Defines the plugin language locale used in RCP.
*
* @var string $get_locale The locale to use. Uses get_user_locale()` in WordPress 4.7 or greater,
* otherwise uses `get_locale()`.
*/
$locale = apply_filters( 'plugin_locale', $get_locale, 'rcp' );
$mofile = sprintf( '%1$s-%2$s.mo', 'rcp', $locale );
// Setup paths to current locale file
$mofile_local = $rcp_lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/rcp/' . $mofile;
if ( file_exists( $mofile_global ) ) {
// Look in global /wp-content/languages/rcp folder
load_textdomain( 'rcp', $mofile_global );
} elseif ( file_exists( $mofile_local ) ) {
// Look in local /wp-content/plugins/easy-digital-downloads/languages/ folder
load_textdomain( 'rcp', $mofile_local );
} else {
// Load the default language files
load_plugin_textdomain( 'rcp', false, $rcp_lang_dir );
}
}
add_action( 'init', 'rcp_load_textdomain' );
/*******************************************
* requirement checks
*******************************************/
if( version_compare( PHP_VERSION, '5.3', '<' ) ) {
/**
* Display an error notice if the PHP version is lower than 5.3.
*
* @return void
*/
function rcp_below_php_version_notice() {
if ( current_user_can( 'rcp_manage_settings' ) ) {
echo '<div class="error"><p>' . __( 'Your version of PHP is below the minimum version of PHP required by Restrict Content Pro. Please contact your host and request that your version be upgraded to 5.3 or later.', 'rcp' ) . '</p></div>';
}
}
add_action( 'admin_notices', 'rcp_below_php_version_notice' );
} else {
/*******************************************
* file includes
*******************************************/
// global includes
require( RCP_PLUGIN_DIR . 'includes/install.php' );
include( RCP_PLUGIN_DIR . 'includes/class-rcp-capabilities.php' );
include( RCP_PLUGIN_DIR . 'includes/class-rcp-emails.php' );
include( RCP_PLUGIN_DIR . 'includes/class-rcp-integrations.php' );
include( RCP_PLUGIN_DIR . 'includes/class-rcp-levels.php' );
include( RCP_PLUGIN_DIR . 'includes/class-rcp-member.php' );
include( RCP_PLUGIN_DIR . 'includes/class-rcp-payments.php' );
include( RCP_PLUGIN_DIR . 'includes/class-rcp-discounts.php' );
include( RCP_PLUGIN_DIR . 'includes/class-rcp-registration.php' );
include( RCP_PLUGIN_DIR . 'includes/scripts.php' );
include( RCP_PLUGIN_DIR . 'includes/ajax-actions.php' );
include( RCP_PLUGIN_DIR . 'includes/cron-functions.php' );
include( RCP_PLUGIN_DIR . 'includes/deprecated/functions.php' );
include( RCP_PLUGIN_DIR . 'includes/discount-functions.php' );
include( RCP_PLUGIN_DIR . 'includes/email-functions.php' );
include( RCP_PLUGIN_DIR . 'includes/gateways/class-rcp-payment-gateway.php' );
include( RCP_PLUGIN_DIR . 'includes/gateways/class-rcp-payment-gateway-authorizenet.php' );
include( RCP_PLUGIN_DIR . 'includes/gateways/class-rcp-payment-gateway-braintree.php' );
include( RCP_PLUGIN_DIR . 'includes/gateways/class-rcp-payment-gateway-manual.php' );
include( RCP_PLUGIN_DIR . 'includes/gateways/class-rcp-payment-gateway-paypal.php' );
include( RCP_PLUGIN_DIR . 'includes/gateways/class-rcp-payment-gateway-paypal-pro.php' );
include( RCP_PLUGIN_DIR . 'includes/gateways/class-rcp-payment-gateway-paypal-express.php' );
include( RCP_PLUGIN_DIR . 'includes/gateways/class-rcp-payment-gateway-stripe.php' );
include( RCP_PLUGIN_DIR . 'includes/gateways/class-rcp-payment-gateway-stripe-checkout.php' );
include( RCP_PLUGIN_DIR . 'includes/gateways/class-rcp-payment-gateway-2checkout.php' );
include( RCP_PLUGIN_DIR . 'includes/gateways/class-rcp-payment-gateways.php' );
include( RCP_PLUGIN_DIR . 'includes/gateways/gateway-functions.php' );
include( RCP_PLUGIN_DIR . 'includes/invoice-functions.php' );
include( RCP_PLUGIN_DIR . 'includes/login-functions.php' );
include( RCP_PLUGIN_DIR . 'includes/member-forms.php' );
include( RCP_PLUGIN_DIR . 'includes/member-functions.php' );
include( RCP_PLUGIN_DIR . 'includes/misc-functions.php' );
include( RCP_PLUGIN_DIR . 'includes/registration-functions.php' );
include( RCP_PLUGIN_DIR . 'includes/subscription-functions.php' );
include( RCP_PLUGIN_DIR . 'includes/error-tracking.php' );
include( RCP_PLUGIN_DIR . 'includes/shortcodes.php' );
include( RCP_PLUGIN_DIR . 'includes/template-functions.php' );
if( !class_exists( 'WP_Logging' ) ) {
include( RCP_PLUGIN_DIR . 'includes/libraries/class-wp-logging.php' );
}
// admin only includes
if( is_admin() ) {
include( RCP_PLUGIN_DIR . 'includes/admin/upgrades.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/class-rcp-upgrades.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/admin-notices.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/admin-ajax-actions.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/class-rcp-add-on-updater.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/screen-options.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/members/members-page.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/settings/settings.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/subscriptions/subscription-levels.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/discounts/discount-codes.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/payments/payments-page.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/reports/reports-page.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/export.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/logs.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/tools/tools-page.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/help/help-menus.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/metabox.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/add-ons.php' );
include( RCP_PLUGIN_DIR . 'includes/admin/terms.php' );
include( RCP_PLUGIN_DIR . 'includes/user-page-columns.php' );
include( RCP_PLUGIN_DIR . 'includes/process-data.php' );
include( RCP_PLUGIN_DIR . 'includes/export-functions.php' );
include( RCP_PLUGIN_DIR . 'includes/deactivation.php' );
include( RCP_PLUGIN_DIR . 'RCP_Plugin_Updater.php' );
// retrieve our license key from the DB
$license_key = ! empty( $rcp_options['license_key'] ) ? trim( $rcp_options['license_key'] ) : false;
if( $license_key ) {
// setup the updater
$rcp_updater = new RCP_Plugin_Updater( 'https://restrictcontentpro.com', RCP_PLUGIN_FILE, array(
'version' => RCP_PLUGIN_VERSION, // current version number
'license' => $license_key, // license key (used get_option above to retrieve from DB)
'item_id' => 479, // Download ID
'author' => 'Restrict Content Pro Team', // author of this plugin
'beta' => ! empty( $rcp_options['show_beta_updates'] )
)
);
}
} else {
include( RCP_PLUGIN_DIR . 'includes/content-filters.php' );
include( RCP_PLUGIN_DIR . 'includes/feed-functions.php' );
if( isset( $rcp_options['enable_recaptcha'] ) ) {
require_once( RCP_PLUGIN_DIR . 'includes/captcha-functions.php' );
}
include( RCP_PLUGIN_DIR . 'includes/query-filters.php' );
include( RCP_PLUGIN_DIR . 'includes/redirects.php' );
}
// Set up database classes.
add_action( 'plugins_loaded', 'rcp_register_databases', 11 );
}
/**
* Register / set up our databases classes
*
* @access private
* @since 2.6
* @return void
*/
function rcp_register_databases() {
global $wpdb, $rcp_payments_db, $rcp_levels_db, $rcp_discounts_db;
$rcp_payments_db = new RCP_Payments;
$rcp_levels_db = new RCP_Levels;
$rcp_discounts_db = new RCP_Discounts;
$wpdb->levelmeta = $rcp_levels_db->meta_db_name;
$wpdb->paymentmeta = $rcp_payments_db->meta_db_name;
}