Skip to content

wpcom_vip_get_page_by_path is deprecated yet sniff still suggests using it #816

@mlipe-nxs

Description

@mlipe-nxs

Bug Description

The code in the vip-go-mu-plugins repo has deprecated the use of wpcom_vip_get_page_by_path which throws a deprecated error via the WP core _deprecated_function callback.
Automattic/vip-go-mu-plugins@213d797

The WordPressVIPMinimum.Functions.RestrictedFunctions sniff provides a warning which states you should use wpcom_vip_get_page_by_path in place of get_page_by_path

'get_page_by_path' => [
'type' => 'warning',
'message' => '%s() is highly discouraged due to not being cached; please use wpcom_vip_get_page_by_path() instead.',
'functions' => [
'get_page_by_path',
],
],
];

I see there was an issue [#801] started and closed for this which suggests a trac ticket will be switching the function to WP_Query but the sniff was left in place although the function was deprecated.

Within the vip-go-mu-plugins repo the sniff is ignored and the deprecated function is still being called.
https://github.com/Automattic/vip-go-mu-plugins/blob/495b22d3965a6173fb6c83c703ea15e1cd0f81fc/search/es-wp-query/class-es-wp-query-wrapper.php#L550-L553

This can be confusing:

  1. The sniff says to use the deprecated function.
  2. The deprecated function throws a deprecated error.
  3. Ultimately, after tracing everything you end up using the core function with an ignored sniff.

It would simplify/streamline things to remove the sniff.

Minimal Code Snippet

get_page_by_path( $page_path, $output, $post_type );

Error Code

145 | WARNING | get_page_by_path() is highly discouraged due to not being cached; please
| | use wpcom_vip_get_page_by_path() instead.
| | (WordPressVIPMinimum.Functions.RestrictedFunctions.get_page_by_path_get_pa
ge_by_path)

Environment

Use php -v and composer show to get versions.

Question Answer
PHP version 8.1.27
PHP_CodeSniffer version 3.9.0
VIPCS version 3.0.0
WordPressCS version 3.0.1

Tested Against main branch?

  • [ x ] I have verified the issue still exists in the main branch of VIPCS.
  • [ x ] I have verified the issue still exists in the develop branch of VIPCS.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions