Skip to content

Commit d4ec6c6

Browse files
kevinlangleyjrkadamwhite
authored andcommitted
Removing nested function and removing duplicates. (#30)
* Removing nested function. * Also wrapping array_merge with array_unique so that if any other filter has run earlier on rest_query_vars that added the same keys, there won't be duplicates in the end.
1 parent d2d380e commit d4ec6c6

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

plugin.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,9 @@ function rest_api_filter_add_filter_param( $args, $request ) {
4141
global $wp;
4242
$vars = apply_filters( 'rest_query_vars', $wp->public_query_vars );
4343

44-
function allow_meta_query( $valid_vars )
45-
{
46-
$valid_vars = array_merge( $valid_vars, array( 'meta_query', 'meta_key', 'meta_value', 'meta_compare' ) );
47-
return $valid_vars;
48-
}
49-
$vars = allow_meta_query( $vars );
50-
44+
// Allow valid meta query vars.
45+
$vars = array_unique( array_merge( $vars, array( 'meta_query', 'meta_key', 'meta_value', 'meta_compare' ) ) );
46+
5147
foreach ( $vars as $var ) {
5248
if ( isset( $filter[ $var ] ) ) {
5349
$args[ $var ] = $filter[ $var ];

0 commit comments

Comments
 (0)