Skip to content

PHP/RestrictedPHPFunctions: add XML documentation#2693

Merged
jrfnl merged 5 commits intoWordPress:developfrom
rodrigoprimo:docs-restricted-php-functions
Mar 5, 2026
Merged

PHP/RestrictedPHPFunctions: add XML documentation#2693
jrfnl merged 5 commits intoWordPress:developfrom
rodrigoprimo:docs-restricted-php-functions

Conversation

@rodrigoprimo
Copy link
Copy Markdown
Collaborator

Description

This PR adds XML documentation for the WordPress.PHP.RestrictedPHPFunctions sniff.

It is based on the work started by @gogdzl in #2491. I squashed the original commits and, in a separate commit, reworked the documentation to address some of the changes suggested during the review of #2491 and a few more that I decided while working on this PR:

  • Make the standard description generic instead of mentioning create_function() specifically, following the pattern used by other docs like DeprecatedFunctionsStandard.xml.
  • Use "must not" instead of "should not" since the sniff produces an error.
  • Simplify the code examples by removing the add_action() wrapper.
  • Reposition the <em> tags to the valid code example.

I suggest squashing the two commits before merging. I'm opening the PR without doing that to make it easier to tell my changes apart from the original changes.

Suggested changelog entry

N/A

Related issues/external references

Related to: #1722
Supersedes: #2491
Closes #2491

gogdzl and others added 2 commits February 4, 2026 09:31
Some of these changes were suggested during the review of PR 2491,
and others were decided while working on the new PR:
- Make the standard description generic instead of mentioning
  create_function() specifically, following the pattern used by other
  docs like DeprecatedFunctionsStandard.xml.
- Use "must not" instead of "should not" since the sniff produces an
  error.
- Simplify the code examples by removing the add_action() wrapper.
- Add <em> tags to the valid code example.
Following the suggestion in PR 2687, this commit improves the
standard description to explain why these functions must not
be used.

The phrasing is kept generic instead of mentioning
create_function() specifically, since the sniff name suggests
it could be extended with more functions in the future.
@rodrigoprimo
Copy link
Copy Markdown
Collaborator Author

Just noting here that, following what was suggested in #2687 (review), I added a new commit that expands the standard description to explain why the rule exists.

Copy link
Copy Markdown
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @rodrigoprimo!

Simplify the code examples by removing the add_action() wrapper.

I'm not so sure that was the right call. The create_function() function was typically used as a callback for a WP hook-in, so while including that wrapper makes the code sample a little more complicated, it also makes it far more realistic and easier to recognize.

Reposition the <em> tags to the valid code example.

I'd suggest ensuring that the <em> tags enclose the complete create_function() function call and it's equivalent closure.
That way it is more straight-forward for someone to see how to replace one with the other.

Comment thread WordPress/Docs/PHP/RestrictedPHPFunctionsStandard.xml Outdated
Comment thread WordPress/Docs/PHP/RestrictedPHPFunctionsStandard.xml Outdated
Comment thread WordPress/Docs/PHP/RestrictedPHPFunctionsStandard.xml Outdated
Comment thread WordPress/Docs/PHP/RestrictedPHPFunctionsStandard.xml Outdated
jrfnl added a commit that referenced this pull request Feb 23, 2026
Follow up on the conversation about this phrasing in #2491 (comment) and #2693 (comment)
jrfnl added a commit that referenced this pull request Feb 23, 2026
Follow up on the conversation about this phrasing in #2491 (comment) and #2693 (comment)
jrfnl added a commit that referenced this pull request Feb 23, 2026
Follow up on the conversation about this phrasing in #2491 (comment) and #2693 (comment)

Also related to: WordPress/wpcs-docs#158
Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
@rodrigoprimo rodrigoprimo force-pushed the docs-restricted-php-functions branch from 3dcdd85 to 3c26be4 Compare February 23, 2026 18:41
@rodrigoprimo
Copy link
Copy Markdown
Collaborator Author

Thanks for your review, @jrfnl!

I have applied the changes that you suggested, and this is now ready for another check.

Copy link
Copy Markdown
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

All good from me. Thanks for working on this @rodrigoprimo !

@jrfnl
Copy link
Copy Markdown
Member

jrfnl commented Feb 24, 2026

For whomever does the second review: please squashmerge.

>
<standard>
<![CDATA[
Certain PHP functions must not be used, as they pose security risks. Use the recommended alternatives instead.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

as they pose security risks

While https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php only contains the one restricted function (and that's because it's a security risk), there's nothing in the sniff name and comments as a whole, which limits the list of restricted functions to just those with security issues. As such, this XML documentation is a little misaligned with the sniff file comments.

If we were to add a new restricted PHP function because it had performance issues or wasn't cross-OS compatible, we'd also have to amend this XML description.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for your review, @GaryJones. That is a good point. Should I update the description to be just:

Certain PHP functions must not be used. Use the recommended alternatives instead.

Or do you have a different suggestion?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, generalising the sniff description, but leaving comments in the rule code.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, @GaryJones! I pushed a new commit implementing your suggestion.

@jrfnl jrfnl modified the milestones: 3.3.x, 3.4.0 Feb 24, 2026
@jrfnl jrfnl mentioned this pull request Feb 24, 2026
61 tasks
@jrfnl jrfnl merged commit 6c040ea into WordPress:develop Mar 5, 2026
31 checks passed
@rodrigoprimo rodrigoprimo deleted the docs-restricted-php-functions branch March 5, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants