| 1 |
<?php |
| 2 |
namespace HTWPForm\Elementor; |
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 4 |
/** |
| 5 |
* Base Class |
| 6 |
*/ |
| 7 |
class Base{ |
| 8 |
|
| 9 |
const MINIMUM_ELEMENTOR_VERSION = '2.0.0'; |
| 10 |
const MINIMUM_PHP_VERSION = '6.0'; |
| 11 |
|
| 12 |
private static $_instance = null; |
| 13 |
public static function instance() { |
| 14 |
if ( is_null( self::$_instance ) ) { |
| 15 |
self::$_instance = new self(); |
| 16 |
} |
| 17 |
return self::$_instance; |
| 18 |
} |
| 19 |
|
| 20 |
public function __construct(){ |
| 21 |
add_action( 'init', [ $this, 'i18n' ] ); |
| 22 |
add_action( 'plugins_loaded', [ $this, 'init' ] ); |
| 23 |
} |
| 24 |
|
| 25 |
// Load Textdomain |
| 26 |
public function i18n() { |
| 27 |
load_plugin_textdomain( 'ht-wpform' ); |
| 28 |
} |
| 29 |
|
| 30 |
public function init() { |
| 31 |
|
| 32 |
if ( ! function_exists('is_plugin_active')) { include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); } |
| 33 |
|
| 34 |
// Check if Elementor installed and activated |
| 35 |
if ( ! did_action( 'elementor/loaded' ) ) { |
| 36 |
add_action( 'admin_notices', [ $this, 'admin_notice_base_elementor_status' ] ); |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
// Check for required Elementor version |
| 41 |
if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) { |
| 42 |
add_action( 'admin_notices', [ $this, 'admin_notice_minimum_elementor_version' ] ); |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
// Check for required PHP version |
| 47 |
if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) { |
| 48 |
add_action( 'admin_notices', [ $this, 'admin_notice_minimum_php_version' ] ); |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
// Check for WPForms |
| 53 |
if( !is_plugin_active('wpforms-lite/wpforms.php') ){ |
| 54 |
if( !is_plugin_active('wpforms/wpforms.php') ){ |
| 55 |
add_action( 'admin_notices', [ $this, 'admin_notice_base_wpform_status' ] ); |
| 56 |
return; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
// Widgets register |
| 61 |
add_action( 'elementor/widgets/widgets_registered', [ $this, 'init_widgets' ] ); |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
// Check Plugins is Installed or not |
| 66 |
public function is_plugins_active( $pl_file_path = NULL ){ |
| 67 |
$installed_plugins_list = get_plugins(); |
| 68 |
return isset( $installed_plugins_list[$pl_file_path] ); |
| 69 |
} |
| 70 |
|
| 71 |
// Enementor Plugins status checking |
| 72 |
public function admin_notice_base_elementor_status() { |
| 73 |
|
| 74 |
if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] ); |
| 75 |
|
| 76 |
$elementor = 'elementor/elementor.php'; |
| 77 |
if( $this->is_plugins_active( $elementor ) ) { |
| 78 |
if( ! current_user_can( 'activate_plugins' ) ) { |
| 79 |
return; |
| 80 |
} |
| 81 |
$activation_url = wp_nonce_url( 'plugins.php?action=activate&plugin=' . $elementor . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $elementor ); |
| 82 |
|
| 83 |
$message = '<p>' . __( 'HT WPForms Addons not working because you need to activate the Elementor plugin.', 'ht-wpform' ) . '</p>'; |
| 84 |
$message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $activation_url, __( 'Activate Elementor Now', 'ht-wpform' ) ) . '</p>'; |
| 85 |
} else { |
| 86 |
if ( ! current_user_can( 'install_plugins' ) ) { |
| 87 |
return; |
| 88 |
} |
| 89 |
$install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=elementor' ), 'install-plugin_elementor' ); |
| 90 |
$message = '<p>' . __( 'HT WPForms Addons not working because you need to install the Elementor plugin', 'ht-wpform' ) . '</p>'; |
| 91 |
$message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $install_url, __( 'Install Elementor Now', 'ht-wpform' ) ) . '</p>'; |
| 92 |
} |
| 93 |
echo '<div class="error"><p>' . $message . '</p></div>'; |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
// Check WPForm install or not. |
| 98 |
function admin_notice_base_wpform_status(){ |
| 99 |
$wpforms = 'wpforms-lite/wpforms.php'; |
| 100 |
if( $this->is_plugins_active( $wpforms ) ) { |
| 101 |
if( ! current_user_can( 'activate_plugins' ) ) { |
| 102 |
return; |
| 103 |
} |
| 104 |
$activation_url = wp_nonce_url( 'plugins.php?action=activate&plugin=' . $wpforms . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $wpforms ); |
| 105 |
|
| 106 |
$message = '<p>' . __( 'HT WPForms Addons not working because you need to activate the WPForms plugin.', 'ht-wpform' ) . '</p>'; |
| 107 |
$message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $activation_url, __( 'Activate WPForms Now', 'ht-wpform' ) ) . '</p>'; |
| 108 |
} else { |
| 109 |
if ( ! current_user_can( 'install_plugins' ) ) { |
| 110 |
return; |
| 111 |
} |
| 112 |
$install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=wpforms-lite' ), 'install-plugin_wpforms-lite' ); |
| 113 |
$message = '<p>' . __( 'HT WPForms Addons not working because you need to install the Wpforms plugin', 'ht-wpform' ) . '</p>'; |
| 114 |
$message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $install_url, __( 'Install WPForms Now', 'ht-wpform' ) ) . '</p>'; |
| 115 |
} |
| 116 |
echo '<div class="error"><p>' . $message . '</p></div>'; |
| 117 |
} |
| 118 |
|
| 119 |
// Elementor Version compare |
| 120 |
public function admin_notice_minimum_elementor_version() { |
| 121 |
if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] ); |
| 122 |
$message = sprintf( |
| 123 |
/* translators: 1: Plugin name 2: Elementor 3: Required Elementor version */ |
| 124 |
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'ht-wpform' ), |
| 125 |
'<strong>' . esc_html__( 'HT WPForms Addons', 'ht-wpform' ) . '</strong>', |
| 126 |
'<strong>' . esc_html__( 'Elementor', 'ht-wpform' ) . '</strong>', |
| 127 |
self::MINIMUM_ELEMENTOR_VERSION |
| 128 |
); |
| 129 |
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message ); |
| 130 |
} |
| 131 |
|
| 132 |
// Php version Compare |
| 133 |
public function admin_notice_minimum_php_version() { |
| 134 |
if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] ); |
| 135 |
$message = sprintf( |
| 136 |
/* translators: 1: Plugin name 2: PHP 3: Required PHP version */ |
| 137 |
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'ht-wpform' ), |
| 138 |
'<strong>' . esc_html__( 'HT WPForms Addons', 'ht-wpform' ) . '</strong>', |
| 139 |
'<strong>' . esc_html__( 'PHP', 'ht-wpform' ) . '</strong>', |
| 140 |
self::MINIMUM_PHP_VERSION |
| 141 |
); |
| 142 |
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message ); |
| 143 |
} |
| 144 |
|
| 145 |
// Register widget |
| 146 |
public function init_widgets() { |
| 147 |
if( is_plugin_active('wpforms-lite/wpforms.php') || is_plugin_active('wpforms/wpforms.php') ){ |
| 148 |
require( HTWPFORM_PL_PATH.'include/elementor_widgets.php' ); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
} |
| 155 |
|