После многих попыток и ошибок я получил свое решение.
wp.hooks.addFilter(
"blocks.registerBlockType",
"sample-plugin/plugin/attribute/data",
(settings, name) => {
if (name == "core/image") {
settings.attributes = Object.assign( settings.attributes, {
'data-id': {
attribute: "data-id",
selector: "figure > a",
source: "attribute",
type: "string",
},
});
}
return settings;
}
);
function applyExtraClass( extraProps, blockType, attributes ) {
if(blockType.name != 'core/image') {
return extraProps;
}
try {
let figure_props = extraProps.children.props;
let first_child = figure_props.children[0];
if(figure_props.children && first_child && (first_child.type == 'a')) {
first_child.props['data-id'] = attributes["data-id"];
}
} catch (error) {
console.log(error);
}
return extraProps;
}
wp.hooks.addFilter(
'blocks.getSaveContent.extraProps',
'sample-plugin/plugin',
applyExtraClass
);