Created
March 3, 2012 02:14
-
-
Save tracend/1963711 to your computer and use it in GitHub Desktop.
Wordpress: Re-attach Media plugin
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
<? | |
/** | |
* Plugin Name: Re-attach Media | |
* Plugin URI: http://makesites.org/ | |
* Description: Enables the option to attach images to other posts. Tested with Wordpress < 3.1. Based on the example by Andy Potanin found here: http://wordpress.org/support/topic/detach-amp-re-attach-media-attachment-images-from-posts | |
* Version: 1.0.0 | |
* Author: Makis Tracend | |
* Author URI: http://about.me/tracend | |
* | |
*/ | |
add_filter("manage_upload_columns", 'upload_columns'); | |
add_action("manage_media_custom_column", 'media_custom_columns', 0, 2); | |
function upload_columns($columns) { | |
unset($columns['parent']); | |
$columns['better_parent'] = "Parent"; | |
return $columns; | |
} | |
function media_custom_columns($column_name, $id) { | |
$post = get_post($id); | |
if($column_name != 'better_parent') | |
return; | |
if ( $post->post_parent > 0 ) { | |
if ( get_post($post->post_parent) ) { | |
$title =_draft_or_post_title($post->post_parent); | |
} | |
?> | |
<strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"><?php echo $title ?></a></strong>, <?php echo get_the_time(__('Y/m/d')); ?> | |
<br /> | |
<a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Re-Attach'); ?></a> | |
<?php | |
} else { | |
?> | |
<?php _e('(Unattached)'); ?><br /> | |
<a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Attach'); ?></a> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment