class-block.php
1 year ago
class-button-container.php
2 years ago
class-button.php
2 years ago
class-container.php
2 years ago
class-element.php
1 year ago
class-grid.php
2 years ago
class-headline.php
2 years ago
class-image.php
2 years ago
class-loop-item.php
1 year ago
class-looper.php
1 year ago
class-media.php
1 year ago
class-query-loop.php
3 years ago
class-query-no-results.php
1 year ago
class-query-page-numbers.php
1 year ago
class-query.php
1 year ago
class-shape.php
1 year ago
class-text.php
1 year ago
class-block.php
70 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Handles block functionality. |
| 4 | * |
| 5 | * @package GenerateBlocks |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; // Exit if accessed directly. |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * The Block class. |
| 14 | */ |
| 15 | class GenerateBlocks_Block { |
| 16 | /** |
| 17 | * Keep track of all blocks of this type on the page. |
| 18 | * |
| 19 | * @var array $block_ids The current block id. |
| 20 | */ |
| 21 | protected static $block_ids = []; |
| 22 | |
| 23 | /** |
| 24 | * Store our block ID in memory. |
| 25 | * |
| 26 | * @param string $id The block ID to store. |
| 27 | */ |
| 28 | public static function store_block_id( $id ) { |
| 29 | static::$block_ids[] = $id; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Check if our block ID exists. |
| 34 | * |
| 35 | * @param string $id The block ID to check. |
| 36 | */ |
| 37 | public static function block_id_exists( $id ) { |
| 38 | return in_array( $id, (array) static::$block_ids ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Render the block. |
| 43 | * |
| 44 | * @param array $attributes The block attributes. |
| 45 | * @param string $block_content The block content. |
| 46 | * @param array $block The block. |
| 47 | */ |
| 48 | public static function render_block( $attributes, $block_content, $block ) { |
| 49 | return $block_content; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get the block CSS. |
| 54 | * |
| 55 | * @param array $attributes The block attributes. |
| 56 | */ |
| 57 | public static function get_css( $attributes ) { |
| 58 | $id = $attributes['uniqueId'] ?? ''; |
| 59 | |
| 60 | if ( ! $id ) { |
| 61 | return ''; |
| 62 | } |
| 63 | |
| 64 | // Store this block ID in memory. |
| 65 | static::store_block_id( $id ); |
| 66 | |
| 67 | return $attributes['css'] ?? ''; |
| 68 | } |
| 69 | } |
| 70 |