Created
January 24, 2012 12:43
-
-
Save scribu/1670037 to your computer and use it in GitHub Desktop.
WP Admin List Tables hooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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