Skip to content

Title Check: Avoid Deprecated warnings when there's no file contents.#482

Open
dd32 wants to merge 2 commits intomasterfrom
fix-deprecated-strpos-null
Open

Title Check: Avoid Deprecated warnings when there's no file contents.#482
dd32 wants to merge 2 commits intomasterfrom
fix-deprecated-strpos-null

Conversation

@dd32
Copy link
Member

@dd32 dd32 commented Sep 9, 2025

Not 100% sure how this is happening, but seems like a quick win to avoid unnecessary processing and break early.

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in wp-content/plugins/theme-check/checks/class-title-check.php on line 57 

@kafleg kafleg self-requested a review September 15, 2025 23:24
Copy link
Member

@kafleg kafleg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@carolinan
Copy link
Collaborator

I believe this closes #476 ?
I installed Astra version 4.12.4 and was able to reproduce the problem.

The PR did not solve the whole problem, I am seeing:
Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in
\theme-check\checks\class-title-check.php on line 59
That is after the preg_replace on line 55.

@carolinan carolinan added the bug label Mar 12, 2026
Check that file_content is a string, both before and after the preg_replace.
@carolinan
Copy link
Collaborator

Copilot changed it to is_string, there is now a check also after the preg_match.

Testing instructions:

  1. Install the theme Astra from the .org theme directory.
  2. Run theme check against Astra, confirm that there is no PHP "Deprecated" warnings.
  3. In Astra, functions.php, add: wp_title();
  4. Run theme check against Astra, confirm that there is a recommendation to remove wp_title.
    RECOMMENDED: wp_title() was found in the file functions.php
    This is to confirm that the check still works.

@carolinan
Copy link
Collaborator

There is an alternative PR that adds the is_string check to the if statement: https://github.com/WordPress/theme-check/pull/477/changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants