arguments
1 year ago
arrayable
2 years ago
filters
1 year ago
http
2 years ago
macro-constants
2 years ago
post
1 year ago
resources
1 year ago
theme
2 years ago
attributes-trait.php
2 years ago
base-attributes-trait.php
2 years ago
builder-helper.php
1 year ago
compatibility.php
2 years ago
date-tools.php
2 years ago
gallery.php
2 years ago
get-icon-trait.php
2 years ago
get-template-trait.php
2 years ago
html-attributes-trait.php
2 years ago
instance-trait.php
2 years ago
regexp-tools.php
2 years ago
tools.php
1 year ago
base-attributes-trait.php
75 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Classes; |
| 5 | |
| 6 | use Jet_Form_Builder\Blocks\Render\Base; |
| 7 | |
| 8 | // If this file is called directly, abort. |
| 9 | if ( ! defined( 'WPINC' ) ) { |
| 10 | die; |
| 11 | } |
| 12 | |
| 13 | trait Base_Attributes_Trait { |
| 14 | |
| 15 | /** |
| 16 | * Add attribute |
| 17 | * |
| 18 | * @param $attr |
| 19 | * @param null $value |
| 20 | */ |
| 21 | abstract public function add_attribute( $attr, $value = null ); |
| 22 | |
| 23 | /** |
| 24 | * Reset attributes array |
| 25 | */ |
| 26 | abstract public function reset_attributes(); |
| 27 | |
| 28 | abstract public function get_all_attrs(); |
| 29 | |
| 30 | /** |
| 31 | * Render current attributes string |
| 32 | * |
| 33 | * @return void |
| 34 | */ |
| 35 | public function render_attributes_string() { |
| 36 | $this->render_attributes_string_save(); |
| 37 | $this->reset_attributes(); |
| 38 | } |
| 39 | |
| 40 | public function render_attributes_string_save() { |
| 41 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 42 | echo Tools::esc_template_string( $this->get_attributes_string_save() ); |
| 43 | } |
| 44 | |
| 45 | public function get_attributes_string_save() { |
| 46 | $response = ''; |
| 47 | $attrs = $this->get_all_attrs(); |
| 48 | |
| 49 | if ( $this instanceof Base ) { |
| 50 | $attrs = apply_filters( |
| 51 | "jet-form-builder/render/{$this->get_name()}/attributes", |
| 52 | $attrs, |
| 53 | $this |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | foreach ( $attrs as $attr => $value ) { |
| 58 | if ( is_array( $value ) ) { |
| 59 | $value = implode( ' ', $value ); |
| 60 | } |
| 61 | $response .= sprintf( ' %1$s="%2$s"', $attr, esc_attr( $value ) ); |
| 62 | } |
| 63 | |
| 64 | return $response; |
| 65 | } |
| 66 | |
| 67 | public function get_attributes_string() { |
| 68 | $response = $this->get_attributes_string_save(); |
| 69 | $this->reset_attributes(); |
| 70 | |
| 71 | return $response; |
| 72 | } |
| 73 | |
| 74 | } |
| 75 |