-
Notifications
You must be signed in to change notification settings - Fork 1
/
exchange-addon-terms-of-service.php
158 lines (128 loc) · 3.48 KB
/
exchange-addon-terms-of-service.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
<?php
/**
* Main plugin file.
*
* @author Iron Bound Designs
* @since 1.0
*/
namespace ITETOS;
/**
* Class Plugin
* @package ITETOS
*/
class Plugin {
/**
* Plugin Version
*/
const VERSION = '1.0.2';
/**
* Translation SLUG
*/
const SLUG = 'ibd-exchange-addon-tos';
/**
* Exchange add-on slug.
*/
const ADD_ON = 'terms-of-service';
/**
* @var string
*/
static $dir;
/**
* @var string
*/
static $url;
/**
* Constructor.
*/
public function __construct() {
self::$dir = plugin_dir_path( __FILE__ );
self::$url = plugin_dir_url( __FILE__ );
register_activation_hook( __FILE__, array( $this, 'activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'scripts_and_styles' ), 5 );
add_action( 'wp_enqueue_scripts', array( $this, 'scripts_and_styles' ), 5 );
self::autoload();
}
/**
* Run the upgrade routine if necessary.
*/
public static function upgrade() {
$current_version = get_option( 'itetos_version', '1.0' );
if ( $current_version != self::VERSION ) {
/**
* Runs when the version upgrades.
*
* @param $current_version
* @param $new_version
*/
do_action( 'itetos_upgrade', self::VERSION, $current_version );
update_option( 'itetos_version', self::VERSION );
}
}
/**
* The activation hook.
*/
public function activate() {
do_action( 'itetos_activate' );
}
/**
* The deactivation hook.
*/
public function deactivate() {
}
/**
* Register admin scripts.
*
* @since 1.0
*/
public function scripts_and_styles() {
wp_register_script( 'itetos-checkout', self::$url . 'assets/js/checkout.js', array( 'jquery' ), self::VERSION );
wp_register_script( 'itetos-sw', self::$url . 'assets/js/super-widget.js', array( 'jquery' ), self::VERSION );
wp_register_style( 'itetos-checkout', self::$url . 'assets/css/checkout.css', array(), self::VERSION );
wp_register_style( 'itetos-sw', self::$url . 'assets/css/super-widget.css', array(), self::VERSION );
}
/**
* Autoloader.
*
* @since 1.0
*/
public static function autoload() {
require_once( self::$dir . 'autoloader.php' );
$autoloader = new Psr4AutoloaderClass();
$autoloader->addNamespace( 'ITETOS', self::$dir . 'lib' );
$autoloader->register();
}
}
new Plugin();
/**
* This registers our add-on
*
* @since 1.0
*/
function register_addon() {
$options = array(
'name' => __( 'Terms of Service', Plugin::SLUG ),
'description' => __( 'Have your customers agree to your Terms of Service when purchasing your products.', Plugin::SLUG ),
'author' => 'Iron Bound Designs',
'author_url' => 'http://www.ironbounddesigns.com',
'file' => dirname( __FILE__ ) . '/init.php',
'icon' => Plugin::$url . '/assets/img/icon-50.png',
'category' => 'product-feature',
'settings-callback' => array( 'ITETOS\Settings', 'display' ),
'basename' => plugin_basename( __FILE__ ),
'labels' => array(
'singular_name' => __( 'Terms of Service', Plugin::SLUG ),
)
);
it_exchange_register_addon( 'terms-of-service', $options );
}
add_action( 'it_exchange_register_addons', __NAMESPACE__ . '\\register_addon' );
/**
* Loads the translation data for WordPress
*
* @since 1.0
*/
function set_textdomain() {
load_plugin_textdomain( Plugin::SLUG, false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\\set_textdomain' );