Context:
I'm testing Faust with WordPress Bedrock, and due to the different structure, when previewing content, it results in a 404 error.
This issue is caused by the $search_pattern in handle_generate_endpoint().
|
function handle_generate_endpoint() { |
|
$search_pattern = ':^' . site_url( '/generate', 'relative' ) . ':'; |
|
|
|
if ( ! preg_match( $search_pattern, $_SERVER['REQUEST_URI'] ) ) { // phpcs:ignore WordPress.Security |
|
return; |
|
} |
Because Bedrock returns the prefix /wp/ in site_url( '/generate', 'relative' ) (/wp/generate) while $_SERVER['REQUEST_URI'] contains only /generate[...], it always fails at the statement below:
if ( ! preg_match( $search_pattern, $_SERVER['REQUEST_URI'] ) ) { // phpcs:ignore WordPress.Security
return;
}
Suggestion
Since site_url() returns the URL for the current site where WordPress applications are accessible, the best way to move forward is to use a callback filter (apply_filters) so anyone can customize it with a callback filter.
/**
* Filter 'faustwp_generate_endpoint_search_pattern'.
*
* @param string $value The search pattern.
*/
$search_pattern = apply_filters( 'faustwp_generate_endpoint_search_pattern', $search_pattern );
Example of how to use the filter
add_filter('faustwp_generate_endpoint_search_pattern', function ($value) {
return str_replace('/wp/', '/', $value);
});
Context:
I'm testing Faust with WordPress Bedrock, and due to the different structure, when previewing content, it results in a 404 error.
This issue is caused by the
$search_patterninhandle_generate_endpoint().faustjs/plugins/faustwp/includes/auth/callbacks.php
Lines 24 to 29 in 002687f
Because Bedrock returns the prefix
/wp/insite_url( '/generate', 'relative' )(/wp/generate) while$_SERVER['REQUEST_URI']contains only/generate[...], it always fails at the statement below:Suggestion
Since
site_url()returns the URL for the current site where WordPress applications are accessible, the best way to move forward is to use a callback filter (apply_filters) so anyone can customize it with a callback filter.Example of how to use the filter