PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.3.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.3.0
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / admin-legacy-loader.php

admin-legacy-loader.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.3.0, at admin-legacy-loader.php

143 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CartFlows Legacy Admin Loader.
4 *
5 * Bootstraps the pre-3.0 admin UI (preserved under admin-legacy-core/) when
6 * the user has opted into the legacy interface via the cartflows-legacy-admin
7 * option. Mirrors admin-loader.php but binds CARTFLOWS_ADMIN_CORE_DIR/URL to
8 * the admin-legacy-core/ directory and registers the legacy Wizard.
9 *
10 * @package CartFlows
11 */
12
13 namespace CartflowsAdmin;
14
15 use CartflowsAdmin\AdminLegacyCore\Api\ApiInit;
16 use CartflowsAdmin\AdminLegacyCore\Ajax\AjaxInit;
17 use CartflowsAdmin\AdminLegacyCore\Inc\AdminMenu;
18 use CartflowsAdmin\AdminLegacyCore\Inc\StoreCheckout;
19 use CartflowsAdmin\Wizard\Inc\WizardCore;
20 use CartflowsAdmin\Wizard\Ajax\WizardAjaxInit;
21
22 if ( ! defined( 'ABSPATH' ) ) {
23 exit;
24 }
25
26 /**
27 * Class Admin_Legacy_Loader.
28 */
29 class Admin_Legacy_Loader {
30
31 /**
32 * Instance
33 *
34 * @var object
35 */
36 private static $instance;
37
38 /**
39 * Initiator
40 *
41 * @return object
42 */
43 public static function get_instance() {
44 if ( ! isset( self::$instance ) ) {
45 self::$instance = new self();
46 }
47 return self::$instance;
48 }
49
50 /**
51 * Autoload classes — kebab-cases the FQN under CartflowsAdmin\* and resolves
52 * it to a file path relative to CARTFLOWS_DIR. Identical mapping as
53 * admin-loader.php so AdminLegacyCore\* resolves to admin-legacy-core/*.
54 *
55 * @param string $class class name.
56 */
57 public function autoload( $class ) {
58
59 if ( 0 !== strpos( $class, __NAMESPACE__ ) ) {
60 return;
61 }
62
63 if ( ! class_exists( $class ) ) {
64 $filename = strtolower(
65 preg_replace(
66 array( '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ),
67 array( '', '$1-$2', '-', DIRECTORY_SEPARATOR ),
68 $class
69 )
70 );
71
72 $file = CARTFLOWS_DIR . $filename . '.php';
73
74 if ( is_readable( $file ) ) {
75 include $file;
76 }
77 }
78 }
79
80 /**
81 * Constructor.
82 */
83 public function __construct() {
84
85 spl_autoload_register( array( $this, 'autoload' ) );
86
87 $this->define_constants();
88 $this->setup_classes();
89 }
90
91 /**
92 * Define legacy admin core paths. Reuses the same constant names as
93 * admin-loader.php so legacy files require no source changes — only the
94 * resolved path differs.
95 */
96 public function define_constants() {
97 define( 'CARTFLOWS_ADMIN_CORE_DIR', CARTFLOWS_DIR . 'admin-legacy-core/' );
98 define( 'CARTFLOWS_ADMIN_CORE_URL', CARTFLOWS_URL . 'admin-legacy-core/' );
99 }
100
101 /**
102 * External code (importer, abilities runtime, SureTriggers compat) imports
103 * CartflowsAdmin\AdminCore\Inc\* classes by FQN. Those classes don't exist
104 * in legacy mode — autoload would miss and fatal on first reference. Alias
105 * the legacy classes under the AdminCore FQN so external callers resolve
106 * transparently regardless of which UI is active.
107 */
108 public function alias_admin_core_classes() {
109
110 $aliases = array(
111 'CartflowsAdmin\\AdminLegacyCore\\Inc\\AdminHelper' => 'CartflowsAdmin\\AdminCore\\Inc\\AdminHelper',
112 'CartflowsAdmin\\AdminLegacyCore\\Inc\\AdminMenu' => 'CartflowsAdmin\\AdminCore\\Inc\\AdminMenu',
113 );
114
115 foreach ( $aliases as $source => $target ) {
116 if ( ! class_exists( $target, false ) ) {
117 class_alias( $source, $target );
118 }
119 }
120 }
121
122 /**
123 * Boot legacy admin classes.
124 */
125 public function setup_classes() {
126
127 $this->alias_admin_core_classes();
128
129 ApiInit::get_instance();
130
131 if ( is_admin() ) {
132 StoreCheckout::get_instance();
133 AdminMenu::get_instance();
134 AjaxInit::get_instance();
135
136 WizardAjaxInit::get_instance();
137 WizardCore::get_instance();
138 }
139 }
140 }
141
142 Admin_Legacy_Loader::get_instance();
143