-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwc-software-license-manager.php
191 lines (163 loc) · 5.1 KB
/
wc-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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
/**
* Plugin Name: WC Software License Manager
* Plugin URI: https://maddisondesigns.com
* Description: Seamless integration between Woocommerce and Software License Manager
* Version: 2.0.1
* Author: Anthony Hortin
* Author URI: https://maddisondesigns.com
* Text Domain: wc-slm
* Domain Path: /languages
* WC requires at least: 2.5.0
* WC tested up to: 3.2.0
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License version 2, 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.
*
* Copyright 2015-2017 Omid Shamlu - http://wp-master.ir
* Copyright 2017-2018 Anthony Hortin - https://maddisondesigns.com
*
* The following code is a derivative work of the code from the WooCommerce Software License Manager,
* which is licensed GPLv2. This code therefore is also licensed under the terms of the GNU Public License, verison 2.
*
* @author Anthony Hortin - https://maddisondesigns.com
* @copyright Copyright Anthony Hortin
* @license https://www.gnu.org/licenses/gpl-2.0.html
*/
// TODO:
// https://wordpress.org/support/topic/modifying-for-variable-products
// Add option to recreate manual linense in order edit page
// Add license columns in order table lists
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) {
exit;
}
if ( !class_exists( 'WC_SLM' ) ) {
class WC_SLM {
// WC_SLM $instance The one true WC_SLM
private static $instance;
/**
* Get active instance
*
* @access public
* @since 1.0.0
* @return object self::$instance The one true WC_SLM
*/
public static function instance() {
if (!self::$instance) {
self::$instance = new WC_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( 'WC_SLM_VER', '2.0.0' );
// Plugin path
define( 'WC_SLM_DIR', plugin_dir_path(__FILE__) );
// Plugin URL
define( 'WC_SLM_URL', plugin_dir_url(__FILE__) );
// SLM Credentials
$api_url = trim( get_option( 'wc_slm_api_url', '' ) );
$api_url = rtrim( $api_url, '/' );
if( ( strpos( $api_url, 'http://' ) === false ) && ( strpos( $api_url, 'https://' ) === false ) ) {
$api_url = 'http://' . $api_url;
}
// Software License Manager API URL
define( 'WC_SLM_API_URL', $api_url );
// Secret Key for Creation
define( 'WC_SLM_API_SECRET', get_option( 'wc_slm_api_secret' ) );
// Secret Key for Verification
if ( '' != get_option( 'wc_slm_api_secret_verify', '' ) ) {
define( 'WC_SLM_API_SECRET_VERFIY', get_option( 'wc_slm_api_secret_verify' ) );
}
// Enable Debug Logging
if ( 'yes' === get_option( 'wc_slm_debug_logging', false ) ) {
define( 'WC_SLM_DEBUG_LOGGING', true );
}
}
/**
* Include necessary files
*
* @access private
* @since 1.0.0
* @return void
*/
private function includes() {
// Get out if WC is not active
if ( !function_exists( 'WC' ) ) {
return;
}
// Include files and scripts
require_once WC_SLM_DIR . 'includes/helper.php';
if ( is_admin() ) {
require_once WC_SLM_DIR . 'includes/meta-boxes.php';
require_once WC_SLM_DIR . 'includes/settings.php';
}
require_once WC_SLM_DIR . 'includes/emails.php';
require_once WC_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( 'wc-slm', false, 'wc-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 WC_SLM
* instance to functions everywhere
*
* @since 1.0.0
* @return \WC_SLM The one true WC_SLM
*/
function WC_SLM_load() {
return WC_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( 'WC_SLM', 'activation' ) );
register_uninstall_hook( __FILE__, array( 'WC_SLM', 'uninstall' ) );
add_action( 'plugins_loaded', 'WC_SLM_load' );
}