block-embedpress.php
36 lines
| 1 | <?php |
| 2 | // Exit if accessed directly. |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | /** |
| 7 | * It renders gutenberg block of embedpress on the frontend |
| 8 | * @param array $attributes |
| 9 | */ |
| 10 | function embedpress_render_block($attributes){ |
| 11 | if ( !empty( $attributes['embedHTML']) ) { |
| 12 | $embed = apply_filters( 'embedpress_gutenberg_embed', $attributes['embedHTML'], $attributes ); |
| 13 | $aligns = [ |
| 14 | 'left' => 'alignleft', |
| 15 | 'right' => 'alignright', |
| 16 | 'wide' => 'alignwide', |
| 17 | 'full' => 'alignfull', |
| 18 | 'center' => 'aligncenter', |
| 19 | ]; |
| 20 | if ( isset($attributes['align']) ) { |
| 21 | $alignment = isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] .' clear' : ''; |
| 22 | }else{ |
| 23 | $alignment = 'aligncenter'; // default alignment is center in js, so keeping same here |
| 24 | } |
| 25 | ob_start(); |
| 26 | ?> |
| 27 | <div class="embedpress-gutenberg-wrapper"> |
| 28 | <div class="wp-block-embed__wrapper <?php echo esc_attr($alignment) ?>"> |
| 29 | <?php echo $embed; ?> |
| 30 | </div> |
| 31 | </div> |
| 32 | <?php |
| 33 | return ob_get_clean(); |
| 34 | } |
| 35 | } |
| 36 |