-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlicenser.php
137 lines (114 loc) · 2.9 KB
/
licenser.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* Plugin Name: Licenser - Self-Hosted License Manager
* Plugin URI: https://github.com/akshuvo/licenser
* Description: A self-hosted license manager for your digital products.
* Author: AddonMaster
* Author URI: https://addonmaster.com
* Version: 1.0.8
* Text Domain: licenser
* Domain Path: /lang
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
// Autoload
require_once( dirname( __FILE__ ) . '/vendor/autoload.php' );
/**
* The main plugin class
*/
final class Licenser {
/**
* Plugin version
*
* @var string
*/
const version = '1.0.1';
/**
* Class construcotr
*/
private function __construct() {
$this->define_constants();
// add_action( 'muplugins_loaded', [ $this, 'muplugins_loaded' ] );
register_activation_hook( __FILE__, [ $this, 'activate' ] );
add_action( 'plugins_loaded', [ $this, 'init_plugin' ] );
}
/**
* Initializes a singleton instance
*
* @return \Licenser
*/
public static function init() {
static $instance = false;
if ( ! $instance ) {
$instance = new self();
}
return $instance;
}
/**
* Define the required plugin constants
*
* @return void
*/
public function define_constants() {
define( 'LICENSER_VERSION', self::version );
define( 'LICENSER_FILE', __FILE__ );
define( 'LICENSER_PATH', __DIR__ );
define( 'LICENSER_URL', plugins_url( '', LICENSER_FILE ) );
define( 'LICENSER_ASSETS', LICENSER_URL . '/assets' );
}
/**
* Initialize the plugin
*
* @return void
*/
public function init_plugin() {
// new Licenser\Assets();
// if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
// new Licenser\Ajax();
// }
if ( is_admin() ) {
new Licenser\Admin();
} else {
// new Licenser\Frontend();
}
// API
new Licenser\Api();
// Addons
$addons = Licenser\Controllers\Addons::instance();
}
/**
* Do stuff upon plugin activation
*
* @return void
*/
public function activate() {
$installer = new Licenser\Installer();
$installer->run();
}
}
// Initialize the plugin
function licenser() {
// Access the global $wpdb instance
global $wpdb;
/**
* Set the table names
*
* @uses $wpdb->licenser_products
*/
foreach ( [
'products',
'product_releases',
'license_packages',
'licenses',
'license_meta',
'license_domains',
] as $table ) {
$wpdb->__set( 'licenser_' . $table, $wpdb->prefix . 'licenser_' . $table );
}
// Initialize the plugin
return Licenser::init();
}
// run the plugin
licenser();