and tags?
* Is there a call to wp_title()?
* There can't be any hardcoded text in the
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 add_theme_support( 'title-tag' ) first
$titletag = true;
if ( ! preg_match( '#add_theme_support\s?\(\s?[\'|"]title-tag#', $php ) ) {
$this->error[] = ''.__('REQUIRED','theme-check').': '.__('No reference to add_theme_support( "title-tag" ) was found in the theme.', 'theme-check' );
$titletag = false;
$ret = false;
}
// Look for and tags.
checkcount();
if ( ( 0 <= strpos( $php, '' ) || 0 <= strpos( $php, '' ) ) && !$titletag ) {
$this->error[] = '' . __( 'REQUIRED', 'theme-check').': ' . __( 'The theme must not used the <title> tags.', 'theme-check' );
$ret = false;
}
// Check whether there is a call to wp_title()
checkcount();
if ( 0 <= strpos( $php, 'wp_title(' ) && !$titletag ) {
$this->error[] = '' . __( 'REQUIRED', 'theme-check').': ' . __( 'The theme must not call to wp_title().', 'theme-check' );
$ret = false;
}
//Check whether the the tag contains something besides a call to wp_title()
checkcount();
foreach ( $php_files as $file_path => $file_content ) {
// Look for anything that looks like and exclude it (inline svg's have titles too)
$file_content = preg_replace('/.*<\/svg>/s', '', $file_content);
// First looks ahead to see of there's ...
// Then performs a negative look ahead for wp_title(...);
if ( preg_match( '/(?=(.*)<\/title>)(?!\s*<\?php\s*wp_title\([^\)]*\);?\s*\?>\s*<\/title>)/s', $file_content ) ) {
$this->error[] = '' . __( 'REQUIRED', 'theme-check').': ' . __( 'The <title> tags can only contain a call to wp_title(). Use the wp_title filter to modify the output', 'theme-check' );
$ret = false;
}
}
return $ret;
}
function getError() { return $this->error; }
}
$themechecks[] = new Title_Checks;