| 1 |
<?php |
| 2 |
|
| 3 |
namespace HT_Builder\Elementor; |
| 4 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 5 |
|
| 6 |
class Base { |
| 7 |
|
| 8 |
const MINIMUM_ELEMENTOR_VERSION = '2.5.0'; |
| 9 |
const MINIMUM_PHP_VERSION = '5.4'; |
| 10 |
|
| 11 |
private static $_instance = null; |
| 12 |
public static function instance() { |
| 13 |
if ( is_null( self::$_instance ) ) { |
| 14 |
self::$_instance = new self(); |
| 15 |
} |
| 16 |
return self::$_instance; |
| 17 |
} |
| 18 |
|
| 19 |
public function __construct() { |
| 20 |
add_action( 'init', [ $this, 'i18n' ] ); |
| 21 |
add_action( 'plugins_loaded', [ $this, 'init' ] ); |
| 22 |
|
| 23 |
if ( did_action( 'elementor/loaded' ) ) { |
| 24 |
// After Active Plugin then redirect setting page |
| 25 |
register_activation_hook( HTBUILDER_PL_ROOT, [ $this, 'plugin_activate_hook'] ); |
| 26 |
add_action('admin_init', [ $this, 'plugin_redirect_option_page' ] ); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
/* |
| 31 |
* Load Text Domain |
| 32 |
*/ |
| 33 |
public function i18n() { |
| 34 |
load_plugin_textdomain( 'ht-builder' ); |
| 35 |
} |
| 36 |
|
| 37 |
/* |
| 38 |
* Init Hook in Init |
| 39 |
*/ |
| 40 |
public function init() { |
| 41 |
|
| 42 |
// Check if Elementor installed and activated |
| 43 |
if ( ! did_action( 'elementor/loaded' ) ) { |
| 44 |
add_action( 'admin_notices', [ $this, 'admin_notice_missing_main_plugin' ] ); |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
// Check for required Elementor version |
| 49 |
if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) { |
| 50 |
add_action( 'admin_notices', [ $this, 'admin_notice_minimum_elementor_version' ] ); |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
// Check for required PHP version |
| 55 |
if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) { |
| 56 |
add_action( 'admin_notices', [ $this, 'admin_notice_minimum_php_version' ] ); |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
// Include File |
| 61 |
$this->require_include_files(); |
| 62 |
|
| 63 |
// Plugins Setting Page |
| 64 |
add_filter('plugin_action_links_'.HTBUILDER_PLUGIN_BASE, [ $this, 'plugins_setting_links' ] ); |
| 65 |
|
| 66 |
// Register custom category |
| 67 |
add_action( 'elementor/elements/categories_registered', [ $this, 'add_category' ] ); |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
/* |
| 72 |
* Include File |
| 73 |
*/ |
| 74 |
public function require_include_files(){ |
| 75 |
if ( ! function_exists('is_plugin_active') ){ include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); } |
| 76 |
if ( is_admin() ) { |
| 77 |
require( __DIR__ . '/admin/class-api.php'); |
| 78 |
require( __DIR__ . '/admin/class-dashboard-widget.php'); |
| 79 |
} |
| 80 |
if( is_plugin_active('htbuilder-pro/ht-builder.php') ){ |
| 81 |
require ( HTBUILDER_PL_PATH_PRO.'includes/admin/admin-setting.php' ); |
| 82 |
}else{ |
| 83 |
require( __DIR__ . '/admin/admin-setting.php'); |
| 84 |
} |
| 85 |
require( __DIR__ . '/helper-function.php'); |
| 86 |
require( __DIR__ . '/../classes/class.enqueue_scripts.php'); |
| 87 |
require( __DIR__ . '/admin/template-library.php'); |
| 88 |
if( htbuilder_get_option( 'enablecustomtemplate', 'htbuilder_templatebuilder_tabs', 'on' ) == 'on' ){ |
| 89 |
require( __DIR__ .'/../classes/class.template_builder.php' ); |
| 90 |
require( __DIR__ .'/../classes/class.widgets_control.php' ); |
| 91 |
require( __DIR__ .'/../classes/class.header_footer.php' ); |
| 92 |
} |
| 93 |
|
| 94 |
add_action('init', function() { |
| 95 |
require( __DIR__ .'/admin/recommended-plugins/recommendations.php' ); |
| 96 |
}); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Add custom category. |
| 101 |
* |
| 102 |
* @param $elements_manager |
| 103 |
*/ |
| 104 |
public function add_category( $elements_manager ) { |
| 105 |
$elements_manager->add_category( |
| 106 |
'ht_builder', |
| 107 |
[ |
| 108 |
'title' => __( 'HT Builder', 'ht-builder' ), |
| 109 |
'icon' => 'fa fa-snowflake-o', |
| 110 |
] |
| 111 |
); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Admin notice. |
| 116 |
* Doesn't have Elementor installed or activated. |
| 117 |
*/ |
| 118 |
public function admin_notice_missing_main_plugin() { |
| 119 |
|
| 120 |
if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] ); |
| 121 |
|
| 122 |
$elementor = 'elementor/elementor.php'; |
| 123 |
if( $this->is_plugins_active( $elementor ) ) { |
| 124 |
if( ! current_user_can( 'activate_plugins' ) ) { |
| 125 |
return; |
| 126 |
} |
| 127 |
$activation_url = wp_nonce_url( 'plugins.php?action=activate&plugin=' . $elementor . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $elementor ); |
| 128 |
$button_text = '<p><a href="' . $activation_url . '" class="button-primary">' . __( 'Activate Elementor', 'ht-builder' ) . '</a></p>'; |
| 129 |
} else { |
| 130 |
if( ! current_user_can( 'activate_plugins' ) ) { |
| 131 |
return; |
| 132 |
} |
| 133 |
$activation_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=elementor' ), 'install-plugin_elementor' ); |
| 134 |
$button_text = '<p><a href="' . $activation_url . '" class="button-primary">' . __( 'Install Elementor', 'ht-builder' ) . '</a></p>'; |
| 135 |
} |
| 136 |
|
| 137 |
$message = sprintf( |
| 138 |
/* translators: 1: Plugin name 2: Elementor */ |
| 139 |
esc_html__( '"%1$s" requires "%2$s" to be installed and activated.', 'ht-builder' ), |
| 140 |
'<strong>' . esc_html__( 'HT Builder', 'ht-builder' ) . '</strong>', |
| 141 |
'<strong>' . esc_html__( 'Elementor', 'ht-builder' ) . '</strong>' |
| 142 |
); |
| 143 |
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p>%2$s</div>', $message, $button_text ); |
| 144 |
|
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Admin notice. |
| 149 |
* Elementor required version. |
| 150 |
*/ |
| 151 |
public function admin_notice_minimum_elementor_version() { |
| 152 |
if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] ); |
| 153 |
$message = sprintf( |
| 154 |
/* translators: 1: Plugin name 2: Elementor 3: Required Elementor version */ |
| 155 |
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'ht-builder' ), |
| 156 |
'<strong>' . esc_html__( 'HT Builder', 'ht-builder' ) . '</strong>', |
| 157 |
'<strong>' . esc_html__( 'Elementor', 'ht-builder' ) . '</strong>', |
| 158 |
self::MINIMUM_ELEMENTOR_VERSION |
| 159 |
); |
| 160 |
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message ); |
| 161 |
|
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Admin notice. |
| 166 |
* PHP required version. |
| 167 |
*/ |
| 168 |
public function admin_notice_minimum_php_version() { |
| 169 |
if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] ); |
| 170 |
$message = sprintf( |
| 171 |
/* translators: 1: Plugin name 2: PHP 3: Required PHP version */ |
| 172 |
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'ht-builder' ), |
| 173 |
'<strong>' . esc_html__( 'HT Builder', 'ht-builder' ) . '</strong>', |
| 174 |
'<strong>' . esc_html__( 'PHP', 'ht-builder' ) . '</strong>', |
| 175 |
self::MINIMUM_PHP_VERSION |
| 176 |
); |
| 177 |
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message ); |
| 178 |
} |
| 179 |
|
| 180 |
/* |
| 181 |
* Check Plugins is Installed or not |
| 182 |
*/ |
| 183 |
public function is_plugins_active( $pl_file_path = NULL ){ |
| 184 |
$installed_plugins_list = get_plugins(); |
| 185 |
return isset( $installed_plugins_list[$pl_file_path] ); |
| 186 |
} |
| 187 |
|
| 188 |
/* |
| 189 |
* Add settings link on plugin page. |
| 190 |
*/ |
| 191 |
public function plugins_setting_links( $links ) { |
| 192 |
$htbuilder_settings_link = '<a href="'.admin_url('admin.php?page=htbuilder').'">'.__( 'Settings', 'ht-builder' ).'</a>'; |
| 193 |
array_unshift( $links, $htbuilder_settings_link ); |
| 194 |
|
| 195 |
if( !is_plugin_active('htbuilder-pro/ht-builder.php') ){ |
| 196 |
$links['htbgo_pro'] = sprintf('<a href="http://hasthemes.com/" target="_blank" style="color: #39b54a; font-weight: bold;">' . __('Go Pro','ht-builder') . '</a>'); |
| 197 |
} |
| 198 |
return $links; |
| 199 |
} |
| 200 |
|
| 201 |
/* |
| 202 |
* Plugins After Install |
| 203 |
* Redirect Setting page |
| 204 |
*/ |
| 205 |
public function plugin_activate_hook() { |
| 206 |
add_option('htbuilder_do_activation_redirect', true); |
| 207 |
} |
| 208 |
public function plugin_redirect_option_page() { |
| 209 |
if ( get_option( 'htbuilder_do_activation_redirect', false ) ) { |
| 210 |
delete_option('htbuilder_do_activation_redirect'); |
| 211 |
if( !isset( $_GET['activate-multi'] ) ){ |
| 212 |
wp_redirect( admin_url('admin.php?page=ht-builder_extensions') ); |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
} |
| 220 |
Base::instance(); |