| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JFB_Compatibility\Bricks; |
| 5 |
|
| 6 |
use Bricks\Elements; |
| 7 |
use Jet_Form_Builder\Plugin; |
| 8 |
use Jet_Form_Builder\Classes\Tools; |
| 9 |
use JFB_Components\Compatibility\Base_Compat_Handle_Trait; |
| 10 |
use JFB_Components\Compatibility\Base_Compat_Url_Trait; |
| 11 |
use JFB_Components\Compatibility\Base_Compat_Dir_Trait; |
| 12 |
use JFB_Components\Module\Base_Module_After_Install_It; |
| 13 |
use JFB_Components\Module\Base_Module_Handle_It; |
| 14 |
use JFB_Components\Module\Base_Module_It; |
| 15 |
use JFB_Components\Module\Base_Module_Url_It; |
| 16 |
use JFB_Components\Module\Base_Module_Dir_It; |
| 17 |
|
| 18 |
// If this file is called directly, abort. |
| 19 |
if ( ! defined( 'WPINC' ) ) { |
| 20 |
die; |
| 21 |
} |
| 22 |
|
| 23 |
class Bricks implements |
| 24 |
Base_Module_It, |
| 25 |
Base_Module_Handle_It, |
| 26 |
Base_Module_Url_It, |
| 27 |
Base_Module_Dir_It, |
| 28 |
Base_Module_After_Install_It { |
| 29 |
|
| 30 |
use Base_Compat_Handle_Trait; |
| 31 |
use Base_Compat_Url_Trait; |
| 32 |
use Base_Compat_Dir_Trait; |
| 33 |
|
| 34 |
/** |
| 35 |
* @var Onboarding_Builder |
| 36 |
*/ |
| 37 |
private $onboarding_builder; |
| 38 |
|
| 39 |
public function rep_item_id() { |
| 40 |
return 'bricks'; |
| 41 |
} |
| 42 |
|
| 43 |
public function condition(): bool { |
| 44 |
return defined( 'BRICKS_VERSION' ); |
| 45 |
} |
| 46 |
|
| 47 |
public function on_install() { |
| 48 |
$this->onboarding_builder = new Onboarding_Builder(); |
| 49 |
} |
| 50 |
|
| 51 |
public function on_uninstall() { |
| 52 |
} |
| 53 |
|
| 54 |
public function init_hooks() { |
| 55 |
add_action( 'init', array( $this, 'register_elements' ), 10 ); |
| 56 |
add_action( 'wp_enqueue_scripts', array( $this, 'editor_styles' ) ); |
| 57 |
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ), 20 ); |
| 58 |
|
| 59 |
$this->get_onboarding_builder()->init_hooks(); |
| 60 |
} |
| 61 |
|
| 62 |
public function remove_hooks() { |
| 63 |
remove_action( 'init', array( $this, 'register_elements' ) ); |
| 64 |
remove_action( 'wp_enqueue_scripts', array( $this, 'editor_styles' ) ); |
| 65 |
remove_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ), 20 ); |
| 66 |
} |
| 67 |
|
| 68 |
public function register_elements() { |
| 69 |
$file_path = $this->get_dir( 'widgets/form.php' ); |
| 70 |
Elements::register_element( $file_path, '', 'JFB_Compatibility\Bricks\Widgets\Form' ); |
| 71 |
|
| 72 |
do_action( 'jet-form-builder/bricks/register-elements' ); |
| 73 |
} |
| 74 |
|
| 75 |
public function editor_styles() { |
| 76 |
// Enqueue your files on the canvas & frontend, not the builder panel. Otherwise custom CSS might affect builder) |
| 77 |
if ( Tools::is_editor() ) { |
| 78 |
wp_enqueue_style( |
| 79 |
$this->get_handle( 'icons' ), |
| 80 |
$this->get_url( 'assets/build/editor/icons.css' ), |
| 81 |
array(), |
| 82 |
Plugin::instance()->get_version() |
| 83 |
); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Enqueue frontend scripts for AJAX popup support |
| 89 |
* |
| 90 |
* @since 3.5.6 |
| 91 |
*/ |
| 92 |
public function frontend_scripts() { |
| 93 |
// Only enqueue on frontend, not in editor |
| 94 |
if ( Tools::is_editor() ) { |
| 95 |
return; |
| 96 |
} |
| 97 |
|
| 98 |
$asset_file = $this->get_dir( 'assets/build/frontend.asset.php' ); |
| 99 |
|
| 100 |
if ( file_exists( $asset_file ) ) { |
| 101 |
$asset = require $asset_file; |
| 102 |
} else { |
| 103 |
$asset = array( |
| 104 |
'dependencies' => array(), |
| 105 |
'version' => Plugin::instance()->get_version(), |
| 106 |
); |
| 107 |
} |
| 108 |
|
| 109 |
// Start with dependencies from asset file |
| 110 |
$dependencies = $asset['dependencies'] ?? array(); |
| 111 |
|
| 112 |
$script_url = $this->get_url( 'assets/build/frontend.js' ); |
| 113 |
$script_handle = $this->get_handle( 'frontend' ); |
| 114 |
|
| 115 |
wp_enqueue_script( |
| 116 |
$script_handle, |
| 117 |
$script_url, |
| 118 |
$dependencies, |
| 119 |
$asset['version'] ?? Plugin::instance()->get_version(), |
| 120 |
true |
| 121 |
); |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* @return Onboarding_Builder |
| 126 |
*/ |
| 127 |
public function get_onboarding_builder(): Onboarding_Builder { |
| 128 |
return $this->onboarding_builder; |
| 129 |
} |
| 130 |
} |
| 131 |
|