PluginProbe
Bricksable for Bricks Builder / 1.4.32
Bricksable for Bricks Builder v1.4.32
1.2.9 1.3.0 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.31 1.4.32 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 All 132 releases
bricksable / includes / class-bricksable.php

class-bricksable.php in Bricksable for Bricks Builder 1.4.32, at includes/class-bricksable.php

416 lines 12.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main plugin class file.
4 *
5 * @package WordPress Plugin Template/Includes
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Main plugin class.
14 */
15 class Bricksable {
16
17 /**
18 * The single instance of Bricksable.
19 *
20 * @var object
21 * @access private
22 * @since 1.0.0
23 */
24 private static $instance = null; //phpcs:ignore
25
26 /**
27 * Local instance of Bricksable_Admin_API
28 *
29 * @var Bricksable_Admin_API|null
30 */
31 public $admin = null;
32
33 /**
34 * Settings class object
35 *
36 * @var object
37 * @access public
38 * @since 1.0.0
39 */
40 public $settings = null;
41
42 /**
43 * The version number.
44 *
45 * @var string
46 * @access public
47 * @since 1.0.0
48 */
49 public $_version; //phpcs:ignore
50
51 /**
52 * The token.
53 *
54 * @var string
55 * @access public
56 * @since 1.0.0
57 */
58 public $_token; //phpcs:ignore
59
60 /**
61 * The main plugin file.
62 *
63 * @var string
64 * @access public
65 * @since 1.0.0
66 */
67 public $file;
68
69 /**
70 * The main plugin directory.
71 *
72 * @var string
73 * @access public
74 * @since 1.0.0
75 */
76 public $dir;
77
78 /**
79 * The plugin assets directory.
80 *
81 * @var string
82 * @access public
83 * @since 1.0.0
84 */
85 public $assets_dir;
86
87 /**
88 * The plugin assets URL.
89 *
90 * @var string
91 * @access public
92 * @since 1.0.0
93 */
94 public $assets_url;
95
96 /**
97 * Suffix for JavaScripts.
98 *
99 * @var string
100 * @access public
101 * @since 1.0.0
102 */
103 public $script_suffix;
104
105 /**
106 * Constructor funtion.
107 *
108 * @param string $file File constructor.
109 * @param string $version Plugin version.
110 */
111 public function __construct( $file = '', $version = '1.0.0' ) {
112 $this->_version = $version;
113 $this->_token = 'bricksable';
114
115 // Load plugin environment variables.
116 $this->file = $file;
117 $this->dir = dirname( $this->file );
118 $this->assets_dir = trailingslashit( $this->dir ) . 'assets';
119 $this->assets_url = esc_url( trailingslashit( plugins_url( '/assets/', $this->file ) ) );
120
121 $this->script_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
122
123 register_activation_hook( $this->file, array( $this, 'install' ) );
124
125 // Load frontend JS & CSS.
126 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ), 10 );
127 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 10 );
128
129 // Load admin JS & CSS.
130 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 10, 1 );
131 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_styles' ), 10, 1 );
132
133 // Load API for generic admin functions.
134 if ( is_admin() ) {
135 $this->admin = new Bricksable_Admin_API();
136 }
137
138 // Handle localisation.
139 $this->load_plugin_textdomain();
140 add_action( 'init', array( $this, 'load_localisation' ), 0 );
141 } // End __construct ()
142
143 /**
144 * Register post type function.
145 *
146 * @param string $post_type Post Type.
147 * @param string $plural Plural Label.
148 * @param string $single Single Label.
149 * @param string $description Description.
150 * @param array $options Options array.
151 *
152 * @return bool|string|Bricksable_Post_Type
153 */
154 public function register_post_type( $post_type = '', $plural = '', $single = '', $description = '', $options = array() ) {
155
156 if ( ! $post_type || ! $plural || ! $single ) {
157 return false;
158 }
159
160 $post_type = new Bricksable_Post_Type( $post_type, $plural, $single, $description, $options );
161
162 return $post_type;
163 }
164
165 /**
166 * Wrapper function to register a new taxonomy.
167 *
168 * @param string $taxonomy Taxonomy.
169 * @param string $plural Plural Label.
170 * @param string $single Single Label.
171 * @param array $post_types Post types to register this taxonomy for.
172 * @param array $taxonomy_args Taxonomy arguments.
173 *
174 * @return bool|string|Bricksable_Taxonomy
175 */
176 public function register_taxonomy( $taxonomy = '', $plural = '', $single = '', $post_types = array(), $taxonomy_args = array() ) {
177
178 if ( ! $taxonomy || ! $plural || ! $single ) {
179 return false;
180 }
181
182 $taxonomy = new Bricksable_Taxonomy( $taxonomy, $plural, $single, $post_types, $taxonomy_args );
183
184 return $taxonomy;
185 }
186
187 /**
188 * Load frontend CSS.
189 *
190 * @access public
191 * @return void
192 * @since 1.0.0
193 */
194 public function enqueue_styles() {
195 $bricks_version_ba_check = substr( BRICKS_VERSION, 0, 3 ) > '1.3' ? 'style.1.4.css' : 'style.min.css';
196 wp_register_style( 'ba-flipbox', esc_url( $this->assets_url ) . 'css/flipbox/' . $bricks_version_ba_check, array(), $this->_version );
197 wp_register_style( 'ba-tilt-image', esc_url( $this->assets_url ) . 'css/tilt-image/' . $bricks_version_ba_check, array(), $this->_version );
198 wp_register_style( 'ba-lottie', esc_url( $this->assets_url ) . 'css/lottie/style.min.css', array(), $this->_version );
199 wp_register_style( 'ba-floating', esc_url( $this->assets_url ) . 'css/floating/' . $bricks_version_ba_check, array(), $this->_version );
200 wp_register_style( 'ba-before-after-image', esc_url( $this->assets_url ) . 'css/before-after-image/' . $bricks_version_ba_check, array(), $this->_version );
201 wp_register_style( 'ba-icon-list', esc_url( $this->assets_url ) . 'css/icon-list/' . $bricks_version_ba_check, array(), $this->_version );
202 wp_register_style( 'ba-multi-heading', esc_url( $this->assets_url ) . 'css/multi-heading/' . $bricks_version_ba_check, array(), $this->_version );
203 wp_register_style( 'ba-content-toggle', esc_url( $this->assets_url ) . 'css/content-toggle/style.min.css', array(), $this->_version );
204
205 if ( function_exists( 'bricks_is_builder_iframe' ) && bricks_is_builder_iframe() ) {
206 if ( 'on' === get_option( 'bricksable_flip-box' ) || false === get_option( 'bricksable_flip-box' ) ) {
207 wp_enqueue_style( 'ba-flipbox' );
208 }
209 if ( 'on' === get_option( 'bricksable_tilt-image' ) || false === get_option( 'bricksable_tilt-image' ) ) {
210 wp_enqueue_style( 'ba-tilt-image' );
211 }
212 if ( 'on' === get_option( 'bricksable_lottie' ) || false === get_option( 'bricksable_lottie' ) ) {
213 wp_enqueue_style( 'ba-lottie' );
214 }
215 if ( 'on' === get_option( 'bricksable_floating' ) || false === get_option( 'bricksable_floating' ) ) {
216 wp_enqueue_style( 'ba-floating' );
217 }
218 if ( 'on' === get_option( 'bricksable_before-after-image' ) || false === get_option( 'bricksable_before-after-image' ) ) {
219 wp_enqueue_style( 'ba-before-after-image' );
220 }
221 if ( 'on' === get_option( 'bricksable_icon-list' ) || false === get_option( 'bricksable_icon-list' ) ) {
222 wp_enqueue_style( 'ba-icon-list' );
223 }
224 if ( 'on' === get_option( 'bricksable_multi-heading' ) || false === get_option( 'bricksable_multi-heading' ) ) {
225 wp_enqueue_style( 'ba-multi-heading' );
226 }
227 if ( 'on' === get_option( 'bricksable_content-toggle' ) || false === get_option( 'bricksable_content-toggle' ) ) {
228 wp_enqueue_style( 'ba-content-toggle' );
229 }
230 }
231 } // End enqueue_styles ()
232
233 /**
234 * Load frontend Javascript.
235 *
236 * @access public
237 * @return void
238 * @since 1.0.0
239 */
240 public function enqueue_scripts() {
241 wp_register_script( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'js/frontend' . $this->script_suffix . '.js', array( 'jquery' ), $this->_version, true );
242 wp_register_script( 'ba-tilt-image', esc_url( $this->assets_url ) . 'js/tilt-image/frontend.min.js', array(), $this->_version, true );
243 wp_register_script( 'ba-text-notation', esc_url( $this->assets_url ) . 'js/text-notation/frontend.min.js', array(), $this->_version, true );
244 wp_register_script( 'ba-lottie', esc_url( $this->assets_url ) . 'js/lottie/frontend.min.js', array(), $this->_version, true );
245 wp_register_script( 'ba-before-after-image', esc_url( $this->assets_url ) . 'js/before-after-image/frontend.min.js', array(), $this->_version, true );
246 wp_register_script( 'ba-content-toggle', esc_url( $this->assets_url ) . 'js/content-toggle/frontend.min.js', array(), $this->_version, true );
247
248 if ( function_exists( 'bricks_is_builder_iframe' ) && bricks_is_builder_iframe() ) {
249 if ( 'on' === get_option( 'bricksable_tilt-image' ) || false === get_option( 'bricksable_tilt-image' ) ) {
250 wp_enqueue_script( 'ba-tilt-image' );
251 wp_localize_script(
252 'ba-tilt-image',
253 'bricksableTiltImageData',
254 array(
255 'tiltImageInstances' => array(),
256 )
257 );
258 }
259 if ( 'on' === get_option( 'bricksable_text-notation' ) || false === get_option( 'bricksable_text-notation' ) ) {
260 wp_enqueue_script( 'ba-text-notation' );
261 wp_localize_script(
262 'ba-text-notation',
263 'BricksabletextNotationData',
264 array(
265 'textNotationInstances' => array(),
266 )
267 );
268 }
269 if ( 'on' === get_option( 'bricksable_lottie' ) || false === get_option( 'bricksable_lottie' ) ) {
270 wp_enqueue_script( 'ba-lottie' );
271 wp_localize_script(
272 'ba-lottie',
273 'bricksableLottieData',
274 array(
275 'lottieInstances' => array(),
276 )
277 );
278 }
279 if ( 'on' === get_option( 'bricksable_before-after-image' ) || false === get_option( 'bricksable_before-after-image' ) ) {
280 wp_enqueue_script( 'ba-before-after-image' );
281 wp_localize_script(
282 'ba-before-after-image',
283 'bricksableBeforeAfterImageData',
284 array(
285 'BeforeAfterImageInstances' => array(),
286 )
287 );
288 }
289 if ( 'on' === get_option( 'bricksable_content-toggle' ) || false === get_option( 'bricksable_content-toggle' ) ) {
290 wp_enqueue_script( 'ba-content-toggle' );
291 }
292 }
293 } // End enqueue_scripts ()
294
295 /**
296 * Admin enqueue style.
297 *
298 * @param string $hook Hook parameter.
299 *
300 * @return void
301 */
302 public function admin_enqueue_styles( $hook = '' ) {
303 wp_register_style( $this->_token . '-admin', esc_url( $this->assets_url ) . 'css/admin.min.css', array(), $this->_version );
304 if ( 'bricks_page_bricksable_settings' === $hook ) {
305 wp_enqueue_style( $this->_token . '-admin' );
306 }
307 } // End admin_enqueue_styles ()
308
309 /**
310 * Load admin Javascript.
311 *
312 * @access public
313 *
314 * @param string $hook Hook parameter.
315 *
316 * @return void
317 * @since 1.0.0
318 */
319 public function admin_enqueue_scripts( $hook = '' ) {
320 wp_register_script( $this->_token . '-admin', esc_url( $this->assets_url ) . 'js/admin' . $this->script_suffix . '.js', array( 'jquery' ), $this->_version, true );
321 if ( 'bricks_page_bricksable_settings' === $hook ) {
322 wp_enqueue_script( $this->_token . '-admin' );
323 }
324 } // End admin_enqueue_scripts ()
325
326 /**
327 * Load plugin localisation
328 *
329 * @access public
330 * @return void
331 * @since 1.0.0
332 */
333 public function load_localisation() {
334 load_plugin_textdomain( 'bricksable', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
335 } // End load_localisation ()
336
337 /**
338 * Load plugin textdomain
339 *
340 * @access public
341 * @return void
342 * @since 1.0.0
343 */
344 public function load_plugin_textdomain() {
345 $domain = 'bricksable';
346
347 $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
348
349 load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
350 load_plugin_textdomain( $domain, false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
351 } // End load_plugin_textdomain ()
352
353 /**
354 * Main Bricksable Instance
355 *
356 * Ensures only one instance of Bricksable is loaded or can be loaded.
357 *
358 * @param string $file File instance.
359 * @param string $version Version parameter.
360 *
361 * @return Object Bricksable instance
362 * @see Bricksable()
363 * @since 1.0.0
364 * @static
365 */
366 public static function instance( $file = '', $version = '1.0.0' ) {
367 if ( is_null( self::$instance ) ) {
368 self::$instance = new self( $file, $version );
369 }
370
371 return self::$instance;
372 } // End instance ()
373
374 /**
375 * Cloning is forbidden.
376 *
377 * @since 1.0.0
378 */
379 public function __clone() {
380 _doing_it_wrong( __FUNCTION__, esc_html( __( 'Cloning of Bricksable is forbidden' ) ), esc_attr( $this->_version ) );
381
382 } // End __clone ()
383
384 /**
385 * Unserializing instances of this class is forbidden.
386 *
387 * @since 1.0.0
388 */
389 public function __wakeup() {
390 _doing_it_wrong( __FUNCTION__, esc_html( __( 'Unserializing instances of Bricksable is forbidden' ) ), esc_attr( $this->_version ) );
391 } // End __wakeup ()
392
393 /**
394 * Installation. Runs on activation.
395 *
396 * @access public
397 * @return void
398 * @since 1.0.0
399 */
400 public function install() {
401 $this->_log_version_number();
402 } // End install ()
403
404 /**
405 * Log the plugin version number.
406 *
407 * @access public
408 * @return void
409 * @since 1.0.0
410 */
411 private function _log_version_number() { //phpcs:ignore
412 update_option( $this->_token . '_version', $this->_version );
413 } // End _log_version_number ()
414
415 }
416