-
Notifications
You must be signed in to change notification settings - Fork 0
/
edd-pricing-tables.php
212 lines (179 loc) · 5.2 KB
/
edd-pricing-tables.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/*
Plugin Name: Easy Digital Downloads - Pricing Tables
Plugin URI: https://easydigitaldownloads.com/downloads/pricing-tables/
Description: Easily create pricing tables for your downloads
Version: 1.0
Author: Easy Digital Downloads
Author URI: https://easydigitaldownloads.com/
License: GPL-2.0+
License URI: http://www.opensource.org/licenses/gpl-license.php
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'EDD_Pricing_Tables' ) ) {
class EDD_Pricing_Tables {
/**
* Holds the instance
*
* Ensures that only one instance exists in memory at any one
* time and it also prevents needing to define globals all over the place.
*
* TL;DR This is a static property property that holds the singleton instance.
*
* @var object
* @static
* @since 1.0
*/
private static $instance;
/**
* Plugin Version
*/
private $version = '1.0';
/**
* Plugin Title
*/
public $title = 'EDD Pricing Tables';
/**
* The frontend instance variable.
*
* @access public
* @since 1.0
* @var object
*/
public $frontend;
/**
* Main Instance
*
* Ensures that only one instance exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @since 1.0
*
*/
public static function get_instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof EDD_Pricing_Tables ) ) {
self::$instance = new EDD_Pricing_Tables;
self::$instance->setup_constants();
self::$instance->includes();
self::$instance->setup_actions();
self::$instance->load_textdomain();
self::$instance->frontend = new EDD_Pricing_Tables_Frontend;
}
return self::$instance;
}
/**
* Constructor Function
*
* @since 1.0
* @access private
*/
private function __construct() {
self::$instance = $this;
}
/**
* Setup plugin constants
*
* @access private
* @since 1.0
*
* @return void
*/
private function setup_constants() {
// Plugin version
if ( ! defined( 'EDD_PT_VERSION' ) ) {
define( 'EDD_PT_VERSION', $this->version );
}
// Plugin Folder Path
if ( ! defined( 'EDD_PT_PLUGIN_DIR' ) ) {
define( 'EDD_PT_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL
if ( ! defined( 'EDD_PT_PLUGIN_URL' ) ) {
define( 'EDD_PT_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
}
/**
* Setup the default hooks and actions
*
* @since 1.0
*
* @return void
*/
private function setup_actions() {
do_action( 'edd_pricing_tables_setup_actions' );
}
/**
* Loads the plugin language files
*
* @access public
* @since 1.0.4
* @return void
*/
public function load_textdomain() {
// Set filter for plugin's languages directory
$lang_dir = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
$lang_dir = apply_filters( 'edd_pricing_tables_languages_directory', $lang_dir );
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), 'edd-pricing-tables' );
$mofile = sprintf( '%1$s-%2$s.mo', 'edd-pricing-tables', $locale );
// Setup paths to current locale file
$mofile_local = $lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/edd-pricing-tables/' . $mofile;
if ( file_exists( $mofile_global ) ) {
// Look in global /wp-content/languages/edd-pricing-tables/ folder
load_textdomain( 'edd-pricing-tables', $mofile_global );
} elseif ( file_exists( $mofile_local ) ) {
// Look in local /wp-content/plugins/edd-pricing-tables/languages/ folder
load_textdomain( 'edd-pricing-tables', $mofile_local );
} else {
// Load the default language files
load_plugin_textdomain( 'edd-pricing-tables', false, $lang_dir );
}
}
/**
* Include required files.
*
* @since 1.0
*
* @return void
*/
private function includes() {
require_once( EDD_PT_PLUGIN_DIR . 'includes/class-shortcodes.php' );
require_once( EDD_PT_PLUGIN_DIR . 'includes/class-frontend.php' );
require_once( EDD_PT_PLUGIN_DIR . 'includes/scripts.php' );
require_once( EDD_PT_PLUGIN_DIR . 'includes/functions.php' );
if ( is_admin() ) {
require_once( EDD_PT_PLUGIN_DIR . 'includes/class-admin.php' );
}
}
}
/**
* Loads a single instance
*
* This follows the PHP singleton design pattern.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* @example <?php $edd_pricing_tables = edd_pricing_tables(); ?>
*
* @since 1.0
*
* @see EDD_Pricing_Tables::get_instance()
*
* @return object Returns an instance of the EDD_Pricing_Tables class
*/
function edd_pricing_tables() {
if ( ! class_exists( 'Easy_Digital_Downloads' ) ) {
if ( ! class_exists( 'EDD_Extension_Activation' ) ) {
require_once 'includes/class-activation.php';
}
$activation = new EDD_Extension_Activation( plugin_dir_path( __FILE__ ), basename( __FILE__ ) );
$activation = $activation->run();
} else {
return EDD_Pricing_Tables::get_instance();
}
}
add_action( 'plugins_loaded', 'edd_pricing_tables', apply_filters( 'edd_pricing_tables_action_priority', 10 ) );
}