| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Suffice Toolkit |
| 4 |
* Plugin URI: https://themegrill.com/themes/suffice |
| 5 |
* Description: Suffice Toolkit is a companion for Suffice WordPress theme by ThemeGrill |
| 6 |
* Version: 1.1.0 |
| 7 |
* Author: ThemeGrill |
| 8 |
* Author URI: http://themegrill.com |
| 9 |
* License: GPLv3 or later |
| 10 |
* Text Domain: suffice-toolkit |
| 11 |
* Domain Path: /i18n/languages/ |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; // Exit if accessed directly. |
| 16 |
} |
| 17 |
|
| 18 |
if ( ! class_exists( 'SufficeToolkit' ) ) : |
| 19 |
|
| 20 |
/** |
| 21 |
* SufficeToolkit main class. |
| 22 |
* |
| 23 |
* @class SufficeToolkit |
| 24 |
* @version 1.0.0 |
| 25 |
*/ |
| 26 |
final class SufficeToolkit { |
| 27 |
|
| 28 |
/** |
| 29 |
* Plugin version. |
| 30 |
* @var string |
| 31 |
*/ |
| 32 |
public $version = '1.1.0'; |
| 33 |
|
| 34 |
/** |
| 35 |
* Instance of this class. |
| 36 |
* @var object |
| 37 |
*/ |
| 38 |
protected static $_instance = null; |
| 39 |
|
| 40 |
/** |
| 41 |
* Return an instance of this class. |
| 42 |
* @return object A single instance of this class. |
| 43 |
*/ |
| 44 |
public static function instance() { |
| 45 |
// If the single instance hasn't been set, set it now. |
| 46 |
if ( is_null( self::$_instance ) ) { |
| 47 |
self::$_instance = new self(); |
| 48 |
} |
| 49 |
return self::$_instance; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Cloning is forbidden. |
| 54 |
* @since 1.0 |
| 55 |
*/ |
| 56 |
public function __clone() { |
| 57 |
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'suffice-toolkit' ), '1.0' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Unserializing instances of this class is forbidden. |
| 62 |
* @since 1.0 |
| 63 |
*/ |
| 64 |
public function __wakeup() { |
| 65 |
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'suffice-toolkit' ), '1.0' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* SufficeToolkit Constructor. |
| 70 |
*/ |
| 71 |
public function __construct() { |
| 72 |
$this->define_constants(); |
| 73 |
$this->includes(); |
| 74 |
$this->init_hooks(); |
| 75 |
|
| 76 |
do_action( 'suffice_toolkit_loaded' ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Hook into actions and filters. |
| 81 |
*/ |
| 82 |
private function init_hooks() { |
| 83 |
register_activation_hook( __FILE__, array( 'ST_Install', 'install' ) ); |
| 84 |
add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
| 85 |
add_action( 'admin_notices', array( $this, 'theme_support_missing_notice' ) ); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Define ST Constants. |
| 90 |
*/ |
| 91 |
private function define_constants() { |
| 92 |
$this->define( 'ST_PLUGIN_FILE', __FILE__ ); |
| 93 |
$this->define( 'ST_ABSPATH', __DIR__ . '/' ); |
| 94 |
$this->define( 'ST_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 95 |
$this->define( 'ST_VERSION', $this->version ); |
| 96 |
$this->define( 'ST_TEMPLATE_DEBUG_MODE', false ); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Define constant if not already set. |
| 101 |
* |
| 102 |
* @param string $name |
| 103 |
* @param string|bool $value |
| 104 |
*/ |
| 105 |
private function define( $name, $value ) { |
| 106 |
if ( ! defined( $name ) ) { |
| 107 |
define( $name, $value ); //phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.VariableConstantNameFound |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* What type of request is this? |
| 113 |
* |
| 114 |
* @param string $type admin or frontend. |
| 115 |
* @return bool |
| 116 |
*/ |
| 117 |
private function is_request( $type ) { |
| 118 |
switch ( $type ) { |
| 119 |
case 'admin': |
| 120 |
return is_admin(); |
| 121 |
case 'frontend': |
| 122 |
return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Includes. |
| 128 |
*/ |
| 129 |
private function includes() { |
| 130 |
include_once ST_ABSPATH . 'includes/functions-suffice-core.php'; |
| 131 |
include_once ST_ABSPATH . 'includes/functions-suffice-widget.php'; |
| 132 |
include_once ST_ABSPATH . 'includes/class-suffice-autoloader.php'; |
| 133 |
include_once ST_ABSPATH . 'includes/class-suffice-install.php'; |
| 134 |
include_once ST_ABSPATH . 'includes/class-suffice-ajax.php'; |
| 135 |
include_once ST_ABSPATH . 'includes/class-suffice-inline-style.php'; |
| 136 |
|
| 137 |
if ( $this->is_request( 'admin' ) ) { |
| 138 |
include_once ST_ABSPATH . 'includes/admin/class-suffice-admin.php'; |
| 139 |
} |
| 140 |
|
| 141 |
if ( is_suffice_pro_active() ) { |
| 142 |
include_once ST_ABSPATH . 'includes/class-suffice-sidebars.php'; |
| 143 |
} |
| 144 |
|
| 145 |
include_once ST_ABSPATH . 'includes/class-suffice-post-types.php'; // Registers post types |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* Load Localisation files. |
| 150 |
* |
| 151 |
* Note: the first-loaded translation file overrides any following ones if the same translation is present. |
| 152 |
* |
| 153 |
* Locales found in: |
| 154 |
* - WP_LANG_DIR/suffice-toolkit/suffice-toolkit-LOCALE.mo |
| 155 |
* - WP_LANG_DIR/plugins/suffice-toolkit-LOCALE.mo |
| 156 |
*/ |
| 157 |
public function load_plugin_textdomain() { |
| 158 |
$locale = apply_filters( 'plugin_locale', get_locale(), 'suffice-toolkit' ); //phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound |
| 159 |
|
| 160 |
load_textdomain( 'suffice-toolkit', WP_LANG_DIR . '/suffice-toolkit/suffice-toolkit-' . $locale . '.mo' ); |
| 161 |
load_plugin_textdomain( 'suffice-toolkit', false, plugin_basename( __DIR__ ) . '/i18n/languages' ); |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Theme support fallback notice. |
| 166 |
* @return string |
| 167 |
*/ |
| 168 |
public function theme_support_missing_notice() { |
| 169 |
$theme = wp_get_theme(); |
| 170 |
$parent = $theme->parent(); |
| 171 |
|
| 172 |
// Check with ThemeGrill Suffice Theme is installed. |
| 173 |
if ( ( $theme != 'Suffice' ) && ( $theme != 'Suffice Pro' ) && ( $parent != 'Suffice' ) && ( $parent != 'Suffice Pro' ) ) { |
| 174 |
// 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>'; |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
* Get the plugin url. |
| 180 |
* @return string |
| 181 |
*/ |
| 182 |
public function plugin_url() { |
| 183 |
return untrailingslashit( plugins_url( '/', __FILE__ ) ); |
| 184 |
} |
| 185 |
|
| 186 |
/** |
| 187 |
* Get the plugin path. |
| 188 |
* @return string |
| 189 |
*/ |
| 190 |
public function plugin_path() { |
| 191 |
return untrailingslashit( plugin_dir_path( __FILE__ ) ); |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Get the template path. |
| 196 |
* @return string |
| 197 |
*/ |
| 198 |
public function template_path() { |
| 199 |
return apply_filters( 'suffice_toolkit_template_path', 'suffice-toolkit/' ); |
| 200 |
} |
| 201 |
|
| 202 |
/** |
| 203 |
* Get Ajax URL. |
| 204 |
* @return string |
| 205 |
*/ |
| 206 |
public function ajax_url() { |
| 207 |
return admin_url( 'admin-ajax.php', 'relative' ); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
endif; |
| 212 |
|
| 213 |
/** |
| 214 |
* Main instance of SufficeToolkit. |
| 215 |
* |
| 216 |
* Returns the main instance of ST to prevent the need to use globals. |
| 217 |
* |
| 218 |
* @since 1.0 |
| 219 |
* @return SufficeToolkit |
| 220 |
*/ |
| 221 |
function ST() { //phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 222 |
return SufficeToolkit::instance(); |
| 223 |
} |
| 224 |
|
| 225 |
// Global for backwards compatibility. |
| 226 |
$GLOBALS['sufficetoolkit'] = ST(); |
| 227 |
|