define_constants(); if ( ! $this->is_supported_php() ) { register_activation_hook( __FILE__, array( $this, 'auto_deactivate' ) ); add_action( 'admin_notices', array( $this, 'php_version_notice' ) ); return; } register_activation_hook( __FILE__, array( $this, 'activate' ) ); register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); add_action( 'admin_init', array( $this, 'plugin_upgrades' ) ); add_action( 'plugins_loaded', array( $this, 'init_plugin' ) ); } /** * Magic getter to bypass referencing plugin. * * @param string $prop The property to get. * * @return mixed */ public function __get( $prop ) { if ( array_key_exists( $prop, $this->container ) ) { return $this->container[ $prop ]; } return $this->{$prop}; } /** * Magic isset to bypass referencing plugin. * * @param string $prop The property to check. * * @return mixed */ public function __isset( $prop ) { return isset( $this->{$prop} ) || isset( $this->container[ $prop ] ); } /** * Initializes the WeForms() class * * Checks for an existing WeForms() instance * and if it doesn't find one, creates it. */ public static function init() { static $instance = false; if ( ! $instance ) { self::log(); $instance = new WeForms(); } return $instance; } /** * Define the constants * * @return void */ private function define_constants() { define( 'WEFORMS_VERSION', $this->version ); define( 'WEFORMS_FILE', __FILE__ ); define( 'WEFORMS_ROOT', __DIR__ ); define( 'WEFORMS_INCLUDES', WEFORMS_ROOT . '/includes' ); define( 'WEFORMS_ROOT_URI', plugins_url( '', __FILE__ ) ); define( 'WEFORMS_ASSET_URI', WEFORMS_ROOT_URI . '/assets' ); } /** * Load the plugin after WP User Frontend is loaded * * @return void */ public function init_plugin() { $this->includes(); $this->init_hooks(); do_action( 'weforms_loaded' ); } /** * Placeholder for activation function */ public function activate() { // Prepare the environment. require_once WEFORMS_INCLUDES . '/functions.php'; require_once WEFORMS_INCLUDES . '/class-installer.php'; require_once WEFORMS_INCLUDES . '/class-field-manager.php'; require_once WEFORMS_INCLUDES . '/class-form-manager.php'; require_once WEFORMS_INCLUDES . '/class-template-manager.php'; if ( ! array_key_exists( 'fields', $this->container ) ) { $this->container['fields'] = new WeForms_Field_Manager(); } if ( ! array_key_exists( 'form', $this->container ) ) { $this->container['form'] = new WeForms_Form_Manager(); } if ( ! array_key_exists( 'templates', $this->container ) ) { $this->container['templates'] = new WeForms_Template_Manager(); } $installer = new WeForms_Installer(); $installer->install(); } /** * Placeholder for deactivation function * * Nothing being called here yet. */ public function deactivate() { } /** * Include the required classes * * @return void */ public function includes() { require_once WEFORMS_INCLUDES . '/compat/class-abstract-wpuf-integration.php'; if ( $this->is_request( 'admin' ) ) { // Compatibility. require_once WEFORMS_INCLUDES . '/class-template-manager.php'; require_once WEFORMS_INCLUDES . '/admin/class-admin.php'; require_once WEFORMS_INCLUDES . '/admin/class-admin-welcome.php'; require_once WEFORMS_INCLUDES . '/class-importer-manager.php'; require_once WEFORMS_INCLUDES . '/admin/class-pro-upgrades.php'; require_once WEFORMS_INCLUDES . '/admin/class-promotion.php'; require_once WEFORMS_INCLUDES . '/admin/class-shortcode-button.php'; require_once WEFORMS_INCLUDES . '/admin/class-privacy.php'; } else { // Add reCaptcha library if not found. if ( ! function_exists( 'recaptcha_get_html' ) ) { require_once WEFORMS_INCLUDES . '/library/reCaptcha/recaptchalib.php'; require_once WEFORMS_INCLUDES . '/library/reCaptcha/recaptchalib_noCaptcha.php'; } } if ( $this->is_request( 'frontend' ) || $this->is_request( 'ajax' ) ) { require_once WEFORMS_INCLUDES . '/class-frontend-form.php'; } require_once WEFORMS_INCLUDES . '/api/class-weforms-api-rest-controller.php'; require_once WEFORMS_INCLUDES . '/class-weforms-api.php'; require_once WEFORMS_INCLUDES . '/class-scripts-styles.php'; require_once WEFORMS_INCLUDES . '/admin/class-gutenblock.php'; require_once WEFORMS_INCLUDES . '/class-emailer.php'; require_once WEFORMS_INCLUDES . '/class-field-manager.php'; require_once WEFORMS_INCLUDES . '/class-form-manager.php'; require_once WEFORMS_INCLUDES . '/class-form-entry-manager.php'; require_once WEFORMS_INCLUDES . '/class-form-entry.php'; require_once WEFORMS_INCLUDES . '/class-form.php'; require_once WEFORMS_INCLUDES . '/class-form-widget.php'; require_once WEFORMS_INCLUDES . '/integrations/class-abstract-integration.php'; require_once WEFORMS_INCLUDES . '/class-integration-manager.php'; require_once WEFORMS_INCLUDES . '/class-ajax.php'; require_once WEFORMS_INCLUDES . '/class-ajax-upload.php'; require_once WEFORMS_INCLUDES . '/class-notification.php'; require_once WEFORMS_INCLUDES . '/class-form-preview.php'; require_once WEFORMS_INCLUDES . '/class-dokan-integration.php'; require_once WEFORMS_INCLUDES . '/functions.php'; } /** * Do plugin upgrades * * @since 1.1.2 * * @return void */ public function plugin_upgrades() { if ( ! current_user_can( 'manage_options' ) ) { return; } require_once WEFORMS_INCLUDES . '/class-upgrades.php'; $upgrader = new WeForms_Upgrades(); if ( $upgrader->needs_update() ) { $upgrader->perform_updates(); } } /** * Initialize the hooks * * @return void */ public function init_hooks() { // Localize our plugin. add_action( 'init', array( $this, 'localization_setup' ) ); // Initialize the classes. add_action( 'init', array( $this, 'init_classes' ) ); add_action( 'init', array( $this, 'wpdb_table_shortcuts' ), 0 ); add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); } /** * Set WPDB table shortcut names * * @return void */ public function wpdb_table_shortcuts() { global $wpdb; $wpdb->weforms_entries = $wpdb->prefix . 'weforms_entries'; $wpdb->weforms_entrymeta = $wpdb->prefix . 'weforms_entrymeta'; } /** * Initialize plugin for localization * * @uses load_plugin_textdomain() */ public function localization_setup() { load_plugin_textdomain( 'weforms', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } /** * Instantiate the required classes * * @return void */ public function init_classes() { if ( $this->is_request( 'admin' ) ) { $this->container['admin'] = new WeForms_Admin(); // $this->container['welcome'] = new WeForms_Admin_Welcome(); $this->container['templates'] = new WeForms_Template_Manager(); $this->container['pro_upgrades'] = new WeForms_Pro_Upgrades(); $this->container['importer'] = new WeForms_Importer_Manager(); $this->container['promo_offer'] = new WeForms_Admin_Promotion(); $this->container['privacy'] = new WeForms_Privacy(); } if ( $this->is_request( 'frontend' ) || $this->is_request( 'ajax' ) ) { $this->container['frontend'] = new WeForms_Frontend_Form(); } $this->container['emailer'] = new WeForms_Emailer(); $this->container['form'] = new WeForms_Form_Manager(); $this->container['fields'] = new WeForms_Field_Manager(); $this->container['integrations'] = new WeForms_Integration_Manager(); $this->container['preview'] = new WeForms_Form_Preview(); $this->container['scripts'] = new WeForms_Scripts_Styles(); $this->container['block'] = new weForms_FormBlock(); $this->container['dokan_integration'] = new weForms_Dokan_Integration(); // Instantiate the integrations. $this->integrations->get_integrations(); if ( $this->is_request( 'ajax' ) ) { $this->container['ajax'] = new WeForms_Ajax(); $this->container['ajax_upload'] = new WeForms_Ajax_Upload(); } $this->container['weforms_api'] = new WeForms_Api(); } /** * The main logging function * * @uses error_log * * @param string $type Type of the error. e.g: debug, error, info. * @param string $msg Message to log. */ public static function log( $type = '', $msg = '' ) { if ( file_exists( WP_CONTENT_DIR . '/weforms.log' ) ) { unlink( WP_CONTENT_DIR . '/weforms.log' ); } return; // Default we are turning the debug mood on, but can be turned off. if ( defined( 'WEFORMS_DEBUG_LOG' ) && false === WEFORMS_DEBUG_LOG ) { return; } $msg = sprintf( "[%s][%s] %s\n", gmdate( 'd.m.Y h:i:s' ), $type, $msg ); @error_log( $msg, 3, weforms_log_file_path() ); } /** * Plugin action links * * @param array $links The action links to display. * * @return array */ public function plugin_action_links( $links ) { $links[] = '' . __( 'Docs', 'weforms' ) . ''; $links[] = '' . __( 'Settings', 'weforms' ) . ''; return $links; } /** * Check if the PHP version is supported * * @param string $min_php The minimum PHP version to check. * * @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: ', 'weforms' ) . PHP_VERSION . '. '; $error .= __( 'The weForms plugin requires PHP version ', 'weforms' ) . $this->min_php . __( ' or greater.', 'weforms' ); ?>
The weforms plugin requires PHP version ', 'weforms' ) . $this->min_php . __( ' or greater', 'weforms' ); $error .= __( '
The version of your PHP is ', 'weforms' ) . '' . __( 'unsupported and old', 'weforms' ) . '.'; $error .= __( 'You should update your PHP software or contact your host regarding this matter.
', 'weforms' ); wp_die( wp_kses_post( $error ), esc_html_e( 'Plugin Activation Error', 'weforms' ), array( 'back_link' => true ) ); } /** * What type of request is this? * * @since 1.2.3 * * @param string $type Type of request. admin, ajax, cron, api or frontend. * * @return bool */ private function is_request( $type ) { switch ( $type ) { case 'admin': return is_admin(); case 'ajax': return defined( 'DOING_AJAX' ); case 'cron': return defined( 'DOING_CRON' ); case 'api': return defined( 'REST_REQUEST' ); case 'frontend': return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ); } } /** * Init appsero tracker */ private function init_appsero() { if ( ! class_exists( 'Appsero\Client' ) ) { require_once WEFORMS_INCLUDES . '/library/appsero/Client.php'; } $client = new Appsero\Client( '213fd70e-0bf3-4710-a35e-934b5a376e13', 'weForms', __FILE__ ); // Active insights. $client->insights()->init(); } } // WeForms /** * Initialize the plugin * * @return \WeForms */ function weforms() { // phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed return WeForms::init(); } // Run. weforms();