-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflash-toolkit.php
241 lines (211 loc) · 6.07 KB
/
flash-toolkit.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
/**
* Plugin Name: Flash Toolkit
* Plugin URI: http://themegrill.com/theme/flash
* Description: Flash Toolkit is a companion for Flash WordPress theme by ThemeGrill
* Version: 1.2.5
* Author: ThemeGrill
* Author URI: http://themegrill.com
* License: GPLv3 or later
* Text Domain: flash-toolkit
* Domain Path: /i18n/languages/
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'FlashToolkit' ) ) :
/**
* FlashToolkit main class.
*
* @class FlashToolkit
* @version 1.0.0
*/
final class FlashToolkit {
/**
* Plugin version.
*
* @var string
*/
public $version = '1.2.5';
/**
* Instance of this class.
*
* @var object
*/
protected static $_instance = null;
/**
* Return an instance of this class.
*
* @return object A single instance of this class.
*/
public static function instance() {
// If the single instance hasn't been set, set it now.
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Cloning is forbidden.
*
* @since 1.0
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'flash-toolkit' ), '1.0' );
}
/**
* Unserializing instances of this class is forbidden.
*
* @since 1.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'flash-toolkit' ), '1.0' );
}
/**
* FlashToolkit Constructor.
*/
public function __construct() {
$this->define_constants();
$this->includes();
$this->init_hooks();
do_action( 'flash_toolkit_loaded' );
}
/**
* Hook into actions and filters.
*/
private function init_hooks() {
register_activation_hook( __FILE__, array( 'FT_Install', 'install' ) );
register_deactivation_hook( __FILE__, array( 'FT_Install', 'deactivate' ) );
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
add_action( 'admin_notices', array( $this, 'theme_support_missing_notice' ) );
}
/**
* Define FT Constants.
*/
private function define_constants() {
$this->define( 'FT_PLUGIN_FILE', __FILE__ );
$this->define( 'FT_ABSPATH', __DIR__ . '/' );
$this->define( 'FT_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
$this->define( 'FT_VERSION', $this->version );
$this->define( 'FT_TEMPLATE_DEBUG_MODE', false );
}
/**
* Define constant if not already set.
*
* @param string $name
* @param string|bool $value
*/
private function define( $name, $value ) {
if ( ! defined( $name ) ) {
define( $name, $value );
}
}
/**
* What type of request is this?
*
* @param string $type admin or frontend.
*
* @return bool
*/
private function is_request( $type ) {
switch ( $type ) {
case 'admin':
return is_admin();
case 'frontend':
return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
}
}
/**
* Includes.
*/
private function includes() {
include_once FT_ABSPATH . 'includes/functions-flash-core.php';
include_once FT_ABSPATH . 'includes/functions-flash-widget.php';
include_once FT_ABSPATH . 'includes/class-flash-autoloader.php';
include_once FT_ABSPATH . 'includes/class-flash-install.php';
include_once FT_ABSPATH . 'includes/class-flash-ajax.php';
include_once FT_ABSPATH . 'includes/class-flash-inline-style.php';
if ( $this->is_request( 'admin' ) ) {
include_once FT_ABSPATH . 'includes/admin/class-flash-admin.php';
}
if ( is_flash_pro_active() ) {
include_once FT_ABSPATH . 'includes/class-flash-sidebars.php';
}
include_once FT_ABSPATH . 'includes/class-flash-post-types.php'; // Registers post types
}
/**
* Load Localisation files.
*
* Note: the first-loaded translation file overrides any following ones if the same translation is present.
*
* Locales found in:
* - WP_LANG_DIR/flash-toolkit/flash-toolkit-LOCALE.mo
* - WP_LANG_DIR/plugins/flash-toolkit-LOCALE.mo
*/
public function load_plugin_textdomain() {
$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
$locale = apply_filters( 'plugin_locale', $locale, 'flash-toolkit' );
unload_textdomain( 'flash-toolkit' );
load_textdomain( 'flash-toolkit', WP_LANG_DIR . '/flash-toolkit/flash-toolkit-' . $locale . '.mo' );
load_plugin_textdomain( 'flash-toolkit', false, plugin_basename( __DIR__ ) . '/i18n/languages' );
}
/**
* Theme support fallback notice.
*
* @return string
*/
public function theme_support_missing_notice() {
$theme = wp_get_theme();
$parent = $theme->parent();
// Check with ThemeGrill Flash Theme is installed.
if ( ( $theme != 'Flash' ) && ( $theme != 'Flash Pro' ) && ( $parent != 'Flash' ) && ( $parent != 'Flash Pro' ) ) {
echo '<div class="error notice is-dismissible"><p><strong>' . __( 'Flash Toolkit', 'flash-toolkit' ) . '</strong> – ' . sprintf( __( 'This plugin requires %s by ThemeGrill to work.', 'flash-toolkit' ), '<a href="http://www.themegrill.com/themes/flash/" target="_blank">' . __( 'Flash Theme', 'flash-toolkit' ) . '</a>' ) . '</p></div>';
}
}
/**
* Get the plugin url.
*
* @return string
*/
public function plugin_url() {
return untrailingslashit( plugins_url( '/', __FILE__ ) );
}
/**
* Get the plugin path.
*
* @return string
*/
public function plugin_path() {
return untrailingslashit( plugin_dir_path( __FILE__ ) );
}
/**
* Get the template path.
*
* @return string
*/
public function template_path() {
return apply_filters( 'flash_toolkit_template_path', 'flash-toolkit/' );
}
/**
* Get Ajax URL.
*
* @return string
*/
public function ajax_url() {
return admin_url( 'admin-ajax.php', 'relative' );
}
}
endif;
/**
* Main instance of FlashToolkit.
*
* Returns the main instance of FT to prevent the need to use globals.
*
* @return FlashToolkit
* @since 1.0
*/
function FT() {
return FlashToolkit::instance();
}
// Global for backwards compatibility.
$GLOBALS['flashtoolkit'] = FT();