Created
May 31, 2012 02:28
-
-
Save imjjss/2840552 to your computer and use it in GitHub Desktop.
add custom col for media page
This file contains 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
add_filter('manage_media_columns', array ($this,'my_media_col')); | |
add_action('manage_media_custom_column', array ($this,'handle_my_media_col'), 10, 2); | |
function my_media_col($cols) | |
{ | |
$cols['my_col'] = 'Footer'; | |
return $cols; | |
} | |
function handle_my_media_col($name, $id) | |
{ | |
if ($name !== 'my_col') | |
return false; | |
$in_footer = get_option('in_footer', array()); | |
?> | |
<input type="checkbox" name="in_footer[]" value="<?php echo $id; ?>" <?php checked(in_array($id, $in_footer)); ?> /> | |
<?php | |
} | |
// save | |
function save_my_col() | |
{ | |
if (!isset($_POST['in_footer'])) | |
return false; | |
$in_footer = $_POST['in_footer']; | |
if (is_array($in_footer)) | |
$in_footer = array_map('absint', $in_footer); // sanitize | |
else | |
$in_footer = array(); | |
$in_footer = array_merge(get_option('in_footer', array()), $in_footer); | |
$in_footer = array_unique(array_filter($in_footer)); | |
update_option('in_footer', $in_footer); | |
} | |
add_action('load-upload.php', 'save_my_col'); | |
// use | |
$query = new WP_Query(array('post__in' => get_option('in_footer', array()) )); | |
if ($query->have_posts()): while ($query->have_posts()): $query->the_post(); | |
?> | |
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> | |
<?php endwhile; endif; ?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment