AdvancedCustomFields / AdvancedCustomFields/acf
ACF prevents some REST responses
Open
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
If another plugin uses the filter rest_pre_dispatch to make the REST API to return a custom response, ACF prevents it.
To Reproduce
- This code should stop any REST request:
add_filter(
'rest_pre_dispatch',
static function ( $response ) {
return new WP_Error( 'oh_no', __( 'Oh no no no no no.' ), array( 'status' => 404 ) );
},
5 // Lower than 10.
);
- But with ACF enabled, it doesn't happen.
Code
class ACF_Rest_Api {
// ...
public function __construct() {
add_filter( 'rest_pre_dispatch', array( $this, 'initialize' ), 10, 3 );
add_action( 'rest_api_init', array( $this, 'register_field' ) );
}
public function initialize( $response, $handler, $request ) {
if ( ! acf_get_setting( 'rest_api_enabled' ) ) {
return; // Should return `$response`.
}
// ...
if ( acf_get_setting( 'rest_api_embed_links' ) ) {
$this->embed_links = new ACF_Rest_Embed_Links();
$this->embed_links->initialize();
}
// Should return `$response`.
}
// ...
}
Version Information:
- WordPress Version 6.9-beta3
- PHP Version 8.0.29
- ACF Version 6.6.2
- "Browser" Insomnia 12
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the ACF_Rest_Api class and trace its rest_pre_dispatch initialize callback, especially the rest_api_enabled and rest_api_embed_links branches. Reproduce the behavior with the supplied filter and verify that a lower-priority custom WP_Error response remains effective when ACF is enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100