Skip to content

Commit

Permalink
Fix DI, remove unwanted plugin-wide Constants
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubboucek committed Oct 13, 2019
1 parent 7d366d0 commit 479d063
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions simpleshop-cz.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
/**
* Start plugin
*/
SimpleShop::$pluginMainFile = __FILE__;
SimpleShop::getInstance();
8 changes: 6 additions & 2 deletions src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ class Admin {
*/
private $pluginDirUrl;

public function __construct(Plugin $loader) {
/**
* @param Plugin $loader
* @param string $pluginMainFile
*/
public function __construct(Plugin $loader, $pluginMainFile) {
$this->loader = $loader;

$this->pluginDirUrl = plugin_dir_url(__DIR__ . '/../');
$this->pluginDirUrl = plugin_dir_url($pluginMainFile);

add_action( 'admin_menu', [ $this, 'add_settings_page' ] );
add_filter( 'manage_edit-ssc_group_columns', [ $this, 'ssc_group_columns' ] );
Expand Down
17 changes: 10 additions & 7 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,29 @@ class Plugin {
/**
* @var string
*/
private $pluginDirPath;
private $pluginMainFile;

/**
* @param string $mainFile Filename of main plugin path. Used for native WP functions
*/
public function __construct( $mainFile ) {
$this->pluginMainFile = $mainFile;

public function __construct() {
$this->init();
$this->init_i18n();

$this->pluginDirPath = plugin_dir_path( __DIR__ . '/../' );

$this->secure_key = $this->load_api_key();
$this->email = $this->load_email();

add_action( 'tgmpa_register', [ $this, 'register_required_plugins' ] );
register_activation_hook( $this->pluginDirPath, [ $this, 'ssc_activation_hook' ] );
register_activation_hook( plugin_dir_path( $this->pluginMainFile ), [ $this, 'ssc_activation_hook' ] );
}

private function init() {
$this->settings = new Settings( $this );
$this->access = new Access( $this->settings );

new Admin( $this );
new Admin( $this, $this->pluginMainFile );
new Rest( $this );
new Cron( $this );
new Metaboxes( $this );
Expand Down Expand Up @@ -157,7 +160,7 @@ public function init_i18n() {
}

public function load_textdomain_i18n() {
$plugin_rel_path = str_replace( WP_PLUGIN_DIR . '/', '', $this->pluginDirPath . 'languages/' );
$plugin_rel_path = str_replace( WP_PLUGIN_DIR . '/', '', plugin_dir_path( $this->pluginMainFile ) . 'languages/' );
load_plugin_textdomain( 'simpleshop-cz', false, $plugin_rel_path );
}
}
7 changes: 6 additions & 1 deletion src/SimpleShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
namespace Redbit\SimpleShop\WpPlugin;

class SimpleShop {
/**
* @var string
*/
public static $pluginMainFile = __DIR__ . '/../simpleshop-cz.php';

/**
* @var Plugin[]
*/
Expand All @@ -31,6 +36,6 @@ public static function getInstance($instanceId = 'default') {
* @return Plugin
*/
protected static function factory() {
return new Plugin();
return new Plugin(self::$pluginMainFile);
}
}

0 comments on commit 479d063

Please sign in to comment.