-
Notifications
You must be signed in to change notification settings - Fork 4
/
woocommerce-recordstore.php
96 lines (71 loc) · 2.47 KB
/
woocommerce-recordstore.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Plugin Name: WooCommerce Record Store
* Plugin URI: http://www.woocommerce-recordstore.com
* Description: A plugin to manage Records in WooCommerce
* Author: Aaltomeri
* Author URI: http://aaltomeri.net
* Text Domain: woocommerce-recordstore
* Domain Path: /languages
* Version: 0.1.0
*
* @package Woocommerce_Recordstore
*/
namespace WC_Discogs;
require __DIR__ . '/vendor/autoload.php';
/**
* Define plugin constants.
*/
define( __NAMESPACE__ . '\VERSION', '0.1.0' );
define( __NAMESPACE__ . '\PLUGIN_NAME', 'woocommerce-discogs' );
define( __NAMESPACE__ . '\PLUGIN_FILE', plugin_basename( __FILE__ ) );
define( __NAMESPACE__ . '\PLUGIN_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) );
define( __NAMESPACE__ . '\PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
// prevent direct access to file
defined( 'ABSPATH' ) or exit;
class Main {
/**
* @var options
*/
protected $options;
public static function register() {
// get ENV vars from specific .env file that we put above the webroot
$root = realpath(ABSPATH . '/../../');
$dotenv = new \Dotenv\Dotenv($root, 'wc-recordstore.env');
if (file_exists($root . '/wc-recordstore.env')) {
$dotenv->load();
}
else {
error_log('WC Recordstore requires that you have a wc-recordstore.env file in the directory above the webroot. The plugin has been de-activated.');
add_action('admin_notices', [ '\WC_Discogs\Main', 'noCredentialsNotice' ] );
add_action('admin_init', function() { deactivate_plugins(\WC_Discogs\PLUGIN_FILE); });
return false;
}
$plugin = new self();
add_action( 'plugins_loaded', array( $plugin, 'run' ) );
register_activation_hook( __FILE__, [ $plugin, 'activate'] );
register_deactivation_hook( __FILE__, [ $plugin, 'deactivate'] );
register_uninstall_hook( __FILE__, [ 'WC_Discogs::uninstall' ]);
}
public function __construct() {}
public function run() {
if( is_admin() ) {
new Admin\Settings();
new Admin\Product();
}
new Setup();
}
public function activate() {
}
public function deactivate() {}
static public function uninstall() {}
public static function noCredentialsNotice() {
$message = __('WC Recordstore requires that you have a wc-recordstore.env file in the directory <em>above the webroot</em>. <strong>The plugin has been de-activated.</strong>');
echo <<<EOT
<div class="notice notice-error">
<p>{$message}</p>
</div>
EOT;
}
}
Main::register();