theme-check icon indicating copy to clipboard operation
theme-check copied to clipboard

Functions is being misread as a default WP function on theme update

Open eramits opened this issue 4 years ago • 5 comments

Hello,

We have a little problem with the new update checker rules. One of our functions (oceanwp_title()) is being misread as a default WP function (wp_title(), which is not in use in the theme at all), and we're unable to push an update. oceanwp_title has been in the theme since the very first version. We could change the function name, but first, we wanted to check if there's a way to bypass this, otherwise, all our users using custom codes related to this function will experience issues. Not to mention other possible and future issues with all functions using oceanwp in the name. Grateful for any help and feedback we can get

https://github.com/WordPress/theme-check/blob/bba5fefad5ae10f1cf50070e9260230770039d9f/checks/class-title-check.php#L38

dsdsd

Thank you

eramits avatar Jun 22 '21 06:06 eramits

The problem here is that we check if wp_title is contained, and oceanwp_title contains wp_title. Ideally we'd look for exact word matches, so using a regex function that would be something like \bwp_title\b Maybe we should introduce a function themecheck_function_located( $function_name ) and use that consistently everywhere instead of the strpos calls? :thinking: cc @carolinan

aristath avatar Jun 22 '21 10:06 aristath

Yes, a regex would be an improvement. I question whether this check should block upload at all.

carolinan avatar Jun 22 '21 11:06 carolinan

I found 11 themes (including oceanwp) that were blocked by this requirement since june 17.

The requirement is in place because wp_title was supposed to be deprecated many years ago, and it was reverted because so many themes still used it incorrectly. add_theme_support( 'title-tag' ); replaced it.

carolinan avatar Jun 22 '21 13:06 carolinan

Should the check be removed, or tweaked? Tweaking it should be relatively easy and changing the line highlighted above to this should do it:

if ( preg_match( '/\bwp_title\b/', $file_content ) ) { 

aristath avatar Jun 22 '21 14:06 aristath

tweaked then kept as required :) The message needs to be more clear and explain why.

carolinan avatar Jun 22 '21 14:06 carolinan