Skip to content

Best way to avoid error with $_POST array using array_map #77

@BWBama85

Description

@BWBama85

I have this code:

( isset( $_POST['display_wpstp_post_type'] ) ) ? array_map( 'sanitize_text_field', $_POST['display_wpstp_post_type'] ) : array();

This works fine with sanitize_text_field, but I would prefer to use a custom function such as this:

function sanitize_unslash( $value ) {
    $value = sanitize_text_field( wp_unslash( $value ) );
    return $value;
}

And pass that function to array_map. However, doing so still presents errors in PHPCS.

$_POST data not unslashed before sanitization. Use wp_unslash() or similarphpcs
Detected usage of a non-sanitized input variable: $_POST['display_wpstp_post_type']phpcs

Would it be possible for this to be supported in the future? Or is there a better way to do what I am trying to do?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions