ShortcodesBlockConversionService.php
3 years ago
ShortcodesService.php
3 years ago
ShortcodesServiceProvider.php
3 years ago
ShortcodesService.php
33 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\WordPress\Shortcodes; |
| 4 | |
| 5 | /** |
| 6 | * The shortcodes service. |
| 7 | */ |
| 8 | class ShortcodesService { |
| 9 | /** |
| 10 | * Convert the block |
| 11 | * |
| 12 | * @param string $name Block name. |
| 13 | * @param string $block Block class. |
| 14 | * @param array $defaults Default attributes. |
| 15 | * |
| 16 | * @return string |
| 17 | */ |
| 18 | public function registerBlockShortcode( $name, $class, $defaults = [] ) { |
| 19 | add_shortcode( |
| 20 | $name, |
| 21 | function( $attributes, $content ) use ( $name, $class, $defaults ) { |
| 22 | return ( new ShortcodesBlockConversionService( $attributes, $content ) )->convert( |
| 23 | $name, |
| 24 | $class, |
| 25 | $defaults |
| 26 | ); |
| 27 | }, |
| 28 | 10, |
| 29 | 2 |
| 30 | ); |
| 31 | } |
| 32 | } |
| 33 |