| 1 |
<?php |
| 2 |
|
| 3 |
namespace Premmerce\Premmerce; |
| 4 |
|
| 5 |
use Premmerce\Premmerce\Admin\Settings; |
| 6 |
use Premmerce\Premmerce\Admin\Admin; |
| 7 |
use Premmerce\Premmerce\Api\WizardApi; |
| 8 |
use Premmerce\SDK\V2\FileManager\FileManager; |
| 9 |
use Premmerce\SDK\V2\Plugin\PluginInterface; |
| 10 |
use Automattic\WooCommerce\Utilities\FeaturesUtil; |
| 11 |
/** |
| 12 |
* Class PremiumPlugin |
| 13 |
* |
| 14 |
* @package Premmerce\Premium |
| 15 |
*/ |
| 16 |
class PremmercePlugin implements PluginInterface { |
| 17 |
const SLUG = 'premmerce'; |
| 18 |
|
| 19 |
const VERSION_OPTION = 'premmerce_version'; |
| 20 |
|
| 21 |
const IS_PREMIUM = true; |
| 22 |
|
| 23 |
/** |
| 24 |
* @var FileManager |
| 25 |
*/ |
| 26 |
private $fileManager; |
| 27 |
|
| 28 |
/** |
| 29 |
* @var string |
| 30 |
*/ |
| 31 |
private $version; |
| 32 |
|
| 33 |
/** |
| 34 |
* PluginManager constructor. |
| 35 |
* |
| 36 |
* @param string $mainFile |
| 37 |
* @param string $version |
| 38 |
*/ |
| 39 |
public function __construct( $mainFile, $version ) { |
| 40 |
$this->version = $version; |
| 41 |
$this->fileManager = new FileManager($mainFile, 'premmerce'); |
| 42 |
$this->registerThemeDirectory(); |
| 43 |
add_action( 'init', array($this, 'loadTextDomain') ); |
| 44 |
add_action( 'before_woocommerce_init', array($this, 'declareHposCompatibility') ); |
| 45 |
} |
| 46 |
|
| 47 |
public function declareHposCompatibility() { |
| 48 |
if ( class_exists( FeaturesUtil::class ) ) { |
| 49 |
$mainFile = $this->fileManager->getMainFile(); |
| 50 |
FeaturesUtil::declare_compatibility( 'custom_order_tables', $mainFile, true ); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Run plugin part |
| 56 |
*/ |
| 57 |
public function run() { |
| 58 |
$container = new Container($this->fileManager); |
| 59 |
if ( is_admin() ) { |
| 60 |
new Admin($container); |
| 61 |
} |
| 62 |
( new Settings() )->addActions(); |
| 63 |
$container->getAddonsManager()->init(); |
| 64 |
} |
| 65 |
|
| 66 |
public function registerThemeDirectory() { |
| 67 |
$theme = wp_get_theme( 'saleszone-premium' ); |
| 68 |
if ( $theme->exists() ) { |
| 69 |
register_theme_directory( $theme->get_template_directory() . '/child-themes' ); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Load plugin translations |
| 75 |
*/ |
| 76 |
public function loadTextDomain() { |
| 77 |
$name = $this->fileManager->getPluginName(); |
| 78 |
load_plugin_textdomain( 'premmerce', false, $name . '/languages/' ); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Fired when the plugin is activated |
| 83 |
*/ |
| 84 |
public function activate() { |
| 85 |
update_option( self::VERSION_OPTION, $this->version, true ); |
| 86 |
update_option( Settings::OPTIONS_KEY, array( |
| 87 |
'transliterate_slugs' => 'on', |
| 88 |
), true ); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Fired when the plugin is deactivated |
| 93 |
*/ |
| 94 |
public function deactivate() { |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Fired during plugin uninstall |
| 99 |
*/ |
| 100 |
public static function uninstall() { |
| 101 |
delete_option( self::VERSION_OPTION ); |
| 102 |
delete_option( WizardApi::KEY_POSITIONS ); |
| 103 |
delete_option( WizardApi::KEY_STATES ); |
| 104 |
delete_option( WizardApi::KEY_SWITCHER_STATE ); |
| 105 |
} |
| 106 |
|
| 107 |
} |
| 108 |
|