-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter-plugins.php
69 lines (55 loc) · 1.57 KB
/
filter-plugins.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*
Plugin Name: Filter Plugins
Description: Filter plugins by their author.
Author: scribu
Author URI: http://scribu.net
Plugin URI: http://wordpress.org/extend/plugins/filter-plugins/
Version: 1.0.1
*/
class Filter_Plugins {
function plugin_row_meta( $meta, $file, $data ) {
if ( empty( $meta ) )
$meta[] = '';
$meta[ key( $meta ) ] .= '<span class="pba-id" data-author="' . esc_attr( $data['Author'] ) . '" style="display:none"></span>';
return $meta;
}
function admin_footer() {
$screen = get_current_screen();
if ( !in_array( $screen->base, array( 'plugins', 'plugins-network' ) ) )
return;
?>
<script type="text/javascript">
(function($){
var $select = $('<select>').append( $('<option value="__pba_none">').html('— Author —') );
var authors = [];
$('.pba-id').each(function(){
var author = $(this).attr('data-author');
if ( -1 == $.inArray( author, authors ) )
authors.push(author);
});
$.each(authors, function(i, author){
$select.append( $('<option>').html(author) );
});
$select.change(function(){
var value = $(this).val();
if ( '__pba_none' == value ) {
$('#the-list tr').show();
return;
}
$('#the-list tr').each(function(){
var $row = $(this);
if ( $row.find('.pba-id[data-author="' + value + '"]').length )
$row.show();
else
$row.hide();
});
});
$select.insertBefore('.top .tablenav-pages');
}(jQuery));
</script>
<?php
}
}
add_filter( 'plugin_row_meta', array( 'Filter_Plugins', 'plugin_row_meta' ), 10, 3 );
add_filter( 'admin_footer', array( 'Filter_Plugins', 'admin_footer' ) );