-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
edd-software-license-manager.php
174 lines (145 loc) · 4.9 KB
/
edd-software-license-manager.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* Plugin Name: EDD Software License Manager
* Plugin URI: https://coder.flowdee.de/edd-software-license-manager/
* Description: Seamless integration between Easy Digital Downloads and Software License Manager.
* Version: 1.0.1
* Author: flowdee
* Author URI: http://flowdee.de
* Text Domain: edd-slm
* Domain Path: /languages
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License version 3, as published by the Free Software Foundation. You may NOT assume
* that you can use any other version of the GPL.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @author flowdee <[email protected]>
* @copyright Copyright (c) flowdee
* @license http://www.gnu.org/licenses/gpl-3.0.html
*/
// Exit if accessed directly
if( !defined( 'ABSPATH' ) ) {
exit;
}
if( !class_exists( 'EDD_SLM' ) ) {
/**
* Main EDD_SLM class
*
* @since 1.0.0
*/
class EDD_SLM {
/**
* @var EDD_SLM $instance The one true EDD_SLM
* @since 1.0.0
*/
private static $instance;
/**
* Get active instance
*
* @access public
* @since 1.0.0
* @return object self::$instance The one true EDD_SLM
*/
public static function instance() {
if( !self::$instance ) {
self::$instance = new EDD_SLM();
self::$instance->setup_constants();
self::$instance->includes();
self::$instance->load_textdomain();
}
return self::$instance;
}
/**
* Setup plugin constants
*
* @access private
* @since 1.0.0
* @return void
*/
private function setup_constants() {
// Plugin version
define( 'EDD_SLM_VER', '1.0.0' );
// Plugin path
define( 'EDD_SLM_DIR', plugin_dir_path( __FILE__ ) );
// Plugin URL
define( 'EDD_SLM_URL', plugin_dir_url( __FILE__ ) );
// SLM Credentials
$api_url = rtrim(edd_get_option( 'edd_slm_api_url' ), '/');
define( 'EDD_SLM_API_URL', $api_url );
define( 'EDD_SLM_API_SECRET', edd_get_option( 'edd_slm_api_secret' ) );
}
/**
* Include necessary files
*
* @access private
* @since 1.0.0
* @return void
*/
private function includes() {
// Get out if EDD is not active
if( ! function_exists( 'EDD' ) ) {
return;
}
// Include files and scripts
require_once EDD_SLM_DIR . 'includes/helper.php';
if ( is_admin() ) {
require_once EDD_SLM_DIR . 'includes/meta-boxes.php';
require_once EDD_SLM_DIR . 'includes/settings.php';
}
require_once EDD_SLM_DIR . 'includes/emails.php';
require_once EDD_SLM_DIR . 'includes/purchase.php';
}
/**
* Internationalization
*
* @access public
* @since 1.0.0
* @return void
*/
public function load_textdomain() {
// Load the default language files
load_plugin_textdomain( 'edd-slm', false, 'edd-software-license-manager/languages' );
}
/*
* Activation function fires when the plugin is activated.
*
* @since 1.0.0
* @access public
* @return void
*/
public static function activation() {
// nothing
}
/*
* Uninstall function fires when the plugin is being uninstalled.
*
* @since 1.0.0
* @access public
* @return void
*/
public static function uninstall() {
// nothing
}
}
/**
* The main function responsible for returning the one true EDD_SLM
* instance to functions everywhere
*
* @since 1.0.0
* @return \EDD_SLM The one true EDD_SLM
*/
function EDD_SLM_load() {
return EDD_SLM::instance();
}
/**
* The activation & uninstall hooks are called outside of the singleton because WordPress doesn't
* register the call from within the class hence, needs to be called outside and the
* function also needs to be static.
*/
register_activation_hook( __FILE__, array( 'EDD_SLM', 'activation' ) );
register_uninstall_hook( __FILE__, array( 'EDD_SLM', 'uninstall') );
add_action( 'plugins_loaded', 'EDD_SLM_load' );
} // End if class_exists check