Advertisement
SergeyBiryukov

Display Active Plugins First

Jan 29th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Display Active Plugins First
  4. Plugin URI:
  5. Description: Changes plugins display order in the admin, showing active plugins first.
  6. Version: 1.0
  7. Author: Sergey Biryukov
  8. Author URI: http://profiles.wordpress.org/sergeybiryukov/
  9. */
  10.  
  11. class Display_Active_Plugins_First {
  12.  
  13.     function __construct() {
  14.         add_action( 'admin_head-plugins.php', array( $this, 'sort_plugins_by_status' ) );
  15.     }
  16.  
  17.     function sort_plugins_by_status() {
  18.         global $wp_list_table;
  19.  
  20.         uksort( $wp_list_table->items, array( $this, '_order_callback' ) );
  21.     }
  22.  
  23.     function _order_callback( $a, $b ) {
  24.         global $wp_list_table;
  25.  
  26.         $a_active = is_plugin_active( $a );
  27.         $b_active = is_plugin_active( $b );
  28.  
  29.         if ( $a_active && $b_active ) {
  30.             return strcasecmp( $wp_list_table->items[ $a ]['Name'], $wp_list_table->items[ $b ]['Name'] );
  31.         } elseif ( $a_active && ! $b_active ) {
  32.             return -1;
  33.         } elseif ( ! $a_active && $b_active ) {
  34.             return 1;
  35.         } else {
  36.             return strcasecmp( $wp_list_table->items[ $a ]['Name'], $wp_list_table->items[ $b ]['Name'] );
  37.         }
  38.     }
  39.  
  40. }
  41.  
  42. new Display_Active_Plugins_First;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement