Skip to content

Instantly share code, notes, and snippets.

@thefuxia
Created September 6, 2012 13:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefuxia/3656132 to your computer and use it in GitHub Desktop.
Save thefuxia/3656132 to your computer and use it in GitHub Desktop.
T5 Attachment Extras
<?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 <info@toscho.de>
* 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