Skip to content

Instantly share code, notes, and snippets.

@marco-s
Forked from scribu/test-list-tables.php
Created February 13, 2012 22:47
Show Gist options
  • Save marco-s/1821209 to your computer and use it in GitHub Desktop.
Save marco-s/1821209 to your computer and use it in GitHub Desktop.
WP Admin List Tables hooks
<?php
//////////////////
// Screens
//////////////////
// Posts
foreach ( array(
'posts', 'pages', 'recipe_posts',
'edit-post', 'edit-page', 'edit-recipe',
) as $screen_id ) {
add_filter( "manage_{$screen_id}_columns", 'register_test_column' );
add_action( "manage_{$screen_id}_custom_column", 'display_test_column', 10, 2 );
}
// Media
foreach ( array(
'media', 'upload'
) as $screen_id ) {
add_filter( "manage_{$screen_id}_columns", 'register_test_column' );
add_action( "manage_{$screen_id}_custom_column", 'display_test_column', 10, 2 );
}
// Terms
foreach ( array(
'category', 'post_tag', 'color'
) as $taxonomy ) {
add_filter( "manage_edit-{$taxonomy}_columns", 'register_test_column' );
add_filter( "manage_{$taxonomy}_custom_column", 'render_test_column', 10, 3 );
}
// Comments
foreach ( array(
'comments'
) as $screen_id ) {
add_filter( "manage_edit-{$screen_id}_columns", 'register_test_column' );
add_action( "manage_{$screen_id}_custom_column", 'display_test_column', 10, 2 );
}
// Users
foreach ( array(
'users', 'users-network'
) as $screen_id ) {
add_filter( "manage_{$screen_id}_columns", 'register_test_column' );
add_filter( "manage_{$screen_id}_custom_column", 'render_test_column', 10, 3 );
}
// Plugins
foreach ( array(
'plugins', 'plugins-network',
) as $screen_id ) {
add_filter( "manage_{$screen_id}_columns", 'register_test_column' );
add_action( "manage_{$screen_id}_custom_column", 'display_test_column', 10, 2 );
}
// Themes
foreach ( array(
'themes', 'themes-network',
) as $screen_id ) {
add_filter( "manage_{$screen_id}_columns", 'register_test_column' );
add_action( "manage_{$screen_id}_custom_column", 'display_test_column', 10, 2 );
}
// Links
add_filter( "manage_link-manager_columns", 'register_test_column' );
add_action( "manage_link_custom_column", 'display_test_column', 10, 2 );
//////////////////
// Callbacks
//////////////////
function register_test_column( $columns ) {
debug(current_filter());
$columns['test'] = 'Test';
return $columns;
}
function display_test_column( $column, $item_id ) {
if ( 'test' != $column )
return;
debug(current_filter(), $item_id);
}
function render_test_column( $out, $column, $item_id ) {
if ( 'test' != $column )
return '';
ob_start();
debug(current_filter(), $item_id);
return ob_get_clean();
}
//////////////////
// Setup
//////////////////
if ( !function_exists('debug') ) :
function debug() {
$args = func_get_args();
echo "<pre>\n";
foreach ( $args as $arg ) {
if ( is_object($arg) || is_array($arg) )
print_r($arg);
else
var_dump($arg);
}
echo "</pre>\n";
}
endif;
function register_color_tax() {
register_taxonomy( 'color', 'recipe', array('label' => 'Color') );
}
add_action( 'init', 'register_color_tax' );
function register_recipe_ptype() {
register_post_type( 'recipe', array( 'public' => true ) );
}
add_action( 'init', 'register_recipe_ptype' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment