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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions WordPress/Sniffs/WP/AlternativeFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,25 @@ public function getGroups() {
'mt_rand',
),
),

'addslashes' => array(
'type' => 'warning',
'message' => '%s() is discouraged. Use wp_slash() for improved handling of complex variables instead; or in the context of database queries: use prepared statements.',
'since' => '3.6.0',
'functions' => array(
'addslashes',
'addcslashes',
),
),
'stripslashes' => array(
'type' => 'warning',
'message' => '%s() is discouraged. Use wp_unslash() for improved handling of complex variables instead.',
'since' => '3.6.0',
'functions' => array(
'stripslashes',
'stripcslashes',
),
),
);
}

Expand Down
5 changes: 5 additions & 0 deletions WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ file_get_contents(MYABSPATH . 'plugin-file.json'); // Warning.
file_get_contents( MUPLUGINDIR . 'some-file.xml' ); // OK.
file_get_contents( plugin_dir_path( __FILE__ ) . 'subfolder/*.conf' ); // OK.
file_get_contents(WP_Upload_Dir()['path'] . 'subdir/file.inc'); // OK.

addslashes( $string );
addcslashes( $string );
stripslashes( $string );
stripcslashes( $string );
5 changes: 5 additions & 0 deletions WordPress/Tests/WP/AlternativeFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public function getWarningList() {
46 => 1,
47 => 1,
49 => 1,

54 => 1,
55 => 1,
56 => 1,
57 => 1,
);
}

Expand Down