diff --git a/simpleshop-cz.php b/simpleshop-cz.php index 4a8c95a..ca27bad 100644 --- a/simpleshop-cz.php +++ b/simpleshop-cz.php @@ -21,12 +21,11 @@ require_once __DIR__ . '/vendor/autoload.php'; -define( 'SIMPLESHOP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); -define( 'SIMPLESHOP_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'SIMPLESHOP_PLUGIN_VERSION', 'dev-master' ); define( 'SIMPLESHOP_PREFIX', '_ssc_' ); /** * Start plugin */ +SimpleShop::$pluginMainFile = __FILE__; SimpleShop::getInstance(); diff --git a/src/Admin.php b/src/Admin.php index d1ce6d5..4cd6028 100644 --- a/src/Admin.php +++ b/src/Admin.php @@ -16,10 +16,20 @@ class Admin { * @var Plugin */ private $loader; + /** + * @var string + */ + private $pluginDirUrl; + /** + * @param Plugin $loader + * @param string $pluginMainFile + */ public function __construct(Plugin $loader) { $this->loader = $loader; + $this->pluginDirUrl = plugin_dir_url($loader->get_plugin_main_file()); + add_action( 'admin_menu', [ $this, 'add_settings_page' ] ); add_filter( 'manage_edit-ssc_group_columns', [ $this, 'ssc_group_columns' ] ); add_action( 'manage_ssc_group_posts_custom_column', [ $this, 'ssc_group_column_content' ], 10, 2 ); @@ -122,7 +132,7 @@ public function tiny_mce_new_buttons() { * @return mixed */ public function tiny_mce_add_buttons( $plugins ) { - $plugins['ssctinymceplugin'] = SIMPLESHOP_PLUGIN_URL . 'js/tiny-mce/tiny-mce.js'; + $plugins['ssctinymceplugin'] = $this->pluginDirUrl . 'js/tiny-mce/tiny-mce.js'; return $plugins; } @@ -192,7 +202,7 @@ public function add_settings_page() { 'manage_options', 'simple_shop_settings', [ $this, 'render_settings_page' ], - SIMPLESHOP_PLUGIN_URL . '/img/white_logo.png', + $this->pluginDirUrl . '/img/white_logo.png', 99 ); } @@ -230,7 +240,7 @@ public function ssc_group_column_content( $column, $post_id ) { * Enqueue admin scripts */ public function enqueue_admin_scripts() { - wp_enqueue_style( 'ssc', SIMPLESHOP_PLUGIN_URL . 'css/ssc.css' ); + wp_enqueue_style( 'ssc', $this->pluginDirUrl . 'css/ssc.css' ); wp_register_style( 'jquery-ui', 'https://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css' ); wp_enqueue_style( 'jquery-ui' ); } diff --git a/src/Plugin.php b/src/Plugin.php index 3658773..a9e33b9 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -28,7 +28,17 @@ class Plugin { */ private $access; - public function __construct() { + /** + * @var string + */ + private $pluginMainFile; + + /** + * @param string $mainFile Filename of main plugin path. Used for native WP functions + */ + public function __construct( $mainFile ) { + $this->pluginMainFile = $mainFile; + $this->init(); $this->init_i18n(); @@ -36,7 +46,7 @@ public function __construct() { $this->email = $this->load_email(); add_action( 'tgmpa_register', [ $this, 'register_required_plugins' ] ); - register_activation_hook( __FILE__, [ $this, 'ssc_activation_hook' ] ); + register_activation_hook( plugin_dir_path( $this->pluginMainFile ), [ $this, 'ssc_activation_hook' ] ); } private function init() { @@ -150,7 +160,11 @@ public function init_i18n() { } public function load_textdomain_i18n() { - $plugin_rel_path = str_replace( WP_PLUGIN_DIR . '/', '', SIMPLESHOP_PLUGIN_DIR . 'languages/' ); + $plugin_rel_path = str_replace( WP_PLUGIN_DIR . '/', '', plugin_dir_path( $this->pluginMainFile ) . 'languages/' ); load_plugin_textdomain( 'simpleshop-cz', false, $plugin_rel_path ); } + + public function get_plugin_main_file() { + return $this->pluginMainFile; + } } diff --git a/src/SimpleShop.php b/src/SimpleShop.php index 19e74b7..c39242d 100644 --- a/src/SimpleShop.php +++ b/src/SimpleShop.php @@ -9,6 +9,11 @@ namespace Redbit\SimpleShop\WpPlugin; class SimpleShop { + /** + * @var string + */ + public static $pluginMainFile = __DIR__ . '/../simpleshop-cz.php'; + /** * @var Plugin|null */ @@ -29,6 +34,6 @@ public static function getInstance() { * @return Plugin */ protected static function factory() { - return new Plugin(); + return new Plugin(self::$pluginMainFile); } }