Skip to content

Commit 20698be

Browse files
authored
Merge pull request #207 from OpenSourceOrg/fix/api-redirect-issues__dev
Move from name= to id= in url params
2 parents 5c5076a + 16ceecb commit 20698be

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

mu-plugins/osi-api/osi-api.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ public function register_routes() {
4949
'callback' => array( $this, 'get_licenses' ),
5050
'permission_callback' => '__return_true',
5151
'args' => array(
52-
'license_name' => array(
52+
'id' => array(
5353
'required' => false,
5454
'type' => 'string',
5555
'description' => 'Filter by license name',
5656
),
57-
'keyword' => array(
57+
'keyword' => array(
5858
'required' => false,
5959
'type' => 'string',
6060
'description' => 'Filter licenses by keyword',
6161
),
62-
'steward' => array(
62+
'steward' => array(
6363
'required' => false,
6464
'type' => 'string',
6565
'description' => 'Filter licenses by steward',
@@ -111,7 +111,7 @@ public function register_routes() {
111111
public function get_licenses( WP_REST_Request $data ) {
112112

113113
// Check if we have an ID passed.
114-
$name = $data->get_param( 'license_name' );
114+
$searched_slug = $data->get_param( 'id' );
115115

116116
// Check if we have any keyword passed.
117117
$keyword = $data->get_param( 'keyword' );
@@ -127,11 +127,11 @@ public function get_licenses( WP_REST_Request $data ) {
127127
);
128128

129129
// If we have an id, search for posts with a name LIKE
130-
if ( ! empty( $name ) ) {
130+
if ( ! empty( $searched_slug ) ) {
131131
// Add the filter
132132
add_filter( 'posts_where', array( $this, 'posts_where_title_like' ), 10, 2 );
133133

134-
$args['post_title_like'] = sanitize_text_field( $name ); // Use the post name (slug) to filter by ID
134+
$args['post_title_like'] = sanitize_text_field( $searched_slug ); // Use the post name (slug) to filter by ID
135135
} elseif ( ! empty( $keyword ) ) {
136136
// Add a tax query on taxonomy-license-category where passed term is a the slug
137137
$args['tax_query'] = array(
@@ -357,11 +357,6 @@ public function handle_redirects() {
357357
// Add query parameters if any
358358
if ( ! empty( $_GET ) ) { // phpcs:ignore WordPress.Security.NonceVerification
359359
foreach ( $_GET as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification
360-
// Remap reserved "name" param to avoid canonical redirect
361-
if ( 'name' === $key ) {
362-
$key = 'license_name';
363-
}
364-
365360
$sanitized_key = sanitize_key( $key );
366361
$sanitized_value = is_array( $value )
367362
? array_map( 'sanitize_text_field', $value )

0 commit comments

Comments
 (0)