Make WordPress Core

Opened 6 years ago

Last modified 2 months ago

#49194 reviewing defect (bug)

Page Template dropdown ordering should be by title, not value

Reported by: leec87's profile leec87 Owned by: sirlouen's profile SirLouen
Milestone: Future Release Priority: normal
Severity: minor Version:
Component: Posts, Post Types Keywords: good-first-bug has-test-info has-patch
Focuses: ui, administration Cc:

Description

The ordering of items within the Page Template dropdown field is sorted by the value alphabetically, which often creates what appears to be an unordered display when viewing on the front end.

I this should be changed so the ordering of the dropdown options is based on the alphabetical order of the list items themselves.

Attachments (2)

template-dropdown-source.png (63.2 KB) - added by leec87 6 years ago.
sort-page-templates.patch (1.1 KB) - added by johnnycocheroo454 3 months ago.
Proposed fix patch file

Download all attachments as: .zip

Change History (7)

#1 @SergeyBiryukov
6 years ago

  • Component changed from General to Posts, Post Types
  • Focuses ui administration added; accessibility removed

This ticket was mentioned in Slack in #core by sirlouen. View the logs.


3 months ago

#3 @SirLouen
3 months ago

  • Keywords good-first-bug needs-patch has-test-info added
  • Milestone changed from Awaiting Review to Future Release
  • Type changed from enhancement to defect (bug)

Reproduction Report

Description

✅ This report validates that the issue can be reproduced.

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.29
  • Server: nginx/1.29.1
  • Database: mysqli (Server: 8.4.6 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 140.0.0.0
  • OS: Windows 10/11
  • Theme: Minimal Theme 1.0.0
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Testing Instructions

  1. I'm using a very minimal theme like this
  2. Then as commented in the OP, created the 3 templates, like a-template.php, b-template.php, c-template.php
  3. Finally add the code in the supp artifacts to add a menu item to display with get_page_templates
  4. 🐞 Exactly as commented, ordering is done by file name and not by template name as it should

Actual Results

  1. ✅ Error condition occurs (reproduced).

Supplemental Artifacts

Added this to functions.php:

function page_templates_admin_menu() {
    add_menu_page(
        'Page Templates',
        'Page Templates',
        'manage_options',
        'page-templates',
        'page_templates_admin_page',
        'dashicons-media-code',
        81
    );
}
add_action( 'admin_menu', 'page_templates_admin_menu' );
function show_page_templates() {
    
}


function page_templates_admin_page() {
    $templates = get_page_templates();
    echo '<div>';
    echo '<h1>Page Templates</h1>';
    
    echo '<ul>';
    foreach ( $templates as $filename => $name ) {
        echo '<li>' . $name . ' (' . $filename . ')</li>';
    }
    echo '</ul>';
    echo '</div>';
}

@johnnycocheroo454
3 months ago

Proposed fix patch file

#4 @johnnycocheroo454
3 months ago

Proposed patch sorts page templates by their human-readable name before flipping the array, ensuring UI ordering by template name, patch file uploaded.

#5 @SirLouen
2 months ago

  • Keywords has-patch added; needs-patch removed
  • Owner set to SirLouen
  • Status changed from new to reviewing

Thanks @johnnycocheroo454 I will be reviewing it asap.

Note: See TracTickets for help on using tickets.