I am writing a Wordpress wordpress plugin which inserts a power grid of images just over the footer on all frontend pages. The applying would be to display sponsor's logos. Let me harness the Wordpress Media Library because the logos happen to be submitted to be used around the 'sponsorship' page as well as in posts.

Basically I am stuck at being able to access the media library interface around the plugin's options page. All the legwork is performed when it comes to creating the choices page, while using action hook to put content on frontend pages in the wordpress plugin, etc. Things I need now's to have the ability to display all of the files in media library in a listing around the options page, and supply a checkbox or something like that to permit the consumer to choose certain files for insertion over the footer.

The Media Library API appears to become targeted at people writing styles or media plug ins. Help being aware of what to take advantage of could be great!

I believe you would be much best adding your personal column in to the existing media library, instead of try re-coding it yourself

function my_media_col($cols)
    $cols['my_col'] = 'Footer';
    return $cols;
add_filter('manage_media_columns', 'my_media_col');

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)); ?> />
add_action('manage_media_custom_column', 'handle_my_media_col', 10, 2);

Then just hook to the load-upload.php (the library page) and save changes when POST'ed

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
        $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');

Note case a good example, and that i might have a couple of typos.


My code example should store a range of IDs within the options table, underneath the key 'in_footer'.

Put used, you will get all media products marked 'in footer' like so

$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; ?>