PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.0.0
ShopBuilder – WooCommerce Builder For Elementor v3.0.0
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / ShopBuilder.php

ShopBuilder.php in ShopBuilder – WooCommerce Builder For Elementor 3.0.0, at app/ShopBuilder.php

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