PluginProbe
Modern Cart – WooCommerce Side Cart & Popup Cart / 1.0.3
Modern Cart – WooCommerce Side Cart & Popup Cart v1.0.3
1.0.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
modern-cart / plugin-loader.php

plugin-loader.php in Modern Cart – WooCommerce Side Cart & Popup Cart 1.0.3, at plugin-loader.php

171 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Loader.
4 *
5 * @package modern-cart
6 * @since 0.0.1
7 */
8
9 namespace ModernCart;
10
11 use ModernCart\Admin_Core\Admin_Menu;
12 use ModernCart\Inc\Floating;
13 use ModernCart\Inc\Floating_Ajax;
14 use ModernCart\Inc\Helper;
15 use ModernCart\Inc\Scripts;
16 use ModernCart\Inc\Slide_Out;
17 use ModernCart\Inc\Slide_Out_Ajax;
18
19 /**
20 * Plugin_Loader
21 *
22 * @since 0.0.1
23 */
24 class Plugin_Loader {
25 /**
26 * Instance
27 *
28 * @access private
29 * @var object Class Instance.
30 * @since 0.0.1
31 */
32 private static $instance;
33
34 /**
35 * Constructor
36 *
37 * @since 0.0.1
38 */
39 public function __construct() {
40 spl_autoload_register( [ $this, 'autoload' ] );
41
42 add_action( 'init', [ $this, 'save_version_info' ] );
43 add_action( 'plugins_loaded', [ $this, 'load_classes' ] );
44 add_filter( 'plugin_action_links_' . MODERNCART_BASE, [ $this, 'action_links' ] );
45
46 do_action( 'moderncart_loaded' );
47 }
48
49 /**
50 * Save version information.
51 */
52 public function save_version_info(): void {
53 $version = get_option( 'moderncart_version' );
54
55 if ( is_array( $version ) && isset( $version['current'] ) && MODERNCART_VER === $version['current'] ) {
56 // Already updated.
57 return;
58 }
59
60 $version = [
61 'current' => MODERNCART_VER,
62 'previous' => ( is_array( $version ) && isset( $version['current'] ) ) ? $version['current'] : '',
63 ];
64
65 update_option( 'moderncart_version', $version );
66 }
67
68 /**
69 * Initiator
70 *
71 * @since 0.0.1
72 * @return object initialized object of class.
73 */
74 public static function get_instance() {
75 if ( null === self::$instance ) {
76 self::$instance = new self();
77 }
78 return self::$instance;
79 }
80
81 /**
82 * Autoload classes.
83 *
84 * @param string $class class name.
85 */
86 public function autoload( $class ): void {
87 if ( 0 !== strpos( $class, __NAMESPACE__ ) ) {
88 return;
89 }
90
91 $class_to_load = $class;
92
93 $filename = preg_replace(
94 [ '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ],
95 [ '', '$1-$2', '-', DIRECTORY_SEPARATOR ],
96 $class_to_load
97 );
98
99 if ( is_string( $filename ) ) {
100 $filename = strtolower( $filename );
101
102 $file = MODERNCART_DIR . $filename . '.php';
103
104 // if the file redable, include it.
105 if ( is_readable( $file ) ) {
106 require_once $file;
107 }
108 }
109 }
110
111 /**
112 * Declare the woo HPOS compatibility.
113 *
114 * @since 1.0.1
115 * @return void
116 */
117 public function declare_woo_hpos_compatibility() {
118 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
119 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', MODERNCART_FILE, true );
120 }
121 }
122
123 /**
124 * Loads plugin classes as per requirement.
125 *
126 * @return void
127 * @since 0.0.1
128 */
129 public function load_classes(): void {
130 if ( ! class_exists( 'woocommerce' ) ) {
131 return;
132 }
133
134 // Let WooCommerce know, CartFlows is compatible with HPOS.
135 add_action( 'before_woocommerce_init', array( $this, 'declare_woo_hpos_compatibility' ) );
136
137 if ( is_admin() ) {
138 Admin_Menu::get_instance();
139 }
140
141 Scripts::get_instance();
142 Floating::get_instance();
143 Slide_Out::get_instance();
144 Slide_Out_Ajax::get_instance();
145 Floating_Ajax::get_instance();
146 }
147
148 /**
149 * Adds links in Plugins page.
150 *
151 * @param array<string> $links Existing links.
152 * @return array<string> Filtered links with settings added.
153 * @since 0.0.1
154 */
155 public function action_links( $links ) {
156 $plugin_links = apply_filters(
157 'moderncart_cpsw_plugin_action_links',
158 [
159 'moderncart_settings' => '<a href="' . admin_url( 'admin.php?page=moderncart_settings' ) . '">' . __( 'Settings', 'modern-cart' ) . '</a>',
160 ]
161 );
162
163 return array_merge( $plugin_links, $links );
164 }
165 }
166
167 /**
168 * Kicking this off by calling 'get_instance()' method
169 */
170 Plugin_Loader::get_instance();
171