Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
19 / 19 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| BlockAttributes | |
100.00% |
18 / 18 |
|
100.00% |
3 / 3 |
7 | |
100.00% |
1 / 1 |
| init | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| registerAudioAttribute | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| registerMarkerAttribute | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * BeyondWords support for Gutenberg blocks. |
| 7 | * |
| 8 | * @package Beyondwords\Wordpress |
| 9 | * @author Stuart McAlpine <stu@beyondwords.io> |
| 10 | * @since 3.7.0 |
| 11 | * @since 4.0.0 Renamed from BlockAudioAttribute.php to BlockAttributes.php to support multiple attributes |
| 12 | */ |
| 13 | |
| 14 | namespace Beyondwords\Wordpress\Component\Post\BlockAttributes; |
| 15 | |
| 16 | /** |
| 17 | * BlockAttributes |
| 18 | * |
| 19 | * @since 3.7.0 |
| 20 | * @since 4.0.0 Renamed from BlockAudioAttribute to BlockAttributes to support multiple attributes. |
| 21 | * @since 6.0.0 Stop adding beyondwordsMarker attribute to blocks. |
| 22 | */ |
| 23 | defined('ABSPATH') || exit; |
| 24 | |
| 25 | class BlockAttributes |
| 26 | { |
| 27 | /** |
| 28 | * Init. |
| 29 | * |
| 30 | * @since 4.0.0 |
| 31 | * @since 6.0.0 Make static and remove renderBlock registration. |
| 32 | */ |
| 33 | public static function init() |
| 34 | { |
| 35 | add_filter('register_block_type_args', [self::class, 'registerAudioAttribute']); |
| 36 | add_filter('register_block_type_args', [self::class, 'registerMarkerAttribute']); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Register "Audio" attribute for Gutenberg blocks. |
| 41 | * |
| 42 | * @since 6.0.0 Make static. |
| 43 | */ |
| 44 | public static function registerAudioAttribute($args) |
| 45 | { |
| 46 | // Setup attributes if needed. |
| 47 | if (! isset($args['attributes'])) { |
| 48 | $args['attributes'] = []; |
| 49 | } |
| 50 | |
| 51 | if (! array_key_exists('beyondwordsAudio', $args['attributes'])) { |
| 52 | $args['attributes']['beyondwordsAudio'] = [ |
| 53 | 'type' => 'boolean', |
| 54 | 'default' => true, |
| 55 | ]; |
| 56 | } |
| 57 | |
| 58 | return $args; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Register "Segment marker" attribute for Gutenberg blocks. |
| 63 | * |
| 64 | * @deprecated This attribute is no longer used as of 6.0.0, but kept for backward compatibility. |
| 65 | * |
| 66 | * @since 6.0.0 Make static. |
| 67 | */ |
| 68 | public static function registerMarkerAttribute($args) |
| 69 | { |
| 70 | // Setup attributes if needed. |
| 71 | if (! isset($args['attributes'])) { |
| 72 | $args['attributes'] = []; |
| 73 | } |
| 74 | |
| 75 | if (! array_key_exists('beyondwordsMarker', $args['attributes'])) { |
| 76 | $args['attributes']['beyondwordsMarker'] = [ |
| 77 | 'type' => 'string', |
| 78 | 'default' => '', |
| 79 | ]; |
| 80 | } |
| 81 | |
| 82 | return $args; |
| 83 | } |
| 84 | } |