| 1 |
<?php |
| 2 |
/** |
| 3 |
* Elementor manager |
| 4 |
* |
| 5 |
* @package |
| 6 |
*/ |
| 7 |
namespace WPFunnels\Widgets\Elementor; |
| 8 |
use WPFunnels\Widgets\Elementor\Controls\Optin_Styles; |
| 9 |
use WPFunnels\Widgets\Elementor\Controls\Product_Control; |
| 10 |
use WPFunnels\Wpfnl_functions; |
| 11 |
|
| 12 |
|
| 13 |
if (!defined('ABSPATH')) { |
| 14 |
exit; // Exit if accessed directly. |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Main Elementor Test Extension Class |
| 19 |
* |
| 20 |
* The main class that initiates and runs the plugin. |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
*/ |
| 24 |
final class Manager |
| 25 |
{ |
| 26 |
|
| 27 |
/** |
| 28 |
* Plugin Version |
| 29 |
* |
| 30 |
* @since 1.0.0 |
| 31 |
* |
| 32 |
* @var string The plugin version. |
| 33 |
*/ |
| 34 |
const VERSION = WPFNL_VERSION; |
| 35 |
|
| 36 |
/** |
| 37 |
* Minimum Elementor Version |
| 38 |
* |
| 39 |
* @since 1.0.0 |
| 40 |
* |
| 41 |
* @var string Minimum Elementor version required to run the plugin. |
| 42 |
*/ |
| 43 |
const MINIMUM_ELEMENTOR_VERSION = '2.0.0'; |
| 44 |
|
| 45 |
/** |
| 46 |
* Minimum PHP Version |
| 47 |
* |
| 48 |
* @since 1.0.0 |
| 49 |
* |
| 50 |
* @var string Minimum PHP version required to run the plugin. |
| 51 |
*/ |
| 52 |
const MINIMUM_PHP_VERSION = '7.0'; |
| 53 |
|
| 54 |
/** |
| 55 |
* Instance |
| 56 |
* |
| 57 |
* @since 1.0.0 |
| 58 |
* |
| 59 |
* @access private |
| 60 |
* @static |
| 61 |
* |
| 62 |
* @var Manager The single instance of the class. |
| 63 |
*/ |
| 64 |
private static $_instance = null; |
| 65 |
|
| 66 |
/** |
| 67 |
* Instance |
| 68 |
* |
| 69 |
* Ensures only one instance of the class is loaded or can be loaded. |
| 70 |
* |
| 71 |
* @return Manager An instance of the class. |
| 72 |
* @since 1.0.0 |
| 73 |
* |
| 74 |
* @access public |
| 75 |
* @static |
| 76 |
*/ |
| 77 |
public static function instance() { |
| 78 |
if (is_null(self::$_instance)) { |
| 79 |
self::$_instance = new self(); |
| 80 |
} |
| 81 |
return self::$_instance; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Constructor |
| 86 |
* |
| 87 |
* @since 1.0.0 |
| 88 |
* |
| 89 |
* @access public |
| 90 |
*/ |
| 91 |
public function __construct() { |
| 92 |
|
| 93 |
if( $this->is_compatible() ) { |
| 94 |
add_action('elementor/init', [$this, 'init']); |
| 95 |
add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'enqueue_elementor_custom_style' ) ); |
| 96 |
add_filter( 'wpfunnels/page_template', array( $this, 'get_page_template' ) ); |
| 97 |
} |
| 98 |
|
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
/** |
| 103 |
* Add css file on Elementor admin |
| 104 |
* |
| 105 |
* @since 1.0.0 |
| 106 |
* |
| 107 |
* @access public |
| 108 |
*/ |
| 109 |
public function enqueue_elementor_custom_style() |
| 110 |
{ |
| 111 |
wp_enqueue_style('elementor-icon', WPFNL_URL. 'includes/core/widgets/elementor/assets/css/elemetor-icon-style.css'); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Compatibility Checks |
| 116 |
* |
| 117 |
* Checks if the installed version of Elementor meets the plugin's minimum requirement. |
| 118 |
* Checks if the installed PHP version meets the plugin's minimum requirement. |
| 119 |
* |
| 120 |
* @since 1.0.0 |
| 121 |
* |
| 122 |
* @access public |
| 123 |
*/ |
| 124 |
public function is_compatible() { |
| 125 |
|
| 126 |
// Check if Elementor installed and activated |
| 127 |
if (!did_action('elementor/loaded')) { |
| 128 |
return false; |
| 129 |
} |
| 130 |
|
| 131 |
// Check for required Elementor version |
| 132 |
if (!version_compare(ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=')) { |
| 133 |
return false; |
| 134 |
} |
| 135 |
|
| 136 |
// Check for required PHP version |
| 137 |
if (version_compare(PHP_VERSION, self::MINIMUM_PHP_VERSION, '<')) { |
| 138 |
return false; |
| 139 |
} |
| 140 |
|
| 141 |
return true; |
| 142 |
|
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Initialize the plugin |
| 147 |
* |
| 148 |
* Load the plugin only after Elementor (and other plugins) are loaded. |
| 149 |
* Load the files required to run the plugin. |
| 150 |
* |
| 151 |
* Fired by `plugins_loaded` action hook. |
| 152 |
* |
| 153 |
* @since 1.0.0 |
| 154 |
* |
| 155 |
* @access public |
| 156 |
*/ |
| 157 |
public function init() { |
| 158 |
|
| 159 |
$editor_compatibility = Elemenetor_Editror_Compatibility::getInstance(); |
| 160 |
$editor_compatibility->elementor_compatibility(); |
| 161 |
|
| 162 |
add_action('elementor/init', [$this, 'add_elementor_widget_categories'],9999); |
| 163 |
if ( version_compare(ELEMENTOR_VERSION, '3.5.0', '>=') ) { |
| 164 |
add_action('elementor/widgets/register', [$this, 'init_widgets']); |
| 165 |
} else { |
| 166 |
add_action('elementor/widgets/widgets_registered', [$this, 'init_widgets']); |
| 167 |
} |
| 168 |
|
| 169 |
add_action('elementor/controls/controls_registered', [$this, 'init_controls']); |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
/** |
| 174 |
* Register Category |
| 175 |
* |
| 176 |
* @since 1.0.0 |
| 177 |
* |
| 178 |
* @access private |
| 179 |
*/ |
| 180 |
public function add_elementor_widget_categories() |
| 181 |
{ |
| 182 |
|
| 183 |
|
| 184 |
$elementsManager = \Elementor\Plugin::instance()->elements_manager; |
| 185 |
$elementsManager->add_category( |
| 186 |
'wp-funnel', |
| 187 |
[ |
| 188 |
'title' => __('WPFunnels', 'wpfnl'), |
| 189 |
'icon' => 'fa fa-plug', |
| 190 |
] |
| 191 |
); |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Init Widgets |
| 196 |
* |
| 197 |
* Include widgets files and register them |
| 198 |
* |
| 199 |
* @since 1.0.0 |
| 200 |
* |
| 201 |
* @access public |
| 202 |
*/ |
| 203 |
public function init_widgets() |
| 204 |
{ |
| 205 |
$step_id = $this->get_step_id(); |
| 206 |
|
| 207 |
if($step_id) { |
| 208 |
$step = $this->widget_registration_manager($step_id); |
| 209 |
if ( $step ) { |
| 210 |
$step_type = get_post_meta($step_id, '_step_type', true); |
| 211 |
if( 'landing' === $step_type || 'custom' === $step_type ) { |
| 212 |
if ( version_compare(ELEMENTOR_VERSION, '3.5.0', '>=') ) { |
| 213 |
\Elementor\Plugin::instance()->widgets_manager->register(new Step_Pointer()); |
| 214 |
\Elementor\Plugin::instance()->widgets_manager->register(new OptinForm()); |
| 215 |
} else { |
| 216 |
// for older version of elementor |
| 217 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Step_Pointer()); |
| 218 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type(new OptinForm()); |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
$funnel_id = get_post_meta($step_id,'_funnel_id',true); |
| 223 |
$type = get_post_meta($funnel_id,'_wpfnl_funnel_type',true); |
| 224 |
|
| 225 |
|
| 226 |
if (Wpfnl_functions::is_plugin_activated('woocommerce/woocommerce.php')) { |
| 227 |
if($step_type == 'checkout') { |
| 228 |
if ( version_compare(ELEMENTOR_VERSION, '3.5.0', '>=') ) { |
| 229 |
\Elementor\Plugin::instance()->widgets_manager->register(new Checkout_Form()); |
| 230 |
} else { |
| 231 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Checkout_Form()); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
if($step_type == 'thankyou') { |
| 236 |
if ( version_compare(ELEMENTOR_VERSION, '3.5.0', '>=') ) { |
| 237 |
\Elementor\Plugin::instance()->widgets_manager->register(new Order_Details()); |
| 238 |
} else { |
| 239 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Order_Details()); |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
// Register Offer Button only if Pro is not active |
| 244 |
if( ( $step_type == 'upsell' || $step_type == 'downsell' ) && ! Wpfnl_functions::is_wpfnl_pro_activated() ) { |
| 245 |
if ( version_compare(ELEMENTOR_VERSION, '3.5.0', '>=') ) { |
| 246 |
\Elementor\Plugin::instance()->widgets_manager->register( new Offer_Button() ); |
| 247 |
} else { |
| 248 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Offer_Button()); |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
} |
| 254 |
}elseif(wp_get_theme()->get('Name') == 'Woodmart'){ |
| 255 |
if ( version_compare(ELEMENTOR_VERSION, '3.5.0', '>=') ) { |
| 256 |
\Elementor\Plugin::instance()->widgets_manager->register(new Step_Pointer()); |
| 257 |
\Elementor\Plugin::instance()->widgets_manager->register(new OptinForm()); |
| 258 |
\Elementor\Plugin::instance()->widgets_manager->register(new Checkout_Form()); |
| 259 |
\Elementor\Plugin::instance()->widgets_manager->register(new Order_Details()); |
| 260 |
// Register Offer Button only if Pro is not active |
| 261 |
if ( ! Wpfnl_functions::is_wpfnl_pro_activated() ) { |
| 262 |
\Elementor\Plugin::instance()->widgets_manager->register(new Offer_Button()); |
| 263 |
} |
| 264 |
} else { |
| 265 |
// for older version of elementor |
| 266 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Step_Pointer()); |
| 267 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type(new OptinForm()); |
| 268 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Checkout_Form()); |
| 269 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Order_Details()); |
| 270 |
// Register Offer Button only if Pro is not active |
| 271 |
if ( ! Wpfnl_functions::is_wpfnl_pro_activated() ) { |
| 272 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Offer_Button()); |
| 273 |
} |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
/** |
| 281 |
* Get step id |
| 282 |
* |
| 283 |
* @since 2.7.7 |
| 284 |
* @return Int |
| 285 |
*/ |
| 286 |
public function get_step_id(){ |
| 287 |
|
| 288 |
$step_id = ''; |
| 289 |
if( wp_doing_ajax() ) { |
| 290 |
if( isset($_POST['step_id']) ) { |
| 291 |
$step_id = $_POST['step_id']; |
| 292 |
} elseif ( isset($_POST['editor_post_id'] ) ) { |
| 293 |
$step_id = $_POST['editor_post_id']; |
| 294 |
} else { |
| 295 |
$step_id = ''; |
| 296 |
} |
| 297 |
if( !$step_id && isset($_POST['initial_document_id'] ) ) { |
| 298 |
$step_id = $_POST['initial_document_id']; |
| 299 |
} |
| 300 |
}else { |
| 301 |
$step_id = isset($_GET['post']) ? $_GET['post'] : get_the_ID(); |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
if( !$step_id ){ |
| 307 |
$class_name = "WPFunnels\\Compatibility\\Plugin\\ElectroExtension"; |
| 308 |
if (class_exists(ucfirst($class_name))) { |
| 309 |
if( $class_name::getInstance()->maybe_activate() ){ |
| 310 |
if( !empty($_COOKIE['wpfunnels_current_post_id']) ){ |
| 311 |
$step_id = $_COOKIE['wpfunnels_current_post_id']; |
| 312 |
} |
| 313 |
} |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
return $step_id; |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
/** |
| 323 |
* Init Controls |
| 324 |
* |
| 325 |
* Include controls files and register them |
| 326 |
* |
| 327 |
* @since 1.0.0 |
| 328 |
* |
| 329 |
* @access public |
| 330 |
*/ |
| 331 |
public function init_controls() { |
| 332 |
\Elementor\Plugin::$instance->controls_manager->register_control(\WPFunnels\Widgets\Elementor\Controls\Product_Control::ProductSelector, new Product_Control()); |
| 333 |
\Elementor\Plugin::$instance->controls_manager->register_control('optin_styles', new Optin_Styles()); |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
/** |
| 339 |
* Widget Registration manager |
| 340 |
* |
| 341 |
* @since 1.0.0 |
| 342 |
* |
| 343 |
* @access private |
| 344 |
*/ |
| 345 |
public function widget_registration_manager($page_id) { |
| 346 |
return get_post_meta($page_id, '_step_type', true); |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
/** |
| 351 |
* Get page templates |
| 352 |
* |
| 353 |
* @param $template |
| 354 |
* |
| 355 |
* @return mixed |
| 356 |
* |
| 357 |
* @since 2.0.5 |
| 358 |
*/ |
| 359 |
public function get_page_template( $template ) { |
| 360 |
|
| 361 |
if ( Wpfnl_functions::is_elementor_active() && is_singular() ) { |
| 362 |
$is_preview_mode = \Elementor\Plugin::$instance->preview->is_preview_mode(); |
| 363 |
if($is_preview_mode) { |
| 364 |
$document = \Elementor\Plugin::$instance->documents->get_doc_for_frontend( get_the_ID() ); |
| 365 |
if ( $document ) { |
| 366 |
$template = $document->get_meta( '_wp_page_template' ); |
| 367 |
} |
| 368 |
} |
| 369 |
} |
| 370 |
return $template; |
| 371 |
} |
| 372 |
} |
| 373 |
|
| 374 |
Manager::instance(); |
| 375 |
|