| 1 |
<?php |
| 2 |
namespace ABlocks\Frontend\DynamicContent\Interpreters; |
| 3 |
|
| 4 |
use ABlocks\Helper; |
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
class Shortcode extends Abstracts\Interpreter { |
| 9 |
protected string $shortcode; |
| 10 |
protected string $pre; |
| 11 |
protected string $post; |
| 12 |
protected string $default; |
| 13 |
|
| 14 |
public function __construct( string $name, array $setting, bool $is_richtext = false ) { |
| 15 |
parent::__construct( $name, $setting, $is_richtext ); |
| 16 |
$this->shortcode = strval( $this->setting[0] ?? '' ); |
| 17 |
$this->pre = strval( $this->setting[3] ?? '' ); |
| 18 |
$this->post = strval( $this->setting[4] ?? '' ); |
| 19 |
$this->default = strval( $this->setting[5] ?? '' ); |
| 20 |
} |
| 21 |
public function content() : string { |
| 22 |
$this->content = do_shortcode( $this->shortcode ); |
| 23 |
return $this->pre . ( $this->content === '' ? $this->default : $this->content ) . $this->post; |
| 24 |
} |
| 25 |
public function req_param_value( array $params ) : string { |
| 26 |
return sanitize_text_field( $params[ $this->param ] ?? '' ); |
| 27 |
} |
| 28 |
} |
| 29 |
|