PluginProbe
BeyondWords – AI audio for publishers / 4.2.4
BeyondWords – AI audio for publishers v4.2.4
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.2.4, at src/Component/Post/BlockAttributes/addAttributes.js

66 lines 1.3 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 * @since 4.0.4 Remove settings.attributes undefined check, to match official docs.
15 *
16 * @param {Object} settings Settings for the block.
17 *
18 * @return {Object} settings Modified settings.
19 */
20 function addAttributes( settings ) {
21 return {
22 ...settings,
23 attributes: {
24 ...settings.attributes,
25 beyondwordsAudio: {
26 type: 'boolean',
27 default: true,
28 },
29 beyondwordsMarker: {
30 type: 'string',
31 default: '',
32 },
33 },
34 };
35 }
36
37 addFilter(
38 'blocks.registerBlockType',
39 'beyondwords/beyondwords-block-attributes',
40 addAttributes
41 );
42
43 /**
44 * Set a unique BeyondWords marker for each block that doesn't already have one.
45 *
46 * @param {Object} attributes Attributes for the block.
47 *
48 * @return {Object} attributes Modified attributes.
49 */
50 function setMarkerAttribute( attributes ) {
51 const marker = getBlockMarkerAttribute( attributes );
52
53 attributes = {
54 ...attributes,
55 beyondwordsMarker: marker,
56 };
57
58 return attributes;
59 }
60
61 addFilter(
62 'blocks.getBlockAttributes',
63 'beyondwords/set-marker-attribute',
64 setMarkerAttribute
65 );
66