-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsuffice-toolkit.php
More file actions
226 lines (197 loc) · 6.27 KB
/
Copy pathsuffice-toolkit.php
File metadata and controls
226 lines (197 loc) · 6.27 KB
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
<?php
/**
* Plugin Name: Suffice Toolkit
* Plugin URI: https://themegrill.com/themes/suffice
* Description: Suffice Toolkit is a companion for Suffice WordPress theme by ThemeGrill
* Version: 1.1.0
* Author: ThemeGrill
* Author URI: http://themegrill.com
* License: GPLv3 or later
* Text Domain: suffice-toolkit
* Domain Path: /i18n/languages/
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'SufficeToolkit' ) ) :
/**
* SufficeToolkit main class.
*
* @class SufficeToolkit
* @version 1.0.0
*/
final class SufficeToolkit {
/**
* Plugin version.
* @var string
*/
public $version = '1.1.0';
/**
* 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?', 'suffice-toolkit' ), '1.0' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Unserializing instances of this class is forbidden.
* @since 1.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'suffice-toolkit' ), '1.0' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* SufficeToolkit Constructor.
*/
public function __construct() {
$this->define_constants();
$this->includes();
$this->init_hooks();
do_action( 'suffice_toolkit_loaded' );
}
/**
* Hook into actions and filters.
*/
private function init_hooks() {
register_activation_hook( __FILE__, array( 'ST_Install', 'install' ) );
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
add_action( 'admin_notices', array( $this, 'theme_support_missing_notice' ) );
}
/**
* Define ST Constants.
*/
private function define_constants() {
$this->define( 'ST_PLUGIN_FILE', __FILE__ );
$this->define( 'ST_ABSPATH', __DIR__ . '/' );
$this->define( 'ST_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
$this->define( 'ST_VERSION', $this->version );
$this->define( 'ST_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 ); //phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.VariableConstantNameFound
}
}
/**
* 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 ST_ABSPATH . 'includes/functions-suffice-core.php';
include_once ST_ABSPATH . 'includes/functions-suffice-widget.php';
include_once ST_ABSPATH . 'includes/class-suffice-autoloader.php';
include_once ST_ABSPATH . 'includes/class-suffice-install.php';
include_once ST_ABSPATH . 'includes/class-suffice-ajax.php';
include_once ST_ABSPATH . 'includes/class-suffice-inline-style.php';
if ( $this->is_request( 'admin' ) ) {
include_once ST_ABSPATH . 'includes/admin/class-suffice-admin.php';
}
if ( is_suffice_pro_active() ) {
include_once ST_ABSPATH . 'includes/class-suffice-sidebars.php';
}
include_once ST_ABSPATH . 'includes/class-suffice-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/suffice-toolkit/suffice-toolkit-LOCALE.mo
* - WP_LANG_DIR/plugins/suffice-toolkit-LOCALE.mo
*/
public function load_plugin_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'suffice-toolkit' ); //phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
load_textdomain( 'suffice-toolkit', WP_LANG_DIR . '/suffice-toolkit/suffice-toolkit-' . $locale . '.mo' );
load_plugin_textdomain( 'suffice-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 Suffice Theme is installed.
if ( ( $theme != 'Suffice' ) && ( $theme != 'Suffice Pro' ) && ( $parent != 'Suffice' ) && ( $parent != 'Suffice Pro' ) ) {
// echo '<div class="error notice is-dismissible"><p><strong>' . __( 'Suffice Toolkit', 'suffice-toolkit' ) . '</strong> – ' . sprintf( __( 'This plugin requires %s by ThemeGrill to work.', 'suffice-toolkit' ), '<a href="http://www.themegrill.com/themes/suffice/" target="_blank">' . __( 'Suffice Theme', 'suffice-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( 'suffice_toolkit_template_path', 'suffice-toolkit/' );
}
/**
* Get Ajax URL.
* @return string
*/
public function ajax_url() {
return admin_url( 'admin-ajax.php', 'relative' );
}
}
endif;
/**
* Main instance of SufficeToolkit.
*
* Returns the main instance of ST to prevent the need to use globals.
*
* @since 1.0
* @return SufficeToolkit
*/
function ST() { //phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
return SufficeToolkit::instance();
}
// Global for backwards compatibility.
$GLOBALS['sufficetoolkit'] = ST();