Skip to content

Add function_exists() check to block PHP template#147

Merged
schlessera merged 1 commit intowp-cli:masterfrom
salcode:sf/function-exists-146
May 8, 2018
Merged

Add function_exists() check to block PHP template#147
schlessera merged 1 commit intowp-cli:masterfrom
salcode:sf/function-exists-146

Conversation

@salcode
Copy link
Copy Markdown
Contributor

@salcode salcode commented Apr 22, 2018

Check for the existance of the function register_block_type() in the PHP
code when creating a block.

Since Gutenberg has not yet been merged into core, currently the function
register_block_type() is only defined if the Gutenberg plugin is installed
and activated.

See #146

@salcode
Copy link
Copy Markdown
Contributor Author

salcode commented Apr 22, 2018

Reading through the existing Behat tests for blocks, it looks like checks for specific lines of code are only being done on lines that are dynamic (i.e. there is a placeholder that gets replaced). Based on this, I have not added any tests for this change.

If I've misunderstood things, please let me know and I'd be happy to update this PR.

Thanks.

Copy link
Copy Markdown
Member

@schlessera schlessera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think there's no need to add a test for this.

However, given that this is not usual practice, and that the scaffolding tools often serve an educational purpose as well, I'd prefer to have a comment before the function_exists(), along the lines of:

// Skip block registration in case Gutenberg is not enabled/merged.

@schlessera schlessera added the command:scaffold-block Related to 'scaffold block' command label May 8, 2018
Check for the existance of the function register_block_type() in the PHP
code when creating a block.

Since Gutenberg has not yet been merged into core, currently the function
register_block_type() is only defined if the Gutenberg plugin is installed
and activated.

See #146
@salcode
Copy link
Copy Markdown
Contributor Author

salcode commented May 8, 2018

@schlessera

Thanks for the feedback. You make a good point that we should call out why this code is included.

I've updated this PR with the following comment as you suggested.

// Skip block registration if Gutenberg is not enabled/merged.

Thanks.

@schlessera schlessera added this to the 1.1.4 milestone May 8, 2018
@schlessera
Copy link
Copy Markdown
Member

Thanks for the pull request, @salcode !

@schlessera schlessera merged commit 7a9b881 into wp-cli:master May 8, 2018
danielbachhuber pushed a commit that referenced this pull request Nov 18, 2022
Add function_exists() check to block PHP template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:scaffold-block Related to 'scaffold block' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants