Skip to content

Commit 2989af6

Browse files
committed
Moved common methods to ToolKit; renamed get_plugin_option()
1 parent bc056d7 commit 2989af6

4 files changed

Lines changed: 14 additions & 30 deletions

File tree

app/Core.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function __construct() {
1010
add_filter( 'body_class', array( &$this, 'add_body_classes' ) );
1111

1212
// Example - Remove Emoji code from header
13-
if( $this->get_plugin_option( 'remove_header_emojicons' ) ) {
13+
if( $this->get_carbon_plugin_option( 'remove_header_emojicons' ) ) {
1414
if(!$this->is_ajax()) add_filter( 'init', array( $this, 'disable_wp_emojicons' ) );
1515
}
1616

@@ -21,7 +21,7 @@ function __construct() {
2121
* logged in, you would need to uncommend the 'wp_ajax_nopriv_clear_object_cache_ajax'
2222
* hook.
2323
*/
24-
if( current_user_can( 'manage_options' ) && $this->get_plugin_option( 'admin_bar_add_clear_cache' ) ) {
24+
if( current_user_can( 'manage_options' ) && $this->get_carbon_plugin_option( 'admin_bar_add_clear_cache' ) ) {
2525
add_action( 'admin_bar_menu', array( $this, 'admin_bar_add_clear_cache' ), 900 );
2626
//add_action( 'wp_ajax_nopriv_clear_object_cache_ajax', array( self::$cache, 'flush' ) );
2727
add_action( 'wp_ajax_clear_object_cache_ajax', array( self::$cache, 'flush' ) );

app/EnqueueScripts.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function __construct() {
1414
$this->inject_javascript_settings();
1515

1616
// Example - Load Font Awesome from CDN, if enabled in Settings Page
17-
$enqueue_font_awesome = $this->get_plugin_option( 'enqueue_font_awesome' );
17+
$enqueue_font_awesome = $this->get_carbon_plugin_option( 'enqueue_font_awesome' );
1818
if( $enqueue_font_awesome ) {
1919
if( in_array( 'frontend', $enqueue_font_awesome) )
2020
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_font_awesome' ) );
@@ -94,7 +94,7 @@ private function inject_javascript_settings() {
9494
);
9595

9696
$values = array(
97-
'admin_bar_add_clear_cache' => $this->get_plugin_option( 'admin_bar_add_clear_cache' ),
97+
'admin_bar_add_clear_cache' => $this->get_carbon_plugin_option( 'admin_bar_add_clear_cache' ),
9898
'admin_bar_add_clear_cache_success' => __( 'WordPress cache has been cleared.', self::$textdomain ),
9999
'show_clear_cache_link' => current_user_can( 'manage_options' ),
100100
);

app/Plugin.php

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,33 @@
22
namespace VendorName\PluginName;
33
use WordPress_ToolKit\ObjectCache;
44
use WordPress_ToolKit\ConfigRegistry;
5-
use WordPress_ToolKit\PluginTools;
65
use WordPress_ToolKit\Helpers\ArrayHelper;
76
use Carbon_Fields\Container;
87
use Carbon_Fields\Field;
9-
use Config;
108

119
class Plugin extends \WordPress_ToolKit\ToolKit {
1210

1311
public static $textdomain;
14-
public static $config;
1512
protected static $cache;
1613

1714
function __construct() {
1815

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 ) ] ) );
2219

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
2521
self::$textdomain = self::$config->get( 'plugin/meta/TextDomain' ) ?: self::$config->get( 'plugin/slug' );
2622

27-
// Define plugin VERSION constant
23+
// Define plugin version
2824
if ( !defined( __NAMESPACE__ . '\VERSION' ) ) define( __NAMESPACE__ . '\VERSION', self::$config->get( 'plugin/meta/Version' ) );
2925

3026
// Initialize ObjectCache
3127
self::$cache = new ObjectCache( self::$config );
3228

33-
// Verify dependecies and load plugin logic
29+
// Load dependecies and load plugin logic
3430
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' ) );
3632

3733
}
3834

@@ -91,7 +87,7 @@ public function activate() {
9187
*
9288
* @since 0.2.0
9389
*/
94-
public function init() {
90+
public function load_dependencies() {
9591

9692
if( class_exists( 'Carbon_Fields\\Carbon_Fields' ) ) {
9793
add_action( 'after_setup_theme', array( 'Carbon_Fields\\Carbon_Fields', 'boot' ) );
@@ -197,7 +193,7 @@ private function verify_dependencies( $deps = true, $args = array() ) {
197193
* @since 0.2.0
198194
*
199195
*/
200-
public static function get_plugin_option( $key, $cache = true ) {
196+
public static function get_carbon_plugin_option( $key, $cache = true ) {
201197

202198
$key = self::prefix( $key );
203199

@@ -245,16 +241,4 @@ public static function get_wpsac_plugin_option( $key, $group_id = 'options', $ca
245241

246242
}
247243

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-
260244
}

app/Settings/Carbon_Page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct() {
2727
$this->create_tabbed_options_page();
2828

2929
// Register uninstall hook to delete settings
30-
if( $this->get_plugin_option( 'uninstall_remove_settings' ) ) {
30+
if( $this->get_carbon_plugin_option( 'uninstall_remove_settings' ) ) {
3131
register_uninstall_hook( self::$config->get( 'plugin/identifier' ), array( $this, 'plugin_settings_uninstall' ) );
3232
}
3333

0 commit comments

Comments
 (0)