Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/wp-includes/rest-api/class-wp-rest-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,11 @@ public function get_params() {
}
}

// Exclude rest_route if pretty permalinks are not enabled.
if ( ! get_option( 'permalink_structure' ) ) {
unset( $params['rest_route'] );
}

return $params;
}

Expand Down
33 changes: 33 additions & 0 deletions tests/phpunit/tests/rest-api/rest-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1126,4 +1126,37 @@ public function data_is_method_should_detect_method_ignoring_case() {
'HEAD wrong method' => array( 'HEAD', 'GET', false ),
);
}

/**
* @ticket 62163
*/
public function test_get_params_without_pretty_permalink() {
update_option( 'permalink_structure', '' );

$request = new WP_REST_Request();
$request->set_param( 'rest_route', '/wp/v2/posts' );
$request->set_param( 'some_param', 'foobar' );

$params = $request->get_params();

$this->assertArrayNotHasKey( 'rest_route', $params );
$this->assertArrayHasKey( 'some_param', $params );
}

/**
* @ticket 62163
*/
public function test_get_params_with_pretty_permalinks() {
update_option( 'permalink_structure', '/%postname%/' );

$request = new WP_REST_Request();

$request->set_param( 'rest_route', '/wp/v2/posts' );
$request->set_param( 'some_param', 'foobar' );

$params = $request->get_params();

$this->assertArrayHasKey( 'rest_route', $params );
$this->assertArrayHasKey( 'some_param', $params );
}
}
Loading