Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AlternativeFunctions: suggest using wp_(un)slash() #1466

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Aug 27, 2018

The WP wp_slash() and wp_unslash() functions are capable of (un)slashing both strings, as well as (nested) arrays, while the PHP native functions can only handle strings.

For input variables, you typically encounter arrays in forms. For instance when a checkbox or dropdown field can accept multiple values. however, the usage of arrays in input variables is definitely not limited to those examples.

With that in mind, I'd like to suggest adding a recommendation to use these functions instead of the PHP native ones to the AlternativeFunctions sniff.

Refs:

The WP `wp_slash()` and `wp_unslash()` functions are capable of (un)slashing both strings, as well as (nested) arrays, while the PHP native functions can only handle strings.

For input variables, you typically encounter arrays in forms. For instance when a checkbox or dropdown field can accept multiple values. however, the usage of arrays in input variables is definitely not limited to those examples.

With that in mind, I'd like to suggest adding a recommendation to use these functions instead of the PHP native ones to the `AlternativeFunctions` sniff.
@jrfnl
Copy link
Member Author

jrfnl commented Sep 3, 2018

@WordPress-Coding-Standards/wpcs-admins Anyone has an opinion on this proposal ?

@westonruter
Copy link
Member

I agree. I think the original purpose being wp_unslash() and wp_slash() was that in the eventual case that magic quotes could be turned off, that these functions could then no-op. I doubt that will ever happen, but if it does, using these functions will ensure that things don't break.

@JDGrimes
Copy link
Contributor

JDGrimes commented Sep 7, 2018

The other side of what @westonruter pointed out is that these functions should really only be used in the context of dealing with magic quotes. Unrelated slashing and unslashing operations shouldn't use them.

@jrfnl
Copy link
Member Author

jrfnl commented Sep 7, 2018

Unrelated slashing and unslashing operations shouldn't use them.

Well, for slashing/unslashing related to database operations, the functions shouldn't be used either as prepared SQL should be used instead.

Let's gather some examples of situations in which it would be preferred to use the PHP native functions over the WP versions. Depending on the examples, either the sniff could try to account for the context in which the functions are used or this PR will be closed.

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.

None yet

3 participants