| 1 |
<?php |
| 2 |
/** |
| 3 |
* Main initialization class. |
| 4 |
* |
| 5 |
* @package RadiusTheme\SB |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace RadiusTheme\SB; |
| 9 |
|
| 10 |
use RadiusTheme\SB\AI\AIinit; |
| 11 |
use RadiusTheme\SB\Helpers\Cache; |
| 12 |
use RadiusTheme\SB\Helpers\Migration; |
| 13 |
use RadiusTheme\SB\Helpers\Installation; |
| 14 |
use RadiusTheme\SB\Modules\ModuleManager; |
| 15 |
use RadiusTheme\SB\Traits\SingletonTrait; |
| 16 |
use RadiusTheme\SB\Controllers\Shortcodes; |
| 17 |
use RadiusTheme\SB\Controllers\Dependencies; |
| 18 |
use RadiusTheme\SB\Controllers\CacheController; |
| 19 |
use RadiusTheme\SB\Controllers\Admin\AdminInit; |
| 20 |
use RadiusTheme\SB\Controllers\AssetsController; |
| 21 |
use RadiusTheme\SB\Controllers\BuilderController; |
| 22 |
use RadiusTheme\SB\Controllers\SupportController; |
| 23 |
use RadiusTheme\SB\Controllers\Hooks\FilterHooks; |
| 24 |
use RadiusTheme\SB\Controllers\Hooks\ActionHooks; |
| 25 |
use RadiusTheme\SB\Controllers\Frontend\Ajax\AddToCart; |
| 26 |
use RadiusTheme\SB\Controllers\Frontend\Ajax\AjaxLogin; |
| 27 |
use RadiusTheme\SB\Controllers\Frontend\Ajax\UpdateCheckoutSection; |
| 28 |
|
| 29 |
// Do not allow directly accessing this file. |
| 30 |
if ( ! defined( 'ABSPATH' ) ) { |
| 31 |
exit( 'This script cannot be accessed directly.' ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Main initialization class. |
| 36 |
*/ |
| 37 |
final class ShopBuilder { |
| 38 |
|
| 39 |
/** |
| 40 |
* Nonce id |
| 41 |
* |
| 42 |
* @var string |
| 43 |
*/ |
| 44 |
public $nonceId = '__rtsb_wpnonce'; |
| 45 |
|
| 46 |
/** |
| 47 |
* Nonce Text |
| 48 |
* |
| 49 |
* @var string |
| 50 |
*/ |
| 51 |
public $nonceText = 'rtsb_nonce'; |
| 52 |
|
| 53 |
/** |
| 54 |
* Post Type. |
| 55 |
* |
| 56 |
* @var string |
| 57 |
*/ |
| 58 |
public $post_type; |
| 59 |
|
| 60 |
/** |
| 61 |
* Post Type. |
| 62 |
* |
| 63 |
* @var string |
| 64 |
*/ |
| 65 |
public $current_theme; |
| 66 |
/** |
| 67 |
* Singleton |
| 68 |
*/ |
| 69 |
|
| 70 |
/** |
| 71 |
* URL for fetch API |
| 72 |
* |
| 73 |
* @var string |
| 74 |
*/ |
| 75 |
public $BASE_API = 'https://shopbuilderwp.com/demo/wp-json/rtsb/v1/layouts/'; |
| 76 |
|
| 77 |
use SingletonTrait; |
| 78 |
|
| 79 |
/** |
| 80 |
* Class Constructor |
| 81 |
*/ |
| 82 |
private function __construct() { |
| 83 |
$this->define_constants(); |
| 84 |
$this->post_type = 'product'; |
| 85 |
$this->current_theme = wp_get_theme()->get( 'Template' ) ? wp_get_theme()->get( 'Template' ) : ( wp_get_theme()->get( 'TextDomain' ) ? wp_get_theme()->get( 'TextDomain' ) : strtolower( str_replace( ' ', '', wp_get_theme()->get( 'Name' ) ) ) ); |
| 86 |
add_action( 'plugins_loaded', [ $this, 'init' ], 15 ); |
| 87 |
add_action( 'upgrader_process_complete', [ $this, 'maybe_run_after_update' ], 10, 2 ); |
| 88 |
|
| 89 |
// Register Plugin Active Hook. |
| 90 |
register_activation_hook( RTSB_FILE, [ Installation::class, 'activate' ] ); |
| 91 |
|
| 92 |
// Register Plugin Deactivate Hook. |
| 93 |
register_deactivation_hook( RTSB_FILE, [ Installation::class, 'deactivation' ] ); |
| 94 |
|
| 95 |
if ( Dependencies::instance()->check() ) { |
| 96 |
SupportController::instance(); |
| 97 |
} |
| 98 |
// HPOS Declare compatibility. |
| 99 |
add_action( |
| 100 |
'before_woocommerce_init', |
| 101 |
function () { |
| 102 |
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { |
| 103 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', RTSB_FILE, true ); |
| 104 |
} |
| 105 |
} |
| 106 |
); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Constants |
| 111 |
* |
| 112 |
* @return void |
| 113 |
*/ |
| 114 |
private function define_constants() { |
| 115 |
if ( ! defined( 'RTSB_ABSPATH' ) ) { |
| 116 |
define( 'RTSB_ABSPATH', dirname( RTSB_FILE ) . '/' ); |
| 117 |
} |
| 118 |
|
| 119 |
if ( ! defined( 'RTSB_URL' ) ) { |
| 120 |
define( 'RTSB_URL', plugins_url( '', RTSB_FILE ) ); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
/** |
| 126 |
* Assets url generate with given assets file |
| 127 |
* |
| 128 |
* @param string $file File. |
| 129 |
* |
| 130 |
* @return string |
| 131 |
*/ |
| 132 |
public function get_assets_uri( $file ) { |
| 133 |
$file = ltrim( $file, '/' ); |
| 134 |
|
| 135 |
return trailingslashit( RTSB_URL . '/assets' ) . $file; |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Assets path. |
| 140 |
* |
| 141 |
* @param string $file File. |
| 142 |
* |
| 143 |
* @return string |
| 144 |
*/ |
| 145 |
public function get_assets_path( $file ) { |
| 146 |
$file = ltrim( $file, '/' ); |
| 147 |
|
| 148 |
return trailingslashit( RTSB_PATH . 'assets' ) . $file; |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Get the template path. |
| 153 |
* |
| 154 |
* @return string |
| 155 |
*/ |
| 156 |
public function get_template_path() { |
| 157 |
return apply_filters( 'rtsb/template/path', 'shopbuilder/' ); |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Get the plugin path. |
| 162 |
* |
| 163 |
* @return string |
| 164 |
*/ |
| 165 |
public function plugin_path() { |
| 166 |
return untrailingslashit( plugin_dir_path( RTSB_FILE ) ); |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* Init |
| 171 |
* |
| 172 |
* @return void |
| 173 |
*/ |
| 174 |
public function init() { |
| 175 |
if ( ! Dependencies::instance()->check() ) { |
| 176 |
return; |
| 177 |
} |
| 178 |
|
| 179 |
do_action( 'rtsb/before/loaded' ); |
| 180 |
CacheController::instance(); |
| 181 |
// Include File. |
| 182 |
AssetsController::instance(); |
| 183 |
ModuleManager::instance(); |
| 184 |
|
| 185 |
// Ajax. |
| 186 |
AddToCart::instance(); |
| 187 |
AjaxLogin::instance(); |
| 188 |
UpdateCheckoutSection::instance(); |
| 189 |
|
| 190 |
BuilderController::instance(); |
| 191 |
FilterHooks::init_hooks(); |
| 192 |
ActionHooks::init_hooks(); |
| 193 |
|
| 194 |
Installation::init(); |
| 195 |
Migration::init(); |
| 196 |
AIinit::instance(); |
| 197 |
|
| 198 |
if ( is_admin() ) { |
| 199 |
AdminInit::instance(); |
| 200 |
} |
| 201 |
|
| 202 |
Shortcodes::instance(); |
| 203 |
|
| 204 |
do_action( 'rtsb/after/loaded' ); |
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* Maybe Run After Update |
| 209 |
* |
| 210 |
* @param object $upgrader_object Upgrader Object. |
| 211 |
* @param array $options Options. |
| 212 |
* |
| 213 |
* @return void |
| 214 |
*/ |
| 215 |
public function maybe_run_after_update( $upgrader_object, $options ) { |
| 216 |
if ( 'plugin' !== $options['type'] || ! in_array( $options['action'], [ 'install', 'update' ], true ) ) { |
| 217 |
return; |
| 218 |
} |
| 219 |
|
| 220 |
// For normal update flow. |
| 221 |
if ( ! empty( $options['plugins'] ) ) { |
| 222 |
foreach ( $options['plugins'] as $plugin ) { |
| 223 |
if ( strpos( $plugin, 'shopbuilder' ) !== false ) { |
| 224 |
Cache::clear_all_cache(); |
| 225 |
break; |
| 226 |
} |
| 227 |
} |
| 228 |
return; |
| 229 |
} |
| 230 |
|
| 231 |
// For upload-based installation. |
| 232 |
if ( |
| 233 |
! empty( $upgrader_object->result['destination_name'] ) && |
| 234 |
strpos( $upgrader_object->result['destination_name'], 'shopbuilder' ) !== false |
| 235 |
) { |
| 236 |
Cache::clear_all_cache(); |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
/** |
| 241 |
* Checks if Pro version installed |
| 242 |
* |
| 243 |
* @return boolean |
| 244 |
*/ |
| 245 |
public function has_pro() { |
| 246 |
return function_exists( 'rtsbpro' ); |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* PRO Version URL. |
| 251 |
* |
| 252 |
* @return string |
| 253 |
*/ |
| 254 |
public function pro_version_link() { |
| 255 |
return 'https://shopbuilderwp.com/'; |
| 256 |
} |
| 257 |
} |
| 258 |
|