| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Modules\Templating\Bricks\Elements; |
| 4 |
|
| 5 |
use Bricks\Element; |
| 6 |
use Bricks\Helpers; |
| 7 |
use FluentCart\App\CPT\FluentProducts; |
| 8 |
use FluentCart\App\Services\URL; |
| 9 |
|
| 10 |
class ProductContent extends Element |
| 11 |
{ |
| 12 |
public $category = 'fluent_cart_product'; |
| 13 |
public $name = 'fct-product-content'; |
| 14 |
public $icon = 'ti-wordpress'; |
| 15 |
|
| 16 |
public function get_label() |
| 17 |
{ |
| 18 |
return esc_html__('Product content', 'fluent-cart'); |
| 19 |
} |
| 20 |
|
| 21 |
public function set_controls() |
| 22 |
{ |
| 23 |
$edit_link = Helpers::get_preview_post_link( get_the_ID() ); |
| 24 |
$label = esc_html__('Edit product content in FluentCart.', 'fluent-cart'); |
| 25 |
|
| 26 |
$this->controls['info'] = [ |
| 27 |
'tab' => 'content', |
| 28 |
'type' => 'info', |
| 29 |
'content' => $edit_link ? '<a href="' . esc_url($edit_link) . '" target="_blank">' . $label . '</a>' : $label, |
| 30 |
]; |
| 31 |
} |
| 32 |
|
| 33 |
public function render() |
| 34 |
{ |
| 35 |
$settings = $this->settings; |
| 36 |
|
| 37 |
$product = get_post($this->post_id); |
| 38 |
|
| 39 |
if (empty($product) || $product->post_type !== FluentProducts::CPT_NAME) { |
| 40 |
return $this->render_element_placeholder( |
| 41 |
[ |
| 42 |
'title' => esc_html__('For better preview select content to show.', 'fluent-cart'), |
| 43 |
'description' => esc_html__('Go to: Settings > Template Settings > Populate Content', 'fluent-cart'), |
| 44 |
] |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
$content = get_post_field('post_content', $this->post_id); |
| 49 |
|
| 50 |
if (!$content) { |
| 51 |
return $this->render_element_placeholder( |
| 52 |
[ |
| 53 |
'title' => esc_html__('Product content is empty.', 'fluent-cart'), |
| 54 |
] |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
$content = $this->render_dynamic_data($content); |
| 59 |
$content = Helpers::parse_editor_content($content); |
| 60 |
$content = str_replace(']]>', ']]>', $content); |
| 61 |
|
| 62 |
echo "<div {$this->render_attributes( '_root' )}>" . wp_kses_post($content) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- render_attributes() handles escaping |
| 63 |
} |
| 64 |
} |
| 65 |
|