PluginProbe
BeyondWords – AI audio for publishers / 4.0.0
BeyondWords – AI audio for publishers v4.0.0
7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.7.0 All 43 releases
speechkit / src / Component / Post / BlockAttributes / addAttributes.js

addAttributes.js in BeyondWords – AI audio for publishers 4.0.0, at src/Component/Post/BlockAttributes/addAttributes.js

65 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress Dependencies
3 */
4 import { addFilter } from '@wordpress/hooks';
5
6 /**
7 * External dependencies
8 */
9 import getBlockMarkerAttribute from './helpers/getBlockMarkerAttribute';
10
11 /**
12 * Register custom block attributes for BeyondWords.
13 *
14 * @param {Object} settings Settings for the block.
15 *
16 * @return {Object} settings Modified settings.
17 */
18 function addAttributes( settings ) {
19 if ( typeof settings.attributes !== 'undefined' ) {
20 settings.attributes = {
21 ...settings.attributes,
22 beyondwordsAudio: {
23 type: 'boolean',
24 default: true,
25 },
26 beyondwordsMarker: {
27 type: 'string',
28 default: '',
29 },
30 };
31 }
32
33 return settings;
34 }
35
36 addFilter(
37 'blocks.registerBlockType',
38 'beyondwords/beyondwords-block-attributes',
39 addAttributes
40 );
41
42 /**
43 * Set a unique BeyondWords marker for each block that doesn't already have one.
44 *
45 * @param {Object} attributes Attributes for the block.
46 *
47 * @return {Object} attributes Modified attributes.
48 */
49 function setMarkerAttribute( attributes ) {
50 const marker = getBlockMarkerAttribute( attributes );
51
52 attributes = {
53 ...attributes,
54 beyondwordsMarker: marker,
55 };
56
57 return attributes;
58 }
59
60 addFilter(
61 'blocks.getBlockAttributes',
62 'beyondwords/set-marker-attribute',
63 setMarkerAttribute
64 );
65