← All changes
|
app/Modules/Templating/Bricks/Elements/ProductTitle.php
+47
-30
1.3.21
→
1.6.6
View file →
| @@ -5,15 +5,15 @@ | ||
| 5 | 5 | |
| 6 | 6 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 7 | 7 | |
| 8 | 8 | class ProductTitle extends Element { |
| 9 | - public $category = 'fluent_cart_product'; | |
| 9 | + public $category = 'fluent-cart'; | |
| 10 | 10 | public $name = 'fct-product-title'; |
| 11 | - public $icon = 'ti-text'; | |
| 11 | + public $icon = 'ti-text fluent-cart-element-icon'; | |
| 12 | 12 | public $tag = 'h1'; |
| 13 | 13 | |
| 14 | 14 | public function get_label() { |
| 15 | - return esc_html__( 'Product title (FluentCart)', 'fluent-cart' ); | |
| 15 | + return esc_html__( 'Product Title', 'fluent-cart' ); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | public function set_controls() { |
| 19 | 19 | $this->controls['tag'] = [ |
| @@ -68,42 +68,59 @@ | ||
| 68 | 68 | 'type' => 'checkbox', |
| 69 | 69 | ]; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public function render() { | |
| 72 | + public function render() | |
| 73 | + { | |
| 73 | 74 | $settings = $this->settings; |
| 75 | + $post = get_post($this->post_id); | |
| 74 | 76 | |
| 77 | + $prefix = !empty($settings['prefix']) ? $settings['prefix'] : false; | |
| 78 | + $suffix = !empty($settings['suffix']) ? $settings['suffix'] : false; | |
| 79 | + $linkToProduct = isset($settings['linkToProduct']); | |
| 75 | 80 | |
| 76 | - $prefix = ! empty( $settings['prefix'] ) ? $settings['prefix'] : false; | |
| 77 | - $suffix = ! empty( $settings['suffix'] ) ? $settings['suffix'] : false; | |
| 78 | - $link_to_product = isset( $settings['linkToProduct'] ); | |
| 79 | - $output = ''; | |
| 81 | + ?> | |
| 82 | + <?php | |
| 83 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- render_attributes() handles escaping internally | |
| 84 | + echo "<" . esc_html($this->tag) . " " . $this->render_attributes('_root') . ">"; | |
| 85 | + ?> | |
| 86 | + <?php if ($linkToProduct) : ?> | |
| 87 | + <a href="<?php echo esc_url(get_the_permalink($this->post_id)); ?>"> | |
| 88 | + <?php endif; ?> | |
| 80 | 89 | |
| 81 | - if ( $link_to_product ) { | |
| 82 | - $output .= '<a href="' . get_the_permalink( $this->post_id ) . '">'; | |
| 83 | - } | |
| 90 | + <?php if ($prefix) : ?> | |
| 91 | + <?php $this->set_attribute('prefix', 'class', ['post-prefix']); ?> | |
| 92 | + <?php if (isset($settings['prefixBlock'])) : ?> | |
| 93 | + <div <?php echo $this->render_attributes('prefix'); ?>> | |
| 94 | + <?php echo wp_kses_post($prefix); ?> | |
| 95 | + </div> | |
| 96 | + <?php else : ?> | |
| 97 | + <span <?php echo $this->render_attributes('prefix'); ?>> | |
| 98 | + <?php echo wp_kses_post($prefix); ?> | |
| 99 | + </span> | |
| 100 | + <?php endif; ?> | |
| 101 | + <?php endif; ?> | |
| 84 | 102 | |
| 85 | - if ( $prefix ) { | |
| 86 | - $this->set_attribute( 'prefix', 'class', [ 'post-prefix' ] ); | |
| 103 | + <span><?php echo esc_html($post->post_title); ?></span> | |
| 87 | 104 | |
| 88 | - $output .= isset( $settings['prefixBlock'] ) ? "<div {$this->render_attributes( 'prefix' )}>{$prefix}</div>" : "<span {$this->render_attributes( 'prefix' )}>{$prefix}</span>"; | |
| 89 | - } | |
| 105 | + <?php if ($suffix) : ?> | |
| 106 | + <?php $this->set_attribute('suffix', 'class', ['post-suffix']); ?> | |
| 107 | + <?php if (isset($settings['suffixBlock'])) : ?> | |
| 108 | + <div <?php echo $this->render_attributes('suffix'); ?>> | |
| 109 | + <?php echo wp_kses_post($suffix); ?> | |
| 110 | + </div> | |
| 111 | + <?php else : ?> | |
| 112 | + <span <?php echo $this->render_attributes('suffix'); ?>> | |
| 113 | + <?php echo wp_kses_post($suffix); ?> | |
| 114 | + </span> | |
| 115 | + <?php endif; ?> | |
| 116 | + <?php endif; ?> | |
| 90 | 117 | |
| 91 | - $post = get_post( $this->post_id ); | |
| 92 | - | |
| 93 | - $output .= $post->post_title; | |
| 94 | - | |
| 95 | - if ( $suffix ) { | |
| 96 | - $this->set_attribute( 'suffix', 'class', [ 'post-suffix' ] ); | |
| 97 | - | |
| 98 | - $output .= isset( $settings['suffixBlock'] ) ? "<div {$this->render_attributes( 'suffix' )}>{$suffix}</div>" : "<span {$this->render_attributes( 'suffix' )}>{$suffix}</span>"; | |
| 99 | - } | |
| 100 | - | |
| 101 | - if ( $link_to_product ) { | |
| 102 | - $output .= '</a>'; | |
| 103 | - } | |
| 104 | - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- render_attributes() handles escaping, output is escaped | |
| 105 | - echo "<" . esc_html($this->tag) . " {$this->render_attributes( '_root' )}>" . wp_kses_post($output) . "</" . esc_html($this->tag) . ">"; | |
| 118 | + <?php if ($linkToProduct) : ?> | |
| 119 | + </a> | |
| 120 | + <?php endif; ?> | |
| 121 | + <?php echo "</" . esc_html($this->tag) . ">"; ?> | |
| 122 | + <?php | |
| 106 | 123 | } |
| 107 | 124 | |
| 108 | 125 | public static function render_builder() { ?> |
| 109 | 126 | <script type="text/x-template" id="tmpl-brxe-product-title"> |