PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5.2
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5.2
3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 All 130 releases
jetformbuilder / includes / classes / base-attributes-trait.php
base-attributes-trait.php
75 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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