is_supported_php() ) {
add_action( 'admin_notices', [ $this, 'php_version_notice' ] );
return;
}
register_activation_hook( __FILE__, [ $this, 'install' ] );
register_deactivation_hook( __FILE__, [ $this, 'uninstall' ] );
$this->includes();
$this->init_hooks();
do_action( 'wpuf_loaded' );
}
/**
* Check if the PHP version is supported
*
* @return bool
*/
public function is_supported_php( $min_php = null ) {
$min_php = $min_php ? $min_php : $this->min_php;
if ( version_compare( PHP_VERSION, $min_php, '<=' ) ) {
return false;
}
return true;
}
/**
* Show notice about PHP version
*
* @return void
*/
public function php_version_notice() {
if ( $this->is_supported_php() || !current_user_can( 'manage_options' ) ) {
return;
}
$error = __( 'Your installed PHP Version is: ', 'wp-user-frontend' ) . PHP_VERSION . '. ';
$error .= __( 'The WP User Frontend plugin requires PHP version ', 'wp-user-frontend' ) . $this->min_php . __( ' or greater.', 'wp-user-frontend' ); ?>
container['tracker'] = new WPUF_WeDevs_Insights( __FILE__ );
}
/**
* Magic getter to bypass referencing plugin.
*
* @since 2.5.7
*
* @param string $prop
*
* @return mixed
*/
public function __get( $prop ) {
if ( array_key_exists( $prop, $this->container ) ) {
return $this->container[ $prop ];
}
return $this->{$prop};
}
/**
* 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 = [
'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', 'wp-user-frontend' ) ) );
$posts = get_posts( $args );
foreach ( $posts as $each_post ) {
$post_to_update = [
'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 );
$post_url = get_permalink( $each_post->ID );
$author_id = $each_post->post_author;
$post_author = get_the_author_meta( 'user_login', $author_id );
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
$search = [
'{post_author}',
'{post_url}',
'{blogname}',
'{post_title}',
'{post_status}',
];
$replace = [
$post_author,
$post_url,
$blogname,
$each_post->post_title,
$each_post->post_status,
];
$message = get_post_meta( $each_post->ID, 'wpuf-post_expiration_message', true );
$message = str_replace( $search, $replace, $message );
$message = get_formatted_mail_body( $message, $mail_subject );
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' ) );
}
/**
* Singleton Instance
*
* @return \self
*/
public static function init() {
if ( !self::$_instance ) {
self::$_instance = new WP_User_Frontend();
}
return self::$_instance;
}
/**
* Include the required files
*
* @return void
*/
public function includes() {
require_once __DIR__ . '/wpuf-functions.php';
require_once __DIR__ . '/lib/gateway/paypal.php';
require_once __DIR__ . '/lib/gateway/bank.php';
require_once __DIR__ . '/lib/class-wedevs-insights.php';
require_once WPUF_ROOT . '/includes/class-frontend-render-form.php';
require_once WPUF_ROOT . '/admin/form-builder/class-wpuf-form-builder-field-settings.php';
// global classes/functions
require_once WPUF_ROOT . '/class/upload.php';
require_once WPUF_ROOT . '/admin/form-template.php';
require_once WPUF_ROOT . '/class/post-form-template.php';
require_once WPUF_ROOT . '/class/subscription.php';
require_once WPUF_ROOT . '/class/render-form.php';
require_once WPUF_ROOT . '/class/payment.php';
require_once WPUF_ROOT . '/class/frontend-account.php';
require_once WPUF_ROOT . '/includes/class-form.php';
require_once WPUF_ROOT . '/includes/class-form-manager.php';
require_once WPUF_ROOT . '/includes/class-login-widget.php';
require_once WPUF_ROOT . '/includes/setup-wizard.php';
require_once WPUF_ROOT . '/includes/countries-state.php';
require_once WPUF_ROOT . '/includes/class-billing-address.php';
include_once WPUF_ROOT . '/includes/class-gutenblock.php';
include_once WPUF_ROOT . '/includes/class-form-preview.php';
include_once WPUF_ROOT . '/includes/class-customizer.php';
include_once WPUF_ROOT . '/includes/log/class-log.php';
include_once WPUF_ROOT . '/includes/log/class-log-wpdb-query.php';
if ( class_exists( 'WeDevs_Dokan' ) ) {
require_once WPUF_ROOT . '/includes/class-dokan-integration.php';
}
if ( class_exists( 'WCMp' ) ) {
require_once WPUF_ROOT . '/includes/class-wcmp-integration.php';
}
if ( class_exists( 'WC_Vendors' ) ) {
require_once WPUF_ROOT . '/includes/class-wc-vendors-integration.php';
}
require_once WPUF_ROOT . '/includes/class-user.php';
require_once WPUF_ROOT . '/includes/class-user-subscription.php';
if ( is_admin() ) {
require_once WPUF_ROOT . '/admin/settings-options.php';
require_once WPUF_ROOT . '/admin/class-admin-settings.php';
require_once WPUF_ROOT . '/admin/form-handler.php';
require_once WPUF_ROOT . '/admin/form.php';
require_once WPUF_ROOT . '/admin/posting.php';
require_once WPUF_ROOT . '/admin/class-admin-subscription.php';
require_once WPUF_ROOT . '/admin/installer.php';
require_once WPUF_ROOT . '/admin/class-admin-welcome.php';
require_once WPUF_ROOT . '/admin/promotion.php';
require_once WPUF_ROOT . '/admin/post-forms-list-table.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';
// include_once WPUF_ROOT . '/lib/class-weforms-upsell.php';
include_once WPUF_ROOT . '/includes/class-whats-new.php';
include_once WPUF_ROOT . '/includes/class-acf.php';
include_once WPUF_ROOT . '/includes/class-privacy.php';
} else {
require_once WPUF_ROOT . '/class/frontend-dashboard.php';
require_once WPUF_ROOT . '/includes/free/class-registration.php';
}
// add reCaptcha library if not found
if ( !function_exists( 'recaptcha_get_html' ) ) {
require_once __DIR__ . '/lib/recaptchalib.php';
require_once __DIR__ . '/lib/invisible_recaptcha.php';
}
require_once WPUF_ROOT . '/includes/free/class-login.php';
require_once WPUF_ROOT . '/includes/class-frontend-form-post.php';
require_once WPUF_ROOT . '/includes/class-field-manager.php';
require_once WPUF_ROOT . '/includes/class-pro-upgrades.php';
require_once WPUF_ROOT . '/includes/fields/field-trait.php';
}
/**
* Instantiate the classes
*
* @return void
*/
public function instantiate() {
$this->container['upload'] = new WPUF_Upload();
$this->container['paypal'] = new WPUF_Paypal();
$this->container['form_template'] = new WPUF_Admin_Form_Template();
$this->container['subscription'] = WPUF_Subscription::init();
$this->container['account'] = new WPUF_Frontend_Account();
$this->container['billing_address'] = new WPUF_Ajax_Address_Form();
$this->container['forms'] = new WPUF_Form_Manager();
$this->container['preview'] = new WPUF_Form_Preview();
$this->container['block'] = new WPUF_Form_Block();
$this->container['customize'] = new WPUF_Customizer_Options();
$this->container['log'] = new WPUF_Log();
if ( class_exists( 'WeDevs_Dokan' ) ) {
$this->container['dokan_integration'] = new WPUF_Dokan_Integration();
}
if ( class_exists( 'WCMp' ) ) {
$this->container['wcmp_integration'] = new WPUF_WCMp_Integration();
}
if ( class_exists( 'WC_Vendors' ) ) {
$this->container['WCV_Integration'] = new WPUF_WC_Vendors_Integration();
}
if ( is_admin() ) {
$this->container['settings'] = WPUF_Admin_Settings::init();
$this->container['form_handler'] = new WPUF_Admin_Form_Handler();
$this->container['admin_form'] = new WPUF_Admin_Form();
$this->container['admin_posting'] = WPUF_Admin_Posting::init();
$this->container['admin_subscription'] = new WPUF_Admin_Subscription();
$this->container['admin_installer'] = new WPUF_Admin_Installer();
$this->container['admin_promotion'] = new WPUF_Admin_Promotion();
$this->container['welcome'] = new WPUF_Admin_Welcome();
$this->container['whats_new'] = new WPUF_Whats_New();
$this->container['wpuf_acf'] = new WPUF_ACF_Compatibility();
$this->container['privacy'] = new WPUF_Privacy();
} else {
$this->container['dashboard'] = new WPUF_Frontend_Dashboard();
$this->container['payment'] = new WPUF_Payment();
$this->container['registration'] = WPUF_Registration::init();
}
$this->container['login'] = WPUF_Simple_Login::init();
$this->container['fields'] = new WPUF_Field_Manager();
$this->container['frontend_form'] = WPUF_Frontend_Form::init();
$this->container['pro_upgrades'] = new WPUF_Pro_Upgrades();
}
/**
* Create tables on plugin activation
*
* @global object $wpdb
*/
public static function install() {
require_once WPUF_ROOT . '/includes/class-installer.php';
$installer = new WPUF_Installer();
$installer->install();
}
/**
* Do plugin upgrades
*
* @since 2.2
*
* @return void
*/
public function plugin_upgrades() {
if ( !is_admin() && !current_user_can( 'manage_options' ) ) {
return;
}
require_once WPUF_ROOT . '/includes/class-upgrades.php';
$upgrader = new WPUF_Upgrades();
if ( $upgrader->needs_update() ) {
$upgrader->perform_updates();
}
}
/**
* Load wpuf free class if not pro
*
* @since 2.5.4
*/
public function wpuf_loader() {
$is_expired = wpuf_is_license_expired();
$has_pro = class_exists( 'WP_User_Frontend_Pro' );
if ( $has_pro && $is_expired ) {
add_action( 'admin_notices', [ $this, 'license_expired' ] );
}
if ( $has_pro ) {
$this->is_pro = true;
add_action( 'admin_notices', [ $this, 'wpuf_latest_pro_activation_notice'] );
} else {
include __DIR__ . '/includes/free/loader.php';
$this->container['free_loader'] = new WPUF_Free_Loader();
}
}
/**
* Latest Pro Activation Message
*
* @return void
*/
public function wpuf_latest_pro_activation_notice() {
if ( !version_compare( WPUF_PRO_VERSION, '3.1.0', '<' ) ) {
return;
}
$offer_msg = __( '
UPDATE REQUIRED
WP User Frontend Pro is not working because you are using an old version of WP User Frontend Pro. Please update WPUF Pro to >= v3.1.0 to work with the latest version of WP User Frontend
', 'wp-user-frontend' ); ?>
ID ) ) {
?>
plugin_scripts();
} elseif ( wpuf_has_shortcode( 'wpuf-login' ) || wpuf_has_shortcode( 'wpuf-registration' ) || wpuf_has_shortcode( 'wpuf-meta' ) || wpuf_has_shortcode( 'wpuf_form' ) || wpuf_has_shortcode( 'wpuf_edit' ) || wpuf_has_shortcode( 'wpuf_profile' ) || wpuf_has_shortcode( 'wpuf_dashboard' ) || wpuf_has_shortcode( 'weforms' ) || wpuf_has_shortcode( 'wpuf_account' ) || wpuf_has_shortcode( 'wpuf_sub_pack' ) || ( isset( $post->ID ) && ( $pay_page == $post->ID ) ) || isset( $_GET['wpuf_preview'] ) || class_exists('\Elementor\Plugin')) {
$this->plugin_scripts();
}
}
/**
* add custom css to head
*/
public function add_custom_css() {
global $post;
if ( !is_a( $post, 'WP_Post' ) ) {
return;
}
if ( wpuf_has_shortcode( 'wpuf-login', $post->ID )
|| wpuf_has_shortcode( 'wpuf-registration', $post->ID )
|| wpuf_has_shortcode( 'wpuf-meta', $post->ID )
|| 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_account', $post->ID )
) {
?>
admin_url( 'admin-ajax.php' ),
'error_message' => __( 'Please fix the errors to proceed', 'wp-user-frontend' ),
'nonce' => wp_create_nonce( 'wpuf_nonce' ),
'word_limit' => __( 'Word limit reached', 'wp-user-frontend' ),
'cancelSubMsg' => __( 'Are you sure you want to cancel your current subscription ?', 'wp-user-frontend' ),
'delete_it' => __( 'Yes', 'wp-user-frontend' ),
'cancel_it' => __( 'No', 'wp-user-frontend' ),
] ) );
wp_localize_script( 'wpuf-subscriptions', 'wpuf_subscription', apply_filters( 'wpuf_subscription_js_data', [
'pack_notice' => __( 'Please Cancel Your Currently Active Pack first!', 'wp-user-frontend' ),
] ) );
wp_localize_script( 'wpuf-upload', 'wpuf_frontend_upload', [
'confirmMsg' => __( 'Are you sure?', 'wp-user-frontend' ),
'delete_it' => __( 'Yes, delete it', 'wp-user-frontend' ),
'cancel_it' => __( 'No, cancel it', 'wp-user-frontend' ),
'nonce' => wp_create_nonce( 'wpuf_nonce' ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'max_filesize' => wpuf_max_upload_size(),
'plupload' => [
'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'wpuf-upload-nonce' ),
'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
'filters' => [
[
'title' => __( 'Allowed Files', 'wp-user-frontend' ),
'extensions' => '*',
],
],
'multipart' => true,
'urlstream_upload' => true,
'warning' => __( 'Maximum number of files reached!', 'wp-user-frontend' ),
'size_error' => __( 'The file you have uploaded exceeds the file size limit. Please try again.', 'wp-user-frontend' ),
'type_error' => __( 'You have uploaded an incorrect file type. Please try again.', 'wp-user-frontend' ),
],
] );
}
/**
* Block user access to admin panel for specific roles
*
* @global string $pagenow
*/
public 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 = [ '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
*/
public function show_admin_bar( $val ) {
if ( !is_user_logged_in() ) {
return false;
}
$roles = wpuf_get_option( 'show_admin_bar', 'wpuf_general', [ 'administrator', 'editor', 'author', 'contributor', 'subscriber' ] );
$roles = $roles && is_string($roles) ? [strtolower($roles)] : $roles;
$current_user = wp_get_current_user();
if ( ! empty( $current_user->roles ) && ! empty( $current_user->roles[0] ) ) {
if ( !in_array( $current_user->roles[0], $roles ) ) {
return false;
}
}
return $val;
}
/**
* Load the translation file for current language.
*
* @since version 0.7
*
* @author Tareq Hasan
*/
public function load_textdomain() {
load_plugin_textdomain( 'wp-user-frontend', 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, __DIR__ . '/log.txt' );
}
/**
* Returns if the plugin is in PRO version
*
* @since 2.3.2
*
* @return bool
*/
public function is_pro() {
return $this->is_pro;
}
/**
* Plugin action links
*
* @param array $links
*
* @since 2.3.3
*
* @return array
*/
public function plugin_action_links( $links ) {
if ( !$this->is_pro() ) {
$links[] = 'Get PRO';
}
$links[] = 'Settings';
$links[] = 'Documentation';
return $links;
}
/**
* Show renew prompt once the license key is expired
*
* @since 2.3.13
*
* @return void
*/
public function license_expired() {
echo '';
echo '
Your WP User Frontend Pro License has been expired. Please renew your license.
';
echo '
';
}
/**
* If the core isn't installed
*
* @return void
*/
public function maybe_weforms_install() {
if ( class_exists( 'WeForms' ) ) {
return;
}
// install the core
add_action( 'wp_ajax_wpuf_weforms_install', [ $this, 'install_weforms' ] );
}
/**
* Install weforms plugin via ajax
*
* @return void
*/
public function install_weforms() {
$nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'wpuf-weforms-installer-nonce' ) ) {
wp_send_json_error( __( 'Error: Nonce verification failed', 'wp-user-frontend' ) );
}
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
if ( file_exists( WP_PLUGIN_DIR . '/weforms/weforms.php' ) ) {
activate_plugin( 'weforms/weforms.php' );
wp_send_json_success();
}
$plugin = 'weforms';
$api = plugins_api( 'plugin_information', [
'slug' => $plugin,
'fields' => [
'sections' => false,
],
] );
$upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() );
$result = $upgrader->install( $api->download_link );
if ( is_wp_error( $result ) ) {
wp_send_json_error( $result );
}
$result = activate_plugin( 'weforms/weforms.php' );
if ( is_wp_error( $result ) ) {
wp_send_json_error( $result );
}
wp_send_json_success();
}
}
/**
* Returns the singleton instance
*
* @return \WP_User_Frontend
*/
function wpuf() {
return WP_User_Frontend::init();
}
// kickoff
wpuf();