forked from weDevsOfficial/wp-user-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwpuf.php
More file actions
480 lines (398 loc) · 15.7 KB
/
Copy pathwpuf.php
File metadata and controls
480 lines (398 loc) · 15.7 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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
<?php
/*
Plugin Name: WP User Frontend
Plugin URI: https://wordpress.org/plugins/wp-user-frontend/
Description: Create, edit, delete, manages your post, pages or custom post types from frontend. Create registration forms, frontend profile and more...
Author: Tareq Hasan
Version: 2.5.3
Author URI: https://tareq.co
License: GPL2
TextDomain: wpuf
*/
define( 'WPUF_VERSION', '2.5.3' );
define( 'WPUF_FILE', __FILE__ );
define( 'WPUF_ROOT', dirname( __FILE__ ) );
define( 'WPUF_ROOT_URI', plugins_url( '', __FILE__ ) );
define( 'WPUF_ASSET_URI', WPUF_ROOT_URI . '/assets' );
/**
* Autoload class files on demand
*
* `WPUF_Form_Posting` becomes => form-posting.php
* `WPUF_Dashboard` becomes => dashboard.php
*
* @param string $class requested class name
*/
function wpuf_autoload( $class ) {
if ( stripos( $class, 'WPUF_' ) !== false ) {
$admin = ( stripos( $class, '_Admin_' ) !== false ) ? true : false;
if ( $admin ) {
$class_name = str_replace( array('WPUF_Admin_', '_'), array('', '-'), $class );
$filename = dirname( __FILE__ ) . '/admin/' . strtolower( $class_name ) . '.php';
} else {
$class_name = str_replace( array('WPUF_', '_'), array('', '-'), $class );
$filename = dirname( __FILE__ ) . '/class/' . strtolower( $class_name ) . '.php';
}
if ( file_exists( $filename ) ) {
require_once $filename;
}
}
}
spl_autoload_register( 'wpuf_autoload' );
/**
* Main bootstrap class for WP User Frontend
*
* @package WP User Frontend
*/
class WP_User_Frontend {
private static $_instance;
private $is_pro = false;
function __construct() {
$this->includes();
$this->instantiate();
// set schedule event
add_action( 'wpuf_remove_expired_post_hook', array( $this, 'action_to_remove_exipred_post' ) );
add_action( 'admin_init', array( $this, 'block_admin_access') );
add_action( 'show_admin_bar', array( $this, 'show_admin_bar') );
add_action( 'init', array( $this, 'load_textdomain') );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts') );
// do plugin upgrades
add_action( 'plugins_loaded', array( $this, 'plugin_upgrades') );
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'plugin_action_links' ) );
//add custom css
add_action( 'wp_head', array( $this, 'add_custom_css' ) );
}
/**
* Schedules the post expiry event
*
* @since 2.2.7
*/
public static function set_schedule_events() {
wp_schedule_event( time(), 'daily', 'wpuf_remove_expired_post_hook' );
}
/**
* Action when posts expiration date is passed
*
* @since 2.2.7
*/
public function action_to_remove_exipred_post() {
$args = array(
'meta_key' => 'wpuf-post_expiration_date',
'meta_value' => date( 'Y-m-d' ),
'meta_compare' => '<',
'post_type' => get_post_types(),
'post_status' => 'publish',
'posts_per_page' => -1
);
$mail_subject = apply_filters( 'wpuf_post_expiry_mail_subject', sprintf( '[%s] %s', get_bloginfo( 'name' ), __( 'Your Post Has Been Expired', 'wpuf' ) ) );
$posts = get_posts( $args );
foreach ( $posts as $each_post ) {
$post_to_update = array(
'ID' => $each_post->ID,
'post_status' => get_post_meta( $each_post->ID, 'wpuf-expired_post_status', true ) ? get_post_meta( $each_post->ID, 'wpuf-expired_post_status', true ) : 'draft'
);
wp_update_post( $post_to_update );
$message = get_post_meta( $each_post->ID, 'wpuf-post_expiration_message', true );
if ( !empty( $message ) ) {
wp_mail( get_the_author_meta( 'user_email', $each_post->post_author ), $mail_subject, $message );
}
}
//save an option for debugging purpose
update_option( 'wpuf_expiry_posts_last_cleaned', date( 'F j, Y g:i a' ) );
}
public static function init() {
if ( !self::$_instance ) {
self::$_instance = new WP_User_Frontend();
}
return self::$_instance;
}
public function includes() {
require_once dirname( __FILE__ ) . '/wpuf-functions.php';
require_once dirname( __FILE__ ) . '/lib/gateway/paypal.php';
require_once dirname( __FILE__ ) . '/lib/gateway/bank.php';
$is_expired = wpuf_is_license_expired();
$has_pro = class_exists( 'WP_User_Frontend_Pro' );
if ( $has_pro && $is_expired ) {
add_action( 'admin_notices', array( $this, 'license_expired' ) );
}
if ( $has_pro ) {
$this->is_pro = true;
} else {
include dirname( __FILE__ ) . '/includes/free/loader.php';
}
if ( is_admin() ) {
require_once WPUF_ROOT . '/admin/settings-options.php';
require_once WPUF_ROOT . '/admin/promotion.php';
require_once WPUF_ROOT . '/includes/free/admin/shortcode-button.php';
require_once WPUF_ROOT . '/admin/form-builder/class-wpuf-admin-form-builder.php';
require_once WPUF_ROOT . '/admin/form-builder/class-wpuf-admin-form-builder-ajax.php';
}
// add reCaptcha library if not found
if ( !function_exists( 'recaptcha_get_html' ) ) {
require_once dirname( __FILE__ ) . '/lib/recaptchalib.php';
require_once dirname( __FILE__ ) . '/lib/recaptchalib_noCaptcha.php';
}
}
/**
* Instantiate the classes
*
* @return void
*/
function instantiate() {
new WPUF_Upload();
new WPUF_Payment();
new WPUF_Paypal();
new WPUF_Admin_Form_Template();
WPUF_Frontend_Form_Post::init(); // requires for form preview
WPUF_Subscription::init();
new WPUF_Frontend_Account();
if ( is_admin() ) {
WPUF_Admin_Settings::init();
new WPUF_Admin_Form_Handler();
new WPUF_Admin_Form();
new WPUF_Admin_Posting();
new WPUF_Admin_Subscription();
new WPUF_Admin_Installer();
new WPUF_Admin_Promotion();
} else {
new WPUF_Frontend_Dashboard();
}
}
/**
* Create tables on plugin activation
*
* @global object $wpdb
*/
public static function install() {
global $wpdb;
self::set_schedule_events();
flush_rewrite_rules( false );
$sql_transaction = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpuf_transaction (
`id` mediumint(9) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) DEFAULT NULL,
`status` varchar(255) NOT NULL DEFAULT 'pending_payment',
`cost` varchar(255) DEFAULT '',
`post_id` varchar(20) DEFAULT NULL,
`pack_id` bigint(20) DEFAULT NULL,
`payer_first_name` longtext,
`payer_last_name` longtext,
`payer_email` longtext,
`payment_type` longtext,
`payer_address` longtext,
`transaction_id` longtext,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( $sql_transaction );
update_option( 'wpuf_version', WPUF_VERSION );
}
/**
* Do plugin upgrades
*
* @since 2.2
* @return void
*/
function plugin_upgrades() {
if ( ! is_admin() && ! current_user_can( 'manage_options' ) ) {
return;
}
new WPUF_Upgrades( WPUF_VERSION );
}
/**
* Manage task on plugin deactivation
*
* @return void
*/
public static function uninstall() {
wp_clear_scheduled_hook( 'wpuf_remove_expired_post_hook' );
}
/**
* Enqueues Styles and Scripts when the shortcodes are used only
*
* @uses has_shortcode()
* @since 0.2
*/
function enqueue_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
global $post;
$scheme = is_ssl() ? 'https' : 'http';
$api_key = wpuf_get_option( 'gmap_api_key', 'wpuf_general' );
if ( !empty( $api_key ) ) {
wp_enqueue_script( 'google-maps', $scheme . '://maps.google.com/maps/api/js?libraries=places&key='.$api_key, array(), null );
}
if ( isset ( $post->ID ) ) {
?>
<script type="text/javascript" id="wpuf-language-script">
var error_str_obj = {
'required' : '<?php esc_attr_e( 'is required', 'wpuf' ); ?>',
'mismatch' : '<?php esc_attr_e( 'does not match', 'wpuf' ); ?>',
'validation' : '<?php esc_attr_e( 'is not valid', 'wpuf' ); ?>'
}
</script>
<?php
wp_enqueue_script( 'wpuf-form', WPUF_ASSET_URI . '/js/frontend-form' . $suffix . '.js', array('jquery') );
}
wp_enqueue_style( 'wpuf-css', WPUF_ASSET_URI . '/css/frontend-forms.css' );
wp_enqueue_script( 'wpuf-subscriptions', WPUF_ASSET_URI . '/js/subscriptions.js', array('jquery'), false, true );
if ( wpuf_get_option( 'load_script', 'wpuf_general', 'on') == 'on') {
$this->plugin_scripts();
} else if ( wpuf_has_shortcode( 'wpuf_form' ) || wpuf_has_shortcode( 'wpuf_edit' ) || wpuf_has_shortcode( 'wpuf_profile' ) || wpuf_has_shortcode( 'wpuf_dashboard' ) ) {
$this->plugin_scripts();
}
}
/**
* add custom css to head
*/
function add_custom_css() {
global $post;
if ( ! is_a( $post, 'WP_Post' ) ) {
return;
}
if ( wpuf_has_shortcode( 'wpuf_form', $post->ID )
|| wpuf_has_shortcode( 'wpuf_edit', $post->ID )
|| wpuf_has_shortcode( 'wpuf_profile', $post->ID )
|| wpuf_has_shortcode( 'wpuf_dashboard', $post->ID )
|| wpuf_has_shortcode( 'wpuf_sub_pack', $post->ID )
|| wpuf_has_shortcode( 'wpuf-login', $post->ID )
|| wpuf_has_shortcode( 'wpuf_form', $post->ID )
|| wpuf_has_shortcode( 'wpuf_profile', $post->ID )
) {
?>
<style>
<?php echo $custom_css = wpuf_get_option( 'custom_css', 'wpuf_general' ); ?>
</style>
<?php
}
}
function plugin_scripts() {
wp_enqueue_style( 'jquery-ui', WPUF_ASSET_URI . '/css/jquery-ui-1.9.1.custom.css' );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
wp_enqueue_script( 'suggest' );
wp_enqueue_script( 'jquery-ui-slider' );
wp_enqueue_script( 'plupload-handlers' );
wp_enqueue_script( 'jquery-ui-timepicker', WPUF_ASSET_URI . '/js/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker') );
wp_enqueue_script( 'wpuf-upload', WPUF_ASSET_URI . '/js/upload.js', array('jquery', 'plupload-handlers') );
wp_localize_script( 'wpuf-form', 'wpuf_frontend', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'error_message' => __( 'Please fix the errors to proceed', 'wpuf' ),
'nonce' => wp_create_nonce( 'wpuf_nonce' ),
'word_limit' => __( 'Word limit reached', 'wpuf' )
) );
wp_localize_script( 'wpuf-upload', 'wpuf_frontend_upload', array(
'confirmMsg' => __( 'Are you sure?', 'wpuf' ),
'nonce' => wp_create_nonce( 'wpuf_nonce' ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'plupload' => array(
'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'wpuf-upload-nonce' ),
'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
'filters' => array(array('title' => __( 'Allowed Files', 'wpuf' ), 'extensions' => '*')),
'multipart' => true,
'urlstream_upload' => true,
'warning' => __( 'Maximum number of files reached!', 'wpuf' ),
'size_error' => __( 'The file you have uploaded exceeds the file size limit. Please try again.', 'wpuf' ),
'type_error' => __( 'You have uploaded an incorrect file type. Please try again.', 'wpuf' )
)
));
}
/**
* Block user access to admin panel for specific roles
*
* @global string $pagenow
*/
function block_admin_access() {
global $pagenow;
// bail out if we are from WP Cli
if ( defined( 'WP_CLI' ) ) {
return;
}
$access_level = wpuf_get_option( 'admin_access', 'wpuf_general', 'read' );
$valid_pages = array('admin-ajax.php', 'admin-post.php', 'async-upload.php', 'media-upload.php');
if ( ! current_user_can( $access_level ) && !in_array( $pagenow, $valid_pages ) ) {
// wp_die( __( 'Access Denied. Your site administrator has blocked your access to the WordPress back-office.', 'wpuf' ) );
wp_redirect( home_url() );
exit;
}
}
/**
* Show/hide admin bar to the permitted user level
*
* @since 2.2.3
* @return void
*/
function show_admin_bar() {
$access_level = wpuf_get_option( 'admin_access', 'wpuf_general', 'read' );
return current_user_can( $access_level );
}
/**
* Load the translation file for current language.
*
* @since version 0.7
* @author Tareq Hasan
*/
function load_textdomain() {
load_plugin_textdomain( 'wpuf', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* The main logging function
*
* @uses error_log
* @param string $type type of the error. e.g: debug, error, info
* @param string $msg
*/
public static function log( $type = '', $msg = '' ) {
$msg = sprintf( "[%s][%s] %s\n", date( 'd.m.Y h:i:s' ), $type, $msg );
error_log( $msg, 3, dirname( __FILE__ ) . '/log.txt' );
}
/**
* Returns if the plugin is in PRO version
*
* @since 2.3.2
*
* @return boolean
*/
public function is_pro() {
return $this->is_pro;
}
/**
* Plugin action links
*
* @param array $links
*
* @since 2.3.3
*
* @return array
*/
function plugin_action_links( $links ) {
if ( ! $this->is_pro() ) {
$links[] = '<a href="' . WPUF_Pro_Prompt::get_pro_url() . '" target="_blank" style="color: red;">Get PRO</a>';
}
$links[] = '<a href="' . admin_url( 'admin.php?page=wpuf-settings' ) . '">Settings</a>';
$links[] = '<a href="https://docs.wedevs.com/docs/wp-user-frontend-pro/getting-started/how-to-install/" target="_blank">Documentation</a>';
return $links;
}
/**
* Show renew prompt once the license key is expired
*
* @since 2.3.13
*
* @return void
*/
function license_expired() {
echo '<div class="error">';
echo '<p>Your <strong>WP User Frontend Pro</strong> License has been expired. Please <a href="https://wedevs.com/account/" target="_blank">renew your license</a>.</p>';
echo '</div>';
}
}
/**
* Returns the singleton instance
*
* @return \WP_User_Frontend
*/
function wpuf() {
return WP_User_Frontend::init();
}
add_action( 'plugins_loaded', 'wpuf' );
register_activation_hook( __FILE__, array( 'WP_User_Frontend', 'install' ) );
register_deactivation_hook( __FILE__, array( 'WP_User_Frontend', 'uninstall' ) );