| 1 |
<?php |
| 2 |
/** |
| 3 |
* Modules Loader |
| 4 |
* |
| 5 |
* @package Beaver Builder Modules |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
/** |
| 13 |
* Initial Setup |
| 14 |
* |
| 15 |
* @since 1.6.15 |
| 16 |
*/ |
| 17 |
class Cartflows_BB_Modules_Loader { |
| 18 |
|
| 19 |
/** |
| 20 |
* Member Variable |
| 21 |
* |
| 22 |
* @var object instance |
| 23 |
*/ |
| 24 |
private static $instance; |
| 25 |
|
| 26 |
/** |
| 27 |
* Initiator |
| 28 |
*/ |
| 29 |
public static function get_instance() { |
| 30 |
if ( ! isset( self::$instance ) ) { |
| 31 |
self::$instance = new self(); |
| 32 |
} |
| 33 |
return self::$instance; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Constructor function that initializes required actions and hooks |
| 38 |
*/ |
| 39 |
public function __construct() { |
| 40 |
|
| 41 |
add_action( 'wp', array( $this, 'init' ), 8 ); |
| 42 |
add_action( 'admin_init', array( $this, 'register_modules' ), 8 ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Function that initializes init function |
| 47 |
* |
| 48 |
* @since 1.6.15 |
| 49 |
*/ |
| 50 |
public function init() { |
| 51 |
$this->include_modules_files(); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Returns Script array. |
| 56 |
* |
| 57 |
* @return array() |
| 58 |
* @since 1.6.15 |
| 59 |
*/ |
| 60 |
public static function get_module_list() { |
| 61 |
|
| 62 |
$widget_list = array( |
| 63 |
'cartflows-bb-next-step', |
| 64 |
'cartflows-bb-order-details', |
| 65 |
'cartflows-bb-checkout-form', |
| 66 |
'cartflows-bb-optin-form', |
| 67 |
); |
| 68 |
|
| 69 |
return $widget_list; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Include Widgets files |
| 74 |
* |
| 75 |
* Load widgets files |
| 76 |
* |
| 77 |
* @since 1.6.15 |
| 78 |
* @access public |
| 79 |
*/ |
| 80 |
public function include_modules_files() { |
| 81 |
|
| 82 |
global $post; |
| 83 |
|
| 84 |
if ( ! isset( $post ) ) { |
| 85 |
return; |
| 86 |
} |
| 87 |
|
| 88 |
$post_type = $post->post_type; |
| 89 |
|
| 90 |
if ( 'cartflows_step' === $post_type && class_exists( 'FLBuilder' ) ) { |
| 91 |
|
| 92 |
$this->get_module_files(); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Register the modules. |
| 98 |
* |
| 99 |
* Register modules early to disply them on options page |
| 100 |
* |
| 101 |
* @since 1.6.15 |
| 102 |
* @access public |
| 103 |
*/ |
| 104 |
public function register_modules() { |
| 105 |
|
| 106 |
if ( is_admin() && isset( $_GET['page'] ) && 'fl-builder-settings' === sanitize_text_field( $_GET['page'] ) && class_exists( 'FLBuilder' ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 107 |
|
| 108 |
$this->get_module_files(); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Get Module files |
| 114 |
* |
| 115 |
* @since 1.6.15 |
| 116 |
* @access public |
| 117 |
*/ |
| 118 |
public function get_module_files() { |
| 119 |
/* Required files */ |
| 120 |
require_once CARTFLOWS_DIR . 'modules/beaver-builder/classes/class-cartflows-bb-editor.php'; |
| 121 |
|
| 122 |
include_once CARTFLOWS_DIR . 'modules/beaver-builder/classes/class-cartflows-bb-helper.php'; |
| 123 |
|
| 124 |
$widget_list = $this->get_module_list(); |
| 125 |
|
| 126 |
if ( ! empty( $widget_list ) ) { |
| 127 |
foreach ( $widget_list as $widget ) { |
| 128 |
|
| 129 |
include_once CARTFLOWS_DIR . 'modules/beaver-builder/' . $widget . '/' . $widget . '.php'; |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Kicking this off by calling 'get_instance()' method |
| 137 |
*/ |
| 138 |
Cartflows_BB_Modules_Loader::get_instance(); |
| 139 |
|