Skip to content

Instantly share code, notes, and snippets.

@trepmal
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trepmal/9477602 to your computer and use it in GitHub Desktop.
Save trepmal/9477602 to your computer and use it in GitHub Desktop.
<?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' );
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