Skip to content

Commit

Permalink
Merge pull request #215 from WPTRT/feature/update-forbidden-functions…
Browse files Browse the repository at this point in the history
…-sniff

Add register block functions to forbidden functions sniff
  • Loading branch information
jrfnl authored May 20, 2019
2 parents 438f350 + e766263 commit 2ed0efc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
10 changes: 10 additions & 0 deletions WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @link https://make.wordpress.org/themes/handbook/review/required/#presentation-vs-functionality
*
* @since 0.1.0
* @since 0.2.0 Added the `editor-blocks` group.
*/
class ForbiddenFunctionsSniff extends AbstractFunctionRestrictionsSniff {

Expand Down Expand Up @@ -46,6 +47,15 @@ public function getGroups() {
'flush_rewrite_rules',
),
),

'editor-blocks' => array(
'type' => 'error',
'message' => 'Registering and deregistering editor blocks should be done in a plugin, not in a theme. Found %s().',
'functions' => array(
'register_block_*',
'unregister_block_*',
),
),
);
}

Expand Down
24 changes: 24 additions & 0 deletions WPThemeReview/Tests/PluginTerritory/ForbiddenFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ register_taxonomy( 'mytaxonomy', 'myposttype' );
add_shortcode( 'myshortcode' , 'myshortcode_function' );
register_taxonomy_for_object_type( 'category', 'page' );
flush_rewrite_rules( false );
register_block_type( 'my_namespace/my_block', [
'render_callback' => 'render_callback',
'attributes' => [
'some_string' => [
'default' => 'default string',
'type' => 'string'
],
'some_array' => [
'type' => 'array',
'items' => [
'type' => 'string',
],
]
]
] );
unregister_block_type( 'my_namespace/my_block' );
register_block_core_rss();
register_block_core_search();
register_block_core_archives();
register_block_core_calendar();
register_block_core_shortcode();
register_block_core_tag_cloud();
register_block_core_categories();
register_block_core_latest_posts();

xyz_add_shortcode(); // OK.
My_Plugin_Class::add_shortcode(); // OK.
Expand Down
20 changes: 15 additions & 5 deletions WPThemeReview/Tests/PluginTerritory/ForbiddenFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,21 @@ class ForbiddenFunctionsUnitTest extends AbstractSniffUnitTest {
*/
public function getErrorList() {
return array(
3 => 1,
4 => 1,
5 => 1,
6 => 1,
7 => 1,
3 => 1,
4 => 1,
5 => 1,
6 => 1,
7 => 1,
8 => 1,
23 => 1,
24 => 1,
25 => 1,
26 => 1,
27 => 1,
28 => 1,
29 => 1,
30 => 1,
31 => 1,
);
}

Expand Down

0 comments on commit 2ed0efc

Please sign in to comment.