PluginProbe
Additional Terms Lite for WooCommerce / 1.6.3
Additional Terms Lite for WooCommerce v1.6.3
1.7.3 1.7.2.1 trunk 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.6.3 All 35 releases
woo-additional-terms / src / Plugin.php

Plugin.php in Additional Terms Lite for WooCommerce 1.6.3, at src/Plugin.php

210 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The core plugin class.
4 *
5 * @author MyPreview (Github: @mahdiyazdani, @gooklani, @mypreview)
6 *
7 * @since 1.6.0
8 *
9 * @package woo-additional-terms
10 */
11
12 namespace Woo_Additional_Terms;
13
14 /**
15 * The plugin class.
16 */
17 class Plugin extends Vendor\Pimple\Container {
18
19 /**
20 * The plugin version.
21 *
22 * @since 1.6.0
23 *
24 * @var string
25 */
26 private $version;
27
28 /**
29 * Constructor.
30 *
31 * @since 1.6.0
32 *
33 * @param string $version The plugin version.
34 * @param string $file The plugin file.
35 *
36 * @return void
37 */
38 public function __construct( $version, $file ) {
39
40 // Set the version.
41 $this->version = $version;
42
43 // Pimple Container construct.
44 parent::__construct();
45
46 // Register the file service.
47 $this['file'] = fn() => new File( $file );
48
49 // Register services early.
50 $this->register_services();
51
52 // Load the plugin.
53 $this->load();
54 }
55
56 /**
57 * Register services.
58 *
59 * @since 1.6.0
60 *
61 * @return void
62 */
63 private function register_services() {
64
65 $provider = new PluginServiceProvider();
66 $provider->register( $this );
67 }
68
69 /**
70 * Get a service by given key.
71 *
72 * @since 1.6.0
73 *
74 * @param string $key The service key.
75 *
76 * @return mixed
77 */
78 public function service( $key ) {
79
80 return $this[ $key ];
81 }
82
83 /**
84 * Get the plugin slug.
85 *
86 * @since 1.6.0
87 *
88 * @return string
89 */
90 public function get_slug() {
91
92 return 'woo-additional-terms';
93 }
94
95 /**
96 * Get the plugin version.
97 *
98 * @since 1.6.0
99 *
100 * @return string
101 */
102 public function get_version() {
103
104 return $this->version;
105 }
106
107 /**
108 * Start loading classes on `woocommerce_loaded`, priority 20.
109 *
110 * @since 1.6.0
111 *
112 * @return void
113 */
114 private function load() {
115
116 // Iterate through the classes and initialize them.
117 foreach ( $this->get_classes() as $class => $args ) {
118
119 // Skip if the condition is not met.
120 if ( isset( $args['condition'] ) && ! $args['condition'] ) {
121 continue;
122 }
123
124 // Initialize the class with parameters.
125 if ( isset( $args['params'] ) ) {
126 ( new $class() )->setup( ...$args['params'] );
127 continue;
128 }
129
130 // Initialize the class.
131 ( new $class() )->setup();
132 }
133
134 add_action( 'before_woocommerce_init', array( 'Woo_Additional_Terms\\I18n', 'textdomain' ) );
135 add_action( 'enqueue_block_editor_assets', array( 'Woo_Additional_Terms\\Assets', 'enqueue_editor' ) );
136 add_action( 'admin_enqueue_scripts', array( 'Woo_Additional_Terms\\Assets', 'enqueue_admin' ) );
137 add_action( 'wp_enqueue_scripts', array( 'Woo_Additional_Terms\\Assets', 'enqueue_frontend' ) );
138 }
139
140 /**
141 * Get the classes to load.
142 *
143 * @since 1.6.0
144 *
145 * @return array
146 */
147 private function get_classes() {
148
149 $is_ajax = wp_doing_ajax();
150 $is_admin = is_admin();
151 $is_frontend = ! $is_admin;
152 $classes = array(
153 'Admin\\Order' => array(
154 'condition' => $is_admin,
155 ),
156 'Ajax\\OnBoarding' => array(
157 'condition' => $is_ajax,
158 ),
159 'Ajax\\Rate' => array(
160 'condition' => $is_ajax,
161 ),
162 'Ajax\\Rated' => array(
163 'condition' => $is_ajax,
164 ),
165 'Compatibility\\WooCommerce' => array(
166 'condition' => $is_admin && class_exists( 'Automattic\\WooCommerce\\Utilities\\FeaturesUtil' ),
167 ),
168 'Enhancements\\Docs' => array(
169 'condition' => $is_admin,
170 ),
171 'Enhancements\\Meta' => array(
172 'condition' => $is_admin,
173 'params' => array(
174 $this['file']->plugin_basename(),
175 ),
176 ),
177 'Enhancements\\Notices' => array(
178 'condition' => $is_admin,
179 ),
180 'Enhancements\\OnBoarding' => array(
181 'condition' => $is_admin,
182 ),
183 'Enhancements\\Rate' => array(
184 'condition' => $is_admin,
185 ),
186 'Enhancements\\Upsell' => array(
187 'condition' => $is_admin,
188 ),
189 'Migration\\Migration160' => array(
190 'condition' => $is_admin,
191 ),
192 'Settings\\Register' => array(
193 'condition' => $is_admin,
194 ),
195 'WooCommerce\\Checkout' => array(
196 'condition' => $is_frontend,
197 ),
198 'WooCommerce\\Block\\Register' => array(),
199 );
200
201 return array_combine(
202 array_map(
203 fn ( $key ) => __NAMESPACE__ . '\\' . $key,
204 array_keys( $classes )
205 ),
206 $classes
207 );
208 }
209 }
210