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 WeDevs\Wpuf\Lib\WeDevs_Insights( __FILE__ );
}
/**
* Include the required files
*
* @return void
*/
public function includes() {
require_once __DIR__ . '/wpuf-functions.php';
require_once __DIR__ . '/includes/class-frontend-render-form.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';
}
// AI Form Builder includes
require_once __DIR__ . '/includes/AI_Manager.php';
// Gateway helper functions
require_once __DIR__ . '/Lib/Gateway/gateway-functions.php';
}
/**
* Instantiate the classes
*
* @return void
*/
public function instantiate() {
$this->container['assets'] = new WeDevs\Wpuf\Assets();
$this->container['subscription'] = new WeDevs\Wpuf\Admin\Subscription();
$this->container['fields'] = new WeDevs\Wpuf\Admin\Forms\Field_Manager();
$this->container['customize'] = new WeDevs\Wpuf\Admin\Customizer_Options();
// Initialize legacy gateway classes for backward compatibility
$this->container['bank'] = new WeDevs\Wpuf\Lib\Gateway\Bank();
$this->container['paypal'] = new WeDevs\Wpuf\Lib\Gateway\Paypal();
// Initialize new gateway manager inside init hook for translation issue
add_action( 'init', [ $this, 'init_gateway_manager' ] );
$this->container['api'] = new WeDevs\Wpuf\API();
$this->container['integrations'] = new WeDevs\Wpuf\Integrations();
$this->container['ai_manager'] = new WeDevs\Wpuf\AI_Manager();
if ( is_admin() ) {
$this->container['admin'] = new WeDevs\Wpuf\Admin();
$this->container['setup_wizard'] = new WeDevs\Wpuf\Setup_Wizard();
$this->container['pro_upgrades'] = new WeDevs\Wpuf\Pro_Upgrades();
$this->container['privacy'] = new WeDevs\Wpuf\WPUF_Privacy();
// Load Frontend when in Elementor editor or Elementor AJAX so shortcodes
// like wpuf_form and wpuf_account are registered and do_shortcode() works.
// Without this, is_admin() is true and Frontend is skipped, so do_shortcode()
// returns the raw shortcode. Covers: (1) editor page ?action=elementor,
// (2) render_widget AJAX when changing "Select Form" (action=elementor_ajax).
$get_action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
$request_act = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : '';
$is_elementor = ( $get_action === 'elementor' )
|| ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) && $request_act === 'elementor_ajax' );
if ( $is_elementor ) {
$this->container['frontend'] = new WeDevs\Wpuf\Frontend();
}
} else {
$this->container['frontend'] = new WeDevs\Wpuf\Frontend();
}
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
// Initialize the ajax class inside init hook for translation issue
add_action( 'init', [ $this, 'init_ajax' ] );
}
}
/**
* Initialize the ajax class
*
* @since 4.1.4
*
* @return void
*/
public function init_ajax() {
$this->container['ajax'] = new WeDevs\Wpuf\Ajax();
}
/**
* Initialize the gateway manager
*
* @since WPUF_PRO_SINCE
*
* @return void
*/
public function init_gateway_manager() {
$this->container['gateway_manager'] = new WeDevs\Wpuf\Lib\Gateway\Gateway_Manager();
}
/**
* Create tables on plugin activation
*
* @global object $wpdb
*/
public function install() {
$installer = new WeDevs\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;
}
$this->container['upgrades'] = new WeDevs\Wpuf\Admin\Upgrades();
}
/**
* Check whether the version of wpuf pro is prior to the code restructure
*
* @since WPUF_FREE
*
* @return void
*/
public function process_wpuf_pro_version() {
// check whether the version of wpuf pro is prior to the code restructure
if ( defined( 'WPUF_PRO_VERSION' ) && version_compare( WPUF_PRO_VERSION, '4', '<' ) ) {
// deactivate_plugins( WPUF_PRO_FILE );
add_action( 'admin_notices', [ $this, 'wpuf_upgrade_notice' ] );
}
}
/**
* Show WordPress error notice if WP User Frontend not found
*
* @since 2.4.2
*/
public function wpuf_upgrade_notice() {
?>
WP User Frontend Free and %1$sWP User Frontend Pro%2$s that requires you to use latest version of both. Please update the WPUF pro to the latest version.
Please make sure to take a complete backup of your site before updating.', 'wp-user-frontend' ),
'',
''
)
);
?>
is_pro = true;
} else {
$this->container['free_loader'] = new WeDevs\Wpuf\Free\Free_Loader();
$this->container['free_loader']->includes();
$this->container['free_loader']->instantiate();
$this->container['free_loader']->run_hooks();
}
// Remove the what's new option.
delete_option( 'wpuf_whats_new' );
delete_option( 'wpufpro_whats_new' );
}
/**
* Manage task on plugin deactivation
*
* @return void
*/
public static function uninstall() {
wp_clear_scheduled_hook( 'wpuf_remove_expired_post_hook' );
}
/**
* 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 ); // phpcs:ignore
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 ) {
$links[] = '' . esc_html( 'Settings' ) . '';
$links[] = ' '. esc_html( 'Docs' ) . '';
if ( ! $this->is_pro() ) {
$links[] = ' '. esc_html( 'Upgrade to Pro' ) . '';
$links[] = ''. esc_html( 'Check Discounts' ) . '';
}
return $links;
}
/**
* Register widgets
*
* @since 4.0.0
*
* @return void
*/
public function register_widgets() {
$this->container['widgets'] = new WeDevs\Wpuf\Widgets\Manager();
}
public function license_expired() {
echo '';
echo '
Your WP User Frontend Pro License has been expired. Please renew your license.
';
echo '
';
}
/**
* Get the global field seperator for WPUF
*
* @since 4.0.0
*
* @return string
*/
public function get_field_seperator() {
return self::$field_separator;
}
/**
* Magic getter to bypass referencing objects
*
* @since 4.0.9
*
* @param string $prop
*
* @return object Class Instance
*/
public function __get( $prop ) {
if ( array_key_exists( $prop, $this->container ) ) {
return $this->container[ $prop ];
}
}
/**
* Get the DB version key
*
* @since 4.0.11
*
* @return string
*/
public function get_db_version_key() {
return 'wpuf_version';
}
}
/**
* Returns the singleton instance
*
* @return WP_User_Frontend
*/
function wpuf() {
return WP_User_Frontend::instance();
}
// kickoff
wpuf();