-
Notifications
You must be signed in to change notification settings - Fork 107
/
title.php
57 lines (49 loc) · 2.08 KB
/
title.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Checks for the title:
* Are there <title> and </title> tags?
* Is there a call to wp_title()?
* There can't be any hardcoded text in the <title> tag.
*
* See: http://make.wordpress.org/themes/guidelines/guidelines-theme-check/
*/
class Title_Checks implements themecheck {
protected $error = array();
function check( $php_files, $css_files, $other_files ) {
$ret = true;
$php = implode( ' ', $php_files );
/**
* Look for <title> and </title> tags.
*/
checkcount();
if ( false === strpos( $php, '<title>' ) || false === strpos( $php, '</title>' ) ) {
$this->error[] = '<span class="tc-lead tc-required">' . __( 'REQUIRED', 'theme-check').'</span>: ' . __( 'The theme needs to have <strong><title></strong> tags, ideally in the <strong>header.php</strong> file.', 'theme-check' );
$ret = false;
}
/**
* Check whether there is a call to wp_title().
*/
checkcount();
if ( false === strpos( $php, 'wp_title(' ) ) {
$this->error[] = '<span class="tc-lead tc-required">' . __( 'REQUIRED', 'theme-check').'</span>: ' . __( 'The theme needs to have a call to <strong>wp_title()</strong>, ideally in the <strong>header.php</strong> file.', 'theme-check' );
$ret = false;
}
/**
* Check whether the the <title> tag contains something besides a call to wp_title().
*/
checkcount();
foreach ( $php_files as $file_path => $file_content ) {
/**
* First looks ahead to see of there's <title>...</title>
* Then performs a negative look ahead for <title><?php wp_title(...); ?></title>
*/
if ( preg_match( '/(?=<title>(.*)<\/title>)(?!<title>\s*<\?php\s*wp_title\([^\)]*\);\s*\?>\s*<\/title>)/s', $file_content ) ) {
$this->error[] = '<span class="tc-lead tc-required">' . __( 'REQUIRED', 'theme-check').'</span>: ' . __( 'The <strong><title></strong> tags can only contain a call to <strong>wp_title()</strong>. Use the <strong>wp_title filter</strong> to modify the output', 'theme-check' );
$ret = false;
}
}
return $ret;
}
function getError() { return $this->error; }
}
$themechecks[] = new Title_Checks;