| @@ -1,415 +1,382 @@ | ||
| 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 | - // wp_register_style( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'css/frontend.min.css', array(), $this->_version );. | |
| 196 | - $bricks_version_ba_check = substr( BRICKS_VERSION, 0, 3 ) > '1.3' ? 'style.1.4.css' : 'style.min.css'; | |
| 197 | - $elements = $this->get_elements(); | |
| 198 | - foreach ( $elements as $element ) { | |
| 199 | - $asset_url = esc_url( trailingslashit( plugins_url( '/includes/elements/' . $element . '/assets/css', $this->file ) ) ); | |
| 200 | - $asset_src = esc_url( $asset_url ) . $bricks_version_ba_check; | |
| 201 | - | |
| 202 | - $element_dir = __DIR__ . '/elements/' . $element . '/assets/css/'; | |
| 203 | - if ( is_dir( $element_dir ) ) { | |
| 204 | - $scan = scandir( $element_dir ); | |
| 205 | - | |
| 206 | - if ( array_search( $bricks_version_ba_check, $scan, true ) ) { | |
| 207 | - wp_register_style( 'ba-' . $element, $asset_src, array(), $this->_version ); | |
| 208 | - if ( function_exists( 'bricks_is_builder_iframe' ) && bricks_is_builder_iframe() ) { | |
| 209 | - if ( 'on' === get_option( 'bricksable_' . $element ) || false === get_option( 'bricksable_' . $element ) ) { | |
| 210 | - wp_enqueue_style( 'ba-' . $element ); | |
| 211 | - } | |
| 212 | - } | |
| 213 | - } | |
| 214 | - } | |
| 215 | - } | |
| 216 | - } // End enqueue_styles () | |
| 217 | - | |
| 218 | - /** | |
| 219 | - * Load frontend Javascript. | |
| 220 | - * | |
| 221 | - * @access public | |
| 222 | - * @return void | |
| 223 | - * @since 1.0.0 | |
| 224 | - */ | |
| 225 | - public function enqueue_scripts() { | |
| 226 | - $elements = $this->get_elements(); | |
| 227 | - foreach ( $elements as $element ) { | |
| 228 | - $filename = 'frontend.min.js'; | |
| 229 | - $asset_url = esc_url( trailingslashit( plugins_url( '/includes/elements/' . $element . '/assets/js/', $this->file ) ) ); | |
| 230 | - $asset_src = $asset_url . $filename; | |
| 231 | - | |
| 232 | - $element_dir = __DIR__ . '/elements/' . $element . '/assets/js/'; | |
| 233 | - if ( is_dir( $element_dir ) ) { | |
| 234 | - $scan = scandir( $element_dir ); | |
| 235 | - | |
| 236 | - if ( array_search( $filename, $scan, true ) ) { | |
| 237 | - wp_register_script( 'ba-' . $element, $asset_src, array(), $this->_version, true ); | |
| 238 | - if ( function_exists( 'bricks_is_builder_iframe' ) && bricks_is_builder_iframe() ) { | |
| 239 | - if ( 'on' === get_option( 'bricksable_' . $element ) || false === get_option( 'bricksable_' . $element ) ) { | |
| 240 | - wp_enqueue_script( 'ba-' . $element ); | |
| 241 | - | |
| 242 | - wp_localize_script( | |
| 243 | - 'ba-tilt-image', | |
| 244 | - 'bricksableTiltImageData', | |
| 245 | - array( | |
| 246 | - 'tiltImageInstances' => array(), | |
| 247 | - ) | |
| 248 | - ); | |
| 249 | - wp_localize_script( | |
| 250 | - 'ba-text-notation', | |
| 251 | - 'BricksabletextNotationData', | |
| 252 | - array( | |
| 253 | - 'textNotationInstances' => array(), | |
| 254 | - ) | |
| 255 | - ); | |
| 256 | - wp_localize_script( | |
| 257 | - 'ba-lottie', | |
| 258 | - 'bricksableLottieData', | |
| 259 | - array( | |
| 260 | - 'lottieInstances' => array(), | |
| 261 | - ) | |
| 262 | - ); | |
| 263 | - wp_localize_script( | |
| 264 | - 'ba-before-after-image', | |
| 265 | - 'bricksableBeforeAfterImageData', | |
| 266 | - array( | |
| 267 | - 'BeforeAfterImageInstances' => array(), | |
| 268 | - ) | |
| 269 | - ); | |
| 270 | - | |
| 271 | - } | |
| 272 | - } | |
| 273 | - } | |
| 274 | - } | |
| 275 | - } | |
| 276 | - } // End enqueue_scripts () | |
| 277 | - | |
| 278 | - /** | |
| 279 | - * Admin enqueue style. | |
| 280 | - * | |
| 281 | - * @param string $hook Hook parameter. | |
| 282 | - * | |
| 283 | - * @return void | |
| 284 | - */ | |
| 285 | - public function admin_enqueue_styles( $hook = '' ) { | |
| 286 | - wp_register_style( $this->_token . '-admin', esc_url( $this->assets_url ) . 'css/admin.min.css', array(), $this->_version ); | |
| 287 | - if ( 'bricks_page_bricksable_settings' === $hook ) { | |
| 288 | - wp_enqueue_style( $this->_token . '-admin' ); | |
| 289 | - } | |
| 290 | - } // End admin_enqueue_styles () | |
| 291 | - | |
| 292 | - /** | |
| 293 | - * Load admin Javascript. | |
| 294 | - * | |
| 295 | - * @access public | |
| 296 | - * | |
| 297 | - * @param string $hook Hook parameter. | |
| 298 | - * | |
| 299 | - * @return void | |
| 300 | - * @since 1.0.0 | |
| 301 | - */ | |
| 302 | - public function admin_enqueue_scripts( $hook = '' ) { | |
| 303 | - wp_register_script( $this->_token . '-admin', esc_url( $this->assets_url ) . 'js/admin' . $this->script_suffix . '.js', array( 'jquery' ), $this->_version, true ); | |
| 304 | - if ( 'bricks_page_bricksable_settings' === $hook ) { | |
| 305 | - wp_enqueue_script( $this->_token . '-admin' ); | |
| 306 | - } | |
| 307 | - } // End admin_enqueue_scripts () | |
| 308 | - | |
| 309 | - /** | |
| 310 | - * Load plugin localisation | |
| 311 | - * | |
| 312 | - * @access public | |
| 313 | - * @return void | |
| 314 | - * @since 1.0.0 | |
| 315 | - */ | |
| 316 | - public function load_localisation() { | |
| 317 | - load_plugin_textdomain( 'bricksable', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); | |
| 318 | - } // End load_localisation () | |
| 319 | - | |
| 320 | - /** | |
| 321 | - * Load plugin textdomain | |
| 322 | - * | |
| 323 | - * @access public | |
| 324 | - * @return void | |
| 325 | - * @since 1.0.0 | |
| 326 | - */ | |
| 327 | - public function load_plugin_textdomain() { | |
| 328 | - $domain = 'bricksable'; | |
| 329 | - | |
| 330 | - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); | |
| 331 | - | |
| 332 | - load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); | |
| 333 | - load_plugin_textdomain( $domain, false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); | |
| 334 | - } // End load_plugin_textdomain () | |
| 335 | - | |
| 336 | - /** | |
| 337 | - * Main Bricksable Instance | |
| 338 | - * | |
| 339 | - * Ensures only one instance of Bricksable is loaded or can be loaded. | |
| 340 | - * | |
| 341 | - * @param string $file File instance. | |
| 342 | - * @param string $version Version parameter. | |
| 343 | - * | |
| 344 | - * @return Object Bricksable instance | |
| 345 | - * @see Bricksable() | |
| 346 | - * @since 1.0.0 | |
| 347 | - * @static | |
| 348 | - */ | |
| 349 | - public static function instance( $file = '', $version = '1.0.0' ) { | |
| 350 | - if ( is_null( self::$instance ) ) { | |
| 351 | - self::$instance = new self( $file, $version ); | |
| 352 | - } | |
| 353 | - | |
| 354 | - return self::$instance; | |
| 355 | - } // End instance () | |
| 356 | - | |
| 357 | - /** | |
| 358 | - * Cloning is forbidden. | |
| 359 | - * | |
| 360 | - * @since 1.0.0 | |
| 361 | - */ | |
| 362 | - public function __clone() { | |
| 363 | - _doing_it_wrong( __FUNCTION__, esc_html( __( 'Cloning of Bricksable is forbidden' ) ), esc_attr( $this->_version ) ); | |
| 364 | - | |
| 365 | - } // End __clone () | |
| 366 | - | |
| 367 | - /** | |
| 368 | - * Unserializing instances of this class is forbidden. | |
| 369 | - * | |
| 370 | - * @since 1.0.0 | |
| 371 | - */ | |
| 372 | - public function __wakeup() { | |
| 373 | - _doing_it_wrong( __FUNCTION__, esc_html( __( 'Unserializing instances of Bricksable is forbidden' ) ), esc_attr( $this->_version ) ); | |
| 374 | - } // End __wakeup () | |
| 375 | - | |
| 376 | - /** | |
| 377 | - * Installation. Runs on activation. | |
| 378 | - * | |
| 379 | - * @access public | |
| 380 | - * @return void | |
| 381 | - * @since 1.0.0 | |
| 382 | - */ | |
| 383 | - public function install() { | |
| 384 | - $this->_log_version_number(); | |
| 385 | - } // End install () | |
| 386 | - | |
| 387 | - /** | |
| 388 | - * Log the plugin version number. | |
| 389 | - * | |
| 390 | - * @access public | |
| 391 | - * @return void | |
| 392 | - * @since 1.0.0 | |
| 393 | - */ | |
| 394 | - private function _log_version_number() { //phpcs:ignore | |
| 395 | - update_option( $this->_token . '_version', $this->_version ); | |
| 396 | - } // End _log_version_number () | |
| 397 | - | |
| 398 | - /** | |
| 399 | - * Get Elements | |
| 400 | - */ | |
| 401 | - public function get_elements() { | |
| 402 | - $elements = array(); | |
| 403 | - $elements_dir = __DIR__ . '/elements'; | |
| 404 | - $scan = scandir( $elements_dir ); | |
| 405 | - foreach ( $scan as $result ) { | |
| 406 | - if ( '.' === $result || '..' === $result ) { | |
| 407 | - continue; | |
| 408 | - } | |
| 409 | - if ( is_dir( $elements_dir . '/' . $result ) ) { | |
| 410 | - $elements[] = $result; | |
| 411 | - } | |
| 412 | - } | |
| 413 | - return $elements; | |
| 414 | - } | |
| 415 | -} | |
| 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 | + wp_register_style( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'css/frontend.min.css', array(), $this->_version ); | |
| 196 | + wp_enqueue_style( $this->_token . '-frontend' ); | |
| 197 | + } // End enqueue_styles () | |
| 198 | + | |
| 199 | + /** | |
| 200 | + * Load frontend Javascript. | |
| 201 | + * | |
| 202 | + * @access public | |
| 203 | + * @return void | |
| 204 | + * @since 1.0.0 | |
| 205 | + */ | |
| 206 | + public function enqueue_scripts() { | |
| 207 | + wp_register_script( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'js/frontend' . $this->script_suffix . '.js', array( 'jquery' ), $this->_version, true ); | |
| 208 | + wp_register_script( 'ba-tilt-image', esc_url( $this->assets_url ) . 'js/tilt-image/frontend.min.js', array(), $this->_version, true ); | |
| 209 | + wp_register_script( 'ba-text-notation', esc_url( $this->assets_url ) . 'js/text-notation/frontend.min.js', array(), $this->_version, true ); | |
| 210 | + wp_register_script( 'ba-lottie', esc_url( $this->assets_url ) . 'js/lottie/frontend.min.js', array(), $this->_version, true ); | |
| 211 | + wp_register_script( 'ba-before-after-image', esc_url( $this->assets_url ) . 'js/before-after-image/frontend.min.js', array(), $this->_version, true ); | |
| 212 | + wp_register_script( 'ba-content-toggle', esc_url( $this->assets_url ) . 'js/content-toggle/frontend.min.js', array(), $this->_version, true ); | |
| 213 | + | |
| 214 | + if ( function_exists( 'bricks_is_builder_iframe' ) && bricks_is_builder_iframe() ) { | |
| 215 | + if ( 'on' === get_option( 'bricksable_tilt-image' ) || false === get_option( 'bricksable_tilt-image' ) ) { | |
| 216 | + wp_enqueue_script( 'ba-tilt-image' ); | |
| 217 | + wp_localize_script( | |
| 218 | + 'ba-tilt-image', | |
| 219 | + 'bricksableTiltImageData', | |
| 220 | + array( | |
| 221 | + 'tiltImageInstances' => array(), | |
| 222 | + ) | |
| 223 | + ); | |
| 224 | + } | |
| 225 | + if ( 'on' === get_option( 'bricksable_text-notation' ) || false === get_option( 'bricksable_text-notation' ) ) { | |
| 226 | + wp_enqueue_script( 'ba-text-notation' ); | |
| 227 | + wp_localize_script( | |
| 228 | + 'ba-text-notation', | |
| 229 | + 'BricksabletextNotationData', | |
| 230 | + array( | |
| 231 | + 'textNotationInstances' => array(), | |
| 232 | + ) | |
| 233 | + ); | |
| 234 | + } | |
| 235 | + if ( 'on' === get_option( 'bricksable_lottie' ) || false === get_option( 'bricksable_lottie' ) ) { | |
| 236 | + wp_enqueue_script( 'ba-lottie' ); | |
| 237 | + wp_localize_script( | |
| 238 | + 'ba-lottie', | |
| 239 | + 'bricksableLottieData', | |
| 240 | + array( | |
| 241 | + 'lottieInstances' => array(), | |
| 242 | + ) | |
| 243 | + ); | |
| 244 | + } | |
| 245 | + if ( 'on' === get_option( 'bricksable_before-after-image' ) || false === get_option( 'bricksable_before-after-image' ) ) { | |
| 246 | + wp_enqueue_script( 'ba-before-after-image' ); | |
| 247 | + wp_localize_script( | |
| 248 | + 'ba-before-after-image', | |
| 249 | + 'bricksableBeforeAfterImageData', | |
| 250 | + array( | |
| 251 | + 'BeforeAfterImageInstances' => array(), | |
| 252 | + ) | |
| 253 | + ); | |
| 254 | + } | |
| 255 | + if ( 'on' === get_option( 'bricksable_content-toggle' ) || false === get_option( 'bricksable_content-toggle' ) ) { | |
| 256 | + wp_enqueue_script( 'ba-content-toggle' ); | |
| 257 | + } | |
| 258 | + } | |
| 259 | + | |
| 260 | + } // End enqueue_scripts () | |
| 261 | + | |
| 262 | + /** | |
| 263 | + * Admin enqueue style. | |
| 264 | + * | |
| 265 | + * @param string $hook Hook parameter. | |
| 266 | + * | |
| 267 | + * @return void | |
| 268 | + */ | |
| 269 | + public function admin_enqueue_styles( $hook = '' ) { | |
| 270 | + wp_register_style( $this->_token . '-admin', esc_url( $this->assets_url ) . 'css/admin.min.css', array(), $this->_version ); | |
| 271 | + if ( 'bricks_page_bricksable_settings' === $hook ) { | |
| 272 | + wp_enqueue_style( $this->_token . '-admin' ); | |
| 273 | + } | |
| 274 | + } // End admin_enqueue_styles () | |
| 275 | + | |
| 276 | + /** | |
| 277 | + * Load admin Javascript. | |
| 278 | + * | |
| 279 | + * @access public | |
| 280 | + * | |
| 281 | + * @param string $hook Hook parameter. | |
| 282 | + * | |
| 283 | + * @return void | |
| 284 | + * @since 1.0.0 | |
| 285 | + */ | |
| 286 | + public function admin_enqueue_scripts( $hook = '' ) { | |
| 287 | + wp_register_script( $this->_token . '-admin', esc_url( $this->assets_url ) . 'js/admin' . $this->script_suffix . '.js', array( 'jquery' ), $this->_version, true ); | |
| 288 | + if ( 'bricks_page_bricksable_settings' === $hook ) { | |
| 289 | + wp_enqueue_script( $this->_token . '-admin' ); | |
| 290 | + } | |
| 291 | + } // End admin_enqueue_scripts () | |
| 292 | + | |
| 293 | + /** | |
| 294 | + * Load plugin localisation | |
| 295 | + * | |
| 296 | + * @access public | |
| 297 | + * @return void | |
| 298 | + * @since 1.0.0 | |
| 299 | + */ | |
| 300 | + public function load_localisation() { | |
| 301 | + load_plugin_textdomain( 'bricksable', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); | |
| 302 | + } // End load_localisation () | |
| 303 | + | |
| 304 | + /** | |
| 305 | + * Load plugin textdomain | |
| 306 | + * | |
| 307 | + * @access public | |
| 308 | + * @return void | |
| 309 | + * @since 1.0.0 | |
| 310 | + */ | |
| 311 | + public function load_plugin_textdomain() { | |
| 312 | + $domain = 'bricksable'; | |
| 313 | + | |
| 314 | + $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); | |
| 315 | + | |
| 316 | + load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); | |
| 317 | + load_plugin_textdomain( $domain, false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); | |
| 318 | + } // End load_plugin_textdomain () | |
| 319 | + | |
| 320 | + /** | |
| 321 | + * Main Bricksable Instance | |
| 322 | + * | |
| 323 | + * Ensures only one instance of Bricksable is loaded or can be loaded. | |
| 324 | + * | |
| 325 | + * @param string $file File instance. | |
| 326 | + * @param string $version Version parameter. | |
| 327 | + * | |
| 328 | + * @return Object Bricksable instance | |
| 329 | + * @see Bricksable() | |
| 330 | + * @since 1.0.0 | |
| 331 | + * @static | |
| 332 | + */ | |
| 333 | + public static function instance( $file = '', $version = '1.0.0' ) { | |
| 334 | + if ( is_null( self::$instance ) ) { | |
| 335 | + self::$instance = new self( $file, $version ); | |
| 336 | + } | |
| 337 | + | |
| 338 | + return self::$instance; | |
| 339 | + } // End instance () | |
| 340 | + | |
| 341 | + /** | |
| 342 | + * Cloning is forbidden. | |
| 343 | + * | |
| 344 | + * @since 1.0.0 | |
| 345 | + */ | |
| 346 | + public function __clone() { | |
| 347 | + _doing_it_wrong( __FUNCTION__, esc_html( __( 'Cloning of Bricksable is forbidden' ) ), esc_attr( $this->_version ) ); | |
| 348 | + | |
| 349 | + } // End __clone () | |
| 350 | + | |
| 351 | + /** | |
| 352 | + * Unserializing instances of this class is forbidden. | |
| 353 | + * | |
| 354 | + * @since 1.0.0 | |
| 355 | + */ | |
| 356 | + public function __wakeup() { | |
| 357 | + _doing_it_wrong( __FUNCTION__, esc_html( __( 'Unserializing instances of Bricksable is forbidden' ) ), esc_attr( $this->_version ) ); | |
| 358 | + } // End __wakeup () | |
| 359 | + | |
| 360 | + /** | |
| 361 | + * Installation. Runs on activation. | |
| 362 | + * | |
| 363 | + * @access public | |
| 364 | + * @return void | |
| 365 | + * @since 1.0.0 | |
| 366 | + */ | |
| 367 | + public function install() { | |
| 368 | + $this->_log_version_number(); | |
| 369 | + } // End install () | |
| 370 | + | |
| 371 | + /** | |
| 372 | + * Log the plugin version number. | |
| 373 | + * | |
| 374 | + * @access public | |
| 375 | + * @return void | |
| 376 | + * @since 1.0.0 | |
| 377 | + */ | |
| 378 | + private function _log_version_number() { //phpcs:ignore | |
| 379 | + update_option( $this->_token . '_version', $this->_version ); | |
| 380 | + } // End _log_version_number () | |
| 381 | + | |
| 382 | +} | |