Add function_exists() check to block PHP template#147
Add function_exists() check to block PHP template#147schlessera merged 1 commit intowp-cli:masterfrom salcode:sf/function-exists-146
Conversation
|
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. |
There was a problem hiding this comment.
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.
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
|
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.
Thanks. |
|
Thanks for the pull request, @salcode ! |
Add function_exists() check to block PHP template
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