From 0f85c957d6274271bf6c3b9f11e40f207a1073dd Mon Sep 17 00:00:00 2001
From: Neil Williams <neil@tailormade.uk>
Date: Mon, 22 Sep 2025 12:27:11 +0100
Subject: [PATCH] get_page_templates(): sort templates by human-readable name
 before flipping. Fixes #49194

---
 src/wp-admin/includes/theme.php | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php
index 8fc9c00f14..8acf5a4749 100644
--- a/src/wp-admin/includes/theme.php
+++ b/src/wp-admin/includes/theme.php
@@ -148,7 +148,13 @@ function delete_theme( $stylesheet, $redirect = '' ) {
  * @return string[] Array of template file names keyed by the template header name.
  */
 function get_page_templates( $post = null, $post_type = 'page' ) {
-	return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) );
+	$templates = wp_get_theme()->get_page_templates( $post, $post_type );
+
+	// Sort by template name
+	asort( $templates, SORT_NATURAL | SORT_FLAG_CASE );
+
+	// Flip to match expected return: filename => template name
+	return array_flip( $templates );
 }
 
 /**
-- 
2.43.0

