From 4c83c0bef449f9c73454c5283b92762e577b0761 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Fri, 16 Feb 2024 18:02:08 +0000 Subject: [PATCH] End restricting usage of get_page_by_title() In WP 6.1.0, `get_page_by_title()` was changed to use `WP_Query` internally`. See core.trac.wordpress.org/ticket/36905. This means that reporting this function as not being cached is not true anymore. Note that since WP 6.2.0, the function was reverted from using `WP_Query` but was deprecated in favour of using `WP_Query` directly. WordPress Coding Standards highlights this deprecation already. See #801. --- WordPress-VIP-Go/ruleset-test.inc | 6 +++--- WordPress-VIP-Go/ruleset-test.php | 4 ---- WordPress-VIP-Go/ruleset.xml | 4 ---- .../Sniffs/Functions/RestrictedFunctionsSniff.php | 7 ------- .../Tests/Functions/RestrictedFunctionsUnitTest.inc | 4 ++-- .../Tests/Functions/RestrictedFunctionsUnitTest.php | 1 - WordPressVIPMinimum/ruleset-test.inc | 2 +- WordPressVIPMinimum/ruleset-test.php | 1 - 8 files changed, 6 insertions(+), 23 deletions(-) diff --git a/WordPress-VIP-Go/ruleset-test.inc b/WordPress-VIP-Go/ruleset-test.inc index 4a36e262..bd7e3de6 100644 --- a/WordPress-VIP-Go/ruleset-test.inc +++ b/WordPress-VIP-Go/ruleset-test.inc @@ -130,9 +130,9 @@ get_next_post(); // Warning. get_previous_post_link(); // Warning. get_next_post_link(); // Warning. -// WordPressVIPMinimum.Functions.RestrictedFunctions.get_page_by_title_get_page_by_title -wpcom_vip_get_page_by_title(); // Ok. -get_page_by_title( $page_title ); // Warning + Message. + + + // WordPressVIPMinimum.Functions.RestrictedFunctions.get_posts_get_children get_child(); // Ok. diff --git a/WordPress-VIP-Go/ruleset-test.php b/WordPress-VIP-Go/ruleset-test.php index 053d9a86..d8701db4 100644 --- a/WordPress-VIP-Go/ruleset-test.php +++ b/WordPress-VIP-Go/ruleset-test.php @@ -154,7 +154,6 @@ 129 => 1, 130 => 1, 131 => 1, - 135 => 1, 139 => 1, 142 => 1, 146 => 1, @@ -304,9 +303,6 @@ 123 => [ 'attachment_url_to_postid() is uncached, please use wpcom_vip_attachment_url_to_postid() instead.', ], - 135 => [ - 'get_page_by_title() is uncached, please use wpcom_vip_get_page_by_title() instead.', - ], 139 => [ 'get_children() is uncached and performs a no limit query. Please use get_posts or WP_Query instead. Please see: https://docs.wpvip.com/technical-references/caching/uncached-functions/', ], diff --git a/WordPress-VIP-Go/ruleset.xml b/WordPress-VIP-Go/ruleset.xml index f8952dcb..8cd531c3 100644 --- a/WordPress-VIP-Go/ruleset.xml +++ b/WordPress-VIP-Go/ruleset.xml @@ -152,10 +152,6 @@ warning - - warning - %s() is uncached, please use wpcom_vip_get_page_by_title() instead. - warning 3 diff --git a/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php b/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php index 8f81f4cf..152f4499 100644 --- a/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php @@ -80,13 +80,6 @@ public function getGroups() { 'switch_to_blog', ], ], - 'get_page_by_title' => [ - 'type' => 'error', - 'message' => '%s() is prohibited, please use wpcom_vip_get_page_by_title() instead.', - 'functions' => [ - 'get_page_by_title', - ], - ], 'url_to_postid' => [ 'type' => 'error', 'message' => '%s() is prohibited, please use wpcom_vip_url_to_postid() instead.', diff --git a/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc b/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc index b4366c98..10851408 100644 --- a/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc +++ b/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc @@ -55,8 +55,8 @@ $wp_rewrite->flush_rules(); // Error. switch_blog(); // Ok - similarly-named function to switch_to_blog(). switch_to_blog( $blogid ); // Warning. -wpcom_vip_get_page_by_title(); // Ok - VIP recommended version of get_page_by_title(). -get_page_by_title( $page_title ); // Error. + + wpcom_vip_url_to_postid( $url ); // Ok - VIP recommended version of url_to_postid(). url_to_postid( $url ); // Error. diff --git a/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php b/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php index bb5236cb..036bd4f7 100644 --- a/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php +++ b/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php @@ -35,7 +35,6 @@ public function getErrorList() { 43 => 1, 46 => 1, 50 => 1, - 59 => 1, 62 => 1, 75 => 1, 76 => 1, diff --git a/WordPressVIPMinimum/ruleset-test.inc b/WordPressVIPMinimum/ruleset-test.inc index fd0567c6..a20a8494 100644 --- a/WordPressVIPMinimum/ruleset-test.inc +++ b/WordPressVIPMinimum/ruleset-test.inc @@ -322,7 +322,7 @@ $wp_rewrite->flush_rules(); // Error. attachment_url_to_postid( $url ); // Error. switch_to_blog( $blogid ); // Warning. -get_page_by_title( $page_title ); // Error. + url_to_postid( $url ); // Error. \add_role(); // Error. diff --git a/WordPressVIPMinimum/ruleset-test.php b/WordPressVIPMinimum/ruleset-test.php index 71016e82..e78ae6a7 100644 --- a/WordPressVIPMinimum/ruleset-test.php +++ b/WordPressVIPMinimum/ruleset-test.php @@ -92,7 +92,6 @@ 320 => 1, 321 => 1, 322 => 1, - 325 => 1, 326 => 1, 327 => 1, 333 => 1,