ShortcodesBlockConversionService.php
2 years ago
ShortcodesService.php
2 years ago
ShortcodesServiceProvider.php
2 years ago
ShortcodesBlockConversionService.php
59 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\WordPress\Shortcodes; |
| 4 | |
| 5 | class ShortcodesBlockConversionService { |
| 6 | /** |
| 7 | * Holds the attributes. |
| 8 | * |
| 9 | * @var array |
| 10 | */ |
| 11 | protected $attributes = []; |
| 12 | |
| 13 | /** |
| 14 | * Holds the content. |
| 15 | * |
| 16 | * @var string |
| 17 | */ |
| 18 | protected $content = ''; |
| 19 | |
| 20 | /** |
| 21 | * Get things going |
| 22 | * |
| 23 | * @param array $attributes Attributes. |
| 24 | * @param string $content Content. |
| 25 | */ |
| 26 | public function __construct( $attributes, $content ) { |
| 27 | $this->attributes = $attributes; |
| 28 | $this->content = $content; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Convert the block |
| 33 | * |
| 34 | * @param string $name Block name. |
| 35 | * @param string $block Block class. |
| 36 | * @param array $defaults Default attributes. |
| 37 | * |
| 38 | * @return string |
| 39 | */ |
| 40 | public function convert( $name, $block, $defaults = [] ) { |
| 41 | |
| 42 | $attributes = shortcode_atts( |
| 43 | $defaults, |
| 44 | $this->attributes, |
| 45 | $name |
| 46 | ); |
| 47 | |
| 48 | return apply_filters( |
| 49 | 'surecart/shortcode/render', |
| 50 | ( new $block() )->render( |
| 51 | $attributes, |
| 52 | do_shortcode( $this->content ) |
| 53 | ), |
| 54 | $attributes, |
| 55 | $name |
| 56 | ); |
| 57 | } |
| 58 | } |
| 59 |