Merge pull request #20298 from woocommerce/fix/array-combine-tests

Prevent array_combine errors in old versions of PHP
This commit is contained in:
Mike Jolley 2018-05-29 18:54:12 +01:00 committed by GitHub
commit 34d4c9cca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -167,10 +167,14 @@ class WC_Product_Variation extends WC_Product_Simple {
$data = $this->get_variation_attributes();
}
// Filter and encode values so this is not broken by add_query_arg.
$data = array_map( 'urlencode', array_filter( $data ) );
$data = array_filter( $data );
// Encode keys.
if ( empty( $data ) ) {
return $url;
}
// Filter and encode keys and values so this is not broken by add_query_arg.
$data = array_map( 'urlencode', $data );
$keys = array_map( 'urlencode', array_keys( $data ) );
return add_query_arg( array_combine( $keys, $data ), $url );