base.php
132 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Compatibility\Bricks\Widgets; |
| 5 | |
| 6 | use Bricks\Element; |
| 7 | |
| 8 | // If this file is called directly, abort. |
| 9 | if ( ! defined( 'WPINC' ) ) { |
| 10 | die; |
| 11 | } |
| 12 | |
| 13 | class Base extends Element { |
| 14 | |
| 15 | /** |
| 16 | * Use predefined element category 'general' |
| 17 | * |
| 18 | * @var string |
| 19 | */ |
| 20 | public $category = 'general'; |
| 21 | /** |
| 22 | * Make sure to prefix your elements |
| 23 | * |
| 24 | * @var string |
| 25 | */ |
| 26 | public $name = ''; |
| 27 | /** |
| 28 | * Themify icon font class |
| 29 | * |
| 30 | * @var string |
| 31 | */ |
| 32 | public $icon = 'ti-bolt-alt'; |
| 33 | /** |
| 34 | * Default CSS selector |
| 35 | * |
| 36 | * @var string |
| 37 | */ |
| 38 | public $css_selector = ''; |
| 39 | /** |
| 40 | * Script(s) run when element is rendered on frontend or updated in builder |
| 41 | * |
| 42 | * @var array |
| 43 | */ |
| 44 | public $scripts = array(); |
| 45 | |
| 46 | public $current_jet_group = null; |
| 47 | public $current_jet_tab = null; |
| 48 | |
| 49 | public $jet_element_render_instance; |
| 50 | public $jet_element_render = ''; |
| 51 | |
| 52 | // Return localised element label |
| 53 | public function get_label() { |
| 54 | return 'Test'; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Register new control group |
| 59 | * You can't add elements into new groups without registering these groups before |
| 60 | * |
| 61 | * @param [type] $name [description] |
| 62 | * @param array $data [description] |
| 63 | * @return [type] [description] |
| 64 | */ |
| 65 | public function register_jet_control_group( $name, $data = array() ) { |
| 66 | $this->control_groups[ $name ] = $data; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Start controls group (aka Sections in Elementor) |
| 71 | * |
| 72 | * @param [type] $group [description] |
| 73 | * @return [type] [description] |
| 74 | */ |
| 75 | public function start_jet_control_group( $group ) { |
| 76 | $data = $this->control_groups[ $group ] ?? array(); |
| 77 | $this->current_jet_tab = $data['tab'] ?? 'content'; |
| 78 | |
| 79 | $this->current_jet_group = $group; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * End controls grous |
| 84 | * |
| 85 | * @return [type] [description] |
| 86 | */ |
| 87 | public function end_jet_control_group() { |
| 88 | $this->current_jet_tab = null; |
| 89 | $this->current_jet_group = null; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Wrapper to register control |
| 94 | * |
| 95 | * @param [type] $name [description] |
| 96 | * @param array $data [description] |
| 97 | * @return [type] [description] |
| 98 | */ |
| 99 | public function register_jet_control( $name, $data = array() ) { |
| 100 | if ( ! $this->current_jet_tab ) { |
| 101 | $this->current_jet_tab = 'content'; |
| 102 | } |
| 103 | |
| 104 | $data['tab'] = $this->current_jet_tab; |
| 105 | $data['group'] = $this->current_jet_group; |
| 106 | |
| 107 | $this->controls[ $name ] = $data; |
| 108 | } |
| 109 | |
| 110 | public function get_jet_settings( $setting = null, $default_value = false ) { |
| 111 | |
| 112 | if ( ! $setting ) { |
| 113 | return $this->settings; |
| 114 | } |
| 115 | |
| 116 | $value = null; |
| 117 | |
| 118 | if ( isset( $this->settings[ $setting ] ) ) { |
| 119 | $value = $this->settings[ $setting ]; |
| 120 | } else { |
| 121 | $value = isset( $this->controls[ $setting ] ) && isset( $this->controls[ $setting ]['default'] ) ? $this->controls[ $setting ]['default'] : $default_value; |
| 122 | } |
| 123 | |
| 124 | return $value; |
| 125 | } |
| 126 | |
| 127 | public function parse_jet_render_attributes( $attrs = array() ) { |
| 128 | return apply_filters( 'jet-form-builder/bricks/element/parsed-attrs', $attrs, $this ); |
| 129 | } |
| 130 | |
| 131 | } |
| 132 |