WordPress.org

Make WordPress Core

Ticket #21643: keep-alphabetical-order.php

File keep-alphabetical-order.php, 765 bytes (added by SergeyBiryukov, 3 years ago)
Line 
1<?php
2/*
3Plugin Name: Keep Alphabetical Order in Gallery
4Version: 1.0
5Plugin URI: http://core.trac.wordpress.org/ticket/21643
6Description: Allows to keep alphabetical order when uploading multiple images at once.
7Author: Sergey Biryukov
8Author URI: http://profiles.wordpress.org/sergeybiryukov/
9*/
10
11function keep_alphabetical_order_in_gallery( $wp_query ) {
12        global $current_screen;
13
14        if ( ! is_admin() || empty( $current_screen->id ) || 'media-upload' != $current_screen->id
15                || empty( $_REQUEST['tab'] ) || ! in_array( $_REQUEST['tab'], array( 'type', 'gallery' ) ) )
16                return;
17
18        $wp_query->set( 'orderby', 'menu_order ASC, name' );
19        $wp_query->set( 'order', 'ASC' );
20}
21add_action( 'pre_get_posts', 'keep_alphabetical_order_in_gallery' );
22?>