| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Plugin Name: Keep Alphabetical Order in Gallery
|
|---|
| 4 | Version: 1.0
|
|---|
| 5 | Plugin URI: http://core.trac.wordpress.org/ticket/21643
|
|---|
| 6 | Description: Allows to keep alphabetical order when uploading multiple images at once.
|
|---|
| 7 | Author: Sergey Biryukov
|
|---|
| 8 | Author URI: http://profiles.wordpress.org/sergeybiryukov/
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | function 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 | }
|
|---|
| 21 | add_action( 'pre_get_posts', 'keep_alphabetical_order_in_gallery' );
|
|---|
| 22 | ?>
|
|---|