|
2 | 2 | namespace VendorName\PluginName; |
3 | 3 | use WordPress_ToolKit\ObjectCache; |
4 | 4 | use WordPress_ToolKit\ConfigRegistry; |
5 | | -use WordPress_ToolKit\PluginTools; |
6 | 5 | use WordPress_ToolKit\Helpers\ArrayHelper; |
7 | 6 | use Carbon_Fields\Container; |
8 | 7 | use Carbon_Fields\Field; |
9 | | -use Config; |
10 | 8 |
|
11 | 9 | class Plugin extends \WordPress_ToolKit\ToolKit { |
12 | 10 |
|
13 | 11 | public static $textdomain; |
14 | | - public static $config; |
15 | 12 | protected static $cache; |
16 | 13 |
|
17 | 14 | function __construct() { |
18 | 15 |
|
19 | | - // Get plugin properties and meta data |
20 | | - $plugin_obj = new PluginTools( __DIR__ ); |
21 | | - $plugin_data = $plugin_obj->get_current_plugin_data( ARRAY_A ); |
| 16 | + // Load plugin configuration |
| 17 | + $this->init( dirname( __DIR__ ), trailingslashit( dirname( __DIR__ ) ) . 'plugin.json' ); |
| 18 | + self::$config->merge( new ConfigRegistry( [ 'plugin' => $this->get_current_plugin_meta( ARRAY_A ) ] ) ); |
22 | 19 |
|
23 | | - self::$config = new ConfigRegistry( $plugin_data['path'] . 'plugin.json' ); |
24 | | - self::$config = self::$config->merge( new ConfigRegistry( [ 'plugin' => $plugin_data ] ) ); |
| 20 | + // Set Text Domain |
25 | 21 | self::$textdomain = self::$config->get( 'plugin/meta/TextDomain' ) ?: self::$config->get( 'plugin/slug' ); |
26 | 22 |
|
27 | | - // Define plugin VERSION constant |
| 23 | + // Define plugin version |
28 | 24 | if ( !defined( __NAMESPACE__ . '\VERSION' ) ) define( __NAMESPACE__ . '\VERSION', self::$config->get( 'plugin/meta/Version' ) ); |
29 | 25 |
|
30 | 26 | // Initialize ObjectCache |
31 | 27 | self::$cache = new ObjectCache( self::$config ); |
32 | 28 |
|
33 | | - // Verify dependecies and load plugin logic |
| 29 | + // Load dependecies and load plugin logic |
34 | 30 | register_activation_hook( self::$config->get( 'plugin/identifier' ), array( $this, 'activate' ) ); |
35 | | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
| 31 | + add_action( 'plugins_loaded', array( $this, 'load_dependencies' ) ); |
36 | 32 |
|
37 | 33 | } |
38 | 34 |
|
@@ -91,7 +87,7 @@ public function activate() { |
91 | 87 | * |
92 | 88 | * @since 0.2.0 |
93 | 89 | */ |
94 | | - public function init() { |
| 90 | + public function load_dependencies() { |
95 | 91 |
|
96 | 92 | if( class_exists( 'Carbon_Fields\\Carbon_Fields' ) ) { |
97 | 93 | add_action( 'after_setup_theme', array( 'Carbon_Fields\\Carbon_Fields', 'boot' ) ); |
@@ -197,7 +193,7 @@ private function verify_dependencies( $deps = true, $args = array() ) { |
197 | 193 | * @since 0.2.0 |
198 | 194 | * |
199 | 195 | */ |
200 | | - public static function get_plugin_option( $key, $cache = true ) { |
| 196 | + public static function get_carbon_plugin_option( $key, $cache = true ) { |
201 | 197 |
|
202 | 198 | $key = self::prefix( $key ); |
203 | 199 |
|
@@ -245,16 +241,4 @@ public static function get_wpsac_plugin_option( $key, $group_id = 'options', $ca |
245 | 241 |
|
246 | 242 | } |
247 | 243 |
|
248 | | - /** |
249 | | - * Returns true if WP_ENV is anything other than 'development' or 'staging'. |
250 | | - * Useful for determining whether or not to enqueue a minified or non- |
251 | | - * minified script (which can be useful for debugging via browser). |
252 | | - * |
253 | | - * @return bool |
254 | | - * @since 0.1.0 |
255 | | - */ |
256 | | - public static function is_production() { |
257 | | - return ( !defined( 'WP_ENV' ) || ( defined('WP_ENV' ) && !in_array( WP_ENV, array( 'development', 'staging' ) ) ) ); |
258 | | - } |
259 | | - |
260 | 244 | } |
0 commit comments