Created
September 6, 2012 13:15
-
-
Save thefuxia/3656132 to your computer and use it in GitHub Desktop.
T5 Attachment Extras
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
<?php # -*- coding: utf-8 -*- | |
/** | |
* Plugin Name: T5 Attachment Extras | |
* Description: Adds attachment ID and link to parent post to the attachment screen. | |
* Plugin URI: http://toscho.de/?p=2260 | |
* Version: 2012.09.06 | |
* Author: Thomas Scholz <[email protected]> | |
* Author URI: http://toscho.de | |
* License: MIT | |
* License URI: http://www.opensource.org/licenses/mit-license.php | |
*/ | |
if ( ! function_exists( 't5_attachment_extras' ) ) | |
{ | |
add_filter( 'attachment_fields_to_edit', 't5_attachment_extras', 10, 2 ); | |
function t5_attachment_extras( $form_fields, $post ) | |
{ | |
$form_fields['t5_id'] = array ( | |
'label' => 'ID', | |
'input' => 'html', | |
'html' => sprintf( | |
'<a href="%1$s" title="View">%2$d</a>', | |
get_permalink( $post->ID ), // Link to attachment page | |
$post->ID | |
) | |
); | |
if ( empty ( $post->post_parent ) or 0 === $post->post_parent ) | |
{ | |
return $form_fields; | |
} | |
$parent = get_post( $post->post_parent ); | |
$parent_title = '' === $parent->post_title | |
? $parent->ID | |
: esc_html( $parent->post_title ); | |
$parent_html = sprintf( | |
'<a href="%1$s" title="View">%2$s</a> • | |
<a href="%3$s" title="Edit">ID: %4$d</a>', | |
get_permalink( $parent->ID ), | |
( '' === $parent->post_title | |
? $parent->ID | |
: esc_html( $parent->post_title ) ), | |
get_edit_post_link( $parent->ID ), | |
$parent->ID | |
); | |
$form_fields['t5_parent'] = array ( | |
'label' => 'Parent:', | |
'input' => 'html', | |
'html' => $parent_html, | |
); | |
return $form_fields; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment