PluginProbe
Additional Terms Lite for WooCommerce / 1.6.0
Additional Terms Lite for WooCommerce v1.6.0
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.0, at src/Plugin.php

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