Skip to content

Commit 7f7cace

Browse files
committed
Added PHLAK/Config
1 parent 1ac2905 commit 7f7cace

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

app/Plugin.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace VendorName\MyPlugin;
33
use Carbon_Fields\Container;
44
use Carbon_Fields\Field;
5+
use Config;
56

67
class Plugin {
78

@@ -10,9 +11,11 @@ class Plugin {
1011

1112
function __construct( $_settings ) {
1213

13-
// Set text domain and option prefix
14+
// Initialize plugin settings
15+
$plugin_config = new Config\Config( $_settings['path'] . 'plugin.json' );
1416
self::$textdomain = $_settings['data']['TextDomain'];
15-
self::$settings = $_settings;
17+
self::$settings = array_merge( $_settings, $plugin_config->get() );
18+
//var_dump(self::$settings); exit;
1619

1720
// Verify dependecies and load plugin logic
1821
register_activation_hook( self::$settings['plugin_file'], array( $this, 'activate' ) );
@@ -89,8 +92,8 @@ public function load_plugin() {
8992
*/
9093
private function verify_dependencies( $deps = true, $args = array() ) {
9194

92-
if( is_bool( $deps ) && $deps ) $deps = self::$settings['deps'];
93-
if( !is_array( $deps ) ) $deps = array( $deps => self::$settings['deps'][$deps] );
95+
if( is_bool( $deps ) && $deps ) $deps = self::$settings['dependencies'];
96+
if( !is_array( $deps ) ) $deps = array( $deps => self::$settings['dependencies'][$deps] );
9497

9598
$args = Utils::set_default_atts( array(
9699
'echo' => true,
@@ -106,7 +109,7 @@ private function verify_dependencies( $deps = true, $args = array() ) {
106109
case 'php':
107110

108111
if( version_compare( phpversion(), $version, '<' ) ) {
109-
$notices[] = __( 'This plugin is not supported on versions of PHP below', self::$textdomain ) . ' ' . self::$settings['deps']['php'] . '.' ;
112+
$notices[] = __( 'This plugin is not supported on versions of PHP below', self::$textdomain ) . ' ' . self::$settings['dependencies']['php'] . '.' ;
110113
}
111114
break;
112115

@@ -116,7 +119,7 @@ private function verify_dependencies( $deps = true, $args = array() ) {
116119
if( !$args['activate'] && !defined('\\Carbon_Fields\\VERSION') ) {
117120
$notices[] = __( 'An unknown error occurred while trying to load the Carbon Fields framework.', self::$textdomain );
118121
} else if ( defined('\\Carbon_Fields\\VERSION') && version_compare( \Carbon_Fields\VERSION, $version, '<' ) ) {
119-
$notices[] = __( 'An outdated version of Carbon Fields has been detected:', self::$textdomain ) . ' ' . \Carbon_Fields\VERSION . ' (&gt;= '.self::$settings['deps']['carbon_fields'] . ' ' . __( 'required', self::$textdomain ) . ').' . ' <strong>' . self::$settings['data']['Name'] . '</strong> ' . __( 'deactivated.', self::$textdomain ) ;
122+
$notices[] = __( 'An outdated version of Carbon Fields has been detected:', self::$textdomain ) . ' ' . \Carbon_Fields\VERSION . ' (&gt;= '.self::$settings['dependencies']['carbon_fields'] . ' ' . __( 'required', self::$textdomain ) . ').' . ' <strong>' . self::$settings['data']['Name'] . '</strong> ' . __( 'deactivated.', self::$textdomain ) ;
120123
}
121124
break;
122125

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"require": {
4343
"php": ">=5.4.0",
4444
"htmlburger/carbon-fields": "^2.0.0",
45+
"PHLAK/Config": "^2.0.0",
4546
"jjgrainger/posttypes": "dev-master",
4647
"hgoebl/mobile-detect": ">=1.3.0",
4748
"composer/installers": "~1.3.0"

plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"prefix": "myplugin_",
33
"object_cache": {
44
"group": "my_plugin_cache",
5-
"expire": 72
5+
"expire_hours": 72
66
},
77
"dependencies": {
88
"php": "5.4.0",
99
"carbon_fields": "2.0"
10-
},
10+
}
1111
}

wordpress-base-plugin.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@
3737
// Initialize plugin - Change to use your own namespace
3838
new \VendorName\MyPlugin\Plugin(array(
3939
'data' => get_plugin_data( __FILE__ ),
40-
'path' => realpath( plugin_dir_path( __FILE__ ) ) . DIRECTORY_SEPARATOR,
40+
'path' => trailingslashit( realpath( plugin_dir_path( __FILE__ ) ) ),
4141
'url' => plugin_dir_url( __FILE__ ),
42-
'object_cache_group' => 'my_plugin_cache',
43-
'object_cache_expire' => 72, // In hours
44-
'deps' => array( 'php' => '5.4.0', 'carbon_fields' => '2.0.0' ),
45-
'plugin_file' => plugin_basename( __FILE__ ),
46-
'prefix' => 'myplugin_' // Change to your own unique field prefix
42+
'plugin_file' => plugin_basename( __FILE__ )
4743
));

0 commit comments

Comments
 (0)