Skip to content

Commit

Permalink
Fixed conflict when multiple instances present
Browse files Browse the repository at this point in the history
  • Loading branch information
dmhendricks committed Oct 2, 2017
1 parent 97d0ea7 commit 5e1698d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions core/PluginTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
*/
class PluginTools extends ToolKit {

protected $plugin_dir;

/**
* Class constructor, runs on object creation.
*
* @param array $values An array of values to inject/enqueue
* @link https://github.com/dmhendricks/wordpress-toolkit/wiki/PluginTools
* @since 0.2.0
*/
public function __construct( ) { }
public function __construct( $plugin_dir = __DIR__ ) {

$this->plugin_dir = $plugin_dir;

}

/**
* Get current plugin properties
Expand All @@ -25,11 +31,11 @@ public function __construct( ) { }
* @return ConfigRegistry object
* @since 0.2.0
*/
public function get_current_plugin_data( $field = null, $type = ConfigRegistry ) {
public function get_current_plugin_data( $type = ConfigRegistry ) {

$plugin_data['slug'] = current( explode( DIRECTORY_SEPARATOR, plugin_basename( __DIR__ ) ) );
$plugin_data['path'] = trailingslashit( str_replace( plugin_basename( __DIR__ ), '', __DIR__ ) . $plugin_data['slug'] );
$plugin_data['url'] = current( explode( $plugin_data['slug'] . '/', plugin_dir_url( __DIR__ ) ) ) . $plugin_data['slug'] . '/';
$plugin_data['slug'] = current( explode( DIRECTORY_SEPARATOR, plugin_basename( $this->plugin_dir ) ) );
$plugin_data['path'] = trailingslashit( str_replace( plugin_basename( $this->plugin_dir ), '', $this->plugin_dir ) . $plugin_data['slug'] );
$plugin_data['url'] = current( explode( $plugin_data['slug'] . '/', plugin_dir_url( $this->plugin_dir ) ) ) . $plugin_data['slug'] . '/';

// Get plugin path/file identifier
foreach( get_plugins() as $key => $plugin ) {
Expand All @@ -43,13 +49,12 @@ public function get_current_plugin_data( $field = null, $type = ConfigRegistry )

}

if( $type == ARRAY_A ) {
return $field ? $plugin_data[ $field ] : $plugin_data;
} else {
if( $type == ConfigRegistry ) {
$plugin_data = new ConfigRegistry( $plugin_data );
return $field ? $plugin_data->get( $field ) : $plugin_data;
}

return $plugin_data;

}

/**
Expand Down

0 comments on commit 5e1698d

Please sign in to comment.