| 1 | <?php |
|---|
| 2 | ////////////////// |
|---|
| 3 | // Screens |
|---|
| 4 | ////////////////// |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | // Posts |
|---|
| 8 | foreach ( array( |
|---|
| 9 | 'posts', 'pages', 'recipe_posts', |
|---|
| 10 | 'edit-post', 'edit-page', 'edit-recipe', |
|---|
| 11 | ) as $screen_id ) { |
|---|
| 12 | add_filter( "manage_{$screen_id}_columns", 'register_test_column' ); |
|---|
| 13 | add_action( "manage_{$screen_id}_custom_column", 'display_test_column', 10, 2 ); |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | // Media |
|---|
| 17 | foreach ( array( |
|---|
| 18 | 'media', 'upload' |
|---|
| 19 | ) as $screen_id ) { |
|---|
| 20 | add_filter( "manage_{$screen_id}_columns", 'register_test_column' ); |
|---|
| 21 | add_action( "manage_{$screen_id}_custom_column", 'display_test_column', 10, 2 ); |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | // Terms |
|---|
| 25 | foreach ( array( |
|---|
| 26 | 'category', 'post_tag', 'color' |
|---|
| 27 | ) as $taxonomy ) { |
|---|
| 28 | add_filter( "manage_edit-{$taxonomy}_columns", 'register_test_column' ); |
|---|
| 29 | add_filter( "manage_{$taxonomy}_custom_column", 'render_test_column', 10, 3 ); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | // Comments |
|---|
| 33 | foreach ( array( |
|---|
| 34 | 'comments' |
|---|
| 35 | ) as $screen_id ) { |
|---|
| 36 | add_filter( "manage_edit-{$screen_id}_columns", 'register_test_column' ); |
|---|
| 37 | add_action( "manage_{$screen_id}_custom_column", 'display_test_column', 10, 2 ); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | // Users |
|---|
| 41 | foreach ( array( |
|---|
| 42 | 'users', 'users-network' |
|---|
| 43 | ) as $screen_id ) { |
|---|
| 44 | add_filter( "manage_{$screen_id}_columns", 'register_test_column' ); |
|---|
| 45 | add_filter( "manage_{$screen_id}_custom_column", 'render_test_column', 10, 3 ); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | // Plugins |
|---|
| 49 | foreach ( array( |
|---|
| 50 | 'plugins', 'plugins-network', |
|---|
| 51 | ) as $screen_id ) { |
|---|
| 52 | add_filter( "manage_{$screen_id}_columns", 'register_test_column' ); |
|---|
| 53 | add_action( "manage_{$screen_id}_custom_column", 'display_test_column', 10, 2 ); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | // Themes |
|---|
| 57 | foreach ( array( |
|---|
| 58 | 'themes', 'themes-network', |
|---|
| 59 | ) as $screen_id ) { |
|---|
| 60 | add_filter( "manage_{$screen_id}_columns", 'register_test_column' ); |
|---|
| 61 | add_action( "manage_{$screen_id}_custom_column", 'display_test_column', 10, 2 ); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | // Links |
|---|
| 65 | add_filter( "manage_link-manager_columns", 'register_test_column' ); |
|---|
| 66 | add_action( "manage_link_custom_column", 'display_test_column', 10, 2 ); |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | ////////////////// |
|---|
| 70 | // Callbacks |
|---|
| 71 | ////////////////// |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | function register_test_column( $columns ) { |
|---|
| 75 | debug(current_filter()); |
|---|
| 76 | |
|---|
| 77 | $columns['test'] = 'Test'; |
|---|
| 78 | |
|---|
| 79 | return $columns; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | function display_test_column( $column, $item_id ) { |
|---|
| 83 | if ( 'test' != $column ) |
|---|
| 84 | return; |
|---|
| 85 | |
|---|
| 86 | debug(current_filter(), $item_id); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | function render_test_column( $out, $column, $item_id ) { |
|---|
| 90 | if ( 'test' != $column ) |
|---|
| 91 | return ''; |
|---|
| 92 | |
|---|
| 93 | ob_start(); |
|---|
| 94 | debug(current_filter(), $item_id); |
|---|
| 95 | return ob_get_clean(); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | ////////////////// |
|---|
| 100 | // Setup |
|---|
| 101 | ////////////////// |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | if ( !function_exists('debug') ) : |
|---|
| 105 | function debug() { |
|---|
| 106 | $args = func_get_args(); |
|---|
| 107 | echo "<pre>\n"; |
|---|
| 108 | foreach ( $args as $arg ) { |
|---|
| 109 | if ( is_object($arg) || is_array($arg) ) |
|---|
| 110 | print_r($arg); |
|---|
| 111 | else |
|---|
| 112 | var_dump($arg); |
|---|
| 113 | } |
|---|
| 114 | echo "</pre>\n"; |
|---|
| 115 | } |
|---|
| 116 | endif; |
|---|
| 117 | |
|---|
| 118 | function register_color_tax() { |
|---|
| 119 | register_taxonomy( 'color', 'recipe', array('label' => 'Color') ); |
|---|
| 120 | } |
|---|
| 121 | add_action( 'init', 'register_color_tax' ); |
|---|
| 122 | |
|---|
| 123 | function register_recipe_ptype() { |
|---|
| 124 | register_post_type( 'recipe', array( 'public' => true ) ); |
|---|
| 125 | } |
|---|
| 126 | add_action( 'init', 'register_recipe_ptype' ); |
|---|
| 127 | |
|---|