| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: HookMeUp – Additional Content for WooCommerce |
| 5 |
* Plugin URI: https://wordpress.org/plugins/hookmeup/ |
| 6 |
* Description: Helps you customize WooCommerce templates without altering the code. |
| 7 |
* Version: 1.3.2 |
| 8 |
* Author: GetBowtied |
| 9 |
* Author URI: https://getbowtied.com/ |
| 10 |
* License: GPL-2.0+ |
| 11 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 12 |
* Text Domain: hookmeup |
| 13 |
* Domain Path: /languages |
| 14 |
* Requires at least: 5.0 |
| 15 |
* Tested up to: 5.6 |
| 16 |
* WC requires at least: 3.3.4 |
| 17 |
* WC tested up to: 4.8.0 |
| 18 |
* |
| 19 |
* @link getbowtied.com |
| 20 |
* @since 1.0.0 |
| 21 |
* @package HMU |
| 22 |
*/ |
| 23 |
|
| 24 |
if ( ! defined( 'ABSPATH' ) ) { |
| 25 |
exit; |
| 26 |
} // Exit if accessed directly |
| 27 |
|
| 28 |
if ( ! defined( 'HMU_DIR' ) ) { |
| 29 |
define( 'HMU_DIR', plugin_dir_path( __FILE__ ) ); |
| 30 |
} |
| 31 |
|
| 32 |
if ( ! function_exists( 'is_plugin_active' ) ) { |
| 33 |
require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 34 |
} |
| 35 |
|
| 36 |
if ( ! class_exists( 'HookMeUp' ) ) : |
| 37 |
|
| 38 |
/** |
| 39 |
* HookMeUp class. |
| 40 |
* |
| 41 |
* @since 1.0.0.0 |
| 42 |
*/ |
| 43 |
class HookMeUp { |
| 44 |
|
| 45 |
/** |
| 46 |
* Maintaining and registering all hooks that power the plugin. |
| 47 |
* |
| 48 |
* @since 1.0.0 |
| 49 |
* @access protected |
| 50 |
*/ |
| 51 |
protected $loader; |
| 52 |
|
| 53 |
/** |
| 54 |
* The unique identifier of this plugin. |
| 55 |
* |
| 56 |
* @since 1.0.0 |
| 57 |
* @var string |
| 58 |
*/ |
| 59 |
protected $plugin_name = "hookmeup"; |
| 60 |
|
| 61 |
/** |
| 62 |
* The current version of the plugin. |
| 63 |
* |
| 64 |
* @since 1.0.0 |
| 65 |
* @var string |
| 66 |
*/ |
| 67 |
protected $version = '1.2.1'; |
| 68 |
|
| 69 |
/** |
| 70 |
* The single instance of the class. |
| 71 |
* |
| 72 |
* @since 1.0.0 |
| 73 |
* @var HookMeUp |
| 74 |
*/ |
| 75 |
protected static $_instance = null; |
| 76 |
|
| 77 |
/** |
| 78 |
* HookMeUp constructor |
| 79 |
* |
| 80 |
* @since 1.0.0 |
| 81 |
*/ |
| 82 |
public function __construct() { |
| 83 |
|
| 84 |
/** |
| 85 |
* Die if WooCommerce not installed/activated |
| 86 |
*/ |
| 87 |
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
| 88 |
$this->includes(); |
| 89 |
$this->add_hooks(); |
| 90 |
$this->loader = new HookMeUp_Loader(); |
| 91 |
$this->set_locale(); |
| 92 |
$this->define_public_hooks(); |
| 93 |
$this->define_customizer(); |
| 94 |
if( !get_option( 'hookmeup_done_import', false ) ) { |
| 95 |
$done_import = $this->import_options(); |
| 96 |
if( $done_import ) { |
| 97 |
update_option( 'hookmeup_done_import', true ); |
| 98 |
} |
| 99 |
} |
| 100 |
} else { |
| 101 |
add_action( 'admin_notices', array( $this, 'woocommerce_not_installed_warning' ) ); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Ensures only one instance of HookMeUp is loaded or can be loaded. |
| 107 |
* |
| 108 |
* @since 1.0.0 |
| 109 |
* |
| 110 |
* @return HookMeUp |
| 111 |
*/ |
| 112 |
public static function instance() { |
| 113 |
if ( is_null( self::$_instance ) ) { |
| 114 |
self::$_instance = new self(); |
| 115 |
} |
| 116 |
return self::$_instance; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Imports hooks stored as theme mods into the options WP table |
| 121 |
* |
| 122 |
* @since 1.2.1 |
| 123 |
* @return void |
| 124 |
*/ |
| 125 |
private function import_options() { |
| 126 |
$done_import = true; |
| 127 |
|
| 128 |
$hooks = new HookMeUp_Hooks(); |
| 129 |
$hooks_list = $hooks->get_all_hooks(); |
| 130 |
foreach( $hooks_list as $hook) { |
| 131 |
if( get_theme_mod( $hook['section'] . '_preview' ) ) { |
| 132 |
update_option( 'hookmeup_' . $hook['section'] . '_preview', get_theme_mod( $hook['section'] . '_preview', 'no' ) ); |
| 133 |
if( get_option( 'hookmeup_' . $hook['section'] . '_preview' ) ) { |
| 134 |
remove_theme_mod( $hook['section'] . '_preview' ); |
| 135 |
} else { |
| 136 |
$done_import = false; |
| 137 |
} |
| 138 |
} |
| 139 |
if( get_theme_mod( $hook['slug'] . '_editor' ) ) { |
| 140 |
update_option( 'hookmeup_' . $hook['slug'] . '_editor', get_theme_mod( $hook['slug'] . '_editor', '' ) ); |
| 141 |
if( get_option( 'hookmeup_' . $hook['slug'] . '_editor' ) ) { |
| 142 |
remove_theme_mod( $hook['slug'] . '_editor' ); |
| 143 |
} else { |
| 144 |
$done_import = false; |
| 145 |
} |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
return $done_import; |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Include required core files used in admin and on the frontend. |
| 154 |
* |
| 155 |
* @since 1.0.0 |
| 156 |
* |
| 157 |
* @return void |
| 158 |
*/ |
| 159 |
protected function includes() { |
| 160 |
|
| 161 |
include_once( HMU_DIR . 'includes/customizer/class/class-hmu-editor.php' ); |
| 162 |
include_once( HMU_DIR . 'includes/customizer/class/class-hmu-collapsible.php' ); |
| 163 |
include_once( HMU_DIR . 'includes/customizer/class/class-hmu-toggle.php' ); |
| 164 |
include_once( HMU_DIR . 'includes/customizer/class/class-hmu-info.php' ); |
| 165 |
|
| 166 |
include_once( HMU_DIR . 'includes/class-hmu-loader.php' ); |
| 167 |
include_once( HMU_DIR . 'includes/class-hmu-i18n.php' ); |
| 168 |
include_once( HMU_DIR . 'includes/class-hmu-hooks.php' ); |
| 169 |
include_once( HMU_DIR . 'includes/class-hmu-customizer.php' ); |
| 170 |
|
| 171 |
include_once( HMU_DIR . 'public/class-hmu-public.php' ); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Add hooks. |
| 176 |
* |
| 177 |
* @since 1.2 |
| 178 |
* |
| 179 |
* @return void |
| 180 |
*/ |
| 181 |
protected function add_hooks() { |
| 182 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_customizer_styles' ) ); |
| 183 |
} |
| 184 |
|
| 185 |
public function enqueue_customizer_styles() { |
| 186 |
|
| 187 |
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 188 |
|
| 189 |
wp_enqueue_script( 'hmu-customizer-scripts', |
| 190 |
plugins_url( 'includes/customizer/assets/js/hmu-go-to-page.js', __FILE__ ), |
| 191 |
array( 'jquery' ), |
| 192 |
$this->get_version(), |
| 193 |
true |
| 194 |
); |
| 195 |
|
| 196 |
wp_enqueue_style( 'hmu-customizer-styles', |
| 197 |
plugins_url( "includes/customizer/assets/css/customizer{$suffix}.css", __FILE__ ), |
| 198 |
array(), |
| 199 |
$this->get_version(), |
| 200 |
false |
| 201 |
); |
| 202 |
} |
| 203 |
|
| 204 |
/** |
| 205 |
* Define the locale for this plugin for internationalization. |
| 206 |
* |
| 207 |
* @since 1.0.0 |
| 208 |
* |
| 209 |
* @return void |
| 210 |
*/ |
| 211 |
private function set_locale() { |
| 212 |
$plugin_i18n = new HookMeUp_i18n(); |
| 213 |
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'hookmeup' ); |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* Register all of the hooks related to the public-facing functionality of the plugin. |
| 218 |
* |
| 219 |
* @since 1.0.0 |
| 220 |
* |
| 221 |
* @return void |
| 222 |
*/ |
| 223 |
private function define_public_hooks() { |
| 224 |
|
| 225 |
$plugin_public = new HookMeUp_Public( $this->get_plugin_name(), $this->get_version() ); |
| 226 |
add_action( 'wp_enqueue_scripts', array( $plugin_public, 'enqueue_styles' ) ); |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* Register all of the hooks related to the customizer. |
| 231 |
* |
| 232 |
* @since 1.2 |
| 233 |
* |
| 234 |
* @return void |
| 235 |
*/ |
| 236 |
private function define_customizer() { |
| 237 |
|
| 238 |
$plugin_customizer = new HookMeUp_Customizer(); |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* Display warning when WooCommerce not installed or activated |
| 243 |
* |
| 244 |
* @since 1.0.0 |
| 245 |
* |
| 246 |
* @return void |
| 247 |
*/ |
| 248 |
public function woocommerce_not_installed_warning() { |
| 249 |
?> |
| 250 |
<div class="message error woocommerce-admin-notice woocommerce-st-inactive woocommerce-not-configured"> |
| 251 |
<p><?php echo esc_html_e( 'HookMeUp is enabled but not effective. It requires WooCommerce in order to work.', 'hookmeup' ); ?></p> |
| 252 |
</div> |
| 253 |
<?php |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Run the loader to execute all of the hooks with WordPress. |
| 258 |
* |
| 259 |
* @since 1.0.0 |
| 260 |
* |
| 261 |
* @return void |
| 262 |
*/ |
| 263 |
public function run() { |
| 264 |
$this->loader->run(); |
| 265 |
} |
| 266 |
|
| 267 |
/** |
| 268 |
* The reference to the class that orchestrates the hooks with the plugin. |
| 269 |
*/ |
| 270 |
public function get_loader() { |
| 271 |
return $this->loader; |
| 272 |
} |
| 273 |
|
| 274 |
/** |
| 275 |
* The name of the plugin used to uniquely identify it within the context of |
| 276 |
* WordPress and to define internationalization functionality. |
| 277 |
*/ |
| 278 |
public function get_plugin_name() { |
| 279 |
return $this->plugin_name; |
| 280 |
} |
| 281 |
|
| 282 |
/** |
| 283 |
* Retrieve the version number of the plugin. |
| 284 |
*/ |
| 285 |
public function get_version() { |
| 286 |
return $this->version; |
| 287 |
} |
| 288 |
|
| 289 |
} |
| 290 |
|
| 291 |
endif; |
| 292 |
|
| 293 |
$hookmeup = new HookMeUp; |
| 294 |
|