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

Extending blocks PHP API #9901

Closed
nk-o opened this issue Sep 14, 2018 · 2 comments
Closed

Extending blocks PHP API #9901

nk-o opened this issue Sep 14, 2018 · 2 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Extensibility The ability to extend blocks or the editing experience [Type] Enhancement A suggestion for improvement.

Comments

@nk-o
Copy link
Contributor

nk-o commented Sep 14, 2018

Currently, we have an API for extending blocks using JS. It is ok. But we also need API on the backend to extend dynamic blocks.

For example, I have the plugin, that extends all core blocks and adds custom attribute and class in output using this filter blocks.getSaveContent.extraProps. Everything works fine with static blocks, but not with dynamic (for ex. Latest Posts block).

function addSaveProps( extraProps ) {
    extraProps.className = ( extraProps.className || '' ) + ' test-class';
    extraProps['data-test-attribure'] = 'test-attribute';
    return extraProps;
}

addFilter( 'blocks.getSaveContent.extraProps', 'test/extra-props', addSaveProps );

Tried to change attributes argument in blocks.getSaveElement filter, but also no luck.

Plus my plugin adds additional attributes to the blocks using filter blocks.registerBlockType:

function addAttribute( blockSettings ) {

    blockSettings.attributes.testAdditionalClass = {
        type: 'string',
        default: '',
    };

    return blockSettings;
}
addFilter( 'blocks.registerBlockType', 'test/additional-attributes', addAttribute );

p.s. all code example simplified just for demonstration. Full extensions code here - https://github.com/nk-o/ghostkit/blob/master/src/blocks/_extend/styles.jsx#L138-L9999

@Soean Soean added [Type] Enhancement A suggestion for improvement. [Feature] Block API API that allows to express the block paradigm. [Feature] Extensibility The ability to extend blocks or the editing experience labels Sep 14, 2018
@mtias
Copy link
Member

mtias commented Oct 7, 2018

#8352

@mtias
Copy link
Member

mtias commented Oct 7, 2018

Consolidating with #6494.

@mtias mtias closed this as completed Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Extensibility The ability to extend blocks or the editing experience [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants