Inserting a Download Link in the Quick Edit Actions of the Media Library?

Modified version of a piece of code found in this tutorial.

add_filter('media_row_actions', 'wpse_30159_qe_download_link', 10, 2);

function wpse_30159_qe_download_link($actions, $post) {
    /* Almost sure this is not necessary. Just in case... */
    global $current_screen;
    if ( 'upload' != $current_screen->id ) 
        return $actions; 

    // if not PDF file, return default $actions
    if ( 'application/pdf' != $post->post_mime_type )
        return $actions;

    // relative path/name of the file
    $the_file = str_replace(WP_CONTENT_URL, '.', $post->guid);

    // adding the Action to the Quick Edit row
    $actions['Download'] = '<a href="'.WP_CONTENT_URL.'/download.php?file=".$the_file."">Download</a>';

    return $actions;    
}

The download script resides here: /wp-content/download.php.
And here’s a sample code of a force download script.

Leave a Comment