wordpress-website-lifecycle/mu-plugins/_core-http-reencode-query-string-spaces.php

31 lines
847 B
PHP
Raw Normal View History

<?php
/*
2023-05-21 15:14:56 +00:00
* Plugin Name: Re-encode spaces in query string with %20
2023-08-04 10:34:27 +00:00
* Plugin URI: https://github.com/szepeviktor/wordpress-website-lifecycle
*/
add_action(
'init',
static function () {
$parsed_url = parse_url($_SERVER['REQUEST_URI']);
if (!isset($parsed_url['path']) || $parsed_url['path'] === '') {
return;
}
$request_uri = $parsed_url['path'];
$query_string = '';
if (isset($parsed_url['query'])) {
$query_parameters = [];
parse_str($parsed_url['query'], $query_parameters);
$query_string = http_build_query($query_parameters, '', '&', PHP_QUERY_RFC3986);
$request_uri .= '?' . $query_string;
}
$_SERVER['REQUEST_URI'] = $request_uri;
$_SERVER['QUERY_STRING'] = $query_string;
},
0,
0
);