From f0f8eb3a8fa789aa9c5c28794db14129042ffbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Sat, 18 May 2019 11:38:04 +0200 Subject: [PATCH 1/4] Add register block functions to forbidden functions sniff --- .../ForbiddenFunctionsSniff.php | 10 ++++++++ .../ForbiddenFunctionsUnitTest.inc | 24 +++++++++++++++++++ .../ForbiddenFunctionsUnitTest.php | 20 ++++++++++++---- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php b/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php index 56eccea8..73a7c327 100644 --- a/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php +++ b/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php @@ -44,6 +44,16 @@ public function getGroups() { 'add_shortcode', 'register_taxonomy_for_object_type', 'flush_rewrite_rules', + 'register_block_type', + 'unregister_block_type', + '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', ), ), ); diff --git a/WPThemeReview/Tests/PluginTerritory/ForbiddenFunctionsUnitTest.inc b/WPThemeReview/Tests/PluginTerritory/ForbiddenFunctionsUnitTest.inc index c30bc3b7..09df6daa 100644 --- a/WPThemeReview/Tests/PluginTerritory/ForbiddenFunctionsUnitTest.inc +++ b/WPThemeReview/Tests/PluginTerritory/ForbiddenFunctionsUnitTest.inc @@ -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. diff --git a/WPThemeReview/Tests/PluginTerritory/ForbiddenFunctionsUnitTest.php b/WPThemeReview/Tests/PluginTerritory/ForbiddenFunctionsUnitTest.php index 2c06081b..2c56d735 100644 --- a/WPThemeReview/Tests/PluginTerritory/ForbiddenFunctionsUnitTest.php +++ b/WPThemeReview/Tests/PluginTerritory/ForbiddenFunctionsUnitTest.php @@ -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, ); } From 96e02e29b3195a09815f6076b3135ae4777dde4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Sat, 18 May 2019 11:40:35 +0200 Subject: [PATCH 2/4] Update docblock with version number indicating change --- WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php | 1 + 1 file changed, 1 insertion(+) diff --git a/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php b/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php index 73a7c327..a4acacf0 100644 --- a/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php +++ b/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php @@ -16,6 +16,7 @@ * * @link https://make.wordpress.org/themes/handbook/review/required/#presentation-vs-functionality * + * @since 0.2.0 Updated the list of forbidden functions. * @since 0.1.0 */ class ForbiddenFunctionsSniff extends AbstractFunctionRestrictionsSniff { From c0d9ec772db3aaa23c3bcb13850efa233b61f13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Mon, 20 May 2019 11:25:15 +0200 Subject: [PATCH 3/4] Update the sniff --- .../ForbiddenFunctionsSniff.php | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php b/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php index a4acacf0..1491a3ed 100644 --- a/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php +++ b/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php @@ -16,8 +16,8 @@ * * @link https://make.wordpress.org/themes/handbook/review/required/#presentation-vs-functionality * - * @since 0.2.0 Updated the list of forbidden functions. * @since 0.1.0 + * @since 0.2.0 Updated the list of forbidden functions. */ class ForbiddenFunctionsSniff extends AbstractFunctionRestrictionsSniff { @@ -45,16 +45,15 @@ public function getGroups() { 'add_shortcode', 'register_taxonomy_for_object_type', 'flush_rewrite_rules', - 'register_block_type', - 'unregister_block_type', - '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', + ), + ), + + 'editor-blocks' => array( + 'type' => 'error', + 'message' => 'Registering and deregistering editor blocks should be done in a plugin, not in the theme. Found %s().', + 'functions' => array( + 'register_block_*', + 'unregister_block_*', ), ), ); From e766263dce856629f18660b6617f2a9777bc9098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Mon, 20 May 2019 14:06:01 +0200 Subject: [PATCH 4/4] Fix minor PR issues --- .../Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php b/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php index 1491a3ed..4e49d15b 100644 --- a/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php +++ b/WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php @@ -17,7 +17,7 @@ * @link https://make.wordpress.org/themes/handbook/review/required/#presentation-vs-functionality * * @since 0.1.0 - * @since 0.2.0 Updated the list of forbidden functions. + * @since 0.2.0 Added the `editor-blocks` group. */ class ForbiddenFunctionsSniff extends AbstractFunctionRestrictionsSniff { @@ -50,7 +50,7 @@ public function getGroups() { 'editor-blocks' => array( 'type' => 'error', - 'message' => 'Registering and deregistering editor blocks should be done in a plugin, not in the theme. Found %s().', + 'message' => 'Registering and deregistering editor blocks should be done in a plugin, not in a theme. Found %s().', 'functions' => array( 'register_block_*', 'unregister_block_*',