Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blocks.getSaveElement example usage #26228

Closed
wants to merge 1 commit into from
Closed

Conversation

shramee
Copy link
Contributor

@shramee shramee commented Oct 16, 2020

Happened to need this for my project so thought I'd add example for this.

I have tested the ES5 version and adapted ESX from that.

var el = wp.element.createElement;

function addCodeElement( element, blockType, attributes ) {
	if ( blockType.name !== "core/paragraph" ) {
		return element;
	}
	return wp.element.cloneElement(
		// The saved element
		element,
		// Overwrite props here
		{},
		// Original content (children)
		element.props.children,
		// Any additional content
		el( 'code', {}, 'My code' )
	);
};
wp.hooks.addFilter(
	'blocks.getSaveContent.extraProps',
	'my-plugin/add-code-element',
	addCodeElement
);

Old PR #8470

Description

Example usage for blocks.getSaveElement hook.

How has this been tested?

Tested locally with a cover block.

Types of changes

Code examples added in markdown file.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

Happened to need this for my project so thought I'd add example for this...
Old PR WordPress#8470
@gziolo gziolo added [Type] Developer Documentation Documentation for developers [Feature] Extensibility The ability to extend blocks or the editing experience labels Nov 8, 2020
Base automatically changed from master to trunk March 1, 2021 15:44
@shramee shramee closed this Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants