Skip to content

Commit

Permalink
Update the VIP.RestrictedFunctions sniff (#969)
Browse files Browse the repository at this point in the history
* As of WordPress 4.8, get_term_by() is cached so we're going to stop recommending the use of wpcom_vip_get_term_by() instead of the core function. The function wpcom_vip_get_term_by() will be deprecated.
* Also revised the sniff for get_category_by_slug() because it uses get_term_by() which is now recommended over wpcom_vip_get_term_by().
* Removing get_term_link() as restricted/flagged functions

Using get_term_link(), get_tag_link(), and get_category_link() is okay as of WP 4.8, so we no longer need to flag these instances. Revised VIP sniff and unit testing to flag wpcom_vip_get_term_link() as deprecated instead.
  • Loading branch information
Alexis Kulash authored and jrfnl committed Aug 3, 2017
1 parent 4b0dece commit eb54d05
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
21 changes: 9 additions & 12 deletions WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,11 @@ public function getGroups() {
),
),

'get_term_link' => array(
'wpcom_vip_get_term_link' => array(
'type' => 'error',
'message' => '%s() is prohibited, please use wpcom_vip_get_term_link() instead.',
'message' => '%s() is deprecated, please use get_term_link(), get_tag_link(), or get_category_link() instead.',
'functions' => array(
'get_term_link',
'get_tag_link',
'get_category_link',
'wpcom_vip_get_term_link',
),
),

Expand All @@ -89,20 +87,19 @@ public function getGroups() {
),
),

'get_term_by' => array(
'wpcom_vip_get_term_by' => array(
'type' => 'error',
'message' => '%s() is prohibited, please use wpcom_vip_get_term_by() instead.',
'message' => '%s() is deprecated, please use get_term_by() or get_cat_ID() instead.',
'functions' => array(
'get_term_by',
'get_cat_ID',
'wpcom_vip_get_term_by',
),
),

'get_category_by_slug' => array(
'wpcom_vip_get_category_by_slug' => array(
'type' => 'error',
'message' => '%s() is prohibited, please use wpcom_vip_get_category_by_slug() instead.',
'message' => '%s() is deprecated, please use get_category_by_slug() instead.',
'functions' => array(
'get_category_by_slug',
'wpcom_vip_get_category_by_slug',
),
),

Expand Down
12 changes: 6 additions & 6 deletions WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ $y = Bar::add_role(); // Ok.

\add_role(); // Error.

get_term_link( $term ); // Error.
wpcom_vip_get_term_link( $term ); // Error.

get_page_by_path( $path ); // Error.

get_page_by_title( $page_title ); // Error.

get_term_by( $field, $value, $taxonomy ); // Error.
wpcom_vip_get_term_by( $field, $value, $taxonomy ); // Error.

get_category_by_slug( $slug ); // Error.
wpcom_vip_get_category_by_slug( $slug ); // Error.

url_to_postid( $url ); // Error.

attachment_url_to_postid( $url ); // Error.
wpcom_vip_attachment_url_to_postid( $url ); // Ok.

get_tag_link(); // Error.
get_category_link(); // Error.
get_cat_ID(); // Error.
get_tag_link(); // Ok.
get_category_link(); // Ok.
get_cat_ID(); // Ok.
url_to_post_id(); // Error.

get_posts(); // Warning.
Expand Down
3 changes: 0 additions & 3 deletions WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ public function getErrorList() {
42 => 1,
44 => 1,
46 => 1,
49 => 1,
50 => 1,
51 => 1,
52 => 1,
62 => 1,
63 => 1,
Expand Down

0 comments on commit eb54d05

Please sign in to comment.