Make WordPress Core

Ticket #49194: sort-page-templates.patch

File sort-page-templates.patch, 1.1 KB (added by johnnycocheroo454, 8 months ago)

Proposed fix patch file

  • src/wp-admin/includes/theme.php

    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 b function delete_theme( $stylesheet, $redirect = '' ) { 
    148148 * @return string[] Array of template file names keyed by the template header name.
    149149 */
    150150function get_page_templates( $post = null, $post_type = 'page' ) {
    151         return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) );
     151        $templates = wp_get_theme()->get_page_templates( $post, $post_type );
     152
     153        // Sort by template name
     154        asort( $templates, SORT_NATURAL | SORT_FLAG_CASE );
     155
     156        // Flip to match expected return: filename => template name
     157        return array_flip( $templates );
    152158}
    153159
    154160/**