WPThemeReview icon indicating copy to clipboard operation
WPThemeReview copied to clipboard

Check for direct load of searchform.php

Open khacoder opened this issue 8 years ago • 4 comments

[New sniff] Check to ensure searchform.php is not loaded directly.

Rule type:

Error

Rule:

Standard templates should be called by their respective function.

Ref: https://make.wordpress.org/themes/handbook/review/required/#templates

ERROR | check that no include calls to searchform.php are found, if they are, recommend using get_search_form() instead.

Theme check file covering this rule:

https://github.com/Otto42/theme-check/blob/master/checks/searchform.php

To do:

  • [ ] Create unit tests
  • [ ] Create new sniff
  • [ ] Adjust existing WPCS / PHPCS sniff and send in PR upstream.
  • [ ] Add existing sniffname sniff to the ruleset.

khacoder avatar Aug 22 '16 20:08 khacoder

I have this sniff ready to go and will upload after final testing.

khacoder avatar Aug 22 '16 20:08 khacoder

Somewhat related but might need its own ticket is that I sometimes see themes directly outputting the search form content within other templates rather than using get_search_form(). Just wanted to make a quick note.

justintadlock avatar Sep 29 '16 15:09 justintadlock

From: https://github.com/WPTRT/WordPress-Coding-Standards/pull/82#issuecomment-269238477

I have run the sniff on the some of the theme of the repo and got some false positives

I don't think limiting the sniff to certain files is the way to go per se. Let's take a step back and try to get a crystal clear definition of what this sniff should do and catch. Let's write unit tests to match. And only once that's done, let's look at the actual sniff again.

Let's continue this discussion here.

jrfnl avatar May 31 '18 10:05 jrfnl

We agreed in the theme triage that we should check for usage of

require 'searchform.php'; // include and the _once counterparts

and

get_template_part( 'searchform.php')

And if these are found, we should throw a warning that users should use get_search_form() instead.

This falls under use core functionality category.

An ok case can be:

echo do_blocks( '<!-- wp:search {"label":""} /-->' ); 
get_search_form();
get_search_form(
  array(
    'label' => _x( '404 not found', 'Label', 'twentytwenty' ),
  )
);

dingo-d avatar Apr 08 '20 17:04 dingo-d