WPTT / WPThemeReview

PHP_CodeSniffer rules (sniffs) to enforce WordPress theme review coding conventions
MIT License
208 stars 38 forks source link

[New sniff] Check if page templates are using reserved prefix #212

Closed dingo-d closed 5 years ago

dingo-d commented 5 years ago
Basic Info -
Rule type: Error
Sniff Category: ThouShallNotUse

Rule:

Do not use reserved name as a prefix, as WordPress will interpret the file as a specialised template, meant to apply to only one page on your site. Found %s

Ref: https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use

Theme check file covering this rule:

None

Notes for implementation:

Based on this list: https://developer.wordpress.org/themes/basics/template-files/#common-wordpress-template-files

If we find a template file - meaning file that contains Template Name: Example template comment but in a file that has reserved template file name in it, an error should be thrown that would notify the user not to do this, as his/her template won't be a reusable template, but used only on one page.

[For new sniffs only] Code Samples:

Error: File name points to a page template, but the intended use is contact page template

// file name: page-contact.php
<?php
/* Template Name: Contact page template */

// code goes here

OK: File name is some custom name, but is a template because of the Template Name comment

// file name: tmpl-contact.php
<?php
/* Template Name: Contact page template */

// code goes here

To do:

jrfnl commented 5 years ago

Closing as fixed by #213