Skip to content

Instantly share code, notes, and snippets.

@TheLastCicada
Created July 31, 2014 02:31
Show Gist options
  • Save TheLastCicada/68b689968afad7abc4da to your computer and use it in GitHub Desktop.
Save TheLastCicada/68b689968afad7abc4da to your computer and use it in GitHub Desktop.
@trepmal's My Sites Search plugin for wordpress multisite menus with too many sites
<?php
/*
* Plugin Name: My Sites Search
* Plugin URI: trepmal.com
* Description: https://twitter.com/trepmal/status/443189183478132736
* Version:
* Author: Kailey Lampert
* Author URI: kaileylampert.com
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* TextDomain: mss
* DomainPath:
* Network:
*/
add_action( 'admin_bar_menu', 'mss_admin_bar_menu' );
function mss_admin_bar_menu( $wp_admin_bar ) {
$wp_admin_bar->add_menu( array(
'parent' => 'my-sites-list',
'id' => 'my-sites-search',
'title' => '<input type="text" placeholder="Search sites" />',
) );
}
add_action( 'admin_footer', 'mss_admin_footer' );
add_action( 'wp_footer', 'mss_admin_footer' );
function mss_admin_footer() {
// This should suck less, but alas...
?>
<style>
#wp-admin-bar-my-sites-search {
height: 34px;
}
</style>
<script>
jQuery(document).ready( function($) {
$('#wp-admin-bar-my-sites-search input').keyup( function( ) {
var searchValRegex = new RegExp( $(this).val(), 'i');
$('#wp-admin-bar-my-sites-list > li.menupop').hide().filter(function() {
return searchValRegex.test( $(this).find('> a').text() );
}).show();
});
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment