From 8557f28456e17e25bc63f472b20df613a41f29a1 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Wed, 10 Jul 2024 21:23:38 +0000 Subject: [PATCH] REST API: Ensure string returned in WP_REST_Templates_Controller::get_wp_templates_author_text_field(). Adds a fail-safe to return an empty string should the `switch` ever fall through without returning. Currently, `WP_REST_Templates_Controller::get_wp_templates_author_text_field()` is tightly coupled to `WP_REST_Templates_Controller::get_wp_templates_original_source_field()`. However, if the `$original_source` values change in either method, but not both, it is possible a `void` or `null` will be returned, rather than a `string`. Follow-up to [57366]. Props antonvlasenko, hellofromTonya, debarghyabanerjee. Fixes #61580. git-svn-id: https://develop.svn.wordpress.org/trunk@58705 602fd350-edb4-49c9-b593-d223f7449a82 --- .../rest-api/endpoints/class-wp-rest-templates-controller.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php index cbf0ee040a9b0..de18cbf5aeadb 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php @@ -871,6 +871,9 @@ private static function get_wp_templates_author_text_field( $template_object ) { } return $author->get( 'display_name' ); } + + // Fail-safe to return a string should the original source ever fall through. + return ''; }