0

im working on Wordpress Plugins. The review team form the WP Plugin directory requires that every get or post value is sanitizes trhough the WP functions before first access.

Usually i check if a value is given by the isset() function which now is not possible due the above requirement.

My solution for now is doing something like

$foo = isset( sanitize_text_field( $_POST['foo'] ?? '' )) ? sanitize_text_field($_POST['foo']) : $something

But this causes some ohter side effects and isnt the most elegant solution, so i was wondering if anybody has an better idea to go about this?

Thank you.

  • Gerhard, I noticed that the suggested edit queue is full for this, but I do not have a high enough score to vote on those edits. If you come back to this question, please fix the grammar (it makes a difference on this site) and show what your syntax was before you came across the "first access" requirement. Then make it clear that your alternate syntax is not a solution, but just something else you tried that also had problems. Maybe with those edits we can get a better answer. – Luke Gedeon Aug 05 '22 at 15:21
  • What you asked in the comment to my answer, is unreasonable. You cannot use that function as the first access to a variable, because it doesn't handle unset or undefined variables natively. There is no way around that. Further I wouldn't call 'isset' as a first access, `isset` is not a PHP function, it's a construct of the language itself. Like `empty` or `include` or even `??` – ArtisticPhoenix Aug 25 '22 at 15:10
  • Language constructs (are hard coded into the PHP language) - https://stackoverflow.com/questions/3254327/php-what-are-language-constructs-and-why-do-we-need-them#:~:text=Language%20constructs%20are%20hard%20coded,not%20play%20by%20normal%20rules.&text=If%20isset%20was%20a%20normal,works%20without%20throwing%20a%20warning. – ArtisticPhoenix Aug 25 '22 at 15:12

0 Answers0