Handled WP Error responses to prevent fatal - #4595
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds WP_Error pass-through handling to Neve’s Elementor REST response filters and introduces unit tests to validate both error and success behavior.
Changes:
- Return early when Elementor REST filter callbacks receive a
WP_Error. - Update PHPDoc to reflect
WP_REST_Response|\WP_Errorinputs/outputs. - Add PHPUnit tests covering WP_Error pass-through and palette color merging.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/test-elementor-compatibility.php | Adds unit tests for Elementor compatibility REST filtering behavior. |
| inc/compatibility/elementor.php | Adds WP_Error early returns and updates docblocks for REST filter callbacks. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
inc/compatibility/elementor.php:197
- The REST route string is hard-coded here while the test introduces a route constant. Consider defining a class-level constant for
/elementor/v1/globals(and reusing it in both picker and front-end methods) to avoid route drift and reduce duplication.
$route = $request->get_route();
if ( $route !== '/elementor/v1/globals' ) {
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
tests/test-elementor-compatibility.php:39
- Tests are reaching into a private property via reflection, which is brittle (renaming/typing changes to
custom_global_colorswill break tests even if public behavior is unchanged). Consider adding a small, test-friendly seam in the production class (e.g., a constructor parameter, protected setter, or dedicated reset method used only in tests) so the tests can set up state without reflection.
private function get_elementor_compat() {
$elementor = new \Neve\Compatibility\Elementor();
$custom_colors = new ReflectionProperty( $elementor, 'custom_global_colors' );
$custom_colors->setAccessible( true );
$custom_colors->setValue( $elementor, [] );
return $elementor;
}
Summary
Handled WP_Error in
rest_request_after_callbacksfilter callbacks to prevent fatal errors when the response is an error. This ensures that the code only attempts to modify the response if it is a validWP_REST_Responseobject.Check before Pull Request is ready:
Closes #4559