| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Flash Toolkit |
| 4 |
* Plugin URI: http://themegrill.com/theme/flash |
| 5 |
* Description: Flash Toolkit is a companion for Flash WordPress theme by ThemeGrill |
| 6 |
* Version: 1.1.6 |
| 7 |
* Author: ThemeGrill |
| 8 |
* Author URI: http://themegrill.com |
| 9 |
* License: GPLv3 or later |
| 10 |
* Text Domain: flash-toolkit |
| 11 |
* Domain Path: /i18n/languages/ |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; // Exit if accessed directly. |
| 16 |
} |
| 17 |
|
| 18 |
if ( ! class_exists( 'FlashToolkit' ) ) : |
| 19 |
|
| 20 |
/** |
| 21 |
* FlashToolkit main class. |
| 22 |
* |
| 23 |
* @class FlashToolkit |
| 24 |
* @version 1.0.0 |
| 25 |
*/ |
| 26 |
final class FlashToolkit { |
| 27 |
|
| 28 |
/** |
| 29 |
* Plugin version. |
| 30 |
* @var string |
| 31 |
*/ |
| 32 |
public $version = '1.1.6'; |
| 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?', 'flash-toolkit' ), '1.0' ); |
| 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?', 'flash-toolkit' ), '1.0' ); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* FlashToolkit Constructor. |
| 70 |
*/ |
| 71 |
public function __construct() { |
| 72 |
$this->define_constants(); |
| 73 |
$this->includes(); |
| 74 |
$this->init_hooks(); |
| 75 |
|
| 76 |
do_action( 'flash_toolkit_loaded' ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Hook into actions and filters. |
| 81 |
*/ |
| 82 |
private function init_hooks() { |
| 83 |
register_activation_hook( __FILE__, array( 'FT_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 FT Constants. |
| 90 |
*/ |
| 91 |
private function define_constants() { |
| 92 |
$this->define( 'FT_PLUGIN_FILE', __FILE__ ); |
| 93 |
$this->define( 'FT_ABSPATH', dirname( __FILE__ ) . '/' ); |
| 94 |
$this->define( 'FT_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 95 |
$this->define( 'FT_VERSION', $this->version ); |
| 96 |
$this->define( 'FT_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 ); |
| 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( FT_ABSPATH . 'includes/functions-flash-core.php' ); |
| 131 |
include_once( FT_ABSPATH . 'includes/functions-flash-widget.php' ); |
| 132 |
include_once( FT_ABSPATH . 'includes/class-flash-autoloader.php' ); |
| 133 |
include_once( FT_ABSPATH . 'includes/class-flash-install.php' ); |
| 134 |
include_once( FT_ABSPATH . 'includes/class-flash-ajax.php' ); |
| 135 |
include_once( FT_ABSPATH . 'includes/class-flash-inline-style.php' ); |
| 136 |
|
| 137 |
if ( $this->is_request( 'admin' ) ) { |
| 138 |
include_once( FT_ABSPATH . 'includes/admin/class-flash-admin.php' ); |
| 139 |
} |
| 140 |
|
| 141 |
if ( is_flash_pro_active() ) { |
| 142 |
include_once( FT_ABSPATH . 'includes/class-flash-sidebars.php' ); |
| 143 |
} |
| 144 |
|
| 145 |
include_once( FT_ABSPATH . 'includes/class-flash-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/flash-toolkit/flash-toolkit-LOCALE.mo |
| 155 |
* - WP_LANG_DIR/plugins/flash-toolkit-LOCALE.mo |
| 156 |
*/ |
| 157 |
public function load_plugin_textdomain() { |
| 158 |
$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
| 159 |
$locale = apply_filters( 'plugin_locale', $locale, 'flash-toolkit' ); |
| 160 |
|
| 161 |
unload_textdomain( 'flash-toolkit' ); |
| 162 |
load_textdomain( 'flash-toolkit', WP_LANG_DIR . '/flash-toolkit/flash-toolkit-' . $locale . '.mo' ); |
| 163 |
load_plugin_textdomain( 'flash-toolkit', false, plugin_basename( dirname( __FILE__ ) ) . '/i18n/languages' ); |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* Theme support fallback notice. |
| 168 |
* @return string |
| 169 |
*/ |
| 170 |
public function theme_support_missing_notice() { |
| 171 |
$theme = wp_get_theme(); |
| 172 |
$parent = $theme->parent(); |
| 173 |
|
| 174 |
// Check with ThemeGrill Flash Theme is installed. |
| 175 |
if ( ( $theme != 'Flash' ) && ( $theme != 'Flash Pro' ) && ( $parent != 'Flash' ) && ( $parent != 'Flash Pro' ) ) { |
| 176 |
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>'; |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
/** |
| 181 |
* Get the plugin url. |
| 182 |
* @return string |
| 183 |
*/ |
| 184 |
public function plugin_url() { |
| 185 |
return untrailingslashit( plugins_url( '/', __FILE__ ) ); |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Get the plugin path. |
| 190 |
* @return string |
| 191 |
*/ |
| 192 |
public function plugin_path() { |
| 193 |
return untrailingslashit( plugin_dir_path( __FILE__ ) ); |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* Get the template path. |
| 198 |
* @return string |
| 199 |
*/ |
| 200 |
public function template_path() { |
| 201 |
return apply_filters( 'flash_toolkit_template_path', 'flash-toolkit/' ); |
| 202 |
} |
| 203 |
|
| 204 |
/** |
| 205 |
* Get Ajax URL. |
| 206 |
* @return string |
| 207 |
*/ |
| 208 |
public function ajax_url() { |
| 209 |
return admin_url( 'admin-ajax.php', 'relative' ); |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
endif; |
| 214 |
|
| 215 |
/** |
| 216 |
* Main instance of FlashToolkit. |
| 217 |
* |
| 218 |
* Returns the main instance of FT to prevent the need to use globals. |
| 219 |
* |
| 220 |
* @since 1.0 |
| 221 |
* @return FlashToolkit |
| 222 |
*/ |
| 223 |
function FT() { |
| 224 |
return FlashToolkit::instance(); |
| 225 |
} |
| 226 |
|
| 227 |
// Global for backwards compatibility. |
| 228 |
$GLOBALS['flashtoolkit'] = FT(); |
| 229 |
|