This repository was archived by the owner on Jun 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcocart-tools.php
164 lines (146 loc) · 3.8 KB
/
cocart-tools.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
<?php
/*
* Plugin Name: CoCart - Tools
* Plugin URI: https://cocart.xyz
* Description: Provides tools to help with testing when developing with CoCart.
* Author: Sébastien Dumont
* Author URI: https://sebastiendumont.com
* Version: 1.0.0
* Text Domain: cocart-tools
* Domain Path: /languages/
*
* WC requires at least: 3.6.0
* WC tested up to: 3.9.3
*
* Copyright: © 2020 Sébastien Dumont, ([email protected])
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
if ( ! class_exists( 'CoCart_Tools' ) ) {
class CoCart_Tools {
/**
* @var CoCart_Tools - the single instance of the class.
*
* @access protected
* @static
*/
protected static $_instance = null;
/**
* Plugin Version
*
* @access public
* @static
*/
public static $version = '1.0.0';
/**
* Required CoCart Version
*
* @access public
* @static
*/
public static $required_cocart = '2.0.0';
/**
* Main CoCart Tools Instance.
*
* Ensures only one instance of CoCart Tools is loaded or can be loaded.
*
* @access public
* @static
* @see CoCart_Tools()
* @return CoCart_Tools - Main instance
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Cloning is forbidden.
*
* @access public
* @return void
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cloning this object is forbidden.', 'cocart-tools' ), self::$version );
} // END __clone()
/**
* Unserializing instances of this class is forbidden.
*
* @access public
* @return void
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'cocart-tools' ), self::$version );
} // END __wakeup()
/**
* Load the plugin.
*
* @access public
*/
public function __construct() {
// Setup Constants.
$this->setup_constants();
// Include required files.
add_action( 'init', array( $this, 'includes' ) );
// Load translation files.
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
} // END __construct()
/**
* Setup Constants
*
* @access public
*/
public function setup_constants() {
$this->define('COCART_TOOLS_VERSION', self::$version);
$this->define('COCART_TOOLS_FILE', __FILE__);
$this->define('COCART_TOOLS_SLUG', 'cocart-tools');
$this->define('COCART_TOOLS_FILE_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
} // END setup_constants()
/**
* Define constant if not already set.
*
* @access private
* @param string $name
* @param string|bool $value
*/
private function define( $name, $value ) {
if ( ! defined( $name ) ) {
define( $name, $value );
}
} // END define()
/**
* Includes REST-API Controllers.
*
* @access public
* @return void
*/
public function includes() {
include_once( COCART_TOOLS_FILE_PATH . '/includes/class-cocart-tools-autoloader.php' );
include_once( COCART_TOOLS_FILE_PATH . '/includes/class-cocart-tools-init.php' );
} // END includes()
/**
* Make the plugin translation ready.
*
* Translations should be added in the WordPress language directory:
* - WP_LANG_DIR/plugins/cocart-tools-LOCALE.mo
*
* @access public
* @return void
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'cocart-tools', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
} // END load_plugin_textdomain()
} // END class
} // END if class exists
/**
* Returns the main instance of CoCart Tools.
*
* @return CoCart Tools
*/
function CoCart_Tools() {
return CoCart_Tools::instance();
}
// Run CoCart Tools
CoCart_Tools();