bordoni / fakerpress

A WordPress plugin that implements an easy way to create fake data inside WordPress.
http://fakerpress.com
Other
338 stars 54 forks source link

fp_array_get parameters are switched up #140

Closed henrikwirth closed 4 years ago

henrikwirth commented 4 years ago

The parameters are applied differently throughout the plugin.

One example here, leading for user inputs, that do not get applied due to wrong defaults:

Module/Post.php

// Fetch Post Content
        $post_content_size = fp_array_get( $request, [ 'content_size' ], FILTER_UNSAFE_RAW, [ 5, 15 ] );
        $post_content_use_html = fp_array_get( $request, [ 'use_html' ], FILTER_SANITIZE_NUMBER_INT, 0 ) === 1;
        $post_content_html_tags = array_map( 'trim', explode( ',', fp_array_get( $request, [ 'html_tags' ], FILTER_SANITIZE_STRING ) ) );

And another example here where default is correctly applied as first argument:

functions/array.php

function fp_array_get_in_any( array $variables, $indexes, $default = null ) {
    foreach ( $variables as $variable ) {
        $found = fp_array_get( $variable, $indexes, null, '__not_found__' );
        if ( '__not_found__' !== $found ) {
            return $found;
        }
    }

    return $default;
}

I'll open a PR with the fix straight away.