From 5b189f6998c832b05412a7171d8d4ced3567ba33 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Fri, 21 Aug 2026 12:24:05 +0530 Subject: [PATCH 1/3] fix: handle WP Error responses to prevent fatal --- inc/compatibility/elementor.php | 24 +++++++---- tests/test-elementor-compatibility.php | 59 ++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 tests/test-elementor-compatibility.php diff --git a/inc/compatibility/elementor.php b/inc/compatibility/elementor.php index d2dca99088..1b4f945956 100644 --- a/inc/compatibility/elementor.php +++ b/inc/compatibility/elementor.php @@ -134,12 +134,16 @@ public function enqueue() { /** * Filter rest responses to add Neve Palette Colors to pages using Elementor. * - * @param \WP_REST_Response $response request response. - * @param array $handler request handler. - * @param \WP_REST_Request $request rest request. - * @return \WP_REST_Response + * @param \WP_REST_Response|\WP_Error $response request response. + * @param array $handler request handler. + * @param \WP_REST_Request $request rest request. + * @return \WP_REST_Response|\WP_Error */ public function alter_global_colors_front_end( $response, $handler, \WP_REST_Request $request ) { + if ( is_wp_error( $response ) ) { + return $response; + } + $route = $request->get_route(); $rest_to_slugs = [ 'nvprimaryaccent' => 'nv-primary-accent', @@ -178,12 +182,16 @@ public function alter_global_colors_front_end( $response, $handler, \WP_REST_Req /** * Filter rest responses to add Neve Palette Colors to Elementor. * - * @param \WP_REST_Response $response request response. - * @param array $handler request handler. - * @param \WP_REST_Request $request rest request. - * @return \WP_REST_Response + * @param \WP_REST_Response|\WP_Error $response request response. + * @param array $handler request handler. + * @param \WP_REST_Request $request rest request. + * @return \WP_REST_Response|\WP_Error */ public function alter_global_colors_in_picker( $response, $handler, \WP_REST_Request $request ) { + if ( is_wp_error( $response ) ) { + return $response; + } + $route = $request->get_route(); if ( $route !== '/elementor/v1/globals' ) { diff --git a/tests/test-elementor-compatibility.php b/tests/test-elementor-compatibility.php new file mode 100644 index 0000000000..3f51e077b9 --- /dev/null +++ b/tests/test-elementor-compatibility.php @@ -0,0 +1,59 @@ + 403 ] ); + + $this->assertSame( $error, $elementor->alter_global_colors_in_picker( $error, [], $request ) ); + } + + /** + * Errored responses on a color route should be passed through untouched. + */ + public function test_global_colors_front_end_passes_through_wp_error() { + $elementor = new \Neve\Compatibility\Elementor(); + $request = new WP_REST_Request( 'GET', '/elementor/v1/globals/colors/nvprimaryaccent' ); + $error = new WP_Error( 'rest_forbidden', 'Sorry, you are not allowed to do that.', [ 'status' => 403 ] ); + + $this->assertSame( $error, $elementor->alter_global_colors_front_end( $error, [], $request ) ); + } + + /** + * Valid responses should still get the Neve palette colors merged in. + */ + public function test_global_colors_in_picker_adds_palette_colors() { + if ( ! defined( 'ELEMENTOR_VERSION' ) ) { + define( 'ELEMENTOR_VERSION', '3.0.0' ); + } + + $elementor = new \Neve\Compatibility\Elementor(); + $elementor->init(); + $request = new WP_REST_Request( 'GET', self::GLOBALS_ROUTE ); + $response = new WP_REST_Response( [ 'colors' => [] ] ); + + $filtered = $elementor->alter_global_colors_in_picker( $response, [], $request ); + $data = $filtered->get_data(); + + $this->assertArrayHasKey( 'nvprimaryaccent', $data['colors'] ); + $this->assertArrayHasKey( 'value', $data['colors']['nvprimaryaccent'] ); + } +} From 90d08db9d848c4f787c1353ca918e5e08eb7cc82 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Fri, 21 Aug 2026 12:50:10 +0530 Subject: [PATCH 2/3] fix: improve Elementor compatibility tests --- tests/test-elementor-compatibility.php | 57 ++++++++++++++++++++------ 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/tests/test-elementor-compatibility.php b/tests/test-elementor-compatibility.php index 3f51e077b9..704c0fc16d 100644 --- a/tests/test-elementor-compatibility.php +++ b/tests/test-elementor-compatibility.php @@ -1,6 +1,6 @@ setAccessible( true ); + $custom_colors->setValue( null, [] ); + + return $elementor; + } + /** * Errored responses should be passed through untouched. */ public function test_global_colors_in_picker_passes_through_wp_error() { - $elementor = new \Neve\Compatibility\Elementor(); + $elementor = $this->get_elementor_compat(); $request = new WP_REST_Request( 'GET', self::GLOBALS_ROUTE ); $error = new WP_Error( 'rest_forbidden', 'Sorry, you are not allowed to do that.', [ 'status' => 403 ] ); @@ -30,8 +53,8 @@ public function test_global_colors_in_picker_passes_through_wp_error() { * Errored responses on a color route should be passed through untouched. */ public function test_global_colors_front_end_passes_through_wp_error() { - $elementor = new \Neve\Compatibility\Elementor(); - $request = new WP_REST_Request( 'GET', '/elementor/v1/globals/colors/nvprimaryaccent' ); + $elementor = $this->get_elementor_compat(); + $request = new WP_REST_Request( 'GET', self::COLOR_ROUTE ); $error = new WP_Error( 'rest_forbidden', 'Sorry, you are not allowed to do that.', [ 'status' => 403 ] ); $this->assertSame( $error, $elementor->alter_global_colors_front_end( $error, [], $request ) ); @@ -41,14 +64,9 @@ public function test_global_colors_front_end_passes_through_wp_error() { * Valid responses should still get the Neve palette colors merged in. */ public function test_global_colors_in_picker_adds_palette_colors() { - if ( ! defined( 'ELEMENTOR_VERSION' ) ) { - define( 'ELEMENTOR_VERSION', '3.0.0' ); - } - - $elementor = new \Neve\Compatibility\Elementor(); - $elementor->init(); - $request = new WP_REST_Request( 'GET', self::GLOBALS_ROUTE ); - $response = new WP_REST_Response( [ 'colors' => [] ] ); + $elementor = $this->get_elementor_compat(); + $request = new WP_REST_Request( 'GET', self::GLOBALS_ROUTE ); + $response = new WP_REST_Response( [ 'colors' => [] ] ); $filtered = $elementor->alter_global_colors_in_picker( $response, [], $request ); $data = $filtered->get_data(); @@ -56,4 +74,19 @@ public function test_global_colors_in_picker_adds_palette_colors() { $this->assertArrayHasKey( 'nvprimaryaccent', $data['colors'] ); $this->assertArrayHasKey( 'value', $data['colors']['nvprimaryaccent'] ); } + + /** + * Valid responses on a single color route should be replaced with the Neve color. + */ + public function test_global_colors_front_end_overrides_color() { + $elementor = $this->get_elementor_compat(); + $request = new WP_REST_Request( 'GET', self::COLOR_ROUTE ); + $response = new WP_REST_Response( [] ); + + $filtered = $elementor->alter_global_colors_front_end( $response, [], $request ); + $data = $filtered->get_data(); + + $this->assertSame( 'nvprimaryaccent', $data['id'] ); + $this->assertArrayHasKey( 'value', $data ); + } } From d1dde77f267035961cbd0f1806ad5cd8e486ba43 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Fri, 21 Aug 2026 14:35:38 +0530 Subject: [PATCH 3/3] fix: correct setting of custom global colors --- tests/test-elementor-compatibility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-elementor-compatibility.php b/tests/test-elementor-compatibility.php index 704c0fc16d..845d0246ba 100644 --- a/tests/test-elementor-compatibility.php +++ b/tests/test-elementor-compatibility.php @@ -33,7 +33,7 @@ private function get_elementor_compat() { $custom_colors = new ReflectionProperty( $elementor, 'custom_global_colors' ); $custom_colors->setAccessible( true ); - $custom_colors->setValue( null, [] ); + $custom_colors->setValue( $elementor, [] ); return $elementor; }